陌小雨博客个人博客大全里面新增了一个站点描述的功能,用到了这个get_meta_tags函数,下面分享给大家:用php代码获取站点描述信息,即meta中信息的方法。
<?php
/**
* @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 <p>";
echo $_getInfo ["author"]."<p>";
echo $_getInfo ["keywords"]."<p>";
echo $_getInfo ["description"]."<p>";
echo $_getInfo ["robots"]."<p>";
?>
有的网站编码为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"]);
快来提交你的网站吧:http://wpsite.dedewp.com/demo1/site-submit
转载请注明:小雨科技 _武汉网站建设_武汉小程序搭建 » php获取站点title、keywords、description的代码


