Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts

    header or meta for UTF-8?

    Hello all

    I have changed my site to php pages so I can use php to include header file

    but now I'm unsure if I should be using a header or meta tag to indicate the charset

    ie which one of these is correct? Should I use a header and a meta tag?

    At the moment i'm using version 2 which seems to be ok.

    There is no other php involved other than the 'include' at the moment.


    1)
    PHP Code:
    <?php    
    header
    ('Content-Type: text/html; charset=UTF-8');
    ?>
    <!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>

    <!-- Leave this out <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > -->

    </head>
    <body>
    <?php include_once ('includes/header.php'?>
    OR

    2)
    PHP Code:
    <?php

    // header('Content-Type: text/html; charset=UTF-8'); //Leave this out

    ?>
    <!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" >

    </head>
    <body>
    <?php include_once ('includes/header.php'?>
    help very much appreciated

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #2
    12k
    12k is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Either one should work fine. It just tells the browser how to read the text.

  • Users who have thanked 12k for this post:

    low tech (01-17-2012)

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Any meta http-equiv is just an attempt to apply the header info after the page has started to load. Sometimes this is allowed and sometimes it isn't. Where you have access to set the http header directly there is no reason why you should use http-equiv to try to set it later than where it is supposed to be set.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    low tech (01-17-2012)

  • #4
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi felgal

    Any meta http-equiv is just an attempt to apply the header info after the page has started to load. Sometimes this is allowed and sometimes it isn't. Where you have access to set the http header directly there is no reason why you should use http-equiv to try to set it later than where it is supposed to be set.

    That makes sense ---- so method 1 -- use php header


    Thanks

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •