Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Php检查网站是否启用了Amp_Php_Amp Html - Fatal编程技术网

如何使用Php检查网站是否启用了Amp

如何使用Php检查网站是否启用了Amp,php,amp-html,Php,Amp Html,是否有一种常规方法来检查是否为URL启用了AMP 我目前使用Curl来获取HTML。 之后我该怎么办 $html; if(AMP is Enabled) echo "You are using AMP in Mobile Version"; else echo "You are not using AMP in Mobile Version"; 是的,你可以这样做 非AMP页面包含 <link rel="amphtml" href="https://www.example

是否有一种常规方法来检查是否为URL启用了AMP

我目前使用Curl来获取HTML。 之后我该怎么办

$html;
if(AMP is Enabled)
    echo "You are using AMP in Mobile Version";
else
    echo "You are not using AMP in Mobile Version";

是的,你可以这样做

非AMP页面包含

<link rel="amphtml" href="https://www.example.com/url/to/amp/document.html">
    $dom = new DOMDocument();
    @$dom->loadHTML($html);

    $nodes = $dom->getElementsByTagName('link');
    foreach ($nodes as $node)
    {
        if ($node->getAttribute('rel') === 'amphtml')
        {
            echo($node->getAttribute('href'));
            /* amp page found do your logic */
        }
    }