开发者

Zend Framework dom problem

I want to get website shortcut icon(favicon) and stylesheet path with zend_dom query

$dom = new Zend_Dom_Query($html); 
$stylesheet = $dom->query('link[rel="stylesheet"]');
$shortcut = $dom->query('link[rel="shortcut icon"]');
开发者_如何学编程

Stylesheet query is work but shortcut icon query not work. How i do?

Thanks.


This appears to be an issue with Zend's css style query implementation. In Zend/Dom/Query.php, the query function calls a conversion function to convert the query into proper xpath format:

public function query($query)
{
    $xpathQuery = Zend_Dom_Query_Css2Xpath::transform($query);
    return $this->queryXpath($xpathQuery, $query);
}

However within the transform() method, they seem to be using some pretty basic regex to split up the string by spaces:

$segments = preg_split('/\s+/', $path);

Which basically means your link[rel="shortcut icon"] query now becomes two queries: link[rel="shortcut and icon"]

To get around this, you can use the method Zend_Dom_Query::queryXpath() and provide it with a proper xPath query. Like this:

$dom->queryXpath('//link[@rel="shortcut icon"]');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜