Writing a PHP program with numeric variables

A numeric variable program is the next PHP program that we will create. String (text) and numeric values are handled different in the computer memory. Although, there are two types of numeric values, integers and floating point real numbers, we will be working with integers in this PHP program.

Numbers without any decimal point are called integers and numbers with decimal values are callted real numbers. Although we have identified the two numeric variables in this PHP program as $x and $y, it is always best to use the tips listed below:

Tips to remember when naming your variables:

  • Always ensure that your variable name describes the information that it contains.
  • The length of your variable should be long enough to describe it accurately.
  • Do not use spaces in a variable name.
  • Do not use special characters and punctuation with the exception of ($) dollar sign and (-) underscore.
  • PHP is a case-sensitive language, so if you use $USERNAME and $username, you have two different variables.
  • Spelling your variable correctly is important, PHP will not catch a misspelling and will assume it is a new variable.

Similar to the previous programs, the PHP code uses the <? and ?> special tag.

As demonstrated in the previous programs, we used notepad a plain text editor and stored the program on our web server, "C:\Wampserver2\www."

The steps to writing a PHP program are outlined below:

1. Select and click "Start."
2. Select and click "All Programs."
3. Select and click "Accessories."
4. Select and click "Notepad."
5. Type the HTML and PHP exactly as shown below.

<html>

<head>

<title>Eight Plus Ten</title>

</head>

<body>

<h1>Eight Plus Ten</h1>

<h3>Demostrates use of numeric variables<h3>

<?php

$x = 8;

$y = 10;

print "$x + $y = ";

print $x + $y;

print "<br><br> ";

print "$x - $y = ";

print $x - $y;

print "<br> <br> ";

print "$x * $y = ";

print $x * $y;

print "<br> <br> ";

print "$x / $y = ";

print $x / $y;

print "<br> <br> ";

?>

</body>

</html>

6. Once you have type the entire program, Select "File," "Save As," and then go to the webroot of your server. For example, C:\Wampserver2\www. Type Filename, "listendoyou.php," and then Select "Save."

7. Use your browser to view the tips.php program. The steps are outlined below:
1.Select and click "Start. "
2.Select and click "All Programs."
3.Select and click "Internet Explorer."
4.Locate the Web Address Field, near the top-left of the Internet Explorer window and type in the Web address of the eightplusten.php program, "http://localhost/eightplusten.php," then enter.

The eightplusten.php program will be displayed

Advertisement

, Tampa Information Technology Examiner

Ginny Putscher, a 25-year information technology veteran, has worked with both private industry and federal government. Ginny's experiences include traveling and working in many foreign countries - Egypt, El Salvador, Kenya, Tanzania and Senegal. Ginny received her BA in Database Development...

Today's top buzz...