PHP collects static pages and CSS,IMG,JS pages to save the method, static page css_php tutorial

Source: Internet
Author: User

PHP collects static pages and CSS,IMG,JS pages to save the method, static page CSS


In this paper, we describe the method by which PHP collects static pages and saves pages css,img,js. Share to everyone for your reference. The specific analysis is as follows:

This is a Web page to get HTML code and Css,js,font and IMG resources, mainly used to quickly get templates, if you do not have time to design the UI or see a good template, you can use this tool to crawl Web pages and extract resource files, extracted content will be relative path to save resources , so you don't have to worry about the wrong URL import of the resource file.

Home index.php, the code is as follows:
Copy the Code code as follows:




Web crawler





Web Grabber




Url





Get



Save All

List







Crawl page code grab.php, the code is as follows:
Copy CodeThe code is as follows: <? Php
/*
* Flute
* 2014/03/31
*/

if (isset ($_post[' url ')) {
if (Isset ($_post[' project ') &&!is_dir ($_post[' project ')) mkdir ($_post[' project '), 0777);
Echo Json_encode (Grab ($_post[' url '));
}

Function Grab ($url) {
$url = ' http://ldixing-wordpress.stor.sinaapp.com/uploads/leaves/test.html ';
$data = Array ();
$file = preg_replace ('/^.*//', ' ', $url);

if ($content = file_get_contents ($url))!== false) {

if (Isset ($_post[' project ')) file_put_contents ($_post[' project '). ' /'. $file, $content);

$pattern = '/ /I ';
if (Preg_match_all ($pattern, $content, $matches)) {
$data [' css '] = $matches [2];
}

$pattern = '/ /I ';
if (Preg_match_all ($pattern, $content, $matches)) {
$data [' js '] = $matches [2];
}

$pattern = '//i ';
if (Preg_match_all ($pattern, $content, $matches)) {
$data [' img '] = $matches [2];
}

$pattern = '/url (' | ' | s) (. *?) 1)/I ';
if (Preg_match_all ($pattern, $content, $matches)) {
$data [' src '] = $matches [2];
}
}

return $data;
}

function Vardump ($obj) {
Echo '



Echo '
';
}
?>
Save css,js,img and other resources such as page save.php, the code is as follows:
Copy CodeThe code is as follows: <? Php
/*
* Flute
* 2014/03/31
*/

if (isset ($_post[' url ')) && isset ($_post[' project ') && isset ($_post[' domain ')) {
Extract ($_post);
$url = Preg_replace ('/?. *$/', ', $url);
$file = $url;
$arr = explode ('/', $file);
$length = sizeof ($arr);
$filename = $arr [$length-1];
$root = $project;
$dir = $root;

if ($domain = = ' http ') {
$dir = $root. ' /http ';
if (!is_dir ($dir)) mkdir ($dir, 0777);
} else {
$file = $domain. ' /'. $url;
for ($i = 0; $i < $length-1; $i + +) {
if (!emptyempty ($arr [$i])) {
$dir. = '/'. $arr [$i];
if (!is_dir ($dir)) mkdir ($dir, 0777);
}
}
}
if (!file_exists ($dir. '/'. $filename) | | filesize ($dir. '/'. $filename) = = 0) {
$content = file_get_contents ($file);
File_put_contents ($dir. '/'. $filename, $content);
}
}
?>
How to use:

1. Open the index page, enter the project name and the URL to crawl, the URL must be the end of the file name, such as index.html;

2. Click the Get button to get a list of all css,js,img and other resources on the current page;

3. Click the CSS link to get a picture of the background resource in the CSS file, appended to the list;

4. Click Save All to save all the files in the list and generate them as relative paths;

5. If there is an HTTP remote file on the webpage, it will be saved directly under the HTTP folder;

6. Get and save sometimes fail, but it's OK to retry several times.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/932075.html www.bkjia.com true http://www.bkjia.com/PHPjc/932075.html techarticle PHP collects static page and css,img,js the page to save the method, static page CSS This article describes the PHP collection of static pages and the page Css,img,js save method. Share to everyone ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.