我總是用preg_match
,它總是能正常工作, 但今天我試圖讓兩個HTML標籤<code: 1>DATA</code>
的preg_match返回空數組
之間的內容和我有一個問題,我的代碼解釋:
function findThis($data){
preg_match_all("/\<code: (.*?)\>(.*?)\<\/code\>/i",$data,$conditions);
return $conditions;
}
// plain text
// working fine
$data1='Some text...Some.. Te<code: 1>This is a php code</code>';
//A text with a new lines
// Not working..
$data2='some text..
some.. te
<code: 1>
This is a php code
..
</code>
';
print_r(findThis($data1));
// OUTPUT
// [0][0] => <code: 1>This is a php code</code>
// [1][0] => 1
// [2][0] => This is a php code
print_r(findThis($data2));
//Outputs nothing!
的'*'佔位符不匹配換行,除非你指定'DOTALL修飾符'/ s'。 – mario
可能的重複[如何匹配正則表達式中多行的任何字符?](http://stackoverflow.com/questions/159118/how-do-i-match-any-character-across-multiple-lines在一個正則表達式) – mario