$text = '
hello
';echo preg_replace("/]*?(\/?)>/i",'', $text);
//
hello
RegExp细分:
/ # Start Pattern
( # Start Capture Group $1 - Tag Name
[a-z] # Match 'a' through 'z'
[a-z0-9]* # Match 'a' through 'z' or '0' through '9' zero or more times
) # End Capture Group
[^>]*? # Match anything other than '>', Zero or More times, not-greedy (wont eat the /)
(\/?) # Capture Group $2 - '/' if it is there
> # Match '>'
/i # End Pattern - Case Insensitive
添加一些引用,并使用替换文本,它应该删除标记名后面的任何文本,直到标记结束/>或只是>。
请注意这不一定适用于所有输入,因为Anti-HTML + RegExp会告诉您。有一些后退,最明显的是
最终会
">和其他一些破坏的问题......我建议在Zend_Filter_StripTags中查看PHP中更完整的证明标签/属性过滤器