Posts Tagged “UTF-8”

A few days ago I started to write since some time a Plugin for WordPress again, for a customer. As I read over on WordPress you shall declare the files as UTF-8, but I would have changed it myself as well. Now after some initial testings I encountered this Problem:

Warning: Cannot modify header information - headers already sent by (output started at /xampp/htdocs/blog/wp-content/plugins/phRelatedLinks.php:1) in /xampp/htdocs/blog/wp-includes/pluggable.php on line 776)

Ah yeah…some known Problem within the WordPress Universe and the PHP one as well, caused by the Problem that infront of the starting < ?php are some other signs. Now when WordPress wants to send the header Information of the Page the whitespace/sign was already sent, but the header needs to be the first part of the website which is sent…therefore PHP throws this error.
Unfortunally this wasn’t the case for my Problem. As I had no clue what it could be else I searched for some time, and anything I could find told it’s a problem with leading signs before < ?php. Luckily I found this Post with the same Problem, which solved it.

While saving my file with SciTE as UTF-8, SciTE added a Byte Order Mask to the file, which isn’t needed at all as UTF-8 doesn’t encounter differences between big-Endian & little-Endian. Anyway it’s now widely used to easily tell apart UTF-8 and ISO-8859. So if a file contains as starting Bytes: EF BB BF it’s (mostly) a UTF-8 formatted file. But as these Bytes aren’t displayed within SciTE at all, you can go crazy with it. To write a file without this optional BOM you need to select as Encoding UTF-8 Cookie within SciTE.

Now the real cause was found, and it wasn’t WordPress who tried to drive me crazy at all. A look within PHP revealed that PHP isn’t able to interpret these Bytes as mark for a following UTF-8 Encoding. The related Bug Post was closed as won’t fix for PHP 5/4, the correct behavior will be implemented with PHP 6+.

In the meantime I hope that not too many other people will encounter that Problem and if, they’re able to find the solution faster than me!

Tags: none

Tags: Byte Order Mask, PHP, UTF-8

Comments 3 Comments »

Bad Behavior has blocked 1454 access attempts in the last 7 days.