{var} {str} in html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jkmcgrath
Forum Commoner
Posts: 33
Joined: Mon May 05, 2003 10:07 am

{var} {str} in html

Post 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>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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 "?>".
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post 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;

?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply