


PHP method to obtain all connections of a web page (with demo source code download), demo source code download_PHP tutorial
How PHP obtains all connections to a web page (with demo source code download), demo source code download
The example in this article describes how PHP obtains all connections to a web page. Share it with everyone for your reference, the details are as follows:
function getHtml($url, $charset='utf-8') { $curl = curl_init(); //curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:192.168.168.1', 'CLIENT-IP:192.168.168.1'));//IP curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_REFERER, ""); //来路 $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31'; curl_setopt($curl, CURLOPT_USERAGENT, $user_agent); // 只需返回HTTP header // curl_setopt($curl, CURLOPT_HEADER, 1); // 页面内容我们并不需要 // curl_setopt($curl, CURLOPT_NOBODY, 1); // 返回结果,而不是输出它 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $html = curl_exec($curl); //$info = curl_getinfo($curl); //echo var_dump($info); if ($html === false) { //echo "cURL Error: " . curl_error($ch); return ''; } curl_close($curl); if ($charset != 'utf-8') { $html = iconv($charset, "UTF-8", $html); } return $html; } header("Content-type: text/html; charset=utf-8"); include('simple_html_dom.php'); // 要打开 extension=php_mbstring.dll //$url = 'http://www.baidu.com/s?wd=kaka'; $url = 'http://www.163.com/'; $str_html = getHtml($url, 'gbk'); $html = str_get_html($str_html); $links = $html->find('a'); foreach($links as $link) { $txt = trim($link->plaintext); echo $link->href . '[' . $txt . ']<br>'; } $html = null;
Click here to download the complete example code from this website.
Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP Network Programming Skills", "Introduction Tutorial on PHP Basic Grammar", "Summary of PHP Office Document Skills (including word, excel, access, ppt)", "php date and time usage summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary" 》
I hope this article will be helpful to everyone in PHP programming.
Articles you may be interested in:
- php method to get all links on a webpage
- php regular expression function to extract webpage hyperlink url
- Introduction to PHP functions used to obtain homepage and site links in WordPress
- Usage analysis of related PHP functions in WordPress to obtain page links and titles
- Regular expression for php to obtain hyperlink text content (5 method)
- php regular expression to get all links of content
- PHP method to get the real address and response header information after the short link jumps
- php self-written function code Get keywords to hyperlink

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
