2010-11-25 256 views
-1

我在閱讀XML時遇到麻煩,我跟着this tutorial,並生成了下面的代碼。PHP解析錯誤:解析錯誤,在codeigniter中期望`T_STRING'或'T_VARIABLE'或'T_NUM_STRING'?

當我打開我的控制,我得到

解析錯誤:解析錯誤,在C期待T_STRING' or T_VARIABLE '或'T_NUM_STRING':\ WAMP \ WWW \ ci_doctrine \ SYSTEM \程序\ \控制器上的welcome.php line 49

line 49 is foreach($ xmlData ['item'] as $ row)我不知道該怎麼做任何想法,建議?幫助非常感謝

這是我的代碼:

<?php 

class Welcome extends Controller { 

/*function Welcome() 
{ 
    parent::Controller(); 
} 

*/ 

function index() 
{ 


    //$this->load->view('welcome_message'); 


    //load the parser library 
    $this->load->library('parser'); 

      $data['title'] = 'Parsing XML using Simplexml class of CodeIgniter'; 

      $data['products'] = $this->_getXML('myxml'); 

     $this->parser->parse('table_view', $data); 

    //$this->load->library('parser'); 
     //$data['title'] = 'Parsing XML using SimpleXML class of CodeIgniter'; 

} 

function _getXML($fname) 
{ 

      $filename = $fname.'.xml'; 
      $xmlfile="「C:\wamp\www\" . $filename; 
      $xmlRaw = file_get_contents($xmlfile); 

      $this->load->library('simplexml'); 
      $xmlData = $this->simplexml->xml_parse($xmlRaw); 

      foreach($xmlData['item'] as $row) 
      { 

     $result .= '<tr>'; 
     $result .= '<td>'.$row['id'].'</td>'; 
     $result .= '<td>'.$row['name'].'</td>'; 
     $result .= '<td>'.$row['category'].'</td>'; 
     $result .= '<td>$ '.$row['price'].'</td>'; 
     $result .= '</tr>'; 

      } 
      return $result; 
    } 

} 
//End of file welcome.php 
// Location: ./system/application/controllers/welcome.php 

?> 

<item> 
    <id>1</id> 
    <name>iPhone</name> 
    <category>Mobile</category> 
    <price>300</price> 
</item> 

<item> 
    <id>2</id> 
    <name>iMac</name> 
    <category>Desktop Computers</category> 
    <price>2500</price> 
</item> 

<item> 
    <id>3</id> 
    <name>MacBook Pro</name> 
    <category>Mobile PC</category> 
    <price>2000</price> 
</item> 

<item> 
    <id>4</id> 
    <name>iTouch</name> 
    <category>Gadgets</category> 
    <price>150</price> 
</item> 

<item> 
    <id>5</id> 
    <name>Wii</name> 
    <category>Gaming</category> 
    <price>1250</price> 
</item> 

<item> 
    <id>6</id> 
    <name>Time Capsule</name> 
    <category>Acessories</category> 
    <price>1000</price> 
</item> 

<item> 
    <id>7</id> 
    <name>Apple TV</name> 
    <category>Gadgets</category> 
    <price>800</price> 
</item> 

+0

您的XML看起來像什麼?另外,XSLT。 – 2010-11-25 04:51:28

+0

@Ignacio。我不認爲XML或XSLT會導致PHP語法錯誤 – Ben 2010-11-25 04:53:14

+0

@Ignacio Vazquez-Abrams我沒有XSLT – bentham 2010-11-25 04:59:29

回答

2

你已經有了$xmlfile="「C:\wamp\www\"

1

雙引號在線路

$xmlfile="「C:\wamp\www\" . $filename; 

您正在使用反斜線,必須轉義。將其更改爲

$xmlfile="C:\\wamp\\www\\" . $filename; 
相關問題