PHP get Web content Method Thief program collection program

Source: Internet
Author: User
Tags fread

Crawled content in the regular expression through the filter to get the content you want, as to how to use regular expression filter, here do not introduce, interested in, the following is a few commonly used in PHP crawl content of the Web page method.
1.file_get_contents

<?  $url = "Http://www.jb51.net"$contentsfile_get_contents($url  //Echo $contents  

2.curl

<?PHP$url= "Http://www.jb51.net"; $ch=curl_init ();$timeout= 5; curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout,$timeout); //The following two lines of//curl_setopt ($ch, Curlopt_httpauth, Curlauth_any) need to be added to the Web page that requires user detection;//curl_setopt ($ch, Curlopt_userpwd, Us_ NAME. ":". US_PWD); $contents= Curl_exec ($ch); Curl_close ($ch); Echo $contents; ?>

3.fopen->fread->fclose

<?PHP$handle=fopen("Http://www.jb51.net", "RB"); $contents= "";  Do { $data=fread($handle, 1024); if(strlen($data) = = 0) {  Break; } $contents.=$data; }  while(true); fclose($handle); Echo $contents; ?>

PHP get Web content Method Thief program collection program

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.