PHP - 在字符串中查找数字 [英] PHP - Find number in a string

查看:91
本文介绍了PHP - 在字符串中查找数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从这个字符串中得到 16 :

I want to get 16 from this string :

request id is 16 (group id 1) for host localhost

以及JID号10的Status消息(在本例中为Kill time expired)

And the Status message of JID No. 10 (which is in this case Kill time expired)

JID  Pri S  Owner Number       Pages Dials      Status
11   127 D   root 0xxxxxx     1:1   1:12         
16   116 F www-da 0xxxxxx     0:1  12:12         No carrier detected; too 
15   127 D   root 0xxxxxx     1:1   1:12         
10   127 F   root 0xxxxxx     0:0   0:12         Kill time expired
9    127 F   root 0xxxxxx     0:0   0:12         Job aborted by request
8    127 F   root 0xxxxxx     0:0   0:12         Job aborted by request

EDIT :我设法解决了第一个问题.答案是(\d+).我需要第二次搜索的提示.

EDIT : I managed to solve the first problem. the answer is (\d+). I need a hint for the second search.

推荐答案

对于第二个方案,您可以查找以10"开头的行,然后是something",然后是 9 个连续的空格.在空格之后是您需要捕获的内容.正则表达式是 ^10.+\s{9}(.*)

For the second one, you could look for a line that starts with "10", then "something" and then 9 consecutive spaces. After the spaces is what you need to capture. The regex is ^10.+\s{9}(.*)

这篇关于PHP - 在字符串中查找数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆