MLSC
MLSC

Reputation: 5972

PHP: Output current script name

Why the code below:

echo "Usage: " basename($_SERVER["SCRIPT_FILENAME"], '.php') "<arg2> <arg1>";

produces the following syntax error:

PHP Parse error: syntax error, unexpected 'basename' (T_STRING), expecting ',' or ';'

Upvotes: 1

Views: 170

Answers (3)

Needhi Agrawal
Needhi Agrawal

Reputation: 1326

echo __FILE__; //to get the current filename.

So your code becomes:

if($argc!=3){
   echo "Usage: ".__FILE__.".php <arg2> <arg1>";
   die;
}

Upvotes: 0

potashin
potashin

Reputation: 44581

You should concatenate with . operator to provide the string as 1 argument to echo:

echo "Usage: " . basename($_SERVER["SCRIPT_FILENAME"], '.php') . "<arg2> <arg1>";

or use , to provide as multiple :

echo "Usage: ", basename($_SERVER["SCRIPT_FILENAME"], '.php'), "<arg2> <arg1>";

Upvotes: 8

Priyank
Priyank

Reputation: 3868

You can also use commas, like this:

if ($argc != 3) {
    echo "Usage:", basename($_SERVER["SCRIPT_FILENAME"]), '.php', "<arg2> <arg1>";
    die;
}

Upvotes: 0

Related Questions