user1178070
user1178070

Reputation:

Simple php .. not working...hmm Looks very simple

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

Answers (2)

Anurag Ramdasan
Anurag Ramdasan

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

Rob W
Rob W

Reputation: 349082

Move the expression outside the quotes:

<?php
   $d = 2;
   echo "the sum of the number is <sub>" . ($d+1) . "</sub>";
?>

Upvotes: 3

Related Questions