SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict justjon's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with UTF-8

    Hi,

    I'm having a probelm displaying Chinese characters using UTF-8.
    When I test the page locally the text displays fine but as soon as I upload it to an external server all hell breaks loose and I get random characters etc.

    I've included the following:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    I've also tried converting the document to PHP and adding <?php header ('Content-Type: text/html; charset=utf-8' ); ?> which has also not helped.

    Any help with this would be very very very appreciated as I'm running to a tight dealine.

    Thanks in advance.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What Content-Type header is the server sending?
    Can you provide a link, so we can check if you're not sure?
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While I doubt it has anything to do with it, are you using an XHTML doctype?

    It's better to send the headers with PHP rather than using a "<META ...>" tag. Use "<?php header ('Content-Type: application/xml+xhtml; charset=utf-8' ); ?> if you are using XHTML.
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  4. #4
    SitePoint Addict justjon's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quick responses guys.

    Quote Originally Posted by BluDragon
    <?php header ('Content-Type: application/xml+xhtml; charset=utf-8' ); ?> if you are using XHTML.
    I gave this a go, but for some reason the browser now wants to download instead of view the page.

    URL to one of the problem pages:

    http://www.reactivespace.co.uk/test/test.php

  5. #5
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems like the document is saved as Shift_JIS. You can change the Content-Type header to send that encoding information, or use e.g. this online converter to convert the document to UTF-8. http://kanjidict.stc.cx/recode.php

    IE doesn't recognize the MIME type application/xhtml+xml, and also doesn't supports the XHTML namespace.
    Simon Pieters

  6. #6
    SitePoint Addict justjon's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zcorpan
    It seems like the document is saved as Shift_JIS. You can change the Content-Type header to send that encoding information, or use e.g. this online converter to convert the document to UTF-8. http://kanjidict.stc.cx/recode.php
    Shift_JIS? Would there be any reason for this? The document was created and saved in Dreamweaver with text copied from Word. Is there a process I should be going through to save as UTF-8 rather than Shift_JIS?

  7. #7
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know what the reason is, but selecting that encoding in View > encoding in Firefox seems to get the correct characters.

    Perhaps you should try with another editor than DW.
    Simon Pieters

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the server is sending UTF-8, but apparently your page is not encoded with UTF-8.

    (Besides, the correct media type for XHTML is application/xhtml+xml, the advice above switched the last two parts around. )
    Birnam wood is come to Dunsinane

  9. #9
    SitePoint Addict justjon's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I don't understand, is that it works fine when tested locally and every single character is perfect, when exactly the same file is uploaded and tested it turns into all sorts of things. This leads me to believe it's something the server is doing, but I've tested it on 2 servers now and both do the same. I created a bare-bones version using TextEdit:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    ??????????????????????????
    </body>
    </html>

    I still get the same. Fine when tested locally but not when uploaded???
    When I switch to Shift_JIS view in Firefox (which I think is Japanese) it looks better but it's no longer in Chinese! and many of the Characters still default.

    Anyone got any other ideas?

  10. #10
    SitePoint Addict justjon's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The question marks were Chinese. Honest.

  11. #11
    SitePoint Addict justjon's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    237
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?


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
  •