duancao1951 2014-07-08 17:31
浏览 24
已采纳

如何使用php [duplicate]提取所有IP地址

This question already has an answer here:

how to extract all ip address from a given string, please.

eg:

"
2014-07-08 19:05:20 1X4YpU-0001kr-6y <= info@arianet-dsl.com H=(server.takcloud.com) [185.4.28.203] P=esmtps X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256 S=1018 id=57844562-138B-4934-9CF7-554F8C613C1C@arianet-dsl.com
"
</div>
  • 写回答

1条回答 默认 最新

  • duanbinren8906 2014-07-08 17:39
    关注

    I would use RegEx

    Search for groups of up to three "{1,3}" digits "\d" separated by a "."

    \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
    

    To use it in PHP

    $mailStr = "2014-07-08 19:05:20 1X4YpU-0001kr-6y <= info@arianet-dsl.com H=(server.takcloud.com) [185.4.28.203] P=esmtps X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256 S=1018 id=57844562-138B-4934-9CF7-554F8C613C1C@arianet-dsl.com";
    $regexpattern = "/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/";
    preg_match_all($regexpattern , $mailStr, $matches);
    print_r($matches);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作