PHP Pocket Reference

PHP Pocket Reference

3.2 5
by Rasmus Lerdorf
     
 

View All Available Formats & Editions

Simple, to the point, and compact--in fact, exactly what you've come to expect in an O'Reilly Pocket Reference--the second edition of PHP Pocket Reference is thoroughly updated to include the specifics of PHP 4.Written by the founder of the PHP Project, Rasmus Lerdorf, PHP Pocket Reference is both a handy introduction to PHP syntax and structure, and

…  See more details below

Overview

Simple, to the point, and compact--in fact, exactly what you've come to expect in an O'Reilly Pocket Reference--the second edition of PHP Pocket Reference is thoroughly updated to include the specifics of PHP 4.Written by the founder of the PHP Project, Rasmus Lerdorf, PHP Pocket Reference is both a handy introduction to PHP syntax and structure, and a quick reference to the vast array of functions provided by PHP. The quick reference section organizes all the core functions of PHP alphabetically so you can find what you need easily; the slim size means you can keep it handy beside your keyboard for those times when you want to look up a function quickly without closing what you're doing.This valuable little book provides an authoritative overview of PHP packed into a pocket-sized guide that's easy to take anywhere. It is also the ideal companion for O'Reilly's comprehensive book on PHP, Programming PHP.The PHP Pocket Reference an indispensable (and inexpensive) tool for any serious PHP coder.

Read More

Product Details

ISBN-13:
9780596552169
Publisher:
O'Reilly Media, Incorporated
Publication date:
11/11/2002
Sold by:
Barnes & Noble
Format:
NOOK Book
Pages:
140
File size:
1 MB

Read an Excerpt


Installation and Configuration

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.

Read More

Meet the Author


Rasmus Lerdorf started the PHP Project back in 1995 and has been actively involved in PHP development ever since. He has also been involved in a number of other Open Source projects, including being a longtime Apache contributor and foundation member. He lives in Cary, North Carolina with his wife, Christine.

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >

PHP Pocket Reference 3.2 out of 5 based on 0 ratings. 5 reviews.
Anonymous More than 1 year ago
Anonymous More than 1 year ago
Anonymous More than 1 year ago
Anonymous More than 1 year ago
mkorsmo More than 1 year ago
Just a heads up for anyone considering buying this book.