Home > php教程 > PHP源码 > body text

php collects beautiful pictures from a website

大家讲道理
Release: 2016-11-09 09:17:48
Original
1570 people have browsed it

<?php
header("Content-type:text/html;charset=utf-8");
function GrabImage($url,$filename="") {
if($url==""):return false;endif;
if($filename=="") {
$ext=strrchr($url,".");
if($ext!=".gif" && $ext!=".jpg"):return false;endif;
$filename=date("dMYHis").$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, "w+");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
 
 
for($i=1;$i<8;$i++){
$url="http://www.topit.me/popular/20120420?p=".$i;
echo $url;
$file=file_get_contents($url);
 
$preg=&#39;/(.*)<div class="e">(.*)<\/div>(.*)/isU&#39;;
preg_match_all($preg,$file,$string);
set_time_limit(0);
 
foreach($string[2] as $key=>$value){
    //echo $value;
    $pattern_src = &#39;/href="(.*)"><img class="img" title="(.*)"/isU&#39;;
    preg_match_all($pattern_src,$value,$str);
    print_r($str."<br/>");
 
    $img=GrabImage($str[1][0],"","");
 
    if($img){
        echo &#39;sucess&#39;;
    }else{
        echo "false";
    }
}
 
}
?>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template