How to remove the first character of string in PHP?

PHPServer Side ProgrammingProgramming

To remove the first character of a string in PHP, the code is as follows−

Example

 Live Demo

<?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

 Live Demo

<?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
raja
Published on 27-Dec-2019 07:53:32
Advertisements