1 réponse
Bonjour,
Comme ceci?
et
Comme ceci?
function getsubdir($str,$dir) {
// Remove the filename
$str = dirname($str);
// Remove the $dir
if(!empty($dir)){
$str = str_replace($dir,"",$str);
}
// Remove the leading '/' if there is one
$si = stripos($str,"/");
if($si == 0){
$str = substr($str,1);
}
// Remove everything after the subdir (if there is anything)
$lastpart = strchr($str,"/");
$str = str_replace($lastpart,"",$str);
return $str;
}
et
$str = "dir1/dir2/dir3/dir4/filename.ext"; $dir = "dir1/dir2"; $subdir = getsubdir($str,$dir); echo $subdir; // sort "dir3"