Home >Backend Development >PHP Tutorial >求个正则 高难度的

求个正则 高难度的

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:29:021137browse


[m:cname]
 

变成 (关键在 如果 上方
[list:cname]
 

变成 



[list:cname]



===============================

如果多层,这个很有挑战性 ,不知道正则行不行 如果行 给多加分



[channel:cname]


[artlist:title]

 


转为


[channel:cname]

   
       [artlist:title]
   

 


 


回复讨论(解决方案)

$s =<<< 'TXT'<!--m:{ $Row=10 $table=Channel $Where=[FatherID]=0 }--><a href="[m:curl]">[m:cname]</a><!--m--> <!--list:{ $Row=10 $table=Channel $Where=[FatherID]=0 }--><a href="[list:curl]">[list:cname]</a><!--list--> <!--channel:{ $row=10 $table=channel  }--><a href="[channel:curl]">[channel:cname]</a><!--artlist:{ $row=6 $cid=[channel:childids] $order=[order] desc,[id] desc }--><a href="[artlist:aurl]">[artlist:title]</a><!--artlist--> <!--channel-->TXT;$p = array(  '/<!--(\w+):{ \$Row=(\d+)(.+)}-->/i',  '/<!--\w+-->/',);$r = array(  '<qlist listname="$1"  row="$2"$3>',  '</qlist>',);echo preg_replace($p, $r, $s);
<qlist listname="m"  row="10" $table=Channel $Where=[FatherID]=0 ><a href="[m:curl]">[m:cname]</a></qlist> <qlist listname="list"  row="10" $table=Channel $Where=[FatherID]=0 ><a href="[list:curl]">[list:cname]</a></qlist> <qlist listname="channel"  row="10" $table=channel  ><a href="[channel:curl]">[channel:cname]</a><qlist listname="artlist"  row="6" $cid=[channel:childids] $order=[order] desc,[id] desc ><a href="[artlist:aurl]">[artlist:title]</a></qlist> </qlist>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn