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? 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 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); 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 Link to comment https://forums.phpfreaks.com/topic/39477-remove-special-chars/#findComment-190546 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.