$str = mysqli_real_escape_string($link, $str);
$pattern = '/(\d+)a/';
$res = preg_match($pattern, $str, $a);
$b = $a[0];
$a = 'Service code 145a is used for...';
$b = '...you are to use code 99a.';$pattern = '/(\d+)a/';$res = preg_match($pattern, $str, $result);$a = 'Service code 145a is used for...';.if(preg_match('/(\d+)a/', $myTextWithCode, $matches)){
$code = $matches[1]; // здесь будет код без буквы а, если нужен в буквой, то ставь нолик
}else{
throw new Exception('Code not found');
}