conker87 Posted July 22, 2009 Share Posted July 22, 2009 I'm looking for a way of removing all punctuation (and everything not letters and numbers), however I'd also like to replace the apostrophe (') and a space with a dash (-). Anyone got any ideas? Link to comment https://forums.phpfreaks.com/topic/166979-str_replace-all-punctuation/ Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 http://www.php.net/manual/en/book.regex.php Link to comment https://forums.phpfreaks.com/topic/166979-str_replace-all-punctuation/#findComment-880361 Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 $string = "This.has,a ;lot! of's pun?tu030ation"; echo foo($string); function foo($string) { $string = preg_replace('/[\'\s]+/', '-', $string); $string = preg_replace('/[^\-a-zA-Z0-9\s]+/', '', $string); return $string; } Link to comment https://forums.phpfreaks.com/topic/166979-str_replace-all-punctuation/#findComment-880515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.