Purely static zero dependencies BOM Helper to handle unicode BOMs

1.0.0 2019-09-20 07:34 UTC

This package is auto-updated.

Last update: 2021-01-18 16:52:37 UTC


Build Status Total Downloads Monthly Downloads Latest Stable Version Scrutinizer Code Quality PRs Welcome License

A purely static zero dependencies byte Order Mark Helper to handle unicode BOMs


Bom can be installed using composer:

composer require "fab2s/bom"

Bom is also included in OpinHelper which packages several bellow "Swiss Army Knife" level Helpers covering some of the most annoying aspects of php programing, such as UTF8 string manipulation, high precision Mathematics or properly locking a file

Should you need to work with php bellow 7.1, you can still use OpinHelper 0.x


Bom has no specific dependencies

In practice

Bom supports UTF-8|16|32 BOMs in both Little and Big Endianness

Bom is minimalistic, it only exposes five methods

// get Bom
$bomAtStartOfString = Bom::extract($string); // returns null when none are found

// remove eventual BOM from beging of string
$bomLessString = Bom::drop($string);

// get encoding from a supported BOM
$encoding = Bom::getBomEncoding($bom); // returns null if the BOM is not valid

// get BOM for a supported encoding
$bom = Bom::getEncodingBom($encoding); // returns null if the encoding is not supported (has no BOM)

// get the list of BOMs as an array with corresponding encodings as indexes
$boms = Bom::getBoms(); // returns an associatiove array of encodings and correesponding BOMs

foreach ($boms as $encoding => $bom) {
    // do something ...


Bom is tested against php 7.1, 7.2, 7.3 and 7.4


Contributions are welcome, do not hesitate to open issues and submit pull requests.


Bom is open-sourced software licensed under the MIT license.