Reputation: 5972
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
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
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
Reputation: 3868
You can also use commas, like this:
if ($argc != 3) {
echo "Usage:", basename($_SERVER["SCRIPT_FILENAME"]), '.php', "<arg2> <arg1>";
die;
}
Upvotes: 0