phphtml-parsing

Insert a span tag containing a p tag with text after each li tag


I am trying to replace some html in php with preg_replace and I don't seem to get the regex fine, because I always screw it up.

Could you please help me with it ?

I have the following:

<ol><li>text</li><li>text</li></ol>

<ol><li><ul><li>text</li></ul></li></ol>

And I want to insert a <span></span> right after <li> and place the text in <p>. I must note that I don't want the <li> inside the <ul> to be affected.


Solution

  • Rather than trying to write a single regexp to handle this (I think it might be possible to do it with a look-behind type match) it'd be easiest to: