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++;
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号