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"
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.
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!
To remove the last three characters from a string, we can use the substr() function by passing the start and length as arguments.
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.
Use rtrim()
$str = rtrim($str, ',');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With