PHP正则表达式以删除< h1>标签(及其内容) [英] PHP Regular express to remove <h1> tags (and their content)

查看:259
本文介绍了PHP正则表达式以删除< h1>标签(及其内容)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,我似乎无法在线找到要删除的正则表达式

Hay, i can't seem to find any regular expressions online to remove

<h1></h1>

标签(及其内容).

任何人都可以帮上忙.

推荐答案

不要使用正则表达式,请使用 PHP简单HTML DOM .

Don't use a regex, use a tool like PHP Simple HTML DOM.

// Construct dom from string
$dom = str_get_html($html);

// ...or construct dom from file/url
$dom = file_get_html($path);

// strip h1 tags (and their content)
foreach ($dom->find('h1') as $node) {
    $node->outertext = '';
}

这篇关于PHP正则表达式以删除&lt; h1&gt;标签(及其内容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆