<?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);
?>没搞清你要干什么~~
乱写个先……
$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);
?>没搞清你要干什么~~
乱写个先……
select * from aaa where x="xasdfas select saflsafj from asfsaf where safasf";
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的部分算第一部分
$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'也没去掉.