我总是用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