Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: Euro woes

  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    Euro woes

    I'm having real trouble displaying the euro character on one of the sites I'm working on. Most of my current clients are located in France so I'm familiar with working with euro symbols and accents etc, none of my other sites have this problem.

    The database is utf8_general_ci and I have set this in the page:

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    &euro; displays fine but the data is free-text input by the client and I can't expect him to use &euro; instead of €. Interestingly - it displays fine in phpMyAdmin too (running on the same server). I've tried using htmlentities in the hope that it would convert € to &euro; but no luck and using htmlentities($data,ENT_COMPAT,'UTF-8') actually displays nothing at all.

    Any ideas?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Are the other unicode symbols OK?
    Last edited by abduraooft; 08-06-2008 at 12:02 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I tried a bunch of other currency symbols and they all came up as 'FFFD' blocks in FF3 or question marks - except this ₧ which came up as a P

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Tried str_replace() or urlencode() or rawurlencode()?

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    str_replace('€','&euro;',$data) works but surely that should be covered in htmlentities? Is there some function I can use to convert all unicode characters to their named equivalents?

  • #6
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    It looks like you're not the only one frustrated with not being able to convert all characters to their html equiv - just grepping the comments on php.net for "euro" I found: http://us3.php.net/manual/en/functio...ties.php#84327 and a few decent follow up posts. Hope it helps!
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #7
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I did some more playing around and this:

    PHP Code:
    echo htmlentities($value,ENT_COMPAT,'UTF-8'); 
    outputs nothing if the $value contains the euro symbol or a pound symbol - presumably others too - I've even set header('Content-type: text/html; charset=utf-8'); as is suggested on the htmlentities page but it seems to just die quietly inside or something when trying to use UTF-8 in htmlentities

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by NancyJ View Post
    I did some more playing around and this:

    PHP Code:
    echo htmlentities($value,ENT_COMPAT,'UTF-8'); 
    outputs nothing if the $value contains the euro symbol or a pound symbol - presumably others too - I've even set header('Content-type: text/html; charset=utf-8'); as is suggested on the htmlentities page but it seems to just die quietly inside or something when trying to use UTF-8 in htmlentities
    first step is the form, next is conversion from utf-8 to html entities:

    http://www.crazysquirrel.com/computi...-encoding.jspx

    I don't think is a proper solution for that, more a hack.

    regards

  • #9
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    What form?

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by NancyJ View Post
    What form?
    Quote Originally Posted by NancyJ View Post
    &euro; displays fine but the data is free-text input by the client and I can't expect him to use &euro; instead of €.
    I assume that come from a form,

    regards

  • #11
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by NancyJ View Post
    outputs nothing if the $value contains the euro symbol or a pound symbol - presumably others too - I've even set header('Content-type: text/html; charset=utf-8'); as is suggested on the htmlentities page but it seems to just die quietly inside or something when trying to use UTF-8 in htmlentities
    If it outputs nothing, then the input isn't a valid UTF-8 string. It's probably being imported incorrectly upon being added (the behaviour of HTML UAs is totally non-obvious with regards to character sets, but websites rely upon the bizzarity so there's little chance of it changing).

  • #12
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Nancy, would it be agreeable for your clients, if they had to type 'EUR' and then you used a REGEX, to store '&euro;' The when if displaying it on a page (either in their admin pages or a public web page), your scripts could enusre that it always was stored as &euro;

    Just a suggestion from a rusty/tired brain.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •