如何将php
块放入变量中?以下代码无效:
$test = "
<?php
session_start();
$test = 'test';
$_SESSION['test'] = $test;
header("Refresh: 0;url=/");
?>
";
答案 0 :(得分:5)
由于您使用双引号进行赋值,因此正在解释内部数据。使用单引号。
$test = '<?php
session_start();
$test = "test";
$_SESSION["test"] = $test;
header("Refresh: 0;url=/");
?>';
echo $test;
输出:
<?php
session_start();
$test = "test";
$_SESSION["test"] = $test;
header("Refresh: 0;url=/");
?>