Jump to content

small Sanitize question


fortnox007

Recommended Posts

Hi all,

 

I just stumbled upon the 'new' filter function of php and i was wondering if someone could maybe recommend me which to use.

 

for instance if i have a script:

<?php
        $_evilstring = "<script> alert('justin bieber is ruining your sound system')</script>";

        $_clean1 = htmlspecialchars($_evilstring);
        echo 'clean string one = '.$_clean1.'<br />';
        $_clean2 = filter_var($_evilstring, FILTER_SANITIZE_SPECIAL_CHARS);
        echo 'clean string two = '.$_clean2.'<br />';
        ?>

Both output exactly the same. Now i was wondering if there might be differences in them. For some reason I would like to use the filter function because the name sounds better, but that of course is not very scientific. Anyone with ideas maybe performance, speed, wickedness??

 

Link to comment
Share on other sites

Have you read the manual for both?  It appears that they act the same for printable characters, but that call to filter_var() will also do this: "and characters with ASCII value less than 32, optionally strip or encode other special characters."  The "optionally" part is controlled by additional flags.

Link to comment
Share on other sites

Have you read the manual for both?  It appears that they act the same for printable characters, but that call to filter_var() will also do this: "and characters with ASCII value less than 32, optionally strip or encode other special characters."  The "optionally" part is controlled by additional flags.

 

Yeah i have read the manual, that's where i discovered this. But i thought without using the optional part they would be pretty much the same, but it seems i missed the word 'and'

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.