- pathinfo: documentation ( source)
- preg_match: documentation ( source)
- glob: documentation ( source)
- print_r: documentation ( source)
<?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
?>