NYCPHP Meetup

NYPHP.org

[nycphp-talk] rtrim broken?

Warren Myers volcimaster at gmail.com
Thu Nov 2 12:26:24 EST 2006


I don't think this does what it looks like

On 11/1/06, David Krings <ramons at gmx.net> wrote:
>
> Hi,
>
>     yes, $text is the string passed to rtrim, which in retrun is
> supposed to overwrite what is in $text previously. Kinda like
> $k = $k++;


$k++ will make k increase by 1. $k=$k++ still only increases $k by one
because ++ is a postffix operator, and the assignment of $k=$k happens
before $k is incremented with ++. $k=$k+1 is equivalent to $k++, but what
you have is an extra assignment for no reason, or at least it looks like it

When k was 5 before this line it will be 6 after.
>
> That string in question is build by a loop, so I may take your advise
> and do it differently. That still doesn't explain why rtrim doesn't work
> as I expect it to.
>
>     David K.
>
> Dell Sala wrote:
> > 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
> >>
> >
> > _______________________________________________
> > 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
> >
> >
> >
>
> _______________________________________________
> 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
>



-- 
http://warrenmyers.com
"God may not play dice with the universe, but something strange is going on
with the prime numbers." --Paul Erdős
"It's not possible. We are the type of people who have everything in our
favor going against us." --Ben Jarhvi, Short Circuit 2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20061102/1d4ae5a9/attachment.html>


More information about the talk mailing list