Joh*_*mBF 0 php regex whois trim preg-replace
使用PHP我希望descr:从RIPE IP地址范围的whois记录开始获取该行的内容,因此它们应该看起来像这样:
% This is RIPE NCC's Routing Information Service
% whois gateway to collected BGP Routing Tables
% IPv4 or IPv6 address to origin prefix match
%
% For more information visit http://www.ripe.net/ris/riswhois.html
route: 53.0.0.0/8
origin: AS31399
descr: DAIMLER-AS Daimler Autonomous System
lastupd-frst: 2011-12-08 23:18Z 195.66.224.97@rrc01
lastupd-last: 2012-01-25 15:18Z 203.119.76.3@rrc00
seen-at: rrc00,rrc01,rrc03,rrc04,rrc05,rrc07,rrc10,rrc11,rrc12,rrc13,rrc14,rrc15,rrc16
num-rispeers: 98
source: RISWHOIS
Run Code Online (Sandbox Code Playgroud)
所以我应该得到DAIMLER-AS Daimler Autonomous System结果.
如何使用最少的代码执行此操作,我在$ whois中有记录.
<?php
$whois = shell_exec('whois -h riswhois.ripe.net ' . $ip);
?>
Run Code Online (Sandbox Code Playgroud)
你可以使用preg_match()以下方法完成
$whois = shell_exec('whois -h riswhois.ripe.net ' . $ip);
$result = preg_match('/^descr:\s*(.+)$/m', $matches);
$descr = $matches[1];
Run Code Online (Sandbox Code Playgroud)
注意mutliline(m)修饰符的使用.