Skip to content
Related Articles

Related Articles

How to remove the first character of string in PHP?

View Discussion
Improve Article
Save Article
  • Last Updated : 31 Jul, 2021

Remove the very first character of a given string in PHP


Input : Geeksforgeeks
Output : eeksforgeeks

Input :, Hello geek!
Output : Hello geek!

In PHP to remove characters from beginning we can use ltrim but in that we have to define what we want to remove from a string i.e. removing characters are to be known.

    $str = "geeks";
    // Or we can write ltrim($str, $str[0]);
    $str = ltrim($str, 'g');
    echo $str;



If string is not known and we want to remove characters from beginning then we can use substr(). Here we can use it by two parameters one is the string and the other is the index. substr() return string from the second parameter index to the end of the string.

    $str = "geeks";
    $str1 = substr($str, 1);
    echo $str1."\n";
    $str1 = substr($str, 2);
    echo $str1



PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!