0

以下のコードを確認してください。

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

出力として与える:

the sum of the number is <sub>(2+1)</sub>

理想的には、出力を にする必要があります"the sum of the number is <sub>3</sub>"。HTMLタグを使用しない場合は問題なく動作します<sub>...

どうすればこれを修正できますか?

4

2 に答える 2

6

のように書いてみてください

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

引用符は文字列表現を与えるため、加算を実行できません。

于 2012-04-11T19:20:20.170 に答える
3

式を引用符の外に移動します。

<?php
   $d = 2;
   echo "the sum of the number is <sub>" . ($d+1) . "</sub>";
?>
于 2012-04-11T19:20:15.727 に答える