PHP USER GUIDE
TABLE OF CONTENTS
- PHP vs Others
- Hello World Program
- Data Types
- Built-in Constants
- Naming Conventions
- Using Text
- Web Sites
PHP is a server-side scripting language that allows for easy development
of complex web-based applications. It is open source, runs on many
platforms and has a short learning curve. PHP provides both the
traditional imperative and object-oriented programming styles. Many
built-in features simplify web content generation, session handling,
database connectivity and other such tasks.
PHP vs Others
Compared to JSP it is less complex.
Compared to Perl it has clearer syntax.
Compared to ASP it is multi-platform.
Compared to Cold Fusion it is a full featured language.
Hello World Program
<?php echo ("Hello World") ?>
There are four ways to execute a command in a ".php" file.
1. As an XML processing instruction.
<?php echo ("Hello World"); ?>
2. As an SGML processing instruction.
<? echo ("Hello World"); ?>
3. As a script.
echo ("Hello World");
4. With Active Server Page (ASP) escape characters.
<% echo ("Hello World"); %>
The echo command can be used without parenthesis.
<? echo "Hello"; ?>
Commands end in a semi-colon, ";".
An example of user interaction is:
Enter Company name:
<INPUT TYPE=TEXT NAME= company>
<INPUT TYPE=SUBMIT VALUE="Enter">
<?php echo ($company); ?>
PHP has all the standard programming statements, for example:
$sapi_type = php_sapi_name();
if ($sapi_type == "cgi")
print "You are using CGI PHP\n";
print "You are not using CGI PHP\n";
integer, 4 byte, range is about -2 billion to +2 billion
double, floating point numbers and exponentials
// this is a single line comment
# this is also a single line comment
/* this is a
multiline comment */
Can't begin with a number
are alphanumerics, _, $
Built-in functions and structures are not case-sensitive
"." = string concatination operator
define("EQPT", "Bill's camera");
echo("I have ".EQPT.NL);
I have Bill's camera
Problem: Server segfaults when using PHP's virtual directive with PHP file.
Description: When the following code is executed server dumps core:
// Segmentation fault here...this point never reached.
echo "Back again...";
PHP online reference states that including php file in virtual directives
is not supported, see: http://www.php.net/manual/en/function.virtual.php.
If you intend to use PHP files consider using include or require directives.
Professional PHP Programming, Castagnetto, Rawat, Schumann, Scollo,
and Veliath, Wrox Press Ltd., 1999.
The information in this document is subject to change without notice.
HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS
INFORMATION, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Hewlett-Packard
shall not be liable for errors contained herein or for direct, indirect,
special, incidental or consequential damages in connection with the
furnishing, performance or use of this material.
RESTRICTED RIGHTS LEGEND
Use, duplication or disclosure by the U.S. Government is subject to
restrictions as set forth in subparagraph (c) (1) (ii) of the Rights in
Technical Data and Computer Software clause at DFARS 252.227-7013 for DOD
agencies. Rights for non-DOD U.S. Government Department and Agencies are
as set forth in FAR 52.227-19 (c)(1,2).
Copyright 2001-2006 Hewlett-Packard Development Company, L.P.
This document contains information which is protected by copyright.
All Rights Reserved. Reproduction, adaptation, or translation without
prior written permission is prohibited, except as allowed under the
UNIX is a registered trademark in the United States and other countries,
licensed exclusively through X/Open Company Limited.
Java and all Java-based trademarks and logos are trademarks or
registered trademarks of Sun Microsystems, Inc. in the U.S. and
This product includes software developed by the Apache Software Foundation.
This documentation is based on information from the Apache Software Foundation
This product includes PHP, freely available from (http://www.php.net).