Using ltrim is not the right answer sometimes.
In a PHP application I was debugging today for a company I found them using ltrim to remove a substring from the start of a string which was producing weird results such as "tal" after invoking with "Total".
When I asked their programmer why is he using ltrim, he replied to strip out a substring from the start of the string.
His code was:
$clean=ltrim($unclean, "To");
So what's the problem? If a string starts with To such as in "ToTotal" (hypothetically), it incorrectly returns "tal" when the needed result was "Total" with just the first part of To stripped.
I've posted the correct way to strip a substring using regular expressions.
3 Comments:
What is wrong with this statement that it is still giving me spaces after ... Judging from the code, it seems that you may be trying to strip spaces and ...
This comment has been removed by the author.
https://www.programingtutorial.com/phpcontinue.html
Post a Comment
<< Home