2017-06-16 61 views
0

我有这样的代码中的一类:DOMXPath ::查询():无效表达

... 
$document = new DOMDocument('1.0', 'utf-8'); 
$document->preserveWhiteSpace = false; 
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'utf-8'); //this fix problems with cyrilic text 
if ([email protected]$document->loadHtml($content)) 
    return false; 
$xpath = new DOMXpath($document); 
$node_list = $xpath->query($this->target->query_name()); // getting warning here 
... 

QUERY_NAME方法的代码(位于其他类和文件)是:

public function query_name($if_arg_needed = ""){ 
    return "//*/*[@class=\'product_name\']"; 
} 

两个包含我的类的文件在utf-8中。 为什么我得到警告: 警告:DOMXPath ::查询():无效的表达......

此代码工作正常:

... 
$xpath = new DOMXpath($document); 
$tempStr = "//*/*[@class=\'product_name\']"; 
$node_list = $xpath->query($tempStr); 

回答

1

你应该设置的XPath这样的:

$tempStr = "//*[@class='product_name']";

$tempStr = '//*[@class="product_name"]';

OMG!
+0

OMG!那些斜线!我甚至忘记了为什么我把它们放在那里。非常感谢劳达! –