To remove the first character of a string in PHP, the code is as follows−
Example
<?php $str = "Test"; echo "Before removing the first character = ".$str; $res = substr($str, 1); echo "\nAfter removing the first character = ".$res; ?>
Output
This will produce the following output −
Before removing the first character = Test After removing the first character = est
Example
Let us now see another example
<?php $str = "Demo"; echo "Before removing the first character = ".$str; $res = ltrim($str, 'D'); echo "\nAfter removing the first character = ".$res; ?>
Output
This will produce the following output−
Before removing the first character = Demo After removing the first character = emo