Handling the euro sign in utf8_encode
Worse still, on their own web page!
What is it trying to say? It’s a character not recognised by the utf8 encoding.
Some smart alecs will use utf8_encode, but the euro won’t get through . . .


This problem is typically found in UTF8-encoded pages that gather content from several sources, some encoded in UTF8 and some in ISO-8859-1. Here, for example, the image titles arrive in ISO-8859-1. The encodings are heterogeneous.
How do you fix this problem?
The short answer
The short answer is to use the utf8_encode() function to utf8-encode, within your web page, any text likely to contain non-standard characters. That way, the browser receiving the text will render these characters properly, as long as your web page imposes charset=UTF-8 on it.If your scripting language is PHP, I’d even recommend using an alias you can define yourself in your function library: my home-made function utf8_encode2(), whose code is shown below. Its huge advantage is that it encodes some characters ignored by utf8_encode(), because they belong to other character sets. In this case cp1252, which includes the euro.
<?php
function utf8_encode2($str) {
$final_str = $str;
$final_str = str_replace('œ', 'œ', $final_str);
$final_str = str_replace('’', 'ߣ', $final_str);
$final_str = str_replace('“', 'ÉC;', $final_str);
$final_str = str_replace('”', 'ÉD;', $final_str);
$final_str = str_replace('…', 'ߪ', $final_str);
$final_str = str_replace('€', '€', $final_str);
$final_str = utf8_encode($final_str);
$final_str = str_replace(utf8_encode('œ') , 'Å“', $final_str);
$final_str = str_replace(utf8_encode('ߣ'), '’', $final_str);
$final_str = str_replace(utf8_encode('ÉC;'), '“', $final_str);
$final_str = str_replace(utf8_encode('ߪ'), '…', $final_str);
$final_str = str_replace(utf8_encode('ÉD;'), 'â€', $final_str);
$final_str = str_replace(utf8_encode('€'), '€', $final_str);
return $final_str;
}
?>
The long answer
With this one, you won’t even need utf8_encode() to pass your text into the HTML stream, nor any htmlentities() etc . . . It’s about following the best practice of saving your web pages in utf8 format. You’ll need to make sure the HTML header of the page to display declares the utf8 charset, as seen in image 2 above.That way you can afford any fancy stuff, euro, the weirdest characters, and everything will hold together, even on browsers made in China.
So if utf8 solves everything, why use conversion functions?
The first good reason to use them is precisely to convert data to UTF8 as part of a migration.The second reason is to deal with mixed sources, when the developer doesn’t have full control over the code or over how the data is encoded. They have to juggle with what they’ve got. Hence the value of having a library of conversion functions at hand.


