Remove all unwanterd characters form a URL
Example
======
<?php
$url=”http://www.phpcoåødez.com”;
echo filter_var($url, FILTER_SANITIZE_URL);
?>
Output
=====
http://www.phpcodez.com
Remove all unwanterd characters form a URL
Example
======
<?php
$url=”http://www.phpcoåødez.com”;
echo filter_var($url, FILTER_SANITIZE_URL);
?>
Output
=====
http://www.phpcodez.com
Return TRUE for “true”, “1”, “on” and “yes”, FALSE for “0”,”false”, “off”, “no”, and “”, NULL otherwise
Example
======
<?php
echo filter_var(“Yes”, FILTER_VALIDATE_BOOLEAN);
?>
Output
=====
1
Removes characters that is potentially harmful for your application
Example
======
<?php
echo filter_var(“PHPCodez'”, FILTER_UNSAFE_RAW);
?>
Output
=====
PHPCodez’
It adds slashes before quotes
Example
======
<?php
echo filter_var(“PHPCodez'”, FILTER_SANITIZE_MAGIC_QUOTES);
?>
Output
=====
PHPCodez’
Remove all illegal characters from a float number
Example
======
<?php
echo filter_var(“1-7php+5.4Codez”, FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
?>
Output
=====
1-7+5.4
Possible flags:
FILTER_FLAG_ALLOW_SCIENTIFIC – Separate fraction with e and E)
FILTER_FLAG_ALLOW_FRACTION – Separate fraction with “.”
FILTER_FLAG_ALLOW_THOUSAND – Separate fraction with “,”
Remove all illegal ineteger characters
Example
======
<?php
echo filter_var(“1php-7+Codez”, FILTER_SANITIZE_NUMBER_INT);
?>
Output
=====
1-7+
Remove all illegal email characters
Example
======
<?php
echo filter_var(“info()@phpcodez.com”, FILTER_SANITIZE_EMAIL);
?>
Output
=====
info@phpcodez.com
Encode special characters
Example
======
<?php
print_r(filter_var(“http://www.phpcodez.com”,FILTER_SANITIZE_ENCODED));
?>
Output
=====
http%3A%2F%2Fwww.phpcodez.com
Strips or encodes unwanted characters .
Example
======
<?php
print_r(filter_var(“<b>PHP Codez<b>”, FILTER_SANITIZE_STRIPPED));
?>
Output
=====
PHP Codez
Strip tags and encode special characters.
Example
======
<?php
print_r(htmlentities(filter_var(“<font>PHPCodez<font>”, FILTER_SANITIZE_STRING)));
?>
Output
=====
PHPCodez