JayT
09-14-2007, 08:39 PM
I'd like to have some PHP coders test this simple utility. Their feedback would help me improve on it.
It is a interactive web page you can use to test blocks of PHP code and functions. I use this program all the time to speed up the development and testing of blocks of PHP code and custom functions.
I just re-engineered it for PHP v5.x, however, if within the program you change
$_POST
to
$HTTP_POST_VARS
Then it should also work for PHP v4.x
There is a handy function within PHP called Eval() and this entire program is built around that function.
With this program you can easily experiment with PHP and test many of its functions directly from the key***rd via your web browser as well as many of your own custom functions.
Here is the complete program code:
<?PHP
/*
General Purpose Basic PHP Script Tester v5.0
PHP v5.2.4
REVISED: 2007 SEP *4 - FRI
*/
Print <<< _HTML
<!DOCTYPE HTML PUBLIC "-//W*C//DTD HTML 4.0* Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML; CHARSET=ISO-885*-*">
<META NAME="robots" CONTENT="noindex,nofollow">
<META NAME="googlebot" CONTENT="noindex,nofollow">
<!-- Optional CSS sheet
<LINK REL=STYLESHEET HREF="path_to_your.css" TYPE="TEXT/CSS">
-->
<TITLE>PHPX - PHP Code Tester v5.0</TITLE>
</HEAD>
<BODY>
_HTML;
// --------------------------
// Name of this program file.
$_ThisFileName_ = "phpx.php";
// Attach optional custom functions.
// include_once ("path_to_your_custom_function_module.php");
// ------------------------------------------
// Read and execute PHP code entered by user.
$_PHPCode_ = "";
If (@$_POST['PHP_Code'] && $_POST['Execute_Button'])
{
$_PHPCode_ = @$_POST['PHP_Code']; // StripSlashes(@$_POST['PHP_Code']);
Eval($_PHPCode_);
}
print "\n";
// ------------------------------
// Display the modified web page.
print <<< _HTML
<FORM NAME="PHPXForm" METHOD="post" ACTION="$_ThisFileName_">
<BR>
<TABLE CLASS="TxBlack" BGCOLOR="yellow" ALIGN="center" CELLPADDING="4" BORDER="8">
<TR>
<TD VALIGN="middle">
<DIV ALIGN="center">
<B>PHPX - PHP Program Code Tester - PHP v5.x</B>
<BR>
<TEXTAREA WRAP="OFF" NAME="PHP_Code" COLS="80" ROWS="20">
_HTML;
print chop($_PHPCode_);
print <<< _HTML
</TEXTAREA>
</DIV>
<DIV ALIGN="center">
<INPUT NAME="Execute_Button" TYPE="submit" VALUE="Execute Code">
</DIV>
</TD>
</TR>
</TABLE>
</FORM>
<DIV ALIGN="center">
<B>Enter PHP Code to Test Minus the <?PHP and ?> Tags</B>
</DIV>
</BODY>
</HTML>
_HTML;
?>
For example, run the program and then copy/paste the following PHP code into the input text area and test it by clicking the [Execute Code] button.
$F = *8.6; // Fahrenheit degrees
print "$F F = " . F_To_C ($F) . " C";
function F_To_C ($F_Arg)
{
return ($F_Arg - *2) * 5/* ;
}
Try it.
Any code entered into the text area within the page is interpreted as PHP code to be executed.
It can also store and remember variables.
It's not a perfect tool yet, but extremely useful nevertheless for quick code and function testing.
You can also attach your own CSS sheet and external custom PHP functions module to it.
IMPORTANT NOTE
When saving this program as a file, it MUST be named "phpx.php" to work correctly. If you change the file name, then the ACTION file name in the form has to be changed to match or the program will not work.
If anyone here tries out this program, let me know what you think about it, if you find any bugs or have any s***estions for improvement.
DANGER DANGER DANGER
This is a potentially very dangerous program! A hacker could possibly damage your site with it, depending on the security settings of your host, so I strongly recommend that if you use it on your web site, rather than locally, that you password protect access to it.
.
It is a interactive web page you can use to test blocks of PHP code and functions. I use this program all the time to speed up the development and testing of blocks of PHP code and custom functions.
I just re-engineered it for PHP v5.x, however, if within the program you change
$_POST
to
$HTTP_POST_VARS
Then it should also work for PHP v4.x
There is a handy function within PHP called Eval() and this entire program is built around that function.
With this program you can easily experiment with PHP and test many of its functions directly from the key***rd via your web browser as well as many of your own custom functions.
Here is the complete program code:
<?PHP
/*
General Purpose Basic PHP Script Tester v5.0
PHP v5.2.4
REVISED: 2007 SEP *4 - FRI
*/
Print <<< _HTML
<!DOCTYPE HTML PUBLIC "-//W*C//DTD HTML 4.0* Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML; CHARSET=ISO-885*-*">
<META NAME="robots" CONTENT="noindex,nofollow">
<META NAME="googlebot" CONTENT="noindex,nofollow">
<!-- Optional CSS sheet
<LINK REL=STYLESHEET HREF="path_to_your.css" TYPE="TEXT/CSS">
-->
<TITLE>PHPX - PHP Code Tester v5.0</TITLE>
</HEAD>
<BODY>
_HTML;
// --------------------------
// Name of this program file.
$_ThisFileName_ = "phpx.php";
// Attach optional custom functions.
// include_once ("path_to_your_custom_function_module.php");
// ------------------------------------------
// Read and execute PHP code entered by user.
$_PHPCode_ = "";
If (@$_POST['PHP_Code'] && $_POST['Execute_Button'])
{
$_PHPCode_ = @$_POST['PHP_Code']; // StripSlashes(@$_POST['PHP_Code']);
Eval($_PHPCode_);
}
print "\n";
// ------------------------------
// Display the modified web page.
print <<< _HTML
<FORM NAME="PHPXForm" METHOD="post" ACTION="$_ThisFileName_">
<BR>
<TABLE CLASS="TxBlack" BGCOLOR="yellow" ALIGN="center" CELLPADDING="4" BORDER="8">
<TR>
<TD VALIGN="middle">
<DIV ALIGN="center">
<B>PHPX - PHP Program Code Tester - PHP v5.x</B>
<BR>
<TEXTAREA WRAP="OFF" NAME="PHP_Code" COLS="80" ROWS="20">
_HTML;
print chop($_PHPCode_);
print <<< _HTML
</TEXTAREA>
</DIV>
<DIV ALIGN="center">
<INPUT NAME="Execute_Button" TYPE="submit" VALUE="Execute Code">
</DIV>
</TD>
</TR>
</TABLE>
</FORM>
<DIV ALIGN="center">
<B>Enter PHP Code to Test Minus the <?PHP and ?> Tags</B>
</DIV>
</BODY>
</HTML>
_HTML;
?>
For example, run the program and then copy/paste the following PHP code into the input text area and test it by clicking the [Execute Code] button.
$F = *8.6; // Fahrenheit degrees
print "$F F = " . F_To_C ($F) . " C";
function F_To_C ($F_Arg)
{
return ($F_Arg - *2) * 5/* ;
}
Try it.
Any code entered into the text area within the page is interpreted as PHP code to be executed.
It can also store and remember variables.
It's not a perfect tool yet, but extremely useful nevertheless for quick code and function testing.
You can also attach your own CSS sheet and external custom PHP functions module to it.
IMPORTANT NOTE
When saving this program as a file, it MUST be named "phpx.php" to work correctly. If you change the file name, then the ACTION file name in the form has to be changed to match or the program will not work.
If anyone here tries out this program, let me know what you think about it, if you find any bugs or have any s***estions for improvement.
DANGER DANGER DANGER
This is a potentially very dangerous program! A hacker could possibly damage your site with it, depending on the security settings of your host, so I strongly recommend that if you use it on your web site, rather than locally, that you password protect access to it.
.