Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Problem with specials characters and php

  1. #11
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by traq View Post
    Note that many web hosts automatically send a charset declaration for you, and it's not always utf-8 (some version of ISO-8859 is very common).

    Setting the charset in your HTML markup is not sufficient in most cases ([almost?] all browsers will ignore the html charset if the server sends a content-type header).
    Quote Originally Posted by traq View Post
    You need to send an HTTP header with the correct charset: the charset in your html markup will not be sufficient.
    If you don't know what an HTTP header is, read more here.

    HTTP ("internet") requests/responses consist of two parts: the headers and the body. An HTTP response looks something like this, for example:
    Code:
    HTTP/1.1 200 OK
    Date: Mon, 23 May 2005 22:38:34 GMT
    Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
    Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
    ETag: "3f80f-1b6-3e1cb03b"
    Content-Type: text/html; charset=UTF-8
    Content-Length: 131
    Accept-Ranges: bytes
    Connection: close
    
    <html>
    <head>
      <title>An Example Page</title>
    </head>
    <body>
      Hello World, this is a very simple HTML document.
    </body>
    </html>
    The Headers are in the top portion; the Body is everything below the blank line. Note that that means all of your HTML is part of the HTTP body. It is a bit confusing, because HTML uses the same terms ("<head>" and "<body>") with html-specific meanings. So, what's happening in your case is something like this:
    Code:
    HTTP/1.1 200 OK
    Content-Type: text/html; charset=ISO-8859-1
    Other-Headers: etc..
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>Untitled Document</title> 
    </head> 
    <body> 
        <!-- the rest of your html ... -->
    See how the HTTP headers say one thing ("ISO-8859-1") and the HTTP body says something else ("UTF-8", in your <meta> tag)? Almost every browser (indeed, every browser period, as far as I know) will believe the HTTP header, and ignore the meta tag. The only time specifying the charset in your html will have any effect is when no corresponding HTTP header is sent—in fact, that's the situation they were designed for.

    Since your server is automatically setting a header with the wrong charset, you need to specify the correct one. That's exactly what the header function does.
    PHP Code:
    <?php

    header
    "Content-type: text/html; charset=UTF-8" );

    //  etc. ...
    Last edited by traq; 02-14-2014 at 11:34 PM.

  2. #12
    Join Date
    Apr 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I have changed the charset in the meta tag to charset=ISO-8859-1 and all problems are gone !

  3. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by paldo View Post
    I have changed the charset in the meta tag to charset=ISO-8859-1 and all problems are gone !
    Glad to hear it. I would still suggest considering UTF-8: it includes nearly every character of every written language, is highly interoperable, and has become the de-facto standard in the computing world. In the long run, it's the better choice.

    If your question has been answered, please mark your thread "resolved":
    • On your original post (post #1), click [edit], then click [go advanced].
    • In the "thread prefix" box, select "Resolved".
    • Click [save changes].

  4. The Following User Says Thank You to traq For This Useful Post:

    paldo (02-17-2014)

  5. #14
    Join Date
    Apr 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    For the moment being I will leave the script in charset=ISO-8859-1 until I have understood the theory behind charsets and their implementation in a php script. Thanks for your help.

Similar Threads

  1. problem with chinese characters
    By paldo in forum HTML
    Replies: 8
    Last Post: 02-11-2014, 08:39 PM
  2. problem with characters...
    By jonybigude in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 05-14-2011, 10:54 PM
  3. Fix to problem displaying RSS feed with accented characters
    By robokev in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 09-22-2008, 05:03 AM
  4. Ajax Tabs Content Script - problem with non alpha-numeric characters
    By masamasa in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 07-25-2008, 02:54 PM
  5. Parsing problem with characters " & < > "
    By SuperLes2006 in forum JavaScript
    Replies: 5
    Last Post: 01-17-2006, 04:21 PM

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
  •