如
Select 不管是什么 from `#@__archives` 条件 order by rand() limit 1,1案例一如:Select aa,dd,cc from `#@__archives` aa='33' and bb='ff' order by rand() limit 1,200
案例二如:Select dd,gggg from `#@__archives` ggg='33' order by rand() limit 60
我要如下条件替换
根据Select from 中间不管是什么替换成 count(*) as count 并把 order 为后面去掉结果案例一:Select count(*) as count from `#@__archives` aa='33' and bb='ff'
结果案例二:Select count(*) as count from `#@__archives` ggg='33'
替换条件二Select from 中间不管是什么替换成 id 并把 order by rand() 去掉结果案例一:Select id from `#@__archives` aa='33' and bb='ff' limit 1,200
结果案例二:Select id from `#@__archives` ggg='33' limit 60先说一下谢谢
Select 不管是什么 from `#@__archives` 条件 order by rand() limit 1,1案例一如:Select aa,dd,cc from `#@__archives` aa='33' and bb='ff' order by rand() limit 1,200
案例二如:Select dd,gggg from `#@__archives` ggg='33' order by rand() limit 60
我要如下条件替换
根据Select from 中间不管是什么替换成 count(*) as count 并把 order 为后面去掉结果案例一:Select count(*) as count from `#@__archives` aa='33' and bb='ff'
结果案例二:Select count(*) as count from `#@__archives` ggg='33'
替换条件二Select from 中间不管是什么替换成 id 并把 order by rand() 去掉结果案例一:Select id from `#@__archives` aa='33' and bb='ff' limit 1,200
结果案例二:Select id from `#@__archives` ggg='33' limit 60先说一下谢谢
$replacement1 = "\${1}count(*) as count\$2";
$replacement2 = "\${1}id\$2\$3";print preg_replace($pattern1, $replacement1, $string);
print preg_replace($pattern1, $replacement2, $string);没有测试,自己试下
Select id from `#@__archives` aa='33' and bb='ff' order by rand()换成limit 1,200就对了还有一个问题是Select和from之间有回车就不起作用了
如Select aa,dd,cc
from `#@__archives` aa='33' and bb='ff' order by rand() limit 1,200
$pattern1 = "/(Select).*(from .*)( order .*)( limit.*)/is";
$replacement1 = "\${1} count(*) as count \$2";
$replacement2 = "\${1} id \$2\$4";print preg_replace($pattern1, $replacement1, $string);
print preg_replace($pattern1, $replacement2, $string);