How to get the last character in a string using PHP

Written by Ian Carnaghan · 10 sec read >
  • This can be done by using the substr which will return a part of a string.
  • The sample code below will return the letter f
    $lastChar= substr("abcdef", -1);

    The -1 is negative, the returned string will start at the last character from the end of the string.

Last Updated On March 22, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. Profile

Leave a Reply

Notify of