PHP Snippets: get contents from file(s), URL


  • Quickest way
$contents = file_get_contents("contents.txt");

$contents = file_get_contents("http://example.com/");
  • Looping more files
foreach (glob("filename/*.ext") as $file) {
    
	$file_handle = fopen($file, "r");
    
	$line = fread($file_handle, 1024*$kbsize);

	echo $line;
    
    fclose($file_handle);
}