Jump to content

Some help


fxuser

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/227523-some-help/
Share on other sites

$string = "the: % string: < with: \ and: _";
$search = array( '%' , '<' , '\\', '_');
$replace = array(' ', ' ', ' ', ' ');
$new_str = str_replace($search, $replace, $string);
echo $new_str;

Returns: the: string: with: and:

Link to comment
https://forums.phpfreaks.com/topic/227523-some-help/#findComment-1173643
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/227523-some-help/#findComment-1173751
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.