I have a string which contains a bunch of html. I want to be able to put different element contents into different arrays. For example I would like all of the contents within each <li></li> element to be put into an array. This is part of the code so far: $desc is the full string $listItems = preg_split("<li>",$desc, -1 , PREG_SPLIT_NO_EMPTY); Code (markup):
The below regex should do what you want. $string = "<li>some stuff, and stuff</li> <li>some more stuff</li>"; preg_match_all("/<li>(.*?)<\/li>/",$string,$stuff); print_r($stuff); It creates an array that looks like this: Array ( [0] => Array ( [0] => <li>some stuff, and stuff</li> [1] => <li>some more stuff</li> ) [1] => Array ( [0] => some stuff, and stuff [1] => some more stuff ) )
i've never tried this but if i was gonna do what you're trying to do, i'd look into this: http://simplehtmldom.sourceforge.net/manual.htm