1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Page encoding

Discussion in 'HTML & Website Design' started by Chetan Tudor, Feb 6, 2016.

  1. #1
    Hello, I have a php script that generates a list of all cities from my country. The problem is that some romanian specific characters are not displayed( they are replaced by "?" signs). Page's meta information is that

    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
    List
    </body>
    </html>

    I have tried in two browsers.
    I am editing the file in cPanel's code editor, but I also downloaded the file, saved it on my computer with UTF-8 encoding and uploaded it again.

    Thanks.

    UPDATE: if I write those characters in the page, they are displayed ok, so the problem is that when php selects those records from database, doesn't recognisez those characters

    SOLVED:
    mysqli_set_charset($db_conn,"utf8") - before the query to the DB
     
    Solved! View solution.
    Last edited: Feb 6, 2016
    Chetan Tudor, Feb 6, 2016 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    Make sure your database is set up to save as utf-8.

    gary

    //edit: I stopped reading too soon. :shrug: It is good that you fixed it. ~gt
     
    kk5st, Feb 6, 2016 IP
  3. Chetan Tudor

    Chetan Tudor Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #3
    It's ok :))
     
    Chetan Tudor, Feb 6, 2016 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Also if you're going to go ahead and use a HTML 5 doctype, you might as well use the HTML 5 charset declaration instead of the outdated http-equiv:
    <meta charset="utf-8">

    Is WAY simpler. NOT that it really matters on deployment since your ACTUAL http headers should be setting that, and if it's setting anything else, the one in the markup is ignored anyways.

    "real world" the only time that charset declaration should do anything is if you are serving it as a local file instead of via a web server.

    Just an observation; something to keep in mind.
     
    deathshadow, Feb 6, 2016 IP
  5. Chetan Tudor

    Chetan Tudor Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #5
    Sorry for the late answer. I read that HTML5 uses utf-8 by default so '<meta charset="utf-8">' is not needed( theoretically ). What do you think about that ?
     
    Chetan Tudor, Feb 16, 2016 IP
  6. #6
    Considering SERVERS by default send iso-8859-1 and that HTTP headers by definition override the any http-equiv or charset declarations, the charset meta is meaningless when deployed from a real server anyways unless you disable what the server sends in the response headers. (PHP's header command for example, or via htaccess).

    The only real reason to have a charset declaration is as a fallback during local testing on static code, or should the server fail to send headers properly. Once you are sending it from a real server software like iiS, ngnix or Apache, 99% of what people try to set from http-equiv doesn't matter one way or the other.

    Which is why that declaration, or the old http-equiv can be completely meaningless if the server is still saying the default!
     
    deathshadow, Feb 17, 2016 IP
  7. Chetan Tudor

    Chetan Tudor Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #7
    Even if I have solved the problem and theoretically my answer is the best I will give you "the best answer" because it will be very useful for those who will read the post. Thank you, again !
     
    Chetan Tudor, Feb 20, 2016 IP