Re: last bit of help ....

From: Date: Thu, 30 Aug 2001 09:15:23 +0000
Subject: Re: last bit of help ....
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65219@lists.php.net to get a copy of this message
> I need to output an array to a text file, now I have created the text file now I just need to > write to it, well I need to get the output of the browser to this text file. HOw can i do this, > oh and return each line ... $file = fopen($new_file_name, 'w') or die("Could not open $new_file_name"); # loop through lines/rows/whatever # For each field, do: $field = str_replace('"', '\\"', $field); $field = '"$field"'; fputs($file, "$field,$field2,$field3"); # end loop. http://php.net/fopen http://php.net/fputs Oh yeah: You probably don't need the touch stuff... If you can do all that, you probably have permission to just create the file using fopen. > heres the code > > that gets the output > array1.php > > <? > // Mail text file extractor. > // Written to extract out certain parts of the file and output in a csv friendly format. > // Dan McCullough > > > include("functions.php"); > > if ($submit) { > $extract = eXtractor1($file_name,$tmp_file_name,$new_file_name); > > > if ($extract) { > > file://here goes, get the parsed file from the output of the grep command. > file://read the file and output > $fcontents = file("/tmp/$tmp_file_name", "r"); > > // run this funtion to format and display the file in a certain output. > function GetField($offset) > { > global $fcontents; > global $new_file_name; > return trim(substr($fcontents[$offset], strpos($fcontents[$offset], > " "))); > } > > for($i = 0, $count = sizeof($fcontents); $i < $count; $i += 6) > { > // Make the numbers 1-6 constants if desired > > echo GetField($i + 1) . "," . > GetField($i + 2) . "," . > GetField($i + 3) . "," . > GetField($i) . "," . > GetField($i + 5) . "," . > GetField($i + 4) . ",yes<br>\n"; > } > exit;} > } > ?> > > <html> > <head> > <title>Extractor</title> > </head> > <body> > <form method="post" action="<? echo $PHP_SELF; ?>"> > Please input the name of the text file.<br><br> > File to extract: <input type="text" name="file_name"><br> > Temp file name: <input type="text" name="tmp_file_name"><br> > CSV File Name: <input type="text" name="new_file_name"><br> > <input type="submit" name="submit" value="submit"> > </form> > </body> > </html> > > function.php > function eXtractor1($file_name,$tmp_file_name,$new_file_name) > { > global $file_name; > global $tmp_file_name; > global $new_file_name; > > $filename = "/tmp/$tmp_file_name"; > $newfilename = "/tmp/$new_file_name"; > > if (!file_exists($filename)) > touch($filename); // Create blank file > touch($newfilename); > chmod($filename,0777); > chmod($newfilename,0777); > > $command = "cat /home/sites/projects/web/extractor/$file_name | egrep > 'State:|Name:|Address:|City:|e-mail:|Zip:'>$filename"; > system($command); > ## nothing worked for me until I added this next line. > system("exit(0)"); > } > return $tmp_file_name; > return $new_file_name; > } > > ?> > > anythoughts would be appreaciated > > dan > > ===== > Dan McCullough > ------------------------------------------------------------------- > "Theres no such thing as a problem unless the servers are on fire!" > h: 603.444.9808 > w: McCullough Family > w: At Work > > __________________________________________________ > Do You Yahoo!? > Make international calls for as low as $.04/minute with Yahoo! Messenger > http://phonecard.yahoo.com/ -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#65219) next »