# PHP5.3.0-dev and Unicode BOM.

- Thread: https://externals.io/message/35970
- Original archive: https://news-web.php.net/php.internals/35970
- Started by Richard Quadling on 2008-03-05T10:21:14+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #35970 — Richard Quadling — 2008-03-05T10:21:14+00:00

URL: https://externals.io/message/35970#35970

Hi.

I don't know if it is a bug or not.

But, having just inherited a load of code which are UTF-8 encoded and
all have a BOM marker, all the BOM markers are being sent to the
browser. This screws up sessions as output is sent before headers
(obviously).

The files are english/non english mix, so I'm assuming the BOM needs
to be present to indicate the order of the encoding (I'm new to the
Unicode stuff, so this is my first real work with anything other than
pure english PHP code). Because of this assumption, I think I can't
remove the BOM marker.

In case it matters, I'm using Win32 PHP5.3.0-dev snapshot built on Mar
4 2008 04:17:22.

I only recently upgraded the PHP dev, and as far as I can tell this is
a new problem, so I'm thinking prior to the upgrade, it worked OK,
i.e. the BOM was dropped by PHP.

Thank you.

Richard.

-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

---

## #35971 — Stefan Walk — 2008-03-05T12:06:15+00:00

URL: https://externals.io/message/35970#35971 · In reply to: #35970

On Wednesday 05 March 2008 11:21:14 Richard Quadling wrote:
> But, having just inherited a load of code which are UTF-8 encoded and
> all have a BOM marker, all the BOM markers are being sent to the
> browser. This screws up sessions as output is sent before headers
> (obviously).
>
> The files are english/non english mix, so I'm assuming the BOM needs
> to be present to indicate the order of the encoding (I'm new to the
> Unicode stuff, so this is my first real work with anything other than
> pure english PHP code). Because of this assumption, I think I can't
> remove the BOM marker.

Since the codeunits for UTF-8 are only one Byte long, the BOM is unnecessary. 
It's just added from some editors that use it as a marker "This file is 
UTF-8". So, you can safely remove it.

Additionally, i don't think PHP has ignored the BOM before.

Regards,
Stefan

---

## #35973 — Adam Harvey — 2008-03-05T14:14:12+00:00

URL: https://externals.io/message/35970#35973 · In reply to: #35971

Quoting Stefan Walk <et@php.net>:
> Additionally, i don't think PHP has ignored the BOM before.

Bug #22108 [1] has the gory details. The gist is that this behaves  
differently depending on whether PHP was configured with  
--enable-zend-multibyte. With the option, the BOM is parsed, used to  
detect which UTF encoding is in use, and then discarded. Without the  
option, it's treated like any other non-PHP content and echoed to  
stdout.

A (very) quick test of the latest PHP 6 snapshot suggests that the  
current behaviour there is the same as PHP 5 without  
--enable-zend-multibyte: just output the BOM to stdout without any  
special handling. It's entirely possible that I've just missed a  
Unicode-related option there, though.

Adam

[1] http://bugs.php.net/bug.php?id=22108

-- 
Adam Harvey            PEAR Profile: <http://pear.php.net/user/aharvey>
                                             Blog: <http://xn--9bi.net/
