user3779269
user3779269

Reputation: 11

load xml which includes unescaped characters PHP

I'm new with PHP :)

I'm trying to load XML which includes unescaped characters. I want to use REGEX. Can anyone tell me, how to do it properly?

This is my simple XML file:

<?xml  version="1.0" encoding="utf-8"?>
<test>
    <url>http://example.com?T=2&P=1</url>
</test>

and my code:

$test = file_get_contents( __DIR__ . '/../test/test.xml' );
$objXml = simplexml_load_string( $test );
var_dump( $objXml );

and i receive this error:

"simplexml_load_string(): Entity: line 3: parser error : EntityRef: expecting ';'"

any ideas how can I get it?

Upvotes: 1

Views: 148

Answers (1)

ZeroWorks
ZeroWorks

Reputation: 1638

Just try to encapslulate data in XML:

<?xml version="1.0" encoding="utf-8"?>
<test>
    <url><![CDATA[http://example.com?T=2&P=1]]></url>
</test>

Also take in consideration @Rakesh Sharma comment to use simplexml_load_file()

Info about CDATA

Upvotes: 1

Related Questions