Latest web development tutorials
 

PHP FILTER_SANITIZE_ENCODED Filter

< PHP Filter Reference

Example

Encode special characters in the $url variable:

<?php
$url="http://www.w3iiÅÅ.com";

$url = filter_var($url, FILTER_SANITIZE_ENCODED);
echo $url;
?>
Run example »

Definition and Usage

The FILTER_SANITIZE_ENCODED filter removes or encodes special characters.

This filter works a lot like the urlencode() function.

Possible options and flags:

  • FILTER_FLAG_STRIP_LOW - Remove characters with ASCII value < 32
  • FILTER_FLAG_STRIP_HIGH - Remove characters with ASCII value > 127
  • FILTER_FLAG_ENCODE_LOW - Encode characters with ASCII value < 32
  • FILTER_FLAG_ENCODE_HIGH - Encode characters with ASCII value > 127

More Examples

Example 1

Encode special characters, and remove all characters with ASCII value > 127:

<?php
$url="http://www.w3iiÅÅ.com";

$url = filter_var($url, FILTER_SANITIZE_ENCODED, FILTER_FLAG_STRIP_HIGH);
echo $url;
?>
Run example »

< PHP Filter Reference