<html>
<head>
<title>在线演示_php获取百度关键词查询结果总数</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="百度,baidu,查询结果">
<meta name="description" content="php获取百度关键词查询结果总数 by enenba.com">
</head>
<body>
<?php $k=isset($_POST['k'])?$_POST['k']:''; ?>
<form method="post" action="">
查询关键词:
<input type="text" name="k" size="50" value="<?php echo $k ?>">
<input type="submit" value="提交">
</form>
<?php
/*
获取百度关键词查询结果总数
2012-7-26
@param str $keyword
@param str 整型字符
*/
function getKeywordTotal($keyword) {
$url = 'http://www.baidu.com/s?wd='.$keyword;
$html = file_get_contents($url);
$search = '/<span class="nums"[^>]*?>[^<]*?([0-9,]*?)</i'; //获取<span class="nums">中部分
preg_match($search,$html,$match);
$match = str_replace(',','',$match); //去逗号
preg_match('/<span[^>]*>.*?(\d+)/',$match[0],$r);//得到最后的总数:
return $r[1];
}
if($k=='') {
exit('请输入数据');
}else{
echo '共有'.getKeywordTotal($k).'个结果。';
}
?>
</body>
</html>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号