在线运行php画图,PHP 写的代码在线运行工具

706c1cacd45b5b86c9520ecdc260718a.png

de27a6221ff156d9d17278f9721ea49d.png

由于权限问题,编译 c 语言要 root 权限,这名改成你自己的root密码    echo 'root' | sudo

/**

author:zbseoag

仅限于本地使用,不要放在服务器上

因为没有任何安全过滤.

而且还能执行 php 代码.

**/

error_reporting(E_ALL);

date_default_timezone_set('Asia/Shanghai');

if(!empty($_REQUEST)){

echo '

*{padding:0; margin: 0; font:14px "微软雅黑";}

table{ border-collapse: collapse; }

tr{ border: 1px solid #CCC; }

td, th{ border: 1px solid #CCC; }

';

$action = $_REQUEST['action'];

$data = $_REQUEST['data'];

$tool = new Tool($data);

if(method_exists($tool, $action)){

$tool->$action();

}else{

$tool->output = '未定义的工具: ' . $action;

}

exit;

}

?>

我的工具包

*{padding:0; margin: 0; font:14px "微软雅黑";}

html,body{ width:100%;}

button{padding:4px 10px;}

.button {padding:4px 10px; min-width: 110px; margin:4px 0; }

li{ margin-bottom: 10px;}

C 语言

PHP 语言

Python 语言

function codefile(){

document.getElementById('codefile').setAttribute('href', '?action=look&data=' + localStorage.getItem('codefile'));

return true;

}

var buttons = document.getElementsByClassName('button');

for(var i in buttons){

buttons[i].onclick = function(){

var form = document.getElementById('form');

var index = 0;

if(this.hasAttribute('data-switch-value')){

var switch_value = this.getAttribute('data-switch-value').split('|');

for(var i in switch_value){

if(this.value == switch_value[i]){

if(i == switch_value.length - 1) break;

index = ++i; break;

}

}

this.value = switch_value[index];

}

document.getElementById('action').setAttribute('value', this.getAttribute('value'));

form.submit();

}

}

class Tool{

public $file = '';

public $output = null;

public $data = '';

public $command = '';

public function __construct($data){

$this->file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'index';

$this->data = trim($data);

}

public function save(){

file_put_contents($this->file, $this->data, LOCK_EX);

}

public static function p($args){

call_user_func_array(array('Debug', 'p'), func_get_args());

}

public function __destruct(){

if($this->command){

$this->output = shell_exec($this->command . ' 2>&1');

$this->output = preg_replace('/\[sudo\].*:\s+/', '', $this->output);

}

echo "";

self::p(htmlspecialchars($this->output, ENT_NOQUOTES));

}

public function exec_c(){

$this->file = $this->file . '.c';

$include = "#include \n#include \n";

$pattern = '/(\s*#\w+\s+.*\n)+/';

if(!preg_match('/(int|void)\s+main\(.*\)\s*\{/', $this->data)){

preg_match_all($pattern, $this->data, $out);

if(isset($out[0][0])) $include .= $out[0][0];

$this->data = $include . "int main(){\n\t" .preg_replace($pattern, '', $this->data) . "\n\n}";

}else{

$this->data = $include . $this->data;

}

$this->save();

$this->command = "echo 'root' | sudo -S gcc -o $this->file.out $this->file 2>&1 && $this->file.out";

}

public function exec_php(){

if(substr($this->data, 0, 5) != '<?php ') $this->data = "<?php \n\n" . $this->data;

$this->file = $this->file . '.php';

$this->save();

$this->command = "php $this->file";

}

public function exec_python(){

$this->file = $this->file . '.py';

$this->save();

$this->command = "python3.8 $this->file";

}

public function look(){

$this->file = $this->data;

$this->output = file_get_contents($this->file);

}

}

?>

依赖文件: Debug.php

/**

+------------------------------------------------------------+

代码调试方便打印数据,包含:对象,类名,函数,数组,字符串,null bool

可一次批量打印多个变量

不方便打印的,还可以写日志(/sys_temp_dir/debug.txt)

@author: 相望成伤(zbseoag)

Debug::p(1,2,3);

打印并退出

Debug::stop(1,2,3);

//输出返回结果

echo Debug::v(1,2,3);

//写日志

Debug::log(1, 2, 3);

+------------------------------------------------------------+

*/

class Debug {

//日志文件

public static $file = '';

/**

* 设置日志文件路径

* @param string $file

* @return mixed|string

*/

public static function file($file = ''){

self::$file = empty($file)? sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'debug.txt' : str_replace('\\', DIRECTORY_SEPARATOR, $file);

return self::$file;

}

/**

* 格式化数据

* @param $data

* @return string

*/

public static function format($data){

if(in_array($data, array('TRUE','true', 'false', 'FALSE', 'null', 'NULL'), true )) $data = "\"$data\"";

if(is_bool($data)) $data = $data? 'true' : 'false';

if(is_null($data)) $data = 'null';

if($data === '') $data = '""';

//thinphp 支持

if(is_array($data) && current($data) instanceof \think\Model){ $data = collection($data)->toArray();}

if(is_string($data)) $data = self::unicode($data);

$output = array();

if(is_string($data) && function_exists($data)){

$object = new \ReflectionFunction($data);

$output = array('Function-Name' => $data, 'Function-Namespace' => $object->getNamespaceName(), 'Function-File' => $object->getFilename());

}

if(is_object($data) || (is_string($data) && class_exists($data, false))){

$message = '';

if(is_object($data)){

if($data instanceof \Exception){

$file = $data->getFile() . ' (' .$data->getLine() .')';

$message = $data->getMessage() . ' (' .$data->getCode() .')';

}

$name = get_class($data);

$fields = get_object_vars($data);

}else{

$name = $data;

$fields = get_class_vars($data);

}

$methods = get_class_methods($data);

$object = new \ReflectionClass($data);

if(!isset($file)) $file = $object->getFilename();

$output += array('Class-Name' => $name, 'Class-Namespace' => $object->getNamespaceName(), 'Class-Exception' => $message, 'Class-File' => $file, 'Class-Attr' => $fields, 'Class-Method' => $methods);

}

return empty($output)? $data : $output;

}

/**

* 打印当前输入数据

*

*/

public static function input(){

self::p('$GLOBALS:', $GLOBALS);

self::p('php://input:', file_get_contents('php://input'));

}

/**

* unicode 解码

* @param $string

* @return string|string[]|null

*/

public static function unicode($string) {

return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($match){

return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');

}, $string);

}

/**

* 返回格式化后的内容

* $args 参数列表

*/

public static function v(){

$args = func_get_args();

$count = func_num_args();

if($count == 0) $args = array();

$cli = PHP_SAPI == 'cli'? true : false;

$output = $cli? '' : '

' ;

foreach($args as $key => $data){

$data = self::format($data);

$output .= print_r($data, true);

if($key < $count - 1) $output .= $cli? PHP_EOL."--------------------------------------------------------".PHP_EOL : '


';

}

$output .= $cli? PHP_EOL : '

';

return $output;

}

/**

* 打印数据

* $args 参数列表

*/

public static function p(){

echo call_user_func_array(array('Debug', 'v'), func_get_args());

}

/**

* 打印并退出

* $args 参数列表

*/

public static function stop(){

call_user_func_array(array('Debug', 'p'), func_get_args());

exit;

}

/**

* 浏览器控制台打印数据

*/

public static function console(){

$output = '';

$args = func_get_args();

foreach($args as $key => $data) $output .= self::format($data);

echo '

echo preg_replace('/\r|\n/', '', $output);

echo '")';

}

/**

* 写入格式化的日志内容

*/

public static function log($args = ''){

$args = func_get_args();

$count = func_num_args();

self::file();

foreach($args as $key => $data){

$data = self::format($data);

if(!is_string($data)){

$data = var_export($data, true);

$data = preg_replace(array('/(=>)(\s+)\n\s+(array)/'), array('\1\2\3'), $data);

}

file_put_contents(self::$file, $data, FILE_APPEND | LOCK_EX);

if($key < $count - 1) file_put_contents(self::$file, "\n----------------------------------------------------------------------------\n", FILE_APPEND | LOCK_EX);

}

file_put_contents(self::$file, "\n==================================================[time ".date('Y-m-d H:i:s')."]==================================================\n", FILE_APPEND | LOCK_EX);

}

/**

* 写文件

*/

public static function write($args = ''){

$args = func_get_args();

if(empty(self::$file)) self::file();

foreach($args as $key => $data){

file_put_contents(self::$file, (is_string($data)? $data : var_export($data, true)), FILE_APPEND | LOCK_EX);

}

}

/**

* 读取文件内容

*/

public static function read($file = ''){

if(empty($file)) $file = self::$file;

self::p('调试文件:', file_get_contents($file));

}

/**

* 清空日志文件

*/

public static function clear(){

self::file();

file_put_contents(self::$file, '',LOCK_EX);

}

}

//快捷函数

if(!function_exists('v')){

function v(){

return call_user_func_array(array('Debug', 'v'), func_get_args());

}

}

if(!function_exists('p')){

function p(){

call_user_func_array(array('Debug', 'p'), func_get_args());

}

}

if(!function_exists('stop')){

function stop(){

return call_user_func_array(array('Debug', 'stop'), func_get_args());

}

}

添加到短语集

没有此单词集: → 中文(简体)...

创建新的单词集...

拷贝

添加到短语集

没有此单词集: → 中文(简体)...

创建新的单词集...

拷贝

标签:function,在线,代码,args,file,output,array,PHP,data

来源: https://www.cnblogs.com/zbseoag/p/14224686.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值