PHP collects the content of a specified URL. 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. Copy the code as follows :? Php * function: get a page to refer to others' ideas and turn them into your own ideas. you will find that you will have a temporary solution to 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 ");
?>
Bytes. The code is as follows :? Php/* function: get the page...