html文件注释放哪里,如何从文件中找到所有不在HTML注释(<!-- -->)中的所有<meta>标签?...

本文介绍了一个用于抓取和解析网页元信息的PHP函数,该函数能够有效地从指定URL中提取网页标题及各种元标签信息,并以数组形式返回这些数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

检查了这一点:

function get_meta_tags2($url)

{

$result = false;

$contents = file_get_contents(str_replace(array(''), '',$url));

if (isset($contents) && is_string($contents))

{

$title = null;

$metaTags = null;

preg_match('/

([^>]*)/si', $contents, $match);

if (isset($match) && is_array($match) && count($match) > 0)

{

$title = strip_tags($match[1]);

}

preg_match_all('/"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $contents, $match);

if (isset($match) && is_array($match) && count($match) == 3)

{

$originals = $match[0];

$names = $match[1];

$values = $match[2];

if (count($originals) == count($names) && count($names) == count($values))

{

$metaTags = array();

for ($i=0, $limiti=count($names); $i < $limiti; $i++)

{

$metaTags[$names[$i]] = array (

'html' => htmlentities($originals[$i]),

'value' => $values[$i]

);

}

}

}

$result = array (

'title' => $title,

'metaTags' => $metaTags

);

}

return $result;

}

输出将是:

Array

(

[title] => Teleit.pl - strony internetowe

[metaTags] => Array

(

[description] => Array

(

[html] =>

[value] => Java, PHP, and some other technological mumble jumble. Also, some real-life stuff as well.

)

[DC.title] => Array

(

[html] =>

[value] => Mariano Iglesias - Weblog

)

[ICBM] => Array

(

[html] =>

[value] => -34.6017, -58.3956

)

[geo.position] => Array

(

[html] =>

[value] => -34.6017;-58.3956

)

[geo.region] => Array

(

[html] =>

[value] => AR-BA

)

[geo.placename] => Array

(

[html] =>

[value] => Buenos Aires

)

)

)

?>

学分原始版本:马里亚诺在cricava点com,我改变这一点给你。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值