#!/usr/bin/php5
<?php

	/// PHP shell - simple PHP shell
	/// allows interactive PHP simple queries
	///
	/// Copyright 2009, 2010 iagoFG.com, Iago de la Fuente Gonzalez
	/// Licensed under GPL 2 or later
	///
	/// If you wish you can send your changes in the code to info@iagofg.com to
	/// evaluate and push into the next release.
	///

	function error_handler() {
	}
	set_error_handler('error_handler');

	/// setup some common values
	//$prompt='~ ';
	$prompt='<? ';

	echo(''."\n");
	echo('phpsh r0.9.1223-dev'."\n");
	echo('Copyright 2009, 2010 iagoFG.com, Iago de la Fuente Gonzalez'."\n");
	echo('Licensed under GPL 2 or later'."\n");
	echo(''."\n");
	echo('Type exit or quit to end session.'."\n");
	echo(''."\n");

	$data='';
	for (;(strtolower($data)!='exit')&&(strtolower($data)!='quit');) {
		echo($prompt); $data=trim(fread(STDIN, 1024));
		if (($data!='')&&(strtolower($data)!='exit')&&(strtolower($data)!='quit')) { /// evaluate non empty strings different from exit/quit
			if (strpos($data, "echo")!==FALSE) $retv=@eval('$ans='.$data.';');
			else $retv=eval('$ans='.$data.';');
			if ($retv===FALSE) $ans=eval(''.$data.';');
			echo($ans."\n");
		}
	}
