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? Quote 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 Quote 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; } Quote Link to comment https://forums.phpfreaks.com/topic/166979-str_replace-all-punctuation/#findComment-880515 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.