Re: New Member: PHP 4 bug? Solved!
| From: | Ernst de Moor | Date: | Tue, 12 Sep 2000 12:54:53 +0000 |
| Subject: | Re: New Member: PHP 4 bug? Solved! | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16343@lists.php.net to get a copy of this message | ||
Thanks for the mails on this subject!
First responses to the reactions, then the solution to the problem:
I wrote:
> > I developed a small program that works fine at the development server, but not at the
> > production server. Specifically the
statement:
> > ereg_replace("\W", "_", $id); seems to be not processed at all
> > (meaning: replace all non alphanumeric characters by an
underscore).
> > Other ereg_replace calls are processed correctly on both servers.
Maxim wrote:
> I had the same thing, when I tried to use Perl RegExpressions it often
> didn't work in PHP(4)
> Pls. Tell me if you'll find out the answers like what to use instead if it's
> not allowed at all..
I found the reason. See below. You should be able to use preg functions instead of ereg functions
(at least it works for me).
Marc wrote:
> Are you sure the Perl library has been compiled into PHP when building 4.0.1
> pl2? Also check if php.ini configurations are identical.
Thanks. This seems to be the reason it doesn't work. I wrongly assumed that the Reg-exp library
was compiled in, as a lot of regular
expressions _did_ work. But obviously you need the Reg-exp library for the remaining regular
expressions.
Teodor wrote:
> is ereg_replace() acting global by default?
> try preg_replace ('/\W/g','_',$id).
Good suggestion, thanks. It gives an message "Warning: Unknown modifier 'g' "
and stops processing. I don't see why!
preg_replace ("/\W/i","_",$id) did work though.
After a lot of testing I found that the ereg_replace call doesn't accept generic character
types on the production server, where it
does accept them on the development server. The difference in functionality is explained by the
following mail I found on the
subject:
----
FROM: jnshah@fetchmail.com
05-Jul-2000 11:23
TO: info@selim-sonos.de
When you compile PHP you can choose to use the bundled Reg-exp library which allows POSIX style
expressions used by nawk and others,
or point it to another library.
More significantly, you can use the Perl style reg-exp (and why not!) by calling the PHP built-in
functions preg_match() etc...
Further information is available in the PHP manual.