2011-02-18 7 views
2

안녕 내가 들어 다음 코드파서 오류 : 문자열 '또는'PHP에

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

하고있는 product.xml를 사용하여 연관 배열로 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 

를 다음과 같이는 오류 메시지를 반환 ing 솔루션을 얻을 수는 없었습니다. 그 이유를 알려주시겠습니까?

+0

[참고 -이 오류는 PHP에서 무엇을 의미합니까?] (http://stackoverflow.com/q/12769982/367456) – hakre

답변

9

이것은 아마도 magic_quotes_runtime이 file_get_contents를 호출 할 때 백 슬래시를 추가 할 때 발생합니다. 당신의 PHP 구성 (이것은 다른 스크립트에 영향을 미칠 수 있지만)

$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를 통해, 매직 코트를 해제 할 수 또는 스크립트의 상단에 다음을 추가하여 : 다음 시도

set_magic_quotes_runtime(false); 
+0

+1 이것은 분명히 대답입니다. http://www.netadmintools.com/part460.html을 참조하십시오. –

+0

안녕하세요 qbert220, 그 stripslashes 후 근무. 감사합니다 –

+0

@ilaya - 정답으로 사용하십시오. – qbert220

0

XML 문자열을 수정해야합니다. 유효하지 않습니다. 당신이 그대로 XML을 유지하고 유효성 검사 오류를 방지하려면 은() 오른쪽 옵션을 설정가 탈출하여 XML을 보여줍니다 왜 이해가 안 http://php.net/manual/fr/function.simplexml-load-string.php 및 Btw는

http://www.php.net/manual/fr/libxml.constants.php 보려면 simplexml_load_string의 세번째 인수를 사용 따옴표, 그것은 소스 파일에서 이스케이프됩니까?