From the manual on ltrim()
(emphasis mine):
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. With ..
you can specify a range of characters.
That means that you list a set of characters to be removed, not a word/string. Here's an example.
$str = "foo";
echo ltrim($str, "for"); // Removes everything, because it encounters an F, then two O, outputs ""
echo ltrim($str, "f"); // Removes F only, outputs "oo"
echo ltrim($str, "o"); // Removes nothing, outputs "foo"
That means that any character listed in the character mask would be removed. Instead, you can remove the beginning of the string by str_replace()
, by replacing http://localhost
with an empty string.
$str = 'http://localhost/contact.html';
echo $str . "<br>";
echo str_replace('http://localhost', '', $str);