Sharing tips on crawling web content with PHP_PHP Tutorial
How to implement it correctlyBut why does PHP not respond after crawling the web content? There is no test text. If I put echo "test"; on the first line, it can be output. I guess the curl_init() function has not been run yet!
See if there is CURL extension support in PHP's phpinfo()!
Copy php_curl.dll to c:windows and c:windowssystem32, restart apache and try again
It is not the file php_curl.dll, but copy libeay32.dll and ssleay32.dll in the php directory to c:windowssystem32 and restart apache
For the sake of server security, allow_url_fopen is turned off.
When the server allow_url_fopen = Off, file_get_contents cannot be used. It can only be used when it is set to ON.
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><span> ?php /* </span></span></span></li> <li> <span>$</span><span class="attribute">getstr</span><span>=</span><span class="attribute-value">file_get_contents</span><span>("http://www.<br>163.com/weatherxml/54511.xml"); </span> </li> <li class="alt"> <span>$</span><span class="attribute">qx</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($getstr,"</span><span class="attribute">qx</span><span>=")); </span> </li> <li> <span>$</span><span class="attribute">wd</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($getstr,"</span><span class="attribute">wd</span><span>=")); </span> </li> <li class="alt"> <span>$</span><span class="attribute">qximg</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($getstr,"</span><span class="attribute">qximg</span><span>=")); </span> </li> <li> <span>$</span><span class="attribute">qximg_</span><span>=</span><span class="attribute-value">explode</span><span>(",",$qximg[1]); </span> </li> <li class="alt"><span>echo "北京 ".$qx[1].""; </span></li> <li><span>echo $wd[1];*/ </span></li> <li class="alt"> <span>//echo "</span><span class="tag"><span> </span><span class="tag-name">img</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">'http://news.<br>163.com/img/logo/".$qximg_[0]."'</span><span class="tag">><br></span><span class="tag"><span> </span><span class="tag-name">img</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">'http://news.163.com<br>/img/logo/".$qximg_[1]."'</span><span class="tag">></span><span>"; </span></span></span> </li> <li> <span class="tag">?></span><span> </span> </li> </ol>
The following example of PHP crawling web content is to obtain the 163 weather forecast through the curl_init function
Put php.ini ( ;extension=php_curl.dll ) Remove the previous (;) and save
Copy php_curl.dll, libeay32.dll, ssleay32.dll to c:windowssystem32 and restart IIS. Apache is not installed
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><span> ?php </span></span></span></li> <li><span>//初始化curl </span></li> <li class="alt"> <span>$</span><span class="attribute">ch</span><span> = </span><span class="attribute-value">curl_init</span><span>() or die (curl_error()); </span> </li> <li><span>//设置URL参数 </span></li> <li class="alt"><span>curl_setopt($ch,CURLOPT_URL,"http:<br>//www.163.com/weatherxml/54511.xml"); </span></li> <li><span>//要求CURL返回数据 </span></li> <li class="alt"><span>curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); </span></li> <li><span>//执行请求 </span></li> <li class="alt"> <span>$</span><span class="attribute">result</span><span> = </span><span class="attribute-value">curl_exec</span><span>($ch) or die (curl_error()); </span> </li> <li><span>//取得返回的结果,并显示 </span></li> <li class="alt"><span>//echo $result; </span></li> <li><span>// echo curl_error($ch); </span></li> <li class="alt"> <span>$</span><span class="attribute">qx</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($result,"</span><span class="attribute">qx</span><span>=")); </span> </li> <li> <span>$</span><span class="attribute">wd</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($result,"</span><span class="attribute">wd</span><span>=")); </span> </li> <li class="alt"> <span>$</span><span class="attribute">qximg</span><span>=</span><span class="attribute-value">explode</span><span>(""",strstr($result,"</span><span class="attribute">qximg</span><span>=")); </span> </li> <li> <span>$</span><span class="attribute">qximg_</span><span>=</span><span class="attribute-value">explode</span><span>(",",$qximg[1]); </span> </li> <li class="alt"> <span>echo "北京 ".$qx[1]."</span><span class="tag"><span> </span><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>"; </span></span> </li> <li><span>echo $wd[1]; </span></li> <li class="alt"><span>//关闭CURL </span></li> <li><span>curl_close($ch); </span></li> <li class="alt"> <span class="tag">?></span><span> </span> </li> </ol>
Through the above study of PHP crawling web content, you can practice it yourself and deepen your understanding of it.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
