Jump to content

Stripping Special Characters out of a User Submitted Variable


ArizonaJohn

Recommended Posts

Hello,

 

For the code below, I would like to strip apostrophes, periods, and slashes from the variable $find if the user enters them in.  How can I do that?  I would like to simply delete these characters, and not replace them with an underscore or anything like that.

 

Thanks in advance,

 

John

 

 <div class="searchbox">
  <form action="search.php" method="post">
  <label>Enter Topic:
  <input type="text" name="find" size="55"/>
  <input type="hidden" name="searching" value="yes" />
  <input type="submit" name="search" value="Search" />
  </label>
  </form>
  </div>

Link to comment
Share on other sites

Try using this function

 

function clean_data($data) {

$code_entities_match = array(' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');

$code_entities_replace = array('','','','','','','','','','','','','','','','','','','','','','','','','','');

$clean = str_replace($code_entities_match, $code_entities_replace, $data);

return $clean;
}

// You would use it like follows

$clean_data = clean_data($_POST['find']);

Link to comment
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.