I try parse an utf-8 html text but I get this error
Warning: DOMDocumentFragment::appendXML(): Entity: line 1: parser error : Entity 'nbsp' not defined
I define:
$dom = new DOMDocument();
$dom->loadHtml(mb_convert_encoding($richText, 'HTML-ENTITIES', "UTF-8"));
this is full code:
function putBetweenText($richText,$webinfo,$url,$keywords,$type = null,$display,$inline)
{
$dom = new DOMDocument();
$dom->loadHtml(mb_convert_encoding($richText, 'HTML-ENTITIES', "UTF-8"));
$xpath = new DOMXPath($dom);
foreach($xpath->query('//text()[not(ancestor::a)]') as $node)
{
$replaced = str_ireplace('.', '.'.randomText($webinfo,$url,$richText,null,$display,$inline), $node->wholeText);
$newNode = $dom->createDocumentFragment();
$newNode->appendXML($replaced);
$node->parentNode->replaceChild($newNode, $node);
}
return mb_substr($dom->saveXML($xpath->query('//body')->item(0)), 6, -7, "UTF-8");
}