2014-11-26 4 views
0

나는 내가 HTML 출력이 $가을 초래할 수있는 방법 간단한 클라이언트HTML로 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 converted to string 

?> 

을 썼다?

위해서 var_dump 결과 :

object(stdClass)[2] 
    public 'GetGeoIPContextResult' => 
    object(stdClass)[3] 
     public 'ReturnCode' => int 1 
     public 'IP' => string '62.122.245.38' (length=13) 
     public 'ReturnCodeDetails' => string 'Success' (length=7) 
     public 'CountryName' => string 'Russian Federation' (length=18) 
     public 'CountryCode' => string 'RUS' (length=3) 
+0

'var_dump'의 출력 기능 :

// 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> 

은 또한 당신이 먼저 성공 여부를 확인할 수 있습니다? HTML 요소가 어떤 값으로 인쇄되고 싶습니까? – Havelock

+0

나는 ip, CountryName, CountryCode 및 그 값을 출력해야합니다. – BKI

답변

1

변수 $resultstdClass입니다. 데이터가 저장되는 (문자열로) 해당 속성 $GetGeoIPContextResult도 유형이 stdClass이므로 간단한 방식으로 처리 할 수 ​​있습니다.

if ($result->GetGeoIPContextResult->ReturnCodeDetails == 'Success') { 
    // insert here the code above 
} 
+1

도움을 주셔서 감사합니다. 모든 것이 잘 작동합니다.)) – BKI

0

당신이 HTML 무엇을 의미합니까?

만 값을 읽을 수 있도록해야하는 경우

$readable_json = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); 
echo '<pre>'; 
echo $readable_json; 
echo '</pre>'; 

또는 var_export

$readable_dump = var_export($result, true); 
echo '<pre>'; 
echo $readable_dump; 
echo '</pre>'; 
0

Silution은 간단 사용할 수 있습니다 : 당신이 JSON으로 한 번에 결과를 표시 할 수 있습니다

print $result->GetGeoIPContextResult->IP . '<br />'; 
print $result->GetGeoIPContextResult->ReturnCode . '<br />'; 
print $result->GetGeoIPContextResult->CountryName . '<br />'; 
print $result->GetGeoIPContextResult->CountryCode . '<br />'; 
관련 문제