2010-10-10 118 views
4

我有一個包含文本段落的文本文件。我想在php中將它作爲字符串加載,然後將其作爲數組收集到其中的所有電子郵件地址。但是,我如何最初加載文本文件內容作爲字符串?重申,我有在php中,如何將txt文件作爲字符串加載?

$string = **WITHIN TEXT FILE "[email protected] MIME-Version: bla bla bla [email protected]"; 
$matches = array(); 
$pattern = '/[A-Za-z0-9_-][email protected][A-Za-z0-9_-]+\.([A-Za-z0-9_-][A-Za-z0-9_]+)/' 
preg_match($pattern, $string, $matches); 

如何從文本文件中的文本加載到字符串變量?

在此先感謝!

回答

1
$lines = file('file.txt'); 

foreach ($lines as $line) { 
    // ... 
}
0

參考的最簡單方法是file-get-contents

$file_content = file_get_contents('/path/to/file'); 
相關問題