Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP(XML到数组)获取作为数组的XML的属性_Php_Arrays_Xml_Json - Fatal编程技术网

PHP(XML到数组)获取作为数组的XML的属性

PHP(XML到数组)获取作为数组的XML的属性,php,arrays,xml,json,Php,Arrays,Xml,Json,您好,我正在使用spilgames xml进行游戏。我设法将其转换为数组,但又出现了一个问题,问题是我要获取的字符串位于数组或1节点xml的属性中。我无法获取该属性 我想得到属性 spilgames网站: 到目前为止,我掌握的代码是: <?php $xml = simplexml_load_string(file_get_contents('http://publishers.spilgames.com/rss-3?limit=100&format=xml&cat

您好,我正在使用spilgames xml进行游戏。我设法将其转换为数组,但又出现了一个问题,问题是我要获取的字符串位于数组或1节点xml的属性中。我无法获取该属性

我想得到属性

spilgames网站:

到目前为止,我掌握的代码是:

<?php

    $xml = simplexml_load_string(file_get_contents('http://publishers.spilgames.com/rss-3?limit=100&format=xml&category=Action')); /* Get the xml */
    $json = json_encode($xml);
    $games = json_decode($json); /* Make it an array */
    $game = $games->entries->entry;
    foreach($game as $entry) { /* Each game information */
        echo $entry->title;
        echo $entry->id;
        echo $entry->description;
        echo $entry->category;
        echo $entry->subcategory;
        echo $entry->technology;
        echo $entry->player->url;;
        echo $entry->thumbnails->small->url; /* Problems starts here */
   /* Because the thumbnails has 3 child but the info is inside of each child */
    }

?>


我在spilgames中得到的是xml而不是json,因为我不知道json是如何工作的。

如果我是你,我会学习json是如何工作的,因为它会让你的生活更轻松:

<?php
$json = file_get_contents('http://publishers.spilgames.com/rss-3?limit=100&format=json&category=Action');
$data = json_decode($json);

foreach ($data->entries as $entry) {
  echo $entry->title . "\n";
  echo $entry->id . "\n";
  echo $entry->description . "\n";
  echo $entry->category . "\n";
  echo $entry->subcategory . "\n";
  echo $entry->technology . "\n";

  echo $entry->thumbnails->small . "\n";
  echo $entry->thumbnails->medium . "\n";
  echo $entry->thumbnails->large . "\n";
}
?>