Reputation: 2044
I have added a line break in this piece of PHP code, but it's getting a syntax error. Does PHP not allow breaks in its code?
<!DOCTYPE>
<html>
<head>
</head>
<body>
</body>
<?php
define("Value_of_Pi", 3.14);
define ("Gravity_Value", 9.8);
echo "Pi value is".Value_of_Pi;
<br/>
echo "Gravity Value is".Gravity_Value;
?>
</html>
Upvotes: 0
Views: 201
Reputation: 3184
<br>
is html and must be echoed within php, like so:
<?php
define("Value_of_Pi", 3.14);
define ("Gravity_Value", 9.8);
echo "Pi value is".Value_of_Pi;
echo "<br/>";
echo "Gravity Value is".Gravity_Value;
?>
You can also use \r\n
in php like so:
echo "Pi value is".Value_of_Pi. "\r\n";
Upvotes: 0
Reputation: 196
You can use \r\n if you want to break line within php.
<?php
define("Value_of_Pi", 3.14);
define ("Gravity_Value", 9.8);
echo "Pi value is".Value_of_Pi. "\r\n";
echo "Gravity Value is".Gravity_Value;
?>
Upvotes: 2
Reputation: 417
You can use the code below instead:
echo '<br/>';
<br/>
is an HTML tag hence the syntax error you're getting.
Upvotes: 0
Reputation: 3497
You need to write echo '<br/>';
.
This is because you can either write HTML code or PHP within the specific sections.
You are currently in a PHP code section so you can only write PHP code there that will be valid.
<br/>
is not a valid PHP code but HTML. However, because you are within <?php ?>
it is not valid.
Upvotes: 0
Reputation: 311088
<br/>
is not valid PHP syntax. You could either have the <br/>
outside the PHP block:
<?php
define("Value_of_Pi", 3.14);
define ("Gravity_Value", 9.8);
echo "Pi value is".Value_of_Pi;
?>
<!-- PHP block terminated -->
<br/>
<!-- New PHP block opened: -->
<?PHP
echo "Gravity Value is".Gravity_Value;
?>
Or just echo it from PHP:
<?php
define("Value_of_Pi", 3.14);
define ("Gravity_Value", 9.8);
echo "Pi value is".Value_of_Pi;
echo "<br/>"; # Here!
echo "Gravity Value is".Gravity_Value;
?>
Upvotes: 1