Still in the beginning stages of learning? Here are some things that will be beneficial to understand about writing PHP script!
A Few Facts About PHP
--try each snippet of code provided to see the different results.
1. PHP does have syntactical rules that your code must follow.
2. PHP syntax only applies when it is within PHP tags.
3. PHP is very much like the C programming language.
4. PHP is not sensitive to extra hard-returns, spaces or tabs.
The following 2 lines of script will produce the exact same result:
print ("Do I really have to learn this? Yes you do.");
<br> <!-- escaped into html to provide a line break-->
print ("Do I really have to learn this?
Yes you do.");
5. String text and variables ARE case sensitive within PHP. Other constructs and functions are NOT.
If you type the following lines of code,
print ("This is boring!");
pRINt ("ShoW Me ThE GoodS!");
Your output will be this:
We will learn about variables later. For now just remember that they ARE case sensitive.
6. As shown in the above examples, all PHP statements must be terminated with a semicolon. If not,
you will get a parse error. Try the code below to see the error. Notice that the error provides
you with a line number from your code. With this example, the message tells you the error is on the
that DOES have a semi-colon. If you get a parse error because of a missing semi-colon (as in this example),
the line number in the error message will correspond to a line AFTER the line with the error.
print ("You will get a parse error without a semi-colon")
print ("A second line will generate the error");
7. There are some rules about how to put a PHP statement together. The following 2 paragraphs are
quoted directly from pages 60-61 of the PHP 4 Bible:
8. Just as in Algebra, PHP does have some rules as to precedence when it evaluates an expression. I will
not list the rules here. If you write an expression and you are unsure how PHP will evaluate it,
put each expression in parenthesis. In all but one instance ("short-circuiting" Boolean expressions),
you can depend on a left to right evaluation order if each expression is within paranthesis. That
exception will be covered further down the road! For now, try the following code to illustrate mathematical
print 5+2*3; //does the multiplication first, then adds 5
<br> <!--escaped into html to provide a line break
print (5+2)*3 //does the parenthesis first, then multiplies by 3
10. A document using PHP must be saved as .php. If it is not, the server will not know to look for PHP script.
That's the end of Lesson2. Once again, all material covered came from the "PHP 4 Bible" by Converse and Park.
Look for Lesson3 soon!!