簡體   English   中英

我如何讀取文件並僅獲取10位數字

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

我在nodepage中有一個文件,其中有數據記錄。 我只想提取10 digit數字字段並將它們放入數組中。

我該如何實現? 我是PHP新手。

這是文件中的數據格式:

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將搜索$ string的所有行,並查找10位數長的數字\\d {10} ,並確保在數字[\\s|$]后沒有空格或字符串結尾,以確保它不是11位數字數。

上面代碼的輸出:

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