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():


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 M. Foster

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

Reply via email to