Beruflich Dokumente
Kultur Dokumente
I Example — php/homepage.php:
<html><head><title>Home page</title></head>
<body>
I Variables are used for storing values during the execution <h2>
of a PHP script <?php $name = "Ken Friis Larsen";
echo "Home page for ";
I Values can, for instance, be character strings and echo $name;
numbers ?>
I Names of variables are chosen freely by the programmer, </h2>
This page is maintained by
although variable names must start with the character $
<?php echo $name ?>
</body>
</html>
I Notice that a variable can be referred to more than once
after it has been initialized with a value.
Computation with Numbers Example: Dollar Exchange
Example — php/dollars.php:
<html><head><title>Dollars</title></head>
<body>
<h2>Dollars</h2>
<?php
There are two types of numbers in PHP:
$rate = 6.13;
1. Integers: 3, 9, 0, -1, ... $kroner = 1000.0;
2. Doubles (double precision): 3.0, 9.2, 0.13, -23.2, ... $dollars = ($kroner - 20.0) / $rate;
echo "For DKr. $kroner you receive \$$dollars"; ?>
The usual number operations (e.g., +,-,*, and /) can be used
</body>
in computations. </html>
Notice:
I It is possible to refer to a variable inside a character
string "..."
I To insert a dollar-sign ($) in a character string, the
character ‘\’ should be placed before the dollar-sign
evaluated.
the script is executed when a client requests the file relative I Technologies for Web sites that are programs
to the user’s home page: I for-loops
http://www.itu.dk/people/user/test.php I Built-in PHP functions
I User defined functions
Exercises — Problem Set 2
I Reuse of code
I Temperature Conversion
I Multiplication Service
I Apple Pie Service