Forum Moderators: coopster

Message Too Old, No Replies

htmlentities and the euro sign

         

Readie

1:24 pm on May 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm controlling the currency via a MySQL table, and I've currently got the € sign as the currency.

php.net says that declaring ISO-8859-15 as the charsheet for htmlentities() should add support for the euro symbol, but... It's not being converted :/

Even when entering it directly, like so:
echo htmlentities('€', ENT_QUOTES, 'ISO-8859-15');
It fails to convert, so I'm wondering if anyone who's had experience with this sort of thing before could offer some insight?

coopster

7:14 pm on May 17, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I use utf8 in both my headers coming from the HTTP server as well as in the meta element (for pages saved to the local machine after being delivered by a web server).
<?php 
print "€";
print "&#8364;";
?>

Both display the same for me.

Character entity references for markup-significant and internationalization characters [w3.org]

Readie

7:36 pm on May 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm using the UTF-8 charsheet, and in Firefox I'm getting the "unknown character" symbol when I echo it directly as €.

Got a work around, but I do wish I knew why htmlentities() wasn't converting it.

str_replace('€', '&#8364;', htmlentities($some_var, ENT_QUOTES))

coopster

10:26 pm on May 17, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Don't use htmlentities. It's unnecessary. If the euro symbol is being stored in your database or merely pasted into your code, you should be fine. Note that you should also save the document (php script) itself as having a text file encoding of UTF-8 -- and watch out for the byte order mark.

Readie

12:49 pm on May 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh, that might be where I was going wrong then. I was saving my PHP file in ANSI format.

jatar_k

1:32 pm on May 18, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



remember everywhere has to be the same

input page, db, output page

most errors are mismatches at one of the points. I had that same issue with save format last month, there are so many points it is easy to miss one.

Readie

3:42 pm on May 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, this is very wierd. When I use the keyboard shortcut (Alt Gr + 4) for the euro symbol, and try and echo that directly, it goes all mashed up.

If I echo &#8364; and copy that, then paste that into an echo, it comes out fine.

Stupid Windows.