Alexis Alexis - 1 month ago 15
PHP Question

Is there a way to modify FILTER_SANITIZE_STRING

FILTER_SANITIZE_STRING basically does not also allow '.' DOTs. Is there any way to make it allow DOTs too?

Answer

Try this, hope this helps you -

<?php
 $smaller = "dots..";
 echo filter_var ( $smaller, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
?>

You can use FILTER_FLAG_STRIP_LOW too.

From php source:

  • FILTER_SANITIZE_STRING - Strip tags, optionally strip or encode special characters.
  • FILTER_FLAG_STRIP_HIGH - Strip characters with ASCII value above 127.
  • FILTER_FLAG_STRIP_LOW - Strip characters with ASCII value below 32.

Actually from php.net documentation FILTER_SANITIZE_STRING we don't get much information about this. So, we will get information from php source mentioned below:

Php sanitizing filters source

In above file look for php_filter_string