-5

How can i print variable in brackets? Like ip board, for example I have this code:

<?php
$variable = "test";
?>
<div class="test">{$variable}</div>

How can I do this? Not

echo $variable;?>

but {$variable} ! Thanks in advance :3

Dewagg
  • 145
  • 10

4 Answers4

3

It's called concatenation and it uses '.' to string things together...

<div class="test"><?php echo '{'.$variable.'}' ?></div>
Justin McKee
  • 156
  • 6
0

you can use it like this

<?= $variable ?>
0

yes, you can just do it like

<?php
    $variable = "test";
?>
<div class="test"><?= $variable; ?></div>

but if you want to use above approach(your one) you've to use blade templating engine

have a look

Mubin
  • 4,325
  • 5
  • 33
  • 55
0

Use a php templating engine. Best for you is that use Laravel and Balde

a45b
  • 489
  • 3
  • 19
  • yeah [someone said that here....](http://stackoverflow.com/questions/31764602/php-html-variable#comment51461364_31764631) – Funk Forty Niner Aug 01 '15 at 18:11
  • **or** create your own `templating system` http://code.tutsplus.com/tutorials/roll-your-own-templating-system-in-php--net-16596 – a45b Aug 01 '15 at 18:18