EchoFool Posted August 21, 2009 Share Posted August 21, 2009 How do you strip off the last character of a string even if you don't know how long the string is initially? Say i have like 'hey,hey,hey,hey," So i want to rid of the last , symbol.. though there could be many more characters in the string.. whats the best approach ? Link to comment https://forums.phpfreaks.com/topic/171353-solved-strip-last-char-off-string/ Share on other sites More sharing options...
thebadbad Posted August 21, 2009 Share Posted August 21, 2009 $str = substr($str, 0, -1); Link to comment https://forums.phpfreaks.com/topic/171353-solved-strip-last-char-off-string/#findComment-903668 Share on other sites More sharing options...
Aravinthan Posted August 21, 2009 Share Posted August 21, 2009 Try this: $lenght = strlen("hey,hey,hey,hey,"); $start = $length - 1; echo substr("hey,hey,hey,hey,",$start,1); Or try what thebadbad gave you... God I am thinking the hard way today.... -.- Link to comment https://forums.phpfreaks.com/topic/171353-solved-strip-last-char-off-string/#findComment-903669 Share on other sites More sharing options...
EchoFool Posted August 21, 2009 Author Share Posted August 21, 2009 Thanks guys ! Link to comment https://forums.phpfreaks.com/topic/171353-solved-strip-last-char-off-string/#findComment-903670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.