2016-11-12 11 views
0

HTTP応答から単一の値を取得するにはどうすればよいですか?実際にはJSONレスポンスですが、テキストのチャンクはJSONでないかのようになります。私は次の応答を取得whoisのAPI照会するとき例えばプレーンテキストの応答から単一のデータを取得する方法は?

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" 
} 

を私はExpiration DatewhoisResponse外の変数に割り当てる取得したいと思い、可能ということでしょうか? PHPでこれをどうすればできますか?

答えて

1

は、文字列に一致するようにpreg_matchを使用することができ、この

$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>'; 

を試してみてください。

+0

こんにちは、固定長のない「ネームサーバー」の値が必要な場合、どうすれば入手できますか?出来ますか? – pleasega

+1

$ data = preg_match_all( '/ Nameサーバー:(。*)\ n /'、$ str、$ match); @pleasega –

関連する問題