Jump to content


Beginning To Learn Php

  • Please log in to reply
3 replies to this topic

#1 natimage


    February Family member of the month

  • Members
  • PipPipPipPip
  • 824 posts

Posted 17 June 2003 - 08:12 AM

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:

This is boring! ShoW Me ThE GoodS!

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:

The smallest building blocks of PHP are the indivisible tokens, such as numbers (3.14159), strings ("two"), variables ($two), constants (TRUE), and the special words that make up the syntax of PHP itself (if, else, and so forth).  These are separated from each other by whitespace and by other special characters such as parenthesis and braces.

The next most complex building block in PHP is the expression, which is any combination of tokens that has a value.  A single number is an expression, as is a single variable.  Simple expressions can also be combined to make more complicated expressions, usually either by puttin an operator in between (for example, (2 + (2 + 2)), or by using them as input to a function call (for example, power_of(2 * 3, 3 * 2)). Operators that take two inputs go in between their inputs, whereas functions take their inputs in parenthesis immediately after their names, with the inputs (known as arguments) separated by commas.

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!!

Edited by natimage, 17 June 2003 - 08:22 PM.

Natural Images Photography

<A HREF="ymsgr:sendIM?natimage72"><IMG SRC="http://www.tchstatus.com:8080/yahoo/natimage72"></a>

#2 surefire


    Immediate Family

  • Members
  • PipPipPipPip
  • 1,008 posts

Posted 17 June 2003 - 09:08 AM

To print this:

Here is a quote, "The cow jumped over the moon."

You need to write:

print("Here is a quote, \"The cow jumped over the moon.\"");

The forward slash escapes the character that follows it and tells the server, "I really want you to print this next character, don't translate it into code."

Edited by surefire, 17 June 2003 - 09:11 AM.

#3 kryles


    New To The Neighborhood

  • Members
  • Pip
  • 7 posts

Posted 30 October 2007 - 02:47 PM

PHP code can also be used in .inc files, not just .php files

#4 TCH-Bruce


    Volunteer Moderator

  • Members
  • PipPipPipPip
  • 20,149 posts

Posted 30 October 2007 - 02:55 PM

You do realize these threads you are posting in are 4 years old, right?

Bruce Richards
Forum Moderator
TotalChoice Hosting, Inc.
Webhosting by Total Choice Web Hosting - General Support Forum

I am a Forum Moderator. While I can assist in answering most of your hosting related questions, I am unable to answer questions about specifics relating to your account such as billing and server related issues. Should you need assistance in these areas, please contact our Help Desk or our many other options. Another good place to find answers is with our help pages, tutorials and movie tutorials.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users