处理 php 中的文本

Processing text in php

我想在遇到某些字符串时以这种方式处理 php 中的文本。删除遇到该字符串的新行,包括该行之后的行。例如我有如下内容:

This is the sample content.

On 2015-02-19 00:35, notifications@test.com wrote:
> line 1
> line 2 etc

我只想要有意义的内容,在这种情况下

This is the sample content.

然后我想跳过所有内容。目前,我使用

preg_match("/\b, notifications@test.com\b/i",$task_comment_descption,$matches)

但是使用这个我得到,这是示例内容。于 2015-02-19 00:35

我会这样做:

$array = array(
'This is the sample content.',
' ',
'On 2015-02-19 00:35, notifications@test.com wrote:',
'> line 1',
'> line 2 etc',
);
$res = array();
foreach ($array as $line) {
    if (preg_match('/\bnotifications@test\.com\b/i', $line)) {
        break;
    }
    $res[] = $line;
}
print_r($res);

输出:

Array
(
    [0] => This is the sample content.
    [1] =>  
)