PHP capture gets the content of the specified URL _php tutorial

Source: Internet
Author: User
By referring to the ideas of others, you will find that you have the ideas and methods to solve many problems on a temporary basis.
Copy CodeThe code is as follows:
/*
Function: Get the content of the page, store it and read it; Lost63
*/
Class geturl{
var $url; Address
var $result; Results
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 unwanted labels
}
}
}
Private Function FileSave () {
foreach ($this->list[2] as $value) {
$this->url= $value; Re-assign Value
$this->content=null;
$this->getcontent (); Extract Content
Preg_match_all ('/ <title>(.*?) <\/title>/', $this->content, $files); Take title</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");
?>

http://www.bkjia.com/PHPjc/321035.html www.bkjia.com true http://www.bkjia.com/PHPjc/321035.html techarticle by referring to the ideas of others, you will find that you have the ideas and methods to solve many problems on a temporary basis. Copy the code as follows:? PHP/* Feature: Get page ...

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.