php variable?

by 7 replies
8
I have some php variables echo out to html page. The php page haves two php include files to. The variables are in a php code block like this <?php echo $variable ?>. How can i get it to echo to the page like this {variable} in the html/php page ?
#programming #php #variable
  • im not sure why you would want to call a variable in brackets.

    curly brackets are usually used like this:

    (variable name inside string)
    $str = "Hello ${username}!";

    and
    $number='2';
    ${'variablenumber'.$number} = 'something';

    is the same as
    $variablenumber2 = 'something';


    maybe I misunderstood your question.

    EDIT:
    Oh, i get it now.
    You're talking about template engines.
    search google for 'create a template engine in php'
  • [DELETED]
  • <?php echo "{" . $variable . "}"; ?>

    that will give you literally what you asked for, printing {variable}, with variable being the contents of "variable".

    peace
  • This is what i have.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta
    content="text/html; charset=ISO-8859-1"
    http-equiv="content-type">
    <title></title>
    </head>
    <body>

    <br>
    </body>
    </html>

    To this

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta
    content="text/html; charset=ISO-8859-1"
    http-equiv="content-type">
    <title></title>
    </head>
    <body>

    <br>
    </body>
    </html>
    • [1] reply

    • <?php echo $title; ?>
      <?php echo $body; ?>

      Do not add "variable" after the variable itself.
  • You want a template engine like Smarty: PHP Template Engine | Smarty
    • [1] reply
  • they look like smarty tags, as KirkMcd mentioned

Next Topics on Trending Feed

  • 8

    I have some php variables echo out to html page. The php page haves two php include files to. The variables are in a php code block like this <?php echo $variable ?>. How can i get it to echo to the page like this {variable} in the html/php page ?