Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Filter Functions : filter_var

filter_var

Filters a variable with a specified filter (PHP 5 >= 5.2.0, PECL filter:0.11.0)
mixed filter_var ( mixed variable [, int filter [, mixed options]] )

Example 678. A filter_var() example

<?php
var_dump
(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));
var_dump(filter_var('example.com', FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED));
?>

The above example will output:

string(15) "bob@example.com"
bool(false)

Code Examples / Notes » filter_var

john

I managed to get this to work with PHP 5.1.6 on CentOS 5 with minor difficulty.
1) Download the PECL filter package
2) Extract the tarball
3) phpize the directory
4) ./configure
5) make
6) filter-0.11.0/logical_filters.c:25:31: error: ext/pcre/php_pcre.h: No such file or directory
7) find / -name php_pcre.h
8) Make sure php-devel is installed
9) Edit filter-0.11.0/logical_filters.c and replace "ext/pcre/php_pcre.h" with the absolute path of php_pcre.h
10) make
11) make install
12) add "extension=filter.so" to php.ini
13) Restart Apache


menic monkey o2 . pl

I dont know why, but this function doesn't work properly with array as $variable. To make it work I suggest to use foreach, and filter each value in this way.

Change Language


Follow Navioo On Twitter
filter_has_var
filter_id
filter_input_array
filter_input
filter_list
filter_var_array
filter_var
eXTReMe Tracker