EspañolDeutschFrançaisItalianoPortuguêsРусскийΕλληνικά日本語中文(简体)हिन्दी; हिंदीالعربية
设置为默认语言
PF 问题 - 论坛

获取当前的 PHP 文件的名称

¿Cómo puedo obtener dinámicamente el nombre del archivo PHP que estoy ejecutando?

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
威力 preguntó 我们的一日三餐 7 年
2 答案
最佳答案

Simplemente usa la constante nativa de PHP __FILE__. En cualquier lugar del código puedes acceder a ella. Prueba a imprimirla por pantalla y lo verás:

echo __FILE__;

 

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
JuanR 说的得 7 年

Si lo que quieres es simplemente conocer el nombre del archivo PHP sin importar la ruta completa, usa la constante __FILE__ de la siguiente forma

basename(__FILE__);

y te devuelve solamente el nombre del script que estás ejecutando.

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
Maria_rg 说的得 7 年