php - Any Elegant Ideas on how to parse this Dataset? -


i'm using php 5.3 receive dataset web service call brings information on 1 or many transactions. each transaction's return values delimited pipe (|), , beginning/ending of transaction delimited space.

2109695|49658|25446|4|nsf|2010-11-24 13:34:00z 2110314|45276|26311|4|nsf|2010-11-24 13:34:00z 2110311|52117|26308|4|nsf|2010-11-24 13:34:00z (etc) 

doing simple split on space doesn't work because of space in datetime stamp. know regex enough know there different ways break down, thought getting few expert opinions me come airtight regex.

if each timestamp going have z @ end can use positive lookbehind assertion split on space if it's preceded z as:

$transaction = preg_split('/(?<=z) /',$input); 

once transactions, can split them on | individual parts.

codepad link

note if data has z followed space anywhere else other timestamp, above logic fail. overcome can split on space if it's preceded timestamp pattern as:

$transaction = preg_split('/(?<=\d\d:\d\d:\d\dz) /',$input); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -