Here is what I want to state I have this structure-

Now considering the directory I want to add the CSS file to all the files if I am using the project-1 > sub-project > subfile.php
then I should be using <link rel="stylesheet" href="../../asset/css/style.css" />
Again if I use the project-1 > file.php
then I should be using <link rel="stylesheet" href="../asset/css/style.css" />
Now even if I use index.php
then it should be like <link rel="stylesheet" href="asset/css/style.css" />
In short, I want it to access CSS file from any file dynamically. It's a type of autoloading whenever included.
I have tried something but it failed because it's not dynamic
$search = glob("asset/css/style.css");
foreach ($search as $ser) {
$ser = $ser;
}
if(strpos($ser,"asset") !== false){
echo "<link type='text/css' rel='stylesheet' href='asset/css/style.css'>";
}else {
echo "<link type='text/css' rel='stylesheet' href='../asset/css/style.css'>";
}
But the problem is it is not dynamic. Please provide a solid solution. Thanks a lot in advance.