0
我使用xpath在樣式表中更改樣式表<link>
的樣式表href
。PHP XPath更改樣式表
但它根本不起作用。
$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;
是[fopen封裝(http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-:
您還可以
foreach
因爲DOMNodeList implements Traversable
更換for($i...)
url-fopen)啓用來從外部來源獲取內容?爲什麼你用@ -notation壓制錯誤信息?也許有你的答案。 – Mamuz@ mamuz,是的,根據phpinfo它是在 – werva