PHP的正则表达式来删除HTML [英] php regex to remove HTML

查看:99
本文介绍了PHP的正则表达式来删除HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始之前,strip_tags()不起作用。

现在,

我有一些需要解析的数据,问题是,我需要去掉所有已经非常奇怪地形成的HTML。
标签看起来像这样:
(注意空格)

 < p>等等等等等等等等。 / p> < a href =link.html>等等等等等等等等。 / a> 

我一直在尝试的所有正则表达式都不起作用,正则表达式格式化,使他们工作。我不在乎保留标签内的任何东西,如果可能的话,宁愿删除链接中的文本。

任何人有任何想法?



(我真的需要坐下来学习一天的正则表达式)

解决方案



  preg_replace('/< [^>]> /','', 

工作吗?


Before we start, strip_tags() doesn't work.

now,

I've got some data that needs to be parsed, the problem is, I need to get rid of all the HTML that has been formated very strangely. the tags look like this: (notice the spaces)

< p > blah blah blah < / p > < a href= " link.html " > blah blah blah < /a >

All the regexs I've been trying aren't working, and I don't know enough about regex formating to make them work. I don't care about preserving anything inside of the tags, and would prefer to get rid of the text inside a link if I could.

Anyone have any idea?

(I really need to just sit down and learn regular expressions one day)

解决方案

Does

preg_replace('/<[^>]*>/', '', $content)

work?

这篇关于PHP的正则表达式来删除HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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