Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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获取属性_Php_Xml - Fatal编程技术网

使用PHP从XML获取属性

使用PHP从XML获取属性,php,xml,Php,Xml,我使用PHP的SimpleXML从以下XML中获取一些值 - <entry> <id>http://www.google.com/m8/feeds/contacts/email_address%40gmail.com/base/0</id> <updated>2010-01-14T22:06:26.565Z</updated> <category scheme="http://schemas.google.com/

我使用PHP的SimpleXML从以下XML中获取一些值

- <entry>
  <id>http://www.google.com/m8/feeds/contacts/email_address%40gmail.com/base/0</id> 
  <updated>2010-01-14T22:06:26.565Z</updated> 
  <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact" /> 
  <title type="text">Customer Name</title> 
  <link rel="http://schemas.google.com/contacts/2008/rel#edit-photo" type="image/*" href="http://www.google.com/m8/feeds/photos/media/email_address%40gmail.com/0/34h5jh34j5kj3444" /> 
  <link rel="self" type="application/atom+xml" href="http://www.google.com/m8/feeds/contacts/email_address%40gmail.com/full/0" /> 
  <link rel="edit" type="application/atom+xml" href="http://www.google.com/m8/feeds/contacts/email_address%40gmail.com/full/0/5555" /> 
  <gd:email rel="http://schemas.google.com/g/2005#other" address="customer@gmail.com" primary="true" /> 
  </entry>
-
http://www.google.com/m8/feeds/contacts/email_address%40gmail.com/base/0 
2010-01-14T22:06:26.565Z
客户名称
我可以通过以下方式获得标题:

$xml = new SimpleXMLElement($response_h1);

foreach ($xml->entry as $entry) {
   echo $entry->title, '<br />';
}
$xml=新的simplexmlement($response\u h1);
foreach($xml->entry as$entry){
echo$entry->title,
; }

但是如何获得地址=”customer@gmail.com属性?

您的命名空间无效。如果没有名称空间,您应该能够像这样获取地址

$email = (string)$xml->email['address'];
SimpleXML中有一些bug。元素使用成员语法“->”,但属性只能使用数组语法“[]”访问