JustinK101 Posted January 12, 2009 Share Posted January 12, 2009 How do I strip everything except a-z, A-Z, 0-9 and spaces from a string. I know I need to use regular expressions, but not sure about the details. Thanks. Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 What details? Google numbers and characters php regex A tutorial http://www.jellyandcustard.com/2006/06/13/regular-expressions-in-php/ and cheat sheet http://www.webcheatsheet.com/php/regular_expressions.php Should point you in the correct direction Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/#findComment-735659 Share on other sites More sharing options...
JustinK101 Posted January 12, 2009 Author Share Posted January 12, 2009 Here is what I have, not sure it is correct. How do I handle spaces? $customer_name = preg_replace("^[a-zA-Z0-9]", '', $customer_name); Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/#findComment-735664 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Just a space should do(i assume), although you can use str_replace before hand to remove spaces Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/#findComment-735671 Share on other sites More sharing options...
killah Posted January 12, 2009 Share Posted January 12, 2009 $customer_name = preg_replace("^[a-zA-Z0-9 ]", '', $customer_name); that there should work for space's i believe. Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/#findComment-735674 Share on other sites More sharing options...
JustinK101 Posted January 12, 2009 Author Share Posted January 12, 2009 Does the ^ go inside the opening bracker or outside? For example, is it: ^[a-zA-Z0-9 ] [^a-zA-Z0-9 ] Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/#findComment-735676 Share on other sites More sharing options...
Mark Baker Posted January 12, 2009 Share Posted January 12, 2009 Does the ^ go inside the opening bracker or outside?Outside Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/#findComment-735677 Share on other sites More sharing options...
DarkWater Posted January 13, 2009 Share Posted January 13, 2009 Umm, it goes inside actually. =/ He wants a negative character class... Link to comment https://forums.phpfreaks.com/topic/140578-strip-everything-out-of-a-string-except-a-z-a-z-0-9-and-spaces/#findComment-735859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.