加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index2.php 4.57 KB
一键复制 编辑 原始数据 按行查看 历史
宋正河 提交于 2019-10-11 15:57 . first commit
<?php
header("content-type:text/html;charset=utf-8");
error_reporting(E_ALL);
ini_set('display_errors',1);
set_time_limit(0);
date_default_timezone_set('Asia/Shanghai');
define('IS_AJAX', isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == 'xmlhttprequest');
if(IS_AJAX){
isset($_GET['action']) or $_GET['action']='';
switch($_GET['action']){
case 'run':
ob_start();
$code=$_POST['code'];
$code=str_replace('<?php','',$code);
$code=str_replace('?>','',$code);
eval($code);
$____result=ob_get_contents();
ob_end_clean();
echo json_encode(array('code'=>1,'result'=>$____result));
exit;
break;
case 'phpinfo':
ob_start();
phpinfo();
$result=ob_get_contents();
ob_end_clean();
echo json_encode(array('code'=>1,'result'=>$result));
exit;
break;
case 'source':
echo json_encode(array('code'=>1,'result'=>htmlspecialchars($_POST['result'],ENT_QUOTES,'UTF-8')));
exit;
break;
case 'fragment':
$result=file_get_contents('./fragment/'.$_POST['file']);
$result=trim($result);
echo json_encode(array('code'=>1,'result'=>$result));
exit;
break;
default:
echo json_encode(array('code'=>0,'result'=>''));
exit;
break;
}
}
$code=<<<'st'
st;
$fragments=array();
$dir='./fragment/';
if ($dh=opendir($dir)){
while(($file=readdir($dh))!==false) {
if($file=='.' || $file=='..') continue;
$fragments[]=$file;
}
closedir($dh);
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>php在线运行工具</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
</head>
<body>
<h2 style="text-align:center">php在线运行工具</h2>
<table width="100%" border="1">
<tbody>
<tr>
<td align="center">
<pre id="code" class="ace_editor" style="min-height:400px"></pre>
</td>
</tr>
<tr>
<td align="center">
<select name="fragment" id="fragment">
<option value="">代码片断</option>
<?php
foreach($fragments as $k=>$v){
?>
<option value="<?php echo $v;?>"><?php echo $k;?> : <?php echo $v;?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td align="center"><input type="button" value="运行" id="run" style="width:19%;height:100px;border:3px solid #E81D20;background:#12E76C;">&nbsp;<input type="button" value="清空" id="clear" style="width:19%;height:100px;border:3px solid #E90BE8;background:#E1C820;">&nbsp;<input type="button" value="phpinfo" id="phpinfo" style="width:19%;height:100px;border:3px solid #E90BE8;background:#074BD5;">&nbsp;<input type="button" value="格式化" id="format" style="width:19%;height:100px;border:3px solid #231A1A;background:#C429CD;">&nbsp;<input type="button" value="源代码" id="source" style="width:19%;height:100px;border:3px solid #0D66D0;background:green;"></td>
</tr>
<tr>
<td align="center"><div id="result" style="width:100%;height:400px;overflow:scroll;"></div></td>
</tr>
</tbody>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-language_tools.js"></script>
<script>
var editor = ace.edit('code');
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/php");
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
editor.setValue('<?php\necho "hello world!";');
</script>
<script src="js/jquery.js"></script>
<script>
$(document).ready(function(e) {
$('#fragment').change(function(){
var v=$(this).val();
if(!v){
editor.setValue('');
return;
}
$.post('?action=fragment',{file:v},function(data){
editor.setValue(data.result);
},'json');
});
$('#run').click(function(){
var code=editor.getValue();
if(!code) return;
$.post('?action=run',{code:code},function(data){
$('#result').html(data.result);
},'json');
});
$('#clear').click(function(){
if(!confirm('确定要清空么?')) return;
editor.setValue('');
$('#result').html('');
});
$('#phpinfo').click(function(){
$.post('?action=phpinfo',{code:''},function(data){
$('#result').html(data.result);
},'json');
});
$('#format').click(function(){
$('#result').html('<pre style="text-align:left;">'+$('#result').html()+'</pre>');
});
$('#source').click(function(){
var result=$('#result').html();
if(!result) return;
$.post('?action=source',{result:result},function(data){
$('#result').html(data.result);
},'json');
});
});
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化