Jump to content

Reading a file into a varriable?


chadrt

Recommended Posts

I have a script that generates a file that has a 0 if it succeded or another number if it did not succede.  It is always a single digit in the file and I would like to know how I can open that file and read it from a PHP script and assign it to a varriable.  This way I can do something like this to rerun it at a later a point:

 

if ($attempt == 0){
exit;
}else{
# I will rerun the script that failed
include('update.php');
}

Link to comment
https://forums.phpfreaks.com/topic/71625-reading-a-file-into-a-varriable/
Share on other sites

so, are you asking if there is a limit to the amount of data that can be stored in a variable? Or do you want to know how to read the file? I think that there may be a problem if the datatype isn't all the same inside the file, but if it is then you should be able to do it easily.

 

 

Read it in and put it in a variable like this:

     $filename = "fread_text.txt";
     $handle = fopen($filename, "r");
     $contents = fread($handle, filesize($filename));
     fclose($handle);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.