Tuesday, October 7, 2025
HomeLanguagesPHP | utf8_decode() Function

PHP | utf8_decode() Function

The utf8_decode() function is an inbuilt function in PHP which is used to decode a UTF-8 string to the ISO-8859-1. This function decodes back to the encoded string which is encoded with the utf8_encode() function.

Syntax: 

string utf8_decode( string $string )

Parameter: This function accepts single parameter $string which is required. It specifies the UTF-8 encoded string to be decoded.

Return Value: This function returns a string representing the decoded string on success and false on failure.

Note: This function is available for PHP 4.0.0 and newer version.

Program 1:  

PHP




<?php
 
// String to decode
$string_to_decode = "\x63";
 
// Encoding string
echo utf8_encode($string_to_encode) ."<br>";
 
// Encoding string
echo utf8_decode($string_to_decode);
 
?>


Output: 

c
c

Program 2:  

PHP




<?php
 
// Creating an array of 256 elements
$text = array(
    "\x20", "\x21", "\x22", "\x23", "\x24", "\x25",
    "\x26", "\x27", "\x28", "\x29", "\x2a", "\x2b",
    "\x2c", "\x2d", "\x2e", "\x2f", "\x30", "\x31"
);
 
echo "Encoded elements:\n";
 
// Encoding and decoding all elements
foreach( $text as $index ) {
    echo utf8_encode($index) . " ";
}
 
echo "\nDecoded elements:\n";
 
foreach( $text as $index ) {
    echo utf8_decode($index) . " ";
}
 
?>


Output: 

Encoded elements:
  ! " # $ % & ' ( ) * + , - . / 0 1 
Decoded elements:
  ! " # $ % & ' ( ) * + , - . / 0 1 

Reference: https://www.php.net/manual/en/function.utf8-decode.php
 

RELATED ARTICLES

Most Popular

Dominic
32340 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6829 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS