I have a file called count.php.
this is where count.php is stored (the absolute path):
/home/content/61/7475161/html/wordpress/project/folder1/folder2/folder3/folder4/count.php
I need a way to count how many sub-folders from the folder project are involved in the path.
So in the case above, its four. I’ve come up with one way:
$pathtofile=dirname(__FILE__);
$path_array=explode("/",$pathtofile);
$f_stat=false;
$num_folders=0;
foreach ($path_array as $folder){
if($f_stat===false){
if($folder=="project"){$f_stat=true}
}//end of f_stat false
else{
$num_folders++;
}//end of else
}//end of foreach
//now $num_folders will equal 4 xD
I don’t think thats the best way to do it, so any suggestions would be awesome. thanks!
Just do strstr with
/projectand count the array elements after explode like this: