Encoding
in package
Represents an encoding utility class.
Table of Contents
Constants
- CP1251 = "windows-1251"
- Windows 1251 encoding
- ISO_8859_1 = 'iso-8859-1'
- ISO 8859-1 encoding
- UTF8 = "utf-8"
- UTF8 encoding
Methods
- Check() : bool
- Checks whether a given string is valid in the specified encoding.
- Convert() : string|array<string|int, mixed>|object
- Converts a string, array, or object from one encoding to another.
- Detect() : string
- Detects the encoding of a given string.
Constants
CP1251
Windows 1251 encoding
public
mixed
CP1251
= "windows-1251"
ISO_8859_1
ISO 8859-1 encoding
public
mixed
ISO_8859_1
= 'iso-8859-1'
UTF8
UTF8 encoding
public
mixed
UTF8
= "utf-8"
Methods
Check()
Checks whether a given string is valid in the specified encoding.
public
static Check(string $string, string $encoding) : bool
Encoding::Check('халлоу', Encoding::CP1251) returns false
Encoding::Check('халлоу', Encoding::UTF8) returns true
Parameters
- $string : string
-
The input string to be checked.
- $encoding : string
-
The target encoding to validate against.
Return values
bool —True if the string is valid in the specified encoding, false otherwise.
Convert()
Converts a string, array, or object from one encoding to another.
public
static Convert(string|array<string|int, mixed>|object $string, string $to[, string|null $from = null ]) : string|array<string|int, mixed>|object
Enconding::Convert('халлоу', Encoding::CP1251) returns 'халлоу' in windows-1251 encoding
Enconding::Convert(['халлоу','hello'], Encoding::CP1251) returns ['халлоу','hello'] in windows-1251 encoding
Parameters
- $string : string|array<string|int, mixed>|object
-
The input data to be converted.
- $to : string
-
The target format.
- $from : string|null = null
-
The source format (optional).
Return values
string|array<string|int, mixed>|object —The converted data.
Detect()
Detects the encoding of a given string.
public
static Detect(string $string) : string
՝՝՝ Encoding::Detect('hello') returns 'utf8' ՝՝՝
Parameters
- $string : string
-
The input string to analyze.
Return values
string —The detected format or encoding.