You can use:

substr ($getstring->string, -4)

Because of (-) it will start form the end of the string and it will take the next 4 characters.

Take care that first() it will return an object and not the string you want.

Answer from Radu on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-get-the-last-n-characters-of-a-php-string
How to get the Last n Characters of a PHP String
March 15, 2026 - <?php $string = "Hello, World!"; $n = 6; // Number of characters to extract from the end $lastNCharacters = substr($string, -$n); echo $lastNCharacters; ?> ... <?php $string = "Programming"; $n = 4; $startPosition = strlen($string) - $n; ...
🌐
ItSolutionstuff
itsolutionstuff.com › post › how-to-get-last-2-characters-of-a-string-in-phpexample.html
How to Get Last 2, 3, 4, 5, 7 Characters of a String in PHP? - ItSolutionstuff.com
May 14, 2024 - Here, I will show you how to get last two characters of a string in php. We will use php get last 4 characters of string. you will learn php get last 3 characters of string.
🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
How to store last 4 characters of a string. - PHP Coding Help - PHP Freaks
January 7, 2008 - Alright I have searched and searched. So here goes ... $number = "123.456.7890" I need to grab "7890". So: $lastfour = "7890" How do I do this? Thanks in advance!
🌐
Delft Stack
delftstack.com › home › howto › php › how to get the last char of a string in php
How to Get the Last Character of a String in PHP | Delft Stack
February 2, 2024 - -1 means the last character of the string. ... The last char of the string is g. A string is an array of chars. We can get the last char of a string by considering it an array of chars. <?php $string = "This is a string"; $lengthOfString = strlen($string); $lastCharPosition = $lengthOfString-1; $lastChar = $string[$lastCharPosition]; echo "The last char of the string is $lastChar."; ?>
🌐
PHP
php.net › manual › en › function.substr.php
PHP: substr - Manual
<?php function py_slice($input, $slice) { $arg = explode(':', $slice); $start = intval($arg[0]); if ($start < 0) { $start += strlen($input); } if (count($arg) === 1) { return substr($input, $start, 1); } if (trim($arg[1]) === '') { return substr($input, $start); } $end = intval($arg[1]); if ($end < 0) { $end += strlen($input); } return substr($input, $start, $end - $start); } print py_slice('abcdefg', '2') . "\n"; print py_slice('abcdefg', '2:4') . "\n"; print py_slice('abcdefg', '2:') . "\n"; print py_slice('abcdefg', ':4') . "\n"; print py_slice('abcdefg', ':-3') . "\n"; print py_slice('abcd
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-get-the-last-character-of-a-string-in-php
How to get the last character of a string in PHP ? - GeeksforGeeks
July 23, 2025 - Using array() Method: In this method, ... of (length-1) is 5 which is the character "t" The length can be found using the PHP strlen() method....
🌐
W3Resource
w3resource.com › php-exercises › php-string-exercise-7.php
PHP String Exercise: Get the last three characters of a string - w3resource
March 31, 2026 - PHP String Exercises, Practice and Solution: Write a PHP script to get the last three characters of a string.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-get-the-last-n-characters-of-a-php-string
How to get the last n characters of a PHP string? - GeeksforGeeks
October 31, 2018 - Method 1: Tn this method, traverse the last N characters of the string and keep appending them in a new string. Example: ... <?php $str = "GeeksforGeeks!"; $n = 6; // Starting index of the string // where the new string begins $start = strlen($str) - $n; // New string $str1 = ''; for ($x = $start; $x < strlen($str); $x++) { // Appending characters to the new string $str1 .= $str[$x]; } // Print new string echo $str1; ?>
🌐
W3Schools
w3schools.com › php › › func_string_substr.asp
PHP substr() Function
The substr() function returns a part of a string. ... <?php echo substr("Hello world",10)."<br>"; echo substr("Hello world",1)."<br>"; echo substr("Hello world",3)."<br>"; echo substr("Hello world",7)."<br>"; echo substr("Hello world",-1)."<br>"; ...
🌐
Reactgo
reactgo.com › home › how to get the last 7 characters of a string in php
How to get the last 7 characters of a string in PHP | Reactgo
August 15, 2022 - Similarly, you can also get last n characters from a string by changing the second argument. $string = "you are learningphp"; $lasttwo = substr($string, -2); echo $lasttwo; ... Getting the length of an array in PHPHow to reverse a string in PHPHow to get a previous year in PHPHow to insert a string in specified position in PHPGet the last 2 digits of a number in PHPHow to uppercase the first letter of a string in PHP
🌐
Laracasts
laracasts.com › discuss › channels › laravel › how-to-get-last-characters-of-string
How to get last characters of string
Hi there, I don't how I can get the last characters of my string. What I am making is a read more button, in the first part it gets the characters from 0 to 100 (works fine), but then in the second part I want all the characters from 100 till the end of the string...