FILTER_SANITIZE_ENCODED constant in PHP

PHPProgrammingServer Side Programming

The FILTER_SANITIZE_ENCODED constant encodes special characters.

Flags and Options

  • FILTER_FLAG_STRIP_LOW − Remove characters with ASCII value less than 32

  • FILTER_FLAG_STRIP_HIGH − Remove characters with ASCII value greater than 127

  • FILTER_FLAG_ENCODE_LOW − Encode characters with ASCII value less than 32

  • FILTER_FLAG_ENCODE_HIGH − Encode characters with ASCII value greater than 127

Return

The FILTER_SANITIZE_ENCODED constant does not return anything.

Example

The following is an example that use FILTER_FLAG_ENCODE_HIGH flag to encode characters with ASCII value > 127

Example

 Live Demo

<?php
   $url="wwwÅ.exampleÅ.com";
   $url = filter_var($url, FILTER_SANITIZE_ENCODED, FILTER_FLAG_STRIP_HIGH);
   echo $url;
?>

Output

The following is the output.

www.example.com

Let us see another example.

Example

 Live Demo

<?php
   $url="example.com££";
   $url = filter_var($url, FILTER_SANITIZE_ENCODED, FILTER_FLAG_STRIP_HIGH);
   echo $url;
?>

Output

Here is the output.

example.com
raja
Published on 04-Dec-2018 07:41:21
Advertisements