日期:2014-05-17 浏览次数:20502 次
select a,
(select b from c where ...) as d,
e
from f,(select j from h where ...) as i
where ....
select count(*)
from f,(select j from h where ...) as i
where ....
$s = <<< TXT
select a,
(select b from c where ...) as d,
e
from f,(select j from h where ...) as i
where ....
TXT;
$ar = preg_split('/(\(?\bselect\b
------解决方案--------------------
\bfrom\b)/i', $s, -1, PREG_SPLIT_NO_EMPTY
------解决方案--------------------
PREG_SPLIT_DELIM_CAPTURE);
$n = 0;
$st = array();
for($i=0; $i<count($ar); $i++) {
$t = strtolower($ar[$i]);
if($t == 'select'
------解决方案--------------------
$t == '(select') {
$st[] = $i;
}
if($t == 'from') {
if(count($st) == 1) break;
array_pop($st);
}
}
for($i--; $i>$st[0]+1; $i--) unset($ar[$i]);
$ar[$st[0]+1] = " count(*)\n";
echo join('', $ar);