在html代码中打印变量

时间:2014-06-05 20:44:21

标签: php html echo

$a="something";
echo ' <div id="content">$a, but not sure how to do it</div>'

如何在echo中打印$a的值?

3 个答案:

答案 0 :(得分:2)

echo " <div id=\"content\">$a, but not sure how to do it</div>";

请阅读PHP中single and double quotes之间的区别。

答案 1 :(得分:1)

echo "<div id=\"content\">" . $a . ", but not sure how to do it </div>";

它是转义序列,允许您在字符串中使用引号(否则它们将终止字符串)。 。是串联。

答案 2 :(得分:0)

有很多方法

1) use " instead of '

echo " <div id='content'>$a, but not sure how to do it</div>"

2) use {} with " if you are want to print something complex and want your editor to format it correctly. most of the time i use it with arrays or when calling a function ex. {$arr['a']} instead of $arr['a'].

 echo " <div id='content'>{$a}, but not sure how to do it</div>"

3) just do this 

echo ' <div id="content">' . $a . ', but not sure how to do it</div>'