【问题标题】:How to check Amp is enabled for a website with Php如何使用 PHP 检查网站是否启用了 Amp
【发布时间】:2017-11-16 18:47:31
【问题描述】:

有没有一种通用的方法来检查是否为 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";

【问题讨论】:

    标签: php amp-html


    【解决方案1】:

    是的,你可以这样做

    非 AMP 网页包含

    <link rel="amphtml" href="https://www.example.com/url/to/amp/document.html">
    

    假设你有 $html 中的内容;

    PHP 代码

        $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 */
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2016-05-10
      • 1970-01-01
      • 2017-10-27
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多