search
Homephp教程PHP源码php获取百度关键词查询结果总数

[PHP]代码    

<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[&#39;k&#39;])?$_POST[&#39;k&#39;]:&#39;&#39;; ?>
<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 = &#39;http://www.baidu.com/s?wd=&#39;.$keyword;
	$html = file_get_contents($url);
	$search = &#39;/<span class="nums"[^>]*?>[^<]*?([0-9,]*?)</i&#39;; //获取<span class="nums">中部分
	preg_match($search,$html,$match);
	$match = str_replace(&#39;,&#39;,&#39;&#39;,$match); //去逗号
	preg_match(&#39;/<span[^>]*>.*?(\d+)/&#39;,$match[0],$r);//得到最后的总数:
	return $r[1];
}
if($k==&#39;&#39;) {
	exit(&#39;请输入数据&#39;);
}else{
	echo &#39;共有&#39;.getKeywordTotal($k).&#39;个结果。&#39;;
}
?>
</body>
</html>

                   

                   

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.