Simple PHP Program

PHP (Hypertext Preprocessor) is basically Perl code that runs on a webserver. It takes input entered by the user from forms which are on HTML webpages and does stuff with them and outputs the results. It’s sometimes called CGI scripting too (Common Gateway Interface). To get the PHP script working you write it and upload it to a server that allows PHP (most paid for webhosts allow it, free ones often do not for security reasons) and you write an HTML file to interact with it. Pretty simple really. Here’s an HTML file that will interact with a PHP script to convert inches and centimeters to each other; you would just need to save it as an html file and open it in your browser, but you’ll have to change the address of the script to the correct server and folder you will eventually upload the PHP file to…
<html>
<body>

Enter inches to convert to centimeters
<form action=”theaddressofthescript.com/thescript.php” method=”post”>

<input type=”double” name=”inches” size=”30″/>
<input type=”submit” value=”Submit”/>
<br/>
or…<br/>
Enter centimeters to convert to inches
<br/>
<input type=”double” name=”centimeters” size=”30″/>
<input type=”submit” value=”Submit”/>
</body>
</html>

But to make it work you upload this script to a webserver and folder on that webserver matching the address in the last file…

<html>
<body>
<?php
$inches = $_POST[‘inches’];
$centimeters = $_POST[‘centimeters’];
echo $inches . ” inches are equal to ” . (double)($inches * 2.54) . ” centimeters”;
echo “<br/>”;
echo $centimeters . ” centimeters are equal to ” . (double)($centimeters / 2.54) . ” centimeters”;
?>

</body>
</html>

You can see it working on my webserver below. Try it out and hit the backbutton on your webbrowser to return here afterwards!

Enter inches to convert to centimeters




or…
Enter centimeters to convert to inches