$string = '<ul>
<li id="34334" class="some_class"><a href="/stack/">Text</a></li>
<li id="someid" class="more_class"><a href="/overflow/">Text</a></li>
</ul>';
What I need (actually don't know how to do, please help):
- We must check
<a>
inside each<li>
- If
href
of<a>
==/stack/
, then add extra classcurrent
for parent<li>
Like, if we are searching for /stack/
, we should get this:
$string = '<ul>
<li id="34334" class="some_class current"><a href="/stack/">Text</a></li>
<li id="someid" class="more_class"><a href="/overflow/">Text</a></li>
<li id="34334" class="some_class current"><a href="/stack/">Text</a></li>
</ul>';