I was trying to convert this into a Drupal module so that I can check PHP code instantly on my site for debugging purposes. I saw this Firefox add on which allows you to execute PHP on the fly but admin log in is necessary, so far I did everything , have one form and set up ajax calls , but if I pass a string like:
preg_match($pat,$str,$matches);
print_r($matches);
How to execute this in backend?
EDIT
To load the form:
$items['localphp'] = array(
'page callback' => 'executePHP',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
function executePHP(){
$output = drupal_get_form('executePHP_form');
return $output;
}
Ajax callback function:
$items['runPHP'] = array(
'page callback' => 'getResult',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
function getResult(){
$code = $_POST['code'];
//I need help here how to execute $code i.e the php code and return back result
echo $code;
}
JS function
function executePHP(baseurl){
var code = $("#edit-code").val();
$.ajax({
type : "POST",
url : baseurl+'runPHP',
data : 'code='+code,
async : true,
cache : false,
success : function (res) {
$("#edit-result").html(res);
},
error : function (res) {
alert("error");
}
});
return false;
}