views:

229

answers:

1

Hi i use zend_dom. 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.

+2  A: 

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"]');
Mark