Latest web development tutorials

PHP FILTER_SANITIZE_SPECIAL_CHARS filter

PHP Filter Reference Complete PHP Filter Reference

Definition and Usage

FILTER_SANITIZE_SPECIAL_CHARS filter HTML special characters escaped.

The filter used to escape "<> & and the ASCII value of the character in the value of 32 or less.

  • Name: "special_chars"
  • ID-number: 515

Possible signs:

  • FILTER_FLAG_STRIP_LOW - removal of characters in the ASCII value of 32 or less
  • FILTER_FLAG_STRIP_HIGH - the removal of more than 32 characters in the ASCII value of
  • FILTER_FLAG_ENCODE_HIGH - encoded ASCII value of the character above 32

Examples

<?php
$url="Is Peter <smart> & funny?";

var_dump(filter_var($url,FILTER_SANITIZE_SPECIAL_CHARS));
?>

Browser output of the code above is as follows:

string(37) "Is Peter <smart> & funny?"

If you view the source code in the browser, you will see the following HTML:

string(37) "Is Peter & lt; smart& gt; & amp; funny?"


PHP Filter Reference Complete PHP Filter Reference