PHP utf8_decode() Function
The PHP utf8_decode() function decodes a UTF-8 string to ISO-8859-1. Bytes in the string which are not valid UTF-8, and UTF-8 characters which do not exist in ISO-8859-1 (that is, characters above U+00FF) are replaced with ?.
Syntax
utf8_decode(string)
Parameters
string |
Required. Specify a UTF-8 encoded string. |
Return Value
Returns the ISO-8859-1 translation of string.
Example: utf8_decode() example
The example below shows the usage of utf8_decode() function.
<?php $text = "\x48\x69"; //encoding string echo utf8_encode($text)."\n"; //decoding string echo utf8_decode($text); ?>
The output of the above code will be:
Hi Hi
Example: applying on elements of an array
Consider one more example where all elements of an array are encoded and decoded.
<?php $str = array("\x31", "\x32", "\x33", "\x34", "\x35", "\x36", "\x37", "\x38", "\x39", "\x40", "\x41", "\x42", "\x43", "\x44", "\x45"); //encoding all elements of the array foreach($str as $i) echo utf8_encode($i)." "; echo "\n"; //decoding all elements of the array foreach($str as $i) echo utf8_decode($i)." "; ?>
The output of the above code will be:
1 2 3 4 5 6 7 8 9 @ A B C D E 1 2 3 4 5 6 7 8 9 @ A B C D E
❮ PHP XML Parser Reference