Using php and Regex I am attempting to add <li>Valid in US</li> in the last UL after the last LI or to simply put after the last LI.
When debugging I cannot even get the contents of the last UL tag. This code brings up nothing when I do a var_dump (I have also tried preg_match_all with it):
if (preg_match("/((<ul>(.*?)<\/ul>/s){3})", $desc, $WARRANTY) == true)
var_dump($WARRANTY);
This is contents of $desc:
<h1>Stuff</h1>
<p>description</p>
<hr />
<strong>Features & Benefits</strong>
<ul>
<li>feat</li>
<li>feat</li>
<li>feat</li>
</ul>
<hr />
<strong>Specifications</strong>
<ul>
<li>spec</li>
<li>spec</li>
<li>spec</li>
</ul>
<hr />
<strong>Warranty Information for a certain product</strong>
<ul>
<li>3 Years Parts</li>
<li>3 Years Labor</li>
</ul>
<div> <a href="/ahref" target="_blank">See more products from MFG </a></div>
If you want to match the
<ul>tag with only 2<li>tags in it, you can use this regex:I can suggest another hacky way of adding the third li tag:
use this regex:
<ul>\s*(?:<li>[^<]+</li>\s*){2}(<)/ul>and replace the match in the first group with your
<li></li>content followed by a<– because that’s what has been captured by the group(<)