将Whois返回的字符串转换为对象或数组

克雷格

我需要将一个返回简单字符串的Whois查询转换为PHP对象,PHP关联数组或PHP json对象。

我从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: [email protected]
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: [email protected]
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: [email protected]
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: [email protected]
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>";

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章