Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "," in end of text in php?

Tags:

php

I have a text:

"2G Network":"GSM 850","3G Network":"HSDPA 850",

How to remove "," in end of text in php

"2G Network":"GSM 850","3G Network":"HSDPA 850"
like image 890
Hai Truong IT Avatar asked Jun 07 '12 04:06

Hai Truong IT


People also ask

How do I remove characters from the end of a string?

In order to remove the last character of a given String, we have to use two parameters: 0 as the starting index, and the index of the penultimate character. We can achieve that by calling String's length() method, and subtracting 1 from the result.

How do you remove the comma at the end of a string?

To remove the last comma from a string, call the replace() method with the following regular expression /,*$/ as the first parameter and an empty string as the second. The replace method will return a new string with the last comma removed. Copied!

How can I remove last three characters from a string in PHP?

To remove the last three characters from a string, we can use the substr() function by passing the start and length as arguments.

How do I remove all characters from a string after a specific character?

To remove everything after a specific character in a string:Use the String. split() method to split the string on the character. Access the array at index 0 . The first element in the array will be the part of the string before the specified character.


1 Answers

Use rtrim()

$str = rtrim($str, ',');
like image 81
flowfree Avatar answered Oct 10 '22 14:10

flowfree