shin
shin

Reputation: 32721

Coding in UTF-8 problem

I am using notepad++ for php coding.

I don't have any problem with format set up using Encode in ANSI.

However when I use Encode in UTF-8, either I have a strange character at the top or not showing anything.

Q1. Am I supposed to use ANSI? Q2. Why do I am not able to display anything when I use UTF-8

My sourse code for the header is following.

<html>
<head>
<title>Hello, PHPlot!</title>
</head>

Is that because I am not using UTF-8 in the header?

Upvotes: 2

Views: 448

Answers (3)

Alex Barrett
Alex Barrett

Reputation: 16455

As Tom Haigh says, it's probably the BOM. It's not necessary for UTF-8 encoding, so you can safely leave them out.

However I should point out that PHP has very weak support for UTF-8 - be prepared for a bumpy ride. Take a look at this page for some details on problems you might encounter.

Upvotes: 0

Quentin
Quentin

Reputation: 943518

It sounds like you are using UTF-8 with a BOM (which has issues) and your server is failing to specify the encoding correctly.

IIRC, BOM is unavoidable in Notepad, so I would suggest using a better editor. I'm fond of Komodo Edit myself.

(Also note, that a Doctype is required in HTML documents)

Upvotes: 0

Tom Haigh
Tom Haigh

Reputation: 57815

It's probably a Byte Order Mark. You can use the 'Encode in UTF-8 without BOM' mode in notepad++.

This question has some helpful information about using UTF-8 with PHP. You will also (as you suggested) need to set the content type in either the header or a meta tag in order for the browser to interpret it correctly.

Upvotes: 7

Related Questions