How Can I Get the Last Character of a String in PHP?

Hello friends Today, through this tutorial, I will tell you how to get the last character from the any string by php. So let’s go.

Extract Last character from String Using PHP, Fetch Last Character from String by PHP Program

It is very easy to get his last character from string via php. You are given below in a very easy way. You can get the last character of string by adding this code to your file.


$string = 'This is a string';
$lastCharacter = substr($string, -1);
echo "The last character of the string is $lastCharacter.";