3v4l.org

run code in 300+ PHP versions simultaneously
<?php $userInput = 'YO264UU'; // remove all spaces and upper case $userInput = strtoupper(preg_replace('/\s+/', '', $userInput)); if (true || isValidPostcode($userInput)) { // Basic postcode formatting - add a space before the last 3 characters $formatted = substr($userInput, 0, -3) . ' ' . substr($userInput, -3); // now look up in db using $formatted } else { // invalid postcode! } var_dump($formatted);

preferences:
37.37 ms | 402 KiB | 5 Q