简体   繁体   English

我如何读取文件并仅获取10位数字

[英]How can i read file and get 10 digit number only

I have a file in nodepage where data record are available. 我在nodepage中有一个文件,其中有数据记录。 I want to extract only the 10 digit numeric fields and put them into an array. 我只想提取10 digit数字字段并将它们放入数组中。

How can I achieve this? 我该如何实现? I am new to PHP. 我是PHP新手。

Here is the data format in file: 这是文件中的数据格式:

STD OBD500-450-0514SIPPOOLPLAN
15/05/16
Page 878
Product Type: SIP Trunk Channel Line Int
Bill Number
PO Number 0
Bill Date
18:38:41 7045693328 Vodafone-MUM 00:01:00  4 0.60 18:51:59 9819286096 Vodafone-MUM 00:00:22 2 0.30
18:41:56 9833329668 Vodafone-MUM 00:03:51 16 2.40 18:52:08 9822965734 Idea-MH      00:01:07 5 0.75
18:42:23 9075613876 Idea-MH      00:01:22  6 0.90 18:53:59 9822965734 Idea-MH      00:00:53 4 0.60
18:44:07 9403358204 BSNL-MH      00:00:43  3 0.45 18:54:30 8691955808 Idea-MUM     00:01:09 5 0.75
 preg_match_all("/(\d{10})[\s|$]/", $string, $output);

 var_dump($output);

Preg_match_all will search all lines of $string and look for numbers \\d that is 10 digits long {10} and make sure there is a space or end of string after the digits [\\s|$] to make sure it's not a 11 digit number. Preg_match_all将搜索$ string的所有行,并查找10位数长的数字\\d {10} ,并确保在数字[\\s|$]后没有空格或字符串结尾,以确保它不是11位数字数。

output of above code: 上面代码的输出:

array(2
    0=>array(8
            0 => 7045693328 
            1 => 9819286096 
            2 => 9833329668 
            3 => 9822965734 
            4 => 9075613876 
            5 => 9822965734 
            6 => 9403358204 
            7 => 8691955808 
    )
    1=>array(8
            0 => 7045693328
            1 => 9819286096
            2 => 9833329668
            3 => 9822965734
            4 => 9075613876
            5 => 9822965734
            6 => 9403358204
            7 => 8691955808
    )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM