i have seen many scripts where you'll see something like this

<meta keyword="{keywords}" ...>


<input type="text" name="name" value="{name}">

what is this called and how can i do this myself.


No correct solution


It is called a template.

You need a template engine or you can write one yourself. A long time ago there was a popular template engine called Smarty. Today, template engines are part of most frameworks.

Here's a list of a few template engines for PHP:

Considering the fact that you have such a question, your very own template engine will more likely have bugs, so I suggest choosing one of the freely available ones.

One more thing. PHP itself is a kind of template engine, so you do not necessarily have to add another level of templating. Use PHP:

<input type="text" name="name" value="<?=$VALUES['name']?>">

can i recommend...

<input type="text" name="name" value="<?= e($name) ?>">

where e is an escaping function

i find template engines unnecessary

more examples...


<?php foreach( $items as $item ): ?>
    <li><?= e($item) ?><li>
<?php endforeach; ?>


<input type="checkbox"<?php if( $checkbox ): ?> selected="selected"<?php endif; ?>>

There are templating engines out there that support this style of variable syntax, for example Blitz templates ( comes to mind.

I am not sure what you mean, but let me take a wild guess:

$foo = "Please replace {this} here!";
$bar = str_replace('{this}', 'that', $foo);

Of course there are plenty of templating systems around that do exactly that, only much smarter. So you might wanna look into that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow