Distributing Contents in subfiles using Delimiter

Hi,
Sometime back I was having a conversation where in a file of 100kb is distributed into several subfiles, each subfile having 40kb data.

However this seems not a very clean solution as assumes 1 char as one byte.

Another way is to have delimiter in the main file and write the subfile1 till the first delimiter is reached and then write to the next subfile till the next delimiter is reached.

How can this be written?

What delimiter you have have in the content? I think exploding the content with delimiter will work for you. Check the explode function.

I am using ^ character as a delimiter, but basically want to write the contents in different files until next delimiter is reached

Will you show us the sample content?

For example the Mainfile contents are say readmain.txt

Time to complete it is the night before. That way you’ll wake up motivated and you won’t be floundering around for half a day just defining what you want to accomplish. ^ Circumstances may cause interruptions and delays, but never lose sight of your goal. ^ Start from where you are with what you have; make something of it - never be satisfied.^Behold the turtle. He makes progress only when he sticks his neck out. ^ It’s better to move forward with your head held high, because the post is not going to move out of your way!^

Now
The subfile readmain.1.txt should have

Time to complete it is the night before. That way you’ll wake up motivated and you won’t be floundering around for half a day just defining what you want to accomplish.

The readmain.2.txt should have
Circumstances may cause interruptions and delays, but never lose sight of your goal.

The readmain.3.txt should have
Start from where you are with what you have; make something of it - never be satisfied.

The readmain.4.txt should have
Behold the turtle. He makes progress only when he sticks his neck out.

The readmain.5.txt should have
It’s better to move forward with your head held high, because the post is not going to move out of your way!

This way the content of readmain.txt is distributed looking at the delimiter


$content = "Time to complete it is the night before. That way you'll wake up motivated and you won't be floundering around for half a day just defining what you want to accomplish. ^ Circumstances may cause interruptions and delays, but never lose sight of your goal. ^ Start from where you are with what you have; make something of it - never be satisfied.^Behold the turtle. He makes progress only when he sticks his neck out. ^ It's better to move forward with your head held high, because the post is not going to move out of your way!^";
$pages = explode("^", $content);
print_r($pages);

Hope now you can loop and write the contents to different files.

Hi,
Yes something what I was looking for and now can read the number of pages using count($pages) . Thanks