Replacing tags inside the parent tag using DOM PHP
Posted
by
user585303
on Stack Overflow
See other posts from Stack Overflow
or by user585303
Published on 2011-02-04T23:06:55Z
Indexed on
2011/02/04
23:25 UTC
Read the original article
Hit count: 219
Here is what I got:
<div id="list">
<ol>
<li>Ordered list 1</li>
<li>Ordered list 2</li>
<ul><li>Unordered list inside ol ul</li></ul>
<ol><li>Ordered list inside ol ol</li></ol>
<ol>
<ul>
<li>Unordered list</li>
<ol><li>Ordered list inside ul</li></ol>
<ul>
<ol>
<li>Ordered list 1</li>
<ol><li>Ordered list inside ol ol</li></ol>
<ol>
</div>
I need somehow replace LI tags only inside div id="list" -> OL tags I need so that it replaces only LI tags only within the first OL tags and not UL or the once inside OL -> OL tags
I tried using preg_replace_callback but it only replaces all LI tags inside id="list" and from what i figured it will be over my head to limit replacement only with first ol tags and not the rest, so I been suggested to try out PHP DOM since it should be as easy as div id="list" -> OL
I would appreciate if someone got me started with the code, maybe with something as replacing all LI tags with in the first OL tag within the whole content.
© Stack Overflow or respective owner