Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\AppServ\www\text.php on line 11
Solution 1
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):
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).
Solution 2
Use single quotes when printing 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.
Solution 3
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.
Comments
-
karthic almost 2 years
I am new to PHP and have a question about it.
<?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
Lline 11 is
echo "My name is:<b><i><div style="text-align:center;">Karthic</div></i></b> ";
How can I fix this?
-
Austin over 11 yearsOr escape your
"
with slashes. -
Kyle Undefined over 11 yearsI think it's a matter of preference really, I like single quotes. Either way, both of our answers would do the job :)