PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > non-utf characters and XML
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
non-utf characters and XML

Réponse
 
LinkBack Outils de la discussion
Vieux 08/11/2007, 06h02   #1
Toine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut non-utf characters and XML

Hello,

My problem:
I'm using PHP to dynamically create an XML document. However, some of
my data (from MySQL) contains non-UTF characters such as the umlaut.
Naturally, browsers like IE 7 throw an error when attempting to parse
these characters. I understand that these characters are invalid for
XML.

My question:
What is the best to handle these characters when creating XML
documents on the fly? It seems like searching and replacing these
characters would be complicated, and there must be an easier way.

Thanks!

  Réponse avec citation
Vieux 08/11/2007, 07h10   #2
Martin Mandl - m2m tech support
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: non-utf characters and XML

On Nov 8, 7:02 am, Toine <bapo...@gmail.com> wrote:
> Hello,
>
> My problem:
> I'm using PHP to dynamically create an XML document. However, some of
> my data (from MySQL) contains non-UTF characters such as the umlaut.
> Naturally, browsers like IE 7 throw an error when attempting to parse
> these characters. I understand that these characters are invalid for
> XML.
>
> My question:
> What is the best to handle these characters when creating XML
> documents on the fly? It seems like searching and replacing these
> characters would be complicated, and there must be an easier way.
>
> Thanks!


Actually Umlauts are in UTF-8. But you should tell your browser which
character set you are using.
You could do that in the xml header, e.g.
<?xml version="1.0" encoding="utf-8"?>

or set it in the header using php, e.g.
header('content-type: text/html; charset=utf-8');

which is basically the same as the meta tag
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

or let .htaccess do the job, e.g.
AddCharset utf-8 .css .html .xhtml .xml .php

good luck
Martin


------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at


  Réponse avec citation
Vieux 08/11/2007, 07h29   #3
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: non-utf characters and XML

On Thu, 08 Nov 2007 08:10:11 +0100, Martin Mandl - m2m tech support
<martin.mandl@gmail.com> wrote:

> On Nov 8, 7:02 am, Toine <bapo...@gmail.com> wrote:
>> Hello,
>>
>> My problem:
>> I'm using PHP to dynamically create an XML document. However, some of
>> my data (from MySQL) contains non-UTF characters such as the umlaut.
>> Naturally, browsers like IE 7 throw an error when attempting to parse
>> these characters. I understand that these characters are invalid for
>> XML.
>>
>> My question:
>> What is the best to handle these characters when creating XML
>> documents on the fly? It seems like searching and replacing these
>> characters would be complicated, and there must be an easier way.
>>
>> Thanks!

>
> Actually Umlauts are in UTF-8. But you should tell your browser which
> character set you are using.


Indeed. When using UTF-8, avoid a BOM btw.

> You could do that in the xml header, e.g.
> <?xml version="1.0" encoding="utf-8"?>
>
> or set it in the header using php, e.g.
> header('content-type: text/html; charset=utf-8');


Do serve XML as XML though, it isn't HTML.
--
Rik Wasmus
  Réponse avec citation
Vieux 09/11/2007, 07h29   #4
lawrence k
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: non-utf characters and XML

On Nov 8, 1:02 am, Toine <bapo...@gmail.com> wrote:
> Hello,
>
> My problem:
> I'm using PHP to dynamically create an XML document. However, some of
> my data (from MySQL) contains non-UTF characters such as the umlaut.
> Naturally, browsers like IE 7 throw an error when attempting to parse
> these characters. I understand that these characters are invalid for
> XML.
>
> My question:
> What is the best to handle these characters when creating XML
> documents on the fly? It seems like searching and replacing these
> characters would be complicated, and there must be an easier way.


If you're only trying to communicate plain text, you can wrap your
text in a CDATA block. Or you can do a lot of str_replace() to change
them all to HTML entities.

If the problem is that your XML is outputting things that your users
input, and your users are inputting a lot of junk, then all you can do
is filter out the non-UTF8 stuff. seems_utf8 can be a , and is
mentioned on this page:

http://wordpress.taragana.net/nav.ht...ons/index.html




  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h27.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10051 seconds with 12 queries