I'm trying to find out how to use xpath wildcard to get the favicon :
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML(file_get_contents($url));
$xml = simplexml_import_dom($doc);
Here, i'm testing both "shortcut icon" and "icon" (using a ternary operator) :
$query = $xml->xpath('//link[@rel="shortcut icon"]');
$arr = (empty($query) ? $xml->xpath('//link[@rel="icon"]') : $query);
$favicon = $arr[0]['href'];
It works, but it's not very elegant ; Is there a wildcard (*
) method to to get both "shortcut icon" and "icon" in one go?