preg split - PHP, identify dates and week days in strings -


I am trying to identify some strings and date of the day and put the data in another array . My problem is that the data comes in the array but not in regular order.

Example of data structure # 1:

  in Array ([3] = & gt; ziua de deminica 26.10.2014 Deminica 27.10.2013 // in the same line Notes of both dates [4] = & gt; Consum D Energy Electrics [5] => Mediu 6168 5407 [6] => Maxim 7233 6552)  

Data structure Example # 2:

  Array ([3] => ziua de miercuri 15.10.2014 // Note There are some more words in the first row [4] => Mercury 16.10.2013 [5] = & gt; Consum D Energy Electica [6] => Mediu 6573 6747 [7] => Maxim 7771 7892)  

Example of data structure # 3:

  array ([4] => Marty 14.10.2014 [6] => Marty 15.10.2013 [7] => Consum de energie electrica [8] = & gt; Mediu 6453 6754 [9] => Maxim 7551 7860) Example of data structure # 4:  
  Array ([4] = & gt; Gt; Duminica 04.05.2014 [6] = & gt; Due Minaca // Just note the line with the day of the week and the next line date is [7] => 05.05.2013 [8] = & gt; Consum de Energy Electica [9] = & gt; Medius 5265 4262 [10] = & gt; Maxim 6318 4873) Example of Data Structure # 5:  
  Array ([4] => Mercury between 12.02.2014 // Note Missing day of week and date [6] = & gt; Mercury 13.02.2013 [7] = & Consum D Energy Power [8] => Mediu 7274 7434 [9] => Maxim 8313 8401)  

All of these structures are repetitive I try to find a way to collect lines for Mediu XXXX XXXX and Maxim XXXX XXXX I do I want to create an array that should look like this ( let's take example # 1 ):

  Array ([0] => Array ([ Weekday] = & gt; Duminica [date] = & gt; 26.10.2014 [Mediu] => 6168 // Line first value [Maxim] = & gt; 7233 // Line before value) [1] = & Gt; Array ([work] = & gt; Duminica [date] => 27.10.2013 [Mediu] => 5407 / second value from the line [Maxim] => 6552 // Line to second Value))  

Is there any possibility of achieving this? I do not have any regedx ideas to split my data.

Thank you.

What can you do string using string, find it days and dates of the week Will be easier for:

  '26.10.2014 in ZIA de Dominica 27.10.2013', '4' = & gt; Consum D Energy Electra ',' 5 '=>' Mediu 6168 5407 ',' 6 '=> Maxim 7233 6552'); $ Pattern = '~ (? & Lt; dd 0> duminiica | luni | marthi | mariquri | joi | veneri | s [iii] mbata) \ h * (? & Lt; date 0> [0-9] ] {10}) \ h * (? & Lt; day 1 & gt; \ g & lt; day 0 & gt;) \ h * (? & Lt; date1 & gt; \ g  0 ;) *? Mediu \ (? & Lt; Med0 & gt; [0-9] +) \ (? & Lt; Med1 & gt; [0-9] +) \ H + Maxim \ (? & Lt; Max0 & gt; [ 0-9] +) \ (? & Lt; max 1 & gt; [0- 9] +) ~ xu '; $ Str = implode ('', $ arr); If (preg_match ($ pattern, $ str, $ m)) {foreach (category (0,1) $ i) {$ result [] = array ('weekday' => $ m ["day $ i"] , 'Date' = & gt; $ m ["date $ i"], 'medius' => $ m ["Made $ i"], 'maxim' = & gt; $ m ["max $ i" ]); }} And $ result = false; Print_r ($ result);  

Note that if you want to avoid getting the day to day and retrieving the date.


Comments

Popular posts from this blog

Active Directory Authenticated Proxy Server with Squid or CNTLM -

java - @PluginTarget(Node.class) not registering as neo4j plugin -

python - Calculate STD manually using Groupby Pandas DataFrame -