Information Technology News
Vamp the Linux LAMP with PHP | Vamp the Linux LAMP with PHP |
|
| by David M Williams | |
| Monday, 24 September 2007 | |
|
Page 2 of 3 Type up the following in a text editor and save it to disc with a .php file extension, perhaps as testing.php. To view it from the web, you’ll need to make sure you save it into an area covered by your web server.Featured Whitepaper
5 Best Practices for Smartphone Support
<html>
Alternatively, you can invoke the PHP pre-processor directly from the command line by executing php testing.php – in this case the HTML output will still be generated but will display to the screen. Either way, you’ll see the output tells you twice what the sum of 10 and 20 is. Compare the output with the program code, reading from top to bottom. You can see we switched into PHP mode twice, with HTML tags used to control the paragraphing and messages.
You’ll also note the differences between the two additions; the first time, two variables called $a and $b are assigned numeric values. Their sum is displayed. The second time around, $a is added to $c which actually contains the text string “20”, rather than the numeric value 20. When the addition is performed PHP sensibly recognises the need for “20” to be interpreted as a numeric value and still delivers the correct result. PHP offers other mathematical operators as well as addition, namely subtraction (-), multiplication (*) and division (/). You might actually want PHP to join two text strings together. In that case, don’t use the + symbol because PHP interprets that as adding numbers. Instead, use a period (.) to join two strings together, one right after the other. There’s two more import things to note in the listing above. Semicolons (;) are used to separate commands in PHP and the echo command, which as you might guess, sends the result of a calculation or some other operation to the output being built up.
|
| < Next story in category | Previous story in the category > |
|---|






