如何检查具有PHP的网站的Amp是否已启用 [英] How to check Amp is enabled for a website with Php

查看:95
本文介绍了如何检查具有PHP的网站的Amp是否已启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种通用的方法来检查是否为URL启用了AMP?

Is there a general way to check if AMP is enabled for an URL?

我目前正在使用Curl来获取HTML. 我该怎么办?

I currently use Curl to get HTML. What should I do after?

$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">

假设您的内容位于$ html;

Assuming that you have the content in $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 */
        }
    }

这篇关于如何检查具有PHP的网站的Amp是否已启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆