Dave Dave - 1 year ago 47
PHP Question

How can I get the last 7 characters of a PHP string?

Possible Duplicate:

PHP - cut a string after X characters

How would I go about grabbing the last 7 characters of the string below?

For example:

$dynamicstring = "2490slkj409slk5409els";
$newstring = some_function($dynamicstring);
echo "The new string is: " . $newstring;

Which would display:

The new string is: 5409els

Answer Source

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

$newstring = substr($dynamicstring, -7);