xml - parser error : String not started expecting ' or " in php -


hi i'm trying convert xml file associative array using following code

$xmlurl = '../products.xml'; $xmlstr = file_get_contents($xmlurl);  $xmlobj = simplexml_load_string($xmlstr);  print_r ($xmlobj);exit; $arrxml = objectsintoarray($xmlobj); 

and product.xml containing

<?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 vodafone, advanced &ndash; in - 1 device has advanced web , navigation features plus handy 360 degree navi key stay in control.<br/><ul>         <li>5 mp camera carl zeiss optics , flash</li>         <li>wifi, hsdpa , 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 carl zeiss optics , flash&lt;/li&gt;       &lt;li&gt;wifi, hsdpa , 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 vodafone calls - unlimited<br/>also includes - voicemail retrieval <br/><br/>flexi credit amount - na<br/>standard national voice calls - unlimited<br/>standard txt , pxt - unlimited<br/>]]>       </getmonthly>     </plan>   </product>...etc 

but returns error message follows

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 

i trying fix issue whole day , searching solution on net not . please let me know reason?

this caused magic_quotes_runtime adding backslashes when call file_get_contents. try following:

$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); 

alternatively disable magic_quotes_runtime (although may have effects elsewhere in script) in php configuration, via .htaccess, or adding following near top of script:

set_magic_quotes_runtime(false); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -