1

I've seen a solution for not having to rework usage of the ereg function for PHP 5.3: Good alternative to eregi() in PHP

It uses if(!function_exists....

Is there a function that can be used in this way for ereg_replace?

ereg_replace("<!--.*-->","",$str);

ereg_replace("[^a-z,A-Z]", "", $str);
Community
  • 1
  • 1
  • Btw the first example is meant to display as ereg_replace("","",$str); –  Sep 15 '09 at 18:26

2 Answers2

12

Use the PCRE function preg_replace instead:

preg_replace("/<!--.*-->/", "", $str);
preg_replace("/[^a-z,A-Z]/", "", $str);

POSIX ERE is (nearly) a complete subset of PCRE. So you can use (nearly) any POSIX ERE regular expression with a PREG implementation. See the Regular Expression Flavor Comparison for futher details.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
0

This line is now raising an exception, I suspect my web host has upgrade it's PHP installation.

$vq = ereg_replace('[[:space:]]+', ' ', trim($vq));

If I just switch to preg_replace it complains about the trailing +

I was hoping for a quick fix, this was from an example I think from IBM.

Muskie
  • 577
  • 3
  • 21
  • This looks like another question to me (and thus shouldn't be an answer), but... preg_... and ereg_... usage differs in that the preg_ functions want a delimiter wrapped around the regular expression. We often use '/' but it doesn't have to be that. (See the way the expressions in Gumbo's answer differ from the originals in the question.) – grossvogel Jan 30 '12 at 01:10