PHP collection Program Daquan

Source: Internet
Author: User

In the forum for a long time no how formally published things, today to share my collection code!

Ideas:

The idea of collecting the program is very simple and can be divided into the following steps:
1. Get the remote file source code (file_get_contents or fopen).
2. Analyze the code to get what you want (here is a regular match, usually get paged).
3. Follow the root to download the contents of the library and other operations.

The second step here is likely to repeat the operation several times, for example, to analyze the paging address, in the analysis of the contents of the inside page to get what we want.

Code:

Remember the previous hair department over part of the code today I'm here in the simple hair Department
Copy PHP content to clipboard
PHP Code:
@ $nl =file_get_contents ($rs [' url ']);//Crawl remote content
Preg_match_all ("/var url = \" gameswf\/(. *?) \.swf\ ";/is", $NL, $connect);//perform regular matches to get what you want
mysql_query ("Insert ... Insert Database section ");


The above code is all the collection to use the code, of course, you can also use Fope, I personally like to use file_get_contents.

Below in share my download picture Flash to local method, too simple two lines of code
Copy PHP content to clipboard
PHP Code:
if (@copy ($url, $newurl)) {
echo ' OK ';
}


in the forum before also sent a picture download function This will also be put up for everyone
copy PHP content to clipboard
PHP Code:
/ * Save Picture function * /
function getimg ($url, $filename) {
/ * Determine if the URL of the picture is empty, if it is an empty stop function * /
if ($url = = "") {
return false;
}
/ * Get the extension of the picture, in the variable $ext * /
$ext =strrchr ($url, ".");
/ * Determine if it is a valid picture file * /
if ($ext! = ". gif" && $ext! = ". jpg") {
return false;
}
/ * Read the picture * /
$img =file_get_contents ($url);
/ * Open the specified file * /
[email protected] ($filename. $ext, "a");
/ * Write the picture to the pointing file * /
fwrite ($fp, $img);
/ * Close file * /
fclose ($fp);
/* Returns the new file name of the picture */(e.g. fclose ($FP); Kunming National Defense Road Hospital)
return $filename. $ext;
}


Share a personal collection of hearts:

1. Do not take those for the anti-theft chain of the station, in fact, can be false, but this station acquisition cost is too high

2. Collect as fast as possible, preferably locally

3. There are many times when you can put some data into the database, and then the next step of processing.

4. When collecting must make the error handling, I generally is if the acquisition three times did not succeed on the skip. I used to be stuck there all the time because a piece of content couldn't be picked.

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.