garethhall Posted November 14, 2009 Share Posted November 14, 2009 Hello, If I had a string say <?php $exts = ".jpg,.gif,.psd,"; ?> How would I go about removing the last "," from the string? So I want it to read ".jpg,.gif,.psd"?? Link to comment https://forums.phpfreaks.com/topic/181470-remove-character-from-string/ Share on other sites More sharing options...
PHPFreaksMaster Posted November 14, 2009 Share Posted November 14, 2009 something like this $exts = ".jpg,.gif,.psd,"; echo substr($exts,0,strlen($exts)-1); Link to comment https://forums.phpfreaks.com/topic/181470-remove-character-from-string/#findComment-957276 Share on other sites More sharing options...
alpine Posted November 14, 2009 Share Posted November 14, 2009 or if you need to remove only if "," on the end <?php $string = ".jpg,"; substr($string, -1) == "," ? $string = substr($string, 0, -1) : $string = $string; echo $string; ?> Link to comment https://forums.phpfreaks.com/topic/181470-remove-character-from-string/#findComment-957278 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.