PHP Dynamic include based on current file path

前端 未结 4 2060
北海茫月
北海茫月 2021-02-04 09:59

I want to find a method to include some files based on the current file path.. for example:

I have \"website.com/templates/name1/index.php\", this \"index.php should be

4条回答
  •  一个人的身影
    2021-02-04 10:29

    I think you need to use __FILE__ (it has two underscores at the start and at the end of the name) and DIRECTORY_SEPARATOR constants for working with files based on the current file path.

    For example:

    Using DIRECTORY_SEPARATOR constant is more safe than using "/" (or "\") symbols, because Windows and *nix directory separators are different and your interpretator will use proper value on the different platforms.

提交回复
热议问题