Help triming a string
Posted: Sun Jul 20, 2003 7:09 pm
I need to figure out some way to trim of the last , in a string.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$string = 'Space ';
$string = rtrim($string);
//$string = 'Space';
?>Code: Select all
<?php
$text = "one, two, three,";
$text = substr($text, 0, -1);
echo($text);
?>Code: Select all
<?php
$string = 'one , two ,three';
?>Code: Select all
<?php
$text = "one, two, three,";
if(substr(trim($text), 0, -1)==",")
{
$text = substr(trim($text), 0, -1);
}
echo($text);
?>