2015-02-24 77 views
2

我想在php中處理一個文本,當遇到一些字符串時。包含該行後面的行將刪除遇到該字符串的新行。比如我有一個像以下內容:在php中處理文本

This is the sample content. 

On 2015-02-19 00:35, [email protected] wrote: 
> line 1 
> line 2 etc 

我只想要有意義的內容,在這種情況下

This is the sample content. 

,然後我想跳過一切。目前,我使用

preg_match("/\b, [email protected]\b/i",$task_comment_descption,$matches) 

但使用此我得到,這是示例內容。在2015年2月19日00:35

+2

什麼是 '有意義的內容' - 舉個例子輸入和清晰的輸出示例。 – naththedeveloper 2015-02-24 08:53:33

+0

這是我現在的實際輸出。 這是示例內容。在2015-02-19 00:35,[email protected]寫道: >第1行 >第2行等 – 2015-02-24 08:58:12

+0

我只想擁有「這是示例內容」。只作爲最終產出。 – 2015-02-24 09:00:37

回答

0

這是我會做這樣的方式:

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

輸出:

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