我需要一些幫助。正如你所想象的那樣,現在我已經在這個問題上打破了近五個小時,我感到有點沮喪。WHOIS API JSON數組內容
我的失望主要是由於我對JSON數組的經驗不足,特別是更復雜的數組以及如何在PHP中處理它們。無論我迄今爲止嘗試修改以下示例代碼,都會導致大量錯誤或無腳本執行...
我正在使用以下服務 - >WHOIS API查找有關某個特定域名/ IP。
服務會返回一個JSON數組,像這樣的一個例子:`
{
"WhoisRecord": {
"createdDate": "1997-09-15T00:00:00-0700",
"updatedDate": "2015-06-12T10:38:52-0700",
"expiresDate": "2020-09-13T21:00:00-0700",
"registrant": {
"name": "Dns Admin",
"organization": "Google Inc.",
"street1": "Please contact [email protected], 1600 Amphitheatre Parkway",
"city": "Mountain View",
"state": "CA",
"postalCode": "94043",
"country": "UNITED STATES",
"email": "[email protected]",
"telephone": "16502530000",
"fax": "16506188571",
"rawText": "Registrant Name: Dns Admin\nRegistrant Organization: Google Inc.\nRegistrant Street: Please contact [email protected], 1600 Amphitheatre Parkway\nRegistrant City: Mountain View\nRegistrant State/Province: CA\nRegistrant Postal Code: 94043\nRegistrant Country: US\nRegistrant Phone: +1.6502530000\nRegistrant Fax: +1.6506188571\nRegistrant Email: [email protected]"
},
"administrativeContact": {
"name": "DNS Admin",
"organization": "Google Inc.",
"street1": "1600 Amphitheatre Parkway",
"city": "Mountain View",
"state": "CA",
"postalCode": "94043",
"country": "UNITED STATES",
"email": "[email protected]",
"telephone": "16506234000",
"fax": "16506188571",
"rawText": "Admin Name: DNS Admin\nAdmin Organization: Google Inc.\nAdmin Street: 1600 Amphitheatre Parkway\nAdmin City: Mountain View\nAdmin State/Province: CA\nAdmin Postal Code: 94043\nAdmin Country: US\nAdmin Phone: +1.6506234000\nAdmin Fax: +1.6506188571\nAdmin Email: [email protected]"
}
}
}`
所有我感興趣的是WhoisRecord - >註冊部分(姓名,單位,street1,城市,州,郵編,國家,電子郵件等)
到目前爲止,這麼好。
但是,當我運行PHP代碼示例時,他們提供的API對於我來說開始變得有點困惑。代碼如下表顯示:
<?php
$username="YOUR_USERNAME";
$password="YOUR_PASSWORD";
$contents = file_get_contents("http://www.whoisxmlapi.com//whoisserver/WhoisService?domainName=google.com&username=$username&password=$password&outputFormat=JSON");
//echo $contents;
$res=json_decode($contents);
if($res){
if($res->ErrorMessage){
echo $res->ErrorMessage->msg;
}
else{
$whoisRecord = $res->WhoisRecord;
if($whoisRecord){
echo "Domain name: " . print_r($whoisRecord->domainName,1) ."<br/>";
echo "Created date: " .print_r($whoisRecord->createdDate,1) ."<br/>";
echo "Updated date: " .print_r($whoisRecord->updatedDate,1) ."<br/>";
if($whoisRecord->registrant)echo "Registrant: <br/><pre>" . print_r($whoisRecord->registrant->rawText, 1) ."</pre>";
//print_r($whoisRecord);
}
}
}
?>
我立刻得到砰的一聲,當我執行它,錯誤的量時,某些數據丟失(例如註冊人的名字)增加了以下錯誤。
Notice: Undefined property: stdClass::$ErrorMessage in /home/users/pcsnlftp/india.pcs-nl.com/includes/scripts/test/test-processor.php on line 47
Domain name: google.com
Created date: 1997-09-15T00:00:00-0700
Updated date: 2015-06-12T10:38:52-0700
Registrant:
Registrant Name: Dns Admin Registrant Organization: Google Inc. Registrant Street: Please contact [email protected], 1600 Amphitheatre Parkway Registrant City: Mountain View Registrant State/Province: CA Registrant Postal Code: 94043 Registrant Country: US Registrant Phone:+1.6502530000 Registrant Fax: +1.6506188571 Registrant Email: [email protected]
我的問題是雙管齊下的;
- 我該如何擺脫基本上無用的錯誤(對我)?
- 如何將所需的數據導入到我可以插入到MySQL數據庫中的變量中?
任何幫助將不勝感激!
'如果(isset($水庫>的ErrorMessage ))'應該解決你的第一個問題....第二個只是使用例如'$ domain = $ whoisRecord-> domainName'而不是整個回聲的東西 –
非常感謝你澄清,請原諒我對此的無知;但如果它像'$ domain = $ whoisRecord-> domainName'那麼簡單,他們爲什麼使用'print_r'? –
print_r($ variable,1)返回值....更多詳細信息,請訪問http://php.net/manual/en/function.print-r.php –