3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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);
Output for 4.3.0 - 7.1.0
string(8) "YO26 4UU"