-2

I've been going through w3schools trying to get to grips with php. I've done a little Java and C++ in the past but nothing web side. I can't figure out why I'm getting a parse error

 <!DOCTYPE html>
<html>
<body>

<?php

// calling a variable can be done with $variable or . $Variable .
// php is loosely typed - you do not have to tell it that a var is a int or string etc


$color = "red"; //variables are case sensitive

echo "My car is " . $color . "<br>";


//scopes for vars are either local, global or static. Local are declared inside a function and global are declared outside a function

function myTest()
{
    $x = 5; //local scope
    echo "<p> Variable X inside function is: $x</p>;
}


?>

</body>
</html> 

This returns a "Parse error: syntax error, unexpected end of file in C:\inetpub\wwwroot\phpinfo.php on line 28"

This runs fine with the function removed. What am I missing?

C Mills
  • 21
  • 5

1 Answers1

-2

You missed the closing double quote (") on your echo line.

Change this line:

echo "<p> Variable X inside function is: $x</p>;

To this:

echo "<p> Variable X inside function is: $x</p>";

Also use good syntax editor. as @aynber suggest.

JAAulde
  • 19,250
  • 5
  • 52
  • 63
Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42