Re: Detecting a BOM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 13, 2010 at 11:42, Leszek Stachowski <shazarre@xxxxxxxxx> wrote:
> Hi,
>
> is there any way to detect BOM in a file? I'm writing a parser which outputs
> a number line if there's an error in it and its content. Every time it
> parser a file saved in UTF-8 with BOM it outputs those three magic letters.
> Can I pre-check for it and skip it? Or convert somehow?
>
> Greetings,
> Leszek Stachowski

The UTF-8 byte order mark is represented by the hexadecimal character
sequence EF BB BF. You can use something like this to detect a BOM:

if (substr($source, 0, 3) == pack('CCC', 0xEF, 0xBB, 0xBF)) {
    // has bom
}

-- 
Daniel Egeberg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux