I've got a neat little preg_replace that is supposed to replace all user entered special characters with their html equivalents - but only when they're outside angle brackets (<>) - this way it leaves the quote marks alone inside an href, for example.
Problem is, when the user types a line of text into the form's textarea, hits return (to start another line) and types some characters there, the preg replace fails - just doesn't replace the characters.
It works great if the text is just a single line of text.
Any thoughts? Here's the code. Sorry for the long line - not sure how best to break it up.
function ConvertToHtmlChars($string) {
$entities = addslashes(implode('', preg_replace('/^([^<].+[^>])$/e', "htmlentities(stripslashes('\\1'))",
preg_split('/(<.+?>)/', stripslashes($string), -1, PREG_SPLIT_DELIM_CAPTURE))));
return $entities;
}
Seems to have something to do with processing the newline character, but I'm not sure where to go from here.
Thanks,
Bob