Get the last "X" characters of a PHP string?


This will show you how get some character length form ending of php string.


Use substr() with a negative number for the 2nd argument.

<?php

$mystring = "abcdefgh123";

//Get last 5 characters
$string = substr($mystring, -5);

//Output will like 'gh123'


//Get last 10 characters from string
$string = substr($mystring, -10);

//Output will like 'bcdefgh123'

?>
Share on Google Plus

About srimaster

Tech Dropper is simple, easy and newest technology source with experiments and demos. I will give you tutorials, notes, code snippets, demos using PHP, MySQL, jQuery, HTML, CSS, Ajax and Javascripts.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment