you can do this:
$string='[li]text1[li]text2[/li][/li]'; $pattern=':\[(/?li[^\]]*)\]:'; echo preg_replace($pattern,"<$1>",$string);
or even like this:
$pattern=':\[([^\]]+)\]:';
http://ideone.com/wj00gf
complete solution with tag verification, etc. such as:
$pattern=':(?P<block>\[((?P<tag>[^\s\]]+)[^\]]*)\]((?&block)|[^\]]+)\[/((?P=tag))\]):'; do{ $string=preg_replace($pattern,'<$2>$4</$5>',$string,-1,$count); } while($count>0);
http://ideone.com/Qu2fmB
should by the way notice that, according to the HTML standard, the <li> should be included only in the <ul> , <ol> or <menu> elements, i.e. code
<li> test <li> test1 </li> </li>
not correct
