Kuzgun
Kuzgun

Reputation: 4737

Simplexml shows warnings

I am trying to read an xml from string, but it shows a few warnings. I couldn't find ^ in the xml string and here is the code I'm using:

//$XMLstring=str_replace($XMLstring,'^','');
    $XML=simplexml_load_string($XMLstring);
    print_r($XMLstring);

This one shows the warnings, but it writes $XMLstring as well. If I uncomment the first line, no warnings but no printing either.

EDIT: I tried to replace & with & by str_replace but now it shows warnings like this:

Warning: simplexml_load_string(): Entity: line 1: parser error : 
Start tag expected, '<' not found in C:\xampp\htdocs\project\file1.php on line 173

Warning: simplexml_load_string(): &amp; in C:\xampp\htdocs\project\file1.php on line 173

Warning: simplexml_load_string(): ^ in C:\xampp\htdocs\project\file1.php on line 173

Warning: simplexml_load_string(): Entity: line 4: parser error : 
EntityRef: expecting ';' in C:\xampp\htdocs\project\file1.php on line 173

Warning: simplexml_load_string(): <item><col1>S&P 500</col1><col2>1656,96</col2>
<col3>0,86</col3><col4>14,16 in C:\xampp\htdocs\project\file1.php on line 173

Warning: simplexml_load_string(): ^ in C:\xampp\htdocs\project\file1.php on line 173

Warning: simplexml_load_string(): Entity: line 17: parser error : EntityRef: 
expecting ';' in C:\xampp\htdocs\project\file1.php on line 173

Warning: simplexml_load_string(): <item><col1>S&P/ASX 200</col1><col2>5123,36</col2>
<col3>0,94</col3><col4>4 in C:\xampp\htdocs\project\file1.php on line 173

And here is sample of xml:

<!--?xml version="1.0" encoding="UTF-8"?-->
<list>
  <item>
    <col1>S&P 500</col1>
    <col2>1656,96</col2>
    <col3>0,86</col3>
    <col4>66,19</col4>
</item>
</list>

Upvotes: 0

Views: 1461

Answers (1)

IMSoP
IMSoP

Reputation: 97638

The ^ is trying to point at the appropriate part of the output above to show where the error is.

The actual problem is the & in S&P, which should have been escaped as &amp;

Upvotes: 1

Related Questions