2021年3月19日星期五

How to get css file from any file using php?

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

enter image description here

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.

https://stackoverflow.com/questions/66718341/how-to-get-css-file-from-any-file-using-php March 20, 2021 at 12:49PM

没有评论:

发表评论