English 中文(简体)
XML 到 ARARAY 解析 [重复]
原标题:XML to ARRAY conversition [duplicate]
  • 时间:2012-05-28 12:58:08
  •  标签:
  • php
  • xml

php。 我需要做一个任务, 将 xml 转换为数组。 我需要完成一个任务, 将 xml 转换为数组 。 I need to do a compulate to find a lot out on the net and find out a search a lot of comple class class doing this for me 但每个函数都需要我不明白如何通过正确的参数的参数 。 我需要一个函数, 这个链接的 xml

  http://feeds.nytimes.com/nyt/rss/SundayBookReview

如果您按 ctrl+u 键, 它将会给您源代码, b xml i 需要 xml through php 然后将其转换成数组, 请帮我解开. i 被卡住 。

最佳回答

这就是我用的东西:

<?php

function xmlobj2arr($Data)
{
   if (!isset($ret)) { $ret = array(); }
   if (is_object($Data))
      { foreach (get_object_vars($Data) as $key => $val) { $ret[$key] = xmlobj2arr($val); } return $ret; }
   elseif (is_array($Data)) {
      foreach ($Data as $key => $val) { $ret[$key] = xmlobj2arr($val); } return $ret;
   } else { return $Data; }
}

$thexml = new SimpleXMLElement( file_get_contents("http://feeds.nytimes.com/nyt/rss/SundayBookReview") );
$arr = xmlobj2arr($thexml);
echo "<pre>";
print_r($arr);
echo "</pre>";

?>
问题回答

使用 < a href=> "http://www.spepepie.org/" rel="no follow" >pepie

很简单 下载它 检查演示

检查演示代码 "https://github.com/spepepie/spepepie/blob/master/demo/index.php" rel="no follow" >这里





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签