Jump to content

Split File into seperate files


oracle765

Recommended Posts

I have the following semi colon delimited file, in fact hundreds of them which are all the same format

 

Does PHP have the facility to open this file and split it into 3 separate excel or csv files

 

 

EG

 

For the OS

 

Machine, Manufacturer, Model, Current User, OS, Version, Install Date

DETAILS HERE

 

For the CPU

 

Model, Socket Designation,Status, 3 of Cores, 3 of Logical Processors

DETAILS HERE

 

and for the Servicea

 

Service,State,Install Date, Install Path

DETAILS HERE

Spiltintofiles.txt

Link to comment
Share on other sites

Sure it can do that - as long as you tell it how.

 

For each file,

1. Read a line. It'll look like ### LABEL ###. Create and open a handle for whatever file should hold the following contents.

2. Read a line. If the line isn't empty then write it out to whatever file you had opened. Repeat.

3. If the line is empty then close the file and, if you aren't at the end of the file yet, go to step 1.

 

- You can read a line with fgets() but remember that it includes the trailing newline and so you should probably remove it with trim() before you look at it too closely.

- fwrite() to write a line.

- Check if you're at the end of the file with feof().

Edited by requinix
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.