【发布时间】:2017-06-21 14:55:38
【问题描述】:
我需要一些 php 中的正则表达式操作方面的帮助。
我有字符串,例如
$string = 'This article is about something. If You want more
<a href='http://www.google.com'>click here</a>. If not just close
我想得到这样的结果:
$string = 'This article is about something. If You want more click here -
http://google.com. If not just close
我如何在 php 中做到这一点?我不能使用简单的 html 解析器和其他库
请帮忙,我不知道如何实现这一点
【问题讨论】:
-
“我不能使用简单的 html 解析器和其他库” ...甚至内置的
DOMDocument也不行?您可能会在 RegExp 和 HTML 上度过一段糟糕的时光...... -
I cannot use simple html parser and other libraries,为什么不呢?你可以使用preg_replace?如果可以使用,您是否尝试过任何方法? -
如果 DOMDocument 在 php 中构建,我会尝试使用它。我错过了。我不能使用外部库。
-
不惜一切代价避免使用正则表达式解析 HTML。