【发布时间】: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";
【问题讨论】:
有没有一种通用的方法来检查是否为 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">
假设你有 $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 */
}
}
【讨论】: