$url='http://blog.sina.com.cn/s/blog_13aa026670102ynjo.html';
$str=file_get_contents($url);
// echo "$str";
$reg='/<!-- 正文开始 -->.*<!-- 正文结束 -->/isU';
preg_match($reg,$str,$arr);
//print_r($arr);
$reg1='/<img .* real_src ="(.*)" .*>/isU';
preg_match_all($reg1,$arr[0],$arr1);
$data['img_path']=$arr1[1];
foreach($data['img_path'] as $k=>$v)
{
$data['img_path'][$k]=str_replace("https","http",$v);
}
$this->load->view("testdd/img",$data);
----------------------前端的------------------------------------
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tu</title>
</head>
<body>
<?php foreach($img_path as $k=>$v){?>
<img class="path" src="<?php echo $v?>" width="50px" height="50px">
<?php }?>
<input type="button" id="cli">
<input type="text" id="nums">
</body>
</html>
<script src="<?php echo base_url("/public/js/jquery.js")?>"></script>
<script>
$(function()
{
localStorage.num=0;
$(document).ready(function()
{
$("#nums").val(localStorage["num"]);
})
$("#cli").click(function(){
var path=$(".path");
ajaxs(path);
})
function ajaxs(data)
{
var num=localStorage["num"]
var path=data.eq(num).attr("src");
if(num>data.length)
{
return false;
}
else {
$.ajax({
type: "post",
url: "filePut",
data: {
path: path,
num:num
},
success: function (a) {
if (a) {
localStorage.num++;
$("#nums").val(localStorage["num"]);
ajaxs(data)
}
else {
alert("采集失败了");
return false;
}
}
})
}
}
})
</script>
$str=file_get_contents($url);
// echo "$str";
$reg='/<!-- 正文开始 -->.*<!-- 正文结束 -->/isU';
preg_match($reg,$str,$arr);
//print_r($arr);
$reg1='/<img .* real_src ="(.*)" .*>/isU';
preg_match_all($reg1,$arr[0],$arr1);
$data['img_path']=$arr1[1];
foreach($data['img_path'] as $k=>$v)
{
$data['img_path'][$k]=str_replace("https","http",$v);
}
$this->load->view("testdd/img",$data);
----------------------前端的------------------------------------
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tu</title>
</head>
<body>
<?php foreach($img_path as $k=>$v){?>
<img class="path" src="<?php echo $v?>" width="50px" height="50px">
<?php }?>
<input type="button" id="cli">
<input type="text" id="nums">
</body>
</html>
<script src="<?php echo base_url("/public/js/jquery.js")?>"></script>
<script>
$(function()
{
localStorage.num=0;
$(document).ready(function()
{
$("#nums").val(localStorage["num"]);
})
$("#cli").click(function(){
var path=$(".path");
ajaxs(path);
})
function ajaxs(data)
{
var num=localStorage["num"]
var path=data.eq(num).attr("src");
if(num>data.length)
{
return false;
}
else {
$.ajax({
type: "post",
url: "filePut",
data: {
path: path,
num:num
},
success: function (a) {
if (a) {
localStorage.num++;
$("#nums").val(localStorage["num"]);
ajaxs(data)
}
else {
alert("采集失败了");
return false;
}
}
})
}
}
})
</script>