Re: htmlspecialchars and UTF-8
| From: | Renato De Giovanni | Date: | Thu, 05 Dec 2002 12:23:58 +0000 |
| Subject: | Re: htmlspecialchars and UTF-8 | ||
| References: | 1 | Groups: | php.i18n |
| Request: | Send a blank email to php-i18n+get-372@lists.php.net to get a copy of this message | ||
Hi Moriyoshi,
To generate a valid xml document I only need to escape five characters
inside any content: &<>"'
So what I really need is "htmlspecialchars", not "htmlentities".
And besides the unnecessary translation of many characters, by doing so
"htmlentities" produces an invalid xml document...
--
Renato
On 5 Dec 2002 at 4:22, Moriyoshi Koizumi wrote:
> Hi,
>
> If you want to do the full entity translation, use htmlentities() instead
> of htmlspecialchars()
>
> http://www.php.net/htmlspecialchars
>
> Moriyoshi
>
> "Renato De Giovanni" wrote:
>
> > Hi,
> >
> > We're working on a program that needs to generate an xml document, utf-8
> > encoded, based on information stored with another charset encoding inside a
> > database.
> >
> > So basically at some point we have a function that looks like:
> >
> > function encodeString($s, $encoding)
> > {
> > $s = mb_convert_encoding($s, 'UTF-8', $encoding);
> >
> > $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
> >
> > return $s;
> > }
> >
> > What happens is that "htmlspecialchars" seems to be always returning a
> > latin1 string, therefore causing problems with the generated document
> > supposedly utf-8 encoded.
> >
> > My question is: is this a php bug or am I misunderstanding something related
> > to multi-byte character support?
> >
> > PHP version is 4.2.3
> >
> > Thank you very much!
> > --
> > Renato
> > CRIA - Centro de Referencia em Informacao Ambiental
> > http://www.cria.org.br/
--
This message has been scanned for viruses and
dangerous content and is believed to be clean.