Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只能找到一种涉及输入目录和内容的方法,但我想要的是这样我可以获取 php 文件名(没有扩展名或目录信息)并将其用作任何文件夹中的任何位置的 var(使用 include 函数包含变量)。
你可以使用pathinfo:
$name = pathinfo($_SERVER['SCRIPT_FILENAME'], PATHINFO_FILENAME);
但是请参考上面评论者的建议:-)
$bname = basename($_SERVER['PHP_SELF']); $name = rtrim($bname, '.php');
That's what works for me.