开发者

Warning: DOMXPath::evaluate() [domxpath.evaluate]: Invalid expression

开发者 https://www.devze.com 2023-02-15 09:01 出处:网络
When my $keyword input string in the function below contains double quotes... \'this is a \"test\" for example\'

When my $keyword input string in the function below contains double quotes...

'this is a "test" for example'

I'm getting this error:

Warning: DOMXPath::evaluate() [domxpath.evaluate]: Invalid expression

It occurs on the line just below the on开发者_运维问答e commented below "ERROR OCCURS" on the xpath->evaluate method.

function my_function($heading, $post){
    $content = $post->post_content;
    if($content=="" || !class_exists('DOMDocument')) return false;
    $keyword = trim(strtolower(my_getKeyword($post)));
    @$dom = new DOMDocument;
    @$dom->loadHTML(strtolower($post->post_content));
    $xPath = new DOMXPath(@$dom);
    switch ($heading)
        {//ERROR OCCURS
        case "img-alt": return $xPath->evaluate('boolean(//img[contains(@alt, "'.$keyword.'")])');
        default: return $xPath->evaluate('boolean(/html/body//'.$heading.'[contains(.,"'.$keyword.'")])');
        }
}


function my_getKeyword($post)
{
    $myKeyword = get_post_meta($post->ID, '_my_keyword', true);

    if($myKeyword == "") $myKeyword = $post->post_title;

    return " ".$myKeyword;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消