要匹配网站的 <body> 标签及其内部内容,你可以使用以下正则表达式:
$pattern = '/<body[^>]*>(.*?)<\/body>/is';
该正则表达式匹配 <body> 标签及其内部内容,其中 .*? 表示非贪婪匹配任意字符。
以下是一个示例代码:
// 获取目标 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';
}
在上述代码中,我们使用 preg_match() 函数来匹配 <body> 标签及其内部内容,并输出匹配结果。如果没有找到 <body> 标签,则输出“没有找到 body”。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


![表情[aini]-红穆笔记](https://www.4s5.cn/wp-content/themes/zibll/img/smilies/aini.gif)
![表情[ciya]-红穆笔记](https://www.4s5.cn/wp-content/themes/zibll/img/smilies/ciya.gif)
![表情[xia]-红穆笔记](https://www.4s5.cn/wp-content/themes/zibll/img/smilies/xia.gif)


暂无评论内容