PHP preg_replace错误wordpress

时间:2013-04-05 03:17:01

标签: php preg-replace

我有以下wordpress代码

function shortcode_parse_atts($text) {
    $atts = array();
    $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
    $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
    if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
        foreach ($match as $m) {
            if (!empty($m[1]))
                $atts[strtolower($m[1])] = stripcslashes($m[2]);
            elseif (!empty($m[3]))
                $atts[strtolower($m[3])] = stripcslashes($m[4]);
            elseif (!empty($m[5]))
                $atts[strtolower($m[5])] = stripcslashes($m[6]);
            elseif (isset($m[7]) and strlen($m[7]))
                $atts[] = stripcslashes($m[7]);
            elseif (isset($m[8]))
                $atts[] = stripcslashes($m[8]);
        }
    } else {
        $atts = ltrim($text);
    }
    return $atts;
}

使用路径执行函数后,出现此错误:

  

警告:preg_replace()[function.preg-replace]:编译失败:在第258行的/PATH/wp-includes/shortcodes.php中设置为偏移-1的未知选项位

第258行标记在这里

$text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); //<--- LINE 258

任何人都可以提供任何帮助吗?

将不胜感激

不能降级php版本......

1 个答案:

答案 0 :(得分:1)

这是因为你的PCRE已经过时了。将PHP更新到5.3版本后,您需要手动更新服务器的PCRE。

在SSH中运行以下代码:

pcretest -C

它会显示您运行它的版本。最后一个版本是8.32。

以下是您应该与每个PHP版本一起使用的PCRE版本的关系: http://php.net/manual/en/pcre.installation.php