取子字符串问题

hblfknight 2006-09-04 05:07:45
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 192.168.14.0/24 anywhere
ACCEPT all -- 192.168.0.10 anywhere MAC 00:01:6C:F0:47:8A
ACCEPT all -- 192.168.0.246 anywhere MAC 00:0D:87:8F:FD:38
ACCEPT all -- 192.168.0.247 anywhere MAC 00:0D:87:C4:85:E8
ACCEPT all -- 192.168.0.248 anywhere MAC 00:90:27:99:26:64
ACCEPT all -- 192.168.0.249 anywhere MAC 00:02:C5:08:BA:E7
ACCEPT all -- 192.168.0.250 anywhere MAC 00:A0:D1:E0:66:A7
ACCEPT all -- 192.168.0.251 anywhere MAC 00:10:5C:AC:D6:90
ACCEPT all -- 192.168.0.253 anywhere MAC 00:D0:B7:C6:8E:F3
利用PHP怎样获得上面输出中的IP地址?谢谢
...全文
438 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hblfknight 2006-09-05
  • 打赏
  • 举报
回复
<?
$pattern="/(\d+)\.(\d+)\.(\d+)\.(\d+)/";
$string="Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 192.168.14.0/24 anywhere
ACCEPT all -- 192.168.0.10 anywhere MAC 00:01:6C:F0:47:8A
ACCEPT all -- 192.168.0.246 anywhere MAC 00:0D:87:8F:FD:38
ACCEPT all -- 192.168.0.247 anywhere MAC 00:0D:87:C4:85:E8
ACCEPT all -- 192.168.0.248 anywhere MAC 00:90:27:99:26:64
ACCEPT all -- 192.168.0.249 anywhere MAC 00:02:C5:08:BA:E7
ACCEPT all -- 192.168.0.250 anywhere MAC 00:A0:D1:E0:66:A7
ACCEPT all -- 192.168.0.251 anywhere MAC 00:10:5C:AC:D6:90
ACCEPT all -- 192.168.0.253 anywhere MAC 00:D0:B7:C6:8E:F3 ";
$i=preg_match_all($pattern, $string, $match);
for ($j=0;$j<$i;$j++)
echo $match[0][$j]."<p>";

?>
PHP_CHRIS_BT1984 2006-09-04
  • 打赏
  • 举报
回复
不好意思些错了是 preg_match_all()...
PHP_CHRIS_BT1984 2006-09-04
  • 打赏
  • 举报
回复
<?
$pattern="/(\d+)\.(\d+)\.(\d+)\.(\d+)/";
$string="Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 192.168.14.0/24 anywhere
ACCEPT all -- 192.168.0.10 anywhere MAC 00:01:6C:F0:47:8A
ACCEPT all -- 192.168.0.246 anywhere MAC 00:0D:87:8F:FD:38
ACCEPT all -- 192.168.0.247 anywhere MAC 00:0D:87:C4:85:E8
ACCEPT all -- 192.168.0.248 anywhere MAC 00:90:27:99:26:64
ACCEPT all -- 192.168.0.249 anywhere MAC 00:02:C5:08:BA:E7
ACCEPT all -- 192.168.0.250 anywhere MAC 00:A0:D1:E0:66:A7
ACCEPT all -- 192.168.0.251 anywhere MAC 00:10:5C:AC:D6:90
ACCEPT all -- 192.168.0.253 anywhere MAC 00:D0:B7:C6:8E:F3 ";
preg_match($pattern, $string, $match);
echo($match);
?>

应该可以吧?
hblfknight 2006-09-04
  • 打赏
  • 举报
回复
就是因为使用正则表达式不会写才问的,不好意思
JackGong2012 2006-09-04
  • 打赏
  • 举报
回复
正则表达式

21,889

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧