Tuesday 15 January 2013

php - Using regex to group data and it's children -


I have a simple document that I need to split into events (by day), unfortunately the other in the document There is waste information (such as event details) which I will need to crawl to get information. Except this document it looks like:

  10 March 2015 Baseball 10:00 Please take care of bringing your bat football from 14:00 to 18 March 2015 only on March 19, 2015 Swimming 10:00 Children only use football 14: 14 more than 14 team training  

To use preg_spit of my starting plan, the date was to split and split the string, then loop on each one, However I need to maintain the structure of the document.

Ideally I would like to return the data to the array:

  arr ['days' = & gt; ['Date' = & gt; '10th March 2015 '' Event '= & gt; ['Baseball 10:00', 'Soccer 14:00'],]]  

How would I go best about doing this? Reggae is not my strongest suit, but I know that the day captures ([0-9] {1,2} [az] {2} / s [az] + / s [0- 9] Is enough to {4}) and the event ([aZ] + / s [0- 9] {2}: [0- 9] {2}) .

You can use this regex:

  / ( ?: \ B (\ d + th \ .h + * \ d {4}) \ b | \ g) \ s + (\ S + \ h + \ d {2}: \ d {2} \ b ) * (= \ S + (& gt; \. S + \ h + \ d {2}: \ d {2} | \ d + th \ h + | \ z)) / i  

And then a bit code loop result through PHP.


No comments:

Post a Comment