当前位置:编程学习 > php >>

PHP截取语句修改求助!高手请进

我想把以下的代码中“ http://d.zhaoxi.net/rs.php?q=”改为“ http://www.zhaoxi.net/s?wd=”,改了之后截取内容的语句也要跟着修改,我要截取百度的搜索页面底部的“相关搜索”的关键词,我自己修改不正确,郁闷中,烦请哪位高人帮忙修改正确的语句并回贴,感激不尽。谢谢!!!
PHP语句如下--
<?php
$key = "a|b|c|d";

//开始抓取百度热门关键词
$splitkey = explode("|", $key);
$keynum=count($splitkey);

for($i=0;$i<=$keynum-1;$i++)
{
$keyword=$splitkey[$i];
$keywords=iconv("UTF-8","GBK",$keyword);
$url = " http://d.zhaoxi.net/rs.php?q=".$keywords."&tn=baidu";
$openurl = @file_get_contents($url);
//$openurl=iconv("GBK","UTF-8",$openurl);

$start=strpos($openurl,"<li class=ls>1</li>");
$end=strpos($openurl,"<li class=ls>6</li>");
$len=$end-$start;
$content=substr($openurl,$start,$len); //截取得指定内容
$content2 = explode("<img", $content);
//划分数组

for($p=0; $p<4; $p++)
{

$key = $content2[$p];

$start2=strpos($key,"baidur");//取得内容的截取段

$end2=strpos($key,"</li><li class=bar>");

$len2=$end2-$start2;

$content3=substr($key,$start2,$len2); //截取得指定内容

$content3 = str_replace("baidur>","",$content3);

$content3 = str_replace("</a>","kkxzkkxz",$content3);

$content4=$content4.$content3;
}
}
//抓取百度热门关键词结束
?>
答案:<?php
$key = "a|b|c|d";

//开始抓取百度热门关键词
$splitkey = explode("|", $key);
$keynum=count($splitkey);

for($i=0;$i<=$keynum-1;$i++)
{
$keyword=$splitkey[$i];
$keywords=iconv("UTF-8","GBK",$keyword);
$url = " http://www.zhaoxi.net/s?wd=".$keywords;
$openurl = @file_get_contents($url);


if($openurl==''){

exit('获取不到地址的内容,退出关键字抓取程序');

}
$fen_ge_string='<td nowrap class="f14">';
$content=explode($fen_ge_string,$openurl);
$content_count=count($content);
$keyword_array=array();

if($content_count<2){
echo "地址{$url}没有列出相关的关键字<br />";
}else{
for($j=1;$j<$content_count;$j++){
$keyword_array[]=strip_tags($content[$j]);
}
unset($content);
echo "对于{$keywords}获取到关键字为:";
foreach($keyword_array as $value){
echo $value.',';
}
echo '<br />';
}
}
//抓取百度热门关键词结束
?>

上一个:php 编程不常见的写法,解释下
下一个:请大侠帮忙做一个简单的php程序

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,