如何以PHP的形式执行文本

如何以PHP的形式执行文本,php,scripting,execute,Php,Scripting,Execute,我有一个问题,我想抓取文本并以PHP的形式执行文本,但是我该怎么做呢?例如,我在.txt文件中有以下代码: $tweetcpitems->post('statuses/update', array('status' => wordFilter("The item Blue has been released on Club Penguin."))); $tweetcpitems->post('statuses/update', array('status

我有一个问题,我想抓取文本并以PHP的形式执行文本,但是我该怎么做呢?例如,我在.txt文件中有以下代码:

$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.")));
现在的问题是,我抓取了这个文本,我想把它作为一个PHP脚本来执行,我该怎么做?请帮忙

eval(file_get_contents('yourfile.txt'));
小心


您可以使用PHP评估文本;但是,请阅读下面一条非常重要的免责声明

eval()语言构造非常危险,因为它允许执行任意PHP代码。因此,不鼓励使用它。如果您已经仔细验证了除了使用此构造之外没有其他选择,请特别注意,在未事先正确验证的情况下,不要将任何用户提供的数据传递到该构造中


您可以从同一个脚本运行text和eval,但与前面提到的一样。保安一定很严密。然而,如果你使用得当,评估功能是非常强大的。请尝试下面的代码

$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";
$b=123;
$a=“您好。我刚刚从母脚本传递了$b。现在我将向母脚本传递一个值”。”。
“我是在一个函数中调用的,因此我的变量无法传递给全局脚本。尽管如此,还是让我们全局地尝试一下。”。
“您可以使用include()或require()函数:

include(/your\u text\u file.txt);
//或

require(/your_text_file.txt);
我希望您知道,如果您使用用户输入进行操作,这是一种被黑客攻击的邀请?如果您询问如何使用
eval
,您绝对不应该使用
eval
。请注意:
eval()
+
file\u get\u contents()
本质上与
包含
相同。如果要这样做,不妨添加

$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";