Jump to content

[SOLVED] html entities converts pound (£) incorectly?


Dragen

Recommended Posts

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.

Link to comment
Share on other sites

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 &amp;)

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..

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.