Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
PHP – Return an array of all supported encodings with mb_list_encodings()
Looking at this article, I notice there's a topic mismatch - it's about PHP but the instructions are for Python articles. However, I'll improve the PHP article following the general improvement guidelines.
The mb_list_encodings() function in PHP returns an array of all supported character encodings available in the multibyte string extension. This function is part of PHP's mbstring extension and is available in PHP 5.0.0 and higher versions.
Syntax
array mb_list_encodings()
Parameters
The mb_list_encodings() function takes no parameters.
Return Value
This function returns a numerically indexed array containing the names of all supported encodings as strings.
Example
Here's how to use mb_list_encodings() to get all supported encodings ?
<?php
$encodings = mb_list_encodings();
echo "Total supported encodings: " . count($encodings) . "\n";
// Display first 10 encodings
echo "First 10 encodings:\n";
for($i = 0; $i < 10; $i++) {
echo "[$i] => " . $encodings[$i] . "\n";
}
?>
The output will be ?
Total supported encodings: 87 First 10 encodings: [0] => pass [1] => auto [2] => wchar [3] => byte2be [4] => byte2le [5] => byte4be [6] => byte4le [7] => BASE64 [8] => UUENCODE [9] => HTML-ENTITIES
Complete Output
The complete array contains all 87 supported encodings ?
array(87) {
[0]=> string(4) "pass"
[1]=> string(4) "auto"
[2]=> string(5) "wchar"
[3]=> string(7) "byte2be"
[4]=> string(7) "byte2le"
[5]=> string(7) "byte4be"
[6]=> string(7) "byte4le"
[7]=> string(6) "BASE64"
[8]=> string(8) "UUENCODE"
[9]=> string(13) "HTML-ENTITIES"
[10]=> string(16) "Quoted-Printable"
[11]=> string(4) "7bit"
[12]=> string(4) "8bit"
[13]=> string(5) "UCS-4"
[14]=> string(7) "UCS-4BE"
[15]=> string(7) "UCS-4LE"
[16]=> string(5) "UCS-2"
[17]=> string(7) "UCS-2BE"
[18]=> string(7) "UCS-2LE"
[19]=> string(6) "UTF-32"
[20]=> string(8) "UTF-32BE"
[21]=> string(8) "UTF-32LE"
[22]=> string(6) "UTF-16"
[23]=> string(8) "UTF-16BE"
[24]=> string(8) "UTF-16LE"
[25]=> string(5) "UTF-8"
[26]=> string(5) "UTF-7"
[27]=> string(9) "UTF7-IMAP"
[28]=> string(5) "ASCII"
[29]=> string(6) "EUC-JP"
[30]=> string(4) "SJIS"
[31]=> string(9) "eucJP-win"
[32]=> string(11) "EUC-JP-2004"
[33]=> string(8) "SJIS-win"
[34]=> string(18) "SJIS-Mobile#DOCOMO"
[35]=> string(16) "SJIS-Mobile#KDDI"
[36]=> string(20) "SJIS-Mobile#SOFTBANK"
[37]=> string(8) "SJIS-mac"
[38]=> string(9) "SJIS-2004"
[39]=> string(19) "UTF-8-Mobile#DOCOMO"
[40]=> string(19) "UTF-8-Mobile#KDDI-A"
[41]=> string(19) "UTF-8-Mobile#KDDI-B"
[42]=> string(21) "UTF-8-Mobile#SOFTBANK"
[43]=> string(5) "CP932"
[44]=> string(7) "CP51932"
[45]=> string(3) "JIS"
[46]=> string(11) "ISO-2022-JP"
[47]=> string(14) "ISO-2022-JP-MS"
[48]=> string(7) "GB18030"
[49]=> string(12) "Windows-1252"
[50]=> string(12) "Windows-1254"
[51]=> string(10) "ISO-8859-1"
[52]=> string(10) "ISO-8859-2"
[53]=> string(10) "ISO-8859-3"
[54]=> string(10) "ISO-8859-4"
[55]=> string(10) "ISO-8859-5"
[56]=> string(10) "ISO-8859-6"
[57]=> string(10) "ISO-8859-7"
[58]=> string(10) "ISO-8859-8"
[59]=> string(10) "ISO-8859-9"
[60]=> string(11) "ISO-8859-10"
[61]=> string(11) "ISO-8859-13"
[62]=> string(11) "ISO-8859-14"
[63]=> string(11) "ISO-8859-15"
[64]=> string(11) "ISO-8859-16"
[65]=> string(6) "EUC-CN"
[66]=> string(5) "CP936"
[67]=> string(2) "HZ"
[68]=> string(6) "EUC-TW"
[69]=> string(5) "BIG-5"
[70]=> string(5) "CP950"
[71]=> string(6) "EUC-KR"
[72]=> string(3) "UHC"
[73]=> string(11) "ISO-2022-KR"
[74]=> string(12) "Windows-1251"
[75]=> string(5) "CP866"
[76]=> string(6) "KOI8-R"
[77]=> string(6) "KOI8-U"
[78]=> string(9) "ArmSCII-8"
[79]=> string(5) "CP850"
[80]=> string(6) "JIS-ms"
[81]=> string(16) "ISO-2022-JP-2004"
[82]=> string(23) "ISO-2022-JP-MOBILE#KDDI"
[83]=> string(7) "CP50220"
[84]=> string(10) "CP50220raw"
[85]=> string(7) "CP50221"
[86]=> string(7) "CP50222"
}
Common Use Cases
This function is useful for:
- Checking if a specific encoding is supported before using it
- Building dynamic encoding selection menus
- Debugging multibyte string operations
- Validating user-provided encoding names
Conclusion
The mb_list_encodings() function provides a comprehensive list of all character encodings supported by PHP's mbstring extension. Use it to programmatically determine available encodings for your application's internationalization needs.
