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

Php 将返回的字符串转换为对象或数组,php,string,parsing,whois,Php,String,Parsing,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 Updat

我需要将返回简单字符串的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: 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;
但我真正需要的是提取这个的特定部分,比如这个

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;

字符串中的每个新字段都以文本开头,然后是“:”,然后以值结尾


是否有人有一个聪明的计划能够将这个字符串解析成一个对象或关联数组?

行由一个换行符分隔,并且在每一个具有字典模式的行中,条目及其对应的值由第一个
分隔:'
(其他行应该是没有字典模式的补充信息),以下内容将帮助您开始:

$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>";
$rows=explode(“\n”,$stresult);
$arr=数组('info'=>“”);
foreach($行作为$行){
$POSOFFIRSTCLON=strpos($row,“:”);
if($POSOFFIRSTCLON==FALSE)
$arr['info'].=$row;
其他的
$arr[substr($row,0,$posOfFirstColon)]=修剪(substr($row,$posOfFirstColon+1));
}
回声“;
var_转储($arr);
回声“;

你是怎么得到这个字符串的?从
exec
?特别是你想要提取哪些部分?使用whois api返回一个已经格式化的字符串\object\array\Ghost-我从Adrian那里得到了这个代码-我想把所有可用字段提取为数组或objectHi。谢谢。我在过去的20分钟里一直沿着这个路径走utes基于@Ghost的建议。这对我很有效。@Craig欢迎:),但正如我所指出的,这只是一个起点,你可以将其更改为更适合你的需要,祝你好运:)