我看到很多关于此的问题,但答案对我不起作用!
我试过了:
$xml = new DomDocument();
$xml->load('sitemap.xml');
$linkforxml = "https://example.com/" . $filename. ".php";
$xpath = new DOMXPATH($xml);
$nodes = $xpath->query('/urlset/url[loc = "'.$linkforxml.'"]');
foreach($nodes as $node){
$node->parentNode->removeChild($node);
}
$xml->save('sitemap.xml');
这是我的站点地图文件中的内容:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://example.com/test.php</loc>
<lastmod>2021-06-21T17:31:16+00:00</lastmod>
</url>
</urlset>
当我运行这段代码时,url 仍然在站点地图文件中,什么也没有发生。 谁能告诉我我的问题在哪里?