Reputation: 5896
<html>
<head>
<title>тест</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
I have set the meta tag, but every time I open up the browser (Chrome), I have to go to Tools -> Encoding
and set encoding on UTF-8
in order to make it work.
Is there a way to avoid this step so browser displays proper UTF-8?
Upvotes: 1
Views: 3994
Reputation: 1
When you use a text editor to view your content try to see your enconding: If the file enconding is different use this PowerShell script to change your enconding to UTF-8. After that you need to upload again your files into teh web server.
Get-ChildItem *.php -Recurse | ForEach-Object {
$content = $_ | Get-Content
Set-Content -PassThru $_.Fullname $content -Encoding UTF8 -Force}
Upvotes: 0
Reputation: 6513
The correct order is
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>тест</title>
Also include before any other output on the php code, and even before the embedd html:
header('Content-Type: text/html; charset=utf-8');
Upvotes: 1
Reputation: 162851
Your web server is probably sending a Content-Type
header with a different charset
. This will take precedence over your <meta>
tag. Confirm this on the command line using curl
(*nix system required):
curl -i http://example.com/yourpage.php
Look at the http headers at the beginning of the response and find the Content-Type
header.
You can remedy this in a couple of ways:
Configure your web server (I'm guessing Apache) to send the appropriate charset. See Apache docs for AddDefaultCharset
.
Set the Content-Type
header just in your script using the header()
function. Like this:
header('Content-Type: text/html; charset=UTF-8');
But make sure to put this call before any other output to the browser or else PHP will choke.
Upvotes: 6