<?php
$strs = [
'/site/a/index.php',
'/site/xx/y/z/a/index.php',
'/site/xx/aa/bb/cc/index.php',
];
foreach($strs as $str)
{
$match = basename(dirname($str));
echo $str.' -> '.$match."\n";
}
/*
/site/a/index.php -> a
/site/xx/y/z/a/index.php -> a
/site/xx/aa/bb/cc/index.php -> cc
*/