2015-03-02 29 views
1

我有以下代碼來創建一個小的doxygen像preg_match_all與Windows/macOS9行尾

public function parserAction() { 

    $code = file_get_contents('/www/htdocs/rumpho/application/controllers/parserStr.php'); 

    preg_match_all ('/(private|public)?\s*function\s*(.*?)\s*\((.*?)\)\s*{(?:\n|\t|$)*(?:\/\*\*((?:\n|.|\t)*?)\*\/)?/msi', $code, $matches); 

    var_dump($matches); 

    die; 

} 

時parserStr.php的行結束與UNIX編碼,但它不若行工作,它的工作原理結尾用Windows或MacOS9編碼。

想法?

THX

回答

2

你想要的特殊字符是\R匹配\n\r\r\n。你正則表達式然後變成:

preg_match_all ('/(private|public)?\s*function\s*(.*?)\s*\((.*?)\)\s*{(?:\R|\t|$)*(?:\/\*\*((?:\R|.|\t)*?)\*\/)?/msi', $code, $matches); 
//                 here __^^    and __^^