Tips for capturing Web content using PHP _ PHP Tutorial

Source: Internet
Author: User
PHP tips for capturing web content. How can we achieve it correctly? why does PHP not respond after capturing webpage content? I don't even have any text for the test. if I test the echo function and put it in the first line, I can output it. how can I implement it correctly?Why does PHP not respond after capturing webpage content? No text for the test. if I put echo "test" on the first line, the output will be available. I guess the curl_init () function is not running yet!

Check whether CURL extension support is available in PHP phpinfo!

Copy php_curl.dll to c: windows and c: windowssystem32, restart apache, and then try again.

Instead of the php_curl.dll file, copy libeay32.dll and ssleay32.dll in the php directory to c: windowssystem32 and restart apache.

Allow_url_fopen is disabled for the sake of server security.

When the server allow_url_fopen = Off, file_get_contents cannot be used. it can only be used when ON is set.

 
 
  1. <? Php /*
  2. $ Getstr = file_get_contents ("http: // www.
    163.com/weatherxml/54511.xml ");
  3. $ Qx = explode (", strstr ($ getstr," qx = "));
  4. $ Wd = explode (", strstr ($ getstr," wd = "));
  5. $ Qximg = explode ("", strstr ($ getstr, "qximg = "));
  6. $ Qximg _ = explode (",", $ qximg [1]);
  7. Echo "Beijing". $ qx [1]. "";
  8. Echo $ wd [1]; */
  9. // Echo "163.com/img/logo/ ". $ qximg _ [0]." '>
    /Img/logo/". $ qximg _ [1]." '> ";
  10. ?>

The following example uses the curl_init function to obtain the 163 weather forecast.

Remove (;) from php. ini (; extension = php_curl.dll) and save it.

Copy php_curl.dll, libeay32.dll, and ssleay32.dll to c: windowssystem32 and restart IIS without installing apache.

 
 
  1. <? Php
  2. // Initialize curl
  3. $ Ch = curl_init () or die (curl_error ());
  4. // Set URL parameters
  5. Curl_setopt ($ ch, CURLOPT_URL, "http:
    // Www.163.com/weatherxml/54511.xml ");
  6. // Request that CURL return data
  7. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
  8. // Execute the request
  9. $ Result = curl_exec ($ ch) or die (curl_error ());
  10. // Obtain the returned result and display it
  11. // Echo $ result;
  12. // Echo curl_error ($ ch );
  13. $ Qx = explode (", strstr ($ result," qx = "));
  14. $ Wd = explode (", strstr ($ result," wd = "));
  15. $ Qximg = explode ("", strstr ($ result, "qximg = "));
  16. $ Qximg _ = explode (",", $ qximg [1]);
  17. Echo "Beijing". $ qx [1]. "<br/> ";
  18. Echo $ wd [1];
  19. // Disable CURL
  20. Curl_close ($ ch );
  21. ?>

Through the above learning on the web page content captured by PHP, you can perform the actual operation on your own to deepen your understanding of it.


Why didn't PHP respond after capturing webpage content? No text for the test. if I test the echo function and put it in the first line, the output will be displayed. I guess it is...

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.