How To Take Away Final Comma From The Goal Of String Inwards Php?
If yous desire to take the comma from the cease of a string, yous tin role diverse tricks. But 1 elementary line a fast 1 on is to role PHP inbuilt constituent rtrim(). The rtrim constituent (and corresponding ltrim() for left trim) is real useful every bit yous tin specify a make of characters to remove.
rtrim() strips whitespace (or other characters) from the cease of a string.
Example:
rtrim() strips whitespace (or other characters) from the cease of a string.
Example:
$string = "Hello, I, am, Anup,"; echo $string = rtrim($string, ','); //it volition take a char if the final char is a comma //output : "Hello, I, Am, Anup";If yous desire to take precisely 1 comma, which may or may non survive there, use:
if (substr($string, -1, 1) == ',') { $string = substr($string, 0, -1); }Sumber http://developer-paradize.blogspot.com
Comments
Post a Comment