2014-08-29 22:54
浏览 66


I have been searching for how to read one node of XML in PHP. The PHP documentation wasn't helpful because I don't understand how to use PHP. All of the tutorials I found weren't useful beacause I only need PHP to read XML(I use CSHTML for Databases and other server-side things). I have working code that can read XML as a tree if it is in a RSS format. I am trying to get the google map geocode api information, from ",-90.8455276&sensor=false." I only want the very first "Formatted_address" node. My current code is;


$xmlDoc = new DOMDocument();

//get and output "<result>" elements
for ($i=0; $i<=2; $i++)

  echo ( $item);

However this always returns a 500 error and I don't understand what i am doing wrong. Thank you all in advance.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtdr84101 2014-08-29 23:00

    Change result to item

    $item = $x->item($i)->getElementsByTagName('formatted_address')

    As you can see DOMNodeList only has one method called item(int $index)

    打赏 评论

相关推荐 更多相似问题