- - - - GimpsterDotCom - Php Tutorial/Action - - - -
Site hosted by Angelfire.com: Build your free website today!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

- Php Tutorial/ Action

- - - - -
-
-
- - - -
-

As in all good tutorials, we start with the (in)famous HelloWorld example. Here's the code:

-
- -

Hello World



- - // This is a comment that extends to the end of the line.

/* This is multi-line comment. Comments are ignored by PHP,
but provide valuable information to people reading the source. */

echo "Hello World! Thank you very much\n" - ;
- ?>



-

You should save this piece of code in a file with the extension .php . If that doesn't work, then try other extensions like .php3 or .phtml . If you can't figure out the right extension, then ask whoever installed the webserver. If that's you, then have a look at the file called httpd.conf - if you're using Apache that is...

It should contain a line that looks like this:

AddType application/x-httpd-php .php
-

Anyway --- this line informs Apache that files ending with .php are PHP scripts. Thanks go to Jon-o Addleman - - mailto jaddle@po-box.mcgill.ca for suggesting that I should write this piece.

Back to the example, which is somewhat silly. But it can be used to teach you a few things anyway.

-

Most of the code is just plain HTML. Only the part between and ?> is PHP-code. You use either or just to start the code and ?> to stop it again. The parser works within these two tags. Between the and ?> you put a number of statements, each of which must be ended by a ; (a semi-colon).

-

Between the two tags there is a comment and one statement, echo "Hello World"; . The comment will be completely ignored, and the echo statement just prints the string " Hello World " into the webpage, which is then sent to the browser. After the parser has processed the page, the final output that is sent to the browser looks this way:

  Hello World   

Hello World

As you can see, there's no trace of the PHP-code left in the final output. In the following code-snippets I won't include all the HTML code, but remember that you'll have to use HTML if you want your PHP scripts to work on the net. You'll also have to include the right HTML codes in the strings you output from PHP, if you're outputting more than just very simple strings.

-

You should think of a PHP-script as a normal web page written in HTML, since most of the page is still just plain-old HTML. But between the start- and end-tags ( or and ?> ) the PHP-parsed spices the page up with possibly dynamic content. You'll need to read - PhpTutorial /Variables for dynamic content, so go there now .

- -
-

Last edited on July 25, 2003.

- - - - - - -
- -
- - -
- -
-
- -
- -