chadrt Posted October 3, 2007 Share Posted October 3, 2007 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'); } Quote Link to comment https://forums.phpfreaks.com/topic/71625-reading-a-file-into-a-varriable/ Share on other sites More sharing options...
sKunKbad Posted October 3, 2007 Share Posted October 3, 2007 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); Quote Link to comment https://forums.phpfreaks.com/topic/71625-reading-a-file-into-a-varriable/#findComment-360611 Share on other sites More sharing options...
trq Posted October 3, 2007 Share Posted October 3, 2007 <?php $var = file_get_contents('file.txt'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71625-reading-a-file-into-a-varriable/#findComment-360675 Share on other sites More sharing options...
chadrt Posted October 3, 2007 Author Share Posted October 3, 2007 thorpe, That was so simple and all my reading thru the php manual and the different functions and I didnt see that it was that simple. Thank you so much. Chad Quote Link to comment https://forums.phpfreaks.com/topic/71625-reading-a-file-into-a-varriable/#findComment-361089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.