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
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Thu Jun 26, 2003 8:59 pm
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.
Sevengraff
Forum Contributor
Posts: 232 Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:
Post
by Sevengraff » Thu Jun 26, 2003 9:19 pm
Are you talking about using {tag} in a template file, or using {$variable} in php?
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Thu Jun 26, 2003 9:23 pm
{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!
Sevengraff
Forum Contributor
Posts: 232 Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:
Post
by Sevengraff » Thu Jun 26, 2003 10:00 pm
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.
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Fri Jun 27, 2003 8:45 am
Hmm, I didn't know you could use {} in an echo, although many people (me included) prefer to do
, 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!
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Fri Jun 27, 2003 8:56 am
{} 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 ${$thisArrayї$i]}ї'thisKey'];
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Fri Jun 27, 2003 11:46 am
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.