Re: ltrim behavior.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 11 Mar 2009 15:28:04 -0400
Paul M Foster <paulf@xxxxxxxxxxxxxxxxx> wrote:

> On Wed, Mar 11, 2009 at 03:07:18PM -0400, Peter van der Does wrote:
> 
> > This might be old for some of you but I never encountered it until
> > today and I would like to know why this is happening.
> > 
> > Here's the situation:
> > php > $a='data[options][name]';
> > php > echo ltrim($a,'data[');
> > options][name]
> > 
> > Just as I expected.
> > 
> > Next one:
> > php > $a='options[options][name]';
> > php > echo ltrim($a,'options[');
> > ][name]
> > 
> > UH, what?
> > Not exactly what I expected.
> > 
> > This works:
> > php > $a='options[options][name]';
> > php > echo ltrim(ltrim($a,'options'),'[');
> > options][name]
> > 
> > Can somebody explain the second behavior? Is this a known bug in
> > PHP, I'm running PHP 5.2.6 on Ubuntu.
> 
> Take a look at the documentation for ltrim():
> 
> http://us2.php.net/manual/en/function.ltrim.php
> 
> The string you're including as the second parameter to ltrim() is the
> *characters* you want to trim on, not the *character pattern*. If you
> think about it that way, it will make sense. Also one of the examples
> on the referenced documentation page does something similar to what
> you've cited. Work through that example, and you'll see.
> 
> Paul
> 
OK, the light bulb went on now. I did see it was characters, and not a
string, but for some reason it didn't get in my brain what the
consequence was.
Thanks and I apologize for the "stupid" question.


-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderdoes@xxxxxxxxx

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux