Last updated on 2019-05-17
<?php function save_image($img, $fullpath) { $ch = curl_init($img); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $rawdata = curl_exec($ch); curl_close($ch); $fp = fopen($fullpath, 'a'); fwrite($fp, $rawdata); fclose($fp); } $str = file_get_contents("https://www.wosign.com/EVSSL/index.htm"); //print_r($str); //正则匹配出所有IMG图片 $preg = '/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i'; preg_match_all($preg, $str, $imgArr); //print_r($imgArr); foreach ($imgArr[2] as $key => $val) { if (!strstr($val, 'http')) { $arr[] = "https://www.wosign.com/EVSSL/" . $val; } else { } } foreach ($arr as $key => $val) { $ext = strrchr($val, '.');//查找字符串中最后一次出点.的位置 并返回之后的值 save_image($val, $key . "$ext"); }