- preg_match: documentation ( source)
- strtoupper: documentation ( source)
- define: documentation ( source)
<?php
if ( ! defined('PHP_EOL')) {
define('PHP_EOL', "\n");
}
function normalise($string) {
preg_match('~[0-9]+[a-z]+$~i', $string, $match);
if ( ! isset($match[0])) {
return false;
}
return strtoupper($match[0]);
}
$tests = array(
'Deu123456tx',
'Deu-12345tx',
'12de45232gb',
);
foreach ($tests as $test) {
echo normalise($test), PHP_EOL;
}
/*
123456TX
12345TX
45232GB
*/