Data in numeri romani con PHP

isola

Data in numeri romani

function date_roman($str) {
$str=strtolower($str);
$str=str_replace("a.c.","",$str);
$str=str_replace("ac","",$str);
$str=str_replace("ca.","",$str);
$str=str_replace("sec","",$str);
$str=str_replace("in.","",$str);
$str=str_replace("ex.","",$str);
$str=str_replace(" ","",$str);
$str=preg_replace('/[^A-Za-z0-9-.]/', '', $str); // Removes special chars.
$str=strtoupper($str);
$roman = array('M'=>1000,'D'=>500,'C'=>100,'L'=>50,'X'=>10,'V'=>5,'I'=>1);
$len = strlen($str);
$pre=0; $value=0; $tot=0;
for($i = $len; $i > -1; --$i) {
$value= $roman[$str[$i]];
if ($value>=$pre) {
$tot += $value;
$pre=$value;}
if ($value<$pre) {
$tot -= ($value);
$pre=0;}
}
return $tot;
}

Torna in alto