How to get the last character in a string using PHP

H
  • 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.

About the author

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.

About Author

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.

Follow Me