Php is used to obtain the implementation code of the specified webpage content. generally, some code is often used by the collection program. this is just a simple Foundation. For more detailed information, refer to the php collection finished products and the source code that can be used to learn more. By referring to others' ideas and turning them into your own ideas, you will find that you will have the ideas and methods to temporarily solve many problems.
The code is as follows:
/*
Function: get the page content and store it for reading. lost63
*/
Class GetUrl {
Var $ url; // address
Var $ result; // result
Var $ content; // content
Var $ list; // list
Function GetUrl ($ url ){
$ This-> url = $ url;
$ This-> GetContent ();
$ This-> GetList ();
$ This-> FileSave ();
// Print_r ($ this-> list [2]);
}
Private function GetContent (){
$ This-> result = fopen ($ this-> url, "r ");
While (! Feof ($ this-> result )){
$ This-> content. = fgets ($ this-> result, 9999 );
}
}
Private function GetList (){
Preg_match_all ('/(.*?) <\/A>/', $ this-> content, $ this-> list );
$ This-> list [2] = array_unique ($ this-> list [2]); // remove the same value
While (list ($ key, $ value) = each ($ this-> list [2]) {
If (strpos ($ value, ". html") = 0 | strpos ($ value, "jiaocheng") = 0 ){
Unset ($ this-> list [2] [$ key]);
} Else {
$ This-> list [2] [$ key] = substr ($ value, 0, strpos ($ value ,". html ")). ". html "; // remove unnecessary tags
}
}
}
Private function FileSave (){
Foreach ($ this-> list [2] as $ value ){
$ This-> url = $ value; // assign a value again
$ This-> content = null;
$ This-> GetContent (); // Extract content
Preg_match_all ('/(.*?) <\/Title>/', $ this-> content, $ files); // obtain the title
$ Filename = $ files [1] [0]. ". html"; // storage name
$ Content = $ this-> str_cut ($ this-> content, 'http: // pagead2.googlesyndication.com/pagead/show_ads.js ','
');
$ File = fopen ($ filename, "w ");
Fwrite ($ file, $ content );
Fclose ($ file );
Echo $ filename. "save OK
\ N ";
}
}
Function str_cut ($ str, $ start, $ end ){
$ Content = strstr ($ str, $ start );
$ Content = substr ($ content, strlen ($ start), strpos ($ content, $ end)-strlen ($ start ));
Return $ content;
}
}
$ W = new GetUrl ("http://www.ijavascript.cn/jiaocheng/javascript-jiaocheng-352.html ");
?>