Write a PHP program to get last n characters of a given string.
Input : $str = "GeeksforGeeks!" $n = 6 Output : Geeks! Input : $str = "GeeksforGeeks!" $n = 9 Output : forGeeks!
Method 1: Tn this method, traverse the last N characters of the string and keep appending them in a new string.
Method 2: Another way to do this use inbuilt library function substr with parameters as the name of the string.
Note: In above example, $start can also take -N to create a sub-string of last n characters
- How to get last day of a month from date in PHP ?
- Last-child and last-of-type selector in SASS
- Count substrings with same first and last characters
- Get first and last elements from ArrayList in Java
- How to get ID of the last updated row in MySQL?
- How to Get First and Last Element of Slice in Golang?
- PHP program to find the length of the last word in string
- Queries to find the last non-repeating character in the sub-string of a given string
- Replace minimal number of characters to make all characters pair wise distinct
- PHP | Get PHP configuration information using phpinfo()
- PHP | Different characters in the given string
- How to remove all non-printable characters in a string in PHP?
- How to remove control characters from PHP string ?
- How to find number of characters in a string in PHP ?
- How to get parameters from a URL string in PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.