Мне нужно преобразовать запрос whois, который возвращает простую строку, в объект PHP, ассоциативный массив PHP или объект json PHP.
Текст, который я получаю с сервера 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>";
Других решений пока нет …