I am trying to turn LIs into DDs… I would have thought if I use a lookback /lookahead combo i could keep from unintentionally changing all the <ul><li>'s ( separating the MAIN UL first… and then having a rgex that checks for <LI>s that are NOT preceded by ULs and then change the <li> and </li> to <dd> and <dd>
this is what I THOUGHT would do it (it actually woks unless there is a nested list in the data)
$dts=preg_replace("#(?<!<ul>)<li([^>]*)>(.*)</li>.*(?!</ul>)#sU", "\ <dd$1>$2</dd>", $dts);
the whole code and sample data is this:
function makeDL($string){
$seg=preg_match_all("#<!--DL-->.*(<ul[^>]*)>(.*)(</ul>.*<!--/DL-->)#sU", $string,$matches, PREG_SET_ORDER);
if ($seg>0){
foreach ($matches as $match){
/*echo "<pre>";var_dump($match);echo "</pre><hr>";continue;*/
$toReplace=$match[0];
$newString= str_replace("<ul","<dl",$match[1]).">";
$dts=preg_replace("#<li><b([^>]*)>(.*)</b></li>#sU", "\ <dt$1>$2</dt>", $match[2]);
$dts=preg_replace("#(?<!<ul>)<li([^>]*)>(.*)</li>.*(?!</ul>)#sU", "\ <dd$1>$2</dd>", $dts);
$newString.=$dts."\
</dl>";
$string= str_replace($toReplace,$newString,$string);
}
}
return ($seg>0)? makeDL( $string) :$string;
}
$s="<p>lorem ipsum test</p>
<!--DL-->
<ul class='x'>
<li><b>item</b></li>
<li>item</li>
<li><b>item</b></li>
<li>item</li>
<li>item</li>
</ul>
<!--/DL-->
<p>lorem ipsum test</p>
<!--DL-->
<ul class='x'>
<li><b>item</b></li>
<li>item</li>
<li>item</li>
<li><b>item</b></li>
<li>item</li>
<li>item2</li>
<li>item2</li>
</ul>
<!--/DL-->
<p>lorem ipsum test</p>
<p>lorem ipsum test</p>
<p>lorem ipsum test</p>
echo makeDL($s);
?>
all help is appreciated