解析错误:语法错误,意外'']?)(“'(T_CONSTANT_ENCAPSED_STRING)

时间:2017-04-16 19:51:45

标签: php wordpress

我尝试使用此建议修复WordML后端的WPML插件错误:https://wpml.org/errata/product-variations-not-display-variation-original-language/

它没有用,现在我收到了这个错误:

  

解析错误:语法错误,意外'']?)(“'   (T_CONSTANT_ENCAPSED_STRING)in   /home/sweetcelebration.nl/public_html/sweetcelebration.nl/wp-includes/functions.php   在第527行

我将代码粘贴在functions.php的开头,并在不起作用时将其删除。我没有碰到这部分代码,所以我不确定为什么现在这样。

function wp_extract_urls( $content ) {
    preg_match_all(
        "#(["']?)("
            . "(?:([w-]+:)?//?)"
            . "[^s()<>]+"
            . "[.]"
            . "(?:"
                . "([wd]+)|"
                . "(?:"
                    . "[^`!()[]{};:'".,<>«»“”‘’s]|"
                    . "(?:[:]d+)?/?"
                . ")+"
            . ")"
        . ")1#",
        $content,
        $post_links
    );

    $post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) );
    return array_values( $post_links );
}

第527行是

  

。 “[^`()[] {} ;:!'”,&LT;&GT;«»‘’'的] |“

如果这是一个愚蠢的问题,我很抱歉。我确实读过之前提出的其他类似问题,但没有找到答案。我真的希望有人可以帮助我。提前谢谢!

2 个答案:

答案 0 :(得分:1)

你应该用反斜杠转义所有"个字符(正则表达式本身的一部分):

"#(["']?)("

变为

"#([\"']?)("

. "[^`!()[]{};:'".,<>«»“”‘’s]|"

变为:

. "[^`!()[]{};:'\".,<>«»“”‘’s]|"

这应解决它:

preg_match_all(
    "#([\"']?)("
        . "(?:([w-]+:)?//?)"
        . "[^s()<>]+"
        . "[.]"
        . "(?:"
            . "([wd]+)|"
            . "(?:"
                . "[^`!()[]{};:'\".,<>«»“”‘’s]|"
                . "(?:[:]d+)?/?"
            . ")+"
        . ")"
    . ")1#",
    $content,
    $post_links
);

答案 1 :(得分:0)

插页式广告&#34;该行中的标记需要转义。 E.g:

. "[^`!()[]{};:'\".,<>«»“”‘’s]|"
相关问题