简体   繁体   English

提取PHP文件的文件名

[英]Fetching filename of a PHP file

I'm trying to fetch the filename of my php file. 我正在尝试获取我的php文件的文件名。 Out of curiosity i was wondering if there are any alternative way of doing this besides. 出于好奇,我想知道除此之外是否还有其他替代方法。

echo "<br/>".basename($_SERVER['PHP_SELF']);

Php has a magic constant that return the file path : __FILE__ PHP具有一个魔术常数,该常数返回文件路径: __FILE__

if you only want the file name, use basename(__FILE__) 如果只需要文件名,请使用basename(__FILE__)

The advantage is that it will work even for a php script called via CLI and not executed by a web server / cgi. 优点是,即使对于通过CLI调用且未由Web服务器/ cgi执行的php脚本,它也将起作用。

See more here 在这里查看更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM