Forums
|

Downloads
|
Bookmarks
|
Contact Us
|
Sale is Over
The sale in the download's section is now over.
Posted by ~Ntsmarkv on Monday, August 31st, 2010 10:03 PM MST
PHP - Comments / Math
PHP can do all kinds of great things. You could almost live without real programs because of the things you could do through a web browser. One of the things PHP can do is math. Although I can not show you because it is protected, I created a program for my "real" job that calculates the weight of metal, the price of the weight times the quantity, etc.
---------------------------------------
<?php // this is a comment line. You can tell because it starts with two forward slashes // here is another line of comments # this is also a comment line. It starts with a hash mark # here is another # here is another /* * this is a multiple line comment * all of this text is commented out * * this type is best for multiple lines, but that is my opinion */ // this defined the variable that will be used in the title tags $title = 'hello world!'; ?> <html> <head> <title><?php echo $title; ?></title> </head> <body> Here is a little math: <?php // start the PHP tags - telling the server to parse the code // assign the value of 4 to the $number1 variable $number1 = '4'; // assign the value of 6 to the $number2 variable $number2 = '6'; // add up $number1 (4) and $number2 (6), the total is assigned to // the $sum variable $sum = $number1 + $number2; // print the $sum (10) to the browser echo "The sum of $number1 + $number2 is $sum"; // add a couple of line breaks to the page echo "<br /><br />"; // you can also use this code to print to a browser: print "The sum of $number1 + $number2 is $sum"; // close the php tags: ?> </body> </html>
---------------------------------------
If you study the top 13 or so lines of that code, you can see what I have done for comments. Comments are notes that a programmer can write to describe what is going on in the code. The good thing about comments is when the server parses the code, it will ignore anything that is commented out, thus making it invisible to everything except the programmer(s).
If you read the PHP Introduction tutorial, you saw how to assign variables. You can assign strings and integers to variables. Strings are text and numbers and characters, but integers are just numbers.
If you have two variables that are defined by numbers, you can add them together or do any other mathematical operations.
For example, you saw that $number1 equals 4 and that $number2 equals 6. When they were added together, they equaled 10 which was assigned the the variable $sum.
The source code for this article is available at http://www.kasl.info/source
This page has been accessed 2,268 times
|