Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-16-2012, 07:12 AM   PM User | #1
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
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
__________________
Ask not what can I do for myself, but what can I do for others

"The greatest revenge is to accomplish what others say you cannot do."
~ Unknown
low tech is offline   Reply With Quote
Old 01-16-2012, 07:43 AM   PM User | #2
12k
New Coder

 
Join Date: Jan 2012
Posts: 29
Thanks: 0
Thanked 6 Times in 6 Posts
12k is an unknown quantity at this point
Either one should work fine. It just tells the browser how to read the text.
12k is offline   Reply With Quote
Users who have thanked 12k for this post:
low tech (01-17-2012)
Old 01-16-2012, 08:40 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
low tech (01-17-2012)
Old 01-17-2012, 12:10 AM   PM User | #4
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
Hi felgal

Quote:
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
__________________
Ask not what can I do for myself, but what can I do for others

"The greatest revenge is to accomplish what others say you cannot do."
~ Unknown
low tech is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:41 PM.


Advertisement
Log in to turn off these ads.