Home » Web

How to read file to string in PHP

By: Zhiqiang Ma On: Feb 19, 2010 Views: 36 Comment: 1 Print Email
Tags: ,

Read content of a file to string (in this example, we echo it):

// Get text from file
function get_text($text_filename) {
 if ($text_filename != "") {
  $text = "";
  $text_file = fopen($text_filename, "r");
  while (!feof($text_file)) {
      $text = $text . fgets($text_file, 4096);
  }
  fclose($text_file);
  if ( $text != "" ) {
    echo $text;
  }
 }
}

Read more:

Digg del.icio.us Stumble Techorati Facebook Newsvine Reddit Twitter
Mixx LinkedIn Google Bookmark Yahoo Bookmark MySpace LiveJournal Blogger RSS feed
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

One Comment »

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.