在<;中添加规范标记;头>;如果不存在,则使用PHP标记
我想要的是在在<;中添加规范标记;头>;如果不存在,则使用PHP标记,php,canonical-link,Php,Canonical Link,我想要的是在标记中添加规范标记,如果使用PHP不存在规范标记 我试过这个,但没用 function addtag(){ $doc = new DOMDocument(); $doc->loadHTMLFile('http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); $body = $doc->getElementsByTagName('head')->item(0);
标记中添加规范标记,如果使用PHP不存在规范标记
我试过这个,但没用
function addtag(){
$doc = new DOMDocument();
$doc->loadHTMLFile('http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
$body = $doc->getElementsByTagName('head')->item(0);
$link = $doc->createElement('link');
$newLink = $body->appendChild($link);
$newLink->setAttribute("canonical", 'http://');
//$linkText = $doc->createTextNode("Display Text For Link");
//$newLink->appendChild($linkText);
echo $doc->saveHTML();
}
什么是失败?任何错误消息?警告:DOMDocument::loadHTMLFile():无法打开流:HTTP请求失败!在第6行的C:\wamp\www\onlineshopping\test\config.php中,配置中是什么,第6行是php?给我们看一些代码这是config.php中的代码你是说你问题中的上述代码是C:\wamp\www\onlineshopping\test\config.php中的代码?