Forum Moderators: coopster
I suspect a combination of PHP string functions will be required but I am concerned about structuring them in the most efficient way because the file may contain 1000s of rows and will be processed every night.
The txt file structure:
#HEADER#
EOF : '¦'
EOR : '~'
#DEFINITION#
ADDRESS_1¦POSTCODE1¦FEATURE1¦SUMMARY¦PRICE¦PUBLISHED_FLAG¦~
#DATA#
107 West Street¦DA2 1AW¦great location¦part furnished with cooker,washing machine, fridge freezer¦550¦0¦~
#END#
Which functions will I need?
fopen to open and read the file?
substr to isolate the data section?
explode find rows and find individual fields?
Thanks in advance for any assistance.
$input = file_get_contents("NETH.txt");
$data_outer = substr($input, (stripos($input, "#DATA#")), (stripos($input, "#END#")));
$data_inner = substr($data_outer, 6, -1);
$rows = explode("~", $data_inner);
$number_rows = count($rows)-2;
for ( $i = 0; $i <= $number_rows; $i++) {
$fields = explode("¦", $rows[$i]);
//insert each array part into database here
}