2011-12-19 71 views
0

我有以下SimpleXML的循环条目

<entry> 
     <id></id> 
     <title></title> 
     <dc:identifier></dc:identifier> 
     <dc:identifier></dc:identifier> 
     <dc:relation></dc:relation> 
     <dc:publisher></dc:publisher> 
     <dc:language xsi:type="dcterms:ISO639-2"></dc:language> 
     <dcterms:issued></dcterms:issued> 
     <updated></updated> 
     <rights></rights> 
     <author> 
      <name></name> 
      <uri></uri> 
     </author> 
     <link rel="alternate" href="" type="text/html"/> 
     <link rel="http://opds-spec.org/image" href="" type="image/jpeg"/> 
     <link rel="http://opds-spec.org/image/thumbnail" href="" type="image/jpeg"/> 
     <link rel="http://opds-spec.org/acquisition/buy" href="" type="application/epub+zip"> 
      <opds:price currencycode="EUR"></opds:price> 
     </link> 
     <summary type="text"></summary> 
</entry> 
<entry> 
     <id></id> 
     <title></title> 
     <dc:identifier></dc:identifier> 
     <dc:identifier></dc:identifier> 
     <dc:relation></dc:relation> 
     <dc:publisher></dc:publisher> 
     <dc:language xsi:type="dcterms:ISO639-2"></dc:language> 
     <dcterms:issued></dcterms:issued> 
     <updated></updated> 
     <rights></rights> 
     <author> 
      <name></name> 
      <uri></uri> 
     </author> 
     <link rel="alternate" href="" type="text/html"/> 
     <link rel="http://opds-spec.org/image" href="" type="image/jpeg"/> 
     <link rel="http://opds-spec.org/image/thumbnail" href="" type="image/jpeg"/> 
     <link rel="http://opds-spec.org/acquisition/buy" href="" type="application/epub+zip"> 
      <opds:price currencycode="EUR"></opds:price> 
     </link> 
     <summary type="text"></summary> 
</entry> 
...... 

的XML解析所有(的SimpleXML)

现在我想在time.So拿到一个项目我路过一个变种,当我可以罚款解析它我的文件中像

file.php?start=1 
file.php?start=2 
etc 

,我试图访问当前项目

$xml->entry[$start] returns NULL 

OR

$xml->entry->{$start} returns NULL 

但都返回NULL

我试图直接访问它

$xml->entry[1] 
$xml->entry->{1} 

其做工精细

我失去了somehthing?

回答

1

$ _GET ['start']可能不是正确的变量类型,请尝试将类型转换为整数。

+0

感谢没有想到这个 – ntan 2011-12-19 07:04:25

1
<?php 
$xml = simplexml_load_file('simplexml.php'); 

$id = '1'; 
print_r($xml->entry[$id]); 
?> 

结果:

NULL

<?php 
$xml = simplexml_load_file('simplexml.php'); 

$id = '1'; 
$id = (int)$id; 

print_r($xml->entry[$id]); 

?> 

结果:

SimpleXMLElement对象 ( [条目] => SimpleXMLElement对象 ( [id] => 2 [标题] =>其他标题 ) )