Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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 如何以HTML格式输出WSDL请求的结果?_Php_Html_Soap_Wsdl - Fatal编程技术网

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
}