Jump to content

File help


Gunnar J

Recommended Posts

<?phpecho "level ";$file=fopen("sam.php","r") or exit("Unable to open file!");while (!feof($file))   {   echo fget($level);   }fclose($file);?>

]Fatal error: Call to undefined function fget() in /home/sproder/public_html/18862.php on line 9

Link to comment
Share on other sites

Theres a variable named level in sam.php and I want to display it.
Not when you use fopen() there's not. fopen() gives you access to text as text, not text as code. You could turn part of the file into code if you pulled out a statement and ran it through eval(). I do that sometimes.Maybe what you want is to use include() to make variables and code in sam.php available to your home script? http://us2.php.net/manual/en/function.include.php
Link to comment
Share on other sites

To put the thought above more simply:

<?phpinclude 'sam.php';echo $level;?>

Link to comment
Share on other sites

I am not at all clear what's in sam.php. I assumed it was a script. Is it in fact a data file? For a data file, you would use one of the many file open/read/write functions. You could keep the data arranged in a set order so that when you read, say, the fourth line, it would contain the value you want, and to change it, you would change the fourth line. If you go this route, I'd chenge the extension from .php to .txt.Or you could teach yourself SQL and keep the info in records that have names, which many people find more convenient. If the file system AND SQL and both new to you, I'd suggest SQL, since what you learn will increase your marketable skillset a lot more.

Link to comment
Share on other sites

It would be easier to keep a single data structure in the text file instead of individual variables. If you keep an array in the text file then you can use the serialize function to write the array to the file, and the unserialize function to read it back in. So you would open the file, get the text in it, use unserialize to turn the text into an array, edit the array to change the values, then use serialize to change it back into a string that you write back to the file.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...