PHP Manual - UP

27 downloads 14524 Views 10MB Size Report
Mar 6, 2003 ... The members of the PHP Documentation Group are listed on the ... phpdoc@lists .php.net [mailto:[email protected]]. ... A simple tutorial .
PHP Manual

by Stig Sæther Bakken, Alexander Aulbach, Egon Schmid, Jim Winstead, Lars Torben Wilson, Rasmus Lerdorf, Andrei Zmievski, and Jouni Ahto

Edited by Stig Sæther Bakken and Egon Schmid

PHP Manual

Published 03-06-2003 Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 the PHP Documentation Group

Copyright Copyright © 1997 - 2003 by the PHP Documentation Group. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder. The members of the PHP Documentation Group are listed on the front page of this manual. In case you would like to contact the group, please write to [email protected] [mailto:[email protected]]. The 'Extending PHP 4.0' section of this manual is copyright © 2000 by Zend Technologies, Ltd. This material may be distributed only subject to the terms

and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/).

Table of Contents Preface ............................................................................................................................................. viii I. Getting Started ................................................................................................................................... 1 1. Introduction .............................................................................................................................. 2 2. A simple tutorial ........................................................................................................................ 5 3. Installation ............................................................................................................................. 10 4. Configuration .......................................................................................................................... 45 5. Security ................................................................................................................................. 54 II. Language Reference ........................................................................................................................ 68 6. Basic syntax ........................................................................................................................... 69 7. Types .................................................................................................................................... 72 8. Variables ................................................................................................................................ 95 9. Constants .............................................................................................................................. 105 10. Expressions .......................................................................................................................... 107 11. Operators ............................................................................................................................. 109 12. Control Structures ................................................................................................................. 116 13. Functions ............................................................................................................................. 131 14. Classes and Objects ............................................................................................................... 138 15. References Explained ............................................................................................................. 151 III. Features ...................................................................................................................................... 155 16. HTTP authentication with PHP ................................................................................................ 156 17. Cookies ............................................................................................................................... 158 18. Handling file uploads ............................................................................................................. 159 19. Using remote files ................................................................................................................. 164 20. Connection handling .............................................................................................................. 166 21. Persistent Database Connections .............................................................................................. 167 22. Safe Mode ........................................................................................................................... 169 23. Using PHP from the command line ........................................................................................... 175 IV. Function Reference ....................................................................................................................... 184 I. Apache-specific Functions ........................................................................................................ 187 II. Array Functions ..................................................................................................................... 199 III. Aspell functions [deprecated] .................................................................................................. 276 IV. BCMath Arbitrary Precision Mathematics Functions ................................................................... 282 V. Bzip2 Compression Functions .................................................................................................. 294 VI. Calendar functions ................................................................................................................ 307 VII. CCVS API Functions ........................................................................................................... 328 VIII. COM support functions for Windows ..................................................................................... 346 IX. Class/Object Functions .......................................................................................................... 364 X. ClibPDF functions ................................................................................................................. 381 XI. Crack functions .................................................................................................................... 458 XII. CURL, Client URL Library Functions ..................................................................................... 465 XIII. Cybercash payment functions ................................................................................................ 491 XIV. Cyrus IMAP administration functions ..................................................................................... 497 XV. Character type functions ....................................................................................................... 505 XVI. Database (dbm-style) abstraction layer functions ...................................................................... 518 XVII. Date and Time functions ..................................................................................................... 538 XVIII. dBase functions ............................................................................................................... 558 XIX. DBM Functions [deprecated] ................................................................................................ 571 XX. dbx functions ...................................................................................................................... 583 XXI. DB++ Functions ................................................................................................................. 596 XXII. Direct IO functions ............................................................................................................ 647 XXIII. Directory functions ........................................................................................................... 658 XXIV. DOM XML functions ....................................................................................................... 670 XXV. .NET functions ................................................................................................................. 760 iv

PHP Manual

XXVI. Error Handling and Logging Functions ................................................................................. 763 XXVII. FrontBase Functions ........................................................................................................ 781 XXVIII. filePro functions ............................................................................................................ 839 XXIX. Filesystem functions ......................................................................................................... 848 XXX. Forms Data Format functions .............................................................................................. 930 XXXI. FriBiDi functions ............................................................................................................. 968 XXXII. FTP functions ................................................................................................................. 971 XXXIII. Function Handling functions .......................................................................................... 1008 XXXIV. Gettext ...................................................................................................................... 1022 XXXV. GMP functions ............................................................................................................. 1033 XXXVI. HTTP functions ........................................................................................................... 1075 XXXVII. Hyperwave functions ................................................................................................... 1084 XXXVIII. Hyperwave API functions ........................................................................................... 1153 XXXIX. iconv functions ............................................................................................................ 1210 XL. Image functions ................................................................................................................. 1217 XLI. IMAP, POP3 and NNTP functions ....................................................................................... 1328 XLII. Informix functions ........................................................................................................... 1405 XLIII. InterBase functions ......................................................................................................... 1448 XLIV. Ingres II functions .......................................................................................................... 1481 XLV. IRC Gateway Functions .................................................................................................... 1503 XLVI. PHP / Java Integration ..................................................................................................... 1530 XLVII. LDAP functions ............................................................................................................ 1536 XLVIII. Mail functions ............................................................................................................. 1585 XLIX. mailparse functions ......................................................................................................... 1592 L. Mathematical Functions ......................................................................................................... 1607 LI. Multi-Byte String Functions .................................................................................................. 1658 LII. MCAL functions ................................................................................................................ 1712 LIII. Mcrypt Encryption Functions .............................................................................................. 1757 LIV. MCVE Payment Functions ................................................................................................. 1800 LV. Mhash Functions ................................................................................................................ 1878 LVI. Mimetype Functions .......................................................................................................... 1886 LVII. Microsoft SQL Server functions ......................................................................................... 1889 LVIII. Ming functions for Flash .................................................................................................. 1922 LIX. Miscellaneous functions ..................................................................................................... 2040 LX. mnoGoSearch Functions ...................................................................................................... 2065 LXI. mSQL functions ............................................................................................................... 2095 LXII. MySQL Functions ........................................................................................................... 2137 LXIII. Improved MySQL Extension ............................................................................................ 2194 LXIV. Mohawk Software session handler functions ........................................................................ 2279 LXV. muscat functions ............................................................................................................. 2302 LXVI. Network Functions ......................................................................................................... 2309 LXVII. Ncurses terminal screen control functions .......................................................................... 2345 LXVIII. Lotus Notes functions ................................................................................................... 2472 LXIX. Unified ODBC functions .................................................................................................. 2488 LXX. Object Aggregation/Composition Functions .......................................................................... 2539 LXXI. Oracle 8 functions .......................................................................................................... 2556 LXXII. OpenSSL functions ........................................................................................................ 2613 LXXIII. Oracle functions ........................................................................................................... 2651 LXXIV. Ovrimos SQL functions ................................................................................................. 2676 LXXV. Output Control Functions ............................................................................................... 2699 LXXVI. Object property and method call overloading ..................................................................... 2716 LXXVII. PDF functions ............................................................................................................ 2720 LXXVIII. Verisign Payflow Pro functions .................................................................................... 2843 LXXIX. PHP Options&Information ............................................................................................. 2852 LXXX. POSIX functions ........................................................................................................... 2908 LXXXI. PostgreSQL functions ................................................................................................... 2942 LXXXII. Process Control Functions ............................................................................................ 3017 LXXXIII. Program Execution functions ....................................................................................... 3033 v

PHP Manual

LXXXIV. Printer functions ........................................................................................................ 3046 LXXXV. Pspell Functions ......................................................................................................... 3080 LXXXVI. GNU Readline .......................................................................................................... 3100 LXXXVII. GNU Recode functions .............................................................................................. 3110 LXXXVIII. Regular Expression Functions (Perl-Compatible) ........................................................... 3115 LXXXIX. qtdom functions ........................................................................................................ 3155 XC. Regular Expression Functions (POSIX Extended) .................................................................... 3159 XCI. Semaphore, Shared Memory and IPC Functions ..................................................................... 3170 XCII. SESAM database functions ............................................................................................... 3190 XCIII. Session handling functions ............................................................................................... 3219 XCIV. Shared Memory Functions ............................................................................................... 3247 XCV. Shockwave Flash functions ............................................................................................... 3256 XCVI. SNMP functions ............................................................................................................. 3329 XCVII. Socket functions ........................................................................................................... 3338 XCVIII. Stream functions .......................................................................................................... 3381 XCIX. String functions ............................................................................................................. 3415 C. Sybase functions .................................................................................................................. 3523 CI. Tokenizer functions ............................................................................................................. 3552 CII. URL Functions .................................................................................................................. 3560 CIII. Variable Functions ............................................................................................................ 3570 CIV. vpopmail functions ........................................................................................................... 3608 CV. W32api functions ............................................................................................................... 3627 CVI. WDDX Functions ............................................................................................................. 3635 CVII. XML parser functions ....................................................................................................... 3644 CVIII. XML-RPC functions ....................................................................................................... 3679 CIX. XSLT functions ................................................................................................................ 3694 CX. YAZ functions .................................................................................................................. 3712 CXI. YP/NIS Functions ............................................................................................................. 3741 CXII. Zip File Functions (Read Only Access) ................................................................................ 3754 CXIII. Zlib Compression Functions ............................................................................................. 3767 V. Extending PHP 4.0 .............................................................................................................................. 24. Overview ........................................................................................................................... 3794 25. Extension Possibilities ......................................................................................................... 3796 26. Source Layout .................................................................................................................... 3798 27. PHP's Automatic Build System .............................................................................................. 3801 28. Creating Extensions ............................................................................................................. 3803 29. Using Extensions ................................................................................................................ 3806 30. Troubleshooting .................................................................................................................. 3807 31. Source Discussion ............................................................................................................... 3808 32. Accepting Arguments .......................................................................................................... 3815 33. Creating Variables ............................................................................................................... 3828 34. Duplicating Variable Contents: The Copy Constructor ............................................................... 3840 35. Returning Values ................................................................................................................ 3841 36. Printing Information ............................................................................................................ 3843 37. Startup and Shutdown Functions ............................................................................................ 3847 38. Calling User Functions ......................................................................................................... 3848 39. Initialization File Support ..................................................................................................... 3850 40. Where to Go from Here ........................................................................................................ 3852 41. Reference: Some Configuration Macros .................................................................................. 3853 42. API Macros ....................................................................................................................... 3854 VI. PHP API: Interfaces for extension writers ........................................................................................ 3855 43. Streams API for PHP Extension Authors ................................................................................. 3856 VII. FAQ: Frequently Asked Questions ................................................................................................ 3906 44. General Information ............................................................................................................ 3907 45. Mailing lists ....................................................................................................................... 3909 46. Obtaining PHP ................................................................................................................... 3911 47. Database issues ................................................................................................................... 3913 48. Installation ......................................................................................................................... 3916 vi

PHP Manual

49. Build Problems ................................................................................................................... 3921 50. Using PHP ......................................................................................................................... 3926 51. PHP and HTML .................................................................................................................. 3930 52. PHP and COM ................................................................................................................... 3933 53. PHP and other languages ...................................................................................................... 3936 54. Migrating from PHP 2 to PHP 3 ............................................................................................. 3937 55. Migrating from PHP 3 to PHP 4 ............................................................................................. 3938 56. Miscellaneous Questions ...................................................................................................... 3939 VIII. Appendixes ............................................................................................................................. 3940 A. History of PHP and related projects ......................................................................................... 3941 B. Migrating from PHP 3 to PHP 4 .............................................................................................. 3944 C. Migrating from PHP/FI 2 to PHP 3 .......................................................................................... 3949 D. Debugging PHP ................................................................................................................... 3953 E. Extending PHP 3 .................................................................................................................. 3956 F. List of Function Aliases ......................................................................................................... 3967 G. List of Reserved Words ......................................................................................................... 3975 H. List of Resource Types .......................................................................................................... 3991 I. List of Supported Protocols/Wrappers ....................................................................................... 4008 J. List of Supported Socket Transports ......................................................................................... 4013 K. PHP type comparison tables ................................................................................................... 4016 L. List of Parser Tokens ............................................................................................................ 4018 M. About the manual ................................................................................................................ 4021 N. Function Index .................................................................................................................... 4025

vii

Preface Abstract PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated webpages quickly, but you can do much more with PHP. This manual consists primarily of a function reference, but also contains a language reference, explanations of some of PHP's major features, and other supplemental information. You can download this manual in several formats at http:/ / www.php.net/ docs.php. The downloads [http:/ / www.php.net/ downloads.php] are updated as the content changes. More information about how this manual is developed can be found in the 'About the manual' appendix. See also PHP History

viii

Part I. Getting Started Table of Contents 1. Introduction ...................................................................................................................................... 2 2. A simple tutorial ................................................................................................................................ 5 3. Installation ..................................................................................................................................... 10 4. Configuration .................................................................................................................................. 45 5. Security ......................................................................................................................................... 54

1

Chapter 1. Introduction Table of Contents What is PHP? ....................................................................................................................................... 2 What can PHP do? ................................................................................................................................ 2

What is PHP? PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Simple answer, but what does that mean? An example:

Example 1.1. An introductory example Example