Using php and regex to grab labels and data and store as associative array -


How can I use regex to find this table in one page (by searching by name it): < / P> & Lt; Td class = "data" & gt; Div class = "datainfo" & gt; Stuff & lt; / Div & gt; & Lt; / Td> & Lt; / Tr & gt; & Lt; Tr & gt; & Lt; Td class = "label" & gt; Email: & lt; / Td> & Lt; Td class = "data" & gt; Div class = "datainfo" & gt; Stuff 2 & lt; / Div & gt; & Lt; / Td> & Lt; / Tr & gt; & Lt; Tr & gt; & Lt; Td class = "label" & gt; Address: & lt; / Td> & Lt; Td class = "data" & gt; Div class = "datainfo" & gt; Stuff 3 & lt; / Div & gt; & Lt; / Td> & Lt; / Tr & gt; & Lt; / Table & gt; & Lt; Table ID = "Table Name 2" & gt; & Lt; Tr & gt; & Lt; Td class = "label" & gt; Field 1: & lt; / Td> & Lt; Td class = "data" & gt; Div class = "datainfo" & gt; More stuff & lt; / Div & gt; & Lt; / Td> & Lt; / Tr & gt; & Lt; Tr & gt; & Lt; Td class = "label" & gt; Field 2: & lt; / Td> & Lt; Td class = "data" & gt; Div class = "datainfo" & gt; More Stuff 2 & lt; / Div & gt; & Lt; / Td> & Lt; / Tr & gt; & Lt; Tr & gt; & Lt; Td class = "label" & gt; Field 3: & lt; / Td> & Lt; Td class = "data" & gt; Div class = "datainfo" & gt; Mortage 3 & lt; / Div & gt; & Lt; / Td> & Lt; / Tr & gt; & Lt; / Table & gt;

Then grab "label" and "datainfo" and store them in a companion array such as:

  $ table_name [name] // content $ Table_name [email] // Stuff2 $ table_name [address] // Stuff3 $ table_name2 [field1] // more info $ table_name2 [field2] // morestaf 2 $ table_name2 [field3] // morefirst 3  
< / Div>

Reggae is a bad solution in this case. Use instead

Update: Here's the function for:

  $ html = str_get_html ($ html); Print_r (get_table_fields ($ html, 'table name')); Print_r (get_table_fields ($ html, 'Table Name 2')); Function get_table_fields ($ html, $ id) {$ table = $ html- & gt; Search ('table [id ='. $ Id. ']', 0); Find foreign currency ($ table-> as line $ ('tr')) {$ key = $ row-> Search ('TD', 0) - & gt; Plain text; $ Value = $ row-> Find ('TD', 1) - & gt; Plain text; ## Finish ':' symbol $ key = preg_replace ('/: $ /', '', $ key); $ Result [$ key] = $ value; } Return result; }  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -