0

In my website I have certain preset variables such as the page title, year/time, and etc.

For example in my title I would use

<title> <?php echo $TITLE; ?> </title>

However, how would I make it so typing something like..

<title> [TITLE] </title>

Will produce the same result?

tshepang
  • 12,111
  • 21
  • 91
  • 136
InVert
  • 53
  • 5
  • possible duplicate of [Search for \[ \] and replace everything between it](http://stackoverflow.com/questions/6473945/search-for-and-replace-everything-between-it) – mario Jan 08 '12 at 19:06

4 Answers4

1

It's recommended that you use the PHP tags for many reasons, including performance and stability. If you want to do less typing you could use the shorthand for echoing variables: <?= $TITLE ?>.

If you're using a PHP version prior to 5.4 you might have to enable short_open_tags in your configuration. After version 5.4 these tags are always available

If you're dead set on using a different syntax for your HTML, you could look into a templating language like Smarty or Dwoo

Hubro
  • 56,214
  • 69
  • 228
  • 381
0
$page = str_replace('[TITLE]', $title, $page);

Replace $page with your variable. Obviously then you'd have to echo out $page to get it to show.

Cyclone
  • 17,939
  • 45
  • 124
  • 193
0

That effect can be accomplished with template tags in a template engine such as Smarty.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
0

Use a PHP templating language like Mustache or Smarty.

PHP vs template engine might point you towards some other options.

Community
  • 1
  • 1
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245