使用php函数分析错误
我一直在学习w3schools,试图掌握php。过去我做了一些java和C++,但没有Web方面。我不明白为什么会出现解析错误使用php函数分析错误,php,Php,我一直在学习w3schools,试图掌握php。过去我做了一些java和C++,但没有Web方面。我不明白为什么会出现解析错误 <!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
<!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>
您错过了echo
行上的结束双引号(“
)
更改此行:
echo "<p> Variable X inside function is: $x</p>;
echo”函数中的变量X是:$X;
为此:
echo "<p> Variable X inside function is: $x</p>";
echo”函数中的变量X是:$X”;
还要使用好的语法编辑器。正如@aynber所建议的那样。是:$x代码>缺少一个引号。通过语法检查获得一个好的IDE/编辑器。这对你的头痛有很大帮助。我觉得自己像个白痴。非常感谢。