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.
- <? 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 "163.com/img/logo/ ". $ qximg _ [0]." '>
/Img/logo/". $ qximg _ [1]." '> ";
- ?>
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.
- <? 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 ");
- // Request that CURL return data
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
- // Execute the request
- $ Result = curl_exec ($ ch) or die (curl_error ());
- // Obtain the returned result and display it
- // 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];
- // Disable CURL
- Curl_close ($ ch );
- ?>
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...