使用php函数解析错误

时间:2018-03-15 13:50:54

标签: php

我一直在经历w3schools试图掌握php。我过去做过一点Java和C ++,但没有网络方面。我无法弄清楚为什么我得到一个解析错误

 <!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> 

这将返回“解析错误:语法错误,第28行C:\ inetpub \ wwwroot \ phpinfo.php中意外的文件结尾”

这项运行正常,删除了该功能。我错过了什么?

1 个答案:

答案 0 :(得分:-2)

您错过了"行的结束双引号(echo)。

更改此行:

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

对此:

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

还要使用良好的语法编辑器。正如@aynber建议的那样。