7 replies
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 ?
#php #variable
  • Profile picture of the author hitmobi
    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'
    {{ DiscussionBoard.errors[4637758].message }}
  • Profile picture of the author imarketstuff
    <?php echo "{" . $variable . "}"; ?>

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

    peace
    Signature
    I MARKET STUFF

    {{ DiscussionBoard.errors[4638561].message }}
  • Profile picture of the author Travis Shelton
    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><?php echo $title variable ?></title>
    </head>
    <body>
    <?php echo $body variable ?>
    <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 variable}</title>
    </head>
    <body>
    {body variable}
    <br>
    </body>
    </html>
    {{ DiscussionBoard.errors[4638950].message }}
    • Profile picture of the author gauvion
      Originally Posted by Bigman252 View Post

      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><?php echo variable ?></title>
      </head>
      <body>
      <?php echo variable ?>
      <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 variable}</title>
      </head>
      <body>
      {body variable}
      <br>
      </body>
      </html>

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

      Do not add "variable" after the variable itself.
      {{ DiscussionBoard.errors[4640915].message }}
  • Profile picture of the author KirkMcD
    You want a template engine like Smarty: PHP Template Engine | Smarty
    {{ DiscussionBoard.errors[4639122].message }}
  • Profile picture of the author johnnyN
    they look like smarty tags, as KirkMcd mentioned
    {{ DiscussionBoard.errors[4641862].message }}

Trending Topics