Jump to content

breaking up form results and writing to file


JimiLives

Recommended Posts

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); 
?>
Link to comment
Share on other sites

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....
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.