function replaceEntities($str)
{
foreach ($this->_entity_replacements as $old => $new) {
$str = preg_replace(sprintf("/&%s;/", $old), $new, $str);
}
// Replace numeric entities because html_entity_decode doesn't
// do it for us.
$str = preg_replace_callback('/&#x([0-9a-f]+);/i', function ($matches) {
return chr(hexdec($matches[1]));
}, $str);
$str = preg_replace_callback('/&#([0-9]+);/', function ($matches) {
return chr($matches[1]);
}, $str);
return $str;
}