What is a HTTP header? What is a charset?
I am new to the worl开发者_如何学Pythond of coding as well as PHP and XHTML. I was just going through the details of meta tags and do not understand the property http-equiv nor what is the charset used for as well as what the value UTF-8 refers to e.g. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
.
There's a really good article by Joel Spolsky that discusses charsets. Take a look:
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
As for HTTP headers, a quick Google search for "understanding HTTP headers" turned up quite a few good articles that describe them. Here's one: HTTP Headers for Dummies.
In short, HTTP headers are basically small messages that get sent to the user's web browser that tell the browser about the output it's going to receive (ie, is it a web page, a file, an image; should it be cached; etc), or for things like cookies that should be saved by the client's browser.
HTTP headers are also sent from the user's web browser back to the server. The most obvious example are again, cookies - every cookie that is saved by the browser is supposed to be sent back to the server on each HTTP request.
In your case, you're probably talking about a specific HTTP header that defines the character set for the page. The <meta http-equiv="">
tags are used to simulate HTTP headers.
For example, if you had a static HTML page and wanted to take advantage of a particular HTTP header, but couldn't configure it in the web server, you could use a <meta http-equiv="">
tag to achieve the same result.
@Ryan: Great link. I wish I had read the article 12 years ago before I embarked on a large international CMS implementation.
In simple terms, when the browser receives an HTTP response stream (the web page that was requested), all it sees is a sequence of bytes. Because bytes can mean different characters, depending on the encoding that was used by the server, it is very important that the browser uses the encoding specified in the meta tag when interpreting the byte stream. If the server used a different encoding than what it put in the meta tag, you will see gibberish.
Conversely, the HTTP request associated with a web page POST also has an encoding that is provided transparently by the browser, because the server needs to know how to interpret any form data that was sent.
精彩评论