尝试通过PHP从xml文件中提取多个节点

My XML file is:

<?xml version="1.0" encoding="UTF-8"?>
<item>
    <title>Hello</title>
    <link>http://www.google.com</link>
</item>
<item>
    <title>Some Title</title>
    <link>http://www.google.com</link>
</item>

I want to get this array from the xml file:

  0 => 
    array
      'title' => string 'Hello' (length=5)
      'link' => string 'http://www.google.com' (length=21)
  1 => 
    array
      'title' => string 'Some Title' (length=10)
      'link' => string 'http://www.google.com' (length=21)

Is it possible? If so, could anyone help me out?

Cheers!

Your XML is not well-formed. Since the tag is the first in the document, the following </item> effectively terminates the document per the spec. You'd want to add an additional tag wrapping the <item>, e.g. <document><item>...</item><item>...</item></document>.

To process simply in PHP, use simplexml, e.g.:

<?php

$xml=<<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<document>
<item>
    <title>Hello</title>
    <link>http://www.google.com</link>
</item>
<item>
    <title>Some Title</title>
    <link>http://www.google.com</link>
</item>
</document>
EOD;

$sxml = simplexml_load_string($xml);
var_dump($sxml);

note that simplexml by default returns objects instead of array values. It's fairly simple to extract values you want from objects instead of arrays, however. For example:

echo $sxml->item[0]->title;

would output Hello with the above XML.