JustinK101 Posted January 17, 2009 Share Posted January 17, 2009 I am trying to remove everything from a string EXCEPT a-z, A-Z, 0-9. This includes removing white space. Here is the code I am using: $customer_name_test = "Justin's Test, Company"; $customer_name_test = preg_replace("[^a-zA-Z0-9 ]", '', $customer_name_test); //Should Return JustinsTestCompany, but is returning Justin's Test, Company echo $customer_name_test; Link to comment https://forums.phpfreaks.com/topic/141155-solved-preg_replace-not-working-as-desired/ Share on other sites More sharing options...
corbin Posted January 17, 2009 Share Posted January 17, 2009 Try preg_replace('/[^a-zA-Z0-9]/', '', $blah). You need delimiters. Link to comment https://forums.phpfreaks.com/topic/141155-solved-preg_replace-not-working-as-desired/#findComment-738832 Share on other sites More sharing options...
JustinK101 Posted January 17, 2009 Author Share Posted January 17, 2009 Thanks, that did the trick, thanks corbin. Link to comment https://forums.phpfreaks.com/topic/141155-solved-preg_replace-not-working-as-desired/#findComment-738837 Share on other sites More sharing options...
corbin Posted January 17, 2009 Share Posted January 17, 2009 No prob. Link to comment https://forums.phpfreaks.com/topic/141155-solved-preg_replace-not-working-as-desired/#findComment-738840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.