Skip to content
PHP Logo

How does utf8_decode affect the display of characters in PHP and MySQL?

When retrieving data from MySQL and displaying it in PHP, characters may not display correctly if they are encoded in UTF-8. To solve this issue, you can use the utf8_decode function in PHP to convert the UTF-8 encoded string to ISO-8859-1, which is more widely supported for displaying characters.

php
// Retrieve data from MySQL
$data = $row['column_name']; // Assuming $row is the fetched row

// Decode UTF-8 encoded string to ISO-8859-1
$decoded_data = utf8_decode($data);

// Display the decoded data
echo $decoded_data;