Php 如何以HTML格式输出WSDL请求的结果?
我写了一个简单的客户端Php 如何以HTML格式输出WSDL请求的结果?,php,html,soap,wsdl,Php,Html,Soap,Wsdl,我写了一个简单的客户端 <?php $client = new SoapClient("http://www.webservicex.net/geoipservice.asmx?WSDL"); $result = $client->GetGeoIPContext(); var_dump($result); print $result; // Issue: Catchable fatal error: Object of class stdClass could not be co
<?php
$client = new SoapClient("http://www.webservicex.net/geoipservice.asmx?WSDL");
$result = $client->GetGeoIPContext();
var_dump($result);
print $result; // Issue: Catchable fatal error: Object of class stdClass could not be converted to string
?>
你说的HTML是什么意思 如果您只需要能够读取值:您可以一次性将结果显示为JSON:
$readable_json = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo '<pre>';
echo $readable_json;
echo '</pre>';
';
方案很简单:
if ($result->GetGeoIPContextResult->ReturnCodeDetails == 'Success') {
// insert here the code above
}
print$result->GetGeoIPContextResult->IP'
;
打印$result->GetGeoIPContextResult->ReturnCode。“
;
打印$result->GetGeoIPContextResult->CountryName。“
;
打印$result->GetGeoIPContextResult->CountryCode。“
;
由于变量$result
的类型为stdClass
,其存储数据(作为字符串)的属性$GetGeoIPContextResult
的类型也为stdClass
,因此可以直接执行,例如
var\u dump
的输出是什么?还有,您希望打印哪些值,在哪些HTML元素中?我需要输出ip、CountryName、CountryCode及其值
$readable_dump = var_export($result, true);
echo '<pre>';
echo $readable_dump;
echo '</pre>';
print $result->GetGeoIPContextResult->IP . '<br />';
print $result->GetGeoIPContextResult->ReturnCode . '<br />';
print $result->GetGeoIPContextResult->CountryName . '<br />';
print $result->GetGeoIPContextResult->CountryCode . '<br />';
// the IP address in a div
<div><?php echo $result->GetGeoIPContextResult->IP; ?></div>
// the country name in a div
<div><?php echo $result->GetGeoIPContextResult->CountryName; ?></div>
// the country code in a div
<div><?php echo $result->GetGeoIPContextResult->CountryCode; ?></div>
if ($result->GetGeoIPContextResult->ReturnCodeDetails == 'Success') {
// insert here the code above
}