DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Read A File Or An URL To A String In PHP

09.09.2005
| 811 views |
  • submit to reddit
        
Simply do this:

$string = implode('',file($pathToFileOrUrl));
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:14pm

Thanks a lot.

Snippets Manager replied on Mon, 2012/05/07 - 2:14pm

If you have PHP 4.3 or later the built-in file_get_contents() function is much faster since it doesn't need to split the file into a temporary array and then convert that back to a string: http://us2.php.net/manual/en/function.file-get-contents.php