- str_pad: documentation ( source)
<?php
function getPatientCodeDisplay($id='') {
if(intval($id)>0) {
$id_length = strlen($id);
$prefix_code = "AHD";
$final_len = 6+strlen($prefix_code)-$id_length;
$retstr = str_pad($prefix_code, $final_len, "0", STR_PAD_RIGHT);
$retstr .= $id;
} else {
$retstr = "";
}
return $retstr;
}
echo getPatientCodeDisplay(12);