communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "file handling" - download "open file"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

file handling - open file was created/last modified on Mon 15 Mar 2004 8:06 AM

opens a file and returns the content as a string

<?
  
function file_open($filename) {
      if(
$fp = @fopen($filename, "r")) {
          
$fp = @fopen($filename, "r");
          
$contents = fread($fp, filesize($filename));
          
fclose($fp);
          return
$contents;
      } else {
          return
false;
      }
  }

// use like $text = file_open('data/file.txt');

  
?>   

learn more about some of the PHP functions used in this snippet: else, fclose, file, filesize, fopen, fread, function, return

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari