好的,首先让我告诉你我的剧本。
<?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
请帮我这样做。对我来说,任何参考都应该没问题。
答案 0 :(得分:1)
要以人类可读的形式输出结果,而不是print_r,您只需在foreach循环中循环结果;
foreach($balance_info as $key=>$value) {
echo "$key: $value<br />";
}
或者对于更具体的命名,如果您知道列是什么,请使用->
访问对象属性并将其回显;
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; ?>
答案 1 :(得分: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 } ?>