-PHPDomDocument function problems this post was finally asked by Dana_Zhang at 2014-02-1700: 26: 13. if someone else gave me an XML format string, the tag contains & nbsp; & lt; & nbsp; or & nbsp; & gt; & nbsp; & help-questions about the PHP DomDocument function
This post was last edited by Dana_Zhang at 00:26:13
For help, what if someone else sends me an XML format string containing <or> or <my new DomDocument and loading it using the loadXML function ~~
To add this question, the PHP version I use is 5.2.17. IIS: 7.5. the server version is windows server 2008 R2.
------ Solution --------------------
Use html_entity_decode () and then new DomDocument
------ Solution --------------------
If the special characters <,>, and & are not in the CDATA mark and are not escaped, they are not XML
You can use the loadHTML method to load data.
------ Solution --------------------
Escape Problem?
------ Solution --------------------
$ Dom = new DOMDocument;
$ Dom-> loadXML ('
I'm a test string.
');
If (! $ Dom ){
Echo 'error while parsing the document ';
Exit;
}
$ S = simplexml_import_dom ($ dom );
Echo $ s-> text;
------ Solution --------------------
if ( file_exists ( 'test.xml' )) {
$xml = simplexml_load_file ( 'test.xml' );
echo $xml->text;
} else {
exit( 'Failed to open test.xml.' );
}
Test. xml
I'm a test string.
------ Solution --------------------
First, determine whether your xml is a standard xml. you can go to the w3 website to check the xml specifications, which cannot contain these special characters.