简体   繁体   中英

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?

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.

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM