1

好的,首先让我向您展示我的脚本。

<?php  
$soap_exception_occured = false;

$wsdl_path = 'http://vrapi.xyz.com/?wsdl';

$response = '';

ini_set('soap.wsdl_cache_enabled', '0'); // disabling WSDL cache

try {
    $client = new SoapClient($wsdl_path);
    }

catch(SoapFault $exception) {
    $soap_exception_occured = true;
    $response .= '\nError occoured when connecting to the SMS SOAP Server!';
    $response .= '\nSoap Exception: '.$exception;
    } 

/* Create a Recharge at VR */
$client_id = 'appl45fgysssl';

$balance_info = new stdClass(); 
try {  
$balance_info = $client->GetBalanceInfo($client_id); 
} 

catch(SoapFault $exception) { 
 $soap_exception_occured = true;  
 $response .= "\nError occoured at method GetBalanceInfo($client_id)";  
 $response .= "\nSoap Exception: ".$exception; 
 } 

 /* Do something or print results */
 if($soap_exception_occured || $balance_info==null) echo $response; 
 else print_r($balance_info); 

 ?>

并在浏览器中输出

stdClass Object ( [client_user_id] => appl45fgysssl [available_credit] => 9755 [last_updated_time] => 2012-07-29 14:30:15 ) 

我想以排列良好的格式显示数据。前任。

客户端:appl45fgysssl

余额:9755

时间:2012-07-29 14:30:15

请帮我这样做。任何参考对我来说都应该没问题。

4

2 回答 2

1

要以人类可读的形式输出结果,而不是 print_r,您可以简单地在 foreach 循环中循环遍历结果;

foreach($balance_info as $key=>$value) {
    echo "$key: $value<br />";
}

或者对于更具体的命名,如果您知道列是什么,则使用 a->访问对象属性并将它们回显;

Client: <?php echo $balance_info->client_user_id; ?><br />
Balance: <?php echo $balance_info->available_credit; ?></br />
Time: <?php echo $balance_info->last_updated_time; ?>

http://php.net/manual/en/sdo.sample.getset.php

于 2012-07-29T09:33:52.177 回答
1

正如@Stu 所说,这将是您的完美答案。检查这部分。

/* Do something or print results */
if($soap_exception_occured || $balance_info==null) echo $response; 
else { ?>

        Client: <?php echo $balance_info->client_user_id; ?><br />
        Balance: <?php echo $balance_info->available_credit; ?></br />
        Time: <?php echo $balance_info->last_updated_time; ?>
<?php } ?>
于 2012-07-29T10:00:16.647 回答