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

How can I print $a's value inside echo?

George Irimiciuc
  • 4,573
  • 8
  • 44
  • 88

3 Answers3

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

Please read the difference between single and double quotes in PHP.

j08691
  • 204,283
  • 31
  • 260
  • 272
1
echo "<div id=\"content\">" . $a . ", but not sure how to do it </div>";

The \'s are escape sequences that allow you to have quotation marks within strings (otherwise they would terminate the string). The .'s are concatenation.

djbhindi
  • 364
  • 3
  • 13
0

there are many ways

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>'
Dimitri
  • 453
  • 3
  • 11