Re: htmlentities -- can it skip tags

From: Date: Mon, 15 Sep 2003 04:08:25 +0000
Subject: Re: htmlentities -- can it skip tags
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-162603@lists.php.net to get a copy of this message
On Monday, September 15, 2003, at 12:58 PM, John W. Holmes wrote:
Justin French wrote:
Hi all, I need to convert some text from a database for presentation on screen... as per usual, characters like quotes and ampersands (&) are giving me grief. the obvious answer is to apply htmlspecialchars(), BUT this also converts all < and > into &lt; and &gt; signs, which destroys the html mark-up within the text. Is there a non-tag equivalent of htmlspecialchars(), or do I need to build one?
You'll have to build one. If you know what characters are causing trouble, you could just use str_replace on them. Or you could use htmlspecialchars() and then run str_replace to convert &lt; and &gt; back into brackets.
Which is what I just did as a 'patch' :)
You could also use get_html_translation_table() to get the conversions, remove the < and > conversion elements of the array and then use strtr() to do the conversion.
I like that idea a LOT. Thanks John! Justin

« previous php.general (#162603) next »