PHP ltrim behavior with character list

The second argument to ltrim is a list of characters to remove from the left side of the string.

If you did

<?php
    ltrim('lllliiiiaaaaaatttttt', 'mailto:');
?>

You would get an empty string as the return value.

Try this instead:

<?php
    $email="mailto:[email protected]";
    $fixedEmail = substr($email, 0, 7) == 'mailto:' ? substr($email, 7) : $email;
?>

Leave a Comment