I've spent the better part of 2 days searching on all the ways to split strings in PHP, but none of them got me anywhere. I need to be able to split the following string format into arrays, and then split each of those arrays into sub-arrays.
The data is a journal of register sales. Each transaction is in the same format and the only difference in string length per transaction is the amount of items purchased. Here is an example: (This receipt is one single hex stream, all empty spaces are a space character (\x20) and all '.' are (\x00). Again, these are all 1 single line just edited to make it easier to look at)
DATE 07/13/2014 MON...
PLU#491320 ..
SPRITE T1 $0.75...
CUSTOMER DATE OF BIRTH 02/05/1978...
PLU#820050 ..
SMIRNOFF VODKA LT T2 $13.99...
TAX1 AMT $0.06...
TAX2 AMT $1.42...
.T.O.T.A.L .$.16..2.2...
.C.H.A.R.G.E .$.16..2.2...
NO.000002 REG01 EMPLOYEE 2 TIME 18:09..€
Basically I'm looking for:
Array {
[0] = Date: 07/13/2014
[1] = PLU#/Tax/Price: 491320 & T1 & 0.75, 820050 & T2 & 13.99 (no spaces)
[2] = Tax: T1 & 0.06, T2 & 1.42 (no spaces)
[3] = Transaction No.: 000001
[4] = Register: 01
[5] = Employee: Employee 2
[6] = Time: 17:59
}
I've tried preg_replace
, preg_split
, substr
and str_split
, using strpos
and searching for the string position for each section. Nothing worked. I can clear the spaces, but it screws up with stuff like Employee name
, which may have an actual space in it.
Are there any other ways of splitting strings besides what I just listed? I've tried dozens of substr and preg functions and none of them helped me. I've spent enough time with trial and error from google searches, I may as well ask if someone knows something I haven't come across.