Remove the very first character of a given string in PHP
Examples:
Input : Geeksforgeeks Output : eeksforgeeks Input :, Hello geek! Output : Hello geek!
Explanation:
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.
Example:
<?php $str = "geeks"; // Or we can write ltrim($str, $str[0]); $str = ltrim($str, 'g'); echo $str; ?> |
eeks
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.
<?php $str = "geeks"; $str1 = substr($str, 1); echo $str1."\n"; $str1 = substr($str, 2); echo $str1; ?> |
eeks eks
Recommended Posts:
- How to remove portion of a string after a certain character in PHP?
- How to Remove Special Character from String in PHP ?
- Replace every character of string by character whose ASCII value is K times more than it
- How to remove a character from string in JavaScript ?
- Delete first character of a string in JavaScript
- Python program to capitalize the first and last character of each word in a string
- Removing occurrences of a specific character from end of a string in PHP
- Remove new lines from string in PHP
- How to remove extension from string in PHP?
- How to remove line breaks from the string in PHP?
- How to remove all non-printable characters in a string in PHP?
- How to remove all leading zeros in a string in PHP ?
- How to remove control characters from PHP string ?
- How to remove all white spaces from a string in PHP ?
- How to remove white spaces only beginning/end of a string using PHP ?
- Queries to find the last non-repeating character in the sub-string of a given string
- Remove first node of the linked list
- Remove characters from a numeric string such that string becomes divisible by 8
- Difference between :first-child and :first-of-type selector in CSS
- How to merge the first index of an array with the first index of second array?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

