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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.