
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Aliases of a Known Encoding Type Using mb_encoding_aliases in PHP
In PHP, mb_encoding_aliases() is used to get the aliases of a known encoding type. This function is supported in PHP 5 or higher version.
Syntax
array mb_encoding_aliases(str $encoding)
Parameters
It accepts only one parameter, $encoding, which is the encoding type checked for aliases.
Return Values
It returns a numerically indexed array of encoding aliases on success or it returns False on failure.
Errors/Exceptions
If the encoding is not known, then it gives an E_WARNING level error.
Example 1
<?php $encoding = 'ASCII'; $known_encodings = mb_list_encodings(); if (in_array($encoding, $known_encodings)) { $aliases = mb_encoding_aliases($encoding); print_r($aliases); } else { echo "Unknown ($encoding) encoding.
"; } ?>
Output
Array ( [0] => ANSI_X3.4-1968 [1] => iso-ir-6 [2] => ANSI_X3.4-1986 [3] => ISO_646.irv:1991 [4] => US-ASCII [5] => ISO646-US [6] => us [7] => IBM367 [8] => IBM-367 [9] => cp367 [10] => csASCII )
Example 2
<?php $array = mb_encoding_aliases("ASCII"); var_dump($array); ?>
Output
array(11) { [0]=> string(14) "ANSI_X3.4-1968" [1]=> string(8) "iso-ir-6" [2]=> string(14) "ANSI_X3.4-1986" [3]=> string(16) "ISO_646.irv:1991" [4]=> string(8) "US-ASCII" [5]=> string(9) "ISO646-US" [6]=> string(2) "us" [7]=> string(6) "IBM367" [8]=> string(7) "IBM-367" [9]=> string(5) "cp367" [10]=> string(7) "csASCII" }
Advertisements