首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从纯文本响应中获取单个数据?

如何从纯文本响应中获取单个数据?
EN

Stack Overflow用户
提问于 2016-11-12 09:22:30
回答 1查看 129关注 0票数 0

如何从HTTP响应中获得单个值?它实际上是一个JSON响应,但是文本块就好像它不是JSON。

例如,当我查询whois API时,会得到以下响应:

代码语言:javascript
复制
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中做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-12 09:37:26

尝尝这个

代码语言:javascript
复制
$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>';

您可以使用匹配来匹配字符串。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40561402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档