-
- if (!is_dir('img')) { mkdir('img'); }
Copy code
> 3. Use regular expressions to get the relative address of the image:
-
- if (preg_match('/^http.*/',$val)) { $target = $val; }
- else if (preg_match('/^/.*/',$val)) { $target=$host.$val; }
- else { $target=$url.$val; }
- echo $target."
rn";
Copy code
> Finally Take out the file name, which is 1.gif in /img/1.gif, and use it to save the file.
-
- if (!is_file('./img/'.$name[1])) {
- $imgc = file_get_contents($target);
- $handle = fopen('./img/'.$ name[1],'w+');
- fwrite($handle,$imgc);
- fclose($handle);
- }
Copy code
>One time, Xiaoxie suddenly discovered the power of Copy.
> Copy can actually be downloaded, so you can easily use the following code to handle it, and the above one can retire the bird.
-
- if (!is_file('./img/'.$name[1])) {
- copy($target,'./img/'.$name[1]);
- }
Copy code
5. Complete source code:
Just fill in $url when using it, and then save all CSS content to abc.css.
-
-
- $url = 'http://bbs.it-home.org/css/';
- $data = file_get_contents('abc.css');
- preg_match('/( .*//.*?)//',$url,$host);
- $host = $host[1];
- if (!is_dir('img')) { mkdir('img'); }
- $regex = '/url('{0,1}"{0,1}(.*?)'{0,1}"{0,1})/';
- preg_match_all($regex,$data,$ result);
- foreach ($result[1] as $val) {
- if (preg_match('/^http.*/',$val)) { $target = $val; }
- else if (preg_match('/ ^/.*/',$val)) { $target=$host.$val; }
- else { $target=$url.$val; }
- echo $target."
rn";
- preg_match('/.*/(.*.D+)$/',$val,$name);
- if (!is_file('./img/'.$name[1])) {
- copy($ target,'./img/'.$name[1]);
- }
- }?>
Copy code
|