I have a problem, I want to grab text and execute text as PHP, but how do I do this? For example I have this code in a .txt file:
$tweetcpitems->post('statuses/update', array('status' => wordFilter("The item Blue has been released on Club Penguin.")));
$tweetcpitems->post('statuses/update', array('status' => wordFilter("The item Green has been released on Club Penguin.")));
Now the problem is that I grabbed this text and I want to execute it as a PHP script, how do I do this? Please help!
Example #1 Execute PHP script as shell scriptThe PHP executable can be used to run PHP scripts absolutely independent of the web server. On Unix systems, the special #! (or "shebang") first line should be added to PHP scripts so that the system can automatically tell which program should run the script.
You can run PHP scripts in the Command Line for a particular PHP version used in Plesk.
eval(file_get_contents('yourfile.txt'));
BE CAREFUL!
http://php.net/manual/en/function.file-get-contents.php
http://php.net/manual/en/function.eval.php
You can run both text and eval from the same script but like previously mentioned. Security must be really tight. Nevertheless, the eval funtion is really powerful if you use it properly. Try the code below.
$b = 123;
$a = "hello <?php echo 'meeeee'; ?>. I just passed $b from the mother script. Now I will pass a value back to the mother script" . '<?php $c; $c = 1 + 8; ?>' .
"I was call within a function, therefore my variable can't passed to the global script. Nonetheless, let try something globally" .
"<?php
global \$d;
\$d = 'I am now a global var. Take care though, don\\'t let anyone edit your file' ;
";
function parseTxtAsCode($invalue){
if( !is_string($invalue) ) return false;
eval('?>' . $invalue);
echo "\n\n\n\n Can't believe I got this from my child: $c \n";
}
parseTxtAsCode($a);
echo "\n\n\n I am global and this is what I got from the eval function: $d";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With