How do I ensure the British Pound Sterling Sign (£) appears correctly?
encoding, php, utf-8, xml
Solution
The problem with character encoding is if some program or process, at any step, fails to deal with it correctly then characters can be munged.
So, you have
- An HTML page that's
- making an AJAX call which
- runs some code on the server that
- builds an XML response froman XML file that is
- returned to the browser and displayed in a text box
So, ideally, at every step, you want UTF-8 encoding. It's likely at some step in the process your character is getting munged. Here's the steps I'd take to track this down
- Make sure that your HTML/PHP page has the correct Meta Tag
- Make sure that your HTML/PHP text file is saved as UTF-8
- Make sure that your XML file that's read from has been saved as UTF-8
- Make sure that your XML file that's read from and the response you build both have their encoding set in the prolouge <?xml version="1.0" encoding="utf-8"?>
- Make sure that the response headers of your server are sending out utf-8
- Call your service manually in a browser to see if the symbol is being returned correctly
Problem
I have a PHP script that reads in data from an XML file, returns it via AJAX to a page which then places the data in to the relevant text area. The Content-Type of the page is as follows: ``` <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> ``` The XML heading looks like this: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY pound "£"> ]> ... ``` The problem is that when the data arrives in the text box it has the character  before it. I was under the impression that setting the content type to UTF-8 fixes this problem but I must be wrong. Can anyone tell me which encoding type I need to use to get it to render consistently?