2017-10-09 12 views
0

これは正規表現の問題です。私は、日付とxxxxxxxx.phpを文の集合で収集したい。ここで PHPを使用して文のセットで特定の用語を取得する方法

は私のTXTです:

09-10-17 05:56:34 ChartConfig.php (25): DEPRECATED (8192) >> message = Methods with the same name as their class will not be constructors in a future version of PHP; ChartConfig has a deprecated constructor 

09-10-17 05:56:34 Point.php (26): DEPRECATED (8192) >> message = Methods with the same name as their class will not be constructors in a future version of PHP; Point has a deprecated constructor 

09-10-17 05:56:34 XYDataSet.php (26): DEPRECATED (8192) >> message = Methods with the same name as their class will not be constructors in a future version of PHP; XYDataSet has a deprecated constructor 

そして、私のようなデータを収集しようとしています:これは役立つはず

$date = ["09-10-17 05:56:34","09-10-17 05:56:34","09-10-17 05:56:34"] 
$file = ["ChartConfig.php","Point.php","XYDataSet.php"] 
+1

あなたは何を試しましたか? – ccKep

+0

あなたは試しましたか?エラーを読んでいますか? – Isaac

+1

@Isaacエラーは、彼が解析しようとしているもので、彼が得ているものではありません。 – ccKep

答えて

0

あなたが軌道に乗る:

<?php 
$lines = file_get_contents("foo.txt"); 

preg_match_all("/^(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (.+) \(/Um", $lines, $matches); 

list(,$times, $filenames) = $matches; 

var_dump($times); 
var_dump($filenames); 

出力を:

array(3) { 
    [0]=> 
    string(17) "09-10-17 05:56:34" 
    [1]=> 
    string(17) "09-10-17 05:56:34" 
    [2]=> 
    string(17) "09-10-17 05:56:34" 
} 
array(3) { 
    [0]=> 
    string(15) "ChartConfig.php" 
    [1]=> 
    string(9) "Point.php" 
    [2]=> 
    string(13) "XYDataSet.php" 
} 

処理を実行する前に戻り値preg_match_all(パターンが一致した回数)をチェックする必要があることに注意してください。これは読者の練習問題として残しておきます。

関連する問題