Question

épargniez heureusement les choses à mes fichiers XML via un formulaire web qui est pared par PHP et le SimpleDOM.php

Je dois enregistrer des éléments qui ont des prix anglais dans les donc je dois le signe dièse anglais. Mais quand je fais ce 2 choses se produisent:

  1. il retourne le prix enregistré en tant que  £

  2. si je puis l'enregistrer à nouveau sans aucune autre modification de l'analyseur SimpleDom puis Barfs et il supprime tout autre contenu INTHE fichier XML au-delà du signe dièse anglais.

La ligne de haut dans mon fichier XML ressemble

<?xml version="1.0" encoding="ISO-8859-1"?>

A l'intérieur du fichier XML est le £ être enregistré en tant que

&amp;Acirc;&amp;pound;

Pour autant que je peux dire devrait avoir le signe £ en elle, donc très confus pourquoi ce acirc arrive en iso-8859-1, il ....

J'ai vu sur une autre personne de fil a dit essayer d'utiliser 8859-15 mais cela ne fait aucune différence.

Toutes les idées des gens?

Vive Jas (Nube complet à tous ce codage des choses)

Était-ce utile?

La solution

The unicode code point for £ is U+00A3. In the UTF-8 encoding it is 0xC2 0xA3. Now, in ISO-8859-1 0xC2 is Å, and 0xA3 is £. So, somewhere in the flow, what you enter becomes UTF-8 which is interpreted as ISO-8859-1. Have you looked at how the "form" encodes the data before reaching your PHP code.

And, besides, what is this SimpleDOM doing w.r.t. entities? &Acirc; and &pound; are not valid XML entities without a declaration. Does SimpleDOM add the declarations?

Autres conseils

Forty-two's response defintely fixed one of the problems... I was putting encoding=iso-8859-1 in the xml doc but using utf-8 in the html meta content-type tag.

One other thing to note if anyone comes across this answer. I was also having brutal problems with the curved quote from a Windows document (copying text from Word 2007 into html form field on my site). There is a BIG difference between a curved quote and an apostrophe. On English keyboards Word interprets the upper-dash (an apostrophe) as a single curved quote. ISO-8859-1 does not have such an entity (its coded in the Windows-1252 "standard"). This was killing my XML documents as they were parsed by PHP from the form field. The solution was simple:

$var = htmlentities($var,ENT_QUOTES, "Windows-1252");

Other people have alluded to htmlentites and striptags... but it took me 4 half days to pull all this together. Hopefully save someone some time.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top