Page 1 of 1

{something}

Posted: Thu Jun 26, 2003 8:59 pm
by evilmonkey
I came accross somethig like this bieng used in a few places:

Code: Select all

{something_in_here_that_looks_like_a_variable}
Could someone please tell me what that is and what it means? How the heck do I work with it if I want to change it's value? Is this even PHP? Thanks.

Cheers!

Jack.

Posted: Thu Jun 26, 2003 9:19 pm
by Sevengraff
Are you talking about using {tag} in a template file, or using {$variable} in php?

Posted: Thu Jun 26, 2003 9:23 pm
by evilmonkey
{tag} in a template (.tpl) file.

You can use {$variable} in PHP? What does this do? But my question is how to set the {tag} in a .tpl file.

Cheers!

Posted: Thu Jun 26, 2003 10:00 pm
by Sevengraff

Code: Select all

<?PHP
$name = "nick";
echo "Welcome to {$name}'s website";
?>
Using {} lets php know exactly where a variable starts and ends. You can also use it as ${name}, but most people code like this:

Code: Select all

<?PHP
$name = "nick";
echo "Welcome to " . $name . "'s website";
?>
As for how it is used in a template file, you will have to either use a pre-made template script (ETS, Smary) or make your own template system. Then you can parse a template file.

Posted: Fri Jun 27, 2003 8:45 am
by evilmonkey
Hmm, I didn't know you could use {} in an echo, although many people (me included) prefer to do

Code: Select all

echo " My name is ".$name." ..."
, the other way seems less complicated, I'll have to remeber it. A bummer with the templates though, I wanted to edit a little something in PHPBB2. :(

Cheers!

Posted: Fri Jun 27, 2003 8:56 am
by Wayne
{} do have there place, they make things alot easy to understand when going back and reading your code where you have things like variable variables.

ie

Code: Select all

echo $&#123;$thisArray&#1111;$i]&#125;&#1111;'thisKey'];

Posted: Fri Jun 27, 2003 11:46 am
by phice
A few more widely used examples:

Code: Select all

<?php
// Adding to another variable
$var2 = 452d;
$var{$var2} = 935;
// Would result in: $var452d = 935;

// Instead of using ". ."
echo "This is a simple {$variable} being used.";

// Also, my POST parser:
foreach($_POST as $key=>$value)
${$key} = $value;

?>
If there are any other uses, please add to mine.