Giving input to a php program

Small example of use of variables.


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Examples of PHP variables and their use
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 9/24/06
-->
<html>
<head>
<title>
Examples of PHP variables and their use
</title>
</head>
<body>
<h2>This page tests PHP variables</h2>
<p>
<?php
// integers and what you can do with them
$n = 2;
$m = 3;
$sum = $n + $m;

// variables are a part of the string that gets printed
print "$n + $m = $sum<br/>\n";

$prod = $n * $m;
$div = $n / $m;
$remainder = $n % $m;
print "$n * $m = $prod<br/>\n $n / $m = $div<br/>\n $n % $m = $remainder<br/>\n";

// changing $n:
$n = $m + 1;
// using \ to print $
print "\$n = $n<br/>\n";
?>
</p>
</body>
</html>

http://rynite.morris.umn.edu/~elenam/1101_fall06/php_examples/first/variables.php


The same program with n and m as inputs


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Examples of PHP variables and their use
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 9/24/06
-->
<html>
<head>
<title>
Examples of PHP variables and their use
</title>
<?php 
$n = $_GET["input1"];
$m = $_GET["input2"];
?>
</head>
<body>
<h2>This page tests PHP variables</h2>
<p>
<?php
// integers and what you can do with them
$sum = $n + $m;

// variables are a part of the string that gets printed
print "$n + $m = $sum<br/>\n";

$prod = $n * $m;
$div = $n / $m;
$remainder = $n % $m;
print "$n * $m = $prod<br/>\n $n / $m = $div<br/>\n $n % $m = $remainder<br/>\n";

// changing $n:
$n = $m + 1;
// using \ to print $
print "\$n = $n<br/>\n";
?>
</p>
</body>
</html>

Note the two parameters passed at the end of the URL. This is called extended URL.
http://rynite.morris.umn.edu/~elenam/1101_fall06/php_examples/first/input.php?input1=5&input2=3
http://rynite.morris.umn.edu/~elenam/1101_fall06/php_examples/first/input.php?input1=55&input2=1

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.