Thursday, 19 July 2012

echo, variable, string, operators


Echo
 The following is the combination of HTML and PHP that we used to write this program.
<html>
<h3>My first PHP Program</h3>
  <? echo "Hello world!"; ?>
</html>
If we remove the HTML we will have only the following PHP.
<? echo "Hello world!"; ?> 
The above example revolves around the PHP language constructecho. The echo language construct must be followed by a space. After the space you can give echo any sentence you choose, provided that the sentence is contained within quotes (" "). Like any PHP statement, it must also end with a semicolon (;).
The echo language construct also raises an important term in PHP, as well as general programming terminology: stringswords andsentences.
Strings
In the purest sense, string is series of characters. In the context of this example we will add the requirement that strings be contained within quotes (" "). Strings can be divided into two types,words and sentences.
  • word is a series of characters within quotes (" ") that does not contain any spaces or commas.
  • sentence is a series of characters within quotes (" ") thatdoes contain at least one space or comma.
Given the above three definitions, we can deduce that in the "Hello World!" example, what was referred to as a sentence, can also be formally refered to as a set of words, or a string.
The following are examples of three different words:
  1.  "1234567890"
  2.  "-=\_+|X~qwertyuioo"
  3.  "String"
and the following are examples of three different sentences:
  1.  "1234567890,-=\_+|X~qwertyuioo"
  2.  "pasdf ghjkl;;'zxcv     bnm,./[]{}"
  3.  "This collection of words is a string!"
All six of the above examples are strings. For more information onstrings see the PHP manual's entry on strings  .
Now that we have our terminology defined we can say that whatever you choose to display with echo must be a string.
PHP also has a a language construct called print which is very similar to echo. Within this tutorial we will use echo. More information onecho   and print   can be found online.
We can use echo to display information on our website. Most of the PHP programs we will examine in this class will use PHP to process data and come up with an answer. We will then use echo to display that answer. Thus, even though it serves a simple function, it is essential to using PHP.
Variables
Variables (as taught in Algebra) can take on unknown values and allow us (and our PHP programs) to generalize, which in turn can allow for flexibility. We use variables in spoken languages like English often. For example, a common word such as age can be considered a variable because age can take different values for different people or for the same person at different times. Similarly, country can be considered a variable because a person's country can be assigned a value. Programming languages like PHP also allow us to give a name to something which we can specify in the future.
Variables are denoted in PHP by preeding them with a dollar sign ($). So if I wanted to create a variable called a, I would type the following:
$a;
When programming you should give your variables meaningful names. For example, $age will make more sense to you then $a, if you want a variable to represent someone's age. Variables should be single words(as specified above) . For example, if we were to type:
$erins age
To represent a person named Erin's age we would have a syntax error, because the word "age" would have no meaning in PHP and $erins would be the variable that we created. You should avoid having a space or a comma in your variable. It is conventional in PHP to use an underscore to take the place of space in order to keep a string a word. So, we would represent the variable for Erin's age in PHP like this:
$erins_age
Another convention which comes from Java for representing spaces is to remove all spaces, but use a capital letter to denote what you would intend to be a separate word. For example:
$erinsAge
This method is referred to by some programmers as "studly caps". In this tutorial we will be using the underscore replacement of space instead.

Operators

Operators do things to variables. If I wanted to say "my age is 26", the word "is" could be seen as an operator. The string "my age" could be seen as a variable, and "26" could be seen as the value of the variable. In PHP this would look like this:
$my_age = 26;
Note the use of the assignment operator (=) which sets $my_age to the value of 26.
PHP has other operators and you should already be familiar with most of the following:
ExampleNameResult
$a + $bAdditionSum of $a and $b.
$a - $bSubtractionDifference of $a and $b.
$a * $bMultiplicationProduct of $a and $b.
$a / $bDivisionQuotient of $a and $b.
$a % $bModulusRemainder of $a divided by $b.

visit below website to know openings for freshers

Saturday, 14 July 2012

Workbook for Web Development and PHP Prgramming - I

Download workbook from below link for subject "Web Development and PHP Prgramming - I"
T.Y.B.Sc (Computer Science)

http://cs.unipune.ernet.in/obx/~hod_cs/Lab2_php.pdf