Hongmu Notes
Home Language Notes PHP regular expression matching for the website's body section
Language Notes PHP PHP collection

PHP regular expression matching for the website's body section

PHP regular expression matching for the website's body section

Match the website <body> For tags and their content, you can use the following regular expression:

$pattern = '/<body[^>]*>(.*?)<\/body>/is';

This regular expression matches. <body> Tag and its internal content, where .*? Represents non-greedy matching of any character.

Here is an example code:

// 获取目标 URL 的 HTML 内容
$html = file_get_contents('https://example.com');

// 匹配 body 部分
$pattern = '/<body[^>]*>(.*?)<\/body>/is';
if (preg_match($pattern, $html, $matches)) {
    // 输出 body 内容
    echo $matches[1];
} else {
    echo '没有找到 body';
}

In the above code, we use preg_match() Use a function for matching <body> The tag and its content are processed, and the matching results are output; if no match is found, <body> If the tag is found, output "Body not found".

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232
PHP capture website source code and json parsing

PHP capture website source code and json parsing Language Notes PHP PHP collection

Recently, I wanted to collect the names of some resource websites, so I found a fun one when I collected it. The opposite website was loaded by ajax technology, so I found the api, so I just wrote the code directly to put it in the warehouse. The code is backed up here and will be used in the future. & lt; ? php $date = file_get_contents(' Website address ' ); $date = json_deco…
👁 136
PHP special character escaping and restoration

PHP special character escaping and restoration Language Notes PHP PHP collection PHP and mysql

Escape character is a special character constant. Escape characters are backslashed " & quot; At the beginning, followed by one or more characters. The escaped character has a specific meaning, which is different from the original meaning of the character, so it is called "escaped" character. The use of escape characters 1: turn ordinary characters into special purposes, such as back key and enter key. 2. Used to convert a character with special meaning back to its original meaning. 3. Before data is written into the database, escape characters (function …
👁 180

Recommended reading

pbootCMS Manual Payment Plugin

pbootCMS Manual Payment Plugin Practical Collection pb tool

Alipay Face-to-Face Payment Plugin – includes a video tutorial! To enable the Alipay Face-to-Face Payment feature in PBootCMS, simply follow the video tutorial for configuration after successful application. Installation Guide: Step 1: Copy the files to the website's root directory; these are all new files and will not modify the existing PBootCMS system. Step 2: Apply for an Alipay Face-to-Face Payment API key (search for it online using Baidu); enter the key as follows: \apps\home\controller\Pay...
👁 862
(Adaptive mobile version) Responsive financial investment management institution website – PBootCMS template; Financial and investment website source code download – 0662

(Adaptive mobile version) Responsive financial investment management institution website – PBootCMS template; Financial and investment website source code download – 0662 Practical Collection pbootcms Template

A responsive PbootCMS website template designed for financial investment and wealth management institutions, compatible with both PC and WAP devices. Its modern financial design makes it ideal for investment firms and wealth management agencies to showcase their products and services. This template helps financial institutions attract high-net-worth clients online and enhance brand trust. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 40
Water Purification Equipment & Water Treatment Company Website Template 0317

Water Purification Equipment & Water Treatment Company Website Template 0317 Practical Collection Yiyou template

This EyouCMS template is ideal for water purification equipment and water treatment companies. Its modern, eco-friendly design is perfect for showcasing water purification products, water treatment systems, technical solutions, and project cases. It helps water treatment enterprises promote their brands online and attract both residential and industrial clients. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 52
Financial Loan Landing Page Website Template 1171

Financial Loan Landing Page Website Template 1171 Practical Collection Yiyou template

An EyouCMS website template designed specifically for financial loan landing pages. It features a strong marketing-oriented design with a compact, efficient layout that effectively highlights the advantages of loan products, interest rate policies, and application portals. This is an excellent tool for financial institutions conducting Baidu PPC campaigns or landing page promotions. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 50