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?

1

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

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

Comments

0

Use a PHP templating language like Mustache or Smarty.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.