PHP is the hottest scripting language around - and with the release of PHP4, more and more developers are looking at it as a rapid Web development tool. This new series of tutorials is aimed at getting novice programmers up to speed on the language, and the first article covers variables, operators and the include() function call. Exploding chewing-gum is optional.
Once you've got the basics of variables down, it's time to start doing something with them. We'll start with PHP's most useful mathematical operators - here's an example which demonstrates them:
Looks complex? Don't be afraid - it's actually pretty simple.
The meat of the script is at the top, where we've set up variables for the various items, the unit cost and the quantity. Next, we've performed a bunch of calculations using PHP's various mathematical operators, and stored the results of those calculations in different variables. The rest of the script is related to the layout and alignment of the various items on the bill, with PHP variables embedded within the HTML code.
Obviously, just as you can add and subtract numbers, PHP also allows you to concatenate strings with the string concatenation operator, represented by a period[.] The next example will make this clear:
<?php
// set up some variables
$a = "Where";
$b = "Are";
$c = "You";
// first alternative
$gamma = $a . " " . $b . " " . $c;
// second alternative
$delta = $a . " " . $c . " " . $b;
?>
<html>
<head>
<title>All Tied Up</title>
</head>
<body>
The first string is <? echo $gamma; ?>
<br>
The second string is <? echo $delta; ?>
</body>
</html>
And here's what you'll see:
The first string is Where Are You
The second string is Where You Are