3v4l.org

run code in 300+ PHP versions simultaneously
<?php $target_dir = "in/"; $target_filename = 'asurite_hw1.m'; // Splits the input file name and its extension. $base_name = pathinfo($target_filename, PATHINFO_FILENAME); $extension = pathinfo($target_filename, PATHINFO_EXTENSION); echo 'base_name: ' . $base_name . "\n"; echo 'extension: ' . $extension . "\n"; $previous_files = glob($target_dir . $base_name . '*'); $previous_files = array('asurite_hw1_1.m'); $id = 1; foreach ($previous_files as $f) { $r = preg_match('/.+_(\d+)\.m/', $f, $matches); if (count($matches) > 1 && $id <= $matches[1]) { $id = $id + 1; } } print_r($id); // $pattern = '/^asurite ?>
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
base_name: asurite_hw1 extension: m 2

preferences:
283.51 ms | 404 KiB | 339 Q