File index.php

Last commit: Mon Jun 27 00:41:50 2022 +0200	Jan Dankert	Fetched from upstream.
1 <?php 2 3 use dsl\executor\DslInterpreter; 4 5 require('./autoload.php'); 6 7 ?><html> 8 <head><title>Scriptbox</title> 9 <style> 10 textarea { 11 width: 100%; 12 height: 50%; 13 } 14 15 </style></head> 16 <body> 17 18 19 <h1>Scriptbox</h1> 20 <p>Scriptbox is a Script sandbox for PHP.</p><p>The syntax is a subset of Javascript.<br/> The interpreter is supporting functions, full arithmetic calculations, for-loops, if-else statements. 21 </p> 22 <?php $code = @$_POST['code'] ?: <<<DEF 23 // Script sandbox 24 // Feel free to write some code here.... 25 //write( "test" ); 26 27 /** 28 * functions without parameters 29 */ 30 function something() { 31 return "something"; 32 } 33 34 write( "I wrote " + something() + "\\n" ); 35 36 /** 37 * functions with parameters 38 */ 39 function sayName( name ) { 40 write( "your name is " + name + "\\n" ); 41 } 42 43 sayName("Alice"); 44 45 // Arithmetic magic 46 write( "Arithmetic magic: 1 + 2 * (3 + 2) = " ); 47 write( 1 + 2 * (3 + 2) ); 48 write( "\\n" ); 49 50 51 // lists... 52 names = Array.of("Alice","Bob",something() ); 53 54 for( name of names ) { 55 write( "A name: " + name + "\\n"); 56 57 // some condition... 58 if ( name == "Alice" ) 59 write( "Hello Alice, nice to meet you! "+"\\n"); 60 else 61 write( "Your are not Alice"+"\\n"); 62 } 63 DEF 64 ; ?> 65 66 <fieldset> 67 <legend>Output</legend> 68 <pre><?php 69 try { 70 error_reporting( E_ALL ); 71 $interpreter = new DslInterpreter( DslInterpreter::FLAG_SHOW_ERROR ); 72 $interpreter->runCode( $code ); 73 echo htmlentities( $interpreter->getOutput() ); 74 } catch( Exception $e ) { 75 // should never happen because the interpreter catches all. 76 echo "Unexcepted error while running the script: \n".htmlentities( $e->getMessage() )."\n"; 77 } 78 ?> 79 </pre> 80 </fieldset> 81 <fieldset> 82 <legend>Source</legend> 83 <form action="./" method="POST"> 84 <textarea name="code" rows="50" style="border:0;"><?php echo htmlentities( $code ) ?></textarea> 85 <input type="submit" value="Execute" /> 86 </form> 87 </fieldset> 88 89 </body></html>
Download index.php
History Mon, 27 Jun 2022 00:41:50 +0200 Jan Dankert Fetched from upstream. Sun, 26 Jun 2022 16:09:55 +0200 Jan Dankert More examples. Sun, 26 Jun 2022 16:04:19 +0200 Jan Dankert Fetched from upstream; More examples. Sun, 26 Jun 2022 15:47:05 +0200 Jan Dankert Fetched from upstream. Mon, 6 Jun 2022 14:06:46 +0200 Jan Dankert First commit after fetching from upstream repo.