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? Link to comment https://forums.phpfreaks.com/topic/47113-combining-_get-and-a-vaiable/ 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 ?> Link to comment https://forums.phpfreaks.com/topic/47113-combining-_get-and-a-vaiable/#findComment-229737 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. Link to comment https://forums.phpfreaks.com/topic/47113-combining-_get-and-a-vaiable/#findComment-229743 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. Link to comment https://forums.phpfreaks.com/topic/47113-combining-_get-and-a-vaiable/#findComment-229769 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'] . ";"); ?> Link to comment https://forums.phpfreaks.com/topic/47113-combining-_get-and-a-vaiable/#findComment-229779 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. Link to comment https://forums.phpfreaks.com/topic/47113-combining-_get-and-a-vaiable/#findComment-229790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.