b1011 Posted April 15, 2007 Share Posted April 15, 2007 Hey guys, im pretty new here, yet im pretty good at php. i decided to register for help with my only question: How do you combine $_GET[]; with a variable. pretend you have a URL: www.url.com/index.php?ID=5 and you had a variable on that page called "$topic"("hello"). how would you combine it into one string or variable that is "$topic" and $_GET['ID']? combining the examples above out output a variable : "hello5" correct? but is this even possible? Quote Link to comment Share on other sites More sharing options...
mendoz Posted April 15, 2007 Share Posted April 15, 2007 Maybe this <?php $id=$_GET['id']; // $id=5 $var='hello'; // $var=hello $newvar=$var.$id; // $newvar=hello5 ?> Quote Link to comment Share on other sites More sharing options...
b1011 Posted April 15, 2007 Author Share Posted April 15, 2007 i shuld have been more spacific..its more complicated that that. im pulling a variable from a txt i need to execute. Quote Link to comment Share on other sites More sharing options...
xenophobia Posted April 15, 2007 Share Posted April 15, 2007 Do you mean this: $myvar = "abc'; $getvar = $_GET['ID']; //if $getvar = "1" //Then you want to declare a variable $abc1 ? eval("\$" . $myvar . $getvar . ";"); visit: http://my2.php.net/manual/en/function.eval.php for eval() function details. Hope this help you. Quote Link to comment Share on other sites More sharing options...
ignace Posted April 15, 2007 Share Posted April 15, 2007 <?PHP // $hello5 ${$topic}{$_GET['ID']}; // or the eval() way eval("\$" . $topic . $_GET['id'] . ";"); ?> Quote Link to comment Share on other sites More sharing options...
xenophobia Posted April 15, 2007 Share Posted April 15, 2007 <?PHP ${$topic}{$_GET['ID']}; ?> ignace, may I know what kind of method is this? Does it have a name? I seems many open sources program used this for parsing data into the HTML templates. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.