Hello All -
I'm trying to write a script which - after text is pulled from a MYSQL DB - checks the text for various characters such as "&" and "..." and "-". If any of these three characters are found, they're converted into the correct html entities - in the case of the "-", that's converted to an ndash.
Here's the weird part: When I test this script as shown here...
++++++++++++++++++++
function char_to_entity($text)
{
$text = str_replace('&', '&', $text);
$text = str_replace(' - ', '–', $text);
$text = str_replace('...', '…', $text);
return $text;
}
$str = 'I have a dog... and a cat - but they only speak french & Latin';
echo char_to_entity($str);
++++++++++++++++++++
... in a regular static document, it works perfectly.
However, when I run text from the database through this script, it will sometimes convert some of the characters, but never all of them as I need.
This would seem so straight-forward but I'm pulling my hair out over it. My database text fields are UTF-8... could that be it?
Any guidance is greatly appreciated.
Neophyte