[英]Removing HTML without escaping
<div class="item itemask" ><div class="tophead"><div class="itemnumber"></div><a class="article" href=""></a> </div><div class="bottomhead"> points by <a class="userlink" rel=""></a> ago <a href="http://news.ycombinator.com/item?id=">discuss</a></div></div>
How can PHP remove all instances of the above snippet in a page without requiring escaping the above string. PHP如何在不转义以上字符串的情况下删除页面中上述片段的所有实例。 Or, how can I easily get the escape-string of the above in order to plug into a preg_replace to remove it.
或者,如何才能轻松获取上述内容的转义字符串,以便插入preg_replace来删除它。
I need to run PHP on the server against a bunch of htm files. 我需要针对一堆htm文件在服务器上运行PHP。 It must be done on the server-side in one operation.
它必须在服务器端一次完成。
You could escape your search string with preg_quote
: 您可以使用
preg_quote
转义搜索字符串:
string preg_quote ( string $str [, string $delimiter = NULL ] )
preg_quote()
takes str and puts a backslash in front of every character that is part of the regular expression syntax.preg_quote()
采用str并将反斜杠放在正则表达式语法中每个字符的前面。 This is useful if you have a run-time string that you need to match in some text and the string may contain special regex characters.如果您有需要在某些文本中匹配的运行时字符串,并且该字符串可能包含特殊的正则表达式字符,这将很有用。
The special regular expression characters are:
. \\ + * ? [ ^ ] $ ( ) { } = ! < > | : -
特殊的正则表达式字符为:
. \\ + * ? [ ^ ] $ ( ) { } = ! < > | : -
. \\ + * ? [ ^ ] $ ( ) { } = ! < > | : -
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.