我使用 xpath 来更改标题中样式表href
的样式表。<link>
但它根本不起作用。
$html=file_get_contents('http://stackoverflow.com');
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$css_links = $xpath->evaluate("//link[@type='text/css']");
for ($i = 0; $i < $css_links->length; $i++)
{
$csslink = $css_links->item($i);
$oldurl = $csslink->getAttribute('href');
$newURL='http://example.com/aaaa.css';
$csslink->removeAttribute('href');
$csslink->setAttribute('href', $newURL);
}
echo $html;