| 1 | <?php |
||
| 27 | final class BOM |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * UTF-8 BOM sequence |
||
| 31 | */ |
||
| 32 | const UTF8 = "\xEF\xBB\xBF"; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * UTF-16 BE BOM sequence |
||
| 36 | */ |
||
| 37 | const UTF16_BE = "\xFE\xFF"; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * UTF-16 LE BOM sequence |
||
| 41 | */ |
||
| 42 | const UTF16_LE = "\xFF\xFE"; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * UTF-32 BE BOM sequence |
||
| 46 | */ |
||
| 47 | const UTF32_BE = "\x00\x00\xFE\xFF"; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * UTF-32 LE BOM sequence |
||
| 51 | */ |
||
| 52 | const UTF32_LE = "\xFF\xFE\x00\x00"; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Returns all possible BOM sequences as an array |
||
| 56 | * |
||
| 57 | * @return string[] |
||
| 58 | */ |
||
| 59 | 158 | private static function toArray(): array |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Returns the BOM sequence found at the start of the string |
||
| 71 | * |
||
| 72 | * If no valid BOM sequence is found an empty string is returned |
||
| 73 | * |
||
| 74 | * @param string $str |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | 152 | public static function match(string $str): string |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Tell whether the submitted sequence is a valid BOM sequence |
||
| 91 | * |
||
| 92 | * @param string $sequence |
||
| 93 | * |
||
| 94 | * @return bool |
||
| 95 | */ |
||
| 96 | 6 | public static function isValid(string $sequence): bool |
|
| 100 | } |
||
| 101 |