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:
 $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

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?