Displaying special characters?

Discussion in 'HTML & Website Design' started by Triexa, Jan 10, 2007.

  1. #1
    I have the following in a file:
    Příšerně žluťoučký kůň úpěl ďábelské ódy

    When I print it out using (PHP) htmlspecialchars(utf8_decode($line), ENT_QUOTES) I get:

    P?�?ern? ?lu?ou?k� k?? �p?l ?�belsk� �dy

    Can anyone help me so that it will display correctly?
     
    Triexa, Jan 10, 2007 IP
  2. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you have a !DOCTYPE line at the start of your document? Perhaps the browser is using a different encoding table and you need to specify the correct one.
     
    rb3m, Jan 10, 2007 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    What are you trying to get? I've not used that particular combination of functions.

    I did this
    
    <?php
    
    $str = "P&#x159;&#xED;&#x161;ern&#x11B; &#x17E;lu&#x165;ou&#x10D;k&#xFD; k&#x16F;&#x148; &#xFA;p&#x11B;l &#x10F;&#xE1;belsk&#xE9; &#xF3;dy
    
    echo $str . "<br /><br />";
    
    echo htmlspecialchars($str) . "<br /><br />";
    
    echo htmlspecialchars_decode($str);
    
    ?>
    Code (markup):
    which renders this in the browser
    
    Příšerně žluťoučký kůň úpěl ďábelské ódy
    
    P&#x159;&#xED;&#x161;ern&#x11B; &#x17E;lu&#x165;ou&#x10D;k&#xFD; k&#x16F;&#x148; &#xFA;p&#x11B;l &#x10F;&#xE1;belsk&#xE9; &#xF3;dy
    
    Příšerně žluťoučký kůň úpěl ďábelské ódy
    Code (markup):
    But, my server has this for the response header
    I think rb3m is on the right track. What response header does your server produce? The default is likely no charset, ASCII or iso-8859-1, depending on the server, its age and its administrator. Apache now defaults to iso-8859-1. Few if any browsers pay much attention to the http-equiv tag's charset. You'd best ask your web server admin to specify utf-8 or add "AddDefaultCharset utf-8" to your .htaccess file.

    cheers,

    gary
     
    kk5st, Jan 10, 2007 IP