Reputation:
Please check the code below:
<?php
$d=2;
echo "the sum of the number is"."<sub>($d+1)</sub>";
?>
Its giving as output:
the sum of the number is <sub>(2+1)</sub>
Ideally I need the output to be "the sum of the number is <sub>3</sub>"
.
It works fine when we don't use the HTML tags <sub>
...
How can I fix this?
Upvotes: 0
Views: 118
Reputation: 4340
try writing it as
<?php $d=2; echo "the sum of the number is"."<sub>".($d+1)."</sub>"; ?>
the quotes give it a string representation and thus not allowing you to perform addition.
Upvotes: 5
Reputation: 349082
Move the expression outside the quotes:
<?php
$d = 2;
echo "the sum of the number is <sub>" . ($d+1) . "</sub>";
?>
Upvotes: 3