Jump to content

Get last two chars of a string


Lienne

Recommended Posts

the function you want is substr (for substring).

Here is how you would use it to find the last 2 characters of a string:

$string="abcdef";
$rest = substr($string, -2); // returns "ef"

the "-2" means it will take a substring starting from 2 characters before the end, and since no end parameter is given, it takes the whole rest of the string. For more on this function, check [a href=\"http://ca.php.net/substr\" target=\"_blank\"]http://ca.php.net/substr[/a]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.