Why does ltrim removes one character when the second argument contains an operator sign?

  • A+
Category:Languages

If I do:

ltrim('53-34567', '53-'); ltrim('53+34567', '53+'); ltrim('53*34567', '53*'); 

I get the 4567 result and not 34567. What's the explanation for this behavior?


The second argument of ltrim() is as follows

character_mask
You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want to be stripped.

It's used to specify which characters to trim, yours include 3. If you know what you want to extract, you can use other string functions.

As to why the other 5 is then not removed, see this comment: http://php.net/manual/en/function.ltrim.php#118221

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: