我有一个包含 sql 语句的字符串,如下所示:
$sql = "SELECT nic_number, client_title, client_lastname FROM customer ORDER BY id_client LIMIT 0, 1";
我想从中删除LIMIT 0, 1
,以便它变成
SELECT nic_number, client_title, client_lastname FROM customer ORDER BY id_client
多谢你们。
使用str_replace:
echo str_replace("LIMIT 0, 1", "", $sql);
$sql = 'SELECT nic_number, client_title, client_lastname FROM customer ORDER BY id_client LIMIT 0, 1';
echo $sql = preg_replace('/LIMIT \d+, \d+/', '', $sql);
假设内容始终相同:
$sql = str_replace('LIMIT 0, 1', '', $sql);