soycharliente Posted July 27, 2007 Share Posted July 27, 2007 What does {} do when you enclose variables in it? I see it all the time and I suck at using Google. Examples I've seen: {$var} {$foo['bar']} Link to comment https://forums.phpfreaks.com/topic/62034-solved-using/ Share on other sites More sharing options...
grimmier Posted July 27, 2007 Share Posted July 27, 2007 you use the curly brackets when you want to plug variable data into a Double quoted string. example <?php $var = 'something'; echo "this is {$var} about Mary"; //prints "this is something about Mary ?> more commonly you will see this when you are constructing SQL queries, ie "SELECT * from DB where `this` = '{$var}' "; Link to comment https://forums.phpfreaks.com/topic/62034-solved-using/#findComment-308843 Share on other sites More sharing options...
Crow Posted July 27, 2007 Share Posted July 27, 2007 Basically, it means 'Evaluate whatever is in the Curly Brace'. Example: Say you wanted to create a dynamic variable..or something. <?php $user = 'Crow'; ${u . $user} = 'Somevalue'; ?> That would create the variable $uCrow with the value Somevalue. (To the above poster, you don't need to use {} to insert variable data into a double-quoted string, that's done automatically.) Link to comment https://forums.phpfreaks.com/topic/62034-solved-using/#findComment-308845 Share on other sites More sharing options...
almightyegg Posted July 27, 2007 Share Posted July 27, 2007 When using a query like: $meh = mysql_query("SELECT * FROM table WHERE col = '$variable['variable']'") or die(mysql_error()); the {}s are needed around the $variable['variable'] so it is executed without errors. It should be: $meh = mysql_query("SELECT * FROM table WHERE col = '{$variable['variable']}'") or die(mysql_error()); There are other ways of doing it but I like this way. NB. It's only necessary when it is a variable like $variable['variable'], not when it is just $variable. Link to comment https://forums.phpfreaks.com/topic/62034-solved-using/#findComment-308848 Share on other sites More sharing options...
soycharliente Posted July 27, 2007 Author Share Posted July 27, 2007 tHANKS GUYS. Link to comment https://forums.phpfreaks.com/topic/62034-solved-using/#findComment-308852 Share on other sites More sharing options...
ignace Posted July 27, 2007 Share Posted July 27, 2007 you should be using sprintf() especially when using queries, also *_real_escape_string() is recommended or something along those lines like addslashes() Link to comment https://forums.phpfreaks.com/topic/62034-solved-using/#findComment-308855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.