3v4l.org

run code in 300+ PHP versions simultaneously
<?php $query = 'UPDATE `list` set `item`=?,`type`=? WHERE (`id` = ?);'; $params = array( 'item' => '1', 'type' => 'Are you o\'k?', 'id' => 2 ); function substitute_params($query, $params) { return sprintf( "-- Not to be used as a query to database. For demonstration purposes only!\n%s", str_replace( "\\?", "?", array_reduce( str_replace("?", "\\?", $params), fn($query, $param) => preg_replace( '/(?<!\\\\)\\?/', is_numeric($param) ? $param : "'" . str_replace("'", "''", $param) . "'", $query, 1 ), $query ) ) ); } echo substitute_params($query, $params);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
-- Not to be used as a query to database. For demonstration purposes only! UPDATE `list` set `item`=1,`type`='Are you o''k?' WHERE (`id` = 2);

preferences:
88.27 ms | 1121 KiB | 4 Q