PHP 运行文件时出现语法错误
PHP Syntax error when i run file
我是 PHP 的新手,在运行 PHP 文件时出现以下 PHP 错误。
一点帮助将不胜感激,非常感谢
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\facebook\arrays.php on line 21
这是我的代码:
<html>
<head>
<title> An empty html page </title>
</head>
<body>
<!-- this is an html comment -->
<!-- currently the body is empty -->
<?php
echo "<p>hello world</p>";
$name = "Peter Pan";
$address = "Neverland";
$age = "14.75";
$unnamed_lost_boys = array(4.5, 6, 7, 5.5, 5.25, 4, 7, 6.75);
$named_lost_boys = array( "Tootles"=> 4.5,
"Nibs"=>6,
"Slightly"=>7.5);
echo "The age of Nibs is $named_lost_boys['Nibs']";
function print_details ($name, $age, $address)
{
echo "My name is $name, I'm from $address and I'm $age years old";
echo "<br>";
echo 'My name is '.$name.",I'm from ".$address." and I'm $age years old";
echo "<br>";
}
print_details($name, $age, $address);
?>
</body>
</html>
如果不将数组用大括号括起来,就不能在字符串插值中使用数组;所以使用:
echo "The age of Nibs is {$named_lost_boys['Nibs']}";
尝试:
echo "The age of Nibs is " . $named_lost_boys['Nibs'];
我是 PHP 的新手,在运行 PHP 文件时出现以下 PHP 错误。 一点帮助将不胜感激,非常感谢
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\facebook\arrays.php on line 21
这是我的代码:
<html>
<head>
<title> An empty html page </title>
</head>
<body>
<!-- this is an html comment -->
<!-- currently the body is empty -->
<?php
echo "<p>hello world</p>";
$name = "Peter Pan";
$address = "Neverland";
$age = "14.75";
$unnamed_lost_boys = array(4.5, 6, 7, 5.5, 5.25, 4, 7, 6.75);
$named_lost_boys = array( "Tootles"=> 4.5,
"Nibs"=>6,
"Slightly"=>7.5);
echo "The age of Nibs is $named_lost_boys['Nibs']";
function print_details ($name, $age, $address)
{
echo "My name is $name, I'm from $address and I'm $age years old";
echo "<br>";
echo 'My name is '.$name.",I'm from ".$address." and I'm $age years old";
echo "<br>";
}
print_details($name, $age, $address);
?>
</body>
</html>
如果不将数组用大括号括起来,就不能在字符串插值中使用数组;所以使用:
echo "The age of Nibs is {$named_lost_boys['Nibs']}";
尝试:
echo "The age of Nibs is " . $named_lost_boys['Nibs'];