Forum Moderators: coopster

Message Too Old, No Replies

PHP Curly bracket output

         

Adamphp

8:42 pm on Feb 7, 2012 (gmt 0)

10+ Year Member



How to you output php in curly brackets on a html page instead off echo tags


I find this good for positioning php on a page

penders

10:05 pm on Feb 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you mean, "How do you write a templating system?" ...?

Adamphp

8:58 am on Feb 8, 2012 (gmt 0)

10+ Year Member



instaed of <php echo 'user_name'?> i can just use {User_name}

penders

10:00 am on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How to you output php in curly brackets


I assume you mean static text rather than PHP code itself?!

Basically you can't, there is nothing built in to PHP that does this. Unless you write some code that handles this for you (which is what a template engine is all about). Is this your intention?

For instance....

<?php 
$template = 'Hello {User_name}, welcome to {PLACE}.';
$templateVars = array (
'User_name' => 'Bob',
'PLACE' => 'the machine',
);
$htm = $template;
foreach ($templateVars as $name => $value) {
$htm = str_replace('{'.$name.'}',$value,$htm);
}
echo $htm;

The above outputs "Hello Bob, welcome to the machine."

Failing that, there is the short echo format...
<?='User_name'?>

Adamphp

3:05 pm on Feb 8, 2012 (gmt 0)

10+ Year Member



Basicly want why outputs set on the page

Price I want to output {car_price} make {car_make} etc etc

StoutFiles

3:28 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since you don't want to write your own template engine, just download the package. It will let you use variables the way you want.

[smarty.net...]

Adamphp

8:40 pm on Feb 8, 2012 (gmt 0)

10+ Year Member



what package?
yea i want to know how to code this myself