welcome hpws docs hp-ux webservers home contact hp support
hp logo - invent  hp-ux web server suite

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

<HTML> <?php echo ("Hello World") ?> </HTML> 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. <script language="php"> echo ("Hello World"); </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: <HTML> <FORM> Enter Company name: <BR> <INPUT TYPE=TEXT NAME= company> <BR>
<INPUT TYPE=SUBMIT VALUE="Enter"> </FORM> <BR>
You entered: <?php echo ($company); ?> </HTML> 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", "<BR>\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 ***************************************************************************