27 June 2010

"Call to undefined function preg_replace()"

I was trying to run/install a PHP site and I was getting blank pages and found this error in my web server logs: "PHP Fatal error: Call to undefined function preg_replace() in /path/to/file.php" This is not a terribly difficult problem and people with PHP experience are probably already yelling: "PCRE!" at the screen. :) (That stands for Perl Compatible Regular Expressions.") I only write this post because the web search of this error did not give an obvious answer in the first couple of hits.

If you're in FreeBSD, the solution is simple: install the port "devel/php5-pcre" (or "devel/php4-pcre" as appropriate). Do that from the ports tree by changing to the directory "/usr/ports/devel/php5-pcre" and typing "make install" as root. Or, you could just run "pkg_add -r php5-pcre" (as root). If it's already installed, then reinstall it from the ports tree. Then you'll probably have to restart your web server as well.

While I usually try to avoid editorializing, it seems to me like the PCRE extension ought to be part of the standard library in PHP by now! (Does PHP have a standard library? I tend to think in python. :) )


Labels:

1 Comments:

At 22/7/10 04:58, Anonymous Anonymous said...

Indeed /usr/ports/MOVED reports:
devel/php5-pcre|lang/php5|2010-04-09|Bundled in core php

 

Post a Comment

<< Home