Jump to content

I didnt understand ...???


qbox

Recommended Posts

Hi to all

This is my first post on this forum.

I have one php code before me and I cant figure out why there is used things like {SOME_TEXT} and how they work, how to define and stuff.

Here is example:

<div align="center">{_TOTAL_NUMBERS} <font class="red">

<input name="submit" type="submit" class="submit" value="{_BTN_GO}" />

......................

And this is used in .html file

There is a .php files but I cant figure out how this in {} worked.  ???

Thanks

Link to comment
Share on other sites

the {} let you add in variables inside there to echo out with the HTML

 

example:

<?php

$variable = "test";

echo <<<HTML

<div>
<p>This is a {$variable}</p>
</div>

HTML;

?>

 

and _TOTAL_NUMBERS must have been defined somewhere

 

example:

<?php

define("_TOTAL_NUMBERS", 28);

echo <<<HTML

<div>
<p>Your Total Number Is: {_TOTAL_NUMBERS}</p>
</div>

HTML;

?>

 

the define() function sets things just like variables do except its a constant

instead of a variable. read this:

 

http://php.net/define

Link to comment
Share on other sites

Hi to all

This is my first post on this forum.

I have one php code before me and I cant figure out why there is used things like {SOME_TEXT} and how they work, how to define and stuff.

Here is example:

<div align="center">{_TOTAL_NUMBERS} <font class="red">

<input name="submit" type="submit" class="submit" value="{_BTN_GO}" />

......................

And this is used in .html file

There is a .php files but I cant figure out how this in {} worked.  ???

Thanks

None of the code you have posted is actually php but likely a template file used by a php template engine to create html. Consider this very simple example.....

 

template.html

<html>
  <head>
    <title>{TITLE}</title>
  </head>
  <body>
    <h1>{HEADING}</h1>
    <p>{CONTENT}</p>
  </body>
</html>

 

engine.php

<?php

  $data = array('TITLE' => 'foo', 'HEADING' => 'this is foo', 'CONTENT' => 'this the story of foo');
  $template = file_get_contents('template.html');
  foreach ($data as $k => $v) {
    $template = str_replace('{' . $k . '}', $v, $template);
  }
  echo $template;

?>
  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.