We have these characters:
“ and ”
(this is not a regular ", but some sort of curly one. No idea what it is called)
When we use htmlentities(), these characters are not converted, and this causes issues later on. Further problem is that we encode our pages in Latin-1, and we can not save this particular character (so we can not do a replace-and-find, because we can not actually program this into any page).
NOTE: We DO set ENT_QUOTES, but this has no effect in htmlentities().
UPDATE
I now know they are called fancy quotes, among others, and their appropriate html entities are “ and ”. Now, the question is, why does PHP not convert these characters appropriately? See sample code:
<?php
var_dump(htmlentities($_POST['t'],ENT_QUOTES));
?>
<form action="" method="post">
<input type="t" name="t" />
<button class="button" type="submit">Send</button>
</form>
Result:

This answer comes from http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php, which was posted as a comment by Tomalak Geret’kal:
The trick is to use the
asciicharacter position to find the characters that we are targeting, and then convert them with the ones we can work with. Eg: