Skip to content
Advertisement

PHP DOMDocument error Entity ‘nbsp’ not defined

I use DOMDocument for editing some HTML files, but some of theme have in their names spaces. So DOMDocument automaticly change the spaces to %20 and then can’t find them.

This is how looks the error exactly:

JavaScript

How to repair this error?

Advertisement

Answer

Use DOMDocument::loadHTMLFile() instead of load(). That’s what it has been made for. HTML is not XML.

XML does not know the named entity  . However if you use loadHTML, the XML parser will get the HTML named entities loaded so the error goes away.

See as well: XML parser error: entity not defined.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement