Get last character in a string using PHP

Similar to how you get the last character in a string using Javascript, you just slice off the last N characters.

$last_character      = substr( $somestring, -1 );
$last_two_characters = substr( $somestring, -2 );

One thought on “Get last character in a string using PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s