========================================
PHP USER GUIDE
========================================
TABLE OF CONTENTS
Overview
- PHP vs Others
- Hello World Program
Programmer Notes
- Data Types
- Built-in Constants
- Comments
- Naming Conventions
- Using Text
Known Bugs
References
- Books
- Web Sites
- Articles
Legal Notices
========================================
OVERVIEW
----------------------------------------
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.
http://www.servlets.com/soapbox/problems-jsp.html
http://php.weblogs.com/php_versus_perl
http://php.weblogs.com/php_vs_cold_fusion
http://php.weblogs.com/php_asp_7_reasons
http://php.weblogs.com/php_vs_asp
Hello World Program
----------------------------------------
There are four ways to execute a command in a ".php" file.
1. As an XML processing instruction.
2. As an SGML processing instruction.
echo ("Hello World"); ?>
3. As a script.
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:
You entered:
----------------------------------------
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";
else
print "You are not using CGI PHP\n";
?>
========================================
PROGRAMMER NOTES
----------------------------------------
Data Types
----------------------------------------
integer, 4 byte, range is about -2 billion to +2 billion
double, floating point numbers and exponentials
string
array
object
case sensitive
$variable
Built-in Constants
----------------------------------------
TRUE
FALSE
__FILE__
__LINE__
E_ERROR
E_WARNING
E_PARSE
E_NOTICE
Comments
----------------------------------------
// this is a single line comment
# this is also a single line comment
/* this is a
multiline comment */
Naming Conventions
----------------------------------------
Identifiers
Can't begin with a number
are alphanumerics, _, $
Built-in functions and structures are not case-sensitive
Using Text
----------------------------------------
"." = string concatination operator
example
define("EQPT", "Bill's camera");
define("NL", "
\n");
echo("I have ".EQPT.NL);
OUTPUT:
I have Bill's camera
======================================
KNOWN BUGS
--------------------------------------
Problem: Server segfaults when using PHP's virtual directive with PHP file.
Description: When the following code is executed server dumps core:
echo "Hello...";
virtual("include_file.php");
// 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.
========================================
REFERENCES
----------------------------------------
Books
----------------------------------------
Professional PHP Programming, Castagnetto, Rawat, Schumann, Scollo,
and Veliath, Wrox Press Ltd., 1999.
Web Sites
----------------------------------------
http://www.php.net
http://www.zend.com
http://php.weblogs.com/
http://PHPBuilder.com/
Articles
----------------------------------------
http://php.weblogs.com/tuning_apache_unix
***************************************************************************
Legal Notices
The information in this document is subject to change without notice.
WARRANTY DISCLAIMER
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 NOTICES
Copyright 2001-_COPYRIGHT_END_REVISION 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
copyright laws.
TRADEMARK NOTICES
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
other countries.
ACKNOWLEDGEMENTS
This product includes software developed by the Apache Software Foundation.
This documentation is based on information from the Apache Software Foundation
(http://www.apache.org).
This product includes PHP, freely available from (http://www.php.net).