onlyican Posted February 21, 2007 Share Posted February 21, 2007 Hey people I thought there was a function out there for this. I have a user input, and I want to remove all special chars, to make it suitable for a file name For example User input is Max's S@urday and then with this function, the output would be maxs surday So it removed the ' and @ Anyone remember this function, if not one out, any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/39477-remove-special-chars/ Share on other sites More sharing options...
ted_chou12 Posted February 21, 2007 Share Posted February 21, 2007 I think you should use preg_replace, but I am not sure what to include for the first part. Ted Quote Link to comment https://forums.phpfreaks.com/topic/39477-remove-special-chars/#findComment-190479 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 There are a few functions that would work, however, you could use preg $newString=preg_replace("/[^a-zA-Z0-9_\s-]+/", "", $string); Quote Link to comment https://forums.phpfreaks.com/topic/39477-remove-special-chars/#findComment-190480 Share on other sites More sharing options...
onlyican Posted February 21, 2007 Author Share Posted February 21, 2007 cheers, preg_replace works Quote Link to comment https://forums.phpfreaks.com/topic/39477-remove-special-chars/#findComment-190546 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.