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! Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted January 25, 2011 Share Posted January 25, 2011 rtrim() Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
jeffkas Posted January 25, 2011 Author Share Posted January 25, 2011 Thanks to you all! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.