basically i have a folder with php scripts and then in that folder i have another folder with scripts. I want to load the same header file in each folder’s index.php script. The script to include is nav.php located in the inclues folder.
Tree
includes
nav.php
Folder1
header.php
index.php
Folder2
index.php
i want to do this:
if getcwd() = 'Folder2'{
include('../../includes/nav.php');
}else{
include('../includes/nav.php');
But the problem is getcwd() returns the whole path in a string but i just want the cur directory name. How can I cut the string specifically to the remove everything but the directory name. All solutions are good to know,but im particularly interested in the function for slicing a string in that way.
See function:
Read about it here: http://php.net/manual/en/function.basename.php
should return to you the folder name from the path.
Here is an example of basename and dirname: