fab2s/bom

Purely static zero dependencies BOM Helper to handle unicode BOMs

1.0.1 2021-06-16 09:43 UTC

This package is auto-updated.

Last update: 2024-11-16 17:17:58 UTC


README

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

Installation

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

Prerequisites

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 ...
}

Requirements

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

Contributing

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

License

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