我怎么在那里使用preg_replace_callback?

时间:2015-05-03 19:01:25

标签: php preg-replace preg-replace-callback

我使用一个论坛脚本。它适用于php5.4中的下面脚本。但是,如下图所示,出现php5.5问题。 error http://oi60.tinypic.com/k0hyfq.jpg

可在此处找到全尺寸图片:http://oi60.tinypic.com/k0hyfq.jpg

代码:

// replace RE: RE: RE: by RE[3]:
$this->subject = preg_replace('/(^RE: RE\[)(\d+)(?=\]:)/ie', '"RE[".(\\2+1)', $this->subject);
$this->subject = preg_replace('/^(RE: RE:(?: RE:)+)/ie', '"RE[".substr_count("\\1", "RE:")."]:"', $this->subject);

1 个答案:

答案 0 :(得分:0)

我们已按如下方式更改了代码。目前没有问题

代码:

$tempSubject = $this->subject;
                    $tempSubject = preg_replace_callback('/(^RE: RE\[)(\d+)(?=\]:)/i', function($match) {
                        return "RE[".$match[2];
                        }, $tempSubject);           
                    $tempSubject = preg_replace_callback('/^(RE: RE:(?: RE:)+)/i', function($match) {
                        return "RE[".substr_count($match[1], "RE:")."]:";
                        }, $tempSubject);

                    $this->subject = $tempSubject;