3v4l.org

run code in 300+ PHP versions simultaneously
<?php $query = 'UPDATE `list?` set `item`=?,`type`=? WHERE ( "ty?pe?"<> \'Are yo?\' `id` = ?);'; $params = array( 'item' => '1', 'type' => 'Are you o\'k?', 'id' => '2' ); function substitute_params($query, $params) { $prep_params = str_replace(array("'","?"),array("''","\\?"),$params); $query = array_reduce($prep_params, function ($interm, $param) { return preg_replace('/^([^"\'`]*?(?:(?:`[^`]*?`[^"\'`]*?)*?(?:"[^"]*?"[^"\'`]*?)*?(?:\'[^\']*?\'[^\'"`]*?)*?)*?)(?<!\\\\)\\?/m', '${1}'.(is_numeric($param) ? $param : '\'' . $param . '\''), $interm, 1); }, $query); return "-- Not to be used as a query to database. For demonstration purposes only!\n" .str_replace("\\?", "?", $query); } echo substitute_params($query, $params); ?>
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
-- Not to be used as a query to database. For demonstration purposes only! UPDATE `list?` set `item`=1,`type`='Are you o''k?' WHERE ( "ty?pe?"<> 'Are yo?' `id` = 2);

preferences:
108.68 ms | 407 KiB | 5 Q