I have a block of HTML that includes an unordered list of items, followed by a paragraph of text. HTML structure looks something like this:
<ul>
<li>...</li>
</ul>
<p>...</p>
I need to split this block into separate vars. I was thinking of using explode but not sure if it’s the best option.
$hpcs = explode("</ul>", $html);
$hlst = $hpcs[0];
$hsum = $hpcs[1];
2
Answers
if you want to parse in you should use preg_replace
from https://gist.github.com/molotovbliss/18acc1522d3c23382757df2dbe6f0134
Yes, you can use
explode
to split the HTML block into separatevars
. In your code, you are using explode to split the HTML block on the closing tag of the unordered list(</ul>)
. This will result in an array with two elements: the first element will be the unordered list, and the second element will be the paragraph. You can then assign these elements to the variables$hlst
and$hsum
respectively.