I need to remove an unwanted last character from a PHP string variable? How can I do this?
If your original string is "a,b,c,d,e,"
substr("a,b,c,d,e,", 0, -1);
will remove the last comma.
$str = "a,b,c,d,e,"; echo substr($str,0, strlen($str) - 1);
PHP Programming Books
substr($str,0,strlen($str)-1)
string substr ( string $string , int $start [, int $length ] )
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
If your original string is "a,b,c,d,e,"
substr("a,b,c,d,e,", 0, -1);
will remove the last comma.
$str = "a,b,c,d,e,";
echo substr($str,0, strlen($str) - 1);
PHP Programming Books
substr($str,0,strlen($str)-1)
string substr ( string $string , int $start [, int $length ] )