Oihana PHP System

CharacterSet uses ConstantsTrait

Enumeration of official character set codes as assigned by IANA and used in Internet standards and documentation.

This class defines integer constants representing the numeric identifiers of various character encodings (code pages) commonly used in databases, networking, and application protocols.

The constants correspond to values supported by connection options such as IANAAppCodePage, facilitating consistent charset handling in database drivers or other components interacting with textual data.

See the official IANA character sets registry for full details: https://www.iana.org/assignments/character-sets/character-sets.xhtml

Example usage:

use oihana\enums\CharacterSet;

$charset = CharacterSet::UTF8;  // 106

Notes:

  • The UTF8 constant represents passing Unicode data without conversion when the database is configured for Unicode.
  • Some values are specific to certain vendors or drivers (e.g. Progress DataDirect), and may not appear in the official IANA list.
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

Big5  = 2026
EUC_JP  = 18
EUC_KR  = 38
GB2312  = 2025
GB_2312_80  = 57
GBK  = 113
HP_ROMAN8  = 2004
HZ_GB_2312  = 2085
IBM00858  = 2089
IBM01140  = 2091
IBM01141  = 2092
IBM01142  = 2093
IBM01143  = 2094
IBM01144  = 2095
IBM01145  = 2096
IBM01146  = 2097
IBM01147  = 2098
IBM01148  = 2099
IBM01149  = 2100
IBM037  = 2028
IBM038  = 2029
IBM1026  = 2063
IBM1047  = 2102
IBM273  = 2030
IBM277  = 2033
IBM278  = 2034
IBM280  = 2035
IBM284  = 2037
IBM285  = 2038
IBM290  = 2039
IBM297  = 2040
IBM420  = 2041
IBM424  = 2043
IBM437  = 2011
IBM500  = 2044
IBM775  = 2087
IBM850  = 2009
IBM851  = 2045
IBM852  = 2010
IBM855  = 2046
IBM857  = 2047
IBM860  = 2048
IBM861  = 2049
IBM862  = 2013
IBM863  = 2050
IBM864  = 2051
IBM865  = 2052
IBM866  = 2086
IBM868  = 2053
IBM869  = 2054
IBM870  = 2055
IBM871  = 2056
IBM918  = 2062
IBM_1025  = 2000001025
IBM_4396  = 2000004396
IBM_5026  = 2000005026
IBM_5035  = 2000005035
IBM_939  = 2000000939
IBM_943_P14A_2000  = 2000000943
IBM_Thai  = 2016
ISO_2022_CN  = 104
ISO_2022_CN_EXT  = 105
ISO_2022_JP  = 39
ISO_2022_JP_2  = 40
ISO_2022_KR  = 37
ISO_646_IRV  = 30
ISO_8859_1  = 4
ISO_8859_13  = 109
ISO_8859_14  = 110
ISO_8859_15  = 111
ISO_8859_2  = 5
ISO_8859_3  = 6
ISO_8859_4  = 7
ISO_8859_5  = 8
ISO_8859_6  = 9
ISO_8859_7  = 10
ISO_8859_8  = 11
ISO_8859_9  = 12
JIS_Encoding  = 16
KOI8_R  = 2084
KS_C_5601  = 36
MACINTOSH  = 2027
Shift_JIS  = 17
TIS_620  = 2259
US_ASCII  = 3
UTF8  = 106
Passes Unicode data without conversion if the database is set to Unicode.
WINDOWS_1250  = 2250
WINDOWS_1251  = 2251
WINDOWS_1252  = 2252
WINDOWS_1253  = 2253
WINDOWS_1254  = 2254
WINDOWS_1255  = 2255
WINDOWS_1256  = 2256
WINDOWS_1257  = 2257
WINDOWS_1258  = 2258
WINDOWS_31J  = 2024

Properties

$ALL  : array<string|int, mixed>|null
The list of all constants.
$CONSTANTS  : array<string|int, mixed>|null
The flipped list of all constants.

Methods

enums()  : array<string|int, mixed>
Returns an array of all constants in this enumeration.
get()  : mixed
Returns a valid enumeration value or the default value.
getAll()  : array<string, string>
Returns an array of constants in this class.
getConstant()  : string|array<string|int, string>|null
Returns the constant name(s) associated with the given value.
includes()  : bool
Checks if a given value is valid (exists as a constant in this class).
resetCaches()  : void
Reset the internal cache of the static methods.
validate()  : void
Validates if the passed-in value is a valid element in the current enum.

Constants

IBM_943_P14A_2000

public mixed IBM_943_P14A_2000 = 2000000943

UTF8

Passes Unicode data without conversion if the database is set to Unicode.

public mixed UTF8 = 106

Properties

$ALL

The list of all constants.

protected static array<string|int, mixed>|null $ALL = null

$CONSTANTS

The flipped list of all constants.

protected static array<string|int, mixed>|null $CONSTANTS = null

Methods

enums()

Returns an array of all constants in this enumeration.

public static enums([int $flags = SORT_STRING ]) : array<string|int, mixed>
Parameters
$flags : int = SORT_STRING

The optional second parameter flags may be used to modify the comparison behavior using these values: Comparison type flags:

  • SORT_REGULAR - compare items normally (don't change types)
  • SORT_NUMERIC - compare items numerically
  • SORT_STRING - compare items as strings
  • SORT_LOCALE_STRING - compare items as strings, based on the current locale.
Return values
array<string|int, mixed>

get()

Returns a valid enumeration value or the default value.

public static get(mixed $value[, mixed|null $default = null ]) : mixed
Parameters
$value : mixed
$default : mixed|null = null

getAll()

Returns an array of constants in this class.

public static getAll() : array<string, string>
Return values
array<string, string>

getConstant()

Returns the constant name(s) associated with the given value.

public static getConstant(string $value[, string|array<string|int, string>|null $separator = null ]) : string|array<string|int, string>|null

This method searches the class constants for one or multiple constants whose value matches (or contains) the provided value.

If the constant values are strings containing multiple parts separated by one or more separators, it splits them accordingly before matching.

The method returns:

  • a string with the constant name if exactly one constant matches,
  • an array of constant names if multiple constants share the same value,
  • or null if no constant matches the given value.

The internal cache is used to optimize repeated lookups.

Parameters
$value : string

The value to search for among the constants.

$separator : string|array<string|int, string>|null = null

Optional separator(s) to split constant values before matching.

  • If null, no splitting is performed.
  • If a string, it is used as the delimiter.
  • If an array of strings, each separator is applied iteratively.
Return values
string|array<string|int, string>|null

The constant name(s) matching the value, or null if none found.

includes()

Checks if a given value is valid (exists as a constant in this class).

public static includes(mixed $value[, bool $strict = false ][, string|null $separator = null ]) : bool
Parameters
$value : mixed
$strict : bool = false

[optional]

If the third parameter strict is set to true then the in_array function will also check the types of the needle in the haystack.

$separator : string|null = null

The optional string separator if the constant value contains multiple values in a single string expression.

Return values
bool

True if the value exist, False otherwise.

resetCaches()

Reset the internal cache of the static methods.

public static resetCaches() : void

validate()

Validates if the passed-in value is a valid element in the current enum.

public static validate(mixed $value[, bool $strict = true ][, string|null $separator = null ]) : void
Parameters
$value : mixed
$strict : bool = true

[optional]

If the third parameter strict is set to true then the in_array function will also check the types of the needle in the haystack.

$separator : string|null = null

The optional string separator if the constant value contains multiple values in a single string expression.

Tags
throws
ConstantException

Thrown when the passed-in value is not a valid constant.


        
On this page

Search results