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

纯粹跟风,用PHP下妹子图

PHP中文网
Release: 2016-05-26 08:19:23
Original
1066 people have browsed it

跳至

 2){
        foreach ($matchs[2] as $k => $v) {
            $links[$v] = $matchs[1][$k];
        }
    }
    return $links;
}

function getImgUrls($url){
    $html = file_get_contents($url);
    preg_match_all('', $html, $matchs);
    return count($matchs) > 1 ? $matchs[1] : null;
}

function getImage($path, $url){
    preg_match('/img\/(\w+)\.jpg/', $url, $match);
    $filepath = $path . DIRECTORY_SEPARATOR . $match[1] . '.jpg';
    ob_start();
    readfile($url);
    $img = ob_get_contents();
    ob_end_clean();
    $fp=@fopen($filepath, 'a') ;
    fwrite($fp, $img);
    fclose($fp) ;
}

while($page  $v) {
        $k = str_replace(' ', ' ', $k);
        // 如果是GBK编码的Windows,需要下面一行转换字符格式
        // $k = mb_convert_encoding($k, 'gb2312', 'utf-8');
        $k = strip_tags($k);
        if(!file_exists($k)){
            echo '>>> Make directory ' . $k . PHP_EOL;
            mkdir($k, 0755, true);
        }
        $img_urls = getImgUrls($v);
        foreach ($img_urls as $key => $value) {
            echo '>>> Downloading ' . $value . PHP_EOL;
            getImage($k, $value);
        }
    }
    $page++;
}
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!