3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getExt($filename) { if(!is_file($filename)) return ''; $n = strlen($filename); if($n<2) return ''; $non_ext = ''; $ext = ''; Echo $filename; for($i=$n;$i--;$i>=1) { $c = $filename[$i]; if($c==='.') { $ext = '.'.$non_ext.$ext; $non_ext = ''; }else $non_ext = $c.$non_ext; } return $ext; } $filename = "asdfasdfasd.tar.gz"; $ext = getExt($filename); var_dump($ext);
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Warning: is_file(): open_basedir restriction in effect. File(asdfasdfasd.tar.gz) is not within the allowed path(s): (/tmp:/in:/etc) in /in/0qdGm on line 5 string(0) ""
Output for 7.3.32 - 7.3.33, 7.4.26, 7.4.33, 8.0.13
string(0) ""

preferences:
230.82 ms | 402 KiB | 292 Q