Is it possible to carry an array forward to make a filename

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Is it possible to carry an array forward to make a filename

Post by andylyon87 »

I have a text box named $array[chat] in it is placed a random number, I would then like this number to be carried forward to the next page where the file created or accessed is the same name as the value of $array[chat].

script designed to write and read $array[chat]

Code: Select all

function WriteToFile($firstname){
         $str= "{$arrayї'chat']}.txt";
         $Open = fopen ($str,"a");
         if($Open){
                   fwrite ($Open,"$firstname");
                   fclose($Open);
                   $Worked=True;
         } else {
           $Worked = False;
          }
          return $Worked;
          }
function readfromfile(){
         $str =  "{$arrayї'chat']}.txt"; 
         $Open = fopen ($str,"r");
         if($Open){
         print("<HR><B><font color=white><a href="#latest" style=text-decoration:none>Comments:(To see the latest comment click here)</B></A><BR>\n");
         $data = file($str);
         for($n = 0; $n<count($data); $n++)&#123;
                $getline = explode("\t",$data&#1111;$n]);
                print("<B>$getline&#1111;0]\t$getline&#1111;1]<HR>\n");&#125;
                fclose($Open);
         &#125;else&#123;
               print("<font color=white><B>Unable to present previous comments!<HR><B><font color=white><a href="#latest" style=text-decoration:none>Comments:(To see the latest comment click here)</B></A><BR>\n");
               &#125;
&#125;
teniosoft
Forum Newbie
Posts: 15
Joined: Tue Feb 03, 2004 1:01 am
Location: Portland, Or

Post by teniosoft »

This seems like a resource intensive and complicated way of doing things I think that you should use some sort of data store using a database but, alas that is just my thought.


You could always do something like this

write the file the way that you are doing it

try header("location : filename.php") this will take you to that file but, it is going to fill up your server with a lot of junk files.

I think that looking at the way that other php chat servers may be a good idea too.
Post Reply