SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    make unicode work in php

    I encounter this problem, that i can not save a file with extension.php with unicode encoding character.

    To be clearer, I am working dream weaver, I use language software to input my own language into html, which worked well, the dreamweaver can save the code correctly and the browser display it correctly.

    However, when I type the language in file with php extension. The error message says "the document's current encoding can not correctly save all the characters within the document you may want to change it to UTF-8 or an encoding that support spacial characters in this document

    As a result of that, browser screws up my text.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, you might have some characters which aren't supported by unicode.

    As it says, try UTF instead.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Well, you might have some characters which aren't supported by unicode.

    As it says, try UTF instead.
    UTF-8 is part of Unicode standard so one can't be used instead of the other. I don't know Dreamweaver much at all and it really is Dreamweaver, not PHP, problem. Try looking in Dreamweaver's documentation, forums or contact support.

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    UTF is part of Unicode standard so one can't be used instead of the other
    Gotcha.

    @RunRunForest - is there a specific reason you want this encoding?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unicode is not an encoding. Unicode is a specification of characters. It's basically a pool of all characters, in any known language. It can be represented (encoded) in different ways. UTF-8 is one such encoding, which supports the full range unicode. ISO-8859-1 (Also known as latin1, and often confused with CP-1252) is a different encoding, which only supports a subset of unicode. ASCII is yet another encoding, which supports an even smaller subset of unicode. In order to write a character in your document, you need to use an encoding which supports that character. Since UTF-8 supports the full unicode range, it's usually a good choice, but a lot of applications still use ISO-8859-1, because it's enough for the English-speaking part of the world.

    In your case, you are probably saving your documents in ISO-8859-1, since this is the default for php. You can save your file as UTF-8 instead. If you do that, you will need to make sure that the page is also served as UTF-8, or the browser will interpret the file wrongly (Expecting it to be ISO-8859-1) and you'll get garbled characters. You can do this in different ways, but the simplest is probably to put the following line of php code at the top of your script (Before any HTML or other output):

    PHP Code:
    header("Content-Type: text/html; charset=utf-8"); 

  6. #6
    SitePoint Enthusiast toytron's Avatar
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want to add a form to your site, this could also be helpfull

  7. #7
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by decowski View Post
    UTF-8 is part of Unicode standard so one can't be used instead of the other. I don't know Dreamweaver much at all and it really is Dreamweaver, not PHP, problem. Try looking in Dreamweaver's documentation, forums or contact support.
    you're absolutely right, I bring the problem to a friend of mine. He asked me if I set the dreamweaver font encoding preferences for entire project to utf8 yet ? I said yes. Its weird, it should be no problem.

    He goes to the document where the problem is, pressing ctrl + J to open quick preference setting for font, its showing that particular document's font encoding is ISO-.....

    So why my preference wasn't applied to that document? Magic.

    But problem solved.

    note: one unexplainable thing is before i meet my friend, i type the language outside the php echo function, but still inside the php tag, the browser could display it correctly.

  8. #8
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by toytron View Post
    if you want to add a form to your site, this could also be helpfull
    Thanks for link dear. Its gonna fix funny characters in my database row


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
  •