([\w\W]*?)<\/TITLE>/si', $output, $matches);
if (!empty($matches[1])) {
$page_info['site_title'] = $matches[1];
}
// 正则匹配,获取全部的meta元数据
preg_match_all('//si', $output, $matches);
$meta_str_array = $matches[0];
$meta_array = array();
$meta_array['description'] = '';
$meta_array['keywords'] = '';
foreach($meta_str_array as $meta_str) {
preg_match('//si', $meta_str, $res);
if(!empty($res)) $meta_array[strtolower($res[3])] = $res[1];
preg_match('//si', $meta_str, $res);
if(!empty($res)) $meta_array[strtolower($res[2])] = $res[3];
}
//如果正则匹配失败则使用php函数尝试再次匹配
if(empty($meta_array['keywords']) || empty($meta_array['description'])){
//将html保存为临时文件
$key = md5(uniqid().Get_Rand_Str(8));
$tempFile = DIR ."/data/temp/".md5(uniqid().Get_Rand_Str(8)).".html";
file_put_contents($tempFile, $output);
$tags = get_meta_tags($tempFile);
unlink($tempFile); //删除临时文件
if(empty($meta_array['keywords']) && !empty($tags['keywords'])){
$meta_array['keywords'] = $tags['keywords'];
}
if(empty($meta_array['description']) && !empty($tags['description'])){
$meta_array['description'] = $tags['description'];
}
}
$page_info['site_keywords'] = $meta_array['keywords'];
$page_info['site_description'] = $meta_array['description'];
//$page_info['meta_array'] = $meta_array; //暂时不需要全部meta
# 判断是否存在友链
if(!empty($friend_link) && strstr($output, $friend_link) != "") {
$page_info['friend_link_status'] = 1;
}
return $page_info;
}