Home » Category » PHP

PHP: execute variable PHP

216| Wed, 14 Nov 2007 01:21:00 GMT| anon| Comments (4)
hi ...
I have a problem :
I have a variable like this :
<?
$a =
"
for ($i=0; $i<3; $i++) {
print $i;
}
";
?>
how to execute the $a variable to get result "012"
OK thank's before.

Keywords & Tags: execute, variable, php

URL: http://programming.itags.org/php/102823/
 
«« Prev - Next »» 4 helpful answers below.
I dont think you can assign a loop to a variable but i understand what you want try this instead -

<?

for ($i=0; $i<3; $i++) {
print $i;

$a .= "$i";

}

?>

This will concaterate the $i with all into the variable $a. in other words adding the value of $i to the end of string $a wach time through the loop so when you then print $a you should get "012"

anon | Fri, 16 Nov 2007 01:11:00 GMT |

Thank u for the answer, but i think that the answer is not what i want.

I mean, is there any function that execute variable?

I\'ve tried add into the function and it is work. But I don\'t know is there an chance to execute this variable.

i will give a simple example :

<?

$b =

\"

for ($i=0; $i<3; $i++) {

print $i;

}

\";

$a = \"this is a #vol\";

$a = ereg_replace(\"#vol\",$b,$a);

?>

and my question :

what is a command that can execute $a and give me a result like this

\"this is a 012\"

thanks\' before.

anon | Fri, 16 Nov 2007 01:12:00 GMT |

The eval() function can 'evaluate' php code as if it where inside your script.

anon | Fri, 16 Nov 2007 01:13:00 GMT |

and I've never seen a real reason why anyone'd ever need to use it :)

anon | Fri, 16 Nov 2007 01:14:00 GMT |

PHP Hot Answers

PHP New questions

PHP Related Categories