this little script parses your order into a multidimensional array (see output below).
from this array you can produce any other format, like inserting it into a database, write it into other files or whatever.
parser
$orders = explode("BREAK", $fileContents);
array_shift($orders); // only required if a "BREAK" is before the first order
$ordersData = array();
foreach($orders as $order) {
if (preg_match("/Order: ([^\r\n]+)[\r\n]+NAME: ([^\r\n]+)[\r\n]+Phone: ([^\r\n]+)[\r\n]+(.+)/si", $order, $regs)) {
$items = preg_split("/[\r\n]+/", $regs[4], null, PREG_SPLIT_NO_EMPTY);
foreach ($items as &$item) {
if (preg_match("/(\d+) *?x *?(.+)/", $item, $regs2)) {
$item = array(
'count' => $regs2[1],
'item' => $regs2[2]
);
} else {
$item = array(
'count' => 1,
'item' => $item
);
}
}
$orderData = array(
'order_no' => $regs[1],
'name' => $regs[2],
'phone' => $regs[3],
'items' => $items
);
$ordersData[] = $orderData;
}
}
output format
$ordersData = Array
(
[0] => Array
(
[order_no] => 10000
[name] => XYZ
[phone] => XXX-XXX-XXX
[items] => Array
(
[0] => Array
(
[count] => 6
[item] => ABC
)
[1] => Array
(
[count] => 6
[item] => Main ST
)
[2] => Array
(
[count] => 6
[item] => CITY
)
[3] => Array
(
[count] => 6
[item] => STATE
)
[4] => Array
(
[count] => 6
[item] => COUNTRY
)
)
)
[1] => Array
(
[order_no] => 10001
[name] => XYZ1
[phone] => XXX-XXX-XXX
[items] => Array
(
[0] => Array
(
[count] => 1
[item] => BMC
)
[1] => Array
(
[count] => 1
[item] => MJ ST
)
[2] => Array
(
[count] => 1
[item] => CITY
)
[3] => Array
(
[count] => 1
[item] => STATE
)
[4] => Array
(
[count] => 1
[item] => COUNTRY
)
)
)
[2] => Array
(
[order_no] => 10002
[name] => XYZ2
[phone] => XXX-XXX-XXX
[items] => Array
(
[0] => Array
(
[count] => 1
[item] => BMC
)
[1] => Array
(
[count] => 1
[item] => MJ ST
)
[2] => Array
(
[count] => 1
[item] => CITY
)
[3] => Array
(
[count] => 1
[item] => STATE
)
[4] => Array
(
[count] => 1
[item] => COUNTRY
)
)
)
)