Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt; &lt;price&gt;€10&lt;/price&gt; </code></pre> <p>The character <code>€</code> does not exist in ISO-8859-1, so this XML declaration can't possibly be right.</p> <p>The output <code>Á€</code> suggests the file has actually been encoded in Windows code page 1252 (Western European), which is similar to ISO-8859-1 but has different characters in the range 0x80–0x9F, include the euro sign.</p> <p>PHP has parsed the data as ISO-8859-1, where the CP1252 encoding of <code>€</code>, byte 0x80, maps to the control character U+0080. It then gives you the Unicode string containing U+0080 as a UTF-8-encoded byte string, U+00C2,U+0080. Outputting that to a browser in a page served as cp1252, ISO-8859-1 (for tedious confusing legacy reasons) or without a charset on a Western European machine, gives <code>Á€</code>. <code>htmlentities()</code> doesn't encode this in any way because there's no HTML entity for the control code U+0080.</p> <p>Here's how you should proceed:</p> <ul> <li><p>If you must have your XML input file in cp1252, state that in the XML declaration's <code>encoding="windows-1252"</code> rather than the inaccurate <code>ISO-8859-1</code>. XML parsers aren't required to be able to read cp1252, though, so better for interoperability would be to just use the default UTF-8 encoding and re-save the file to match.</p></li> <li><p>Serve your output HTML page as UTF-8, using a <code>Content-Type</code> header or meta tag. Then use <code>htmlspecialchars()</code> instead of <code>htmlentities()</code> so you don't waste time encoding non-ASCII characters that don't need it.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload