勉强写一个,匹配第一个的.
$string = 'select * from test limit 1';
$pattern = "/(select)\s+\*\s+(from)\s+(.*?)\s+(limit)\s+(\d)/";
$replacement = "\$1 top \$5 * \$2 \$3";
echo preg_replace($pattern, $replacement, $string);另: "select * from test limit 1 2 转换成 select top 2 * from test; "     select * from test limit 1 2   是从第2条记录开录的两条(2,3)记录
用sqlserver的写法应该是: select top 2 * from (select top 3 * from test order by id desc) a order by id