Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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处理SimpleXML元素_Php - Fatal编程技术网

用PHP处理SimpleXML元素

用PHP处理SimpleXML元素,php,Php,对此不熟悉,无法理解如何引用元素 我正在使用PHP,希望能够将First_Name中的值放入HTML表的单元格中 谢谢你的帮助 小部分输出: SimpleXMLElement Object ( [@attributes] => Array ( [organization_KEY] => 5728 ) [supporter-supporter_KEY-supporter_groups] => SimpleXMLElement Object

对此不熟悉,无法理解如何引用元素

我正在使用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);** 


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

$data->supporter->item[0]->名字

尝试:

echo$data->{'supporter-supporter\u KEY-supporter\u groups'}->item->[0]->First\u Name


大括号可以防止连字符被用作减法运算。

稍微调整一下。。echo$data->{'supporter-supporter\u KEY-supporter\u groups'}->item->First\u Name