PHP FILTER_SANITIZE_STRING Filter
What is FILTER_SANITIZE_STRING in PHP?
Explanation
PHP FILTER_SANITIZE_STRING is used to strip or encode or remove unwanted special characters from a string.
Name: "string"
ID-number: 513
Options :
| FILTER_FLAG_NO_ENCODE_QUOTES | This flag does not encode quotes |
| FILTER_FLAG_STRIP_LOW | Strip characters with ASCII value below 32 |
| FILTER_FLAG_STRIP_HIGH | Strip characters with ASCII value above 127 |
| FILTER_FLAG_ENCODE_LOW | Encode characters with ASCII value below 32 |
| FILTER_FLAG_ENCODE_HIGH | Encode characters with ASCII value above 127 |
| FILTER_FLAG_ENCODE_AMP | Encode the & character to & |
Example :
<?php
$var="<b>We welcome you to Hscripts.com<b>";
echo filter_var($var, FILTER_SANITIZE_STRING);
?>
Result :
We Welcome You To Hscripts.com
In the above example, the unwanted special characters <b> is removed from the given string.