首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除除日期以外的字符串中的所有文本

删除除日期以外的字符串中的所有文本
EN

Stack Overflow用户
提问于 2017-11-10 09:49:40
回答 1查看 67关注 0票数 0

我目前正在一个PHP模板(使用)上输出一些身份信息,该模板通过这个变量$whois_answer返回大量文本

相关日期:登记日期:19-8月-2015年到期日期:19-8月-2025年最后更新日期:21-9月-2015年登记状态:登记截止日期。名称服务器: xxx.mainnameserver.com xxx.mainnameserver.com WHOIS查找在09:34:40 10-2017年11月--这一WHOIS信息是免费提供的诺米内英国,中央注册中心.uk域名。这一信息和.uk WHOIS是:版权诺米内英国1996-2017年.您不得访问.uk WHOIS或使用它中的任何数据,除非在http://www.nominet.uk/whoisterms完全可用的使用条款允许的情况下,这包括以下方面的限制:(A)将数据用于广告或其重新包装、重新编译、重新分配或重用(B)遮挡、删除或隐藏本通知的任何或全部,以及(C)超过查询速率或数量限制。这些数据是在“如实”的基础上提供的,可能落后于登记册。访问可能在任何时候被撤回或限制。域注册

我不想修改原始代码,只需要修改最终输出(因为我以后可能会使用其他功能)。

我只想抓住域名的到期日期,我怎么才能瞄准它,把所有的东西都去掉呢?请注意,域是动态的,因此日期可以是任何内容,但总是以该格式。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-10 09:58:45

使用preg_match:

代码语言:javascript
复制
$str ="Relevant dates: Registered on: 19-Aug-2015 Expiry date: 19-Aug-2025 Last updated: 21-Sep-2015 Registration status: Registered until expiry date. Name servers: xxx.mainnameserver.com xxx.mainnameserver.com WHOIS lookup made at 09:34:40 10-Nov-2017 -- This WHOIS information is provided for free by Nominet UK the central registry for .uk domain names. This information and the .uk WHOIS are: Copyright Nominet UK 1996 - 2017. You may not access the .uk WHOIS or use any data from it except as permitted by the terms of use available in full at http://www.nominet.uk/whoisterms, which includes restrictions on: (A) use of the data for advertising, or its repackaging, recompilation, redistribution or reuse (B) obscuring, removing or hiding any or all of this notice and (C) exceeding query rate or volume limits. The data is provided on an 'as-is' basis and may lag behind the register. Access may be withdrawn or restricted at any time. Domain is registered";

Preg_match("/Expiry date:\s([a-zA-Z0-9-]+)/", $str, $match);

Echo $match[1];

https://3v4l.org/k7W2b

这将匹配“到期日期”,然后捕获:a-Z0-9-,这意味着它将在空间停止捕获。

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

https://stackoverflow.com/questions/47219900

复制
相关文章

相似问题

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