更新时间:2022-04-06 17:11:33
使用simplexml
using simplexml
$html = '<link type="text/html" rel="alternate" href="http://link"/>';
$xml = simplexml_load_string($html);
$attr = $xml->attributes();
使用dom
$dom = new DOMDocument;
$dom->loadHTML($html);
$nodes = $dom->getElementsByTagName('link');
$attr = $nodes->item(0)->getAttribute('href');