我想做的很简单,但似乎不起作用。
在这个主页中,我试图从另一个页面插入一段代码,就像这样。
<?php
include_once $_SERVER['DOCUMENT_ROOT'].'\attach\common.php';
$clear = False;
echo $code;
if($clear){
echo 'Clear was cleared';
}
?>
这是common.php
<?php
$code = "if(isset($_GET['n'],$_GET['c'])) {";
$code .=" echo 'Name and Country were set <br />';";
$code .=" $clear = True;";
$code .="} else {";
$code .=" echo 'An error occured <br />';";
$code .="}";
?>
我怎样才能在 php 中做到这一点?
更新
<?php
include_once $_SERVER['DOCUMENT_ROOT'].'\attach\common.php';
$clear = False;
d();
if($clear){
echo 'Clear was cleared';
}
?>
<?php
function d() {
if(isset($_GET['n'],$_GET['c'])) {
echo 'Name and Country were set';
$clear = True;
} else {
echo 'An error occured <br />';
}
}
?>