This question already has an answer here:
Can anyone tell me why I am getting parse errors for these simple codes? The PHP version I am using is 5.5.12.
<?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>
( ! ) Parse error: syntax error, unexpected 'Â Â Â ' (T_STRING), expecting case (T_CASE) or default (T_DEFAULT) or '}' in on line 5
<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$email = $gender = $comment = $website = "";
$MyVar = $_SERVER["REQUEST_METHOD"];
echo $_SERVER["REQUEST_METHOD"];
if ($MyVar == "GET") {
echo "This is it.
";
}
}
?>
( ! ) Parse error: syntax error, unexpected '{' in on line 18
</div>
The first code is totally right!
The second one, you have put an extra '}' in the end of the file. just use:
<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$email = $gender = $comment = $website = "";
$MyVar = $_SERVER["REQUEST_METHOD"];
echo $_SERVER["REQUEST_METHOD"];
if ($MyVar == "GET") {
echo "This is it.
";
}
or
<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$email = $gender = $comment = $website = "";
$MyVar = $_SERVER["REQUEST_METHOD"];
echo $_SERVER["REQUEST_METHOD"];
if ($MyVar == "GET")
echo "This is it.
";