$p) { if (strpos($content, $p[0]) !== false) { $content = str_replace($p[0], $p[1], $content); $content = str_replace($p[2], $p[3], $content); echo "Patched #$i \n"; // Let's also add the ? to the query string $q0 = "VALUES ("; $q1 = "VALUES (?, "; // We only want to add it inside the specific INSERT query $insert_start = strpos($content, $p[1]); if ($insert_start !== false) { $values_start = strpos($content, 'VALUES (', $insert_start); if ($values_start !== false) { $content = substr_replace($content, 'VALUES (?, ', $values_start, 9); } } } } file_put_contents('index.php', $content);