In php, how to load a txt file as a string?

I have a text file containing paragraphs of text. I want to load it as a string in php and then collect all the email addresses into it as an array. However, how to initially load the contents of a text file as a string? Recounted, I have

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

How to load text from a text file into a string variable?

Thanks in advance!

+4
source share
4 answers
 $fileContent = file_get_contents($url); 

Check out the link at http://php.net/manual/en/function.file-get-contents.php

+12
source
 $lines = file('file.txt'); foreach ($lines as $line) { // ... } 
+1
source

The easiest way is file-get-contents !

 $file_content = file_get_contents('/path/to/file'); 
0
source

All Articles