
July 9th, 2003, 02:02 PM
|
|
Junior Member
|
|
Join Date: Jun 2003
Posts: 22
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
PHP writing to a file
I'm new to PHP but I have a class assignment right now that resembles what you need. (I'm just getting started on it), but I think what you need to do.
I think they call it "writing to a file" (text file).
with this function you can write to the file (saved on your server somewhere) then later you can open it and read it.
This may give you an idea of what the code would look like:
If this helps then, good. If not take your question over to the PHP forum. Sorry if it's a vague answer, this is only my second week with PHP and haven't finished reading the chapter on the book yet...but I know you answer is in there. Maybe someone else can elaborate?
P.S.
I'm assuming that you want to keep things simple i.e. get the info from one text file and then create a database with that info. If you want to use a "real" database like MySQL then definitively, go to the PHP forum with your question.
PHP Code:
//*************************************************
//Write out records with data if they exist.
//*************************************************
$action = $HTTP_POST_VARS['action'];
if ($action == 'update') This looks at the value of the hidden field
{ The first time the program is called it doesn't exist
@ $fp = fopen("test.txt", 'w'); //Open text file for Write
{
$item_name = 'source';
$item_value = $HTTP_POST_VARS[$item_name];
if (empty($item_value)) {
break; Exits the loop control
}
// Write out value to file
$outline = "*$item_value*\n";
fwrite($fp, $outline);
}
fclose($fp);
}
//*************************************************
//Now Read text file and Display
//*************************************************
@ $fp = fopen("test.txt", 'r'); //Open file for reading
if ($fp)
{
while (true)
{
$line = fgets($fp,200); \\Reads a line in the file
Last edited by dmonk : July 9th, 2003 at 02:05 PM.
|