Fatal error: Call to undefined function filter_var() in php script
Fatal error: Call to undefined function filter_var() in a php file
This php error is outputed because your PHP installation does not have the filter extension loaded.
On my setup, I have PHP 5.2 installed from sources and the filter
module was not built at the same time with php (reading the internet, seems that php 5.2.X doesn't install it automatically).
Sometimes, using the pecl installer is not an option. This could be because you're behind a firewall, or it could be because the extension you want to install is not available as a PECL compatible package, such as unreleased extensions from SVN. If you need to build such an extension, you can use the lower-level build tools to perform the build manually.
The phpize command is used to prepare the build environment for a PHP extension. In the following sample, the sources for an extension are in a directory named filter
So, go to to php extension source and to filter module's directory:
# sudo cd /usr/src/php-5.2.10/ext/filter
# sudo /opt/php-5.2.x/bin/phpize
# sudo ./configure --with-php-config=/opt/php-5.2.x/bin/php-config
# sudo make
# sudo make install
The above commands will:
2) phpize will prepare the php build environment for the filter php extension
3) configure the source code and create the necessary files for compiling (Makefile) with the path of the php-config binary
5) install the filter extension to php extension's directory.
Now, check the the filter.so
file is where all the other php extensions are, and edit your php.ini
file, go to Extensions
section, and add the line:
Then, gracefully (or not), restart your apache and test with a webpage calling a filter
function, or call your php binary with the '-m' argument:
# sudo php -m | grep -i filter