我在下面的字符串中有一串链接
<link type="image/png" href="http://infinitewp.com/wp-content/themes/mystile-child/images/favicon.png" />
<link rel="shortcut icon" type="image/png" href="http://infinitewp.com/wp-content/themes/mystile-child/images/favicon.png" />
<link type="image/png" href="http://infinitewp.com/wp-content/themes/mystile-child/images/favicon.png" />
我需要获得href
哪个链接有rel="shortcut icon"
我可以使用
strpos($content,"shortcut icon")
此代码,但我需要获取此链接的href?如何以简单的方式做到这一点?
答案 0 :(得分:0)
试试这个:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "Your URL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec ($ch);
curl_close($ch);
$xml = new DOMDocument();
$xml->strictErrorChecking = FALSE;
$xml->loadHTML($html);
$xpath = new DOMXPath($xml);
$arr = $xpath->query('//link[@rel="shortcut icon"]');
echo $arr[0]['href']; // This is the content of your href.