9

I'm using Notepad++ for editing my PHP scripts.

However, I found a strange problem: when changing the encoding from ANSI to UTF-8 (without BOM), saving, closing, re-loading – then checking encoding: is still ANSI.

Any ideas what's wrong? It always worked for me in the past.

zx485
  • 2,337
Fuxi
  • 803

4 Answers4

11

This is expected behaviour.

It can happen that a file is saved with a certain encoding, but upon reopening it in Notepad++ it is detected with another encoding. This is a technical limitation and happens because sometimes the resulting file will not differ even though different encodings are used. This is most noticeable if the file is saved without a special BOM (Byte Order Mark) indicating the used encoding.

ANSI and UTF-8 share their first 128 characters (ASCII), making them indistinguishable if those are all you use. With a plain text file, there is no metadata indicating the encoding, so all Notepad++ (and other editors) can do is look at the characters/data in the file and take a guess.

  • If the file has a BOM, NP++ detects it and knows about the encoding.
  • If the file is HTML or XML, the encoding is read from the first line of the file.
  • Otherwise, NP++ takes a guess between UCS-2LE, UCS2-BE and ANSI. You cannot make a difference between a file encoded in UTF-8 without BOM and a file in ANSI with plenty of high ASCII characters.

http://sourceforge.net/projects/notepad-plus/forums/forum/331754/topic/3822723


In theory, PRacicot's answer should open all ANSI/UTF-8 files (without a BOM) as UTF-8. This is also recommended in an answer to a similar Stack Overflow question. If this doesn't work for you, I'm not sure what can be done. The encoding is indicated as ANSI as UTF-8 in the status bar, for me.

Bob
  • 63,170
7

You may want to change this setting in you're notepad++ preference.

Go in the menu Settings -> Preference -> New document/ Default Directory. In the suck section Encoding, check UTF-8 without BOM and check Apply to opened ANSI files.

By checking the Apply to opened ANSI files, this preference will also be apply to current opened documents in notepad++.

Since I don't have enough points yet to post image here is a link to postimage where I uploaded the image: http://postimage.org/image/4qza0bkv9/

Good Luck and happy programming.

PRacicot
  • 103
3

You have to Convert to ... instead of change the Encode to ... option.
You may also want to change this option in the settings, so all your new files will get created with your choosen encoding.

imuge

Apache
  • 16,299
0

I was able to do save as ANSI and worked fine, but a new version on Notepad++ added here a clickable selection to change CRLF to CR and LF for the correct systemThats Notepad++ latest version nov 2023