Dragen Posted November 11, 2009 Share Posted November 11, 2009 Hi, Can anyone tell me why, when I use htmlentities on the pound symbol (£), instead of converting it to £ as expected, it changes it to £? I have a form in which users can enter information and I am using htmlentities on it and when it is output it returns all of the pound signs as above. Any ides? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/181164-solved-html-entities-converts-pound-%C2%A3-incorectly/ Share on other sites More sharing options...
Psycho Posted November 11, 2009 Share Posted November 11, 2009 Works fine for me. May be a problem due to the region settings on the server or the client. Can you post example of the EXACT input and the EXACT output. For the output, I am referring to the raw HTML code, not what is displayed in the browser. Quote Link to comment https://forums.phpfreaks.com/topic/181164-solved-html-entities-converts-pound-%C2%A3-incorectly/#findComment-955779 Share on other sites More sharing options...
Dragen Posted November 11, 2009 Author Share Posted November 11, 2009 hm, strange. It's all on a British server and also the same on my local server. The input is the following (taken directly from a textarea in thet form): WE ARE DELIGHTED TO OFFER FREE SHIPPING ON ALL ORDERS OVER £20.00! (UK ONLY) And here's part of the code that processes it: $var = html_entity_decode(trim($var)); echo $var.'<br />'; $var = htmlentities($var, ENT_COMPAT, 'ISO-8859-15'); echo 'htmlentities: '.$var.'<br />'; return $var; I use entity decode to ensure that when I encode, I'm not double encoding (ending up with things like &) The first echo statement outputs the text correctly (although the pound sign is not encoded as £, obviously). After the htmlentities, I echo again, but now the output is as follows: WE ARE DELIGHTED TO OFFER FREE SHIPPING ON ALL ORDERS OVER £20.00! (UK ONLY) That's taken from the source view. Strangely it appears to have encoded the pound AND added the  which has also been encoded.. Quote Link to comment https://forums.phpfreaks.com/topic/181164-solved-html-entities-converts-pound-%C2%A3-incorectly/#findComment-955786 Share on other sites More sharing options...
Dragen Posted November 11, 2009 Author Share Posted November 11, 2009 I found this, which appears to be the same, or similar, problem: http://bugs.php.net/bug.php?id=39075 Although I don't understand what the answer means? Quote Link to comment https://forums.phpfreaks.com/topic/181164-solved-html-entities-converts-pound-%C2%A3-incorectly/#findComment-955857 Share on other sites More sharing options...
Dragen Posted November 11, 2009 Author Share Posted November 11, 2009 Okay, Sorry for the tripple post, but I've found the solution. The problem was that my web page was using charset UTF-8 whereas it appears this doesn't understand the pound symbol properly? I've now changed it to charset ISO-8859-15, which seems to have fixed the problem! Quote Link to comment https://forums.phpfreaks.com/topic/181164-solved-html-entities-converts-pound-%C2%A3-incorectly/#findComment-955866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.