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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
paulferree Posted July 31, 2008 Author Share Posted July 31, 2008 Perfect! thanks for the help. Paul Quote Link to comment 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.