views:

28

answers:

2

I have a large file that I would like to read via php, and then insert various fields into MySQL.

Each file in the feed is in plain text format, separated into columns and rows. Each record has the same set of fields. The following are the delimiters for each field and record:

Field Separator (FS): SOH (ASCII character 1) Record Separator (RS) : STX (ASCII character 2) + "\n"

If I look at the first few lines of the file they look like this:

#export_dateapplication_idlanguage_codetitledescriptionrelease_notescompany_urlsupport_urlscreenshot_url_1screenshot_url_2screenshot_url_3screenshot_url_4screenshot_width_height_1screenshot_width_height_2screenshot_width_height_3screenshot_width_height_4
#primaryKey:application_idlanguage_code
#dbTypes:BIGINTINTEGERVARCHAR(20)VARCHAR(1000)LONGTEXTLONGTEXTVARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(20)VARCHAR(20)VARCHAR(20)VARCHAR(20)
#exportMode:FULL

I am struggling to no where to start in order to read this file into PHP, can anyone help with the basic PHP to read each record, and assign a variable to each field, which I then will be able to write into MySQL. I can handle the writing into SQL once I have the various fields set up.

Thanks in advance,

Greg

A: 

files greator than 2gb cant be read in PHP (32 bit limit).

For lower size use simple fopen function

And inserting mysql is all the work of macthing patterns and inserts.

If structure of table is same every row then better make it manual once and then just execute inserts by extracting values either by regex or other functions like explode and split .

Arsheep
thanks, fopen will read the file but how do I pick each field up and pass that into a variable?
kitenski
the posted lines of the file is not sufficient to answer or code that thing . paste some more lines , Current set of lines just shows a structure not actual values
Arsheep
A: 

If every line has delimiters between each field, you may look at fgetcsv().

When you use fgetcsv() on a line, it will return an array with the contents from that line. Since you have several lines, put the funciton inside a while()-loop (look at example #1)

qualbeen