php 信息采集程序代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?
//采集首页地址
$url="http://emotion.pclady.com.cn/skills/";
//获取页面代码
$rs=file_get_contents($url);
//设置匹配正则
//$fp=fopen("text.txt","a");
//$fw=fwrite($fp,$rs);
//fclose($fp);
/*<I class=titles><A
href="http://emotion.pclady.com.cn/skills/0903/376476.html"
target=_blank>留住你身边的好男人</A></I>*/
$preg='/<i\s+class=\"titles\"><a\s+href=\"[^>]+\">(.*)<\/a><\/i>/i';
//进行正则搜索
preg_match_all($preg,$rs,$title);
//计算标题数量
$count=count($title[0]);
echo $count."<br>";
//通过标题数量进行内容采集
for ($i=0;$i<$count;$i++){

//设置内容页地址
$pr='/<a\s+href=\"[^>]+\">/isU';
preg_match_all($pr,$title[0][$i],$jurl);
$substr=substr($jurl[0][0],9);
$curl=substr($substr,0,-18);
//获取内容页代码
$c=file_get_contents($curl);
//设置内容页匹配正则
$pc='/<a\s+href=\"[^>]+\">/i';
//进行正则匹配搜索
preg_match($pc,$c,$content);
//输出标题
echo $title[0][$i]."<br>";
echo $title[1][$i]."<br>";
$concount=count($content[0]);
echo $concount."<br>";
echo $content[0][0];
for ($j=0;$j<$concount;$j++){

}
}
?>

通过检测,$c已经是内容页的数据流了,可是$pc这个的正则表达式为什么只匹配<这个字符其他的都没有呢,是因为我上面用了subsrt()函数吗?还是什么问题?麻烦各位大侠指点迷津啊?

相关文章

thinkphp在低版本Nginx 下支持PATHINFO的方法分享

最近在用thinkphp做一个项目,基本完成后部署到nginx服务器上才发觉nginx是不支持pathinfo的那么我们如何来处理呢。 Nginx环境 在Nginx低版本中,是不支持PA...

关于session在PHP5的配置文件中的详细设置参数说明

;处理session存取的模式(预设:files) session.save_handler = files ;session档案存放路径(预设:/tmp) session.save_p...

php使用scandir()函数扫描指定目录下所有文件示例

本文实例讲述了php使用scandir()函数扫描指定目录下所有文件。分享给大家供大家参考,具体如下: //遍历子文件夹和文件夹的内容 并且计算出文件的多少 //一个demo 引号替...

PHP 500报错的快速解决方法

1 先看nginx error.log 指定的错误日记文件路径 找到这个日记文件看 里面信息 2 再看  php-fpm.conf 里面指定的PHP错误日记的路径 具体如下 p...

php 函数中使用static的说明

复制代码 代码如下: function sendHeader($num, $rtarr = null) { static $sapi = null; if ($sapi === null...