如何从php中的simplexml_load_file()获取值?

时间:2021-07-31 00:12:03

I am getting an XML response from an api.Here is the code

我从api获得XML响应。这是代码

$xml = simplexml_load_file($actualurl);
    echo '<pre>';
print_r($xml);
    echo '</pre>';

The output will look like this

输出将如下所示

SimpleXMLElement Object
(
    [MERCHANT] => SimpleXMLElement Object
        (
            [RESPONSE] => SimpleXMLElement Object
                (
                    [url] => https://xxx/xxx/epi/fts
                    [param] => Array
                        (
                            [0] => NBFundTransfer
                            [1] => 354206
                            [2] => fhyF1K5nmhXJmhoIUb04%2BEiIe80rLda52l4bCviNPwg%3D
                            [3] => 1
                        )

                )

        )

)

Problem I cant get the node values of param array.I tried $xml->param but it shows nothing returns an empty value.

问题我无法得到param数组的节点值。我尝试了$ xml-> param,但它没有显示任何返回空值。

2 个解决方案

#1


3  

Use

使用

print_r($xml->MERCHANT->RESPONSE->param[0]);

#2


0  

    print_r($xml->MERCHANT->RESPONSE->param);

    $param = $xml->MERCHANT->RESPONSE->param;
    echo $param[0]; //=> NBFundTransfer
 echo '<br>';
    echo $param[1]; // => 354206
 echo '<br>';
    echo $param[2]; // => fhyF1K5nmhXJmhoIUb04%2BEiIe80rLda52l4bCviNPwg%3D
 echo '<br>';
    echo $param[3]; // => 1

#1


3  

Use

使用

print_r($xml->MERCHANT->RESPONSE->param[0]);

#2


0  

    print_r($xml->MERCHANT->RESPONSE->param);

    $param = $xml->MERCHANT->RESPONSE->param;
    echo $param[0]; //=> NBFundTransfer
 echo '<br>';
    echo $param[1]; // => 354206
 echo '<br>';
    echo $param[2]; // => fhyF1K5nmhXJmhoIUb04%2BEiIe80rLda52l4bCviNPwg%3D
 echo '<br>';
    echo $param[3]; // => 1