Ltrim|()

why is


$str = "http://";
$Website = $_POST['Website'];
$Trimmed_Website = ltrim($Facebook,$str);

printing
Website = ‘estwebsite’
What happened to the beginning t?
this is after I submit the form (screenshot)

Where is the value of $Facebook set?

This may be crazy, but /t isn’t being interpreted as a tab (whitespace) for some screwed up reason?

Please, show us the result of print_r($Facebook) before and after it is trimmed.

I wouldn’t have thought so; \ maybe.

This would help. :slight_smile:

The difference between these two:


$str = "hffp://";
$Website = 'hffp://testwebsite';
echo ltrim($Website, $str);
echo "<br />--------------------<br />";
$str = "http://";
$Website = 'http://testwebsite';
echo ltrim($Website, $str);

Outputs:


testwebsite
--------------------
estwebsite

Is it again trimming the first ‘t’ from ‘testwebsite’ even after trimming the whole ‘http://’ because ‘t’ exists in the list to trim?

Yeah, I would think so too; I just didn’t want to say so until we knew the contents of $Facebook.

Doesn’t ltrim go through each letter in the first parameter, and remove it if it present in the list of characters in the second parameter?

So, $str isn’t seen as “http://”, it is actually specifying the characters “h”, “t”, “p”, “:”, “/”

http://testwebsite.com, “e” is the first character not in $str, so it stops trimming there

I think it just a typo so OP supposed to use $Website variable instead.

Yes I think so too since the manual itself says characters not the whole string :

Strip whitespace (or other characters) from the beginning of a string

thanks all

So instead, you’ll want to use ltrim() with no second argument, and instead use [URL=“http://www.php.net/manual/en/function.str-replace.php”]str_replace() to replace the http:// with an empty string.

echo str_replace($str, '', ltrim($Website));