PHP mb_convert_encoding() Function
Last Updated :
28 Mar, 2023
The mb_convert_encoding() function is an inbuilt function in PHP that transforms the string into another character encoding.
Syntax:
mb_convert_encoding(
array|string $string,
string $to_encoding,
array|string|null
$from_encoding = null
): array|string|false
Parameters: This function has 3 parameters:
- string: The parameter specifies the string or array that is to be converted.
- to_encoding: This parameter specifies the desired encoding for the result.
- from_encoding: If mbstring.internal_encoding setting will be utilized, if from_encoding is null or not specified, otherwise the default_charset setting will be used.
Return Value: This function returns an encoded string if the function is successfully executed otherwise it will return false.
Example 1: The following code demonstrates the mb_convert_encoding() function.
PHP
<?php
$string = "Café au lait" ;
$ascii_string = mb_convert_encoding( $string , "ASCII" );
echo $ascii_string ;
?>
|
Output:
Caf? au lait
Example 2: The following code demonstrates the mb_convert_encoding() function.
PHP
<?php
$string = "Björk" ;
$utf8_string = mb_convert_encoding(
$string , "UTF-8" , "ISO-8859-1" );
echo $utf8_string ;
?>
|
Output:
Björk
Reference: https://www.php.net/manual/en/function.mb-convert-encoding.php
Share your thoughts in the comments
Please Login to comment...