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) { $intyearend = null; if ($arrvalidrules[0]!='') { if (is_numeric($arrvalidrules[0])) { $intyearstart=intval($arrvalidrules[0]); } else if (strpos($arrvalidrules[0], 'Y') === 0) { $intyearstart = date('Y'); if (($intsignpos = strpos($arrvalidrules[0], '+')) !== false) { $intyearstart += intval(trim(substr($arrvalidrules[0], $intsignpos+1))); } else if (($intsignpos = strpos($arrvalidrules[0], '-')) !== false) { $intyearstart -= intval(trim(substr($arrvalidrules[0], $intsignpos+1))); } } else { $intyearstart = false; } } else { $intyearstart = 0; } if ($arrvalidrules[1]!='') { if (is_numeric($arrvalidrules[1])) { $intyearend=intval($arrvalidrules[1]); } else if (strpos($arrvalidrules[1], 'Y') === 0) { $intyearend = date('Y'); if (($intsignpos = strpos($arrvalidrules[1], '+')) !== false) { $intyearend += intval(trim(substr($arrvalidrules[1], $intsignpos+1))); } else if (($intsignpos = strpos($arrvalidrules[1], '-')) !== false) { $intyearend -= intval(trim(substr($arrvalidrules[1], $intsignpos+1))); } } else { $intyearend = false; } } else { $intyearend = 0; } } $label = 'intyear'; ${$label} = 'test'; echo $intyear; echo 'Date : '.$intyearstart.' - '.$intyearend;
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
testDate : 1913 - 2003