Jump to content


Photo

breaking up form results and writing to file


  • Please log in to reply
2 replies to this topic

#1 JimiLives

JimiLives
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 19 September 2006 - 05:57 PM

Hi all, here is the problem: I have a form that has a multiline text box i have labelled as "terms", the users can paste up to 2000 lines in the terms box and i want to save each group of 100 lines into a seperate text file. So how do i loop this and have it cut and go to next file after 100 lines have been written?

Any help would be greatly appreciated, here is the code I have now that is grabbing the terms they enter and saving it to a single file, it works great but only saves all of the terms to one file:

<?php 
//write keywords to a file
$data = $_POST["terms"]; 
$file = "terms.txt";
$file_handle = fopen($file,"a");   
fwrite($file_handle, $data);
fclose($file_handle); 
?>

#2 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 19 September 2006 - 06:41 PM

I dont know exactly how you would go about it as I have very limited knowledge on REGEXP, but you could loop over the text file looking for ( /r/n ) which is the REGEXP for carriage return/line feed, count them and split the file up at that point when you reach 1 hundred of them....
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 19 September 2006 - 06:45 PM

Instead of using regular expressions, you can just use explode()

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users