簡體   English   中英

將Whois返回的字符串轉換為對象或數組

[英]Convert whois returned string to object or array

我需要轉換將簡單字符串返回到PHP對象,PHP關聯數組或PHP json對象的whois查詢。

我從whois服務器返回的文本看起來像這樣...

Domain Name: SAILING-WHITSUNDAYS.COM
Registry Domain ID: 95143260_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.wildwestdomains.com
Registrar URL: http://www.wildwestdomains.com
Update Date: 2012-07-24T05:38:29Z
Creation Date: 2003-02-21T05:20:23Z
Registrar Registration Expiration Date: 2021-02-21T05:20:23Z
Registrar: Wild West Domains, LLC
Registrar IANA ID: 440
Registrar Abuse Contact Email: abuse@wildwestdomains.com
Registrar Abuse Contact Phone: +1.480-624-2505
Reseller: Domains Priced Right
Domain Status: clientTransferProhibited http://www.icann.org/epp#clientTransferProhibited
Domain Status: clientUpdateProhibited http://www.icann.org/epp#clientUpdateProhibited
Domain Status: clientRenewProhibited http://www.icann.org/epp#clientRenewProhibited
Domain Status: clientDeleteProhibited http://www.icann.org/epp#clientDeleteProhibited
Registry Registrant ID:
Registrant Name: Craig Hamilton
Registrant Organization:
Registrant Street: Airlie Beach
Registrant City: Airlie Beach
Registrant State/Province: Queensland
Registrant Postal Code: 4802
Registrant Country: Australia
Registrant Phone: 749461451
Registrant Phone Ext:
Registrant Fax:
Registrant Fax Ext:
Registrant Email: craig@mr-travel.com
Registry Admin ID:
Admin Name: Craig Hamilton
Admin Organization:
Admin Street: Airlie Beach
Admin City: Airlie Beach
Admin State/Province: Queensland
Admin Postal Code: 4802
Admin Country: Australia
Admin Phone: 749461451
Admin Phone Ext:
Admin Fax:
Admin Fax Ext:
Admin Email: craig@mr-travel.com
Registry Tech ID:
Tech Name: Craig Hamilton
Tech Organization:
Tech Street: Airlie Beach
Tech City: Airlie Beach
Tech State/Province: Queensland
Tech Postal Code: 4802
Tech Country: Australia
Tech Phone: 749461451
Tech Phone Ext:
Tech Fax:
Tech Fax Ext:
Tech Email: craig@mr-travel.com
Name Server: NS1.OZIDEA.COM
Name Server: NS2.OZIDEA.COM
DNSSEC: unsigned
URL of the ICANN WHOIS Data Problem Reporting System: http://wdprs.internic.net/
Last update of WHOIS database: 2015-05-05T04:00:00Z
For more information on Whois status codes, please visit https://www.icann.org/resources/pages/epp-status-codes-2014-06-16-en
The data contained in this Registrar's Whois database,
while believed by the registrar to be reliable, is provided "as is"
with no guarantee or warranties regarding its accuracy. This information
is provided for the sole purpose of assisting you in obtaining
information about domain name registration records. Any use of
this data for any other purpose is expressly forbidden without
the prior written permission of this registrar.  By submitting an
inquiry, you agree to these terms of usage and limitations of warranty.
In particular, you agree not to use this data to allow, enable, or
otherwise make possible, dissemination or collection of this data, in
part or in its entirety, for any purpose, such as the transmission of
unsolicited advertising and solicitations of any kind, including spam.
You further agree not to use this data to enable high volume, automated
or robotic electronic processes designed to collect or compile this data
for any purpose, including mining this data for your own personal or
commercial purposes.
Please note: the owner of the domain name is specified in the "registrant" section.
In most cases, the Registrar is not the owner of domain names listed in this database.

我真正需要的是提取像這樣的特定部分...

$Result->Reseller;

要么

$Result['Reseller'];

字符串中的每個新字段均以文本開頭,然后是“:”,然后以值結尾。

有沒有人有一個聰明的計划能夠將這個字符串解析為一個對象或關聯數組?

這些行由換行符分隔,並且在每條具有字典模式的行中,條目及其對應的值都由第一個':'分隔(其他行應該是沒有字典模式的補充信息。 ),以下內容將幫助您入門:

$rows = explode("\n", $strResult);
$arr = array('info'=>"");
foreach($rows as $row) {
    $posOfFirstColon = strpos($row, ":");
    if($posOfFirstColon === FALSE)
        $arr['info'] .= $row;
    else
        $arr[substr($row, 0, $posOfFirstColon)] = trim(substr($row, $posOfFirstColon+1));
}
echo "<pre>";
var_dump($arr);
echo "</pre>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM