How to get the last 7 characters from a string in PHP
To get the last 7 characters from a PHP string, we can use the substr()
function by passing the first argument as a string and second argument is -7
.
Here is an example
$string = "you are learningphp";
$lastseven = substr($string, -7);
echo $lastseven;
Output:
ningphp
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;