<?php
$Str="select a.*,b.* from aaa a left join bbb b on a.id=b.id where a.id=33 group by a.id order by b.id";
echo preg_replace("/select (.+?) from (.+?) where (.+?) /i","$1<br />$2<br />$3<br />",$Str);
?>没搞清你要干什么~~
乱写个先……

解决方案 »

  1.   

    嘿嘿,要考虑这种情况:
    select * from aaa where x="xasdfas select saflsafj from asfsaf where safasf";
      

  2.   

    这样不行,详细说一下吧,现在语句的可能性有
    select .... from .....
    select .... from .... order by ...
    select .... from .... group by ... order by ...
    select .... from .... where ....
    select .... from .... where .... order by ...
    select .... from .... where .... group by ... order by ...
    主要的就是这些了吧,就是order by ... 部分不要 group by ...部分不要 然后有where的,join的 都包含到第二部分里边 select的部分算第一部分
      

  3.   

    <?php
    $Str="select a.*,b.* from aaa a left join bbb b on a.id=b.id where x=\"xasdfas select saflsafj from asfsaf where x=\"xasdfas select saflsafj from asfsaf where x=\"xasdfas select saflsafj from asfsaf where safasf\"\" safasf\" a.id=33 group by a.id order by b.id ";
    print preg_replace("/select(.+?)from(.+?)where(.*?)(order|group)/","Se: $1<br />Fro: $2<br /> Whe $3 <p />",$Str);
    ?>结果:
    ---------------
    Se: a.*,b.* 
    Fro: aaa a left join bbb b on a.id=b.id 
    Whe x="xasdfas select saflsafj from asfsaf where x="xasdfas select saflsafj from asfsaf where x="xasdfas select saflsafj from asfsaf where safasf"" safasf" a.id=33 by b.id group by a.id
    ---------------
    可包含无限子查询
    换成
    'order by b.id group by a.id'
    'group by a.id order by b.id'
    都没问题但~~
    哪位高手给看看,我搞了半天'by b.id group by a.id'也没去掉.