paulferree Posted July 31, 2008 Share Posted July 31, 2008 I'm trying to remove anything that isn't a number,letter, or underscore from a string. I think I have my syntax wrong...this replacement code worked in ColdFusion, what is the correct way to write this in php? Here is what I have (that isn't working): preg_replace("[^0-9a-zA-Z_]", "", $the_variable); Thanks! Paul Link to comment https://forums.phpfreaks.com/topic/117585-replacing-multiple-characters-in-a-string-with-preg_replace/ Share on other sites More sharing options...
discomatt Posted July 31, 2008 Share Posted July 31, 2008 Close $this_var = preg_replace("/[^0-9a-zA-Z_]/", "", $the_variable); Or easier $this_var = preg_replace("/[^0-9a-z_]/i", "", $the_variable); The 'i' switch forces a case-insensitive search. Link to comment https://forums.phpfreaks.com/topic/117585-replacing-multiple-characters-in-a-string-with-preg_replace/#findComment-604818 Share on other sites More sharing options...
paulferree Posted July 31, 2008 Author Share Posted July 31, 2008 Perfect! thanks for the help. Paul Link to comment https://forums.phpfreaks.com/topic/117585-replacing-multiple-characters-in-a-string-with-preg_replace/#findComment-604932 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.