我有形式有錯誤的文件:PHP正則表達式和preg_match_all()問題
================================================
Header of file with date and time
================================================
Loaded options from XML file: 'path/to/file/some_file.xml
extendedPrintPDF started
extendedPrintPDF: Error: Unsaved documents have no full name.; line: 332
================================================
Header of file with date and time
================================================
Error opening document: path/to/file/some_file1: Error: Either the file does not exist, you do not have permission, or the file may be in use by another application; line: 190
Error opening document: path/to/file/some_file2: Error: Either the file does not exist, you do not have permission, or the file may be in use by another application; line: 190
我使用
preg_match_all('/Error: (.*)/m', $file_data, $erroenames,PREG_PATTERN_ORDER);
獲得陣列中的所有錯誤。 它似乎在第一組中的錯誤正常工作。但是,以'Error Opening document'開頭的第二組錯誤似乎顯示爲數組的單個元素,因此,我只有4個元素而不是9個數。但是,當我在http://www.spaweditor.com/scripts/regex/index.php上嘗試相同的操作時,所有的錯誤顯示爲數組的不同元素,我得到9個元素。 有人能告訴我我做錯了什麼嗎? 我試過使用|併爲「錯誤打開文檔」創建一個RegEx。但是,即使這似乎不起作用。
如何檢索'$ file_data'?我嘗試了成功的正則表達式...... –
也許「錯誤打開文檔」條目不能用換行符分隔(例如
)。 – periklis
@ Tiger-222:我正在使用file_get_contents。這是 的延續http://stackoverflow.com/questions/13995685/reading-errors-and-file-names-from-a-log-txt-file –