我的目标是从没有名称的元标记中提取信息,例如“charset”
目标是提取字符集并将其保存在JSON文件中,我知道如何保存它但我很遗憾如何提取没有名称的元标记
代码应该有效还是我必须更改?
这是我的代码:
<?php
$domain = "http://www.americanairlines.de/";
$tags = get_meta_tags($domain);
echo $tags['charset'];
尝试从此处获取值:
<meta charset="utf-8">
但它不起作用,有人可以告诉我为什么?
答案 0 :(得分:1)
答案 1 :(得分:1)
请看这里http://php.net/manual/en/function.get-meta-tags.php。它提到“只有具有名称属性的元标记才会被解析。”因此,您需要使用字符串匹配来获取所需的数据。
答案 2 :(得分:0)
如何从页面获取指定的元标记:
$domain = "https://www.nu.nl/"; // Better example url
$tags = get_meta_tags($domain); // Get the tags!
var_dump($tags); // This dumps all that's there
if isset($tags['charset']){ // You can only echo an element...
echo $tags['charset']; // ...if it exists (NOTE: charset in a named tag would be incorrect but if it's there it will echo it)
}
请注意,charset不是一个命名的元标记! charset本身就是一个元属性。因此,如果你在charset之后,你需要一些不同的东西。