1. Home
  2. Computing & Technology
  3. PHP / MySQL

Read & Return Data From Files Into PHP

By Angela Bradley, About.com

3 of 5

Using file_get_contents () in PHP

File_get_contents () is similar to fread () in that it returns the entire contents of the file to a single string, however it can be done in a single line and performs better then fread ().
<?php
$file = file_get_contents ('YourFile.txt');
Echo $file;
?>
This little bit of code retrieves the data from YourFile.text and then echos it onto the page.
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Advanced PHP
  5. File Get Contents - PHP File Get Contents - Tutorial File Get Contents

©2009 About.com, a part of The New York Times Company.

All rights reserved.