{something}

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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

{something}

Post 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.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

Are you talking about using {tag} in a template file, or using {$variable} in php?
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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!
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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!
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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'];
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

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