我想通过php preg_march从电子邮件中获取文本,我的文字如下:
Details: Cras ultrices quam id nisl
Additional Informations
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nunc eu enim non ipsum feugiat aliquam. Cras eget orci tellus, ac feugiat ligula.
Proin tristique lobortis lacinia. Morbi facilisis
Next line with value: Lorem ipsum dolor sit
我希望在“空白行”之前得到“附加信息”以下的内容。
答案 0 :(得分:0)
'~Additional Informations\\r?\\n(.+?)\\r?\\n\\r?\\n~si'
试试这个。
确实有效:
$string = <<<SZ
Details: Cras ultrices quam id nisl
Additional Informations
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nunc eu enim non ipsum feugiat aliquam. Cras eget orci tellus, ac feugiat ligula.
Proin tristique lobortis lacinia. Morbi facilisis
Next line with value: Lorem ipsum dolor sit
SZ;
preg_match('~Additional Informations\\r?\\n(.+?)\\r?\\n\\r?\\n~si', $string, $matches);
var_dump($matches[1]);