Avatar of ROM
ROM
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

Best way to import file into PHP.. Has its own tags NOT CSV.

Hi Everyone,

I have part of a project where I need to import an RTF file that has custom tags that I need to build a set of data. This will be based within a Joomla Framework if that changes any suggestions.

So the task is:

a) Import file via PHP.
b) Need to process either line by line or post import and cut the file into database records. E.g. Line 1-4 is a piece of information. Tagged as such. And needs to split into 5 fields within a table.
c) Allow me to parametise this so I can maintain it as this format changes as variations happen from one year to the next.

I am right at the start so would like some guidance as this is NOT a CSV file.

My first challenge is getting the file imported. Hows and to where. I would like a copy of the the PIECE OF INFORMATION in its entirety as well as the broken up part into fields.

Then it is to either process as it imports or post process if I import into staging table and blob field or something. It is that working through the file and then moving the data into table records etc...

Bit of info.

File looks like this:

{Info/sec/newinfostart In the new office}
{Info/sec/keypeople Dan,Mary}
{Info/sec/focuspeople John, Leanne}
{Info/sec/tasks task1}
{Info/sec/tasks task2}
{Info/sec/tasks task3}  
{Info/sec/endinfo End of Information card}
{Info/sec/newinfostart At the swimming pool}
{Info/sec/keypeople Tim,Mary}
{Info/sec/tasks task1}
{Info/sec/endinfo End of Information card}
{Info/sec/newinfostart Evening time at the gym}
{Info/sec/keypeople Joe, Laurie}
{Info/sec/focuspeople Gerald}
{Info/sec/tasks task1}
{Info/sec/tasks task2}
{Info/sec/endinfo End of Information card}

So this would be split into using the first Info Card as an example:

ID, Location,  Main People, Secondary People, All Tasks, Original Info Card
1, In the Office, Dan - Mary, John - Leanne, Task1 - Task2 - Task3, ALL INFO WITHOUT TAGS
2. At the swimming pool, Tim - Mary, , Task1, ALL INFO WITHOUT TAGS

And so on.

There is a lot more information that I am placing here to give a very general idea of what I am trying to do. It is not csv based. It does have identifying tags for the piece of info and line start and end with curly brackets.

Unsure about start approach and do not want to get lost in a see of Google articles.. saying that .. most appear to revolve around structed delimited data on one line.

I cannot change the format and contents of the file... This is how I receive it. Bit like reading machine code for cues.

Please advise and help

Many thanks in advance

R


Web DevelopmentPHPJoomla

Avatar of undefined
Last Comment
ste5an

8/22/2022 - Mon