0

对此很陌生,无法弄清楚如何引用元素。

我正在使用 PHP,并且希望能够将 First_Name 中的值放入 HTML 表中的单元格中。

谢谢你的帮助。

输出片段:

SimpleXMLElement Object
(
[@attributes] => Array
    (
        [organization_KEY] => 5728
    )

[supporter-supporter_KEY-supporter_groups] => SimpleXMLElement Object
    (
        [item] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [supporter_KEY] => 6147839
                        [organization_KEY] => 12345
                        [chapter_KEY] => SimpleXMLElement Object
                            (
                            )

                        [Last_Modified] => Thu Jul 09 2009 15:11:39 GMT-0400 (EDT)
                        [Date_Created] => Thu Jul 09 2009 14:44:22 GMT-0400 (EDT)
                        [Title] => Mr.
                        [First_Name] => Michael
                        [MI] => SimpleXMLElement Object
                            (

----------------------------------------------------

php ----------------------------------------------------
curl_setopt($ch, CURLOPT_URL, "$url/getLeftJoin.sjs");
$fields = array('object' => 'supporter(supporter_KEY)supporter_groups',       'condition'=>'supporter_KEY=123456' );
echo (http_build_query($fields));
//return the transfer as a string
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
// $output contains the output string
$output = curl_exec($ch);
//Populate results from salsa into SimpleXML object
// See http://us3.php.net/manual/en/book.simplexml.php for more information
// on SimpleXML objects in PHP
$data = simplexml_load_string($output);
**echo ("data ". $data->supporter->First_Name);** 

4

1 回答 1

0

Item 是一个数组,因此您可以寻址数组中的第一个元素:

$data->supporter->item[0]->First_Name

http://www.php.net/manual/en/simplexml.examples-basic.php

尝试:

echo $data->{'supporter-supporter_KEY-supporter_groups'}->item->[0]->First_Name;

花括号可防止对用作减法的连字符进行任何解释。

于 2013-10-04T14:24:40.253 回答