Lienne Posted April 4, 2006 Share Posted April 4, 2006 Like the topic says, I have a string of variable lengths, and I want to find out what the last two characters are. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/6578-get-last-two-chars-of-a-string/ Share on other sites More sharing options...
djnrempel Posted April 4, 2006 Share Posted April 4, 2006 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] Link to comment https://forums.phpfreaks.com/topic/6578-get-last-two-chars-of-a-string/#findComment-23859 Share on other sites More sharing options...
Lienne Posted April 4, 2006 Author Share Posted April 4, 2006 ooh, ingenius. so Instead of using a positive number to move to the right, we us a negative to move to the left (which is the end). Great! Thank you very much! Link to comment https://forums.phpfreaks.com/topic/6578-get-last-two-chars-of-a-string/#findComment-23864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.