0

I wonderd if theres a way you can do this ive seen it on some other php scripting where you do a variable like below

<?php //variable as {name} $name = "Jake"; ?> 

and you can show it by typing {name} or something like that if you include the file with php?

4
  • php.net/manual/en/… Commented Sep 26, 2013 at 16:53
  • It's common for templating engines. Smarty, for example, will replace instances of {variable} if it corresponds to a variable set in the controller. But you have to either use an existing engine or write it yourself. It's not terribly complicated though Commented Sep 26, 2013 at 16:53
  • 1
    are you talking about templating, or are you referring to the way PHP interpolates complex variables in double-quoted strings (e.g. echo "my object property is {$obj->prop}";)? Commented Sep 26, 2013 at 16:56
  • Im new to php and not sure what i mean, i just seen it and thoughtit was cool, im sue its called template engine ill look up a tutorial on it thanks for the ideas Commented Sep 26, 2013 at 16:59

1 Answer 1

1

Smarty Templates is good, but if you don't want to worry about including 3rd party libraries, and you are in control of your php.ini settings (to enable the short_open_tags directive), you can use short tags to do stuff like:

<p>Here's some html... hello <?= $dynamicName; ?>, how are you today?</p>

or

<? foreach($someArray as $val) : ?>
    <div><?= $val; ?></div>
<? endforeach; ?>
Sign up to request clarification or add additional context in comments.

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.