PHP FILTER_SANITIZE_ENCODED Filter
Example
Encode special characters in the $url variable:
<?php
$url="https://www.w3schoolsÅÅ.com";
$url = filter_var($url, FILTER_SANITIZE_ENCODED);
echo $url;
?>
Try it Yourself »
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="https://www.w3schoolsÅÅ.com";
$url = filter_var($url, FILTER_SANITIZE_ENCODED, FILTER_FLAG_STRIP_HIGH);
echo $url;
?>
Try it Yourself »
❮ PHP Filter Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.