解析错误:语法错误、未预期的T_STRING、expect“、”或“;”在C:\AppServ\www\text中。php在第11行

时间:2021-03-16 22:31:10

I am new to PHP and have a question about it.

我是PHP新手,有一个问题。

<?php

    echo "Do you like it?";
    echo "<br>";
    echo "My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ";

?>

When I try to load this script in my browser, I am getting this error:

当我尝试在浏览器中加载这个脚本时,我得到了这个错误:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\AppServ\www\text.php on line 11

解析错误:语法错误、未预期的T_STRING、expect“、”或“;”在C:\AppServ\www\text中。php在第11行

Lline 11 is

Lline 11

echo "My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ";

How can I fix this?

我怎么解决这个问题?

4 个解决方案

#1


5  

The issue is the inner quotes (") around the style data are ending the string. Either use a single quote ' (this way PHP will look for another single quote to represent the end of the string):

问题是围绕样式数据的内部引号(")结束字符串。或者使用单引号”(这样PHP就会寻找另一个单引号来表示字符串的结尾):

echo 'My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ';

Or escape the double quotes in the string:

或者在字符串中避免双引号:

echo "My name is:<b><i><div style=\"text-align:center;\">Karthic</div></i></b>";

This tells PHP to ignore them when parsing the code (and instead place them INSIDE the string itself).

这告诉PHP在解析代码时忽略它们(而不是将它们放在字符串本身中)。

#2


3  

Use single quotes when printing HTML

在打印HTML时使用单引号。

echo 'My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ';

Instead of

而不是

echo "My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ";

You were cutting off the HTML string, so it was erroring out.

你切断了HTML字符串,所以它是错误的。

#3


2  

you can't do

你不能做

echo "My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ";

because there is 2 double quote one after echo one after style

因为有2个双引号,一个接一个。

you should then do

你应该那么做

echo "My name is:<b><i><div style=\"text-align:center;\">Karthic</div></i></b> ";

but most of all of this ; you dont need to do echo for HTML code like this.

但大多数情况下;您不需要对这样的HTML代码进行echo。

Regards

问候

#4


1  

You will have to escape any double quotes that are contained within double quotes. You escape double quotes using the backslash character.

你必须避免双引号内包含的双引号。使用反斜杠字符来避免双引号。

<?php
echo "Do you like it?";
echo "<br>";
echo "My name is:<b><i><div style=\"text-align:center;\">Karthic</div></i></b> ";
?>

You should also put the bold and italic tags within the div instead of outside of it.

您还应该将粗体和斜体标记放在div中,而不是放在它的外部。

#1


5  

The issue is the inner quotes (") around the style data are ending the string. Either use a single quote ' (this way PHP will look for another single quote to represent the end of the string):

问题是围绕样式数据的内部引号(")结束字符串。或者使用单引号”(这样PHP就会寻找另一个单引号来表示字符串的结尾):

echo 'My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ';

Or escape the double quotes in the string:

或者在字符串中避免双引号:

echo "My name is:<b><i><div style=\"text-align:center;\">Karthic</div></i></b>";

This tells PHP to ignore them when parsing the code (and instead place them INSIDE the string itself).

这告诉PHP在解析代码时忽略它们(而不是将它们放在字符串本身中)。

#2


3  

Use single quotes when printing HTML

在打印HTML时使用单引号。

echo 'My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ';

Instead of

而不是

echo "My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ";

You were cutting off the HTML string, so it was erroring out.

你切断了HTML字符串,所以它是错误的。

#3


2  

you can't do

你不能做

echo "My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ";

because there is 2 double quote one after echo one after style

因为有2个双引号,一个接一个。

you should then do

你应该那么做

echo "My name is:<b><i><div style=\"text-align:center;\">Karthic</div></i></b> ";

but most of all of this ; you dont need to do echo for HTML code like this.

但大多数情况下;您不需要对这样的HTML代码进行echo。

Regards

问候

#4


1  

You will have to escape any double quotes that are contained within double quotes. You escape double quotes using the backslash character.

你必须避免双引号内包含的双引号。使用反斜杠字符来避免双引号。

<?php
echo "Do you like it?";
echo "<br>";
echo "My name is:<b><i><div style=\"text-align:center;\">Karthic</div></i></b> ";
?>

You should also put the bold and italic tags within the div instead of outside of it.

您还应该将粗体和斜体标记放在div中,而不是放在它的外部。