$string = "'1', '2', '3'"; $string = str_replace("'", '', $string); $sql = "SELECT * FROM name WHERE id NOT IN ( " . implode(",", explode(',',$string)) . ") LIMIT 10 "; echo $sql;