<?php /** * 正則表達式匹配須要的圖片 * @return ArrayIterator $arr */ function pregIMG($str){ $pattern='/<img.+src=\"(.+large.+\.jpg)\"?.+>/i'; preg_match_all($pattern,$str,$matchs); return $matchs; } /** * 查找某個頁面的jpg */ function getIMG($url,$dir){ if (empty($url)) return false; $contents = file_get_contents($url); $data = pregIMG($contents); $jpgs = $data[1]; unset($data); $data = $jpgs; if(!file_exists($dir) || !is_dir($dir)){ mkdir($dir,0777); } $num = 1; foreach ($data as $v){ copy($v, $dir.'/'.time(). rand(10,100).'.jpg'); usleep(1); $num++; } return $num; } /** * 獲取給定頁數頁數的暴漫 */ function getBaoZou($page=1){ $url = "http://baozoumanhua.com/tucao/fresh/page/".$page."?sv=1395827058"; $dir = "public"; return getIMG($url, $dir); } function getMoreBaoZou($page){ //下載前10頁 $num = 0; for ($i = 1;$i < $page; $i++){ $num += getBaoZou($i); } echo '一共下載了'.$num.'張暴走漫畫';//未設置頁編碼,可能會亂碼,請自行設定 } getMoreBaoZou(10);//獲取前10頁的暴走漫畫 ?>