3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $value = 'Y-100;Y+10'; $arrvalidrules = explode(';', $value); // On vérifie qu'il n'y bien que deux valeurs. if (count($arrvalidrules) == 2) { $arrvarlabels = array('intyearstart', 'intyearend'); foreach ($arrvarlabels as $key => $label) { if ($arrvalidrules[$key]!='') { if (is_numeric($arrvalidrules[$key])) { ${$label} = intval($arrvalidrules[$key]); } else if (strpos($arrvalidrules[$key], 'Y') === 0) { ${$label} = date('Y'); if (($intsignpos = strpos($arrvalidrules[$key], '+')) !== false) { ${$label} += intval(trim(substr($arrvalidrules[$key], $intsignpos+1))); } else if (($intsignpos = strpos($arrvalidrules[$key], '-')) !== false) { ${$label} -= intval(trim(substr($arrvalidrules[$key], $intsignpos+1))); } } else { ${$label} = 0; } } else { ${$label} = 0; } } } echo 'Date : '.$intyearstart.' - '.$intyearend;
Output for 4.3.0 - 7.1.0
Date : 1913 - 2023