好的,这可能是一个愚蠢的问题,但是如何从 XML 文档中获取单个元素?
我有这个 XML
$element = $response['linkedin'];
SimpleXMLElement Object
(
[id] => 575677478478
[first-name] => John
[last-name] => Doe
[email-address] => john@doe.com
[picture-url] => http://m3.licdn.com/mpr/mprx/123
[headline] => Headline goes here
[industry] => Internet
[num-connections] => 71
我只想分配first-name
为$firstName
我可以使用 xPath 循环它,但这似乎有点过头了。
前任:
$fName = $element->xpath('first-name');
foreach ($fName as $name)
{
$firstName = $name;
}