[thelist] Regular expression help (PHP)

Scott Wehrenberg swehren at gmail.com
Thu Mar 31 10:26:10 CST 2005


On Thu, 31 Mar 2005 16:23:38 +0200 (CEST), Chris Heilmann
<lists at onlinetools.org> wrote:
> 
> I am working on an automatic navigation highlight script which uses an
> HTML template and removes the current link:
> http://www.onlinetools.org/tests/easynav/
> http://www.onlinetools.org/tests/easynav/easynav.txt
> 
> What the regexp should do is:
> 
> - Remove every <ul> inside an <li> unless there is a <strong> somewhere
> inside that <li>
> 

If you can "cheat" and use the whitespace to match items then here's
my ugly hack:

$items = preg_split('/^ <li>/m',$menu);
$out_ar = array();
foreach($items as $item)
{
    $out_ar[] = strstr($item,'<strong>') ? $item :
preg_replace('/<\/a>.*/s',"</a></li>\n",$item);
}


echo implode('  <li>',$out_ar) . '</ul>'


More information about the thelist mailing list