d'erreur de l'analyseur : String pas commencé à s'attendre à " ou " en php
Salut, je vais essayer de convertir le fichier XML dans un tableau associatif en utilisant le code suivant
$xmlUrl = '../products.xml';
$xmlStr = file_get_contents($xmlUrl);
$xmlObj = simplexml_load_string($xmlStr); print_r ($xmlObj);exit;
$arrXml = objectsIntoArray($xmlObj);
et product.xml contenant
<?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 – 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><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></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
mais il renvoie un message d'erreur comme suit
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
Je suis en train d'essayer de résoudre ce problème toute la journée et la recherche de solution sur le net mais je ne pouvais pas obtenir . S'il vous plaît laissez-moi savoir la raison?
OriginalL'auteur | 2011-02-18
Vous devez vous connecter pour publier un commentaire.
Ceci est probablement causé par magic_quotes_runtime l'ajout de barres obliques inverses lorsque vous appelez file_get_contents. Essayez ce qui suit:
Sinon, vous pouvez désactiver magic_quotes_runtime (bien que cela puisse avoir des répercussions ailleurs dans votre script) dans votre configuration PHP, via .htaccess, ou par adjonction, près du haut de votre script:
Salut qbert220, de son travaillé après que j'ai mis stripslashes. merci
Veuillez accepter ceci comme la réponse correcte, puis
OriginalL'auteur qbert220
Vous devez réparer votre chaîne XML, il n'est pas valide.
Si vous voulez garder le XML est et d'éviter les erreurs de validation, utilisez le 3ème argument de simplexml_load_string() pour définir les bonnes options, voir http://php.net/manual/fr/function.simplexml-load-string.php et http://www.php.net/manual/fr/libxml.constants.php
Btw, je ne comprends pas pourquoi il montre votre XML avec échappé citations, est-il échappé dans le fichier source?
OriginalL'auteur Capsule
Juste par curiosité, pourquoi n'êtes-vous pas à l'aide de simplexml_load_file()?
OriginalL'auteur Jeremy