PHP 4 commonly used crawl network data method, PHP4 crawl Data _php Tutorial

Source: Internet
Author: User

PHP 4 commonly used crawl network data method, PhP4 kind of crawl data


The name of this section is Fsockopen,curl and file_get_contents, specifically to explore these three ways of network data input and output of some of the summary. About Fsockopen Front has been talked about a lot, below began to transfer to others. Here is a brief list of some common ways to crawl network data.

1. Use file_get_contents to get the content in the Get mode:

$url = ' http://localhost/test2.php '; $html = file_get_contents ($url); Echo $html;

2. Open the URL with fopen and get the content in Get mode

$url = ' http://localhost/test2.php '; $fp = fopen ($url, ' R '); Stream_get_meta_data ($fp); $result = "; while (!feof ($fp)) {  $result. = Fgets ($fp, 1024);} echo "URL body: $result"; fclose ($FP);

3. Use the File_get_contents function to get the URL by post

$data = Array (' foo ' = ' bar ', ' baz ' = ' boom ', ' site ' = ' www.jb51.net ', ' name ' = ' Nowa Magic '); $data = Http_build_query ($data);//$postdata = Http_build_query ($data); $options = Array (' http ' = = Array (' method ' => ; ' POST ', ' header ' = ' content-type:application/x-www-form-urlencoded ', ' Content ' + $data//' Timeout ' = 60 * 60/ /timeout (unit: s)), $url = "http://localhost/test2.php"; $context = Stream_context_create ($options); $result = file_get_ Contents ($url, False, $context); Echo $result;

4. Using the Curl Library, before using the Curl Library, you may need to check to see if the php.ini has already turned on the curl extension

$url = ' http://localhost/test2.php?site=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); $file _contents = Curl _exec ($ch); Curl_close ($ch); Echo $file _contents;

http://www.bkjia.com/PHPjc/1011954.html www.bkjia.com true http://www.bkjia.com/PHPjc/1011954.html techarticle PHP 4 commonly used crawl network data method, PhP4 kind of crawl data This section of the name is Fsockopen,curl and file_get_contents, specifically to explore these three ways to network data input and output ...

  • 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.