If you encounter a regular expression problem, please kindly advise. I am doing regular expression matching and want to set the following attribute names (such as color classification and package type) and attribute values (white, black, package 1, package 2 and package 3 ).
The content in the middle is matched by regular expressions, and then
Attribute name
It matches the property value, but the test fails in the first step :/
. *) <\/Dl> I use this regular expression to match each
But it has never been easy. please give me some advice. thank you.
-
Color classification
-
-
White
Selected
-
Black
Selected
-
Package Type
-
-
Package 1
Selected
-
Package 2
Selected
-
Package 3
Selected
Reply to discussion (solution)
// Add an include ('simple _ html_dom.php ') on the Internet by yourself; $ dom = new simple_html_dom (); $ dom-> load ($ s ); // $ s is your html $ dls = $ dom-> find ('dl '); $ res = array (); foreach ($ dls as $ k => $ dl) {$ res [$ k] ['type'] = $ dl-> find ('dt ') [0]-> text (); foreach ($ dl-> find ('Lil') as $ k1 => $ li) {$ res [$ k] [] = $ li-> find ('span ') [0]-> text () ;}} echo"";print_r($res);echo "
";/* Array ([0] => Array ([type] => color classification [0] => White [1] => Black) [1] => Array ([type] => package type [0] => Package 1 [1] => package 2 [2] => package 3 ))*/
$ S = <HTML
-
Color classification
-
- WhiteSelected
- BlackSelected
-
Package Type
-
- Package 1Selected
- Package 2Selected
- Package 3Selected
HTML; preg_match_all ('#
Array ([0] => Array ([0] => color classification [1] => White [2] => Black) [1] => Array ([0] => package type [1] => Package 1 [2] => package 2 [3] => package 3 ))