ereg_replace for PHP 5.3 +?

前端 未结 2 922
别跟我提以往
别跟我提以往 2021-01-16 08:32

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....

相关标签:
2条回答
  • 2021-01-16 09:03

    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.

    0 讨论(0)
  • 2021-01-16 09:20

    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.

    0 讨论(0)
提交回复
热议问题