PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
enfys
Forum Newbie
Posts: 4 Joined: Thu Nov 18, 2004 4:32 am
Post
by enfys » Thu Nov 18, 2004 8:10 am
I need to execute some flow control but from within code that is embedded in quote marks e.g.
Code: Select all
<?php
$test = if($counter == 12) {
echo "Counter equals twelve";
}
$counter=12;
$test;
?>
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Thu Nov 18, 2004 8:20 am
Code: Select all
$code = '$counter = 12;';
eval($code);
echo $counter;
etc. Just eval() the code.
jl
Forum Commoner
Posts: 53 Joined: Tue Nov 09, 2004 12:05 am
Post
by jl » Sun Nov 21, 2004 12:47 am
would this work?
Code: Select all
$func="if (\$counter==12) { echo 'foo' ; }" ;
$counter=12 ;
eval($func) ;
Last edited by
jl on Sun Nov 21, 2004 1:28 am, edited 2 times in total.
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Sun Nov 21, 2004 12:55 am
No. [php_man]exec()[/php_man] is used to execute an external program. Check out the
php manual entry on exec() for more information.
potsed
Forum Commoner
Posts: 50 Joined: Sat Oct 09, 2004 12:00 pm
Location: - South Africa
Post
by potsed » Sun Nov 21, 2004 1:18 am
im not sure this is what your looking for
Code: Select all
function echoFoo($foo) {
echo $foo;
}
then call the function like
Code: Select all
$counter = 12;
$show = ($counter === 12) ? echoFoo($counter) : false;
jl
Forum Commoner
Posts: 53 Joined: Tue Nov 09, 2004 12:05 am
Post
by jl » Sun Nov 21, 2004 1:29 am
nigma wrote: No. [php_man]exec()[/php_man] is used to execute an external program. Check out the
php manual entry on exec() for more information.
Typo, clearly I meant eval()
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Sun Nov 21, 2004 1:33 am
jl wrote: nigma wrote: No. [php_man]exec()[/php_man] is used to execute an external program. Check out the
php manual entry on exec() for more information.
Typo, clearly I meant eval()
... Well how was I supposed to know