JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.guru99.com/Sanjay/PhpEditor/codemirror.js"></script>
<link rel="stylesheet" href="http://code.guru99.com/Sanjay/PhpEditor/codemirror.css">
<script src="http://code.guru99.com/Sanjay/PhpEditor/clike.js"></script>
<script src="http://code.guru99.com/Sanjay/PhpEditor/php.js"></script>
<script src="http://code.guru99.com/Sanjay/PhpEditor/css.js"></script>
<pre class="codeguru"><?php
echo sanjay();
?></pre>
<form class="hidden code-box" method="GET" name="sample">
<div dir="ltr"><textarea class="php" name="codeguru"></textarea></div>
<div class="hint">This code is editable. Click Run to execute.</div>
<input type="submit" value="Run" />
<img class="hidden" style="vertical-align: middle;" alt="Try PHP " src="http://code.guru99.com/img/ajax-loader.gif" name="ajax-loader" title="Try PHP " />
<div class="hidden stdout"></div>
<div class="hidden stderr"></div>
</form>
<form class="hidden code-box" method="GET" name="NoSample">
<div dir="ltr"><textarea class="php" name="codeNrun"></textarea></div>
</form>
CSS
.CodeMirror {
border: 1px solid #eee;
height: 300px;
}
.CodeMirror-scroll {
overflow-y: hidden;
overflow-x: auto;
}
.hidden{
visibility:hidden;
}
JavaScript
$('pre.codeguru').each(function()
{
var pre = this;
var form = $('form[name=sample]').clone();
$(form).removeAttr('name');
$(form).removeClass('hidden');
$($(form).find('textarea')[0]).val($(pre).text());
var id = $(pre).attr('id');
$(form).find('div textarea[name=code]').first().attr('id', id);
$(pre).replaceWith(form);
});
var editors = [];
$('textarea[name=codeguru]').each(function()
{
var editor = CodeMirror.fromTextArea(this,
{
lineNumbers: true,
matchBrackets: true,
mode: "application/x-httpd-php",
tabMode: "shift"
});
editors.push(editor);
});
$('form').submit(function()
{
var form = this;
var textarea = $(this).find('div textarea[name=codeguru]').first();
var code = $(textarea).val();
var id = $(textarea).attr('id');
//alert(code);
var code= "code="+code;
var loader = $(this).find('img[name=ajax-loader]').first();
$(loader).removeClass("hidden");
$.ajax({
type: 'GET',
url: 'http://code1.guru99.com/eval/exec.php',
dataType: 'JSONP',
data: {code : code},
success: function(data)
{
//alert(data.result);
var data = data.result;
$(loader).addClass('hidden');
var stdout = $(form).children('.stdout');
if (data.search("Parse error")>0)
{
var str = data.replace('<b>Parse error</b>: ','');
$(stdout).html(str);
$(stdout).removeClass('hidden');
}
else
{
$(stdout).html(data);
$(stdout).removeClass('hidden');
}
},
jsonpCallback: 'mycallback',
error: function (xhr, ajaxOptions, thrownError,err,textStatus) {
alert("Fatal error generated!!! Please check your code");
}
});
return false;
});
$('pre.codeNrun').each(function()
{
var pre = this;
var...