NYCPHP Meetup

[nycphp-talk] rtrim broken?

Dell Sala dell at sala.ca
Tue Oct 31 20:49:53 EST 2006


Are you reassigning the result to $text? The first argument is not  
passed by reference -- instead, it returns the trimmed string.

$text = rtrim($text, ', ');
echo $text;

BTW: if this string is build by a loop, there is another idiom that I  
find cleaner than stripping off the last separator: Build text as an  
array, then implode it.

$text = array();
foreach (range(0, 2) as $i) {
    $text[] = 'blah';
}
$text = implode(', ', $text);


-- Dell


On Oct 31, 2006, at 8:33 PM, David Krings wrote:

> Hi,
>
> I have a string that looks like this
> $text = 'blah, blah, blah, ';
> I want to use rtrim to cut off the last comma and the whitespace.  
> So I use
> rtrim($text, ', ');
>
> To my surprise, it doesn't cut anything off. When I echo $text the  
> comma
> and the space are still there.
>
> Is rtrim broken or my logic or my script?
>
> David K.
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php




More information about the talk mailing list