Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split text file into equal blocks. How???

Status
Not open for further replies.

josel

Programmer
Oct 16, 2001
716
US
I would like to limit size of content per page. So, given document (A), how can I load this document a block at a time? Better yet, how can I split the document into variables each holding X-bites?

Thank you all in advance!

Regards,


Jose Lerebours



KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
Have you tried file()

php.net said:
array file ( string $filename [, int $flags [, resource $context]] )

Reads an entire file into an array.
Returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Upon failure, file() returns FALSE.
or maybe

fread()

php.net said:
Description
string fread ( resource $handle, int $length )

fread() reads up to length bytes from the file pointer referenced by handle. Reading stops when up to length bytes have been read, EOF (end of file) is reached, (for network streams) when a packet becomes available, or (after opening userspace stream) when 8192 bytes have been read whichever comes first.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
OK - This is a start. I guess the question now is how do I now how many elements are there in an array ???

Once I have a file read onto an array, array can then be referenced 0-X; X being the unknown ...

This is very good information vacunita (Do you know that vacunita in Spanish means "little vaccination"? - lol You could just be the vaccination I need to improve my PHP)

Regards,


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
vacunita,

I found that the function sizeof() is the answer to my follow-up question.

Armed with this information, I can now write UDF that will accept three parameters ArrayName, StartRow, NumberOfRows

Using a for/next (or while) loop, I can set my pointer to StartRow and take it from there.

Once the loop is complete, I will then return the built string and ... I shall be victorious!

What do you think?

Thanks,

Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
You could also have used the count() function on the array, and gotten the number of entries in the array, then you would know how many lines there are, and decide how many to show.

By the way, the php.net online manual is your friend in these situations.


---
And yeah I know what my screen name means. LOL I picked out a long time ago off of an old inoculation floppy disc from Norton.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top