I have the following code which I'm using to parse HTML Code and only leave UL and LI tags:
function strip_tags_content($text, $tags = '', $invert = FALSE)
{
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0)
{
if($invert == FALSE)
{
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
}
else
{
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
}
}
elseif($invert == FALSE)
{
return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
}
return $text;
}
echo strip_tags_content($html, "<ul><li>");
This works perfectly fine and I get the following return:
<ul><li class="myLi">Item 1</li><li class="myLi">Item 2</li><li class="myLi">Item 3</li></ul>
What I want to do next is to assign a variable:
$myList = strip_tags_content($html, "<ul><li>");
And then for each li value, push the content within that li tag in an array, so I finish with an array containing 3 items: Item 1, Item 2 and Item 3.
But have no idea how to finish this last part. Can someone help please?