Coder Profile - Show off your skills, get a coder profile.
 
 
 
Introduction To PHP
Web Development
Welcome to the Introduction To PHP tutorial. In this tutorial we will discuss the basics of PHP and what it can and is used for. It is best you learn HTML before attempting these tutorials.

What is PHP?


Quoted from PHP's homepage, PHP.net, "PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly."

This is generally a good definition of PHP. However, it does contain a lot of terms you may not be used to. Another way to think of PHP is a powerful, behind the scenes scripting language that your visitors won't see!

When someone visits your PHP webpage, your web server processes the PHP code. It then sees which parts it needs to show to visitors (content and pictures) and hides the other stuff (file operations, math calculations, etc.). Then it translates your PHP into HTML. After the translation into HTML, it sends the webpage to your visitor's web browser.

What does PHP do?

It is also helpful to think of PHP in terms of what it can do for you. PHP will allow you to:

  Reduce the time to create large websites.
  Create a customized user experience for visitors based on information that you have gathered from them.
  Open up thousands of possibilities for online tools.
  Allow creation of shopping carts for e-commerce websites.

Writing in PHP


All PHP code must be contained with PHP Tags. These tags consist of <?php or <? (opening tags), code goes after that, then ending the tag, we have ?>.

For PHP to work, the file must have a .php file extension.

Your first code


Let's put some text onto a page. Open your text editor, and paste this in. It is okay to change the text, it will just display that text on the page.
Code Copy / Restore
  1. <html>
  2. <head>
  3. <title>My First PHP Page</title>
  4. </head>
  5. <body>
  6. <?php
  7. echo "Hello World!";
  8. ?>
  9. </body>
  10. </html>
Save the file as helloworld.php and open it in your browser.

This displays:
Code Copy / Restore
  1. Hello World!
If you view the source, all you get is:
Code Copy / Restore
  1. Hello World!
Note: This is displayed in between all of the other HTML tags.

If it displays Hello World!, you just created your first PHP file!

The PHP echo function basically tells the browser to write whatever comes after echo in the quotes onto the page, and the semicolon ends the statement.

If it shows code, you may need to download and install PHP.

The semicolon!


As you may or may not have noticed in the above example, there was a semicolon after the line of PHP code. The semicolon signifies the end of a PHP statement and should never be forgotten. For example, if we repeated our "Hello World!" code several times, then we would need to place a semicolon at the end of each statement.
Code Copy / Restore
  1. <html>
  2. <head>
  3. <title>My First PHP Page</title>
  4. </head>
  5. <body>
  6. <?php
  7. echo "Hello World! ";
  8. echo "Hello World! ";
  9. echo "Hello World! ";
  10. echo "Hello World! ";
  11. echo "Hello World! ";
  12. ?>
  13. </body>
  14. </html>
This displays:
Code Copy / Restore
  1. Hello World! Hello World! Hello World! Hello World! Hello World!
Good job!

Whitespace (extra blank spaces) are ignored in HTML and PHP.

And that ends our PHP introduction!


Posted By Relish
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
 
Relish     Posted 135 Days Ago
 
 
This was originally posted on my website, so I decided to post it here.
Page 1 of 1
More Articles By This Author
Introduction To PHP
Recently Posted "Web Development" Articles
Website Optimization
How to use Memcache on Windows
PHP Sessions = Member Database Cache
Speed Up Delivery of your JavaScript Libraries
A cool tool ^^
AJAX - When to use it?
Introduction To PHP
[PHP] XML
HTML vs XHTML
[PHP] XML: HTML DOM Basics
Recently Rated "Web Development" Articles
Website Optimization
How to use Memcache on Windows
Preventing raw PHP leaks on Apache
When to use OOP in PHP
AJAX - When to use it?
Speed Up Delivery of your JavaScript Libraries
[PHP] XML
A cool tool ^^
HTML vs XHTML
Introduction To PHP
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Internet & Web Sites (1)
Life In General (2)
Operating Systems (3)
Other (2)
Programming (48)
Security (10)
Software Development (5)
Web Development (15)
search Search Inside
Web Development
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved