How to check Amp is enabled for a website with Php

半腔热情 提交于 2019-12-04 22:55:27

Yes you can do like this

Non AMP page contain

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

Assuming that you have the content in $html;

PHP CODE

    $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 */
        }
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!