How to achieve the rightBut why does PHP not respond when crawling Web content? Not even the text of the test, if I put echo "test", put in the first line can be output, I guess the curl_init () function is not running!
You see PHP phpinfo () with no curl extension support!
Cuff Php_curl.dll to C:windows and C:windowssystem32 and try again after you restart Apache.
Not php_curl.dll This file, is the PHP directory in the libeay32.dll,ssleay32.dll copy to c:windowssystem32 inside restart Apache
For the sake of server security, so turn off the allow_url_fopen.
When the server Allow_url_fopen = Off, the file_get_contents cannot be used, only when set on.
- < ? PHP/*
- $ Getstr = file_get_contents ("http://www.
163.com/weatherxml/54511.xml ");
- $ QX = Explode ("" " , Strstr ($getstr,"qx= "));
- $ WD = Explode ("" " , Strstr ($getstr,"wd= "));
- $ qximg = Explode ("" " , Strstr ($getstr,"qximg= "));
- $ Qximg_ = Explode (",", $qximg [1]);
- echo "Beijing". $qx [1]. "";
- echo $WD [1];*/
- //echo " < img src=' http://news.
163.com/img/logo/". $qximg _[0]." ' >
< img src=' http://news.163.com
/img/logo/". $qximg _[1]." ' > ";
- ?>
The following example of PHP crawling Web content is the pass Curl_init function to get 163 weather forecast
Remove the php.ini (; extension=php_curl.dll) in front of the (;)) Save
Copy Php_curl.dll,libeay32.dll,ssleay32.dll to C:windowssystem32, restart IIS, no Apache
- < ? PHP
- Initialize Curl
- $ CH = Curl_init () or Die (Curl_error ());
- Set URL parameters
- curl_setopt ($ch, Curlopt_url, "http:
Www.163.com/weatherxml/54511.xml ");
- Require Curl to return data
- curl_setopt ($ch, curlopt_returntransfer,1);
- Execute request
- $ result = curl_exec ($ch) or Die (Curl_error ());
- Gets the returned result and displays
- echo $result;
- echo Curl_error ($ch);
- $ QX = Explode ("" " , Strstr ($result,"qx= "));
- $ WD = Explode ("" " , Strstr ($result,"wd= "));
- $ qximg = Explode ("" " , Strstr ($result,"qximg= "));
- $ Qximg_ = Explode (",", $qximg [1]);
- echo "Beijing". $qx [1]. " < br />";
- echo $WD [1];
- Turn off Curl
- Curl_close ($ch);
- ?>
Through the above on the PHP crawl Web content learning, you can actually work on their own to deepen the understanding of it.
http://www.bkjia.com/PHPjc/446179.html www.bkjia.com true http://www.bkjia.com/PHPjc/446179.html techarticle How can I do it correctly why does PHP not respond when crawling Web content? Not even the text of the test, if I put echo test, put in the first line can be output, I guess is ...