Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.