SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Special character encoding

    I'm sure this should be easy, but for some reason it is escaping me. No pun intended.

    I have the following code

    PHP Code:
    header('Content-Type: text/plain; charset=UTF-8');
    echo 
    htmlentities('Montréal'); 
    which returns

    Code:
    Montréal
    I would like it to return

    Code:
    Montréal

    Any suggestions would be appreciated.

  2. #2
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Since you are using UTF-8, you don't need to escape anything.
    Can output it as is.

    In any case you want:
    PHP Code:
    htmlentities'Montréal'ENT_QUOTES'utf-8' ); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Since you are using UTF-8, you don't need to escape anything.
    Can output it as is.

    In any case you want:
    PHP Code:
    htmlentities'Montréal'ENT_QUOTES'utf-8' ); 
    Thanks - that works.

    However, I don't know what you mean by "you are using UTF-8, you don't need to escape anything"? If I don't encode Montréal, I get question marks in place of the special character...

  4. #4
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You are saving the file and editing the file using UTF-8 right? The é is capable of being directly inserted into a file and displayed in a browser if both are using UTF-8 as the character set.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    You are saving the file and editing the file using UTF-8 right? The é is capable of being directly inserted into a file and displayed in a browser if both are using UTF-8 as the character set.
    Interesting. I just ran some tests, and I see what you are saying when it comes to static files. But, when I select 'Montréal' from a MySQl database (using PHP), I get a question mark instead of the acute e.

    Any idea why this would be?

  6. #6
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Sounds like the connection between PHP and MySQL is not sending the data as UTF-8.
    http://pureform.wordpress.com/2008/0...tf-8-friendly/
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

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