waynew Posted June 5, 2009 Share Posted June 5, 2009 How would I go about stripping everything that isn't alphanumeric OR a space? I'm creating URLs and I need the alphanumeric characters and the space characters to stay in place, while everything else gets stripped out. I need the space characters because I'll be turning them into - for a better SEO impact. Quote Link to comment https://forums.phpfreaks.com/topic/161106-stripping-non-alphanumericalspace-characters/ Share on other sites More sharing options...
waynew Posted June 5, 2009 Author Share Posted June 5, 2009 For example, I have this: $new_string = ereg_replace("[^A-Za-z0-9]", "", $string_to_be_stripped ); But how would I go about allowing spaces? Quote Link to comment https://forums.phpfreaks.com/topic/161106-stripping-non-alphanumericalspace-characters/#findComment-850163 Share on other sites More sharing options...
PFMaBiSmAd Posted June 5, 2009 Share Posted June 5, 2009 Just a side note, but the ereg functions are depreciated and as of php5.3 they are not include in the main php core by default. You should be using the preg_ functions. Quote Link to comment https://forums.phpfreaks.com/topic/161106-stripping-non-alphanumericalspace-characters/#findComment-850181 Share on other sites More sharing options...
.josh Posted June 5, 2009 Share Posted June 5, 2009 $new_string = preg_replace('~[^a-z0-9\s]~i', '', $string_to_be_stripped); Quote Link to comment https://forums.phpfreaks.com/topic/161106-stripping-non-alphanumericalspace-characters/#findComment-850233 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.