这样的递归怎么做?!
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);