Subtle Development Space
Subtle Development Space

Reputation: 1254

Why does UTF-8 work in one of my PHP files, but not the other?

I use <meta http-equiv="content-type" content="text/html; charset=utf-8" /> in my PHP files to enable characters like ąčęė....

In my index.php file, text produced by HTML or PHP looks fine, but in another file (miestai.php) text written by PHP looks fine, but text written by HTML is messed up (instead of ą I get �).

When I remove <meta http-equiv="content-type" content="text/html; charset=utf-8" /> from that file, text written by HTML looks fine, but text written by PHP is messed up.

How can I fix this problem?

Note: both files are in the same folder. I even pasted all content from index.php to miestai.php but I still got the same problem.

Upvotes: 1

Views: 138

Answers (2)

user1329212
user1329212

Reputation:

Your script may be saved as ANSI. You should save your document as UTF-8 without BOM. Save as like that. (You should convert it for this you can use Notepad ++)

Upvotes: 2

Esailija
Esailija

Reputation: 140220

almost always means something is not encoded in UTF-8 but is being interpreted as UTF-8. You need to go UTF-8 all the way through, not just in headers. Save your files in UTF-8, set your database to use UTF-8 and so on.

If you have these strings literally in your PHP files, then those files are not saved in UTF-8. As in:

<?php
header("Content-Type: text/html; charset=utf-8");
echo "äöäöää"; //if this shows up as ������ this file was not saved in UTF-8

Upvotes: 4

Related Questions