<?php $fileContents = <<<TEXT 1|2 2|6 3|8 4|3 5|10 TEXT; $_GET['candidate'] = '4'; if (isset($_GET['candidate'])) { $fileContents = preg_replace_callback( '~^' . (int)$_GET['candidate'] . '\|\K\d+~m', function($m) { return ++$m[0]; }, $fileContents ); echo "New total: " . array_sum(preg_match_all('~\|\K\d+~', $fileContents, $m) ? $m[0] : []); echo "\n---\n"; echo $fileContents; //file_put_contents('results.txt', $fileContents); }
You have javascript disabled. You will not be able to edit any code.