rhyspaterson Posted May 30, 2007 Share Posted May 30, 2007 Hey guys, Been having a look a split and preg_split, and i was just wondering how would would get the last character of a string with no spaces, no matter how long the string is..? I.e - thisismyreallylongstringabc How would we get the last character ('c') ? I mean you could use: preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); but that would put each character into an array which is a bit of overkill if all we want is the last character.. any suggestions? Thanks, /Rhys Link to comment https://forums.phpfreaks.com/topic/53626-solved-splitting/ Share on other sites More sharing options...
rhyspaterson Posted May 30, 2007 Author Share Posted May 30, 2007 Wait. $last = $str[strlen($str)-1]; Bingo Link to comment https://forums.phpfreaks.com/topic/53626-solved-splitting/#findComment-265071 Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 that or www.php.net/substr I think it would be $last = substr($str, -1); Link to comment https://forums.phpfreaks.com/topic/53626-solved-splitting/#findComment-265077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.