home *** CD-ROM | disk | FTP | other *** search
Wrap
Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
<HTML ><HEAD ><TITLE >Manußl PHP</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="book" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="BOOK" ><A NAME="manual" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="manual" ></A >Manußl PHP</H1 ><DIV CLASS="author" >Stig Sæther Bakken</DIV ><DIV CLASS="author" >Alexander Aulbach</DIV ><DIV CLASS="author" >Egon Schmid</DIV ><DIV CLASS="author" >Jim Winstead</DIV ><DIV CLASS="author" >Lars Torben Wilson</DIV ><DIV CLASS="author" >Rasmus Lerdorf</DIV ><DIV CLASS="author" >Andrei Zmievski</DIV ><DIV CLASS="author" >Jouni Ahto</DIV ><H2 CLASS="EDITEDBY" >Sestavil</H2 ><DIV CLASS="editor" >Lukß╣ Jelφnek</DIV ><DIV CLASS="editor" >Jakub Vrßna</DIV ><P CLASS="pubdate" >03-01-2004<BR></P ><P CLASS="copyright" >Copyright © 1997, 1998, 1999, 2000, 2001, 2002 the PHP Documentation Group</P ><DIV CLASS="legalnotice" ><A NAME="copyright" ></A ><P ><B >Copyright</B ></P ><P >
Tento manußl je © Copyright 1997, 1998, 1999, 2000, 2001, 2002 PHP Documentation Group. Seznam Φlen∙ tΘto skupiny je na titulnφ stran∞ tohoto manußlu. </P ><P >
Tento manußl lze redistribuovat podle podmφnek GNU General Public License publikovanΘ Free Software Foundation; bu∩ verzφ 2 tΘto Licence, nebo (dle va╣eho uvß╛enφ) kterΘkoliv pozd∞j╣φ verze. </P ><P >
Sekce tohoto manußlu "Roz╣φ°enφ PHP 4.0" je © 2000 Zend Technologies, Ltd. Tento materißl smφ b²t redistribuovßn pouze za podmφnek specifikovan²ch v Open Publication License v1.0 nebo pozd∞j╣φ (nejnov∞j╣φ verze je v souΦasnosti k dispozici na <A HREF="http://www.opencontent.org/openpub/" TARGET="_top" >http://www.opencontent.org/openpub/</A >). </P ></DIV ><HR></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#preface" >P°edmluva</A ></DT ><DT >I. <A HREF="#getting-started" >ZaΦφnßme</A ></DT ><DD ><DL ><DT >1. <A HREF="#introduction" >Introduction</A ></DT ><DT >2. <A HREF="#tutorial" >A simple tutorial</A ></DT ><DT >3. <A HREF="#installation" >Instalace</A ></DT ><DT >4. <A HREF="#configuration" >Runtime Configuration</A ></DT ></DL ></DD ><DT >II. <A HREF="#langref" >Reference jazyka</A ></DT ><DD ><DL ><DT >5. <A HREF="#language.basic-syntax" >Zßkladnφ syntaxe</A ></DT ><DT >6. <A HREF="#language.types" >Types</A ></DT ><DT >7. <A HREF="#language.variables" >Prom∞nnΘ</A ></DT ><DT >8. <A HREF="#language.constants" >Konstanty</A ></DT ><DT >9. <A HREF="#language.expressions" >V²razy</A ></DT ><DT >10. <A HREF="#language.operators" >Operßtory</A ></DT ><DT >11. <A HREF="#control-structures" >╪φdicφ struktury</A ></DT ><DT >12. <A HREF="#functions" >Funkce</A ></DT ><DT >13. <A HREF="#language.oop" >Classes and Objects</A ></DT ><DT >14. <A HREF="#language.references" >Vysv∞tlenφ referencφ (odkaz∙)</A ></DT ></DL ></DD ><DT >III. <A HREF="#security" >Security</A ></DT ><DD ><DL ><DT >15. <A HREF="#security.index" >Security</A ></DT ></DL ></DD ><DT >IV. <A HREF="#features" >Vlastnosti</A ></DT ><DD ><DL ><DT >16. <A HREF="#features.http-auth" >HTTP autentikace a PHP</A ></DT ><DT >17. <A HREF="#features.cookies" >Cookies</A ></DT ><DT >18. <A HREF="#features.file-upload" >Zpracovßnφ uploadu soubor∙</A ></DT ><DT >19. <A HREF="#features.remote-files" >Pou╛itφ vzdßlen²ch soubor∙</A ></DT ><DT >20. <A HREF="#features.connection-handling" >Obsluha spojenφ</A ></DT ><DT >21. <A HREF="#features.persistent-connections" >Persistentnφ databßzovß spojenφ</A ></DT ><DT >22. <A HREF="#features.safe-mode" >BezpeΦn² re╛im</A ></DT ><DT >23. <A HREF="#features.commandline" >Pou╛itφ PHP z p°φkazovΘ °ßdky</A ></DT ></DL ></DD ><DT >V. <A HREF="#funcref" >Reference funkcφ</A ></DT ><DD ><DL ><DT >I. <A HREF="#ref.apache" >Funkce specifickΘ pro Apache</A ></DT ><DT >II. <A HREF="#ref.array" >Funkce pro prßci s poli</A ></DT ><DT >III. <A HREF="#ref.aspell" >Aspell funkce [zastaralΘ]</A ></DT ><DT >IV. <A HREF="#ref.bc" >BCMath funkce pro v²poΦty s libovolnou p°esnostφ</A ></DT ><DT >V. <A HREF="#ref.bzip2" >Kompresnφ funkce bzip2</A ></DT ><DT >VI. <A HREF="#ref.calendar" >Kalendß°ovΘ funkce</A ></DT ><DT >VII. <A HREF="#ref.ccvs" >CCVS API Functions</A ></DT ><DT >VIII. <A HREF="#ref.com" >Funkce na podporu COM ve Windows</A ></DT ><DT >IX. <A HREF="#ref.classobj" >Funkce pro prßci s t°φdami/objekty</A ></DT ><DT >X. <A HREF="#ref.cpdf" >ClibPDF functions</A ></DT ><DT >XI. <A HREF="#ref.crack" >Crack functions</A ></DT ><DT >XII. <A HREF="#ref.curl" >Funkce pro prßci s CURL, Client URL Library</A ></DT ><DT >XIII. <A HREF="#ref.cybercash" >Cybercash platebnφ funkce</A ></DT ><DT >XIV. <A HREF="#ref.cyrus" >Cyrus IMAP administration functions</A ></DT ><DT >XV. <A HREF="#ref.ctype" >Character type functions</A ></DT ><DT >XVI. <A HREF="#ref.dba" >Database (dbm-style) abstraction layer functions</A ></DT ><DT >XVII. <A HREF="#ref.datetime" >Funkce pro datum a Φas</A ></DT ><DT >XVIII. <A HREF="#ref.dbase" >dBase functions</A ></DT ><DT >XIX. <A HREF="#ref.dbm" >DBM Funkce [zastaralΘ]</A ></DT ><DT >XX. <A HREF="#ref.dbx" >dbx functions</A ></DT ><DT >XXI. <A HREF="#ref.dbplus" >DB++ Functions</A ></DT ><DT >XXII. <A HREF="#ref.dio" >Direct IO functions</A ></DT ><DT >XXIII. <A HREF="#ref.dir" >Adresß°ovΘ funkce</A ></DT ><DT >XXIV. <A HREF="#ref.domxml" >DOM XML functions</A ></DT ><DT >XXV. <A HREF="#ref.dotnet" >.NET functions</A ></DT ><DT >XXVI. <A HREF="#ref.errorfunc" >Error Handling and Logging Functions</A ></DT ><DT >XXVII. <A HREF="#ref.fam" >File alteration monitor functions</A ></DT ><DT >XXVIII. <A HREF="#ref.fbsql" >FrontBase Functions</A ></DT ><DT >XXIX. <A HREF="#ref.filepro" >filePro funkce</A ></DT ><DT >XXX. <A HREF="#ref.filesystem" >Funkce filesystΘmu</A ></DT ><DT >XXXI. <A HREF="#ref.fdf" >Forms Data Format functions</A ></DT ><DT >XXXII. <A HREF="#ref.fribidi" >FriBiDi functions</A ></DT ><DT >XXXIII. <A HREF="#ref.ftp" >FTP functions</A ></DT ><DT >XXXIV. <A HREF="#ref.funchand" >Funkce pro prßci s funkcemi</A ></DT ><DT >XXXV. <A HREF="#ref.gettext" >Gettext</A ></DT ><DT >XXXVI. <A HREF="#ref.gmp" >GMP functions</A ></DT ><DT >XXXVII. <A HREF="#ref.http" >HTTP funkce</A ></DT ><DT >XXXVIII. <A HREF="#ref.hyperwave" >Hyperwave functions</A ></DT ><DT >XXXIX. <A HREF="#ref.hwapi" >Hyperwave API functions</A ></DT ><DT >XL. <A HREF="#ref.iconv" >iconv functions</A ></DT ><DT >XLI. <A HREF="#ref.image" >Image functions</A ></DT ><DT >XLII. <A HREF="#ref.imap" >IMAP, POP3 and NNTP functions</A ></DT ><DT >XLIII. <A HREF="#ref.ifx" >Informix functions</A ></DT ><DT >XLIV. <A HREF="#ref.ibase" >InterBase functions</A ></DT ><DT >XLV. <A HREF="#ref.ingres" >Ingres II functions</A ></DT ><DT >XLVI. <A HREF="#ref.ircg" >IRC Gateway Functions</A ></DT ><DT >XLVII. <A HREF="#ref.java" >PHP / Java Integration</A ></DT ><DT >XLVIII. <A HREF="#ref.ldap" >LDAP functions</A ></DT ><DT >XLIX. <A HREF="#ref.mail" >MailovΘ funkce</A ></DT ><DT >L. <A HREF="#ref.mailparse" >mailparse functions</A ></DT ><DT >LI. <A HREF="#ref.math" >MatematickΘ funkce</A ></DT ><DT >LII. <A HREF="#ref.mbstring" >Multi-Byte String Functions</A ></DT ><DT >LIII. <A HREF="#ref.mcal" >MCAL functions</A ></DT ><DT >LIV. <A HREF="#ref.mcrypt" >Mcrypt Encryption Functions</A ></DT ><DT >LV. <A HREF="#ref.mcve" >MCVE Payment Functions</A ></DT ><DT >LVI. <A HREF="#ref.mhash" >Mhash funkce</A ></DT ><DT >LVII. <A HREF="#ref.mime-magic" >Mimetype Functions</A ></DT ><DT >LVIII. <A HREF="#ref.mssql" >Microsoft SQL Server functions</A ></DT ><DT >LIX. <A HREF="#ref.ming" >Ming functions for Flash</A ></DT ><DT >LX. <A HREF="#ref.misc" >R∙znΘ funkce</A ></DT ><DT >LXI. <A HREF="#ref.mnogo" >mnoGoSearch Functions</A ></DT ><DT >LXII. <A HREF="#ref.msql" >mSQL functions</A ></DT ><DT >LXIII. <A HREF="#ref.mysql" >MySQL funkce</A ></DT ><DT >LXIV. <A HREF="#ref.mysqli" >Improved MySQL Extension</A ></DT ><DT >LXV. <A HREF="#ref.msession" >Mohawk Software session handler functions</A ></DT ><DT >LXVI. <A HREF="#ref.muscat" >muscat functions</A ></DT ><DT >LXVII. <A HREF="#ref.network" >Sφ╗ovΘ funkce</A ></DT ><DT >LXVIII. <A HREF="#ref.ncurses" >Ncurses terminal screen control functions</A ></DT ><DT >LXIX. <A HREF="#ref.notes" >Lotus Notes functions</A ></DT ><DT >LXX. <A HREF="#ref.nsapi" >NSAPI-specific Functions</A ></DT ><DT >LXXI. <A HREF="#ref.odbc" >Unified ODBC functions</A ></DT ><DT >LXXII. <A HREF="#ref.objaggregation" >Object Aggregation/Composition Functions</A ></DT ><DT >LXXIII. <A HREF="#ref.oci8" >Oracle 8 functions</A ></DT ><DT >LXXIV. <A HREF="#ref.openssl" >OpenSSL funkce</A ></DT ><DT >LXXV. <A HREF="#ref.oracle" >Oracle functions</A ></DT ><DT >LXXVI. <A HREF="#ref.ovrimos" >Ovrimos SQL functions</A ></DT ><DT >LXXVII. <A HREF="#ref.outcontrol" >Funkce pro °φzenφ v²stupu</A ></DT ><DT >LXXVIII. <A HREF="#ref.overload" >Object property and method call overloading</A ></DT ><DT >LXXIX. <A HREF="#ref.pdf" >PDF funkce</A ></DT ><DT >LXXX. <A HREF="#ref.pfpro" >Funkce pro prßci s Verisign Payflow Pro</A ></DT ><DT >LXXXI. <A HREF="#ref.info" >PHP volby a informace</A ></DT ><DT >LXXXII. <A HREF="#ref.posix" >POSIX functions</A ></DT ><DT >LXXXIII. <A HREF="#ref.pgsql" >PostgreSQL functions</A ></DT ><DT >LXXXIV. <A HREF="#ref.pcntl" >Process Control Functions</A ></DT ><DT >LXXXV. <A HREF="#ref.exec" >Funkce spou╣t∞nφ program∙</A ></DT ><DT >LXXXVI. <A HREF="#ref.printer" >Printer functions</A ></DT ><DT >LXXXVII. <A HREF="#ref.pspell" >Pspell Functions</A ></DT ><DT >LXXXVIII. <A HREF="#ref.readline" >GNU Readline</A ></DT ><DT >LXXXIX. <A HREF="#ref.recode" >GNU Recode funkce</A ></DT ><DT >XC. <A HREF="#ref.pcre" >Regular Expression Functions (Perl-Compatible)</A ></DT ><DT >XCI. <A HREF="#ref.qtdom" >qtdom functions</A ></DT ><DT >XCII. <A HREF="#ref.regex" >Regular Expression Functions (POSIX Extended)</A ></DT ><DT >XCIII. <A HREF="#ref.sem" >Semaphore, Shared Memory and IPC Functions</A ></DT ><DT >XCIV. <A HREF="#ref.sesam" >SESAM database functions</A ></DT ><DT >XCV. <A HREF="#ref.session" >Session handling functions</A ></DT ><DT >XCVI. <A HREF="#ref.shmop" >Funkce pro prßci se sdφlenou pam∞tφ</A ></DT ><DT >XCVII. <A HREF="#ref.sqlite" >SQLite</A ></DT ><DT >XCVIII. <A HREF="#ref.swf" >Shockwave Flash functions</A ></DT ><DT >XCIX. <A HREF="#ref.snmp" >SNMP functions</A ></DT ><DT >C. <A HREF="#ref.sockets" >Socket functions</A ></DT ><DT >CI. <A HREF="#ref.stream" >Stream functions</A ></DT ><DT >CII. <A HREF="#ref.strings" >Funkce pro prßci s °et∞zci</A ></DT ><DT >CIII. <A HREF="#ref.sybase" >Sybase functions</A ></DT ><DT >CIV. <A HREF="#ref.tidy" >tidy Functions</A ></DT ><DT >CV. <A HREF="#ref.tokenizer" >Tokenizer functions</A ></DT ><DT >CVI. <A HREF="#ref.url" >URL funkce</A ></DT ><DT >CVII. <A HREF="#ref.variables" >Variable Functions</A ></DT ><DT >CVIII. <A HREF="#ref.vpopmail" >vpopmail functions</A ></DT ><DT >CIX. <A HREF="#ref.w32api" >W32api functions</A ></DT ><DT >CX. <A HREF="#ref.wddx" >WDDX funkce</A ></DT ><DT >CXI. <A HREF="#ref.xml" >XML parser functions</A ></DT ><DT >CXII. <A HREF="#ref.xmlrpc" >XML-RPC functions</A ></DT ><DT >CXIII. <A HREF="#ref.xslt" >XSLT funkce</A ></DT ><DT >CXIV. <A HREF="#ref.yaz" >YAZ functions</A ></DT ><DT >CXV. <A HREF="#ref.nis" >Funkce pro prßci s YP/NIS</A ></DT ><DT >CXVI. <A HREF="#ref.zip" >Zip File Functions (Read Only Access)</A ></DT ><DT >CXVII. <A HREF="#ref.zlib" >Zlib Compression Functions</A ></DT ></DL ></DD ><DT >VI. <A HREF="#zend" >Zend API</A ></DT ><DD ><DL ><DT >24. <A HREF="#zend.overview" >Overview</A ></DT ><DT >25. <A HREF="#zend.possibilities" >Extension Possibilities</A ></DT ><DT >26. <A HREF="#zend.layout" >Source Layout</A ></DT ><DT >27. <A HREF="#zend.build" >PHP's Automatic Build System</A ></DT ><DT >28. <A HREF="#zend.creating" >Creating Extensions</A ></DT ><DT >29. <A HREF="#zend.using" >Using Extensions</A ></DT ><DT >30. <A HREF="#zend.troubleshooting" >Troubleshooting</A ></DT ><DT >31. <A HREF="#zend.structure" >Source Discussion</A ></DT ><DT >32. <A HREF="#zend.arguments" >Accepting Arguments</A ></DT ><DT >33. <A HREF="#zend.variables" >Creating Variables</A ></DT ><DT >34. <A HREF="#zend.copy-constructor" >Duplicating Variable Contents: The Copy Constructor</A ></DT ><DT >35. <A HREF="#zend.returning" >Returning Values</A ></DT ><DT >36. <A HREF="#zend.printing" >Printing Information</A ></DT ><DT >37. <A HREF="#zend.startup-and-shutdown" >Startup and Shutdown Functions</A ></DT ><DT >38. <A HREF="#zend.calling-user-functions" >Calling User Functions</A ></DT ><DT >39. <A HREF="#zend.ini-file-support" >Initialization File Support</A ></DT ><DT >40. <A HREF="#zend.where-to-go" >Where to Go from Here</A ></DT ><DT >41. <A HREF="#zend.configuration-macros" >Reference: Some Configuration Macros</A ></DT ><DT >42. <A HREF="#zend.api-macros" >API Macros</A ></DT ></DL ></DD ><DT >VII. <A HREF="#api" >PHP API: Interfaces for extension writers</A ></DT ><DD ><DL ><DT >43. <A HREF="#streams" >Streams API for PHP Extension Authors</A ></DT ></DL ></DD ><DT >VIII. <A HREF="#faq" >FAQ: ╚asto zodpovφdanΘ otßzky</A ></DT ><DD ><DL ><DT >44. <A HREF="#faq.general" >ObecnΘ informace</A ></DT ><DT >45. <A HREF="#faq.mailinglist" >E-mailovΘ konference (mailing lists)</A ></DT ><DT >46. <A HREF="#faq.obtaining" >Zφskßnφ PHP</A ></DT ><DT >47. <A HREF="#faq.databases" >Zßle╛itosti databßzφ</A ></DT ><DT >48. <A HREF="#faq.installation" >Instalace</A ></DT ><DT >49. <A HREF="#faq.build" >Sestavovacφ (kompilaΦnφ) problΘmy</A ></DT ><DT >50. <A HREF="#faq.using" >Pou╛φvßnφ PHP</A ></DT ><DT >51. <A HREF="#faq.html" >PHP a HTML</A ></DT ><DT >52. <A HREF="#faq.com" >PHP a COM</A ></DT ><DT >53. <A HREF="#faq.languages" >PHP a jinΘ jazyky</A ></DT ><DT >54. <A HREF="#faq.migration" >P°echod z PHP 2 na PHP 3</A ></DT ><DT >55. <A HREF="#faq.migration4" >P°echod z PHP 3 na PHP 4</A ></DT ><DT >56. <A HREF="#faq.misc" >Ostatnφ otßzky</A ></DT ></DL ></DD ><DT >IX. <A HREF="#appendixes" >Dodatky</A ></DT ><DD ><DL ><DT >A. <A HREF="#history" >Historie PHP a souvisejφcφch projekt∙</A ></DT ><DT >B. <A HREF="#migration4" >P°echod z PHP 3 na PHP 4</A ></DT ><DT >C. <A HREF="#migration" >P°echod z PHP/FI 2 na PHP 3</A ></DT ><DT >D. <A HREF="#debugger" >Lad∞nφ (debugging) PHP</A ></DT ><DT >E. <A HREF="#phpdevel" >Extending PHP 3</A ></DT ><DT >F. <A HREF="#aliases" >Seznam alias∙ funkcφ</A ></DT ><DT >G. <A HREF="#reserved" >Seznam vyhrazen²ch slov</A ></DT ><DT >H. <A HREF="#resource" >List of Resource Types</A ></DT ><DT >I. <A HREF="#wrappers" >List of Supported Protocols/Wrappers</A ></DT ><DT >J. <A HREF="#transports" >List of Supported Socket Transports</A ></DT ><DT >K. <A HREF="#types.comparisons" >PHP type comparison tables</A ></DT ><DT >L. <A HREF="#tokens" >List of Parser Tokens</A ></DT ><DT >M. <A HREF="#about" >O tomto manußlu</A ></DT ><DT >N. <A HREF="#opl.license" >Open Publication License</A ></DT ><DT >O. <A HREF="#indexes" >Rejst°φk funkcφ</A ></DT ><DT >P. <A HREF="#missing-stuff" >Co zde chybφ</A ></DT ></DL ></DD ></DL ></DIV ><DIV CLASS="preface" ><HR><H1 ><A NAME="preface" >P°edmluva</A ></H1 ><BLOCKQUOTE CLASS="ABSTRACT" ><DIV CLASS="abstract" ><A NAME="AEN53" ></A ><P ></P ><P >
<SPAN CLASS="acronym" >PHP</SPAN >, co╛ znamenß "PHP: Hypertext Preprocessor", je ╣iroce pou╛φvan² mnoho·Φelov² skriptovacφ jazyk, ╣φ°en² pod Open Source licencφ, zvlß╣╗ vhodn² pro v²voj WWW aplikacφ a zp∙sobil² pro vklßdßnφ do HTML. Velkß Φßst jeho syntaxe je vyp∙jΦenß z C, Javy a Perlu. Cφlem tohoto jazyka je je umo╛nit webov²m v²vojß°um rychle psßt dynamicky generovanΘ strßnky - ale s PHP m∙╛ete d∞lat mnohem vφc! </P ><P ></P ></DIV ></BLOCKQUOTE ><P >
Tento manußl je tvo°en p°edev╣φm referenΦnφ p°φruΦkou funkcφ, ale obsahuje takΘ refereΦnφ p°φruΦku jazyka, vysv∞tlenφ hlavnφch vlastnostφ a mo╛nostφ PHP a r∙znΘ dopl≥kovΘ informace. </P ><P >
Manußl si m∙╛ete stßhnout v r∙zn²ch formßtech na <A HREF="http://www.php.net/docs.php" TARGET="_top" >http://www.php.net/docs.php</A >. Soubory ke sta╛enφ se aktualizujφ v╛dy p°i zm∞n∞ obsahu. Vφce informacφ o tom, jak je tento manußl vytvß°en, najdete v dodatku <A HREF="#about" >'O manußlu'</A >. </P ></DIV ><DIV CLASS="PART" ><A NAME="getting-started" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >I. ZaΦφnßme</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT >1. <A HREF="#introduction" >Introduction</A ></DT ><DT >2. <A HREF="#tutorial" >A simple tutorial</A ></DT ><DT >3. <A HREF="#installation" >Instalace</A ></DT ><DT >4. <A HREF="#configuration" >Runtime Configuration</A ></DT ></DL ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="introduction" >Kapitola 1. Introduction</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="intro-whatis" ></A >What is PHP?</H2 ><P >
<SPAN CLASS="acronym" >PHP</SPAN > (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. </P ><P >
Simple answer, but what does that mean? An example: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN70" ></A ><P ><B >P°φklad 1-1. An introductory example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><html> <head> <title>Example</title> </head> <body> <?php echo "Hi, I'm a PHP script!"; ?> </body> </html></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Notice how this is different from a script written in other languages like Perl or C -- instead of writing a program with lots of commands to output HTML, you write an HTML script with some embedded code to do something (in this case, output some text). The PHP code is enclosed in special <A HREF="#language.basic-syntax.phpmode" >start and end tags</A > that allow you to jump into and out of "PHP mode". </P ><P >
What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server. If you were to have a script similar to the above on your server, the client would receive the results of running that script, with no way of determining what the underlying code may be. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve. </P ><P >
The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid reading the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours. </P ><P >
Although PHP's development is focused on server-side scripting, you can do much more with it. Read on, and see more in the <A HREF="#intro-whatcando" >What can PHP do?</A > section. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="intro-whatcando" ></A >What can PHP do?</H2 ><P >
Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more. </P ><P >
There are three main fields where PHP scripts are used. <P ></P ><UL ><LI ><P >
Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work. The PHP parser (CGI or server module), a webserver and a web browser. You need to run the webserver, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. See the <A HREF="#installation" >installation instructions</A > section for more information. </P ></LI ><LI ><P >
Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks. See the section about <A HREF="#features.commandline" >Command line usage of PHP</A > for more information. </P ></LI ><LI ><P >
Writing client-side GUI applications. PHP is probably not the very best language to write windowing applications, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in PHP-GTK, visit <A HREF="http://gtk.php.net/" TARGET="_top" >its own website</A >. </P ></LI ></UL > </P ><P >
PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. For the majority of the servers PHP has a module, for the others supporting the CGI standard, PHP can work as a CGI processor. </P ><P >
So with PHP, you have the freedom of choosing an operating system and a web server. Furthermore, you also have the choice of using procedural programming or object oriented programming, or a mixture of them. Although not every standard OOP feature is realized in the current version of PHP, many code libraries and large applications (including the PEAR library) are written only using OOP code. </P ><P >
With PHP you are not limited to output HTML. PHP's abilities includes outputting images, PDF files and even Flash movies (using libswf and Ming) generated on the fly. You can also output easily any text, such as XHTML and any other XML file. PHP can autogenerate these files, and save them in the file system, instead of printing it out, forming a server-side cache for your dynamic content. </P ><P >
One of the strongest and most significant feature in PHP is its support for a wide range of databases. Writing a database-enabled web page is incredibly simple. The following databases are currently supported: <A NAME="AEN97" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >Adabas D</TD ><TD >Ingres</TD ><TD >Oracle (OCI7 and OCI8)</TD ></TR ><TR ><TD >dBase</TD ><TD >InterBase</TD ><TD >Ovrimos</TD ></TR ><TR ><TD >Empress</TD ><TD >FrontBase</TD ><TD >PostgreSQL</TD ></TR ><TR ><TD >FilePro (read-only)</TD ><TD >mSQL</TD ><TD >Solid</TD ></TR ><TR ><TD >Hyperwave</TD ><TD >Direct MS-SQL</TD ><TD >Sybase</TD ></TR ><TR ><TD >IBM DB2</TD ><TD >MySQL</TD ><TD >Velocis</TD ></TR ><TR ><TD >Informix</TD ><TD >ODBC</TD ><TD >Unix dbm</TD ></TR ></TBODY ></TABLE ><P ></P ></BLOCKQUOTE > We also have a DBX database abstraction extension allowing you to transparently use any database supported by that extension. Additionally PHP supports ODBC, the Open Database Connection standard, so you can connect to any other database supporting this world standard. </P ><P >
PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects. You can also use our CORBA extension to access remote objects. </P ><P >
PHP has extremely useful text processing features, from the POSIX Extended or Perl regular expressions to parsing XML documents. For parsing and accessing XML documents, we support the SAX and DOM standards. You can use our XSLT extension to transform XML documents. </P ><P >
While using PHP in the e-commerce field, you'll find the Cybercash payment, CyberMUT, VeriSign Payflow Pro and CCVS functions useful for your online payment programs. </P ><P >
At last but not least, we have many other interesting extensions, the mnoGoSearch search engine functions, the IRC Gateway functions, many compression utilities (gzip, bz2), calendar conversion, translation... </P ><P >
As you can see this page is not enough to list all the features and benefits PHP can offer. Read on in the sections about <A HREF="#installation" >installing PHP</A >, and see the <A HREF="#funcref" >function reference</A > part for explanation of the extensions mentioned here. </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="tutorial" >Kapitola 2. A simple tutorial</A ></H1 ><P >
Here we would like to show the very basics of PHP in a short, simple tutorial. This text only deals with dynamic webpage creation with PHP, though PHP is not only capable of creating webpages. See the section titled <A HREF="#intro-whatcando" >What can PHP do</A > for more information. </P ><P >
PHP-enabled web pages are treated just like regular HTML pages and you can create and edit them the same way you normally create regular HTML pages. </P ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="tutorial.requirements" ></A >What do I need?</H2 ><P >
In this tutorial we assume that your server has activated support for PHP and that all files ending in <TT CLASS="filename" >.php</TT > are handled by PHP. On most servers, this is the default extension for PHP files, but ask your server administrator to be sure. If your server supports PHP, then you do not need to do anything. Just create your <TT CLASS="filename" >.php</TT > files, put them in your web directory and the server will automatically parse them for you. There is no need to compile anything nor do you need to install any extra tools. Think of these PHP-enabled files as simple HTML files with a whole new family of magical tags that let you do all sorts of things. Most web hosts offer PHP support, but if your host does not consider reading the <A HREF="http://www.php.net/links.php" TARGET="_top" >
PHP Links</A > section for resources on finding PHP enabled web hosts. </P ><P >
Let us say you want to save precious bandwidth and develop locally. In this case, you will want to install a web server, such as <A HREF="#install.apache" >Apache</A >, and of course <A HREF="http://www.php.net/downloads.php" TARGET="_top" >PHP</A >. You will most likely want to install a database as well, such as <A HREF="http://www.mysql.com/documentation/" TARGET="_top" >MySQL</A >. You can either install these individually or choose a simpler way. <A HREF="http://www.hotscripts.com/PHP/Software_and_Servers/Installation_Kits/" TARGET="_top" >Locate a pre-configured package</A > which automatically installs all of these with just a few mouse clicks. It is easy to setup a web server with PHP support on any operating system, including Linux and Windows. On Linux, you may find <A HREF="http://www.rpmfind.net/" TARGET="_top" >rpmfind</A > and <A HREF="http://rpm.pbone.net/" TARGET="_top" >PBone</A > helpful for locating RPMs. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="tutorial.firstpage" ></A >Your first PHP-enabled page</H2 ><P >
Create a file named <TT CLASS="filename" >hello.php</TT > and put it in your web servers root directory (<TT CLASS="varname" >DOCUMENT_ROOT</TT >) with the following content: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN151" ></A ><P ><B >P°φklad 2-1. Our first PHP script: <TT CLASS="filename" >hello.php</TT ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><html> <head> <title>PHP Test</title> </head> <body> <?php echo "<p>Hello World</p>"; ?> </body> </html></PRE ></TD ></TR ></TABLE ><P >
Use your browser to access the file with your web access URL, ending with the "/hello.php" file reference. When developing locally this url will be something like <TT CLASS="literal" >http://localhost/hello.php</TT > or <TT CLASS="literal" >http://127.0.0.1/hello.php</TT > but this depends on the web servers configuration. Although this is outside the scope of this tutorial, see also the <TT CLASS="varname" >DocumentRoot</TT > and <TT CLASS="varname" >ServerName</TT > directives in your web server's configuration file (for Apache, this is <TT CLASS="filename" >httpd.conf</TT >). If everything is configured correctly, this file will be parsed by PHP and the following output will be sent to your browser: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" ><html> <head> <title>PHP Test</title> </head> <body> <p>Hello World</p> </body> </html></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Note that this is not like a CGI script. The file does not need to be executable or special in any way. Think of it as a normal HTML file which happens to have a set of special tags available to you that do a lot of interesting things. </P ><P >
This program is extremely simple and you really did not need to use PHP to create a page like this. All it does is display: <TT CLASS="literal" >Hello World</TT > using the PHP <A HREF="#function.echo" ><B CLASS="function" >echo()</B ></A > statement. </P ><P >
If you tried this example and it did not output anything, or it prompted for download, or you see the whole file as text, chances are that the server you are on does not have PHP enabled. Ask your administrator to enable it for you using the <A HREF="#installation" >Installation</A > chapter of the manual. If you are developing locally, also read the installation chapter to make sure everything is configured properly. If problems continue to persist, do not hesitate to use one of the many <A HREF="http://www.php.net/support.php" TARGET="_top" >PHP support</A > options. </P ><P >
The point of the example is to show the special PHP tag format. In this example we used <TT CLASS="literal" ><?php</TT > to indicate the start of a PHP tag. Then we put the PHP statement and left PHP mode by adding the closing tag, <TT CLASS="literal" >?></TT >. You may jump in and out of PHP mode in an HTML file like this all you want. For more details, read the manual section on <A HREF="#language.basic-syntax" >
basic PHP syntax</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >A Note on Text Editors: </B > There are many text editors and Integrated Development Environments (IDEs) that you can use to create, edit and manage PHP files. A partial list of these tools is maintained at <A HREF="http://phpeditors.linuxbackup.co.uk/" TARGET="_top" >PHP Editor's List</A >. If you wish to recommend an editor, please visit the above page and ask the page maintainer to add the editor to the list. Having an editor with syntax highlighting can be helpful. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >A Note on Word Processors: </B > Word processors such as StarOffice Writer, Microsoft Word and Abiword are not optimal for editing PHP files. If you wish to use one for this test script, you must ensure that you save the file as PLAIN TEXT or PHP will not be able to read and execute the script. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >A Note on Windows Notepad: </B > If you are writing your PHP scripts using Windows Notepad, you will need to ensure that your files are saved with the .php extension. (Notepad adds a .txt extension to files automatically unless you take one of the following steps to prevent it.) When you save the file and are prompted to provide a name for the file, place the filename in quotes (i.e. "<TT CLASS="filename" >hello.php</TT >"). Alternately, you can click on the 'Text Documents' drop-down menu in the save dialog box and change the setting to "All Files". You can then enter your filename without quotes. </P ></BLOCKQUOTE ></DIV ><P >
Now that you have successfully created a working PHP script, it is time to create the most famous PHP script! Make a call to the <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A > function and you will see a lot of useful information about your system and setup such as available <A HREF="#language.variables.predefined" >predefined variables</A >, loaded PHP modules, and <A HREF="#configuration" >configuration</A > settings. Take some time and review this important information. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="tutorial.useful" ></A >Something Useful</H2 ><P >
Let us do something more useful now. We are going to check what sort of browser the visitor is using. For that, we check the user agent string the browser sends as part of the HTTP request. This information is stored in a <A HREF="#language.variables" >variable</A >. Variables always start with a dollar-sign in PHP. The variable we are interested in right now is <TT CLASS="varname" >$_SERVER["HTTP_USER_AGENT"]</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <A HREF="#reserved.variables.server" >$_SERVER</A > is a special reserved PHP variable that contains all web server information. It is known as an autoglobal (or superglobal). See the related manual page on <A HREF="#language.variables.superglobals" >autoglobals</A > for more information. These special variables were introduced in PHP <A HREF="http://www.php.net/release_4_1_0.php" TARGET="_top" >4.1.0</A >. Before this time, we used the older <TT CLASS="varname" >$HTTP_*_VARS</TT > arrays instead, such as <TT CLASS="varname" >$HTTP_SERVER_VARS</TT >. Although deprecated, these older variables still exist. (See also the note on <A HREF="#tutorial.oldcode" >old code</A >.) </P ></BLOCKQUOTE ></DIV ><P >
To display this variable, you can simply do: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN203" ></A ><P ><B >P°φklad 2-2. Printing a variable (Array element)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo $_SERVER["HTTP_USER_AGENT"]; ?></PRE ></TD ></TR ></TABLE ><P >
A sample output of this script may be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" >Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
There are many <A HREF="#language.types" >types</A > of variables available in PHP. In the above example we printed an <A HREF="#language.types.array" >Array</A > element. Arrays can be very useful. </P ><P >
<TT CLASS="varname" >$_SERVER</TT > is just one variable that is automatically made available to you by PHP. A list can be seen in the <A HREF="#reserved.variables" >Reserved Variables</A > section of the manual or you can get a complete list of them by creating a file that looks like this: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN215" ></A ><P ><B >P°φklad 2-3. Show all predefined variables with <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php phpinfo(); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
When you load up this file in your browser, you will see a page full of information about PHP along with a list of all the variables available to you. </P ><P >
You can put multiple PHP statements inside a PHP tag and create little blocks of code that do more than just a single echo. For example, if you want to check for Internet Explorer you can do this: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN222" ></A ><P ><B >P°φklad 2-4. Example using <A HREF="#control-structures" >control structures</A > and <A HREF="#functions" >functions</A ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php if (strpos($_SERVER["HTTP_USER_AGENT"], "MSIE") !== false) { echo "You are using Internet Explorer<br />"; } ?></PRE ></TD ></TR ></TABLE ><P >
A sample output of this script may be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" >You are using Internet Explorer<br /></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Here we introduce a couple of new concepts. We have an <A HREF="#control-structures.if" >if</A > statement. If you are familiar with the basic syntax used by the C language, this should look logical to you. Otherwise, you should probably pick up any introductory PHP book and read the first couple of chapters, or read the <A HREF="#langref" >Language Reference</A > part of the manual. You can find a list of PHP books at <A HREF="http://www.php.net/books.php" TARGET="_top" >http://www.php.net/books.php</A >. </P ><P >
The second concept we introduced was the <A HREF="#function.strpos" ><B CLASS="function" >strpos()</B ></A > function call. <A HREF="#function.strpos" ><B CLASS="function" >strpos()</B ></A > is a function built into PHP which searches a string for another string. In this case we are looking for <TT CLASS="literal" >"MSIE"</TT > (so-called needle) inside <TT CLASS="varname" >$_SERVER["HTTP_USER_AGENT"]</TT > (so-called haystack). If the needle is found inside the haystack, the function returns the position of the needle relative to the start of the haystack. Otherwise, it returns <TT CLASS="constant" ><B >FALSE</B ></TT >. If it does not return <TT CLASS="constant" ><B >FALSE</B ></TT >, the <A HREF="#control-structures.if" >if</A > expression evaluates to <TT CLASS="constant" ><B >TRUE</B ></TT > and the code within its {braces} is executed. Otherwise, the code is not run. Feel free to create similar examples, with <A HREF="#control-structures.if" >if</A >, <A HREF="#control-structures.else" >else</A >, and other functions such as <A HREF="#function.strtoupper" ><B CLASS="function" >strtoupper()</B ></A > and <A HREF="#function.strlen" ><B CLASS="function" >strlen()</B ></A >. Each related manual page contains examples too. If you are unsure how to use functions, you will want to read both the manual page on <A HREF="#about.prototypes" >how to read a function definition</A > and the section about <A HREF="#functions" >PHP functions</A >. </P ><P >
We can take this a step further and show how you can jump in and out of PHP mode even in the middle of a PHP block: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN250" ></A ><P ><B >P°φklad 2-5. Mixing both HTML and PHP modes</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php if (strpos($_SERVER["HTTP_USER_AGENT"], "MSIE") !== false) { ?> <h3>strpos must have returned non-false</h3> <center><b>You are using Internet Explorer</b></center> <?php } else { ?> <h3>strpos must have returned false</h3> <center><b>You are not using Internet Explorer</b></center> <?php } ?></PRE ></TD ></TR ></TABLE ><P >
A sample output of this script may be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" ><h3>strpos must have returned non-false</h3> <center><b>You are using Internet Explorer</b></center></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Instead of using a PHP echo statement to output something, we jumped out of PHP mode and just sent straight HTML. The important and powerful point to note here is that the logical flow of the script remains intact. Only one of the HTML blocks will end up getting sent to the viewer depending on the result of <A HREF="#function.strpos" ><B CLASS="function" >strpos()</B ></A >. In other words, it depends on whether the string <TT CLASS="literal" >MSIE</TT > was found or not. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="tutorial.forms" ></A >Dealing with Forms</H2 ><P >
One of the most powerful features of PHP is the way it handles HTML forms. The basic concept that is important to understand is that any form element in a form will automatically be available to your PHP scripts. Please read the manual section on <A HREF="#language.variables.external" >Variables from outside of PHP</A > for more information and examples on using forms with PHP. Here is an example HTML form: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN263" ></A ><P ><B >P°φklad 2-6. A simple HTML form</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" ><form action="action.php" method="POST"> Your name: <input type="text" name="name" /> Your age: <input type="text" name="age" /> <input type="submit"> </form></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
There is nothing special about this form. It is a straight HTML form with no special tags of any kind. When the user fills in this form and hits the submit button, the <TT CLASS="filename" >action.php</TT > page is called. In this file you would have something like this: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN269" ></A ><P ><B >P°φklad 2-7. Printing data from our form</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >Hi <?php echo $_POST["name"]; ?>. You are <?php echo $_POST["age"]; ?> years old.</PRE ></TD ></TR ></TABLE ><P >
A sample output of this script may be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" >Hi Joe. You are 22 years old.</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
It should be obvious what this does. There is nothing more to it. The <TT CLASS="varname" >$_POST["name"]</TT > and <TT CLASS="varname" >$_POST["age"]</TT > variables are automatically set for you by PHP. Earlier we used the <TT CLASS="varname" >$_SERVER</TT > autoglobal, now above we just introduced the <A HREF="#reserved.variables.post" >$_POST</A > autoglobal which contains all POST data. Notice how the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >method</I ></SPAN > of our form is POST. If we used the method <SPAN CLASS="emphasis" ><I CLASS="emphasis" >GET</I ></SPAN > then our form information would live in the <A HREF="#reserved.variables.get" >$_GET</A > autoglobal instead. You may also use the <A HREF="#reserved.variables.request" >$_REQUEST</A > autoglobal, if you do not care about the source of your request data. It contains the merged information of GET, POST and COOKIE data. Also see the <A HREF="#function.import-request-variables" ><B CLASS="function" >import_request_variables()</B ></A > function. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="tutorial.oldcode" ></A >Using old code with new versions of PHP</H2 ><P >
Now that PHP has grown to be a popular scripting language, there are a lot of public repositories/libraries containing code you can reuse. The PHP developers have largely tried to preserve backwards compatibility, so a script written for an older version will run (ideally) without changes in a newer version of PHP. In practice, some changes will usually be needed. </P ><P >
Two of the most important recent changes that affect old code are: <P ></P ><UL ><LI ><P >
The deprecation of the old <TT CLASS="varname" >$HTTP_*_VARS</TT > arrays (which need to be indicated as global when used inside a function or method). The following <A HREF="#language.variables.superglobals" >autoglobal arrays</A > were introduced in PHP <A HREF="http://www.php.net/release_4_1_0.php" TARGET="_top" >4.1.0</A >. They are: <TT CLASS="varname" >$_GET</TT >, <TT CLASS="varname" >$_POST</TT >, <TT CLASS="varname" >$_COOKIE</TT >, <TT CLASS="varname" >$_SERVER</TT >, <TT CLASS="varname" >$_FILES</TT >, <TT CLASS="varname" >$_ENV</TT >, <TT CLASS="varname" >$_REQUEST</TT >, and <TT CLASS="varname" >$_SESSION</TT >. The older <TT CLASS="varname" >$HTTP_*_VARS</TT > arrays, such as <TT CLASS="varname" >$HTTP_POST_VARS</TT >, still exist and have since PHP 3. Od PHP 5.0.0 mohou b²t dlouhΘ <A HREF="#language.variables.predefined" >p°eddefinovanΘ pole</A > zakßzanΘ direktivou <A HREF="#ini.register-long-arrays" >register_long_arrays</A >. </P ></LI ><LI ><P >
External variables are no longer registered in the global scope by default. In other words, as of PHP <A HREF="http://www.php.net/release_4_2_0.php" TARGET="_top" >4.2.0</A > the PHP directive <A HREF="#ini.register-globals" >register_globals</A > is <SPAN CLASS="emphasis" ><I CLASS="emphasis" >off</I ></SPAN > by default in <TT CLASS="filename" >php.ini</TT >. The preferred method of accessing these values is via the autoglobal arrays mentioned above. Older scripts, books, and tutorials may rely on this directive being on. If on, for example, one could use <TT CLASS="varname" >$id</TT > from the URL <TT CLASS="literal" >http://www.example.com/foo.php?id=42</TT >. Whether on or off, <TT CLASS="varname" >$_GET['id']</TT > is available. </P ></LI ></UL > For more details on these changes, see the section on <A HREF="#language.variables.predefined" >predefined variables</A > and links therein. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="tutorial.whatsnext" ></A >What's next?</H2 ><P >
With your new knowledge you should be able to understand most of the manual and also the various example scripts available in the example archives. You can also find other examples on the php.net websites in the links section: <A HREF="http://www.php.net/links.php" TARGET="_top" >http://www.php.net/links.php</A >. </P ><P >
To view various slide presentations that show more of what PHP can do, see the PHP Conference Material Sites: <A HREF="http://conf.php.net/" TARGET="_top" >
http://conf.php.net/</A > and <A HREF="http://talks.php.net/" TARGET="_top" >http://talks.php.net/ </A > </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="installation" >Kapitola 3. Instalace</A ></H1 ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.general" ></A >General Installation Considerations</H2 ><P >
Before installing first, you need to know what do you want to use PHP for. There are three main fields you can use PHP, as described in the <A HREF="#intro-whatcando" >What can PHP do?</A > section: <P ></P ><UL ><LI ><P >Server-side scripting</P ></LI ><LI ><P >Command line scripting</P ></LI ><LI ><P >Client-side GUI applications</P ></LI ></UL > </P ><P >
For the first and most common form, you need three things: PHP itself, a web server and a web browser. You probably already have a web browser, and depending on your operating system setup, you may also have a web server (e.g. Apache on Linux or IIS on Windows). You may also rent webspace at a company. This way, you don't need to set up anything on your own, only write your PHP scripts, upload it to the server you rent, and see the results in your browser. </P ><P >
While setting up the server and PHP on your own, you have two choices for the method of connecting PHP to the server. For many servers PHP has a direct module interface (also called SAPI). These servers include Apache, Microsoft Internet Information Server, Netscape and iPlanet servers. Many other servers have support for ISAPI, the Microsoft module interface (OmniHTTPd for example). If PHP has no module support for your web server, you can always use it as a CGI processor. This means you set up your server to use the command line executable of PHP (<TT CLASS="filename" >php.exe</TT > on Windows) to process all PHP file requests on the server. </P ><P >
If you are also interested to use PHP for command line scripting (e.g. write scripts autogenerating some images for you offline, or processing text files depending on some arguments you pass to them), you always need the command line executable. For more information, read the section about <A HREF="#features.commandline" >writing command line PHP applications</A >. In this case, you need no server and no browser. </P ><P >
With PHP you can also write client side GUI applications using the PHP-GTK extension. This is a completely different approach than writing web pages, as you do not output any HTML, but manage windows and objects within them. For more information about PHP-GTK, please <A HREF="http://gtk.php.net/" TARGET="_top" >visit the site dedicated to this extension</A >. PHP-GTK is not included in the official PHP distribution. </P ><P >
From now on, this section deals with setting up PHP for web servers on Unix and Windows with server module interfaces and CGI executables. </P ><P >
Downloading PHP, the source code, and binary distributions for Windows can be found at <A HREF="http://www.php.net/downloads.php" TARGET="_top" >http://www.php.net/downloads.php</A >. We recommend you to choose a <A HREF="http://www.php.net/mirrors.php" TARGET="_top" >mirror</A > nearest to you for downloading the distributions. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.hpux" ></A >Unix/HP-UX installs</H2 ><P >
This section contains notes and hints specific to installing PHP on HP-UX systems. (Contributed by paul_mckay at clearwater-it dot co dot uk). </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > These tips were written for PHP 4.0.4 and Apache 1.3.9. </P ></BLOCKQUOTE ></DIV ><P >
<P ></P ><OL TYPE="1" ><LI ><P >
You need gzip, download a binary distribution from <TT CLASS="filename" >http://hpux.connect.org.uk/ftp/hpux/Gnu/gzip-1.2.4a/gzip-1.2.4a-sd-10.20.depot.Z</TT > uncompress the file and install using swinstall. </P ></LI ><LI ><P >
You need gcc, download a binary distribution from <TT CLASS="filename" >http://gatekeep.cs.utah.edu/ftp/hpux/Gnu/gcc-2.95.2/gcc-2.95.2-sd-10.20.depot.gz</TT >. uncompress this file and install gcc using swinstall. </P ></LI ><LI ><P >
You need the GNU binutils, you can download a binary distribution from <TT CLASS="filename" >http://hpux.connect.org.uk/ftp/hpux/Gnu/binutils-2.9.1/binutils-2.9.1-sd-10.20.depot.gz</TT >. uncompress this file and install binutils using swinstall. </P ></LI ><LI ><P >
You now need bison, you can download a binary distribution from <TT CLASS="filename" >http://hpux.connect.org.uk/ftp/hpux/Gnu/bison-1.28/bison-1.28-sd-10.20.depot.gz</TT >, install as above. </P ></LI ><LI ><P >
You now need flex, you need to download the source from one of the http://www.gnu.org mirrors. It is in the non-gnu directory of the ftp site. Download the file, <B CLASS="command" >gunzip</B >, then <B CLASS="command" >tar -xvf</B > it. Go into the newly created flex directory and run <B CLASS="command" >./configure</B >, followed by <B CLASS="command" >make</B >, and then <B CLASS="command" >make install</B >. </P ><P >
If you have errors here, it's probably because gcc etc. are not in your PATH so add them to your PATH. </P ></LI ><LI ><P >
Download the PHP and apache sources. </P ></LI ><LI ><P >
<B CLASS="command" >gunzip</B > and <B CLASS="command" >tar -xvf</B > them. We need to hack a couple of files so that they can compile OK. </P ></LI ><LI ><P >
Firstly the configure file needs to be hacked because it seems to lose track of the fact that you are a hpux machine, there will be a better way of doing this but a cheap and cheerful hack is to put <TT CLASS="literal" >lt_target=hpux10.20</TT > on line 47286 of the configure script. </P ></LI ><LI ><P >
Next, the Apache GuessOS file needs to be hacked. Under <TT CLASS="filename" >apache_1.3.9/src/helpers</TT > change line 89 from <TT CLASS="literal" >echo "hp${HPUXMACH}-hpux${HPUXVER}"; exit 0</TT > to: <TT CLASS="literal" >echo "hp${HPUXMACH}-hp-hpux${HPUXVER}"; exit 0</TT > </P ></LI ><LI ><P >
You cannot install PHP as a shared object under HP-UX so you must compile it as a static, just follow the instructions at the Apache page. </P ></LI ><LI ><P >
PHP and Apache should have compiled OK, but Apache won't start. you need to create a new user for Apache, e.g. www, or apache. You then change lines 252 and 253 of the <TT CLASS="filename" >conf/httpd.conf</TT > in Apache so that instead of </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >User nobody Group nogroup</PRE ></TD ></TR ></TABLE ><P >
you have something like </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >User www Group sys</PRE ></TD ></TR ></TABLE ><P >
This is because you can't run Apache as nobody under hp-ux. Apache and PHP should then work. </P ></LI ></OL > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.linux" ></A >Unix/Linux installs</H2 ><P >
This section contains notes and hints specific to installing PHP on Linux distributions. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.linux.packages" ></A >Using Packages</H3 ><P >
Many Linux distributions have some sort of package installation system, such as RPM. This can assist in setting up a standard configuration, but if you need to have a different set of features (such as a secure server, or a different database driver), you may need to build PHP and/or your webserver. If you are unfamiliar with building and compiling your own software, it is worth checking to see whether somebody has already built a packaged version of PHP with the features you need. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.macosx" ></A >Unix/Mac OS X installs</H2 ><P >
This section contains notes and hints specific to installing PHP on Mac OS X Server. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.macosx.packages" ></A >Using Packages</H3 ><P >
There are a few pre-packaged and pre-compiled versions of PHP for Mac OS X. This can help in setting up a standard configuration, but if you need to have a different set of features (such as a secure server, or a different database driver), you may need to build PHP and/or your web server yourself. If you are unfamiliar with building and compiling your own software, it's worth checking whether somebody has already built a packaged version of PHP with the features you need. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.macosx.compile" ></A >Compiling for OS X server</H3 ><P >
There are two slightly different versions of Mac OS X, client and server. The following is for OS X Server. </P ><DIV CLASS="formalpara" ><P ><A NAME="install.macosx.compile.example" ></A ><B >Mac OS X server install. </B > <P ></P ><OL TYPE="1" ><LI ><P >Get the latest distributions of Apache and PHP.</P ></LI ><LI ><P >
Untar them, and run the <B CLASS="command" >configure</B > program on Apache like so. <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >./configure --exec-prefix=/usr \ --localstatedir=/var \ --mandir=/usr/share/man \ --libexecdir=/System/Library/Apache/Modules \ --iconsdir=/System/Library/Apache/Icons \ --includedir=/System/Library/Frameworks/Apache.framework/Versions/1.3/Headers \ --enable-shared=max \ --enable-module=most \ --target=apache</PRE ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
If you want the compiler to do some optimization., you may also want to add this line: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >setenv OPTIM=-O2</PRE ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
Next, go to the PHP 4 source directory and configure it. <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >./configure --prefix=/usr \ --sysconfdir=/etc \ --localstatedir=/var \ --mandir=/usr/share/man \ --with-xml \ --with-apache=/src/apache_1.3.12</PRE ></TD ></TR ></TABLE > If you have any other additions (MySQL, GD, etc.), be sure to add them here. For the <TT CLASS="option" >--with-apache</TT > string, put in the path to your apache source directory, for example <TT CLASS="filename" >/src/apache_1.3.12</TT >. </P ></LI ><LI ><P >
Type <B CLASS="command" >make</B > and <B CLASS="command" >make install</B >. This will add a directory to your Apache source directory under <TT CLASS="filename" >src/modules/php4</TT >. </P ></LI ><LI ><P >
Now, reconfigure Apache to build in PHP 4. <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >./configure --exec-prefix=/usr \ --localstatedir=/var \ --mandir=/usr/share/man \ --libexecdir=/System/Library/Apache/Modules \ --iconsdir=/System/Library/Apache/Icons \ --includedir=/System/Library/Frameworks/Apache.framework/Versions/1.3/Headers \ --enable-shared=max \ --enable-module=most \ --target=apache \ --activate-module=src/modules/php4/libphp4.a</PRE ></TD ></TR ></TABLE > You may get a message telling you that libmodphp4.a is out of date. If so, go to the <TT CLASS="filename" >src/modules/php4</TT > directory inside your apache source directory and run this command: <B CLASS="command" >ranlib libmodphp4.a</B >. Then go back to the root of the apache source directory and run the above <B CLASS="command" >configure</B > command again. That'll bring the link table up to date. Run <B CLASS="command" >make</B > and <B CLASS="command" >make install</B > again. </P ></LI ><LI ><P >
Copy and rename the <TT CLASS="filename" >php.ini-dist</TT > file to your <TT CLASS="filename" >bin</TT > directory from your PHP 4 source directory: <TT CLASS="userinput" ><B >cp php.ini-dist /usr/local/bin/php.ini</B ></TT > or (if your don't have a local directory) <TT CLASS="userinput" ><B >cp php.ini-dist /usr/bin/php.ini</B ></TT >. </P ></LI ></OL > </P ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.macosx.client" ></A >Compiling for MacOS X client</H3 ><P >
Those tips are graciously provided by <A HREF="http://www.entropy.ch/software/macosx/" TARGET="_top" >Marc Liyanage</A >. </P ><P >
The PHP module for the Apache web server included in Mac OS X. This version includes support for the MySQL and PostgreSQL databases. </P ><P >
NOTE: Be careful when you do this, you could screw up your Apache web server! </P ><P >
Do this to install: <P ></P ><OL TYPE="1" ><LI ><P >
Open a terminal window. </P ></LI ><LI ><P >
Type <TT CLASS="userinput" ><B >wget http://www.diax.ch/users/liyanage/software/macosx/libphp4.so.gz</B ></TT >, wait for the download to finish. </P ></LI ><LI ><P >
Type <TT CLASS="userinput" ><B >gunzip libphp4.so.gz</B ></TT >. </P ></LI ><LI ><P >
Type <TT CLASS="userinput" ><B >sudo apxs -i -a -n php4 libphp4.so</B ></TT > </P ></LI ><LI ><P >
Now type <TT CLASS="userinput" ><B >sudo open -a TextEdit /etc/httpd/httpd.conf</B ></TT >. TextEdit will open with the web server configuration file. Locate these two lines towards the end of the file: (Use the Find command) <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="apache" >#AddType application/x-httpd-php .php #AddType application/x-httpd-php-source .phps</PRE ></TD ></TR ></TABLE > Remove the two hash marks (<TT CLASS="literal" >#</TT >), then save the file and quit TextEdit. </P ></LI ><LI ><P >
Finally, type <TT CLASS="userinput" ><B >sudo apachectl graceful</B ></TT > to restart the web server. </P ></LI ></OL > </P ><P >
PHP should now be up and running. You can test it by dropping a file into your <TT CLASS="filename" >Sites</TT > folder which is called <TT CLASS="filename" >test.php</TT >. Into that file, write this line: <TT CLASS="literal" ><?php phpinfo() ?></TT >. </P ><P >
Now open up <TT CLASS="literal" >127.0.0.1/~your_username/test.php</TT > in your web browser. You should see a status table with information about the PHP module. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.openbsd" ></A >Unix/OpenBSD installs</H2 ><P >
This section contains notes and hints specific to installing PHP on <A HREF="http://www.openbsd.org/" TARGET="_top" >OpenBSD 3.4</A >. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.openbsd.packages" ></A >Using Binary Packages</H3 ><P >
Using binary packages to install PHP on OpenBSD is the recommended and simplest method. The core package has been separated from the various modules, and each can be installed and removed independently from the others. The files you need can be found on your OpenBSD CD or on the FTP site. </P ><P >
The main package you need to install is <TT CLASS="filename" >php4-core-4.3.3.tgz</TT >, which contains the basic engine (plus gettext and iconv). Next, take a look at the module packages, such as <TT CLASS="filename" >php4-mysql-4.3.3.tgz</TT > or <TT CLASS="filename" >php4-imap-4.3.3.tgz</TT >. You need to use the <B CLASS="command" >phpxs</B > command to activate and deactivate these modules in your <TT CLASS="filename" >php.ini</TT >. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="install.openbsd.ports.example" ></A ><P ><B >P°φklad 3-1. OpenBSD Package Install Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ># pkg_add php4-core-4.3.3.tgz # /usr/local/sbin/phpxs -s # cp /usr/local/share/doc/php4/php.ini-recommended /var/www/conf/php.ini (add in mysql) # pkg_add php4-mysql-4.3.3.tgz # /usr/local/sbin/phpxs -a mysql (add in imap) # pkg_add php4-imap-4.3.3.tgz # /usr/local/sbin/phpxs -a imap (remove mysql as a test) # pkg_delete php4-mysql-4.3.3 # /usr/local/sbin/phpxs -r mysql (install the PEAR libraries) # pkg_add php4-pear-4.3.3.tgz</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Read the <A HREF="http://www.openbsd.org/cgi-bin/man.cgi?query=packages" TARGET="_top" >packages(7)</A > manual page for more information about binary packages on OpenBSD. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.openbsd.ports" ></A >Using Ports</H3 ><P >
You can also compile up PHP from source using the <A HREF="http://www.openbsd.org/ports.html" TARGET="_top" >ports tree</A >. However, this is only recommended for users familiar with OpenBSD. The PHP 4 port is split into two sub-directories: core and extensions. The extensions directory generates sub-packages for all of the supported PHP modules. If you find you do not want to create some of these modules, use the <B CLASS="command" >no_*</B > FLAVOR. For example, to skip building the imap module, set the FLAVOR to <B CLASS="command" >no_imap</B >. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.openbsd.faq" ></A >Common Problems</H3 ><P ></P ><UL ><LI ><P >The default install of Apache runs inside a <A HREF="http://www.openbsd.org/cgi-bin/man.cgi?query=chroot" TARGET="_top" >chroot(2) jail</A >, which will restrict PHP scripts to accessing files under <TT CLASS="filename" >/var/www</TT >. You will therefore need to create a <TT CLASS="filename" >/var/www/tmp</TT > directory for PHP session files to be stored, or use an alternative session backend. In addition, database sockets need to be placed inside the jail or listen on the <TT CLASS="filename" >localhost</TT > interface. If you use network functions, some files from <TT CLASS="filename" >/etc</TT > such as <TT CLASS="filename" >/etc/resolv.conf</TT > and <TT CLASS="filename" >/etc/services</TT > will need to be moved into <TT CLASS="filename" >/var/www/etc</TT >. The OpenBSD PEAR package automatically installs into the correct chroot directories, so no special modification is needed there. More information on the OpenBSD Apache is available in the <A HREF="http://www.openbsd.org/faq/faq10.html#httpdchroot" TARGET="_top" >OpenBSD FAQ</A >. </P ></LI ><LI ><P >
The OpenBSD 3.4 package for the <A HREF="http://www.boutell.com/gd/" TARGET="_top" >gd</A > extension requires XFree86 to be installed. If you do not wish to use some of the font features that require X11, install the <TT CLASS="filename" >php4-gd-4.3.3-no_x11.tgz</TT > package instead. </P ></LI ></UL ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.openbsd.older" ></A >Older Releases</H3 ><P >
Older releases of OpenBSD used the FLAVORS system to compile up a statically linked PHP. Since it is hard to generate binary packages using this method, it is now deprecated. You can still use the old stable ports trees if you wish, but they are unsupported by the OpenBSD team. If you have any comments about this, the current maintainer for the port is Anil Madhavapeddy (avsm at openbsd dot org). </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.solaris" ></A >Unix/Solaris installs</H2 ><P >
This section contains notes and hints specific to installing PHP on Solaris systems. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.solaris.required" ></A >Required software</H3 ><P >
Solaris installs often lack C compilers and their related tools. Read <A HREF="#faq.installation.needgnu" >this FAQ</A > for information on why using GNU versions for some of these tools is necessary. The required software is as follows: <P ></P ><UL ><LI ><P >
gcc (recommended, other C compilers may work) </P ></LI ><LI ><P >
make </P ></LI ><LI ><P >
flex </P ></LI ><LI ><P >
bison </P ></LI ><LI ><P >
m4 </P ></LI ><LI ><P >
autoconf </P ></LI ><LI ><P >
automake </P ></LI ><LI ><P >
perl </P ></LI ><LI ><P >
gzip </P ></LI ><LI ><P >
tar </P ></LI ><LI ><P >
GNU sed </P ></LI ></UL > In addition, you will need to install (and possibly compile) any additional software specific to your configuration, such as Oracle or MySQL. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.solaris.packages" ></A >Using Packages</H3 ><P >
You can simplify the Solaris install process by using pkgadd to install most of your needed components. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.unix" ></A >Installation on Unix systems</H2 ><P >
This section will guide you through the general configuration and installation of PHP on Unix systems. Be sure to investigate any sections specific to your platform or web server before you begin the process. </P ><P >
Prerequisite knowledge and software: <P ></P ><UL ><LI ><P >
Basic Unix skills (being able to operate "make" and a C compiler, if compiling) </P ></LI ><LI ><P >
An ANSI C compiler (if compiling) </P ></LI ><LI ><P >
flex (for compiling) </P ></LI ><LI ><P >
bison (for compiling) </P ></LI ><LI ><P >
A web server </P ></LI ><LI ><P >
Any module specific components (such as gd, pdf libs, etc.) </P ></LI ></UL > </P ><P >
There are several ways to install PHP for the Unix platform, either with a compile and configure process, or through various pre-packaged methods. This documentation is mainly focused around the process of compiling and configuring PHP. </P ><P >
The initial PHP setup and configuration process is controlled by the use of the commandline options of the <TT CLASS="filename" >configure</TT > script. This page outlines the usage of the most common options, but there are many others to play with. Check out the <A HREF="#install.configure" >Complete list of configure options</A > for an exhaustive rundown. There are several ways to install PHP: <P ></P ><UL ><LI ><P >
As an <A HREF="#install.apache" >Apache 1.x module</A > or an <A HREF="#install.apache2" >Apache 2.x module</A >. </P ></LI ><LI ><P >
As an <A HREF="#install.caudium" >Pike module for Caudium</A > </P ></LI ><LI ><P >
For use with <A HREF="#install.otherhttpd" >AOLServer, NSAPI, phttpd, Pi3Web, Roxen, thttpd, or Zeus.</A > </P ></LI ><LI ><P >
As a <A HREF="#install.commandline" >CGI executable</A > </P ></LI ></UL > </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.unix.apache-module" ></A >Apache Module Quick Reference</H3 ><P >
PHP can be compiled in a number of different ways, but one of the most popular is as an Apache module. The following is a quick installation overview. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="install.unix.apache-module.quick" ></A ><P ><B >P°φklad 3-2. Quick Installation Instructions for PHP 4 (Apache Module Version) </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >1. gunzip apache_1.3.x.tar.gz 2. tar xvf apache_1.3.x.tar 3. gunzip php-x.x.x.tar.gz 4. tar xvf php-x.x.x.tar 5. cd apache_1.3.x 6. ./configure --prefix=/www 7. cd ../php-x.x.x 8. ./configure --with-mysql --with-apache=../apache_1.3.x --enable-ftp 9. make 10. make install 11. cd ../apache_1.3.x 12. ./configure --activate-module=src/modules/php4/libphp4.a 13. make 14. make install 15. cd ../php-x.x.x 16. cp php.ini-dist /usr/local/lib/php.ini 17. Edit your httpd.conf or srm.conf file and add: AddType application/x-httpd-php .php 18. Use your normal procedure for restarting the Apache server. (You must stop and restart the server, not just cause the server to reload by use a HUP or USR1 signal.)</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.building" ></A >Building</H3 ><P >
When PHP is configured, you are ready to build the CGI executable. The command <B CLASS="command" >make</B > should take care of this. If it fails and you can't figure out why, see the <A HREF="#install.problems" >Problems section</A >. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.windows" ></A >Installation on Windows systems</H2 ><P >
This section applies to Windows 98/Me and Windows NT/2000/XP. PHP will not work on 16 bit platforms such as Windows 3.1 and sometimes we refer to the supported Windows platforms as Win32. Windows 95 is no longer supported as of PHP 4.3.0. </P ><P >
There are two main ways to install PHP for Windows: either <A HREF="#install.windows.manual" >manually</A > or by using the <A HREF="#install.windows.installer" >InstallShield</A > installer. </P ><P >
If you have Microsoft Visual Studio, you can also <A HREF="#install.windows.build" >build</A > PHP from the original source code. </P ><P >
Once you have PHP installed on your Windows system, you may also want to <A HREF="#install.windows.extensions" >load various extensions</A > for added functionality. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.windows.installer" ></A >Windows InstallShield</H3 ><P >
The Windows PHP installer is available from the downloads page at <A HREF="http://www.php.net/downloads.php" TARGET="_top" >http://www.php.net/downloads.php</A >. This installs the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >CGI version</I ></SPAN > of <TT CLASS="literal" >PHP</TT > and, for IIS, PWS, and Xitami, configures the web server as well. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > While the InstallShield installer is an easy way to make <TT CLASS="literal" >PHP</TT > work, it is restricted in many aspects, as automatic setup of extensions for example is not supported. The whole set of supported extensions is only available by downloading the zip binary distribution. </P ></BLOCKQUOTE ></DIV ><P >
Install your selected <SPAN CLASS="acronym" >HTTP</SPAN > server on your system and make sure that it works. </P ><P >
Run the executable installer and follow the instructions provided by the installation wizard. Two types of installation are supported - standard, which provides sensible defaults for all the settings it can, and advanced, which asks questions as it goes along. </P ><P >
The installation wizard gathers enough information to set up the <TT CLASS="filename" >php.ini</TT > file and configure the web server to use PHP. For IIS and also PWS on NT Workstation, a list of all the nodes on the server with script map settings is displayed, and you can choose those nodes to which you wish to add the PHP script mappings. </P ><P >
Once the installation has completed the installer will inform you if you need to restart your system, restart the server, or just start using PHP. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Be aware, that this setup of PHP is not secure. If you would like to have a secure PHP setup, you'd better go on the manual way, and set every option carefully. This automatically working setup gives you an instantly working PHP installation, but it is not meant to be used on online servers. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.windows.manual" ></A >Manual Installation Steps</H3 ><P >
This install guide will help you manually install and configure PHP on your Windows webserver. The original version of this guide was compiled by <A HREF="mailto:bob_silva@mail.umesd.k12.or.us" TARGET="_top" >Bob Silva</A >, and can be found at <A HREF="http://www.umesd.k12.or.us/php/win32install.html" TARGET="_top" >http://www.umesd.k12.or.us/php/win32install.html</A >. You need to download the zip binary distribution from the downloads page at <A HREF="http://www.php.net/downloads.php" TARGET="_top" >http://www.php.net/downloads.php</A >. </P ><P >
PHP 4 for Windows comes in three flavours - a CGI executable (php.exe), a CLI executable (sapi/php.exe) and some other SAPI modules: <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >
<TT CLASS="filename" >php4apache.dll</TT > - Apache 1.3.x module </TD ></TR ><TR ><TD >
<TT CLASS="filename" >php4apache2.dll</TT > - Apache 2.0.x module </TD ></TR ><TR ><TD >
<TT CLASS="filename" >php4isapi.dll</TT > - ISAPI Module for ISAPI compliant webservers like IIS 4.0/PWS 4.0 or newer. </TD ></TR ><TR ><TD >
<TT CLASS="filename" >php4nsapi.dll</TT > - Netscape/iPlanet module </TD ></TR ></TBODY ></TABLE ><P ></P > The latter form is new to PHP 4, and provides significantly improved performance and some new functionality. The CLI version is designed to use PHP for command line scripting. More information about CLI is available in the chapter about <A HREF="#features.commandline" >using PHP from the command line</A > </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
The SAPI modules have been significantly improved in the 4.1 release, however, you may find that you encounter possible server errors or other server modules such as ASP failing, in older systems. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >DCOM and MDAC requirements: </B > If you choose one of the SAPI modules and use <SPAN CLASS="emphasis" ><I CLASS="emphasis" >Windows 95</I ></SPAN >, be sure to download and install the DCOM update from the <A HREF="http://download.microsoft.com/msdownload/dcom/95/x86/en/dcom95.exe" TARGET="_top" >Microsoft DCOM pages</A >. If you use Microsoft <SPAN CLASS="emphasis" ><I CLASS="emphasis" >Windows 9x/NT4</I ></SPAN > download the latest version of the Microsoft Data Access Components (MDAC) for your platform. MDAC is available at <A HREF="http://www.microsoft.com/data/" TARGET="_top" >http://www.microsoft.com/data/</A >. </P ></BLOCKQUOTE ></DIV ><P >
The following steps should be performed on all installations before any server specific instructions. <P ></P ><UL ><LI ><P >
Extract the distribution file to a directory of your choice, <TT CLASS="filename" >c:\</TT > is a good start. The zip package expands to a foldername like <TT CLASS="filename" >php-4.3.1-Win32</TT > which is assumed to be renamed to <TT CLASS="filename" >php</TT >. For the sake of convenience and to be version independent the following steps assume your extracted version of PHP lives in <TT CLASS="filename" >c:\php</TT >. You might choose any other location but you probably do not want to use a path in which spaces are included (for example: <TT CLASS="filename" >C:\Program Files\PHP</TT > is not a good idea). Some web servers will crash if you do. The structure of your directory you extracted the zip file will look like: </P ></LI ></UL > <DIV CLASS="informalexample" ><A NAME="AEN668" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >c:\php | +--cli | | | |-php.exe -- CLI executable - ONLY for commandline scripting | | +--dlls -- support dlls for extensions --> Windows system directory | | | |-expat.dll | | | |-fdftk.dll | | | |-... | +--extensions -- extension dlls for PHP | | | |-php_bz2.dll | | | |-php_cpdf.dll | | | |-.. | +--mibs -- support files for SNMP | | +--openssl -- support files for Openssl | | +--pdf-related -- support files for PDF | | +--sapi -- SAPI dlls | | | |-php4apache.dll | | | |-php4apache2.dll | | | |-php4isapi.dll | | | |-.. | |-install.txt | |-.. | |-php.exe -- CGI executable | |-.. | |-php.ini-dist | |-php.ini-recommended | |-php4ts.dll -- main dll --> Windows system directory | |-...</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
The CGI binary - <TT CLASS="filename" >c:\php\php.exe</TT > -, the CLI binary - <TT CLASS="filename" >c:\php\cli\php.exe</TT > -, and the SAPI modules - <TT CLASS="filename" >c:\php\sapi\*.dll</TT > - rely on the main dll <TT CLASS="filename" >c:\php\php4ts.dll</TT >. You have to make sure, that this dll can be found by your PHP installation. The search order for this dll is as follows: <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >
The same directory from where <TT CLASS="filename" >php.exe</TT > is called. In case you use a SAPI module the same directory from where your webserver loads the dll (e.g. <TT CLASS="filename" >php4apache.dll</TT >). </TD ></TR ><TR ><TD >
Any directory in your Windows PATH environment variable. </TD ></TR ></TBODY ></TABLE ><P ></P > <P ></P ><UL ><LI ><P >
The best bet is to make <TT CLASS="filename" >php4ts.dll</TT > available, regardless which interface (CGI or SAPI module) you plan to use. To do so, you have to copy this dll to a directory on your Windows path. The best place is your Windows system directory: <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >
<TT CLASS="filename" >C:\Windows\System</TT > for Windows 9x/ME </TD ></TR ><TR ><TD >
<TT CLASS="filename" >C:\WINNT\System32</TT > for Windows NT/2000 or <TT CLASS="filename" >C:\WINNT40\System32</TT > for NT/2000 server </TD ></TR ><TR ><TD >
<TT CLASS="filename" >C:\Windows\System32</TT > for Windows XP </TD ></TR ></TBODY ></TABLE ><P ></P > If you plan to use a SAPI module from <TT CLASS="filename" >c:\php\sapi</TT > and do not like to copy dlls to your Windows system directory, you have the alternative choice to simply copy <TT CLASS="filename" >php4ts.dll</TT > to the sapi folder of your extracted zip package, <TT CLASS="filename" >c:\php\sapi</TT >. </P ></LI ><LI ><P >
The next step is to set up a valid configuration file for PHP, <TT CLASS="filename" >php.ini</TT >. There are two ini files distributed in the zip file, <TT CLASS="filename" >php.ini-dist</TT > and <TT CLASS="filename" >php.ini-recommended</TT >. We advise you to use <TT CLASS="filename" >php.ini-recommended</TT >, because we optimized the default settings in this file for performance, and security. Read this well documented file carefully and in addition study the <A HREF="#configuration.file" >ini settings</A > and set every element manually yourself. If you would like to achieve the best security, then this is the way for you, although PHP works fine with these default ini files. Copy your chosen ini-file to a directory where PHP is able to find and rename it to <TT CLASS="filename" >php.ini</TT >. By default PHP searches <TT CLASS="filename" >php.ini</TT > in your Windows directory: <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >
On Windows 9x/ME/XP copy your chosen ini file to your <TT CLASS="filename" > %WINDIR%</TT >, which is typically <TT CLASS="filename" >C:\Windows</TT >. </TD ></TR ><TR ><TD >
On Windows NT/2000 copy your chosen ini file to your <TT CLASS="filename" >%WINDIR%</TT > or <TT CLASS="filename" >%SYSTEMROOT%</TT >, which is typically <TT CLASS="filename" >C:\WINNT</TT > or <TT CLASS="filename" >C:\WINNT40</TT > for NT/2000 servers. </TD ></TR ></TBODY ></TABLE ><P ></P > </P ></LI ><LI ><P >
If you're using NTFS on Windows NT, 2000 or XP, make sure that the user running the webserver has read permissions to your <TT CLASS="filename" >php.ini</TT > (e.g. make it readable by Everyone). </P ></LI ></UL > </P ><P >
The following steps are optional. <P ></P ><UL ><LI ><P >
Edit your new <TT CLASS="filename" >php.ini</TT > file. If you plan to use <A HREF="#install.omnihttpd" >OmniHTTPd</A >, do not follow the next step. Set the <A HREF="#ini.doc-root" >doc_root</A > to point to your webservers document_root. For example: <DIV CLASS="informalexample" ><A NAME="AEN723" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" >doc_root = c:\inetpub // for IIS/PWS doc_root = c:\apache\htdocs // for Apache</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></LI ><LI ><P >
Choose which extensions you would like to load when PHP starts. See the section about <A HREF="#install.windows.extensions" >Windows extensions</A >, about how to set up one, and what is already built in. Note that on a new installation it is advisable to first get PHP working and tested without any extensions before enabling them in <TT CLASS="filename" >php.ini</TT >. </P ></LI ><LI ><P >
On PWS and IIS, you can set the <A HREF="#ini.browscap" >browscap</A > configuration setting to point to: <TT CLASS="filename" >c:\windows\system\inetsrv\browscap.ini</TT > on Windows 9x/Me, <TT CLASS="filename" >c:\winnt\system32\inetsrv\browscap.ini</TT > on NT/2000, and <TT CLASS="filename" >c:\windows\system32\inetsrv\browscap.ini</TT > on XP. </P ></LI ></UL > </P ><P >
Following this instructions you are done with the basic steps to setup PHP on Windows. The next step is to choose a webserver and enable it to run PHP. Installation instructions for the following webservers are available: <P ></P ><UL ><LI ><P >
.. the <A HREF="#install.iis" >Windows server family</A >, Personal Web server (PWS) 3 and 4 or newer; Internet Information Server (IIS) 3 and 4 or newer. </P ></LI ><LI ><P >
.. the Apache servers <A HREF="#install.apache.windows" >Apache 1.3.x</A >, and <A HREF="#install.apache2.windows" >Apache 2.x</A >. </P ></LI ><LI ><P >
.. the <A HREF="#install.netscape.windows" >Netscape/iPlanet</A > servers. </P ></LI ><LI ><P >
.. the <A HREF="#install.omnihttpd" >OmniHTTPd</A > server. </P ></LI ><LI ><P >
.. the <A HREF="#install.oreilly" >Oreilly Website Pro</A > server. </P ></LI ><LI ><P >
.. the <A HREF="#install.sambar" >Sambar</A > server. </P ></LI ><LI ><P >
.. the <A HREF="#install.xitami" >Xitami</A > server. </P ></LI ></UL > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.windows.build" ></A >Building from source</H3 ><P >
Before getting started, it is worthwhile answering the question: "Why is building on Windows so hard?" Two reasons come to mind: </P ><P ></P ><OL TYPE="1" ><LI ><P >
Windows does not (yet) enjoy a large community of developers who are willing to freely share their source. As a direct result, the necessary investment in infrastructure required to support such development hasn't been made. By and large, what is available has been made possible by the porting of necessary utilities from Unix. Don't be surprised if some of this heritage shows through from time to time. </P ></LI ><LI ><P >
Pretty much all of the instructions that follow are of the "set and forget" variety. So sit back and try follow the instructions below as faithfully as you can. </P ></LI ></OL ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.windows.build.requirement" ></A >Po╛adavky</H4 ><P >
To compile and build <TT CLASS="literal" >PHP</TT > you need a Microsoft Development Environment. Microsoft Visual C++ 6.0 is recommended. To extract the downloaded files you need a extraction utility (e.g.: Winzip). If you don't already have an unzip utility, you can get a free version from <A HREF="http://www.info-zip.org/pub/infozip/" TARGET="_top" >InfoZip</A >. </P ><P >
Before you get started, you have to download... </P ><P ></P ><UL ><LI ><P >
..the win32 buildtools from the <TT CLASS="literal" >PHP</TT > site at <A HREF="http://www.php.net/extra/win32build.zip" TARGET="_top" >http://www.php.net/extra/win32build.zip</A >. </P ></LI ><LI ><P >
..the source code for the DNS name resolver used by <TT CLASS="literal" >PHP </TT > from <A HREF="http://www.php.net/extra/bindlib_w32.zip" TARGET="_top" >
http://www.php.net/extra/bindlib_w32.zip</A >. This is a replacement for the <TT CLASS="filename" >resolv.lib</TT > library included in <TT CLASS="filename" >
win32build.zip</TT >. </P ></LI ><LI ><P >
If you plan to compile <TT CLASS="literal" >PHP</TT > as a Apache module you will also need the <A HREF="http://www.apache.org/dist/httpd/" TARGET="_top" >Apache sources</A >. </P ></LI ></UL ><P >
Finally, you are going to need the source to PHP 4 itself. You can get the latest development version using <A HREF="http://www.php.net/anoncvs.php" TARGET="_top" >
anonymous CVS</A >, a <A HREF="http://snaps.php.net/" TARGET="_top" >
snapshot</A > or the most recent released <A HREF="http://www.php.net/downloads.php" TARGET="_top" >
source</A > tarball. </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.windows.build.install" ></A >Putting it all together</H4 ><P >
After downloading the required packages you have to extract them in a proper place. <P ></P ><UL ><LI ><P >
Create a working directory where all files end up after extracting, e.g: <TT CLASS="filename" >C:\work</TT >. </P ></LI ><LI ><P >
Create the directory <TT CLASS="filename" >win32build</TT > under your working directory (<TT CLASS="filename" >C:\work</TT >) and unzip <TT CLASS="filename" >
win32build.zip</TT > into it. </P ></LI ><LI ><P >
Create the directory <TT CLASS="filename" >bindlib_w32</TT > under your working directory (<TT CLASS="filename" >C:\work</TT >) and unzip <TT CLASS="filename" >
bindlib_w32.zip</TT > into it. </P ></LI ><LI ><P >
Extract the downloaded PHP source code into your working directory (<TT CLASS="filename" >C:\work</TT >). </P ></LI ></UL > Following this steps your directory structure looks like this: <DIV CLASS="informalexample" ><A NAME="AEN812" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >+--c:\work | | | +--bindlib_w32 | | | | | +--arpa | | | | | +--conf | | | | | +--... | | | +--php-4.x.x | | | | | +--build | | | | | +--... | | | | | +--win32 | | | | | +--... | | | +--win32build | | | | | +--bin | | | | | +--include | | | | | +--lib</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Create the directories <TT CLASS="filename" >c:\usr\local\lib</TT >. Copy <TT CLASS="filename" >bison.simple</TT > from <TT CLASS="filename" >c:\work\win32build\bin </TT > to <TT CLASS="filename" >c:\usr\local\lib</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <A HREF="http://www.cygwin.com/" TARGET="_top" >Cygwin</A > users may omit the last step. A properly installed Cygwin environment provides the mandatory files <TT CLASS="filename" >bison.simple</TT > and <TT CLASS="filename" >bison.exe</TT >. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.windows.build.configure" ></A >Configure MVC ++</H4 ><P >
The next step is to configure MVC ++ to prepare for compiling. Launch Microsoft Visual C++, and from the menu select Tools => Options. In the dialog, select the directories tab. Sequentially change the dropdown to Executables, Includes, and Library files. Your entries should look like this: <P ></P ><UL ><LI ><P >
Executable files: <TT CLASS="filename" >c:\work\win32build\bin</TT >, Cygwin users: <TT CLASS="filename" >cygwin\bin</TT > </P ></LI ><LI ><P >
Include files: <TT CLASS="filename" >c:\work\win32build\include</TT > </P ></LI ><LI ><P >
Library files: <TT CLASS="filename" >c:\work\win32build\lib</TT > </P ></LI ></UL > </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.windows.build.resolvlib" ></A >Build resolv.lib</H4 ><P >
You must build the <TT CLASS="filename" >resolv.lib</TT > library. Decide whether you want to have debug symbols available (bindlib - Win32 Debug) or not (bindlib - Win32 Release). Build the appropriate configuration: <P ></P ><UL ><LI ><P >
For GUI users, launch VC++, and then select File => Open Workspace, navigate to <TT CLASS="filename" >c:\work\bindlib_w32</TT > and select <TT CLASS="filename" >bindlib.dsw</TT >. Then select Build=>Set Active Configuration and select the desired configuration. Finally select Build=>Rebuild All. </P ></LI ><LI ><P >
For command line users, make sure that you either have the C++ environment variables registered, or have run <B CLASS="command" >vcvars.bat</B >, and then execute one of the following commands: </P ><P ></P ><UL ><LI ><P >
<TT CLASS="userinput" ><B >msdev bindlib.dsp /MAKE "bindlib - Win32 Debug"</B ></TT > </P ></LI ><LI ><P >
<TT CLASS="userinput" ><B >msdev bindlib.dsp /MAKE "bindlib - Win32 Release"</B ></TT > </P ></LI ></UL ></LI ></UL > At this point, you should have a usable <TT CLASS="filename" >resolv.lib</TT > in either your <TT CLASS="filename" >c:\work\bindlib_w32\Debug</TT > or <TT CLASS="filename" >Release</TT > subdirectories. Copy this file into your <TT CLASS="filename" >c:\work\win32build\lib</TT > directory over the file by the same name found in there. </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.windows.build.compile" ></A >Compiling</H4 ><P >
The best way to get started is to build the CGI version. </P ><P ></P ><UL ><LI ><P >
For GUI users, launch VC++, and then select File => Open Workspace and select <TT CLASS="filename" >c:\work\php-4.x.x\win32\php4ts.dsw </TT >. Then select Build=>Set Active Configuration and select the desired configuration, either <TT CLASS="literal" >php4ts - Win32 Debug_TS</TT > or <TT CLASS="literal" >php4ts - Win32 Release_TS</TT >. Finally select Build=>Rebuild All. </P ></LI ><LI ><P >
For command line users, make sure that you either have the C++ environment variables registered, or have run <B CLASS="command" >vcvars.bat</B >, and then execute one of the following commands from the <TT CLASS="filename" >c:\work\php-4.x.x\win32 </TT > directory: </P ><P ></P ><UL ><LI ><P >
<TT CLASS="userinput" ><B >msdev php4ts.dsp /MAKE "php4ts - Win32 Debug_TS"</B ></TT > </P ></LI ><LI ><P >
<TT CLASS="userinput" ><B >msdev php4ts.dsp /MAKE "php4ts - Win32 Release_TS"</B ></TT > </P ></LI ><LI ><P >
At this point, you should have a usable <TT CLASS="filename" >php.exe</TT > in either your <TT CLASS="filename" >c:\work\php-4.x.x.\Debug_TS</TT > or <TT CLASS="filename" >Release_TS</TT > subdirectories. </P ></LI ></UL ></LI ></UL ><P >
It is possible to do minor customization to the build process by editing the <TT CLASS="filename" >main/config.win32.h</TT > file. For example you can change the default location of <TT CLASS="filename" >php.ini</TT >, the built-in extensions, and the default location for your extensions. </P ><P >
Next you may want to build the CLI version which is designed to use <A HREF="#features.commandline" >PHP from the command line</A >. The steps are the same as for building the CGI version, except you have to select the <TT CLASS="literal" >php4ts_cli - Win32 Debug_TS</TT > or <TT CLASS="literal" >php4ts_cli - Win32 Release_TS</TT > project file. After a successful compiling run you will find the <TT CLASS="filename" >php.exe</TT > in either the directory <TT CLASS="filename" >Release_TS\cli\</TT > or <TT CLASS="filename" >Debug_TS\cli\</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > If you want to use PEAR and the comfortable command line installer, the CLI-SAPI is mandatory. For more information about PEAR and the installer read the documentation at the <A HREF="http://pear.php.net/manual/" TARGET="_top" >
PEAR</A > website. </P ></BLOCKQUOTE ></DIV ><P >
In order to build the SAPI module (<TT CLASS="filename" >php4isapi.dll</TT >) for integrating PHP with Microsoft IIS, set your active configuration to <TT CLASS="filename" >php4isapi-whatever-config</TT > and build the desired dll. </P ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.windows.extensions" ></A >Installation of Windows extensions</H3 ><P >
After installing PHP and a webserver on Windows, you will probably want to install some extensions for added functionality. You can choose which extensions you would like to load when PHP starts by modifying your <TT CLASS="filename" >php.ini</TT >. You can also load a module dynamically in your script using <A HREF="#function.dl" ><B CLASS="function" >dl()</B ></A >. </P ><P >
The DLLs for PHP extensions are prefixed with 'php_' in PHP 4 (and 'php3_' in PHP 3). This prevents confusion between PHP extensions and their supporting libraries. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > In PHP 4.3.1 BCMath, Calendar, COM, Ctype, FTP, MySQL, ODBC, Overload, PCRE, Session, Tokenizer, WDDX, XML and Zlib support is <SPAN CLASS="emphasis" ><I CLASS="emphasis" >built in</I ></SPAN >. You don't need to load any additional extensions in order to use these functions. See your distributions <TT CLASS="filename" >README.txt</TT > or <TT CLASS="filename" >install.txt</TT > or <A HREF="#install.extensions.overview" >this table</A > for a list of built in modules. </P ></BLOCKQUOTE ></DIV ><P >
The default location <TT CLASS="literal" >PHP</TT > searches for extensions is <TT CLASS="filename" >c:\php4\extensions</TT >. To change this setting to reflect your setup of <TT CLASS="literal" >PHP</TT > edit your <TT CLASS="filename" >php.ini</TT > file: <P ></P ><UL ><LI ><P >
You will need to change the <A HREF="#ini.extension-dir" >extension_dir</A > setting to point to the directory where your extensions lives, or where you have placed your <TT CLASS="filename" >php_*.dll</TT > files. Please do not forget the last backslash. For example: <DIV CLASS="informalexample" ><A NAME="AEN923" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" >extension_dir = c:/php/extensions/</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></LI ><LI ><P >
Enable the extension(s) in <TT CLASS="filename" >php.ini</TT > you want to use by uncommenting the <TT CLASS="literal" >extension=php_*.dll</TT > lines in <TT CLASS="filename" >php.ini</TT >. This is done by deleting the leading ; form the extension you want to load. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN930" ></A ><P ><B >P°φklad 3-3. Enable <A HREF="#ref.bzip2" >Bzip2</A > extension for PHP-Windows</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" >// change the following line from ... ;extension=php_bz2.dll // ... to extension=php_bz2.dll</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
Some of the extensions need extra DLLs to work. Couple of them can be found in the distribution package, in the <TT CLASS="filename" >c:\php\dlls\</TT > folder but some, for example Oracle (<TT CLASS="filename" >php_oci8.dll</TT >) require DLLs which are not bundled with the distribution package. Copy the bundled DLLs from <TT CLASS="filename" >c:\php\dlls</TT > folder to your Windows PATH, safe places are: <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >c:\windows\system for Windows 9x/Me</TD ></TR ><TR ><TD >c:\winnt\system32 for Windows NT/2000</TD ></TR ><TR ><TD >c:\windows\system32 for Windows XP</TD ></TR ></TBODY ></TABLE ><P ></P > If you have them already installed on your system, overwrite them only if something doesn't work correctly (Before overwriting them, it is a good idea to make a backup of them, or move them to another folder - just in case something goes wrong). </P ></LI ></UL > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > If you are running a server module version of <TT CLASS="literal" >PHP</TT > remember to restart your webserver to reflect your changes to <TT CLASS="filename" >php.ini</TT >. </P ></BLOCKQUOTE ></DIV > </P ><P >
The following table describes some of the extensions available and required additional dlls. <DIV CLASS="table" ><A NAME="install.extensions.overview" ></A ><P ><B >Tabulka 3-1. PHP Extensions</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Extension</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Description</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Notes</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_bz2.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.bzip2" >bzip2</A > compression functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_calendar.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.calendar" >Calendar</A > conversion functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Built in since PHP 4.0.3</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_cpdf.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.cpdf" >ClibPDF</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_crack.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.crack" >Crack</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php3_crypt.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Crypt functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >unknown</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_ctype.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.ctype" >ctype</A > family functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Built in since PHP 4.3.0</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_curl.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.curl" >CURL</A >, Client URL library functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >libeay32.dll</TT >, <TT CLASS="filename" >ssleay32.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_cybercash.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.cybercash" >Cybercash</A > payment functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP <= 4.2.0</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_db.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.dbm" >DBM</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Deprecated. Use DBA instead (<TT CLASS="filename" >php_dba.dll</TT >)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_dba.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.dba" >DBA</A >: DataBase (dbm-style) Abstraction layer functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_dbase.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.dbase" >dBase</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php3_dbm.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Berkeley DB2 library</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >unknown</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_dbx.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.dbx" >dbx</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_domxml.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.domxml" >DOM XML</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
PHP <= 4.2.0 requires: <TT CLASS="filename" >libxml2.dll</TT > (bundled) PHP >= 4.3.0 requires: <TT CLASS="filename" >iconv.dll</TT > (bundled) </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_dotnet.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.dotnet" >.NET</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP <= 4.1.1</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_exif.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.read-exif-data" >Read EXIF</A > headers from JPEG</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_fbsql.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.fbsql" >FrontBase</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP <= 4.2.0</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_fdf.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.fdf" >FDF</A >: Forms Data Format functions.</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >fdftk.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_filepro.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.filepro" >filePro</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Read-only access</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_ftp.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.ftp" >FTP</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Built-in since PHP 4.0.3</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_gd.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.image" >GD</A > library image functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Removed in PHP 4.3.2. Also note that truecolor functions are not available in GD1, instead, use <TT CLASS="filename" >php_gd2.dll</TT >. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_gd2.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.image" >GD</A > library image functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >GD2</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_gettext.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.gettext" >Gettext</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
PHP <= 4.2.0 requires <TT CLASS="filename" >gnu_gettext.dll</TT > (bundled), PHP >= 4.2.3 requires <TT CLASS="filename" >libintl-1.dll</TT >, <TT CLASS="filename" >iconv.dll</TT > (bundled). </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_hyperwave.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.hyperwave" >HyperWave</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_iconv.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.iconv" >ICONV</A > characterset conversion</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >iconv-1.3.dll</TT > (bundled), PHP >=4.2.1 <TT CLASS="filename" >iconv.dll</TT ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_ifx.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.ifx" >Informix</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: Informix libraries</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_iisfunc.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >IIS management functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_imap.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.imap" >IMAP</A > POP3 and NNTP functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 3: <TT CLASS="filename" >php3_imap4r1.dll</TT ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_ingres.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.ingres" >Ingres II</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: Ingres II libraries</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_interbase.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.ibase" >InterBase</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >gds32.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_java.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.java" >Java</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP <= 4.0.6 requires: <TT CLASS="filename" >jvm.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_ldap.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.ldap" >LDAP</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
PHP <= 4.2.0 requires <TT CLASS="filename" >libsasl.dll</TT > (bundled), PHP >= 4.3.0 requires <TT CLASS="filename" >libeay32.dll</TT >, <TT CLASS="filename" >ssleay32.dll</TT > (bundled) </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_mbstring.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.mbstring" >Multi-Byte String</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_mcrypt.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.mcrypt" >Mcrypt Encryption</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >libmcrypt.dll</TT ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_mhash.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.mhash" >Mhash</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP >= 4.3.0 requires: <TT CLASS="filename" >libmhash.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_mime_magic.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.mime-magic" >Mimetype</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >magic.mime</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_ming.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.ming" >Ming</A > functions for Flash</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_msql.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.msql" >mSQL</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >msql.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php3_msql1.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >mSQL 1 client</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >unknown</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php3_msql2.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >mSQL 2 client</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >unknown</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_mssql.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.mssql" >MSSQL</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >ntwdblib.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php3_mysql.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.mysql" >MySQL</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Built-in in PHP 4</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php3_nsmail.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Netscape mail functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >unknown</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php3_oci73.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Oracle functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >unknown</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_oci8.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.oci8" >Oracle 8</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: Oracle 8.1+ client libraries</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_openssl.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.openssl" >OpenSSL</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >libeay32.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_oracle.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.oracle" >Oracle</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: Oracle 7 client libraries</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_overload.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.overload" >Object overloading</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Built in since PHP 4.3.0</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_pdf.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.pdf" >PDF</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_pgsql.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.pgsql" >PostgreSQL</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_printer.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.printer" >Printer</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_shmop.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.shmop" >Shared Memory</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_snmp.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.snmp" >SNMP</A > get and walk functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NT only!</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_sockets.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.sockets" >Socket</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_sybase_ct.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.sybase" >Sybase</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: Sybase client libraries</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_tokenizer.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.tokenizer" >Tokenizer</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Built in since PHP 4.3.0</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_w32api.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.w32api" >W32api</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >None</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_xmlrpc.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.xmlrpc" >XML-RPC</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP >= 4.2.1 requires: <TT CLASS="filename" >iconv.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_xslt.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.xslt" >XSLT</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
PHP <= 4.2.0 requires <TT CLASS="filename" >sablot.dll</TT >, <TT CLASS="filename" >expat.dll</TT > (bundled). PHP >= 4.2.1 requires <TT CLASS="filename" >sablot.dll</TT >, <TT CLASS="filename" >expat.dll</TT >, <TT CLASS="filename" >iconv.dll</TT > (bundled). </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_yaz.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.yaz" >YAZ</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Requires: <TT CLASS="filename" >yaz.dll</TT > (bundled)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_zib.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.zip" >Zip File</A > functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Read only access</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >php_zlib.dll</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#ref.zlib" >ZLib</A > compression functions</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Built in since PHP 4.3.0</TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.commandline" ></A >Servers-CGI/Commandline</H2 ><P >
The default is to build PHP as a CGI program. This creates a commandline interpreter, which can be used for CGI processing, or for non-web-related PHP scripting. If you are running a web server PHP has module support for, you should generally go for that solution for performance reasons. However, the CGI version enables Apache users to run different PHP-enabled pages under different user-ids. Please make sure you read through the <A HREF="#security.index" >Security chapter</A > if you are going to run PHP as a CGI. </P ><P >
As of PHP 4.3.0, some important additions have happened to PHP. A new SAPI named CLI also exists and it has the same name as the CGI binary. What is installed at <TT CLASS="literal" >{PREFIX}/bin/php</TT > depends on your configure line and this is described in detail in the manual section named <A HREF="#features.commandline" >Using PHP from the command line</A >. For further details please read that section of the manual. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.commandline.testing" ></A >Testing</H3 ><P >
If you have built PHP as a CGI program, you may test your build by typing <B CLASS="command" >make test</B >. It is always a good idea to test your build. This way you may catch a problem with PHP on your platform early instead of having to struggle with it later. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.commandline.benchmarking" ></A >Benchmarking</H3 ><P >
If you have built PHP 3 as a CGI program, you may benchmark your build by typing <B CLASS="command" >make bench</B >. Note that if <A HREF="#ini.safe-mode" >bezpeΦn² re╛im</A > is on by default, the benchmark may not be able to finish if it takes longer then the 30 seconds allowed. This is because the <A HREF="#function.set-time-limit" ><B CLASS="function" >set_time_limit()</B ></A > can not be used in <A HREF="#ini.safe-mode" >bezpeΦn² re╛im</A >. Use the <A HREF="#ini.max-execution-time" >max_execution_time</A > configuration setting to control this time for your own scripts. <B CLASS="command" >make bench</B > ignores the <A HREF="#configuration.file" >configuration file</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <B CLASS="command" >make bench</B > is only available for PHP 3. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.commandline.using-variables" ></A >Using Variables</H3 ><P >
Some server supplied environment variables are not defined in the current <A HREF="http://hoohoo.ncsa.uiuc.edu/cgi/env.html" TARGET="_top" >CGI/1.1 specification</A >. Only the following variables are defined there; everything else should be treated as 'vendor extensions': AUTH_TYPE, CONTENT_LENGTH, CONTENT_TYPE, GATEWAY_INTERFACE, PATH_INFO, PATH_TRANSLATED, QUERY_STRING, REMOTE_ADDR, REMOTE_HOST, REMOTE_IDENT, REMOTE_USER, REQUEST_METHOD, SCRIPT_NAME, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL and SERVER_SOFTWARE </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.apache" ></A >Servers-Apache</H2 ><P >
This section contains notes and hints specific to Apache installs of PHP, both for <A HREF="#install.apache.unix" >Unix</A > and <A HREF="#install.apache.windows" >Windows</A > versions. We also have <A HREF="#install.apache2" >instructions and notes for Apache 2 on a separate page</A >. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.apache.unix" ></A >Details of installing PHP with Apache on Unix</H3 ><P >
You can select arguments to add to the <B CLASS="command" >configure</B > on line 10 below from the <A HREF="#install.configure" >Complete list of configure options</A >. The version numbers have been omitted here, to ensure the instructions are not incorrect. You will need to replace the 'xxx' here with the correct values from your files. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="install.apache.unix.longer" ></A ><P ><B >P°φklad 3-4. Installation Instructions (Apache Shared Module Version) for PHP </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >1. gunzip apache_xxx.tar.gz 2. tar -xvf apache_xxx.tar 3. gunzip php-xxx.tar.gz 4. tar -xvf php-xxx.tar 5. cd apache_xxx 6. ./configure --prefix=/www --enable-module=so 7. make 8. make install 9. cd ../php-xxx 10. Now, configure your PHP. This is where you customize your PHP with various options, like which extensions will be enabled. Do a ./configure --help for a list of available options. In our example we'll do a simple configure with Apache 1 and MySQL support. Your path to apxs may differ from our example. ./configure --with-mysql --with-apxs=/www/bin/apxs 11. make 12. make install If you decide to change your configure options after installation, you only need to repeat the last three steps. You only need to restart apache for the new module to take effect. A recompile of Apache is not needed. Note that unless told otherwise, 'make install' will also install PEAR, various PHP tools such as phpize, install the PHP CLI, and more. 13. Setup your php.ini file: cp php.ini-dist /usr/local/lib/php.ini You may edit your .ini file to set PHP options. If you prefer your php.ini in another location, use --with-config-file-path=/some/path in step 10. If you instead choose php.ini-recommended, be certain to read the list of changes within, as they affect how PHP behaves. 14. Edit your httpd.conf to load the PHP module. The path on the right hand side of the LoadModule statement must point to the path of the PHP module on your system. The make install from above may have already added this for you, but be sure to check. For PHP 4: LoadModule php4_module libexec/libphp4.so For PHP 5: LoadModule php5_module libexec/libphp5.so 15. And in the AddModule section of httpd.conf, somewhere under the ClearModuleList, add this: For PHP 4: AddModule mod_php4.c For PHP 5: AddModule mod_php5.c 16. Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse the .php extension as PHP. You could have any extension(s) parse as PHP by simply adding more, with each separated by a space. We'll add .phtml to demonstrate. AddType application/x-httpd-php .php .phtml It's also common to setup the .phps extension to show highlighted PHP source, this can be done with: AddType application/x-httpd-php-source .phps 17. Use your normal procedure for starting the Apache server. (You must stop and restart the server, not just cause the server to reload by use a HUP or USR1 signal.)</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Depending on your Apache install and Unix variant, there are many possible ways to stop and restart the server. Below are some typical lines used in restarting the server, for different apache/unix installations. You should replace <TT CLASS="literal" >/path/to/</TT > with the path to these applications on your systems. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN1336" ></A ><P ><B >P°φklad 3-5. Example commands for restarting Apache</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >1. Several Linux and SysV variants: /etc/rc.d/init.d/httpd restart 2. Using apachectl scripts: /path/to/apachectl stop /path/to/apachectl start 3. httpdctl and httpsdctl (Using OpenSSL), similar to apachectl: /path/to/httpsdctl stop /path/to/httpsdctl start 4. Using mod_ssl, or another SSL server, you may want to manually stop and start: /path/to/apachectl stop /path/to/apachectl startssl</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
The locations of the apachectl and http(s)dctl binaries often vary. If your system has <TT CLASS="literal" >locate</TT > or <TT CLASS="literal" >whereis</TT > or <TT CLASS="literal" >which</TT > commands, these can assist you in finding your server control programs. </P ><P >
Different examples of compiling PHP for apache are as follows: <DIV CLASS="informalexample" ><A NAME="AEN1344" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >./configure --with-apxs --with-pgsql</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
This will create a <TT CLASS="filename" >libphp4.so</TT > shared library that is loaded into Apache using a LoadModule line in Apache's <TT CLASS="filename" >httpd.conf</TT > file. The PostgreSQL support is embedded into this <TT CLASS="filename" >libphp4.so</TT > library. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN1351" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >./configure --with-apxs --with-pgsql=shared</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
This will create a <TT CLASS="filename" >libphp4.so</TT > shared library for Apache, but it will also create a <TT CLASS="filename" >pgsql.so</TT > shared library that is loaded into PHP either by using the extension directive in <TT CLASS="filename" >php.ini</TT > file or by loading it explicitly in a script using the <A HREF="#function.dl" ><B CLASS="function" >dl()</B ></A > function. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN1359" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >./configure --with-apache=/path/to/apache_source --with-pgsql</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
This will create a <TT CLASS="filename" >libmodphp4.a</TT > library, a <TT CLASS="filename" >mod_php4.c</TT > and some accompanying files and copy this into the <TT CLASS="literal" >src/modules/php4</TT > directory in the Apache source tree. Then you compile Apache using <TT CLASS="literal" >--activate-module=src/modules/php4/libphp4.a</TT > and the Apache build system will create <TT CLASS="filename" >libphp4.a</TT > and link it statically into the <TT CLASS="filename" >httpd</TT > binary. The PostgreSQL support is included directly into this <TT CLASS="filename" >httpd</TT > binary, so the final result here is a single <TT CLASS="filename" >httpd</TT > binary that includes all of Apache and all of PHP. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN1371" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >./configure --with-apache=/path/to/apache_source --with-pgsql=shared</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Same as before, except instead of including PostgreSQL support directly into the final <TT CLASS="filename" >httpd</TT > you will get a <TT CLASS="filename" >pgsql.so</TT > shared library that you can load into PHP from either the <TT CLASS="filename" >php.ini</TT > file or directly using <A HREF="#function.dl" ><B CLASS="function" >dl()</B ></A >. </P ><P >
When choosing to build PHP in different ways, you should consider the advantages and drawbacks of each method. Building as a shared object will mean that you can compile apache separately, and don't have to recompile everything as you add to, or change, PHP. Building PHP into apache (static method) means that PHP will load and run faster. For more information, see the Apache <A HREF="http://httpd.apache.org/docs/dso.html" TARGET="_top" >webpage on DSO support</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Apache's default <TT CLASS="filename" >httpd.conf</TT > currently ships with a section that looks like this: <DIV CLASS="informalexample" ><A NAME="AEN1383" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >User nobody Group "#-1"</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Unless you change that to "Group nogroup" or something like that ("Group daemon" is also very common) PHP will not be able to open files. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Make sure you specify the installed version of apxs when using <TT CLASS="option" >--with-apxs=/path/to/apxs</TT >. You must NOT use the apxs version that is in the apache sources but the one that is actually installed on your system. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.apache.windows" ></A >Installing PHP on Windows with Apache 1.3.x</H3 ><P >
There are two ways to set up PHP to work with Apache 1.3.x on Windows. One is to use the CGI binary (php.exe), the other is to use the Apache module DLL. In either case you need to stop the Apache server, and edit your <TT CLASS="filename" >httpd.conf</TT > to configure Apache to work with PHP. </P ><P >
It is worth noting here that now the SAPI module has been made more stable under Windows, we recommend it's use above the CGI binary, since it is more transparent and secure. </P ><P >
Although there can be a few variations of configuring PHP under Apache, these are simple enough to be used by the newcomer. Please consult the Apache Docs for further configuration directives. </P ><P >
If you unziped the PHP package to <TT CLASS="filename" >c:\php\</TT > as described in the <A HREF="#install.windows.manual" >Manual Installation Steps</A > section, you need to insert these lines to your Apache configuration file to set up the CGI binary: <P ></P ><UL ><LI ><P >
<TT CLASS="literal" >
ScriptAlias /php/ "c:/php/" </TT > </P ></LI ><LI ><P >
<TT CLASS="literal" >
AddType application/x-httpd-php .php .phtml </TT > </P ></LI ><LI ><P >
<TT CLASS="literal" >
Action application/x-httpd-php "/php/php.exe" </TT > </P ></LI ></UL > Note that the second line in the list above can be found in the actual versions of <TT CLASS="filename" >httpd.conf</TT >, but it is commented out. Remember also to substitute the <TT CLASS="filename" >c:/php/</TT > for your actual path to PHP. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
By using the CGI setup, your server is open to several possible attacks. Please read our <A HREF="#security.cgi-bin" >CGI security section</A > to learn how to defend yourself from attacks. </P ></TD ></TR ></TABLE ></DIV ><P >
If you would like to use PHP as a module in Apache, be sure to copy <TT CLASS="filename" >php4ts.dll</TT > to the <TT CLASS="filename" >windows/system</TT > (for Windows 9x/Me), <TT CLASS="filename" >winnt/system32</TT > (for Windows NT/2000) or <TT CLASS="filename" >windows/system32</TT > (for Windows XP) directory, overwriting any older file. Then you should add the following lines to your Apache <TT CLASS="filename" >httpd.conf</TT > file: <P ></P ><UL ><LI ><P >
Open <TT CLASS="filename" >httpd.conf</TT > with your favorite editor and locate the <TT CLASS="literal" >LoadModule</TT > directive and add the following line <SPAN CLASS="emphasis" ><I CLASS="emphasis" >at the end</I ></SPAN > of the list for PHP 4: <TT CLASS="literal" >LoadModule php4_module "c:/php/sapi/php4apache.dll"</TT > or the following for PHP 5: <TT CLASS="literal" >LoadModule php5_module "c:/php/sapi/php5apache.dll"</TT > </P ></LI ><LI ><P >
You may find after using the Windows installer for Apache that you need to define the <TT CLASS="literal" >AddModule</TT > directive for <TT CLASS="filename" >mod_php4.c</TT >. This is especially important if the <TT CLASS="literal" >ClearModuleList</TT > directive is defined, which you will find by scrolling down a few lines. You will see a list of <TT CLASS="literal" >AddModule</TT > entries, add the following line <SPAN CLASS="emphasis" ><I CLASS="emphasis" >at the end</I ></SPAN > of the list: <TT CLASS="literal" >AddModule mod_php4.c</TT > For PHP 5, instead use <TT CLASS="literal" >AddModule mod_php5.c</TT > </P ></LI ><LI ><P >
Search for a phrase similar to <TT CLASS="literal" ># AddType allows you to tweak mime.types</TT >. You will see some <TT CLASS="literal" >AddType</TT > entries, add the following line <SPAN CLASS="emphasis" ><I CLASS="emphasis" >at the end</I ></SPAN > of the list: <TT CLASS="literal" >AddType application/x-httpd-php .php</TT >. You can choose any extension you want to parse through PHP here. .php is simply the one we suggest. You can even include .html, and .php3 can be added for backwards compatibility. </P ></LI ></UL > </P ><P >
After changing the configuration file, remember to restart the server, for example, <B CLASS="command" >NET STOP APACHE</B > followed by <B CLASS="command" >NET START APACHE</B >, if you run Apache as a Windows Service, or use your regular shortcuts. </P ><P >
There are two ways you can use the source code highlighting feature, however their ability to work depends on your installation. If you have configured Apache to use PHP as an SAPI module, then by adding the following line to your <TT CLASS="filename" >httpd.conf</TT > (at the same place you inserted <TT CLASS="literal" >AddType application/x-httpd-php .php</TT >, see above) you can use this feature: <TT CLASS="literal" >AddType application/x-httpd-php-source .phps</TT >. </P ><P >
If you chose to configure Apache to use PHP as a CGI binary, you will need to use the <A HREF="#function.show-source" ><B CLASS="function" >show_source()</B ></A > function. To do this simply create a PHP script file and add this code: <TT CLASS="literal" ><?php show_source ("original_php_script.php"); ?></TT >. Substitute <TT CLASS="literal" >original_php_script.php</TT > with the name of the file you wish to show the source of. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > On Win-Apache all backslashes in a path statement such as "c:\directory\file.ext", must be converted to forward slashes, as "c:/directory/file.ext". </P ></BLOCKQUOTE ></DIV ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.apache2" ></A >Servers-Apache 2.0</H2 ><P >
This section contains notes and hints specific to Apache 2.0 installs of <TT CLASS="literal" >PHP</TT >, both for <A HREF="#install.apache2.unix" >Unix</A > and <A HREF="#install.apache2.windows" >Windows</A > versions. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Do not use Apache 2.0 and <TT CLASS="literal" >PHP</TT > in a production environment neither on Unix nor on Windows. </P ></TD ></TR ></TABLE ></DIV ><P >
You are highly encouraged to take a look at the <A HREF="http://httpd.apache.org/docs-2.0/" TARGET="_top" >Apache Documentation</A > to get a basic understanding of the Apache 2.0 Server. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="compat.apache2" ></A >PHP and Apache 2.0 compatibility notes</H3 ><P >
The following versions of PHP are known to work with the most recent version of Apache 2.0: <P ></P ><UL COMPACT="COMPACT" ><LI ><SPAN >
PHP 4.3.0 or later available at <A HREF="http://www.php.net/downloads.php" TARGET="_top" >http://www.php.net/downloads.php</A >. </SPAN ></LI ><LI ><SPAN >
the latest stable development version. Get the source code <A HREF="http://snaps.php.net/php4-latest.tar.gz" TARGET="_top" >
http://snaps.php.net/php4-latest.tar.gz</A > or download binaries for Windows <A HREF="http://snaps.php.net/win32/php4-win32-latest.zip" TARGET="_top" >
http://snaps.php.net/win32/php4-win32-latest.zip</A >. </SPAN ></LI ><LI ><SPAN >
a prerelease version downloadable from <A HREF="http://qa.php.net/" TARGET="_top" >http://qa.php.net/</A >. </SPAN ></LI ><LI ><SPAN >
you have always the option to obtain <TT CLASS="literal" >PHP</TT > through <A HREF="http://www.php.net/anoncvs.php" TARGET="_top" >anonymous CVS</A >. </SPAN ></LI ></UL > These versions of <TT CLASS="literal" >PHP</TT > are compatible to Apache 2.0.40 and later. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Apache 2.0 <TT CLASS="literal" >SAPI</TT >-support started with PHP 4.2.0. PHP 4.2.3 works with Apache 2.0.39, don't use any other version of Apache with PHP 4.2.3. However, the recommended setup is to use PHP 4.3.0 or later with the most recent version of Apache2. </P ><P >
All mentioned versions of <TT CLASS="literal" >PHP</TT > will work still with Apache 1.3.x. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.apache2.unix" ></A >PHP and Apache 2 on Linux</H3 ><P >
Download the most recent version of <A HREF="http://www.apache.org/" TARGET="_top" >
Apache 2.0</A > and a fitting PHP version from the above mentioned places. This quick guide covers only the basics to get started with Apache 2.0 and <TT CLASS="literal" >PHP</TT >. For more information read the <A HREF="http://httpd.apache.org/docs-2.0/" TARGET="_top" >Apache Documentation</A >. The version numbers have been omitted here, to ensure the instructions are not incorrect. You will need to replace the 'NN' here with the correct values from your files. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN1495" ></A ><P ><B >P°φklad 3-6. Installation Instructions (Apache 2 Shared Module Version) </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >1. gzip -d httpd-2_0_NN.tar.gz 2. tar xvf httpd-2_0_NN.tar 3. gunzip php-NN.tar.gz 4. tar -xvf php-NN.tar 5. cd httpd-2_0_NN 6. ./configure --enable-so 7. make 8. make install Now you have Apache 2.0.NN available under /usr/local/apache2, configured with loadable module support and the standard MPM prefork. To test the installation use your normal procedure for starting the Apache server, e.g.: /usr/local/apache2/bin/apachectl start and stop the server to go on with the configuration for PHP: /usr/local/apache2/bin/apachectl stop. 9. cd ../php-NN 10. Now, configure your PHP. This is where you customize your PHP with various options, like which extensions will be enabled. Do a ./configure --help for a list of available options. In our example we'll do a simple configure with Apache 2 and MySQL support. Your path to apxs may differ, in fact, the binary may even be named apxs2 on your system. ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql 11. make 12. make install If you decide to change your configure options after installation, you only need to repeat the last three steps. You only need to restart apache for the new module to take effect. A recompile of Apache is not needed. Note that unless told otherwise, 'make install' will also install PEAR, various PHP tools such as phpize, install the PHP CLI, and more. 13. Setup your php.ini cp php.ini-dist /usr/local/lib/php.ini You may edit your .ini file to set PHP options. If you prefer having php.ini in another location, use --with-config-file-path=/some/path in step 10. If you instead choose php.ini-recommended, be certain to read the list of changes within, as they affect how PHP behaves. 14. Edit your httpd.conf to load the PHP module. The path on the right hand side of the LoadModule statement must point to the path of the PHP module on your system. The make install from above may have already added this for you, but be sure to check. For PHP 4: LoadModule php4_module libexec/libphp4.so For PHP 5: LoadModule php5_module libexec/libphp5.so 15. Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse the .php extension as PHP. You could have any extension(s) parse as PHP by simply adding more, with each separated by a space. We'll add .phtml to demonstrate. AddType application/x-httpd-php .php .phtml It's also common to setup the .phps extension to show highlighted PHP source, this can be done with: AddType application/x-httpd-php-source .phps 16. Use your normal procedure for starting the Apache server, e.g.: /usr/local/apache2/bin/apachectl start</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Following the steps above you will have a running Apache 2.0 with support for <TT CLASS="literal" >PHP</TT > as <TT CLASS="literal" >SAPI</TT > module. Of course there are many more configuration options available for both, Apache and <TT CLASS="literal" >PHP</TT >. For more information use <B CLASS="command" >./configure --help</B > in the corresponding source tree. In case you wish to build a multithreaded version of Apache 2.0 you must overwrite the standard MPM-Module <TT CLASS="filename" >prefork</TT > either with <TT CLASS="filename" >worker</TT > or <TT CLASS="filename" >perchild</TT >. To do so append to your configure line in step 6 above either the option <TT CLASS="option" >--with-mpm=worker</TT > or <TT CLASS="option" >--with-mpm=perchild</TT >. Take care about the consequences and understand what you are doing. For more information read the Apache documentation about the <A HREF="http://httpd.apache.org/docs-2.0/mpm.html" TARGET="_top" >
MPM-Modules</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > To build a multithreaded version of Apache your system must support threads. This also implies to build <TT CLASS="literal" >PHP</TT > with experimental Zend Thread Safety (ZTS). Therefore not all extensions might be available. The recommended setup is to build Apache with the standard <TT CLASS="filename" >prefork</TT > MPM-Module. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.apache2.windows" ></A >PHP and Apache 2.0 on Windows</H3 ><P >
Consider to read the <A HREF="http://httpd.apache.org/docs-2.0/platform/windows.html" TARGET="_top" >
Windows specific notes</A > for Apache 2.0. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Apache 2.0 is designed to run on Windows NT 4.0, Windows 2000 or Windows XP. At this time, support for Windows 9x is incomplete. Apache 2.0 is not expected to work on those platforms at this time. </P ></TD ></TR ></TABLE ></DIV ><P >
Download the most recent version of <A HREF="http://www.apache.org/" TARGET="_top" >
Apache 2.0</A > and a fitting PHP version from the above mentioned places. Follow the <A HREF="#install.windows.manual" >Manual Installation Steps</A > and come back to go on with the integration of <TT CLASS="literal" >PHP</TT > and Apache. </P ><P >
There are two ways to set up <TT CLASS="literal" >PHP</TT > to work with Apache 2.0 on Windows. One is to use the CGI binary the other is to use the Apache module DLL. In either case you need to stop the Apache server, and edit your <TT CLASS="filename" >httpd.conf</TT > to configure Apache to work with <TT CLASS="literal" >PHP</TT >. </P ><P >
You need to insert these three lines to your Apache <TT CLASS="filename" >httpd.conf</TT > configuration file to set up the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >CGI binary</I ></SPAN >: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN1530" ></A ><P ><B >P°φklad 3-7. PHP and Apache 2.0 as CGI</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="apache" >ScriptAlias /php/ "c:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php.exe"</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
If you would like to use <TT CLASS="literal" >PHP</TT > as a module in Apache 2.0, be sure to move <TT CLASS="filename" >php4ts.dll</TT > for PHP 4, or <TT CLASS="filename" >php5ts.dll</TT > for PHP 5, to <TT CLASS="filename" >winnt/system32</TT > (for Windows NT/2000) or <TT CLASS="filename" >windows/system32</TT > (for Windows XP), overwriting any older file. You need to insert these two lines to your Apache <TT CLASS="filename" >httpd.conf</TT > configuration file to set up the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >PHP-Module</I ></SPAN > for Apache 2.0: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN1541" ></A ><P ><B >P°φklad 3-8. PHP and Apache 2.0 as Module</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="apache" >; For PHP 4 do something like this: LoadModule php4_module "c:/php/sapi/php4apache2.dll" AddType application/x-httpd-php .php ; For PHP 5 do something like this: LoadModule php5_module "c:/php/sapi/php5apache2.dll" AddType application/x-httpd-php .php</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Remember to substitute the <TT CLASS="filename" >c:/php/</TT > for your actual path to <TT CLASS="literal" >PHP</TT > in the above examples. Take care to use either <TT CLASS="filename" >php4apache2.dll</TT > or <TT CLASS="filename" >php5apache2.dll</TT > in your LoadModule directive and <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN ><TT CLASS="filename" >php4apache.dll</TT > or <TT CLASS="filename" >php5apache.dll</TT > as the latter ones are designed to run with <A HREF="#install.apache.windows" >Apache 1.3.x</A >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Don't mix up your installation with dll files from <SPAN CLASS="emphasis" ><I CLASS="emphasis" >different PHP versions </I ></SPAN >. You have the only choice to use the dll's and extensions that ship with your downloaded PHP version. </P ></TD ></TR ></TABLE ></DIV ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.caudium" ></A >Servers-Caudium</H2 ><P >
PHP 4 can be built as a Pike module for the <A HREF="http://caudium.net/" TARGET="_top" >Caudium webserver</A >. Note that this is not supported with PHP 3. Follow the simple instructions below to install PHP 4 for Caudium. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="install.caudium.instructions" ></A ><P ><B >P°φklad 3-9. Caudium Installation Instructions</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >1. Make sure you have Caudium installed prior to attempting to install PHP 4. For PHP 4 to work correctly, you will need Pike 7.0.268 or newer. For the sake of this example we assume that Caudium is installed in /opt/caudium/server/. 2. Change directory to php-x.y.z (where x.y.z is the version number). 3. ./configure --with-caudium=/opt/caudium/server 4. make 5. make install 6. Restart Caudium if it's currently running. 7. Log into the graphical configuration interface and go to the virtual server where you want to add PHP 4 support. 8. Click Add Module and locate and then add the PHP 4 Script Support module. 9. If the documentation says that the 'PHP 4 interpreter isn't available', make sure that you restarted the server. If you did check /opt/caudium/logs/debug/default.1 for any errors related to <filename>PHP4.so</filename>. Also make sure that <filename>caudium/server/lib/[pike-version]/PHP4.so</filename> is present. 10. Configure the PHP Script Support module if needed.</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
You can of course compile your Caudium module with support for the various extensions available in PHP 4. See the <A HREF="#install.configure" >complete list of configure options</A > for an exhaustive rundown. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > When compiling PHP 4 with MySQL support you must make sure that the normal MySQL client code is used. Otherwise there might be conflicts if your Pike already has MySQL support. You do this by specifying a MySQL install directory the <TT CLASS="option" > --with-mysql</TT > option. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.fhttpd" ></A >Servers-fhttpd</H2 ><P >
To build PHP as an fhttpd module, answer "yes" to "Build as an fhttpd module?" (the <A HREF="#install.configure.with-fhttpd" >
--with-fhttpd</A >=<TT CLASS="replaceable" ><I >DIR</I ></TT > option to configure) and specify the fhttpd source base directory. The default directory is <TT CLASS="filename" >/usr/local/src/fhttpd</TT >. If you are running fhttpd, building PHP as a module will give better performance, more control and remote execution capability. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Support for fhttpd is no longer available as of PHP 4.3.0. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.iis" ></A >Servers-IIS/PWS</H2 ><P >
This section contains notes and hints specific to IIS (Microsoft Internet Information Server). Installing PHP for <A HREF="#install.iis.iis3" >PWS/IIS 3</A >, <A HREF="#install.iis.pws4" >PWS 4 or newer</A > and <A HREF="#install.iis.iis4" >IIS 4 or newer</A > versions. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Important for CGI users: </B > Read the <A HREF="#faq.installation.forceredirect" >faq on cgi.force_redirect</A > for important details. This directive needs to be set to <TT CLASS="literal" >0</TT >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.iis.iis3" ></A >Windows and PWS/IIS 3</H3 ><P >
The recommended method for configuring these servers is to use the REG file included with the distribution (pws-php4cgi.reg). You may want to edit this file and make sure the extensions and PHP install directories match your configuration. Or you can follow the steps below to do it manually. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
These steps involve working directly with the Windows registry. One error here can leave your system in an unstable state. We highly recommend that you back up your registry first. The PHP Development team will not be held responsible if you damage your registry. </P ></TD ></TR ></TABLE ></DIV ><P >
<P ></P ><UL ><LI ><P >
Run Regedit. </P ></LI ><LI ><P >
Navigate to: <TT CLASS="literal" >HKEY_LOCAL_MACHINE /System /CurrentControlSet /Services /W3Svc /Parameters /ScriptMap</TT >. </P ></LI ><LI ><P >
On the edit menu select: <TT CLASS="literal" >New->String Value</TT >. </P ></LI ><LI ><P >
Type in the extension you wish to use for your php scripts. For example <TT CLASS="literal" >.php</TT > </P ></LI ><LI ><P >
Double click on the new string value and enter the path to <TT CLASS="literal" >php.exe</TT > in the value data field. ex: <TT CLASS="literal" >c:\php\php.exe</TT >. </P ></LI ><LI ><P >
Repeat these steps for each extension you wish to associate with PHP scripts. </P ></LI ></UL > </P ><P >
The following steps do not affect the web server installation and only apply if you want your PHP scripts to be executed when they are run from the command line (ex. run <TT CLASS="filename" >c:\myscripts\test.php</TT >) or by double clicking on them in a directory viewer window. You may wish to skip these steps as you might prefer the PHP files to load into a text editor when you double click on them. </P ><P >
<P ></P ><UL ><LI ><P >
Navigate to: <TT CLASS="literal" >HKEY_CLASSES_ROOT</TT > </P ></LI ><LI ><P >
On the edit menu select: <TT CLASS="literal" >New->Key</TT >. </P ></LI ><LI ><P >
Name the key to the extension you setup in the previous section. ex: <TT CLASS="literal" >.php</TT > </P ></LI ><LI ><P >
Highlight the new key and in the right side pane, double click the "default value" and enter <TT CLASS="literal" >phpfile</TT >. </P ></LI ><LI ><P >
Repeat the last step for each extension you set up in the previous section. </P ></LI ><LI ><P >
Now create another <TT CLASS="literal" >New->Key</TT > under <TT CLASS="literal" >HKEY_CLASSES_ROOT</TT > and name it <TT CLASS="literal" >phpfile</TT >. </P ></LI ><LI ><P >
Highlight the new key <TT CLASS="literal" >phpfile</TT > and in the right side pane, double click the "default value" and enter <TT CLASS="literal" >PHP Script</TT >. </P ></LI ><LI ><P >
Right click on the <TT CLASS="literal" >phpfile</TT > key and select <TT CLASS="literal" >New->Key</TT >, name it <TT CLASS="literal" >Shell</TT >. </P ></LI ><LI ><P >
Right click on the <TT CLASS="literal" >Shell</TT > key and select <TT CLASS="literal" >New->Key</TT >, name it <TT CLASS="literal" >open</TT >. </P ></LI ><LI ><P >
Right click on the <TT CLASS="literal" >open</TT > key and select <TT CLASS="literal" >New->Key</TT >, name it <TT CLASS="literal" >command</TT >. </P ></LI ><LI ><P >
Highlight the new key <TT CLASS="literal" >command</TT > and in the right side pane, double click the "default value" and enter the path to <TT CLASS="literal" >php.exe</TT >. ex: <TT CLASS="literal" >c:\php\php.exe -q %1</TT >. (don't forget the <TT CLASS="literal" >%1</TT >). </P ></LI ><LI ><P >
Exit Regedit. </P ></LI ><LI ><P >
If using PWS on Windows, reboot to reload the registry. </P ></LI ></UL > </P ><P >
PWS and IIS 3 users now have a fully operational system. IIS 3 users can use a nifty <A HREF="http://www.genusa.com/iis/iiscfg.html" TARGET="_top" >tool</A > from Steven Genusa to configure their script maps. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.iis.pws4" ></A >Windows and PWS 4 or newer</H3 ><P >
When installing PHP on Windows with PWS 4 or newer version, you have two options. One to set up the PHP CGI binary, the other is to use the ISAPI module DLL. </P ><P >
If you choose the CGI binary, do the following: <P ></P ><UL ><LI ><P >
Edit the enclosed <TT CLASS="filename" >pws-php4cgi.reg</TT > file (look into the SAPI dir) to reflect the location of your <TT CLASS="filename" >php.exe</TT >. Backslashes should be escaped, for example: <TT CLASS="literal" >[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="c:\\php\\php.exe"</TT > Now merge this registery file into your system; you may do this by double-clicking it. </P ></LI ><LI ><P >
In the PWS Manager, right click on a given directory you want to add PHP support to, and select Properties. Check the 'Execute' checkbox, and confirm. </P ></LI ></UL > </P ><P >
If you choose the ISAPI module, do the following: <P ></P ><UL ><LI ><P >
Edit the enclosed <TT CLASS="filename" >pws-php4isapi.reg</TT > file (look into the SAPI dir) to reflect the location of your <TT CLASS="filename" >php4isapi.dll</TT >. Backslashes should be escaped, for example: <TT CLASS="literal" >[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="c:\\php\\sapi\\php4isapi.dll"</TT > Now merge this registery file into your system; you may do this by double-clicking it. </P ></LI ><LI ><P >
In the PWS Manager, right click on a given directory you want to add PHP support to, and select Properties. Check the 'Execute' checkbox, and confirm. </P ></LI ></UL > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.iis.iis4" ></A >Windows NT/2000/XP and IIS 4 or newer</H3 ><P >
To install PHP on an NT/2000/XP Server running IIS 4 or newer, follow these instructions. You have two options to set up PHP, using the CGI binary (php.exe) or with the ISAPI module. </P ><P >
In either case, you need to start the Microsoft Management Console (may appear as 'Internet Services Manager', either in your Windows NT 4.0 Option Pack branch or the Control Panel=>Administrative Tools under Windows 2000/XP). Then right click on your Web server node (this will most probably appear as 'Default Web Server'), and select 'Properties'. </P ><P >
If you want to use the CGI binary, do the following: <P ></P ><UL ><LI ><P >
Under 'Home Directory', 'Virtual Directory', or 'Directory', click on the 'Configuration' button, and then enter the App Mappings tab. </P ></LI ><LI ><P >
Click Add, and in the Executable box, type: <TT CLASS="literal" >c:\php\php.exe</TT > (assuming that you have unziped PHP in c:\php\). </P ></LI ><LI ><P >
In the Extension box, type the file name extension you want associated with PHP scripts. Leave 'Method exclusions' blank, and check the Script engine checkbox. You may also like to check the 'check that file exists' box - for a small performance penalty, IIS (or PWS) will check that the script file exists and sort out authentication before firing up php. This means that you will get sensible 404 style error messages instead of cgi errors complaining that PHP did not output any data. </P ><P >
You must start over from the previous step for each extension you want associated with PHP scripts. <TT CLASS="literal" >.php</TT > and <TT CLASS="literal" >.phtml</TT > are common, although <TT CLASS="literal" >.php3</TT > may be required for legacy applications. </P ></LI ><LI ><P >
Set up the appropriate security. (This is done in Internet Service Manager), and if your NT Server uses NTFS file system, add execute rights for I_USR_ to the directory that contains <TT CLASS="literal" >php.exe</TT >. </P ></LI ></UL > </P ><P >
To use the ISAPI module, do the following: <P ></P ><UL ><LI ><P >
If you don't want to perform HTTP Authentication using PHP, you can (and should) skip this step. Under ISAPI Filters, add a new ISAPI filter. Use PHP as the filter name, and supply a path to the php4isapi.dll. </P ></LI ><LI ><P >
Under 'Home Directory', click on the 'Configuration' button. Add a new entry to the Application Mappings. Use the path to the php4isapi.dll as the Executable, supply <TT CLASS="literal" >.php</TT > as the extension, leave Method exclusions blank, and check the Script engine checkbox. </P ></LI ><LI ><P >
Stop IIS completely (NET STOP iisadmin) </P ></LI ><LI ><P >
Start IIS again (NET START w3svc) </P ></LI ></UL > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.netscape-enterprise" ></A >Servers-Netscape, iPlanet and SunONE</H2 ><P >
This section contains notes and hints specific to Netscape, iPlanet and SunONE webserver installs of PHP, both for <A HREF="#install.netscape.sun" >Sun Solaris</A > and <A HREF="#install.netscape.windows" >Windows</A > versions. </P ><P >
From PHP 4.3.3 on you can use PHP scripts with the <A HREF="#ref.nsapi" >NSAPI module</A > to <A HREF="#install.netscape.specialpages" >generate custom directory listings and error pages</A >. Additional functions for Apache compatibility are also available. For support in current webservers read the <A HREF="#install.netscape.notes" >note about subrequests</A >. </P ><P >
You can find more information about setting up PHP for the Netscape Enterprise Server (NES) here: <A HREF="http://benoit.noss.free.fr/php/install-php4.html" TARGET="_top" >http://benoit.noss.free.fr/php/install-php4.html</A > </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.netscape.sun" ></A >Installing PHP with NES/iPlanet/SunONE Webserver on Sun Solaris</H3 ><P >
To build PHP with NES/iPlanet/SunONE webservers, enter the proper install directory for the <A HREF="#install.configure.with-nsapi" >--with-nsapi=[DIR]</A > option. The default directory is usually <TT CLASS="filename" >/opt/netscape/suitespot/</TT >. Please also read <TT CLASS="filename" >/php-xxx-version/sapi/nsapi/nsapi-readme.txt</TT >. </P ><P >
<P ></P ><OL TYPE="1" ><LI ><P >
Install the following packages from <A HREF="http://www.sunfreeware.com/" TARGET="_top" >
http://www.sunfreeware.com/</A > or another download site: <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><TT CLASS="filename" >autoconf-2.13</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >automake-1.4</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >bison-1_25-sol26-sparc-local</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >flex-2_5_4a-sol26-sparc-local</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >gcc-2_95_2-sol26-sparc-local</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >gzip-1.2.4-sol26-sparc-local</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >m4-1_4-sol26-sparc-local</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >make-3_76_1-sol26-sparc-local</TT ></TD ></TR ><TR ><TD >
<TT CLASS="filename" >mysql-3.23.24-beta</TT > (if you want mysql support) </TD ></TR ><TR ><TD ><TT CLASS="filename" >perl-5_005_03-sol26-sparc-local</TT ></TD ></TR ><TR ><TD ><TT CLASS="filename" >tar-1.13</TT > (GNU tar)</TD ></TR ></TBODY ></TABLE ><P ></P > </P ></LI ><LI ><P >
Make sure your path includes the proper directories <TT CLASS="literal" >PATH=.:/usr/local/bin:/usr/sbin:/usr/bin:/usr/ccs/bin</TT > and make it available to your system <TT CLASS="userinput" ><B >export PATH</B ></TT >. </P ></LI ><LI ><P >
<TT CLASS="userinput" ><B >gunzip php-x.x.x.tar.gz</B ></TT > (if you have a .gz dist, otherwise go to 4). </P ></LI ><LI ><P >
<TT CLASS="userinput" ><B >tar xvf php-x.x.x.tar</B ></TT > </P ></LI ><LI ><P >
Change to your extracted PHP directory: <TT CLASS="userinput" ><B >cd ../php-x.x.x </B ></TT > </P ></LI ><LI ><P >
For the following step, make sure <TT CLASS="filename" >/opt/netscape/suitespot/</TT > is where your netscape server is installed. Otherwise, change to the correct path and run: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >./configure --with-mysql=/usr/local/mysql \ --with-nsapi=/opt/netscape/suitespot/ \ --enable-libgcc</PRE ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
Run <B CLASS="command" >make</B > followed by <B CLASS="command" >make install</B >. </P ></LI ></OL > </P ><P >
After performing the base install and reading the appropriate readme file, you may need to perform some additional configuration steps. </P ><DIV CLASS="formalpara" ><P ><B >Configuration Instructions for NES/iPlanet/SunONE. </B > Firstly you may need to add some paths to the LD_LIBRARY_PATH environment for SunONE to find all the shared libs. This can best done in the start script for your SunONE webserver. Windows users can probably skip this step. The start script is often located in: <TT CLASS="filename" >/path/to/server/https-servername/start</TT >. You may also need to edit the configuration files that are located in: <TT CLASS="filename" >/path/to/server/https-servername/config/</TT >. <P ></P ><OL TYPE="1" ><LI ><P >
Add the following line to <TT CLASS="filename" >mime.types</TT > (you can do that by the administration server): <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >type=magnus-internal/x-httpd-php exts=php</PRE ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
Edit <TT CLASS="filename" >magnus.conf</TT > (for servers >= 6) or <TT CLASS="filename" >obj.conf</TT > (for servers < 6) and add the following, shlib will vary depending on your OS, for Unix it will be something like <TT CLASS="filename" >/opt/netscape/suitespot/bin/libphp4.so</TT >. You should place the following lines after <TT CLASS="literal" >mime types init</TT >. <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Init fn="load-modules" funcs="php4_init,php4_execute,php4_auth_trans" shlib="/opt/netscape/suitespot/bin/libphp4.so" Init fn="php4_init" LateInit="yes" errorString="Failed to initialize PHP!" [php_ini="/path/to/php.ini"]</PRE ></TD ></TR ></TABLE > (PHP >= 4.3.3) The <TT CLASS="literal" >php_ini</TT > parameter is optional but with it you can place your <TT CLASS="filename" >php.ini</TT > in your webserver config directory. </P ></LI ><LI ><P >
Configure the default object in <TT CLASS="filename" >obj.conf</TT > (for virtual server classes [SunONE 6.0+] in their <TT CLASS="filename" >vserver.obj.conf</TT >): <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><Object name="default"> . . . .#NOTE this next line should happen after all 'ObjectType' and before all 'AddLog' lines Service fn="php4_execute" type="magnus-internal/x-httpd-php" [inikey=value inikey=value ...] . . </Object></PRE ></TD ></TR ></TABLE > (PHP >= 4.3.3) As additional parameters you can add some special <TT CLASS="filename" >php.ini</TT >-values, for example you can set a <TT CLASS="literal" >docroot="/path/to/docroot"</TT > specific to the context <TT CLASS="literal" >php4_execute</TT > is called. For boolean ini-keys please use 0/1 as value, not <TT CLASS="literal" >"On","Off",...</TT > (this will not work correctly), e.g. <TT CLASS="literal" >zlib.output_compression=1</TT > instead of <TT CLASS="literal" >zlib.output_compression="On"</TT > </P ></LI ><LI ><P >
This is only needed if you want to configure a directory that only consists of PHP scripts (same like a <TT CLASS="filename" >cgi-bin</TT > directory): <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><Object name="x-httpd-php"> ObjectType fn="force-type" type="magnus-internal/x-httpd-php" Service fn=php4_execute [inikey=value inikey=value ...] </Object></PRE ></TD ></TR ></TABLE > After that you can configure a directory in the Administration server and assign it the style <TT CLASS="literal" >x-httpd-php</TT >. All files in it will get executed as PHP. This is nice to hide PHP usage by renaming files to <TT CLASS="filename" >.html</TT >. </P ></LI ><LI ><P >
Setup of authentication: PHP authentication cannot be used with any other authentication. ALL AUTHENTICATION IS PASSED TO YOUR PHP SCRIPT. To configure PHP Authentication for the entire server, add the following line to your default object: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><Object name="default"> AuthTrans fn=php4_auth_trans . . . </Object></PRE ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
To use PHP Authentication on a single directory, add the following: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><Object ppath="d:\path\to\authenticated\dir\*"> AuthTrans fn=php4_auth_trans </Object></PRE ></TD ></TR ></TABLE > </P ></LI ></OL > </P ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.netscape.windows" ></A >Installing PHP with NES/iPlanet/SunONE on Windows</H3 ><P >
To Install PHP as CGI (for Netscape Enterprise Server, iPlanet, SunONE, perhaps Fastrack), do the following: </P ><P ></P ><UL ><LI ><P >
Copy <TT CLASS="filename" >php4ts.dll</TT > to your systemroot (the directory where you installed Windows) </P ></LI ><LI ><P >
Make a file association from the command line. Type the following two lines: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >assoc .php=PHPScript ftype PHPScript=c:\php\php.exe %1 %*</PRE ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
In the Netscape Enterprise Administration Server create a dummy shellcgi directory and remove it just after (this step creates 5 important lines in obj.conf and allow the web server to handle shellcgi scripts). </P ></LI ><LI ><P >
In the Netscape Enterprise Administration Server create a new mime type (Category: type, Content-Type: magnus-internal/shellcgi, File Suffix:php). </P ></LI ><LI ><P >
Do it for each web server instance you want PHP to run </P ></LI ></UL ><P >
More details about setting up PHP as a CGI executable can be found here: <A HREF="http://benoit.noss.free.fr/php/install-php.html" TARGET="_top" >http://benoit.noss.free.fr/php/install-php.html</A > </P ><P >
To Install PHP as NSAPI (for Netscape Enterprise Server, iPlanet, SunONE, perhaps Fastrack), do the following: </P ><P ></P ><UL ><LI ><P >
Copy <TT CLASS="filename" >php4ts.dll</TT > to your systemroot (the directory where you installed Windows) </P ></LI ><LI ><P >
Make a file association from the command line. Type the following two lines: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="shell" >assoc .php=PHPScript ftype PHPScript=c:\php\php.exe %1 %*</PRE ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
In the Netscape Enterprise Administration Server create a new mime type (Category: type, Content-Type: magnus-internal/x-httpd-php, File Suffix: php). </P ></LI ><LI ><P >
Edit <TT CLASS="filename" >magnus.conf</TT > (for servers >= 6) or <TT CLASS="filename" >obj.conf</TT > (for servers < 6) and add the following: You should place the the lines after <TT CLASS="literal" >mime types init</TT >. <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Init fn="load-modules" funcs="php4_init,php4_execute,php4_auth_trans" shlib="c:/php/sapi/php4nsapi.dll" Init fn="php4_init" LateInit="yes" errorString="Failed to initialise PHP!" [php_ini="c:/path/to/php.ini"]</PRE ></TD ></TR ></TABLE > (PHP >= 4.3.3) The <TT CLASS="literal" >php_ini</TT > parameter is optional but with it you can place your <TT CLASS="filename" >php.ini</TT > in your webserver config directory. </P ></LI ><LI ><P >
Configure the default object in <TT CLASS="filename" >obj.conf</TT > (for virtual server classes [SunONE 6.0+] in their <TT CLASS="filename" >vserver.obj.conf</TT >): In the <TT CLASS="literal" ><Object name="default"></TT > section, place this line necessarily after all 'ObjectType' and before all 'AddLog' lines: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Service fn="php4_execute" type="magnus-internal/x-httpd-php" [inikey=value inikey=value ...]</PRE ></TD ></TR ></TABLE > (PHP >= 4.3.3) As additional parameters you can add some special <TT CLASS="filename" >php.ini</TT >-values, for example you can set a <TT CLASS="literal" >docroot="/path/to/docroot"</TT > specific to the context <TT CLASS="literal" >php4_execute</TT > is called. For boolean ini-keys please use 0/1 as value, not <TT CLASS="literal" >"On","Off",...</TT > (this will not work correctly), e.g. <TT CLASS="literal" >zlib.output_compression=1</TT > instead of <TT CLASS="literal" >zlib.output_compression="On"</TT > </P ></LI ><LI ><P >
This is only needed if you want to configure a directory that only consists of PHP scripts (same like a cgi-bin directory): <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><Object name="x-httpd-php"> ObjectType fn="force-type" type="magnus-internal/x-httpd-php" Service fn=php4_execute [inikey=value inikey=value ...] </Object></PRE ></TD ></TR ></TABLE > After that you can configure a directory in the Administration server and assign it the style <TT CLASS="literal" >x-httpd-php</TT >. All files in it will get executed as PHP. This is nice to hide PHP usage by renaming files to <TT CLASS="filename" >.html</TT >. </P ></LI ><LI ><P >
Restart your web service and apply changes </P ></LI ><LI ><P >
Do it for each web server instance you want PHP to run </P ></LI ></UL ><P >
More details about setting up PHP as an NSAPI filter can be found here: <A HREF="http://benoit.noss.free.fr/php/install-php4.html" TARGET="_top" >http://benoit.noss.free.fr/php/install-php4.html</A > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.netscape.phpini" ></A >CGI environment and recommended modifications in php.ini</H3 ><P >
Important when writing PHP scripts is the fact that iPlanet/SunONE/Netscape is a multithreaded web server. Because of that all requests are running in the same process space (the space of the webserver itsself) and this space has only one environment. If you want to get CGI variables like <TT CLASS="literal" >PATH_INFO</TT >, <TT CLASS="literal" >HTTP_HOST</TT > etc. it is not the correct way to try this in the old PHP 3.x way with <A HREF="#function.getenv" ><B CLASS="function" >getenv()</B ></A > or a similar way (register globals to environment, <TT CLASS="literal" >$_ENV</TT >). You would only get the environment of the running webserver without any valid CGI variables! </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Why are there (invalid) CGI variables in the environment? </P ><P >
Answer: This is because you started the webserver process from the admin server which runs the startup script of the webserver, you wanted to start, as a CGI script (a CGI script inside of the admin server!). This is why the environment of the started webserver has some CGI environment variables in it. You can test this by starting the webserver not from the administration server. Use the Unix command line as root user and start it manually - you will see there are no CGI-like environment variables. </P ></BLOCKQUOTE ></DIV ><P >
Simply change your scripts to get CGI variables in the correct way for PHP 4.x by using the superglobal <TT CLASS="literal" >$_SERVER</TT >. If you have older scripts which use <TT CLASS="literal" >$HTTP_HOST</TT >,..., you should turn on <TT CLASS="literal" >register_globals</TT > in <TT CLASS="filename" >php.ini</TT > and change the variable order to (important: remove <TT CLASS="literal" >"E"</TT > from it, because you do not need the environment here): <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >variables_order = "GPCS" register_globals = On</PRE ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.netscape.specialpages" ></A >Special use for error pages or self-made directory listings (PHP >= 4.3.3)</H3 ><P >
You can use PHP to generate the error pages for "404 Not Found" or similar. Add the following line to the object in <TT CLASS="filename" >obj.conf</TT > for every error page you want to overwrite: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Error fn="php4_execute" code=XXX script="/path/to/script.php" [inikey=value inikey=value...]</PRE ></TD ></TR ></TABLE > where <TT CLASS="literal" >XXX</TT > is the HTTP error code. Please delete any other <TT CLASS="literal" >Error</TT > directives which could interfere with yours. If you want to place a page for all errors that could exist, leave the <TT CLASS="literal" >code</TT > parameter out. Your script can get the HTTP status code with <TT CLASS="literal" >$_SERVER['ERROR_TYPE']</TT >. </P ><P >
Another possibility is to generate self-made directory listings. Just create a PHP script which displays a directory listing and replace the corresponding default Service line for <TT CLASS="literal" >type="magnus-internal/directory"</TT > in <TT CLASS="filename" >obj.conf</TT > with the following: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Service fn="php4_execute" type="magnus-internal/directory" script="/path/to/script.php" [inikey=value inikey=value...]</PRE ></TD ></TR ></TABLE > For both error and directory listing pages the original URI and translated URI are in the variables <TT CLASS="literal" >$_SERVER['PATH_INFO']</TT > and <TT CLASS="literal" >$_SERVER['PATH_TRANSLATED']</TT >. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.netscape.notes" ></A >Note about <A HREF="#function.nsapi-virtual" ><B CLASS="function" >nsapi_virtual()</B ></A > and subrequests (PHP >= 4.3.3)</H3 ><P >
The NSAPI module now supports the <A HREF="#function.nsapi-virtual" ><B CLASS="function" >nsapi_virtual()</B ></A > function (alias: <A HREF="#function.virtual" ><B CLASS="function" >virtual()</B ></A >) to make subrequests on the webserver and insert the result in the webpage. The problem is, that this function uses some undocumented features from the NSAPI library. </P ><P >
Under Unix this is not a problem, because the module automatically looks for the needed functions and uses them if available. If not, <A HREF="#function.nsapi-virtual" ><B CLASS="function" >nsapi_virtual()</B ></A > is disabled. </P ><P >
Under Windows limitations in the DLL handling need the use of a automatic detection of the most recent <TT CLASS="filename" >ns-httpdXX.dll</TT > file. This is tested for servers till version 6.1. If a newer version of the SunONE server is used, the detection fails and <A HREF="#function.nsapi-virtual" ><B CLASS="function" >nsapi_virtual()</B ></A > is disabled. </P ><P >
If this is the case, try the following: Add the following parameter to <TT CLASS="literal" >php4_init</TT > in <TT CLASS="filename" >magnus.conf</TT >/<TT CLASS="filename" >obj.conf</TT >: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Init fn=php4_init ... server_lib="ns-httpdXX.dll"</PRE ></TD ></TR ></TABLE > where <TT CLASS="literal" >XX</TT > is the correct DLL version number. To get it, look in the server-root for the correct DLL name. The DLL with the biggest filesize is the right one. </P ><P >
You can check the status by using the <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A > function. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > But be warned: Support for <A HREF="#function.nsapi-virtual" ><B CLASS="function" >nsapi_virtual()</B ></A > is EXPERIMENTAL!!! </P ></BLOCKQUOTE ></DIV ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.omnihttpd" ></A >Servers-OmniHTTPd Server</H2 ><P >
This section contains notes and hints specific to <A HREF="http://www.omnicron.ca/" TARGET="_top" >OmniHTTPd</A >. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.omnihttpd.windows" ></A >OmniHTTPd 2.0b1 and up for Windows</H3 ><P >
You need to complete the following steps to make PHP work with OmniHTTPd. This is a CGI executable setup. SAPI is supported by OmniHTTPd, but some tests have shown that it is not so stable to use PHP as an ISAPI module. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Important for CGI users: </B > Read the <A HREF="#faq.installation.forceredirect" >faq on cgi.force_redirect</A > for important details. This directive needs to be set to <TT CLASS="literal" >0</TT >. </P ></BLOCKQUOTE ></DIV ><P >
<P ></P ><OL TYPE="1" ><LI ><P >
Install OmniHTTPd server. </P ></LI ><LI ><P >
Right click on the blue OmniHTTPd icon in the system tray and select <TT CLASS="literal" >Properties</TT > </P ></LI ><LI ><P >
Click on <TT CLASS="literal" >Web Server Global Settings</TT > </P ></LI ><LI ><P >
On the 'External' tab, enter: <TT CLASS="literal" >virtual = .php | actual = c:\path-to-php-dir\php.exe</TT >, and use the Add button. </P ></LI ><LI ><P >
On the <TT CLASS="literal" >Mime</TT > tab, enter: <TT CLASS="literal" >virtual = wwwserver/stdcgi | actual = .php</TT >, and use the Add button. </P ></LI ><LI ><P >
Click <TT CLASS="literal" >OK</TT > </P ></LI ></OL > </P ><P >
Repeat steps 2 - 6 for each extension you want to associate with PHP. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Some OmniHTTPd packages come with built in PHP support. You can choose at setup time to do a custom setup, and uncheck the PHP component. We recommend you to use the latest PHP binaries. Some OmniHTTPd servers come with PHP 4 beta distributions, so you should choose not to set up the built in support, but install your own. If the server is already on your machine, use the Replace button in Step 4 and 5 to set the new, correct information. </P ></BLOCKQUOTE ></DIV ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.oreilly" ></A >Servers-Oreilly Website Pro</H2 ><P >
This section contains notes and hints specific to Oreilly Website Pro. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.oreilly.windows" ></A >Oreilly Website Pro 2.5 and up for Windows</H3 ><P >
This list describes how to set up the PHP CGI binary or the ISAPI module to work with Oreilly Website Pro on Windows. </P ><P >
<P ></P ><UL ><LI ><P >
Edit the Server Properties and select the tab "Mapping". </P ></LI ><LI ><P >
From the List select "Associations" and enter the desired extension (<TT CLASS="literal" >.php</TT >) and the path to the CGI exe (ex. <TT CLASS="filename" >c:\php\php.exe</TT >) or the ISAPI DLL file (ex. <TT CLASS="filename" >c:\php\sapi\php4isapi.dll</TT >). </P ></LI ><LI ><P >
Select "Content Types" add the same extension (<TT CLASS="literal" >.php</TT >) and enter the content type. If you choose the CGI executable file, enter 'wwwserver/shellcgi', if you choose the ISAPI module, enter 'wwwserver/isapi' (both without quotes). </P ></LI ></UL > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.sambar" ></A >Servers-Sambar</H2 ><P >
This section contains notes and hints specific to the <A HREF="http://www.sambar.com/" TARGET="_top" >Sambar server</A > for Windows. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.sambar.windows" ></A >Sambar Windows</H3 ><P >
This list describes how to set up the ISAPI module to work with the Sambar server on Windows. </P ><P >
<P ></P ><UL ><LI ><P >
Find the file called <TT CLASS="filename" >mappings.ini</TT > (in the config directory) in the Sambar install directory. </P ></LI ><LI ><P >
Open <TT CLASS="filename" >mappings.ini</TT > and add the following line under <TT CLASS="literal" >[ISAPI]</TT >: <DIV CLASS="informalexample" ><A NAME="AEN2009" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >*.php = c:\php\php4isapi.dll</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > (This line assumes that PHP was installed in <TT CLASS="literal" >c:\php</TT >.) </P ></LI ><LI ><P >
Now restart the Sambar server for the changes to take effect. </P ></LI ></UL > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.xitami" ></A >Servers-Xitami</H2 ><P >
This section contains notes and hints specific to <A HREF="http://www.xitami.com/" TARGET="_top" >Xitami</A >. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.xitami.windows" ></A >Xitami for Windows</H3 ><P >
This list describes how to set up the PHP CGI binary to work with Xitami on Windows. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Important for CGI users: </B > Read the <A HREF="#faq.installation.forceredirect" >faq on cgi.force_redirect</A > for important details. This directive needs to be set to <TT CLASS="literal" >0</TT >. </P ></BLOCKQUOTE ></DIV ><P >
<P ></P ><UL ><LI ><P >
Make sure the webserver is running, and point your browser to xitamis admin console (usually <TT CLASS="literal" >http://127.0.0.1/admin</TT >), and click on Configuration. </P ></LI ><LI ><P >
Navigate to the Filters, and put the extension which PHP should parse (i.e. .php) into the field File extensions (.xxx). </P ></LI ><LI ><P >
In Filter command or script put the path and name of your PHP executable i.e. <TT CLASS="literal" >c:\php\php.exe</TT >. </P ></LI ><LI ><P >
Press the 'Save' icon. </P ></LI ><LI ><P >
Restart the server to reflect changes. </P ></LI ></UL > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.otherhttpd" ></A >Servers-Other web servers</H2 ><P >
PHP can be built to support a large number of web servers. Please see Server-related options for a full list of server-related configure options. The PHP CGI binaries are compatible with almost all webservers supporting the CGI standard. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.problems" ></A >Problems?</H2 ><DIV CLASS="sect2" ><H3 CLASS="sect2" ><A NAME="AEN2045" ></A >Read the FAQ</H3 ><P >
Some problems are more common than others. The most common ones are listed in the <A HREF="#faq" >PHP FAQ</A >, part of this manual. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.otherproblems" ></A >Other problems</H3 ><P >
If you are still stuck, someone on the PHP installation mailing list may be able to help you. You should check out the archive first, in case someone already answered someone else who had the same problem as you. The archives are available from the support page on <A HREF="http://www.php.net/support.php" TARGET="_top" >http://www.php.net/support.php</A >. To subscribe to the PHP installation mailing list, send an empty mail to <A HREF="mailto:php-install-subscribe@lists.php.net" TARGET="_top" >php-install-subscribe@lists.php.net</A >. The mailing list address is <A HREF="mailto:php-install@lists.php.net" TARGET="_top" >php-install@lists.php.net</A >. </P ><P >
If you want to get help on the mailing list, please try to be precise and give the necessary details about your environment (which operating system, what PHP version, what web server, if you are running PHP as CGI or a server module, <A HREF="#ini.safe-mode" >bezpeΦn² re╛im</A >, etc...), and preferably enough code to make others able to reproduce and test your problem. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.bugreports" ></A >Bug reports</H3 ><P >
If you think you have found a bug in PHP, please report it. The PHP developers probably don't know about it, and unless you report it, chances are it won't be fixed. You can report bugs using the bug-tracking system at <A HREF="http://bugs.php.net/" TARGET="_top" >http://bugs.php.net/</A >. Please do not send bug reports in mailing list or personal letters. The bug system is also suitable to submit feature requests. </P ><P >
Read the <A HREF="http://bugs.php.net/how-to-report.php" TARGET="_top" >How to report a bug</A > document before submitting any bug reports! </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="install.configure" ></A >Miscellaneous configure options</H2 ><P >
Below is a partial list of configure options used by the PHP <TT CLASS="filename" >configure</TT > scripts when compiling in Unix-like environments. Most configure options are listed in their appropriate locations and not here. For a complete up-to-date list of configure options, run <B CLASS="command" >./configure --help</B > in your PHP source directory after running <B CLASS="command" >autoconf</B > (see also the <A HREF="#installation" >Installation chapter</A >). You may also be interested in reading the <A HREF="http://www.airs.com/ian/configure/" TARGET="_top" >GNU configure</A > documentation for information on additional <B CLASS="command" >configure</B > options such as <TT CLASS="literal" >--prefix=PREFIX</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > These are only used at compile time. If you want to alter PHP's runtime configuration, please see the chapter on <A HREF="#configuration" >Runtime Configuration</A >. </P ></BLOCKQUOTE ></DIV ><P ></P ><UL ><LI ><P >
<A HREF="#install.configure.options.graphics" >Graphics</A > </P ></LI ><LI ><P >
<A HREF="#install.configure.options.misc" >Miscellaneous</A > </P ></LI ><LI ><P >
<A HREF="#install.configure.options.php" >PHP Behaviour</A > </P ></LI ><LI ><P >
<A HREF="#install.configure.options.servers" >Server</A > </P ></LI ></UL ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="install.configure.options" ></A >Configure Options in PHP 4</H3 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > These options are only used in PHP 4 as of PHP 4.1.0. Some are available in older versions of PHP 4, some even in PHP 3, some only in PHP 4.1.0. If you want to compile an older version, some options will probably not be available. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.configure.options.graphics" ></A >Graphics options</H4 ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="install.configure.with-imagick" ></A ><TT CLASS="parameter" ><I >--with-imagick</I ></TT ></DT ><DD ><P >
The imagick extension has been moved to PECL in PEAR and can be found at <A HREF="http://pear.php.net/imagick" TARGET="_top" >http://pear.php.net/imagick</A >. Install instructions for PHP 4 can be found on the PEAR site. </P ><P >
Simply doing <TT CLASS="literal" >--with-imagick</TT > is only supported in PHP 3 unless you follow the instructions found on the PEAR site. </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.configure.options.misc" ></A >Misc options</H4 ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="install.configure.enable-debug" ></A ><TT CLASS="parameter" ><I >--enable-debug</I ></TT ></DT ><DD ><P >
Compile with debugging symbols. </P ></DD ><DT ><A NAME="install.configure.with-layout" ></A ><TT CLASS="parameter" ><I >--with-layout=TYPE</I ></TT ></DT ><DD ><P >
Sets how installed files will be laid out. Type is one of PHP (default) or GNU. </P ></DD ><DT ><A NAME="install.configure.with-pear" ></A ><TT CLASS="parameter" ><I >--with-pear=DIR</I ></TT ></DT ><DD ><P >
Install PEAR in DIR (default PREFIX/lib/php). </P ></DD ><DT ><A NAME="install.configure.without-pear" ></A ><TT CLASS="parameter" ><I >--without-pear</I ></TT ></DT ><DD ><P >
Do not install PEAR. </P ></DD ><DT ><A NAME="install.configure.enable-sigchild" ></A ><TT CLASS="parameter" ><I >--enable-sigchild</I ></TT ></DT ><DD ><P >
Enable PHP's own SIGCHLD handler. </P ></DD ><DT ><A NAME="install.configure.disable-rpath" ></A ><TT CLASS="parameter" ><I >--disable-rpath</I ></TT ></DT ><DD ><P >
Disable passing additional runtime library search paths. </P ></DD ><DT ><A NAME="install.configure.enable-libgcc" ></A ><TT CLASS="parameter" ><I >--enable-libgcc</I ></TT ></DT ><DD ><P >
Enable explicitly linking against libgcc. </P ></DD ><DT ><A NAME="install.configure.enable-php-streams" ></A ><TT CLASS="parameter" ><I >--enable-php-streams</I ></TT ></DT ><DD ><P >
Include experimental PHP streams. Do not use unless you are testing the code! </P ></DD ><DT ><A NAME="install.configure.with-zlib-dir" ></A ><TT CLASS="parameter" ><I >--with-zlib-dir=<DIR></I ></TT ></DT ><DD ><P >
Define the location of zlib install directory. </P ></DD ><DT ><A NAME="install.configure.enable-trans-sid" ></A ><TT CLASS="parameter" ><I >--enable-trans-sid</I ></TT ></DT ><DD ><P >
Enable transparent session id propagation. Only valid for PHP 4.1.2 or less. From PHP 4.2.0, trans-sid feature is always compiled. </P ></DD ><DT ><A NAME="install.configure.with-tsrm-pthreads" ></A ><TT CLASS="parameter" ><I >--with-tsrm-pthreads</I ></TT ></DT ><DD ><P >
Use POSIX threads (default). </P ></DD ><DT ><A NAME="install.configure.enable-shared" ></A ><TT CLASS="parameter" ><I >--enable-shared[=PKGS]</I ></TT ></DT ><DD ><P >
Build shared libraries [default=yes]. </P ></DD ><DT ><A NAME="install.configure.enable-static" ></A ><TT CLASS="parameter" ><I >--enable-static[=PKGS]</I ></TT ></DT ><DD ><P >
Build static libraries [default=yes]. </P ></DD ><DT ><A NAME="install.configure.enable-fast-install" ></A ><TT CLASS="parameter" ><I >--enable-fast-install[=PKGS]</I ></TT ></DT ><DD ><P >
Optimize for fast installation [default=yes]. </P ></DD ><DT ><A NAME="install.configure.with-gnu-ld" ></A ><TT CLASS="parameter" ><I >--with-gnu-ld</I ></TT ></DT ><DD ><P >
Assume the C compiler uses GNU ld [default=no]. </P ></DD ><DT ><A NAME="install.configure.disable-libtool-lock" ></A ><TT CLASS="parameter" ><I >--disable-libtool-lock</I ></TT ></DT ><DD ><P >
Avoid locking (might break parallel builds). </P ></DD ><DT ><A NAME="install.configure.with-pic" ></A ><TT CLASS="parameter" ><I >--with-pic</I ></TT ></DT ><DD ><P >
Try to use only PIC/non-PIC objects [default=use both]. </P ></DD ><DT ><A NAME="install.configure.enable-memory-limit" ></A ><TT CLASS="parameter" ><I >--enable-memory-limit</I ></TT ></DT ><DD ><P >
Compile with memory limit support. </P ></DD ><DT ><A NAME="install.configure.disable-url-fopen-wrapper" ></A ><TT CLASS="parameter" ><I >--disable-url-fopen-wrapper</I ></TT ></DT ><DD ><P >
Disable the URL-aware fopen wrapper that allows accessing files via HTTP or FTP. </P ></DD ><DT ><A NAME="install.configure.enable-versioning.php4" ></A ><TT CLASS="parameter" ><I >--enable-versioning</I ></TT ></DT ><DD ><P >
Export only required symbols. See INSTALL for more information. </P ></DD ><DT ><A NAME="install.configure.with-ismp" ></A ><TT CLASS="parameter" ><I >--with-imsp[=DIR]</I ></TT ></DT ><DD ><P >
Include IMSp support (DIR is IMSP's include dir and libimsp.a dir). PHP 3 only! </P ></DD ><DT ><A NAME="install.configure.with-mck" ></A ><TT CLASS="parameter" ><I >--with-mck[=DIR]</I ></TT ></DT ><DD ><P >
Include Cybercash MCK support. DIR is the cybercash mck build directory, defaults to /usr/src/mck-3.2.0.3-linux for help look in extra/cyberlib. PHP 3 only! </P ></DD ><DT ><A NAME="install.configure.with-mod-dav" ></A ><TT CLASS="parameter" ><I >--with-mod-dav=DIR</I ></TT ></DT ><DD ><P >
Include DAV support through Apache's mod_dav, DIR is mod_dav's installation directory (Apache module version only!) PHP 3 only! </P ></DD ><DT ><A NAME="install.configure.enable-debugger" ></A ><TT CLASS="parameter" ><I >--enable-debugger</I ></TT ></DT ><DD ><P >
Compile with remote debugging functions. PHP 3 only! </P ></DD ><DT ><A NAME="install.configure.enable-versioning.php3" ></A ><TT CLASS="parameter" ><I >--enable-versioning</I ></TT ></DT ><DD ><P >
Take advantage of versioning and scoping provided by Solaris 2.x and Linux. PHP 3 only! </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.configure.options.php" ></A >PHP options</H4 ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="install.configure.enable-maintainer-mode" ></A ><TT CLASS="parameter" ><I >--enable-maintainer-mode</I ></TT ></DT ><DD ><P >
Enable make rules and dependencies not useful (and sometimes confusing) to the casual installer. </P ></DD ><DT ><A NAME="install.configure.with-config-file-path" ></A ><TT CLASS="parameter" ><I >--with-config-file-path=PATH</I ></TT ></DT ><DD ><P >
Sets the path in which to look for <TT CLASS="filename" >php.ini</TT >, defaults to PREFIX/lib. </P ></DD ><DT ><A NAME="install.configure.enable-safe-mode" ></A ><TT CLASS="parameter" ><I >--enable-safe-mode</I ></TT ></DT ><DD ><P >
Enable safe mode by default. </P ></DD ><DT ><A NAME="install.configure.with-exec-dir" ></A ><TT CLASS="parameter" ><I >--with-exec-dir[=DIR]</I ></TT ></DT ><DD ><P >
Only allow executables in DIR when in safe mode defaults to /usr/local/php/bin. </P ></DD ><DT ><A NAME="install.configure.enable-magic-quotes" ></A ><TT CLASS="parameter" ><I >--enable-magic-quotes</I ></TT ></DT ><DD ><P >
Enable magic quotes by default. </P ></DD ><DT ><A NAME="install.configure.disable-short-tags" ></A ><TT CLASS="parameter" ><I >--disable-short-tags</I ></TT ></DT ><DD ><P >
Disable the short-form <? start tag by default. </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="install.configure.options.servers" ></A >SAPI options</H4 ><P >
The following list contains the available SAPI&s (<TT CLASS="literal" >Server Application Programming Interface)</TT > for PHP. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="install.configure.with-aolserver" ></A ><TT CLASS="parameter" ><I >--with-aolserver=DIR</I ></TT ></DT ><DD ><P >
Specify path to the installed AOLserver. </P ></DD ><DT ><A NAME="install.configure.with-apxs" ></A ><TT CLASS="parameter" ><I >--with-apxs[=FILE]</I ></TT ></DT ><DD ><P >
Build shared Apache module. FILE is the optional pathname to the Apache apxs tool; defaults to apxs. Make sure you specify the version of apxs that is actually installed on your system and NOT the one that is in the apache source tarball. </P ></DD ><DT ><A NAME="install.configure.with-apache" ></A ><TT CLASS="parameter" ><I >--with-apache[=DIR]</I ></TT ></DT ><DD ><P >
Build a static Apache module. DIR is the top-level Apache build directory, defaults to <TT CLASS="filename" >/usr/local/apache</TT >. </P ></DD ><DT ><A NAME="install.configure.with-mod_charset" ></A ><TT CLASS="parameter" ><I >--with-mod_charset</I ></TT ></DT ><DD ><P >
Enable transfer tables for mod_charset (Russian Apache). </P ></DD ><DT ><A NAME="install.configure.with-apxs2" ></A ><TT CLASS="parameter" ><I >--with-apxs2[=FILE]</I ></TT ></DT ><DD ><P >
Build shared Apache 2.0 module. FILE is the optional pathname to the Apache apxs tool; defaults to apxs. </P ></DD ><DT ><A NAME="install.configure.with-caudium" ></A ><TT CLASS="parameter" ><I >--with-caudium=DIR</I ></TT ></DT ><DD ><P >
Build PHP as a Pike module for use with Caudium. DIR is the Caudium server dir, with the default value <TT CLASS="filename" >/usr/local/caudium/server</TT >. </P ></DD ><DT ><A NAME="install.configure.disable-cli" ></A ><TT CLASS="parameter" ><I >--disable-cli</I ></TT ></DT ><DD ><P >
Available with PHP 4.3.0. Disable building the CLI version of PHP (this forces <A HREF="#install.configure.without-pear" >--without-pear</A >). More information is available in the section about <A HREF="#features.commandline" >Using PHP from the command line</A >. </P ></DD ><DT ><A NAME="install.configure.enable-embed" ></A ><TT CLASS="parameter" ><I > --enable-embed[=TYPE]</I ></TT ></DT ><DD ><P >
Enable building of the embedded SAPI library. TYPE is either <TT CLASS="literal" >shared</TT > or <TT CLASS="literal" >static</TT >, which defaults to <TT CLASS="literal" >shared</TT >. Available with PHP 4.3.0. </P ></DD ><DT ><A NAME="install.configure.with-fhttpd" ></A ><TT CLASS="parameter" ><I >--with-fhttpd[=DIR]</I ></TT ></DT ><DD ><P >
Build fhttpd module. DIR is the fhttpd sources directory, defaults to <TT CLASS="filename" >/usr/local/src/fhttpd</TT >. No longer available as of PHP 4.3.0. </P ></DD ><DT ><A NAME="install.configure.with-isapi" ></A ><TT CLASS="parameter" ><I >--with-isapi=DIR</I ></TT ></DT ><DD ><P >
Build PHP as an ISAPI module for use with Zeus. </P ></DD ><DT ><A NAME="install.configure.with-nsapi" ></A ><TT CLASS="parameter" ><I >--with-nsapi=DIR</I ></TT ></DT ><DD ><P >
Specify path to the installed Netscape/iPlanet/SunONE Webserver. </P ></DD ><DT ><A NAME="install.configure.with-phttpd" ></A ><TT CLASS="parameter" ><I >--with-phttpd=DIR</I ></TT ></DT ><DD ><P >
No information yet. </P ></DD ><DT ><A NAME="install.configure.with-pi3web" ></A ><TT CLASS="parameter" ><I >--with-pi3web=DIR</I ></TT ></DT ><DD ><P >
Build PHP as a module for use with Pi3Web. </P ></DD ><DT ><A NAME="install.configure.with-roxen" ></A ><TT CLASS="parameter" ><I >--with-roxen=DIR</I ></TT ></DT ><DD ><P >
Build PHP as a Pike module. DIR is the base Roxen directory, normally <TT CLASS="filename" >/usr/local/roxen/server</TT >. </P ></DD ><DT ><A NAME="install.configure.enable-roxen-zts" ></A ><TT CLASS="parameter" ><I >--enable-roxen-zts</I ></TT ></DT ><DD ><P >
Build the Roxen module using Zend Thread Safety. </P ></DD ><DT ><A NAME="install.configure.with-servlet" ></A ><TT CLASS="parameter" ><I >--with-servlet[=DIR]</I ></TT ></DT ><DD ><P >
Include servlet support. DIR is the base install directory for the JSDK. This SAPI requires the java extension must be built as a shared dl. </P ></DD ><DT ><A NAME="install.configure.with-thttpd" ></A ><TT CLASS="parameter" ><I >--with-thttpd=SRCDIR</I ></TT ></DT ><DD ><P >
Build PHP as thttpd module. </P ></DD ><DT ><A NAME="install.configure.with-tux" ></A ><TT CLASS="parameter" ><I >--with-tux=MODULEDIR</I ></TT ></DT ><DD ><P >
Build PHP as a TUX module (Linux only). </P ></DD ><DT ><A NAME="install.configure.with-webjames" ></A ><TT CLASS="parameter" ><I >--with-webjames=SRCDIR</I ></TT ></DT ><DD ><P >
Build PHP as a WebJames module (RISC OS only) </P ></DD ><DT ><A NAME="install.configure.disable-cgi" ></A ><TT CLASS="parameter" ><I > --disable-cgi</I ></TT ></DT ><DD ><P >
Disable building CGI version of PHP. Available with PHP 4.3.0. </P ></DD ><DT ><A NAME="install.configure.enable-force-cgi-redirect" ></A ><TT CLASS="parameter" ><I >--enable-force-cgi-redirect</I ></TT ></DT ><DD ><P >
Enable the security check for internal server redirects. You should use this if you are running the CGI version with Apache. </P ></DD ><DT ><A NAME="install.configure.enable-discard-path" ></A ><TT CLASS="parameter" ><I >--enable-discard-path</I ></TT ></DT ><DD ><P >
If this is enabled, the PHP CGI binary can safely be placed outside of the web tree and people will not be able to circumvent <TT CLASS="filename" >.htaccess</TT > security. </P ></DD ><DT ><A NAME="install.configure.with-fastcgi" ></A ><TT CLASS="parameter" ><I >--with-fastcgi</I ></TT ></DT ><DD ><P >
Build PHP as FastCGI application. No longer available as of PHP 4.3.0, instead you should use <TT CLASS="parameter" ><I >--enable-fastcgi</I ></TT >. </P ></DD ><DT ><A NAME="install.configure.enable-fastcgi" ></A ><TT CLASS="parameter" ><I >--enable-fastcgi</I ></TT ></DT ><DD ><P >
If this is enabled, the CGI module will be built with support for FastCGI also. Available since PHP 4.3.0 </P ></DD ><DT ><A NAME="install.configure.disable-path-info-check" ></A ><TT CLASS="parameter" ><I >--disable-path-info-check</I ></TT ></DT ><DD ><P >
If this is disabled, paths such as <TT CLASS="filename" >/info.php/test?a=b</TT > will fail to work. Available since <TT CLASS="literal" >PHP 4.3.0</TT >. For more information see the <A HREF="http://httpd.apache.org/docs-2.0/en/mod/core.html#acceptpathinfo" TARGET="_top" >Apache Manual</A >. </P ></DD ></DL ></DIV ></DIV ></DIV ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="configuration" >Kapitola 4. Runtime Configuration</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="configuration.file" ></A >The configuration file</H2 ><P >
The configuration file (called <TT CLASS="filename" >php3.ini</TT > in PHP 3.0, and simply <TT CLASS="filename" >php.ini</TT > as of PHP 4.0) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the <SPAN CLASS="acronym" >CGI</SPAN > and <SPAN CLASS="acronym" >CLI</SPAN > version, it happens on every invocation. </P ><P >
The default location of <TT CLASS="filename" >php.ini</TT > is a compile time option (see the <A HREF="#faq.installation.phpini" >FAQ</A > entry), but can be changed for the <SPAN CLASS="acronym" >CGI</SPAN > and <SPAN CLASS="acronym" >CLI</SPAN > version with the <TT CLASS="literal" >-c</TT > command line switch, see the chapter about using <TT CLASS="literal" >PHP</TT > from the <A HREF="#features.commandline" >command line</A >. You can also use the environment variable <TT CLASS="literal" >PHPRC</TT > for an additional path to search for a <TT CLASS="filename" >php.ini</TT > file. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The Apache web server changes the directory to root at startup causing PHP to attempt to read <TT CLASS="filename" >php.ini</TT > from the root filesystem if it exists. </P ></BLOCKQUOTE ></DIV ><P >
Not every PHP directive is documented below. For a list of all directives, please read your well commented <TT CLASS="filename" >php.ini</TT > file. You may want to view the latest <A HREF="http://cvs.php.net/co.php/php-src/php.ini-dist" TARGET="_top" >php.ini here</A > from CVS. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The default value for the PHP directive <A HREF="#ini.register-globals" >register_globals</A > changed from <SPAN CLASS="emphasis" ><I CLASS="emphasis" >on</I ></SPAN > to <SPAN CLASS="emphasis" ><I CLASS="emphasis" >off</I ></SPAN > in PHP <A HREF="http://www.php.net/release_4_2_0.php" TARGET="_top" >4.2.0</A >. </P ></BLOCKQUOTE ></DIV ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN2442" ></A ><P ><B >P°φklad 4-1. <TT CLASS="filename" >php.ini</TT > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" >; any text on a line after an unquoted semicolon (;) is ignored [php] ; section markers (text within square brackets) are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off magic_quotes_gpc = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="configuration.changes" ></A >How to change configuration settings</H2 ><DIV CLASS="sect2" ><H3 CLASS="sect2" ><A NAME="configuration.changes.apache" ></A >Running <TT CLASS="literal" >PHP</TT > as Apache module</H3 ><P >
When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files (e.g. <TT CLASS="filename" >httpd.conf</TT >) and <TT CLASS="filename" >.htaccess</TT > files (You will need "AllowOverride Options" or "AllowOverride All" privileges) </P ><P >
With PHP 4.0, there are several Apache directives that allow you to change the PHP configuration from within the Apache configuration files. For a listing of which directives are <TT CLASS="constant" ><B >PHP_INI_ALL</B ></TT >, <TT CLASS="constant" ><B >PHP_INI_PERDIR</B ></TT >, or <TT CLASS="constant" ><B >PHP_INI_SYSTEM</B ></TT >, have a look at the table found within the <A HREF="#function.ini-set" ><B CLASS="function" >ini_set()</B ></A > documentation. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > With PHP 3.0, there are Apache directives that correspond to each configuration setting in the <TT CLASS="filename" >php3.ini</TT > name, except the name is prefixed by "php3_". </P ></BLOCKQUOTE ></DIV ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><SPAN CLASS="systemitem" >php_value</SPAN > <TT CLASS="parameter" ><I >name</I ></TT > <TT CLASS="parameter" ><I >value</I ></TT ></DT ><DD ><P >
Sets the value of the specified directive. Can be used only with <TT CLASS="constant" ><B >PHP_INI_ALL</B ></TT > and <TT CLASS="constant" ><B >PHP_INI_PERDIR</B ></TT > type directives. To clear a previously set value use <TT CLASS="literal" >none</TT > as the value. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Don't use <TT CLASS="literal" >php_value</TT > to set boolean values. <TT CLASS="literal" >php_flag</TT > (see below) should be used instead. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><SPAN CLASS="systemitem" >php_flag</SPAN > <TT CLASS="parameter" ><I >name</I ></TT > <TT CLASS="parameter" ><I >on|off</I ></TT ></DT ><DD ><P >
Used to set a Boolean configuration directive. Can be used only with <TT CLASS="constant" ><B >PHP_INI_ALL</B ></TT > and <TT CLASS="constant" ><B >PHP_INI_PERDIR</B ></TT > type directives. </P ></DD ><DT ><SPAN CLASS="systemitem" >php_admin_value</SPAN > <TT CLASS="parameter" ><I >name</I ></TT > <TT CLASS="parameter" ><I >value</I ></TT ></DT ><DD ><P >
Sets the value of the specified directive. This can NOT be used in <TT CLASS="filename" >.htaccess</TT > files. Any directive type set with <SPAN CLASS="systemitem" >php_admin_value</SPAN > can not be overridden by <TT CLASS="filename" >.htaccess</TT > or virtualhost directives. To clear a previously set value use <TT CLASS="literal" >none</TT > as the value. </P ></DD ><DT ><SPAN CLASS="systemitem" >php_admin_flag</SPAN > <TT CLASS="parameter" ><I >name</I ></TT > <TT CLASS="parameter" ><I >on|off</I ></TT ></DT ><DD ><P >
Used to set a Boolean configuration directive. This can NOT be used in <TT CLASS="filename" >.htaccess</TT > files. Any directive type set with <SPAN CLASS="systemitem" >php_admin_flag</SPAN > can not be overridden by <TT CLASS="filename" >.htaccess</TT > or virtualhost directives. </P ></DD ></DL ></DIV > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN2509" ></A ><P ><B >P°φklad 4-2. Apache configuration example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" ><IfModule mod_php4.c> php_value include_path ".:/usr/local/lib/php" php_admin_flag safe_mode on </IfModule> <IfModule mod_php3.c> php3_include_path ".:/usr/local/lib/php" php3_safe_mode on </IfModule></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
PHP constants do not exist outside of PHP. For example, in <TT CLASS="filename" >httpd.conf</TT > you can not use PHP constants such as <TT CLASS="constant" ><B >E_ALL</B ></TT > or <TT CLASS="constant" ><B >E_NOTICE</B ></TT > to set the <A HREF="#ini.error-reporting" >error_reporting</A > directive as they will have no meaning and will evaluate to <SPAN CLASS="emphasis" ><I CLASS="emphasis" >0</I ></SPAN >. Use the associated bitmask values instead. These constants can be used in <TT CLASS="filename" >php.ini</TT > </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="configuration.changes.windows" ></A >Changing <TT CLASS="literal" >PHP</TT > configuration via the Windows registry</H3 ><P >
When running PHP on Windows, the configuration values can be modified on per-directory basis using the Windows registry. The configuration values are stored in the registry key <TT CLASS="literal" >HKLM\SOFTWARE\PHP\Per Directory Values</TT >, in the sub-keys corresponding to the path names. For example, configuration values for the directory <TT CLASS="literal" >c:\inetpub\wwwroot</TT > would be stored in the key <TT CLASS="literal" >HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot</TT >. The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values under the key should have the name of <A HREF="#configuration" >PHP configuration directive</A > and the string value. PHP constants in the values would not be parsed. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="configuration.changes.other" ></A >Other interfaces to <TT CLASS="literal" >PHP</TT ></H3 ><P >
Regardless of the interface to <TT CLASS="literal" >PHP</TT > you can change certain values at runtime of your scripts through <A HREF="#function.ini-set" ><B CLASS="function" >ini_set()</B ></A >. The following table provides an overview at which level a directive can be set/changed. </P ><P >
<DIV CLASS="table" ><A NAME="AEN2535" ></A ><P ><B >Tabulka 4-1. Definition of PHP_INI_* constants</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Constant</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Value</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Meaning</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_USER</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >1</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Entry can be set in user scripts</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_PERDIR</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >2</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Entry can be set in <TT CLASS="filename" >php.ini</TT >, <TT CLASS="filename" >.htaccess</TT > or <TT CLASS="filename" >httpd.conf</TT > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >4</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Entry can be set in <TT CLASS="filename" >php.ini</TT > or <TT CLASS="filename" >httpd.conf</TT > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >7</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Entry can be set anywhere</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >
You can view the settings of the configuration values in the output of <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A >. You can also access the values of individual configuration directives using <A HREF="#function.ini-get" ><B CLASS="function" >ini_get()</B ></A > or <A HREF="#function.get-cfg-var" ><B CLASS="function" >get_cfg_var()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="configuration.directives" ></A >Miscellaneous configuration directives</H2 ><P >
This is not a complete list of PHP directives. Directives are listed in their appropriate locations so for example information on session directives is located in the <A HREF="#ref.session" >sessions chapter</A >. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sect.httpd-options" ></A >Httpd Options</H3 ><P >
<DIV CLASS="table" ><A NAME="AEN2576" ></A ><P ><B >Tabulka 4-2. Httpd Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >async_send</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >
</P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sect.language-options" ></A >Language Options</H3 ><P >
<DIV CLASS="table" ><A NAME="AEN2593" ></A ><P ><B >Tabulka 4-3. Language and Misc Configuration Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >short_open_tag</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >On</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >asp_tags</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Off</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >precision</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"14"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >y2k_compliance</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Off</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >allow_call_time_pass_reference</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >On</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >expose_php</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >On</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.short-open-tag" ></A ><TT CLASS="parameter" ><I >short_open_tag</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Tells whether the short form (<TT CLASS="userinput" ><B ><? ?></B ></TT >) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <TT CLASS="userinput" ><B ><?xml ?></B ></TT > inline. Otherwise, you can print it with PHP, for example: <TT CLASS="userinput" ><B ><?php echo '<?xml version="1.0"'; ?></B ></TT >. Also if disabled, you must use the long form of the PHP open tag (<TT CLASS="userinput" ><B ><?php ?></B ></TT >). </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > This directive also affects the shorthand <TT CLASS="userinput" ><B ><?=</B ></TT >, which is identical to <TT CLASS="userinput" ><B ><? echo</B ></TT >. Use of this shortcut requires <SPAN CLASS="systemitem" >short_open_tag</SPAN > to be on. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.asp-tags" ></A ><TT CLASS="parameter" ><I >asp_tags</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Enables the use of ASP-like <% %> tags in addition to the usual <?php ?> tags. This includes the variable-value printing shorthand of <%= $value %>. For more information, see <A HREF="#language.basic-syntax.phpmode" >Escaping from HTML</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Support for ASP-style tags was added in 3.0.4. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.precision" ></A ><TT CLASS="parameter" ><I >precision</I ></TT > <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P >
The number of significant digits displayed in floating point numbers. </P ></DD ><DT ><A NAME="ini.y2k-compliance" ></A ><TT CLASS="parameter" ><I >y2k_compliance</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Enforce year 2000 compliance (will cause problems with non-compliant browsers) </P ></DD ><DT ><A NAME="ini.allow-call-time-pass-reference" ></A ><TT CLASS="parameter" ><I >allow_call_time_pass_reference</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Whether to enable the ability to force arguments to be passed by reference at function call time. This method is deprecated and is likely to be unsupported in future versions of PHP/Zend. The encouraged method of specifying which arguments should be passed by reference is in the function declaration. You're encouraged to try and turn this option Off and make sure your scripts work properly with it in order to ensure they will work with future versions of the language (you will receive a warning each time you use this feature, and the argument will be passed by value instead of by reference). </P ><P >
See also <A HREF="#language.references" >References Explained</A >. </P ></DD ><DT ><A NAME="ini.expose-php" ></A ><TT CLASS="parameter" ><I >expose_php</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Decides whether PHP may expose the fact that it is installed on the server (e.g. by adding its signature to the Web server header). It is no security threat in any way, but it makes it possible to determine whether you use PHP on your server or not. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sect.resource-limits" ></A >Resource Limits</H3 ><P >
<DIV CLASS="table" ><A NAME="AEN2682" ></A ><P ><B >Tabulka 4-4. Resource Limits</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >memory_limit</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"8M"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.memory-limit" ></A ><TT CLASS="parameter" ><I >memory_limit</I ></TT > <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P >
This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. In order to use this directive you must have enabled it at compile time. So, your configure line would have included: <TT CLASS="literal" >--enable-memory-limit</TT >. Note that you have to set it to -1 if you don't want any limit for your memory. </P ><P >
As of PHP 4.3.2, and when memory_limit is enabled, the PHP function <A HREF="#function.memory-get-usage" ><B CLASS="function" >memory_get_usage()</B ></A > is made available. </P ></DD ></DL ></DIV > </P ><P >
See also: <A HREF="#ini.max-execution-time" >max_execution_time</A >. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sect.data-handling" ></A >Data Handling</H3 ><P >
<DIV CLASS="table" ><A NAME="AEN2712" ></A ><P ><B >Tabulka 4-5. Data Handling Configuration Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >track-vars</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"On"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_??</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >arg_separator.output</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"&"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >arg_separator.input</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"&"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >variables_order</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"EGPCS"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >register_globals</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"Off"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_PERDIR|PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >register_argc_argv</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"On"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_PERDIR|PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >register_long_arrays</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"On"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_PERDIR|PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >post_max_size</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"8M"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >gpc_order</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"GPC"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >auto_prepend_file</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >""</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >auto_append_file</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >""</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >default_mimetype</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"text/html"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >default_charset</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"iso-8859-1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >always_populate_raw_post_data</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >allow_webdav_methods</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.track-vars" ></A ><TT CLASS="parameter" ><I >track_vars</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
If enabled, then Environment, GET, POST, Cookie, and Server variables can be found in the global associative arrays <TT CLASS="varname" >$_ENV</TT >, <TT CLASS="varname" >$_GET</TT >, <TT CLASS="varname" >$_POST</TT >, <TT CLASS="varname" >$_COOKIE</TT >, and <TT CLASS="varname" >$_SERVER</TT >. </P ><P >
Note that as of PHP 4.0.3, <SPAN CLASS="systemitem" >track_vars</SPAN > is always turned on. </P ></DD ><DT ><A NAME="ini.arg-separator.output" ></A ><TT CLASS="parameter" ><I >arg_separator.output</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
The separator used in PHP generated URLs to separate arguments. </P ></DD ><DT ><A NAME="ini.arg-separator.input" ></A ><TT CLASS="parameter" ><I >arg_separator.input</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
List of separator(s) used by PHP to parse input URLs into variables. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Every character in this directive is considered as separator! </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.variables-order" ></A ><TT CLASS="parameter" ><I >variables_order</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
Set the order of the EGPCS (Environment, GET, POST, Cookie, Server) variable parsing. The default setting of this directive is "EGPCS". Setting this to "GP", for example, will cause PHP to completely ignore environment variables, cookies and server variables, and to overwrite any GET method variables with POST-method variables of the same name. </P ><P >
See also <A HREF="#ini.register-globals" >register_globals</A >. </P ></DD ><DT ><A NAME="ini.register-globals" ></A ><TT CLASS="parameter" ><I >register_globals</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Tells whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables. For example; if register_globals = on, the url <TT CLASS="literal" >http://www.example.com/test.php?id=3</TT > will produce <TT CLASS="varname" >$id</TT >. Or, <TT CLASS="varname" >$DOCUMENT_ROOT</TT > from <TT CLASS="varname" >$_SERVER['DOCUMENT_ROOT']</TT >. You may want to turn this off if you don't want to clutter your scripts' global scope with user data. As of PHP <A HREF="http://www.php.net/release_4_2_0.php" TARGET="_top" >4.2.0</A >, this directive defaults to <SPAN CLASS="emphasis" ><I CLASS="emphasis" >off</I ></SPAN >. It's preferred to go through PHP <A HREF="#reserved.variables" >Predefined Variables </A > instead, such as the <A HREF="#language.variables.superglobals" >superglobals</A >: <TT CLASS="varname" >$_ENV</TT >, <TT CLASS="varname" >$_GET</TT >, <TT CLASS="varname" >$_POST</TT >, <TT CLASS="varname" >$_COOKIE</TT >, and <TT CLASS="varname" >$_SERVER</TT >. Please read the security chapter on <A HREF="#security.registerglobals" >Using register_globals</A > for related information. </P ><P >
Please note that <SPAN CLASS="systemitem" >register_globals</SPAN > cannot be set at runtime (<A HREF="#function.ini-set" ><B CLASS="function" >ini_set()</B ></A >). Although, you can use <TT CLASS="filename" >.htaccess</TT > if your host allows it as described above. An example <TT CLASS="filename" >.htaccess</TT > entry: <TT CLASS="userinput" ><B >php_flag register_globals on</B ></TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <SPAN CLASS="systemitem" >register_globals</SPAN > is affected by the <A HREF="#ini.variables-order" >variables_order</A > directive. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.register-argc-argv" ></A ><TT CLASS="parameter" ><I >register_argc_argv</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Tells PHP whether to declare the argv & argc variables (that would contain the GET information). </P ><P >
See also <A HREF="#features.commandline" >command line</A >. Also, this directive became available in PHP 4.0.0 and was always "on" before that. </P ></DD ><DT ><A NAME="ini.register-long-arrays" ></A ><TT CLASS="parameter" ><I >register_long_arrays</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Tells PHP whether or not to register the deprecated long <TT CLASS="varname" >$HTTP_*_VARS</TT > type <A HREF="#language.variables.predefined" >predefined variables</A >. When On (default), long predefined PHP variables like <TT CLASS="varname" >$HTTP_GET_VARS</TT > will be defined. If you're not using them, it's recommended to turn them off, for performance reasons. Instead, use the superglobal arrays, like <TT CLASS="varname" >$_GET</TT >. </P ><P >
This directive became available in PHP 5.0.0. </P ></DD ><DT ><A NAME="ini.post-max-size" ></A ><TT CLASS="parameter" ><I >post_max_size</I ></TT > <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P >
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than <A HREF="#ini.upload-max-filesize" >upload_max_filesize</A >. </P ><P >
If memory limit is enabled by your configure script, <A HREF="#ini.memory-limit" >memory_limit</A > also affects file uploading. Generally speaking, <A HREF="#ini.memory-limit" >memory_limit</A > should be larger than <TT CLASS="parameter" ><I >post_max_size</I ></TT >. </P ></DD ><DT ><A NAME="ini.gpc-order" ></A ><TT CLASS="parameter" ><I >gpc_order</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
Set the order of GET/POST/COOKIE variable parsing. The default setting of this directive is "GPC". Setting this to "GP", for example, will cause PHP to completely ignore cookies and to overwrite any GET method variables with POST-method variables of the same name. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > This option is not available in PHP 4. Use <A HREF="#ini.variables-order" >variables_order</A > instead. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.auto-prepend-file" ></A ><TT CLASS="parameter" ><I >auto_prepend_file</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > function, so <A HREF="#ini.include-path" >include_path</A > is used.</P ><P >
The special value <SPAN CLASS="systemitem" >none</SPAN > disables auto-prepending. </P ></DD ><DT ><A NAME="ini.auto-append-file" ></A ><TT CLASS="parameter" ><I >auto_append_file</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
Specifies the name of a file that is automatically parsed after the main file. The file is included as if it was called with the <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > function, so <A HREF="#ini.include-path" >include_path</A > is used.</P ><P >
The special value <SPAN CLASS="systemitem" >none</SPAN > disables auto-appending. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > If the script is terminated with <A HREF="#function.exit" ><B CLASS="function" >exit()</B ></A >, auto-append will <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > occur.</P ></BLOCKQUOTE ></DIV > </P ></DD ><DT ><A NAME="ini.default-mimetype" ></A ><TT CLASS="parameter" ><I >default_mimetype</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
</P ></DD ><DT ><A NAME="ini.default-charset" ></A ><TT CLASS="parameter" ><I >default_charset</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
As of 4.0b4, PHP always outputs a character encoding by default in the Content-type: header. To disable sending of the charset, simply set it to be empty. </P ></DD ><DT ><A NAME="ini.always-populate-raw-post-data" ></A ><TT CLASS="parameter" ><I >always_populate_raw_post_data</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Always populate the $HTTP_RAW_POST_DATA variable. </P ></DD ><DT ><A NAME="ini.allow-webdav-methods" ></A ><TT CLASS="parameter" ><I >allow_webdav_methods</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Allow handling of WebDAV http requests within PHP scripts (eg. PROPFIND, PROPPATCH, MOVE, COPY, etc..) If you want to get the post data of those requests, you have to set <A HREF="#ini.always-populate-raw-post-data" >
always_populate_raw_post_data</A > as well. </P ></DD ></DL ></DIV > </P ><P >
See also: <A HREF="#ini.magic-quotes-gpc" >magic_quotes_gpc</A >, <A HREF="#ini.magic-quotes-runtime" >magic-quotes-runtime</A >, and <A HREF="#ini.magic-quotes-sybase" >magic_quotes_sybase</A >. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sect.path-directory" ></A >Paths and Directories</H3 ><P >
<DIV CLASS="table" ><A NAME="AEN2944" ></A ><P ><B >Tabulka 4-6. Paths and Directories Configuration Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >include_path</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INCLUDE_PATH</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >doc_root</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INCLUDE_PATH</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >user_dir</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NULL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >extension_dir</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_EXTENSION_DIR</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >cgi.fix_pathinfo</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >cgi.force_redirect</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >cgi.redirect_status_env</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >""</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >fastcgi.impersonate</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >cgi.rfc2616_headers</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.include-path" ></A ><TT CLASS="parameter" ><I >include_path</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
Specifies a list of directories where the <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >, <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > and <B CLASS="function" >fopen_with_path()</B > functions look for files. The format is like the system's <TT CLASS="envar" >PATH</TT > environment variable: a list of directories separated with a colon in Unix or semicolon in Windows. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3003" ></A ><P ><B >P°φklad 4-3. Unix include_path</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php.ini" >include_path=".:/php/includes"</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3007" ></A ><P ><B >P°φklad 4-4. Windows include_path</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php.ini" >include_path=".;c:\php\includes"</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Using a <TT CLASS="literal" >.</TT > in the include path allows for relative includes as it means the current directory. </P ></DD ><DT ><A NAME="ini.doc-root" ></A ><TT CLASS="parameter" ><I >doc_root</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
PHP's "root directory" on the server. Only used if non-empty. If PHP is configured with <A HREF="#ini.safe-mode" >bezpeΦn² re╛im</A >, no files outside this directory are served. If PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root if you are running PHP as a CGI under any web server (other than IIS) The alternative is to use the <A HREF="#ini.cgi.force-redirect" >
cgi.force_redirect</A > configuration below. </P ></DD ><DT ><A NAME="ini.user-dir" ></A ><TT CLASS="parameter" ><I >user_dir</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
The base name of the directory used on a user's home directory for <TT CLASS="literal" >PHP</TT > files, for example <TT CLASS="literal" >public_html</TT >. </P ></DD ><DT ><A NAME="ini.extension-dir" ></A ><TT CLASS="parameter" ><I >extension_dir</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
In what directory PHP should look for dynamically loadable extensions. See also: <A HREF="#ini.enable-dl" >enable_dl</A >, and <A HREF="#function.dl" ><B CLASS="function" >dl()</B ></A >. </P ></DD ><DT ><A NAME="ini.extension" ></A ><TT CLASS="parameter" ><I >extension</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
Which dynamically loadable extensions to load when PHP starts up. </P ></DD ><DT ><A NAME="ini.cgi.fix_pathinfo" ></A ><TT CLASS="parameter" ><I >cgi.fix_pathinfo</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Provides <SPAN CLASS="emphasis" ><I CLASS="emphasis" >real</I ></SPAN > PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix it's paths to conform to the spec. A setting of zero causes PHP to behave as before. Default is zero. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED. </P ></DD ><DT ><A NAME="ini.cgi.force-redirect" ></A ><TT CLASS="parameter" ><I >cgi.force_redirect</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
cgi.force_redirect is necessary to provide security running PHP as a CGI under most web servers. Left undefined, PHP turns this on by default. You can turn it off <SPAN CLASS="emphasis" ><I CLASS="emphasis" >AT YOUR OWN RISK</I ></SPAN >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Windows Users: You CAN safely turn this off for IIS, in fact, you MUST. To get OmniHTTPD or Xitami to work you MUST turn it off. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.cgi.redirect-status-env" ></A ><TT CLASS="parameter" ><I >cgi.redirect_status_env</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
If cgi.force_redirect is turned on, and you are not running under Apache or Netscape (iPlanet) web servers, you MAY need to set an environment variable name that PHP will look for to know it is OK to continue execution. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Setting this variable MAY cause security issues, KNOW WHAT YOU ARE DOING FIRST. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.fastcgi.impersonate" ></A ><TT CLASS="parameter" ><I >fastcgi.impersonate</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
FastCGI under IIS (on WINNT based OS) supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under. mod_fastcgi under Apache does not currently support this feature (03/17/2002) Set to 1 if running under IIS. Default is zero. </P ></DD ><DT ><A NAME="ini.cgi.rfc2616-headers" ></A ><TT CLASS="parameter" ><I >cgi.rfc2616_headers</I ></TT > <A HREF="#language.types.integer" ><B CLASS="type" >int</B ></A ></DT ><DD ><P >
Tells PHP what type of headers to use when sending HTTP response code. If it's set 0, PHP sends a Status: header that is supported by Apache and other web servers. When this option is set to 1, PHP will send <A HREF="http://www.faqs.org/rfcs/rfc2616" TARGET="_top" >RFC 2616</A > compliant headers. Leave it set to 0 unless you know what you're doing. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sect.file_uploads" ></A >File Uploads</H3 ><P >
<DIV CLASS="table" ><A NAME="AEN3082" ></A ><P ><B >Tabulka 4-7. File Uploads Configuration Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >file_uploads</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >upload_tmp_dir</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NULL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >upload_max_filesize</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"2M"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM|PHP_INI_PERDIR</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.file-uploads" ></A ><TT CLASS="parameter" ><I >file_uploads</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Whether or not to allow HTTP <A HREF="#features.file-upload" >file uploads</A >. See also the <A HREF="#ini.upload-max-filesize" >upload_max_filesize</A >, <A HREF="#ini.upload-tmp-dir" >upload_tmp_dir</A >, and <A HREF="#ini.post-max-size" >post_max_size</A > directives. </P ></DD ><DT ><A NAME="ini.upload-tmp-dir" ></A ><TT CLASS="parameter" ><I >upload_tmp_dir</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
The temporary directory used for storing files when doing file upload. Must be writable by whatever user <TT CLASS="literal" >PHP</TT > is running as. If not specified PHP will use the system's default. </P ></DD ><DT ><A NAME="ini.upload-max-filesize" ></A ><TT CLASS="parameter" ><I >upload_max_filesize</I ></TT > <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P >
The maximum size of an uploaded file. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sql-general" ></A >General SQL</H3 ><P >
<DIV CLASS="table" ><A NAME="AEN3132" ></A ><P ><B >Tabulka 4-8. General SQL Configuration Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >sql.safe_mode</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.sql.safe-mode" ></A ><TT CLASS="parameter" ><I >sql.safe_mode</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
</P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="ini.sect.debugger" ></A >Debugger Configuration Directives</H3 ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Only PHP 3 implements a default debugger, for more information see <A HREF="#debugger" >D</A >. </P ></TD ></TR ></TABLE ></DIV ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.debugger.host" ></A ><TT CLASS="parameter" ><I >debugger.host</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
DNS name or IP address of host used by the debugger. </P ></DD ><DT ><A NAME="ini.debugger.port" ></A ><TT CLASS="parameter" ><I >debugger.port</I ></TT > <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A ></DT ><DD ><P >
Port number used by the debugger. </P ></DD ><DT ><A NAME="ini.debugger.enabled" ></A ><TT CLASS="parameter" ><I >debugger.enabled</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
Whether the debugger is enabled. </P ></DD ></DL ></DIV ></DIV ></DIV ></DIV ></DIV ><DIV CLASS="PART" ><A NAME="langref" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >II. Reference jazyka</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT >5. <A HREF="#language.basic-syntax" >Zßkladnφ syntaxe</A ></DT ><DT >6. <A HREF="#language.types" >Types</A ></DT ><DT >7. <A HREF="#language.variables" >Prom∞nnΘ</A ></DT ><DT >8. <A HREF="#language.constants" >Konstanty</A ></DT ><DT >9. <A HREF="#language.expressions" >V²razy</A ></DT ><DT >10. <A HREF="#language.operators" >Operßtory</A ></DT ><DT >11. <A HREF="#control-structures" >╪φdicφ struktury</A ></DT ><DT >12. <A HREF="#functions" >Funkce</A ></DT ><DT >13. <A HREF="#language.oop" >Classes and Objects</A ></DT ><DT >14. <A HREF="#language.references" >Vysv∞tlenφ referencφ (odkaz∙)</A ></DT ></DL ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.basic-syntax" >Kapitola 5. Zßkladnφ syntaxe</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="language.basic-syntax.phpmode" ></A >Opu╣t∞nφ HTML</H2 ><P >
Jsou Φty°i zp∙soby jak opustit HTML a vstoupit to "PHP m≤du": </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3186" ></A ><P ><B >P°φklad 5-1. Zp∙soby opu╣t∞nφ HTML</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >1. <? echo ("toto je nejjednodu╣╣φ SGML zpracovatelskß instrukce\n"); ?> 2. <?php echo("pokud chcete zpracovßvat XHTML nebo XML dokumenty, pou╛φvejte toto\n"); ?> 3. <script language="php"> echo ("n∞kterΘ editory (nap°φklad FrontPage) nemajφ zpracovatelskΘ instrukce v lßsce"); </script> 4. <% echo ("p°φpadn∞ m∙╛ete pou╛φvat ASP tagy"); %> <%= $variable; # toto je zkratka za "<%echo .." %></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Prvnφ zp∙sob je dostupn² pouze, pokud jsou povoleny krßtkΘ tagy. To se dß ud∞lat povolenφm konfiguraΦnφ direktivy <A HREF="#ini.short-open-tag" >short_open_tag</A > v konfiguraΦnφm souboru PHP, nebo kompilacφ PHP s <B CLASS="command" >configure</B > volbou --enable-short-tags. </P ><P >
Obecn∞ preferovanou metodou je druh² zp∙sob, proto╛e umo╛≥uje snadnou implementaci dal╣φho generovßnφ XHTML z PHP. </P ><P >
╚tvrt² zp∙sob je dostupn², pouze pokud byly povoleny ASP tagy pomocφ konfiguraΦnφ direktivy <A HREF="#ini.asp-tags" >asp_tags</A >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B >Podpora ASP tag∙ byla p°idßna v 3.0.4.</P ></BLOCKQUOTE ></DIV ></P ><P >
P°φpadnß bezprost°edn∞ nßsledujφcφ sekvence konce °ßdku je souΦßstφ uzavφrajφcφho tagu. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.basic-syntax.instruction-separation" ></A >Odd∞lovßnφ instrukcφ</H2 ><P >
Instrukce se odd∞lujφ stejn∞ jako v C nebo Perlu - ukonΦujte ka╛d² v²raz st°ednφkem. </P ><P >
Uzavφrajφcφ tag (?>) takΘ implikuje konec v²razu, tak╛e nßsledujφcφ ukßzky jsou ekvivalentnφ: <DIV CLASS="informalexample" ><A NAME="AEN3202" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php echo "Toto je test"; ?> <?php echo "Toto je test" ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.basic-syntax.comments" ></A >Komentß°e</H2 ><P >
PHP podporuje komentß°ovΘ notace jazyk∙ 'C', 'C++' a UnixovΘho shellu. Nap°φklad: <DIV CLASS="informalexample" ><A NAME="AEN3207" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php echo "Toto je test"; // Toto je jedno°ßdkov² komentß° typu C++ /* Toto je vφce°ßdkov² komentß° a je╣t∞ jeden komentß° */ echo "Toto je dal╣φ test"; echo "Poslednφ Test"; # Toto je komentß° shellovΘho typu ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></P ><P >
Jedno°ßdkovΘ typy komentß°∙ ve skuteΦnosti komentujφ do konce °ßdku nebo souΦasnΘho bloku PHP k≤du, podle toho, co se vyskytuje d°φv. </P ><DIV CLASS="informalexample" ><A NAME="AEN3210" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><h1>Toto je <?php # echo "mal²";?> p°φklad.</h1> <p>HlaviΦka na p°edchozφm °ßdku bude 'Toto je p°φklad'.</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
M∞li byste si dßt pozor na vno°ovßnφ komentß°∙ typu 'C++', ke kterΘmu m∙╛e dojφt p°i zakomentovßnφ velk²ch blok∙. </P ><DIV CLASS="informalexample" ><A NAME="AEN3213" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php /* echo "Toto je test"; /* Tento komentß° zp∙sobφ problΘm */ */ ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.types" >Kapitola 6. Types</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="language.types.intro" ></A >Introduction</H2 ><P >
PHP supports eight primitive types. </P ><P >
Four scalar types: <P ></P ><UL ><LI ><P >
<A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A > </P ></LI ><LI ><P >
<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > </P ></LI ><LI ><P >
<A HREF="#language.types.float" ><B CLASS="type" >float</B ></A > (floating-point number, aka '<A HREF="#language.types.float" ><B CLASS="type" >double</B ></A >') </P ></LI ><LI ><P >
<A HREF="#language.types.string" ><B CLASS="type" >string</B ></A > </P ></LI ></UL > Two compound types: <P ></P ><UL ><LI ><P >
<A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > </P ></LI ><LI ><P >
<A HREF="#language.types.object" ><B CLASS="type" >object</B ></A > </P ></LI ></UL > And finally two special types: <P ></P ><UL ><LI ><P >
<A HREF="#language.types.resource" ><B CLASS="type" >resource</B ></A > </P ></LI ><LI ><P >
<A HREF="#language.types.null" ><B CLASS="type" >NULL</B ></A > </P ></LI ></UL > This manual also introduces some <A HREF="#language.pseudo-types" >pseudo-types</A > for readability reasons: <P ></P ><UL ><LI ><P >
<A HREF="#language.types.mixed" >mixed</A > </P ></LI ><LI ><P >
<A HREF="#language.types.number" >number</A > </P ></LI ><LI ><P >
<A HREF="#language.types.mixed" >callback</A > </P ></LI ></UL > You may also find some references to the type "double". Consider double the same as float, the two names exist only for historic reasons. </P ><P >
The type of a variable is usually not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > If you want to check out the type and value of a certain <A HREF="#language.expressions" >expression</A >, use <A HREF="#function.var-dump" ><B CLASS="function" >var_dump()</B ></A >. </P ><P ><B >Poznßmka: </B > If you simply want a human-readable representation of the type for debugging, use <A HREF="#function.gettype" ><B CLASS="function" >gettype()</B ></A >. To check for a certain type, do <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > use <A HREF="#function.gettype" ><B CLASS="function" >gettype()</B ></A >, but use the <TT CLASS="literal" >is_<TT CLASS="replaceable" ><I >type</I ></TT ></TT > functions. Some examples: <DIV CLASS="informalexample" ><A NAME="AEN3271" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $bool = TRUE; // a boolean $str = "foo"; // a string $int = 12; // an integer echo gettype($bool); // prints out "boolean" echo gettype($str); // prints out "string" // If this is an integer, increment it by four if (is_int($int)) { $int += 4; } // If $bool is a string, print it out // (does not print out anything) if (is_string($bool)) { echo "String: $bool"; } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></BLOCKQUOTE ></DIV ><P >
If you would like to force a variable to be converted to a certain type, you may either <A HREF="#language.types.typecasting" >cast</A > the variable or use the <A HREF="#function.settype" ><B CLASS="function" >settype()</B ></A > function on it. </P ><P >
Note that a variable may be evaluated with different values in certain situations, depending on what type it is at the time. For more information, see the section on <A HREF="#language.types.type-juggling" >Type Juggling</A >. Also, you may be interested in viewing <A HREF="#types.comparisons" >the type comparison tables</A >, as they show examples of various type related comparisons. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.boolean" ></A >Booleans</H2 ><P >
This is the easiest type. A <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A > expresses a truth value. It can be either <TT CLASS="constant" ><B >TRUE</B ></TT > or <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The boolean type was introduced in PHP 4. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.boolean.syntax" ></A >Syntax</H3 ><P >
To specify a boolean literal, use either the keyword <TT CLASS="constant" ><B >TRUE</B ></TT > or <TT CLASS="constant" ><B >FALSE</B ></TT >. Both are case-insensitive. <DIV CLASS="informalexample" ><A NAME="AEN3292" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = True; // assign the value TRUE to $foo ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Usually you use some kind of <A HREF="#language.operators" >operator</A > which returns a <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A > value, and then pass it on to a <A HREF="#control-structures" >control structure</A >. <DIV CLASS="informalexample" ><A NAME="AEN3298" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // == is an operator which test // equality and returns a boolean if ($action == "show_version") { echo "The version is 1.23"; } // this is not necessary... if ($show_separators == TRUE) { echo "<hr>\n"; } // ...because you can simply type if ($show_separators) { echo "<hr>\n"; } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.boolean.casting" ></A >Converting to boolean</H3 ><P >
To explicitly convert a value to <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A >, use either the <TT CLASS="literal" >(bool)</TT > or the <TT CLASS="literal" >(boolean)</TT > cast. However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires a <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A > argument. </P ><P >
See also <A HREF="#language.types.type-juggling" >Type Juggling</A >. </P ><P >
When converting to <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A >, the following values are considered <TT CLASS="constant" ><B >FALSE</B ></TT >: <P ></P ><UL ><LI ><P >the <A HREF="#language.types.boolean" >boolean</A > <TT CLASS="constant" ><B >FALSE</B ></TT > itself</P ></LI ><LI ><P >the <A HREF="#language.types.integer" >integer</A > 0 (zero) </P ></LI ><LI ><P >the <A HREF="#language.types.float" >float</A > 0.0 (zero) </P ></LI ><LI ><P >the empty <A HREF="#language.types.string" >string</A >, and the <A HREF="#language.types.string" >string</A > "0"</P ></LI ><LI ><P >an <A HREF="#language.types.array" >array</A > with zero elements</P ></LI ><LI ><P >an <A HREF="#language.types.object" >object</A > with zero member variables</P ></LI ><LI ><P >the special type <A HREF="#language.types.null" >NULL</A > (including unset variables) </P ></LI ></UL > Every other value is considered <TT CLASS="constant" ><B >TRUE</B ></TT > (including any <A HREF="#language.types.resource" >resource</A >). <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
<TT CLASS="literal" >-1</TT > is considered <TT CLASS="constant" ><B >TRUE</B ></TT >, like any other non-zero (whether negative or positive) number! </P ></TD ></TR ></TABLE ></DIV > <DIV CLASS="informalexample" ><A NAME="AEN3342" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo gettype((bool) ""); // bool(false) echo gettype((bool) 1); // bool(true) echo gettype((bool) -2); // bool(true) echo gettype((bool) "foo"); // bool(true) echo gettype((bool) 2.3e5); // bool(true) echo gettype((bool) array(12)); // bool(true) echo gettype((bool) array()); // bool(false) ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.integer" ></A >Integers</H2 ><P >
An <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}. </P ><P >
See also: <A HREF="#ref.gmp" >Arbitrary length integer / GMP</A >, <A HREF="#language.types.float" >Floating point numbers</A >, and <A HREF="#ref.bc" >Arbitrary precision / BCMath</A > </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.integer.syntax" ></A >Syntax</H3 ><P >
Integers can be specified in decimal (10-based), hexadecimal (16-based) or octal (8-based) notation, optionally preceded by a sign (- or +). </P ><P >
If you use the octal notation, you must precede the number with a <TT CLASS="literal" >0</TT > (zero), to use hexadecimal notation precede the number with <TT CLASS="literal" >0x</TT >. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3358" ></A ><P ><B >P°φklad 6-1. Integer literals</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = 1234; # decimal number $a = -123; # a negative number $a = 0123; # octal number (equivalent to 83 decimal) $a = 0x1A; # hexadecimal number (equivalent to 26 decimal) ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Formally the possible structure for integer literals is: <DIV CLASS="informalexample" ><A NAME="AEN3361" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >decimal : [1-9][0-9]* | 0 hexadecimal : 0[xX][0-9a-fA-F]+ octal : 0[0-7]+ integer : [+-]?decimal | [+-]?hexadecimal | [+-]?octal</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). PHP does not support unsigned integers. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.integer.overflow" ></A >Integer overflow</H3 ><P >
If you specify a number beyond the bounds of the <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > type, it will be interpreted as a <A HREF="#language.types.float" ><B CLASS="type" >float</B ></A > instead. Also, if you perform an operation that results in a number beyond the bounds of the <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > type, a <A HREF="#language.types.float" ><B CLASS="type" >float</B ></A > will be returned instead. <DIV CLASS="informalexample" ><A NAME="AEN3370" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $large_number = 2147483647; var_dump($large_number); // output: int(2147483647) $large_number = 2147483648; var_dump($large_number); // output: float(2147483648) // this goes also for hexadecimal specified integers: var_dump( 0x80000000 ); // output: float(2147483648) $million = 1000000; $large_number = 50000 * $million; var_dump($large_number); // output: float(50000000000) ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Unfortunately, there was a bug in PHP so that this does not always work correctly when there are negative numbers involved. For example: when you do <TT CLASS="literal" >-50000 * $million</TT >, the result will be <TT CLASS="literal" >-429496728</TT >. However, when both operands are positive there is no problem. </P ><P >
This is solved in PHP 4.1.0. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
There is no integer division operator in PHP. <TT CLASS="literal" >1/2</TT > yields the <A HREF="#language.types.float" ><B CLASS="type" >float</B ></A > <TT CLASS="literal" >0.5</TT >. You can cast the value to an integer to always round it downwards, or you can use the <A HREF="#function.round" ><B CLASS="function" >round()</B ></A > function. <DIV CLASS="informalexample" ><A NAME="AEN3382" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php var_dump(25/7); // float(3.5714285714286) var_dump((int) (25/7)); // int(3) var_dump(round(25/7)); // float(4) ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.integer.casting" ></A >Converting to integer</H3 ><P >
To explicitly convert a value to <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >, use either the <TT CLASS="literal" >(int)</TT > or the <TT CLASS="literal" >(integer)</TT > cast. However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires an <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > argument. You can also convert a value to integer with the function <A HREF="#function.intval" ><B CLASS="function" >intval()</B ></A >. </P ><P >
See also <A HREF="#language.types.type-juggling" >type-juggling</A >. </P ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.integer.casting.from-boolean" ></A >From <A HREF="#language.types.boolean" >booleans</A ></H4 ><P >
<TT CLASS="constant" ><B >FALSE</B ></TT > will yield <TT CLASS="literal" >0</TT > (zero), and <TT CLASS="constant" ><B >TRUE</B ></TT > will yield <TT CLASS="literal" >1</TT > (one). </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.integer.casting.from-float" ></A >From <A HREF="#language.types.float" >floating point numbers</A ></H4 ><P >
When converting from float to integer, the number will be rounded <SPAN CLASS="emphasis" ><I CLASS="emphasis" >towards zero</I ></SPAN >. </P ><P >
If the float is beyond the boundaries of integer (usually <TT CLASS="literal" >+/- 2.15e+9 = 2^31</TT >), the result is undefined, since the float hasn't got enough precision to give an exact integer result. No warning, not even a notice will be issued in this case! </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Never cast an unknown fraction to <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >, as this can sometimes lead to unexpected results. <DIV CLASS="informalexample" ><A NAME="AEN3412" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo (int) ( (0.1+0.7) * 10 ); // echoes 7! ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > See for more information the <A HREF="#warn.float-precision" >warning about float-precision</A >. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.integer.casting.from-string" ></A >From strings</H4 ><P >
See <A HREF="#language.types.string.conversion" >String conversion to numbers</A > </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.integer.casting.from-other" ></A >From other types</H4 ><P >
<DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Behaviour of converting to integer is undefined for other types. Currently, the behaviour is the same as if the value was first <A HREF="#language.types.boolean.casting" >converted to boolean</A >. However, do <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > rely on this behaviour, as it can change without notice. </P ></TD ></TR ></TABLE ></DIV > </P ></DIV ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.float" ></A >Floating point numbers</H2 ><P >
Floating point numbers (AKA "floats", "doubles" or "real numbers") can be specified using any of the following syntaxes: <DIV CLASS="informalexample" ><A NAME="AEN3429" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = 1.234; $b = 1.2e3; $c = 7E-10; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Formally: <DIV CLASS="informalexample" ><A NAME="AEN3431" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >LNUM [0-9]+ DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? {LNUM})</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (that's 64 bit IEEE format). </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B ><A NAME="warn.float-precision" ></A >Floating point precision</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
It is quite usual that simple decimal fractions like <TT CLASS="literal" >0.1</TT > or <TT CLASS="literal" >0.7</TT > cannot be converted into their internal binary counterparts without a little loss of precision. This can lead to confusing results: for example, <TT CLASS="literal" >floor((0.1+0.7)*10)</TT > will usually return <TT CLASS="literal" >7</TT > instead of the expected <TT CLASS="literal" >8</TT > as the result of the internal representation really being something like <TT CLASS="literal" >7.9999999999...</TT >. </P ><P >
This is related to the fact that it is impossible to exactly express some fractions in decimal notation with a finite number of digits. For instance, <TT CLASS="literal" >1/3</TT > in decimal form becomes <TT CLASS="literal" >0.3333333. . .</TT >. </P ><P >
So never trust floating number results to the last digit and never compare floating point numbers for equality. If you really need higher precision, you should use the <A HREF="#ref.bc" >arbitrary precision math functions</A > or <A HREF="#ref.gmp" >gmp</A > functions instead. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.float.casting" ></A >Converting to float</H3 ><P >
For information on when and how strings are converted to floats, see the section titled <A HREF="#language.types.string.conversion" >String conversion to numbers</A >. For values of other types, the conversion is the same as if the value would have been converted to integer and then to float. See the <A HREF="#language.types.integer.casting" >Converting to integer</A > section for more information. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.string" ></A >Strings</H2 ><P >
A <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A > is series of characters. In PHP, a character is the same as a byte, that is, there are exactly 256 different characters possible. This also implies that PHP has no native support of Unicode. See <A HREF="#function.utf8-encode" ><B CLASS="function" >utf8_encode()</B ></A > and <A HREF="#function.utf8-decode" ><B CLASS="function" >utf8_decode()</B ></A > for some Unicode support. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > It is no problem for a string to become very large. There is no practical bound to the size of strings imposed by PHP, so there is no reason at all to worry about long strings. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.string.syntax" ></A >Syntax</H3 ><P >
A string literal can be specified in three different ways. <P ></P ><UL ><LI ><P >
<A HREF="#language.types.string.syntax.single" >single quoted</A > </P ></LI ><LI ><P >
<A HREF="#language.types.string.syntax.double" >double quoted</A > </P ></LI ><LI ><P >
<A HREF="#language.types.string.syntax.heredoc" >heredoc syntax</A > </P ></LI ></UL > </P ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.string.syntax.single" ></A >Single quoted</H4 ><P >
The easiest way to specify a simple string is to enclose it in single quotes (the character <TT CLASS="literal" >'</TT >). </P ><P >
To specify a literal single quote, you will need to escape it with a backslash (<TT CLASS="literal" >\</TT >), like in many other languages. If a backslash needs to occur before a single quote or at the end of the string, you need to double it. Note that if you try to escape any other character, the backslash will also be printed! So usually there is no need to escape the backslash itself. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > In PHP 3, a warning will be issued at the <TT CLASS="literal" >E_NOTICE</TT > level when this happens. </P ></BLOCKQUOTE ></DIV > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Unlike the two other syntaxes, <A HREF="#language.variables" >variables</A > and escape sequences for special characters will <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > be expanded when they occur in single quoted strings. </P ></BLOCKQUOTE ></DIV > <DIV CLASS="informalexample" ><A NAME="AEN3487" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo 'this is a simple string'; echo 'You can also have embedded newlines in strings this way as it is okay to do'; // Outputs: Arnold once said: "I'll be back" echo 'Arnold once said: "I\'ll be back"'; // Outputs: You deleted C:\*.*? echo 'You deleted C:\\*.*?'; // Outputs: You deleted C:\*.*? echo 'You deleted C:\*.*?'; // Outputs: This will not expand: \n a newline echo 'This will not expand: \n a newline'; // Outputs: Variables do not $expand $either echo 'Variables do not $expand $either'; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.string.syntax.double" ></A >Double quoted</H4 ><P >
If the string is enclosed in double-quotes ("), PHP understands more escape sequences for special characters: </P ><DIV CLASS="table" ><A NAME="AEN3492" ></A ><P ><B >Tabulka 6-1. Escaped characters</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >sequence</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >meaning</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\n</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >linefeed (LF or 0x0A (10) in ASCII)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\r</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >carriage return (CR or 0x0D (13) in ASCII)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\t</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >horizontal tab (HT or 0x09 (9) in ASCII)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\\</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >backslash</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\$</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >dollar sign</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\"</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >double-quote</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\[0-7]{1,3}</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
the sequence of characters matching the regular expression is a character in octal notation </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="literal" >\x[0-9A-Fa-f]{1,2}</TT ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
the sequence of characters matching the regular expression is a character in hexadecimal notation </TD ></TR ></TBODY ></TABLE ></DIV ><P >
Again, if you try to escape any other character, the backslash will be printed too! </P ><P >
But the most important feature of double-quoted strings is the fact that variable names will be expanded. See <A HREF="#language.types.string.parsing" >string parsing</A > for details. </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.string.syntax.heredoc" ></A >Heredoc</H4 ><P >
Another way to delimit strings is by using heredoc syntax ("<<<"). One should provide an identifier after <TT CLASS="literal" ><<<</TT >, then the string, and then the same identifier to close the quotation. </P ><P >
The closing identifier <SPAN CLASS="emphasis" ><I CLASS="emphasis" >must</I ></SPAN > begin in the first column of the line. Also, the identifier used must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
It is very important to note that the line with the closing identifier contains no other characters, except <SPAN CLASS="emphasis" ><I CLASS="emphasis" >possibly</I ></SPAN > a semicolon (<TT CLASS="literal" >;</TT >). That means especially that the identifier <SPAN CLASS="emphasis" ><I CLASS="emphasis" >may not be indented</I ></SPAN >, and there may not be any spaces or tabs after or before the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is <TT CLASS="literal" >\r</TT > on Macintosh for example. </P ><P >
If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one. If in this case a proper closing identifier is not found then a parse error will result with the line number being at the end of the script. </P ></TD ></TR ></TABLE ></DIV ><P >
Heredoc text behaves just like a double-quoted string, without the double-quotes. This means that you do not need to escape quotes in your here docs, but you can still use the escape codes listed above. Variables are expanded, but the same care must be taken when expressing complex variables inside a here doc as with strings. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3549" ></A ><P ><B >P°φklad 6-2. Heredoc string quoting example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; /* More complex example, with variables. */ class foo { var $foo; var $bar; function foo() { $this->foo = 'Foo'; $this->bar = array('Bar1', 'Bar2', 'Bar3'); } } $foo = new foo(); $name = 'MyName'; echo <<<EOT My name is "$name". I am printing some $foo->foo. Now, I am printing some {$foo->bar[1]}. This should print a capital 'A': \x41 EOT; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Heredoc support was added in PHP 4. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.string.parsing" ></A >Variable parsing</H4 ><P >
When a string is specified in double quotes or with heredoc, <A HREF="#language.variables" >variables</A > are parsed within it. </P ><P >
There are two types of syntax: a <A HREF="#language.types.string.parsing.simple" >simple</A > one and a <A HREF="#language.types.string.parsing.complex" >complex</A > one. The simple syntax is the most common and convenient. It provides a way to parse a variable, an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > value, or an object property. </P ><P >
The complex syntax was introduced in PHP 4, and can be recognised by the curly braces surrounding the expression. </P ><DIV CLASS="sect4" ><HR><H5 CLASS="sect4" ><A NAME="language.types.string.parsing.simple" ></A >Simple syntax</H5 ><P >
If a dollar sign (<TT CLASS="literal" >$</TT >) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces if you want to explicitly specify the end of the name. </P ><DIV CLASS="informalexample" ><A NAME="AEN3568" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $beer = 'Heineken'; echo "$beer's taste is great"; // works, "'" is an invalid character for varnames echo "He drank some $beers"; // won't work, 's' is a valid character for varnames echo "He drank some ${beer}s"; // works echo "He drank some {$beer}s"; // works ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Similarly, you can also have an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > index or an object property parsed. With array indices, the closing square bracket (<TT CLASS="literal" >]</TT >) marks the end of the index. For object properties the same rules apply as to simple variables, though with object properties there doesn't exist a trick like the one with variables. </P ><DIV CLASS="informalexample" ><A NAME="AEN3574" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // These examples are specific to using arrays inside of strings. // When outside of a string, always quote your array string keys // and do not use {braces} when outside of strings either. // Let's show all errors error_reporting(E_ALL); $fruits = array('strawberry' => 'red', 'banana' => 'yellow'); // Works but note that this works differently outside string-quotes echo "A banana is $fruits[banana]."; // Works echo "A banana is {$fruits['banana']}."; // Works but PHP looks for a constant named banana first // as described below. echo "A banana is {$fruits[banana]}."; // Won't work, use braces. This results in a parse error. echo "A banana is $fruits['banana']."; // Works echo "A banana is " . $fruits['banana'] . "."; // Works echo "This square is $square->width meters broad."; // Won't work. For a solution, see the complex syntax. echo "This square is $square->width00 centimeters broad."; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
For anything more complex, you should use the complex syntax. </P ></DIV ><DIV CLASS="sect4" ><HR><H5 CLASS="sect4" ><A NAME="language.types.string.parsing.complex" ></A >Complex (curly) syntax</H5 ><P >
This isn't called complex because the syntax is complex, but because you can include complex expressions this way. </P ><P >
In fact, you can include any value that is in the namespace in strings with this syntax. You simply write the expression the same way as you would outside the string, and then include it in { and }. Since you can't escape '{', this syntax will only be recognised when the $ is immediately following the {. (Use "{\$" or "\{$" to get a literal "{$"). Some examples to make it clear: </P ><DIV CLASS="informalexample" ><A NAME="AEN3581" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Let's show all errors error_reporting(E_ALL); $great = 'fantastic'; // Won't work, outputs: This is { fantastic} echo "This is { $great}"; // Works, outputs: This is fantastic echo "This is {$great}"; echo "This is ${great}"; // Works echo "This square is {$square->width}00 centimeters broad."; // Works echo "This works: {$arr[4][3]}"; // This is wrong for the same reason as $foo[bar] is wrong // outside a string. In other words, it will still work but // because PHP first looks for a constant named foo, it will // throw an error of level E_NOTICE (undefined constant). echo "This is wrong: {$arr[foo][3]}"; // Works. When using multi-dimensional arrays, always use // braces around arrays when inside of strings echo "This works: {$arr['foo'][3]}"; // Works. echo "This works: " . $arr['foo'][3]; echo "You can even write {$obj->values[3]->name}"; echo "This is the value of the var named $name: {${$name}}"; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></DIV ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.string.substr" ></A >String access and modification by character</H4 ><P >
Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string in curly braces. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > For backwards compatibility, you can still use array-brackets for the same purpose. However, this syntax is deprecated as of PHP 4. </P ></BLOCKQUOTE ></DIV ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3589" ></A ><P ><B >P°φklad 6-3. Some string examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Get the first character of a string $str = 'This is a test.'; $first = $str{0}; // Get the third character of a string $third = $str{2}; // Get the last character of a string. $str = 'This is still a test.'; $last = $str{strlen($str)-1}; // Modify the last character of a string $str = 'Look at the sea'; $str{strlen($str)-1} = 'e'; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.string.useful-funcs" ></A >Useful functions and operators</H3 ><P >
Strings may be concatenated using the '.' (dot) operator. Note that the '+' (addition) operator will not work for this. Please see <A HREF="#language.operators.string" >String operators</A > for more information. </P ><P >
There are a lot of useful functions for string modification. </P ><P >
See the <A HREF="#ref.strings" >string functions section</A > for general functions, the regular expression functions for advanced find&replacing (in two tastes: <A HREF="#ref.pcre" >Perl</A > and <A HREF="#ref.regex" >POSIX extended</A >). </P ><P >
There are also <A HREF="#ref.url" >functions for URL-strings</A >, and functions to encrypt/decrypt strings (<A HREF="#ref.mcrypt" >mcrypt</A > and <A HREF="#ref.mhash" >mhash</A >). </P ><P >
Finally, if you still didn't find what you're looking for, see also the <A HREF="#ref.ctype" >character type functions</A >. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.string.casting" ></A >Converting to string</H3 ><P >
You can convert a value to a string using the <TT CLASS="literal" >(string)</TT > cast, or the <A HREF="#function.strval" ><B CLASS="function" >strval()</B ></A > function. String conversion is automatically done in the scope of an expression for you where a string is needed. This happens when you use the <A HREF="#function.echo" ><B CLASS="function" >echo()</B ></A > or <A HREF="#function.print" ><B CLASS="function" >print()</B ></A > functions, or when you compare a variable value to a string. Reading the manual sections on <A HREF="#language.types" >Types</A > and <A HREF="#language.types.type-juggling" >Type Juggling</A > will make the following clearer. See also <A HREF="#function.settype" ><B CLASS="function" >settype()</B ></A >. </P ><P >
A <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A > <TT CLASS="constant" ><B >TRUE</B ></TT > value is converted to the string <TT CLASS="literal" >"1"</TT >, the <TT CLASS="constant" ><B >FALSE</B ></TT > value is represented as <TT CLASS="literal" >""</TT > (empty string). This way you can convert back and forth between boolean and string values. </P ><P > An <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > or a floating point number (<A HREF="#language.types.float" ><B CLASS="type" >float</B ></A >) is converted to a string representing the number with its digits (including the exponent part for floating point numbers). </P ><P >
Arrays are always converted to the string <TT CLASS="literal" >"Array"</TT >, so you cannot dump out the contents of an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > with <A HREF="#function.echo" ><B CLASS="function" >echo()</B ></A > or <A HREF="#function.print" ><B CLASS="function" >print()</B ></A > to see what is inside them. To view one element, you'd do something like <TT CLASS="literal" >
echo $arr['foo']</TT >. See below for tips on dumping/viewing the entire contents. </P ><P >
Objects are always converted to the string <TT CLASS="literal" >"Object"</TT >. If you would like to print out the member variable values of an <A HREF="#language.types.object" ><B CLASS="type" >object</B ></A > for debugging reasons, read the paragraphs below. If you would like to find out the class name of which an object is an instance of, use <A HREF="#function.get-class" ><B CLASS="function" >get_class()</B ></A >. </P ><P >
Resources are always converted to strings with the structure <TT CLASS="literal" >"Resource id #1"</TT > where <TT CLASS="literal" >1</TT > is the unique number of the <A HREF="#language.types.resource" ><B CLASS="type" >resource</B ></A > assigned by PHP during runtime. If you would like to get the type of the resource, use <A HREF="#function.get-resource-type" ><B CLASS="function" >get_resource_type()</B ></A >. </P ><P >
<TT CLASS="constant" ><B >NULL</B ></TT > is always converted to an empty string. </P ><P >
As you can see above, printing out the arrays, objects or resources does not provide you any useful information about the values themselfs. Look at the functions <A HREF="#function.print-r" ><B CLASS="function" >print_r()</B ></A > and <A HREF="#function.var-dump" ><B CLASS="function" >var_dump()</B ></A > for better ways to print out values for debugging. </P ><P >
You can also convert PHP values to strings to store them permanently. This method is called serialization, and can be done with the function <A HREF="#function.serialize" ><B CLASS="function" >serialize()</B ></A >. You can also serialize PHP values to XML structures, if you have <A HREF="#ref.wddx" >WDDX</A > support in your PHP setup. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.string.conversion" ></A >String conversion to numbers</H3 ><P >
When a string is evaluated as a numeric value, the resulting value and type are determined as follows. </P ><P >
The string will evaluate as a <A HREF="#language.types.float" ><B CLASS="type" >float</B ></A > if it contains any of the characters '.', 'e', or 'E'. Otherwise, it will evaluate as an integer. </P ><P >
The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits. </P ><DIV CLASS="informalexample" ><A NAME="AEN3655" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = 1 + "10.5"; // $foo is float (11.5) $foo = 1 + "-1.3e3"; // $foo is float (-1299) $foo = 1 + "bob-1.3e3"; // $foo is integer (1) $foo = 1 + "bob3"; // $foo is integer (1) $foo = 1 + "10 Small Pigs"; // $foo is integer (11) $foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2) $foo = "10.0 pigs " + 1; // $foo is float (11) $foo = "10.0 pigs " + 1.0; // $foo is float (11) ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
For more information on this conversion, see the Unix manual page for strtod(3). </P ><P >
If you would like to test any of the examples in this section, you can cut and paste the examples and insert the following line to see for yourself what's going on: <DIV CLASS="informalexample" ><A NAME="AEN3659" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo "\$foo==$foo; type is " . gettype ($foo) . "<br />\n"; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Do not expect to get the code of one character by converting it to integer (as you would do in C for example). Use the functions <A HREF="#function.ord" ><B CLASS="function" >ord()</B ></A > and <A HREF="#function.chr" ><B CLASS="function" >chr()</B ></A > to convert between charcodes and characters. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.array" ></A >Arrays</H2 ><P >
An array in PHP is actually an ordered map. A map is a type that maps <SPAN CLASS="emphasis" ><I CLASS="emphasis" >values</I ></SPAN > to <SPAN CLASS="emphasis" ><I CLASS="emphasis" >keys</I ></SPAN >. This type is optimized in several ways, so you can use it as a real array, or a list (vector), hashtable (which is an implementation of a map), dictionary, collection, stack, queue and probably more. Because you can have another PHP array as a value, you can also quite easily simulate trees. </P ><P >
Explanation of those data structures is beyond the scope of this manual, but you'll find at least one example for each of them. For more information we refer you to external literature about this broad topic. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.array.syntax" ></A >Syntax</H3 ><DIV CLASS="sect3" ><H4 CLASS="sect3" ><A NAME="language.types.array.syntax.array-func" ></A >Specifying with <A HREF="#function.array" ><B CLASS="function" >array()</B ></A ></H4 ><P >
An <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > can be created by the <A HREF="#function.array" ><B CLASS="function" >array()</B ></A > language-construct. It takes a certain number of comma-separated <TT CLASS="literal" ><TT CLASS="replaceable" ><I >key</I ></TT > => <TT CLASS="replaceable" ><I >value</I ></TT ></TT > pairs. </P ><P >
<TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="synopsis" >array( [<TT CLASS="replaceable" ><I >key</I ></TT > =>] <TT CLASS="replaceable" ><I >value</I ></TT > , ... ) // <TT CLASS="replaceable" ><I >key</I ></TT > may be an <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > or <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A > // <TT CLASS="replaceable" ><I >value</I ></TT > may be any value</PRE ></TD ></TR ></TABLE > </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN3691" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $arr = array("foo" => "bar", 12 => true); echo $arr["foo"]; // bar echo $arr[12]; // 1 ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
A <TT CLASS="varname" >key</TT > may be either an <TT CLASS="literal" >integer</TT > or a <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A >. If a key is the standard representation of an <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >, it will be interpreted as such (i.e. <TT CLASS="literal" >"8"</TT > will be interpreted as <TT CLASS="literal" >8</TT >, while <TT CLASS="literal" >"08"</TT > will be interpreted as <TT CLASS="literal" >"08"</TT >). There are no different indexed and associative array types in PHP; there is only one array type, which can both contain integer and string indices. </P ><P >
A value can be of any PHP type. <DIV CLASS="informalexample" ><A NAME="AEN3703" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $arr = array("somearray" => array(6 => 5, 13 => 9, "a" => 42)); echo $arr["somearray"][6]; // 5 echo $arr["somearray"][13]; // 9 echo $arr["somearray"]["a"]; // 42 ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
If you do not specify a key for a given value, then the maximum of the integer indices is taken, and the new key will be that maximum value + 1. If you specify a key that already has a value assigned to it, that value will be overwritten. <DIV CLASS="informalexample" ><A NAME="AEN3706" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // This array is the same as ... array(5 => 43, 32, 56, "b" => 12); // ...this array array(5 => 43, 6 => 32, 7 => 56, "b" => 12); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
As of PHP 4.3.0, the index generation behaviour described above has changed. Now, if you append to an array in which the current maximum key is negative, then the next key created will be zero (<TT CLASS="literal" >0</TT >). Before, the new index would have been set to the largest existing key + 1, the same as positive indices are. </P ></TD ></TR ></TABLE ></DIV ><P >
Using <TT CLASS="constant" ><B >TRUE</B ></TT > as a key will evaluate to <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > <TT CLASS="literal" >1</TT > as key. Using <TT CLASS="constant" ><B >FALSE</B ></TT > as a key will evaluate to <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > <TT CLASS="literal" >0</TT > as key. Using <TT CLASS="literal" >NULL</TT > as a key will evaluate to the empty string. Using the empty string as key will create (or overwrite) a key with the empty string and its value; it is not the same as using empty brackets. </P ><P >
You cannot use arrays or objects as keys. Doing so will result in a warning: <TT CLASS="literal" >Illegal offset type</TT >. </P ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.types.array.syntax.modifying" ></A >Creating/modifying with square-bracket syntax</H4 ><P >
You can also modify an existing array by explicitly setting values in it. </P ><P >
This is done by assigning values to the array while specifying the key in brackets. You can also omit the key, add an empty pair of brackets ("<TT CLASS="literal" >[]</TT >") to the variable name in that case. <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="synopsis" >$arr[<TT CLASS="replaceable" ><I >key</I ></TT >] = <TT CLASS="replaceable" ><I >value</I ></TT >; $arr[] = <TT CLASS="replaceable" ><I >value</I ></TT >; // <TT CLASS="replaceable" ><I >key</I ></TT > may be an <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > or <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A > // <TT CLASS="replaceable" ><I >value</I ></TT > may be any value</PRE ></TD ></TR ></TABLE > If <TT CLASS="varname" >$arr</TT > doesn't exist yet, it will be created. So this is also an alternative way to specify an array. To change a certain value, just assign a new value to an element specified with its key. If you want to remove a key/value pair, you need to <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A > it. <DIV CLASS="informalexample" ><A NAME="AEN3736" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $arr = array(5 => 1, 12 => 2); $arr[] = 56; // This is the same as $arr[13] = 56; // at this point of the script $arr["x"] = 42; // This adds a new element to // the array with key "x" unset($arr[5]); // This removes the element from the array unset($arr); // This deletes the whole array ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > As mentioned above, if you provide the brackets with no key specified, then the maximum of the existing integer indices is taken, and the new key will be that maximum value + 1 . If no integer indices exist yet, the key will be <TT CLASS="literal" >0</TT > (zero). If you specify a key that already has a value assigned to it, that value will be overwritten. </P ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
As of PHP 4.3.0, the index generation behaviour described above has changed. Now, if you append to an array in which the current maximum key is negative, then the next key created will be zero (<TT CLASS="literal" >0</TT >). Before, the new index would have been set to the largest existing key + 1, the same as positive indices are. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
Note that the maximum integer key used for this <SPAN CLASS="emphasis" ><I CLASS="emphasis" >need not currently exist in the array</I ></SPAN >. It simply must have existed in the array at some time since the last time the array was re-indexed. The following example illustrates: </P ><DIV CLASS="informalexample" ><A NAME="AEN3747" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Create a simple array. $array = array(1, 2, 3, 4, 5); print_r($array); // Now delete every item, but leave the array itself intact: foreach ($array as $i => $value) { unset($array[$i]); } print_r($array); // Append an item (note that the new key is 5, instead of 0 as you // might expect). $array[] = 6; print_r($array); // Re-index: $array = array_values($array); $array[] = 7; print_r($array); ?></PRE ></TD ></TR ></TABLE ><P >
The above example would produce the following output: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Array ( ) Array ( [5] => 6 ) Array ( [0] => 6 [1] => 7 )</PRE ></TD ></TR ></TABLE > </P ><P ></P ></DIV ></BLOCKQUOTE ></DIV ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.array.useful-funcs" ></A >Useful functions</H3 ><P >
There are quite a few useful functions for working with arrays. See the <A HREF="#ref.array" >array functions</A > section. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A > function allows unsetting keys of an array. Be aware that the array will NOT be reindexed. If you only use "usual integer indices" (starting from zero, increasing by one), you can achieve the reindex effect by using <A HREF="#function.array-values" ><B CLASS="function" >array_values()</B ></A >. <DIV CLASS="informalexample" ><A NAME="AEN3759" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = array(1 => 'one', 2 => 'two', 3 => 'three'); unset($a[2]); /* will produce an array that would have been defined as $a = array(1 => 'one', 3 => 'three'); and NOT $a = array(1 => 'one', 2 =>'three'); */ $b = array_values($a); // Now $b is array(0 => 'one', 1 =>'three') ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></BLOCKQUOTE ></DIV ><P >
The <A HREF="#control-structures.foreach" >foreach</A > control structure exists specifically for arrays. It provides an easy way to traverse an array. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.array.donts" ></A >Array do's and don'ts</H3 ><DIV CLASS="sect3" ><H4 CLASS="sect3" ><A NAME="language.types.array.foo-bar" ></A >Why is <TT CLASS="literal" >$foo[bar]</TT > wrong?</H4 ><P >
You should always use quotes around a string literal array index. For example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] wrong? You might have seen the following syntax in old scripts: <DIV CLASS="informalexample" ><A NAME="AEN3769" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo[bar] = 'enemy'; echo $foo[bar]; // etc ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > This is wrong, but it works. Then, why is it wrong? The reason is that this code has an undefined constant (bar) rather than a string ('bar' - notice the quotes), and PHP may in future define constants which, unfortunately for your code, have the same name. It works because PHP automatically converts a <SPAN CLASS="emphasis" ><I CLASS="emphasis" >bare string</I ></SPAN > (an unquoted string which does not correspond to any known symbol) into a string which contains the bare string. For instance, if there is no defined constant named <TT CLASS="constant" ><B >bar</B ></TT >, then PHP will substitute in the string <TT CLASS="literal" >'bar'</TT > and use that. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > This does not mean to <SPAN CLASS="emphasis" ><I CLASS="emphasis" >always</I ></SPAN > quote the key. You do not want to quote keys which are <A HREF="#language.constants" >constants</A > or <A HREF="#language.variables" >variables</A >, as this will prevent PHP from interpreting them. </P ><DIV CLASS="informalexample" ><A NAME="AEN3779" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php error_reporting(E_ALL); ini_set('display_errors', true); ini_set('html_errors', false); // Simple array: $array = array(1, 2); $count = count($array); for ($i = 0; $i < $count; $i++) { echo "\nChecking $i: \n"; echo "Bad: " . $array['$i'] . "\n"; echo "Good: " . $array[$i] . "\n"; echo "Bad: {$array['$i']}\n"; echo "Good: {$array[$i]}\n"; } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P ><B >Poznßmka: </B > The output from the above is: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Checking 0: Notice: Undefined index: $i in /path/to/script.html on line 9 Bad: Good: 1 Notice: Undefined index: $i in /path/to/script.html on line 11 Bad: Good: 1 Checking 1: Notice: Undefined index: $i in /path/to/script.html on line 9 Bad: Good: 2 Notice: Undefined index: $i in /path/to/script.html on line 11 Bad: Good: 2</PRE ></TD ></TR ></TABLE > </P ></BLOCKQUOTE ></DIV ><P >
More examples to demonstrate this fact: <DIV CLASS="informalexample" ><A NAME="AEN3784" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Let's show all errors error_reporting(E_ALL); $arr = array('fruit' => 'apple', 'veggie' => 'carrot'); // Correct print $arr['fruit']; // apple print $arr['veggie']; // carrot // Incorrect. This works but also throws a PHP error of // level E_NOTICE because of an undefined constant named fruit // // Notice: Use of undefined constant fruit - assumed 'fruit' in... print $arr[fruit]; // apple // Let's define a constant to demonstrate what's going on. We // will assign value 'veggie' to a constant named fruit. define('fruit', 'veggie'); // Notice the difference now print $arr['fruit']; // apple print $arr[fruit]; // carrot // The following is okay as it's inside a string. Constants are not // looked for within strings so no E_NOTICE error here print "Hello $arr[fruit]"; // Hello apple // With one exception, braces surrounding arrays within strings // allows constants to be looked for print "Hello {$arr[fruit]}"; // Hello carrot print "Hello {$arr['fruit']}"; // Hello apple // This will not work, results in a parse error such as: // Parse error: parse error, expecting T_STRING' or T_VARIABLE' or T_NUM_STRING' // This of course applies to using autoglobals in strings as well print "Hello $arr['fruit']"; print "Hello $_GET['foo']"; // Concatenation is another option print "Hello " . $arr['fruit']; // Hello apple ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
When you turn <A HREF="#function.error-reporting" ><B CLASS="function" >error_reporting()</B ></A > up to show <TT CLASS="constant" ><B >E_NOTICE</B ></TT > level errors (such as setting it to <TT CLASS="constant" ><B >E_ALL</B ></TT >) then you will see these errors. By default, <A HREF="#ini.error-reporting" >
error_reporting</A > is turned down to not show them. </P ><P >
As stated in the <A HREF="#language.types.array.syntax" >syntax</A > section, there must be an expression between the square brackets ('<TT CLASS="literal" >[</TT >' and '<TT CLASS="literal" >]</TT >'). That means that you can write things like this: <DIV CLASS="informalexample" ><A NAME="AEN3795" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo $arr[somefunc($bar)]; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > This is an example of using a function return value as the array index. PHP also knows about constants, as you may have seen the <TT CLASS="literal" >E_*</TT > ones before. <DIV CLASS="informalexample" ><A NAME="AEN3798" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $error_descriptions[E_ERROR] = "A fatal error has occured"; $error_descriptions[E_WARNING] = "PHP issued a warning"; $error_descriptions[E_NOTICE] = "This is just an informal notice"; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Note that <TT CLASS="literal" >E_ERROR</TT > is also a valid identifier, just like <TT CLASS="literal" >bar</TT > in the first example. But the last example is in fact the same as writing: <DIV CLASS="informalexample" ><A NAME="AEN3802" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $error_descriptions[1] = "A fatal error has occured"; $error_descriptions[2] = "PHP issued a warning"; $error_descriptions[8] = "This is just an informal notice"; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > because <TT CLASS="literal" >E_ERROR</TT > equals <TT CLASS="literal" >1</TT >, etc. </P ><P >
As we already explained in the above examples, <TT CLASS="literal" >$foo[bar]</TT > still works but is wrong. It works, because <TT CLASS="literal" >bar</TT > is due to its syntax expected to be a constant expression. However, in this case no constant with the name <TT CLASS="literal" >bar</TT > exists. PHP now assumes that you meant <TT CLASS="literal" >bar</TT > literally, as the string <TT CLASS="literal" >"bar"</TT >, but that you forgot to write the quotes. </P ><DIV CLASS="sect4" ><HR><H5 CLASS="sect4" ><A NAME="AEN3812" ></A >So why is it bad then?</H5 ><P >
At some point in the future, the PHP team might want to add another constant or keyword, or you may introduce another constant into your application, and then you get in trouble. For example, you already cannot use the words <TT CLASS="literal" >empty</TT > and <TT CLASS="literal" >default</TT > this way, since they are special <A HREF="#reserved" >reserved keywords</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > To reiterate, inside a double-quoted <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A >, it's valid to not surround array indexes with quotes so <TT CLASS="literal" >"$foo[bar]"</TT > is valid. See the above examples for details on why as well as the section on <A HREF="#language.types.string.parsing" >variable parsing in strings</A >. </P ></BLOCKQUOTE ></DIV ></DIV ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.array.casting" ></A >Converting to array</H3 ><P >
For any of the types: <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >, <A HREF="#language.types.float" ><B CLASS="type" >float</B ></A >, <A HREF="#language.types.string" ><B CLASS="type" >string</B ></A >, <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A > and <A HREF="#language.types.resource" ><B CLASS="type" >resource</B ></A >, if you convert a value to an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A >, you get an array with one element (with index 0), which is the scalar value you started with. </P ><P >
If you convert an <A HREF="#language.types.object" ><B CLASS="type" >object</B ></A > to an array, you get the properties (member variables) of that object as the array's elements. The keys are the member variable names. </P ><P >
If you convert a <TT CLASS="constant" ><B >NULL</B ></TT > value to an array, you get an empty array. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.array.examples" ></A >Examples</H3 ><P >
The array type in PHP is very versatile, so here will be some examples to show you the full power of arrays. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN3840" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // this $a = array( 'color' => 'red', 'taste' => 'sweet', 'shape' => 'round', 'name' => 'apple', 4 // key will be 0 ); // is completely equivalent with $a['color'] = 'red'; $a['taste'] = 'sweet'; $a['shape'] = 'round'; $a['name'] = 'apple'; $a[] = 4; // key will be 0 $b[] = 'a'; $b[] = 'b'; $b[] = 'c'; // will result in the array array(0 => 'a' , 1 => 'b' , 2 => 'c'), // or simply array('a', 'b', 'c') ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3842" ></A ><P ><B >P°φklad 6-4. Using array()</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Array as (property-)map $map = array( 'version' => 4, 'OS' => 'Linux', 'lang' => 'english', 'short_tags' => true ); // strictly numerical keys $array = array( 7, 8, 0, 156, -10 ); // this is the same as array(0 => 7, 1 => 8, ...) $switching = array( 10, // key = 0 5 => 6, 3 => 7, 'a' => 4, 11, // key = 6 (maximum of integer-indices was 5) '8' => 2, // key = 8 (integer!) '02' => 77, // key = '02' 0 => 12 // the value 10 will be overwritten by 12 ); // empty array $empty = array(); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="language.types.array.examples.loop" ></A ><P ><B >P°φklad 6-5. Collection</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $colors = array('red', 'blue', 'green', 'yellow'); foreach ($colors as $color) { echo "Do you like $color?\n"; } /* output: Do you like red? Do you like blue? Do you like green? Do you like yellow? */ ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Note that it is currently not possible to change the values of the array directly in such a loop. A workaround is the following: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="language.types.array.examples.changeloop" ></A ><P ><B >P°φklad 6-6. Collection</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php foreach ($colors as $key => $color) { // won't work: //$color = strtoupper($color); // works: $colors[$key] = strtoupper($color); } print_r($colors); /* output: Array ( [0] => RED [1] => BLUE [2] => GREEN [3] => YELLOW ) */ ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
This example creates a one-based array. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3853" ></A ><P ><B >P°φklad 6-7. One-based index</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $firstquarter = array(1 => 'January', 'February', 'March'); print_r($firstquarter); /* output: Array ( [1] => 'January' [2] => 'February' [3] => 'March' ) */ ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3856" ></A ><P ><B >P°φklad 6-8. Filling an array</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // fill an array with all items from a directory $handle = opendir('.'); while (false !== ($file = readdir($handle))) { $files[] = $file; } closedir($handle); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Arrays are ordered. You can also change the order using various sorting functions. See the <A HREF="#ref.array" >array functions</A > section for more information. You can count the number of items in an array using the <A HREF="#function.count" ><B CLASS="function" >count()</B ></A > function. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3862" ></A ><P ><B >P°φklad 6-9. Sorting an array</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php sort($files); print_r($files); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Because the value of an array can be anything, it can also be another array. This way you can make recursive and multi-dimensional arrays. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3866" ></A ><P ><B >P°φklad 6-10. Recursive and multi-dimensional arrays</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $fruits = array ( "fruits" => array ( "a" => "orange", "b" => "banana", "c" => "apple" ), "numbers" => array ( 1, 2, 3, 4, 5, 6 ), "holes" => array ( "first", 5 => "second", "third" ) ); // Some examples to address values in the array above echo $fruits["holes"][5]; // prints "second" echo $fruits["fruits"]["a"]; // prints "orange" unset($fruits["holes"][0]); // remove "first" // Create a new multi-dimensional array $juices["apple"]["green"] = "good"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
You should be aware that array assignment always involves value copying. You need to use the reference operator to copy an array by reference. <DIV CLASS="informalexample" ><A NAME="AEN3870" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $arr1 = array(2, 3); $arr2 = $arr1; $arr2[] = 4; // $arr2 is changed, // $arr1 is still array(2, 3) $arr3 = &$arr1; $arr3[] = 4; // now $arr1 and $arr3 are the same ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.object" ></A >Objects</H2 ><DIV CLASS="sect2" ><H3 CLASS="sect2" ><A NAME="language.types.object.init" ></A >Object Initialization</H3 ><P >
To initialize an object, you use the <TT CLASS="literal" >new</TT > statement to instantiate the object to a variable. <DIV CLASS="informalexample" ><A NAME="AEN3878" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class foo { function do_foo() { echo "Doing foo."; } } $bar = new foo; $bar->do_foo(); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
For a full discussion, please read the section <A HREF="#language.oop" >Classes and Objects</A >. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.object.casting" ></A >Converting to object</H3 ><P >
If an object is converted to an object, it is not modified. If a value of any other type is converted to an object, a new instance of the <TT CLASS="literal" >stdClass</TT > built in class is created. If the value was null, the new instance will be empty. For any other value, a member variable named <TT CLASS="literal" >scalar</TT > will contain the value. <DIV CLASS="informalexample" ><A NAME="AEN3887" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $obj = (object) 'ciao'; echo $obj->scalar; // outputs 'ciao' ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.resource" ></A >Resource</H2 ><P >
A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions. See the <A HREF="#resource" >appendix</A > for a listing of all these functions and the corresponding resource types. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The resource type was introduced in PHP 4 </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.resource.casting" ></A >Converting to resource</H3 ><P >
As resource types hold special handlers to opened files, database connections, image canvas areas and the like, you cannot convert any value to a resource. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.resource.self-destruct" ></A >Freeing resources</H3 ><P >
Due to the reference-counting system introduced with PHP 4's Zend-engine, it is automatically detected when a resource is no longer referred to (just like Java). When this is the case, all resources that were in use for this resource are made free by the garbage collector. For this reason, it is rarely ever necessary to free the memory manually by using some free_result function. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Persistent database links are special, they are <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > destroyed by the garbage collector. See also the section about <A HREF="#features.persistent-connections" >persistent connections</A >. </P ></BLOCKQUOTE ></DIV > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.null" ></A >NULL</H2 ><P >
The special <TT CLASS="constant" ><B >NULL</B ></TT > value represents that a variable has no value. <TT CLASS="constant" ><B >NULL</B ></TT > is the only possible value of type <A HREF="#language.types.null" ><B CLASS="type" >NULL</B ></A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The null type was introduced in PHP 4 </P ></BLOCKQUOTE ></DIV ><P >
A variable is considered to be <TT CLASS="constant" ><B >NULL</B ></TT > if <P ></P ><UL ><LI ><P >
it has been assigned the constant <TT CLASS="constant" ><B >NULL</B ></TT >. </P ></LI ><LI ><P >
it has not been set to any value yet. </P ></LI ><LI ><P >
it has been <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A >. </P ></LI ></UL > </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.null.syntax" ></A >Syntax</H3 ><P >
There is only one value of type <TT CLASS="constant" ><B >NULL</B ></TT >, and that is the case-insensitive keyword <TT CLASS="constant" ><B >NULL</B ></TT >. <DIV CLASS="informalexample" ><A NAME="AEN3929" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $var = NULL; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
See also <A HREF="#function.is-null" ><B CLASS="function" >is_null()</B ></A > and <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.pseudo-types" ></A >Pseudo-types used in this documentation</H2 ><DIV CLASS="sect2" ><H3 CLASS="sect2" ><A NAME="language.types.mixed" ></A >mixed</H3 ><P >
<TT CLASS="literal" >mixed</TT > indicates that a parameter may accept multiple (but not necessarily all) types. </P ><P >
<A HREF="#function.gettype" ><B CLASS="function" >gettype()</B ></A > for example will accept all PHP types, while <A HREF="#function.str-replace" ><B CLASS="function" >str_replace()</B ></A > will accept strings and arrays. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.number" ></A >number</H3 ><P >
<TT CLASS="literal" >number</TT > indicates that a parameter can be either <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A > or <A HREF="#language.types.float" ><B CLASS="type" >float</B ></A >. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.callback" ></A >callback</H3 ><P >
Some functions like <A HREF="#function.call-user-func" ><B CLASS="function" >call_user_func()</B ></A > or <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A > accept user defined callback functions as a parameter. Callback functions can not only be simple functions but also object methods including static class methods. </P ><P >
A PHP function is simply passed by its name as a string. You can pass any builtin or user defined function with the exception of <A HREF="#function.array" ><B CLASS="function" >array()</B ></A >, <A HREF="#function.echo" ><B CLASS="function" >echo()</B ></A >, <A HREF="#function.empty" ><B CLASS="function" >empty()</B ></A >, <A HREF="#function.eval" ><B CLASS="function" >eval()</B ></A >, <A HREF="#function.exit" ><B CLASS="function" >exit()</B ></A >, <A HREF="#function.isset" ><B CLASS="function" >isset()</B ></A >, <A HREF="#function.list" ><B CLASS="function" >list()</B ></A >, <A HREF="#function.print" ><B CLASS="function" >print()</B ></A > and <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A >. </P ><P >
A method of an instantiated object is passed as an array containing an object as the element with index 0 and a method name as the element with index 1. </P ><P >
Static class methods can also be passed without instantiating an object of that class by passing the class name instead of an object as the element with index 0. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN3967" ></A ><P ><B >P°φklad 6-11. Callback function examples </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // simple callback example function my_callback_function() { echo 'hello world!'; } call_user_func('my_callback_function'); // method callback examples class MyClass { function myCallbackMethod() { echo 'Hello World!'; } } // static class method call without instantiating an object call_user_func(array('MyClass', 'myCallbackMethod')); // object method call $obj = new MyClass(); call_user_func(array(&$obj, 'myCallbackMethod')); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.types.type-juggling" ></A >Type Juggling</H2 ><P >
PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable <TT CLASS="parameter" ><I >$var</I ></TT >, <TT CLASS="parameter" ><I >$var</I ></TT > becomes a string. If you then assign an integer value to <TT CLASS="parameter" ><I >$var</I ></TT >, it becomes an integer. </P ><P >
An example of PHP's automatic type conversion is the addition operator '+'. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated. <DIV CLASS="informalexample" ><A NAME="AEN3977" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = "0"; // $foo is string (ASCII 48) $foo += 2; // $foo is now an integer (2) $foo = $foo + 1.3; // $foo is now a float (3.3) $foo = 5 + "10 Little Piggies"; // $foo is integer (15) $foo = 5 + "10 Small Pigs"; // $foo is integer (15) ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
If the last two examples above seem odd, see <A HREF="#language.types.string.conversion" >String conversion to numbers</A >. </P ><P >
If you wish to force a variable to be evaluated as a certain type, see the section on <A HREF="#language.types.typecasting" >Type casting</A >. If you wish to change the type of a variable, see <A HREF="#function.settype" ><B CLASS="function" >settype()</B ></A >. </P ><P >
If you would like to test any of the examples in this section, you can use the <A HREF="#function.var-dump" ><B CLASS="function" >var_dump()</B ></A > function. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The behaviour of an automatic conversion to array is currently undefined. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN3989" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = "1"; // $a is a string $a[0] = "f"; // What about string offsets? What happens? ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being "f", or should "f" become the first character of the string $a? </P ><P >
The current versions of PHP interpret the second assignment as a string offset identification, so $a becomes "f", the result of this automatic conversion however should be considered undefined. PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above: <DIV CLASS="informalexample" ><A NAME="AEN3993" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = "abc"; // $a is a string $a{1} = "f"; // $a is now "afc" ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > See the section titled <A HREF="#language.types.string.substr" >String access by character</A > for more information. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.types.typecasting" ></A >Type Casting</H3 ><P >
Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast. <DIV CLASS="informalexample" ><A NAME="AEN3999" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = 10; // $foo is an integer $bar = (boolean) $foo; // $bar is a boolean ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
The casts allowed are: <P ></P ><UL ><LI ><P >(int), (integer) - cast to integer</P ></LI ><LI ><P >(bool), (boolean) - cast to boolean</P ></LI ><LI ><P >(float), (double), (real) - cast to float</P ></LI ><LI ><P >(string) - cast to string</P ></LI ><LI ><P >(array) - cast to array</P ></LI ><LI ><P >(object) - cast to object</P ></LI ></UL > </P ><P >
Note that tabs and spaces are allowed inside the parentheses, so the following are functionally equivalent: <DIV CLASS="informalexample" ><A NAME="AEN4016" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = (int) $bar; $foo = ( int ) $bar; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Instead of casting a variable to string, you can also enclose the variable in double quotes. <DIV CLASS="informalexample" ><A NAME="AEN4020" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = 10; // $foo is an integer $str = "$foo"; // $str is a string $fst = (string) $foo; // $fst is also a string // This prints out that "they are the same" if ($fst === $str) { echo "they are the same"; } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></BLOCKQUOTE ></DIV ><P >
It may not be obvious exactly what will happen when casting between certain types. For more info, see these sections: <P ></P ><UL ><LI ><P ><A HREF="#language.types.boolean.casting" >Converting to boolean</A ></P ></LI ><LI ><P ><A HREF="#language.types.integer.casting" >Converting to integer</A ></P ></LI ><LI ><P ><A HREF="#language.types.float.casting" >Converting to float</A ></P ></LI ><LI ><P ><A HREF="#language.types.string.casting" >Converting to string</A ></P ></LI ><LI ><P ><A HREF="#language.types.array.casting" >Converting to array</A ></P ></LI ><LI ><P ><A HREF="#language.types.object.casting" >Converting to object</A ></P ></LI ><LI ><P ><A HREF="#language.types.resource.casting" >Converting to resource</A ></P ></LI ><LI ><P >
<A HREF="#types.comparisons" >The type comparison tables</A > </P ></LI ></UL > </P ></DIV ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.variables" >Kapitola 7. Prom∞nnΘ</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="language.variables.basics" ></A >Zßklady</H2 ><P >
Prom∞nnΘ jsou v PHP reprezentovßny znakem dolaru, nßsledovan²m nßzvem p°φslu╣nΘ prom∞nnΘ. V nßzvech prom∞nn²ch se rozli╣uje velikost pφsmen. </P ><P >
Nßzvy prom∞nn²ch jsou pod°φzeny stejn²m pravidl∙m jako jinß nßv∞╣tφ v PHP. Platn² nßzev prom∞nnΘ zaΦφnß pφsmenem nebo podtr╛φtkem, nßsledovan²m libovoln²m poΦtem pφsmen, Φφslic nebo potr╛φtek. Jako regulßrnφ v²raz to lze zapsat takto: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Pro na╣e ·Φely zde budeme za pφsmena pova╛ovat znaky a-z, A-Z a ASCII znaky od 127 do 255 (0x7f-0xff). </P ></BLOCKQUOTE ></DIV ><P >
<DIV CLASS="informalexample" ><A NAME="AEN4057" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$var = "Bob"; $Var = "Joe"; echo "$var, $Var"; // vypφ╣e "Bob, Joe" $4site = 'not yet'; // neplatnΘ; zaΦφnß Φφslicφ $_4site = 'not yet'; // platnΘ; zaΦφnß podtr╛φtkem $tΣyte = 'mansikka'; // platnΘ; 'Σ' je ASCII 228.</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
V PHP 3 majφ prom∞nnΘ v╛dy p°i°azenu hodnotu. To znamenß, ╛e kdy╛ p°i°adφte v²raz do prom∞nnΘ, celß hodnota p∙vodnφho v²razu se zkopφruje do cφlovΘ prom∞nnΘ. Tedy, nap°φklad, po p°i°azenφ hodnoty jednΘ prom∞nnΘ do druhΘ, zm∞na jednΘ z nich se na druhΘ neprojevφ. Vφce informacφ o tomto zp∙sobu p°i°azenφ viz <A HREF="#language.expressions" >V²razy</A >. </P ><P >
PHP nabφzφ jin² zp∙sob p°i°azenφ hodnot prom∞nn²m: <SPAN CLASS="emphasis" ><I CLASS="emphasis" >p°i°azenφ odkazu</I ></SPAN >. To znamenß, ╛e novß prom∞nnß jednodu╣e odkazuje (jin²mi slovy, "stßvß se aliasem" nebo "ukazuje na") na p∙vodnφ prom∞nnou. Zm∞ny na novΘ prom∞nnΘ se projevφ na tΘ p∙vodnφ a naopak. To takΘ znamenß, ╛e se nic nekopφruje; proto je p°i°azenφ rychlej╣φ. Av╣ak toto zrychlenφ bude zjistitelnΘ pouze v t∞sn²ch cyklech nebo p°i p°i°azovßnφ velk²ch polφ Φi objekt∙. </P ><P >
Pro p°i°azenφ odkazu staΦφ jednodu╣e p°ed prom∞nnou, kterß bude p°i°azovßna (zdrojovß prom∞nnß), p°ed°adit ampersand (&). Nap°φklad nßsledujφcφ kus k≤du vypφ╣e dvakrßt 'Jmenuji se Bob': <DIV CLASS="informalexample" ><A NAME="AEN4064" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = 'Bob'; // P°i°adφ hodnotu 'Bob' do $foo $bar = &$foo; // Odkaz $foo p°es $bar. $bar = "Jmenuji se $bar"; // Zm∞na $bar... echo $bar; echo $foo; // $foo je takΘ zm∞n∞no. ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Jednou z d∙le╛it²ch v∞cφ, kterΘ je t°eba si uv∞domit, je to, ╛e p°es odkazy lze p°i°azovat pouze pojmenovanΘ prom∞nnΘ. <DIV CLASS="informalexample" ><A NAME="AEN4067" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $foo = 25; $bar = &$foo; // Toto je platnΘ p°i°azenφ. $bar = &(24 * 7); // NeplatnΘ; odkazuje se nepojmenovan² v²raz. function test() { return 25; } $bar = &test(); // NeplatnΘ. ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.variables.predefined" ></A >P°eddefinovanΘ prom∞nnΘ</H2 ><P >
PHP poskytuje velkΘ mno╛stvφ p°eddefinovan²ch prom∞nn²ch jakΘmukoli skriptu, kter² provßdφ. Mnoho t∞chto prom∞nn²ch, bohu╛el, nem∙╛e b²t pln∞ zdokumentovßno, proto╛e zßvisejφ na tom, na kterΘm serveru skript b∞╛φ, na verzi a nastavenφ serveru a dal╣φch faktorech. N∞kterΘ z t∞chto prom∞nn²ch nebudou dostupnΘ, kdy╛ PHP pob∞╛φ z p°φkazovΘ °ßdky. Seznam prom∞nn²ch - viz sekce <A HREF="#reserved.variables" >P°eddefinovanΘ prom∞nnΘ</A >. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
V PHP 4.2.0 a pozd∞j╣φch se zm∞nila implicitnφ sada p°eddefinovan²ch prom∞nn²ch, kterΘ jsou globßln∞ dostupnΘ. Individußlnφ vstupnφ a serverovΘ prom∞nnΘ se <SPAN CLASS="emphasis" ><I CLASS="emphasis" >implicitn∞</I ></SPAN > neumφs╗ujφ do globßlnφho kontextu; namφsto toho jsou v nßsledujφcφch <A HREF="#language.variables.superglobals" >superglobßlnφch polφch</A >. </P ><P >
M∙╛ete v╣ak stßle vynutit starΘ chovßnφ nastavenφm <A HREF="#ini.register-globals" >register_globals</A > v souboru <TT CLASS="filename" >php.ini</TT > na 'On'. </P ><P >
Pro vφce informacφ a pozadφ t∞chto zm∞n prosφm nahlΘdn∞te do <A HREF="http://www.php.net/release_4_1_0.php" TARGET="_top" >PHP 4.1.0 Release Announcement</A >. </P ></TD ></TR ></TABLE ></DIV ><P >
Od verze 4.1.0 poskytuje PHP sadu p°eddefinovan²ch polφ, obsahujφcφch prom∞nnΘ WWW serveru (pokud to jde), prost°edφ a u╛ivatelskΘho vstupu. Tato novß pole majφ tu zvlß╣tnost, ╛e jsou automaticky globßlnφ -- tedy nap°. automaticky dostupnΘ v ka╛dΘm kontextu. Z tohoto d∙vodu jsou Φasto znßma jako "autoglobßlnφ" nebo "superglobßlnφ". (V PHP neexistuje mechanismus pro u╛ivatelskou definici superglobßlnφch prom∞nn²ch). Superglobßlnφ prom∞nnΘ jsou vypsßny nφ╛e; pro seznam jejich obsah∙ a dal╣φ diskusi o p°eddefinovan²ch prom∞nn²ch v PHP a jejich charakteru v╣ak musφte nahlΘdnout do Φßsti <A HREF="#reserved.variables" >P°eddefinovanΘ prom∞nnΘ</A >. </P ><P ></P ><DIV CLASS="variablelist" ><P ><B >PHP superglobals (superglobßlnφ prom∞nnΘ)</B ></P ><DL ><DT ><A HREF="#reserved.variables.globals" >$GLOBALS</A ></DT ><DD ><P >
Obsahuje odkaz na ka╛dou prom∞nnou, kterß je momentßln∞ dostupnß v globßlnφm kontextu skriptu. KlφΦi tohoto pole jsou nßzvy globßlnφch prom∞nn²ch. </P ></DD ><DT ><A HREF="#reserved.variables.server" >$_SERVER</A ></DT ><DD ><P >
Prom∞nnΘ nastavovanΘ WWW serveru nebo jinak p°φmo spjatΘ s provßd∞cφm prost°edφm aktußlnφho skriptu. AnalogickΘ starΘmu poli <TT CLASS="varname" >$HTTP_SERVER_VARS</TT > (kterΘ je stßle dostupnΘ, ale zavr╛enΘ). </P ></DD ><DT ><A HREF="#reserved.variables.get" >$_GET</A ></DT ><DD ><P >
Prom∞nnΘ poskytovanΘ skriptu p°es HTTP GET. AnalogickΘ starΘmu poli <TT CLASS="varname" >$HTTP_GET_VARS</TT > (kterΘ je stßle dostupnΘ, ale zavr╛enΘ). </P ></DD ><DT ><A HREF="#reserved.variables.post" >$_POST</A ></DT ><DD ><P >
Prom∞nnΘ poskytovanΘ skriptu p°es HTTP POST. AnalogickΘ starΘmu poli <TT CLASS="varname" >$HTTP_POST_VARS</TT > (kterΘ je stßle dostupnΘ, ale zavr╛enΘ). </P ></DD ><DT ><A HREF="#reserved.variables.cookies" >$_COOKIE</A ></DT ><DD ><P >
Prom∞nnΘ poskytovanΘ skriptu p°es HTTP cookies. AnalogickΘ starΘmu poli <TT CLASS="varname" >$HTTP_COOKIE_VARS</TT > (kterΘ je stßle dostupnΘ, ale zavr╛enΘ). </P ></DD ><DT ><A HREF="#reserved.variables.files" >$_FILES</A ></DT ><DD ><P >
Prom∞nnΘ poskytovanΘ skriptu p°es HTTP post uploady soubor∙. AnalogickΘ uploads. AnalogickΘ starΘmu poli <TT CLASS="varname" >$HTTP_POST_FILES</TT > (kterΘ je stßle dostupnΘ, ale zavr╛enΘ). Vφce informacφ - viz <A HREF="#features.file-upload.post-method" >Upload metodou POST</A >. </P ></DD ><DT ><A HREF="#reserved.variables.environment" >$_ENV</A ></DT ><DD ><P >Prom∞nnΘ poskytovanΘ skriptu z prost°edφ. AnalogickΘ starΘmu poli <TT CLASS="varname" >$HTTP_ENV_VARS</TT > (kterΘ je stßle dostupnΘ, ale zavr╛enΘ). </P ></DD ><DT ><A HREF="#reserved.variables.request" >$_REQUEST</A ></DT ><DD ><P >
Prom∞nnΘ poskytovanΘ skriptu p°es libovoln² vstupnφ mechanismus a kter²m proto nelze d∙v∞°ovat. Pozn.: p°i b∞hu z p°φkazovΘ °ßdky zde <SPAN CLASS="emphasis" ><I CLASS="emphasis" >nebudou</I ></SPAN > p°φtomny polo╛ky <TT CLASS="varname" >argv</TT > a <TT CLASS="varname" >argc</TT >; nachßzejφ se v poli <TT CLASS="varname" >$_SERVER</TT >. P°φtomnost a po°adφ prom∞nn²ch v tomto poli se definuje podle konfiguraΦnφ direktivy <A HREF="#ini.variables-order" >variables_order</A >. Toto pole nemß p°φmou analogii ve verzφch PHP p°ed 4.1.0. </P ></DD ><DT ><A HREF="#reserved.variables.session" >$_SESSION</A ></DT ><DD ><P >
Prom∞nnΘ, kterΘ jsou momentßln∞ registrovßny v aktußlnφ relaci skriptu. AnalogickΘ starΘmu poli <TT CLASS="varname" >$HTTP_SESSION_VARS</TT > (kterΘ je stßle dostupnΘ, ale zavr╛enΘ). Vφce informacφ - viz <A HREF="#ref.session" >Funkce pro obsluhu sessions</A >. </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.variables.scope" ></A >Kontext ("scope") prom∞nnΘ</H2 ><P >
Kontext prom∞nnΘ je oblast, ve kterΘ je definovßna. V∞t╣ina prom∞nn²ch v PHP mß pouze jedin² kontext. Ten zahrnuje i soubory vlo╛enΘ pomocφ "include" nebo "require". Nap°φklad: </P ><DIV CLASS="informalexample" ><A NAME="AEN4148" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = 1; include "b.inc";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Zde bude prom∞nnß <TT CLASS="varname" >$a</TT > dostupnß ve vlo╛enΘm skriptu <TT CLASS="filename" >b.inc</TT >. Av╣ak uvnit° u╛ivatelsky definovan²ch funkcφ se zaklßdß jejich lokßlnφ kontext. Jakßkoli prom∞nnß pou╛itß uvnit° funkce je implicitn∞ omezena na tento mφstnφ kontext. Nap°φklad: </P ><DIV CLASS="informalexample" ><A NAME="AEN4153" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = 1; /* globßlnφ kontext */ function Test() { echo $a; /* odkaz na prom∞nnou v lokßlnφm kontextu */ } Test();</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Tento skript nevyprodukuje ╛ßdn² v²stup, proto╛e konstrukt "echo" odkazuje na lokßlnφ verzi prom∞nnΘ <TT CLASS="varname" >$a</TT >, a ta nemß v tomto kontextu p°i°azenu ╛ßdnou hodnotu. M∙╛ete si v╣imnout, ╛e to je trochu jinΘ ne╛ v jazyce C, kde jsou globßlnφ funkce automaticky dostupnΘ ve funkcφch, pokud nejsou specificky zastφn∞ny lokßlnφ definicφ. To m∙╛e zp∙sobit problΘmy tφm, ╛e Φlov∞k m∙╛e necht∞n∞ zm∞nit globßlnφ prom∞nnou. V PHP musφ b²t globßlnφ prom∞nnΘ deklarovßny uvnit° funkce jako globßlnφ, pokud se v nφ majφ pou╛φvat. P°φklad: </P ><DIV CLASS="informalexample" ><A NAME="AEN4157" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = 1; $b = 2; function Sum() { global $a, $b; $b = $a + $b; } Sum(); echo $b;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
V²╣e uveden² skript vytiskne "3". Deklaracφ <TT CLASS="varname" >$a</TT > a <TT CLASS="varname" >$b</TT > ve funkci jako globßlnφch prom∞nn²ch se dosßhne toho, ╛e p°i odkazovßnφ na prom∞nnΘ se pracuje s jejich globßlnφ verzφ. PoΦet globßlnφch prom∞nn²ch, se kter²mi lze ve funkci manipulovat, nenφ omezen. </P ><P >
Druh²m zp∙sobem, jak p°istupovat k prom∞nn²m z globßlnφho kontextu, je pou╛itφ specißlnφho pole <TT CLASS="varname" >$GLOBALS</TT >, definovanΘho v PHP. P°edchozφ p°φklad lze p°epsat: </P ><DIV CLASS="informalexample" ><A NAME="AEN4164" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = 1; $b = 2; function Sum() { $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"]; } Sum(); echo $b;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Pole <TT CLASS="varname" >$GLOBALS</TT > je asociativnφ pole s nßzvem globßlnφ prom∞nnΘ jako klφΦem a obsahem p°φslu╣nΘ prom∞nnΘ jako obsahem elementu pole. </P ><P >
Jinou d∙le╛itou vlastnostφ rozli╣ovßnφ kontext∙ prom∞nn²ch je mo╛nost pou╛φvßnφ <SPAN CLASS="emphasis" ><I CLASS="emphasis" >static</I ></SPAN > prom∞nn²ch. Statickß prom∞nnß existuje pouze v lokßlnφm kontextu funkce, ale neztrßcφ svoji hodnotu, pokud provßd∞nφ programu tento kontext opustφ. Uva╛ujme nßsledujφcφ p°φklad: </P ><DIV CLASS="informalexample" ><A NAME="AEN4170" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function Test () { $a = 0; echo $a; $a++; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Tato funkce je pon∞kud neu╛iteΦnß, nebo╗ p°i ka╛dΘm volßnφ nastavuje <TT CLASS="varname" >$a</TT > na <TT CLASS="literal" >0</TT > a tiskne "0". Konstrukt <TT CLASS="varname" >$a</TT >++, kter² inkrementuje prom∞nnou, nemß ╛ßdn² v²znam, proto╛e p°i skonΦenφ vykonßvßnφ funkce se obsah prom∞nnΘ <TT CLASS="varname" >$a</TT > ztrßcφ. Aby m∞la funkce skuteΦn² v²znam ΦφtaΦe a hodnota se neztrßcela, deklaruje se prom∞nnß <TT CLASS="varname" >$a</TT > jako statickß: </P ><DIV CLASS="informalexample" ><A NAME="AEN4178" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function Test() { static $a = 0; echo $a; $a++; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Nynφ se p°i ka╛dΘm volßnφ funkce Test() vytiskne hodnota prom∞nnΘ <TT CLASS="varname" >$a</TT > a inkrementuje se. </P ><P >
StatickΘ prom∞nnΘ takΘ poskytujφ zp∙sob, jak °e╣it rekurzφvnφ funkce. Rekurzφvnφ funkce je takovß funkce, kterß volß sama sebe. Psanφ rekurzφvnφch funkcφ je t°eba v∞novat zvlß╣tnφ pΘΦi, proto╛e m∙╛e vzniknout nekoneΦn² cyklus volßnφ. Musφte se ujistit, ╛e mßte rekurzi adekvßtn∞ ukonΦenu. Nßsledujφcφ jednoduchß funkce rekurzφvn∞ poΦφtß do 10 za pou╛itφ statickΘ prom∞nnΘ <TT CLASS="varname" >$count</TT > ke zji╣t∞nφ okam╛iku pro ukonΦenφ: </P ><DIV CLASS="informalexample" ><A NAME="AEN4184" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function Test() { static $count = 0; $count++; echo $count; if ($count < 10) { Test (); } $count--; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.variables.variable" ></A >Prom∞nnΘ s prom∞nn²mi nßzvy</H2 ><P >
N∞kdy je vhodnΘ, aby se nßzvy prom∞nn²ch mohly m∞nit, tj. aby mohly b²t dynamicky nastavovßny a pou╛φvßny. Normßlnφ prom∞nnß se nastavuje takov²mto konstruktem: </P ><DIV CLASS="informalexample" ><A NAME="AEN4189" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = "ahoj";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Prom∞nnß s prom∞nn²m nßzvem vezme hodnotu prom∞nnΘ a pou╛ije ji jako nßzev prom∞nnΘ. Ve v²╣e uvedenΘm p°φkladu, <SPAN CLASS="emphasis" ><I CLASS="emphasis" >ahoj</I ></SPAN > lze pou╛φt jako nßzev prom∞nnΘ uvedenφm dvou symbol∙ dolaru: </P ><DIV CLASS="informalexample" ><A NAME="AEN4193" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$$a = "sv∞te";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
V tΘto chvφli byly definovßny dv∞ prom∞nnΘ a byly ulo╛eny do stromu symbol∙ PHP: <TT CLASS="varname" >$a</TT > s obsahem "ahoj" a <TT CLASS="varname" >$ahoj</TT > s obsahem "sv∞te". Proto konstrukt: </P ><DIV CLASS="informalexample" ><A NAME="AEN4198" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo "$a ${$a}";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
provede p°esn∞ totΘ╛ jako: </P ><DIV CLASS="informalexample" ><A NAME="AEN4201" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo "$a $ahoj";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
tedy oba vyprodukujφ: <TT CLASS="computeroutput" >ahoj sv∞te</TT >. </P ><P >
P°i pou╛itφ prom∞nn²ch s prom∞nn²mi nßzvy s poli musφte vy°e╣it problΘm vφceznaΦnosti. Tj. kdy╛ napφ╣ete <TT CLASS="varname" >$$a[1]</TT >, parser pot°ebuje v∞d∞t, mßte-li na mysli pou╛itφ <TT CLASS="varname" >$a[1]</TT > jako prom∞nnΘ nebo chcete <TT CLASS="varname" >$$a</TT > jako prom∞nnou a potom index [1] v tΘto prom∞nnΘ. Syntaxe pro °e╣enφ tΘto vφceznaΦnosti je <TT CLASS="varname" >${$a[1]}</TT > pro prvnφ p°φpad a <TT CLASS="varname" >${$a}[1]</TT > pro druh². </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.variables.external" ></A >Promm∞nΘ zvenΦφ PHP</H2 ><DIV CLASS="sect2" ><H3 CLASS="sect2" ><A NAME="language.variables.external.form" ></A >HTML formulß°e (GET a POST)</H3 ><P >
Kdy╛ se ode╣le formulß° do PHP skriptu, jakΘkoli prom∞nnΘ z tohoto formulß°e budou automaticky dostupnΘ v tomto skriptu. Je-li zapnuta konfiguraΦnφ volba <A HREF="#ini.track-vars" >track_vars</A >, budou tyto prom∞nnΘ umφst∞ny v asociativnφch polφch <TT CLASS="varname" >$HTTP_POST_VARS</TT >, <TT CLASS="varname" >$HTTP_GET_VARS</TT >, a/nebo <TT CLASS="varname" >$HTTP_POST_FILES</TT > v zßvislosti na zdroji prom∞nn²ch. </P ><P >
Pro vφce informacφ o t∞chto prom∞nn²ch si laskav∞ p°eΦt∞te <A HREF="#language.variables.predefined" >P°eddefinovanΘ prom∞nnΘ</A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN4223" ></A ><P ><B >P°φklad 7-1. Jednoduchß prom∞nnß formulß°e</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><form action="foo.php" method="post"> Name: <input type="text" name="username"><br> <input type="submit"> </form></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Kdy╛ se v²╣e uveden² formulß° ode╣le, hodnota vstupnφho textu bude dostupnß v <TT CLASS="varname" >$HTTP_POST_VARS['username']</TT >. Je-li zapnuta konfiguraΦnφ direktiva <A HREF="#ini.register-globals" >register_globals</A >, prom∞nnß bude dostupnß i jako <TT CLASS="varname" >$username</TT > v globßlnφm kontextu. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The <A HREF="#ini.magic-quotes-gpc" >magic_quotes_gpc</A > configuration directive affects Get, Post and Cookie values. If turned on, value (It's "PHP!") will automagically become (It\'s \"PHP!\"). Escaping is needed for DB insertion. Also see <A HREF="#function.addslashes" ><B CLASS="function" >addslashes()</B ></A >, <A HREF="#function.stripslashes" ><B CLASS="function" >stripslashes()</B ></A > and <A HREF="#ini.magic-quotes-sybase" >magic_quotes_sybase</A >. </P ></BLOCKQUOTE ></DIV ><P >
PHP also understands arrays in the context of form variables (see the <A HREF="#faq.html" >related faq</A >). You may, for example, group related variables together, or use this feature to retrieve values from a multiple select input: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN4239" ></A ><P ><B >P°φklad 7-2. More complex form variables</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><form action="array.php" method="post"> Name: <input type="text" name="personal[name]"><br> Email: <input type="text" name="personal[email]"><br> Beer: <br> <select multiple name="beer[]"> <option value="warthog">Warthog <option value="guinness">Guinness <option value="stuttgarter">Stuttgarter SchwabenbrΣu </select> <input type="submit"> </form></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
In PHP 3, the array form variable usage is limited to single-dimensional arrays. In PHP 4, no such restriction applies. </P ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="language.variables.external.form.submit" ></A >IMAGE SUBMIT variable names</H4 ><P >
When submitting a form, it is possible to use an image instead of the standard submit button with a tag like:</P ><DIV CLASS="informalexample" ><A NAME="AEN4246" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><input type="image" src="image.gif" name="sub"></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
When the user clicks somewhere on the image, the accompanying form will be transmitted to the server with two additional variables, sub_x and sub_y. These contain the coordinates of the user click within the image. The experienced may note that the actual variable names sent by the browser contains a period rather than an underscore, but PHP converts the period to an underscore automatically. </P ></DIV ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.variables.external.cookies" ></A >HTTP Cookies</H3 ><P >
PHP transparently supports HTTP cookies as defined by <A HREF="http://www.netscape.com/newsref/std/cookie_spec.html" TARGET="_top" >Netscape's Spec</A >. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users. You can set cookies using the <A HREF="#function.setcookie" ><B CLASS="function" >setcookie()</B ></A > function. Cookies are part of the HTTP header, so the SetCookie function must be called before any output is sent to the browser. This is the same restriction as for the <A HREF="#function.header" ><B CLASS="function" >header()</B ></A > function. Any cookies sent to you from the client will automatically be turned into a PHP variable just like GET and POST method data.</P ><P >
If you wish to assign multiple values to a single cookie, just add <SPAN CLASS="emphasis" ><I CLASS="emphasis" >[]</I ></SPAN > to the cookie name. For example: </P ><DIV CLASS="informalexample" ><A NAME="AEN4257" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >setcookie("MyCookie[]", "Testing", time()+3600);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Note that a cookie will replace a previous cookie by the same name in your browser unless the path or domain is different. So, for a shopping cart application you may want to keep a counter and pass this along. i.e. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN4260" ></A ><P ><B >P°φklad 7-3. SetCookie Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$Count++; setcookie("Count", $Count, time()+3600); setcookie("Cart[$Count]", $item, time()+3600);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.variables.external.environment" ></A >Environment variables</H3 ><P >
PHP automatically makes environment variables available as normal PHP variables. <DIV CLASS="informalexample" ><A NAME="AEN4266" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo $HOME; /* Shows the HOME environment variable, if set. */</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Since information coming in via GET, POST and Cookie mechanisms also automatically create PHP variables, it is sometimes best to explicitly read a variable from the environment in order to make sure that you are getting the right version. The <A HREF="#function.getenv" ><B CLASS="function" >getenv()</B ></A > function can be used for this. You can also set an environment variable with the <A HREF="#function.putenv" ><B CLASS="function" >putenv()</B ></A > function. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.variables.external.dot-in-names" ></A >Dots in incoming variable names</H3 ><P >
Typically, PHP does not alter the names of variables when they are passed into a script. However, it should be noted that the dot (period, full stop) is not a valid character in a PHP variable name. For the reason, look at it: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$varname.ext; /* invalid variable name */</PRE ></TD ></TR ></TABLE > Now, what the parser sees is a variable named <TT CLASS="varname" >$varname</TT >, followed by the string concatenation operator, followed by the barestring (i.e. unquoted string which doesn't match any known key or reserved words) 'ext'. Obviously, this doesn't have the intended result. </P ><P >
For this reason, it is important to note that PHP will automatically replace any dots in incoming variable names with underscores. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="language.variables.determining-type-of" ></A >Determining variable types</H3 ><P >
Because PHP determines the types of variables and converts them (generally) as needed, it is not always obvious what type a given variable is at any one time. PHP includes several functions which find out what type a variable is. They are <A HREF="#function.gettype" ><B CLASS="function" >gettype()</B ></A >, <A HREF="#function.is-array" ><B CLASS="function" >is_array()</B ></A >, <A HREF="#function.is-float" ><B CLASS="function" >is_float()</B ></A >, <A HREF="#function.is-int" ><B CLASS="function" >is_int()</B ></A >, <A HREF="#function.is-object" ><B CLASS="function" >is_object()</B ></A >, and <A HREF="#function.is-string" ><B CLASS="function" >is_string()</B ></A >. </P ></DIV ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.constants" >Kapitola 8. Konstanty</A ></H1 ><P >
PHP definuje n∞kolik konstant a poskytuje mechanismus pro definici dal╣φch za b∞hu. Konstanty se hodn∞ podobajφ prom∞nn²m s v²jimkou dvou skuteΦnostφ: konstanty se musφ definovat pomocφ funkce <A HREF="#function.define" ><B CLASS="function" >define()</B ></A >, a nemohou pozd∞ji nab²vat jin²ch hodnot. </P ><P >
P°eddefinovanΘ konstanty (dostupnΘ v╛dy) jsou: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >__FILE__</DT ><DD ><P >
Nßzev souboru skriptu, kter² je prßv∞ Φten. Pokud je pou╛ita v souboru, kter² byl vlo╛en pomocφ "include" nebo "require", obsahuje nßzev vlo╛enΘho souboru, nikoli rodiΦovskΘho. </P ></DD ><DT >__LINE__</DT ><DD ><P >
╚φslo °ßdku ve skriptu, kter² je prßv∞ Φten. Pokud je pou╛ita v souboru vlo╛enΘho pomocφ "include" nebo "require", obsahuje pozici v rßmci tohoto souboru. </P ></DD ><DT >PHP_VERSION</DT ><DD ><P >
TextovΘ vyjßd°enφ verze b∞╛φcφho PHP parseru, nap°. '3.0.8-dev'. </P ></DD ><DT >PHP_OS</DT ><DD ><P >
Nßzev operaΦnφho systΘmu, na kterΘm PHP parser b∞╛φ, nap°. 'Linux'. </P ></DD ><DT ><TT CLASS="constant" ><B >TRUE</B ></TT ></DT ><DD ><P >
Pravdivß hodnota (logickß jedniΦka). </P ></DD ><DT ><TT CLASS="constant" ><B >FALSE</B ></TT ></DT ><DD ><P >
Nepravdivß hodnota (logickß nula). </P ></DD ><DT >E_ERROR</DT ><DD ><P >
OznaΦuje neo╣et°itelnou chybu jinou ne╛ "parse error". </P ></DD ><DT >E_WARNING</DT ><DD ><P >
OznaΦuje stav, kdy PHP vφ, ╛e je n∞co ╣patn∞, ale bude dßl pokraΦovat. Tyto stavy se dajφ o╣et°it v samotnΘm skriptu. P°φkladem by byl neplatn² "regexp" (regulßrnφ v²raz) ve funkci <A HREF="#function.ereg" ><B CLASS="function" >ereg()</B ></A >. </P ></DD ><DT >E_PARSE</DT ><DD ><P >
Chyba p°i syntaktickΘ anal²ze skriptu (chybnß syntaxe). O╣et°enφ nenφ mo╛nΘ. </P ></DD ><DT >E_NOTICE</DT ><DD ><P >
Do╣lo k n∞Φemu, co by mohlo b²t chybou. Provßd∞nφ skriptu pokraΦuje. Mezi p°φklady pat°φ textov² index pole neopat°en² uvozovkami nebo prßce s prom∞nnou, kterß je╣t∞ nebyla definovßna. </P ></DD ><DT >E_ALL</DT ><DD ><P >
V╣echny E_* konstanty shrnutΘ do jednΘ. P°i pou╛itφ s funkcφ <A HREF="#function.error-reporting" ><B CLASS="function" >error_reporting()</B ></A > zp∙sobφ hlß╣enφ ·pln∞ v╣ech problΘmu zaregistrovan²ch PHP. </P ></DD ></DL ></DIV > </P ><P >
E_* konstanty se typicky pou╛φvajφ s funkcφ <A HREF="#function.error-reporting" ><B CLASS="function" >error_reporting()</B ></A > nastavenφ hladiny hlß╣enφ chyb. Viz v╣echny tyto konstanty v <A HREF="#features.error-handling" >O╣et°enφ chyb</A >. </P ><P >
Dal╣φ konstanty m∙╛ete definovat pomocφ funkce <A HREF="#function.define" ><B CLASS="function" >define()</B ></A >. </P ><P >
V╣imn∞te si, ╛e toto jsou konstanty, ne cΘΦkovskß makra; konstanty mohou reprezentovat pouze platnß skalßrnφ data. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN4346" ></A ><P ><B >P°φklad 8-1. Definice konstant</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php define("CONSTANT", "Hello world."); echo CONSTANT; // vytiskne "Hello world." ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN4349" ></A ><P ><B >P°φklad 8-2. Pou╛itφ __FILE__ a __LINE__</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php function report_error($file, $line, $message) { echo "Do╣lo k chyb∞ v souboru $file na °ßdku $line: $message."; } report_error(__FILE__,__LINE__, "N∞co je ╣patn∞!"); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></P ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.expressions" >Kapitola 9. V²razy</A ></H1 ><P >
V²razy jsou nejd∙le╛it∞j╣φmi stavebnφmi kameny PHP. V PHP je tΘm∞° v╣e, co napφ╣ete, v²raz. Nejjednodu╣╣φ, a p°ece nejp°esn∞j╣φ definicφ v²razu je "v╣echno, co mß hodnotu". </P ><P >
Nejzßkladn∞j╣φmi formami v²raz∙ jsou konstanty a prom∞nnΘ. Kdy╛ napφ╣ete "$a = 5", p°i°azujete '5' do $a. '5' mß, pochopiteln∞, hodnotu 5, nebo jin²mi slovy, '5' je v²raz s hodnotou 5 (v tomto p°φpad∞ je '5' celoΦφselnou konstantou). </P ><P >
Po tomto p°i°azenφ budete oΦekßvat, ╛e hodnota $a bude 5, tak╛e kdybyste napsali $b = $a, oΦekßvali byste totΘ╛, jako p°i napsßnφ $b = 5. Jin²mi slovy, $a je tedy v²raz s hodnotou 5. Pokud v╣e pracuje sprßvn∞, p°esn∞ to se takΘ stane. </P ><P >
O n∞co slo╛it∞j╣φm p°φkladem v²raz∙ jsou funkce. Uva╛ujme nap°. tuto funkci: <DIV CLASS="informalexample" ><A NAME="AEN4358" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function foo () { return 5; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></P ><P >
Za p°edpokladu, ╛e jste dob°e seznßmeni s konceptem funkcφ (pokud ne, nahlΘdn∞te do kapitoly o funkcφch), byste p°edpoklßdali, ╛e napsßnφ <TT CLASS="literal" >$c = foo()</TT > je v zßsad∞ totΘ╛ jako <TT CLASS="literal" >$c = 5</TT >, a mßte pravdu. Funkce jsou v²razy s hodnotou jejich nßvratovΘ hodnoty. Funkce foo() vracφ 5, tudφ╛ hodnota v²razu 'foo()' je 5. Obvykle funkce nevracejφ konstantnφ hodnotu, n²br╛ n∞co vypoΦφtßvajφ. </P ><P >
Hodnoty v PHP samoz°ejm∞ nemusejφ b²t pouze celß Φφsla, a velmi Φasto takΘ nejsou. PHP podporuje t°i typy skalßrnφch hodnot: celoΦφselnΘ, reßlnΘ (pohyblivß °ßdovß Φßrka) a °et∞zce (skalßrnφ hodnoty jsou hodnoty, kterΘ nejde "rozbφt" na men╣φ Φßsti, narozdφl nap°. od polφ). PHP podporuje takΘ dva kompozitnφ (neskalßrnφ) typy: pole a objekty. Ka╛d² z t∞chto typ∙ hodnot m∙╛e b²t p°i°azen do prom∞nnΘ nebo vracen z funkce. </P ><P >
U╛ivatelΘ PHP/FI 2 by nem∞li pocφtit zm∞nu. Ale PHP jde ve v²razech mnohem dßle, stejn∞ jako mnoho jin²ch programovacφch jazyk∙. PHP je v²razov∞ orientovan² jazyk, ve smyslu, ╛e tΘm∞° v╣e je v²raz. Uva╛ujme p°φklad, kter²m jsme se ji╛ zab²vali, '$a = 5'. Ihned vidφme, ╛e jsou zde zahrnuty dv∞ hodnoty, celoΦφselnß konstanta '5' a hodnota $a, kterß je aktualizovßna na 5. Ale je pravda, ╛e je tu je╣t∞ jedna hodnota, je to hodnota samotnΘho p°i°azenφ. P°i°azenφ jako takovΘ ohodnocuje p°i°azovanou hodnotu, v tomto p°φpad∞ 5. V praxi to znamenß, ╛e '$a = 5', bez ohledu na to co d∞lß, je v²raz s hodnotou 5. Proto je '$b = ($a = 5)' totΘ╛ jako '$a = 5; $b = 5;' (st°ednφk oznaΦuje konec v²razu). Proto╛e p°i°ezenφ jsou parsovßna zprava doleva, m∙╛ete takΘ napsat '$b = $a = 5'. </P ><P >
Jin²m dobr²m p°φkladem orientace na v²razy je pre- a post-inkrementace a dekrementace. U╛ivatelΘ PHP/FI 2 a mnoha jin²ch jazyk∙ znajφ notaci prom∞nnß++ a prom∞nnß--. To jsou inkrementaΦnφ a dekrementaΦnφ operßtory. V PHP/FI 2 nem∞lo '$a++' ╛ßdnou hodnotu (nenφ to v²raz), a proto ne╣lo p°i°adit nebo jinak pou╛φt. PHP roz╣i°uje schopnosti p°em∞nou t∞chto konstrukcφ ve v²razy, jako v C. V PHP, stejn∞ jako v C, existujφ dva typy inkrementace - pre-inkrementace a post-inkrementace. Oba ve svΘ podstat∞ inkrementujφ prom∞nnou a efekt na tuto prom∞nnou je toto╛n². Rozdφl je v hodnot∞ inkrementaΦnφho v²razu. Pre-inkrementace, zapsanß jako '++$var', ohodnocuje v²raz inkrementovanou hodnotou (PHP inkrementuje prom∞nnou d°φve, ne╛ p°eΦte jejφ hodnotu, proto "pre-inkrementace"). Post-inkrementace, zapsanß jako '$var++', ohodnocuje v²raz p∙vodnφ hodnotou prom∞nnΘ $var, p°ed inkrementacφ (PHP inkrementuje prom∞nnou po p°eΦtenφ jejφ hodnoty, proto "post-inkrement"). </P ><P >
Velmi Φast²m typem v²raz∙ jsou v²razy porovnßvacφ. Tyto v²razy se ohodnocujφ 0 a 1 ve v²znamu <TT CLASS="constant" ><B >FALSE</B ></TT >, resp. <TT CLASS="constant" ><B >TRUE</B ></TT >. PHP podporuje > (v∞t╣φ ne╛), >= (v∞t╣φ nebo rovno), == (rovnß se), != (nerovnß se), < (men╣φ ne╛) a <= (men╣φ nebo rovno). Tyto v²razy se nejΦast∞ji pou╛φvajφ v podmφnkßch, jako je konstrukt <TT CLASS="literal" >if</TT >. </P ><P >
Poslednφm p°φkladem v²raz∙, kter²m se budeme zab²vat, je kombinacφ p°i°azenφ a operßtor∙. Ji╛ vφte, ╛e kdy╛ chcete inkrementovat $a o jedniΦku, jednodu╣e napφ╣ete '$a++' nebo '++$a'. Ale co kdy╛ chcete hodnotu zv²╣it o jinΘ Φφslo, nap°. o 3? Mohli byste napsat '$a++' vφckrßt za sebou, ale to samoz°ejm∞ nenφ efektivnφ ani pohodlnΘ. Mnohem praktiΦt∞j╣φ je napsat '$a = $a + 3'. V²raz '$a + 3' ohodnocuje hodnotu $a plus 3 a je p°i°azen zp∞t do $a, co╛ dßvß $a inkrementovanΘ o 3. V PHP, stejn∞ jako v °ad∞ jin²ch jazyk∙ (jako je C), to m∙╛ete napsat krat╣φm zp∙sobem, kter² se Φasem stane jasn∞j╣φ i rychlej╣φ k pochopenφ. P°iΦtenφ 3 k aktußlnφ hodnot∞ $a lze zapsat jako '$a += 3'. P°esn∞ to znamenß "vezmi hodnotu $a, p°iΦti k nφ 3 a p°i°a∩ zp∞t do $a". Krom∞ krat╣φho a p°ehledn∞j╣φho zßpisu je v²hodou takΘ rychlej╣φ provedenφ. Hodnota '$a += 3', jako hodnota regulΘrnφho p°i°azenφ, je p°i°azovanß hodnota. Uv∞domte si, ╛e to NEN═ 3, n²br╛ $a plus 3 (co╛ je hodnota v²razu p°i°azovanΘho do $a). Takto lze pou╛φt jak²koli binßrnφ operßtor, nap°φklad '$a -= 5' (odeΦti 5 od hodnoty $a), '$b *= 7' (vynßsob hodnotu $b Φφslem 7) apod. </P ><P >
Je tu je╣t∞ jeden v²raz, kter² se m∙╛e zdßt zvlß╣tnφ, pokud jste ho je╣t∞ nevid∞li v jin²ch jazycφch: ternßrnφ podmφn∞n² operßtor: <DIV CLASS="informalexample" ><A NAME="AEN4372" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >$prvni ? $druhy : $treti</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Pokud hodnota prvnφho podv²razu je <TT CLASS="constant" ><B >TRUE</B ></TT > (nenulovß), je ohodnocen druh² podv²raz a je v²sledkem celΘho podmφn∞nΘho v²razu. Jinak je ohodnocen t°etφ podv²raz a je pak hodotou celΘho v²razu. </P ><P >
Nßsledujφcφ p°φklad by m∞l pomoci lΘpe pochopit pre- a post-inkrementaci i v²razy obecn∞: <DIV CLASS="informalexample" ><A NAME="AEN4376" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function double($i) { return $i*2; } $b = $a = 5; /* p°i°a∩ hodnotu p∞t do prom∞nn²ch $a a $b */ $c = $a++; /* prove∩ post-inkrement, p°i°a∩ p∙vodnφ hodnotu $a (5) do $c */ $e = $d = ++$b; /* prove∩ pre-inkrement, p°i°a∩ inkrementovanou hodnotu $b (6) do $d a $e */ /* nynφ jsou hodnoty prom∞nn²ch $d a $e rovny 6 */ $f = double($d++); /* p°i°a∩ dvakrßt hodnotu $d <emphasis>p°ed</emphasis> inkrementacφ, 2*6 = 12, do $f */ $g = double(++$e); /* p°i°a∩ dvakrßt hodnotu $e <emphasis>po</emphasis> inkrementaci, 2*7 = 14 do $g */ $h = $g += 10; /* nejd°φve je $g inkrementovßno o 10 mß pak hodnotu 24. Hodnota p°i°azenφ (24) se p°i°adφ do $h a $h tφm zφskßvß takΘ hodnotu 24. */</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Na zaΦßtku kapitoly bylo °eΦeno, ╛e si popφ╣eme r∙znΘ typy konstrukt∙, a jak bylo slφbeno, v²razy mohou b²t konstrukty. V tomto p°φpad∞ majφ konstrukty formßt 'expr' ';', co╛ znamenß "v²raz nßsledovan² st°ednφkem. V konstruktu '$b=$a=5;', je $a=5 platn² v²raz, ale samo o sob∞ to nenφ konstrukt.'$b=$a=5;' je i platn² konstrukt. </P ><P >
<SPAN CLASS="emphasis" ><I CLASS="emphasis" >
Pozn. p°ekladatele: P°edchozφm odstavci (obΦas i jinde) pou╛φvßm termφn "konstrukt" pro anglickΘ slovo "statement". Tento p°eklad nenφ p°φli╣ korektnφ, ale v ΦeskΘ programßtorskΘ mluv∞ neexistuje vhodn² termφn. Kdyby n∞kdo v∞d∞l o lep╣φm, napi╣te mi, prosφm, na luk@php.net. </I ></SPAN > </P ><P >
Poslednφ v∞cφ, kterß si zaslou╛φ zmφnku, je pravdivostnφ hodnota v²raz∙. V mnoha p°φpadech, hlavn∞ podmφnkßch a cyklech, vßs nezajφmß konkrΘtnφ hodnota v²razu, n²br╛ pouze to, jestli je <TT CLASS="constant" ><B >TRUE</B ></TT > nebo <TT CLASS="constant" ><B >FALSE</B ></TT >. Konstanty <TT CLASS="constant" ><B >TRUE</B ></TT > a <TT CLASS="constant" ><B >FALSE</B ></TT > (malß/velkß pφsmena nehrajφ roli) p°edstavujφ dv∞ mo╛nΘ boolovskΘ (pravdivostnφ) hodnoty. V p°φpad∞ pot°eby je v²raz automaticky p°eveden na typ boolean. Detailn∞j╣φ informace o zp∙sobu konverze - viz <A HREF="#language.types.typecasting" >sekce o typovΘ konverzi</A >. </P ><P >
PHP poskytuje plnou a silnou implementaci v²raz∙ a ·pln∞ je zdokumentovat p°esahuje rozsah tohoto manußlu. V²╣e uvedenΘ p°φklady by vßm m∞li naznaΦit, co jsou v∙bec v²razy a jak konstruovat u╛iteΦnΘ v²razy. Ve zb²vajφcφ Φßsti manußlu budeme psßt <TT CLASS="replaceable" ><I >expr</I ></TT > jako╛to jak²koli platn² PHP v²raz. </P ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.operators" >Kapitola 10. Operßtory</A ></H1 ><P >
</P ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.arithmetic" ></A >AritmetickΘ operßtory</H2 ><P >
Vzpomφnßte si na zßkladnφ aritmetiku ze ╣koly? Tohle je ·pln∞ stejnΘ. </P ><DIV CLASS="table" ><A NAME="AEN4395" ></A ><P ><B >Tabulka 10-1. AritmetickΘ operßtory</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >P°φklad</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Nßzev</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >V²sledek</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a + $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >SΦφtßnφ</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >SouΦet $a a $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a - $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >OdΦφtßnφ</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >ROzdφl $a a $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a * $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Nßsobenφ</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >SouΦin $a a $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a / $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >D∞lenφ</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Podφl $a a $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a % $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Zbytek</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Zbytek po d∞lenφ $a a $b.</TD ></TR ></TBODY ></TABLE ></DIV ><P >
Operßtor d∞lenφ ("/") vracφ celoΦφselnou hodnotu (v²sledek celoΦφselnΘho d∞lenφ) prßv∞ tehdy, kdy╛ oba operandy jsou celß Φφsla (nebo °et∞zce, kterΘ se dajφ p°evΘst na celß Φφsla) a podφl je celΘ Φφslo. Pokud n∞kter² z operand∙ celoΦφseln² nenφ nebo v²sledek nenφ celΘ Φφslo, vrßtφ se hodnota v plovoucφ °ßdovΘ Φßrce (float). </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.assignment" ></A >Operßtory p°i°azenφ</H2 ><P >
Zßkladnφm p°i°azovacφm operßtorem je "=". Mohli byste si zprvu myslet, ╛e se jednß o "rovnß se". Nikoliv. SkuteΦn∞ to znamenß, ╛e se levΘmu operandu p°i°adφ hodnota v²razu vpravo (tj. "nastav na", "p°i°a∩ do" atd.). </P ><P >
Hodnotou v²razu p°i°azenφ je hodnota, kterß se p°i°azuje. Tj. hodnotou "$a = 3" je Φφslo 3. To vßm umo╛≥uje provßd∞t r∙znΘ triky: <DIV CLASS="informalexample" ><A NAME="AEN4429" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = ($b = 4) + 5; // $a se ted rovnß 9, a $b bylo nastaveno na 4.</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Krom∞ zßkladnφho operßtoru p°i°azenφ existujφ je╣t∞ "kombinovanΘ operßtory" pro v╣echny binßrnφ aritmetickΘ a °et∞zovΘ operßtory, kterΘ umo╛≥ujφ pou╛φt hodnotu ve v²razu a pak hodnotu tohoto v²razu p°i°adit zp∞t. Nap°φklad: <DIV CLASS="informalexample" ><A NAME="AEN4432" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = 3; $a += 5; // nastavφ $a na hodnotu 8, jako kdybychom °ekli: $a = $a + 5; $b = "Ahoj "; $b .= "tam!"; // nastavφ $b na "Ahoj tam!", p°esn∞ tak, jako $b = $b . "tam!";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Uv∞domte si, ╛e p°i°azenφ zkopφruje hodnotu p∙vodnφ prom∞nnΘ do novΘ prom∞nnΘ (p°i°azenφ hodnoty), tak╛e zm∞ny jednΘ z nich se na druhΘ prom∞nnΘ neprojevφ. To m∙╛e mφt v²znam takΘ tehdy, kdy╛ pot°ebujete zkopφrovat n∞co jako obrovskΘ pole uvnit° krßtkΘho cyklu. PHP 4 podporuje p°i°azenφ odkazem pou╛itφm syntaxe <TT CLASS="computeroutput" >$var = &$othervar;</TT >, ale v PHP 3 to provΘst nelze. "P°i°azenφ odkazem" znamenß, ╛e ob∞ prom∞nnΘ ukazujφ na tatß╛ data a nic se nikam nekopφruje. Chcete-li se o odkazech dozv∞d∞t vφce, Φt∞te prosφm <A HREF="#language.references" >Vysv∞tlenφ referencφ</A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.bitwise" ></A >BitovΘ operßtory</H2 ><P >
BitovΘ operßtory umo╛≥ujφ "p°ehodit" konkrΘtnφ bit v celoΦφselnΘ hodnot∞ (integer) na jedniΦku nebo nulu. Pokud jsou jak lev², tak prav² parametr °et∞zce, pracujφ bitovΘ operßtory na znacφch v t∞chto °etezcφch. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN4441" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php echo 12 ^ 9; // Vypφ╣e '5' echo "12" ^ "9"; // Vypφ╣e znak Backspace (ascii 8) // ('1' (ascii 49)) ^ ('9' (ascii 57)) = #8 echo "hallo" ^ "hello"; // Vypφ╣e ascii hodnoty #0 #4 #0 #0 #0 // 'a' ^ 'e' = #4 ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="table" ><A NAME="AEN4443" ></A ><P ><B >Tabulka 10-2. BitovΘ operßtory</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >P°φklad</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Nßzev</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >V²sledek</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a & $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >And (log. souΦin)</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Nastavujφ se bity, kde je jedniΦka v $a i v $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a | $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Or(log. souΦet)</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Nastavujφ se bity, kde je jedniΦka v $a nebo v $b (i v obou souΦasn∞).</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a ^ $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Xor (exkluzφvnφ log. souΦet)</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Nastavujφ se bity, kde je jedniΦka v $a nebo v $b, ale ne v obou souΦasn∞. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >~ $a</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Not (negace)</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Tam, kde je nula, bude jedniΦka, a naopak. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a << $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Posun vlevo</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Posune bity v $a o $b krok∙ (mφst) vlevo (ka╛d² krok znamenß "nßsobenφ dv∞ma"). </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a >> $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Posun vpravo</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Posune bity v $a o $b krok∙ (mφst) vpravo (ka╛d² krok znamenß "d∞lenφ dv∞ma"). </TD ></TR ></TBODY ></TABLE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.comparison" ></A >Operßtory porovnßnφ</H2 ><P >
Operßtory porovnßnφ, jak nßzev napovφdß, slou╛φ k porovnßnφ dvou hodnot. </P ><DIV CLASS="table" ><A NAME="AEN4479" ></A ><P ><B >Tabulka 10-3. Operßtory porovnßnφ</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >P°φklad</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Nßzev</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >V²sledek</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a == $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Rovnost</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT >, prßv∞ kdy╛ je $a rovno $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a === $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Identita</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
<TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ je $a rovno $b a navφc tΘto╛ typu (pouze PHP 4). </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a != $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Nerovnost</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > prßv∞ kdy╛ $a nenφ rovno $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a <> $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Nerovnost</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > prßv∞ kdy╛ $a nenφ rovno $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a !== $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Neidentita</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
<TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ $a nenφ rovno $b nebo nejsou tΘho╛ typu (pouze PHP 4). </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a < $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Men╣φ ne╛</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ je $a ost°e men╣φ ne╛ $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a > $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >V∞t╣φ ne╛</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ je $a ost°e v∞t╣φ ne╛ $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a <= $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Men╣φ nebo rovno</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ je $a men╣φ nebo rovno $b.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a >= $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >V∞t╣φ nebo rovno</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ je $a v∞t╣φ nebo rovno $b.</TD ></TR ></TBODY ></TABLE ></DIV ><P >
Jin²m podmφnkov²m operßtorem je "?:" (ternßrnφ) operßtor, kter² funguje stejn∞ jako v C a mnoh²ch jin²ch jazycφch. <DIV CLASS="informalexample" ><A NAME="AEN4534" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >(expr1) ? (expr2) : (expr3);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > V²raz je ohodnocen jako hodnota <TT CLASS="replaceable" ><I >expr2</I ></TT > kdy╛ mß <TT CLASS="replaceable" ><I >expr1</I ></TT > hodnotu <TT CLASS="constant" ><B >TRUE</B ></TT >, a <TT CLASS="replaceable" ><I >expr3</I ></TT > kdy╛ mß <TT CLASS="replaceable" ><I >expr1</I ></TT > hodnotu <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.errorcontrol" ></A >Operßtory °φzenφ chyb</H2 ><P >
PHP podporuje jeden operßtor °φzenφ chyb: znak at (@). Kdy╛ ho p°ed°adφte v²razu v PHP, jakΘkoli chybovΘ zprßvy, kterΘ se mohou generovat ve v²razu, budou ignorovßny. </P ><P >
Pokud je zapnuto<A HREF="#ini.track-errors" >track_errors</A >, budou se v╣echny chybovΘ zprßvy generovanΘ v²razem uklßdat do globßlnφ prom∞nnΘ $php_errormsg. Tato prom∞nnß bude p°epsßna p°i ka╛dΘ chyb∞, tak╛e ji testujte v╛dy co nejd°φve, pokud ji chcete pou╛φvat. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN4548" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php /* Intentional file error */ $my_file = @file ('non_existent_file') or die ("Failed opening file: error was '$php_errormsg'"); // this works for any expression, not just functions: $value = @$cache[$key]; // will not issue a notice if the index $key doesn't exist. ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Operßtor @ pracuje pouze na v²razech. Platφ jednoduchΘ pravidlo: m∙╛ete-li zφskat hodnotu n∞Φeho, m∙╛ete p°ed to dßt operßtor @. To se t²kß nap°φklad prom∞nn²ch, funkcφ, volßnφ <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > konstant a podobn∞. Nem∙╛ete ho p°ed°adit definicφm funkcφ nebo t°φd a podmφnkov²m strukturßm typu <TT CLASS="literal" >if</TT > nebo <TT CLASS="literal" >foreach</TT >. </P ></BLOCKQUOTE ></DIV ><P >
Viz takΘ <A HREF="#function.error-reporting" ><B CLASS="function" >error_reporting()</B ></A >. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
V souΦasnosti p°ed°azenφ operßtoru °φzenφ chyb "@" vy°adφ i hlß╣enφ kritick²ch chyb, kterΘ zp∙sobφ ukonΦenφ provßd∞nφ skriptu. To mj. znamenß, ╛e pokud pou╛ijete "@" k potlaΦenφ chyb z n∞jakΘ funkce, a tato funkce nenφ k dispozici nebo obsahuje chyby, skript zde skonΦφ bez jakΘkoli indikace, co se stalo. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.execution" ></A >Provßd∞cφ operßtory</H2 ><P >
PHP podporuje jeden provßd∞cφ operßtor: obrßcenΘ apostrofy (``). Uv∞domte si, ╛e to nejsou obyΦejnΘ apostrofy! PHP se pokusφ provΘst obsah uzav°en² mezi t∞mito znaky jako p°φkaz shellu; v²stup je vrßcen (tzn. nebude pouze vypsßn na v²stup∙ m∙╛e b²t p°i°azen prom∞nnΘ). <DIV CLASS="informalexample" ><A NAME="AEN4562" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$output = `ls -al`; echo "<pre>$output</pre>";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Operßtor m∙╛e b²t vy°azen, pokud je aktivnφ <A HREF="#ini.safe-mode" >bezpeΦn² re╛im</A > nebo je vypnuto <A HREF="#function.shell-exec" ><B CLASS="function" >shell_exec()</B ></A >. </P ></BLOCKQUOTE ></DIV ><P >
Viz takΘ <A HREF="#function.escapeshellcmd" ><B CLASS="function" >escapeshellcmd()</B ></A >, <A HREF="#function.exec" ><B CLASS="function" >exec()</B ></A >, <A HREF="#function.passthru" ><B CLASS="function" >passthru()</B ></A >, <A HREF="#function.popen" ><B CLASS="function" >popen()</B ></A >, <A HREF="#function.shell-exec" ><B CLASS="function" >shell_exec()</B ></A >, a <A HREF="#function.system" ><B CLASS="function" >system()</B ></A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.increment" ></A >InkrementaΦnφ/DekrementaΦnφ operßtory</H2 ><P >
PHP podporuje pre- a post inkrementaΦnφ a dekrementaΦnφ operßtory ve stylu C. </P ><DIV CLASS="table" ><A NAME="AEN4578" ></A ><P ><B >Tabulka 10-4. InkrementaΦnφ/dekrementaΦnφ operßtory</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >P°φklad</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Nßzev</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >┌Φinek</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >++$a</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Pre-inkrementace</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Inkrementuje $a o jedniΦku, potom vrßtφ $a.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a++</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Post-inkrementace</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Vrßtφ $a, potom inkrementuje $a o jedniΦku.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >--$a</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Pre-dekrementace</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Dekrementuje $a o jedniΦku, potom vrßtφ $a.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a--</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Post-dekrementace</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Vrßtφ $a, potom dkrementuje $a o jedniΦku.</TD ></TR ></TBODY ></TABLE ></DIV ><P >
Zde je p°φklad jednoduchΘho skriptu: <DIV CLASS="informalexample" ><A NAME="AEN4604" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php echo "<h3>Postinkrementace</h3>"; $a = 5; echo "M∞lo by b²t 5: " . $a++ . "<br>\n"; echo "M∞lo by b²t 6: " . $a . "<br>\n"; echo "<h3>Preinkrementace</h3>"; $a = 5; echo "M∞lo by b²t 6: " . ++$a . "<br>\n"; echo "M∞lo by b²t 6: " . $a . "<br>\n"; echo "<h3>Postdekrementace</h3>"; $a = 5; echo "M∞lo by b²t 5: " . $a-- . "<br>\n"; echo "M∞lo by b²t: " . $a . "<br>\n"; echo "<h3>Predekrementace</h3>"; $a = 5; echo "M∞lo by b²t 4: " . --$a . "<br>\n"; echo "M∞lo by b²t 4: " . $a . "<br>\n"; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.logical" ></A >LogickΘ operßtory</H2 ><DIV CLASS="table" ><A NAME="AEN4608" ></A ><P ><B >Tabulka 10-5. LogickΘ operßtory</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >P°φklad</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Nßzev</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >V²sledek</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a and $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >And</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ $a i $b jsou <TT CLASS="constant" ><B >TRUE</B ></TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a or $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Or</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ $a nebo $b je <TT CLASS="constant" ><B >TRUE</B ></TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a xor $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Xor</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ $a nebo $b je <TT CLASS="constant" ><B >TRUE</B ></TT >, ale ne oba souΦasn∞.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >! $a</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Not</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ $a nenφ <TT CLASS="constant" ><B >TRUE</B ></TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a && $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >And</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ $a i $b jsou <TT CLASS="constant" ><B >TRUE</B ></TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >$a || $b</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Or</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><TT CLASS="constant" ><B >TRUE</B ></TT > kdy╛ $a nebo $b je <TT CLASS="constant" ><B >TRUE</B ></TT >.</TD ></TR ></TBODY ></TABLE ></DIV ><P >
D∙vodem pro dv∞ r∙znΘ varianty operßtor∙ "and" a "or" je to, ╛e majφ jinou prioritu. (Viz <A HREF="#language.operators.precedence" >Priorita operßtor∙</A >.) </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.precedence" ></A >Priorita operßtor∙</H2 ><P >
Priorita operßtoru specifikuje, jak "t∞sn∞" vß╛e dva v²razy mezi sebou. Nap°φklad v²raz <TT CLASS="literal" >1 + 5 * 3</TT >, v²sledkem je <TT CLASS="literal" >16</TT > a nikoli <TT CLASS="literal" >18</TT >, proto╛e operßtor nßsobenφ ("*") mß vy╣╣φ prioritu ne╛ operßtor sΦφtßnφ ("+"). K vynucenφ priority m∙╛eme v p°φpad∞ pot°eby pou╛φt zßvorky. Kup°. <TT CLASS="literal" >(1 + 5) * 3</TT > mß hodnotu <TT CLASS="literal" >18</TT >. </P ><P >
Nßsledujφcφ tabulka ukazuje p°ehled operßtor∙ vzestupn∞ se°azen²ch podle priority. <DIV CLASS="table" ><A NAME="AEN4664" ></A ><P ><B >Tabulka 10-6. Priorita operßtor∙</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Asociativita</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Operßtory</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >,</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >or</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >xor</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >and</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pravß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >print</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
= += -= *= /= .= %= &= |= ^= ~= <<= >>= </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >? :</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >||</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >&&</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >|</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >^</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >&</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >bez asociativity</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >== != === !==</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >bez asociativity</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >< <= > >=</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><< >></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >+ - .</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >levß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >* / %</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pravß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >! ~ ++ -- (int) (double) (string) (array) (object) @</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pravß</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >[</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >bez asociativity</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >new</TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.operators.string" ></A >╪et∞zcovΘ operßtory</H2 ><P >
Existujφ dva °etezcovΘ operßtory. Jednφm je operßtor spojenφ ('.'), kter² vracφ spojenφ pravΘho a levΘho argumentu. Druh²m je operßtor spojujφcφho p°i°azenφ ('.='), jen╛ p°ipojφ argument na pravΘ stran∞ k argumentu na stran∞ levΘ. Pro vφce informacφ si laskav∞ p°eΦt∞te <A HREF="#language.operators.assignment" >Operßtory p°i°azenφ</A >. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN4737" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = "Ahoj "; $b = $a . "sv∞te!"; // nynφ $b obsahuje "Ahoj sv∞te!" $a = "Ahoj "; $a .= "sv∞te!"; // nynφ $a obsahuje "Ahoj sv∞te!"</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="control-structures" >Kapitola 11. ╪φdicφ struktury</A ></H1 ><P >
Jak²koli PHP skript je slo╛en ze sΘrie konstrukt∙. Konstrukt m∙╛e b²t p°i°azenφ, volßnφ funkce, cyklus, podmφnka, stejn∞ jako konstrukt, kter² nic ned∞lß (prßzdn² konstrukt). Konstrukt obvykle konΦφ st°ednφkem. Navφc lze konstrukty seskupit do skupiny (bloku) uzav°enΘ slo╛en²mi zßvorkami. Tento blok je sßm o sob∞ konstruktem. V tΘto kapitole jsou popsßny r∙znΘ typy konstrukt∙. </P ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.if" ></A ><TT CLASS="literal" >if</TT ></H2 ><P >
Konstrukt <TT CLASS="literal" >if</TT > je jednφm z nejd∙le╛it∞j╣φch prvk∙ v mnoha jazycφch, vΦetn∞ PHP. Umo╛≥uje podmφn∞nΘ provßd∞nφ kusu k≤du. Struktura <TT CLASS="literal" >if</TT > v PHP je podobnß struktu°e v C: <DIV CLASS="informalexample" ><A NAME="AEN4748" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >if (expr) statement</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Jak je popsßno v <A HREF="#language.expressions" >sekci o v²razech</A >, v²raz <TT CLASS="replaceable" ><I >expr</I ></TT > je ohodnoce svou boolovskou hodnotou. Poku je <TT CLASS="replaceable" ><I >expr</I ></TT > ohodnocen jako <TT CLASS="constant" ><B >TRUE</B ></TT >, PHP provede <TT CLASS="replaceable" ><I >statement</I ></TT >; je-li ohodnocen jako <TT CLASS="constant" ><B >FALSE</B ></TT >, neprovede se nic. Vφce informacφ o to, jak se v²razy ohodnocujφ jako <TT CLASS="constant" ><B >FALSE</B ></TT > najdete v Φßsti <A HREF="#language.types.boolean.casting" >'Konverze na typ boolean'</A >. </P ><P >
Nßsledujφcφ p°φklad by vypsal <TT CLASS="computeroutput" >a je v∞t╣φ ne╛ b</TT >, pokud <TT CLASS="replaceable" ><I >$a</I ></TT > je v∞t╣φ ne╛ <TT CLASS="replaceable" ><I >$b</I ></TT >: <DIV CLASS="informalexample" ><A NAME="AEN4763" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >if ($a > $b) print "a je v∞t╣φ ne╛ b";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
╚asto byste cht∞li, aby se podmφn∞n∞ provßd∞l vφce ne╛ jeden konstrukt. Nenφ samoz°ejm∞ nutnΘ ka╛d² konstrukt zabalit do struktury <TT CLASS="literal" >if</TT >. Mφsto toho m∙╛ete seskupit vφce konstrukt∙ do bloku. Nap°φklad tento k≤d by zobrazil <TT CLASS="computeroutput" >a je v∞t╣φ ne╛ b</TT >, pokud <TT CLASS="replaceable" ><I >$a</I ></TT > je v∞t╣φ ne╛ <TT CLASS="replaceable" ><I >$b</I ></TT > a p°i°adil by hodnotu <TT CLASS="replaceable" ><I >$a</I ></TT > do <TT CLASS="replaceable" ><I >$b</I ></TT >: <DIV CLASS="informalexample" ><A NAME="AEN4772" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >if ($a > $b) { print "a je v∞t╣φ ne╛ b"; $b = $a; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Konstrukty <TT CLASS="literal" >if</TT > mohou b²t libovoln∞ vno°ovßny do jin²ch konstrukt∙ <TT CLASS="literal" >if</TT >, co╛ poskytuje plnou flexibilitu podmφn∞nΘho provßd∞nφ r∙zn²ch Φßstφ programu. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.else" ></A ><TT CLASS="literal" >else</TT ></H2 ><P >
╚asto takΘ m∙╛ete chtφt n∞co provßd∞t, pokud je jistß podmφnka spln∞na, a n∞co jinΘho, kdy╛ spln∞na nenφ. To umo╛≥uje konstrukt <TT CLASS="literal" >else</TT >. <TT CLASS="literal" >else</TT > roz╣i°uje konstrukt <TT CLASS="literal" >if</TT > o provßd∞nφ k≤du v p°φpad∞, ╛e v²raz v konstruktu <TT CLASS="literal" >if</TT > je ohodnocen jako <TT CLASS="constant" ><B >FALSE</B ></TT >. Nap°φklad nßsledujφcφ k≤d vypφ╣e <TT CLASS="computeroutput" >a je v∞t╣φ ne╛ b</TT >, pokud <TT CLASS="replaceable" ><I >$a</I ></TT > je v∞t╣φ ne╛ <TT CLASS="replaceable" ><I >$b</I ></TT >, a <TT CLASS="computeroutput" >a NEN═ v∞t╣φ ne╛ b</TT > v ostatnφch p°φpadech: <DIV CLASS="informalexample" ><A NAME="AEN4790" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >if ($a > $b) { print "a je v∞t╣φ ne╛ b"; } else { print "a NEN═ v∞t╣φ ne╛ b"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Konstrukt v <TT CLASS="literal" >else</TT > se provßdφ, pouze pokud je v²raz v <TT CLASS="literal" >if</TT > ohodnocen jako <TT CLASS="constant" ><B >FALSE</B ></TT >, a pokud by zde byly n∞jakΘ v²razy <TT CLASS="literal" >elseif</TT > - pouze pokud by byly takΘ ohodnoceny jako <TT CLASS="constant" ><B >FALSE</B ></TT > (viz <A HREF="#control-structures.elseif" >elseif</A >). </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.elseif" ></A ><TT CLASS="literal" >elseif</TT ></H2 ><P >
Jak nßzev napovφdß, <TT CLASS="literal" >elseif</TT >, je kombinacφ <TT CLASS="literal" >if</TT > a <TT CLASS="literal" >else</TT >. Stejn∞ jako <TT CLASS="literal" >else</TT >, roz╣i°uje konstrukt <TT CLASS="literal" >if</TT > k provßd∞nφ odli╣n²ch konstrukt∙ v p°φpad∞, ╛e jev²raz p∙vodnφho konstruktu <TT CLASS="literal" >if</TT > ohodnocen jako <TT CLASS="constant" ><B >FALSE</B ></TT >. Tedy, narozdφl od <TT CLASS="literal" >else</TT >, se provßdφ pouze tehdy, je-li v²raz v podmφnce <TT CLASS="literal" >elseif</TT > ohodnocen jako <TT CLASS="constant" ><B >TRUE</B ></TT >. Nap°φklad nßsledujφcφ k≤d vypφ╣e <TT CLASS="computeroutput" >a je v∞t╣φ ne╛ b</TT >, <TT CLASS="computeroutput" >a se rovnß b</TT > nebo <TT CLASS="computeroutput" >a je men╣φ ne╛ b</TT >: <DIV CLASS="informalexample" ><A NAME="AEN4815" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >if ($a > $b) { print "a je v∞t╣φ ne╛ b"; } elseif ($a == $b) { print "a se rovnß b"; } else { print "a je men╣φ ne╛ b"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
V rßmci jednoho konstruktu <TT CLASS="literal" >if</TT > m∙╛e b²t vφce konstrukt∙ <TT CLASS="literal" >elseif</TT >. Provßdφ se prvnφ konstrukt <TT CLASS="literal" >elseif</TT > (pokud v∙bec n∞jak²), jeho╛ v²raz je ohodnocen <TT CLASS="constant" ><B >TRUE</B ></TT >. V PHP m∙╛ete napsat i 'else if' (dv∞ma slovy), chovßnφ bude naprosto toto╛nΘ jako u 'elseif' (jednφm slovem). Syntaktick² v²znam je mφrn∞ odli╣n² (znßte-li C, je to stejnΘ), av╣ak ve v²sledku dostaneme p°esn∞ toto╛nΘ chovßnφ. </P ><P >
Konstrukt <TT CLASS="literal" >elseif</TT > se provßdφ, pouze jsou-li p°φslu╣n² (bezprost°edn∞ p°edchßzejφcφ) v²raz konstruktu <TT CLASS="literal" >if</TT > a v²razy v╣ech p°φslu╣n²ch p°edchßzejφcφch konstrukt∙ <TT CLASS="literal" >elseif</TT > ohodnoceny jako <TT CLASS="constant" ><B >FALSE</B ></TT >, a konkrΘtnφ v²raz v <TT CLASS="literal" >elseif</TT > ohodnocen jako <TT CLASS="constant" ><B >TRUE</B ></TT >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.alternative-syntax" ></A >Alternativnφ syntaxe °φdicφch struktur</H2 ><P >
PHP nabφzφ alternativnφ syntaxi pro n∞kterΘ z °φdicφch struktur, jmenovit∞ <TT CLASS="literal" >if</TT >, <TT CLASS="literal" >while</TT >, <TT CLASS="literal" >for</TT >, <TT CLASS="literal" >foreach</TT >, a <TT CLASS="literal" >switch</TT >. V ka╛dΘm z t∞chto p°φpad∙ je zßkladnφm formßtem alternativnφ syntaxe zßm∞na otvφracφ zßvorky za dvojteΦku (:) a uzavφracφ zßvorky za <TT CLASS="literal" >endif;</TT >, <TT CLASS="literal" >endwhile;</TT >, <TT CLASS="literal" >endfor;</TT >, <TT CLASS="literal" >endforeach;</TT >, resp. <TT CLASS="literal" >endswitch;</TT >. <DIV CLASS="informalexample" ><A NAME="AEN4842" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php if ($a == 5): ?> A se rovnß 5 <?php endif; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Ve v²╣e uvedenΘm p°φkladu je HTML blok vno°en do konstruktu <TT CLASS="literal" >if</TT > napsanΘm alternativnφ syntaxφ. Tento HTML blok by se zobrazil pouze v p°φpad∞, ╛e je $a rovno 5. </P ><P >
Alternativnφ syntaxi lze pou╛φt i pro <TT CLASS="literal" >else</TT > a <TT CLASS="literal" >elseif</TT >. Nßsledujφcφ p°φklad ukazuje strukturu <TT CLASS="literal" >if</TT >, <TT CLASS="literal" >elseif</TT > a <TT CLASS="literal" >else</TT > v alternativnφm formßtu: <DIV CLASS="informalexample" ><A NAME="AEN4852" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >if ($a == 5): print "a se rovnß 5"; print "..."; elseif ($a == 6): print "a se rovnß 6"; print "!!!"; else: print "a nenφ ani 5, ani 6"; endif;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Dal╣φ p°φklady - viz takΘ <A HREF="#control-structures.while" >while</A >, <A HREF="#control-structures.for" >for</A >, a <A HREF="#control-structures.if" >if</A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.while" ></A ><TT CLASS="literal" >while</TT ></H2 ><P >
Cykly <TT CLASS="literal" >while</TT > jsou nejjednodu╣╣φm typem cykl∙ v PHP. Chovajφ se jako jejich prot∞j╣ci v C. Zßkladφ formßt konstruktu <TT CLASS="literal" >while</TT > je tento: <DIV CLASS="informalexample" ><A NAME="AEN4864" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >while (expr) statement</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
V²znam konstruktu <TT CLASS="literal" >while</TT > je snadno pochopiteln². ╪φkß PHP, ╛e mß provßd∞t vno°en²(Θ) konstrukt(y) tak dlouho, dokud je v²raz ve <TT CLASS="literal" >while</TT > roven <TT CLASS="constant" ><B >TRUE</B ></TT >. Hodnota v²razu je testovßna poka╛dΘ na zaΦßtku cyklu (v ka╛dΘ iteraci), tak╛e i kdy╛ se tato hodnota b∞hem provßd∞nφ vno°en²ch konstrukt∙ zm∞nφ, provede se zbytek k≤du uvnit° cyklu - v konkrΘtnφ iteraci - a╛ do konce (ka╛dΘ provedenφ k≤du uvnit° cyklu je jedna iterace). N∞kdy, kdy╛ je v²raz ve <TT CLASS="literal" >while</TT > ohodnocen jako <TT CLASS="constant" ><B >FALSE</B ></TT > ji╛ p°i vstupu do cyklu, vno°en² k≤d se neprovede v∙bec. </P ><P >
Podobn∞, jako v p°φpad∞ <TT CLASS="literal" >if</TT >, m∙╛ete i zde seskupovat konstrukty uvnit° cyklu <TT CLASS="literal" >while</TT > ohraniΦenφm tohoto k≤du slo╛en²mi zßvorkami nebo za pou╛itφ alternativnφ syntaxe: <DIV CLASS="informalexample" ><A NAME="AEN4875" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >while (expr): statement ... endwhile;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Nßsledujφcφ p°φklady jsou identickΘ, oba vypφ╣φ Φφsla od 1 do 10: <DIV CLASS="informalexample" ><A NAME="AEN4878" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >/* p°φklad 1 */ $i = 1; while ($i <= 10) { print $i++; /* vyti╣t∞nß hodnota by byla rovna $i p°ed inkrementacφ (post-inkrementace) */ } /* p°φklad 2 */ $i = 1; while ($i <= 10): print $i; $i++; endwhile;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.do.while" ></A ><TT CLASS="literal" >do..while</TT ></H2 ><P >
Cykly <TT CLASS="literal" >do..while</TT > jsou velmi podobnΘ cykl∙m <TT CLASS="literal" >while</TT > krom∞ toho, ╛e pravdivost v²razu se testuje na konci ka╛dΘ iterace namφsto jejφho zaΦßtku. Hlavnφ rozdφl oproti b∞╛n²m cykl∙m <TT CLASS="literal" >while</TT > je ten, ╛e prvnφ iterace cyklu <TT CLASS="literal" >do..while</TT > se provede v╛dy (pravdivostnφ v²raz je testovßn a╛ na konci iterace), co╛ u cyklu <TT CLASS="literal" >while</TT > nenφ zaruΦeno (pravdivostnφ v²raz je testovßn na zaΦßtku iterace; pokud je ohodnocen jako <TT CLASS="constant" ><B >FALSE</B ></TT >, provßd∞nφ cyklu hned skonΦφ). </P ><P >
Toto je jedinß syntaxe pro cykly <TT CLASS="literal" >do..while</TT >: <DIV CLASS="informalexample" ><A NAME="AEN4892" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$i = 0; do { print $i; } while ($i>0);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
V²╣e uveden² cyklus by se provedl prßv∞ jednou, proto╛e po prvnφ iteraci, kdy╛ se testuje pravdivostnφ v²raz, je tento ohodnocen jako <TT CLASS="constant" ><B >FALSE</B ></TT > ($i nenφ v∞t╣φ ne╛ 0) a provßd∞nφ cyklu konΦφ. </P ><P >
PokroΦilφ programßto°i v C mohou znßt i odli╣nΘ pou╛itφ cyklu <TT CLASS="literal" >do..while</TT >. K≤d se uzav°e do <TT CLASS="literal" >do..while</TT >(0) a pou╛ije se p°φkaz <A HREF="#control-structures.break" ><TT CLASS="literal" >break</TT ></A >. To umo╛≥uje p°eru╣it provßd∞nφ cyklu uprost°ed k≤du, jak je znßzorn∞no v tomto p°φkladu: <DIV CLASS="informalexample" ><A NAME="AEN4901" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >do { if ($i < 5) { print "i nenφ dost velkΘ"; break; } $i *= $factor; if ($i < $minimum_limit) { break; } print "i je ok"; ...zpracuj i... } while(0);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Ned∞lejte si nic z toho, ╛e tomu hned a beze zbytku nerozumφte. M∙╛ete psßt skripty, a to i velmi ·ΦinnΘ skripty, i bez pou╛itφ tΘto 'finty'. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.for" ></A ><TT CLASS="literal" >for</TT ></H2 ><P >
Cykly <TT CLASS="literal" >for</TT > jsou nejslo╛it∞j╣φmi cykly v PHP. Chovajφ se stejn∞, jako jejich soukmenovci v C. Syntaxe cyklu <TT CLASS="literal" >for</TT > je nßsledujφcφ: <DIV CLASS="informalexample" ><A NAME="AEN4910" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >for (expr1; expr2; expr3) statement</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Prvnφ v²raz (<TT CLASS="replaceable" ><I >expr1</I ></TT >) je ohodnocen (proveden) jednou, bezpodmφneΦn∞, na zaΦßtku cyklu. </P ><P >
Na zaΦßtku ka╛dΘ iterace je ohodnocen v²raz <TT CLASS="replaceable" ><I >expr2</I ></TT >. Pokud mß hodnotu <TT CLASS="constant" ><B >TRUE</B ></TT >, cyklus pokraΦuje a zpracovßvß se k≤d uvnit° cyklu. Je-li naopak jeho hodnota <TT CLASS="constant" ><B >FALSE</B ></TT >, provßd∞nφ cyklu konΦφ. </P ><P >
Na konci ka╛dΘ iterace se ohodnotφ (provede) v²raz <TT CLASS="replaceable" ><I >expr3</I ></TT >. </P ><P >
Ka╛d² z v²raz∙ m∙╛e b²t prßzdn². Prßzdn² v²raz <TT CLASS="replaceable" ><I >expr2</I ></TT > znamenß, ╛e cyklus bude probφhat nekoneΦn∞ dlouho (PHP, stejn∞ jako C, implicitn∞ p°edpoklßdß hodnotu <TT CLASS="constant" ><B >TRUE</B ></TT >). To nemusφ b²t tak bez u╛itku, jak si m∙╛ete myslet. ╚asto m∙╛ete toti╛ chtφt ukonΦit cyklus pomocφ podmφn∞nΘho p°φkazu <A HREF="#control-structures.break" ><TT CLASS="literal" >break</TT ></A >, namφsto pou╛itφ pravdivostnφho v²razu v konstruktu cyklu <TT CLASS="literal" >for</TT >. </P ><P >
P°edpoklßdejme nßsledujφcφ p°φklady. V╣echny zobrazφ Φφsla od 1 do 10: <DIV CLASS="informalexample" ><A NAME="AEN4927" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >/* p°φklad 1 */ for ($i = 1; $i <= 10; $i++) { print $i; } /* p°φklad 2 */ for ($i = 1;;$i++) { if ($i > 10) { break; } print $i; } /* p°φklad 3 */ $i = 1; for (;;) { if ($i > 10) { break; } print $i; $i++; } /* p°φklad 4 */ for ($i = 1; $i <= 10; print $i, $i++);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Prvnφ p°φklad samoz°ejm∞ vypadß nejlΘpe (nebo mo╛nß i ten Φtvrt²), ale m∙╛ete p°ijφt na to, ╛e schopnost pou╛φvat prßzdnΘ v²razy v cyklech <TT CLASS="literal" >for</TT > nemusφ b²t n∞kdy ·pln∞ k zahozenφ. </P ><P >
PHP podporuje pro cykly <TT CLASS="literal" >for</TT > takΘ alternativnφ "dvojteΦkovou syntaxi". <DIV CLASS="informalexample" ><A NAME="AEN4933" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >for (expr1; expr2; expr3): statement; ...; endfor;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
JinΘ jazyky majφ konstrukt <TT CLASS="literal" >foreach</TT > k traverzovßnφ polφ nebo hash∙. V PHP 3 nic takovΘho nenφ, PHP 4 ano (viz <A HREF="#control-structures.foreach" >foreach</A >). V PHP 3 m∙╛ete k dosa╛enφ stejnΘho efektu kombinovat <A HREF="#control-structures.while" >while</A > s funkcemi <A HREF="#function.list" ><B CLASS="function" >list()</B ></A > a <A HREF="#function.each" ><B CLASS="function" >each()</B ></A >. P°φklady najdete v dokumentaci. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.foreach" ></A ><TT CLASS="literal" >foreach</TT ></H2 ><P >
PHP 4 (ne PHP 3) zahrnuje konstrukt <TT CLASS="literal" >foreach</TT >, podobn∞ jako Perl a r∙znΘ dal╣φ jazyky. To poskytuje snadn² zp∙sob k iteraci p°es pole. Existujφ dv∞ syntaxe; ta druhß je men╣φm, av╣ak u╛iteΦn²m roz╣φ°enφm tΘ prvnφ: <DIV CLASS="informalexample" ><A NAME="AEN4946" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >foreach(array_expression as $value) statement foreach(array_expression as $key => $value) statement</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Prvnφ forma traverzuje pole danΘ v²razem <TT CLASS="literal" >array_expression</TT >. V ka╛dΘ iteraci je hodnota aktußlnφho elementu p°i°azena do <TT CLASS="literal" >$value</TT > a vnit°nφ ukazatel na pole je zv²╣en o jednotku (tzn. v p°φ╣tφ iteraci budete hled∞t na nßsledujφcφ element). </P ><P >
Druhß forma d∞lß totΘ╛, krom∞ toho, ╛e aktußlnφ klφΦ elementu bude v ka╛dΘ iteraci p°i°azen do prom∞nnΘ <TT CLASS="literal" >$key</TT >. </P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Kdy╛ <TT CLASS="literal" >foreach</TT > zaΦne provßd∞nφ prvnφ iterace, je vnit°nφ ukazatel automaticky nastaven na prvnφ element pole. To znamenß, ╛e p°ed <TT CLASS="literal" >foreach</TT > nemusφte volat <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >. </P ></BLOCKQUOTE ></DIV > </P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Uv∞domte si takΘ, ╛e <TT CLASS="literal" >foreach</TT > pracuje na kopii specifikovanΘho pole, nikoli na poli samotnΘm, proto ukazatel na pole nenφ modifikovßn tak, jako konstruktem <A HREF="#function.each" ><B CLASS="function" >each()</B ></A > a zm∞ny na vrßcenΘm elementu se na p∙vodnφm poli neprojevφ. </P ></BLOCKQUOTE ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <TT CLASS="literal" >foreach</TT > nepodporuje mo╛nost potlaΦit chybovß hlß╣enφ pou╛itφm '@'. </P ></BLOCKQUOTE ></DIV ><P >
M∙╛ete si v╣imnout, ╛e nßsledujφcφ p°φklady jsou funkΦn∞ toto╛nΘ: <DIV CLASS="informalexample" ><A NAME="AEN4968" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >reset ($arr); while (list(, $value) = each ($arr)) { echo "Hodnota: $value<br>\n"; } foreach ($arr as $value) { echo "Hodnota: $value<br>\n"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Nßsledujφcφ p°φklady jsou rovn∞╛ funkΦn∞ toto╛nΘ: <DIV CLASS="informalexample" ><A NAME="AEN4970" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >reset ($arr); while (list($key, $value) = each ($arr)) { echo "KlφΦ: $key; Hodnota: $value<br>\n"; } foreach ($arr as $key => $value) { echo "KlφΦ: $key; Hodnota: $value<br>\n"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Dal╣φ p°φklady demonstrujφcφ pou╛φtφ: <DIV CLASS="informalexample" ><A NAME="AEN4973" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >/* foreach p°φklad 1: pouze hodnota */ $a = array (1, 2, 3, 17); foreach ($a as $v) { print "SouΦasnß hodnota \$a: $v.\n"; } /* foreach p°φklad 2: hodnota (pro ilustraci je vypsßn i klφΦ) */ $a = array (1, 2, 3, 17); $i = 0; /* pouze pro ilustrativnφ ·Φely */ foreach($a as $v) { print "\$a[$i] => $v.\n"; $i++; } /* foreach p°φklad 3: klφΦ a hodnota */ $a = array ( "jedna" => 1, "dv∞" => 2, "t°i" => 3, "sedmnßct" => 17 ); foreach($a as $k => $v) { print "\$a[$k] => $v.\n"; } /* foreach p°φklad 4: vφcerozm∞rnß pole */ $a[0][0] = "a"; $a[0][1] = "b"; $a[1][0] = "y"; $a[1][1] = "z"; foreach($a as $v1) { foreach ($v1 as $v2) { print "$v2\n"; } } /* foreach p°φklad 5: dynamickß pole */ foreach(array(1, 2, 3, 4, 5) as $v) { print "$v\n"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.break" ></A ><TT CLASS="literal" >break</TT ></H2 ><P >
<TT CLASS="literal" >break</TT > ukonΦuje provßd∞nφ aktußlnφho konstruktu <TT CLASS="literal" >for</TT >, <TT CLASS="literal" >foreach</TT > <TT CLASS="literal" >while</TT >, <TT CLASS="literal" >do..while</TT > nebo <TT CLASS="literal" >switch</TT >. </P ><P >
<TT CLASS="literal" >break</TT > akceptuje nepovinn² Φφseln² argument, kter² °φkß, z kolika vno°en²ch struktur se mß vyskoΦit. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN4988" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$arr = array ('jedna', 'dv∞', 't°i', 'Φty°i', 'stop', 'p∞t'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { break; /* Tady byste mohli napsat takΘ 'break 1;'. */ } echo "$val<br>\n"; } /* Pou╛itφ nepovinnΘho argumentu. */ $i = 0; while (++$i) { switch ($i) { case 5: echo "P°i 5<br>\n"; break 1; /* UkonΦuje pouze switch. */ case 10: echo "P°i 10; konec<br>\n"; break 2; /* UkonΦuje switch a while. */ default: break; } }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.continue" ></A ><TT CLASS="literal" >continue</TT ></H2 ><P >
<TT CLASS="literal" >continue</TT > se pou╛φvß uvnit° cykl∙ k p°eskoΦenφ zbytku aktußlnφ iterace a bezprost°ednφmu p°echodu na nßsledujφcφ iteraci. </P ><P >
<TT CLASS="literal" >continue</TT > akceptuje nepovinn² Φφseln² argument, kter² °φkß, kolik ·rovnφ cykl∙ se mß narßz dokonΦit. </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN4998" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >while (list ($key, $value) = each ($arr)) { if (!($key % 2)) { // p°eskoΦ sudΘ Φleny continue; } do_something_odd ($value); } $i = 0; while ($i++ < 5) { echo "Vn∞j╣φ<br>\n"; while (1) { echo " St°ednφ<br>\n"; while (1) { echo " Vnit°nφ<br>\n"; continue 3; } echo "Toto se nikdy nevytiskne.<br>\n"; } echo "Ani tohle se neprovßdφ.<br>\n"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.switch" ></A ><TT CLASS="literal" >switch</TT ></H2 ><P >
Konstrukt <TT CLASS="literal" >switch</TT > je podobnß sΘrii konstrukt∙ IF, testujφcφch tent²╛ v²raz. V mnoha p°φpadech m∙╛ete chtφt porovnßvat stejnou prom∞nnou (nebo v²raz) s mnoha r∙zn²mi hodnotami a provßd∞t r∙znΘ kusy k≤du v zßvislosti na tom, kterΘ hodnot∞ se rovnß. To je p°esn∞ to, k Φemu je <TT CLASS="literal" >switch</TT >. </P ><P >
Nßsledujφcφ dva p°φklady p°edstavujφ dva odli╣nΘ zp∙soby, jak napsat totΘ╛; jeden pou╛φvß sΘrii podmφnek <TT CLASS="literal" >if</TT >, zatφmco druh² je zalo╛en na konstruktu <TT CLASS="literal" >switch</TT >: <DIV CLASS="informalexample" ><A NAME="AEN5009" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >if ($i == 0) { print "i se rovnß 0"; } if ($i == 1) { print "i se rovnß 1"; } if ($i == 2) { print "i se rovnß 2"; } switch ($i) { case 0: print "i se rovnß 0"; break; case 1: print "i se rovnß 1"; break; case 2: print "i se rovnß 2"; break; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Je d∙le╛itΘ pochopit, jak se konstrukt <TT CLASS="literal" >switch</TT > provßdφ, aby se zabrßnilo chybßm. Konstrukt <TT CLASS="literal" >switch</TT > provßdφ °ßdek po °ßdku (resp. konstrukt po konstruktu). Na zaΦßtku nenφ proveden ╛ßdn² k≤d. Pouze tehdy, kdy╛ se najde <TT CLASS="literal" >case</TT > s hodnotou odpovφdajφcφ hodnot∞ v²razu u <TT CLASS="literal" >switch</TT >, zaΦne PHP provßd∞t nßsledujφcφ konstrukty. Vykonßvßnφ k≤du pokraΦuje, dokud se nedosßhne konce bloku <TT CLASS="literal" >switch</TT > nebo prvnφho p°φkazu <TT CLASS="literal" >break</TT >. Pokud nenapφ╣ete na konec bloku po <TT CLASS="literal" >case</TT > p°φkaz <TT CLASS="literal" >break</TT >, bude PHP pokraΦovat v provßd∞nφ dal╣φch konstrukt∙ (po dal╣φm <TT CLASS="literal" >case</TT >). Nap°φklad: <DIV CLASS="informalexample" ><A NAME="AEN5021" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >switch ($i) { case 0: print "i se rovnß 0"; case 1: print "i se rovnß 1"; case 2: print "i se rovnß 2"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Zde, pokud se $i rovnß 0, se budou provßd∞t v╣echny p°φkazy "print"! Pokud se $i rovnß 1, PHP provede poslednφ dva p°φkazy, a pouze rovnß-li se $i Φφslu 2, obdr╛φte "oΦekßvanΘ" chovßnφ a zobrazφ se pouze "i se rovnß 2". Tak╛e je d∙le╛itΘ nezapomenout na p°φkaz <TT CLASS="literal" >break</TT > (krom∞ p°φpadu, kdy ho chcete vynechat zßm∞rn∞ k dosa╛enφ urΦitΘho cφle). </P ><P >
V konstruktu <TT CLASS="literal" >switch</TT > se podmφnka testuje pouze jednou a v²sledek se porovnßvß s ka╛dou hodnotou v <TT CLASS="literal" >case</TT >. V p°φpad∞ <TT CLASS="literal" >elseif</TT > se podmφnka poka╛dΘ testuje znovu. Pokud je va╣e podmφnka komplikovan∞j╣φ ne╛ jednoduchΘ porovnßnφ a/nebo je uvnit° cyklu, <TT CLASS="literal" >switch</TT > m∙╛e b²t rychlej╣φ. </P ><P >
Seznam konstrukt∙ za <TT CLASS="literal" >case</TT > m∙╛e b²t takΘ prßzdn², co╛ jednodu╣e p°edß °φzenφ nßsledujφcφmu <TT CLASS="literal" >case</TT >. <DIV CLASS="informalexample" ><A NAME="AEN5033" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >switch ($i) { case 0: case 1: case 2: print "i je men╣φ ne╛ 3, ale nezßpornΘ"; break; case 3: print "i je 3"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Specißlnφ <TT CLASS="literal" >case</TT > je "default". Vyhovuje v╣em ostatnφm hodnotßm, kterΘ nejsou pokryty n∞kter²m z ostatnφch <TT CLASS="literal" >case</TT > a mß b²t v╛dy jako poslednφ. Nap°φklad: <DIV CLASS="informalexample" ><A NAME="AEN5038" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >switch ($i) { case 0: print "i se rovnß 0"; break; case 1: print "i se rovnß 1"; break; case 2: print "i se rovnß 2"; break; default: print "i se nerovnß 0, 1 ani 2"; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
V²raz v <TT CLASS="literal" >case</TT > m∙╛e b²t libovoln² v²raz, jeho╛ hodnota je jednoduchΘho typu, tj. celΘ nebo reßlnΘ Φφslo nebo °et∞zec. Pole ani objekty nelze pou╛φt, leda╛e by odkazovaly na jednoduch² typ. </P ><P >
Alternativnφ syntaxe pro konstrukty <TT CLASS="literal" >switch</TT > je podporovßna. Pro vφc informacφ viz <A HREF="#control-structures.alternative-syntax" >Alternativnφ syntaxe °φdicφch struktur</A > . <DIV CLASS="informalexample" ><A NAME="AEN5045" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >switch ($i): case 0: print "i se rovnß 0"; break; case 1: print "i se rovnß 1"; break; case 2: print "i se rovnß 2"; break; default: print "i se nerovnß 0, 1 ani 2"; endswitch;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="control-structures.declare" ></A ><TT CLASS="literal" >declare</TT ></H2 ><P >
Konstrukt <TT CLASS="literal" >declare</TT > se pou╛φvß k nastavenφ provßd∞cφch direktiv pro blok k≤du. Syntaxe <TT CLASS="literal" >declare</TT > je podobnß syntaxi ostatnφcj konstrukt∙ pro °φzenφ toku: <DIV CLASS="informalexample" ><A NAME="AEN5053" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >declare (directive) statement</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
╚ßst <TT CLASS="literal" >directive</TT > umo╛≥uje nastavit chovßnφ bloku, kter² mß b²t ovlivn∞n pomocφ <TT CLASS="literal" >declare</TT >. V souΦasnosti je rozpoznßvßna pouze jedinß direktiva: <TT CLASS="literal" >ticks</TT >. (Pro vφce informacφ viz nφ╛e - direktiva <A HREF="#control-structures.declare.ticks" >ticks</A >) </P ><P >
╚ßst <TT CLASS="literal" >statement</TT > bloku <TT CLASS="literal" >declare</TT > bude provedena - jak bude provedena a jakΘ vedlej╣φ efekty nastanou b∞hem provßd∞nφ m∙╛e zßle╛et na direktiv∞ nastavenΘ v bloku <TT CLASS="literal" >directive</TT >. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="control-structures.declare.ticks" ></A >Ticks</H3 ><P >Tick je udßlost, kterß nastane pro ka╛d²ch <TT CLASS="replaceable" ><I >N</I ></TT > nφzko·rov≥ov²ch konstrukt∙ proveden²ch parserem uvnit° bloku <TT CLASS="literal" >declare</TT >. Hodnota <TT CLASS="replaceable" ><I >N</I ></TT > je specifikovßna pomocφ <TT CLASS="literal" >ticks=<TT CLASS="replaceable" ><I >N</I ></TT ></TT > uvnit° sekce <TT CLASS="literal" >directive</TT > bloku <TT CLASS="literal" >declare</TT >. </P ><P >
Udßlost(i), kterß nastane p°i ka╛dΘm ticku, se specifikuje pomocφ <A HREF="#function.register-tick-function" ><B CLASS="function" >register_tick_function()</B ></A >. Vφce podrobnostφ - viz p°φklad nφ╛e. Uv∞domte si, ╛e na ka╛d² tick m∙╛e nastat vφce ne╛ jedna udßlost. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5077" ></A ><P ><B >P°φklad 11-1. Profile a section of PHP code</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><pre> <?php // A function that records the time when it is called function profile ($dump = FALSE) { static $profile; // Return the times stored in profile, then erase it if ($dump) { $temp = $profile; unset ($profile); return ($temp); } $profile[] = microtime (); } // Set up a tick handler register_tick_function("profile"); // Initialize the function before the declare block profile (); // Run a block of code, throw a tick every 2nd statement declare (ticks=2) { for ($x = 1; $x < 50; ++$x) { echo similar_text (md5($x), md5($x*$x)), "<br>"; } } // Display the data stored in the profiler print_r (profile (TRUE)); ?> </pre></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > The example profiles the PHP code within the 'declare' block, recording the time at which every second low-level statement in the block was executed. This information can then be used to find the slow areas within particular segments of code. This process can be performed using other methods: using ticks is more convenient and easier to implement. </P ><P >
Ticks are well suited for debugging, implementing simple multitasking, backgrounded I/O and many other tasks. </P ><P >
See also <A HREF="#function.register-tick-function" ><B CLASS="function" >register_tick_function()</B ></A > and <A HREF="#function.unregister-tick-function" ><B CLASS="function" >unregister_tick_function()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="function.return" ></A >return</H2 ><P >
Zavolßn uvnit° funkce, konstrukt <A HREF="#function.return" ><B CLASS="function" >return()</B ></A > okam╛it∞ ukonΦφ provßd∞nφ tΘto funkce a vracφ sv∙j argument jako hodnotu volßnφ funkce. <A HREF="#function.return" ><B CLASS="function" >return()</B ></A > takΘ obdobn∞ ukonΦφ provßd∞nφ konstruktu <A HREF="#function.eval" ><B CLASS="function" >eval()</B ></A > nebo celΘho skriptu. </P ><P >
Pokud se volß z globßlnφho kontextu, provßd∞nφ skriptu se ukonΦφ. Byl-li aktußlnφ skript vlo╛en pomocφ <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > nebo <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >, p°edß se °φzenφ volajφcφmu souboru. Navφc, bylo-li pou╛ito <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >, bude hodnota specifikovanß v <A HREF="#function.return" ><B CLASS="function" >return()</B ></A > vrßcena jako hodnota volßnφ <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >. Pokud se <A HREF="#function.return" ><B CLASS="function" >return()</B ></A > zavolß z hlavnφho souboru skriptu, provßd∞nφ skonΦφ. Kdy╛ se jednß o soubor specifikovan² pomocφ konfiguraΦnφch voleb <A HREF="#ini.auto-prepend-file" >auto_prepend_file</A > nebo <A HREF="#ini.auto-append-file" >auto_append_file</A > v <A HREF="#configuration.file" >konfiguraΦnφm souboru</A >, zpracovßnφ souboru konΦφ. </P ><P >Vφce informacφ - viz <A HREF="#functions.returning-values" >NßvratovΘ hodnoty</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Uv∞domte si, ╛e <A HREF="#function.return" ><B CLASS="function" >return()</B ></A > je jazykov² konstrukt, a nikoli funkce -- uzav°enφ argument∙ do zßvorek <SPAN CLASS="emphasis" ><I CLASS="emphasis" >nenφ</I ></SPAN > nutnΘ. Obvykle se vynechßvajφ, ale nezßle╛φ na tom, zda se pou╛ijφ Φi nikoli. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="function.require" ></A ><A HREF="#function.require" ><B CLASS="function" >require()</B ></A ></H2 ><P >
Konstrukt <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > vlo╛φ a ohodnotφ specifikovan² soubor. </P ><P >
<A HREF="#function.require" ><B CLASS="function" >require()</B ></A > vlo╛φ a ohodnotφ specifikovan² soubor. PodrobnΘ informace o tom, jak vklßdßnφ pracuje, jsou popsßny v dokumentaci o <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >. </P ><P >
<A HREF="#function.require" ><B CLASS="function" >require()</B ></A > a <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > jsou toto╛nΘ, krom∞ toho, jak zpracovßvajφ chyby. <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > vyprodukuje <A HREF="#internal.e-warning" >Warning</A > (varovßnφ), zatφmco <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > skonΦφ s chybou typu <A HREF="#internal.e-error" >Fatal Error</A > (velmi vß╛nß chyba). Jinak °eΦeno, nerozpakujte se pou╛φt <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >, pokud chcete, aby nep°φtomnost souboru zastavila zpracovßnφ strßnky. <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > se takto nechovß, skript bude neru╣en∞ pokraΦovat. Ujist∞te se takΘ, ╛e mßte v po°ßdku nastavenφ <A HREF="#ini.include-path" >include_path</A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5125" ></A ><P ><B >P°φklad 11-2. Zßkladnφ p°φklady pou╛itφ <A HREF="#function.require" ><B CLASS="function" >require()</B ></A ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php require 'prepend.php'; require $somefile; require ('somefile.txt'); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Dal╣φ p°φklady -- viz dokumentace <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > U verzφ p°ed PHP 4.0.2 platφ toto: <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > se v╛dy pokusφ p°eΦφst p°φslu╣n² soubor, krom∞ p°φpadu, ╛e se °ßdek s tφmto p°φkazem nem∙╛e nikdy provΘst. Podmφn∞n² v²raz <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > neovliv≥uje. Av╣ak pokud se °ßdek, na kterΘm <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > le╛φ, v∙bec neprovßdφ, nebude se provßd∞t ani k≤d v p°φslu╣nΘm souboru. Podobn∞ je tomu i v p°φpad∞ cykl∙ -- ani ty neovliv≥ujφ chovßnφ <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >. P°esto╛e k≤d obsa╛en² ve vklßdanΘm souboru je stßle p°edm∞tem opakovßnφ, samotnΘ <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > se provede pouze jednou. </P ></BLOCKQUOTE ></DIV ><P >
Viz takΘ <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >, <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A >, <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A >, <A HREF="#function.eval" ><B CLASS="function" >eval()</B ></A >, <A HREF="#function.file" ><B CLASS="function" >file()</B ></A >, <A HREF="#function.readfile" ><B CLASS="function" >readfile()</B ></A >, <A HREF="#function.virtual" ><B CLASS="function" >virtual()</B ></A > a <A HREF="#ini.include-path" >include_path</A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="function.include" ></A ><A HREF="#function.include" ><B CLASS="function" >include()</B ></A ></H2 ><P >
Konstrukt <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > vlo╛φ a ohodnotφ specifikovan² soubor. </P ><P >
Nφ╛e popsanΘ platφ i pro <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >. Tyto dva konstrukty jsou zcela toto╛nΘ, krom∞ toho, jak zpracovßvajφ chyby. <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > produkuje <A HREF="#internal.e-warning" >Warning</A > (varovßnφ), zatφmco <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > skonΦφ s chybou typu <A HREF="#internal.e-error" >Fatal Error</A >. Jin²mi slovy, <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > pou╛ijte tehdy, chcete-li, aby se p°i chyb∞jφcφm souboru zastavilo zpracovßvßnφ. <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > se tak nechovß, skript bude neru╣en∞ pokraΦovat. Ujist∞te se takΘ, ╛e mßte v po°ßdku nastavenφ <A HREF="#ini.include-path" >include_path</A >. </P ><P >
Pokud se vlo╛φ soubor, potom k≤d v n∞m obsa╛en² d∞dφ <A HREF="#language.variables.scope" >kontext prom∞nnΘ</A > °ßdku, kde byl vlo╛en. V╣echny prom∞nnΘ dostupnΘ na tomto °ßdku volajφcφho souboru budou (od tΘto chvφle) dostupnΘ i ve volanΘm souboru. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5164" ></A ><P ><B >P°φklad 11-3. Zßkladnφ p°φklad -- <A HREF="#function.include" ><B CLASS="function" >include()</B ></A ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >vars.php <?php $color = 'zelenΘ'; $fruit = 'jablko'; ?> test.php <?php echo "Vidφm $color $fruit"; // Vidφm include 'vars.php'; echo "Vidφm $color $fruit"; // Vidφm zelenΘ jablko ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Pokud ke vlo╛enφ dojde uvnit° funkce ve volajφcφm souboru, potom se v╣echen k≤d obsa╛en² ve volanΘm souboru bude chovat, jako by byl definovßn uvnit° tΘto funkce -- tedy v rßmci kontextu prom∞nn²ch funkce. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5170" ></A ><P ><B >P°φklad 11-4. Vklßdßnφ uvnit° funkcφ</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function foo() { global $color; include 'vars.php'; echo "Vidφm $color $fruit"; } /* vars.php je v kontextu foo(), tak╛e * * $fruit NEN═ dostupnß mimo tento kontext. * * Naopak $color JE, proto╛e je deklarovßna * * jako globßlnφ. */ foo(); // Vidφm zelenΘ jablko echo "Vidφm $color $fruit"; // Vidφm zelenΘ ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
P°i vklßdßnφ souboru p°ejde parsing na zaΦßtku souboru z PHP re╛imu do m≤du HTML a na jeho konci se vracφ zp∞t do m≤du PHP. Z tohoho d∙vodu musφ b²t provßd∞n² PHP k≤d ve vklßdanΘm souboru uzav°en mezi <A HREF="#language.basic-syntax.phpmode" >platnou poΦßteΦnφ a koncovou PHP znaΦku</A >. </P ><P >
Pokud jsou v PHP povoleny "<A HREF="#ini.allow-url-fopen" >URL fopen wrappery</A >" (co╛ tak implicitn∞ je), m∙╛ete specifikovat soubor ke vlo╛enφ pomocφ URL (p°es HTTP) namφsto lokßlnφho umφst∞nφ. Pokud p°φsku╣n² server interpretuje po╛adovan² soubor jako PHP k≤d, prom∞nnΘ mohou b²t odkazovßny pomocφ °et∞zce URL po╛adavku jako u HTTP GET. Nenφ to ·pln∞ totΘ╛ jako vlo╛enφ souboru s d∞d∞nφm kontextu prom∞nn²ch od rodiΦovskΘho souboru; skript b∞╛φ na vzdßlenΘm serveru a v²sledek se potom vlo╛φ do lokßlnφho skriptu. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5178" ></A ><P ><B >P°φklad 11-5. <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > p°es HTTP</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php /* Tento p°φklad p°edpoklßdß, ╛e www.example.com je konfigurovßn k parsovßnφ * * soubor∙ .php a nikoli soubor∙ .txt. Tedy, 'funguje' zde znamenß, ╛e * * prom∞nnΘ $foo a $bar jsou dostupnΘ uvnit° vklßdanΘho souboru. */ // Nefunguje; file.txt nebyl na www.example.com zpracovßn jako PHP include 'http://www.example.com/file.txt?foo=1&bar=2'; // Nefunguje; hledß soubor 'file.php?foo=1&bar=2' v lokßlnφm systΘmu soubor∙. include 'file.php?foo=1&bar=2'; // Funguje. include 'http://www.example.com/file.php?foo=1&bar=2'; $foo = 1; $bar = 2; include 'file.txt'; // Funguje. include 'file.php'; // Funguje. ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Souvisejφcφ informace -- viz takΘ <A HREF="#features.remote-files" >VzdßlenΘ soubory</A >, <A HREF="#function.fopen" ><B CLASS="function" >fopen()</B ></A > a <A HREF="#function.file" ><B CLASS="function" >file()</B ></A >. </P ><P >
Proto╛e <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > a <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > jsou specißlnφ jazykovΘ konstrukty, pokud se provßd∞jφ podmφn∞n∞, musφte je uzav°φt do bloku. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5189" ></A ><P ><B >P°φklad 11-6. include() a podmφn∞nΘ bloky</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Toto je ⌐PATN╠ a (jak bylo °eΦeno) nebude to fungovat. if ($condition) include $file; else include $other; // Tohle je SPR┴VN╠. if ($condition) { include $file; } else { include $other; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Obsluha nßvrat∙: Uvnit° vklßdanΘho souboru lze provΘst konstrukt <A HREF="#function.return" ><B CLASS="function" >return()</B ></A > k ukonΦenφ provßd∞nφ souboru a nßvrat do volajφcφho skriptu. Je tedy mo╛nΘ z vlo╛en²ch soubor∙ vracet hodnoty. M∙╛ete vzφt hodnotu volßnφ include, jako by to byla normßlnφ funkce. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > V PHP 3 se return nesmφ objevit uvnit° bloku, pokud to nenφ funkΦnφ blok; tehdy v╣ak se v╣ak <A HREF="#function.return" ><B CLASS="function" >return()</B ></A > t²kß tΘto funkce a ne celΘho souboru. </P ></BLOCKQUOTE ></DIV ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5198" ></A ><P ><B >P°φklad 11-7. <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > a konstrukt <A HREF="#function.return" ><B CLASS="function" >return()</B ></A ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >return.php <?php $var = 'PHP'; return $var; ?> noreturn.php <?php $var = 'PHP'; ?> testreturns.php <?php $foo = include 'return.php'; echo $foo; // vypφ╣e 'PHP' $bar = include 'noreturn.php'; echo $bar; // vypφ╣e 1 ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="literal" >$bar</TT > mß hodnotu <TT CLASS="literal" >1</TT >, proto╛e p°φkaz include byl ·sp∞╣n². V╣imn∞te si rozdφlu mezi v²╣e uveden²mi p°φklady. Prvnφ pou╛φvß ve vklßdanΘm souboru <A HREF="#function.return" ><B CLASS="function" >return()</B ></A >, druh² nikoli. Dal╣φmi zp∙soby, jak p°i°adit hodnotu souboru do prom∞nnΘ, jsou funkce <A HREF="#function.fopen" ><B CLASS="function" >fopen()</B ></A >, <A HREF="#function.file" ><B CLASS="function" >file()</B ></A > a pou╛itφ <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > spoleΦn∞ s <A HREF="#ref.outcontrol" >funkcemi °φzenφ v²stupu</A >. </P ><P >
Viz takΘ <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >, <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A >, <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A >, <A HREF="#function.readfile" ><B CLASS="function" >readfile()</B ></A >, <A HREF="#function.virtual" ><B CLASS="function" >virtual()</B ></A >, a <A HREF="#ini.include-path" >include_path</A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="function.require-once" ></A ><A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A ></H2 ><P >
Konstrukt <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A > vlo╛φ a ohodnotφ specifikovan² soubor b∞hem provßd∞nφ skriptu. Chovß se tedy podobn∞ jako <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >, s tφm rozdφlem, ╛e pokud u╛ byl k≤d ze souboru d°φve vlo╛en do skriptu, nebude znovu vklßdßn. Vφce informacφ o chovßnφ p°φkazu -- viz p°φkaz <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >. </P ><P >
P°φkaz <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A > by se m∞l pou╛φvat v p°φpadech, kde by mohl b²t b∞hem provßd∞nφ skriptu tent²╛ soubor vlo╛en a ohodnocen vφckrßt, a p°itom chcete zajistit prßv∞ jedno vlo╛enφ (je t°eba se vyhnout redefinicφm funkcφ, novΘmu p°i°azenφ hodnot atd.). </P ><P >
P°φklady na pou╛itφ <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A > a <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A > najdete v k≤du <A HREF="http://pear.php.net/" TARGET="_top" >PEAR</A > p°ilo╛enΘm v nejnov∞j╣φch distribucφch zdrojov²ch k≤d∙ PHP. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > P°φkaz <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A > byl p°idßn v PHP 4.0.1pl2. </P ></BLOCKQUOTE ></DIV ><P >
Viz takΘ: <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >, <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >, <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A >, <A HREF="#function.get-required-files" ><B CLASS="function" >get_required_files()</B ></A >, <A HREF="#function.get-included-files" ><B CLASS="function" >get_included_files()</B ></A >, <A HREF="#function.readfile" ><B CLASS="function" >readfile()</B ></A >, a <A HREF="#function.virtual" ><B CLASS="function" >virtual()</B ></A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="function.include-once" ></A ><A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A ></H2 ><P >
Konstrukt <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A > vlo╛φ a ohodnotφ specifikovan² soubor b∞hem provßd∞nφ skriptu. Chovß se tedy podobn∞ jako <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > , s tφm rozdφlem, ╛e pokud u╛ byl k≤d ze souboru d°φve vlo╛en do skriptu, nebude znovu vklßdßn. Jak nßzev napovφdß, bude vlo╛en prßv∞ jednou. </P ><P >
P°φkaz <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A > by se m∞l pou╛φvat v p°φpadech, kde by mohl b²t b∞hem provßd∞nφ skriptu tent²╛ soubor vlo╛en a ohodnocen vφckrßt, a p°itom chcete zajistit prßv∞ jedno vlo╛enφ (je t°eba se vyhnout redefinicφm funkcφ, novΘmu p°i°azenφ hodnot atd.). </P ><P >
P°φklady na pou╛itφ <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A > and <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A > najdete v k≤du <A HREF="http://pear.php.net/" TARGET="_top" >PEAR</A > p°ilo╛enΘm v nejnov∞j╣φch distribucφch zdrojov²ch k≤d∙ PHP. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > P°φkaz <A HREF="#function.include-once" ><B CLASS="function" >include_once()</B ></A > byl p°idßn v PHP 4.0.1pl2. </P ></BLOCKQUOTE ></DIV ><P >
Viz takΘ <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >, <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >, <A HREF="#function.require-once" ><B CLASS="function" >require_once()</B ></A >, <A HREF="#function.get-required-files" ><B CLASS="function" >get_required_files()</B ></A >, <A HREF="#function.get-included-files" ><B CLASS="function" >get_included_files()</B ></A >, <A HREF="#function.readfile" ><B CLASS="function" >readfile()</B ></A >, a <A HREF="#function.virtual" ><B CLASS="function" >virtual()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="functions" >Kapitola 12. Funkce</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="functions.user-defined" ></A >U╛ivatelsky definovanΘ funkce</H2 ><P >
Funkce m∙╛e b²t definovßna pomocφ syntaxe podobnΘ tΘto: <DIV CLASS="informalexample" ><A NAME="AEN5270" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function foo ($arg_1, $arg_2, ..., $arg_n) { echo "Ukßzkovß funkce.\n"; return $retval; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Do funkce m∙╛e b²t vlo╛en jak²koli platn² PHP k≤d, dokonce i definice jin²ch funkcφ a <A HREF="#keyword.class" >t°φd</A >. </P ><P >
V PHP 3 musφ b²t funkce definovßny d°φve, ne╛ je na n∞ odkazovßno. V PHP u╛ tento po╛adavek neplatφ. </P ><P >
PHP nepodporuje p°et∞╛ovßnφ funkcφ, nenφ mo╛nΘ ani oddefinovßnφ nebo p°edefinovanß d°φve deklarovan²ch funkcφ. </P ><P >
PHP 3 nepodporuje prom∞nn² poΦet argument∙ funkcφ, zatφmco implicitnφ argumenty jsou podporovßny (vφce informacφ - viz <A HREF="#functions.arguments.default" >Implicitnφ hodnoty argument∙</A >). PHP 4 podporuje obojφ: vφce informacφ - viz <A HREF="#functions.variable-arg-list" >Seznam argument∙ prom∞nnΘ dΘlky</A > a reference funkcφ <A HREF="#function.func-num-args" ><B CLASS="function" >func_num_args()</B ></A >, <A HREF="#function.func-get-arg" ><B CLASS="function" >func_get_arg()</B ></A >, a <A HREF="#function.func-get-args" ><B CLASS="function" >func_get_args()</B ></A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="functions.arguments" ></A >Argumenty funkcφ</H2 ><P >
Informace mohou b²t do funkcφ p°edßvßny p°es seznam argument∙, co╛ je seznam prom∞nn²ch a/nebo konstant odd∞len²ch Φßrkou. </P ><P >
PHP podporuje p°edßvßnφ argument∙ hodnotou (implicitnφ), <A HREF="#functions.arguments.by-reference" >p°edßvßnφ odkazem</A >, a <A HREF="#functions.arguments.default" >implicitnφ hodnoty argument∙</A >. Prom∞nnß dΘlka seznamu argument∙ je podporovßna pouze v PHP 4 a pozd∞j╣φch; viz <A HREF="#functions.variable-arg-list" >Seznam argument∙ prom∞nnΘ dΘlky</A > a reference funkcφ <A HREF="#function.func-num-args" ><B CLASS="function" >func_num_args()</B ></A >, <A HREF="#function.func-get-arg" ><B CLASS="function" >func_get_arg()</B ></A >, a <A HREF="#function.func-get-args" ><B CLASS="function" >func_get_args()</B ></A >. Podobn² efekt m∙╛e b²t v PHP 3 dosa╛en p°edßnφm pole argument∙ do funkce: <DIV CLASS="informalexample" ><A NAME="AEN5292" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function takes_array($input) { echo "$input[0] + $input[1] = ", $input[0]+$input[1]; }</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="functions.arguments.by-reference" ></A >P°edßvßnφ argument∙ odkazem</H3 ><P >
Implicitn∞ jsou argumenty funkcφ p°edßvßny hodnotou (tak╛e kdy╛ zm∞nφte hodnotu argumentu ve funkci, nezm∞nφ se mimo funkci). Pokud chcete umo╛nit funkci modifikovat svΘ argumenty, musφte je p°edßvat odkazem. </P ><P >
Pokud chcete, aby byl argument do funkce p°edßvßn v╛dy odkazem, m∙╛ete p°ed nßzev argumentu v definici funkce p°ed°adit ampersand (&): <DIV CLASS="informalexample" ><A NAME="AEN5298" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function add_some_extra(&$string) { $string .= 'a n∞co navφc.'; } $str = 'Toto je °et∞zec '; add_some_extra($str); echo $str; // vypφ╣e 'Toto je °et∞zec a n∞co navφc.'</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="functions.arguments.default" ></A >Implicitnφ hodnoty argument∙</H3 ><P >
Funkce m∙╛e ve stylu C++ definovat implicitnφ hodnoty pro skalßrnφ argumenty takto: <DIV CLASS="informalexample" ><A NAME="AEN5303" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function makecoffee ($type = "cappucina") { return "D∞lßm ╣ßlek $type.\n"; } echo makecoffee (); echo makecoffee ("espressa");</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
V²stupem v²╣e uvedenΘho k≤du je: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >D∞lßm ╣ßlek cappucina. D∞lßm ╣ßlek espressa.</PRE ></TD ></TR ></TABLE > </P ><P >
Implicitnφ hodnota musφ b²t konstantnφ v²raz, ne (nap°φklad) prom∞nnß nebo polo╛ka t°φdy. </P ><P >
Uv∞domte si, ╛e kdy╛ pou╛φvßte implicitnφ argumenty, jakΘkoli implicitnφ hodnoty by m∞ly b²t na pravΘ stan∞ neimplicitnφho argumentu; jinak to nebude pracovat podle oΦekßvßnφ. Uva╛ujme tento kus k≤du: <DIV CLASS="informalexample" ><A NAME="AEN5309" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function makeyogurt ($type = "acidophilus", $flavour) { return "D∞lßm kelφmek jogurtu $type $flavour.\n"; } echo makeyogurt ("malina"); // nebude pracovat podle oΦekßvßnφ</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
V²stupem uvedenΘho p°φkladu bude: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Warning: Missing argument 2 in call to makeyogurt() in /usr/local/etc/httpd/htdocs/php3test/functest.html on line 41 D∞lßm kelφmek jogurtu malina.</PRE ></TD ></TR ></TABLE > </P ><P >
A nynφ to porovnejme s tφmto: <DIV CLASS="informalexample" ><A NAME="AEN5314" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function makeyogurt ($flavour, $type = "acidophilus") { return "D∞lßm kelφmek jogurtu $type $flavour.\n"; } echo makeyogurt ("malina"); // pracuje podle oΦekßvßnφ</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
P°φklad vytiskne: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >D∞lßm kelφmek jogurtu acidophilus malina.</PRE ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="functions.variable-arg-list" ></A >Seznam argument∙ prom∞nnΘ dΘlky</H3 ><P >
PHP 4 mß podporu pro seznam argument∙ prom∞nnΘ dΘlky v u╛ivatelsk²ch funkcφch. Je to opravdu jednoduchΘ, pou╛itφm funkcφ <A HREF="#function.func-num-args" ><B CLASS="function" >func_num_args()</B ></A >, <A HREF="#function.func-get-arg" ><B CLASS="function" >func_get_arg()</B ></A >, a <A HREF="#function.func-get-args" ><B CLASS="function" >func_get_args()</B ></A >. </P ><P >
Nenφ t°eba ╛ßdnß zvlß╣tnφ syntaxe, seznam argument∙ m∙╛e b²t stßle explicitn∞ poskytovßn definicemi funkcφ a bude se chovat jako normßln∞. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="functions.returning-values" ></A >NßvratovΘ hodnoty</H2 ><P >
Hodnoty jsou vraceny pomocφ nepovinnΘ klausule return. M∙╛e b²t vracen libovoln² typ, vΦetn∞ seznam∙ a objekt∙. Klasule zp∙sobuje, ╛e funkce okam╛it∞ ukonΦφ sv∙j b∞h a p°edß °φzenφ zp∞t na °ßdek, odkud byla volßna. Pro vφce informacφ viz <A HREF="#function.return" ><B CLASS="function" >return()</B ></A >. <DIV CLASS="informalexample" ><A NAME="AEN5329" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function square ($num) { return $num * $num; } echo square (4); // vypφ╣e '16'.</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Z funkce nem∙╛ete vracet vφce hodnot, ale podobnΘho v²sledku m∙╛e b²t dosa╛eno vrßcenφm seznamu. <DIV CLASS="informalexample" ><A NAME="AEN5332" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function small_numbers() { return array (0, 1, 2); } list ($zero, $one, $two) = small_numbers();</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
K vrßcenφ odkazu z funkce musφte pou╛φt referenΦnφ operßtor & jak v deklaraci funkce, tak p°i p°i°azovßnφ vrßcenΘ hodnoty do prom∞nnΘ: <DIV CLASS="informalexample" ><A NAME="AEN5335" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function &returns_reference() { return $someref; } $newref =& returns_reference();</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Pro dal╣φ informace o odkazech se laskav∞ podφvejte na <A HREF="#language.references" >Vysv∞tlenφ odkaz∙</A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="functions.old-syntax" ></A ><TT CLASS="literal" >old_function</TT ></H2 ><P >
Klausule <TT CLASS="literal" >old_function</TT > umo╛≥uje deklarovat funkci s identickou syntaxφ jako v PHP/FI2 (krom∞ toho, ╛e musφte 'function' nahradit 'old_function'. </P ><P >
Toto je zavr╛enß mo╛nost a m∞la by b²t pou╛φvßna pouze PHP/FI2->PHP 3 konvertorem. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Funkce deklarovanΘ jako <TT CLASS="literal" >old_function</TT > nelze volat z internφho k≤du PHP. To mj. znamenß, ╛e je nem∙╛ete pou╛φvat ve funkcφch jako <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A >, <A HREF="#function.array-walk" ><B CLASS="function" >array_walk()</B ></A >, a <A HREF="#function.register-shutdown-function" ><B CLASS="function" >register_shutdown_function()</B ></A >. Toto omezenφ m∙╛ete obejφt napsßnφm wrapperu (v normßlnφ PHP 3 form∞), z n∞ho╛ volßte <TT CLASS="literal" >old_function</TT >. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="functions.variable-functions" ></A >Funkce v prom∞nn²ch</H2 ><P >
PHP podporuje koncept funkcφ v prom∞nn²ch. To znamenß, ╛e kdy╛ mß nßzev prom∞nnΘ p°ipojeny zßvorky, PHP bude hledat funkci se stejn²m nßzvem, jako mß hodnota prom∞nnΘ, a pokusφ se ji provΘst. To lze mj. pou╛φt k implementacφ zp∞tn²ch volßnφ, tabulek funkcφ atd. </P ><P >
Funkce v prom∞nn²ch nebudou fungovat s jazykov²mi konstrukty jin²mi ne╛ <A HREF="#function.print" ><B CLASS="function" >print()</B ></A >, jako je <A HREF="#function.echo" ><B CLASS="function" >echo()</B ></A >, <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A >, <A HREF="#function.isset" ><B CLASS="function" >isset()</B ></A > a <A HREF="#function.empty" ><B CLASS="function" >empty()</B ></A >. To je jeden z velk²ch rozdφl∙ mezi funkcemi PHP a jazykov²mi konstrukty. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5362" ></A ><P ><B >P°φklad 12-1. P°φklad na funkce v prom∞nn²ch</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function foo() { echo "V foo()<br>\n"; } function bar($arg = '') { echo "V bar(); byl argument '$arg'.<br>\n"; } $func = 'foo'; $func(); $func = 'bar'; $func('test'); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.oop" >Kapitola 13. Classes and Objects</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="keyword.class" ></A ><TT CLASS="literal" >class</TT ></H2 ><P >
A class is a collection of variables and functions working with these variables. A class is defined using the following syntax: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN5372" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class Cart { var $items; // Items in our shopping cart // Add $num articles of $artnr to the cart function add_item ($artnr, $num) { $this->items[$artnr] += $num; } // Take $num articles of $artnr out of the cart function remove_item ($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } else { return false; } } } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
This defines a class named Cart that consists of an associative array of articles in the cart and two functions to add and remove items from this cart. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
You can <SPAN CLASS="emphasis" ><I CLASS="emphasis" >NOT</I ></SPAN > break up a class definition into multiple files, or multiple PHP blocks. The following will not work: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN5379" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class test { ?> <?php function test() { print 'OK'; } } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></TD ></TR ></TABLE ></DIV ><P >
The following cautionary notes are valid for PHP 4. </P ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
The name <TT CLASS="literal" >stdClass</TT > is used interally by Zend and is reserved. You cannot have a class named <TT CLASS="literal" >stdClass</TT > in PHP. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
The function names <TT CLASS="literal" >__sleep</TT > and <TT CLASS="literal" >__wakeup</TT > are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them. See below for more information. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality. </P ></TD ></TR ></TABLE ></DIV ><P >
In PHP 4, only constant initializers for <TT CLASS="literal" >var</TT > variables are allowed. To initialize variables with non-constant values, you need an initialization function which is called automatically when an object is being constructed from the class. Such a function is called a constructor (see below). </P ><DIV CLASS="informalexample" ><A NAME="AEN5394" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class Cart { /* None of these will work in PHP 4. */ var $todays_date = date("Y-m-d"); var $name = $firstname; var $owner = 'Fred ' . 'Jones'; /* Arrays containing constant values will, though. */ var $items = array("VCR", "TV"); } /* This is how it should be done. */ class Cart { var $todays_date; var $name; var $owner; var $items = array("VCR", "TV"); function Cart() { $this->todays_date = date("Y-m-d"); $this->name = $GLOBALS['firstname']; /* etc. . . */ } } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Classes are types, that is, they are blueprints for actual variables. You have to create a variable of the desired type with the <TT CLASS="literal" >new</TT > operator. </P ><DIV CLASS="informalexample" ><A NAME="AEN5398" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $cart = new Cart; $cart->add_item("10", 1); $another_cart = new Cart; $another_cart->add_item("0815", 3); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
This creates the objects <TT CLASS="varname" >$cart</TT > and <TT CLASS="varname" >$another_cart</TT >, both of the class Cart. The function add_item() of the <TT CLASS="varname" >$cart</TT > object is being called to add 1 item of article number 10 to the <TT CLASS="varname" >$cart</TT >. 3 items of article number 0815 are being added to <TT CLASS="varname" >$another_cart</TT >. </P ><P >
Both, <TT CLASS="varname" >$cart</TT > and <TT CLASS="varname" >$another_cart</TT >, have functions add_item(), remove_item() and a variable items. These are distinct functions and variables. You can think of the objects as something similar to directories in a filesystem. In a filesystem you can have two different files README.TXT, as long as they are in different directories. Just like with directories where you'll have to type the full pathname in order to reach each file from the toplevel directory, you have to specify the complete name of the function you want to call: In PHP terms, the toplevel directory would be the global namespace, and the pathname separator would be <TT CLASS="literal" >-></TT >. Thus, the names <TT CLASS="varname" >$cart->items</TT > and <TT CLASS="varname" >$another_cart->items</TT > name two different variables. Note that the variable is named <TT CLASS="varname" >$cart->items</TT >, not <TT CLASS="varname" >$cart->$items</TT >, that is, a variable name in PHP has only a single dollar sign. </P ><DIV CLASS="informalexample" ><A NAME="AEN5414" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // correct, single $ $cart->items = array("10" => 1); // invalid, because $cart->$items becomes $cart->"" $cart->$items = array("10" => 1); // correct, but may or may not be what was intended: // $cart->$myvar becomes $cart->items $myvar = 'items'; $cart->$myvar = array("10" => 1); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
Within a class definition, you do not know under which name the object will be accessible in your program: at the time the Cart class was written, it was unknown that the object will be named <TT CLASS="varname" >$cart</TT > or <TT CLASS="varname" >$another_cart</TT > later. Thus, you cannot write <TT CLASS="varname" >$cart->items</TT > within the Cart class itself. Instead, in order to be able to access it's own functions and variables from within a class, one can use the pseudo-variable <TT CLASS="varname" >$this</TT > which can be read as 'my own' or 'current object'. Thus, '<TT CLASS="varname" >$this->items[$artnr]</TT > += <TT CLASS="varname" >$num</TT >' can be read as 'add <TT CLASS="varname" >$num</TT > to the <TT CLASS="varname" >$artnr</TT > counter of my own items array' or 'add <TT CLASS="varname" >$num</TT > to the <TT CLASS="varname" >$artnr</TT > counter of the items array within the current object'. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > There are some nice functions to handle classes and objects. You might want to take a look at the <A HREF="#ref.classobj" >Class/Object Functions</A > </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="keyword.extends" ></A ><TT CLASS="literal" >extends</TT ></H2 ><P >
Often you need classes with similar variables and functions to another existing class. In fact, it is good practice to define a generic class which can be used in all your projects and adapt this class for the needs of each of your specific projects. To facilitate this, classes can be extensions of other classes. The extended or derived class has all variables and functions of the base class (this is called 'inheritance' despite the fact that nobody died) and what you add in the extended definition. It is not possible to substract from a class, that is, to undefine any existing functions or variables. An extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'. </P ><DIV CLASS="informalexample" ><A NAME="AEN5434" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class Named_Cart extends Cart { var $owner; function set_owner ($name) { $this->owner = $name; } } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
This defines a class Named_Cart that has all variables and functions of Cart plus an additional variable <TT CLASS="varname" >$owner</TT > and an additional function set_owner(). You create a named cart the usual way and can now set and get the carts owner. You can still use normal cart functions on named carts: </P ><DIV CLASS="informalexample" ><A NAME="AEN5438" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $ncart = new Named_Cart; // Create a named cart $ncart->set_owner("kris"); // Name that cart print $ncart->owner; // print the cart owners name $ncart->add_item("10", 1); // (inherited functionality from cart) ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
This is also called a "parent-child" relationship. You create a class, parent, and use <TT CLASS="literal" >extends</TT > to create a new class <SPAN CLASS="emphasis" ><I CLASS="emphasis" >based</I ></SPAN > on the parent class: the child class. You can even use this new child class and create another class based on this child class. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Classes must be defined before they are used! If you want the class <TT CLASS="literal" >Named_Cart</TT > to extend the class <TT CLASS="literal" >Cart</TT >, you will have to define the class <TT CLASS="literal" >Cart</TT > first. If you want to create another class called <TT CLASS="literal" >Yellow_named_cart</TT > based on the class <TT CLASS="literal" >Named_Cart</TT > you have to define <TT CLASS="literal" >Named_Cart</TT > first. To make it short: the order in which the classes are defined is important. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.oop.constructor" ></A ><TT CLASS="literal" >Constructors</TT ></H2 ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
In PHP 3 and PHP 4 constructors behave differently. The PHP 4 semantics are strongly preferred. </P ></TD ></TR ></TABLE ></DIV ><P >
Constructors are functions in a class that are automatically called when you create a new instance of a class with <TT CLASS="literal" >new</TT >. In PHP 3, a function becomes a constructor when it has the same name as the class. In PHP 4, a function becomes a constructor, when it has the same name as the class it is defined in - the difference is subtle, but crucial (see below). </P ><DIV CLASS="informalexample" ><A NAME="AEN5458" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Works in PHP 3 and PHP 4. class Auto_Cart extends Cart { function Auto_Cart() { $this->add_item ("10", 1); } } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
This defines a class Auto_Cart that is a Cart plus a constructor which initializes the cart with one item of article number "10" each time a new Auto_Cart is being made with "new". Constructors can take arguments and these arguments can be optional, which makes them much more useful. To be able to still use the class without parameters, all parameters to constructors should be made optional by providing default values. </P ><DIV CLASS="informalexample" ><A NAME="AEN5461" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // Works in PHP 3 and PHP 4. class Constructor_Cart extends Cart { function Constructor_Cart($item = "10", $num = 1) { $this->add_item ($item, $num); } } // Shop the same old boring stuff. $default_cart = new Constructor_Cart; // Shop for real... $different_cart = new Constructor_Cart("20", 17); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
You also can use the <TT CLASS="literal" >@</TT > operator to <SPAN CLASS="emphasis" ><I CLASS="emphasis" >mute</I ></SPAN > errors occurring in the constructor, e.g. <TT CLASS="literal" >@new</TT >. </P ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
In PHP 3, derived classes and constructors have a number of limitations. The following examples should be read carefully to understand these limitations. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="informalexample" ><A NAME="AEN5469" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class A { function A() { echo "I am the constructor of A.<br>\n"; } } class B extends A { function C() { echo "I am a regular function.<br>\n"; } } // no constructor is being called in PHP 3. $b = new B; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
In PHP 3, no constructor is being called in the above example. The rule in PHP 3 is: 'A constructor is a function of the same name as the class.'. The name of the class is B, and there is no function called B() in class B. Nothing happens. </P ><P >
This is fixed in PHP 4 by introducing another rule: If a class has no constructor, the constructor of the base class is being called, if it exists. The above example would have printed 'I am the constructor of A.<br>' in PHP 4. </P ><DIV CLASS="informalexample" ><A NAME="AEN5473" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class A { function A() { echo "I am the constructor of A.<br>\n"; } function B() { echo "I am a regular function named B in class A.<br>\n"; echo "I am not a constructor in A.<br>\n"; } } class B extends A { function C() { echo "I am a regular function.<br>\n"; } } // This will call B() as a constructor. $b = new B; ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
In PHP 3, the function B() in class A will suddenly become a constructor in class B, although it was never intended to be. The rule in PHP 3 is: 'A constructor is a function of the same name as the class.'. PHP 3 does not care if the function is being defined in class B, or if it has been inherited. </P ><P >
This is fixed in PHP 4 by modifying the rule to: 'A constructor is a function of the same name as the class it is being defined in.'. Thus in PHP 4, the class B would have no constructor function of its own and the constructor of the base class would have been called, printing 'I am the constructor of A.<br>'. </P ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Neither PHP 3 nor PHP 4 call constructors of the base class automatically from a constructor of a derived class. It is your responsibility to propagate the call to constructors upstream where appropriate. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > There are no destructors in PHP 3 or PHP 4. You may use <A HREF="#function.register-shutdown-function" ><B CLASS="function" >register_shutdown_function()</B ></A > instead to simulate most effects of destructors. </P ></BLOCKQUOTE ></DIV ><P >
Destructors are functions that are called automatically when an object is destroyed, either with <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A > or by simply going out of scope. There are no destructors in PHP. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="keyword.paamayim-nekudotayim" ></A ><TT CLASS="literal" >::</TT ></H2 ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
The following is valid for PHP 4 and later only. </P ></TD ></TR ></TABLE ></DIV ><P >
Sometimes it is useful to refer to functions and variables in base classes or to refer to functions in classes that have not yet any instances. The :: operator is being used for this. </P ><DIV CLASS="informalexample" ><A NAME="AEN5490" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class A { function example() { echo "I am the original function A::example().<br>\n"; } } class B extends A { function example() { echo "I am the redefined function B::example().<br>\n"; A::example(); } } // there is no object of class A. // this will print // I am the original function A::example().<br> A::example(); // create an object of class B. $b = new B; // this will print // I am the redefined function B::example().<br> // I am the original function A::example().<br> $b->example(); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
The above example calls the function example() in class A, but there is no object of class A, so that we cannot write $a->example() or similar. Instead we call example() as a 'class function', that is, as a function of the class itself, not any object of that class. </P ><P >
There are class functions, but there are no class variables. In fact, there is no object at all at the time of the call. Thus, a class function may not use any object variables (but it can use local and global variables), and it may no use <TT CLASS="varname" >$this</TT > at all. </P ><P >
In the above example, class B redefines the function example(). The original definition in class A is shadowed and no longer available, unless you are referring specifically to the implementation of example() in class A using the ::-operator. Write A::example() to do this (in fact, you should be writing parent::example(), as shown in the next section). </P ><P >
In this context, there is a current object and it may have object variables. Thus, when used from WITHIN an object function, you may use <TT CLASS="varname" >$this</TT > and object variables. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="keyword.parent" ></A ><TT CLASS="literal" >parent</TT ></H2 ><P >
You may find yourself writing code that refers to variables and functions in base classes. This is particularly true if your derived class is a refinement or specialisation of code in your base class. </P ><P >
Instead of using the literal name of the base class in your code, you should be using the special name <TT CLASS="literal" >parent</TT >, which refers to the name of your base class as given in the <TT CLASS="literal" >extends</TT > declaration of your class. By doing this, you avoid using the name of your base class in more than one place. Should your inheritance tree change during implementation, the change is easily made by simply changing the <TT CLASS="literal" >extends</TT > declaration of your class. </P ><DIV CLASS="informalexample" ><A NAME="AEN5506" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class A { function example() { echo "I am A::example() and provide basic functionality.<br>\n"; } } class B extends A { function example() { echo "I am B::example() and provide additional functionality.<br>\n"; parent::example(); } } $b = new B; // This will call B::example(), which will in turn call A::example(). $b->example(); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.oop.serialization" ></A >Serializing objects - objects in sessions</H2 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > In PHP 3, objects will lose their class association throughout the process of serialization and unserialization. The resulting variable is of type object, but has no class and no methods, thus it is pretty useless (it has become just like an array with a funny syntax). </P ></BLOCKQUOTE ></DIV ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >V²straha</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
The following information is valid for PHP 4 only. </P ></TD ></TR ></TABLE ></DIV ><P >
<A HREF="#function.serialize" ><B CLASS="function" >serialize()</B ></A > returns a string containing a byte-stream representation of any value that can be stored in PHP. <A HREF="#function.unserialize" ><B CLASS="function" >unserialize()</B ></A > can use this string to recreate the original variable values. Using serialize to save an object will save all variables in an object. The functions in an object will not be saved, only the name of the class. </P ><P >
In order to be able to <A HREF="#function.unserialize" ><B CLASS="function" >unserialize()</B ></A > an object, the class of that object needs to be defined. That is, if you have an object <TT CLASS="varname" >$a</TT > of class A on page1.php and serialize this, you'll get a string that refers to class A and contains all values of variabled contained in <TT CLASS="varname" >$a</TT >. If you want to be able to unserialize this on page2.php, recreating <TT CLASS="varname" >$a</TT > of class A, the definition of class A must be present in page2.php. This can be done for example by storing the class definition of class A in an include file and including this file in both page1.php and page2.php. </P ><DIV CLASS="informalexample" ><A NAME="AEN5522" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // classa.inc: class A { var $one = 1; function show_one() { echo $this->one; } } // page1.php: include("classa.inc"); $a = new A; $s = serialize($a); // store $s somewhere where page2.php can find it. $fp = fopen("store", "w"); fputs($fp, $s); fclose($fp); // page2.php: // this is needed for the unserialize to work properly. include("classa.inc"); $s = implode("", @file("store")); $a = unserialize($s); // now use the function show_one() of the $a object. $a->show_one(); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV ><P >
If you are using sessions and use <A HREF="#function.session-register" ><B CLASS="function" >session_register()</B ></A > to register objects, these objects are serialized automatically at the end of each PHP page, and are unserialized automatically on each of the following pages. This basically means that these objects can show up on any of your pages once they become part of your session. </P ><P >
It is strongly recommended that you include the class definitions of all such registered objects on all of your pages, even if you do not actually use these classes on all of your pages. If you don't and an object is being unserialized without its class definition being present, it will lose its class association and become an object of class <TT CLASS="literal" >stdClass</TT > without any functions available at all, that is, it will become quite useless. </P ><P >
So if in the example above <TT CLASS="varname" >$a</TT > became part of a session by running <TT CLASS="literal" >session_register("a")</TT >, you should include the file <TT CLASS="literal" >classa.inc</TT > on all of your pages, not only page1.php and page2.php. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.oop.magic-functions" ></A >The magic functions <TT CLASS="literal" >__sleep</TT > and <TT CLASS="literal" >__wakeup</TT ></H2 ><P >
<A HREF="#function.serialize" ><B CLASS="function" >serialize()</B ></A > checks if your class has a function with the magic name <TT CLASS="literal" >__sleep</TT >. If so, that function is being run prior to any serialization. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. </P ><P >
The intended use of <TT CLASS="literal" >__sleep</TT > is to close any database connections that object may have, committing pending data or perform similar cleanup tasks. Also, the function is useful if you have very large objects which need not be saved completely. </P ><P >
Conversely, <A HREF="#function.unserialize" ><B CLASS="function" >unserialize()</B ></A > checks for the presence of a function with the magic name <TT CLASS="literal" >__wakeup</TT >. If present, this function can reconstruct any resources that object may have. </P ><P >
The intended use of <TT CLASS="literal" >__wakeup</TT > is to reestablish any database connections that may have been lost during serialization and perform other reinitialization tasks. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.oop.newref" ></A >References inside the constructor</H2 ><P >
Creating references within the constructor can lead to confusing results. This tutorial-like section helps you to avoid problems. <DIV CLASS="informalexample" ><A NAME="AEN5549" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class Foo { function Foo($name) { // create a reference inside the global array $globalref global $globalref; $globalref[] = &$this; // set name to passed value $this->setName($name); // and put it out $this->echoName(); } function echoName() { echo "<br>",$this->name; } function setName($name) { $this->name = $name; } } ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Let us check out if there is a difference between <TT CLASS="varname" >$bar1</TT > which has been created using the copy <TT CLASS="literal" >=</TT > operator and <TT CLASS="varname" >$bar2</TT > which has been created using the reference <TT CLASS="literal" >=&</TT > operator... <DIV CLASS="informalexample" ><A NAME="AEN5556" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $bar1 = new Foo('set in constructor'); $bar1->echoName(); $globalref[0]->echoName(); /* output: set in constructor set in constructor set in constructor */ $bar2 =& new Foo('set in constructor'); $bar2->echoName(); $globalref[1]->echoName(); /* output: set in constructor set in constructor set in constructor */ ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Apparently there is no difference, but in fact there is a very significant one: <TT CLASS="varname" >$bar1</TT > and <TT CLASS="varname" >$globalref[0]</TT > are _NOT_ referenced, they are NOT the same variable. This is because "new" does not return a reference by default, instead it returns a copy. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > There is no performance loss (since PHP 4 and up use reference counting) returning copies instead of references. On the contrary it is most often better to simply work with copies instead of references, because creating references takes some time where creating copies virtually takes no time (unless none of them is a large array or object and one of them gets changed and the other(s) one(s) subsequently, then it would be wise to use references to change them all concurrently). </P ></BLOCKQUOTE ></DIV > To prove what is written above let us watch the code below. <DIV CLASS="informalexample" ><A NAME="AEN5563" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // now we will change the name. what do you expect? // you could expect that both $bar1 and $globalref[0] change their names... $bar1->setName('set from outside'); // as mentioned before this is not the case. $bar1->echoName(); $globalref[0]->echoName(); /* output: set from outside set in constructor */ // let us see what is different with $bar2 and $globalref[1] $bar2->setName('set from outside'); // luckily they are not only equal, they are the same variable // thus $bar2->name and $globalref[1]->name are the same too $bar2->echoName(); $globalref[1]->echoName(); /* output: set from outside set from outside */ ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Another final example, try to understand it. <DIV CLASS="informalexample" ><A NAME="AEN5566" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class A { function A($i) { $this->value = $i; // try to figure out why we do not need a reference here $this->b = new B($this); } function createRef() { $this->c = new B($this); } function echoValue() { echo "<br>","class ",get_class($this),': ',$this->value; } } class B { function B(&$a) { $this->a = &$a; } function echoValue() { echo "<br>","class ",get_class($this),': ',$this->a->value; } } // try to understand why using a simple copy here would yield // in an undesired result in the *-marked line $a =& new A(10); $a->createRef(); $a->echoValue(); $a->b->echoValue(); $a->c->echoValue(); $a->value = 11; $a->echoValue(); $a->b->echoValue(); // * $a->c->echoValue(); /* output: class A: 10 class B: 10 class B: 10 class A: 11 class B: 11 class B: 11 */ ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.oop.object-comparison-php4" ></A >Comparing objects in PHP 4</H2 ><P >
In PHP 4, objects are compared in a very simple manner, namely: Two object instances are equal if they have the same attributes and values, and are instances of the same class. Similar rules are applied when comparing two objects using the identity operator (<TT CLASS="literal" >===</TT >). </P ><P >
If we were to execute the code in the example below: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5573" ></A ><P ><B >P°φklad 13-1. Example of object comparison in PHP 4</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function bool2str($bool) { if ($bool === false) { return 'FALSE'; } else { return 'TRUE'; } } function compareObjects(&$o1, &$o2) { echo 'o1 == o2 : '.bool2str($o1 == $o2)."\n"; echo 'o1 != o2 : '.bool2str($o1 != $o2)."\n"; echo 'o1 === o2 : '.bool2str($o1 === $o2)."\n"; echo 'o1 !== o2 : '.bool2str($o1 !== $o2)."\n"; } class Flag { var $flag; function Flag($flag=true) { $this->flag = $flag; } } class SwitchableFlag extends Flag { function turnOn() { $this->flag = true; } function turnOff() { $this->flag = false; } } $o = new Flag(); $p = new Flag(false); $q = new Flag(); $r = new SwitchableFlag(); echo "Compare instances created with the same parameters\n"; compareObjects($o, $q); echo "\nCompare instances created with different parameters\n"; compareObjects($o, $p); echo "\nCompare an instance of a parent class with one from a subclass\n"; compareObjects($o, $r); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > We will see: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Compare instances created with the same parameters o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE Compare instances created with different parameters o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE Compare an instance of a parent class with one from a subclass o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE</PRE ></TD ></TR ></TABLE > Which is the output we will expect to obtain given the comparison rules above. Only instances with the same values for their attributes and from the same class are considered equal and identical. </P ><P >
Even in the cases where we have object composition, the same comparison rules apply. In the example below we create a container class that stores an associative array of <B CLASS="classname" >Flag</B > objects. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5579" ></A ><P ><B >P°φklad 13-2. Compound object comparisons in PHP 4</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class FlagSet { var $set; function FlagSet($flagArr = array()) { $this->set = $flagArr; } function addFlag($name, $flag) { $this->set[$name] = $flag; } function removeFlag($name) { if (array_key_exists($name, $this->set)) { unset($this->set[$name]); } } } $u = new FlagSet(); $u->addFlag('flag1', $o); $u->addFlag('flag2', $p); $v = new FlagSet(array('flag1'=>$q, 'flag2'=>$p)); $w = new FlagSet(array('flag1'=>$q)); echo "\nComposite objects u(o,p) and v(q,p)\n"; compareObjects($u, $v); echo "\nu(o,p) and w(q)\n"; compareObjects($u, $w); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Which gives the expected output: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Composite objects u(o,p) and v(q,p) o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE u(o,p) and w(q) o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE</PRE ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.oop.object-comparison-php5" ></A >Comparing objects in PHP 5</H2 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Toto roz╣φ°enφ je <SPAN CLASS="emphasis" ><I CLASS="emphasis" >EXPERIMENT┴LN═</I ></SPAN >. Chovßnφ tohoto roz╣φ°enφ, nßzvy funkcφ a v╣echno ostatnφ, co je zde zdokumentovßno, se v budoucφch verzφch PHP m∙╛e bez ohlß╣enφ zm∞nit. Berte to v ·vahu a pou╛φvejte tento modul na vlastnφ nebezpeΦφ.</P ></TD ></TR ></TABLE ></DIV ><P >
In PHP 5, object comparison is a more complicated than in PHP 4 and more in accordance to what one will expect from an Object Oriented Language (not that PHP 5 is such a language). </P ><P >
When using the comparison operator (<TT CLASS="literal" >==</TT >), object variables are compared in a simple manner, namely: Two object instances are equal if they have the same attributes and values, and are instances of the same class. </P ><P >
On the other hand, when using the identity operator (<TT CLASS="literal" >===</TT >), object variables are identical if and only if they refer to the same instance of the same class. </P ><P >
An example will clarify these rules. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5594" ></A ><P ><B >P°φklad 13-3. Example of object comparison in PHP 5</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function bool2str($bool) { if ($bool === false) { return 'FALSE'; } else { return 'TRUE'; } } function compareObjects(&$o1, &$o2) { echo 'o1 == o2 : '.bool2str($o1 == $o2)."\n"; echo 'o1 != o2 : '.bool2str($o1 != $o2)."\n"; echo 'o1 === o2 : '.bool2str($o1 === $o2)."\n"; echo 'o1 !== o2 : '.bool2str($o1 !== $o2)."\n"; } class Flag { var $flag; function Flag($flag=true) { $this->flag = $flag; } } class OtherFlag { var $flag; function OtherFlag($flag=true) { $this->flag = $flag; } } $o = new Flag(); $p = new Flag(); $q = $o; $r = new OtherFlag(); echo "Two instances of the same class\n"; compareObjects($o, $p); echo "\nTwo references to the same instance\n"; compareObjects($o, $q); echo "\nInstances of two different classes\n"; compareObjects($o, $r); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > This example will output: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Two instances of the same class o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : FALSE o1 !== o2 : TRUE Two references to the same instance o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE Instances of two different classes o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE</PRE ></TD ></TR ></TABLE > </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="language.references" >Kapitola 14. Vysv∞tlenφ referencφ (odkaz∙)</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="language.references.whatare" ></A >Co jsou reference</H2 ><P >
Reference (odkazy) jsou prost°edek, jak v PHP p°istupovat k tΘmu╛ obsahu prom∞nnΘ pod r∙zn²mi jmΘny. Nejsou to ukazatele (pointery) jako v C, jsou to aliasy v tabulce symbol∙. Uv∞domte si, ╛e v PHP je rozdφl mezi nßzvem prom∞nnΘ a jejφm obsahem, tak╛e stejn² obsah m∙╛e mφt r∙znΘ nßzvy. Nejbli╛╣φ analogiφ jsou nßzvy soubor∙ a soubory v UNIXu - nßzvy prom∞nn²ch jsou polo╛ky adresß°e, obsahy prom∞nn²ch samotnΘ soubory. Na reference m∙╛e b²t nazφrßno jako na hardlinky v UNIXovΘm systΘmu soubor∙. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.references.whatdo" ></A >Co reference d∞lajφ</H2 ><P >
PHP reference umo╛≥ujφ zajistit, aby dv∞ prom∞nnΘ odkazovaly na tent²╛ obsah. Tzn. kdy╛ provedete: <DIV CLASS="informalexample" ><A NAME="AEN5606" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a =& $b</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > znamenß to, ╛e <TT CLASS="varname" >$a</TT > a <TT CLASS="varname" >$b</TT > ukazujφ na stejnou prom∞nnou. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <TT CLASS="varname" >$a</TT > a <TT CLASS="varname" >$b</TT > jsou zde ·pln∞ ekvivalentnφ, tj. nikoliv ╛e <TT CLASS="varname" >$a</TT > ukazuje na <TT CLASS="varname" >$b</TT > apod., n²br╛ ╛e <TT CLASS="varname" >$a</TT > a <TT CLASS="varname" >$b</TT > ukazujφ na stejnΘ mφsto. </P ></BLOCKQUOTE ></DIV > </P ><P >
Stejnß syntaxe se m∙╛e pou╛φt s funkcemi, kterΘ vracφ reference a s operßtorem <TT CLASS="literal" >new</TT > (v PHP 4.0.4 a pozd∞j╣φch): <DIV CLASS="informalexample" ><A NAME="AEN5620" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$bar =& new fooclass(); $foo =& find_var ($bar);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Nepou╛itφ operßtoru <TT CLASS="literal" >&</TT > zp∙sobφ zkopφrovßnφ objektu. Kdy╛ ve t°φd∞ pou╛ijete <TT CLASS="literal" >$this</TT >, bude se pracovat s aktußlnφ instancφ t°φdy. P°i°azenφ bez <TT CLASS="literal" >&</TT > zkopφruje instanci (nap°. objektu) a <TT CLASS="literal" >$this</TT > bude pracovat s touto kopiφ, co╛ nenφ v╛dy to, co se po╛aduje. V∞t╣inou chcete mφt jedinou instanci, s nφ╛ budete pracovat, kv∙li rychlosti a alokaci pam∞ti. </P ></BLOCKQUOTE ></DIV ><P >
Druhou v∞cφ, kterou reference d∞lajφ, je p°edßvßnφ prom∞nn²ch odkazem. To se d∞lß vytvo°enφm lokßlnφ prom∞nnΘ ve funkci a prom∞nnΘ v kontextu volajφcφho prost°edφ, kdy se odkazuje na tent²╛ obsah. Nap°φklad: <DIV CLASS="informalexample" ><A NAME="AEN5629" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function foo (&$var) { $var++; } $a=5; foo ($a);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > nastavφ do <TT CLASS="varname" >$a</TT > hodnotu 6. To proto, ╛e ve funkci <TT CLASS="varname" >foo</TT > prom∞nnß <TT CLASS="varname" >$var</TT > odkazuje tent²╛ obsah jako <TT CLASS="varname" >$a</TT >. Viz detailn∞j╣φ vysv∞tlenφ o <A HREF="#language.references.pass" >p°edßvßnφ odkazem</A >. </P ><P >
T°etφ v∞cφ, kterou mohou reference d∞lat, je <A HREF="#language.references.return" >vracenφ p°es reference</A >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.references.arent" ></A >Co reference nejsou</H2 ><P >
Jak ji╛ bylo °eΦeno, reference nejsou ukazatele. To znamenß, ╛e tento konstrukt nebude d∞lat to, co oΦekßvßte: <DIV CLASS="informalexample" ><A NAME="AEN5641" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function foo (&$var) { $var =& $GLOBALS["baz"]; } foo($bar);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Nastane to, ╛e <TT CLASS="varname" >$var</TT > ve funkci <TT CLASS="varname" >foo</TT > bude p°i°azena <TT CLASS="varname" >$bar</TT > ve volajφcφm kontextu, av╣ak potΘ bude p°i°azena <TT CLASS="varname" >$GLOBALS["baz"]</TT >. Nenφ zp∙sob, jak p°i°adit <TT CLASS="varname" >$bar</TT > ve volajφcφm kontextu n∞Φemu jinΘmu za pou╛itφ mechanismu referencφ, proto╛e <TT CLASS="varname" >$bar</TT > nenφ ve funkci <TT CLASS="varname" >foo</TT > dostupnß (je reprezentovßna <TT CLASS="varname" >$var</TT >, ale <TT CLASS="varname" >$var</TT > mß pouze obsah a nikoli spojenφ nßzvu s hodnotou v tabulce symbol∙). </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.references.pass" ></A >P°edßvßnφ referencφ (odkazem)</H2 ><P >
M∙╛ete p°edßvat prom∞nnou do funkce pomocφ odkazu, tak╛e funkce m∙╛e modifikovat jejφ argumenty. Syntaxe je nßsledujφcφ: <DIV CLASS="informalexample" ><A NAME="AEN5656" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function foo (&$var) { $var++; } $a=5; foo ($a); // $a je te∩ 6</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > V╣imn∞te si, ╛e ve volßnφ funkce nenφ znak reference - pouze v jejφ definici. Samotnß definice funkce staΦφ na sprßvnΘ p°edßvßnφ argumentu odkazem. </P ><P >
Nßsledujφcφ v∞ci lze p°edßvat referencφ: <P ></P ><UL ><LI ><P >
Prom∞nnß, nap°. <TT CLASS="literal" >foo($a)</TT > </P ></LI ><LI ><P >
Konstrukt s new, nap°. <TT CLASS="literal" >foo(new foobar())</TT > </P ></LI ><LI ><P >
Reference, vracenß z funkce, nap°.: <DIV CLASS="informalexample" ><A NAME="AEN5668" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function &bar() { $a = 5; return $a; } foo(bar());</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Viz takΘ vysv∞tlenφ <A HREF="#language.references.return" >vracenφ p°es reference</A >. </P ></LI ></UL > </P ><P >
«ßdnΘ jinΘ v²razy nemohou b²t p°edßvßny odkazem, v²sledek tohoto nenφ definovßn. Nap°φklad, nßsledujφcφ ukßzky p°edßvßnφ odkazem jsou neplatnΘ: <DIV CLASS="informalexample" ><A NAME="AEN5672" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function bar() // V╣imn∞te si chyb∞jφcφho & { $a = 5; return $a; } foo(bar()); foo($a = 5) // V²raz, nikoli prom∞nnß foo(5) // Konstanta, nikoli prom∞nnß</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Tyto po╛adavky platφ pro PHP 4.0.4 a pozd∞j╣φ. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.references.return" ></A >Vracenφ referencφ</H2 ><P >
Vracenφ odkazem je u╛iteΦnΘ, kdy╛ chcete pou╛φt funkci k nalezenφ prom∞nnΘ, kterß by m∞la b²t odkazu p°i°azena. P°i vracenφ referencφ pou╛ijte tuto syntaxi: <DIV CLASS="informalexample" ><A NAME="AEN5677" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function &find_var ($param) { ...n∞jak² k≤d... return $found_var; } $foo =& find_var ($bar); $foo->x = 2;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > V tomto p°φkladu by bylo funkcφ <TT CLASS="varname" >find_var</TT > nastaveno vlastnictvφ tΘho╛ objektu, nikoli jeho kopie, jak by se stalo bez pou╛itφ syntaxe bez odkaz∙. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Narozdφl od p°edßvßnφ parametru, zde musφte <TT CLASS="literal" >&</TT > pou╛φt na obou mφstech - k indikaci, ╛e vracφte odkaz a nikoli kopii jako obvykle, a k indikaci p°i°azenφ reference do <TT CLASS="varname" >$foo</TT > namφsto b∞╛nΘho p°i°azenφ (hodnoty). </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.references.unset" ></A >Odnastavenφ odkaz∙</H2 ><P >
Kdy╛ odnastavφte referenci, p°eru╣φte vazbu mezi nßzvem prom∞nnΘ a jejφm obsahem. To neznamenß, ╛e by obsah byl zniΦen. Nap°φklad: <DIV CLASS="informalexample" ><A NAME="AEN5687" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a = 1; $b =& $a; unset ($a);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > neodnastavφ <TT CLASS="varname" >$b</TT >, n²br╛ pouze <TT CLASS="varname" >$a</TT >. </P ><P >
Znovu je dobrΘ si p°ipomenout analogii s UNIXov²m p°φkazem <B CLASS="command" >unlink</B >. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="language.references.spot" ></A >Dal╣φ v²skyt referencφ</H2 ><P >
Mnoho syntaktick²ch konstrukt∙ v PHP je implementovßno p°es odkazov² mechanismus, tak╛e v╣e, co bylo °eΦeno v²╣e o p°i°azovßnφ referencφ, platφ i na tyto konstrukty. N∞kterΘ konstrukty, jako p°edßvßnφ a vracenφ p°es odkazy, byly ji╛ zmφn∞ny. Ostatnφ konstrukty pou╛φvajφcφ reference jsou: </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="references.global" ></A >odkazy <TT CLASS="literal" >global</TT ></H3 ><P >
Kdy╛ deklarujete prom∞nnou jako <B CLASS="command" >global $var</B >, ve skuteΦnosti vytvß°φte odkaz na globßlnφ prom∞nnou. Tzn. je to totΘ╛, jako: <DIV CLASS="informalexample" ><A NAME="AEN5701" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$var =& $GLOBALS["var"];</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
To znamenß, nap°φklad, ╛e odnastavenφ <TT CLASS="varname" >$var</TT > neodnastavφ globßlnφ prom∞nnou. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="references.this" ></A ><TT CLASS="literal" >$this</TT ></H3 ><P >
V metod∞ objektu je <TT CLASS="varname" >$this</TT > v╛dy odkazem na volajφcφ objekt. </P ></DIV ></DIV ></DIV ></DIV ><DIV CLASS="PART" ><A NAME="security" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >III. Security</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT >15. <A HREF="#security.index" >Security</A ></DT ></DL ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="security.index" >Kapitola 15. Security</A ></H1 ><P >
PHP is a powerful language and the interpreter, whether included in a web server as a module or executed as a separate <SPAN CLASS="acronym" >CGI</SPAN > binary, is able to access files, execute commands and open network connections on the server. These properties make anything run on a web server insecure by default. PHP is designed specifically to be a more secure language for writing CGI programs than Perl or C, and with correct selection of compile-time and runtime configuration options, and proper coding practices, it can give you exactly the combination of freedom and security you need. </P ><P >
As there are many different ways of utilizing PHP, there are many configuration options controlling its behaviour. A large selection of options guarantees you can use PHP for a lot of purposes, but it also means there are combinations of these options and server configurations that result in an insecure setup. </P ><P >
The configuration flexibility of PHP is equally rivalled by the code flexibility. PHP can be used to build complete server applications, with all the power of a shell user, or it can be used for simple server-side includes with little risk in a tightly controlled environment. How you build that environment, and how secure it is, is largely up to the PHP developer. </P ><P >
This chapter starts with some general security advice, explains the different configuration option combinations and the situations they can be safely used, and describes different considerations in coding for different levels of security. </P ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.general" ></A >General considerations</H2 ><P >
A completely secure system is a virtual impossibility, so an approach often used in the security profession is one of balancing risk and usability. If every variable submitted by a user required two forms of biometric validation (such as a retinal scan and a fingerprint), you would have an extremely high level of accountability. It would also take half an hour to fill out a fairly complex form, which would tend to encourage users to find ways of bypassing the security. </P ><P >
The best security is often inobtrusive enough to suit the requirements without the user being prevented from accomplishing their work, or over-burdening the code author with excessive complexity. Indeed, some security attacks are merely exploits of this kind of overly built security, which tends to erode over time. </P ><P >
A phrase worth remembering: A system is only as good as the weakest link in a chain. If all transactions are heavily logged based on time, location, transaction type, etc. but the user is only verified based on a single cookie, the validity of tying the users to the transaction log is severely weakened. </P ><P >
When testing, keep in mind that you will not be able to test all possibilities for even the simplest of pages. The input you may expect will be completely unrelated to the input given by a disgruntled employee, a cracker with months of time on their hands, or a housecat walking across the keyboard. This is why it's best to look at the code from a logical perspective, to discern where unexpected data can be introduced, and then follow how it is modified, reduced, or amplified. </P ><P >
The Internet is filled with people trying to make a name for themselves by breaking your code, crashing your site, posting inappropriate content, and otherwise making your day interesting. It doesn't matter if you have a small or large site, you are a target by simply being online, by having a server that can be connected to. Many cracking programs do not discern by size, they simply trawl massive IP blocks looking for victims. Try not to become one. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.cgi-bin" ></A >Installed as CGI binary</H2 ><DIV CLASS="sect2" ><H3 CLASS="sect2" ><A NAME="security.cgi-bin.attacks" ></A >Possible attacks</H3 ><P >
Using PHP as a <SPAN CLASS="acronym" >CGI</SPAN > binary is an option for setups that for some reason do not wish to integrate PHP as a module into server software (like Apache), or will use PHP with different kinds of CGI wrappers to create safe chroot and setuid environments for scripts. This setup usually involves installing executable PHP binary to the web server cgi-bin directory. CERT advisory <A HREF="http://www.cert.org/advisories/CA-1996-11.html" TARGET="_top" >CA-96.11</A > recommends against placing any interpreters into cgi-bin. Even if the PHP binary can be used as a standalone interpreter, PHP is designed to prevent the attacks this setup makes possible: </P ><P ></P ><UL ><LI ><P >
Accessing system files: <TT CLASS="filename" >http://my.host/cgi-bin/php?/etc/passwd</TT > </P ><P >
The query information in a url after the question mark (?) is passed as command line arguments to the interpreter by the CGI interface. Usually interpreters open and execute the file specified as the first argument on the command line. </P ><P >
When invoked as a CGI binary, PHP refuses to interpret the command line arguments. </P ></LI ><LI ><P >
Accessing any web document on server: <TT CLASS="filename" >http://my.host/cgi-bin/php/secret/doc.html</TT > </P ><P >
The path information part of the url after the PHP binary name, <TT CLASS="filename" >/secret/doc.html</TT > is conventionally used to specify the name of the file to be opened and interpreted by the <SPAN CLASS="acronym" >CGI</SPAN > program. Usually some web server configuration directives (Apache: Action) are used to redirect requests to documents like <TT CLASS="filename" >http://my.host/secret/script.php</TT > to the PHP interpreter. With this setup, the web server first checks the access permissions to the directory <TT CLASS="filename" >/secret</TT >, and after that creates the redirected request <TT CLASS="filename" >http://my.host/cgi-bin/php/secret/script.php</TT >. Unfortunately, if the request is originally given in this form, no access checks are made by web server for file <TT CLASS="filename" >/secret/script.php</TT >, but only for the <TT CLASS="filename" >/cgi-bin/php</TT > file. This way any user able to access <TT CLASS="filename" >/cgi-bin/php</TT > is able to access any protected document on the web server. </P ><P >
In PHP, compile-time configuration option <A HREF="#install.configure.enable-force-cgi-redirect" >--enable-force-cgi-redirect</A > and runtime configuration directives <A HREF="#ini.doc-root" >doc_root</A > and <A HREF="#ini.user-dir" >user_dir</A > can be used to prevent this attack, if the server document tree has any directories with access restrictions. See below for full the explanation of the different combinations. </P ></LI ></UL ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.cgi-bin.default" ></A >Case 1: only public files served</H3 ><P >
If your server does not have any content that is not restricted by password or ip based access control, there is no need for these configuration options. If your web server does not allow you to do redirects, or the server does not have a way to communicate to the PHP binary that the request is a safely redirected request, you can specify the option <A HREF="#install.configure.enable-force-cgi-redirect" >--enable-force-cgi-redirect</A > to the configure script. You still have to make sure your PHP scripts do not rely on one or another way of calling the script, neither by directly <TT CLASS="filename" >http://my.host/cgi-bin/php/dir/script.php</TT > nor by redirection <TT CLASS="filename" >http://my.host/dir/script.php</TT >. </P ><P >
Redirection can be configured in Apache by using AddHandler and Action directives (see below). </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.cgi-bin.force-redirect" ></A >Case 2: using --enable-force-cgi-redirect</H3 ><P >
This compile-time option prevents anyone from calling PHP directly with a url like <TT CLASS="filename" >http://my.host/cgi-bin/php/secretdir/script.php</TT >. Instead, PHP will only parse in this mode if it has gone through a web server redirect rule. </P ><P >
Usually the redirection in the Apache configuration is done with the following directives: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="apache-conf" >Action php-script /cgi-bin/php AddHandler php-script .php</PRE ></TD ></TR ></TABLE ><P >
This option has only been tested with the Apache web server, and relies on Apache to set the non-standard CGI environment variable <TT CLASS="envar" >REDIRECT_STATUS</TT > on redirected requests. If your web server does not support any way of telling if the request is direct or redirected, you cannot use this option and you must use one of the other ways of running the CGI version documented here. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.cgi-bin.doc-root" ></A >Case 3: setting doc_root or user_dir</H3 ><P >
To include active content, like scripts and executables, in the web server document directories is sometimes considered an insecure practice. If, because of some configuration mistake, the scripts are not executed but displayed as regular HTML documents, this may result in leakage of intellectual property or security information like passwords. Therefore many sysadmins will prefer setting up another directory structure for scripts that are accessible only through the PHP CGI, and therefore always interpreted and not displayed as such. </P ><P >
Also if the method for making sure the requests are not redirected, as described in the previous section, is not available, it is necessary to set up a script doc_root that is different from web document root. </P ><P >
You can set the PHP script document root by the configuration directive <A HREF="#ini.doc-root" >doc_root</A > in the <A HREF="#configuration.file" >configuration file</A >, or you can set the environment variable <TT CLASS="envar" >PHP_DOCUMENT_ROOT</TT >. If it is set, the CGI version of PHP will always construct the file name to open with this <TT CLASS="parameter" ><I >doc_root</I ></TT > and the path information in the request, so you can be sure no script is executed outside this directory (except for <TT CLASS="parameter" ><I >user_dir</I ></TT > below). </P ><P >
Another option usable here is <A HREF="#ini.user-dir" >user_dir</A >. When user_dir is unset, only thing controlling the opened file name is <TT CLASS="parameter" ><I >doc_root</I ></TT >. Opening an url like <TT CLASS="filename" >http://my.host/~user/doc.php</TT > does not result in opening a file under users home directory, but a file called <TT CLASS="filename" >~user/doc.php</TT > under doc_root (yes, a directory name starting with a tilde [<TT CLASS="literal" >~</TT >]). </P ><P >
If user_dir is set to for example <TT CLASS="filename" >public_php</TT >, a request like <TT CLASS="filename" >http://my.host/~user/doc.php</TT > will open a file called <TT CLASS="filename" >doc.php</TT > under the directory named <TT CLASS="filename" >public_php</TT > under the home directory of the user. If the home of the user is <TT CLASS="filename" >/home/user</TT >, the file executed is <TT CLASS="filename" >/home/user/public_php/doc.php</TT >. </P ><P >
<TT CLASS="parameter" ><I >user_dir</I ></TT > expansion happens regardless of the <TT CLASS="parameter" ><I >doc_root</I ></TT > setting, so you can control the document root and user directory access separately. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.cgi-bin.shell" ></A >Case 4: PHP parser outside of web tree</H3 ><P >
A very secure option is to put the PHP parser binary somewhere outside of the web tree of files. In <TT CLASS="filename" >/usr/local/bin</TT >, for example. The only real downside to this option is that you will now have to put a line similar to: <DIV CLASS="informalexample" ><A NAME="AEN5800" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >#!/usr/local/bin/php</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > as the first line of any file containing PHP tags. You will also need to make the file executable. That is, treat it exactly as you would treat any other CGI script written in Perl or sh or any other common scripting language which uses the <TT CLASS="literal" >#!</TT > shell-escape mechanism for launching itself. </P ><P >
To get PHP to handle <TT CLASS="envar" >PATH_INFO</TT > and <TT CLASS="envar" >PATH_TRANSLATED</TT > information correctly with this setup, the PHP parser should be compiled with the <A HREF="#install.configure.enable-discard-path" >--enable-discard-path</A > configure option. </P ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.apache" ></A >Installed as an Apache module</H2 ><P >
When PHP is used as an Apache module it inherits Apache's user permissions (typically those of the "nobody" user). This has several impacts on security and authorization. For example, if you are using PHP to access a database, unless that database has built-in access control, you will have to make the database accessible to the "nobody" user. This means a malicious script could access and modify the database, even without a username and password. It's entirely possible that a web spider could stumble across a database administrator's web page, and drop all of your databases. You can protect against this with Apache authorization, or you can design your own access model using LDAP, <TT CLASS="filename" >.htaccess</TT > files, etc. and include that code as part of your PHP scripts. </P ><P >
Often, once security is established to the point where the PHP user (in this case, the apache user) has very little risk attached to it, it is discovered that PHP is now prevented from writing any files to user directories. Or perhaps it has been prevented from accessing or changing databases. It has equally been secured from writing good and bad files, or entering good and bad database transactions. </P ><P >
A frequent security mistake made at this point is to allow apache root permissions, or to escalate apache's abilitites in some other way. </P ><P >
Escalating the Apache user's permissions to root is extremely dangerous and may compromise the entire system, so sudo'ing, chroot'ing, or otherwise running as root should not be considered by those who are not security professionals. </P ><P >
There are some simpler solutions. By using <A HREF="#ini.open-basedir" >open_basedir</A > you can control and restrict what directories are allowed to be used for PHP. You can also set up apache-only areas, to restrict all web based activity to non-user, or non-system, files. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.filesystem" ></A >Filesystem Security</H2 ><P >
PHP is subject to the security built into most server systems with respect to permissions on a file and directory basis. This allows you to control which files in the filesystem may be read. Care should be taken with any files which are world readable to ensure that they are safe for reading by all users who have access to that filesystem. </P ><P >
Since PHP was designed to allow user level access to the filesystem, it's entirely possible to write a PHP script that will allow you to read system files such as /etc/passwd, modify your ethernet connections, send massive printer jobs out, etc. This has some obvious implications, in that you need to ensure that the files that you read from and write to are the appropriate ones. </P ><P >
Consider the following script, where a user indicates that they'd like to delete a file in their home directory. This assumes a situation where a PHP web interface is regularly used for file management, so the Apache user is allowed to delete files in the user home directories. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5822" ></A ><P ><B >P°φklad 15-1. Poor variable checking leads to....</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // remove a file from the user's home directory $username = $_POST['user_submitted_name']; $homedir = "/home/$username"; $file_to_delete = "$userfile"; unlink ("$homedir/$userfile"); echo "$file_to_delete has been deleted!"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Since the username is postable from a user form, they can submit a username and file belonging to someone else, and delete files. In this case, you'd want to use some other form of authentication. Consider what could happen if the variables submitted were "../etc/" and "passwd". The code would then effectively read: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5825" ></A ><P ><B >P°φklad 15-2. ... A filesystem attack</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // removes a file from anywhere on the hard drive that // the PHP user has access to. If PHP has root access: $username = "../etc/"; $homedir = "/home/../etc/"; $file_to_delete = "passwd"; unlink ("/home/../etc/passwd"); echo "/home/../etc/passwd has been deleted!"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > There are two important measures you should take to prevent these issues. <P ></P ><UL ><LI ><P >
Only allow limited permissions to the PHP web user binary. </P ></LI ><LI ><P >
Check all variables which are submitted. </P ></LI ></UL > Here is an improved script: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5833" ></A ><P ><B >P°φklad 15-3. More secure file name checking</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // removes a file from the hard drive that // the PHP user has access to. $username = $_SERVER['REMOTE_USER']; // using an authentication mechanisim $homedir = "/home/$username"; $file_to_delete = basename("$userfile"); // strip paths unlink ($homedir/$file_to_delete); $fp = fopen("/home/logging/filedelete.log","+a"); //log the deletion $logstring = "$username $homedir $file_to_delete"; fputs ($fp, $logstring); fclose($fp); echo "$file_to_delete has been deleted!"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > However, even this is not without it's flaws. If your authentication system allowed users to create their own user logins, and a user chose the login "../etc/", the system is once again exposed. For this reason, you may prefer to write a more customized check: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5836" ></A ><P ><B >P°φklad 15-4. More secure file name checking</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $username = $_SERVER['REMOTE_USER']; // using an authentication mechanisim $homedir = "/home/$username"; if (!ereg('^[^./][^/]*$', $userfile)) die('bad filename'); //die, do not process if (!ereg('^[^./][^/]*$', $username)) die('bad username'); //die, do not process //etc... ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Depending on your operating system, there are a wide variety of files which you should be concerned about, including device entries (/dev/ or COM1), configuration files (/etc/ files and the .ini files), well known file storage areas (/home/, My Documents), etc. For this reason, it's usually easier to create a policy where you forbid everything except for what you explicitly allow. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.database" ></A >Database Security</H2 ><P >
Nowadays, databases are cardinal components of any web based application by enabling websites to provide varying dynamic content. Since very sensitive or secret information can be stored in a database, you should strongly consider protecting your databases. </P ><P >
To retrieve or to store any information you need to connect to the database, send a legitimate query, fetch the result, and close the connection. Nowadays, the commonly used query language in this interaction is the Structured Query Language (SQL). See how an attacker can <A HREF="#security.database.sql-injection" >tamper with an SQL query</A >. </P ><P >
As you can surmise, PHP cannot protect your database by itself. The following sections aim to be an introduction into the very basics of how to access and manipulate databases within PHP scripts. </P ><P >
Keep in mind this simple rule: defense in depth. The more places you take action to increase the protection of your database, the less probability of an attacker succeeding in exposing or abusing any stored information. Good design of the database schema and the application deals with your greatest fears. </P ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.database.design" ></A >Designing Databases</H3 ><P >
The first step is always to create the database, unless you want to use one from a third party. When a database is created, it is assigned to an owner, who executed the creation statement. Usually, only the owner (or a superuser) can do anything with the objects in that database, and in order to allow other users to use it, privileges must be granted. </P ><P >
Applications should never connect to the database as its owner or a superuser, because these users can execute any query at will, for example, modifying the schema (e.g. dropping tables) or deleting its entire content. </P ><P >
You may create different database users for every aspect of your application with very limited rights to database objects. The most required privileges should be granted only, and avoid that the same user can interact with the database in different use cases. This means that if intruders gain access to your database using your applications credentials, they can only effect as many changes as your application can. </P ><P >
You are encouraged not to implement all the business logic in the web application (i.e. your script), instead do it in the database schema using views, triggers or rules. If the system evolves, new ports will be intended to open to the database, and you have to re-implement the logic in each separate database client. Over and above, triggers can be used to transparently and automatically handle fields, which often provides insight when debugging problems with your application or tracing back transactions. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.database.connection" ></A >Connecting to Database</H3 ><P >
You may want to estabilish the connections over SSL to encrypt client/server communications for increased security, or you can use ssh to encrypt the network connection between clients and the database server. If either of these is used, then monitoring your traffic and gaining information about your database will be difficult for a would-be attacker. </P ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.database.storage" ></A >Encrypted Storage Model</H3 ><P >
SSL/SSH protects data travelling from the client to the server, SSL/SSH does not protect the persistent data stored in a database. SSL is an on-the-wire protocol. </P ><P >
Once an attacker gains access to your database directly (bypassing the webserver), the stored sensitive data may be exposed or misused, unless the information is protected by the database itself. Encrypting the data is a good way to mitigate this threat, but very few databases offer this type of data encryption. </P ><P >
The easiest way to work around this problem is to first create your own encryption package, and then use it from within your PHP scripts. PHP can assist you in this with several extensions, such as <A HREF="#ref.mcrypt" >Mcrypt</A > and <A HREF="#ref.mhash" >Mhash</A >, covering a wide variety of encryption algorithms. The script encrypts the data before inserting it into the database, and decrypts it when retrieving. See the references for further examples of how encryption works. </P ><P >
In case of truly hidden data, if its raw representation is not needed (i.e. not be displayed), hashing may also be taken into consideration. The well-known example for the hashing is storing the MD5 hash of a password in a database, instead of the password itself. See also <A HREF="#function.crypt" ><B CLASS="function" >crypt()</B ></A > and <A HREF="#function.md5" ><B CLASS="function" >md5()</B ></A >. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5866" ></A ><P ><B >P°φklad 15-5. Using hashed password field</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >// storing password hash $query = sprintf("INSERT INTO users(name,pwd) VALUES('%s','%s');", addslashes($username), md5($password)); $result = pg_exec($connection, $query); // querying if user submitted the right password $query = sprintf("SELECT 1 FROM users WHERE name='%s' AND pwd='%s';", addslashes($username), md5($password)); $result = pg_exec($connection, $query); if (pg_numrows($result) > 0) { echo "Welcome, $username!"; } else { echo "Authentication failed for $username."; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="sect2" ><HR><H3 CLASS="sect2" ><A NAME="security.database.sql-injection" ></A >SQL Injection</H3 ><P >
Many web developers are unaware of how SQL queries can be tampered with, and assume that an SQL query is a trusted command. It means that SQL queries are able to circumvent access controls, thereby bypassing standard authentication and authorization checks, and sometimes SQL queries even may allow access to host operating system level commands. </P ><P >
Direct SQL Command Injection is a technique where an attacker creates or alters existing SQL commands to expose hidden data, or to override valuable ones, or even to execute dangerous system level commands on the database host. This is accomplished by the application taking user input and combining it with static parameters to build a SQL query. The following examples are based on true stories, unfortunately. </P ><P >
Owing to the lack of input validation and connecting to the database on behalf of a superuser or the one who can create users, the attacker may create a superuser in your database. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5874" ></A ><P ><B >P°φklad 15-6. Splitting the result set into pages ... and making superusers (PostgreSQL and MySQL) </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$offset = argv[0]; // beware, no input validation! $query = "SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET $offset;"; // with PostgreSQL $result = pg_exec($conn, $query); // with MySQL $result = mysql_query($query);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Normal users click on the 'next', 'prev' links where the <TT CLASS="varname" >$offset</TT > is encoded into the URL. The script expects that the incoming <TT CLASS="varname" >$offset</TT > is a decimal number. However, what if someone tries to break in by appending a <A HREF="#function.urlencode" ><B CLASS="function" >urlencode()</B ></A >'d form of the following to the URL <DIV CLASS="informalexample" ><A NAME="AEN5880" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >// in case of PostgreSQL 0; insert into pg_shadow(usename,usesysid,usesuper,usecatupd,passwd) select 'crack', usesysid, 't','t','crack' from pg_shadow where usename='postgres'; -- // in case of MySQL 0; UPDATE user SET Password=PASSWORD('crack') WHERE user='root'; FLUSH PRIVILEGES;</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > If it happened, then the script would present a superuser access to him. Note that <TT CLASS="literal" >0;</TT > is to supply a valid offset to the original query and to terminate it. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > It is common technique to force the SQL parser to ignore the rest of the query written by the developer with <TT CLASS="literal" >--</TT > which is the comment sign in SQL. </P ></BLOCKQUOTE ></DIV ><P >
A feasible way to gain passwords is to circumvent your search result pages. The only thing the attacker needs to do is to see if there are any submitted variables used in SQL statements which are not handled properly. These filters can be set commonly in a preceding form to customize <TT CLASS="literal" >WHERE, ORDER BY, LIMIT</TT > and <TT CLASS="literal" >OFFSET</TT > clauses in <TT CLASS="literal" >SELECT</TT > statements. If your database supports the <TT CLASS="literal" >UNION</TT > construct, the attacker may try to append an entire query to the original one to list passwords from an arbitrary table. Using encrypted password fields is strongly encouraged. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5891" ></A ><P ><B >P°φklad 15-7. Listing out articles ... and some passwords (any database server) </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$query = "SELECT id, name, inserted, size FROM products WHERE size = '$size' ORDER BY $order LIMIT $limit, $offset;"; $result = odbc_exec($conn, $query);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > The static part of the query can be combined with another <TT CLASS="literal" >SELECT</TT > statement which reveals all passwords: <DIV CLASS="informalexample" ><A NAME="AEN5895" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >' union select '1', concat(uname||'-'||passwd) as name, '1971-01-01', '0' from usertable; --</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > If this query (playing with the <TT CLASS="literal" >'</TT > and <TT CLASS="literal" >--</TT >) were assigned to one of the variables used in <TT CLASS="varname" >$query</TT >, the query beast awakened. </P ><P >
SQL UPDATE's are also susceptible to attack. These queries are also threatened by chopping and appending an entirely new query to it. But the attacker might fiddle with the <TT CLASS="literal" >SET</TT > clause. In this case some schema information must be possessed to manipulate the query successfully. This can be acquired by examining the form variable names, or just simply brute forcing. There are not so many naming conventions for fields storing passwords or usernames. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5902" ></A ><P ><B >P°φklad 15-8. From resetting a password ... to gaining more privileges (any database server) </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$query = "UPDATE usertable SET pwd='$pwd' WHERE uid='$uid';";</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > But a malicious user sumbits the value <TT CLASS="literal" >' or uid like'%admin%'; --</TT > to <TT CLASS="varname" >$uid</TT > to change the admin's password, or simply sets <TT CLASS="varname" >$pwd</TT > to <TT CLASS="literal" >"hehehe', admin='yes', trusted=100 "</TT > (with a trailing space) to gain more privileges. Then, the query will be twisted: <DIV CLASS="informalexample" ><A NAME="AEN5909" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >// $uid == ' or uid like'%admin%'; -- $query = "UPDATE usertable SET pwd='...' WHERE uid='' or uid like '%admin%'; --"; // $pwd == "hehehe', admin='yes', trusted=100 " $query = "UPDATE usertable SET pwd='hehehe', admin='yes', trusted=100 WHERE ...;"</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
A frightening example how operating system level commands can be accessed on some database hosts. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5912" ></A ><P ><B >P°φklad 15-9. Attacking the database hosts operating system (MSSQL Server)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$query = "SELECT * FROM products WHERE id LIKE '%$prod%'"; $result = mssql_query($query);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > If attacker submits the value <TT CLASS="literal" >a%' exec master..xp_cmdshell 'net user test testpass /ADD' --</TT > to <TT CLASS="varname" >$prod</TT >, then the <TT CLASS="varname" >$query</TT > will be: <DIV CLASS="informalexample" ><A NAME="AEN5918" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$query = "SELECT * FROM products WHERE id LIKE '%a%' exec master..xp_cmdshell 'net user test testpass /ADD'--"; $result = mssql_query($query);</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > MSSQL Server executes the SQL statements in the batch including a command to add a new user to the local accounts database. If this application were running as <TT CLASS="literal" >sa</TT > and the MSSQLSERVER service is running with sufficient privileges, the attacker would now have an account with which to access this machine. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Some of the examples above is tied to a specific database server. This does not mean that a similar attack is impossible against other products. Your database server may be similarly vulnerable in another manner. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect3" ><HR><H4 CLASS="sect3" ><A NAME="security.database.avoiding" ></A >Avoiding techniques</H4 ><P >
You may plead that the attacker must possess a piece of information about the database schema in most examples. You are right, but you never know when and how it can be taken out, and if it happens, your database may be exposed. If you are using an open source, or publicly available database handling package, which may belong to a content management system or forum, the intruders easily produce a copy of a piece of your code. It may be also a security risk if it is a poorly designed one. </P ><P >
These attacks are mainly based on exploiting the code not being written with security in mind. Never trust any kind of input, especially that which comes from the client side, even though it comes from a select box, a hidden input field or a cookie. The first example shows that such a blameless query can cause disasters. </P ><P ></P ><UL ><LI ><P >
Never connect to the database as a superuser or as the database owner. Use always customized users with very limited privileges. </P ></LI ><LI ><P >
Check if the given input has the expected data type. PHP has a wide range of input validating functions, from the simplest ones found in <A HREF="#ref.variables" >Variable Functions</A > and in <A HREF="#ref.ctype" >Character Type Functions</A > (e.g. <A HREF="#function.is-numeric" ><B CLASS="function" >is_numeric()</B ></A >, <A HREF="#function.ctype-digit" ><B CLASS="function" >ctype_digit()</B ></A > respectively) and onwards to the <A HREF="#ref.pcre" >Perl compatible Regular Expressions</A > support. </P ></LI ><LI ><P >
If the application waits for numerical input, consider verifying data with <A HREF="#function.is-numeric" ><B CLASS="function" >is_numeric()</B ></A >, or silently change its type using <A HREF="#function.settype" ><B CLASS="function" >settype()</B ></A >, or use its numeric representation by <A HREF="#function.sprintf" ><B CLASS="function" >sprintf()</B ></A >. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5942" ></A ><P ><B >P°φklad 15-10. A more secure way to compose a query for paging</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >settype($offset, 'integer'); $query = "SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET $offset;"; // please note %d in the format string, using %s would be meaningless $query = sprintf("SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET %d;", $offset);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></LI ><LI ><P >
Quote each non numeric user input which is passed to the database with <A HREF="#function.addslashes" ><B CLASS="function" >addslashes()</B ></A > or <A HREF="#function.addcslashes" ><B CLASS="function" >addcslashes()</B ></A >. See <A HREF="#security.database.storage" >the first example</A >. As the examples shows, quotes burnt into the static part of the query is not enough, and can be easily cracked. </P ></LI ><LI ><P >
Do not print out any database specific information, especially about the schema, by fair means or foul. See also <A HREF="#security.errors" >Error Reporting</A > and <A HREF="#ref.errorfunc" >Error Handling and Logging Functions</A >. </P ></LI ><LI ><P >
You may use stored procedures and previously defined cursors to abstract data access so that users do not directly access tables or views, but this solution has another impacts. </P ></LI ></UL ><P >
Besides these, you benefit from logging queries either within your script or by the database itself, if it supports logging. Obviously, the logging is unable to prevent any harmful attempt, but it can be helpful to trace back which application has been circumvented. The log is not useful by itself, but through the information it contains. More detail is generally better than less. </P ></DIV ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.errors" ></A >Error Reporting</H2 ><P >
With PHP security, there are two sides to error reporting. One is beneficial to increasing security, the other is detrimental. </P ><P >
A standard attack tactic involves profiling a system by feeding it improper data, and checking for the kinds, and contexts, of the errors which are returned. This allows the system cracker to probe for information about the server, to determine possible weaknesses. For example, if an attacker had gleaned information about a page based on a prior form submission, they may attempt to override variables, or modify them: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5961" ></A ><P ><B >P°φklad 15-11. Attacking Variables with a custom HTML page</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><form method="POST" action="attacktarget?username=badfoo&password=badfoo"> <input type="hidden" name="username" value="badfoo"> <input type="hidden" name="password" value="badfoo"> </form></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
The PHP errors which are normally returned can be quite helpful to a developer who is trying to debug a script, indicating such things as the function or file that failed, the PHP file it failed in, and the line number which the failure occured in. This is all information that can be exploited. It is not uncommon for a php developer to use <A HREF="#function.show-source" ><B CLASS="function" >show_source()</B ></A >, <A HREF="#function.highlight-string" ><B CLASS="function" >highlight_string()</B ></A >, or <A HREF="#function.highlight-file" ><B CLASS="function" >highlight_file()</B ></A > as a debugging measure, but in a live site, this can expose hidden variables, unchecked syntax, and other dangerous information. Especially dangerous is running code from known sources with built-in debugging handlers, or using common debugging techniques. If the attacker can determine what general technique you are using, they may try to brute-force a page, by sending various common debugging strings: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5968" ></A ><P ><B >P°φklad 15-12. Exploiting common debugging variables</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><form method="POST" action="attacktarget?errors=Y&showerrors=1&debug=1"> <input type="hidden" name="errors" value="Y"> <input type="hidden" name="showerrors" value="1"> <input type="hidden" name="debug" value="1"> </form></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Regardless of the method of error handling, the ability to probe a system for errors leads to providing an attacker with more information. </P ><P >
For example, the very style of a generic PHP error indicates a system is running PHP. If the attacker was looking at an .html page, and wanted to probe for the back-end (to look for known weaknesses in the system), by feeding it the wrong data they may be able to determine that a system was built with PHP. </P ><P >
A function error can indicate whether a system may be running a specific database engine, or give clues as to how a web page or programmed or designed. This allows for deeper investigation into open database ports, or to look for specific bugs or weaknesses in a web page. By feeding different pieces of bad data, for example, an attacker can determine the order of authentication in a script, (from the line number errors) as well as probe for exploits that may be exploited in different locations in the script. </P ><P >
A filesystem or general PHP error can indicate what permissions the webserver has, as well as the structure and organization of files on the web server. Developer written error code can aggravate this problem, leading to easy exploitation of formerly "hidden" information. </P ><P >
There are three major solutions to this issue. The first is to scrutinize all functions, and attempt to compensate for the bulk of the errors. The second is to disable error reporting entirely on the running code. The third is to use PHP's custom error handling functions to create your own error handler. Depending on your security policy, you may find all three to be applicable to your situation. </P ><P >
One way of catching this issue ahead of time is to make use of PHP's own <A HREF="#function.error-reporting" ><B CLASS="function" >error_reporting()</B ></A >, to help you secure your code and find variable usage that may be dangerous. By testing your code, prior to deployment, with E_ALL, you can quickly find areas where your variables may be open to poisoning or modification in other ways. Once you are ready for deployment, by using E_NONE, you insulate your code from probing. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5978" ></A ><P ><B >P°φklad 15-13. Finding dangerous variables with E_ALL</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php if ($username) { // Not initialized or checked before usage $good_login = 1; } if ($good_login == 1) { // If above test fails, not initialized or checked before usage readfile ("/highly/sensitive/data/index.html"); } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.registerglobals" ></A >Using Register Globals</H2 ><P >
Perhaps the most controversial change in PHP is when the default value for the PHP directive <A HREF="#ini.register-globals" >
register_globals</A > went from ON to OFF in PHP <A HREF="http://www.php.net/release_4_2_0.php" TARGET="_top" >4.2.0</A >. Reliance on this directive was quite common and many people didn't even know it existed and assumed it's just how PHP works. This page will explain how one can write insecure code with this directive but keep in mind that the directive itself isn't insecure but rather it's the misuse of it. </P ><P >
When on, register_globals will inject (poison) your scripts will all sorts of variables, like request variables from HTML forms. This coupled with the fact that PHP doesn't require variable initialization means writing insecure code is that much easier. It was a difficult decision, but the PHP community decided to disable this directive by default. When on, people use variables yet really don't know for sure where they come from and can only assume. Internal variables that are defined in the script itself get mixed up with request data sent by users and disabling register_globals changes this. Let's demonstrate with an example misuse of register_globals: </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5988" ></A ><P ><B >P°φklad 15-14. Example misuse with register_globals = on</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // define $authorized = true only if user is authenticated if (authenticated_user()) { $authorized = true; } // Because we didn't first initialize $authorized as false, this might be // defined through register_globals, like from GET auth.php?authorized=1 // So, anyone can be seen as authenticated! if ($authorized) { include "/highly/sensitive/data.php"; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
When register_globals = on, our logic above may be compromised. When off, <TT CLASS="varname" >$authorized</TT > can't be set via request so it'll be fine, although it really is generally a good programming practice to initialize variables first. For example, in our example above we might have first done <TT CLASS="literal" >$authorized = false</TT >. Doing this first means our above code would work with register_globals on or off as users by default would be unauthorized. </P ><P >
Another example is that of <A HREF="#ref.session" >sessions</A >. When register_globals = on, we could also use <TT CLASS="varname" >$username</TT > in our example below but again you must realize that <TT CLASS="varname" >$username</TT > could also come from other means, such as GET (through the URL). </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5999" ></A ><P ><B >P°φklad 15-15. Example use of sessions with register_globals on or off</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // We wouldn't know where $username came from but do know $_SESSION is // for session data if (isset($_SESSION['username'])) { echo "Hello <b>{$_SESSION['username']}</b>"; } else { echo "Hello <b>Guest</b><br />"; echo "Would you like to login?"; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
It's even possible to take preventative measures to warn when forging is being attempted. If you know ahead of time exactly where a variable should be coming from, you can check to see if the submitted data is coming from an inappropriate kind of submission. While it doesn't guarantee that data has not been forged, it does require an attacker to guess the right kind of forging. If you don't care where the request data comes from, you can use <TT CLASS="varname" >$_REQUEST</TT > as it contains a mix of GET, POST and COOKIE data. See also the manual section on using <A HREF="#language.variables.external" >variables from outside of PHP</A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6006" ></A ><P ><B >P°φklad 15-16. Detecting simple variable poisoning</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php if (isset($_COOKIE['MAGIC_COOKIE'])) { // MAGIC_COOKIE comes from a cookie. // Be sure to validate the cookie data! } elseif (isset($_GET['MAGIC_COOKIE']) || isset($_POST['MAGIC_COOKIE'])) { mail("admin@example.com", "Possible breakin attempt", $_SERVER['REMOTE_ADDR']); echo "Security violation, admin has been alerted."; exit; } else { // MAGIC_COOKIE isn't set through this REQUEST } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Of course, simply turning off register_globals does not mean your code is secure. For every piece of data that is submitted, it should also be checked in other ways. Always validate your user data and initialize your variables! To check for unitialized variables you may turn up <A HREF="#function.error-reporting" ><B CLASS="function" >error_reporting()</B ></A > to show <TT CLASS="constant" ><B >E_NOTICE</B ></TT > level errors. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >dostupnost superglobßlnφch prom∞nn²ch: </B >Od PHP 4.1.0 jsou k dispozici superglobßlnφ pole jako <TT CLASS="varname" >$_GET </TT >, <TT CLASS="varname" >$_POST</TT > a <TT CLASS="varname" >$_SERVER</TT >. Pro vφce informacφ viz Φßst manußlu o <A HREF="#language.variables.predefined" >superglobals</A ></P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.variables" ></A >User Submitted Data</H2 ><P >
The greatest weakness in many PHP programs is not inherent in the language itself, but merely an issue of code not being written with security in mind. For this reason, you should always take the time to consider the implications of a given piece of code, to ascertain the possible damage if an unexpected variable is submitted to it. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6022" ></A ><P ><B >P°φklad 15-17. Dangerous Variable Usage</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // remove a file from the user's home directory... or maybe // somebody else's? unlink ($evil_var); // Write logging of their access... or maybe an /etc/passwd entry? fputs ($fp, $evil_var); // Execute something trivial.. or rm -rf *? system ($evil_var); exec ($evil_var); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > You should always carefully examine your code to make sure that any variables being submitted from a web browser are being properly checked, and ask yourself the following questions: <P ></P ><UL ><LI ><P >
Will this script only affect the intended files? </P ></LI ><LI ><P >
Can unusual or undesirable data be acted upon? </P ></LI ><LI ><P >
Can this script be used in unintended ways? </P ></LI ><LI ><P >
Can this be used in conjunction with other scripts in a negative manner? </P ></LI ><LI ><P >
Will any transactions be adequately logged? </P ></LI ></UL > By adequately asking these questions while writing the script, rather than later, you prevent an unfortunate re-write when you need to increase your security. By starting out with this mindset, you won't guarantee the security of your system, but you can help improve it. </P ><P >
You may also want to consider turning off register_globals, magic_quotes, or other convenience settings which may confuse you as to the validity, source, or value of a given variable. Working with PHP in error_reporting(E_ALL) mode can also help warn you about variables being used before they are checked or initialized (so you can prevent unusual data from being operated upon). </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.hiding" ></A >Hiding PHP</H2 ><P >
In general, security by obscurity is one of the weakest forms of security. But in some cases, every little bit of extra security is desirable. </P ><P >
A few simple techniques can help to hide PHP, possibly slowing down an attacker who is attempting to discover weaknesses in your system. By setting expose_php = off in your <TT CLASS="filename" >php.ini</TT > file, you reduce the amount of information available to them. </P ><P >
Another tactic is to configure web servers such as apache to parse different filetypes through PHP, either with an <TT CLASS="filename" >.htaccess</TT > directive, or in the apache configuration file itself. You can then use misleading file extensions: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6044" ></A ><P ><B >P°φklad 15-18. Hiding PHP as another language</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="apache-conf" ># Make PHP code look like other code types AddType application/x-httpd-php .asp .py .pl</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Or obscure it completely: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6047" ></A ><P ><B >P°φklad 15-19. Using unknown types for PHP extensions</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="apache-conf" ># Make PHP code look like unknown types AddType application/x-httpd-php .bop .foo .133t</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Or hide it as HTML code, which has a slight performance hit because all HTML will be parsed through the PHP engine: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6050" ></A ><P ><B >P°φklad 15-20. Using HTML types for PHP extensions</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="apache-conf" ># Make all PHP code look like HTML AddType application/x-httpd-php .htm .html</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > For this to work effectively, you must rename your PHP files with the above extensions. While it is a form of security through obscurity, it's a minor preventative measure with few drawbacks. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="security.current" ></A >Keeping Current</H2 ><P >
PHP, like any other large system, is under constant scrutiny and improvement. Each new version will often include both major and minor changes to enhance and repair security flaws, configuration mishaps, and other issues that will affect the overall security and stability of your system. </P ><P >
Like other system-level scripting languages and programs, the best approach is to update often, and maintain awareness of the latest versions and their changes. </P ></DIV ></DIV ></DIV ><DIV CLASS="PART" ><A NAME="features" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >IV. Vlastnosti</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT >16. <A HREF="#features.http-auth" >HTTP autentikace a PHP</A ></DT ><DT >17. <A HREF="#features.cookies" >Cookies</A ></DT ><DT >18. <A HREF="#features.file-upload" >Zpracovßnφ uploadu soubor∙</A ></DT ><DT >19. <A HREF="#features.remote-files" >Pou╛itφ vzdßlen²ch soubor∙</A ></DT ><DT >20. <A HREF="#features.connection-handling" >Obsluha spojenφ</A ></DT ><DT >21. <A HREF="#features.persistent-connections" >Persistentnφ databßzovß spojenφ</A ></DT ><DT >22. <A HREF="#features.safe-mode" >BezpeΦn² re╛im</A ></DT ><DT >23. <A HREF="#features.commandline" >Pou╛itφ PHP z p°φkazovΘ °ßdky</A ></DT ></DL ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.http-auth" >Kapitola 16. HTTP autentikace a PHP</A ></H1 ><P >
Prost°edky HTTP autentikace jsou v PHP p°φstupnΘ pouze pokud PHP b∞╛φ jako modul Apache, tudφ╛ nejsou p°φstupnΘ v CGI verzi. V PHP skriptu b∞╛φcφm pod modulem Apache lze pou╛φt funkci <A HREF="#function.header" ><B CLASS="function" >header()</B ></A > k odeslßnφ zprßvy "Authentication Required" klientskΘmu browseru, co╛ vyvolß zobrazenφ dialogovΘho okna pro vlo╛enφ u╛ivatelskΘho jmΘna a hesla. Jakmile u╛ivatel zadß jmΘno a heslo, URL obsahujφcφ tento PHP skript se zavolß znovu s prom∞nn²mi $PHP_AUTH_USER, $PHP_AUTH_PW and $PHP_AUTH_TYPE obsahujφcφmi jmΘno, heslo a typ autentikace. V souΦasnosti je podporovßna pouze "Basic" autentikace. Vφce informacφ viz funkce <A HREF="#function.header" ><B CLASS="function" >header()</B ></A >. </P ><P >
Nßsledujφcφ fragment k≤du m∙╛e poslou╛it jako ukßzka vy╛ßdßnφ autentikace u╛ivatele na strßnce: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6065" ></A ><P ><B >P°φklad 16-1. Ukßzka HTTP Autentikace</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php if(!isset($PHP_AUTH_USER)) { Header("WWW-Authenticate: Basic realm=\"My Realm\""); Header("HTTP/1.0 401 Unauthorized"); echo "Text, kter² se ode╣le, pokud u╛ivatel zmßΦkne tlaΦφtko Cancel\n"; exit; } else { echo "Ahoj $PHP_AUTH_USER.<P>"; echo "Jako heslo jsi zadal $PHP_AUTH_PW.<P>"; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></P ><P >
Mφsto protΘho vyti╣t∞nφ $PHP_AUTH_USER a $PHP_AUTH_PW byste asi cht∞li ov∞°it platnost zadanΘho jmΘna a hesla. Nap°φklad dotazem v databßzi nebo vyhledßnφm u╛ivatele v dbm souboru. </P ><P >
Pozor na chybovΘ browsery Internet Explorer. Zdß se, ╛e jsou velice vybφravΘ, pokud jde o po°adφ hlaviΦek. Zdß se, ╛e odeslßnφ hlaviΦky <SPAN CLASS="emphasis" ><I CLASS="emphasis" >WWW-Authenticate</I ></SPAN > p°ed hlaviΦkou <SPAN CLASS="errorcode" >HTTP/1.0 401</SPAN > zabφrß. </P ><P >
Aby se zabrßnilo psanφ skript∙ odhalujφcφch hesla na strßnkßch autentikovan²ch n∞kter²m z tradiΦnφch externφch mechanism∙, PHP_AUTH prom∞nnΘ se nevytvo°φ, pokud je pro tu kterou strßnku zapnuta externφ autentikace. V takovΘm p°φpad∞ m∙╛ete k identifikaci extern∞ autentikovanΘho u╛ivatele pou╛φt prom∞nnou $REMOTE_USER. </P ><P >
V╣imn∞te si nicmΘn∞, ╛e v²╣e uvedenΘ nezabrßnφ krßde╛φm hesel z autentikovan²ch URL osobou, kterß ovlßdß neautentikovanou URL na stejnΘm serveru. </P ><P >
Jak Netscape, tak Internet Explorer po p°ijetφ response k≤du 401 vyprßzdnφ autentikaΦnφ cache souΦasnΘho realmu. Tak m∙╛ete u╛ivatele v podstat∞ "odlogovat". N∞kte°φ lidΘ toho vyu╛φvajφ k "vypr╣enφ" p°ihlß╣enφ nebo tvorb∞ odhla╣ovacφho tlaΦφtka. </P ><P ></P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6076" ></A ><P ><B >P°φklad 16-2. Ukßzka HTTP autentikace vy╛adujφcφ novΘ jmΘno a heslo</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function authenticate() { Header( "WWW-Authenticate: Basic realm=\"Test Authentication System\""); Header( "HTTP/1.0 401 Unauthorized"); echo "K p°φstupu na tento zdroj musφte zadat platnΘ ID a heslo\n"; exit; } if(!isset($PHP_AUTH_USER) || ($SeenBefore == 1 && !strcmp($OldAuth, $PHP_AUTH_USER)) ) { authenticate(); } else { echo "Welcome: $PHP_AUTH_USER<BR>"; echo "Old: $OldAuth"; echo "<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n"; echo "<INPUT TYPE=HIDDEN NAME=\"SeenBefore\" VALUE=\"1\">\n"; echo "<INPUT TYPE=HIDDEN NAME=\"OldAuth\" VALUE=\"$PHP_AUTH_USER\">\n"; echo "<INPUT TYPE=Submit VALUE=\"Re Authenticate\">\n"; echo "</FORM>\n"; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Podle standardu HTTP Basic authentication se toto chovßnφ nevy╛aduje, tak╛e byste na to nikdy nem∞li spolΘhat. Pokusy s Lynxem ukßzaly, ╛e Lynx po p°ijetφ response k≤du 401 nevyprßzdnφ autentikaΦnφ ·daje, tak╛e po stisknutφ back a forward se znovu ukß╛e po╛adovan² zdroj (pokud se nezm∞nily po╛adavky na ·daje). </P ><P >
Dßle si v╣imn∞te, ╛e tato vlastnost p°i pou╛itφ IIS serveru a CGI verze PHP dφky omezenφm IIS nefunguje. </P ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.cookies" >Kapitola 17. Cookies</A ></H1 ><P >
PHP transparentn∞ podporuje HTTP cookies. Cookies jsou mechanismem na uklßdßnφ dat ve vzdßlenΘm browseru a tudφ╛ sledovßnφ nebo identifikaci vracejφcφch se u╛ivatel∙. Cookies m∙╛ete nastavovat pomocφ funkce <A HREF="#function.setcookie" ><B CLASS="function" >setcookie()</B ></A >. Cookies jsou souΦßstφ HTTP hlaviΦky, tudφ╛ <A HREF="#function.setcookie" ><B CLASS="function" >setcookie()</B ></A > se musφ volat p°ed odeslßnφm v²stupu do browseru. To je stejnΘ omezenφ, jako mß funkce <A HREF="#function.header" ><B CLASS="function" >header()</B ></A >. </P ><P >
V╣echny cookies p°ijatΘ od klienta se automaticky stßvajφ PHP prom∞nnou stejn∞ jako u GET a POST dat. Pokud chcete p°i°adit jednomu cookie vφce hodnot, p°idejte <SPAN CLASS="emphasis" ><I CLASS="emphasis" >[]</I ></SPAN > na konec jmΘna cookie. Vφce detail∙ viz funkce <A HREF="#function.setcookie" ><B CLASS="function" >setcookie()</B ></A >.</P ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.file-upload" >Kapitola 18. Zpracovßnφ uploadu soubor∙</A ></H1 ><DIV CLASS="sect1" ><H2 CLASS="sect1" ><A NAME="features.file-upload.post-method" ></A >Uploading metodou POST</H2 ><P >
PHP umo╛≥uje zpracovßnφ uploadu soubor∙ z jakΘhokoli prohlφ╛eΦe vyhovujφcφho RFC-1867 (co╛ zahrnuje mj. Netscape Navigator 3 a pozd∞j╣φ, Microsoft Internet Explorer 3 se zßplatou od Microsoftu, nebo pozd∞j╣φ bez zßplaty). Tato schopnost umo╛≥uje lidem uploadovat textovΘ i binßrnφ soubory. S autentizacφ poskytovanou PHP a s funkcemi pro manipulaci se soubory mßte plnou kontrolu nad tφm, kdo smφ uploadovat a co se mß ud∞lat s uploadovan²m souborem. </P ><P >
Nezapome≥te, ╛e PHP podporuje takΘ uploady metodou PUT tak, jak se pou╛φvß v Netscape Composeru a v editoru Amaya od W3C. Pro bli╛╣φ detaily viz <A HREF="#features.file-upload.put-method" >Podpora metody PUT</A >. </P ><P >
Obrazovka pro upload souboru m∙╛e b²t tvo°ena specißlnφm formulß°em, kter² vypadß podobn∞ jako tento: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6098" ></A ><P ><B >P°φklad 18-1. Formulß° pro upload souboru</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" ><form enctype="multipart/form-data" action="_URL_" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000"> Send this file: <input name="userfile" type="file"> <input type="submit" value="Send File"> </form></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > _URL_ by m∞lo oznaΦovat PHP soubor. SkrytΘ pole MAX_FILE_SIZE musφ p°edchßzet pole pro vlo╛enφ souboru a jeho hodnota specifikuje maximßlnφ akceptovanou velikost souboru. Hodnota je v bytech. <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Hodnota MAX_FILE_SIZE je z hlediska prohlφ╛eΦe pouze informativnφ. Je snadnΘ ji obejφt. Tak╛e nepoΦφtejte s tφm, ╛e prohlφ╛eΦ se bude chovat tak, jak si p°ejete. Nastavenφ maximßlnφ velikosti v PHP v╣ak samoz°ejm∞ nem∙╛e b²t obelst∞no. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
Prom∞nnΘ definovanΘ pro uploadovanΘ soubory se li╣φ v zßvislosti na verzi a konfiguraci PHP. Pokud je aktivnφ volba <A HREF="#ini.track-vars" >track_vars</A >, bude inicializovßno pole $HTTP_POST_FILES/$_FILES. KoneΦn∞, souvisejφcφ prom∞nnΘ mohou b²t inicializovßny jako globßlnφ, pokud je zapnuta volba <A HREF="#ini.register-globals" >register_globals</A >. Ov╣em pou╛φvßnφ globßlnφch prom∞nn²ch nenφ doporuΦeno. Po ·sp∞╣nΘm uploadu budou v cφlovΘm skriptu definovßny nßsledujφcφ prom∞nnΘ: </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <A HREF="#ini.track-vars" >track_vars</A > je od PHP 4.0.3 v╛dy zapnuto. U PHP 4.1.0 a pozd∞j╣φch m∙╛e b²t pou╛ito $_FILES namφsto <TT CLASS="varname" >$HTTP_POST_FILES</TT >. <TT CLASS="varname" >$_FILES</TT > je v╛dy globßlnφ prom∞nnß, tak╛e by se nem∞la pou╛φvat specifikace <TT CLASS="literal" >global</TT > pro prom∞nnou $_FILES. </P ></BLOCKQUOTE ></DIV ><P >
<TT CLASS="varname" >$HTTP_POST_FILES</TT >/<TT CLASS="varname" >$_FILES</TT > obsahuje informace o uploadovanΘm souboru. </P ><P >
Obsah <TT CLASS="varname" >$HTTP_POST_FILES</TT > je takov²to (uv∞domte si, ╛e se p°edpoklßdß pou╛itφ nßzvu uploadovanΘho souboru 'userfile' tak, jako v p°φkladu v²╣e): <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="varname" >$HTTP_POST_FILES['userfile']['name']</TT ></DT ><DD ><P >
Originßlnφ nßzev souboru na klientskΘm poΦφtaΦi. </P ></DD ><DT ><TT CLASS="varname" >$HTTP_POST_FILES['userfile']['type']</TT ></DT ><DD ><P >
MIME typ souboru, pokud prohlφ╛eΦ tuto informaci poskytuje (nap°. <TT CLASS="literal" >"image/gif"</TT >). </P ></DD ><DT ><TT CLASS="varname" >$HTTP_POST_FILES['userfile']['size']</TT ></DT ><DD ><P >
Velikost uploadovanΘho souboru v bytech. </P ></DD ><DT ><TT CLASS="varname" >$HTTP_POST_FILES['userfile']['tmp_name']</TT ></DT ><DD ><P >
DoΦasn² nßzev souboru, pod nφm╛ byl uploadovan² soubor ulo╛en na server. </P ></DD ></DL ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > PHP 4.1.0 a pozd∞j╣φ podporujφ zkrßcen² nßzev prom∞nnΘ <TT CLASS="varname" >$_FILES</TT >. PHP 3 nepodporuje <TT CLASS="varname" >$HTTP_POST_FILES</TT >. </P ></BLOCKQUOTE ></DIV ><P >
Obsah prom∞nnßch v situaci, kdy je prom∞nnß <A HREF="#ini.register-globals" >register_globals</A > zapnuta nastavenφm v souboru <TT CLASS="filename" >php.ini</TT > (uv∞domte si, ╛e se p°edpoklßdß pou╛itφ nßzvu uploadovanΘho souboru 'userfile' tak, jako v p°φkladu v²╣e): <P ></P ><UL ><LI ><P >
<TT CLASS="varname" >$userfile</TT > - DoΦasn² nßzev souboru, pod kter²m byl uploadovan² soubor ulo╛en na server. </P ></LI ><LI ><P >
<TT CLASS="varname" >$userfile_name</TT > - Originßlnφ nßzev souboru nebo cesta na odesφlajφcφm systΘmu. </P ></LI ><LI ><P >
<TT CLASS="varname" >$userfile_size</TT > - Velikost uploadovanΘho souboru v bytech. </P ></LI ><LI ><P >
<TT CLASS="varname" >$userfile_type</TT > - MIME typ souboru, pokud prohlφ╛eΦ tuto informaci poskytuje (nap°. "image/gif"). </P ></LI ></UL > Uv∞domte si, ╛e prom∞nnß "<TT CLASS="varname" >$userfile</TT >" ve skuteΦnosti p°edstavuje nßzev pole <input> se specifikacφ type="file" ve formulß°i. Pro v²╣e uveden² p°φklad jsme zvolili nßzev "userfile". </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Nastavenφ <TT CLASS="literal" >register_globals = On</TT > se nedoporuΦuje z bezpeΦnostnφch a v²konnostnφch d∙vod∙. </P ></BLOCKQUOTE ></DIV ><P >
Soubory se implicitn∞ uklßdajφ do systΘmovΘho adresß°e pro doΦasnΘ soubory, pokud nebylo direktivou <A HREF="#ini.upload-tmp-dir" >upload_tmp_dir</A > v souboru <TT CLASS="filename" >php.ini</TT > stanoveno jinak. SystΘmov² adresß° pro doΦasnΘ soubory m∙╛e b²t zm∞n∞n nastavenφ prom∞nnΘ prost°edφ <TT CLASS="envar" >TMPDIR</TT > v prost°edφ, kde PHP b∞╛φ. Nastavenφ za pou╛itφ <A HREF="#function.putenv" ><B CLASS="function" >putenv()</B ></A > z PHP skriptu nebude fungovat. Tato prom∞nnß prost°edφ m∙╛e b²t takΘ pou╛ita k uji╣t∞nφ se, ╛e v╣echny ostatnφ operace pracujφ s uploadovan²mi soubory. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6168" ></A ><P ><B >P°φklad 18-2. Ov∞°ovßnφ uploadu souboru</B ></P ><P >
Nßsledujφcφ p°φklady jsou pro verze PHP 4 vy╣╣φ ne╛ PHP 4.0.2. (viz funkce <A HREF="#function.is-uploaded-file" ><B CLASS="function" >is_uploaded_file()</B ></A > a <A HREF="#function.move-uploaded-file" ><B CLASS="function" >move_uploaded_file()</B ></A >). </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // V PHP 4.1.0 a pozd∞j╣φch by m∞lo b²t pou╛ito $_FILES namφsto $HTTP_POST_FILES. if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { copy($HTTP_POST_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack. Filename: " . $HTTP_POST_FILES['userfile']['name']; } /* ...or... */ move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file"); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
PHP skript, kter² p°ijφmß uploadovanΘ soubory, by m∞l implementovat ve╣kerou logiku pro stanovenφ, co by se m∞lo ud∞lat s uploadovan²m souborem. M∙╛ete nap°. pou╛φt prom∞nnou <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['size']</TT > pro zahozenφ soubor∙, kterΘ jsou p°φli╣ malΘ nebo velkΘ. Mohli byste pou╛φt takΘ prom∞nnou <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['type']</TT > pro filtraci soubor∙ podle MIME datovΘho typu. Bez ohledu na °e╣enφ, soubor by m∞l b²t smazßn nebo p°esunut jinam. </P ><P >
Soubor bude automaticky smazßn z doΦasnΘho adresß°e na konci skriptu, pokud nebyl p°esunut jinam nebo p°ejmenovßn. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="features.file-upload.common-pitfalls" ></A >╚astß ·skalφ</H2 ><P >
<TT CLASS="literal" >MAX_FILE_SIZE</TT > nem∙╛e specifikovat velikost souboru v∞t╣φ ne╛ je ta, kterß byla nastavena pomocφ <A HREF="#ini.upload-max-filesize" >upload_max_filesize</A > v konfiguraci PHP. Implicitn∞ jsou to 2 MB. </P ><P >
Pokud je zapnut limit pam∞ti, m∙╛e b²t pot°eba v∞t╣φ hodnota <A HREF="#ini.memory-limit" >memory_limit</A >. Ujist∞te se, ╛e je hodnota <A HREF="#ini.memory-limit" >memory_limit</A > dostateΦn∞ velkß. </P ><P >
Pokud je nastavenß hodnota <TT CLASS="literal" >max_execution_time</TT > p°φli╣ malß, doba provßd∞nφ skriptu ji m∙╛e p°ekroΦit. Ujist∞te se, ╛e je hodnota <TT CLASS="literal" >max_execution_time</TT > dostateΦn∞ velkß. </P ><P >
Pokud je nastavenß hodnota <TT CLASS="literal" >post_max_size</TT > p°φli╣ malß, nem∙╛e b²t uploadovßn v∞t╣φ soubor. Ujist∞te se, ╛e je hodnota <TT CLASS="literal" >post_max_size</TT > dostateΦn∞ velkß. </P ><P >
Neov∞°ovßnφ, se kter²m souborem se pracuje, m∙╛e znamenat, ╛e se u╛ivatelΘ mohou dostat k citliv²m informacφm v jin²ch adresß°φch. </P ><P >
Uv∞domte si prosφm, ╛e server CERN httpd odstra≥uje v╣echno, co poΦφnaje prvnφ bφlou mezerou (whitespace) v MIME hlaviΦce Content-Type obdr╛φ od klienta. Za existence tohoto jevu nebude CERN httpd podporovat uploading soubor∙. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="features.file-upload.multiple" ></A >Uploading vφce soubor∙</H2 ><P >
Vφce soubor∙ m∙╛e b²t uploadovßnφ za pou╛itφ r∙zn²ch nßzv∙ <TT CLASS="literal" >name</TT > pro souborovΘ pole <TT CLASS="literal" >input</TT >. </P ><P >
Je takΘ mo╛nΘ uploadovat vφce soubor∙ souΦasn∞ a nechat informace automaticky zorganizovat v polφch. V takovΘm p°φpad∞ je t°eba pou╛φt stejnou syntaxi v HTML formulß°i jako pro vφcenßsobnΘ v²b∞ry a za╣krtßvacφ polφΦka (checkboxy). </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Podpora pro upload vφce soubor∙ byla p°idßna ve verzi 3.0.10. </P ></BLOCKQUOTE ></DIV ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6203" ></A ><P ><B >P°φklad 18-3. Uploading vφce soubor∙</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" ><form action="file-upload.php" method="post" enctype="multipart/form-data"> Send these files:<br> <input name="userfile[]" type="file"><br> <input name="userfile[]" type="file"><br> <input type="submit" value="Send files"> </form></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Pokud je v²╣e uveden² formulß° odeslßn, pole <TT CLASS="varname" >$HTTP_POST_FILES['userfile']</TT >, <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['name']</TT >, a <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['size']</TT > budou inicializovßna (jak $_FILES v PHP 4.1.0 a pozd∞j╣φm, tak $HTTP_POST_VARS v PHP 3. Pokud je nastavenφ <TT CLASS="literal" >register_globals</TT > aktivnφ globßlnφ prom∞nnΘ pro uploadovanΘ soubory jsou takΘ inicializovßny). Ka╛dΘ z nich bude Φφseln∞ indexovanΘ pole odpovφdajφcφch hodnot pro odeslanΘ soubory. </P ><P >
Kup°φkladu p°edpoklßdejme, ╛e se posφlajφ soubory s nßzvy <TT CLASS="filename" >/home/test/review.html</TT > a <TT CLASS="filename" >/home/test/xwp.out</TT >. V tom p°φpad∞ by <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['name'][0]</TT > obsahovalo hodnotu <TT CLASS="filename" >review.html</TT > a <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['name'][1]</TT > hodnotu <TT CLASS="filename" >xwp.out</TT >. Podobn∞ <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['size'][0]</TT > by obsahovalo velikost <TT CLASS="filename" >review.html</TT > atd. </P ><P >
<TT CLASS="varname" >$HTTP_POST_FILES['userfile']['name'][0]</TT >, <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['tmp_name'][0]</TT >, <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['size'][0]</TT > a <TT CLASS="varname" >$HTTP_POST_FILES['userfile']['type'][0]</TT > budou rovn∞╛ nastaveny. </P ></DIV ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="features.file-upload.put-method" ></A >Podpora metody PUT</H2 ><P >
PHP poskytuje podporu pro HTTP PUT metodu pou╛φvanou klienty jako Netscape Composer nebo W3C Amaya. Po╛adavky s metodou PUT jsou mnohem jednodu╣╣φ ne╛ upload soubor∙ a vypadajφ p°ibli╛n∞ takto: <DIV CLASS="informalexample" ><A NAME="AEN6228" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >PUT /path/filename.html HTTP/1.1</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Toto by normßln∞ znamenalo, ╛e by cht∞l klient ulo╛it obsah, kter² nßsleduje za nßzvem /path/filename.html, do svΘho webovΘho stromu. To samoz°ejm∞ nenφ dobr² nßpad, aby Apache nebo PHP automaticky nechal kohokoli p°epsat jakΘkoli soubory ve strom∞. Tak╛e, pro zpracovßnφ takovΘho po╛adavku je t°eba nejd°φv °ici va╣emu WWW serveru, ╛e chcete po╛adavek zpracovßvat konkrΘtnφm PHP skriptem. U serveru Apache se to provede direktivou <SPAN CLASS="emphasis" ><I CLASS="emphasis" >Script</I ></SPAN >. M∙╛e b²t umφst∞na kdekoli v konfiguraΦnφm souboru Apache. ╚ast²mi mφsty jsou bloky <Directory> a <Virtualhost>. Pou╛ije se k tomu °ßdek podobn² tomuto: <DIV CLASS="informalexample" ><A NAME="AEN6232" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Skript PUT /put.php</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Toto °ekne serveru Apache, aby v╣echny PUT po╛adavky na n∞jak² URI vyhovujφcφ kontextu posφlal skriptu put.php. To pochopiteln∞ p°edpoklßdß, ╛e mßte povoleno PHP pro p°φponu .php a PHP je aktivnφ. </P ><P >
V souboru put.php byste potom mohli napsat n∞co jako: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN6237" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Toto by m∞lo zkopφrovat soubor na mφsto po╛adovanΘ vzdßlen²m klientem. Pravd∞podobn∞ byste cht∞li provΘst n∞jakß ov∞°enφ a/nebo autentizace u╛ivatele p°ed provedenφm tohoto zkopφrovßnφ. Jedin²m pou╛iteln²m trikem je, ╛e PHP ulo╛φ p°enesen² soubor do doΦasnΘho adresß°e podobn∞, jako p°i pou╛itφ <A HREF="#features.file-upload.post-method" >metody POST</A >. A╛ skript skonΦφ, doΦasn² soubor bude odstran∞n. Tak╛e vß╣ PHP skipt pro zpracovßnφ PUT po╛adavk∙ musφ soubor zkopφrovat jinam. Nßzev souboru v doΦasnΘm umφst∞nφ je ulo╛en v prom∞nnΘ $PHP_PUT_FILENAME a po╛adovan² nßzev cφlovΘho souboru v prom∞nnΘ $REQUEST_URI (m∙╛e se li╣it u server∙ jin²ch ne╛ Apache). Toto cφlovΘ jmΘno je to jedinΘ, co klient specifikoval. Nemusφte ho poslechnout. Mohli byste, nap°φklad, kopφrovat v╣echny uploadovanΘ soubory do specißlnφho uploadovΘho adresß°e. </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.remote-files" >Kapitola 19. Pou╛itφ vzdßlen²ch soubor∙</A ></H1 ><P >
Pokud p°i konfiguraci PHP aktivujete podporu "URL fopen wrapper" (standardn∞ je zapnutß, leda╛e pro configure explicitn∞ zadßte <TT CLASS="option" >--disable-url-fopen-wrapper</TT > p°φznak (verze do 4.0.3), nebo (u nov∞j╣φch verzφ) nastavφte <TT CLASS="parameter" ><I >allow_url_fopen</I ></TT > v php.ini na off), m∙╛ete ve volßnφch v∞t╣iny funkcφ, kterΘ oΦekßvajφ jako argument nßzev souboru (vΦetn∞ <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > a <A HREF="#function.include" ><B CLASS="function" >include()</B ></A >) uvΘst HTTP nebo FTP URL. </P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Na Windows nelze pou╛φvat vzdßlenΘ soubory v <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > a <A HREF="#function.require" ><B CLASS="function" >require()</B ></A > v²razech. </P ></BLOCKQUOTE ></DIV > </P ><P >
M∙╛ete nap°φklad otev°φt soubor na vzdßlenΘm web serveru, vyseparovat z v²stupu data, kterß pot°ebujete, a tato data potom pou╛φt v dotazu na databßzi, nebo je prost∞ zaΦlenit do v²stupu stylem odpovφdajφcφm zbytku va╣φ web site. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6255" ></A ><P ><B >P°φklad 19-1. Zφskßnφ nßzvu vzdßlenΘ strßnky</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $file = fopen ("http://www.php.net/", "r"); if (!$file) { echo "<p>Nelze otev°φt vzdßlen² soubor.\n"; exit; } while (!feof ($file)) { $line = fgets ($file, 1024); /* Toto bude fungovat pouze pokud jsou tagy a nßzev na jednΘ °ßdce */ if (eregi ("<title>(.*)</title>", $line, $out)) { $title = $out[1]; break; } } fclose($file); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Pokud se p°ipojφte jako u╛ivatel s dostateΦn²mi prßvy, a dan² soubor u╛ neexistuje, m∙╛ete data takΘ uklßdat po FTP. Pokud se chcete p°ipojit jako jin² u╛ivatel ne╛ 'anonymous', musφte v URL udat u╛ivatelskΘ jmΘno (a pravd∞podobn∞ i heslo), nap°. 'ftp://uzivatel:heslo@ftp.example.com/path/to/file'. (Pro p°φstup k soubor∙m p°es HTTP, kterΘ vy╛adujφ Basic authentication, m∙╛ete pou╛φt stejnou syntaxi.) </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6260" ></A ><P ><B >P°φklad 19-2. Ulo╛enφ dat na vzdßlenΘm serveru</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $file = fopen ("ftp://ftp.php.net/incoming/outputfile", "w"); if (!$file) { echo "<p>Nelze otev°φt vzdßlen² soubor pro zßpis.\n"; exit; } /* Zapφ╣eme data. */ fputs ($file, "$HTTP_USER_AGENT\n"); fclose ($file); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Z v²╣e uvedenΘho p°φkladu by vßs mohlo napadnout vyu╛φt tuto techniku k zßpisu do vzdßlenΘho logu, ale jak u╛ bylo zmφn∞no v²╣e, pomocφ URL fopen() wrapperu m∙╛ete zapisovat pouze do novΘho souboru. Pokud mßte zßjem o distribuovanΘ logovßnφ, podφvejte se na <A HREF="#function.syslog" ><B CLASS="function" >syslog()</B ></A >. </P ></BLOCKQUOTE ></DIV > </P ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.connection-handling" >Kapitola 20. Obsluha spojenφ</A ></H1 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B >Nßsledujφcφ text platφ pro verzi 3.0.7 a vy╣╣φ.</P ></BLOCKQUOTE ></DIV ><P >
Stav spojenφ se v PHP intern∞ sleduje. Jsou t°i mo╛nΘ stavy: <P ></P ><UL ><LI ><P >0 - NORMAL (normßlnφ)</P ></LI ><LI ><P >1 - ABORTED (zru╣eno)</P ></LI ><LI ><P >2 - TIMEOUT (vypr╣el Φasov² limit)</P ></LI ></UL > </P ><P >
P°i normßlnφm b∞hu PHP skriptu je aktivnφ stav NORMAL. Pokud se klient odpojφ, nastavφ se p°φznak ABORTED. K odpojenφ vzdßlenΘho klienta typicky dochßzφ, kdy╛ u╛ivatel zmßΦkne tlaΦφtko STOP. Pokud se dosßhne ΦasovΘho limitu (viz <A HREF="#function.set-time-limit" ><B CLASS="function" >set_time_limit()</B ></A >), nastavφ se stavov² p°φznak TIMEOUT. </P ><P >
M∙╛ete se rozhodnout jestli chcete, aby odpojenφ klienta zp∙sobilo p°edΦasnΘ ukonΦenφ va╣eho skriptu. N∞kdy je u╛iteΦnΘ nechat skripty dob∞hnout do konce, p°esto╛e nenφ vzdßlenΘho browseru, kter² by p°ijφmal v²stup. V²chozφ chovßnφ je nicmΘn∞ takovΘ, ╛e p°i odpojenφ vzdßlenΘho klienta dojde k ukonΦenφ b∞hu skriptu. Toto chovßnφ se dß zm∞nit skrze konfiguraΦnφ direktivu ignore_user_abort v php3.ini, odpovφdajφcφ direktivu php3_ignore_user_abort v .conf souboru Apache, Φi funkci <A HREF="#function.ignore-user-abort" ><B CLASS="function" >ignore_user_abort()</B ></A >. Pokud nedßte PHP pokyn ignorovat odpojenφ u╛ivatele a ten se odpojφ, vß╣ skript se ukonΦφ. V²jimkou je, pokud mßte pomocφ <A HREF="#function.register-shutdown-function" ><B CLASS="function" >register_shutdown_function()</B ></A > zaregistrovanou funkci pro provedenφ p°i ukonΦenφ skriptu. V tom p°φpad∞, pokud vzdßlen² u╛ivatel zmßΦkne tlaΦφtko STOP, p°i dal╣φm pokusu tohoto skriptu odeslat v²stup PHP detekuje, ╛e spojenφ bylo zru╣eno, a zavolß se funkce zaregistrovanß pro provedenφ p°i ukonΦenφ skriptu. Tato funkce se zavolß takΘ na konci b∞hu skriptu konΦφcφm normßln∞, tak╛e pokud chcete po zru╣enΘm spojenφ ud∞lat n∞co jinΘho, m∙╛ete pou╛φt <A HREF="#function.connection-aborted" ><B CLASS="function" >connection_aborted()</B ></A >. Tato funkce vrßtφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud bylo spojenφ zru╣eno. </P ><P >
Vß╣ skript m∙╛e takΘ ukonΦit vestav∞n² ΦφtaΦ Φasu. V²chozφ Φasov² limit je 30 sekund. To se dß zm∞nit max_execution_time direktivou v php╣.ini nebo odpovφdajφcφ php3_max_execution_time direktivou v .conf souboru Apahe, Φi volßnφm funkce <A HREF="#function.set-time-limit" ><B CLASS="function" >set_time_limit()</B ></A >. Kdy╛ ΦφtaΦ Φasu dob∞hne, skript se ukonΦφ, a jako ve v²╣e uvedenΘm p°φpad∞ u╛ivatelskΘho odpojenφ, pokud je zaregistrovanß funkce pro provedenφ p°i ukonΦenφ skriptu, tato se zavolß. Uvnit° tΘto funkce m∙╛te zkontrolovat, jestli jejφ zavolßnφ zp∙sobilo dob∞hnutφ ΦφtaΦe Φasu zavolßnφm funkce <A HREF="#function.connection-timeout" ><B CLASS="function" >connection_timeout()</B ></A >. Tato funkce vrßtφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud volßnφ funkce registrovanΘ pro provedenφ p°i ukonΦenφ skriptu zp∙sobilo dob∞hnutφ ΦφtaΦe Φasu. </P ><P >
SkuteΦnostφ hodnou pov╣imnutφ je, ╛e stavy ABORTED a TIMEOUT mohou b²t aktivnφ souΦasn∞. Mo╛nΘ je to v p°φpad∞, ╛e na°φdφte PHP ignorovat odpojenφ u╛ivatee. PHP i tak bude v∞d∞t, ╛e u╛ivatel p°eru╣il spojenφ, ale skript pob∞╛φ dßl. Pokud potom dosßhne ΦasovΘho limitu, bude ukonΦen, a zavolß se va╣e funkce pro provedenφ p°i ukonΦenφ skriptu, pokud existuje. V tomto okam╛iku zjistφte, ╛e jak <A HREF="#function.connection-timeout" ><B CLASS="function" >connection_timeout()</B ></A >, tak <A HREF="#function.connection-aborted" ><B CLASS="function" >connection_aborted()</B ></A > vracejφ <TT CLASS="constant" ><B >TRUE</B ></TT >. Oba stavy m∙╛ete zkontrolovat jedin²m volßnφm funkce <A HREF="#function.connection-status" ><B CLASS="function" >connection_status()</B ></A >. Tato funkce vracφ bitovΘ pole aktivnφch stav∙. Tak╛e nap°φklad, pokud jsou aktivnφ oba tyto stavy, vrßtφ 3. </P ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.persistent-connections" >Kapitola 21. Persistentnφ databßzovß spojenφ</A ></H1 ><P >
Trvalß spojenφ jsou SQL spojenφ, kterß se nezavφrajφ na konci pr∙b∞hu skriptu. P°i po╛adavku na trvalΘ spojenφ PHP nejd°φve zkontroluje, jestli u╛ neexistuje identickΘ spojenφ (kterΘ z∙stalo otev°eno z d°φv∞j╣ka) - a pokud existuje, pou╛ije ho. Pokud neexistuje, PHP ho otev°e. "IdentickΘ" spojenφ je spojenφ, kterΘ bylo otev°eno se stejn²m serverem, u╛ivatelsk²m jmΘnem a heslem (pokud je zadßte). </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Existujφ i dal╣φ roz╣φ°enφ, kterß vytvß°φ trvalß spojenφ, nap°φklad <A HREF="#ref.imap" >Roz╣φ°enφ IMAP</A >. </P ></BLOCKQUOTE ></DIV ><P >
LidΘ, kte°φ nejsou d∙kladn∞ obeznßmeni se zp∙sobem, jak²m web servery fungujφ a distribuujφ zßt∞╛, mohou poklßdat trvalß spojenφ za n∞co Φφm nejsou. Zvlß╣t∞ <SPAN CLASS="emphasis" ><I CLASS="emphasis" >neumo╛≥ujφ</I ></SPAN > otvφrßnφ "u╛ivatelsk²ch sessions" na stejnΘm SQL spojenφ, <SPAN CLASS="emphasis" ><I CLASS="emphasis" >neumo╛≥ujφ</I ></SPAN > efektivnφ tvorbu transakcφ, a neumo╛≥ujφ spoustu dal╣φch v∞cφ. Dokonce, aby o tom bylo opravdu a d∙kladn∞ jasno, vßm trvalß spojenφ nedajφ <SPAN CLASS="emphasis" ><I CLASS="emphasis" >╛ßdnou</I ></SPAN > funkcionalitu, kterß by nebyla mo╛nß s jejich netrval²mi prot∞j╣ky. </P ><P >
ProΦ? </P ><P >
To je dßno zp∙sobem, jak²m fungujφ webovΘ servery. Jsou t°i zp∙soby, jak²mi vß╣ web server m∙╛e vyu╛φt PHP ke generovßnφ webov²ch strßnek. </P ><P >
Prvnφ metodou je pou╛φt PHP jako CGI "obal". V tomto re╛imu se vytvß°φ a niΦφ jedna instance PHP interpretru pro ka╛d² po╛adavek (na PHP strnßnku) na va╣em web serveru. Proto╛e je zniΦena po obslou╛enφ po╛adavku, v╣echny zdroje, kterΘ zφskß (jako t°eba spojenφ s databßzov²m serverem) jsou p°i jejφm zniΦenφ zav°eny. V tomto p°φpad∞ pokusem o pou╛itφ trval²ch spojenφ nic nezφskßte - prost∞ nevydr╛φ. </P ><P >
Druhou, a nejpopulßrn∞j╣φ, metodou, je provozovat PHP jako modul v multiprocesnφm web serveru, co╛ je mno╛ina, kterß v souΦasnosti obsahuje pouze Apache. Multiprocesnφ web server mß typicky jeden proces (rodiΦe), kter² °φdφ skupinu proces∙ (sv²ch d∞tφ), kterΘ d∞lajφ vlastnφ prßci - servφrujφ strßnky. Ka╛d² po╛adavek, kter² p°ijde od klienta, je obslou╛en jednφm z d∞tφ, kterΘ prßv∞ neobsluhuje jinΘho klienta. To znamenß, ╛e kdy╛ stejn² klient vznese dal╣φ po╛adavek na stejn² server, tento m∙╛e b²t obslou╛en jin²m d∞tsk²m procesem ne╛ ten prvnφ. Trvalß spojenφ zaji╣╗ujφ, aby se ka╛d² d∞tsk² proces musel na vß╣ SQL server p°ihlßsit pouze p°i prvnφm odeslßnφ strßnky, kterß takovΘ spojenφ vyu╛φvß. Kdy╛ spojenφ s SQL serverem vy╛aduje dal╣φ strßnka, m∙╛e pou╛φt spojenφ, kterΘ toto dφt∞ otev°elo u╛ d°φve. </P ><P >
Poslednφ metodou je pou╛φt PHP jako plug-in v multivlßknovΘm web serveru. Aktußln∞ PHP 4 mß tuto podporu pro ISAPI, WSAPI a NSAPI (na Windows), co╛ umo╛nuje pou╛φvat PHP jako plug-in v multivlßknov²ch serverech jako Netscape FastTrack (iPlanet), Microsoft Internet Information Server (IIS), a O'Reilly's WebSite Pro. Chovßnφ je stejnΘ jako u multiprocesnφm modelu popsanΘm d°φve. Podpora pro SAPI nenφ dostupnß v PHP 3. </P ><P >
Pokud trvalß spojenφ neposkytujφ ╛ßdnou p°idanou funkcionalitu, k Φemu jsou dobrß? </P ><P >
Odpov∞∩ na tuto otßzku je velmi jednoduchß - efektivita. Trvalß spojenφ jsou dobrß, pokud mß tvorba spojenφ s va╣φm SQL serverem vysokou re╛ii. Reßlnß v²╣e tΘto re╛ie zßle╛φ na mnoha faktorech. Nap°φklad jak² je to typ databßze, jestli sφdlφ na stejnΘm poΦφtaΦi jako vß╣ webserver, jak zatφ╛en² je stroj, na kterΘm vß╣ SQL server b∞╛φ a tak dßle. Pointa je, ╛e pokud je spojovacφ re╛ie vysokß, trvalß spojenφ vßm znateln∞ pomohou. Umo╛nφ d∞tskΘmu procesu p°ipojit se pouze jednou za cel² jeho ╛ivotnφ cyklus mφsto ka╛dΘho zpracovßnφ strßnky, kterß vy╛aduje spojenφ s SQL serverem. To znamenß, ╛e ka╛dΘ dφt∞, kterΘ otev°elo trvalΘ spojenφ, bude mφt otev°enΘ vlastnφ trvalΘ spojenφ se serverem. Pokud nap°φklad mßte 20 d∞tsk²ch proces∙, kterΘ spustily skript, kter² otev°el trvalΘ spojenφ s va╣φm SQL serverem, mßte 20 nezßvisl²ch spojenφ s SQL serverem, po jednom z ka╛dΘho dφt∞te. </P ><P >
V╣imn∞te si nicmΘn∞, ╛e to m∙╛e mφt nev²hody, pokud pou╛φvate databßzi s omezen²m poΦtem p°ipojenφ, kter² trvalß spojenφ d∞tφ p°ekroΦφ. Pokud mß va╣e databßze limit 16 souΦasn²ch p°ipojenφ, a v ru╣nΘm okam╛iku se pokusφ p°ipojit 17 d∞tsk²ch proces∙, jednomu se to nepoda°φ. Pokud mßte ve sv²ch skriptech chyby, kterΘ brßnφ zavφrßnφ spojenφ (nap°. nekoneΦnΘ smyΦky), databßze s pouh²mi 32 spojenφmi bude brzy zaplavena. Vyhledejte si v dokumentaci va╣φ databßze informace o obsluze opu╣t∞n²ch nebo neΦinn²ch spojenφ. </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Zde je n∞kolik dodateΦn²ch nßmitek, kterΘ se usadily v mysli b∞hem pou╛φvßnφ trval²ch spojenφ. Jedna z nich je, kdy╛ pou╛φvßte zamknutΘ tabulky p°i trvalΘm spojenφ a skript z jakΘhokoli d∙vodu nem∙╛e uvolnit zßmek, pak nßsledujφcφ skript, kter² pou╛φvß stejnΘ spojenφ, bude nejspφ╣e na trvalo zablokovßn a mo╛nß bude nutnΘ, abyste poka╛dΘ restartovali http server nebo databßzov² server. Dßle pak v p°φpad∞ pou╛itφ transakcφ se transakΦnφ blok p°enese i do dal╣φho skriptu pou╛φvajφcφho stejnΘ spojenφ, pokud jeho vykonßnφ konΦφ d°φve ne╛ transakΦnφ blok. V ka╛dΘm p°φpad∞ m∙╛ete pou╛φt <A HREF="#function.register-shutdown-function" ><B CLASS="function" >register_shutdown_function()</B ></A > k registraci a jednoduchΘmu vyΦi╣t∞nφ funkce pro odemknutφ tabulek nebo zru╣enφ b∞╛φcφ transakce (roll back). NejlΘpe se problΘmu vyvarujete ·pln∞ nepou╛φvßnφm trval²ch spojenφ ve skriptech, ve kter²ch se zamykajφ tabulky nebo pou╛φvajφ transakce (m∙╛ete je stßle pou╛φvat na mnoh²ch dal╣φch mφstech). </P ></TD ></TR ></TABLE ></DIV ><P >
D∙le╛it² souhrn. Trvalß spojenφ byla navr╛ena tak, aby odpovφdala jedna k jednΘ normßlnφm spojenφm. To znamenß, ╛e byste <SPAN CLASS="emphasis" ><I CLASS="emphasis" >v╛dy</I ></SPAN > m∞li b²t schopni nahradit trvalß spojenφ netrval²mi beze zm∞ny fungovßnφ va╣eho skriptu. <SPAN CLASS="emphasis" ><I CLASS="emphasis" >M∙╛e</I ></SPAN > to (a pravd∞podobn∞ bude) mφt vliv na efektivitu tohoto skriptu, ale ne jeho chovßnφ! </P ><P >
Dßle takΘ: <A HREF="#function.fbsql-pconnect" ><B CLASS="function" >fbsql_pconnect()</B ></A >, <A HREF="#function.ibase-pconnect" ><B CLASS="function" >ibase_pconnect()</B ></A >, <A HREF="#function.ifx-pconnect" ><B CLASS="function" >ifx_pconnect()</B ></A >, <B CLASS="function" >imap_popen()</B >, <A HREF="#function.ingres-pconnect" ><B CLASS="function" >ingres_pconnect()</B ></A >, <A HREF="#function.msql-pconnect" ><B CLASS="function" >msql_pconnect()</B ></A >, <A HREF="#function.mssql-pconnect" ><B CLASS="function" >mssql_pconnect()</B ></A >, <A HREF="#function.mysql-pconnect" ><B CLASS="function" >mysql_pconnect()</B ></A >, <A HREF="#function.ociplogon" ><B CLASS="function" >OCIPLogon()</B ></A >, <A HREF="#function.odbc-pconnect" ><B CLASS="function" >odbc_pconnect()</B ></A >, <A HREF="#function.ora-plogon" ><B CLASS="function" >Ora_pLogon()</B ></A >, <A HREF="#function.pfsockopen" ><B CLASS="function" >pfsockopen()</B ></A >, <A HREF="#function.pg-pconnect" ><B CLASS="function" >pg_pconnect()</B ></A > a <A HREF="#function.sybase-pconnect" ><B CLASS="function" >sybase_pconnect()</B ></A >. </P ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.safe-mode" >Kapitola 22. BezpeΦn² re╛im</A ></H1 ><P >
BezpeΦn² re╛im PHP je pokus o °e╣enφ bezpeΦnosti sdφlen²ch server∙. Je architekturßln∞ nekorektnφ pokou╣et se °e╣it tento problΘm na ·rovni PHP, ale proto╛e °e╣enφ na ·rovni webovskΘho serveru a operaΦnφho systΘmu nejsou p°φli╣ realistickß, mnoho lidφ, zvla╣t∞ ISP, pou╛φvß nynφ bezpeΦn² re╛im. </P ><P >
KonfiguraΦnφ direktivy, kterΘ ovlßdajφ bezpeΦn² re╛im: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" >safe_mode = Off open_basedir = safe_mode_exec_dir = safe_mode_allowed_env_vars = PHP_ safe_mode_protected_env_vars = LD_LIBRARY_PATH disable_functions =</PRE ></TD ></TR ></TABLE > </P ><P >
Pokud je <A HREF="#ini.safe-mode" >safe_mode</A > zapnut², PHP kontroluje, je-li vlastnφk b∞╛φcφho skriptu vlastnφkem souboru, s nφm╛ se mß manipulovat. Nap°φklad: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ls" >-rw-rw-r-- 1 rasmus rasmus 33 Jul 1 19:20 script.php -rw-r--r-- 1 root root 1116 May 26 18:01 /etc/passwd</PRE ></TD ></TR ></TABLE > Spu╣t∞nφ skriptu script.php <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php readfile('/etc/passwd'); ?></PRE ></TD ></TR ></TABLE > bude mφt v bezpeΦnΘm re╛imu za v²sledek tuto chybu: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Warning: SAFE MODE Restriction in effect. The script whose uid is 500 is not allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2</PRE ></TD ></TR ></TABLE > </P ><P >
Pokud namφsto <A HREF="#ini.safe-mode" >safe_mode</A > nastavφte adresß° <A HREF="#ini.open-basedir" >open_basedir</A >, potom v╣echny operace se soubory budou omezeny pod specifikovan² adresß°. Nap°φklad (p°φklad Apache httpd.conf): <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" ><Directory /docroot> php_admin_value open_basedir /docroot </Directory></PRE ></TD ></TR ></TABLE > Kdy╛ spustφte tent²╛ soubor script.php s timto nastavenφm <A HREF="#ini.open-basedir" >open_basedir</A >, dostanete tento v²sledek: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Warning: open_basedir restriction in effect. File is in wrong directory in /docroot/script.php on line 2</PRE ></TD ></TR ></TABLE > </P ><P >
M∙╛ete takΘ vypnout jednotlivΘ funkce. Pokud p°idßme toto do souboru php.ini: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="ini" >disable_functions readfile,system</PRE ></TD ></TR ></TABLE > zφskßme takov²to v²stup: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Warning: readfile() has been disabled for security reasons in /docroot/script.php on line 2</PRE ></TD ></TR ></TABLE > </P ><DIV CLASS="sect1" ><HR><H2 CLASS="sect1" ><A NAME="features.safe-mode.functions" ></A >Funkce omezenΘ/deaktivovanΘ v bezpeΦnΘm re╛imu</H2 ><P >
Toto je pravd∞podobn∞ ne·pln² a mo╛nß nesprßvn² p°ehled funkcφ omezen²ch v <A HREF="#features.safe-mode" >bezpeΦnΘm re╛imu</A >. <DIV CLASS="table" ><A NAME="AEN6357" ></A ><P ><B >Tabulka 22-1. Funkce omezenΘ v bezpeΦnΘm re╛imu</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Funkce</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Omezenφ</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.dbmopen" ><B CLASS="function" >dbmopen()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.dbase-open" ><B CLASS="function" >dbase_open()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.filepro" ><B CLASS="function" >filepro()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.filepro-rowcount" ><B CLASS="function" >filepro_rowcount()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.filepro-retrieve" ><B CLASS="function" >filepro_retrieve()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >ifx_*()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >sql_safe_mode restrictions, (!= safe mode)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >ingres_*()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >sql_safe_mode restrictions, (!= safe mode)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >mysql_*()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >sql_safe_mode restrictions, (!= safe mode)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_loimport()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.posix-mkfifo" ><B CLASS="function" >posix_mkfifo()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.putenv" ><B CLASS="function" >putenv()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Obeys the safe_mode_protected_env_vars and safe_mode_allowed_env_vars ini-directives. Viz takΘ dokumentaci <A HREF="#function.putenv" ><B CLASS="function" >putenv()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.move-uploaded-file" ><B CLASS="function" >move_uploaded_file()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.chdir" ><B CLASS="function" >chdir()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.dl" ><B CLASS="function" >dl()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Tyto funkce jsou v bezpeΦnΘm re╛imu (<A HREF="#features.safe-mode" >safe-mode</A >) deaktivovßny.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#language.operators.execution" >backtick operßtor</A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Tyto funkce jsou v bezpeΦnΘm re╛imu (<A HREF="#features.safe-mode" >safe-mode</A >) deaktivovßny.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.shell-exec" ><B CLASS="function" >shell_exec()</B ></A > (funkΦnφ ekvivalent backticks)</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Tyto funkce jsou v bezpeΦnΘm re╛imu (<A HREF="#features.safe-mode" >safe-mode</A >) deaktivovßny.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.exec" ><B CLASS="function" >exec()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >M∙╛ete spou╣t∞t programy pouze uvnit° adresß°e <A HREF="#ini.safe-mode-exec-dir" >safe_mode_exec_dir</A >. Z praktick²ch d∙vod∙ nenφ momentßln∞ mo╛nΘ mφt v cest∞ k souboru s programem komponenty <TT CLASS="literal" >..</TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.system" ><B CLASS="function" >system()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >M∙╛ete spou╣t∞t programy pouze uvnit° adresß°e <A HREF="#ini.safe-mode-exec-dir" >safe_mode_exec_dir</A >. Z praktick²ch d∙vod∙ nenφ momentßln∞ mo╛nΘ mφt v cest∞ k souboru s programem komponenty <TT CLASS="literal" >..</TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.passthru" ><B CLASS="function" >passthru()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >M∙╛ete spou╣t∞t programy pouze uvnit° adresß°e <A HREF="#ini.safe-mode-exec-dir" >safe_mode_exec_dir</A >. Z praktick²ch d∙vod∙ nenφ momentßln∞ mo╛nΘ mφt v cest∞ k souboru s programem komponenty <TT CLASS="literal" >..</TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.popen" ><B CLASS="function" >popen()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >M∙╛ete spou╣t∞t programy pouze uvnit° adresß°e <A HREF="#ini.safe-mode-exec-dir" >safe_mode_exec_dir</A >. Z praktick²ch d∙vod∙ nenφ momentßln∞ mo╛nΘ mφt v cest∞ k souboru s programem komponenty <TT CLASS="literal" >..</TT >.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.mkdir" ><B CLASS="function" >mkdir()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.rmdir" ><B CLASS="function" >rmdir()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.rename" ><B CLASS="function" >rename()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.unlink" ><B CLASS="function" >unlink()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.copy" ><B CLASS="function" >copy()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript. (pro <TT CLASS="parameter" ><I >source</I ></TT > a <TT CLASS="parameter" ><I >target</I ></TT >) </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.chgrp" ><B CLASS="function" >chgrp()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.chown" ><B CLASS="function" >chown()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.chmod" ><B CLASS="function" >chmod()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. Navφc nem∙╛ete nastavovat SUID, SGID a sticky bit</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.touch" ><B CLASS="function" >touch()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.symlink" ><B CLASS="function" >symlink()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript. (pozn.: testovßn je pouze cφl)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.link" ><B CLASS="function" >link()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Kontroluje, zda soubory/adresß°e, se kter²mi pracujete, majφ stejnΘ UID jako spu╣t∞n² skript. Kontroluje, zda adresß°, ve kterΘm pracujete, mß stejnΘ UID jako spu╣t∞n² skript. (pozn.: testovßn je pouze cφl)</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="#function.getallheaders" ><B CLASS="function" >getallheaders()</B ></A ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >V bezpeΦnΘm re╛imu nebudou hlaviΦky zaΦφnajφcφ 'authorization' (bez ohledu na velikost pφsmen) vraceny. Varovßnφ: toto nefunguje s aol-server implementacφ <A HREF="#function.getallheaders" ><B CLASS="function" >getallheaders()</B ></A >!</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >JakΘkoli funkce kterΘ pou╛φvajφ <TT CLASS="filename" >php4/main/fopen_wrappers.c</TT > </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >??</TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ></DIV ><DIV CLASS="chapter" ><HR><H1 ><A NAME="features.commandline" >Kapitola 23. Pou╛itφ PHP z p°φkazovΘ °ßdky</A ></H1 ><P >
Mo╛nosti PHP p°i spou╣t∞nφ z p°φkazovΘ °ßdky p°inß╣ejφ mnoho u╛itku, pokud chcete ladit nebo testovat va╣e nastavenφ PHP, hodφ se v╣ak i pro p°φpady, kdy byste rßdi pou╛ili PHP pro jinΘ ·Φely ne╛ WWW skriptovßnφ. </P ><P >
Uv∞domte si, ╛e m∙╛ete v╛dy sm∞rovat v²stup programu PHP do vn∞j╣φho souboru pomocφ znaku >, tak╛e <TT CLASS="literal" >php -q test.php > test.html</TT > vytiskne v²stup <TT CLASS="filename" >test.php</TT > bez HTTP hlaviΦek do <TT CLASS="filename" >test.html</TT > ve stejnΘm adresß°i. </P ><P >
Mo╛nosti p°φkazovΘ °ßdky m∙╛ete vyu╛φvat pouze tehdy, mßte-li (spustiteln²) program PHP. Pokud jste zkompilovali pouze modul do serveru a nemßte na poΦφtaΦi ╛ßdnou CGI verzi, nem∙╛ete p°φkazovou °ßdku pou╛φvat. Pro u╛ivatele Windows je v binßrnφm balφΦku jak serverov² modul, tak spustiteln² soubor nazvan² <TT CLASS="filename" >php.exe</TT >. </P ><P >
Tento seznem voleb pro p°φkazovou °ßdku je konzistentnφ s PHP 4.0.6. Aktußlnφ seznam vΦetn∞ jedno°ßdkov²ch popis∙ m∙╛ete zφskat pomocφ parametru <TT CLASS="literal" >-h</TT >. V²stup <TT CLASS="literal" >php -h</TT > by m∞l vypadat p°ibli╛n∞ takto: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Usage: php [-q] [-h] [-s [-v] [-i] [-f <file>] | {<file> [args...]} -q Quiet-mode. Suppress HTTP Header output. -s Display colour syntax highlighted source. -f <file> Parse <file>. Implies `-q' -v Version number -C Do not chdir to the script's directory -c <path> Look for php.ini file in this directory -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -z <file> Load Zend extension <file>. -l Syntax check only (lint) -m Show compiled in modules -i PHP information -h This help</PRE ></TD ></TR ></TABLE > </P ><P >
Zde uvßdφme n∞kterΘ z nejd∙le╛it∞j╣φch voleb s detailnφm vysv∞tlenφm. </P ><P >
<DIV CLASS="table" ><A NAME="AEN6527" ></A ><P ><B >Tabulka 23-1. Volby pro p°φkazovou °ßdku</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Volba</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Popis</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-q</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
PotlaΦφ v²stup HTTP hlaviΦek. Normßln∞ PHP tiskne HTTP hlaviΦky pro volajφcφ program (typicky WWW server) k p°edßnφ prohlφ╛eΦi. P°i pou╛itφ pro aplikace spou╣t∞nΘ z p°φkazovΘ °ßdky nemajφ hlaviΦky smysl. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-s</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Zobrazφ barevn∞ vysvφcen² zdrojov² soubor s dan²m nßzvem. Je to totΘ╛, jako kdy╛ se zdroj vytiskne pomocφ funkce <A HREF="#function.highlight-file" ><B CLASS="function" >highlight_file()</B ></A > v PHP skriptu. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-f</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Parsuje dan² soubor a hledß syntaktickΘ a fatßlnφ chyby. Tato volba implikuje -q. Pou╛ijte pro ladicφ ·Φely (debugging). </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-v</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Zavolßnφm PHP s tφmto p°epφnaΦem si m∙╛ete vypsat Φφslo verze, nap°. 4.0.6. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-C</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Za normßlnφch okolnostφ PHP m∞nφ pracovnφ adresß° na ten, kde se nachßzφ spou╣t∞n² skript. To nap°φklad umo╛≥uje otvφrat soubory ve stejnΘm adresß°i urΦenφm pouhΘho nßzvu souboru (bez cesty). Pokud byste toto cht∞li potlaΦit, pou╛ijte tuto volbu. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-c</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Pou╛itφm tohoto argumentu m∙╛ete specifikovat alternativnφ umφst∞nφ souboru <TT CLASS="filename" >php.ini</TT >, tak╛e PHP bude hledat konfiguraΦnφ soubor zde namφsto implicitnφho umφst∞nφ. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-d</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Touto volbou m∙╛ete provΘst individußlnφ nastavenφ <TT CLASS="filename" >php.ini</TT > b∞hem provßd∞nφ skriptu. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-l</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Otestuje dan² soubor na syntaktickΘ chyby. Tato volba implikuje -q. Pou╛ijte ji pro ·Φely lad∞nφ. Nebudou se hledat fatßlnφ chyby (jako jsou nedefinovanΘ funkce). Pokud chcete hledat i fatßlnφ chyby, pou╛ijte -f. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-m</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Pou╛itφm tΘto volby PHP vypφ╣e zabudovanΘ (a naΦtenΘ) PHP a Zend moduly, Φφsla verzφ PHP a Zend, a takΘ krßtkou informaci o autorsk²ch prßvech k jßdru Zend. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-i</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Tento p°epφnaΦ zavolß funkci <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A > a vypφ╣e jejφ v²sledek. Pokud PHP nepracuje sprßvn∞, je dobrΘ spustit <TT CLASS="literal" >php -i</TT > a podφvat se, zda se nevypsala n∞jakß chybovß hlß╣enφ p°ed nebo uvnit° informaΦnφch tabulek. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >-h</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Touto volbou zφskßte informace o aktußlnφch volbßch p°φkazovΘ °ßdky a jedno°ßdkovΘ popisy o tom, co d∞lajφ. </TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >
Spustitelnß verze PHP m∙╛e b²t pou╛ita pro spou╣t∞nφ skript∙ absolutn∞ nezßvisle na webovskΘm serveru. Pokud jste na unixovΘm systΘmu, m∙╛ete do PHP skriptu p°idat specißlnφ prvnφ °ßdek a ud∞lat z n∞j spustiteln² program - systΘm bude v∞d∞t, jak² program by m∞l skript zpracovßvat. Na Windows m∙╛ete asociovat <TT CLASS="literal" >php.exe -q</TT > se souborovou p°φponou <TT CLASS="literal" >.php</TT > (pro spou╣t∞nφ dvojklikem), nebo m∙╛ete vytvo°it dßvkov² soubor pro spu╣t∞nφ skriptu p°es PHP. Prvnφ °ßdek skriptu pro prßci v Unixu nebude ve Windows vadit, tak╛e tφmto zp∙sobem m∙╛ete psßt programy pro vφce platforem. Jednoduch² p°φklad psanφ PHP programu pro p°φkazovou °ßdku je uveden nφ╛e. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6576" ></A ><P ><B >P°φklad 23-1. Skript urΦen² ke spou╣t∞nφ z p°φkazovΘ °ßdky (script.php)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >#!/usr/bin/php -q <?php if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) { ?> This is a command line PHP script with one option. Usage: <?php echo $argv[0]; ?> <option> <option> can be some word you would like to print out. With the --help, -help, -h, or -? options, you can get this help. <?php } else { echo $argv[1]; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Ve v²╣e uvedenΘm skriptu jsme pou╛ili specißlnφ prvnφ °ßdek k indikaci, ╛e by tento soubor m∞l b²t spou╣t∞n pomocφ PHP a nem∞l by vypisovat HTTP hlaviΦky. Jsou zde dv∞ prom∞nnΘ, kterΘ m∙╛ete pou╛φt p°i psanφ aplikacφ pro PHP spou╣t∞n²ch z p°φkazovΘ °ßdky: <TT CLASS="varname" >$argc</TT > a <TT CLASS="varname" >$argv</TT >. Prvnφ z nich je poΦet argument∙ + 1 (nßzev b∞╛φcφho skriptu). Druhß je pole obsahujφcφ argumenty, poΦφnaje nßzvem skriptu jako Φφslo 0 (<TT CLASS="varname" >$argv[0]</TT >). </P ><P >
V ukßzkovΘm programu se testuje, zda je argument∙ vφce Φi mΘn∞ ne╛ jeden. Pokud by argument byl <TT CLASS="literal" >--help</TT >, <TT CLASS="literal" >-help</TT >, <TT CLASS="literal" >-h</TT > nebo <TT CLASS="literal" >-?</TT >, vytiskne se nßpov∞da k programu vΦetn∞ skuteΦnΘho nßzvu skriptu. Pokud by byly p°idßny n∞jakΘ dal╣φ argumenty, vytisknou se na v²stup. </P ><P >
Pokud byste cht∞li spou╣t∞t uveden² skript pod Unixem, musφte ho ud∞lat spustiteln²m (nastavit prßva pro spou╣t∞nφ), a pak jednodu╣e napsat <TT CLASS="literal" >script.php vypis_tohle</TT > nebo <TT CLASS="literal" >script.php -h</TT >. Na Windows musφte pro tento ·kol vytvo°it dßvkov² soubor: </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6591" ></A ><P ><B >P°φklad 23-2. Dßvkov² soubor pro spou╣t∞nφ PHP skriptu z p°φkazovΘ °ßdky (script.bat)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="winbat" >@c:\php\php.exe -q script.php %1 %2 %3 %4</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
Za p°edpokladu, ╛e jste v²╣e uveden² program nazvali <TT CLASS="filename" >script.php</TT > a soubor <TT CLASS="filename" >php.exe</TT > mßte ulo╛en² jako <TT CLASS="filename" >c:\php\php.exe</TT >, m∙╛ete tento dßvkov² soubor spou╣t∞t takto: <TT CLASS="literal" >script.bat echothis</TT > nebo <TT CLASS="literal" >script.bat -h</TT >. </P ><P >
Viz takΘ dokumentaci roz╣φ°enφ <A HREF="#ref.readline" >Readline</A >, kde najdete vφce funkcφ pro pou╛itφ k aplikacφm PHP spou╣t∞n²ch z p°φkazovΘ °ßdky. </P ></DIV ></DIV ><DIV CLASS="PART" ><A NAME="funcref" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >V. Reference funkcφ</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT >I. <A HREF="#ref.apache" >Funkce specifickΘ pro Apache</A ></DT ><DT >II. <A HREF="#ref.array" >Funkce pro prßci s poli</A ></DT ><DT >III. <A HREF="#ref.aspell" >Aspell funkce [zastaralΘ]</A ></DT ><DT >IV. <A HREF="#ref.bc" >BCMath funkce pro v²poΦty s libovolnou p°esnostφ</A ></DT ><DT >V. <A HREF="#ref.bzip2" >Kompresnφ funkce bzip2</A ></DT ><DT >VI. <A HREF="#ref.calendar" >Kalendß°ovΘ funkce</A ></DT ><DT >VII. <A HREF="#ref.ccvs" >CCVS API Functions</A ></DT ><DT >VIII. <A HREF="#ref.com" >Funkce na podporu COM ve Windows</A ></DT ><DT >IX. <A HREF="#ref.classobj" >Funkce pro prßci s t°φdami/objekty</A ></DT ><DT >X. <A HREF="#ref.cpdf" >ClibPDF functions</A ></DT ><DT >XI. <A HREF="#ref.crack" >Crack functions</A ></DT ><DT >XII. <A HREF="#ref.curl" >Funkce pro prßci s CURL, Client URL Library</A ></DT ><DT >XIII. <A HREF="#ref.cybercash" >Cybercash platebnφ funkce</A ></DT ><DT >XIV. <A HREF="#ref.cyrus" >Cyrus IMAP administration functions</A ></DT ><DT >XV. <A HREF="#ref.ctype" >Character type functions</A ></DT ><DT >XVI. <A HREF="#ref.dba" >Database (dbm-style) abstraction layer functions</A ></DT ><DT >XVII. <A HREF="#ref.datetime" >Funkce pro datum a Φas</A ></DT ><DT >XVIII. <A HREF="#ref.dbase" >dBase functions</A ></DT ><DT >XIX. <A HREF="#ref.dbm" >DBM Funkce [zastaralΘ]</A ></DT ><DT >XX. <A HREF="#ref.dbx" >dbx functions</A ></DT ><DT >XXI. <A HREF="#ref.dbplus" >DB++ Functions</A ></DT ><DT >XXII. <A HREF="#ref.dio" >Direct IO functions</A ></DT ><DT >XXIII. <A HREF="#ref.dir" >Adresß°ovΘ funkce</A ></DT ><DT >XXIV. <A HREF="#ref.domxml" >DOM XML functions</A ></DT ><DT >XXV. <A HREF="#ref.dotnet" >.NET functions</A ></DT ><DT >XXVI. <A HREF="#ref.errorfunc" >Error Handling and Logging Functions</A ></DT ><DT >XXVII. <A HREF="#ref.fam" >File alteration monitor functions</A ></DT ><DT >XXVIII. <A HREF="#ref.fbsql" >FrontBase Functions</A ></DT ><DT >XXIX. <A HREF="#ref.filepro" >filePro funkce</A ></DT ><DT >XXX. <A HREF="#ref.filesystem" >Funkce filesystΘmu</A ></DT ><DT >XXXI. <A HREF="#ref.fdf" >Forms Data Format functions</A ></DT ><DT >XXXII. <A HREF="#ref.fribidi" >FriBiDi functions</A ></DT ><DT >XXXIII. <A HREF="#ref.ftp" >FTP functions</A ></DT ><DT >XXXIV. <A HREF="#ref.funchand" >Funkce pro prßci s funkcemi</A ></DT ><DT >XXXV. <A HREF="#ref.gettext" >Gettext</A ></DT ><DT >XXXVI. <A HREF="#ref.gmp" >GMP functions</A ></DT ><DT >XXXVII. <A HREF="#ref.http" >HTTP funkce</A ></DT ><DT >XXXVIII. <A HREF="#ref.hyperwave" >Hyperwave functions</A ></DT ><DT >XXXIX. <A HREF="#ref.hwapi" >Hyperwave API functions</A ></DT ><DT >XL. <A HREF="#ref.iconv" >iconv functions</A ></DT ><DT >XLI. <A HREF="#ref.image" >Image functions</A ></DT ><DT >XLII. <A HREF="#ref.imap" >IMAP, POP3 and NNTP functions</A ></DT ><DT >XLIII. <A HREF="#ref.ifx" >Informix functions</A ></DT ><DT >XLIV. <A HREF="#ref.ibase" >InterBase functions</A ></DT ><DT >XLV. <A HREF="#ref.ingres" >Ingres II functions</A ></DT ><DT >XLVI. <A HREF="#ref.ircg" >IRC Gateway Functions</A ></DT ><DT >XLVII. <A HREF="#ref.java" >PHP / Java Integration</A ></DT ><DT >XLVIII. <A HREF="#ref.ldap" >LDAP functions</A ></DT ><DT >XLIX. <A HREF="#ref.mail" >MailovΘ funkce</A ></DT ><DT >L. <A HREF="#ref.mailparse" >mailparse functions</A ></DT ><DT >LI. <A HREF="#ref.math" >MatematickΘ funkce</A ></DT ><DT >LII. <A HREF="#ref.mbstring" >Multi-Byte String Functions</A ></DT ><DT >LIII. <A HREF="#ref.mcal" >MCAL functions</A ></DT ><DT >LIV. <A HREF="#ref.mcrypt" >Mcrypt Encryption Functions</A ></DT ><DT >LV. <A HREF="#ref.mcve" >MCVE Payment Functions</A ></DT ><DT >LVI. <A HREF="#ref.mhash" >Mhash funkce</A ></DT ><DT >LVII. <A HREF="#ref.mime-magic" >Mimetype Functions</A ></DT ><DT >LVIII. <A HREF="#ref.mssql" >Microsoft SQL Server functions</A ></DT ><DT >LIX. <A HREF="#ref.ming" >Ming functions for Flash</A ></DT ><DT >LX. <A HREF="#ref.misc" >R∙znΘ funkce</A ></DT ><DT >LXI. <A HREF="#ref.mnogo" >mnoGoSearch Functions</A ></DT ><DT >LXII. <A HREF="#ref.msql" >mSQL functions</A ></DT ><DT >LXIII. <A HREF="#ref.mysql" >MySQL funkce</A ></DT ><DT >LXIV. <A HREF="#ref.mysqli" >Improved MySQL Extension</A ></DT ><DT >LXV. <A HREF="#ref.msession" >Mohawk Software session handler functions</A ></DT ><DT >LXVI. <A HREF="#ref.muscat" >muscat functions</A ></DT ><DT >LXVII. <A HREF="#ref.network" >Sφ╗ovΘ funkce</A ></DT ><DT >LXVIII. <A HREF="#ref.ncurses" >Ncurses terminal screen control functions</A ></DT ><DT >LXIX. <A HREF="#ref.notes" >Lotus Notes functions</A ></DT ><DT >LXX. <A HREF="#ref.nsapi" >NSAPI-specific Functions</A ></DT ><DT >LXXI. <A HREF="#ref.odbc" >Unified ODBC functions</A ></DT ><DT >LXXII. <A HREF="#ref.objaggregation" >Object Aggregation/Composition Functions</A ></DT ><DT >LXXIII. <A HREF="#ref.oci8" >Oracle 8 functions</A ></DT ><DT >LXXIV. <A HREF="#ref.openssl" >OpenSSL funkce</A ></DT ><DT >LXXV. <A HREF="#ref.oracle" >Oracle functions</A ></DT ><DT >LXXVI. <A HREF="#ref.ovrimos" >Ovrimos SQL functions</A ></DT ><DT >LXXVII. <A HREF="#ref.outcontrol" >Funkce pro °φzenφ v²stupu</A ></DT ><DT >LXXVIII. <A HREF="#ref.overload" >Object property and method call overloading</A ></DT ><DT >LXXIX. <A HREF="#ref.pdf" >PDF funkce</A ></DT ><DT >LXXX. <A HREF="#ref.pfpro" >Funkce pro prßci s Verisign Payflow Pro</A ></DT ><DT >LXXXI. <A HREF="#ref.info" >PHP volby a informace</A ></DT ><DT >LXXXII. <A HREF="#ref.posix" >POSIX functions</A ></DT ><DT >LXXXIII. <A HREF="#ref.pgsql" >PostgreSQL functions</A ></DT ><DT >LXXXIV. <A HREF="#ref.pcntl" >Process Control Functions</A ></DT ><DT >LXXXV. <A HREF="#ref.exec" >Funkce spou╣t∞nφ program∙</A ></DT ><DT >LXXXVI. <A HREF="#ref.printer" >Printer functions</A ></DT ><DT >LXXXVII. <A HREF="#ref.pspell" >Pspell Functions</A ></DT ><DT >LXXXVIII. <A HREF="#ref.readline" >GNU Readline</A ></DT ><DT >LXXXIX. <A HREF="#ref.recode" >GNU Recode funkce</A ></DT ><DT >XC. <A HREF="#ref.pcre" >Regular Expression Functions (Perl-Compatible)</A ></DT ><DT >XCI. <A HREF="#ref.qtdom" >qtdom functions</A ></DT ><DT >XCII. <A HREF="#ref.regex" >Regular Expression Functions (POSIX Extended)</A ></DT ><DT >XCIII. <A HREF="#ref.sem" >Semaphore, Shared Memory and IPC Functions</A ></DT ><DT >XCIV. <A HREF="#ref.sesam" >SESAM database functions</A ></DT ><DT >XCV. <A HREF="#ref.session" >Session handling functions</A ></DT ><DT >XCVI. <A HREF="#ref.shmop" >Funkce pro prßci se sdφlenou pam∞tφ</A ></DT ><DT >XCVII. <A HREF="#ref.sqlite" >SQLite</A ></DT ><DT >XCVIII. <A HREF="#ref.swf" >Shockwave Flash functions</A ></DT ><DT >XCIX. <A HREF="#ref.snmp" >SNMP functions</A ></DT ><DT >C. <A HREF="#ref.sockets" >Socket functions</A ></DT ><DT >CI. <A HREF="#ref.stream" >Stream functions</A ></DT ><DT >CII. <A HREF="#ref.strings" >Funkce pro prßci s °et∞zci</A ></DT ><DT >CIII. <A HREF="#ref.sybase" >Sybase functions</A ></DT ><DT >CIV. <A HREF="#ref.tidy" >tidy Functions</A ></DT ><DT >CV. <A HREF="#ref.tokenizer" >Tokenizer functions</A ></DT ><DT >CVI. <A HREF="#ref.url" >URL funkce</A ></DT ><DT >CVII. <A HREF="#ref.variables" >Variable Functions</A ></DT ><DT >CVIII. <A HREF="#ref.vpopmail" >vpopmail functions</A ></DT ><DT >CIX. <A HREF="#ref.w32api" >W32api functions</A ></DT ><DT >CX. <A HREF="#ref.wddx" >WDDX funkce</A ></DT ><DT >CXI. <A HREF="#ref.xml" >XML parser functions</A ></DT ><DT >CXII. <A HREF="#ref.xmlrpc" >XML-RPC functions</A ></DT ><DT >CXIII. <A HREF="#ref.xslt" >XSLT funkce</A ></DT ><DT >CXIV. <A HREF="#ref.yaz" >YAZ functions</A ></DT ><DT >CXV. <A HREF="#ref.nis" >Funkce pro prßci s YP/NIS</A ></DT ><DT >CXVI. <A HREF="#ref.zip" >Zip File Functions (Read Only Access)</A ></DT ><DT >CXVII. <A HREF="#ref.zlib" >Zlib Compression Functions</A ></DT ></DL ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.apache" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >I. Funkce specifickΘ pro Apache</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN6607" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="apache.intro" ></A >┌vod</H1 ><P >
Tyto funkce jsou k dispozici pouze pokud PHP b∞╛φ jako modul Apache 1.x. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="apache.installation" ></A >Instalace</H1 ><P >
Instalaci PHP v Apache 1.x viz <A HREF="#install.apache" >Φßst Apache</A > kapitoly o instalaci. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="apache.configuration" ></A >Konfigurace b∞hu</H1 ><P >
The behaviour of the Apache PHP module is affected by settings in <TT CLASS="filename" >php.ini</TT >. Configuration settings from <TT CLASS="filename" >php.ini</TT > may be overridden by php_flag settings in the server configuration file or local <TT CLASS="filename" >.htaccess</TT > files. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6621" ></A ><P ><B >P°φklad 1. Turning off PHP parsing for a directory using <TT CLASS="filename" >.htaccess</TT ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >php_flag engine off</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
<DIV CLASS="table" ><A NAME="AEN6626" ></A ><P ><B >Tabulka 1. Apache configuration options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Function</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >engine</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >On</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >turns PHP parsing on or off</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >child_terminate</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Off</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
specify whether PHP scripts may request child process termination on end of request, see also <A HREF="#function.apache-child-terminate" ><B CLASS="function" >apache_child_terminate()</B ></A > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >last_modified</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Off</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >send PHP scripts modification date as Last-Modified: header for this request</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >xbithack</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Off</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >parse files with executable bit set as PHP regardless of their file ending</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.engine" ></A ><TT CLASS="parameter" ><I >engine</I ></TT > <A HREF="#language.types.boolean" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P >
This directive is really only useful in the Apache module version of PHP. It is used by sites that would like to turn PHP parsing on and off on a per-directory or per-virtual server basis. By putting <TT CLASS="userinput" ><B >engine off</B ></TT > in the appropriate places in the <TT CLASS="filename" >httpd.conf</TT > file, PHP can be enabled or disabled. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="apache.resources" ></A >Typy prost°edk∙</H1 ><P >Toto roz╣φ°enφ nemß definovßn ╛ßdn² typ prost°edku (resource).</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="apache.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >Toto roz╣φ°enφ nemß definovßny ╛ßdnΘ konstanty.</P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.apache-child-terminate" >apache_child_terminate</A > -- Terminate apache process after this request</DT ><DT ><A HREF="#function.apache-get-version" >apache_get_version</A > -- Fetch Apache version </DT ><DT ><A HREF="#function.apache-lookup-uri" >apache_lookup_uri</A > -- Provßdφ ΦßsteΦn² po╛adavek na zadanou URI a vracφ v╣echno info o nφ </DT ><DT ><A HREF="#function.apache-note" >apache_note</A > -- Zφskßvß a nastavuje poznßmky po╛adavku u Apache.</DT ><DT ><A HREF="#function.apache-request-headers" >apache_request_headers</A > -- Fetch all HTTP request headers</DT ><DT ><A HREF="#function.apache-response-headers" >apache_response_headers</A > -- Fetch all HTTP response headers </DT ><DT ><A HREF="#function.apache-setenv" >apache_setenv</A > -- Set an Apache subprocess_env variable</DT ><DT ><A HREF="#function.ascii2ebcdic" >ascii2ebcdic</A > -- P°eklßdß °et∞zec z ASCII do EBCDIC</DT ><DT ><A HREF="#function.ebcdic2ascii" >ebcdic2ascii</A > -- P°eklßdß °et∞zec z EBCDIC do ASCII</DT ><DT ><A HREF="#function.getallheaders" >getallheaders</A > -- Zφskßvß v╣echny hlaviΦky HTTP po╛adavku</DT ><DT ><A HREF="#function.virtual" >virtual</A > -- Provßdφ sub-po╛adavek Apache</DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.apache-child-terminate" ></A >apache_child_terminate</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6675" ></A ><P > (PHP 4 >= 4.0.5)</P >apache_child_terminate -- Terminate apache process after this request</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6678" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >apache_child_terminate</B > ( void )<BR ></BR ><P >
<B CLASS="function" >apache_child_terminate()</B > will register the Apache process executing the current PHP request for termination once execution of PHP code it is completed. It may be used to terminate a process after a script with high memory consumption has been run as memory will usually only be freed internally but not given back to the operating system. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The availability of this feature is controlled by the <TT CLASS="filename" >php.ini</TT > directive <TT CLASS="option" >child_terminate</TT >, which is set to <TT CLASS="literal" >off</TT > by default. </P ><P >
This feature is also not available on multithreaded versions of apache like the win32 version. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.exit" ><B CLASS="function" >exit()</B ></A >. </P ></DIV ><H1 ><A NAME="function.apache-get-version" ></A >apache_get_version</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6695" ></A ><P > (PHP 4 >= 4.3.2)</P >apache_get_version -- Fetch Apache version </DIV ><DIV CLASS="refsect1" ><A NAME="AEN6698" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >apache_get_version</B > ( void )<BR ></BR ><P >
<B CLASS="function" >apache_get_version()</B > returns the version of Apache as string, or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6707" ></A ><P ><B >P°φklad 1. <B CLASS="function" >apache_get_version()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $version = apache_get_version(); echo "$version \n <br \>"; ?></PRE ></TD ></TR ></TABLE ><P >
The printout of the above program will look similar to: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Apache/1.3.29 (Unix) PHP/4.3.4</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
See also <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A >. </P ></DIV ><H1 ><A NAME="function.apache-lookup-uri" ></A >apache_lookup_uri</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6716" ></A ><P > (PHP 3>= 3.0.4, PHP 4 )</P >apache_lookup_uri -- Provßdφ ΦßsteΦn² po╛adavek na zadanou URI a vracφ v╣echno info o nφ </DIV ><DIV CLASS="refsect1" ><A NAME="AEN6719" ></A ><H2 >Popis</H2 >class <B CLASS="methodname" >apache_lookup_uri</B > ( string filename)<BR ></BR ><P >
Tato funkce provßdφ ΦßsteΦn² po╛adavek na URI. Jde jen tak daleko, aby zφskala v╣echny d∙le╛itΘ informace o danΘm zdroji a vracφ tyto informace ve t°φd∞. Vlastnosti tΘto t°φdy jsou: <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >status</TD ></TR ><TR ><TD >the_request</TD ></TR ><TR ><TD >status_line</TD ></TR ><TR ><TD >method</TD ></TR ><TR ><TD >content_type</TD ></TR ><TR ><TD >handler</TD ></TR ><TR ><TD >uri</TD ></TR ><TR ><TD >filename</TD ></TR ><TR ><TD >path_info</TD ></TR ><TR ><TD >args</TD ></TR ><TR ><TD >boundary</TD ></TR ><TR ><TD >no_cache</TD ></TR ><TR ><TD >no_local_copy</TD ></TR ><TR ><TD >allowed</TD ></TR ><TR ><TD >send_bodyct</TD ></TR ><TR ><TD >bytes_sent</TD ></TR ><TR ><TD >byterange</TD ></TR ><TR ><TD >clength</TD ></TR ><TR ><TD >unparsed_uri</TD ></TR ><TR ><TD >mtime</TD ></TR ><TR ><TD >request_time</TD ></TR ></TBODY ></TABLE ><P ></P > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <B CLASS="function" >apache_lookup_uri()</B > pouze, pokud je PHP nainstalovßno jako modul Apache. </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.apache-note" ></A >apache_note</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6754" ></A ><P > (PHP 3>= 3.0.2, PHP 4 )</P >apache_note -- Zφskßvß a nastavuje poznßmky po╛adavku u Apache.</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6757" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >apache_note</B > ( string note_name [, string note_value])<BR ></BR ><P >
<B CLASS="function" >apache_note()</B > je funkce specifickß pro Apache, kterß zφskßvß a nastavuje hodnoty v tabulce <TT CLASS="literal" >poznßmek</TT > po╛adavku. P°i volßnφ s jednφm argumentem vracφ souΦasnou hodnotu poznßmky <TT CLASS="literal" >note_name</TT >. P°i volßnφ se dv∞ma argumenty nastavuje hodnotu poznßmky <TT CLASS="literal" >note_name</TT > na <TT CLASS="literal" >note_value</TT >, a vracφ p°edchozφ hodnotu poznßmky <TT CLASS="literal" >note_name</TT >. </P ></DIV ><H1 ><A NAME="function.apache-request-headers" ></A >apache_request_headers</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6776" ></A ><P > (PHP 4 >= 4.3.0)</P >apache_request_headers -- Fetch all HTTP request headers</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6779" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >apache_request_headers</B > ( void )<BR ></BR ><P >
<B CLASS="function" >apache_request_headers()</B > returns an associative array of all the HTTP headers in the current request. This is only supported when PHP runs as an <SPAN CLASS="productname" >Apache</SPAN > module. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6789" ></A ><P ><B >P°φklad 1. <B CLASS="function" >apache_request_headers()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $headers = apache_request_headers(); foreach ($headers as $header => $value) { echo "$header: $value <br />\n"; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Prior to PHP 4.3.0, <B CLASS="function" >apache_request_headers()</B > was called <A HREF="#function.getallheaders" ><B CLASS="function" >getallheaders()</B ></A >. After PHP 4.3.0, <A HREF="#function.getallheaders" ><B CLASS="function" >getallheaders()</B ></A > is an alias for <B CLASS="function" >apache_request_headers()</B >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > You can also get at the value of the common CGI variables by reading them from the environment, which works whether or not you are using PHP as an <SPAN CLASS="productname" >Apache</SPAN > module. Use <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A > to see a list of all of the available <A HREF="#language.variables.predefined" >environment variables</A >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > From PHP 4.3.3 on you can use this function with the <A HREF="#ref.nsapi" >NSAPI server module</A > in Netscape/iPlanet/SunONE webservers, too. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.apache-response-headers" ><B CLASS="function" >apache_response_headers()</B ></A >. </P ></DIV ><H1 ><A NAME="function.apache-response-headers" ></A >apache_response_headers</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6810" ></A ><P > (PHP 4 >= 4.3.0)</P >apache_response_headers -- Fetch all HTTP response headers </DIV ><DIV CLASS="refsect1" ><A NAME="AEN6813" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >apache_response_headers</B > ( void )<BR ></BR ><P >
Returns an array of all Apache response headers. This functionality is only available in PHP version 4.3.0 and greater. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > From PHP 4.3.3 on you can use this function with the <A HREF="#ref.nsapi" >NSAPI server module</A > in Netscape/iPlanet/SunONE webservers, too. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.apache-request-headers" ><B CLASS="function" >apache_request_headers()</B ></A >, and <A HREF="#function.headers-sent" ><B CLASS="function" >headers_sent()</B ></A >. </P ></DIV ><H1 ><A NAME="function.apache-setenv" ></A >apache_setenv</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6827" ></A ><P > (PHP 4 >= 4.2.0)</P >apache_setenv -- Set an Apache subprocess_env variable</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6830" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >apache_setenv</B > ( string variable, string value [, bool walk_to_top])<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ascii2ebcdic" ></A >ascii2ebcdic</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6848" ></A ><P > (PHP 3>= 3.0.17)</P >ascii2ebcdic -- P°eklßdß °et∞zec z ASCII do EBCDIC</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6851" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >ascii2ebcdic</B > ( string ascii_str)<BR ></BR ><P >
<B CLASS="function" >ascii2ebcdic()</B > je funkce specifickß pro Apache dostupnß pouze na operaΦnφch systΘmech zalo╛en²ch na EBCDIC (OS/390, BS2000). P°eklßdß (binßrn∞ bezpeΦn∞) °e╛∞zec v ASCII k≤dovßnφ <TT CLASS="parameter" ><I >ascii_str</I ></TT > na jeho ekvivalentnφ EBCDIC reprezentaci, a vracφ v²sledek. </P ><P >
Viz takΘ opaΦnou funkci <A HREF="#function.ebcdic2ascii" ><B CLASS="function" >ebcdic2ascii()</B ></A > </P ></DIV ><H1 ><A NAME="function.ebcdic2ascii" ></A >ebcdic2ascii</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6865" ></A ><P > (PHP 3>= 3.0.17)</P >ebcdic2ascii -- P°eklßdß °et∞zec z EBCDIC do ASCII</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6868" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >ebcdic2ascii</B > ( string ebcdic_str)<BR ></BR ><P >
<B CLASS="function" >ebcdic2ascii()</B > je funkce specifickß pro Apache dostupnß pouze na operaΦnφch systΘmech zalo╛en²ch na EBCDIC (OS/390, BS2000). P°eklßdß (binßrn∞ bezpeΦn∞) °e╛∞zec v k≤dovßnφ EBCDIC <TT CLASS="parameter" ><I >ascii_str</I ></TT > na jeho ekvivalentnφ ASCII reprezentaci, a vracφ v²sledek. </P ><P >
Viz takΘ opaΦnou funkci <A HREF="#function.ascii2ebcdic" ><B CLASS="function" >ascii2ebcdic()</B ></A > </P ></DIV ><H1 ><A NAME="function.getallheaders" ></A >getallheaders</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6882" ></A ><P > (PHP 3, PHP 4 )</P >getallheaders -- Zφskßvß v╣echny hlaviΦky HTTP po╛adavku</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6885" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >getallheaders</B > ( void )<BR ></BR ><P >
Tato funkce vracφ asociativnφ pole v╣ech HTTP hlaviΦek v souΦasnΘm po╛adavku. </P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Hodnotu b∞╛n²ch CGI prom∞nn²ch m∙╛ete takΘ zφskat tφm, ╛e je p°eΦtete z prost°edφ, co╛ funguje, a╗ pou╛φvßte PHP jako modu Apache nebo ne. Pokud chcete vid∞t seznam v╣ech systΘmov²ch prom∞nn²ch definovan²ch tφmto zp∙sobem, pou╛ijte <A HREF="#function.phpinfo" ><B CLASS="function" >phpinfo()</B ></A >. </P ></BLOCKQUOTE ></DIV > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6899" ></A ><P ><B >P°φklad 1. <B CLASS="function" >getallheaders()</B > Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$headers = getallheaders(); while (list ($header, $value) = each ($headers)) { echo "$header: $value<br>\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tento p°φklad zobrazφ v╣echny hlaviΦky souΦasnΘho po╛adavku. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <B CLASS="function" >getallheaders()</B > je v souΦasnosti podporovßna jen kdy╛ PHP b∞╛φ jako modul <SPAN CLASS="productname" >Apache</SPAN >. </P ></BLOCKQUOTE ></DIV > </P ></DIV ><H1 ><A NAME="function.virtual" ></A >virtual</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN6909" ></A ><P > (PHP 3, PHP 4 )</P >virtual -- Provßdφ sub-po╛adavek Apache</DIV ><DIV CLASS="refsect1" ><A NAME="AEN6912" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >virtual</B > ( string filename)<BR ></BR ><P >
<B CLASS="function" >virtual()</B > je funkce specifickß pro Apache ekvivalentnφ s <!--#include virtual...--> v mod_include. Provßdφ sub-po╛adavek Apache. Je u╛iteΦnß pro vklßdßnφ CGI skript∙ nebo .shtml soubor∙, nebo Φehokoliv jinΘho, co mß Apache parsovat. CGI skripty musφ generovat platnΘ CGI hlaviΦky. To znamenß, ╛e musφ p°inejmen╣φm generovat Content-type hlaviΦku. Pro PHP soubory musφte pou╛φt <A HREF="#function.include" ><B CLASS="function" >include()</B ></A > nebo <A HREF="#function.require" ><B CLASS="function" >require()</B ></A >; <B CLASS="function" >virtual()</B > se nedß pou╛φt k vlo╛enφ dokumentu, kter² je sßm PHP skriptem. </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.array" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >II. Funkce pro prßci s poli</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN6928" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="array.intro" ></A >┌vod</H1 ><P >
Tyto funkce vßm umo╛≥ujφ manipulovat a interagovat r∙zn²mi zp∙soby s poli. Pole jsou nezbytnß pro uklßdßnφ a prßci se sadami prom∞nn²ch. </P ><P >
Podporovßna jsou jednoduchß a vφcerozm∞rnß pole; vytvß°et se dajφ u╛ivatelsky i jako v²stup funkce. Existujφ databßzovΘ funkce na pln∞nφ polφ v²sledky databßzov²ch dotaz∙, a n∞kolik dal╣φch funkcφ vracφ pole. </P ><P >
Viz takΘ Φßst manußlu <A HREF="#language.types.array" >pole</A > pro detailnφ popis toho, jak jsou pole v PHP implementovßny a jak se pou╛φvajφ. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="array.requirements" ></A >Po╛adavky</H1 ><P >Tyto funkce jsou k dispozici jako souΦßst standardnφho modulu, kter² je v╛dy dostupn².</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="array.installation" ></A >Instalace</H1 ><P >K pou╛φvßnφ t∞chto funkcφ nenφ t°eba ╛ßdnß instalace, jsou souΦßstφ jßdra PHP.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="array.configuration" ></A >Konfigurace b∞hu</H1 ><P >Toto roz╣φ°enφ nemß definovßno ╛ßdnΘ konfiguraΦnφ direktivy.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="array.resources" ></A >Typy prost°edk∙</H1 ><P >Toto roz╣φ°enφ nemß definovßn ╛ßdn² typ prost°edku (resource).</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="array.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >
Konstanty z tohoto seznamu jsou v╛dy dostupnΘ jako souΦßst jßdra PHP. </P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CASE_LOWER</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
<TT CLASS="constant" ><B >CASE_LOWER</B ></TT > is used with <A HREF="#function.array-change-key-case" ><B CLASS="function" >array_change_key_case()</B ></A > and is used to convert array keys to lower case. This is also the default case for <A HREF="#function.array-change-key-case" ><B CLASS="function" >array_change_key_case()</B ></A >. </P ></DD ><DT ><TT CLASS="constant" ><B >CASE_UPPER</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
<TT CLASS="constant" ><B >CASE_UPPER</B ></TT > is used with <A HREF="#function.array-change-key-case" ><B CLASS="function" >array_change_key_case()</B ></A > and is used to convert array keys to upper case. </P ></DD ></DL ></DIV > </P ><P > Sorting order flags: <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >SORT_ASC</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
<TT CLASS="constant" ><B >SORT_ASC</B ></TT > is used with <A HREF="#function.array-multisort" ><B CLASS="function" >array_multisort()</B ></A > to sort in ascending order. </P ></DD ><DT ><TT CLASS="constant" ><B >SORT_DESC</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
<TT CLASS="constant" ><B >SORT_DESC</B ></TT > is used with <A HREF="#function.array-multisort" ><B CLASS="function" >array_multisort()</B ></A > to sort in descending order. </P ></DD ></DL ></DIV > </P ><P > Sorting type flags: used by various sort functions <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >SORT_REGULAR</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
<TT CLASS="constant" ><B >SORT_REGULAR</B ></TT > is used to compare items normally. </P ></DD ><DT ><TT CLASS="constant" ><B >SORT_NUMERIC</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
<TT CLASS="constant" ><B >SORT_NUMERIC</B ></TT > is used to compare items numerically. </P ></DD ><DT ><TT CLASS="constant" ><B >SORT_STRING</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
<TT CLASS="constant" ><B >SORT_STRING</B ></TT > is used to compare items as strings. </P ></DD ></DL ></DIV > </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >COUNT_NORMAL</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >COUNT_RECURSIVE</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_OVERWRITE</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_SKIP</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_PREFIX_SAME</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_PREFIX_ALL</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_PREFIX_INVALID</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_PREFIX_IF_EXISTS</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_IF_EXISTS</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >EXTR_REFS</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="array.seealso" ></A >Viz takΘ</H1 ><P >
Viz takΘ <A HREF="#function.is-array" ><B CLASS="function" >is_array()</B ></A >, <A HREF="#function.explode" ><B CLASS="function" >explode()</B ></A >, <A HREF="#function.implode" ><B CLASS="function" >implode()</B ></A >, <A HREF="#function.split" ><B CLASS="function" >split()</B ></A >, <A HREF="#function.preg-split" ><B CLASS="function" >preg_split()</B ></A > a <A HREF="#function.unset" ><B CLASS="function" >unset()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.array-change-key-case" >array_change_key_case</A > -- Returns an array with all string keys lowercased or uppercased</DT ><DT ><A HREF="#function.array-chunk" >array_chunk</A > -- Split an array into chunks</DT ><DT ><A HREF="#function.array-combine" >array_combine</A > -- Creates an array by using one array for keys and another for its values </DT ><DT ><A HREF="#function.array-count-values" >array_count_values</A > -- SpoΦφtat v╣echny hodnoty v poli</DT ><DT ><A HREF="#function.array-diff-assoc" >array_diff_assoc</A > -- Computes the difference of arrays with additional index check</DT ><DT ><A HREF="#function.array-diff-uassoc" >array_diff_uassoc</A > -- Computes the difference of arrays with additional index check which is performed by a user supplied callback function.</DT ><DT ><A HREF="#function.array-diff" >array_diff</A > -- SpoΦφtat rozdφl polφ</DT ><DT ><A HREF="#function.array-fill" >array_fill</A > -- Fill an array with values</DT ><DT ><A HREF="#function.array-filter" >array_filter</A > -- Filters elements of an array using a callback function </DT ><DT ><A HREF="#function.array-flip" >array_flip</A > -- Prohodit klφΦe a hodnoty pole</DT ><DT ><A HREF="#function.array-intersect-assoc" >array_intersect_assoc</A > -- Computes the intersection of arrays with additional index check</DT ><DT ><A HREF="#function.array-intersect" >array_intersect</A > -- SpoΦφtat pr∙nik polφ</DT ><DT ><A HREF="#function.array-key-exists" >array_key_exists</A > -- Checks if the given key or index exists in the array</DT ><DT ><A HREF="#function.array-keys" >array_keys</A > -- Vrßtit v╣echny klφΦe pole</DT ><DT ><A HREF="#function.array-map" >array_map</A > -- Applies the callback to the elements of the given arrays </DT ><DT ><A HREF="#function.array-merge-recursive" >array_merge_recursive</A > -- Rekurzivn∞ slouΦit dv∞ nebo vφce polφ</DT ><DT ><A HREF="#function.array-merge" >array_merge</A > -- SlouΦit dv∞ nebo vφce polφ</DT ><DT ><A HREF="#function.array-multisort" >array_multisort</A > -- T°φdit vφce polφ, nebo vφcerozm∞rnΘ pole</DT ><DT ><A HREF="#function.array-pad" >array_pad</A > -- Doplnit pole hodnotou na urΦenou dΘlku</DT ><DT ><A HREF="#function.array-pop" >array_pop</A > -- Odstranit prvek z konce pole</DT ><DT ><A HREF="#function.array-push" >array_push</A > -- P°idat jeden nebo vφce prvk∙ na konec pole</DT ><DT ><A HREF="#function.array-rand" >array_rand</A > -- Vybrat nßhodn∞ jeden nebo vφce prvk∙ pole</DT ><DT ><A HREF="#function.array-reduce" >array_reduce</A > -- Iteratively reduce the array to a single value using a callback function </DT ><DT ><A HREF="#function.array-reverse" >array_reverse</A > -- Vrßtit pole s prvky v opaΦnΘm po°adφ</DT ><DT ><A HREF="#function.array-search" >array_search</A > -- Searches the array for a given value and returns the corresponding key if successful </DT ><DT ><A HREF="#function.array-shift" >array_shift</A > -- Odstranit prvek ze zaΦßtku pole</DT ><DT ><A HREF="#function.array-slice" >array_slice</A > -- Vytßhnout Φßst pole</DT ><DT ><A HREF="#function.array-splice" >array_splice</A > -- Odstranit Φßst pole a nahradit ji n∞Φφm jin²m</DT ><DT ><A HREF="#function.array-sum" >array_sum</A > -- Calculate the sum of values in an array. </DT ><DT ><A HREF="#function.array-udiff-assoc" >array_udiff_assoc</A > -- Computes the difference of arrays with additional index check. The data is compared by using a callback function.</DT ><DT ><A HREF="#function.array-udiff-uassoc" >array_udiff_uassoc</A > -- Computes the difference of arrays with additional index check. The data is compared by using a callback function. The index check is done by a callback function also</DT ><DT ><A HREF="#function.array-udiff" >array_udiff</A > -- Computes the difference of arrays by using a callback function for data comparison.</DT ><DT ><A HREF="#function.array-unique" >array_unique</A > -- Odstranit z pole duplicitnφ hodnoty</DT ><DT ><A HREF="#function.array-unshift" >array_unshift</A > -- P°ipojit jeden nebo vφce prvk∙ na zaΦßtek pole</DT ><DT ><A HREF="#function.array-values" >array_values</A > -- Vrßtit v╣echny hodnoty v poli</DT ><DT ><A HREF="#function.array-walk" >array_walk</A > -- Pou╛φt u╛ivatelskou funkci na v╣echny prvky pole</DT ><DT ><A HREF="#function.array" >array</A > -- Vytvo°it pole </DT ><DT ><A HREF="#function.arsort" >arsort</A > -- T°φdit pole sestupn∞ se zachovßnφm klφΦ∙ </DT ><DT ><A HREF="#function.asort" >asort</A > -- T°φdit pole se zachovßnφm index∙</DT ><DT ><A HREF="#function.compact" >compact</A > -- Vytvo°it pole obsahujφcφ prom∞nnΘ a jejich hodnoty</DT ><DT ><A HREF="#function.count" >count</A > -- SpoΦφtat prvky v prom∞nnΘ</DT ><DT ><A HREF="#function.current" >current</A > -- Vrßtit souΦasn² prvek pole</DT ><DT ><A HREF="#function.each" >each</A > -- Vracφ dal╣φ klφΦ/hodnota pßr z pole </DT ><DT ><A HREF="#function.end" >end</A > -- Nastavit vnit°nφ ukazatel pole na jeho poslednφ prvek </DT ><DT ><A HREF="#function.extract" >extract</A > -- Importovat prom∞nnΘ z pole do symbolovΘ tabulky</DT ><DT ><A HREF="#function.in-array" >in_array</A > -- Vrßtit <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud v poli existuje danß hodnota</DT ><DT ><A HREF="#function.key" >key</A > -- Fetch a key from an associative array</DT ><DT ><A HREF="#function.krsort" >krsort</A > -- T°φdit pole sestupn∞ podle klφΦ∙</DT ><DT ><A HREF="#function.ksort" >ksort</A > -- T°φdit pole podle klφΦ∙</DT ><DT ><A HREF="#function.list" >list</A > -- P°i°adit hodnoty p°om∞nn²m jako kdyby byly polem</DT ><DT ><A HREF="#function.natcasesort" >natcasesort</A > -- T°φdit pole s vyu╛itφm algoritmu "p°irozenΘho t°φd∞nφ" (case-insensitive) </DT ><DT ><A HREF="#function.natsort" >natsort</A > -- T°φdit pole s vyu╛itφm algoritmu "p°irozenΘho t°φd∞nφ" </DT ><DT ><A HREF="#function.next" >next</A > -- Posunout internφ ukazatel pole</DT ><DT ><A HREF="#function.pos" >pos</A > -- Zφskat souΦasn² prvek pole</DT ><DT ><A HREF="#function.prev" >prev</A > -- Rewind internφ ukazatel pole</DT ><DT ><A HREF="#function.range" >range</A > -- Vytvo°it pole obsahujφcφ rozsah integer∙</DT ><DT ><A HREF="#function.reset" >reset</A > -- Nastavit internφ ukazatel pole na jeho prvnφ prvek</DT ><DT ><A HREF="#function.rsort" >rsort</A > -- T°φdit pole sestupn∞</DT ><DT ><A HREF="#function.shuffle" >shuffle</A > -- Zamφchat pole</DT ><DT ><A HREF="#function.sizeof" >sizeof</A > -- Zjistit poΦet prvk∙ v poli</DT ><DT ><A HREF="#function.sort" >sort</A > -- T°φdit pole</DT ><DT ><A HREF="#function.uasort" >uasort</A > -- T°φdit pole pomocφ u╛ivatelsky definovanΘ porovnßvacφ funkce se zachovßnφm klφΦ∙ </DT ><DT ><A HREF="#function.uksort" >uksort</A > -- T°φdit pole podle klφΦ∙ pomocφ u╛ivatelsky definovane porovnßvacφ funkce </DT ><DT ><A HREF="#function.usort" >usort</A > -- T°φdit pole podle hodnot pomocφ u╛ivatelsky definovanΘ porovnßvacφ funkce </DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.array-change-key-case" ></A >array_change_key_case</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7081" ></A ><P > (PHP 4 >= 4.2.0)</P >array_change_key_case -- Returns an array with all string keys lowercased or uppercased</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7084" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_change_key_case</B > ( array input [, int case])<BR ></BR ><P >
<B CLASS="function" >array_change_key_case()</B > changes the keys in the <TT CLASS="parameter" ><I >input</I ></TT > array to be all lowercase or uppercase. The change depends on the last optional <TT CLASS="parameter" ><I >case</I ></TT > parameter. You can pass two constants there, <TT CLASS="constant" ><B >CASE_UPPER</B ></TT > and <TT CLASS="constant" ><B >CASE_LOWER</B ></TT >. The default is <TT CLASS="constant" ><B >CASE_LOWER</B ></TT >. The function will leave number indices as is. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7102" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_change_key_case()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $input_array = array("FirSt" => 1, "SecOnd" => 4); print_r(array_change_key_case($input_array, CASE_UPPER)); ?></PRE ></TD ></TR ></TABLE ><P >
The printout of the above program will be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [FIRST] => 1 [SECOND] => 4 )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
If an array has indices that will be the same once run through this function (e.g. "keY" and "kEY"), the value that is later in the array will override other indices. </P ></DIV ><H1 ><A NAME="function.array-chunk" ></A >array_chunk</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7110" ></A ><P > (PHP 4 >= 4.2.0)</P >array_chunk -- Split an array into chunks</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7113" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_chunk</B > ( array input, int size [, bool preserve_keys])<BR ></BR ><P >
<B CLASS="function" >array_chunk()</B > splits the array into several arrays with <TT CLASS="parameter" ><I >size</I ></TT > values in them. You may also have an array with less values at the end. You get the arrays as members of a multidimensional array indexed with numbers starting from zero. </P ><P >
By setting the optional <TT CLASS="parameter" ><I >preserve_keys</I ></TT > parameter to <TT CLASS="constant" ><B >TRUE</B ></TT >, you can force PHP to preserve the original keys from the input array. If you specify <TT CLASS="constant" ><B >FALSE</B ></TT > new number indices will be used in each resulting array with indices starting from zero. The default is <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7135" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_chunk()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $input_array = array('a', 'b', 'c', 'd', 'e'); print_r(array_chunk($input_array, 2)); print_r(array_chunk($input_array, 2, true)); ?></PRE ></TD ></TR ></TABLE ><P >
The printout of the above program will be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0] => Array ( [0] => a [1] => b ) [1] => Array ( [0] => c [1] => d ) [2] => Array ( [0] => e ) ) Array ( [0] => Array ( [0] => a [1] => b ) [1] => Array ( [2] => c [3] => d ) [2] => Array ( [4] => e ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><H1 ><A NAME="function.array-combine" ></A >array_combine</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7142" ></A ><P > (PHP 5 CVS only)</P >array_combine -- Creates an array by using one array for keys and another for its values </DIV ><DIV CLASS="refsect1" ><A NAME="AEN7145" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_combine</B > ( array keys, array values)<BR ></BR ><P >
Returns an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > by using the values from the <TT CLASS="parameter" ><I >keys</I ></TT > array as keys and the values from the <TT CLASS="parameter" ><I >values</I ></TT > array as the corresponding values. </P ><P >
Returns <TT CLASS="constant" ><B >FALSE</B ></TT > if the number of elements for each array isn't equal or if the arrays are empty. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7163" ></A ><P ><B >P°φklad 1. A simple <B CLASS="function" >array_combine()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = array('green', 'red', 'yellow'); $b = array('avocado', 'apple', 'banana'); $c = array_combine($a, $b); print_r($c); ?></PRE ></TD ></TR ></TABLE ><P >
Outputs: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [green] => avocado [red] => apple [yellow] => banana )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.array-merge" ><B CLASS="function" >array_merge()</B ></A >, <A HREF="#function.array-walk" ><B CLASS="function" >array_walk()</B ></A >, and <A HREF="#function.array-values" ><B CLASS="function" >array_values()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-count-values" ></A >array_count_values</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7174" ></A ><P > (PHP 4 )</P >array_count_values -- SpoΦφtat v╣echny hodnoty v poli</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7177" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_count_values</B > ( array input)<BR ></BR ><P >
<B CLASS="function" >array_count_values()</B > vracφ pole pou╛φvajφcφ hodnoty z <TT CLASS="parameter" ><I >input</I ></TT > jako klφΦe a jejich Φetnosti v <TT CLASS="parameter" ><I >input</I ></TT > jako hodnoty. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7190" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_count_values()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array = array (1, "hello", 1, "world", "hello"); array_count_values ($array); // vracφ array(1=>2, "hello"=>2, "world"=>1)</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.array-diff-assoc" ></A >array_diff_assoc</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7195" ></A ><P > (PHP 4 >= 4.3.0)</P >array_diff_assoc -- Computes the difference of arrays with additional index check</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7198" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_diff_assoc</B > ( array array1, array array2 [, array ...])<BR ></BR ><P >
<B CLASS="function" >array_diff_assoc()</B > returns an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > containing all the values from <TT CLASS="parameter" ><I >array1</I ></TT > that are not present in any of the other arguments. Note that the keys are used in the comparison unlike <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7218" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_diff_assoc()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "yellow", "red"); $result = array_diff_assoc($array1, $array2); print_r($result); ?></PRE ></TD ></TR ></TABLE ><P >
The result is: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [b] => brown [c] => blue [0] => red )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
In our example above you see the <TT CLASS="literal" >"a" => "green"</TT > pair is present in both arrays and thus it is not in the ouput from the function. Unlike this, the pair <TT CLASS="literal" >0 => "red"</TT > is in the ouput because in the second argument <TT CLASS="literal" >"red"</TT > has key which is <TT CLASS="literal" >1</TT >. </P ><P >
Two values from <SPAN CLASS="emphasis" ><I CLASS="emphasis" >key => value</I ></SPAN > pairs are considered equal only if <TT CLASS="literal" >(string) $elem1 === (string) $elem2 </TT >. In other words a strict check takes place so the string representations must be the same. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, <TT CLASS="literal" >array_diff_assoc($array1[0], $array2[0]);</TT >. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >, <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >, and <A HREF="#function.array-intersect-assoc" ><B CLASS="function" >array_intersect_assoc()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-diff-uassoc" ></A >array_diff_uassoc</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7240" ></A ><P > (no version information, might be only in CVS)</P >array_diff_uassoc -- Computes the difference of arrays with additional index check which is performed by a user supplied callback function.</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7243" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_diff_assoc</B > ( array array1, array array2 [, array ..., callback key_compare_func])<BR ></BR ><P >
<B CLASS="function" >array_diff_uassoc()</B > returns an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > containing all the values from <TT CLASS="parameter" ><I >array1</I ></TT > that are not present in any of the other arguments. Note that the keys are used in the comparison unlike <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >. This comparison is done by a user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. This is unlike <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A > where an internal function for comparing the indices is used. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7267" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_diff_uassoc()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function key_compare_func($a, $b) { if ($a === $b) return 0; return ($a > $b)? 1:-1; } $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "yellow", "red"); $result = array_diff_uassoc($array1, $array2, "key_compare_func"); ?></PRE ></TD ></TR ></TABLE ><P >
The result is: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [b] => brown [c] => blue [0] => red )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
In our example above you see the <TT CLASS="literal" >"a" => "green"</TT > pair is present in both arrays and thus it is not in the ouput from the function. Unlike this, the pair <TT CLASS="literal" >0 => "red"</TT > is in the ouput because in the second argument <TT CLASS="literal" >"red"</TT > has key which is <TT CLASS="literal" >1</TT >. </P ><P >
The equality of 2 indices is checked by the user supplied callback function. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, <TT CLASS="literal" >array_diff_uassoc($array1[0], $array2[0], "key_compare_func");</TT >. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >, <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A >, <A HREF="#function.array-udiff" ><B CLASS="function" >array_udiff()</B ></A >, <A HREF="#function.array-udiff-assoc" ><B CLASS="function" >array_udiff_assoc()</B ></A >, <A HREF="#function.array-udiff-uassoc" ><B CLASS="function" >array_udiff_uassoc()</B ></A >, <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >, <A HREF="#function.array-intersect-assoc" ><B CLASS="function" >array_intersect_assoc()</B ></A >, <B CLASS="function" >array_uintersect()</B >, <B CLASS="function" >array_uintersect_assoc()</B > and <B CLASS="function" >array_uintersect_uassoc()</B >. </P ></DIV ><H1 ><A NAME="function.array-diff" ></A >array_diff</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7294" ></A ><P > (PHP 4 >= 4.0.1)</P >array_diff -- SpoΦφtat rozdφl polφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7297" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_diff</B > ( array array1, array array2 [, array ...])<BR ></BR ><P >
<B CLASS="function" >array_diff()</B > vracφ pole obsahujφcφ v╣echny hodnoty z <TT CLASS="parameter" ><I >array1</I ></TT >, kterΘ se nevyskytujφ v ╛ßdnΘm z dal╣φch argument∙. KlφΦe jsou zachovßny. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7315" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_diff()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array1 = array ("a" => "green", "red", "blue"); $array2 = array ("b" => "green", "yellow", "red"); $result = array_diff ($array1, $array2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$result</TT > obsahuje <TT CLASS="literal" >array ("blue");</TT > </P ><P >
Viz takΘ: <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-fill" ></A >array_fill</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7325" ></A ><P > (PHP 4 >= 4.2.0)</P >array_fill -- Fill an array with values</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7328" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_fill</B > ( int start_index, int num, mixed value)<BR ></BR ><P >
<B CLASS="function" >array_fill()</B > fills an array with <TT CLASS="parameter" ><I >num</I ></TT > entries of the value of the <TT CLASS="parameter" ><I >value</I ></TT > parameter, keys starting at the <TT CLASS="parameter" ><I >start_index</I ></TT > parameter. Note that <TT CLASS="parameter" ><I >
num</I ></TT > must be a number greater than zero, or PHP will throw a warning. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7349" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_fill()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = array_fill(5, 6, 'banana'); print_r($a); ?></PRE ></TD ></TR ></TABLE ><P >
<TT CLASS="varname" >$a</TT > now is: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [5] => banana [6] => banana [7] => banana [8] => banana [9] => banana [10] => banana )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.str-repeat" ><B CLASS="function" >str_repeat()</B ></A > and <A HREF="#function.range" ><B CLASS="function" >range()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-filter" ></A >array_filter</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7360" ></A ><P > (PHP 4 >= 4.0.6)</P >array_filter -- Filters elements of an array using a callback function </DIV ><DIV CLASS="refsect1" ><A NAME="AEN7363" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_filter</B > ( array input [, callback callback])<BR ></BR ><P >
<B CLASS="function" >array_filter()</B > iterates over each value in the <TT CLASS="parameter" ><I >input</I ></TT > array passing them to the <TT CLASS="parameter" ><I >callback</I ></TT > function. If the <TT CLASS="parameter" ><I >
callback</I ></TT > function returns true, the current value from <TT CLASS="parameter" ><I >input</I ></TT > is returned into the result array. Array keys are preserved. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7381" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_filter()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function odd($var) { return($var % 2 == 1); } function even($var) { return($var % 2 == 0); } $array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5); $array2 = array(6, 7, 8, 9, 10, 11, 12); echo "Odd :\n"; print_r(array_filter($array1, "odd")); echo "Even:\n"; print_r(array_filter($array2, "even")); ?></PRE ></TD ></TR ></TABLE ><P >
The printout of the program above will be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >Odd : Array ( [a] => 1 [c] => 3 [e] => 5 ) Even: Array ( [0] => 6 [2] => 8 [4] => 10 [6] => 12 )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Users may not change the array itself from the callback function. e.g. Add/delete an element, unset the array that <B CLASS="function" >array_filter()</B > is applied to. If the array is changed, the behavior of this function is undefined. </P ><P >
If the <TT CLASS="parameter" ><I >callback</I ></TT > function is not supplied, <B CLASS="function" >array_filter()</B > will remove all the entries of <TT CLASS="parameter" ><I >input</I ></TT > that are equal to <TT CLASS="constant" ><B >FALSE</B ></TT >. See <A HREF="#language.types.boolean.casting" >converting to boolean</A > for more information. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7396" ></A ><P ><B >P°φklad 2. <B CLASS="function" >array_filter()</B > without <TT CLASS="parameter" ><I >callback</I ></TT ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $entry = array( 0 => 'foo', 1 => false, 2 => -1, 3 => null, 4 => '' ); print_r(array_filter($entry)); ?></PRE ></TD ></TR ></TABLE ><P >
This will output : </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0] => foo [2] => -1 )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.array-map" ><B CLASS="function" >array_map()</B ></A >, <A HREF="#function.array-reduce" ><B CLASS="function" >array_reduce()</B ></A >, and <A HREF="#function.array-walk" ><B CLASS="function" >array_walk()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-flip" ></A >array_flip</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7408" ></A ><P > (PHP 4 )</P >array_flip -- Prohodit klφΦe a hodnoty pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7411" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_flip</B > ( array trans)<BR ></BR ><P >
<B CLASS="function" >array_flip()</B > pole s prohozen²mi klφΦi a hodnotami. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7422" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_flip()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$trans = array_flip ($trans); $original = strtr ($str, $trans);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.array-intersect-assoc" ></A >array_intersect_assoc</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7427" ></A ><P > (PHP 4 >= 4.3.0)</P >array_intersect_assoc -- Computes the intersection of arrays with additional index check</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7430" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_intersect_assoc</B > ( array array1, array array2 [, array ...])<BR ></BR ><P >
<B CLASS="function" >array_intersect_assoc()</B > returns an array containing all the values of <TT CLASS="parameter" ><I >array1</I ></TT > that are present in all the arguments. Note that the keys are used in the comparison unlike in <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7449" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_intersect_assoc()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "yellow", "red"); $result_array = array_intersect_assoc($array1, $array2); ?></PRE ></TD ></TR ></TABLE ><P >
$result_array will look like: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [a] => green )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
In our example you see that only the pair <TT CLASS="literal" >"a" => "green"</TT > is present in both arrays and thus is returned. The value <TT CLASS="literal" >"red"</TT > is not returned because in <TT CLASS="varname" >$array1</TT > it's key is <TT CLASS="literal" >0</TT > while the key of "red" in <TT CLASS="varname" >$array2</TT > is <TT CLASS="literal" >1</TT >. </P ><P >
The two values from the <TT CLASS="literal" >key => value</TT > pairs are considered equal only if <TT CLASS="literal" >(string) $elem1 === (string) $elem2 </TT >. In otherwords a strict type check is executed so the string representation must be the same. </P ><P >
See also <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >, <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A > and <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-intersect" ></A >array_intersect</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7470" ></A ><P > (PHP 4 >= 4.0.1)</P >array_intersect -- SpoΦφtat pr∙nik polφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7473" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_intersect</B > ( array array1, array array2 [, array ...])<BR ></BR ><P >
<B CLASS="function" >array_intersect()</B > vracφ pole obsahujφcφ v╣echny hodnoty z <TT CLASS="parameter" ><I >array1</I ></TT >, kterΘ se vyskytujφ ve v╣ech argumentech. KlφΦe jsou zachovßny. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7491" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_intersect()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array1 = array ("a" => "green", "red", "blue"); $array2 = array ("b" => "green", "yellow", "red"); $result = array_intersect ($array1, $array2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$result</TT > obsahuje <TT CLASS="literal" >array ("a" => "green", "red");</TT > </P ><P >
Viz takΘ: <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-key-exists" ></A >array_key_exists</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7501" ></A ><P > (PHP 4 >= 4.1.0)</P >array_key_exists -- Checks if the given key or index exists in the array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7504" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >array_key_exists</B > ( mixed key, array search)<BR ></BR ><P >
<B CLASS="function" >array_key_exists()</B > returns <TT CLASS="constant" ><B >TRUE</B ></TT > if the given <TT CLASS="parameter" ><I >key</I ></TT > is set in the array. <TT CLASS="parameter" ><I >key</I ></TT > can be any value possible for an array index. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7521" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_key_exists()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $search_array = array("first" => 1, "second" => 4); if (array_key_exists("first", $search_array)) { echo "The 'first' element is in the array"; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The name of this function is <B CLASS="function" >key_exists()</B > in PHP version 4.0.6. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.isset" ><B CLASS="function" >isset()</B ></A >, <A HREF="#function.array-keys" ><B CLASS="function" >array_keys()</B ></A >, and <A HREF="#function.in-array" ><B CLASS="function" >in_array()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-keys" ></A >array_keys</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7533" ></A ><P > (PHP 4 )</P >array_keys -- Vrßtit v╣echny klφΦe pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7536" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_keys</B > ( array input [, mixed search_value])<BR ></BR ><P >
<B CLASS="function" >array_keys()</B > vracφ klφΦe, numerickΘ i textovΘ, z pole <TT CLASS="parameter" ><I >input</I ></TT >. </P ><P >
Pokud je p°φtomen voliteln² argument <TT CLASS="parameter" ><I >search_value</I ></TT >, vracφ pouze klφΦe tΘto hodnoty. Jinak vracφ v╣echny klφΦe z pole <TT CLASS="parameter" ><I >input</I ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7554" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_keys()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array = array (0 => 100, "color" => "red"); array_keys ($array); // vracφ array (0, "color") $array = array ("blue", "red", "green", "blue", "blue"); array_keys ($array, "blue"); // vracφ array (0, 3, 4) $array = array ("color" => array("blue", "red", "green"), "size" => array("small", "medium", "large")); array_keys ($array); // vracφ array ("color", "size")</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Tato funkce byla p°idßna v PHP 4, dßle je uvedena implementace pro ty, kte°φ stßle pou╛φvajφ PHP 3. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7560" ></A ><P ><B >P°φklad 2. Implementace <B CLASS="function" >array_keys()</B > pro u╛ivatele PHP 3 </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function array_keys ($arr, $term="") { $t = array(); while (list($k,$v) = each($arr)) { if ($term && $v != $term) continue; $t[] = $k; } return $t; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></BLOCKQUOTE ></DIV ><P >
Viz takΘ: <A HREF="#function.array-values" ><B CLASS="function" >array_values()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-map" ></A >array_map</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7567" ></A ><P > (PHP 4 >= 4.0.6)</P >array_map -- Applies the callback to the elements of the given arrays </DIV ><DIV CLASS="refsect1" ><A NAME="AEN7570" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_map</B > ( mixed callback, array arr1 [, array ...])<BR ></BR ><P >
<B CLASS="function" >array_map()</B > returns an array containing all the elements of <TT CLASS="parameter" ><I >arr1</I ></TT > after applying the <TT CLASS="parameter" ><I >callback</I ></TT > function to each one. The number of parameters that the <TT CLASS="parameter" ><I >callback</I ></TT > function accepts should match the number of arrays passed to the <B CLASS="function" >array_map()</B > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7591" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_map()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function cube($n) { return($n * $n * $n); } $a = array(1, 2, 3, 4, 5); $b = array_map("cube", $a); print_r($b); ?></PRE ></TD ></TR ></TABLE ><P >
This makes <TT CLASS="varname" >$b</TT > have: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0] => 1 [1] => 8 [2] => 27 [3] => 64 [4] => 125 )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7599" ></A ><P ><B >P°φklad 2. <B CLASS="function" >array_map()</B > - using more arrays</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function show_Spanish($n, $m) { return("The number $n is called $m in Spanish"); } function map_Spanish($n, $m) { return(array($n => $m)); } $a = array(1, 2, 3, 4, 5); $b = array("uno", "dos", "tres", "cuatro", "cinco"); $c = array_map("show_Spanish", $a, $b); print_r($c); $d = array_map("map_Spanish", $a , $b); print_r($d); ?></PRE ></TD ></TR ></TABLE ><P >
This results: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >// printout of $c Array ( [0] => The number 1 is called uno in Spanish [1] => The number 2 is called dos in Spanish [2] => The number 3 is called tres in Spanish [3] => The number 4 is called cuatro in Spanish [4] => The number 5 is called cinco in Spanish ) // printout of $d Array ( [0] => Array ( [1] => uno ) [1] => Array ( [2] => dos ) [2] => Array ( [3] => tres ) [3] => Array ( [4] => cuatro ) [4] => Array ( [5] => cinco ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Usually when using two or more arrays, they should be of equal length because the callback function is applied in parallel to the corresponding elements. If the arrays are of unequal length, the shortest one will be extended with empty elements. </P ><P >
An interesting use of this function is to construct an array of arrays, which can be easily performed by using <TT CLASS="constant" ><B >NULL</B ></TT > as the name of the callback function </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7609" ></A ><P ><B >P°φklad 3. Creating an array of arrays</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = array(1, 2, 3, 4, 5); $b = array("one", "two", "three", "four", "five"); $c = array("uno", "dos", "tres", "cuatro", "cinco"); $d = array_map(null, $a, $b, $c); print_r($d); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
The printout of the program above will be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0] => Array ( [0] => 1 [1] => one [2] => uno ) [1] => Array ( [0] => 2 [1] => two [2] => dos ) [2] => Array ( [0] => 3 [1] => three [2] => tres ) [3] => Array ( [0] => 4 [1] => four [2] => cuatro ) [4] => Array ( [0] => 5 [1] => five [2] => cinco ) )</PRE ></TD ></TR ></TABLE ><P >
See also <A HREF="#function.array-filter" ><B CLASS="function" >array_filter()</B ></A >, <A HREF="#function.array-reduce" ><B CLASS="function" >array_reduce()</B ></A >, and <A HREF="#function.array-walk" ><B CLASS="function" >array_walk()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-merge-recursive" ></A >array_merge_recursive</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7619" ></A ><P > (PHP 4 >= 4.0.1)</P >array_merge_recursive -- Rekurzivn∞ slouΦit dv∞ nebo vφce polφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7622" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_merge_recursive</B > ( array array1, array array2 [, array ...])<BR ></BR ><P >
<B CLASS="function" >array_merge_recursive()</B > slouΦφ prvky dvou nebo vφce polφ tak, ╛e hodnoty pole se p°ipojφ na konec p°edchozφho pole. Vracφ v²slednΘ pole. </P ><P >
Pokud obsahujφ vstupnφ pole stejn² textov² klφΦ, hodnoty t∞chto klφΦ∙ se rekurzivn∞ slouΦφ do pole tak, ╛e pokud je jedna z hodnot sama pole, tato funkce ji takΘ slouΦφ s odpovφdajφcφ polo╛kou z dal╣φho pole. Pokud ale tato pole majφ stejn² Φφseln² klφΦ, pozd∞j╣φ hodnota nep°epφ╣e tu d°φv∞j╣φ, ale p°ipojφ se. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7640" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_merge_recursive()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$ar1 = array ("color" => array ("favorite" => "red"), 5); $ar2 = array (10, "color" => array ("favorite" => "green", "blue")); $result = array_merge_recursive ($ar1, $ar2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
V²slednΘ pole bude <TT CLASS="literal" >array ("color" => array ("favorite" => array ("red", "green"), "blue"), 5, 10)</TT >. </P ><P >
Viz takΘ: <A HREF="#function.array-merge" ><B CLASS="function" >array_merge()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-merge" ></A >array_merge</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7649" ></A ><P > (PHP 4 )</P >array_merge -- SlouΦit dv∞ nebo vφce polφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7652" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_merge</B > ( array array1, array array2 [, array ...])<BR ></BR ><P >
<B CLASS="function" >array_merge()</B > slouΦφ prvky dvou nebo vφce polφ dohromady tak, ╛e hodnoty ka╛dΘho pole se p°ipojφ na konec p°edchozφho. Vracφ v²slednΘ pole. </P ><P >
Pokud majφ vstupnφ pole stejn² textov² klφΦ, pozd∞j╣φ hodnota p°epφ╣e d°φv∞j╣φ hodnotu. Pokud ale majφ stejn² Φφseln² klφΦ, pozd∞j╣φ hodnota tu p·vodnφ nep°epφ╣e, ale p°ipojφ se k nφ. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7670" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_merge()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array1 = array ("color" => "red", 2, 4); $array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4); array_merge ($array1, $array2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
V²slednΘ pole bude <TT CLASS="literal" >array("color" => "green", 2, 4, "a", "b", "shape" => "trapezoid", 4)</TT >. </P ><P >
Viz takΘ: <A HREF="#function.array-merge-recursive" ><B CLASS="function" >array_merge_recursive()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-multisort" ></A >array_multisort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7679" ></A ><P > (PHP 4 )</P >array_multisort -- T°φdit vφce polφ, nebo vφcerozm∞rnΘ pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7682" ></A ><H2 >Popis</H2 >bool <B CLASS="methodname" >array_multisort</B > ( array ar1 [, mixed arg [, mixed ... [, array ...]]])<BR ></BR ><P >
<B CLASS="function" >array_multisort()</B > se dß vyu╛φt k t°φd∞nφ n∞kolika polφ najednou nebo k t°φd∞nφ vφcerozm∞rnΘho pole XXX according by one of more dimensions. P°i t°φd∞nφ udr╛uje asociace klφΦ∙. </P ><P >
Vstupnφ pole jsou manipulovßna jako sloupce tabulky, kterß se mß t°φdit podle °ßdk∙ - p°ipomφnß to funkcionalitu SQL klauzule ORDER BY. Prvnφ pole je to, podle kterΘho se bude t°φdit. ╪ßdky (hodnoty) v tomto poli that compare the same are sorted by the next input array, and so on. </P ><P >
Struktura argument∙ tΘto funkce je trochu neobvyklß, ale pru╛nß. Prvnφ argument musφ b²t pole. Ka╛d² dal╣φ argument m∙╛e b²t bu∩ pole nebo jeden z p°φznak z nßsledujφcφch seznam∙: </P ><P >
P°φznaky sm∞ru t°φd∞nφ: <P ></P ><UL ><LI ><P >SORT_ASC - t°φdit vzestupn∞</P ></LI ><LI ><P >SORT_DESC - t°φdit sestupn∞</P ></LI ></UL > </P ><P >
P°φznaky typu t°φd∞nφ: <P ></P ><UL ><LI ><P >SORT_REGULAR - porovnßvat polo╛ky normßln∞</P ></LI ><LI ><P >SORT_NUMERIC - porovnßvat polo╛ky Φφseln∞</P ></LI ><LI ><P >SORT_STRING - porovnßvat polo╛ky jako °et∞zce</P ></LI ></UL > </P ><P >
Po ka╛dΘm poli m∙╛ete specifikovat jeden p°φznak ka╛dΘho typu. P°φznaky t°φd∞nφ specifikovanΘ po ka╛dΘm poli platφ pouze pro toto pole - pro dal╣φ pole se resetujφ na defaultnφ SORT_ASC a SORT_REGULAR. </P ><P >
P°i ·sp∞chu vracφ <TT CLASS="constant" ><B >TRUE</B ></TT >, p°i selhßnφ <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7722" ></A ><P ><B >P°φklad 1. T°φd∞nφ vφce polφ</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$ar1 = array ("10", 100, 100, "a"); $ar2 = array (1, 3, "2", 1); array_multisort ($ar1, $ar2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
V tΘto ukßzce bude po set°φd∞nφ prvnφ pole obsahovat 10, "a", 100, 100. DruhΘ pole bude obsahovat 1, 1, 2, "3". Polo╛ky druhΘho pole odpovφdajφcφ identick²m polo╛kßm v prvnφm poli (100 a 100) byly takΘ set°φd∞ny. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7727" ></A ><P ><B >P°φklad 2. T°φd∞nφ vφcerozm∞rnΘho pole</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1)); array_multisort ($ar[0], SORT_ASC, SORT_STRING, $ar[1], SORT_NUMERIC, SORT_DESC);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
V tΘto ukßzce bude po set°φd∞nφ prvnφ pole obsahovat 10, 100, 100, "a" (bylo t°φd∞no vzestupn∞ jako °et∞zce) a druhΘ pole bude obsahovat 1, 3, "2", 1 (t°φd∞no jako Φφsla, sestupn∞). </P ></DIV ><H1 ><A NAME="function.array-pad" ></A >array_pad</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7732" ></A ><P > (PHP 4 )</P >array_pad -- Doplnit pole hodnotou na urΦenou dΘlku</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7735" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_pad</B > ( array input, int pad_size, mixed pad_value)<BR ></BR ><P >
<B CLASS="function" >array_pad()</B > vracφ kopii pole <TT CLASS="parameter" ><I >input</I ></TT > dopln∞nou na velikost <TT CLASS="parameter" ><I >pad_size</I ></TT > hodnotou <TT CLASS="parameter" ><I >pad_value</I ></TT >. Pokud je <TT CLASS="parameter" ><I >pad_size</I ></TT > kladnß, pole je dopln∞no zprava, pokud je negativnφ, zleva. Pokud je absolutnφ hodnota <TT CLASS="parameter" ><I >pad_size</I ></TT > men╣φ nebo rovna velikosti <TT CLASS="parameter" ><I >input</I ></TT >, k dopln∞nφ nedojde. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7758" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_pad()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$input = array (12, 10, 9); $result = array_pad ($input, 5, 0); // v²sledek je array (12, 10, 9, 0, 0) $result = array_pad ($input, -7, -1); // v²sledek je array (-1, -1, -1, -1, 12, 10, 9) $result = array_pad ($input, 2, "noop"); // nedopln∞no</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.array-pop" ></A >array_pop</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7763" ></A ><P > (PHP 4 )</P >array_pop -- Odstranit prvek z konce pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7766" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >array_pop</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >array_pop()</B > odstranφ a vrßtφ poslednφ hodnotu pole <TT CLASS="parameter" ><I >array</I ></TT >, Φφm╛ ho zkrßtφ o jeden prvek. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7778" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_pop()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$stack = array ("orange", "apple", "raspberry"); $fruit = array_pop ($stack);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$stack</TT > mß te∩ pouze dva prvky: "orange" a "apple", a <TT CLASS="varname" >$fruit</TT > obsahuje "raspberry". </P ><P >
Viz takΘ: <A HREF="#function.array-push" ><B CLASS="function" >array_push()</B ></A >, <A HREF="#function.array-shift" ><B CLASS="function" >array_shift()</B ></A > a <A HREF="#function.array-unshift" ><B CLASS="function" >array_unshift()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-push" ></A >array_push</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7790" ></A ><P > (PHP 4 )</P >array_push -- P°idat jeden nebo vφce prvk∙ na konec pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7793" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >array_push</B > ( array array, mixed var [, mixed ...])<BR ></BR ><P >
<B CLASS="function" >array_push()</B > p°ipojuje p°edanΘ prom∞nnΘ na konec <TT CLASS="parameter" ><I >array</I ></TT >. DΘlka <TT CLASS="parameter" ><I >array</I ></TT > se zv∞t╣uje o poΦet p°idan²ch prom∞nn²ch. ┌Φinek je stejn² jako: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array[] = $var;</PRE ></TD ></TR ></TABLE > opakovanΘ pro ka╛dou <TT CLASS="parameter" ><I >var</I ></TT >. </P ><P >
Vracφ nov² poΦet prvk∙ v poli. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7815" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_push()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$stack = array (1, 2); array_push ($stack, "+", 3);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
V²sledkem tΘto ukßzky by byl <TT CLASS="varname" >$stack</TT > obsahujφcφ 4 prvky: 1, 2, "+" a 3. </P ><P >
Viz takΘ: <A HREF="#function.array-pop" ><B CLASS="function" >array_pop()</B ></A >, <A HREF="#function.array-shift" ><B CLASS="function" >array_shift()</B ></A > a <A HREF="#function.array-unshift" ><B CLASS="function" >array_unshift()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-rand" ></A >array_rand</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7826" ></A ><P > (PHP 4 )</P >array_rand -- Vybrat nßhodn∞ jeden nebo vφce prvk∙ pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7829" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >array_rand</B > ( array input [, int num_req])<BR ></BR ><P >
<B CLASS="function" >array_rand()</B > je pom∞rn∞ u╛iteΦnß, kdy╛ chcete z pole vybrat nßhodn∞ jednu nebo vφce hodnot. P°ijφmß pole <TT CLASS="parameter" ><I >input</I ></TT > a voliteln² argument <TT CLASS="parameter" ><I >num_req</I ></TT >, kter² urΦuje, kolik polo╛ek chcete. Jeho defaultnφ hodnota je 1. </P ><P >
Pokud vybφrßte pouze jednu polo╛ku, <B CLASS="function" >array_rand()</B > vracφ klφΦ nßhodnΘ polo╛ky. Jinak vracφ pole klφΦ∙ nßhodn∞ vybran²ch polo╛ek. Takto m∙╛ete vybφrat nßhodn∞ hodnoty i klφΦe. </P ><P >
Nezapome≥te inicializovat generßtor nßhodn²ch Φφsel pomocφ <A HREF="#function.srand" ><B CLASS="function" >srand()</B ></A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7849" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_rand()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >srand ((double) microtime() * 10000000); $input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); $rand_keys = array_rand ($input, 2); print $input[$rand_keys[0]]."\n"; print $input[$rand_keys[1]]."\n";</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.array-reduce" ></A >array_reduce</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7854" ></A ><P > (PHP 4 >= 4.0.5)</P >array_reduce -- Iteratively reduce the array to a single value using a callback function </DIV ><DIV CLASS="refsect1" ><A NAME="AEN7857" ></A ><H2 >Description</H2 >mixed <B CLASS="methodname" >array_reduce</B > ( array input, callback function [, int initial])<BR ></BR ><P >
<B CLASS="function" >array_reduce()</B > applies iteratively the <TT CLASS="parameter" ><I >function</I ></TT > function to the elements of the array <TT CLASS="parameter" ><I >input</I ></TT >, so as to reduce the array to a single value. If the optional <TT CLASS="parameter" ><I >initial</I ></TT > is available, it will be used at the beginning of the process, or as a final result in case the array is empty. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7877" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_reduce()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function rsum($v, $w) { $v += $w; return $v; } function rmul($v, $w) { $v *= $w; return $v; } $a = array(1, 2, 3, 4, 5); $x = array(); $b = array_reduce($a, "rsum"); $c = array_reduce($a, "rmul", 10); $d = array_reduce($x, "rsum", 1); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
This will result in <TT CLASS="varname" >$b</TT > containing <TT CLASS="literal" >15</TT >, <TT CLASS="varname" >$c</TT > containing <TT CLASS="literal" >1200</TT > (= 1*2*3*4*5*10), and <TT CLASS="varname" >$d</TT > containing <TT CLASS="literal" >1</TT >. </P ><P >
See also <A HREF="#function.array-filter" ><B CLASS="function" >array_filter()</B ></A >, <A HREF="#function.array-map" ><B CLASS="function" >array_map()</B ></A >, <A HREF="#function.array-unique" ><B CLASS="function" >array_unique()</B ></A >, and <A HREF="#function.array-count-values" ><B CLASS="function" >array_count_values()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-reverse" ></A >array_reverse</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7894" ></A ><P > (PHP 4 )</P >array_reverse -- Vrßtit pole s prvky v opaΦnΘm po°adφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7897" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_reverse</B > ( array array [, bool preserve_keys])<BR ></BR ><P >
<B CLASS="function" >array_reverse()</B > takes input <TT CLASS="parameter" ><I >array</I ></TT > and returns a new array with the order of the elements reversed, preserving the keys if <TT CLASS="parameter" ><I >preserve_keys</I ></TT > is <TT CLASS="constant" ><B >TRUE</B ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7914" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_reverse()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$input = array ("php", 4.0, array ("green", "red")); $result = array_reverse ($input); $result_keyed = array_reverse ($input, true);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$result</TT > te∩ obsahuje <TT CLASS="literal" >array (array ("green", "red"), 4.0, "php")</TT >. Ale <TT CLASS="varname" >$result2[0]</TT > je stßle <TT CLASS="literal" >"php"</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Druh² argument byl p°idßn v PHP 4.0.3. </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.array-search" ></A >array_search</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7926" ></A ><P > (PHP 4 >= 4.0.5)</P >array_search -- Searches the array for a given value and returns the corresponding key if successful </DIV ><DIV CLASS="refsect1" ><A NAME="AEN7929" ></A ><H2 >Description</H2 >mixed <B CLASS="methodname" >array_search</B > ( mixed needle, array haystack [, bool strict])<BR ></BR ><P >
Searches <TT CLASS="parameter" ><I >haystack</I ></TT > for <TT CLASS="parameter" ><I >needle</I ></TT > and returns the key if it is found in the array, <TT CLASS="constant" ><B >FALSE</B ></TT > otherwise. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > If <TT CLASS="parameter" ><I >needle</I ></TT > is a string, the comparison is done in a case-sensitive manner. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Prior to PHP 4.2.0, <B CLASS="function" >array_search()</B > returns <TT CLASS="constant" ><B >NULL</B ></TT > on failure instead of <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ></BLOCKQUOTE ></DIV ><P >
If the optional third parameter <TT CLASS="parameter" ><I >strict</I ></TT > is set to <TT CLASS="constant" ><B >TRUE</B ></TT > then the <B CLASS="function" >array_search()</B > will also check the types of the <TT CLASS="parameter" ><I >needle</I ></TT > in the <TT CLASS="parameter" ><I >haystack</I ></TT >. </P ><P >
If <TT CLASS="parameter" ><I >needle</I ></TT > is found in <TT CLASS="parameter" ><I >haystack</I ></TT > more than once, the first matching key is returned. To return the keys for all matching values, use <A HREF="#function.array-keys" ><B CLASS="function" >array_keys()</B ></A > with the optional <TT CLASS="parameter" ><I >search_value</I ></TT > parameter instead. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7967" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_search()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('green', $array); // $key = 2; $key = array_search('red', $array); // $key = 1; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce m∙╛e vracet booleovskou hodnotu <TT CLASS="constant" ><B >FALSE</B ></TT >, ale takΘ nebooleovskou hodnotu odpovφdajφcφ ohodnocenφ <TT CLASS="constant" ><B >FALSE</B ></TT >, nap°φklad <TT CLASS="literal" >0</TT > nebo "". ╚t∞te prosφm sekci o typu <A HREF="#language.types.boolean" >Boolean</A >, kde najdete vφce informacφ. Pro testovßnφ nßvratovΘ hodnoty tΘto funkce pou╛ijte <A HREF="#language.operators.comparison" >operßtor ===</A >.</P ></TD ></TR ></TABLE ></DIV ><P >
See also <A HREF="#function.array-keys" ><B CLASS="function" >array_keys()</B ></A >, <A HREF="#function.array-values" ><B CLASS="function" >array_values()</B ></A >, <A HREF="#function.array-key-exists" ><B CLASS="function" >array_key_exists()</B ></A >, and <A HREF="#function.in-array" ><B CLASS="function" >in_array()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-shift" ></A >array_shift</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7984" ></A ><P > (PHP 4 )</P >array_shift -- Odstranit prvek ze zaΦßtku pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7987" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >array_shift</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >array_shift()</B > vracφ prvnφ polo╛ku <TT CLASS="parameter" ><I >array</I ></TT > a odstranφ ji, Φφm╛ zkrßtφ <TT CLASS="parameter" ><I >array</I ></TT > o jeden prvek a ostatnφ posune dol∙. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8000" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_shift()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$args = array ("-v", "-f"); $opt = array_shift ($args);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$args</TT > te∩ mß jeden prvek: "-f" a <TT CLASS="varname" >$opt</TT > je "-v". </P ><P >
Viz takΘ: <A HREF="#function.array-unshift" ><B CLASS="function" >array_unshift()</B ></A >, <A HREF="#function.array-push" ><B CLASS="function" >array_push()</B ></A > a <A HREF="#function.array-pop" ><B CLASS="function" >array_pop()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-slice" ></A >array_slice</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8012" ></A ><P > (PHP 4 )</P >array_slice -- Vytßhnout Φßst pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8015" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_slice</B > ( array array, int offset [, int length])<BR ></BR ><P >
<B CLASS="function" >array_slice()</B > vracφ sekvenci prvk∙ <TT CLASS="parameter" ><I >array</I ></TT > urΦen²ch argumenty <TT CLASS="parameter" ><I >offset</I ></TT > a <TT CLASS="parameter" ><I >length</I ></TT >. </P ><P >
Pokud je <TT CLASS="parameter" ><I >offset</I ></TT > kladn², tato sekvence zaΦne <TT CLASS="parameter" ><I >offset</I ></TT > polo╛ek od zaΦßtku <TT CLASS="parameter" ><I >array</I ></TT >. Pokud je <TT CLASS="parameter" ><I >offset</I ></TT > zßporn², tato sekvence zaΦne tolik polo╛ek od konce <TT CLASS="parameter" ><I >array</I ></TT >. </P ><P >
Pokud je <TT CLASS="parameter" ><I >length</I ></TT > kladnß, tato sekvence bude obsahovat tolik prvk∙. Pokud je <TT CLASS="parameter" ><I >length</I ></TT > zßpornß, tato sekvence skonΦφ tolik prvk∙ od konce <TT CLASS="parameter" ><I >array</I ></TT >. Pokud <TT CLASS="parameter" ><I >length</I ></TT > vynechßte, tato sekvence bude obsahovat v╣echny prvky <TT CLASS="parameter" ><I >array</I ></TT > od <TT CLASS="parameter" ><I >offset</I ></TT > do konce. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8048" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_slice()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$input = array ("a", "b", "c", "d", "e"); $output = array_slice ($input, 2); // returns "c", "d", and "e" $output = array_slice ($input, 2, -1); // returns "c", "d" $output = array_slice ($input, -2, 1); // returns "d" $output = array_slice ($input, 0, 3); // returns "a", "b", and "c"</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ: <A HREF="#function.array-splice" ><B CLASS="function" >array_splice()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-splice" ></A >array_splice</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8055" ></A ><P > (PHP 4 )</P >array_splice -- Odstranit Φßst pole a nahradit ji n∞Φφm jin²m</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8058" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_splice</B > ( array input, int offset [, int length [, array replacement]])<BR ></BR ><P >
<B CLASS="function" >array_splice()</B > odstra≥uje prvky pole <TT CLASS="parameter" ><I >input</I ></TT > urΦenΘ argumenty <TT CLASS="parameter" ><I >offset</I ></TT > a <TT CLASS="parameter" ><I >length</I ></TT >, a p°φpadn∞ je nahrazuje prvky volitelnΘho argumentu (pole) <TT CLASS="parameter" ><I >replacement</I ></TT >. </P ><P >
Pokud je <TT CLASS="parameter" ><I >offset</I ></TT > kladn², tato odstran∞nß Φßst zaΦne <TT CLASS="parameter" ><I >offset</I ></TT > polo╛ek od zaΦßtku <TT CLASS="parameter" ><I >array</I ></TT >. Pokud je <TT CLASS="parameter" ><I >offset</I ></TT > zßporn², zaΦne tolik polo╛ek od konce <TT CLASS="parameter" ><I >array</I ></TT >. </P ><P >
Pokud vynechßte <TT CLASS="parameter" ><I >length</I ></TT >, <B CLASS="function" >array_splice()</B > odstranφ v╣echno od <TT CLASS="parameter" ><I >offset</I ></TT > do konce pole. Pokud je <TT CLASS="parameter" ><I >length</I ></TT > kladnß, odstranφ se prßv∞ tolik prvk∙. Pokud je <TT CLASS="parameter" ><I >length</I ></TT > zßpornß, konec odstran∞nΘ Φßsti bude prßv∞ tolik prvk∙ od konce pole. Tip: k odstran∞nφ v╣ech prvk∙ od <TT CLASS="parameter" ><I >offset</I ></TT > do konce pole p°i souΦasn∞ urΦenΘm argumentu <TT CLASS="parameter" ><I >replacement</I ></TT > pou╛ijte jako <TT CLASS="parameter" ><I >length</I ></TT > <TT CLASS="literal" >count($input)</TT >. </P ><P >
Pokud zadßte <TT CLASS="parameter" ><I >replacement</I ></TT > pole, odstran∞nΘ prvky se nahradφ prvky tohoto pole. Pokud argumenty <TT CLASS="parameter" ><I >offset</I ></TT > a <TT CLASS="parameter" ><I >length</I ></TT > definovßny tak, ╛e se nic neodstranφ, prvky pole <TT CLASS="parameter" ><I >replacement</I ></TT > se vlo╛φ na mφsto urΦenΘ argumentem <TT CLASS="parameter" ><I >offset</I ></TT >. Tip: pokud je <TT CLASS="parameter" ><I >replacement</I ></TT > jen jedna hodnota, nenφ nutno ji umis╗ovat do <TT CLASS="literal" >array()</TT >, leda╛e chcete, aby tato polo╛ka byla opravdu pole. </P ><P >
Nßsledujφcφ volßnφ jsou ekvivalentnφ: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >array_push ($input, $x, $y) array_splice ($input, count ($input), 0, array ($x, $y)) array_pop ($input) array_splice ($input, -1) array_shift ($input) array_splice ($input, 0, 1) array_unshift ($input, $x, $y) array_splice ($input, 0, 0, array ($x, $y)) $a[$x] = $y array_splice ($input, $x, 1, $y)</PRE ></TD ></TR ></TABLE > </P ><P >
Vracφ pole odstran∞n²ch prvk∙. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8109" ></A ><P ><B >P°φklad 1. Ukßzky <B CLASS="function" >array_splice()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$input = array ("red", "green", "blue", "yellow"); array_splice ($input, 2); // $input is now array ("red", "green") array_splice ($input, 1, -1); // $input is now array ("red", "yellow") array_splice ($input, 1, count($input), "orange"); // $input is now array ("red", "orange") array_splice ($input, -1, 1, array("black", "maroon")); // $input is now array ("red", "green", // "blue", "black", "maroon")</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ: <A HREF="#function.array-slice" ><B CLASS="function" >array_slice()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-sum" ></A >array_sum</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8116" ></A ><P > (PHP 4 >= 4.0.4)</P >array_sum -- Calculate the sum of values in an array. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN8119" ></A ><H2 >Description</H2 >mixed <B CLASS="methodname" >array_sum</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >array_sum()</B > returns the sum of values in an array as an integer or float. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8130" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_sum()</B > examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = array(2, 4, 6, 8); echo "sum(a) = " . array_sum($a) . "\n"; $b = array("a" => 1.2, "b" => 2.3, "c" => 3.4); echo "sum(b) = " . array_sum($b) . "\n"; ?></PRE ></TD ></TR ></TABLE ><P >
The printout of the program above will be: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >sum(a) = 20 sum(b) = 6.9</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > PHP versions prior to 4.2.1 modified the passed array itself and converted strings to numbers (which most of the time converted them to zero, depending on their value). </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.array-udiff-assoc" ></A >array_udiff_assoc</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8139" ></A ><P > (no version information, might be only in CVS)</P >array_udiff_assoc -- Computes the difference of arrays with additional index check. The data is compared by using a callback function.</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8142" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_udiff_assoc</B > ( array array1, array array2 [, array ..., callback data_compare_func])<BR ></BR ><P >
<B CLASS="function" >array_udiff_assoc()</B > returns an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > containing all the values from <TT CLASS="parameter" ><I >array1</I ></TT > that are not present in any of the other arguments. Note that the keys are used in the comparison unlike <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A > and <A HREF="#function.array-udiff" ><B CLASS="function" >array_udiff()</B ></A >. The comparison of arrays' data is performed by using an user-supplied callback. In this aspect the behaviour is opposite to the behaviour of <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A > which uses internal function for comparison. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8167" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_udiff_assoc()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class cr { var $priv_member; function cr($val) { $this->priv_member = $val; } function comp_func_cr($a, $b) { if ($a->priv_member === $b->priv_member) return 0; return ($a->priv_member > $b->priv_member)? 1:-1; } } $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1=> new cr(4), 2 => new cr(-15),); $result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); print_r($result); ?></PRE ></TD ></TR ></TABLE ><P >
The result is: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0.1] => cr Object ( [priv_member:private] => 9 ) [0.5] => cr Object ( [priv_member:private] => 12 ) [0] => cr Object ( [priv_member:private] => 23 ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
In our example above you see the <TT CLASS="literal" >"1" => new cr(4)</TT > pair is present in both arrays and thus it is not in the ouput from the function. </P ><P >
For comparison is used the user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, <TT CLASS="literal" >array_udiff_assoc($array1[0], $array2[0], "some_comparison_func");</TT >. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >, <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A >, <A HREF="#function.array-diff-uassoc" ><B CLASS="function" >array_diff_uassoc()</B ></A >, <A HREF="#function.array-udiff" ><B CLASS="function" >array_udiff()</B ></A >, <A HREF="#function.array-udiff-uassoc" ><B CLASS="function" >array_udiff_uassoc()</B ></A >, <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >, <A HREF="#function.array-intersect-assoc" ><B CLASS="function" >array_intersect_assoc()</B ></A >, <B CLASS="function" >array_uintersect()</B >, <B CLASS="function" >array_uintersect_assoc()</B > and <B CLASS="function" >array_uintersect_uassoc()</B >. </P ></DIV ><H1 ><A NAME="function.array-udiff-uassoc" ></A >array_udiff_uassoc</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8191" ></A ><P > (no version information, might be only in CVS)</P >array_udiff_uassoc -- Computes the difference of arrays with additional index check. The data is compared by using a callback function. The index check is done by a callback function also</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8194" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_udiff_uassoc</B > ( array array1, array array2 [, array ..., callback data_compare_func, callback key_compare_func])<BR ></BR ><P >
<B CLASS="function" >array_udiff_uassoc()</B > returns an <A HREF="#language.types.array" ><B CLASS="type" >array</B ></A > containing all the values from <TT CLASS="parameter" ><I >array1</I ></TT > that are not present in any of the other arguments. Note that the keys are used in the comparison unlike <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A > and <A HREF="#function.array-udiff" ><B CLASS="function" >array_udiff()</B ></A >. The comparison of arrays' data is performed by using an user-supplied callback : <TT CLASS="parameter" ><I >data_compare_func</I ></TT >. In this aspect the behaviour is opposite to the behaviour of <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A > which uses internal function for comparison. The comparison of keys (indices) is done also by the callback function <TT CLASS="parameter" ><I >key_compare_func</I ></TT >. This behaviour is unlike what <A HREF="#function.array-udiff-assoc" ><B CLASS="function" >array_udiff_assoc()</B ></A > does, since the latter compares the indices by using an internal function. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8225" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_udiff_uassoc()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class cr { var $priv_member; function cr($val) { $this->priv_member = $val; } function comp_func_cr($a, $b) { if ($a->priv_member === $b->priv_member) return 0; return ($a->priv_member > $b->priv_member)? 1:-1; } function comp_func_key($a, $b) { if ($a === $b) return 0; return ($a > $b)? 1:-1; } } $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1=> new cr(4), 2 => new cr(-15),); $result = array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); print_r($result); ?></PRE ></TD ></TR ></TABLE ><P >
The result is: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0.1] => cr Object ( [priv_member:private] => 9 ) [0.5] => cr Object ( [priv_member:private] => 12 ) [0] => cr Object ( [priv_member:private] => 23 ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
In our example above you see the <TT CLASS="literal" >"1" => new cr(4)</TT > pair is present in both arrays and thus it is not in the ouput from the function. Keep in mind that you have to supply 2 callback functions. </P ><P >
For comparison is used the user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, <TT CLASS="literal" >array_udiff_uassoc($array1[0], $array2[0], "data_compare_func", "key_compare_func");</TT >. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >, <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A >, <A HREF="#function.array-diff-uassoc" ><B CLASS="function" >array_diff_uassoc()</B ></A >, <A HREF="#function.array-udiff" ><B CLASS="function" >array_udiff()</B ></A >, <A HREF="#function.array-udiff-assoc" ><B CLASS="function" >array_udiff_assoc()</B ></A >, <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >, <A HREF="#function.array-intersect-assoc" ><B CLASS="function" >array_intersect_assoc()</B ></A >, <B CLASS="function" >array_uintersect()</B >, <B CLASS="function" >array_uintersect_assoc()</B > and <B CLASS="function" >array_uintersect_uassoc()</B >. </P ></DIV ><H1 ><A NAME="function.array-udiff" ></A >array_udiff</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8249" ></A ><P > (no version information, might be only in CVS)</P >array_udiff -- Computes the difference of arrays by using a callback function for data comparison.</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8252" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_udiff</B > ( array array1, array array2 [, array ..., callback data_compare_func])<BR ></BR ><P >
<B CLASS="function" >array_udiff()</B > returns an array containing all the values of <TT CLASS="parameter" ><I >array1</I ></TT > that are not present in any of the other arguments. Note that keys are preserved. For the comparison of the data <TT CLASS="parameter" ><I >data_compare_func</I ></TT > is used. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. This is unlike <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A > which uses an internal function for comparing the data. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8275" ></A ><P ><B >P°φklad 1. <B CLASS="function" >array_udiff()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class cr { var $priv_member; function cr($val) { $this->priv_member = $val; } function comp_func_cr($a, $b) { if ($a->priv_member === $b->priv_member) return 0; return ($a->priv_member > $b->priv_member)? 1:-1; } } $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1=> new cr(4), 2 => new cr(-15),); $result = array_udiff($a, $b, array("cr", "comp_func_cr")); print_r($result); ?></PRE ></TD ></TR ></TABLE ><P >
The result is: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0.5] => cr Object ( [priv_member:private] => 12 ) [0] => cr Object ( [priv_member:private] => 23 ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Two elements are considered equal if and only if <TT CLASS="literal" >(string) $elem1 === (string) $elem2</TT >. In words: when the string representation is the same. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using <TT CLASS="literal" >array_udiff($array1[0], $array2[0], "data_compare_func");</TT >. </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.array-diff" ><B CLASS="function" >array_diff()</B ></A >, <A HREF="#function.array-diff-assoc" ><B CLASS="function" >array_diff_assoc()</B ></A >, <A HREF="#function.array-diff-uassoc" ><B CLASS="function" >array_diff_uassoc()</B ></A >, <A HREF="#function.array-udiff-assoc" ><B CLASS="function" >array_udiff_assoc()</B ></A >, <A HREF="#function.array-udiff-uassoc" ><B CLASS="function" >array_udiff_uassoc()</B ></A >, <A HREF="#function.array-intersect" ><B CLASS="function" >array_intersect()</B ></A >, <A HREF="#function.array-intersect-assoc" ><B CLASS="function" >array_intersect_assoc()</B ></A >, <B CLASS="function" >array_uintersect()</B >, <B CLASS="function" >array_uintersect_assoc()</B > and <B CLASS="function" >array_uintersect_uassoc()</B >. </P ></DIV ><H1 ><A NAME="function.array-unique" ></A >array_unique</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8299" ></A ><P > (PHP 4 >= 4.0.1)</P >array_unique -- Odstranit z pole duplicitnφ hodnoty</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8302" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_unique</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >array_unique()</B > p°ijφmß pole <TT CLASS="parameter" ><I >array</I ></TT > a vracφ novΘ pole bez duplicitnφch hodnot. KlφΦe jsou zachovßny. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8314" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_unique()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$input = array ("a" => "green", "red", "b" => "green", "blue", "red"); $result = array_unique ($input);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$result</TT > te∩ obsahuje <TT CLASS="literal" >array ("a" => "green", "red", "blue");</TT >. </P ></DIV ><H1 ><A NAME="function.array-unshift" ></A >array_unshift</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8322" ></A ><P > (PHP 4 )</P >array_unshift -- P°ipojit jeden nebo vφce prvk∙ na zaΦßtek pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8325" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >array_unshift</B > ( array array, mixed var [, mixed ...])<BR ></BR ><P >
<B CLASS="function" >array_unshift()</B > p°ipojφ p°edanΘ prvky na zaΦßtek <TT CLASS="parameter" ><I >array</I ></TT >. V╣echny prvky jsou p°idßny jako celek, Φili p°idanΘ prvky si zachovßvajφ po°adφ. </P ><P >
vracφ nov² poΦet prvk∙ v <TT CLASS="parameter" ><I >array</I ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8345" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_unshift()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$queue = array ("p1", "p3"); array_unshift ($queue, "p4", "p5", "p6");</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$queue</TT > bude mφt 5 prvk∙: "p4", "p5", "p6", "p1" a "p3". </P ><P >
Viz takΘ: <A HREF="#function.array-shift" ><B CLASS="function" >array_shift()</B ></A >, <A HREF="#function.array-push" ><B CLASS="function" >array_push()</B ></A > a <A HREF="#function.array-pop" ><B CLASS="function" >array_pop()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array-values" ></A >array_values</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8356" ></A ><P > (PHP 4 )</P >array_values -- Vrßtit v╣echny hodnoty v poli</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8359" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array_values</B > ( array input)<BR ></BR ><P >
<B CLASS="function" >array_values()</B > vracφ v╣echny hodnoty pole <TT CLASS="parameter" ><I >input</I ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8371" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_values()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array = array ("size" => "XL", "color" => "gold"); array_values ($array); // vrßtφ array ("XL", "gold")</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Tato funkce byla p°idßna v PHP 4, nßsleduje implementace pro ty, kdo stßle pou╛φvajφ PHP 3. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8377" ></A ><P ><B >P°φklad 2. Implementace <B CLASS="function" >array_values()</B > pro u╛ivatele PHP 3 </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function array_values ($arr) { $t = array(); while (list($k, $v) = each ($arr)) { $t[] = $v; return $t; } }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.array-walk" ></A >array_walk</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8382" ></A ><P > (PHP 3>= 3.0.3, PHP 4 )</P >array_walk -- Pou╛φt u╛ivatelskou funkci na v╣echny prvky pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8385" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >array_walk</B > ( array arr, string func, mixed userdata)<BR ></BR ><P >
Aplikuje funkci <TT CLASS="parameter" ><I >func</I ></TT > na v╣echny prvky pole <TT CLASS="parameter" ><I >arr</I ></TT >. Funkci <TT CLASS="parameter" ><I >func</I ></TT > se jako prvnφ argument p°edß hodnota a jako druh² klφΦ. Pokud je p°φtomen argument <TT CLASS="parameter" ><I >userdata</I ></TT >, bude u╛ivatelskΘ funkci p°edßn jako t°etφ argument. </P ><P >
Pokud <TT CLASS="parameter" ><I >func</I ></TT > vy╛aduje vφce ne╛ dva nebo t°i argumenty (v zßvislosti na <TT CLASS="parameter" ><I >userdata</I ></TT >), pro ka╛dΘ volßnφ <TT CLASS="parameter" ><I >func</I ></TT > z <B CLASS="function" >array_walk()</B > se vygeneruje varovßnφ. Tato varovßnφ se dajφ potlaΦit p°idßnφm znaku '@' p°ed volßnφ <B CLASS="function" >array_walk()</B > nebo pomocφ <A HREF="#function.error-reporting" ><B CLASS="function" >error_reporting()</B ></A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Pokud <TT CLASS="parameter" ><I >func</I ></TT > pot°ebuje pracovat p°φmo s dan²m polem, prvnφ argument <TT CLASS="parameter" ><I >func</I ></TT > se musφ p°edßvat odkazem. V╣echny zm∞ny t∞chto hodnot se pak promφtnou p°φmo v <TT CLASS="parameter" ><I >arr</I ></TT >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Druh² a t°etφ argument <TT CLASS="parameter" ><I >func</I ></TT > byly p°idßny v PHP 4.0. </P ><P >
V PHP 4 je t°eba volat podle pot°eby <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >, proto╛e <B CLASS="function" >array_walk()</B > sama vstupnφ pole neresetuje. </P ></BLOCKQUOTE ></DIV ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8423" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array_walk()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); function test_alter (&$item1, $key, $prefix) { $item1 = "$prefix: $item1"; } function test_print ($item2, $key) { echo "$key. $item2<br>\n"; } array_walk ($fruits, 'test_print'); reset ($fruits); array_walk ($fruits, 'test_alter', 'fruit'); reset ($fruits); array_walk ($fruits, 'test_print');</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ: <A HREF="#function.each" ><B CLASS="function" >each()</B ></A > a <A HREF="#function.list" ><B CLASS="function" >list()</B ></A >. </P ></DIV ><H1 ><A NAME="function.array" ></A >array</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8431" ></A ><P > (PHP 3, PHP 4 )</P >array -- Vytvo°it pole </DIV ><DIV CLASS="refsect1" ><A NAME="AEN8434" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >array</B > ( [mixed ...])<BR ></BR ><P >
Vracφ pole argument∙. Argument∙m m∙╛e b²t p°i°azen index pomocφ operßtoru <TT CLASS="literal" >=></TT >. </P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > <B CLASS="function" >array()</B > je jazykov² konstrukt pou╛φvan² k reprezentaci polφ, nikoliv b∞╛nß funkce. </P ></BLOCKQUOTE ></DIV > </P ><P >
Syntaxe "index => hodnota", s Φßrko jako odd∞lovaΦem, definuje indexy a hodnoty. Index m∙╛e b²t °et∞zec nebo Φφslo. Pokud se index vynechß, automaticky se generuje Φφseln² index zaΦφnajφcφ na 0. Pokud je index integer, dal╣φ generovan² index bude nejvy╣╣φ celoΦφseln² index + 1. Pozn.: pokud jsou definovßny dva identickΘ indexy, prvnφ se p°epφ╣e poslednφm. </P ><P >
Nßsledujφcφ ukßzka demonstruje jak vytvo°it dvourozm∞rnΘ pole, jak urΦit klφΦe v asociativnφch polφch, a jak p°eskakovat ΦφselnΘ indexy v normßlnφch polφch. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8450" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >array()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$fruits = array ( "fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"), "numbers" => array (1, 2, 3, 4, 5, 6), "holes" => array ("first", 5 => "second", "third") );</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8455" ></A ><P ><B >P°φklad 2. Automatick² index a <B CLASS="function" >array()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13); print_r($array);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > v²stup bude nßsledujφcφ: <DIV CLASS="informalexample" ><A NAME="AEN8459" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 13 [4] => 1 [8] => 1 [9] => 19 )</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Index 3 je definovßn dvakrßt, a podr╛φ si poslednφ hodnotu 13. Index 4 je definovßn po indexu 8 a dal╣φ generovan² index (hodnota 19) je 9, proto╛e nejvy╣╣φ index byl 8. </P ><P >
Tato ukßzka vytvo°φ pole ΦφslovanΘ od 1. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8462" ></A ><P ><B >P°φklad 3. Index zaΦφnajφcφ 1 s <B CLASS="function" >array()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$firstquarter = array(1 => 'January', 'February', 'March'); print_r($firstquarter);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > toto bude v²stup: <DIV CLASS="informalexample" ><A NAME="AEN8466" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Array ( [1] => 'January' [2] => 'February' [3] => 'March' )</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Viz takΘ: <A HREF="#function.list" ><B CLASS="function" >list()</B ></A >. </P ></DIV ><H1 ><A NAME="function.arsort" ></A >arsort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8471" ></A ><P > (PHP 3, PHP 4 )</P >arsort -- T°φdit pole sestupn∞ se zachovßnφm klφΦ∙ </DIV ><DIV CLASS="refsect1" ><A NAME="AEN8474" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >arsort</B > ( array array [, int sort_flags])<BR ></BR ><P >
<B CLASS="function" >arsort()</B > t°φdφ pole tak, ╛e indexy pole si zachovßvajφ korelace s prvky, se kter²mi jsou asociovßny. Toto je u╛iteΦnΘ hlavn∞ p°i t°φd∞nφ asociativnφch polφ, kde je po°adφ prvk∙ signifikantnφ. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8487" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >arsort()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); arsort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key = $val\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka zobrazφ: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN8493" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >fruits[a] = orange fruits[d] = lemon fruits[b] = banana fruits[c] = apple</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Ovoce bylo sestupn∞ set°φd∞no podle abecedy, a indexy asociovanΘ s jednotliv²mi prvky byly zachovßny. </P ><P >
Chovßnφ t°φd∞nφ m∙╛ete upravit pomocφ volitelnΘho argumentu <TT CLASS="parameter" ><I >sort_flags</I ></TT >, detaily viz <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >. </P ><P >
Viz takΘ: <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A > a <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >. </P ></DIV ><H1 ><A NAME="function.asort" ></A >asort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8505" ></A ><P > (PHP 3, PHP 4 )</P >asort -- T°φdit pole se zachovßnφm index∙</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8508" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >asort</B > ( array array [, int sort_flags])<BR ></BR ><P >
<B CLASS="function" >asort()</B > t°φdφ pole tak, ╛e si indexy zachovajφ corelace s prvky, se kter²mi jsou spojeny. To je u╛iteΦnΘ hlavn∞ p°i t°φd∞nφ asociativnφch polφ, u kter²ch je po°adφ prvk∙ signifikantnφ. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8521" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >asort()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); asort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key = $val\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka zobrazφ: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN8527" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >fruits[c] = apple fruits[b] = banana fruits[d] = lemon fruits[a] = orange</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Ovoce bylo set°φd∞no podle abecedy a indexy spojenΘ s jednotliv²mi prvky byly zachovßny. </P ><P >
Chovßnφ t°φd∞nφ m∙╛ete upravit pomocφ volitelnΘho argumentu <TT CLASS="parameter" ><I >sort_flags</I ></TT >, detaily viz <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >. </P ><P >
Viz takΘ: <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A > a <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >. </P ></DIV ><H1 ><A NAME="function.compact" ></A >compact</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8539" ></A ><P > (PHP 4 )</P >compact -- Vytvo°it pole obsahujφcφ prom∞nnΘ a jejich hodnoty</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8542" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >compact</B > ( mixed varname [, mixed ...])<BR ></BR ><P >
<B CLASS="function" >compact()</B > p°ijφmß prom∞nn² poΦet argument∙. Ka╛d² argument m∙╛e b²t bu∩ °et∞zec obsahujφcφ nßzev prom∞nnΘ nebo pole nßzv∙ prom∞nn²ch. Toto pole m∙╛e takΘ obsahovat pole nßzv∙ prom∞nn²ch∙; <B CLASS="function" >compact()</B > je rekurzivn∞ zpracuje. </P ><P >
Pro ka╛d² z °et∞zc∙ <B CLASS="function" >compact()</B > vyhledß v aktivnφ symbolovΘ tabulce prom∞nnou tohoto jmΘna a p°idß ji do v²slednΘho pole tak, ╛e nßzev tΘto prom∞nnΘ se stane klφΦem a obsah tΘto prom∞nnΘ hodnotou tohoto klφΦe. StruΦn∞ °eΦeno, d∞lß prav² opak toho, co <A HREF="#function.extract" ><B CLASS="function" >extract()</B ></A >. Vracφ pole obsahujφcφ v╣echny tyto prom∞nnΘ. </P ><P >
╪et∞zce, kterΘ neobsahujφ nßzvy platn²ch prom∞nn²ch se p°eskoΦφ. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8561" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >compact()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$city = "San Francisco"; $state = "CA"; $event = "SIGGRAPH"; $location_vars = array ("city", "state"); $result = compact ("event", "nothing_here", $location_vars);</PRE ></TD ></TR ></TABLE ><P >
<TT CLASS="varname" >$result</TT > bude <TT CLASS="literal" >array ("event" => "SIGGRAPH", "city" => "San Francisco", "state" => "CA")</TT >. </P ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ: <A HREF="#function.extract" ><B CLASS="function" >extract()</B ></A >. </P ></DIV ><H1 ><A NAME="function.count" ></A >count</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8571" ></A ><P > (PHP 3, PHP 4 )</P >count -- SpoΦφtat prvky v prom∞nnΘ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8574" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >count</B > ( mixed var)<BR ></BR ><P >
Vracφ poΦet prvk∙ v <TT CLASS="parameter" ><I >var</I ></TT >, kterß je typicky pole (jeliko╛ v╣echno ostatnφ mß jeden prvek). </P ><P >
Vracφ <TT CLASS="literal" >1</TT >, pokud <TT CLASS="parameter" ><I >var</I ></TT > nenφ pole. </P ><P >
Vracφ <TT CLASS="literal" >0</TT >, pokud <TT CLASS="parameter" ><I >var</I ></TT > nenφ inicializovßna. <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
<B CLASS="function" >count()</B > vracφ <TT CLASS="literal" >0</TT > pro prom∞nnΘ, kterΘ nejsou inicializovßny, ale vracφ takΘ <TT CLASS="literal" >0</TT > pro prom∞nnΘ, kterΘ obsahujφ prßzdnΘ pole. Pokud pot°ebujete zjistit, jestli dotyΦnß prom∞nnß existuje, pou╛ijte <A HREF="#function.isset" ><B CLASS="function" >isset()</B ></A >. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8597" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >count()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$a[0] = 1; $a[1] = 3; $a[2] = 5; $result = count ($a); //$result == 3</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ: <A HREF="#function.sizeof" ><B CLASS="function" >sizeof()</B ></A >, <A HREF="#function.isset" ><B CLASS="function" >isset()</B ></A > a <A HREF="#function.is-array" ><B CLASS="function" >is_array()</B ></A >. </P ></DIV ><H1 ><A NAME="function.current" ></A >current</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8606" ></A ><P > (PHP 3, PHP 4 )</P >current -- Vrßtit souΦasn² prvek pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8609" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >current</B > ( array array)<BR ></BR ><P >
Ka╛dΘ pole mß vnit°nφ ukazatel na jeho "souΦasny" prvek, kter² se inicializuje na prvnφ prvek vlo╛en² do tohoto pole. </P ><P >
<B CLASS="function" >current()</B > vracφ prvek, na kter² tento internφ ukazatel prßv∞ ukazuje. Nijak tento ukazatel nem∞nφ. Pokud teto vnit°nφ ukazatel ukazuje za konec seznamu prvk∙, <B CLASS="function" >current()</B > returns <TT CLASS="constant" ><B >FALSE</B ></TT >. <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Pokud toto pole obsahuje prßzdnΘ prvky (0 nebo "", prßzdn² °et∞zec), tato funkce pro tyto prvky takΘ vrßtφ <TT CLASS="constant" ><B >FALSE</B ></TT >. Je proto nemo╛nΘ urΦit pomocφ <B CLASS="function" >current()</B >, jestli jste opravdu na konci pole. To properly traverse an array that may contain empty elements, use the <A HREF="#function.each" ><B CLASS="function" >each()</B ></A > function. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
Viz takΘ: <A HREF="#function.end" ><B CLASS="function" >end()</B ></A >, <A HREF="#function.next" ><B CLASS="function" >next()</B ></A >, <A HREF="#function.prev" ><B CLASS="function" >prev()</B ></A > a <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >. </P ></DIV ><H1 ><A NAME="function.each" ></A >each</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8633" ></A ><P > (PHP 3, PHP 4 )</P >each -- Vracφ dal╣φ klφΦ/hodnota pßr z pole </DIV ><DIV CLASS="refsect1" ><A NAME="AEN8636" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >each</B > ( array array)<BR ></BR ><P >
Vracφ souΦasn² klφΦ/hodnota pßr z pole <TT CLASS="parameter" ><I >array</I ></TT > a posune internφ ukazatel pole. Tento pßr se vracφ jako pole Φty° prvk∙ s klφΦi <SPAN CLASS="emphasis" ><I CLASS="emphasis" >0</I ></SPAN >, <SPAN CLASS="emphasis" ><I CLASS="emphasis" >1</I ></SPAN >, <SPAN CLASS="emphasis" ><I CLASS="emphasis" >key</I ></SPAN > a <SPAN CLASS="emphasis" ><I CLASS="emphasis" >value</I ></SPAN >. Prvky <SPAN CLASS="emphasis" ><I CLASS="emphasis" >0</I ></SPAN > a <SPAN CLASS="emphasis" ><I CLASS="emphasis" >key</I ></SPAN > obsahujφ nßzev klφΦe tohoto prvku pole a <SPAN CLASS="emphasis" ><I CLASS="emphasis" >1</I ></SPAN > a <SPAN CLASS="emphasis" ><I CLASS="emphasis" >value</I ></SPAN > obsahujφ hodnotu. </P ><P >
Pokud internφ ukazatel pole ukazuje za konec tohoto pole, <B CLASS="function" >each()</B > vracφ <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8658" ></A ><P ><B >P°φklad 1. Ukßzky <B CLASS="function" >each()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$foo = array ("bob", "fred", "jussi", "jouni", "egon", "marliese"); $bar = each ($foo);</PRE ></TD ></TR ></TABLE ><P >
<TT CLASS="varname" >$bar</TT > te∩ obsahuje nßsledujφcφ klφΦ/hodnota pßry: <P ></P ><UL COMPACT="COMPACT" ><LI ><SPAN >0 => 0</SPAN ></LI ><LI ><SPAN >1 => 'bob'</SPAN ></LI ><LI ><SPAN >key => 0</SPAN ></LI ><LI ><SPAN >value => 'bob'</SPAN ></LI ></UL > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$foo = array ("Robert" => "Bob", "Seppo" => "Sepi"); $bar = each ($foo);</PRE ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$bar</TT > te∩ obsahuje nßsledujφcφ klφΦ/hodnota pßry: <P ></P ><UL COMPACT="COMPACT" ><LI ><SPAN >0 => 'Robert'</SPAN ></LI ><LI ><SPAN >1 => 'Bob'</SPAN ></LI ><LI ><SPAN >key => 'Robert'</SPAN ></LI ><LI ><SPAN >value => 'Bob'</SPAN ></LI ></UL > </P ></DIV ></TD ></TR ></TABLE > </P ><P >
<B CLASS="function" >each()</B > se v∞t╣inou pou╛φva s <A HREF="#function.list" ><B CLASS="function" >list()</B ></A > k pr∙chodu polem, nap°. <TT CLASS="varname" >$HTTP_POST_VARS</TT >: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8689" ></A ><P ><B >P°φklad 2. Pr∙chod <TT CLASS="varname" >$HTTP_POST_VARS</TT > pomocφ <B CLASS="function" >each()</B > </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo "Hodnoty odeslanΘ metodou POST:<br>"; reset ($HTTP_POST_VARS); while (list ($key, $val) = each ($HTTP_POST_VARS)) { echo "$key => $val<br>"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
PotΘ, co prob∞hne <B CLASS="function" >each()</B >, se internφ ukazatel pole posune na dal╣φ prvek pole nebo z∙stane na poslednφm prvku pole, pokud dojde na konec. </P ><P >
Viz takΘ: <A HREF="#function.key" ><B CLASS="function" >key()</B ></A >, <A HREF="#function.list" ><B CLASS="function" >list()</B ></A >, <A HREF="#function.current" ><B CLASS="function" >current()</B ></A >, <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >, <A HREF="#function.next" ><B CLASS="function" >next()</B ></A > a <A HREF="#function.prev" ><B CLASS="function" >prev()</B ></A >. </P ></DIV ><H1 ><A NAME="function.end" ></A >end</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8704" ></A ><P > (PHP 3, PHP 4 )</P >end -- Nastavit vnit°nφ ukazatel pole na jeho poslednφ prvek </DIV ><DIV CLASS="refsect1" ><A NAME="AEN8707" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >end</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >end()</B > posune vnit°nφ ukazatel pole <TT CLASS="parameter" ><I >array</I ></TT > na jeho poslednφ prvek a vracφ tento prvek. </P ><P >
Viz takΘ: <A HREF="#function.current" ><B CLASS="function" >current()</B ></A >, <A HREF="#function.each" ><B CLASS="function" >each()</B ></A >, <B CLASS="function" >end()</B >, <A HREF="#function.next" ><B CLASS="function" >next()</B ></A > a <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >. </P ></DIV ><H1 ><A NAME="function.extract" ></A >extract</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8725" ></A ><P > (PHP 3>= 3.0.7, PHP 4 )</P >extract -- Importovat prom∞nnΘ z pole do symbolovΘ tabulky</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8728" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >extract</B > ( array var_array [, int extract_type [, string prefix]])<BR ></BR ><P >
Tato funkce se pou╛φvß k importu prom∞nn²ch z pole do aktivnφ symbolovΘ tabulky. P°ijφmß pole <TT CLASS="parameter" ><I >var_array</I ></TT >; z klφΦ∙ vytvß°φ nßzvy prom∞nn²ch a z hodnot hodnoty t∞chto prom∞nn²ch. Vytvß°φ jednu prom∞nnou z ka╛dΘho klφΦ/hodnota pßru (s ohledem na argumenty <TT CLASS="parameter" ><I >extract_type</I ></TT > a <TT CLASS="parameter" ><I >prefix</I ></TT >). </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Od PHP 4.0.5 tato funkce vracφ poΦet extrahovan²ch prom∞nn²ch. </P ></BLOCKQUOTE ></DIV ><P >
<B CLASS="function" >extract()</B > ov∞°uje, jestli v╣echny klφΦe tvo°φ platnΘ nßzvy prom∞nn²ch, a takΘ jestli nekolidujφ s prom∞nn²mi existujφcφmi v aktivnφ symbolovΘ tabulce. Zp∙sob, jak²m se naklßdß s neplatn²mi/numerick²mi klφΦi a kolizemi zßvisφ na <TT CLASS="parameter" ><I >extract_type</I ></TT >. Ten m∙╛e mφt jednu z nßsledujφcφch hodnot. <P ></P ><DIV CLASS="variablelist" ><DL ><DT >EXTR_OVERWRITE</DT ><DD ><P >
Pokud existuje kolize, p°epsat existujφcφ prom∞nnou. </P ></DD ><DT >EXTR_SKIP</DT ><DD ><P >
Pokud existuje kolize, nep°epsat existujφcφ prom∞nnou. </P ></DD ><DT >EXTR_PREFIX_SAME</DT ><DD ><P >
Pokud existuje kolize, p°ed°adit p°ed nßzev novΘ prom∞nnΘ <TT CLASS="parameter" ><I >prefix</I ></TT >. </P ></DD ><DT >EXTR_PREFIX_ALL</DT ><DD ><P >
Opat°it prefixem <TT CLASS="parameter" ><I >prefix</I ></TT > v╣echny nßzvy prom∞nn²ch. Od PHP 4.0.5 toto zahrnuje i ΦφselnΘ indexy. </P ></DD ><DT >EXTR_PREFIX_INVALID</DT ><DD ><P >
Prefixem <TT CLASS="parameter" ><I >prefix</I ></TT > opat°it pouze neplatnΘ/ΦφselnΘ nßzvy prom∞nn²ch. Tento p°φznak byl p°idßn v PHP 4.0.5. </P ></DD ></DL ></DIV > </P ><P >
Defaultnφ <TT CLASS="parameter" ><I >extract_type</I ></TT > je EXTR_OVERWRITE. </P ><P >
Pozn.: <TT CLASS="parameter" ><I >prefix</I ></TT > se vy╛aduje pouze pokud je <TT CLASS="parameter" ><I >extract_type</I ></TT > EXTR_PREFIX_SAME, EXTR_PREFIX_ALL nebo EXTR_PREFIX_INVALID. Pokud v²sledn² nßzev (vΦ. prefixu) nenφ platn² nßzev prom∞nnΘ, nenaimportuje se do symbolovΘ tabulky. </P ><P >
<B CLASS="function" >extract()</B > vracφ poΦet prom∞nn²ch ·sp∞╣n∞ naimportovan²ch do symbolovΘ tabulky. </P ><P >
Mo╛nΘ vyu╛itφ <B CLASS="function" >extract()</B > je import prom∞nn²ch do symbolovΘ tabulky z asociativnφho pole vrßcenΘho <A HREF="#function.wddx-deserialize" ><B CLASS="function" >wddx_deserialize()</B ></A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8786" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >extract()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php /* P°edpoklßdejme, ╛e $var_array je pole vrßcenΘ z wddx_deserialize */ $size = "large"; $var_array = array ("color" => "blue", "size" => "medium", "shape" => "sphere"); extract ($var_array, EXTR_PREFIX_SAME, "wddx"); print "$color, $size, $shape, $wddx_size\n"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
V²╣e uvedenß ukßzka vytiskne: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >blue, large, sphere, medium</PRE ></TD ></TR ></TABLE > </P ><P >
<TT CLASS="varname" >$size</TT > se nep°epsala, proto╛e bylo specifikovßno EXTR_PREFIX_SAME, tudφ╛ se vytvo°ila prom∞nnß <TT CLASS="varname" >$wddx_size</TT >. Pokud by bylo zadßno EXTR_SKIP, nevytvo°ila by se ani <TT CLASS="varname" >$wddx_size</TT >. EXTR_OVERWRITE by zp∙sobilo p°epsßnφ hodnoty <TT CLASS="varname" >$size</TT > na "medium", a EXTR_PREFIX_ALL by vytvo°ilo novΘ prom∞nnΘ pojmenovanΘ <TT CLASS="varname" >$wddx_color</TT >, <TT CLASS="varname" >$wddx_size</TT > a <TT CLASS="varname" >$wddx_shape</TT >. </P ><P >
U PHP verzφ ni╛╣φch ne╛ 4.0.5 musφte pou╛φt asociativnφ pole. </P ><P >
Viz takΘ: <A HREF="#function.compact" ><B CLASS="function" >compact()</B ></A >. </P ></DIV ><H1 ><A NAME="function.in-array" ></A >in_array</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8804" ></A ><P > (PHP 4 )</P >in_array -- Vrßtit <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud v poli existuje danß hodnota</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8808" ></A ><H2 >Popis</H2 >bool <B CLASS="methodname" >in_array</B > ( mixed needle, array haystack, bool strict)<BR ></BR ><P >
Hledß v <TT CLASS="parameter" ><I >haystack</I ></TT > <TT CLASS="parameter" ><I >needle</I ></TT > a pokud ji najde, vracφ <TT CLASS="constant" ><B >TRUE</B ></TT >, jinak <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ><P >
Pokud je t°etφ argument <TT CLASS="parameter" ><I >strict</I ></TT > <TT CLASS="constant" ><B >TRUE</B ></TT >, <B CLASS="function" >in_array()</B > takΘ kontroluje typ <TT CLASS="parameter" ><I >needle</I ></TT > v <TT CLASS="parameter" ><I >haystack</I ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8834" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >in_array()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$os = array ("Mac", "NT", "Irix", "Linux"); if (in_array ("Irix", $os)){ print "Got Irix"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8839" ></A ><P ><B >P°φklad 2. Ukßzka <B CLASS="function" >in_array()</B > s argumentem <TT CLASS="parameter" ><I >strict</I ></TT ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >// V²stup bude: 1.13 found with strict check</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.key" ></A >key</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8845" ></A ><P > (PHP 3, PHP 4 )</P >key -- Fetch a key from an associative array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8848" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >key</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >key()</B > vracφ index souΦasnΘho prvku pole. </P ><P >
Viz takΘ: <A HREF="#function.current" ><B CLASS="function" >current()</B ></A > a <A HREF="#function.next" ><B CLASS="function" >next()</B ></A >. </P ></DIV ><H1 ><A NAME="function.krsort" ></A >krsort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8862" ></A ><P > (PHP 3>= 3.0.13, PHP 4 )</P >krsort -- T°φdit pole sestupn∞ podle klφΦ∙</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8865" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >krsort</B > ( array array [, int sort_flags])<BR ></BR ><P >
T°φdφ pole sestupn∞ podle klφΦ∙ se zachovßnφ asociacφ index∙. To je u╛iteΦnΘ hlavn∞ p°i prßci s asociativnφmi poli. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8877" ></A ><P ><B >P°φklad 1. <B CLASS="function" >krsort()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); krsort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key -> $val\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka vytiskne: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN8883" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >fruits[d] = lemon fruits[c] = apple fruits[b] = banana fruits[a] = orange</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Vlastnosti t°φd∞nφ lze upravit pomocφ volitelnΘho argumentu <TT CLASS="parameter" ><I >sort_flags</I ></TT >, detaily viz <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >. </P ><P >
Viz takΘ: <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A >, <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >, <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A > a <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >. </P ></DIV ><H1 ><A NAME="function.ksort" ></A >ksort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8896" ></A ><P > (PHP 3, PHP 4 )</P >ksort -- T°φdit pole podle klφΦ∙</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8899" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >ksort</B > ( array array [, int sort_flags])<BR ></BR ><P >
T°φdφ pole podle klφΦ∙ se zachovßnφ asociacφ index∙. To je u╛iteΦnΘ hlavn∞ p°i prßci s asociativnφmi poli. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8911" ></A ><P ><B >P°φklad 1. <B CLASS="function" >ksort()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); ksort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key -> $val\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka vytiskne: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN8917" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >fruits[a] = orange fruits[b] = banana fruits[c] = apple fruits[d] = lemon</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Vlastnosti t°φd∞nφ lze upravit pomocφ volitelnΘho argumentu <TT CLASS="parameter" ><I >sort_flags</I ></TT >, detaily viz <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >. </P ><P >
Viz takΘ: <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >, <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A > a <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Druh² argument byl p°idßn v PHP 4. </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.list" ></A >list</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8931" ></A ><P > (PHP 3, PHP 4 )</P >list -- P°i°adit hodnoty p°om∞nn²m jako kdyby byly polem</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8934" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >list</B > ( mixed ...)<BR ></BR ><P >
Stejn∞ jako <A HREF="#function.array" ><B CLASS="function" >array()</B ></A >, <B CLASS="function" >list()</B > vlastn∞ nenφ funkce, ale jazykov² konstrukt. Pou╛φvß se k p°i°azenφ hodnot vφce prom∞nn²m v jednΘ operaci. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8945" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >list()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><table> <tr> <th>Employee name</th> <th>Salary</th> </tr> <?php $result = mysql ($conn, "SELECT id, name, salary FROM employees"); while (list ($id, $name, $salary) = mysql_fetch_row ($result)) { print (" <tr>\n". " <td><a href=\"info.php3?id=$id\">$name</a></td>\n". " <td>$salary</td>\n". " </tr>\n"); } ?> </table></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ: <A HREF="#function.each" ><B CLASS="function" >each()</B ></A > a <A HREF="#function.array" ><B CLASS="function" >array()</B ></A >. </P ></DIV ><H1 ><A NAME="function.natcasesort" ></A >natcasesort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8953" ></A ><P > (PHP 4 )</P >natcasesort -- T°φdit pole s vyu╛itφm algoritmu "p°irozenΘho t°φd∞nφ" (case-insensitive) </DIV ><DIV CLASS="refsect1" ><A NAME="AEN8956" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >natcasesort</B > ( array array)<BR ></BR ><P >
Tato funkce implementuje srovnßvacφ algoritmus kter² t°φdφ alfanumerickΘ °et∞zce stejn²m zp∙sobem jako Φlov∞k, toto se popisuje jako "p°irozenΘ t°φd∞nφ". </P ><P >
<B CLASS="function" >natcasesort()</B > je case-insensitive verze <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A >. Ukßzka rozdφlu mezi tφmto algoritmem a b∞╛n²m poΦφtaΦov²m t°φd∞nφm °et∞zc∙ viz <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A >. </P ><P >
Vφce informacφ viz strßnka Martina Poola <A HREF="http://www.naturalordersort.org/" TARGET="_top" >Natural Order String Comparison</A >. </P ><P >
Viz takΘ: <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >, <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A >, <A HREF="#function.strnatcmp" ><B CLASS="function" >strnatcmp()</B ></A > and <A HREF="#function.strnatcasecmp" ><B CLASS="function" >strnatcasecmp()</B ></A >. </P ></DIV ><H1 ><A NAME="function.natsort" ></A >natsort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8977" ></A ><P > (PHP 4 )</P >natsort -- T°φdit pole s vyu╛itφm algoritmu "p°irozenΘho t°φd∞nφ" </DIV ><DIV CLASS="refsect1" ><A NAME="AEN8980" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >natsort</B > ( array array)<BR ></BR ><P >
Tato funkce implementuje srovnßvacφ algoritmus kter² t°φdφ alfanumerickΘ °et∞zce stejn²m zp∙sobem jako Φlov∞k, toto se popisuje jako "p°irozenΘ t°φd∞nφ". Ukßzka rozdφlu m∞zi tφmto algoritmem a b∞╛n²mi poΦφtaΦov²mi algoritmy pro °azenφ °et∞zc∙ (nap°. <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >): </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN8991" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >natsort()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$array1 = $array2 = array ("img12.png","img10.png","img2.png","img1.png"); sort($array1); echo "Standardnφ t°φd∞nφ\n"; print_r($array1); natsort($array2); echo "\nP°irozenΘ t°φd∞nφ\n"; print_r($array2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
V²╣e uveden² k≤d vygeneruje nßsledujφcφ v²stup: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN8997" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >Standardnφ t°φd∞nφ Array ( [0] => img1.png [1] => img10.png [2] => img12.png [3] => img2.png ) P°irozenΘ t°φd∞nφ Array ( [3] => img1.png [2] => img2.png [1] => img10.png [0] => img12.png )</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Vφce informacφ viz strßnka Martina Poola <A HREF="http://www.naturalordersort.org/" TARGET="_top" >Natural Order String Comparison</A >. </P ><P >
Viz takΘ: <A HREF="#function.natcasesort" ><B CLASS="function" >natcasesort()</B ></A >, <A HREF="#function.strnatcmp" ><B CLASS="function" >strnatcmp()</B ></A > a <A HREF="#function.strnatcasecmp" ><B CLASS="function" >strnatcasecmp()</B ></A >. </P ></DIV ><H1 ><A NAME="function.next" ></A >next</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9005" ></A ><P > (PHP 3, PHP 4 )</P >next -- Posunout internφ ukazatel pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9008" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >next</B > ( array array)<BR ></BR ><P >
Vracφ dal╣φ prvek pole nebo <TT CLASS="constant" ><B >FALSE</B ></TT >, pokud prvky do╣ly. </P ><P >
<B CLASS="function" >next()</B > se chovß jako <A HREF="#function.current" ><B CLASS="function" >current()</B ></A >, s jednφm rozdφlem: posouvß internφ ukazatel pole o jeden prvek a vracφ prvek, na kter² tento ukazatel ukazuje po posunu. To znamenß, ╛e vracφ dal╣φ prvek pole a posouvß internφ ukazatel o jeden. Pokud by ukazatel po psunu ukazoval mimo pole, <B CLASS="function" >next()</B > vracφ <TT CLASS="constant" ><B >FALSE</B ></TT >. <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Pokud toto pole obsahuje prßzdnΘ prvky, nebo prvky, jejich╛ index je 0, tato funkce vrßtφ <TT CLASS="constant" ><B >FALSE</B ></TT > i pro tyto prvky. Ke sprßvnΘmu pr∙chodu polem, kterΘ m∙╛e obsahovat prßzdnΘ prvky nebo prvky s indexem 0 pou╛ijte <A HREF="#function.each" ><B CLASS="function" >each()</B ></A >. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
Viz takΘ: <A HREF="#function.current" ><B CLASS="function" >current()</B ></A >, <A HREF="#function.end" ><B CLASS="function" >end()</B ></A >, <A HREF="#function.prev" ><B CLASS="function" >prev()</B ></A > a <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >. </P ></DIV ><H1 ><A NAME="function.pos" ></A >pos</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9033" ></A ><P > (PHP 3, PHP 4 )</P >pos -- Zφskat souΦasn² prvek pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9036" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >pos</B > ( array array)<BR ></BR ><P >
Toto je alias k <A HREF="#function.current" ><B CLASS="function" >current()</B ></A >. </P ><P >
Viz takΘ: <A HREF="#function.end" ><B CLASS="function" >end()</B ></A >, <A HREF="#function.next" ><B CLASS="function" >next()</B ></A >, <A HREF="#function.prev" ><B CLASS="function" >prev()</B ></A > a <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >. </P ></DIV ><H1 ><A NAME="function.prev" ></A >prev</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9052" ></A ><P > (PHP 3, PHP 4 )</P >prev -- Rewind internφ ukazatel pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9055" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >prev</B > ( array array)<BR ></BR ><P >
Vracφ prvek pole p°ed tφm prvkem, na kter² ukazuje internφ ukazatel pole, nebo <TT CLASS="constant" ><B >FALSE</B ></TT >, pokud prvky do╣ly. <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Pokud toto pole obsahuje prßzdnΘ prvky, tato funkce vrßtφ <TT CLASS="constant" ><B >FALSE</B ></TT > i pro tyto prvky. Ke sprßvnΘmu pr∙chodu polem, kterΘ m∙╛e obsahovat prßzdnΘ prvky pou╛ijte <A HREF="#function.each" ><B CLASS="function" >each()</B ></A >. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
<B CLASS="function" >prev()</B > se chovß stejn∞ jako <A HREF="#function.next" ><B CLASS="function" >next()</B ></A >, ale posouvß internφ ukazatel pole o jedno mφsto zpßtky mφsto dop°edu. </P ><P >
Viz takΘ: <A HREF="#function.current" ><B CLASS="function" >current()</B ></A >, <A HREF="#function.end" ><B CLASS="function" >end()</B ></A >, <A HREF="#function.next" ><B CLASS="function" >next()</B ></A > a <A HREF="#function.reset" ><B CLASS="function" >reset()</B ></A >. </P ></DIV ><H1 ><A NAME="function.range" ></A >range</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9078" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >range -- Vytvo°it pole obsahujφcφ rozsah integer∙</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9081" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >range</B > ( int low, int high)<BR ></BR ><P >
<B CLASS="function" >range()</B > vracφ pole integer∙ od <TT CLASS="parameter" ><I >low</I ></TT > po <TT CLASS="parameter" ><I >high</I ></TT > vΦetn∞. </P ><P >
Ukßzka pou╛itφ viz <A HREF="#function.shuffle" ><B CLASS="function" >shuffle()</B ></A >. </P ></DIV ><H1 ><A NAME="function.reset" ></A >reset</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9099" ></A ><P > (PHP 3, PHP 4 )</P >reset -- Nastavit internφ ukazatel pole na jeho prvnφ prvek</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9102" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >reset</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >reset()</B > p°etoΦφ internφ ukazatel pole <TT CLASS="parameter" ><I >array</I ></TT > na jeho prvnφ prvek. </P ><P >
<B CLASS="function" >reset()</B > vracφ hodnotu prvnφho prvku pole. </P ><P >
Viz takΘ: <A HREF="#function.current" ><B CLASS="function" >current()</B ></A >, <A HREF="#function.each" ><B CLASS="function" >each()</B ></A >, <A HREF="#function.next" ><B CLASS="function" >next()</B ></A > a <A HREF="#function.prev" ><B CLASS="function" >prev()</B ></A >. </P ></DIV ><H1 ><A NAME="function.rsort" ></A >rsort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9121" ></A ><P > (PHP 3, PHP 4 )</P >rsort -- T°φdit pole sestupn∞</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9124" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >rsort</B > ( array array [, int sort_flags])<BR ></BR ><P >
Tato funkce sestupn∞ t°φdφ pole. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9136" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >rsort()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$fruits = array ("lemon", "orange", "banana", "apple"); rsort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key -> $val\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka zobrazφ: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN9142" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >fruits[0] = orange fruits[1] = lemon fruits[2] = banana fruits[3] = apple</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Ovoce bylo set°φd∞no podle abecedy sestupn∞. </P ><P >
Vlastnosti t°φd∞nφ lze upravit pomocφ volitelnΘho argumentu <TT CLASS="parameter" ><I >sort_flags</I ></TT >, detaily viz <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >. </P ><P >
Viz takΘ: <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A >, <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A > a <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A >. </P ></DIV ><H1 ><A NAME="function.shuffle" ></A >shuffle</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9155" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >shuffle -- Zamφchat pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9158" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >shuffle</B > ( array array)<BR ></BR ><P >
<B CLASS="function" >shuffle()</B > zamφchß (nßhodn∞ zm∞nφ po°adφ prvk∙) pole. Musφte inicializovat generßtor nßhodn²ch Φφsel pomocφ <A HREF="#function.srand" ><B CLASS="function" >srand()</B ></A >. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9169" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >shuffle()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$numbers = range (1,20); srand ((double)microtime()*1000000); shuffle ($numbers); while (list (, $number) = each ($numbers)) { echo "$number "; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ: <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A >, <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >, <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A > a <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A >. </P ></DIV ><H1 ><A NAME="function.sizeof" ></A >sizeof</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9181" ></A ><P > (PHP 3, PHP 4 )</P >sizeof -- Zjistit poΦet prvk∙ v poli</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9184" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >sizeof</B > ( array array)<BR ></BR ><P >
Vracφ poΦet prvk∙ v poli. </P ><P >
Viz takΘ: <A HREF="#function.count" ><B CLASS="function" >count()</B ></A >. </P ></DIV ><H1 ><A NAME="function.sort" ></A >sort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9196" ></A ><P > (PHP 3, PHP 4 )</P >sort -- T°φdit pole</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9199" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >sort</B > ( array array [, int sort_flags])<BR ></BR ><P >
<B CLASS="function" >sort()</B > t°φdφ pole. Prvky se uspo°ßdajφ od nejmen╣φho k nejv∞t╣φmu. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9212" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >sort()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $fruits = array ("lemon", "orange", "banana", "apple"); sort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "fruits[".$key."] = ".$val; } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka zobrazφ: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN9218" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Ovoce bylo se°azeno podle abecedy. </P ><P >
Vlastnosti t°φd∞nφ lze upravit pomocφ volitelnΘho argumentu <TT CLASS="parameter" ><I >sort_flags</I ></TT >, kter² m∙╛e nab²vat t∞chto hodnot: </P ><P >
Typy t°φd∞nφ: <P ></P ><UL ><LI ><P >SORT_REGULAR - normßlnφ porovnßvßnφ</P ></LI ><LI ><P >SORT_NUMERIC - numerickΘ porovnßvßnφ</P ></LI ><LI ><P >SORT_STRING - textovΘ porovnßvßnφ</P ></LI ></UL > </P ><P >
Viz takΘ: <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A >, <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A >, <A HREF="#function.natcasesort" ><B CLASS="function" >natcasesort()</B ></A >, <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >, <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A >, <A HREF="#function.array-multisort" ><B CLASS="function" >array_multisort()</B ></A > a <A HREF="#function.uksort" ><B CLASS="function" >uksort()</B ></A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Druh² argument byl p°idßn v PHP 4. </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.uasort" ></A >uasort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9244" ></A ><P > (PHP 3>= 3.0.4, PHP 4 )</P >uasort -- T°φdit pole pomocφ u╛ivatelsky definovanΘ porovnßvacφ funkce se zachovßnφm klφΦ∙ </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9247" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >uasort</B > ( array array, function cmp_function)<BR ></BR ><P >
Tato funkce t°φdφ pole tak, ╛e si indexy uchovßvajφ spojenφ s hodnotami. To je u╛iteΦnΘ hlavn∞ p°i t°φd∞nφ asociativnφch polφ, kde je d∙le╛itΘ po°adφ prvk∙. Srovnßvacφ funkce je u╛ivatelsky definovßna. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Ukßzky u╛ivatelsky definovan²ch porovnßvacφch funkcφ viz <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A > a <A HREF="#function.uksort" ><B CLASS="function" >uksort()</B ></A >. </P ></BLOCKQUOTE ></DIV ><P >
Viz takΘ: <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A >, <A HREF="#function.uksort" ><B CLASS="function" >uksort()</B ></A >, <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >, <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A > a <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >. </P ></DIV ><H1 ><A NAME="function.uksort" ></A >uksort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9272" ></A ><P > (PHP 3>= 3.0.4, PHP 4 )</P >uksort -- T°φdit pole podle klφΦ∙ pomocφ u╛ivatelsky definovane porovnßvacφ funkce </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9275" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >uksort</B > ( array array, function cmp_function)<BR ></BR ><P >
Tato funkce t°φdφ pole podle klφΦ∙ pomocφ u╛ivatelsky definovanΘ porovnßvacφ funkce. Pokud pot°ebujete t°φdit pole podle komplikovan∞j╣φch kritΘriφ, m∞li byste pou╛φt tuto funkci. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9288" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >uksort()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function cmp ($a, $b) { if ($a == $b) return 0; return ($a > $b) ? -1 : 1; } $a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten"); uksort ($a, "cmp"); while (list ($key, $value) = each ($a)) { echo "$key: $value\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka zobrazφ: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN9294" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >20: twenty 10: ten 4: four 3: three</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Viz takΘ: <A HREF="#function.usort" ><B CLASS="function" >usort()</B ></A >, <A HREF="#function.uasort" ><B CLASS="function" >uasort()</B ></A >, <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >, <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A >, <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A > a <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >. </P ></DIV ><H1 ><A NAME="function.usort" ></A >usort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9306" ></A ><P > (PHP 3>= 3.0.3, PHP 4 )</P >usort -- T°φdit pole podle hodnot pomocφ u╛ivatelsky definovanΘ porovnßvacφ funkce </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9309" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >usort</B > ( array array, string cmp_function)<BR ></BR ><P >
Tato funkce t°φdφ pole podle hodnot pomocφ u╛ivatelsky definovanΘ porovnßvacφ funkce. Pokud pot°ebujete t°φdit pole podle komplikovan∞j╣φch kritΘriφ, m∞li byste pou╛φt tuto funkci. </P ><P >
Porovnßvacφ funkce musφ vrace integer men╣φ ne╛ 0, 0, a v∞t╣φ ne╛ 0, pokud je prvnφ argument men╣φ ne╛, stejn², nebo v∞t╣φ ne╛ druh² argument. Pokud jsou dv∞ porovnßvanΘ hodnoty stejnΘ, jejich po°adφ v t°φd∞nΘm poli je nedefinovßno. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9323" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >usort()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function cmp ($a, $b) { if ($a == $b) return 0; return ($a > $b) ? -1 : 1; } $a = array (3, 2, 5, 6, 1); usort ($a, "cmp"); while (list ($key, $value) = each ($a)) { echo "$key: $value\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Tato ukßzka zobrazφ: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN9329" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >0: 6 1: 5 2: 3 3: 2 4: 1</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > V tomto jednoduchΘm p°φpad∞ by pochopiteln∞ bylo vhodn∞j╣φ pou╛φt <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >. </P ></BLOCKQUOTE ></DIV ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9335" ></A ><P ><B >P°φklad 2. Ukßzka <B CLASS="function" >usort()</B > s vφcerozm∞rn²m polem </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function cmp ($a, $b) { return strcmp($a["fruit"],$b["fruit"]); } $fruits[0]["fruit"] = "lemons"; $fruits[1]["fruit"] = "apples"; $fruits[2]["fruit"] = "grapes"; usort($fruits, "cmp"); while (list ($key, $value) = each ($fruits)) { echo "\$fruits[$key]: " . $value["fruit"] . "\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
P°i t°φd∞nφ vφcerozm∞rnΘho pole $a a $b obsahujφ reference na prvnφ index pole. </P ><P >
Tato ukßzka zobrazφ: </P ><P >
<DIV CLASS="informalexample" ><A NAME="AEN9342" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >$fruits[0]: apples $fruits[1]: grapes $fruits[2]: lemons</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
Pou╛itß quicksort funkce v n∞kter²ch C knihovnßch (nap°. na systΘmech Solaris) m∙╛e zp∙sobit zhroucenφ PHP, pokud porovnßvacφ funkce nevracφ konsistentnφ hodnoty. </P ></TD ></TR ></TABLE ></DIV > </P ><P >
Viz takΘ: <A HREF="#function.uasort" ><B CLASS="function" >uasort()</B ></A >, <A HREF="#function.uksort" ><B CLASS="function" >uksort()</B ></A >, <A HREF="#function.sort" ><B CLASS="function" >sort()</B ></A >, <A HREF="#function.asort" ><B CLASS="function" >asort()</B ></A >, <A HREF="#function.arsort" ><B CLASS="function" >arsort()</B ></A >, <A HREF="#function.ksort" ><B CLASS="function" >ksort()</B ></A >, <A HREF="#function.natsort" ><B CLASS="function" >natsort()</B ></A > a <A HREF="#function.rsort" ><B CLASS="function" >rsort()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.aspell" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >III. Aspell funkce [zastaralΘ]</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN9359" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="aspell.intro" ></A >┌vod</H1 ><P >
<B CLASS="function" >aspell()</B > funkce umo╛≥ujφ ov∞°it hlßskovßnφ slova a nabφdnout mo╛nΘ opravy. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Toto roz╣φ°enφ bylo z PHP odebrßno a od PHP 4.3.0 nenφ k dispozici. Pokud chcete v PHP pou╛φt kontrolu hlßskovßnφ, pou╛ijte mφsto toho <A HREF="#ref.pspell" >pspell</A >. Vyu╛φvß pspell knihovnu, a pracuje s nov∞j╣φmi verzemi aspellu. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="aspell.requirements" ></A >Po╛adavky</H1 ><P >
Roz╣φ°enφ aspell funguje pouze s velmi star²mi (do p°ibli╛n∞ .27.*) verzemi aspell knihovny. Tento modul, ani tyto verze aspell knihovny u╛ nejsou podporovßny. Budete pot°ebovat knihovnu aspell dostupnou na: <A HREF="http://aspell.sourceforge.net/" TARGET="_top" >http://aspell.sourceforge.net/</A >. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="aspell.installation" ></A >Instalace</H1 ><P >
In PHP 4, these functions are only available if <TT CLASS="literal" >PHP</TT > was configured with <TT CLASS="option" >--with-aspell=[DIR]</TT >. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="aspell.seealso" ></A >Viz takΘ</H1 ><P >
Viz takΘ <A HREF="#ref.pspell" >pspell</A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.aspell-check-raw" >aspell_check_raw</A > -- Zkontrolovat slovo beze zm∞ny velikosti pφsmen nebo pokus∙ o o°ezßnφ </DT ><DT ><A HREF="#function.aspell-check" >aspell_check</A > -- Zkontrolovat slovo</DT ><DT ><A HREF="#function.aspell-new" >aspell_new</A > -- NaΦφst nov² slovnφk</DT ><DT ><A HREF="#function.aspell-suggest" >aspell_suggest</A > -- Nabφdnout mo╛nΘ hlßskovßnφ slova</DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.aspell-check-raw" ></A >aspell_check_raw</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9381" ></A ><P > (PHP 3>= 3.0.7, PHP 4 <= 4.2.3)</P >aspell_check_raw -- Zkontrolovat slovo beze zm∞ny velikosti pφsmen nebo pokus∙ o o°ezßnφ </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9384" ></A ><H2 >Popis</H2 >boolean <B CLASS="methodname" >aspell_check_raw</B > ( int dictionary_link, string word)<BR ></BR ><P >
<B CLASS="function" >aspell_check_raw()</B > zkontroluje hlßskovßnφ slova beze zm∞n velikosti pφsmen nebo pokus∙ ho jak²mkoliv zp∙sobem o°ezat, a vrßtφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud je hlßskovßnφ sprßvnΘ, a <TT CLASS="constant" ><B >FALSE</B ></TT >, pokud nenφ. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9400" ></A ><P ><B >P°φklad 1. <B CLASS="function" >aspell_check_raw()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$aspell_link=aspell_new ("english"); if (aspell_check_raw ($aspell_link, "test")) { echo "Toto je platnΘ hlßskovßnφ"; } else { echo "Pardon, ╣patnΘ hlßskovßnφ"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.aspell-check" ></A >aspell_check</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9405" ></A ><P > (PHP 3>= 3.0.7, PHP 4 <= 4.2.3)</P >aspell_check -- Zkontrolovat slovo</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9408" ></A ><H2 >Popis</H2 >boolean <B CLASS="methodname" >aspell_check</B > ( int dictionary_link, string word)<BR ></BR ><P >
<B CLASS="function" >aspell_check()</B > zkontroluje hlßskovßnφ slova a vrßtφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud je hlßskovßnφ sprßvnΘ, a <TT CLASS="constant" ><B >FALSE</B ></TT >, pokud nenφ. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9424" ></A ><P ><B >P°φklad 1. <B CLASS="function" >aspell_check()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >$aspell_link=aspell_new ("english"); if (aspell_check ($aspell_link, "testt")) { echo "Toto je platnΘ hlßskovßnφ"; } else { echo "Pardon, ╣patnΘ hlßskovßnφ"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.aspell-new" ></A >aspell_new</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9429" ></A ><P > (PHP 3>= 3.0.7, PHP 4 <= 4.2.3)</P >aspell_new -- NaΦφst nov² slovnφk</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9432" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >aspell_new</B > ( string master, string personal)<BR ></BR ><P >
<B CLASS="function" >aspell_new()</B > otev°e nov² slovnφk, a vrßtφ identifikßtor spojenφ na tento slovnφk vyu╛iteln² s dal╣φmi aspell funkcemi. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9446" ></A ><P ><B >P°φklad 1. <B CLASS="function" >aspell_new()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$aspell_link=aspell_new ("english");</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.aspell-suggest" ></A >aspell_suggest</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9451" ></A ><P > (PHP 3>= 3.0.7, PHP 4 <= 4.2.3)</P >aspell_suggest -- Nabφdnout mo╛nΘ hlßskovßnφ slova</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9454" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >aspell_suggest</B > ( int dictionary_link, string word)<BR ></BR ><P >
<B CLASS="function" >aspell_suggest()</B > vrßtφ pole mo╛n²ch hlßskovßnφ danΘho slova. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9468" ></A ><P ><B >P°φklad 1. <B CLASS="function" >aspell_suggest()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$aspell_link=aspell_new ("english"); if (!aspell_check ($aspell_link, "test")) { $suggestions=aspell_suggest ($aspell_link, "test"); for ($i=0; $i < count ($suggestions); $i++) { echo "Mo╛nΘ hlßskovßnφ: " . $suggestions[$i] . "<br>"; } }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.bc" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >IV. BCMath funkce pro v²poΦty s libovolnou p°esnostφ</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN9475" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="bc.intro" ></A >┌vod</H1 ><P >
Pro prßci s Φφsly libovolnΘ p°esnosti PHP nabφzφ Binary Calculator, kter² podporuje Φφsla libovoln∞ velkß a s libovolnou p°esnostφ, kterß jsou reprezentovßna jako °et∞zce. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bc.requirements" ></A >Po╛adavky</H1 ><P >
Od PHP 4.0.4 je knihovna libbcmath dodßvßna s PHP. Pro toto roz╣φ°enφ tedy nepot°ebujete ╛ßdnΘ externφ knihovny. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bc.installation" ></A >Instalace</H1 ><P >
Tyto funkce jsou v PHP 4 dostupnΘ pouze pokud bylo PHP zkonfigurovßno s volbou <TT CLASS="option" >--enable-bcmath</TT >. V PHP 3 jsou dostupnΘ, pokud nebylo zkonfigurovßno s volbou <TT CLASS="option" >--disable-bcmath</TT >. </P ><P >Verze <TT CLASS="literal" >PHP</TT > pro Windows mß vestav∞nou podporu pro toto roz╣φ°enφ. K pou╛itφ t∞chto funkcφ nenφ t°eba naΦφtat ╛ßdnß dal╣φ roz╣φ°enφ.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bc.configuration" ></A >Konfigurace b∞hu</H1 ><P >
Chovßnφ t∞chto funkcφ je ovlivn∞no nastavenφm parametr∙ v <TT CLASS="filename" >php.ini</TT >. </P ><P >
<DIV CLASS="table" ><A NAME="AEN9494" ></A ><P ><B >Tabulka 1. BC math configuration options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >bcmath.scale</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >0</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ></TBODY ></TABLE ></DIV > For further details and definition of the PHP_INI_* constants see <A HREF="#function.ini-set" ><B CLASS="function" >ini_set()</B ></A >. </P ><P >Zde je struΦnΘ vysv∞tlenφ konfiguraΦnφch direktiv.</P ><P >
<P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.bcmath.scale" ></A ><TT CLASS="parameter" ><I >bcmath.scale</I ></TT > <A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P >
Number of decimal digits for all bcmath functions. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bc.resources" ></A >Typy prost°edk∙</H1 ><P >Toto roz╣φ°enφ nemß definovßn ╛ßdn² typ prost°edku (resource).</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bc.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >Toto roz╣φ°enφ nemß definovßny ╛ßdnΘ konstanty.</P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.bcadd" >bcadd</A > -- SeΦφst dv∞ Φφsla s libovolnou p°esnostφ</DT ><DT ><A HREF="#function.bccomp" >bccomp</A > -- Porovnat dv∞ Φφsla s libovolnou p°esnostφ</DT ><DT ><A HREF="#function.bcdiv" >bcdiv</A > -- D∞lit dv∞ Φφsla s libovolnou p°esnostφ</DT ><DT ><A HREF="#function.bcmod" >bcmod</A > -- Zφskat modulus Φφsla s libovolnou p°esnostφ</DT ><DT ><A HREF="#function.bcmul" >bcmul</A > -- Vynßsobit dv∞ Φφsla s libovolnou p°esnostφ</DT ><DT ><A HREF="#function.bcpow" >bcpow</A > -- Umocnit jedno Φφslo na jinΘ s libovolnou p°esnostφ </DT ><DT ><A HREF="#function.bcpowmod" >bcpowmod</A > -- Raise an arbitrary precision number to another, reduced by a specified modulus. </DT ><DT ><A HREF="#function.bcscale" >bcscale</A > -- Nastavit v²chozφ ╣kßlu pro v╣echny bc math funkce </DT ><DT ><A HREF="#function.bcsqrt" >bcsqrt</A > -- Zφskat druhou odmocninu Φφsla s libovolnou p°esnostφ </DT ><DT ><A HREF="#function.bcsub" >bcsub</A > -- OdeΦφst jedno Φφslo od druhΘho s libovolnou p°esnostφ </DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.bcadd" ></A >bcadd</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9524" ></A ><P > (PHP 3, PHP 4 )</P >bcadd -- SeΦφst dv∞ Φφsla s libovolnou p°esnostφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9527" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcadd</B > ( string left operand, string right operand [, int scale])<BR ></BR ><P >
P°iΦte <TT CLASS="parameter" ><I >left operand</I ></TT > k <TT CLASS="parameter" ><I >right operand</I ></TT > a vrßtφ souΦet v °et∞zci. Voliteln² argument <TT CLASS="parameter" ><I >scale</I ></TT > se pou╛φvß k urΦenφ poΦtu desetinn²ch mφst ve v²sledku. </P ><P >
Viz takΘ <A HREF="#function.bcsub" ><B CLASS="function" >bcsub()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bccomp" ></A >bccomp</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9548" ></A ><P > (PHP 3, PHP 4 )</P >bccomp -- Porovnat dv∞ Φφsla s libovolnou p°esnostφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9551" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >bccomp</B > ( string left operand, string right operand [, int scale])<BR ></BR ><P >
Porovnß <TT CLASS="parameter" ><I >left operand</I ></TT > s <TT CLASS="parameter" ><I >right operand</I ></TT > a vrßtφ v²sledek jako integer. Voliteln² argument <TT CLASS="parameter" ><I >scale</I ></TT > se pou╛φvß k urΦenφ poΦtu desetinn²ch mφst pou╛it²ch p°i porovnßnφ. Nßvratovß hodnota je 0, pokud jsou si oba operandy rovnΘ. Pokud je <TT CLASS="parameter" ><I >left operand</I ></TT > v∞t╣φ ne╛ <TT CLASS="parameter" ><I >right operand</I ></TT >, nßvratovß hodnota je +1, a pokud je <TT CLASS="parameter" ><I >left operand</I ></TT > men╣φ ne╛ <TT CLASS="parameter" ><I >right operand</I ></TT >, nßvratovß hodnota je -1. </P ></DIV ><H1 ><A NAME="function.bcdiv" ></A >bcdiv</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9574" ></A ><P > (PHP 3, PHP 4 )</P >bcdiv -- D∞lit dv∞ Φφsla s libovolnou p°esnostφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9577" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcdiv</B > ( string left operand, string right operand [, int scale])<BR ></BR ><P >
Vyd∞lφ argument <TT CLASS="parameter" ><I >left operand</I ></TT > argumentem <TT CLASS="parameter" ><I >right operand</I ></TT > a vrßtφ v²sledek. Voliteln² argument <TT CLASS="parameter" ><I >scale</I ></TT > se pou╛φvß k urΦenφ poΦtu desetinn²ch mφst ve v²sledku. </P ><P >
Viz takΘ <A HREF="#function.bcmul" ><B CLASS="function" >bcmul()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bcmod" ></A >bcmod</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9598" ></A ><P > (PHP 3, PHP 4 )</P >bcmod -- Zφskat modulus Φφsla s libovolnou p°esnostφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9601" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcmod</B > ( string left operand, string modulus)<BR ></BR ><P >
Vrßtφ modulus argumentu <TT CLASS="parameter" ><I >left operand</I ></TT > s pou╛itφm argumentu <TT CLASS="parameter" ><I >modulus</I ></TT >. </P ><P >
Viz takΘ <A HREF="#function.bcdiv" ><B CLASS="function" >bcdiv()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bcmul" ></A >bcmul</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9618" ></A ><P > (PHP 3, PHP 4 )</P >bcmul -- Vynßsobit dv∞ Φφsla s libovolnou p°esnostφ</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9621" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcmul</B > ( string left operand, string right operand [, int scale])<BR ></BR ><P >
Vynßsobφ argument <TT CLASS="parameter" ><I >left operand</I ></TT > argumentem <TT CLASS="parameter" ><I >right operand</I ></TT > a vrßtφ v²sledek. Voliteln² argument <TT CLASS="parameter" ><I >scale</I ></TT > se pou╛φvß k urΦenφ poΦtu desetinn²ch mφst ve v²sledku. </P ><P >
Viz takΘ <A HREF="#function.bcdiv" ><B CLASS="function" >bcdiv()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bcpow" ></A >bcpow</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9642" ></A ><P > (PHP 3, PHP 4 )</P >bcpow -- Umocnit jedno Φφslo na jinΘ s libovolnou p°esnostφ </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9645" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcpow</B > ( string x, string y [, int scale])<BR ></BR ><P >
Umocnφ <TT CLASS="parameter" ><I >x</I ></TT > na <TT CLASS="parameter" ><I >y</I ></TT >. Voliteln² argument <TT CLASS="parameter" ><I >scale</I ></TT > se pou╛φvß k urΦenφ poΦtu desetinn²ch mφst ve v²sledku. </P ><P >
Viz takΘ <A HREF="#function.bcsqrt" ><B CLASS="function" >bcsqrt()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bcpowmod" ></A >bcpowmod</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9666" ></A ><P > (PHP 5 CVS only)</P >bcpowmod -- Raise an arbitrary precision number to another, reduced by a specified modulus. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9669" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >bcpowmod</B > ( string x, string y, string modulus [, int scale])<BR ></BR ><P >
Use the fast-exponentiation method to raise <TT CLASS="parameter" ><I >x</I ></TT > to the power <TT CLASS="parameter" ><I >y</I ></TT > with respect to the modulus <TT CLASS="parameter" ><I >modulus</I ></TT >. The optional <TT CLASS="parameter" ><I >scale</I ></TT > can be used to set the number of digits after the decimal place in the result. </P ><P >
The following two statements are functionally identical. The <B CLASS="function" >bcpowmod()</B > version however, executes in less time and can accept larger parameters. <DIV CLASS="informalexample" ><A NAME="AEN9693" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $a = bcpowmod($x, $y, $mod); $b = bcmod(bcpow($x, $y), $mod); // $a and $b are equal to each other. ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Because this method uses the modulus operation, non-natural numbers may give unexpected results. A natural number is any positive non-zero integer. </P ></BLOCKQUOTE ></DIV > </P ><P >
See also <A HREF="#function.bcpow" ><B CLASS="function" >bcpow()</B ></A >, and <A HREF="#function.bcmod" ><B CLASS="function" >bcmod()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bcscale" ></A >bcscale</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9702" ></A ><P > (PHP 3, PHP 4 )</P >bcscale -- Nastavit v²chozφ ╣kßlu pro v╣echny bc math funkce </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9705" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcscale</B > ( int scale)<BR ></BR ><P >
Tato funkce nastavφ v²chozφ ╣kßlu pro v╣echna nßslednß volßnφ bc math funkcφ, ktera neudßvajφ explicitn∞ ╣kßlu p°esnosti. </P ></DIV ><H1 ><A NAME="function.bcsqrt" ></A >bcsqrt</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9715" ></A ><P > (PHP 3, PHP 4 )</P >bcsqrt -- Zφskat druhou odmocninu Φφsla s libovolnou p°esnostφ </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9718" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcsqrt</B > ( string operand, int scale)<BR ></BR ><P >
Vrßtφ druhou odmocninu argumentu <TT CLASS="parameter" ><I >operand</I ></TT >. Voliteln² argument <TT CLASS="parameter" ><I >scale</I ></TT > se pou╛φvß k urΦenφ poΦtu desetinn²ch mφst ve v²sledku. </P ><P >
Viz takΘ <A HREF="#function.bcpow" ><B CLASS="function" >bcpow()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bcsub" ></A >bcsub</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9735" ></A ><P > (PHP 3, PHP 4 )</P >bcsub -- OdeΦφst jedno Φφslo od druhΘho s libovolnou p°esnostφ </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9738" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bcsub</B > ( string left operand, string right operand [, int scale])<BR ></BR ><P >
OdeΦte argument <TT CLASS="parameter" ><I >right operand</I ></TT > od argumentu <TT CLASS="parameter" ><I >left operand</I ></TT > a vrßtφ v²sledek v °et∞zci. Voliteln² argument <TT CLASS="parameter" ><I >scale</I ></TT > se pou╛φvß k urΦenφ poΦtu desetinn²ch mφst ve v²sledku. </P ><P >
Viz takΘ <A HREF="#function.bcadd" ><B CLASS="function" >bcadd()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.bzip2" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >V. Kompresnφ funkce bzip2</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN9761" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="bzip2.intro" ></A >┌vod</H1 ><P >
Funkce bzip2 se pou╛φvajφ k transparentnφmu Φtenφ a zßpisu soubor∙ komprimovan²ch algoritmem bzip2 (.bz2). </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bzip2.requirements" ></A >Po╛adavky</H1 ><P >
Tento modul pou╛φvß funkce z knihovny <A HREF="http://sources.redhat.com/bzip2/" TARGET="_top" >bzip2</A > od Juliana Sewarda. Tento modul vy╛aduje bzip2/libbzip2 verze >= 1.0.x. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bzip2.installation" ></A >Instalace</H1 ><P >
Podpora bzip2 nenφ v PHP implicitn∞ k dispozici. K aktivaci budete muset p°i kompilaci PHP pou╛φt konfiguraΦnφ volbu <TT CLASS="option" >--with-bz2[=DIR]</TT >. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bzip2.configuration" ></A >Konfigurace b∞hu</H1 ><P >Toto roz╣φ°enφ nemß definovßno ╛ßdnΘ konfiguraΦnφ direktivy.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bzip2.resources" ></A >Typy prost°edk∙</H1 ><P >
Toto roz╣φ°enφ definuje jeden typ prost°edku: souborov² ukazatel identifikujφcφ soubor bz2, nad kter²m se pracuje. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bzip2.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >Toto roz╣φ°enφ nemß definovßny ╛ßdnΘ konstanty.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="bzip2.examples" ></A >P°φklady</H1 ><P >
Tento p°φklad otev°e doΦasn² soubor a zapφ╣e do n∞j testovacφ °etezec; potom vypφ╣e obsah souboru. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9785" ></A ><P ><B >P°φklad 1. Mal² p°φklad na bzip2</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $filename = "/tmp/testfile.bz2"; $str = "Toto je testovacφ °et∞zec.\n"; // otev°i soubor pro zßpis $bz = bzopen($filename, "w"); // zapo╣ °et∞zec do souboru bzwrite($bz, $str); // zav°i soubor bzclose($bz); // otev°i soubor pro Φtenφ $bz = bzopen($filename, "r"); // p°eΦti 10 znak∙ print bzread($bz, 10); // tiskni dokud nenφ konec souboru (nebo nßsledujφcφ 1024. znak) a zav°i soubor print bzread($bz); bzclose($bz); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.bzclose" >bzclose</A > -- Zav°e ukazatel na soubor bzip2</DT ><DT ><A HREF="#function.bzcompress" >bzcompress</A > -- Zkomprimuje °et∞zec algoritmem bzip2</DT ><DT ><A HREF="#function.bzdecompress" >bzdecompress</A > -- Dekomprimuje data komprimovanß pomocφ bzip2</DT ><DT ><A HREF="#function.bzerrno" >bzerrno</A > -- Vracφ Φφslo chyby bzip2</DT ><DT ><A HREF="#function.bzerror" >bzerror</A > -- Vracφ v poli Φφslo a popis chyby bzip2</DT ><DT ><A HREF="#function.bzerrstr" >bzerrstr</A > -- Vracφ popis chyby bzip2</DT ><DT ><A HREF="#function.bzflush" >bzflush</A > -- Vynutφ zßpis v╣ech bufferovan²ch dat</DT ><DT ><A HREF="#function.bzopen" >bzopen</A > -- Otev°e soubor komprimovan² pomocφ bzip2</DT ><DT ><A HREF="#function.bzread" >bzread</A > -- Binßrn∞ bezpeΦnΘ Φtenφ ze souboru bzip2</DT ><DT ><A HREF="#function.bzwrite" >bzwrite</A > -- Binßrn∞ bezpeΦn² zßpis do souboru bzip2</DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.bzclose" ></A >bzclose</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9789" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzclose -- Zav°e ukazatel na soubor bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9792" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >bzclose</B > ( resource bz)<BR ></BR ><P >
Zav°e soubor bzip2 odkazovan² ukazatelem <TT CLASS="parameter" ><I >bz</I ></TT >. </P ><P >
Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
Ukazatel na soubor musφ b²t platn² a musφ ukazovat na soubor ·sp∞╣n∞ otev°en² pomocφ <A HREF="#function.bzopen" ><B CLASS="function" >bzopen()</B ></A >. </P ><P >
Viz takΘ <A HREF="#function.bzopen" ><B CLASS="function" >bzopen()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzcompress" ></A >bzcompress</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9810" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzcompress -- Zkomprimuje °et∞zec algoritmem bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9813" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bzcompress</B > ( string source [, int blocksize [, int workfactor]])<BR ></BR ><P >
<B CLASS="function" >bzcompress()</B > komprimuje °et∞zec <TT CLASS="parameter" ><I >source</I ></TT > a vracφ ho ve form∞ dat zφskan²ch pomocφ algoritmu bzip2. </P ><P >
Nepovinn² parametr <TT CLASS="parameter" ><I >blocksize</I ></TT > specifikuje velikost bloku pou╛itou p°i komprimaci; m∞lo by to b²t Φφslo od 1 do 9, kde 9 znamenß nej·Φinn∞j╣φ kompresi, ale s v∞t╣φmi nßroky na pot°ebnΘ prost°edky. Implicitnφ hodnota <TT CLASS="parameter" ><I >blocksize</I ></TT > je 4. </P ><P >
Nepovinn² parametr <TT CLASS="parameter" ><I >workfactor</I ></TT > urΦuje, jak se kompresnφ mechanismus chovß v p°φpad∞ nejhor╣φch, velmi se opakujφcφch, vstupnßch dat. M∙╛e nab²vat hodnot mezi 0 a 250; 0 p°edstavuje specißlnφ p°φpad, 30 je implicitnφ hodnota. Generovan² v²stup je bez ohledu na <TT CLASS="parameter" ><I >workfactor</I ></TT > v╛dy stejn². </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9837" ></A ><P ><B >P°φklad 1. <B CLASS="function" >bzcompress()</B > P°φklad</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $str = "zku╣ebnφ data"; $bzstr = bzcompress($str, 9); echo $bzstr; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ <A HREF="#function.bzdecompress" ><B CLASS="function" >bzdecompress()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzdecompress" ></A >bzdecompress</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9844" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzdecompress -- Dekomprimuje data komprimovanß pomocφ bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9847" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bzdecompress</B > ( string source [, int small])<BR ></BR ><P >
<B CLASS="function" >bzdecompress()</B > dekomprimuje °et∞zec <TT CLASS="parameter" ><I >source</I ></TT > obsahujφcφ data komprimovanß pomocφ algoritmu bzip2, a vracφ je. Pokud mß nepovinn² parametr <TT CLASS="parameter" ><I >small</I ></TT > hodnotu <TT CLASS="constant" ><B >TRUE</B ></TT >, pou╛ije se alternativnφ dekompresnφ algoritmus s ni╛╣φmi nßroky na pam∞╗ (maximßlnφ pam∞tovΘ po╛adavky klesnou na cca 2300 KB), ale zhruba poloviΦnφ rychlostφ. Vφce informacφ najdete v <A HREF="http://sources.redhat.com/bzip2/" TARGET="_top" >dokumentaci k bzip2</A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9865" ></A ><P ><B >P°φklad 1. <B CLASS="function" >bzdecompress()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $start_str = "Tohle nenφ up°φmn² obliΦej?"; $bzstr = bzcompress($start_str); echo "Komprimovan² °et∞zec: "; echo $bzstr; echo "\n<br>\n"; $str = bzdecompress($bzstr); echo "Dekomprimovan² °etezec: "; echo $str; echo "\n<br>\n"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ <A HREF="#function.bzcompress" ><B CLASS="function" >bzcompress()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzerrno" ></A >bzerrno</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9872" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzerrno -- Vracφ Φφslo chyby bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9875" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >bzerrno</B > ( resource bz)<BR ></BR ><P >
Vracφ chybovΘ Φφslo jakΘkoli chyby bzip2 podle souborovΘho ukazatele <TT CLASS="parameter" ><I >bz</I ></TT >. </P ><P >
Vuz takΘ <A HREF="#function.bzerror" ><B CLASS="function" >bzerror()</B ></A > a <A HREF="#function.bzerrstr" ><B CLASS="function" >bzerrstr()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzerror" ></A >bzerror</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9889" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzerror -- Vracφ v poli Φφslo a popis chyby bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9892" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >bzerror</B > ( resource bz)<BR ></BR ><P >
Vracφ Φφslo chyby a chybov² °et∞zec (popis) v asociativnφm poli pro jakoukoli chybu bzip2 podle souborovΘho ukazatele <TT CLASS="parameter" ><I >bz</I ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9903" ></A ><P ><B >P°φklad 1. P°φklad - <B CLASS="function" >bzerror()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $error = bzerror($bz); echo $error["errno"]; echo $error["errstr"]; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ <A HREF="#function.bzerrno" ><B CLASS="function" >bzerrno()</B ></A > a <A HREF="#function.bzerrstr" ><B CLASS="function" >bzerrstr()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzerrstr" ></A >bzerrstr</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9911" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzerrstr -- Vracφ popis chyby bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9914" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bzerrstr</B > ( resource bz)<BR ></BR ><P >
Vracφ chybov² °et∞zec (popis) pro jakoukoli chybu bzip2 podle souborovΘho ukazatele <TT CLASS="parameter" ><I >bz</I ></TT >. </P ><P >
Viz takΘ <A HREF="#function.bzerrno" ><B CLASS="function" >bzerrno()</B ></A > a <A HREF="#function.bzerror" ><B CLASS="function" >bzerror()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzflush" ></A >bzflush</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9928" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzflush -- Vynutφ zßpis v╣ech bufferovan²ch dat</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9931" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >bzflush</B > ( resource bz)<BR ></BR ><P >
Vynutφ zßpis v╣ech bufferovan²ch dat pro souborov² ukazatel <TT CLASS="parameter" ><I >bz</I ></TT >. </P ><P >
Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
Viz takΘ <A HREF="#function.bzread" ><B CLASS="function" >bzread()</B ></A > a <A HREF="#function.bzwrite" ><B CLASS="function" >bzwrite()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzopen" ></A >bzopen</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9948" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzopen -- Otev°e soubor komprimovan² pomocφ bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9951" ></A ><H2 >Popis</H2 >resource <B CLASS="methodname" >bzopen</B > ( string filename, string mode)<BR ></BR ><P >
Otev°e soubor bzip2 (.bz2) pro Φtenφ nebo zßpis. <TT CLASS="parameter" ><I >filename</I ></TT > je nßzev otvφranΘho souboru. Parametr <TT CLASS="parameter" ><I >mode</I ></TT > mß podobn² v²znam jako u funkce <A HREF="#function.fopen" ><B CLASS="function" >fopen()</B ></A > (`r' pro Φtenφ, `w' pro zßpis atd.). </P ><P >
Pokud otvφrßnφ sel╛e, vracφ funkce <TT CLASS="constant" ><B >FALSE</B ></TT >, jinak vracφ ukazatel (deskriptor) na nov∞ otev°en² soubor. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9969" ></A ><P ><B >P°φklad 1. P°φklad - <B CLASS="function" >bzopen()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $bz = bzopen("/tmp/foo.bz2", "r"); $decompressed_file = ''; while (!feof($bz)) { $decompressed_file .= bzread($bz, 4096); } bzclose($bz); echo "Obsah souboru /tmp/foo.bz2 je: "; echo "\n<br>\n"; echo $decompressed_file; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ <A HREF="#function.bzclose" ><B CLASS="function" >bzclose()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzread" ></A >bzread</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9976" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzread -- Binßrn∞ bezpeΦnΘ Φtenφ ze souboru bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN9979" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >bzread</B > ( resource bz [, int length])<BR ></BR ><P >
<B CLASS="function" >bzread()</B > p°eΦte nejv²╣e <TT CLASS="parameter" ><I >length</I ></TT > byt∙ z bzip2 souboru odkazovanΘho pomocφ <TT CLASS="parameter" ><I >bz</I ></TT >. ╚tenφ konΦφ, je-li p°eΦteno <TT CLASS="parameter" ><I >length</I ></TT > (nekomprimovan²ch) byt∙ nebo se dosßhne konce souboru - podle toho, co nastane d°φv. Nenφ-li specifikovßn nepovinn² parametr <TT CLASS="parameter" ><I >length</I ></TT >, funkce <B CLASS="function" >bzread()</B > p°eΦte najednou 1024 (nekomprimovan²ch) byt∙. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9998" ></A ><P ><B >P°φklad 1. P°φklad - <B CLASS="function" >bzread()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $bz = bzopen("/tmp/foo.bz2", "r"); $str = bzread($bz, 2048); echo $str; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ <A HREF="#function.bzwrite" ><B CLASS="function" >bzwrite()</B ></A > a <A HREF="#function.bzopen" ><B CLASS="function" >bzopen()</B ></A >. </P ></DIV ><H1 ><A NAME="function.bzwrite" ></A >bzwrite</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10006" ></A ><P > (4.0.4 - 4.3.2 only)</P >bzwrite -- Binßrn∞ bezpeΦn² zßpis do souboru bzip2</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10009" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >bzwrite</B > ( resource bz, string data [, int length])<BR ></BR ><P >
<B CLASS="function" >bzwrite()</B > zapφ╣e obsah °et∞zce <TT CLASS="parameter" ><I >data</I ></TT > do souboru bzip2 odkazovanΘho pomocφ <TT CLASS="parameter" ><I >bz</I ></TT >. Je-li p°φtomen nepovinn² parametr <TT CLASS="parameter" ><I >length</I ></TT >, zßpis skonΦφ potΘ, co bude zapsßno <TT CLASS="parameter" ><I >length</I ></TT > (nekomprimovan²ch) byt∙ nebo bude dosa╛eno konce °et∞zce - podle toho, co nastane d°φv. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN10030" ></A ><P ><B >P°φklad 1. P°φklad <B CLASS="function" >bzwrite()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $str = "nekomprimovanß data"; $bz = bzopen("/tmp/foo.bz2", "w"); bzwrite($bz, $str, strlen($str)); bzclose($bz); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ <A HREF="#function.bzread" ><B CLASS="function" >bzread()</B ></A > a <A HREF="#function.bzopen" ><B CLASS="function" >bzopen()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.calendar" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >VI. Kalendß°ovΘ funkce</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN10040" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="calendar.intro" ></A >┌vod</H1 ><P >
Toto roz╣φ°enφ p°edstavuje sadu funkcφ urΦen²ch ke zjednodu╣enφ p°evod∙ mezi r∙zn²mi kalendß°i. Prost°ednφkem nebo standardem, na kterΘm je zalo╛ena, je Julian Day Count. To je poΦet dnφ zaΦφnajφcφ daleko p°ed jak²mkoli datem o kterΘ by se v∞t╣ina lidφ zajφmala (n∞kde kolem 4000 p°. n. l.). Pokud chcete p°evßd∞t mezi kalendß°ov²mi systΘmy, musφte nejd°φv p°evΘst na Julian Day Count, potom na k²╛en² kalendß°. Julian Day Count se velmi li╣φ od JulißnskΘho kaledß°e! Pro vφce informacφ o Julian Day Count viz <A HREF="http://www.hermetic.ch/cal_stud/jdn.htm" TARGET="_top" >http://www.hermetic.ch/cal_stud/jdn.htm</A >. Pro vφce informacφ o kalendß°ov²ch systΘmech viz <A HREF="http://www.boogle.com/info/cal-overview.html" TARGET="_top" >http://www.boogle.com/info/cal-overview.html</A >. Tyto instrukce obsahujφ v²≥atky z tΘto strßnky (v uvozovkßch). </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="calendar.installation" ></A >Instalace</H1 ><P >
Pro prßci tohoto roz╣φ°enφ musφte PHP zkompilovat s volbou <TT CLASS="option" >--enable-calendar</TT >. </P ><P >Verze <TT CLASS="literal" >PHP</TT > pro Windows mß vestav∞nou podporu pro toto roz╣φ°enφ. K pou╛itφ t∞chto funkcφ nenφ t°eba naΦφtat ╛ßdnß dal╣φ roz╣φ°enφ.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="calendar.configuration" ></A >Konfigurace b∞hu</H1 ><P >Toto roz╣φ°enφ nemß definovßno ╛ßdnΘ konfiguraΦnφ direktivy.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="calendar.resources" ></A >Typy prost°edk∙</H1 ><P >Toto roz╣φ°enφ nemß definovßn ╛ßdn² typ prost°edku (resource).</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="calendar.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >
Tyto konstanty jsou definovßny tφmto roz╣φ°enφm a budou k dispozici pouze tehdy, bylo-li roz╣φ°enφ zkompilovßno spoleΦn∞ s PHP nebo dynamicky zavedeno za b∞hu. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CAL_GREGORIAN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_JULIAN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_JEWISH</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_FRENCH</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_NUM_CALS</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_DOW_DAYNO</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_DOW_SHORT</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_DOW_LONG</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_MONTH_GREGORIAN_SHORT</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_MONTH_GREGORIAN_LONG</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_MONTH_JULIAN_SHORT</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_MONTH_JULIAN_LONG</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_MONTH_JEWISH</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_MONTH_FRENCH</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ></DL ></DIV ><P >
The following constants are available since <TT CLASS="literal" >PHP</TT > 4.3.0 : </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CAL_EASTER_DEFAULT</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_EASTER_ROMAN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_EASTER_ALWAYS_GREGORIAN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_EASTER_ALWAYS_JULIAN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ></DL ></DIV ><P >
The following constants are available since <TT CLASS="literal" >PHP</TT > 5.0.0 : </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CAL_JEWISH_ADD_ALAFIM_GERESH</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_JEWISH_ADD_ALAFIM</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CAL_JEWISH_ADD_GERESHAYIM</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ></DL ></DIV ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.cal-days-in-month" >cal_days_in_month</A > -- Return the number of days in a month for a given year and calendar</DT ><DT ><A HREF="#function.cal-from-jd" >cal_from_jd</A > -- Converts from Julian Day Count to a supported calendar</DT ><DT ><A HREF="#function.cal-info" >cal_info</A > -- Returns information about a particular calendar</DT ><DT ><A HREF="#function.cal-to-jd" >cal_to_jd</A > -- Converts from a supported calendar to Julian Day Count</DT ><DT ><A HREF="#function.easter-date" >easter_date</A > -- Zjistit UNIXov² timestamp VelikonoΦnφ p∙lnoci v danΘm roce </DT ><DT ><A HREF="#function.easter-days" >easter_days</A > -- Get number of days after March 21 on which Easter falls for a given year </DT ><DT ><A HREF="#function.frenchtojd" >FrenchToJD</A > -- P°evΘst datum z FrancouzskΘho republikßnskΘho kalendß°e na Julian Day Count </DT ><DT ><A HREF="#function.gregoriantojd" >GregorianToJD</A > -- P°evΘst GregorißnskΘ datum na Julian Day Count</DT ><DT ><A HREF="#function.jddayofweek" >JDDayOfWeek</A > -- Vrßtit den v t²dnu</DT ><DT ><A HREF="#function.jdmonthname" >JDMonthName</A > -- Vrßtit nßzev m∞sφce</DT ><DT ><A HREF="#function.jdtofrench" >JDToFrench</A > -- P°evΘst Julian Day Count na Francouzsk² republikßnsk² kalendß° </DT ><DT ><A HREF="#function.jdtogregorian" >JDToGregorian</A > -- P°evΘst Julian Day Count na GregorißnskΘ datum</DT ><DT ><A HREF="#function.jdtojewish" >JDToJewish</A > -- P°evΘst Julian Day Count na idovsk² kalendß° </DT ><DT ><A HREF="#function.jdtojulian" >JDToJulian</A > -- P°evΘst Julian Day Count na JulißnskΘ datum </DT ><DT ><A HREF="#function.jdtounix" >jdtounix</A > -- P°evΘst Julian Day Count na UNIXov² timestamp</DT ><DT ><A HREF="#function.jewishtojd" >JewishToJD</A > -- P°evΘst datum podle idovskΘho kalendß°e na Julian Day Count </DT ><DT ><A HREF="#function.juliantojd" >JulianToJD</A > -- P°evΘst JulißnskΘ datum na Julian Day Count </DT ><DT ><A HREF="#function.unixtojd" >unixtojd</A > -- P°evΘst UNIXov² timestamp na Julian Day Count</DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.cal-days-in-month" ></A >cal_days_in_month</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10195" ></A ><P > (PHP 4 >= 4.1.0)</P >cal_days_in_month -- Return the number of days in a month for a given year and calendar</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10198" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >cal_days_in_month</B > ( int calendar, int month, int year)<BR ></BR ><P >
This function will return the number of days in the <TT CLASS="parameter" ><I >month</I ></TT > of <TT CLASS="parameter" ><I >year</I ></TT > for the specified <TT CLASS="parameter" ><I >calendar</I ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN10217" ></A ><P ><B >P°φklad 1. <B CLASS="function" >cal_days_in_month()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $num = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31 echo "There was $num days in August 2003"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.jdtounix" ><B CLASS="function" >jdtounix()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cal-from-jd" ></A >cal_from_jd</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10224" ></A ><P > (PHP 4 >= 4.1.0)</P >cal_from_jd -- Converts from Julian Day Count to a supported calendar</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10227" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >cal_from_jd</B > ( int jd, int calendar)<BR ></BR ><P >
<B CLASS="function" >cal_from_jd()</B > converts the Julian day given in <TT CLASS="parameter" ><I >jd</I ></TT > into a date of the specified <TT CLASS="parameter" ><I >calendar</I ></TT >. Supported <TT CLASS="parameter" ><I >calendar</I ></TT > values are <TT CLASS="constant" ><B >CAL_GREGORIAN</B ></TT >, <TT CLASS="constant" ><B >CAL_JULIAN</B ></TT >, <TT CLASS="constant" ><B >CAL_JEWISH</B ></TT > and <TT CLASS="constant" ><B >CAL_FRENCH</B ></TT >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN10248" ></A ><P ><B >P°φklad 1. <B CLASS="function" >cal_from_jd()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $today = unixtojd(mktime(0, 0, 0, 8, 16, 2003)); print_r(cal_from_jd($today, CAL_GREGORIAN)); ?></PRE ></TD ></TR ></TABLE ><P >
This will output : </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [date] => 8/16/2003 [month] => 8 [day] => 16 [year] => 2003 [dow] => 6 [abbrevdayname] => Sat [dayname] => Saturday [abbrevmonth] => Aug [monthname] => August )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.cal-to-jd" ><B CLASS="function" >cal_to_jd()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cal-info" ></A >cal_info</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10257" ></A ><P > (PHP 4 >= 4.1.0)</P >cal_info -- Returns information about a particular calendar</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10260" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >cal_info</B > ( [int calendar])<BR ></BR ><P >
<B CLASS="function" >cal_info()</B > returns information on the specified <TT CLASS="parameter" ><I >calendar</I ></TT > or on all supported calendars if no <TT CLASS="parameter" ><I >calendar</I ></TT > is specified. </P ><P >
Calendar information is returned as an array containing the elements <TT CLASS="literal" >calname</TT >, <TT CLASS="literal" >calsymbol</TT >, <TT CLASS="literal" >month</TT >, <TT CLASS="literal" >abbrevmonth</TT > and <TT CLASS="literal" >maxdaysinmonth</TT >. </P ><P >
If no <TT CLASS="parameter" ><I >calendar</I ></TT > is specified information on all supported calendars is returned as an array. This functionality will be available beginning with PHP 5. </P ></DIV ><H1 ><A NAME="function.cal-to-jd" ></A >cal_to_jd</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10281" ></A ><P > (PHP 4 >= 4.1.0)</P >cal_to_jd -- Converts from a supported calendar to Julian Day Count</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10284" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >cal_to_jd</B > ( int calendar, int month, int day, int year)<BR ></BR ><P >
<B CLASS="function" >cal_to_jd()</B > calculates the Julian day count for a date in the specified <TT CLASS="parameter" ><I >calendar</I ></TT >. Supported <TT CLASS="parameter" ><I >calendar</I ></TT >s are <TT CLASS="constant" ><B >CAL_GREGORIAN</B ></TT >, <TT CLASS="constant" ><B >CAL_JULIAN</B ></TT >, <TT CLASS="constant" ><B >CAL_JEWISH</B ></TT > and <TT CLASS="constant" ><B >CAL_FRENCH</B ></TT >. </P ><P >
See also <B CLASS="function" >cal_to_jd()</B >. </P ></DIV ><H1 ><A NAME="function.easter-date" ></A >easter_date</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10312" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >easter_date -- Zjistit UNIXov² timestamp VelikonoΦnφ p∙lnoci v danΘm roce </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10315" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >easter_date</B > ( int year)<BR ></BR ><P >
Vracφ UNIXov² timestamp odpovφdajφcφ VelikonoΦnφ p∙lnoci v danΘm roce. Default <TT CLASS="parameter" ><I >year</I ></TT > je souΦasn² rok. </P ><P >
<SPAN CLASS="emphasis" ><I CLASS="emphasis" >Varovßnφ:</I ></SPAN > Tato funkce vygeneruje varovßnφ, pokud je <TT CLASS="parameter" ><I >year</I ></TT > mimo rozsah UNIXov²ch timestamp∙ (tj. p°ed 1970 nebo po 2037). <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN10328" ></A ><P ><B >P°φklad 1. Ukßzka <B CLASS="function" >easter_date()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo date ("M-d-Y", easter_date(1999)); /* "Apr-04-1999" */ echo date ("M-d-Y", easter_date(2000)); /* "Apr-23-2000" */ echo date ("M-d-Y", easter_date(2001)); /* "Apr-15-2001" */</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Datum Velikonoc bylo definovßno Nicaejsk²m koncilem v r. 325 n. l. jako ned∞le po prvnφm ·pl≥ku kter² p°ipadß na nebo po jarnφ rovnodennosti. Rovnodennost se v╛dy p°edpoklßdß na 21. b°ezna, tak╛e se v²poΦet redukuje na urΦenφ data ·pl≥ku a data nßsledujφcφ ned∞le. Zde pou╛it² algoritmus byl poprvΘ pou╛it kolem roku 532 Dionysiem Exiguem. V JulißnskΘm kalendß°i (pro lΘta p°ed 1753) se na sledovßnφ fßzφ M∞sφce pou╛φval jednoduch² devatenßctilet² cyklus. V GregorißnskΘm kalendß°i (pro lΘta po 1753 - navr╛en Claviem a Liliem a zaveden pape╛em ╪eho°em XIII v °φjnu 1582, v Britßnii a jejφch koloniφch v zß°φ 1752) se p°idßvajφ dva faktory, kterΘ tento cyklus zp°es≥ujφ. </P ><P >
(K≤d je zalo╛en na C programu od Simona Kershawa, <webmaster@ely.anglican.org>) </P ><P >
V²poΦet Velikonoc p°ed rokem 1970 nebo po roce 2037 viz <A HREF="#function.easter-days" ><B CLASS="function" >easter_days()</B ></A >. </P ></DIV ><H1 ><A NAME="function.easter-days" ></A >easter_days</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10337" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >easter_days -- Get number of days after March 21 on which Easter falls for a given year </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10340" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >easter_days</B > ( int year)<BR ></BR ><P >
Vracφ poΦet dnφ od 21. b°ezna do Velikonoc v danΘm roce. Default <TT CLASS="parameter" ><I >year</I ></TT > je souΦasn² rok. </P ><P >
Tato funkce je vyu╛itelnß mφsto <A HREF="#function.easter-date" ><B CLASS="function" >easter_date()</B ></A > na v²poΦty Velikonoc pro roky kterΘ spadajφ mimo rozsah UNIXov²ch timestamp∙ (tj. p°ed rokem 1970 a po roce 2037). <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN10352" ></A ><P ><B >P°φklad 1. Ukßzka <A HREF="#function.easter-date" ><B CLASS="function" >easter_date()</B ></A ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo easter_days (1999); /* 14, i.e. April 4 */ echo easter_days (1492); /* 32, i.e. April 22 */ echo easter_days (1913); /* 2, i.e. March 23 */</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Datum Velikonoc bylo definovßno Nicaejsk²m koncilem v r. 325 n. l. jako ned∞le po prvnφm ·pl≥ku kter² p°ipadß na nebo po jarnφ rovnodennosti. Rovnodennost se v╛dy p°edpoklßdß na 21. b°ezna, tak╛e se v²poΦet redukuje na urΦenφ data ·pl≥ku a data nßsledujφcφ ned∞le. Zde pou╛it² algoritmus byl poprvΘ pou╛it kolem roku 532 Dionysiem Exiguem. V JulißnskΘm kalendß°i (pro lΘta p°ed 1753) se na sledovßnφ fßzφ M∞sφce pou╛φval jednoduch² devatenßctilet² cyklus. V GregorißnskΘm kalendß°i (pro lΘta po 1753 - navr╛en Claviem a Liliem a zaveden pape╛em ╪eho°em XIII v °φjnu 1582, v Britßnii a jejφch koloniφch v zß°φ 1752) se p°idßvajφ dva faktory, kterΘ tento cyklus zp°es≥ujφ. </P ><P >
(K≤d je zalo╛en na C programu od Simona Kershawa, <webmaster@ely.anglican.org>) </P ><P >
Viz takΘ: <A HREF="#function.easter-date" ><B CLASS="function" >easter_date()</B ></A >. </P ></DIV ><H1 ><A NAME="function.frenchtojd" ></A >FrenchToJD</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10361" ></A ><P > (PHP 3, PHP 4 )</P >FrenchToJD -- P°evΘst datum z FrancouzskΘho republikßnskΘho kalendß°e na Julian Day Count </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10364" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >frenchtojd</B > ( int month, int day, int year)<BR ></BR ><P >
P°evßdφ datum z FrancouzskΘho republikßnskΘho kalendß°e na Julian Day Count. </P ><P >
Tyto rutiny konvertujφ pouze data v letech 1 a╛ 14 (Gregorißnskß data 22. zß°φ 1792 a╛ 22. zß°φ 1806). To vφce ne╛ dostateΦn∞ pokr²vß obdobφ, po kterΘ se tento kalendß° pou╛φval. </P ></DIV ><H1 ><A NAME="function.gregoriantojd" ></A >GregorianToJD</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10381" ></A ><P > (PHP 3, PHP 4 )</P >GregorianToJD -- P°evΘst GregorißnskΘ datum na Julian Day Count</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10384" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >gregoriantojd</B > ( int month, int day, int year)<BR ></BR ><P >
Platn² rozsah GregorißnskΘho kalendß°e je 4714 p°. n. l. a╛ 9999 n. l. </P ><P >
Jakkoli tento software zvlßdß data a╛ do 4714 p°. n. l., takovΘ pou╛itφ asi nemß smysl. Gregorißnsk² kalendß° byl zalo╛en a╛ 15. °φjna 1582 (5. °φjna 1582 podle JulißnskΘho kalendß°e). N∞kterΘ zem∞ ho p°ijaly mnohem pozd∞ji, ╪ecko a╛ v r. 1923. V∞t╣ina evropsk²m stßt∙ p°ed Gregorißnsk²m kalendß°em pou╛φvala Julißnsk². <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN10400" ></A ><P ><B >P°φklad 1. Kalendß°ovΘ funkce</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $jd = GregorianToJD (10,11,1970); echo "$jd\n"; $gregorian = JDToGregorian ($jd); echo "$gregorian\n"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.jddayofweek" ></A >JDDayOfWeek</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10404" ></A ><P > (PHP 3, PHP 4 )</P >JDDayOfWeek -- Vrßtit den v t²dnu</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10407" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >jddayofweek</B > ( int julianday, int mode)<BR ></BR ><P >
Vracφ den v t²dnu. V zßvislosti na m≤du vracφ °et∞zec nebo integer. <DIV CLASS="table" ><A NAME="AEN10419" ></A ><P ><B >Tabulka 1. Kalendß°ovΘ t²dennφ m≤dy</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >M≤d</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >V²znam</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >0</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Vracφ Φφslo dne jako integer (0=sunday, 1=monday, etc) </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >1</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Vracφ °et∞zec obsahujφcφ nßzev dne v t²dnu (anglick² gregorißnsk²) </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >2</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >
Vracφ °et∞zec obsahujφcφ zkrßcen² nßzev dne v t²dnu (anglick² gregorißnsk²) </TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.jdmonthname" ></A >JDMonthName</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10437" ></A ><P > (PHP 3, PHP 4 )</P >JDMonthName -- Vrßtit nßzev m∞sφce</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10440" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >jdmonthname</B > ( int julianday, int mode)<BR ></BR ><P >
Vracφ °et∞zec obsahujφcφ nßzev m∞sφce. <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje, na kter² kalendß° se mß Julian Day Count konvertovat a jak² typ jmΘna se mß vrßtit. <DIV CLASS="table" ><A NAME="AEN10453" ></A ><P ><B >Tabulka 1. Kalendß°ovΘ m≤dy</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >M≤d</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >V²znam</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >0</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Gregorißnsk² - zkrßcen²</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >1</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Gregorißnsk²</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >2</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Julißnsk² - zkrßcen²</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >3</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Julißnsk²</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >4</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > idovsk²</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >5</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Francouzsk² republikßnsk²</TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.jdtofrench" ></A >JDToFrench</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10480" ></A ><P > (PHP 3, PHP 4 )</P >JDToFrench -- P°evΘst Julian Day Count na Francouzsk² republikßnsk² kalendß° </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10483" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >jdtofrench</B > ( int juliandaycount)<BR ></BR ><P >
P°evßdφ Julian Day Count na Francouzsk² republikßnsk² kalendß°. </P ></DIV ><H1 ><A NAME="function.jdtogregorian" ></A >JDToGregorian</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10493" ></A ><P > (PHP 3, PHP 4 )</P >JDToGregorian -- P°evΘst Julian Day Count na GregorißnskΘ datum</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10496" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >jdtogregorian</B > ( int julianday)<BR ></BR ><P >
P°evßdφ Julian Day Count na °et∞zec obsahujφcφ GregorißnskΘ datum ve formßtu "m∞sφc/den/rok". </P ></DIV ><H1 ><A NAME="function.jdtojewish" ></A >JDToJewish</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10506" ></A ><P > (PHP 3, PHP 4 )</P >JDToJewish -- P°evΘst Julian Day Count na idovsk² kalendß° </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10509" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >jdtojewish</B > ( int julianday)<BR ></BR ><P >
P°evßdφ Julian Day Count na idovsk² kalendß°. </P ></DIV ><H1 ><A NAME="function.jdtojulian" ></A >JDToJulian</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10519" ></A ><P > (PHP 3, PHP 4 )</P >JDToJulian -- P°evΘst Julian Day Count na JulißnskΘ datum </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10522" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >jdtojulian</B > ( int julianday)<BR ></BR ><P >
P°evßdφ Julian Day Count na °et∞zec obsahujφcφ JulißnskΘ datum ve formßtu "m∞sφc/den/rok". </P ></DIV ><H1 ><A NAME="function.jdtounix" ></A >jdtounix</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10532" ></A ><P > (PHP 4 )</P >jdtounix -- P°evΘst Julian Day Count na UNIXov² timestamp</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10535" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >jdtounix</B > ( int jday)<BR ></BR ><P >
<B CLASS="function" >jdtounix()</B > vracφ UNIXov² timestamp odpovφdajφcφ Julian Day Countu danΘmu v <TT CLASS="parameter" ><I >jday</I ></TT > nebo <TT CLASS="constant" ><B >FALSE</B ></TT >, pokud je <TT CLASS="parameter" ><I >jday</I ></TT > mimo UNIXovou epochu (GregorißnskΘ roky mezi 1970 a 2037, nebo-li 2440588 <= <TT CLASS="parameter" ><I >jday</I ></TT > <= 2465342 ) </P ><P >
Viz takΘ: <B CLASS="function" >jdtounix()</B >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Tato funkce byla p°idßna v PHP 4 RC2. </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.jewishtojd" ></A >JewishToJD</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10554" ></A ><P > (PHP 3, PHP 4 )</P >JewishToJD -- P°evΘst datum podle idovskΘho kalendß°e na Julian Day Count </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10557" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >jewishtojd</B > ( int month, int day, int year)<BR ></BR ><P >
Platn² rozsah Jakkoli tento software zvlßdß data a╛ do roku 1 (3761 p°. n. l.), takovΘ pou╛itφ asi nemß smysl. </P ><P >
idovsk² kalendß° se pou╛φvß n∞kolik tisφc let, ale zpoΦßtku neexistoval vzorec na urΦenφ zaΦßtku m∞sφce. Nov² m∞sφc zaΦφnal, kdy╛ byl poprvΘ spat°en nov² M∞sφc. </P ></DIV ><H1 ><A NAME="function.juliantojd" ></A >JulianToJD</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10574" ></A ><P > (PHP 3, PHP 4 )</P >JulianToJD -- P°evΘst JulißnskΘ datum na Julian Day Count </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10577" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >juliantojd</B > ( int month, int day, int year)<BR ></BR ><P >
Platn² rozsah pro Julißnsk² kalendß° je 4713 p°. n. l. a╛ 9999 n. l. </P ><P >
Jakkoli tento software zvlßdß data a╛ do 4713 p°. n. l., takovΘ pou╛itφ asi nemß smysl. Tento kalendß° byl vytvo°en v roce 46 p°. n. l., ale detaily se nestabilizovaly nejmΘn∞ do 8 n. l., a mo╛nß a╛ do konce 4. stoletφ. Navφc zaΦßtek roku se li╣il od kultury ke kultu°e - ne v╣echny p°ijφmaly leden jako prvnφ m∞sφc roku. </P ></DIV ><H1 ><A NAME="function.unixtojd" ></A >unixtojd</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10594" ></A ><P > (PHP 4 )</P >unixtojd -- P°evΘst UNIXov² timestamp na Julian Day Count</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10597" ></A ><H2 >Popis</H2 >int <B CLASS="methodname" >unixtojd</B > ( [int timestamp])<BR ></BR ><P >
Vracφ Julian Day Count pro UNIXov² <TT CLASS="parameter" ><I >timestamp</I ></TT > (sekundy od 1.1.1970), nebo pro aktußlnφ den, pokud nenφ dßn <TT CLASS="parameter" ><I >timestamp</I ></TT >. </P ><P >
Viz takΘ: <A HREF="#function.jdtounix" ><B CLASS="function" >jdtounix()</B ></A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > Tato funkce byla p°idßna v PHP 4 RC2. </P ></BLOCKQUOTE ></DIV ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.ccvs" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >VII. CCVS API Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN10615" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="ccvs.intro" ></A >┌vod</H1 ><P >
Tyto funkce p°edstavujφ interface k CCVS API, a umo╛nujφ tak p°φmo pracovat s CCVS z va╣ich PHP skript∙. CCVS je <A HREF="http://www.redhat.com/" TARGET="_top" >RedHatφ</A > °e╣enφ "zprost°edkovatele" ve zpracovßnφ kreditnφch karet. Umo╛%nuje vßm oslovovat p°φmo zpracovatele kreditnφch karet p°es vß╣ *nix systΘm a modem. Pomocφ CCVS modulu pro PHP m∙╛ete zpracovßvat kreditnφ karty p°es CCVS ve va╣ich PHP skriptech. Nßsledujφcφ reference tento proces p°iblφ╛φ. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > CCVS bylo firmou RedHat pozastaveno a nemß v plßnu vydßvat dal╣φ klφΦe nebo podporovat kontrakty. Pokud hledßte nßhradu, zva╛te <A HREF="http://www.mcve.com/" TARGET="_top" >MCVE firmy Main Street Softworks</A > jako mo╛nou nßhradu. Mß podobn² design a dokumentovanou podporu PHP! </P ><P >
Toto roz╣φ°enφ bylo z PHP odstran∞no a od verze 4.3.0 nenφ k dispozici. Pokud chcete pou╛φvat funkce pro zpracovßnφ kreditnφch karet, m∙╛ete mφsto toho pou╛φt roz╣φ°enφ <A HREF="#ref.mcve" >MCVE</A >. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="ccvs.installation" ></A >Instalace</H1 ><P >
Pokud chcete zapnout CCVS podporu v PHP, zjist∞te si nejd°φve instalaΦnφ adresß° CCVS. Potom budete muset PHP zkonfigurovat s <TT CLASS="option" >--with-ccvs</TT >. Pokud toto pou╛ijete be udßnφ cesty k va╣φ instalaci CCVS, PHP se pokusφ podφvat do defaultnφ instalaΦnφ lokace CCVS (/usr/local/ccvs). Pokud je CCVS na nestandardnφm mφst∞, spust∞te configure s: <TT CLASS="option" >--with-ccvs=$ccvs_path</TT >, kde $ccvs_path je cesta k va╣φ instalaci CVS. Pozn.: Podpora CCVS vy╛aduje existenci $ccvs_path/lib a $ccvs_path/include, a p°φtomnost cv_api.h v adresß°i include a libccvs.a v adresß°i lib. </P ><P >
Dßle je pot°eba, aby b∞╛el proces ccvsd. Navφc, PHP processy musφ b∞╛et pod stejn²m u╛ivatelem, pod kter²m b∞hß CCVS (nap°. pokud jste instalovali ccvs jako 'ccvs', va╣e PHP procesy musφ takΘ b∞╛et jako 'ccvs'). </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="ccvs.seealso" ></A >Viz takΘ</H1 ><P >
RedHat p°eru╣il podporu CCVS, p°esto je mφrn∞ zastaralß dokumentace k dispozici na <A HREF="http://redhat.com/docs/manuals/ccvs/" TARGET="_top" >http://redhat.com/docs/manuals/ccvs/</A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.ccvs-add" >ccvs_add</A > -- Add data to a transaction </DT ><DT ><A HREF="#function.ccvs-auth" >ccvs_auth</A > -- Perform credit authorization test on a transaction </DT ><DT ><A HREF="#function.ccvs-command" >ccvs_command</A > -- Performs a command which is peculiar to a single protocol, and thus is not available in the general CCVS API </DT ><DT ><A HREF="#function.ccvs-count" >ccvs_count</A > -- Find out how many transactions of a given type are stored in the system </DT ><DT ><A HREF="#function.ccvs-delete" >ccvs_delete</A > -- Delete a transaction</DT ><DT ><A HREF="#function.ccvs-done" >ccvs_done</A > -- Terminate CCVS engine and do cleanup work</DT ><DT ><A HREF="#function.ccvs-init" >ccvs_init</A > -- Initialize CCVS for use</DT ><DT ><A HREF="#function.ccvs-lookup" >ccvs_lookup</A > -- Look up an item of a particular type in the database # </DT ><DT ><A HREF="#function.ccvs-new" >ccvs_new</A > -- Create a new, blank transaction </DT ><DT ><A HREF="#function.ccvs-report" >ccvs_report</A > -- Return the status of the background communication process </DT ><DT ><A HREF="#function.ccvs-return" >ccvs_return</A > -- Transfer funds from the merchant to the credit card holder </DT ><DT ><A HREF="#function.ccvs-reverse" >ccvs_reverse</A > -- Perform a full reversal on an already-processed authorization </DT ><DT ><A HREF="#function.ccvs-sale" >ccvs_sale</A > -- Transfer funds from the credit card holder to the merchant </DT ><DT ><A HREF="#function.ccvs-status" >ccvs_status</A > -- Check the status of an invoice</DT ><DT ><A HREF="#function.ccvs-textvalue" >ccvs_textvalue</A > -- Get text return value for previous function call</DT ><DT ><A HREF="#function.ccvs-void" >ccvs_void</A > -- Perform a full reversal on a completed transaction </DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.ccvs-add" ></A >ccvs_add</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10636" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_add -- Add data to a transaction </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10639" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_add</B > ( string session, string invoice, string argtype, string argval)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-auth" ></A >ccvs_auth</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10660" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_auth -- Perform credit authorization test on a transaction </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10663" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_auth</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-command" ></A >ccvs_command</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10678" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_command -- Performs a command which is peculiar to a single protocol, and thus is not available in the general CCVS API </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10681" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_command</B > ( string session, string type, string argval)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-count" ></A >ccvs_count</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10699" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_count -- Find out how many transactions of a given type are stored in the system </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10702" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >ccvs_count</B > ( string session, string type)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-delete" ></A >ccvs_delete</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10717" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_delete -- Delete a transaction</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10720" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_delete</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-done" ></A >ccvs_done</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10735" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_done -- Terminate CCVS engine and do cleanup work</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10738" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_done</B > ( string sess)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-init" ></A >ccvs_init</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10750" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_init -- Initialize CCVS for use</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10753" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_init</B > ( string name)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-lookup" ></A >ccvs_lookup</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10765" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_lookup -- Look up an item of a particular type in the database # </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10768" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_lookup</B > ( string session, string invoice, int inum)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-new" ></A >ccvs_new</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10786" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_new -- Create a new, blank transaction </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10789" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_new</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-report" ></A >ccvs_report</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10804" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_report -- Return the status of the background communication process </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10807" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_report</B > ( string session, string type)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-return" ></A >ccvs_return</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10822" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_return -- Transfer funds from the merchant to the credit card holder </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10825" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_return</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-reverse" ></A >ccvs_reverse</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10840" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_reverse -- Perform a full reversal on an already-processed authorization </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10843" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_reverse</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-sale" ></A >ccvs_sale</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10858" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_sale -- Transfer funds from the credit card holder to the merchant </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10861" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_sale</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-status" ></A >ccvs_status</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10876" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_status -- Check the status of an invoice</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10879" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_status</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-textvalue" ></A >ccvs_textvalue</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10894" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_textvalue -- Get text return value for previous function call</DIV ><DIV CLASS="refsect1" ><A NAME="AEN10897" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_textvalue</B > ( string session)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.ccvs-void" ></A >ccvs_void</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN10909" ></A ><P > (4.0.2 - 4.2.3 only)</P >ccvs_void -- Perform a full reversal on a completed transaction </DIV ><DIV CLASS="refsect1" ><A NAME="AEN10912" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >ccvs_void</B > ( string session, string invoice)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.com" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >VIII. Funkce na podporu COM ve Windows</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN10929" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="com.intro" ></A >┌vod</H1 ><P >
COM je technologie, kterß umo╛≥uje znovupou╛φt k≤d napsan² v jakΘmkoliv jazyce za pou╛itφ standardnφho volßnφ a schovßnφm implementaΦnφch detail∙ - jako na kterΘm poΦφtaΦi je komponenta ulo╛ena a kter² spustiteln² soubor ji uchovßvß - za API. Lze si to p°edstavit jako roz╣φ°en² mechanismus vzdßlenΘho volßnφ procedur (RPC) se zßklady objekt∙. COM odd∞luje implementaci od rozhranφ. </P ><P >
COM podporuje verzovßnφ, odd∞lenφ implementace od rozhranφ a skrytφ implementaΦnφch detail∙ jako je umφst∞nφ spustitelnΘho souboru a jazyku, kter² byl pou╛it. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="com.requirements" ></A >Po╛adavky</H1 ><P >
Tyto funkce jsou dostupnΘ pouze ve Windows verzi PHP. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="com.installation" ></A >Instalace</H1 ><P >K pou╛φvßnφ t∞chto funkcφ nenφ t°eba ╛ßdnß instalace, jsou souΦßstφ jßdra PHP.</P ><P >Verze <TT CLASS="literal" >PHP</TT > pro Windows mß vestav∞nou podporu pro toto roz╣φ°enφ. K pou╛itφ t∞chto funkcφ nenφ t°eba naΦφtat ╛ßdnß dal╣φ roz╣φ°enφ.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="com.configuration" ></A >Konfigurace b∞hu</H1 ><P >
Chovßnφ t∞chto funkcφ je ovlivn∞no nastavenφm parametr∙ v <TT CLASS="filename" >php.ini</TT >. </P ><P >
<DIV CLASS="table" ><A NAME="AEN10947" ></A ><P ><B >Tabulka 1. Com configuration options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >com.allow_dcom</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >com.autoregister_typelib</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >com.autoregister_verbose</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >com.autoregister_casesensitive</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >com.typelib_file</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >""</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ></TBODY ></TABLE ></DIV > For further details and definition of the PHP_INI_* constants see <A HREF="#function.ini-set" ><B CLASS="function" >ini_set()</B ></A >. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="com.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >
Tyto konstanty jsou definovßny tφmto roz╣φ°enφm a budou k dispozici pouze tehdy, bylo-li roz╣φ°enφ zkompilovßno spoleΦn∞ s PHP nebo dynamicky zavedeno za b∞hu. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CLSCTX_INPROC_SERVER</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CLSCTX_INPROC_HANDLER</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CLSCTX_LOCAL_SERVER</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CLSCTX_REMOTE_SERVER</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CLSCTX_SERVER</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CLSCTX_ALL</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_NULL</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_EMPTY</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_UI1</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_I2</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_I4</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_R4</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_R8</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_BOOL</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_ERROR</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_CY</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_DATE</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_BSTR</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_DECIMAL</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_UNKNOWN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_DISPATCH</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_VARIANT</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_I1</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_UI2</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_UI4</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_INT</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_UINT</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_ARRAY</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >VT_BYREF</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CP_ACP</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CP_MACCP</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CP_OEMCP</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CP_UTF7</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CP_UTF8</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CP_SYMBOL</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CP_THREAD_ACP</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="com.seealso" ></A >Viz takΘ</H1 ><P >
Vφce informacφ o COM naleznete ve <A HREF="http://www.microsoft.com/Com/resources/comdocs.asp" TARGET="_top" >specifikaci COM</A > nebo se t°eba podφvejte na <A HREF="http://www.develop.com/essentialcom/sources/YACL.htm" TARGET="_top" >Yet Another COM Library (YACL)</A > Dona Boxe. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#class.com" >COM</A > -- COM class</DT ><DT ><A HREF="#class.variant" >VARIANT</A > -- VARIANT class</DT ><DT ><A HREF="#function.com-addref" >com_addref</A > -- Increases the components reference counter. </DT ><DT ><A HREF="#function.com-get" >com_get</A > -- Zφskßvß hodnotu vlastnosti COM komponenty </DT ><DT ><A HREF="#function.com-invoke" >com_invoke</A > -- Volß metodu COM komponenty. </DT ><DT ><A HREF="#function.com-isenum" >com_isenum</A > -- Grabs an IEnumVariant</DT ><DT ><A HREF="#function.com-load-typelib" >com_load_typelib</A > -- Loads a Typelib</DT ><DT ><A HREF="#function.com-load" >com_load</A > -- Vytvo°φ nov² odkaz na COM komponentu </DT ><DT ><A HREF="#function.com-propget" >com_propget</A > -- Zφskßvß hodnotu vlastnosti COM komponenty </DT ><DT ><A HREF="#function.com-propput" >com_propput</A > -- P°i°azuje hodnotu vlastnosti COM komponenty. </DT ><DT ><A HREF="#function.com-propset" >com_propset</A > -- P°i°azuje hodnotu vlastnosti COM komponenty. </DT ><DT ><A HREF="#function.com-release" >com_release</A > -- Decreases the components reference counter. </DT ><DT ><A HREF="#function.com-set" >com_set</A > -- P°i°azuje hodnotu vlastnosti COM komponenty. </DT ></DL ></DIV ></DIV ><H1 ><A NAME="class.com" ></A >COM</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11203" ></A ><P > (no version information, might be only in CVS)</P >COM -- COM class</DIV ><DIV CLASS="refsynopsisdiv" ><A NAME="AEN11206" ></A ><H2 >P°ehled</H2 ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="synopsis" >$obj = new COM("server.object")</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="class.com.class" ></A ><H2 >Description</H2 ><P >
The COM class provides a framework to integrate (D)COM components into your PHP scripts. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="class.com.constructor" ></A ><H2 >Methods</H2 >string <B CLASS="methodname" >COM::COM</B > ( string module_name [, string server_name [, int codepage]])<BR ></BR ><P >
COM class constructor. Parameters: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >module_name</DT ><DD ><P >
name or class-id of the requested component. </P ></DD ><DT >server_name</DT ><DD ><P >
name of the DCOM server from which the component should be fetched. If <TT CLASS="constant" ><B >NULL</B ></TT >, <TT CLASS="literal" >localhost</TT > is assumed. To allow DCOM <TT CLASS="constant" ><B >com.allow_dcom</B ></TT > has to be set to <TT CLASS="constant" ><B >TRUE</B ></TT > in <TT CLASS="filename" >php.ini</TT >. </P ></DD ><DT >codepage</DT ><DD ><P >
specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are <TT CLASS="constant" ><B >CP_ACP</B ></TT >, <TT CLASS="constant" ><B >CP_MACCP</B ></TT >, <TT CLASS="constant" ><B >CP_OEMCP</B ></TT >, <TT CLASS="constant" ><B >CP_SYMBOL</B ></TT >, <TT CLASS="constant" ><B >CP_THREAD_ACP</B ></TT >, <TT CLASS="constant" ><B >CP_UTF7</B ></TT > and <TT CLASS="constant" ><B >CP_UTF8</B ></TT >. </P ></DD ></DL ></DIV > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.com1" ></A ><P ><B >P°φklad 1. COM example (1)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // starting word $word = new COM("word.application") or die("Unable to instanciate Word"); echo "Loaded Word, version {$word->Version}\n"; //bring it to front $word->Visible = 1; //open an empty document $word->Documents->Add(); //do some weird stuff $word->Selection->TypeText("This is a test..."); $word->Documents[1]->SaveAs("Useless test.doc"); //closing word $word->Quit(); //free the object $word->Release(); $word = null; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.com2" ></A ><P ><B >P°φklad 2. COM example (2)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $conn->Open("Provider=SQLOLEDB; Data Source=localhost; Initial Catalog=database; User ID=user; Password=password"); $rs = $conn->Execute("SELECT * FROM sometable"); // Recordset $num_columns = $rs->Fields->Count(); echo $num_columns . "\n"; for ($i=0; $i < $num_columns; $i++) { $fld[$i] = $rs->Fields($i); } $rowcount = 0; while (!$rs->EOF) { for ($i=0; $i < $num_columns; $i++) { echo $fld[$i]->value . "\t"; } echo "\n"; $rowcount++; // increments rowcount $rs->MoveNext(); } $rs->Close(); $conn->Close(); $rs->Release(); $conn->Release(); $rs = null; $conn = null; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="class.variant" ></A >VARIANT</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11261" ></A ><P > (no version information, might be only in CVS)</P >VARIANT -- VARIANT class</DIV ><DIV CLASS="refsynopsisdiv" ><A NAME="AEN11264" ></A ><H2 >P°ehled</H2 ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="synopsis" >$vVar = new VARIANT($var)</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="class.variant.class" ></A ><H2 >Description</H2 ><P >
A simple container to wrap variables into VARIANT structures. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="class.variant.constructor" ></A ><H2 >Methods</H2 >string <B CLASS="methodname" >VARIANT::VARIANT</B > ( [mixed value [, int type [, int codepage]]])<BR ></BR ><P >
VARIANT class constructor. Parameters: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >value</DT ><DD ><P >
initial value. if omitted an VT_EMPTY object is created. </P ></DD ><DT >type</DT ><DD ><P >
specifies the content type of the VARIANT object. Possible values are <TT CLASS="constant" ><B >VT_UI1</B ></TT >, <TT CLASS="constant" ><B >VT_UI2</B ></TT >, <TT CLASS="constant" ><B >VT_UI4</B ></TT >, <TT CLASS="constant" ><B >VT_I1</B ></TT >, <TT CLASS="constant" ><B >VT_I2</B ></TT >, <TT CLASS="constant" ><B >VT_I4</B ></TT >, <TT CLASS="constant" ><B >VT_R4</B ></TT >, <TT CLASS="constant" ><B >VT_R8</B ></TT >, <TT CLASS="constant" ><B >VT_INT</B ></TT >, <TT CLASS="constant" ><B >VT_UINT</B ></TT >, <TT CLASS="constant" ><B >VT_BOOL</B ></TT >, <TT CLASS="constant" ><B >VT_ERROR</B ></TT >, <TT CLASS="constant" ><B >VT_CY</B ></TT >, <TT CLASS="constant" ><B >VT_DATE</B ></TT >, <TT CLASS="constant" ><B >VT_BSTR</B ></TT >, <TT CLASS="constant" ><B >VT_DECIMAL</B ></TT >, <TT CLASS="constant" ><B >VT_UNKNOWN</B ></TT >, <TT CLASS="constant" ><B >VT_DISPATCH</B ></TT > and <TT CLASS="constant" ><B >VT_VARIANT</B ></TT >. These values are mutual exclusive, but they can be combined with <TT CLASS="constant" ><B >VT_BYREF</B ></TT > to specify being a value. If omitted, the type of <TT CLASS="parameter" ><I >value</I ></TT > is used. Consult the <SPAN CLASS="acronym" >MSDN</SPAN > library for additional information. </P ></DD ><DT >codepage</DT ><DD ><P >
specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are <TT CLASS="constant" ><B >CP_ACP</B ></TT >, <TT CLASS="constant" ><B >CP_MACCP</B ></TT >, <TT CLASS="constant" ><B >CP_OEMCP</B ></TT >, <TT CLASS="constant" ><B >CP_SYMBOL</B ></TT >, <TT CLASS="constant" ><B >CP_THREAD_ACP</B ></TT >, <TT CLASS="constant" ><B >CP_UTF7</B ></TT > and <TT CLASS="constant" ><B >CP_UTF8</B ></TT >. </P ></DD ></DL ></DIV > </P ></DIV ><H1 ><A NAME="function.com-addref" ></A >com_addref</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11328" ></A ><P > (4.1.0 - 4.3.2 only)</P >com_addref -- Increases the components reference counter. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11331" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >com_addref</B > ( void )<BR ></BR ><P >
Increases the components reference counter. </P ></DIV ><H1 ><A NAME="function.com-get" ></A >com_get</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11339" ></A ><P > (PHP 3>= 3.0.3, 4.0.5 - 4.3.2 only)</P >com_get -- Zφskßvß hodnotu vlastnosti COM komponenty </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11342" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >com_get</B > ( resource com_object, string property)<BR ></BR ><P >
Vracφ hodnotu <TT CLASS="parameter" ><I >property</I ></TT > COM komponenty odkazovanΘ <TT CLASS="parameter" ><I >com_object</I ></TT >. P°i chyb∞ vracφ <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ></DIV ><H1 ><A NAME="function.com-invoke" ></A >com_invoke</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11358" ></A ><P > (PHP 3>= 3.0.3)</P >com_invoke -- Volß metodu COM komponenty. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11361" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >com_invoke</B > ( resource com_object, string function_name [, mixed parametry funkce, ...])<BR ></BR ><P >
<B CLASS="function" >com_invoke()</B > volß metodu COM komponenty odkazovanΘ <TT CLASS="parameter" ><I >com_object</I ></TT >. Pokud dojde k chyb∞, vracφ <TT CLASS="constant" ><B >FALSE</B ></TT >, p°i ·sp∞chu vracφ nßvratovou hodnotu metody <TT CLASS="parameter" ><I >function_name</I ></TT >. </P ></DIV ><H1 ><A NAME="function.com-isenum" ></A >com_isenum</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11381" ></A ><P > (4.1.0 - 4.3.2 only)</P >com_isenum -- Grabs an IEnumVariant</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11384" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >com_isenum</B > ( object com_module)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.com-load-typelib" ></A >com_load_typelib</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11396" ></A ><P > (4.1.0 - 4.3.2 only)</P >com_load_typelib -- Loads a Typelib</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11399" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >com_load_typelib</B > ( string typelib_name [, int case_insensitive])<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.com-load" ></A >com_load</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11414" ></A ><P > (PHP 3>= 3.0.3)</P >com_load -- Vytvo°φ nov² odkaz na COM komponentu </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11417" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >com_load</B > ( string module name [, string server name])<BR ></BR ><P >
<B CLASS="function" >com_load()</B > vytvß°φ novou COM komponentu a vracφ odkaz na ni. P°i ne·sp∞chu vracφ <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ></DIV ><H1 ><A NAME="function.com-propget" ></A >com_propget</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11432" ></A ><P > (PHP 3>= 3.0.3, 4.0.5 - 4.3.2 only)</P >com_propget -- Zφskßvß hodnotu vlastnosti COM komponenty </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11435" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >com_propget</B > ( resource com_object, string property)<BR ></BR ><P >
Tato funkce je alias k <A HREF="#function.com-get" ><B CLASS="function" >com_get()</B ></A >. </P ></DIV ><H1 ><A NAME="function.com-propput" ></A >com_propput</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11449" ></A ><P > (PHP 3>= 3.0.3, 4.0.5 - 4.3.2 only)</P >com_propput -- P°i°azuje hodnotu vlastnosti COM komponenty. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11452" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >com_propput</B > ( resource com_object, string property, mixed value)<BR ></BR ><P >
Tato funkce je alias ke <A HREF="#function.com-set" ><B CLASS="function" >com_set()</B ></A >. </P ></DIV ><H1 ><A NAME="function.com-propset" ></A >com_propset</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11469" ></A ><P > (PHP 3>= 3.0.3, 4.0.5 - 4.3.2 only)</P >com_propset -- P°i°azuje hodnotu vlastnosti COM komponenty. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11472" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >com_propset</B > ( resource com_object, string property, mixed value)<BR ></BR ><P >
Tato funkce je alias ke <A HREF="#function.com-set" ><B CLASS="function" >com_set()</B ></A >. </P ></DIV ><H1 ><A NAME="function.com-release" ></A >com_release</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11489" ></A ><P > (4.1.0 - 4.3.2 only)</P >com_release -- Decreases the components reference counter. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11492" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >com_release</B > ( void )<BR ></BR ><P >
Decreases the components reference counter. </P ></DIV ><H1 ><A NAME="function.com-set" ></A >com_set</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11500" ></A ><P > (PHP 3>= 3.0.3, 4.0.5 - 4.3.2 only)</P >com_set -- P°i°azuje hodnotu vlastnosti COM komponenty. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11503" ></A ><H2 >Popis</H2 >void <B CLASS="methodname" >com_set</B > ( resource com_object, string property, mixed value)<BR ></BR ><P >
Nastavuje hodnotu vlastnosti <TT CLASS="parameter" ><I >property</I ></TT > COM komponent odkazovanΘ <TT CLASS="parameter" ><I >com_object</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud je <TT CLASS="parameter" ><I >property</I ></TT > nastaveno. P°i chyb∞ vracφ <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.classobj" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >IX. Funkce pro prßci s t°φdami/objekty</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN11526" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="classobj.intro" ></A >┌vod</H1 ><P >
Tyto funkce vßm umo╛≥ujφ zφskßvat informace o t°φdßch a instancφch. M∙╛ete zjistit nßzev t°φdy do kterΘ objekt pat°φ nebo jeho prom∞nnΘ a metody. Pomocφ t∞chto funkcφ m∙╛ete zjistit nejen p°φslu╣nost objektu k t°φd∞, ale i jeho p°edka (tj. kterou t°φdu t°φda tohoto objektu roz╣i°uje). </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="classobj.requirements" ></A >Po╛adavky</H1 ><P >Tyto funkce jsou k dispozici jako souΦßst standardnφho modulu, kter² je v╛dy dostupn².</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="classobj.installation" ></A >Instalace</H1 ><P >K pou╛φvßnφ t∞chto funkcφ nenφ t°eba ╛ßdnß instalace, jsou souΦßstφ jßdra PHP.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="classobj.configuration" ></A >Konfigurace b∞hu</H1 ><P >Toto roz╣φ°enφ nemß definovßno ╛ßdnΘ konfiguraΦnφ direktivy.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="classobj.resources" ></A >Typy prost°edk∙</H1 ><P >Toto roz╣φ°enφ nemß definovßn ╛ßdn² typ prost°edku (resource).</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="classobj.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >Toto roz╣φ°enφ nemß definovßny ╛ßdnΘ konstanty.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="classobj.examples" ></A >P°φklady</H1 ><P >
V tΘto ukßzce nejd°φve definujeme zßkladnφ t°φdu a roz╣φ°enφ tΘto t°φdy. Zßkladnφ t°φda popisuje obecnou zeleninu, a╗ u╛ je jedlß nebo ne a bez ohledu na jejφ barvu. Podt°φda <TT CLASS="varname" >Spenat</TT > p°idßvß metodu na uva°enφ tΘto zeleniny a dal╣φ, kterß zjistφ, jestli je va°enß. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11550" ></A ><P ><B >P°φklad 1. classes.inc</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // zßkladnφ t°φda s Φlensk²mi prom∞nn²mi a metodami class Zelenina { var $jedla; var $barva; function Zelenina( $jedla, $barva="green" ) { $this->jedla = $jedla; $this->barva = $barva; } function je_jedla() { return $this->jedla; } function jaka_barva() { return $this->barva; } } // konec t°φdy Zelenina // roz╣i°uje zßkladnφ t°φdu class Spenat extends Zelenina { var $varena = false; function Spenat() { $this->Zelenina( true, "zelena" ); } function cook_it() { $this->varena = true; } function je_varena() { return $this->varena; } } // konec t°φdy Spenat ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Potom z t∞chto t°φd vytvo°φme 2 objekty a vytiskneme informace o nich, vΦ. rodiΦovsk²ch t°φd. TakΘ definujeme n∞kterΘ pomocnΘ funkce, p°edev╣φm kv∙li pohodlnΘmu tisku informacφ. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11555" ></A ><P ><B >P°φklad 2. test_script.php</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><pre> <?php include "classes.inc"; // pomocnΘ funkce function vytiskni_promenne($obj) { $pole = get_object_vars($obj); while (list($vlastnost, $hodnota) = each($pole)) echo "\t$vlastnost = $hodnota\n"; } function vytiskni_metody($obj) { $pole = get_class_methods(get_class($obj)); foreach ($pole as $metoda) echo "\tfunction $metoda()\n"; } function class_parentage($obj, $class) { if (is_subclass_of($GLOBALS[$obj], $class)) { echo "Objekt $obj pat°φ do t°φdy ".get_class($$obj); echo ", kterß je podt°φdou $class\n"; } else { echo "Objekt $obj nepat°φ do podt°φdy t°φdy $class\n"; } } // instancujeme 2 objekty $zeleninka = new Zelenina(true,"modrß"); $listnaty = new Spenat(); // vytisknout informace o obou objektech echo "zeleninka: CLASS ".get_class($zeleninka)."\n"; echo "listnat²: CLASS ".get_class($listnaty); echo ", PARENT ".get_parent_class($listnaty)."\n"; // vytisknout vlastnosti zeleninky echo "\nzeleninka: Vlastnosti\n"; vytiskni_promenne($zeleninka); // a metody objektu listnat² echo "\nlistnat²: Metody\n"; vytiskni_metody($listnaty); echo "\nRodiΦ:\n"; class_parentage("listnaty", "Spenat"); class_parentage("listnaty", "Zelenina"); ?> </pre></PRE ></TD ></TR ></TABLE ><P >
Je t°eba poznamenat, ╛e ve v²╣e uvedenΘ ukßzce je objekt <TT CLASS="varname" >$listnaty</TT > instancφ t°φdy <B CLASS="classname" >Spenat</B >, kterß je podt°φdou t°φdy <B CLASS="classname" >Zelenina</B >, a poslednφ Φßst v²╣e uvedenΘho skriptu tudφ╛ vytiskne: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >[...] RodiΦ: Objekt listnaty nepat°φ do podt°φdy t°φdy Spenat Object listnaty pat°φ do t°φdy Spenat, kterß je podt°φdou Zelenina</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.call-user-method-array" >call_user_method_array</A > -- Call a user method given with an array of parameters [deprecated] </DT ><DT ><A HREF="#function.call-user-method" >call_user_method</A > -- Zavolat u╛ivatelsky definouvanou metodu urΦitΘho objektu </DT ><DT ><A HREF="#function.class-exists" >class_exists</A > -- Zjistit, jestli je t°φda definovßna</DT ><DT ><A HREF="#function.get-class-methods" >get_class_methods</A > -- Vrßtit pole nßzv∙ metod t°φdy</DT ><DT ><A HREF="#function.get-class-vars" >get_class_vars</A > -- Vrßtit pole defaultnφch vlastnostφ t°φdy</DT ><DT ><A HREF="#function.get-class" >get_class</A > -- Vrßtit jmΘno t°φdy objektu</DT ><DT ><A HREF="#function.get-declared-classes" >get_declared_classes</A > -- Vrßtit pole nßzv∙ definovan²ch t°φd</DT ><DT ><A HREF="#function.get-object-vars" >get_object_vars</A > -- Vrßtit asociativnφ pole vlastnostφ objektu</DT ><DT ><A HREF="#function.get-parent-class" >get_parent_class</A > -- Vrßtit nßzev rodiΦovskΘ t°φdy objektu</DT ><DT ><A HREF="#function.is-a" >is_a</A > -- Returns <TT CLASS="constant" ><B >TRUE</B ></TT > if the object is of this class or has this class as one of its parents </DT ><DT ><A HREF="#function.is-subclass-of" >is_subclass_of</A > -- Zjistit, jestli objekt pat°φ do podt°φdy urΦitΘ t°φdy </DT ><DT ><A HREF="#function.method-exists" >method_exists</A > -- Zjistit, jestli mß t°φda urΦitou metodu</DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.call-user-method-array" ></A >call_user_method_array</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11564" ></A ><P > (PHP 4 >= 4.0.5)</P >call_user_method_array -- Call a user method given with an array of parameters [deprecated] </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11567" ></A ><H2 >Description</H2 >mixed <B CLASS="methodname" >call_user_method_array</B > ( string method_name, object obj [, array paramarr])<BR ></BR ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >
The <B CLASS="function" >call_user_method_array()</B > function is deprecated as of PHP 4.1.0, use the <A HREF="#function.call-user-func-array" ><B CLASS="function" >call_user_func_array()</B ></A > variety with the <TT CLASS="literal" >array(&$obj, "method_name")</TT > syntax instead. </P ></TD ></TR ></TABLE ></DIV ><P >
Calls the method referred by <TT CLASS="parameter" ><I >method_name</I ></TT > from the user defined <TT CLASS="parameter" ><I >obj</I ></TT > object, using the parameters in <TT CLASS="parameter" ><I >paramarr</I ></TT >. </P ><P >
See also: <A HREF="#function.call-user-func-array" ><B CLASS="function" >call_user_func_array()</B ></A >, and <A HREF="#function.call-user-func" ><B CLASS="function" >call_user_func()</B ></A >. </P ></DIV ><H1 ><A NAME="function.call-user-method" ></A >call_user_method</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11594" ></A ><P > (PHP 3>= 3.0.3, PHP 4 )</P >call_user_method -- Zavolat u╛ivatelsky definouvanou metodu urΦitΘho objektu </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11597" ></A ><H2 >Popis</H2 >mixed <B CLASS="methodname" >call_user_method</B > ( string method_name, object obj [, mixed parameter [, mixed ...]])<BR ></BR ><P >
Zavolß metodu <TT CLASS="parameter" ><I >method_name</I ></TT > objektu <TT CLASS="parameter" ><I >obj</I ></TT >. Ukßzka vyu╛itφ je nφ╛e, kde definujeme t°φdu, vytvo°φme objekt a pou╛ijeme <B CLASS="function" >call_user_method()</B > k nep°φmΘmu volßnφ jejφ <TT CLASS="varname" >print_info</TT > metody. <DIV CLASS="informalexample" ><A NAME="AEN11619" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class Country { var $NAME; var $TLD; function Country($name, $tld) { $this->NAME = $name; $this->TLD = $tld; } function print_info($prestr="") { echo $prestr."Country: ".$this->NAME."\n"; echo $prestr."Top Level Domain: ".$this->TLD."\n"; } } $cntry = new Country("Peru","pe"); echo "* Calling the object method directly\n"; $cntry->print_info(); echo "\n* Calling the same method indirectly\n"; call_user_method ("print_info", $cntry, "\t"); ?></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P >
Viz takΘ <A HREF="#function.call-user-func" ><B CLASS="function" >call_user_func()</B ></A >. </P ></DIV ><H1 ><A NAME="function.class-exists" ></A >class_exists</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11624" ></A ><P > (PHP 4 )</P >class_exists -- Zjistit, jestli je t°φda definovßna</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11627" ></A ><H2 >Popis</H2 >bool <B CLASS="methodname" >class_exists</B > ( string class_name)<BR ></BR ><P >
Tato funkce vrßtφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud je t°φda <TT CLASS="parameter" ><I >class_name</I ></TT > definovßna, jinak <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ></DIV ><H1 ><A NAME="function.get-class-methods" ></A >get_class_methods</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11640" ></A ><P > (PHP 4 )</P >get_class_methods -- Vrßtit pole nßzv∙ metod t°φdy</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11643" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >get_class_methods</B > ( string class_name)<BR ></BR ><P >
Tato funkce vracφ pole nßzv∙ metod definovan²ch pro t°φdu specifikovanou argumentem <TT CLASS="parameter" ><I >class_name</I ></TT >. </P ><P >
Viz takΘ <A HREF="#function.get-class-vars" ><B CLASS="function" >get_class_vars()</B ></A >, <A HREF="#function.get-object-vars" ><B CLASS="function" >get_object_vars()</B ></A > </P ></DIV ><H1 ><A NAME="function.get-class-vars" ></A >get_class_vars</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11657" ></A ><P > (PHP 4 )</P >get_class_vars -- Vrßtit pole defaultnφch vlastnostφ t°φdy</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11660" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >get_class_vars</B > ( string class_name)<BR ></BR ><P >
Tato funkce vracφ pole defaultnφch vlastnostφ t°φdy <TT CLASS="parameter" ><I >class_name</I ></TT >. </P ><P >
Viz takΘ <A HREF="#function.get-class-methods" ><B CLASS="function" >get_class_methods()</B ></A >, <A HREF="#function.get-object-vars" ><B CLASS="function" >get_object_vars()</B ></A > </P ></DIV ><H1 ><A NAME="function.get-class" ></A >get_class</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11674" ></A ><P > (PHP 4 )</P >get_class -- Vrßtit jmΘno t°φdy objektu</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11677" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >get_class</B > ( object obj)<BR ></BR ><P >
Tato funkce vracφ nßzev t°φdy jφ╛ je objekt <TT CLASS="parameter" ><I >obj</I ></TT > instancφ. </P ><P >
Viz takΘ <A HREF="#function.get-parent-class" ><B CLASS="function" >get_parent_class()</B ></A >, <A HREF="#function.is-subclass-of" ><B CLASS="function" >is_subclass_of()</B ></A > </P ></DIV ><H1 ><A NAME="function.get-declared-classes" ></A >get_declared_classes</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11691" ></A ><P > (PHP 4 )</P >get_declared_classes -- Vrßtit pole nßzv∙ definovan²ch t°φd</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11694" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >get_declared_classes</B > ( void )<BR ></BR ><P >
Tato funkce vracφ pole nßzv∙ t°φd definovan²ch v souΦasnΘm skriptu. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > V PHP 4.0.1pl2 jsou na zaΦßtku pole vrßceny je╣t∞ t°i dal╣φ t°φdy: <B CLASS="classname" >stdClass</B > (definovanß v <TT CLASS="filename" >Zend/zend.c</TT >), <B CLASS="classname" >OverloadedTestClass</B > (definovanß v <TT CLASS="filename" >ext/standard/basic_functions.c</TT >) a <B CLASS="classname" >Directory</B > (definovanß v <TT CLASS="filename" >ext/standard/dir.c</TT >). </P ></BLOCKQUOTE ></DIV ></DIV ><H1 ><A NAME="function.get-object-vars" ></A >get_object_vars</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11710" ></A ><P > (PHP 4 )</P >get_object_vars -- Vrßtit asociativnφ pole vlastnostφ objektu</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11713" ></A ><H2 >Popis</H2 >array <B CLASS="methodname" >get_object_vars</B > ( object obj)<BR ></BR ><P >
Tato funkce vracφ asociativnφ pole definovan²ch vlastnostφ objektu <TT CLASS="parameter" ><I >obj</I ></TT >. Prom∞nn²m deklarovan²m v t°φd∞ jφ╛ je <TT CLASS="parameter" ><I >obj</I ></TT > instancφ, kter²m nebyla p°i°azena hodnota, nejsou ve vrßcenΘm poli obsa╛eny. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11724" ></A ><P ><B >P°φklad 1. Pou╛itφ <B CLASS="function" >get_object_vars()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php class Point2D { var $x, $y; var $label; function Point2D($x, $y) { $this->x = $x; $this->y = $y; } function setLabel($label) { $this->label = $label; } function getPoint() { return array("x" => $this->x, "y" => $this->y, "label" => $this->label); } } $p1 = new Point2D(1.233, 3.445); print_r(get_object_vars($p1)); // "$label" is declared but not defined // Array // ( // [x] => 1.233 // [y] => 3.445 // ) $p1->setLabel("point #1"); print_r(get_object_vars($p1)); // Array // ( // [x] => 1.233 // [y] => 3.445 // [label] => point #1 // ) ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
Viz takΘ <A HREF="#function.get-class-methods" ><B CLASS="function" >get_class_methods()</B ></A >, <A HREF="#function.get-class-vars" ><B CLASS="function" >get_class_vars()</B ></A > </P ></DIV ><H1 ><A NAME="function.get-parent-class" ></A >get_parent_class</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11732" ></A ><P > (PHP 4 )</P >get_parent_class -- Vrßtit nßzev rodiΦovskΘ t°φdy objektu</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11735" ></A ><H2 >Popis</H2 >string <B CLASS="methodname" >get_parent_class</B > ( object obj)<BR ></BR ><P >
Tato funkce vracφ nßzev rodiΦovskΘ t°φdy objektu <TT CLASS="parameter" ><I >obj</I ></TT >. </P ><P >
Viz takΘ <A HREF="#function.get-class" ><B CLASS="function" >get_class()</B ></A >, <A HREF="#function.is-subclass-of" ><B CLASS="function" >is_subclass_of()</B ></A > </P ></DIV ><H1 ><A NAME="function.is-a" ></A >is_a</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11749" ></A ><P > (PHP 4 >= 4.2.0)</P >is_a -- Returns <TT CLASS="constant" ><B >TRUE</B ></TT > if the object is of this class or has this class as one of its parents </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11753" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >is_a</B > ( object object, string class_name)<BR ></BR ><P >
This function returns <TT CLASS="constant" ><B >TRUE</B ></TT > if the object is of this class or has this class as one of its parents, <TT CLASS="constant" ><B >FALSE</B ></TT > otherwise. </P ><P >
See also <A HREF="#function.get-class" ><B CLASS="function" >get_class()</B ></A >, <A HREF="#function.get-parent-class" ><B CLASS="function" >get_parent_class()</B ></A >, and <A HREF="#function.is-subclass-of" ><B CLASS="function" >is_subclass_of()</B ></A >. </P ></DIV ><H1 ><A NAME="function.is-subclass-of" ></A >is_subclass_of</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11772" ></A ><P > (PHP 4 )</P >is_subclass_of -- Zjistit, jestli objekt pat°φ do podt°φdy urΦitΘ t°φdy </DIV ><DIV CLASS="refsect1" ><A NAME="AEN11775" ></A ><H2 >Popis</H2 >bool <B CLASS="methodname" >is_subclass_of</B > ( object obj, string superclass)<BR ></BR ><P >
Tato funkce vracφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud je objekt <TT CLASS="parameter" ><I >obj</I ></TT > instancφ t°φdy, kterß je podt°φdou <TT CLASS="parameter" ><I >superclass</I ></TT >, jinak <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ><P >
Viz takΘ <A HREF="#function.get-class" ><B CLASS="function" >get_class()</B ></A >, <A HREF="#function.get-parent-class" ><B CLASS="function" >get_parent_class()</B ></A > </P ></DIV ><H1 ><A NAME="function.method-exists" ></A >method_exists</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11795" ></A ><P > (PHP 4 )</P >method_exists -- Zjistit, jestli mß t°φda urΦitou metodu</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11798" ></A ><H2 >Popis</H2 >bool <B CLASS="methodname" >method_exists</B > ( object object, string method_name)<BR ></BR ><P >
Tato funkce vracφ <TT CLASS="constant" ><B >TRUE</B ></TT >, pokud mß <TT CLASS="parameter" ><I >object</I ></TT > definovßnu metodu <TT CLASS="parameter" ><I >method_name</I ></TT >, jinak <TT CLASS="constant" ><B >FALSE</B ></TT >. </P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.cpdf" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >X. ClibPDF functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN11817" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.intro" ></A >┌vod</H1 ><P >
ClibPDF lets you create PDF documents with PHP. ClibPDF functionality and API are similar to <A HREF="#ref.pdf" >PDFlib</A >. This documentation should be read alongside the ClibPDF manual since it explains the library in much greater detail. </P ><P >
Many functions in the native ClibPDF and the PHP module, as well as in <A HREF="#ref.pdf" >PDFlib</A >, have the same name. All functions except for <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A > take the handle for the document as their first parameter. </P ><P >
Currently this handle is not used internally since ClibPDF does not support the creation of several PDF documents at the same time. Actually, you should not even try it, the results are unpredictable. I can't oversee what the consequences in a multi threaded environment are. According to the author of ClibPDF this will change in one of the next releases (current version when this was written is 1.10). If you need this functionality use the pdflib module. </P ><P >
A nice feature of ClibPDF (and <A HREF="#ref.pdf" >PDFlib</A >) is the ability to create the pdf document completely in memory without using temporary files. It also provides the ability to pass coordinates in a predefined unit length. (This feature can also be simulated by <A HREF="#function.pdf-translate" ><B CLASS="function" >pdf_translate()</B ></A > when using the <A HREF="#ref.pdf" >PDFlib</A > functions.) </P ><P >
Another nice feature of ClibPDF is the fact that any page can be modified at any time even if a new page has been already opened. The function <A HREF="#function.cpdf-set-current-page" ><B CLASS="function" >cpdf_set_current_page()</B ></A > allows to leave the current page and presume modifying an other page. </P ><P >
Most of the functions are fairly easy to use. The most difficult part is probably creating a very simple PDF document at all. The following example should help you to get started. It creates a document with one page. The page contains the text "Times-Roman" in an outlined 30pt font. The text is underlined. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > If you're interested in alternative free PDF generators that do not utilize external PDF libraries, see <A HREF="#faq.using.freepdf" >
this related FAQ</A >. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="cpdf.requirements" ></A >Po╛adavky</H1 ><P >
In order to use the ClibPDF functions you need to install the ClibPDF package. It is available for download from <A HREF="http://www.fastio.com/" TARGET="_top" >
FastIO</A >, but requires that you purchase a license for commercial use. PHP requires that you use cpdflib >= 2. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="cpdf.installation" ></A >Instalace</H1 ><P >
To get these functions to work, you have to compile PHP with <TT CLASS="option" >--with-cpdflib[=DIR]</TT >. DIR is the cpdflib install directory, defaults to <TT CLASS="filename" >/usr</TT >. In addition you can specify the jpeg library and the tiff library for ClibPDF to use. To do so add to your configure line the options <TT CLASS="option" >--with-jpeg-dir[=DIR]</TT > <TT CLASS="option" >--with-tiff-dir[=DIR]</TT >. </P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="cpdf.configuration" ></A >Konfigurace b∞hu</H1 ><P >Toto roz╣φ°enφ nemß definovßno ╛ßdnΘ konfiguraΦnφ direktivy.</P ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="cpdf.constants" ></A >P°eddefinovanΘ konstanty</H1 ><P >
Tyto konstanty jsou definovßny tφmto roz╣φ°enφm a budou k dispozici pouze tehdy, bylo-li roz╣φ°enφ zkompilovßno spoleΦn∞ s PHP nebo dynamicky zavedeno za b∞hu. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CPDF_PM_NONE</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PM_OUTLINES</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PM_THUMBS</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PM_FULLSCREEN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_SINGLE</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_1COLUMN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_2LCOLUMN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_2RCOLUMN</B ></TT > (<A HREF="#language.types.integer" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P >
</P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="cpdf.examples" ></A >P°φklady</H1 ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11904" ></A ><P ><B >P°φklad 1. Simple ClibPDF Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $cpdf = cpdf_open(0); cpdf_page_init($cpdf, 1, 0, 595, 842, 1.0); cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1"); cpdf_begin_text($cpdf); cpdf_set_font($cpdf, "Times-Roman", 30, "WinAnsiEncoding"); cpdf_set_text_rendering($cpdf, 1); cpdf_text($cpdf, "Times Roman outlined", 50, 750); cpdf_end_text($cpdf); cpdf_moveto($cpdf, 50, 740); cpdf_lineto($cpdf, 330, 740); cpdf_stroke($cpdf); cpdf_finalize($cpdf); Header("Content-type: application/pdf"); cpdf_output_buffer($cpdf); cpdf_close($cpdf); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >
The pdflib distribution contains a more complex example which creates a series of pages with an analog clock. Here is that example converted into PHP using the ClibPDF extension: </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11908" ></A ><P ><B >P°φklad 2. pdfclock example from pdflib 2.0 distribution</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $radius = 200; $margin = 20; $pagecount = 40; $pdf = cpdf_open(0); cpdf_set_creator($pdf, "pdf_clock.php3"); cpdf_set_title($pdf, "Analog Clock"); while ($pagecount-- > 0) { cpdf_page_init($pdf, $pagecount+1, 0, 2 * ($radius + $margin), 2 * ($radius + $margin), 1.0); cpdf_set_page_animation($pdf, 4, 0.5, 0, 0, 0); /* wipe */ cpdf_translate($pdf, $radius + $margin, $radius + $margin); cpdf_save($pdf); cpdf_setrgbcolor($pdf, 0.0, 0.0, 1.0); /* minute strokes */ cpdf_setlinewidth($pdf, 2.0); for ($alpha = 0; $alpha < 360; $alpha += 6) { cpdf_rotate($pdf, 6.0); cpdf_moveto($pdf, $radius, 0.0); cpdf_lineto($pdf, $radius-$margin/3, 0.0); cpdf_stroke($pdf); } cpdf_restore($pdf); cpdf_save($pdf); /* 5 minute strokes */ cpdf_setlinewidth($pdf, 3.0); for ($alpha = 0; $alpha < 360; $alpha += 30) { cpdf_rotate($pdf, 30.0); cpdf_moveto($pdf, $radius, 0.0); cpdf_lineto($pdf, $radius-$margin, 0.0); cpdf_stroke($pdf); } $ltime = getdate(); /* draw hour hand */ cpdf_save($pdf); cpdf_rotate($pdf, -(($ltime['minutes']/60.0) + $ltime['hours'] - 3.0) * 30.0); cpdf_moveto($pdf, -$radius/10, -$radius/20); cpdf_lineto($pdf, $radius/2, 0.0); cpdf_lineto($pdf, -$radius/10, $radius/20); cpdf_closepath($pdf); cpdf_fill($pdf); cpdf_restore($pdf); /* draw minute hand */ cpdf_save($pdf); cpdf_rotate($pdf, -(($ltime['seconds']/60.0) + $ltime['minutes'] - 15.0) * 6.0); cpdf_moveto($pdf, -$radius/10, -$radius/20); cpdf_lineto($pdf, $radius * 0.8, 0.0); cpdf_lineto($pdf, -$radius/10, $radius/20); cpdf_closepath($pdf); cpdf_fill($pdf); cpdf_restore($pdf); /* draw second hand */ cpdf_setrgbcolor($pdf, 1.0, 0.0, 0.0); cpdf_setlinewidth($pdf, 2); cpdf_save($pdf); cpdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0)); cpdf_moveto($pdf, -$radius/5, 0.0); cpdf_lineto($pdf, $radius, 0.0); cpdf_stroke($pdf); cpdf_restore($pdf); /* draw little circle at center */ cpdf_circle($pdf, 0, 0, $radius/30); cpdf_fill($pdf); cpdf_restore($pdf); cpdf_finalize_page($pdf, $pagecount+1); } cpdf_finalize($pdf); Header("Content-type: application/pdf"); cpdf_output_buffer($pdf); cpdf_close($pdf); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="section" ><HR><H1 CLASS="section" ><A NAME="cpdf.seealso" ></A >Viz takΘ</H1 ><P >
See also the <A HREF="#ref.pdf" >PDFlib</A > extension documentation. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Obsah</B ></DT ><DT ><A HREF="#function.cpdf-add-annotation" >cpdf_add_annotation</A > -- Adds annotation</DT ><DT ><A HREF="#function.cpdf-add-outline" >cpdf_add_outline</A > -- Adds bookmark for current page</DT ><DT ><A HREF="#function.cpdf-arc" >cpdf_arc</A > -- Draws an arc</DT ><DT ><A HREF="#function.cpdf-begin-text" >cpdf_begin_text</A > -- Starts text section</DT ><DT ><A HREF="#function.cpdf-circle" >cpdf_circle</A > -- Draw a circle</DT ><DT ><A HREF="#function.cpdf-clip" >cpdf_clip</A > -- Clips to current path</DT ><DT ><A HREF="#function.cpdf-close" >cpdf_close</A > -- Closes the pdf document</DT ><DT ><A HREF="#function.cpdf-closepath-fill-stroke" >cpdf_closepath_fill_stroke</A > -- Close, fill and stroke current path</DT ><DT ><A HREF="#function.cpdf-closepath-stroke" >cpdf_closepath_stroke</A > -- Close path and draw line along path</DT ><DT ><A HREF="#function.cpdf-closepath" >cpdf_closepath</A > -- Close path</DT ><DT ><A HREF="#function.cpdf-continue-text" >cpdf_continue_text</A > -- Output text in next line</DT ><DT ><A HREF="#function.cpdf-curveto" >cpdf_curveto</A > -- Draws a curve</DT ><DT ><A HREF="#function.cpdf-end-text" >cpdf_end_text</A > -- Ends text section</DT ><DT ><A HREF="#function.cpdf-fill-stroke" >cpdf_fill_stroke</A > -- Fill and stroke current path</DT ><DT ><A HREF="#function.cpdf-fill" >cpdf_fill</A > -- Fill current path</DT ><DT ><A HREF="#function.cpdf-finalize-page" >cpdf_finalize_page</A > -- Ends page</DT ><DT ><A HREF="#function.cpdf-finalize" >cpdf_finalize</A > -- Ends document</DT ><DT ><A HREF="#function.cpdf-global-set-document-limits" >cpdf_global_set_document_limits</A > -- Sets document limits for any pdf document</DT ><DT ><A HREF="#function.cpdf-import-jpeg" >cpdf_import_jpeg</A > -- Opens a JPEG image</DT ><DT ><A HREF="#function.cpdf-lineto" >cpdf_lineto</A > -- Draws a line</DT ><DT ><A HREF="#function.cpdf-moveto" >cpdf_moveto</A > -- Sets current point</DT ><DT ><A HREF="#function.cpdf-newpath" >cpdf_newpath</A > -- Starts a new path</DT ><DT ><A HREF="#function.cpdf-open" >cpdf_open</A > -- Opens a new pdf document</DT ><DT ><A HREF="#function.cpdf-output-buffer" >cpdf_output_buffer</A > -- Outputs the pdf document in memory buffer</DT ><DT ><A HREF="#function.cpdf-page-init" >cpdf_page_init</A > -- Starts new page</DT ><DT ><A HREF="#function.cpdf-place-inline-image" >cpdf_place_inline_image</A > -- Places an image on the page</DT ><DT ><A HREF="#function.cpdf-rect" >cpdf_rect</A > -- Draw a rectangle</DT ><DT ><A HREF="#function.cpdf-restore" >cpdf_restore</A > -- Restores formerly saved environment</DT ><DT ><A HREF="#function.cpdf-rlineto" >cpdf_rlineto</A > -- Draws a line</DT ><DT ><A HREF="#function.cpdf-rmoveto" >cpdf_rmoveto</A > -- Sets current point</DT ><DT ><A HREF="#function.cpdf-rotate-text" >cpdf_rotate_text</A > -- Sets text rotation angle </DT ><DT ><A HREF="#function.cpdf-rotate" >cpdf_rotate</A > -- Sets rotation</DT ><DT ><A HREF="#function.cpdf-save-to-file" >cpdf_save_to_file</A > -- Writes the pdf document into a file</DT ><DT ><A HREF="#function.cpdf-save" >cpdf_save</A > -- Saves current environment</DT ><DT ><A HREF="#function.cpdf-scale" >cpdf_scale</A > -- Sets scaling</DT ><DT ><A HREF="#function.cpdf-set-action-url" >cpdf_set_action_url</A > -- Sets hyperlink </DT ><DT ><A HREF="#function.cpdf-set-char-spacing" >cpdf_set_char_spacing</A > -- Sets character spacing</DT ><DT ><A HREF="#function.cpdf-set-creator" >cpdf_set_creator</A > -- Sets the creator field in the pdf document</DT ><DT ><A HREF="#function.cpdf-set-current-page" >cpdf_set_current_page</A > -- Sets current page</DT ><DT ><A HREF="#function.cpdf-set-font-directories" >cpdf_set_font_directories</A > -- Sets directories to search when using external fonts </DT ><DT ><A HREF="#function.cpdf-set-font-map-file" >cpdf_set_font_map_file</A > -- Sets fontname to filename translation map when using external fonts </DT ><DT ><A HREF="#function.cpdf-set-font" >cpdf_set_font</A > -- Select the current font face and size</DT ><DT ><A HREF="#function.cpdf-set-horiz-scaling" >cpdf_set_horiz_scaling</A > -- Sets horizontal scaling of text</DT ><DT ><A HREF="#function.cpdf-set-keywords" >cpdf_set_keywords</A > -- Sets the keywords field of the pdf document</DT ><DT ><A HREF="#function.cpdf-set-leading" >cpdf_set_leading</A > -- Sets distance between text lines</DT ><DT ><A HREF="#function.cpdf-set-page-animation" >cpdf_set_page_animation</A > -- Sets duration between pages</DT ><DT ><A HREF="#function.cpdf-set-subject" >cpdf_set_subject</A > -- Sets the subject field of the pdf document</DT ><DT ><A HREF="#function.cpdf-set-text-matrix" >cpdf_set_text_matrix</A > -- Sets the text matrix</DT ><DT ><A HREF="#function.cpdf-set-text-pos" >cpdf_set_text_pos</A > -- Sets text position</DT ><DT ><A HREF="#function.cpdf-set-text-rendering" >cpdf_set_text_rendering</A > -- Determines how text is rendered</DT ><DT ><A HREF="#function.cpdf-set-text-rise" >cpdf_set_text_rise</A > -- Sets the text rise</DT ><DT ><A HREF="#function.cpdf-set-title" >cpdf_set_title</A > -- Sets the title field of the pdf document</DT ><DT ><A HREF="#function.cpdf-set-viewer-preferences" >cpdf_set_viewer_preferences</A > -- How to show the document in the viewer </DT ><DT ><A HREF="#function.cpdf-set-word-spacing" >cpdf_set_word_spacing</A > -- Sets spacing between words</DT ><DT ><A HREF="#function.cpdf-setdash" >cpdf_setdash</A > -- Sets dash pattern</DT ><DT ><A HREF="#function.cpdf-setflat" >cpdf_setflat</A > -- Sets flatness</DT ><DT ><A HREF="#function.cpdf-setgray-fill" >cpdf_setgray_fill</A > -- Sets filling color to gray value</DT ><DT ><A HREF="#function.cpdf-setgray-stroke" >cpdf_setgray_stroke</A > -- Sets drawing color to gray value</DT ><DT ><A HREF="#function.cpdf-setgray" >cpdf_setgray</A > -- Sets drawing and filling color to gray value</DT ><DT ><A HREF="#function.cpdf-setlinecap" >cpdf_setlinecap</A > -- Sets linecap parameter</DT ><DT ><A HREF="#function.cpdf-setlinejoin" >cpdf_setlinejoin</A > -- Sets linejoin parameter</DT ><DT ><A HREF="#function.cpdf-setlinewidth" >cpdf_setlinewidth</A > -- Sets line width</DT ><DT ><A HREF="#function.cpdf-setmiterlimit" >cpdf_setmiterlimit</A > -- Sets miter limit</DT ><DT ><A HREF="#function.cpdf-setrgbcolor-fill" >cpdf_setrgbcolor_fill</A > -- Sets filling color to rgb color value</DT ><DT ><A HREF="#function.cpdf-setrgbcolor-stroke" >cpdf_setrgbcolor_stroke</A > -- Sets drawing color to rgb color value</DT ><DT ><A HREF="#function.cpdf-setrgbcolor" >cpdf_setrgbcolor</A > -- Sets drawing and filling color to rgb color value</DT ><DT ><A HREF="#function.cpdf-show-xy" >cpdf_show_xy</A > -- Output text at position</DT ><DT ><A HREF="#function.cpdf-show" >cpdf_show</A > -- Output text at current position</DT ><DT ><A HREF="#function.cpdf-stringwidth" >cpdf_stringwidth</A > -- Returns width of text in current font</DT ><DT ><A HREF="#function.cpdf-stroke" >cpdf_stroke</A > -- Draw line along path</DT ><DT ><A HREF="#function.cpdf-text" >cpdf_text</A > -- Output text with parameters</DT ><DT ><A HREF="#function.cpdf-translate" >cpdf_translate</A > -- Sets origin of coordinate system</DT ></DL ></DIV ></DIV ><H1 ><A NAME="function.cpdf-add-annotation" ></A >cpdf_add_annotation</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11916" ></A ><P > (PHP 3>= 3.0.12, PHP 4 )</P >cpdf_add_annotation -- Adds annotation</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11919" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_add_annotation</B > ( int pdf_document, float llx, float lly, float urx, float ury, string title, string content [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_add_annotation()</B > adds a note with the lower left corner at (<TT CLASS="parameter" ><I >llx</I ></TT >, <TT CLASS="parameter" ><I >lly</I ></TT >) and the upper right corner at (<TT CLASS="parameter" ><I >urx</I ></TT >, <TT CLASS="parameter" ><I >ury</I ></TT >). Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ></DIV ><H1 ><A NAME="function.cpdf-add-outline" ></A >cpdf_add_outline</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11959" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_add_outline -- Adds bookmark for current page</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11962" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >cpdf_add_outline</B > ( int pdf_document, int lastoutline, int sublevel, int open, int pagenr, string text)<BR ></BR ><P >
The <B CLASS="function" >cpdf_add_outline()</B > function adds a bookmark with text <TT CLASS="parameter" ><I >text</I ></TT > that points to the current page. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11989" ></A ><P ><B >P°φklad 1. Adding a page outline</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $cpdf = cpdf_open(0); cpdf_page_init($cpdf, 1, 0, 595, 842); cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1"); // ... // some drawing // ... cpdf_finalize($cpdf); Header("Content-type: application/pdf"); cpdf_output_buffer($cpdf); cpdf_close($cpdf); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.cpdf-arc" ></A >cpdf_arc</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN11993" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_arc -- Draws an arc</DIV ><DIV CLASS="refsect1" ><A NAME="AEN11996" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_arc</B > ( int pdf_document, float x-coor, float y-coor, float radius, float start, float end [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_arc()</B > function draws an arc with center at point (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >) and radius <TT CLASS="parameter" ><I >radius</I ></TT >, starting at angle <TT CLASS="parameter" ><I >start</I ></TT > and ending at angle <TT CLASS="parameter" ><I >end</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-circle" ><B CLASS="function" >cpdf_circle()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-begin-text" ></A >cpdf_begin_text</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12036" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_begin_text -- Starts text section</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12039" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_begin_text</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_begin_text()</B > function starts a text section. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. The created text section must be ended with <A HREF="#function.cpdf-end-text" ><B CLASS="function" >cpdf_end_text()</B ></A >. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN12053" ></A ><P ><B >P°φklad 1. Text output</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php cpdf_begin_text($pdf); cpdf_set_font($pdf, 16, "Helvetica", "WinAnsiEncoding"); cpdf_text($pdf, 100, 100, "Some text"); cpdf_end_text($pdf) ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.cpdf-end-text" ><B CLASS="function" >cpdf_end_text()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-circle" ></A >cpdf_circle</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12059" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_circle -- Draw a circle</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12062" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_circle</B > ( int pdf_document, float x-coor, float y-coor, float radius [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_circle()</B > function draws a circle with center at point (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >) and radius <TT CLASS="parameter" ><I >radius</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-arc" ><B CLASS="function" >cpdf_arc()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-clip" ></A >cpdf_clip</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12094" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_clip -- Clips to current path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12097" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_clip</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_clip()</B > function clips all drawing to the current path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-close" ></A >cpdf_close</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12110" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_close -- Closes the pdf document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12113" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_close</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_close()</B > function closes the pdf document. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. This should be the last function even after <A HREF="#function.cpdf-finalize" ><B CLASS="function" >cpdf_finalize()</B ></A >, <A HREF="#function.cpdf-output-buffer" ><B CLASS="function" >cpdf_output_buffer()</B ></A > and <A HREF="#function.cpdf-save-to-file" ><B CLASS="function" >cpdf_save_to_file()</B ></A >. </P ><P >
See also <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-closepath-fill-stroke" ></A >cpdf_closepath_fill_stroke</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12131" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_closepath_fill_stroke -- Close, fill and stroke current path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12134" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_closepath_fill_stroke</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_closepath_fill_stroke()</B > function closes, fills the interior of the current path with the current fill color and draws current path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-closepath" ><B CLASS="function" >cpdf_closepath()</B ></A >, <A HREF="#function.cpdf-stroke" ><B CLASS="function" >cpdf_stroke()</B ></A >, <A HREF="#function.cpdf-fill" ><B CLASS="function" >cpdf_fill()</B ></A >, <A HREF="#function.cpdf-setgray-fill" ><B CLASS="function" >cpdf_setgray_fill()</B ></A >, <A HREF="#function.cpdf-setgray" ><B CLASS="function" >cpdf_setgray()</B ></A >, <A HREF="#function.cpdf-setrgbcolor-fill" ><B CLASS="function" >cpdf_setrgbcolor_fill()</B ></A > and <A HREF="#function.cpdf-setrgbcolor" ><B CLASS="function" >cpdf_setrgbcolor()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-closepath-stroke" ></A >cpdf_closepath_stroke</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12155" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_closepath_stroke -- Close path and draw line along path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12158" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_closepath_stroke</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_closepath_stroke()</B > function is a combination of <A HREF="#function.cpdf-closepath" ><B CLASS="function" >cpdf_closepath()</B ></A > and <A HREF="#function.cpdf-stroke" ><B CLASS="function" >cpdf_stroke()</B ></A >. Then clears the path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-closepath" ><B CLASS="function" >cpdf_closepath()</B ></A > and <A HREF="#function.cpdf-stroke" ><B CLASS="function" >cpdf_stroke()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-closepath" ></A >cpdf_closepath</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12176" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_closepath -- Close path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12179" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_closepath</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_closepath()</B > function closes the current path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-continue-text" ></A >cpdf_continue_text</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12192" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_continue_text -- Output text in next line</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12195" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_continue_text</B > ( int pdf_document, string text)<BR ></BR ><P >
The <B CLASS="function" >cpdf_continue_text()</B > function outputs the string in <TT CLASS="parameter" ><I >text</I ></TT > in the next line. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-show-xy" ><B CLASS="function" >cpdf_show_xy()</B ></A >, <A HREF="#function.cpdf-text" ><B CLASS="function" >cpdf_text()</B ></A >, <A HREF="#function.cpdf-set-leading" ><B CLASS="function" >cpdf_set_leading()</B ></A > and <A HREF="#function.cpdf-set-text-pos" ><B CLASS="function" >cpdf_set_text_pos()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-curveto" ></A >cpdf_curveto</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12217" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_curveto -- Draws a curve</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12220" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_curveto</B > ( int pdf_document, float x1, float y1, float x2, float y2, float x3, float y3 [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_curveto()</B > function draws a Bezier curve from the current point to the point (<TT CLASS="parameter" ><I >x3</I ></TT >, <TT CLASS="parameter" ><I >y3</I ></TT >) using (<TT CLASS="parameter" ><I >x1</I ></TT >, <TT CLASS="parameter" ><I >y1</I ></TT >) and (<TT CLASS="parameter" ><I >x2</I ></TT >, <TT CLASS="parameter" ><I >y2</I ></TT >) as control points. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-moveto" ><B CLASS="function" >cpdf_moveto()</B ></A >, <A HREF="#function.cpdf-rmoveto" ><B CLASS="function" >cpdf_rmoveto()</B ></A >, <A HREF="#function.cpdf-rlineto" ><B CLASS="function" >cpdf_rlineto()</B ></A > and <A HREF="#function.cpdf-lineto" ><B CLASS="function" >cpdf_lineto()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-end-text" ></A >cpdf_end_text</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12267" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_end_text -- Ends text section</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12270" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_end_text</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_end_text()</B > function ends a text section which was started with <A HREF="#function.cpdf-begin-text" ><B CLASS="function" >cpdf_begin_text()</B ></A >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN12284" ></A ><P ><B >P°φklad 1. Text output</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php cpdf_begin_text($pdf); cpdf_set_font($pdf, 16, "Helvetica", "WinAnsiEncoding"); cpdf_text($pdf, 100, 100, "Some text"); cpdf_end_text($pdf) ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.cpdf-begin-text" ><B CLASS="function" >cpdf_begin_text()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-fill-stroke" ></A >cpdf_fill_stroke</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12290" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_fill_stroke -- Fill and stroke current path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12293" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_fill_stroke</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_fill_stroke()</B > function fills the interior of the current path with the current fill color and draws current path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-closepath" ><B CLASS="function" >cpdf_closepath()</B ></A >, <A HREF="#function.cpdf-stroke" ><B CLASS="function" >cpdf_stroke()</B ></A >, <A HREF="#function.cpdf-fill" ><B CLASS="function" >cpdf_fill()</B ></A >, <A HREF="#function.cpdf-setgray-fill" ><B CLASS="function" >cpdf_setgray_fill()</B ></A >, <A HREF="#function.cpdf-setgray" ><B CLASS="function" >cpdf_setgray()</B ></A >, <A HREF="#function.cpdf-setrgbcolor-fill" ><B CLASS="function" >cpdf_setrgbcolor_fill()</B ></A > and <A HREF="#function.cpdf-setrgbcolor" ><B CLASS="function" >cpdf_setrgbcolor()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-fill" ></A >cpdf_fill</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12314" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_fill -- Fill current path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12317" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_fill</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_fill()</B > function fills the interior of the current path with the current fill color. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-closepath" ><B CLASS="function" >cpdf_closepath()</B ></A >, <A HREF="#function.cpdf-stroke" ><B CLASS="function" >cpdf_stroke()</B ></A >, <A HREF="#function.cpdf-setgray-fill" ><B CLASS="function" >cpdf_setgray_fill()</B ></A >, <A HREF="#function.cpdf-setgray" ><B CLASS="function" >cpdf_setgray()</B ></A >, <A HREF="#function.cpdf-setrgbcolor-fill" ><B CLASS="function" >cpdf_setrgbcolor_fill()</B ></A > and <A HREF="#function.cpdf-setrgbcolor" ><B CLASS="function" >cpdf_setrgbcolor()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-finalize-page" ></A >cpdf_finalize_page</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12337" ></A ><P > (PHP 3>= 3.0.10, PHP 4 )</P >cpdf_finalize_page -- Ends page</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12340" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_finalize_page</B > ( int pdf_document, int page_number)<BR ></BR ><P >
The <B CLASS="function" >cpdf_finalize_page()</B > function ends the page with page number <TT CLASS="parameter" ><I >page_number</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
This function is only for saving memory. A finalized page takes less memory but cannot be modified anymore. </P ><P >
See also <A HREF="#function.cpdf-page-init" ><B CLASS="function" >cpdf_page_init()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-finalize" ></A >cpdf_finalize</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12360" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_finalize -- Ends document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12363" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_finalize</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_finalize()</B > function ends the document. You still have to call <A HREF="#function.cpdf-close" ><B CLASS="function" >cpdf_close()</B ></A >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-close" ><B CLASS="function" >cpdf_close()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-global-set-document-limits" ></A >cpdf_global_set_document_limits</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12379" ></A ><P > (PHP 4 )</P >cpdf_global_set_document_limits -- Sets document limits for any pdf document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12382" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_global_set_document_limits</B > ( int maxpages, int maxfonts, int maximages, int maxannotations, int maxobjects)<BR ></BR ><P >
The <B CLASS="function" >cpdf_global_set_document_limits()</B > function sets several document limits. This function has to be called before <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A > to take effect. It sets the limits for any document open afterwards. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-import-jpeg" ></A >cpdf_import_jpeg</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12410" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_import_jpeg -- Opens a JPEG image</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12413" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >cpdf_import_jpeg</B > ( int pdf_document, string file_name, float x-coor, float y-coor, float angle, float width, float height, float x-scale, float y-scale, int gsave [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_import_jpeg()</B > function opens an image stored in the file with the name <TT CLASS="parameter" ><I >file name</I ></TT >. The format of the image has to be jpeg. The image is placed on the current page at position (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). The image is rotated by <TT CLASS="parameter" ><I >angle</I ></TT > degrees. <TT CLASS="parameter" ><I >gsave</I ></TT > should be non-zero to allow this function to operate correctly. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-place-inline-image" ><B CLASS="function" >cpdf_place_inline_image()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-lineto" ></A >cpdf_lineto</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12463" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_lineto -- Draws a line</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12466" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_lineto</B > ( int pdf_document, float x-coor, float y-coor [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_lineto()</B > function draws a line from the current point to the point with coordinates (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-moveto" ><B CLASS="function" >cpdf_moveto()</B ></A >, <A HREF="#function.cpdf-rmoveto" ><B CLASS="function" >cpdf_rmoveto()</B ></A > and <A HREF="#function.cpdf-curveto" ><B CLASS="function" >cpdf_curveto()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-moveto" ></A >cpdf_moveto</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12496" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_moveto -- Sets current point</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12499" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_moveto</B > ( int pdf_document, float x-coor, float y-coor [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_moveto()</B > function set the current point to the coordinates <TT CLASS="parameter" ><I >x-coor</I ></TT > and <TT CLASS="parameter" ><I >y-coor</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ></DIV ><H1 ><A NAME="function.cpdf-newpath" ></A >cpdf_newpath</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12525" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_newpath -- Starts a new path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12528" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_newpath</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_newpath()</B > starts a new path on the document given by the <TT CLASS="parameter" ><I >pdf_document</I ></TT > parameter. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-open" ></A >cpdf_open</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12542" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_open -- Opens a new pdf document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12545" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >cpdf_open</B > ( int compression [, string filename])<BR ></BR ><P >
The <B CLASS="function" >cpdf_open()</B > function opens a new pdf document. The first parameter turns document compression on if it is unequal to 0. The second optional parameter sets the file in which the document is written. If it is omitted the document is created in memory and can either be written into a file with the <A HREF="#function.cpdf-save-to-file" ><B CLASS="function" >cpdf_save_to_file()</B ></A > or written to standard output with <A HREF="#function.cpdf-output-buffer" ><B CLASS="function" >cpdf_output_buffer()</B ></A >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The return value will be needed in further versions of ClibPDF as the first parameter in all other functions which are writing to the pdf document. </P ><P >
The ClibPDF library takes the filename "-" as a synonym for stdout. If PHP is compiled as an apache module this will not work because the way ClibPDF outputs to stdout does not work with apache. You can solve this problem by skipping the filename and using <A HREF="#function.cpdf-output-buffer" ><B CLASS="function" >cpdf_output_buffer()</B ></A > to output the pdf document. </P ></BLOCKQUOTE ></DIV > </P ><P >
See also <A HREF="#function.cpdf-close" ><B CLASS="function" >cpdf_close()</B ></A > and <A HREF="#function.cpdf-output-buffer" ><B CLASS="function" >cpdf_output_buffer()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-output-buffer" ></A >cpdf_output_buffer</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12568" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_output_buffer -- Outputs the pdf document in memory buffer</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12571" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_output_buffer</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_output_buffer()</B > function outputs the pdf document to stdout. The document has to be created in memory which is the case if <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A > has been called with no filename parameter. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-page-init" ></A >cpdf_page_init</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12587" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_page_init -- Starts new page</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12590" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_page_init</B > ( int pdf_document, int page_number, int orientation, float height, float width [, float unit])<BR ></BR ><P >
The <B CLASS="function" >cpdf_page_init()</B > function starts a new page with height <TT CLASS="parameter" ><I >height</I ></TT > and width <TT CLASS="parameter" ><I >width</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. The page has number <TT CLASS="parameter" ><I >page_number</I ></TT > and orientation <TT CLASS="parameter" ><I >orientation</I ></TT >. <TT CLASS="parameter" ><I >orientation</I ></TT > can be 0 for portrait and 1 for landscape. The last optional parameter <TT CLASS="parameter" ><I >unit</I ></TT > sets the unit for the coordinate system. The value should be the number of postscript points per unit. Since one inch is equal to 72 points, a value of 72 would set the unit to one inch. The default is also 72. </P ><P >
See also <A HREF="#function.cpdf-set-current-page" ><B CLASS="function" >cpdf_set_current_page()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-place-inline-image" ></A >cpdf_place_inline_image</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12626" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_place_inline_image -- Places an image on the page</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12629" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_place_inline_image</B > ( int pdf_document, int image, float x-coor, float y-coor, float angle, float width, float height [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_place_inline_image()</B > function places an image created with the PHP image functions on the page at position (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). The image can be scaled at the same time. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-import-jpeg" ><B CLASS="function" >cpdf_import_jpeg()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-rect" ></A >cpdf_rect</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12669" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_rect -- Draw a rectangle</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12672" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_rect</B > ( int pdf_document, float x-coor, float y-coor, float width, float height [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_rect()</B > function draws a rectangle with its lower left corner at point (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). This width is set to <TT CLASS="parameter" ><I >width</I ></TT >. This height is set to <TT CLASS="parameter" ><I >height</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN12706" ></A ><P ><B >P°φklad 1. Drawing a rectangle</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $cpdf = cpdf_open(0); cpdf_page_init($cpdf, 1, 0, 595, 842, 1.0); // set the fill color to red cpdf_setrgbcolor($cpdf, 1, 0, 0); // draw a (180 * 100) rectangle cpdf_rect($cpdf, 645, 400, 180, 100); // fill the rectangle cpdf_fill($cpdf); cpdf_finalize($cpdf); Header("Content-type: application/pdf"); cpdf_output_buffer($cpdf); cpdf_close($cpdf); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><H1 ><A NAME="function.cpdf-restore" ></A >cpdf_restore</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12710" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_restore -- Restores formerly saved environment</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12713" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_restore</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_restore()</B > function restores the environment saved with <A HREF="#function.cpdf-save" ><B CLASS="function" >cpdf_save()</B ></A >. It works like the postscript command grestore. Very useful if you want to translate or rotate an object without effecting other objects. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN12727" ></A ><P ><B >P°φklad 1. Save/Restore</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php cpdf_save($pdf); // do all kinds of rotations, transformations, ... cpdf_restore($pdf) ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P >
See also <A HREF="#function.cpdf-save" ><B CLASS="function" >cpdf_save()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-rlineto" ></A >cpdf_rlineto</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12733" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_rlineto -- Draws a line</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12736" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_rlineto</B > ( int pdf_document, float x-coor, float y-coor [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_rlineto()</B > function draws a line from the current point to the relative point with coordinates (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-moveto" ><B CLASS="function" >cpdf_moveto()</B ></A >, <A HREF="#function.cpdf-rmoveto" ><B CLASS="function" >cpdf_rmoveto()</B ></A > and <A HREF="#function.cpdf-curveto" ><B CLASS="function" >cpdf_curveto()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-rmoveto" ></A >cpdf_rmoveto</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12766" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_rmoveto -- Sets current point</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12769" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_rmoveto</B > ( int pdf_document, float x-coor, float y-coor [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_rmoveto()</B > function set the current point relative to the coordinates <TT CLASS="parameter" ><I >x-coor</I ></TT > and <TT CLASS="parameter" ><I >y-coor</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-moveto" ><B CLASS="function" >cpdf_moveto()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-rotate-text" ></A >cpdf_rotate_text</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12797" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_rotate_text -- Sets text rotation angle </DIV ><DIV CLASS="refsect1" ><A NAME="AEN12800" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_rotate_text</B > ( int pdfdoc, float angle)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.cpdf-rotate" ></A >cpdf_rotate</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12815" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_rotate -- Sets rotation</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12818" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_rotate</B > ( int pdf_document, float angle)<BR ></BR ><P >
The <B CLASS="function" >cpdf_rotate()</B > function set the rotation in degrees to <TT CLASS="parameter" ><I >angle</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-save-to-file" ></A >cpdf_save_to_file</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12835" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_save_to_file -- Writes the pdf document into a file</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12838" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_save_to_file</B > ( int pdf_document, string filename)<BR ></BR ><P >
The <B CLASS="function" >cpdf_save_to_file()</B > function outputs the pdf document into a file if it has been created in memory. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
This function is not needed if the pdf document has been open by specifying a filename as a parameter of <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A >. </P ><P >
See also <A HREF="#function.cpdf-output-buffer" ><B CLASS="function" >cpdf_output_buffer()</B ></A > and <A HREF="#function.cpdf-open" ><B CLASS="function" >cpdf_open()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-save" ></A >cpdf_save</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12859" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_save -- Saves current environment</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12862" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_save</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_save()</B > function saves the current environment. It works like the postscript command gsave. Very useful if you want to translate or rotate an object without effecting other objects. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-restore" ><B CLASS="function" >cpdf_restore()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-scale" ></A >cpdf_scale</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12877" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_scale -- Sets scaling</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12880" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_scale</B > ( int pdf_document, float x-scale, float y-scale)<BR ></BR ><P >
The <B CLASS="function" >cpdf_scale()</B > function set the scaling factor in both directions. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-set-action-url" ></A >cpdf_set_action_url</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12899" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_set_action_url -- Sets hyperlink </DIV ><DIV CLASS="refsect1" ><A NAME="AEN12902" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_action_url</B > ( int pdfdoc, float xll, float yll, float xur, float xur, string url [, int mode])<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.cpdf-set-char-spacing" ></A >cpdf_set_char_spacing</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12932" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_char_spacing -- Sets character spacing</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12935" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_char_spacing</B > ( int pdf_document, float space)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_char_spacing()</B > function sets the spacing between characters. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-set-word-spacing" ><B CLASS="function" >cpdf_set_word_spacing()</B ></A > and <A HREF="#function.cpdf-set-leading" ><B CLASS="function" >cpdf_set_leading()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-creator" ></A >cpdf_set_creator</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12954" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_creator -- Sets the creator field in the pdf document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12957" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_creator</B > ( string creator)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_creator()</B > function sets the creator of a pdf document. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-set-subject" ><B CLASS="function" >cpdf_set_subject()</B ></A >, <A HREF="#function.cpdf-set-title" ><B CLASS="function" >cpdf_set_title()</B ></A > and <A HREF="#function.cpdf-set-keywords" ><B CLASS="function" >cpdf_set_keywords()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-current-page" ></A >cpdf_set_current_page</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12974" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_set_current_page -- Sets current page</DIV ><DIV CLASS="refsect1" ><A NAME="AEN12977" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_current_page</B > ( int pdf_document, int page_number)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_current_page()</B > function set the page on which all operations are performed. One can switch between pages until a page is finished with <A HREF="#function.cpdf-finalize-page" ><B CLASS="function" >cpdf_finalize_page()</B ></A >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-finalize-page" ><B CLASS="function" >cpdf_finalize_page()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-font-directories" ></A >cpdf_set_font_directories</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN12996" ></A ><P > (PHP 4 >= 4.0.6)</P >cpdf_set_font_directories -- Sets directories to search when using external fonts </DIV ><DIV CLASS="refsect1" ><A NAME="AEN12999" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_font_directories</B > ( int pdfdoc, string pfmdir, string pfbdir)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.cpdf-set-font-map-file" ></A >cpdf_set_font_map_file</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13017" ></A ><P > (PHP 4 >= 4.0.6)</P >cpdf_set_font_map_file -- Sets fontname to filename translation map when using external fonts </DIV ><DIV CLASS="refsect1" ><A NAME="AEN13020" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_font_map_file</B > ( int pdfdoc, string filename)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.cpdf-set-font" ></A >cpdf_set_font</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13035" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_font -- Select the current font face and size</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13038" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_font</B > ( int pdf_document, string font_name, float size, string encoding)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_font()</B > function sets the current font face, font size and encoding. Currently only the standard postscript fonts are supported. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
The last parameter <TT CLASS="parameter" ><I >encoding</I ></TT > can take the following values: "MacRomanEncoding", "MacExpertEncoding", "WinAnsiEncoding", and "<TT CLASS="constant" ><B >NULL</B ></TT >". "<TT CLASS="constant" ><B >NULL</B ></TT >" stands for the font's built-in encoding. </P ><P >
See the ClibPDF Manual for more information, especially how to support Asian fonts. </P ></DIV ><H1 ><A NAME="function.cpdf-set-horiz-scaling" ></A >cpdf_set_horiz_scaling</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13065" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_horiz_scaling -- Sets horizontal scaling of text</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13068" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_horiz_scaling</B > ( int pdf_document, float scale)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_horiz_scaling()</B > function sets the horizontal scaling to <TT CLASS="parameter" ><I >scale</I ></TT > percent. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-set-keywords" ></A >cpdf_set_keywords</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13085" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_keywords -- Sets the keywords field of the pdf document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13088" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_keywords</B > ( string keywords)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_keywords()</B > function sets the keywords of a pdf document. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-set-title" ><B CLASS="function" >cpdf_set_title()</B ></A >, <A HREF="#function.cpdf-set-creator" ><B CLASS="function" >cpdf_set_creator()</B ></A > and <A HREF="#function.cpdf-set-subject" ><B CLASS="function" >cpdf_set_subject()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-leading" ></A >cpdf_set_leading</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13105" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_leading -- Sets distance between text lines</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13108" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_leading</B > ( int pdf_document, float distance)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_leading()</B > function sets the <TT CLASS="parameter" ><I >distance</I ></TT > between text lines. This will be used if text is output by <A HREF="#function.cpdf-continue-text" ><B CLASS="function" >cpdf_continue_text()</B ></A >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-continue-text" ><B CLASS="function" >cpdf_continue_text()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-page-animation" ></A >cpdf_set_page_animation</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13128" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_set_page_animation -- Sets duration between pages</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13131" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_page_animation</B > ( int pdf_document, int transition, float duration)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_page_animation()</B > function set the transition between following pages. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
The value of <TT CLASS="parameter" ><I >transition</I ></TT > can be <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD >0 for none,</TD ></TR ><TR ><TD >
1 for two lines sweeping across the screen reveal the page, </TD ></TR ><TR ><TD >
2 for multiple lines sweeping across the screen reveal the page, </TD ></TR ><TR ><TD >3 for a box reveals the page,</TD ></TR ><TR ><TD >
4 for a single line sweeping across the screen reveals the page, </TD ></TR ><TR ><TD >5 for the old page dissolves to reveal the page,</TD ></TR ><TR ><TD >
6 for the dissolve effect moves from one screen edge to another, </TD ></TR ><TR ><TD >
7 for the old page is simply replaced by the new page (default) </TD ></TR ></TBODY ></TABLE ><P ></P > </P ><P >
The value of <TT CLASS="parameter" ><I >duration</I ></TT > is the number of seconds between page flipping. </P ></DIV ><H1 ><A NAME="function.cpdf-set-subject" ></A >cpdf_set_subject</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13163" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_subject -- Sets the subject field of the pdf document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13166" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_subject</B > ( int pdf_document, string subject)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_subject()</B > function sets the <TT CLASS="parameter" ><I >subject</I ></TT > of a pdf document. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-set-title" ><B CLASS="function" >cpdf_set_title()</B ></A >, <A HREF="#function.cpdf-set-creator" ><B CLASS="function" >cpdf_set_creator()</B ></A > and <A HREF="#function.cpdf-set-keywords" ><B CLASS="function" >cpdf_set_keywords()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-text-matrix" ></A >cpdf_set_text_matrix</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13187" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_text_matrix -- Sets the text matrix</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13190" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_text_matrix</B > ( int pdf_document, array matrix)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_text_matrix()</B > function sets a <TT CLASS="parameter" ><I >matrix</I ></TT > which describes a transformation applied on the current text font. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-set-text-pos" ></A >cpdf_set_text_pos</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13207" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_text_pos -- Sets text position</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13210" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_text_pos</B > ( int pdf_document, float x-coor, float y-coor [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_text_pos()</B > function sets the position of text for the next <A HREF="#function.cpdf-show" ><B CLASS="function" >cpdf_show()</B ></A > function call. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
See also <A HREF="#function.cpdf-show" ><B CLASS="function" >cpdf_show()</B ></A > and <A HREF="#function.cpdf-text" ><B CLASS="function" >cpdf_text()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-text-rendering" ></A >cpdf_set_text_rendering</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13238" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_text_rendering -- Determines how text is rendered</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13241" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_text_rendering</B > ( int pdf_document, int rendermode)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_text_rendering()</B > function determines how text is rendered. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
The possible values for <TT CLASS="parameter" ><I >rendermode</I ></TT > are 0=fill text, 1=stroke text, 2=fill and stroke text, 3=invisible, 4=fill text and add it to clipping path, 5=stroke text and add it to clipping path, 6=fill and stroke text and add it to clipping path, 7=add it to clipping path. </P ></DIV ><H1 ><A NAME="function.cpdf-set-text-rise" ></A >cpdf_set_text_rise</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13259" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_text_rise -- Sets the text rise</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13262" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_text_rise</B > ( int pdf_document, float value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_text_rise()</B > function sets the text rising to <TT CLASS="parameter" ><I >value</I ></TT > units. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-set-title" ></A >cpdf_set_title</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13279" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_title -- Sets the title field of the pdf document</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13282" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_title</B > ( string title)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_title()</B > function sets the <TT CLASS="parameter" ><I >title</I ></TT > of a pdf document. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-set-subject" ><B CLASS="function" >cpdf_set_subject()</B ></A >, <A HREF="#function.cpdf-set-creator" ><B CLASS="function" >cpdf_set_creator()</B ></A > and <A HREF="#function.cpdf-set-keywords" ><B CLASS="function" >cpdf_set_keywords()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-set-viewer-preferences" ></A >cpdf_set_viewer_preferences</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13300" ></A ><P > (PHP 3>= 3.0.9, PHP 4 )</P >cpdf_set_viewer_preferences -- How to show the document in the viewer </DIV ><DIV CLASS="refsect1" ><A NAME="AEN13303" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_viewer_preferences</B > ( int pdfdoc, array preferences)<BR ></BR ><P >
<DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Varovßnφ</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >Tato funkce je╣t∞ nenφ zdokumentovßna, k dispozici je pouze seznam argument∙.</P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><H1 ><A NAME="function.cpdf-set-word-spacing" ></A >cpdf_set_word_spacing</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13318" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_set_word_spacing -- Sets spacing between words</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13321" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_set_word_spacing</B > ( int pdf_document, float space)<BR ></BR ><P >
The <B CLASS="function" >cpdf_set_word_spacing()</B > function sets the spacing between words. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-set-char-spacing" ><B CLASS="function" >cpdf_set_char_spacing()</B ></A > and <A HREF="#function.cpdf-set-leading" ><B CLASS="function" >cpdf_set_leading()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-setdash" ></A >cpdf_setdash</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13340" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setdash -- Sets dash pattern</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13343" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setdash</B > ( int pdf_document, float white, float black)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setdash()</B > function set the dash pattern <TT CLASS="parameter" ><I >white</I ></TT > white units and <TT CLASS="parameter" ><I >black</I ></TT > black units. If both are 0 a solid line is set. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-setflat" ></A >cpdf_setflat</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13364" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setflat -- Sets flatness</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13367" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setflat</B > ( int pdf_document, float value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setflat()</B > function set the flatness to a value between 0 and 100. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-setgray-fill" ></A >cpdf_setgray_fill</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13383" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setgray_fill -- Sets filling color to gray value</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13386" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setgray_fill</B > ( int pdf_document, float value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setgray_fill()</B > function sets the current gray <TT CLASS="parameter" ><I >value</I ></TT > to fill a path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-setrgbcolor-fill" ><B CLASS="function" >cpdf_setrgbcolor_fill()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-setgray-stroke" ></A >cpdf_setgray_stroke</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13405" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setgray_stroke -- Sets drawing color to gray value</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13408" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setgray_stroke</B > ( int pdf_document, float gray_value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setgray_stroke()</B > function sets the current drawing color to the given gray value. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-setrgbcolor-stroke" ><B CLASS="function" >cpdf_setrgbcolor_stroke()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-setgray" ></A >cpdf_setgray</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13426" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setgray -- Sets drawing and filling color to gray value</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13429" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setgray</B > ( int pdf_document, float gray_value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setgray()</B > function sets the current drawing and filling color to the given gray value. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-setrgbcolor-stroke" ><B CLASS="function" >cpdf_setrgbcolor_stroke()</B ></A > and <A HREF="#function.cpdf-setrgbcolor-fill" ><B CLASS="function" >cpdf_setrgbcolor_fill()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-setlinecap" ></A >cpdf_setlinecap</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13448" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setlinecap -- Sets linecap parameter</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13451" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setlinecap</B > ( int pdf_document, int value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setlinecap()</B > function set the linecap parameter between a <TT CLASS="parameter" ><I >value</I ></TT > of 0 and 2. 0 = butt end, 1 = round, 2 = projecting square. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-setlinejoin" ></A >cpdf_setlinejoin</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13468" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setlinejoin -- Sets linejoin parameter</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13471" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setlinejoin</B > ( int pdf_document, int value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setlinejoin()</B > function set the linejoin parameter between a <TT CLASS="parameter" ><I >value</I ></TT > of 0 and 2. 0 = miter, 1 = round, 2 = bevel. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-setlinewidth" ></A >cpdf_setlinewidth</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13488" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setlinewidth -- Sets line width</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13491" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setlinewidth</B > ( int pdf_document, float width)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setlinewidth()</B > function set the line width to <TT CLASS="parameter" ><I >width</I ></TT >. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-setmiterlimit" ></A >cpdf_setmiterlimit</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13508" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setmiterlimit -- Sets miter limit</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13511" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setmiterlimit</B > ( int pdf_document, float value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setmiterlimit()</B > function set the miter limit to a value greater or equal than 1. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ></DIV ><H1 ><A NAME="function.cpdf-setrgbcolor-fill" ></A >cpdf_setrgbcolor_fill</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13527" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setrgbcolor_fill -- Sets filling color to rgb color value</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13530" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setrgbcolor_fill</B > ( int pdf_document, float red_value, float green_value, float blue_value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setrgbcolor_fill()</B > function sets the current rgb color value to fill a path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The values are expected to be floating point values between 0.0 and 1.0. (i.e black is (0.0, 0.0, 0.0) and white is (1.0, 1.0, 1.0)). </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.cpdf-setrgbcolor-stroke" ><B CLASS="function" >cpdf_setrgbcolor_stroke()</B ></A > and <A HREF="#function.cpdf-setrgbcolor" ><B CLASS="function" >cpdf_setrgbcolor()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-setrgbcolor-stroke" ></A >cpdf_setrgbcolor_stroke</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13557" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setrgbcolor_stroke -- Sets drawing color to rgb color value</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13560" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setrgbcolor_stroke</B > ( int pdf_document, float red_value, float green_value, float blue_value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setrgbcolor_stroke()</B > function sets the current drawing color to the given rgb color value. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The values are expected to be floating point values between 0.0 and 1.0. (i.e black is (0.0, 0.0, 0.0) and white is (1.0, 1.0, 1.0)). </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.cpdf-setrgbcolor-fill" ><B CLASS="function" >cpdf_setrgbcolor_fill()</B ></A > and <A HREF="#function.cpdf-setrgbcolor" ><B CLASS="function" >cpdf_setrgbcolor()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-setrgbcolor" ></A >cpdf_setrgbcolor</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13587" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_setrgbcolor -- Sets drawing and filling color to rgb color value</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13590" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_setrgbcolor</B > ( int pdf_document, float red_value, float green_value, float blue_value)<BR ></BR ><P >
The <B CLASS="function" >cpdf_setrgbcolor()</B > function sets the current drawing and filling color to the given rgb color value. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The values are expected to be floating point values between 0.0 and 1.0. (i.e black is (0.0, 0.0, 0.0) and white is (1.0, 1.0, 1.0)). </P ></BLOCKQUOTE ></DIV ><P >
See also <A HREF="#function.cpdf-setrgbcolor-stroke" ><B CLASS="function" >cpdf_setrgbcolor_stroke()</B ></A > and <A HREF="#function.cpdf-setrgbcolor-fill" ><B CLASS="function" >cpdf_setrgbcolor_fill()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-show-xy" ></A >cpdf_show_xy</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13617" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_show_xy -- Output text at position</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13620" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_show_xy</B > ( int pdf_document, string text, float x-coor, float y-coor [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_show_xy()</B > function outputs the string <TT CLASS="parameter" ><I >text</I ></TT > at position with coordinates (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
<DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Poznßmka: </B > The function <B CLASS="function" >cpdf_show_xy()</B > is identical to <A HREF="#function.cpdf-text" ><B CLASS="function" >cpdf_text()</B ></A > without the optional parameters. </P ></BLOCKQUOTE ></DIV > </P ><P >
See also <A HREF="#function.cpdf-text" ><B CLASS="function" >cpdf_text()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-show" ></A >cpdf_show</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13657" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_show -- Output text at current position</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13660" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_show</B > ( int pdf_document, string text)<BR ></BR ><P >
The <B CLASS="function" >cpdf_show()</B > function outputs the string in <TT CLASS="parameter" ><I >text</I ></TT > at the current position. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-text" ><B CLASS="function" >cpdf_text()</B ></A >, <A HREF="#function.cpdf-begin-text" ><B CLASS="function" >cpdf_begin_text()</B ></A > and <A HREF="#function.cpdf-end-text" ><B CLASS="function" >cpdf_end_text()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-stringwidth" ></A >cpdf_stringwidth</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13681" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_stringwidth -- Returns width of text in current font</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13684" ></A ><H2 >Description</H2 >float <B CLASS="methodname" >cpdf_stringwidth</B > ( int pdf_document, string text)<BR ></BR ><P >
The <B CLASS="function" >cpdf_stringwidth()</B > function returns the width of the string in <TT CLASS="parameter" ><I >text</I ></TT >. It requires a font to be set before. </P ><P >
See also <A HREF="#function.cpdf-set-font" ><B CLASS="function" >cpdf_set_font()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-stroke" ></A >cpdf_stroke</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13701" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_stroke -- Draw line along path</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13704" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_stroke</B > ( int pdf_document)<BR ></BR ><P >
The <B CLASS="function" >cpdf_stroke()</B > function draws a line along current path. Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >
See also <A HREF="#function.cpdf-closepath" ><B CLASS="function" >cpdf_closepath()</B ></A > and <A HREF="#function.cpdf-closepath-stroke" ><B CLASS="function" >cpdf_closepath_stroke()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-text" ></A >cpdf_text</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13720" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_text -- Output text with parameters</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13723" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_text</B > ( int pdf_document, string text, float x-coor, float y-coor [, int mode [, float orientation [, int alignmode]]])<BR ></BR ><P >
The <B CLASS="function" >cpdf_text()</B > function outputs the string <TT CLASS="parameter" ><I >text</I ></TT > at position with coordinates (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ><P >
The optional parameter <TT CLASS="parameter" ><I >orientation</I ></TT > is the rotation of the text in degree. </P ><P >
The optional parameter <TT CLASS="parameter" ><I >alignmode</I ></TT > determines how the text is aligned. </P ><P >
See the ClibPDF documentation for possible values. </P ><P >
See also <A HREF="#function.cpdf-show-xy" ><B CLASS="function" >cpdf_show_xy()</B ></A >. </P ></DIV ><H1 ><A NAME="function.cpdf-translate" ></A >cpdf_translate</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13766" ></A ><P > (PHP 3>= 3.0.8, PHP 4 )</P >cpdf_translate -- Sets origin of coordinate system</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13769" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >cpdf_translate</B > ( int pdf_document, float x-coor, float y-coor [, int mode])<BR ></BR ><P >
The <B CLASS="function" >cpdf_translate()</B > function set the origin of coordinate system to the point (<TT CLASS="parameter" ><I >x-coor</I ></TT >, <TT CLASS="parameter" ><I >y-coor</I ></TT >). Vracφ <TT CLASS="constant" ><B >TRUE</B ></TT > p°i ·sp∞chu, <TT CLASS="constant" ><B >FALSE</B ></TT > p°i selhßnφ. </P ><P >Nepovinn² parametr <TT CLASS="parameter" ><I >mode</I ></TT > urΦuje dΘlku jednotky. Kdy╛ je nastaven na 0 nebo nenφ uveden, je pou╛ita v²chozφ jednotka strßnky. Jinak jsou sou°adnice m∞°eny v bodech PostScript bez ohledu na aktußlnφ jednotku.</P ></DIV ></DIV ><DIV CLASS="reference" ><A NAME="ref.crack" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >XI. Crack functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN13797" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="crack.intro" ></A >┌vod</H1 ><P >
These functions allow you to use the CrackLib library to test the 'strength' of a password. The 'strength' of a pa