3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php date_default_timezone_set('America/New_York'); function findInvestment($invest, $interest, $years) { // calculate the future value $future_value = $invest; for ($i = 1; $i <= $years; $i++) { $future_value = ($future_value + ($future_value * $interest *.01)); } // apply currency and percent formatting $investment_f = '$'.number_format($invest, 2); $yearly_rate_f = $interest.'%'; $future_value_f = '$'.number_format($future_value, 2); print(" <label>Investment Amount:</label> <span>$investment_f</span><br> <label>Yearly Interest Rate:</label> <span>$yearly_rate_f</span><br> <label>Number of Years:</label> <span>$years</span><br> <label>Future Value:</label> <span>$future_value_f</span><br> <h4>This calculation was done on " . date("m/d/Y").". "); } function printForm($print, $invest, $interest, $years) { if ($print == TRUE) { $invest = ""; $interest = ""; $years = ""; } else { if ( strlen($invest) == 0 ) { $error_message[] = 'Investment is a required field.'; } else if ( !is_numeric($invest) ) { $error_message[] = 'Investment must be a valid number.'; $invest = ""; } else if ( $invest <= 0 ) { $error_message[] = 'Investment must be greater than zero.'; } elseif ( strlen($interest) == 0 ) { $error_message[] = 'Interest rate is a required field.'; } else if ( !is_numeric($interest) ) { $error_message[] = 'Interest rate must be a valid number.'; $interest = ""; } else if ( $interest <= 0 OR $interest > 15 ) { $error_message[] = 'Interest rate must be greater than zero and less than or equal to 15.'; } elseif ( strlen($years) == 0 ) { $error_message[] = 'Years is a required field.'; } else if ( !is_numeric($years) ) { $error_message[] = 'Years must be a valid number.'; $years = ""; } else if ( $years <= 0 OR $years > 50 ) { $error_message[] = 'Years must be greater than zero and less than or equal to 50.'; } // set error message to empty string if no invalid entries else { $printResults = 1; $error_message = ''; } } print(" <!DOCTYPE html> <html> <head> <title>Future Value Calculator</title> <link href=\"main.css\" rel=\"stylesheet\" type=\"text/css\"> <meta charset=\"utf-8\"> </head> <body> <div id=\"content\"> <h1>Future Value Calculator</h1>"); if (!empty($error_message)) { foreach($error_message as $msg) { print("<p class=\"error\">$msg</p>"); } } else { $invest = ""; $interest = ""; $years = ""; } print("<form action=\"index.php\" method=\"post\"> <div id=\"data\"> <label>Investment Amount:</label> <input type=\"text\" name=\"investment\" value=\"$invest\"><br> <label class=\"clear\">Yearly Interest Rate:</label> <input type=\"text\" name=\"interest_rate\" value=\"$interest\"><br> <label class=\"clear\">Number of Years:</label> <input type=\"text\" name=\"years\" value=\"$years\"><br> </div> <div id=\"buttons\"> <label class=\"clear\">&nbsp;</label> <input type=\"submit\" value=\"Calculate\" name=\"submit\"><br> </div> </form>"); if (!empty($_POST['submit']) AND !$error_message) { findInvestment($_POST['investment'], $_POST['interest_rate'], $_POST['years']); } print("</div> </body> </html> "); } //if (empty($_POST['investment']) && empty($_POST['interest_rate']) && empty($_POST['years'])) { // printForm(1, "", "", ""); //} if (!empty($_POST['submit'])) { printForm(0, $_POST['investment'], $_POST['interest_rate'], $_POST['years']); } else { printForm(1, "", "", ""); } ?>
Output for 5.1.0 - 7.1.0
<!DOCTYPE html> <html> <head> <title>Future Value Calculator</title> <link href="main.css" rel="stylesheet" type="text/css"> <meta charset="utf-8"> </head> <body> <div id="content"> <h1>Future Value Calculator</h1><form action="index.php" method="post"> <div id="data"> <label>Investment Amount:</label> <input type="text" name="investment" value=""><br> <label class="clear">Yearly Interest Rate:</label> <input type="text" name="interest_rate" value=""><br> <label class="clear">Number of Years:</label> <input type="text" name="years" value=""><br> </div> <div id="buttons"> <label class="clear">&nbsp;</label> <input type="submit" value="Calculate" name="submit"><br> </div> </form></div> </body> </html>
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function date_default_timezone_set() in /in/SB6XF on line 3
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: date_default_timezone_set() in /in/SB6XF on line 3
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: date_default_timezone_set() in /in/SB6XF on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: date_default_timezone_set() in /in/SB6XF on line 3