Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 它可能会使用没有名字的get_meta_标记吗?_Php - Fatal编程技术网

Php 它可能会使用没有名字的get_meta_标记吗?

Php 它可能会使用没有名字的get_meta_标记吗?,php,Php,我的目标是从没有名字的元标记中提取信息,例如“charset” 目标是提取字符集并将其保存在JSON文件中,我知道如何保存它,但我对如何提取没有名称的meta标记感到非常困惑 代码应该有效,否则我必须更改它? 这是我的代码: <?php $domain = "http://www.americanairlines.de/"; $tags = get_meta_tags($domain); echo $tags['charset']; 我相信如果没有名称属性,您将无法获得标签 将仅解析具

我的目标是从没有名字的元标记中提取信息,例如“charset”

目标是提取字符集并将其保存在JSON文件中,我知道如何保存它,但我对如何提取没有名称的meta标记感到非常困惑

代码应该有效,否则我必须更改它?

这是我的代码:

<?php
$domain = "http://www.americanairlines.de/";
$tags = get_meta_tags($domain);
echo $tags['charset'];

我相信如果没有
名称
属性,您将无法获得标签

将仅解析具有名称属性的元标记。引用不正确 必需的


请看一下这里。它提到“只有具有名称属性的元标记才会被解析。”。因此,您需要使用字符串匹配来获得所需的数据

如何从页面获取命名元标记:

$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)
} 

请注意,字符集不是命名的元标记!字符集本身就是一个元属性。所以,如果你想要的是字符集,你将需要一些不同的东西

嗯,但是标签没有名字,所以我怎么做才能获取没有名字的标签呢?当我在上查看页面源代码时,我确实看到了命名的元标签…是的,但这只是一个例子,我必须从另一个网页获取命名的标签和包含“字符集”的元标签没有名称,如何使用字符串匹配?可以使用函数file()获取数组中的内容并循环。然后,您可以使用函数strstr提取所需的内容。一旦你发现你的元标签与字符集,你可以打破循环。
$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)
}