2011-12-19 7 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は)

を解析するとき、私は罰金それを解析することができます今、私はVARを渡すtime.Soで一つのアイテムを取得したいです

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

ように私のファイルへと私は、現在の項目

$xml->entry[$start] returns NULL 
012にアクセスしようとしました

OR

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

が、両方のリターンが

をNULL私は

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

その作業罰金直接アクセスしようとした私はsomehthing足りませんか?

答えて

1

$ _GET ['start']はおそらく適切な変数型ではありません。

+0

ありがとうございました – ntan

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 [title] =>その他のタイトル )