Jump to content

Does anyone have experience with Filter()


fortnox007

Recommended Posts

HI all,

 

Yesterday i read quite alot about htmlentities() htmlspecialchars() mysql_real_escape_string

But today i stumbled upon filter()  (http://www.w3schools.com/php/php_filter.asp). Does anyone know if this is also a good way to sanitize and may even be an alternative for the other functions? OR is it something completly different? I am still a novice with this so please enlighten me : )

 

TY ;D

Link to comment
Share on other sites

I think a better question is what EXACTLY are you trying to accomplish. All of the functions you listeed above and the filter functions all have different purposes. If you are saving data to a MySQL database, then use the function built for that: mysql_real_escape_string(). That function will "escape" the data so that it is safe for a DB query - it doesn't change the result of the input.

 

The two html functions do the same thing. They convert/escape specific characters so they will display as intended. For example, if a user entered their name as "<b>Myname</b>" and you do not want user entered HTML code to be parsed you could use one of the two html functions to convert the greaterthan/lessthan characters to specific codes so the name will display as "<b>Myname</b>" instead of Myname

 

The filter functions allow for many different filters. They can remove unwanted values or they may just return false if the value does not pass the filter. See this page to get an idea of the filters available: http://us3.php.net/manual/en/filter.filters.php

 

In other words, all of the functions/filters have a specific purpose. You should pick the appropriate method for each situation. There is not one method that is superior to the others for all situations.

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.