我正在尝试从字符串中读取 xml,但它显示了一些警告。我在 xml 字符串中找不到 ^,这是我正在使用的代码:
//$XMLstring=str_replace($XMLstring,'^','');
$XML=simplexml_load_string($XMLstring);
print_r($XMLstring);
这个显示了警告,但它也写入了 $XMLstring。如果我取消注释第一行,则没有警告但也没有打印。
编辑:
我试图用&
str_replace 替换 & ,但现在它显示如下警告:
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(): & 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
这是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>