dongshubang7816 2017-11-10 09:49
浏览 33
已采纳

除了日期之外,从字符串中删除所有文本

I'm currently outputting some Whois information on a PHP template (using this) which returns a large block of text via this variable $whois_answer:

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

I don't want to amend the original code, just amend the final output (as I may use other functionality at a later date).

I purely want to grab the expiry date of the domain, how can I target that and strip everything else out? Be aware that the domain is dynamic so the date could be anything but will always be in that format.

  • 写回答

1条回答 默认 最新

  • douren0558 2017-11-10 09:58
    关注

    Use preg_match:

    $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

    This will match "Expiry date " and then capture: a-Z and 0-9 and - meaning it will stop the capture at space.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?