1
<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?

1
  • Please post the URL of the page. This will let us see the HTTP headers. Commented May 9, 2012 at 18:20

3 Answers 3

6

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:

  1. Configure your web server (I'm guessing Apache) to send the appropriate charset. See Apache docs for AddDefaultCharset.

  2. 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.

Sign up to request clarification or add additional context in comments.

Comments

1

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'); 

1 Comment

It's unlikely to make a difference. Although this is a good practice, modern browsers will tolerate any order.
0

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}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.