1

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 ';'

3 Answers 3

8

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>";
Sign up to request clarification or add additional context in comments.

2 Comments

What is , '.php'. Am I allowed to discard it?
@MortezaLSC : It is not required, but you can use it to cut off the suffix of the file, for example, if file is index.php, then only index is returned.
0

You can also use commas, like this:

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

Comments

0
echo __FILE__; //to get the current filename.

So your code becomes:

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

1 Comment

You might want to look up what the second parameter of the basename() function does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.