Page 1 of 1

{var} {str} in html

Posted: Wed Sep 03, 2003 1:21 pm
by jkmcgrath
I read some where once upon a time that you can put your variables and strings in curly bracees in your html code and they will print out with out using echo. I am unable to find that source again.

Can anyone help me on this? Is the below example correct or what am I missing.

Thanks
John


ex save below code as john.htm or php?

Code: Select all

<?php

$strName = "John";

<?

<html><head><title></title></head><body>
<p>&#123;$strName&#125;</p>
</body></html>

Posted: Wed Sep 03, 2003 2:29 pm
by DuFF
I have never heard of that before but I doubt it could be true. I have heard you can have HTML processed by PHP if you add something to a file (httpd.conf or something?) so that might be how you do it. But you do use PHP at the top of the script anyway so why not name it john.php??

BTW, you never ended the PHP at the top. You should replace "<?" with "?>".

Posted: Wed Sep 03, 2003 6:10 pm
by Bennettman
A similar method to the one you're describing (I haven't heard of that either >_>), feel free to replace print with echo and someword with any word you like:

Code: Select all

<?php

$strname = "John";

print <<<someword

<html><head><title></title></head><body> 
<p>$strName</p> 
</body></html> 

someword;

?>

Posted: Wed Sep 03, 2003 6:14 pm
by McGruff
Template engines sometimes use curly braces to denote dynamic content. A bunch of vars are passed to the parsing engine which then looks for delineated { values } in the static content and then echo's out vars of the same name.