Home > Backend Development > PHP Tutorial > PHP collects and obtains the content of the specified URL_PHP tutorial

PHP collects and obtains the content of the specified URL_PHP tutorial

WBOY
Release: 2016-07-21 15:42:09
Original
844 people have browsed it

By referring to other people's ideas and turning them into your own, you will find that over time you will have ideas and methods to temporarily solve many problems.

Copy code The code is as follows:

/*
Function: Get page content, Store and read; 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('/(.*?)/',$this->content,$this->list);
$this->list[2]=array_unique($this-> ;list[2]); //Remove the same values
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; //Reassign value
$this->content=null;
$this->GetContent(); //Extract content
preg_match_all('/(.*? )/',$this->content,$files); //Get 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");
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321035.htmlTechArticleRefer to other people’s ideas and turn them into your own. You will find that after you slow down, you will have temporary solutions to many problems. ideas and methods. Copy the code The code is as follows: ?php /* Function: Get the page...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template