pleasega pleasega - 11 days ago 5
HTML Question

How to get single data from a plain text response?

How can I get a single value from a HTTP response? It is actually a JSON response but the chunk of text is just as if it is not JSON.

For example when I query a whois API I get the following response:

HTTP/1.1 200
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Date: Sat, 12 Nov 2016 09:10:56 GMT
Server: Mashape/5.0.6
Transfer-Encoding: chunked
X-Ratelimit-Requests-Limit: 11000
X-Ratelimit-Requests-Remaining: 10991

{
"available": false,
"whoisResponse": "\nWhois Server Version 2.0\n\nDomain names in the .com and .net domains can now be registered\nwith many different competing registrars. Go to http://www.internic.net\nfor detailed information.\n\n Domain Name: TEST.COM\n Registrar: ENOM, INC.\n Sponsoring Registrar IANA ID: 48\n Whois Server: whois.enom.com\n Referral URL: http://www.enom.com\n Name Server: JAY.NS.CLOUDFLARE.COM\n Name Server: RITA.NS.CLOUDFLARE.COM\n Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited\n Updated Date: 02-feb-2016\n Creation Date: 13-sep-2014\n Expiration Date: 13-sep-2017\n\n>>> Last update of whois database: Sat, 12 Nov 2016 09:10:45 GMT <<<\n\nFor more information on Whois status codes, please visit https://icann.org/epp\n\nNOTICE: The expiration date displayed in this record is the date the\nregistrar's sponsorship of the domain name registration in the registry is\ncurrently set to expire. This date does not necessarily reflect the expiration\ndate of the domain name registrant's agreement with the sponsoring\nregistrar. Users may consult the sponsoring registrar's Whois database to\nview the registrar's reported date of expiration for this registration.\n\nTERMS OF USE: You are not authorized to access or query our Whois\ndatabase through the use of electronic processes that are high-volume and\nautomated except as reasonably necessary to register domain names or\nmodify existing registrations; the Data in VeriSign Global Registry\nServices' (\"VeriSign\") Whois database is provided by VeriSign for\ninformation purposes only, and to assist persons in obtaining information\nabout or related to a domain name registration record. VeriSign does not\nguarantee its accuracy. By submitting a Whois query, you agree to abide\nby the following terms of use: You agree that you may use this Data only\nfor lawful purposes and that under no circumstances will you use this Data\nto: (1) allow, enable, or otherwise support the transmission of mass\nunsolicited, commercial advertising or solicitations via e-mail, telephone,\nor facsimile; or (2) enable high volume, automated, electronic processes\nthat apply to VeriSign (or its computer systems). The compilation,\nrepackaging, dissemination or other use of this Data is expressly\nprohibited without the prior written consent of VeriSign. You agree not to\nuse electronic processes that are automated and high-volume to access or\nquery the Whois database except as reasonably necessary to register\ndomain names or modify existing registrations. VeriSign reserves the right\nto restrict your access to the Whois database in its sole discretion to ensure\noperational stability. VeriSign may restrict or terminate your access to the\nWhois database for failure to abide by these terms of use. VeriSign\nreserves the right to modify these terms at any time.\n\nThe Registry database contains ONLY .COM, .NET, .EDU domains and\nRegistrars.\n"
}


I would like to get the
Expiration Date
to assign to a variable out of the
whoisResponse
, is that possible? How can I do this in PHP?

Answer

try this

$str = "\nWhois Server Version 2.0\n\nDomain names in the .com and .net domains can now be registered\nwith many different competing registrars. Go to http://www.internic.net\nfor detailed information.\n\n   Domain Name: TEST.COM\n   Registrar: ENOM, INC.\n   Sponsoring Registrar IANA ID: 48\n   Whois Server: whois.enom.com\n   Referral URL: http://www.enom.com\n   Name Server: JAY.NS.CLOUDFLARE.COM\n   Name Server: RITA.NS.CLOUDFLARE.COM\n   Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited\n   Updated Date: 02-feb-2016\n   Creation Date: 13-sep-2014\n   Expiration Date: 13-sep-2017\n\n>>> Last update of whois database: Sat, 12 Nov 2016 09:10:45 GMT <<<\n\nFor more information on Whois status codes, please visit https://icann.org/epp\n\nNOTICE: The expiration date displayed in this record is the date the\nregistrar's sponsorship of the domain name registration in the registry is\ncurrently set to expire. This date does not necessarily reflect the expiration\ndate of the domain name registrant's agreement with the sponsoring\nregistrar.  Users may consult the sponsoring registrar's Whois database to\nview the registrar's reported date of expiration for this registration.\n\nTERMS OF USE: You are not authorized to access or query our Whois\ndatabase through the use of electronic processes that are high-volume and\nautomated except as reasonably necessary to register domain names or\nmodify existing registrations; the Data in VeriSign Global Registry\nServices' (\"VeriSign\") Whois database is provided by VeriSign for\ninformation purposes only, and to assist persons in obtaining information\nabout or related to a domain name registration record. VeriSign does not\nguarantee its accuracy. By submitting a Whois query, you agree to abide\nby the following terms of use: You agree that you may use this Data only\nfor lawful purposes and that under no circumstances will you use this Data\nto: (1) allow, enable, or otherwise support the transmission of mass\nunsolicited, commercial advertising or solicitations via e-mail, telephone,\nor facsimile; or (2) enable high volume, automated, electronic processes\nthat apply to VeriSign (or its computer systems). The compilation,\nrepackaging, dissemination or other use of this Data is expressly\nprohibited without the prior written consent of VeriSign. You agree not to\nuse electronic processes that are automated and high-volume to access or\nquery the Whois database except as reasonably necessary to register\ndomain names or modify existing registrations. VeriSign reserves the right\nto restrict your access to the Whois database in its sole discretion to ensure\noperational stability.  VeriSign may restrict or terminate your access to the\nWhois database for failure to abide by these terms of use. VeriSign\nreserves the right to modify these terms at any time.\n\nThe Registry database contains ONLY .COM, .NET, .EDU domains and\nRegistrars.\n";

$data = preg_match('/Expiration Date: ([0-9]{2})-([a-z]{3})-([0-9]{4})/',$str,$match);

echo '<pre>';
print_r($match);
echo '</pre>';

you can use preg_match to match a string.

Comments