gpt4 book ai didi

xml - 解析器错误 : String not started expecting ' or " in php

转载 作者:可可西里 更新时间:2023-11-01 00:11:12 25 4
gpt4 key购买 nike

您好,我正在尝试使用以下代码将 XML 文件转换为关联数组

$xmlUrl = '../products.xml';
$xmlStr = file_get_contents($xmlUrl);
$xmlObj = simplexml_load_string($xmlStr); print_r ($xmlObj);exit;
$arrXml = objectsIntoArray($xmlObj);

和包含

的product.xml
<?xml version="1.0" encoding="utf-8"?>
<products>
<product>
<sku>p750h3</sku>
<category>Plans: Vodafone Unlimited Cap</category>
<price>$0</price>
<totalmonthlycost>$129</totalmonthlycost>
<totalmincost>$3096</totalmincost>
<upfront>$0</upfront>
<imageurl>http://store.vodafone.com.au/Images/Upload/nokia-6260-slide-front_118x307.png</imageurl>
<threedurl>http://store.vodafone.com.au/handset-nokia-6260-slide.aspx#3d</threedurl>
<smallimageurl>http://store.vodafone.com.au/Images/Upload/nokia-6260-slide-front_23x60.png</smallimageurl>
<name>Nokia 6260 Slide $129 Unlimited Cap - 24 Months</name>
<description></description>
<ctppage>http://store.vodafone.com.au/handset-nokia-6260-slide.aspx</ctppage>
<features>
<![CDATA[
Exclusive to Vodafone, this advanced all &ndash; in - one device has advanced web and navigation features plus a handy 360 degree Navi key to help you stay in control.<br/><ul>
<li>5 MP camera with Carl Zeiss optics and Flash</li>
<li>WiFi, HSDPA and HSUPA</li>
<li>Integrated GPS Navigation</li>
<li>3G (<a href="/whatis3g-popup.aspx" onclick="window.open(this.href,'','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=600,height=590,status'); return false"><u>What's this?</u></a>)</li>
</ul>
]]>
</features>
<available>Yes</available>
<shippingcost>$0.0</shippingcost>
<dimensions></dimensions>
<manufacturer>Nokia</manufacturer>
<modelnumber>6260 Slide</modelnumber>
<currency>AUD</currency>
<devicekeypoints>&lt;ul&gt;

&lt;li&gt;5 MP camera with Carl Zeiss optics and Flash&lt;/li&gt;
&lt;li&gt;WiFi, HSDPA and HSUPA&lt;/li&gt;
&lt;li&gt;Integrated GPS Navigation&lt;/li&gt;
&lt;li&gt;3G (&lt;a href="/whatis3g-popup.aspx" onclick="window.open(this.href,'','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=600,height=590,status'); return false"&gt;&lt;u&gt;What's this?&lt;/u&gt;&lt;/a&gt;)&lt;/li&gt;

&lt;/ul&gt;</devicekeypoints>
<deviceTagline></deviceTagline>
<deviceColor>Black</deviceColor>
<deviceSpecialOffers></deviceSpecialOffers>
<deviceMonthlyHandsetCost>0.0</deviceMonthlyHandsetCost>
<deviceRecommendedPlan>$129 Unlimited Cap - 24 Months</deviceRecommendedPlan>
<deviceOverallRating></deviceOverallRating>
<plan>
<term>24</term>
<monthlyCapCost>$129</monthlyCapCost>
<getMonthly>
<![CDATA[Monthly credit amount - UNLIMITED<br/>Monthly data - 4GB<sup>3</sup><br/>Vodafone to Vodafone Calls - UNLIMITED<br/>Also includes - Voicemail retrieval <br/><br/>Flexi credit amount - NA<br/>Standard national voice calls - UNLIMITED<br/>Standard txt and pxt - UNLIMITED<br/>]]>
</getMonthly>
</plan>
</product>...etc

但是返回错误信息如下

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : String not started expecting ' or " in D:\EBU\xampp\htdocs\biglinks\include\productUpdate.php on line 24

Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in D:\EBU\xampp\htdocs\biglinks\include\productUpdate.php on line 24

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in D:\EBU\xampp\htdocs\biglinks\include\productUpdate.php on line 24

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Malformed declaration expecting version in D:\EBU\xampp\htdocs\biglinks\include\productUpdate.php on line 24

Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"utf-8\"?> in D:\EBU\xampp\htdocs\biglinks\include\productUpdate.php on line 24

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in D:\EBU\xampp\htdocs\biglinks\include\productUpdate.php on line 24......etc

我一整天都在尝试解决这个问题,并在网上搜索解决方案,但我找不到。请告知原因?

最佳答案

这可能是由于 magic_quotes_runtime 在调用 file_get_contents 时添加反斜杠造成的。尝试以下操作:

$xmlUrl = '../products.xml';
$xmlStr = file_get_contents($xmlUrl);
if (get_magic_quotes_runtime())
{
$xmlStr = stripslashes($xmlStr);
}
$xmlObj = simplexml_load_string($xmlStr); print_r ($xmlObj);exit;
$arrXml = objectsIntoArray($xmlObj); $xmlStr = file_get_contents($xmlUrl);

或者,您可以通过 .htaccess 在您的 PHP 配置中禁用 magic_quotes_runtime(虽然这可能会在您的脚本的其他地方产生影响),或者通过在您的脚本顶部附近添加以下内容:

set_magic_quotes_runtime(false);

关于xml - 解析器错误 : String not started expecting ' or " in php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5039838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com