3v4l.org

run code in 300+ PHP versions simultaneously
<?php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">      <head>        <title>Form Example</title>        <meta http-equiv="content-type"            content="text/html; charset=utf-8"/>      </head>      <body>        <form action="" method="post">          <div><label for="firstname">First name:            <input type="text" name="firstname" id="firstname"/></label>          </div>          <div><label for="lastname">Last name:            <input type="text" name="lastname" id="lastname"/></label>          </div>          <div><input type="submit" value="GO"/></div>        </form>      </body>     </html> As you can see, we’re leaving the action attribute blank. This tells the browser to submit the form back to the same URL from which it received the form – in this case, the URL of the controller that included this template file. Let’s take a look at the controller for this example. Create an index.php script in the welcome directory alongside your form template. Type the following code into this file: <?php     if (!isset($_REQUEST['firstname']))     {      include 'form.html.php';     }     else3     {      $firstname = $_REQUEST['firstname'];      $lastname = $_REQUEST['lastname'];      if ($firstname == 'Kevin' and $lastname == 'Yank')      {        $output = 'Welcome, oh glorious leader!';      }      else      {        $output = 'Welcome to our web site, ' .            htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' .            htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!';      }          include 'welcome.html.php';5     }     ?> This code should look fairly familiar at first glance; it’s a lot like the welcome8.php script we wrote earlier. Let me explain the differences: if (!isset($_REQUEST['firstname']))     { The first thing the controller needs to do is decide whether the current request is a submission of the form in form.html.php or not. You can do this by checking if the request contains a firstname variable. If it does, PHP will have stored the value in $_REQUEST['firstname']. isset is a built-in PHP function that will tell you if a particular variable (or array element) has been assigned a value or not. If $_REQUEST['firstname'] has a value, isset($_REQUEST['firstname']) will be true. If $_REQUEST['firstname'] lacks a value, isset($_REQUEST['firstname']) will be false. For the sake of readability, I like to put the code that sends the form first in my controller. What we need this if statement to check, therefore, is if $_REQUEST['firstname'] is not set. To do this, we use the not operator (!). By putting this operator before the name of a function, you reverse the value that function returns from true to false, or from false to true. Thus, if the request does not contain a firstname variable, then !isset($_REQUEST['firstname']) will return true, and the body of the if statement will be executed. include 'form.html.php'; If the request is not a form submission, the controller includes the form.html.php file to display the form. }     else     { If the request is a form submission, the body of the else statement is executed instead. This code pulls the firstname and lastname variables out of the $_REQUEST array, and then generates the appropriate welcome message for the name submitted: $firstname = $_REQUEST['firstname'];     $lastname = $_REQUEST['lastname'];     if ($firstname == 'Kevin' and $lastname == 'Yank')     {      $output = 'Welcome, oh glorious leader!';     }     else     {      $output = 'Welcome to our web site, ' .          htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' .          htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!';     } Instead of echoing the welcome message, the controller stores the welcome message in a variable named $output.  include 'welcome.html.php';     } After generating the appropriate welcome message, the controller includes the welcome.html.php template, which will display that welcome message. All that's left is to write the welcome.html.php template. Here it is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">      <head>        <title>Form Example</title>        <meta http-equiv="content-type"            content="text/html; charset=utf-8"/>      </head>      <body>        <p>          <?php echo $output; ?>        </p>      </body>     </html>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.320.0060.04012.50
5.4.310.0080.04512.49
5.4.300.0110.03712.50
5.4.290.0060.04212.49
5.4.280.0070.03512.39
5.4.270.0070.04712.39
5.4.260.0100.04912.39
5.4.250.0100.05012.39
5.4.240.0060.04212.39
5.4.230.0060.05012.38
5.4.220.0060.03912.38
5.4.210.0060.03512.38
5.4.200.0080.03612.38
5.4.190.0070.03512.38
5.4.180.0100.03312.38
5.4.170.0080.05112.39
5.4.160.0080.04812.38
5.4.150.0080.03912.38
5.4.140.0150.03512.07
5.4.130.0040.04612.05
5.4.120.0040.03712.02
5.4.110.0090.04412.01
5.4.100.0050.03712.01
5.4.90.0070.03712.01
5.4.80.0050.04912.01
5.4.70.0080.03412.01
5.4.60.0100.03812.00
5.4.50.0120.03712.00
5.4.40.0080.04012.00
5.4.30.0080.04411.99
5.4.20.0080.03411.98
5.4.10.0040.03711.99
5.4.00.0050.03711.48
5.3.290.0110.04112.80
5.3.280.0070.03812.71
5.3.270.0050.04212.73
5.3.260.0100.04912.72
5.3.250.0110.03612.72
5.3.240.0040.03912.72
5.3.230.0050.04612.71
5.3.220.0070.03712.68
5.3.210.0070.04112.68
5.3.200.0080.03712.68
5.3.190.0120.03312.68
5.3.180.0080.04312.67
5.3.170.0090.05012.67
5.3.160.0060.04712.68
5.3.150.0050.03912.68
5.3.140.0050.04712.66
5.3.130.0060.04912.66
5.3.120.0070.04312.66
5.3.110.0050.04612.66
5.3.100.0110.03812.12
5.3.90.0060.03612.08
5.3.80.0090.03312.07
5.3.70.0080.03412.07
5.3.60.0050.04212.07
5.3.50.0060.04112.00
5.3.40.0090.03812.00
5.3.30.0140.04311.95
5.3.20.0040.03911.73
5.3.10.0050.04011.70
5.3.00.0050.04411.68
5.2.170.0060.0349.19
5.2.160.0050.0339.19
5.2.150.0100.0359.19
5.2.140.0070.0319.18
5.2.130.0050.0299.14
5.2.120.0100.0349.14
5.2.110.0070.0359.15
5.2.100.0080.0279.15
5.2.90.0040.0309.15
5.2.80.0080.0289.14
5.2.70.0050.0309.14
5.2.60.0110.0249.10
5.2.50.0070.0309.07
5.2.40.0040.0339.04
5.2.30.0060.0309.02
5.2.20.0020.0339.01
5.2.10.0020.0318.93
5.2.00.0050.0298.79
5.1.60.0050.0258.07
5.1.50.0130.0538.07
5.1.40.0060.0358.05
5.1.30.0060.0288.40
5.1.20.0060.0288.42
5.1.10.0060.0358.15
5.1.00.0050.0278.15
5.0.50.0030.0256.63
5.0.40.0050.0216.49
5.0.30.0030.0326.30
5.0.20.0060.0186.27
5.0.10.0040.0206.25
5.0.00.0040.0346.25
4.4.90.0030.0214.78
4.4.80.0070.0144.75
4.4.70.0020.0164.76
4.4.60.0040.0184.76
4.4.50.0040.0164.77
4.4.40.0030.0284.71
4.4.30.0050.0144.76
4.4.20.0030.0154.84
4.4.10.0030.0154.85
4.4.00.0030.0264.76
4.3.110.0050.0214.67
4.3.100.0050.0204.67
4.3.90.0010.0224.63
4.3.80.0050.0304.58
4.3.70.0030.0184.63
4.3.60.0040.0194.63
4.3.50.0020.0164.63
4.3.40.0020.0254.54
4.3.30.0000.0183.29
4.3.20.0030.0153.26
4.3.10.0010.0203.23
4.3.00.0000.02018.16

preferences:
143.47 ms | 1394 KiB | 7 Q