此函数可以获取 HTML 内容的每个元数据,并去除所有 js 和 css。
<?php
function get_meta_data($content)
{
$content = strtolower($content);
$content = preg_replace("'<style[^>]*>.*</style>'siU",'',$content); $content = preg_replace("'<script[^>]*>.*</script>'siU",'',$content); $split = explode("\n",$content);
foreach ($split as $k => $v)
{
if (strpos(' '.$v,'<meta')) {
preg_match_all(
"/<meta[^>]+(http\-equiv|name)=\"([^\"]*)\"[^>]" . "+content=\"([^\"]*)\"[^>]*>/i",
$v, $split_content[],PREG_PATTERN_ORDER);;
}
}
return $split_content;
}
?>