陌小雨博客个人博客大全里面新增了一个站点描述的功能,用到了这个 get_meta_tags 函数,下面分享给大家:用 php 代码获取站点描述信息,即 meta 中信息的方法。
/**
* @get_meta_tags 函数的应用实例
* @获取站点描述信息
* @collect:www.dedewp.com
*
*/
// Header...
header("Content-Type: text/html; charset=utf-8");
// Function Starts Here...
function getInfo($URL){
$getInfo= get_meta_tags($URL);
return $getInfo;
}
// URL...
$URL = "https://dedewp.com";
$_getInfo = getInfo($URL);
// Print.
echo "$URL
";
echo $_getInfo ["author"]."
";
echo $_getInfo ["keywords"]."
";
echo $_getInfo ["description"]."
";
echo $_getInfo ["robots"]."
";
?>
有的网站编码为 gb2312,使用上述代码后会发现字符出现乱码,我们只需要再运用一个转码函数即可。
function characet($data){
if( !empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != 'UTF-8'){
$data = mb_convert_encoding($data ,'utf-8' , $fileType);
}
}
return $data;
}
具体使用方法就为:
echo characet($_getInfo ["description"]);