php获取网页title,php获取站点title、keywords、description的代码

陌小雨博客个人博客大全里面新增了一个站点描述的功能,用到了这个 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"]);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值