fxuser Posted February 13, 2011 Share Posted February 13, 2011 Hello, i have a mysql query using LIKE .. so what i saw is that when i type % , < , \ , _ i can easily show all the results of the query.. what i want to do is when i type these in the input to replace them with "" so what i have tried is : $bad_symbols = array("/%/", "/_/", "/</"); $newvar = preg_replace($bad_symbols, " ", $to); but just the first two seem to work , also how can i add the "\" in the array? thanks Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted February 13, 2011 Share Posted February 13, 2011 Someone with more experience may have another idea but can you use something like str_replace before you enter the variables into the query? Quote Link to comment Share on other sites More sharing options...
fxuser Posted February 13, 2011 Author Share Posted February 13, 2011 Someone with more experience may have another idea but can you use something like str_replace before you enter the variables into the query? i have tried it but i get the same problem the "<" doesnt get replaced with " " and i cant put inside the array the "\". Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 $string = "the: % string: < with: \ and: _"; $search = array( '%' , '<' , '\\', '_'); $replace = array(' ', ' ', ' ', ' '); $new_str = str_replace($search, $replace, $string); echo $new_str; Returns: the: string: with: and: Quote Link to comment Share on other sites More sharing options...
fxuser Posted February 13, 2011 Author Share Posted February 13, 2011 as i stated in my first post i wanna remove these symbols from the input box when a user types them in due to the LIKE sql query i use but it seems doesnt seem to work for the "<" and "\" .. they dont get replaced when i type them.. weird Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2011 Share Posted February 13, 2011 Are you converting the text using html entities or anything? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 I just tested it and it does indeed work, as evidenced by the string before and after using str_replace on it. Did you bother to try it before deciding it wouldn't work? Quote Link to comment Share on other sites More sharing options...
fxuser Posted February 13, 2011 Author Share Posted February 13, 2011 Are you converting the text using html entities or anything? i had a function that checks for my inputs and it seems it was strip_tags() I just tested it and it does indeed work, as evidenced by the string before and after using str_replace on it. Did you bother to try it before deciding it wouldn't work? i have tried a similar way before your response but i also tried what you posted and it seems the strip_tags() was the problem. 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.