PHP
  Home arrow PHP arrow Page 3 - Sample Chapter: PHP Pocket Reference
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Sample Chapter: PHP Pocket Reference
By: Tim Pabst
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2002-06-15

    Table of Contents:
  • Sample Chapter: PHP Pocket Reference
  • Introduction
  • Installation and Configuration
  • Including Files
  • Arrays
  • Control Structures
  • Functions
  • Showing the Browser and IP Address
  • Web Database Integration
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Sample Chapter: PHP Pocket Reference - Installation and Configuration


    (Page 3 of 10 )

    PHP Version 3 can be installed in two primary ways: as an Apache module on Unix systems or as a CGI script on both Unix and Windows systems. See the installation instructions that come with PHP for full and current information.

    When you are using PHP as an Apache module, PHP processing is triggered by a special MIME type. This is defined in the Apache configuration file with a line similar to:

    AddType application/x-httpd-php3 .php3

    This tells Apache to treat all files that end with the .php3 extension as PHP files, which means that any file with that extension is parsed for PHP tags. The actual extension is completely arbitrary and you are free to change it to whatever you wish to use.

    If you are running PHP as a dynamic shared object (DSO) module, you also need this line in your Apache configuration file:

    LoadModule php3_module modules/libphp3.so

    When you are running PHP as a CGI script (with any web server), PHP processing is still triggered by this special MIME type, but a bit more work is needed. The web server needs to know that it has to redirect the request for the PHP MIME type to the CGI version of PHP. With ApacheNT, for example, this redirect is done with a set of configuration lines like the following:

    ScriptAlias /php3/ "/path-to-php-dir/php.exe"
    AddType application/x-httpd-php3 .php3
    Action application/x-httpd-php3 "/php3/php.exe"


    For IIS, this redirect is set up through the Windows registry. Refer to the PHP installation instructions for full details.

    At runtime, most aspects of PHP can be controlled with the php3.ini file (located in /usr/local/lib by default). For the Apache module version of PHP, this file is read only when the server is started or reinitialized. Changes to this file should be treated the same as changes to Apache's own configuration files. In other words, if you make a change, you need to send your Apache server an HUB or a USR1 signal before the change will take effect.

    Many aspects of PHP can also be controlled on a per-directory basis (or even per-location or per-request) when using the Apache module version. Most of the directives available in the php3.ini file are also available as native Apache directives. The name of a particular directive is the php3.ini name with "php3_" prepended. For a list of all available Apache directives, run your Apache httpd binary with the -h switch.

    Embedding PHP in HTML
    You embed PHP code into a standard HTML page. For example, here's how you can dynamically generate the title of an HTML document:

    <HTML><HEAD><TITLE><?echo $title?></TITLE>
    </HEAD>...


    The <?echo $title?> portion of the document is replaced by the contents of the $title PHP variable. echo is a basic language statement that you can use to output data.

    There are a few different ways that you can embed your PHP code. As you just saw, you can put PHP code between <? and ?> tags:

    <? echo "Hello World"; ?>

    This style is the most common way to embed PHP, but it is a problem if your PHP code needs to co-exist with XML, as XML may use that tagging style itself. If this is the case, you can turn off this style in the php3.ini file with the short_open_tag directive. Another way to embed PHP code is within <?php and ?> tags:

    <?php echo "Hello World"; ?>

    This style is always available and is recommended when your PHP code needs to be portable to many different systems. Embedding PHP within <SCRIPT> tags is another style that is always available:

    <SCRIPT LANGUAGE="php"> echo "Hello World";
    </SCRIPT>


    One final style, where the code is between <% and %> tags, is disabled by default:

    <% echo "Hello World"; %>

    You can turn on this style with the asp_tags directive in your php3.ini file. The style is most useful when you are using Microsoft FrontPage or another HTML authoring tool that prefers that tag style for HTML embedded scripts.

    You can embed multiple statements by separating them with semicolons:

    <?
    echo "Hello World";
    echo "A second statement";
    ?>


    It is legal to switch back and forth between HTML and PHP at any time. For example, if you want to output 100 <BR> tags for some reason, you can do it this way:

    <? for($i=0; $i<100; $i++) { ?>
    <BR>
    <? } ?>


    When you embed PHP code in an HTML file, you need to use the .php3 file extension for that file, so that your web server knows to send the file to PHP for processing. Or, if you have configured your web server to use a different extension for PHP files, use that extension instead.

    When you have PHP code embedded in an HTML page, you can think of that page as being a PHP program. The bits and pieces of HTML and PHP combine to provide the functionality of the program. A collection of pages that contain programs can be thought of as a web application.

    More PHP Articles
    More By Tim Pabst


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek