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 codeThe Code is as follows:
<? Php
/*
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 ('/<(.*?) Href = "(.*?) "> (.*?) <\/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> (.*?) <\/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', '<div id = "article_detail"> ');
$ File = fopen ($ filename, "w ");
Fwrite ($ file, $ content );
Fclose ($ file );
Echo $ filename. "Save OK <br> \ 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 ");
?>