Is there a way to limit exactly what ltrim removes in PHP.
I had a the following outcome:
$str = \"axxMyString\";
$newStr = ltrim($str, \"ax\");
// resu
I think the confusion has come in because ltrim receives a list of characters to remove, not a string. Your code removes all occurrences of a
or x
not the string ax
. So axxxaxxaMyString
becomes MyString
and axxaiaxxaMyString
becomes iaxxaMyString
.
If you know how many characters you need to remove, you can use substr()
otherwise for more complicated patterns, you can use regular expressions via preg_replace()
.