9 Replies - 4679 Views - Last Post: 05 August 2012 - 12:06 PM

#1 Zarlach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 12

Notepad++ Encoding Problem

Posted 22 July 2012 - 05:50 PM

Hi, I am about to go crazy with this encoding problem I have. :wacko:
I'm at the moment working on my website where I do sometimes use other characters (than English) like "". In the beginning it was all fine and it displayed as it should. Then suddenly they all turned into weird characters like "å". I took a look at my html code to see if I had set any UTF-8 which I have had problems with before, however, no type was set.

After googling, I find that my Notepad++ is set to ANSI, and some people were recommending to set to UTF-8. However, when I tried doing that, a "Header has already sent" PHP error suddenly appeared. :eek: (Yes, it was caused by changing to utf-8)

So, basically what I need is suggestions for what to do. Apparently, most (if not all) of my php files are encoded in ANSI. Do I have to change them all? I've never been into encoding before.

Is This A Good Question/Topic? 0
  • +

Replies To: Notepad++ Encoding Problem

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 856
  • View blog
  • Posts: 2,248
  • Joined: 28-March 11

Re: Notepad++ Encoding Problem

Posted 22 July 2012 - 05:58 PM

Did you check in the "Encoding" menu?

Also, under Settings > Preferences > New Doc you can set the format for new docs, and the encoding.

There is more than one "Unicode" file encoding.
Was This Post Helpful? 1
  • +
  • -

#3 Zarlach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 12

Re: Notepad++ Encoding Problem

Posted 22 July 2012 - 06:05 PM

Yes, I was changing to UTF-8 in the Encoding menu when I got the PHP error.

So I basically have to convert all of my php files into utf-8?
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5960
  • View blog
  • Posts: 23,238
  • Joined: 23-August 08

Re: Notepad++ Encoding Problem

Posted 28 July 2012 - 08:39 AM

Hmmm, a little late to the party here.

I'm guessing the "headers already sent" error in PHP are because the BOM (byte-order marker) is being set when saving the UTF8-encoded files, and that's resulting in output to the browser. Make sure, if it's a possibility, that you don't save the BOMs. There might be a setting in Notepad++.
Was This Post Helpful? 1
  • +
  • -

#5 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3637
  • View blog
  • Posts: 5,765
  • Joined: 08-June 10

Re: Notepad++ Encoding Problem

Posted 28 July 2012 - 10:02 AM

Yes, that's exactly it JackOfAllTrades. PHP doesn't really support Unicode, but because of the way strings are saved you can actually use UTF-8 documents without problems if you save it as an ANSI file. (Which is basically the same as an UTF-8 file without the BOM.)

Notepad++ has the "Encode UTF-8 without BOM" option to allow for this.
Was This Post Helpful? 0
  • +
  • -

#6 Zarlach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 12

Re: Notepad++ Encoding Problem

Posted 05 August 2012 - 10:21 AM

Ok, so when I set the PHP file that starts the session and the PHP file that includes the PHP file to UTF-8 without BOM, I got rid of the PHP error, if the PHP file which includes the other is UTF-8, the PHP error will come back. However, when echoing something out from the database with non-english characters, they get this question mark symbol (�). Is this a problem on the database's side? I checked the database and it said: "MySQL charset: UTF-8 Unicode (utf8)" and "MySQL connection collation: utf8_general_ci".

I can type any weird character manually in notepad++, and they will display as normal on the website, even the same characters which is fetched from the DB. :wacko:

I tried using
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
and all files ANSI, and it work without any problems. Is it a bad idea to use this? (Since it says windows-1252, will it be different on another OS?), About every website I see uses UTF-8 without any problems.

This post has been edited by Zarlach: 05 August 2012 - 10:22 AM

Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3637
  • View blog
  • Posts: 5,765
  • Joined: 08-June 10

Re: Notepad++ Encoding Problem

Posted 05 August 2012 - 10:32 AM

How are you connecting to MySQL from PHP? It could be that the connection from PHP to MySQL is not encoded correctly. Then any data coming in from MySQL would be corrupted before it even reaches the PHP code.
Was This Post Helpful? 0
  • +
  • -

#8 Zarlach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 12

Re: Notepad++ Encoding Problem

Posted 05 August 2012 - 10:40 AM

I'm using PDO
$conn = new PDO('mysql:host=localhost;dbname=website', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


I realized the file that is used to connect was ANSI, however, it didn't make any difference changing it to UTF-8 or UTF-8 without BOM.

This post has been edited by Zarlach: 05 August 2012 - 10:41 AM

Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3637
  • View blog
  • Posts: 5,765
  • Joined: 08-June 10

Re: Notepad++ Encoding Problem

Posted 05 August 2012 - 11:25 AM

Do you set the encoding for the PDO connection?

Try this:
$conn->exec("SET NAMES 'utf8'");



In reality, it doesn't really matter what encoding the PHP files have unless you have UTF-8 characters outside the ASCII range encoded into the PHP code itself. As such, most PHP files, even those serving UTF-8 data, are fine being encoded as ASCII. UTF-8 is, after all, a super-set of ASCII (ISO-8859-1), so any ASCII character in the PHP document will translate directly into the HTML even if the HTML has UTF-8 specified with the the mime-type.
Was This Post Helpful? 2
  • +
  • -

#10 Zarlach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 12

Re: Notepad++ Encoding Problem

Posted 05 August 2012 - 12:06 PM

Thanks! It worked like a charm.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1