How do you replace < and > (but not what's between them) with PHP RegExp?
I've found dozens of funct开发者_开发百科ions that can remove whole HTML tags with the preg_replace() function, but I need to remove only the html brackets < and > (leaving anything inside them put). What regexp would accomplish this?
How about htmlspecialchars
. It replaces HTML reserved characters with escape sequences. This way the characters are displayed in the browser but aren't harmful at all.
This probably is what you want - show exactly the text the client typed in, but make it harmless.
PS: If you really do need a regex to remove tag-brackets, here you go: $text = preg_replace('/[<>]/', '', $text)
.
How about
str_replace(array("<", ">", "<", ">"), "", $text);
..?
精彩评论