<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
function
getKeywordTotal(
$keyword
) {
$url
= 'http:
$html
=
file_get_contents
(
$url
);
$search
= '/<span
class
=
"nums"
[^>]*?>[^<]*?([0-9,]*?)</i';
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>