echo '<?';
输出为空,考虑到可能是被php 解析了
但是我想实现的是textare 中 输入php 语句 直接返回 php 解析后的结果
用 eval 可以实现 但是 不能返回什么错误,
所以想通过写文件,读文件的方式来解决
有什么好的解决方式吗
<?php
if(empty($_REQUEST)){
$html = <<< EOF
<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js"></script>
<textarea id ="content" name="content" style="width: 100%;height: 300px" onkeydown="ctlSubmit(event)"></textarea>
<button id="button"> 提交</button>
<div id="eval"></div>
<script>
$("#button").click(
function(){
$("#eval").load('',{content:$("#content").val()});
}
);
//ctrl +回车
function ctlSubmit(event) {
if (event.ctrlKey && event.keyCode == 13) { $("#button").click() }
}
</script>
EOF;
echo $html;
}else{
$content = $_REQUEST['content'];
$content = preg_replace('/;/',';',$content);// 分号容易犯错
$string = addslashes($content);
// echo $string;
// echo '<br/>';
if(eval($string) === false){
echo '输入错误';
}
}
echo '<?'; 返回空 不是被PHP解析了 是被当成 HTML 标记了,你查看网页源代码看看……
你要输出带有 < > 等特殊符号的内容到网页上,要用 htmlspecialchars 函数进行处理的呀 …… 不是 addslashes , addslashes 是用来处理 SQL 过滤的……