jeffkas Posted January 25, 2011 Share Posted January 25, 2011 I'm trying to remove a dash at the end of a title, for the times when a dash appears there (which isn't always). Since my titles are always different lengths, I don't think substr will work. How can I code the following... If $title ends with '-', replace with '' Thanks! Link to comment https://forums.phpfreaks.com/topic/225647-removing-a-dash-from-the-end-of-title/ Share on other sites More sharing options...
AbraCadaver Posted January 25, 2011 Share Posted January 25, 2011 rtrim() Link to comment https://forums.phpfreaks.com/topic/225647-removing-a-dash-from-the-end-of-title/#findComment-1165070 Share on other sites More sharing options...
PaulRyan Posted January 25, 2011 Share Posted January 25, 2011 <?PHP $string = 'sdfsdfsfsdfdfjkdb adfk ahif-fff-'; $string = $string[strlen($string)-1] == '-' ? substr($string,0,-1) : $string; echo $string; ?> Try the above out, works for me Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/225647-removing-a-dash-from-the-end-of-title/#findComment-1165076 Share on other sites More sharing options...
BlueSkyIS Posted January 25, 2011 Share Posted January 25, 2011 rtrim() $string = rtrim($string, '-'); http://php.net/manual/en/function.rtrim.php Link to comment https://forums.phpfreaks.com/topic/225647-removing-a-dash-from-the-end-of-title/#findComment-1165080 Share on other sites More sharing options...
PaulRyan Posted January 25, 2011 Share Posted January 25, 2011 My bad, didn't see above post from mine. Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/225647-removing-a-dash-from-the-end-of-title/#findComment-1165084 Share on other sites More sharing options...
jeffkas Posted January 25, 2011 Author Share Posted January 25, 2011 Thanks to you all! Link to comment https://forums.phpfreaks.com/topic/225647-removing-a-dash-from-the-end-of-title/#findComment-1165097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.