简单的php 采集页面url
function str_url($str){$preg='/href=\"(http\:\/\/[^\"]+)/im'; //匹配url规则
if(preg_match_all($preg,$str,$temp)){
$con=array_unique($temp); //删除重复的地址;
};
$preg2='/http\:\/\/(\S)+/';
$new_array=array();
foreach ($con as $key=>$value){ //遍历数组,删除无用的字符,重新加入数组;
preg_match($preg2,$value,$temp);
array_push($new_array,$temp);
};
return $new_array;
} 下面为采集页面的 html;<?php
//字符串过滤HTML
function replace_HTML($start, $end, $str)
{
$temp = explode($start, $str, 2);
$content = explode($end, $temp, 2);
return $content;
}
$html=iconv('gbk','gbk',file_get_contents('http://www.163.com'));
//获取网站HTML,并且转换网站字符偏码 参数1为获取网站,参数2为本地的
//下面为实例示范;
echo '采集内容:'.preg_HTML('<title>','</title>',$html);
?> 5665yhhhhhhhhhhhhh 支持高人O(∩_∩)O~
页:
[1]