function auto_save_image($body){ $img_array = explode('&',$body); /*$img_array = array(); preg_match_all(/(src)=[\|\'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))[\|\'| ]{0,}/isu, $body, $img_array); $img_array = array_unique($img_array[2]);*/ //也可以自动匹配 set_time_limit(0); $imgpath = uploads/allimg/.date(ymd)./; $millisecond = strftime(%h%m%s,time()); if(!is_dir($imgpath)) @mkdir($imgpath,0777); foreach($img_array as $key =>$value) { $value = trim($value); $get_file = @file_get_contents($value); $rndfilename = $imgpath./.$millisecond.$key...substr($value,-3,3); if($get_file) { $fp = @fopen($rndfilename,w); @fwrite($fp,$get_file); @fclose($fp); } $body = @ereg_replace($value, $rndfilename, $body); } return $body;}
复制代码
php