PHP mb_encoding_aliases() Function
The mb_encoding_aliases() is an inbuilt PHP function that can be utilized to retrieve aliases for a known encoding type.
Syntax:
mb_encoding_aliases(string $encoding): array
Parameter: This function has only one parameter:
- encoding: This parameter specifies the encoding type that is to be checked for aliases.
Return value: The numerically indexed array for encoding aliases will be returned.
Example 1: The following code demonstrates the mb_encoding_aliases() function.
PHP
<?php $aliases = mb_encoding_aliases( 'UTF-8' ); print_r( $aliases ); ?> |
Output
Array ( [0] => utf8 )
Example 2: The following code demonstrates the mb_encoding_aliases() function.
PHP
<?php // An alias for GBK encoding $alias = 'cp936' ; if (in_array( $alias , mb_encoding_aliases( 'GBK' ))) { echo "$alias is a valid encoding alias for GBK" ; } else { echo "$alias is not a valid encoding alias for GBK" ; } ?> |
Output
cp936 is not a valid encoding alias for GBK
Reference: https://www.php.net/manual/en/function.mb-encoding-aliases.php
Contact Us