Intranet Journal   Earthweb  
Images Events Jobs Premium Services Media Kit Network Map E-mail Offers Vendor Solutions Webcasts

   Intranet Journal Subjects
Search Earthweb

Privacy Policy



internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

internet commerce
Be a Commerce Partner
















 

[ Home | Discussion Forum | How Do I... | Lotus Notes Intranets | Microsoft SharePoint | Products | Shopping  ]

free news!

PHP Basics


P.G. Daly

2/8/2006

Go to page: 1 2 

Printer Friendly Version

(Editor's note: Intranet Journal is re-running some of our popular tutorials. This one was first published in February.)

This introductory article on PHP will explain what PHP is, how it works, and how you can get started using it.

PHP (Hypertext Preprocessor) is an open source, server-side, HTML embedded scripting language used to create dynamic Web pages. PHP script is embedded within a HTML document and the programmer can jump between HTML and PHP seamlessly within the document while the code remains inaccessible to users since it is processed on the server. It combines the power of CGI scripting with the ease of working within HTML.

PHP offers several key advantages:

  • Cross-platform operability
  • Compatibility with a wide variety of databases
  • Support for most current web servers
  • Communicates with numerous network protocols
  • Not limited to HTML output
  • Strong text processing capabilities

Assuming you have an operating system and Web server setup on your server, PHP installation is fairly easy. Essentially you need to install the PHP processor and have your server associate .php files with it. PHP.net has detailed installation instructions for UNIX/Linux, Windows, and Mac OS on its Web site.

Once you have PHP installed, all you need to do is place your php files in your Web directories and the server will automatically parse them when someone points their web-browser to that page.

Article Tools
  • Print this article
  • E-mail this article
  • Discuss this article
  • Related resources
  • Getting Started with PHP Pages

    The one thing that holds true regardless of the technology you work with is this: the infamous "hello world" is the way to get started. In PHP, our "hello world" would look as follows:

    <html>
     <head>
      <title>Hello World Example</title>
     </head>
     <body>
     <?php echo '<p>Hello World</p>'; ?>
    </body>
    </html>
    
    As you can see, it is essentially a HTML page with one line of PHP code indicated by the opening tag <?php and the closing tag of ?>. It uses the PHP function "echo" to output the content contained within single quotes.

    The beauty of PHP is that you can jump in and out of PHP coding using these tags within your HTML. Like with all text-based code, use a text editor (not a word processor) for best results.

    If you wish to see all your PHP system information and configuration details, add the following line to the PHP file you created above:

    <?php phpinfo(); ?>

    As you would expect, PHP has a complete syntax all its own. From variables to operators to built-in functions, it is pretty much the same as anything else - refer to the reference manual until it becomes second nature. For my next few examples I will be assuming basic web programming knowledge, so if you need to reference something, refer to the complete online manual for PHP at: http://us2.php.net/manual/en/index.php

    A Quick Form

    Let's face it; forms are the cornerstone of almost all web interactivity. As such, let's explore some very basic form processing with PHP to get the hang of it.

    First you create the HTML form and call it form.html

    <html> 
    <head></head> 
    <body> 
    <form action="form_process.php" method="post"> 
    Enter your comments: <input type="text" name="comments" size="30"> <input type="submit" value="Send">
    </form> 
    </body> 
    </html>
    

    If you are familiar with writing CGI to process your forms, you can see that the HTML side is almost identical with the <form action="form_process.php" method="post"> being the critical piece. When a user hits the "Send" button, it calls the .php file entitled form_process.php. This is the file that will be able to capture the input the user entered into the form and "do" something with it (e-mail, display on a page, etc.).

    Let's assume form_process.php is designed to display the user's comments on a Web page. The script would look like:

    <html>
    <head></head>
    <body> 
    

    <?php 
    // get the form data 
    $field1 = $_POST['comments']; 
    // do something with it 
    echo "You said: <i>$field1</i>"; 
    ?>
    

    </body>
    "/html>
    

    Go to page: 1 2 

    Printer Friendly Version


    Other Resources
    from Intranet Journal
  • Intranet Journal Discussion Board
  • Creating a PHP-Based Content Management System
  • PHP: Three Versions, One Promise
  • from JupiterWeb
  • PHPBuilder.com
  • Shining a Light on LAMP (Developer.com)
  • from the Web
  • PHP.net
  • email this page

    Tutorials
    and more at:
    Intranet Journal's Tutorials
    Intranet Journal Favorites

    Creating a PHP-Based Content Management System

    The Spyware Guide

    Introduction to Microsoft SharePoint Portal

    Intranet Journal
    Part of the EarthWeb Network

    Managing Editor
    Intranet Journal

    Tom Dunlap

    EarthWeb Home Page
    Jupitermedia Home Page

    Media Kit



    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers