How can I get the only name of the current executing file?

Answers were Sorted based on User's Feedback



How can I get the only name of the current executing file?..

Answer / hitha

$file_path=$_SERVER["SCRIPT_NAME"];

$break=explode('/',$file_path);

$file_name=$break[count($break)-1];

Is This Answer Correct ?    12 Yes 0 No

How can I get the only name of the current executing file?..

Answer / sudeb mandal

<?php
//To get current file name.
$file = $_SERVER["SCRIPT_NAME"];
echo $file;

?>

Is This Answer Correct ?    5 Yes 1 No

How can I get the only name of the current executing file?..

Answer / palaniraja.wordpress.com

echo end(explode('/',$_SERVER["SCRIPT_NAME"]));

Is This Answer Correct ?    2 Yes 0 No

How can I get the only name of the current executing file?..

Answer / nilsoft

There are too many solutions. But i am showing 4 among them

Method 1.
$file = trim($_SERVER["SCRIPT_NAME"],'/');

Method 2.
$file =
substr($_SERVER["SCRIPT_NAME"],1,strlen($_SERVER["SCRIPT_NAME"])-1);

Method 3.
$file = str_replace('/','',$_SERVER["SCRIPT_NAME"]);

Method 4.
$file = basename($_SERVER["SCRIPT_NAME"]);

and so on............

Is This Answer Correct ?    1 Yes 0 No

How can I get the only name of the current executing file?..

Answer / bhawani

$name=basename($_SERVER['PHP_SELF']);

echo $name;

Is This Answer Correct ?    0 Yes 0 No

How can I get the only name of the current executing file?..

Answer / vaishali

basename($_SERVER('PHP_SELF'));


give the current file name

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More PHP Interview Questions

What is the difference between indexed and associative array?

0 Answers  


what are interfaces and Abstart classes

0 Answers   Net Solution,


How many escape sequences are recognized in single-quoted strings?

0 Answers  


I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?

0 Answers  


How to get the DNS servers of a domain name?

1 Answers   Life Infotech,


What is the use of mysqli_real_escape_string() function?

0 Answers  


Which is used to maintain the value of a variable over different pages?

0 Answers  


Is php pass by reference or value?

0 Answers  


1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10

14 Answers   Aquasol, Infosys, TCS, Torque Infotech,


What is difference between php and html?

0 Answers  


How to upload file in php?

0 Answers  


What is difference between php and wordpress?

0 Answers  


Categories