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

编程入门 行业动态 更新时间:2024-10-24 08:20:52
本文介绍了如何使用 PHP 检查网站是否启用了 Amp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有一种通用的方法可以检查某个网址是否启用了 AMP?

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

$html;如果(AMP 已启用)回声您在移动版本中使用 AMP";别的回声您没有在移动版本中使用 AMP";

解决方案

是的,你可以这样做

非 AMP 网页包含

假设你有 $html 中的内容;

PHP 代码

$dom = new DOMDocument();@$dom->loadHTML($html);$nodes = $dom->getElementsByTagName('link');foreach ($nodes 作为 $node){if ($node->getAttribute('rel') === 'amphtml'){echo($node->getAttribute('href'));/* 放大器页面找到你的逻辑 */}}

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

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

解决方案

Yes you can do like this

Non AMP page contain

<link rel="amphtml" href="www.example/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 */ } }

更多推荐

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

本文发布于:2023-11-01 01:20:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547830.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   网站   PHP   Amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!