• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

how to?

ozefrog

Active Member
just wondering how i would include an existing varible into a new one

for example if $var = "1"

how would it include the 1 in the middle of a new variable for instance if the variable was something like $some1thing and the '1' was where the $var was.

so if $var = "2", the new variable would be $some2thing

like how would i echo that new variable, <? echo some.$var.thing ?>

(also the words some and thing in the new variable should just b regular text, not additional variables)

thanks in advance
 
Last edited:
you mean??

Code:
#!/usr/bin/perl
use strict;

my $variable = 1;

print "Content-Type: text/html\n\n";

print "Some" . $variable . "Thing";


__END__
 
Originally posted by YUPAPA
you mean??

Code:
#!/usr/bin/perl
use strict;

my $variable = 1;

print "Content-Type: text/html\n\n";

print "Some" . $variable . "Thing";


__END__


no i meant so it works something like $some$var$thing all as the one variable, and that variable has a value.
 
Originally posted by ozefrog
no i meant so it works something like $some$var$thing all as the one variable, and that variable has a value.

Code:
#!/usr/bin/perl
use strict;

my $variable = 1;
my $some = 'some';
my $thing = 'thing';
my $all_has_one_variable = $some . $variable . $thing;

print "Content-Type: text/html\n\n";

print $all_has_one_variable;


__END__

:confused:
 
Originally posted by Canuckkev
It is possible. http://www.php.net/manual/en/language.variables.variable.php

But you could also just use an array (most of the time). I suppose there are a few times when variable variables come in handy.

see the script im trying to make has the following line in the form:

<input type="radio" name="question<? echo $myrow["id"] ?>" value="1" style="background: #008ACC;">

if the $myrow["id"] was equal to 1 then the name of that input field would be 'question1'

when that form sends the info to the next script, how would i get it to echo that in a new variable, so if the $myrow["id"] value was 2, i wouldnt have to do the following:

<? echo $question1; echo $question2; ?>

and instead, do something like...

<? echo $"question".$myrow["id"] ?> (i no that aint a valid piece of code) so its echo'ing $question1 or $question2 as the variable.

i had a read of that page at php.net but i didnt quite understand it.

from wat i can understand it would be:

$question{"question".$myrow["id"]}; <- am i rite?
 
I might be missing the point so bare with me. How about this:
PHP:
<input type="radio" name="question[<? echo $myrow["id"] ?>]" value="1" style="background: #008ACC;">
{/PHP]
and then on the receiving end:
[PHP]
<?
foreach($question as $value) {
echo $value;
}
?>
If you needed the $question index:
PHP:
<?
foreach($question as $id => $value)
?>
tell me if this helps and we can work from there
 
that wouldnt really work spec from wat i can tell?

this is really hard to explain how im trying to do it...

if you think you can help, please let me know and ill email the script to u.
 
i re-read through the stuff at php.net and found out how to do it. so that problem is solved...


thanks for ya help
 
Back
Top