Home >php教程 >PHP源码 >纯粹跟风,用PHP下妹子图

纯粹跟风,用PHP下妹子图

PHP中文网
PHP中文网Original
2016-05-26 08:19:231090browse

跳至

 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++;
}

                   

Statement:
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
Previous article:二维数组合并及去重复Next article:银联网页支付