The elementary collection program written in php can use this collection program and then process it in the Empire.
######################################## ######################################## ####
# Author: 9 elong
# Website: Personal websites are not worth mentioning
# Time: 2007-01-01
# Declaration: it is only used for learning php.
# Function: collect images on a single page.
# Note: Regular expressions have been written in three demonstration forms for demonstration. There is no function description, and everything is in the source code. Demonstration of adding Forum Image Collection regular expressions
######################################## ######################################## ####
// Function for capturing an image from the information page
Function getimg ($ url, $ n, $ key, $ imgqian, $ imgbiao, $ titlekey)
{
// $ Key: Image address regular
// $ Titlekey: Image title regular
// $ Imgqian Image Address Prefix
// $ Imgbiao Image address special identifier
Global $ n;
Global $ msg;
Global $ result;
Global $ imgadd;
Global $ title;
$ Msg = file_get_contents ($ url );
$ Key = str_replace ("{image address}", "(. +)", $ key );
$ Key = "|". $ key. "| isU ";
Preg_match_all ($ key, $ msg, $ result );
$ C = count ($ result [0]);
For ($ I = 0; $ I <$ c; $ I ++)
{
$ Img = $ result [0] [$ I]."
";
If (ereg ("^. *". $ imgbiao. ". * $", $ img ))
{
$ Img = str_replace ($ imgbiao, $ imgqian. $ imgbiao, $ img );
Preg_match ("| http: // (. +) jpg | isU", $ img, $ img );
$ Imgadd [$ n] = $ img [0];
// Echo"
";
$ N ++;
}
Elseif (ereg ("^. * jpg. * $", $ img ))
{
Preg_match ("| http: // (. +) jpg | isU", $ img, $ img );
$ Imgadd [$ n] = $ img [0];
If ($ img [0]! = "")
$ N ++;
}
Unset ($ img );
}
$ Titlekey = str_replace ("{image Title}", "(. +)", $ titlekey );
$ Titlekey = "|". $ titlekey. "| isU ";
Preg_match ($ titlekey, $ msg, $ title );
// Echo $ title [0];
Return $ title;
Return $ msg;
Return $ result;
Return $ n;
Return $ imgadd;
}
######################################## ######################################## ####
# The following Replace is not supported for the file_get_contents () function
# $ I = 0;
# $ Handle = @ fopen ($ url, "rb ");
# While (! @ Feof ($ handle ))
#{
# $ Buffer [$ I] = @ fgets ($ handle, 4096 );
# $ I ++;
#}
# Fclose ($ handle );
# $ Msg = join ("", $ buffer );
######################################## ######################################## ####
If ($ _ GET ['AC'] = "getimgadd" & $ _ POST ['URL']! = "")
{
$ Url = $ _ POST ['URL'];
Getimg ($ url, "0", $ _ POST ['key'], $ _ POST ['imgqian '], $ _ POST ['imgbiao'], $ _ POST ['titlekey']);
######################################## ######################################## ####
// Retrieve the page
If ($ _ POST ['getpage'] = "yes ")
{
$ _ POST ['Page'] = str_replace ("{pagination address}", "(. +)", $ _ POST ['Page']);
$ Page = "|". $ _ POST ['Page']. "| isU ";
// Echo $ page;
Preg_match_all ($ page, $ msg, $ presult );
If ($ _ POST ['PC'] = "" | $ _ POST ['PC'] = "all ")
$ Pc = count ($ presult [0]);
Else
$ Pc =$ _ POST ['PC'];
If ($ _ POST ['PC']> count ($ presult [0])
$ Pc = count ($ presult [0]);
For ($ I = 1; $ I <$ pc; $ I ++)
{
$ Pageurl = $ presult [0] [$ I];
// Echo $ pageurl ."
";
If (ereg ("^. * [1-9]. * $", $ pageurl ))
{
$ Pageurl = str_replace ("$ pagekey = str_replace (" {key address} "," (. +) ", $ _ POST ['pagekey']);
$ Pagekey = "|". $ pagekey. "| isU ";
Preg_match ($ pagekey, $ pageurl, $ N3 [$ I]);
// Echo ($ N3 [$ I] [0])."
";
Getimg ($ N3 [$ I] [0], $ n, $ _ POST ['key'], $ _ POST ['imgqian '], $ _ POST ['imgbiao'], $ _ POST ['titlekey']);
}
}
}
######################################## ######################################## ####
Echo "image set [". $ title [1]. "]". $ n. "captured images
Back to homepage
";
While (list ($ num, $ var) = each ($ imgadd ))
{
If ($ _ POST ['showtype'] = "image ")
{
Echo"
";
}
Else
Echo $ var ."
";
}
######################################## ######################################## ####
// Exit ();
}
?>
Instance 1 (the information page has pagination, and a simple paging regular expression is used ):
Instance 2 (there is no paging on the information page, so the paging regular is blank ):
Instance 3 (there is no paging on the information page, so the paging regular is blank, the image is an absolute address, so the image address prefix is blank ):
Huasheng Forum pictures for the attachment http://bbs.hnol.net/dispbbs2.asp? BoardID = 50 & ID = 336436
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