1

I'm trying to grasp UTF-8 and charset encoding in general, but it's tricky

This code:

<?php
header('Content-type: text/html; charset=utf-8');
?>
<!doctype html>
<html lang="da">
<head>
<title>UTF-8 test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<p>UTF-8 æøå tést Señor!</p>
</div>
</body>
</html>

Outputs:

UTF-8 ��� t�st Se�or!

Same result on both local server and on multiple public sites (all Apache) Do I need to change something in php? Or Apache? Or my text editor? (notepad++)

2 Answers 2

5

Your text editor isn't saving as UTF-8.

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

1 Comment

So simple it hurts. Damn, I've been reading and trying many guides on how to fix php/apache encoding. Thanks ;)
2

I think you should change the character encoding of your notepad++, you can change this under "Encoding" menu.

you can check your right corner of status bar for the encoding of your file.

2 Comments

Right, but note that for existing data, you need to select the command (in the Encoding menu of Notepad++) for converting to UTF-8 format. For new files, it is sufficient to initially set encoding to UTF-8. You can also set (in Settings) the default encoding for new files to UTF-8.
@Jukka I just selected "code in UTF-8" (not convert) in the existing file, and it switched and worked.

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.