https://github.com/fab2s/bom
A purely static zero dependencies Helper to handle unicode BOMs
https://github.com/fab2s/bom
big-endian bom byte-order-mark little-endian php utf-16 utf-32 utf-8
Last synced: about 1 month ago
JSON representation
A purely static zero dependencies Helper to handle unicode BOMs
- Host: GitHub
- URL: https://github.com/fab2s/bom
- Owner: fab2s
- License: mit
- Created: 2019-08-11T10:20:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-16T09:46:18.000Z (almost 4 years ago)
- Last Synced: 2025-02-18T18:16:41.935Z (3 months ago)
- Topics: big-endian, bom, byte-order-mark, little-endian, php, utf-16, utf-32, utf-8
- Language: PHP
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bom
[](https://travis-ci.com/fab2s/Bom) [](//packagist.org/packages/fab2s/bom) [](//packagist.org/packages/fab2s/bom) [](https://packagist.org/packages/fab2s/bom) [](https://scrutinizer-ci.com/g/fab2s/Bom/?branch=master) [](http://makeapullrequest.com) [](https://packagist.org/packages/fab2s/bom)
A purely static zero dependencies [byte Order Mark](https://en.wikipedia.org/wiki/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](https://github.com/fab2s/OpinHelpers) 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](https://github.com/fab2s/OpinHelpers) `0.x`
## Prerequisites
`Bom` has no specific dependencies
## In practice
`Bom` supports `UTF-8|16|32` BOMs in both [_Little_](https://en.wikipedia.org/wiki/Endianness#Little) and [_Big_](https://en.wikipedia.org/wiki/Endianness#Big) [Endianness](https://en.wikipedia.org/wiki/Endianness)
`Bom` is minimalistic, it only exposes five methods
```php
// 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 BOMsforeach ($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](https://opensource.org/licenses/MIT).