-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
102 lines (94 loc) · 3.3 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Created by PhpStorm.
* User: Tim
* Date: 28-6-2015
* Time: 12:46
*/
//
//switch (strtoupper(substr(PHP_OS, 0, 3))) {
// // Windows
// case 'WIN':
// $linebreak = "\r\n";
// break;
//
// // Mac
// case 'DAR':
// $linebreak = "\r";
// break;
//
// // Unix
// default:
// $linebreak = "\n";
//}
//define('PHP_EOL', $linebreak);
//Handle the AJAX-call from button 'Run Again'
if (isset ( $_GET ["codeJSON"] )){
$code = $_GET ["codeJSON"];
ob_start();
eval($code);
$generated_html = ob_get_contents();
ob_end_clean();
echo $generated_html;
return;
}
function showcodeEchoEachLinesResult($code){
$lines = explode("\n",$code);
foreach ($lines as $line) {
$posIs = strpos('=',$line);
$var = substr($line, 1, $posIs - 1);
$result = eval($line);
echo '$' . $var. ' = ' . $result . '\n';
}
}
function showcode($code, $lines = null, $echoeachline = false){
$stringarray = explode("\n",$code);
if($lines!==NULL){
$numoflines = $lines;
}else {
$numoflines = min(20, max(3, count($stringarray)));
}
$numofcolumnssource = 65;
$numofcolumnsresult = 65;
$id = (int)microtime(true)*rand(0,100000);
//$bgcolor = dechex(rand(190,256)*256*256 + rand(190,256)*256 + rand(190,256));
$bgcolor = "496d89";
echo '<div style="background-color: #' . $bgcolor . '; padding:5px;">';
// echo '<label for="source'.$id.'" rows="'.$numoflines .'">Sourcecode:</label>';
echo '<textarea id="source'.$id.'" rows="'.$numoflines .'" cols="' . $numofcolumnssource . '">'.$code.'</textarea>';
echo '<div style="display:inline-block;vertical-align: top;"><input title="Using eval(<code>) this evaluates to:" type="button" value=">>" style="height:40px;" onclick="EvaluateAgain(\''.$id.'\')" style="height:20px;"/></div>';
echo '<textarea id="result'.$id.'" rows="'.$numoflines .'" cols="' . $numofcolumnsresult . '">';
if ($echoeachline) {
foreach ($stringarray as $line) {
$posIs = strpos($line,'=');
$var = substr($line, 1, $posIs - 2);
$line = $line . 'echo $$var;';
echo '$' . $var. ' = ';
eval($line);
echo ";\n";
}
}else{
eval($code);
}
echo '</textarea>';
echo '<br/>';
echo '</div>';
}
function showXMLdoc($code){
$stringarray = explode("\n",$code);
$numoflines = min(20, max(3, count($stringarray)));
$numofcolumnssource = 60;
$numofcolumnsresult = 80;
$id = microtime(true)*rand();
$bgcolor = dechex(rand(190,256)*256*256 + rand(190,256)*256 + rand(190,256));
echo '<div style="background-color: #' . $bgcolor . '; padding:5px;">';
// echo '<label for="source'.$id.'" rows="'.$numoflines .'">Sourcecode:</label>';
echo '<textarea id="source'.$id.'" rows="'.$numoflines .'" cols="' . $numofcolumnssource . '">'.$code.'</textarea>';
echo '<div style="display:inline-block;vertical-align: top;"><input type="button" value="> Evaluates to >" onclick="EvaluateAgain(\''.$id.'\')" style="height:20px;"/></div>';
echo '<textarea id="result'.$id.'" rows="'.$numoflines .'" cols="' . $numofcolumnsresult . '">';
$xml = new SimpleXMLElement($code);
print_r($xml);
echo '</textarea>';
echo '<br/>';
echo '</div>';
}