Problems with preg_replace?


#1

A script that has been running successfully for a few months has suddenly stopped working (just within the last couple days, I believe). It generates the following warning message:

Warning: preg_replace() [function.preg-replace]: Numeric named subpatterns are not allowed in [filename]

Has something changed in Dreamhost’s PHP configuration?

Any help or advice would be greatly appreciated.


#2

[quote]Warning: preg_replace() [function.preg-replace]: Numeric named subpatterns are not allowed in [filename]

Has something changed in Dreamhost’s PHP configuration?[/quote]
That’s built in to the PCRE code for PHP, and its not something that can be switched on or off. But the PHP developers have made some changes to that code in recent versions, so maybe PCRE behaved differently in older versions of PHP.

It boils down to that you can’t do this anymore in patterns: (?P<1>pattern)(?P<2>pattern)

  1. You can’t do that in Perl either
  2. Conflicts with capturing to an associative array (because you get two keys for each value, one key is the position (1, 2, etc) and the other key is the name)

The code should be changed to something like (?Ppattern)(?Ppattern)

:cool: openvein.org -//-


#3

THANK YOU!

That was indeed the problem, and once I knew where to look, I fixed it pretty easily.

I really appreciate your help!