3

私はphpに本当に慣れていないので、外部xmlフィードからphpドキュメントにデータをロードしようとしています。次に、そのデータを使用して出力を生成します。

私が使用している xml フィードは - http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=1&marketSort=--&filterBIR=Nです。

私がやろうとしているのは、「市場」とそこにある名前のリストを生成することです。そのため、リストの最初の 3 つの項目を書いている時点での xml フィードは次のようになります。

  • スコティッシュ ディビジョン 1 - アウトライト - アウトライト
  • ダンバートン v ハミルトン - 前半結果/後半結果
  • ダンバートン v ハミルトン - マッチ ハンディキャップ

現時点では、これを達成するために次のコードを使用しようとしていますが、すぐにどこにも行きません。ここで何が間違っているのかについてのアイデアはありますか?

php 5.4.4を使用している背景のもう1つの部分ですが、simplexmlはすでに事前にインストールされていると考えています..だから、ここに何か追加する必要はありませんか?

<?php 

$xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=1&marketSort=--&filterBIR=N');

foreach ($xml->market as $event) {
  echo $event;
}

?>
4

2 に答える 2

3

xml をドリルダウンして市場を取得し、市場の属性を取得する必要があります。

<?php 

$xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=1&marketSort=--&filterBIR=N');

foreach ($xml->response->williamhill->class->type as $type) {
  $type_attrib = $type->attributes();
  echo "<p><h2>Type ".$type_attrib['id'].": ".$type_attrib['name']."</h2>";
  foreach ($type->market as $event) {
    $event_attributes = $event->attributes();
    echo $event_attributes['name']."<br />";
    //commented out the following which prints all attributes
    //replaced by above to just print the name
    /*
    echo "<p>";
    foreach($event->attributes() as $attrib=>$value) {
      echo "$attrib: $value <br />";
    }
    echo "</p>";
    */
  }
  echo "</p>";
}
于 2013-01-21T16:34:21.947 に答える
0

たとえば、これを行う参加者の名前とそれぞれのオッズを表示できます。

<?php 

$xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=1&marketSort=--&filterBIR=N');


$data = $xml->response->williamhill->class->type->market;
$ps = $data->participant;
foreach($ps as $p)
{
    echo $p['name']." - ".$p['odds']."<br />";
}

?>
于 2013-01-21T16:40:54.620 に答える