This question already has an answer here:
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");
}
</div>
Change:
putBetweenText($richText,$webinfo,$url,$keywords,$type = null,$display,$inline)
to:
putBetweenText($richText, $webinfo, $url, $keywords, $type , $display, $inline)
You can call the function similar to:
putBetweenText('rich text value', $webinfo_setFromHere, 'http://www.google.com', $keywords_array, 'integer' , 'TRUE', $makeIt_inline)
nbsp is not inside an echo statement wherever it is.
You can't put variable assignments into functions, you can only pass them in, or say they're from outside the function($var1, $var2, $var3) by saying global.
$type = null is illegal. You should assign variables being received, but not passed into the function like: global $a, $b;