警告:DOMXPath :: evaluate()[domxpath.evaluate]:表达式无效

时间:2011-03-08 17:33:37

标签: domdocument xpath

当下面函数中的$ keyword输入字符串包含双引号...

  

'这是一个“测试”,例如'

我收到了这个错误:

  

警告:DOMXPath :: evaluate()   [domxpath.evaluate]:无效   表达

它出现在xpath-> evaluate方法下面“ERROR OCCURS”下方注释的行的下方。

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 个答案:

没有答案
相关问题