PHP Manual

Stig Sæther Bakken
Alexander Aulbach
Egon Schmid
Jim Winstead
Lars Torben Wilson
Rasmus Lerdorf
Zeev Suraski

Edited by

Stig Sæther Bakken
Egon Schmid

¹ø¿ª :

Ȳ¿øÈñ (Home Page: http://php.morosolution.com E-Mail: regina@morosolution.com)
(ÀÌ ±ÛÀº Ȳ¿øÈñ °³ÀÎÀÌ ¹ø¿ªÇÑ ³»¿ëÀÔ´Ï´Ù. ±ÛÀÇ ¿À¿ª¿¡ µû¸¥ Ã¥ÀÓÀ» ÁöÁö ¾Ê½À´Ï´Ù. ±ÛÀÇ À߸øµÈ ºÎºÐÀº ¿¬¶ôÇØ ÁÖ½Ã¸é °¨»çÇϰڽÀ´Ï´Ù.)

Copyright ¨Ï 1997, 1998, 1999, 2000 by the PHP Documentation Group

Copyright (¿ªÀÚÁÖ : ¿ø¹®ÀÇ ¹ýÀûÀÎ È¿·Â¹®Á¦·Î ¹ø¿ªÇÏÁö ¾Ê½À´Ï´Ù. ³»¿ëÀº GPLÀ» µû¸£°í ÀÖ´Ù´Â ³»¿ëÀÔ´Ï´Ù.)

This manual is © Copyright 1997, 1998, 1999, 2000 by the PHP Documentation Group. The members of this group are listed on the front page of this manual.

This manual can be redistributed under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.


Dedication

Â÷·Ê
¼­¹®
ÀÌ ¸Å´º¾ó¿¡ ´ëÇÏ¿©
I. Getting Started
1. ¼Ò°³ (Introduction)
2. ¼³Ä¡ (Installation)
3. ¼³Á¤ (Configuration)
4. º¸¾È (Security)
II. Language Reference
5. ±âº»¹®¹ý (Basic syntax)
6. º¯¼öÇüÅ (Types)
7. º¯¼ö (Variables)
8. »ó¼ö (Constants)
9. Ç¥Çö½Ä (Expressions)
10. ¿¬»êÀÚ (Operators)
11. Á¦¾î ±¸Á¶ (Control Structures)
12. ÇÔ¼ö (Functions)
13. Ŭ·¡½º¿Í °´Ã¼ (Classes and Objects)
III. ±â´É (Features)
14. Error handling
15. Creating GIF images
16. HTTP authentication with PHP
17. Cookies
18. Handling file uploads
19. Using remote files
20. Connection handling
21. Persistent database connections
IV. ÇÔ¼ö ¸ñ·Ï (Function Reference)
I. Apache-specific functions
II. Arbitrary precision mathematics functions
III. Array functions
IV. Aspell functions
V. Calendar functions
VI. COM support functions for Windows
VII. Class/Object Functions
VIII. ClibPDF functions
IX. Cybercash payment functions
X. DOM XML functions
XI. Compression functions
XII. Database (dbm-style) abstraction layer functions
XIII. Date and Time functions
XIV. dBase functions
XV. dbm functions
XVI. Directory functions
XVII. Dynamic Loading functions
XVIII. Encryption functions
XIX. filePro functions
XX. Filesystem functions
XXI. Forms Data Format functions
XXII. FTP functions
XXIII. GNU Gettext
XXIV. Hash functions
XXV. HTTP functions
XXVI. Hyperwave functions
XXVII. Image functions
XXVIII. IMAP, POP3, and NNTP functions
XXIX. Informix functions
XXX. InterBase functions
XXXI. LDAP functions
XXXII. Mail functions
XXXIII. Mathematical functions
XXXIV. MCAL functions
XXXV. Microsoft SQL Server functions
XXXVI. Miscellaneous functions
XXXVII. mSQL functions
XXXVIII. MySQL functions
XXXIX. Network functions
XL. NIS functions
XLI. ODBC functions
XLII. Oracle functions
XLIII. Oracle 8 functions
XLIV. PDF functions
XLV. Perl-compatible Regular Expression functions
XLVI. PHP options & information
XLVII. POSIX functions
XLVIII. PostgreSQL functions
XLIX. Program Execution functions
L. GNU Recode functions
LI. Regular expression functions
LII. Semaphore and shared memory functions
LIII. Session handling functions
LIV. SNMP functions
LV. String functions
LVI. Shockwave Flash functions
LVII. Sybase functions
LVIII. URL functions
LIX. Variable functions
LX. Vmailmgr functions
LXI. WDDX functions
LXII. XML parser functions
V. ºÎ·Ï (Appendixes)
A. Migrating from PHP/FI 2.0 to PHP 3.0
B. PHP development
C. The PHP Debugger


¼­¹®

PHP Version 3.0Àº HTML¿¡ ³»ÀåµÇ¾î µ¿ÀÛÇÏ´Â ½ºÅ©¸³Æ® ¾ð¾îÀÌ´Ù.(HTML-embedded scripting language) PHP´Â C¿Í Java, PerlµîÀ¸·ÎºÎÅÍ ¸¹Àº ¹®Àå Çü½ÄÀ» ºô·Á¾²°í ÀÖ°í, ¸î°¡Áö´Â °íÀ¯ÇÑ °Íµµ ÀÖ´Ù. ÀÌ ¾ð¾îÀÇ ¸ñÀûÀº À¥°³¹ßÀÚµéÀÌ µ¿ÀûÀÎ À¥¹®¼­¸¦ ºü¸£°í ½±°Ô ÀÛ¼ºÇÒ ¼ö ÀÖµµ·Ï ÇÏ´Â °ÍÀÌ´Ù.


ÀÌ ¸Å´º¾ó¿¡ ´ëÇÏ¿©

¿ø·¡ ¿µ¹® ¸Å´º¾óÀº DocBook DTDÀ» »ç¿ëÇÑ SGML·Î ÀÛ¼ºµÇ¾î ÀÖ°í, formattingÀ» À§Çؼ­´Â DSSSL (Document Style and Semantics Specification Language)À» »ç¿ëÇϰí ÀÖ´Ù. ¶ÇÇÑ Tex¿Í RTF¹öÁ¯µµ ÀÖÀ¸³ª, ÇÑ±Û ¹®¼­´Â ¿ªÀÚÀÇ ÆíÀǸ¦ À§ÇØ ÀÏ´Ü HTML¸¸À» »ç¿ëÇϵµ·Ï ÇϰڴÙ.


I. Getting Started

Table of Contents
1. ¼Ò°³ (Introduction)
2. ¼³Ä¡ (Installation)
3. ¼³Á¤ (Configuration)
4. º¸¾È (Security)


Chapter 1. ¼Ò°³ (Introduction)


PHP¶õ ¹«¾ùÀΰ¡?

PHP´Â server-side HTML-embedded scripting languageÀÔ´Ï´Ù.

°£´ÜÇÑ ´äÀÌÁö¸¸, ¹«¾ùÀ» ÀǹÌÇÒ±î? ´ÙÀ½ ¿¹¸¦ º¸ÀÚ. :

Example 1-1. An introductory example

<html><head><title>Example</title>
<body>
<?php echo "Hi, I'm a PHP script!"; ?>
</body></html>
 

PerlÀ̳ª C¿Í°°Àº ´Ù¸¥ ¾ð¾î¿Í ´Ù¸£°Ô HTMLÀ» Ãâ·ÂÇϴµ¥ ¸¹Àº ¸í·É¾î°¡ ÇÊ¿ä¾ø´Ù. ¿©·¯ºÐÀº HTML³»¿¡ ¿©·¯ºÐÀÌ ÇϰíÀÚ ÇÏ´Â ÀÏ(À§ÀÇ °æ¿ì´Â ÇÑÁÙÀÇ ¹®ÀÚ¿­ Ãâ·Â)¿¡ ´ëÇÑ ½ºÅ©¸³Æ®¸¦ Àû¾îÁÖ¸é µÈ´Ù. PHP ÄÚµå´Â ƯÁ¤ÇÑ ½ÃÀÛ/³¡ ÅÂÅ©»çÀÌ¿¡ µé¾î°¡°Ô µÇ´Âµ¥ ÀÌ Å±״ "PHP ¸ðµå"·Î µé¾î°¡°Å³ª ³ª¿À°Ô ÇÏ´Â °ÍÀÌ´Ù.

PHP°¡ client-side Javascript °°Àº °Í°ú ±¸º°µÇ´Â °ÍÀº ÀÌ Äڵ尡 ¼­¹ö¿¡¼­ ½ÇÇàµÈ´Ù´Â °ÍÀÌ´Ù.


PHP´Â ¹«¾ùÀ» ÇÒ ¼ö Àִ°¡?

°¡Àå ±âº»ÀûÀÎ ·¹º§¿¡¼­, PHP´Â CGI ÇÁ·Î±×·¥¿¡¼­ ÇÒ ¼ö ÀÖ´Â ¸ðµç °ÍÀ» ÇÒ ¼ö ÀÖ´Ù. form data¸¦ °¡Á®¿À°í, µ¿ÀûÀÎ À¥ÆäÀÌÁö¸¦ ¸¸µé°Å³ª, Cookie¸¦ º¸³»°í ¹ÞÀ» ¼öµµ ÀÖ´Ù.

¾Æ¸¶ PHPÀÇ °¡Àå °­·ÂÇÏ°í °ü½É°¡´Â ºÎºÐÀº database¿ÍÀÇ ¿¬µ¿ºÎºÐÀÏ °ÍÀÌ´Ù. PHP¸¦ »ç¿ëÇÏ¸é ¿©·¯ºÐÀº DatabaseÀÇ Data¸¦ »ç¿ëÇÑ Web page¸¦ ³î¶øµµ·Ï °£´ÜÈ÷ ¸¸µé ¼ö ÀÖ´Ù. ´ÙÀ½¿¡ ³ª¿À´Â DB serverµéÀ» ÇöÀç »ç¿ëÇÒ ¼ö ÀÖ´Ù. :

Adabas D

InterBase

Solid

dBase

mSQL

Sybase

Empress

MySQL

Velocis

FilePro

Oracle

Unix dbm

Informix

PostgreSQL

 

 

PHP´Â IMAP³ª SNMP, NNTP, POP3, HTTPµîÀÇ ÇÁ·ÎÅäÄݵéÀ» »ç¿ëÇØ¼­ ´Ù¸¥ ¼­ºñ½ºµé¿¡ ´ëÇØ Á¢±ÙÇÏ¿© µ¥ÀÌÅ͸¦ ±³È¯ÇÒ ¼ö ÀÖ´Ù. ½ÉÁö¾î´Â raw network ¼ÒÄÏÀ» »ç¿ëÇϸé, ±×¿ÜÀÇ ÇÁ·ÎÅäÄݵéÀ» »ç¿ëÇÒ ¼öµµ ÀÖ´Ù.


PHPÀÇ ¿ª»ç

PHP´Â 1994³â °¡À» Rasmus Lerdorf°¡ óÀ½ °í¾ÈÇÏ¿´´Ù. óÀ½ ºñ°ø°³ÆÇÀº ±×ÀÇ È¨ÆäÀÌÁö¿¡ »ç¿ëµÇ¾ú°í, ¿ÜºÎ¿¡ »ç¿ëµÈ °ÍÀº 1995³â ÃʺÎÅÍ »ç¿ëµÇ¾î Personal Home Page Tools¶ó°í ºÒ¸®°Ô µÇ¾ú´Ù. À̰ÍÀº ¸î °³ÀÇ Æ¯º°ÇÑ ¸ÅÅ©·Î¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Â ´Ü¼øÇÑ ÆÄ¼­(¸í·É ÇØ¼®±â) ¿£Áø°ú ¹æ¸í·ÏÀ̳ª Ä«¿îÅÍ °°ÀÌ È¨ÆäÀÌÁöÀÇ µÚ¿¡¼­ °øÅëÀûÀ¸·Î »ç¿ëÇÒ ¼ö ÀÖ´Â ¸î °³ÀÇ °£´ÜÇÑ À¯Æ¿¸®Æ¼·Î ±¸¼ºµÇ¾ú´Ù. ÀÌ ÆÄ¼­°¡ 1995³â Á߹ݿ¡ ÀçÀÛ¼ºµÇ¾î PHP/FI Version 2¶ó°í ¸í¸íµÇ¾ú´Ù. FI´Â Rasmus°¡ ÀÛ¼ºÇÑ html Çü½ÄÀÇ µ¥ÀÌÅ͸¦ ÇØ¼®ÇÒ ¼ö ÀÖ´Â º°µµÀÇ ÆÐŰÁö´Ù. ±×´Â ÀÌ µÎ°¡Áö¸¦ ÇÕÄ¡°í mSQLÀ» Áö¿øÇϵµ·ÏÇÏ¿© PHP/FI¸¦ ź»ý½ÃÄ×´Ù. PHP/FI´Â ºü¸¥ ¼Óµµ·Î ¹ßÀüÇÏ¿´°í, ¸¹Àº »ç¶÷µéÀÌ ÀÌ¿¡ °øÇåÇÏ¿´´Ù.

Á¤È®ÇÑ Åë°è´Â ¾øÁö¸¸ 1996³â ÈÄ¹Ý PHP/FI´Â Àü¼¼°èÀûÀ¸·Î ÃÖ¼ÒÇÑ 15,000°³ ÀÌ»óÀÇ À¥»çÀÌÆ®¿¡¼­ »ç¿ëµÇ´Â °ÍÀ¸·Î ÃßÁ¤µÇ¾ú°í, 1997³â Á߹ݿ¡ ±×¼ö´Â 50,000À¸·Î ´Ã¾î³µ´Ù. 1997³â Áß¹Ý PHP´Â ¶Ç´Ù¸¥ Áß¿äÇÑ º¯È­¸¦ °¡Á®¿Ô´Ù. À̶§ºÎÅÍ PHP´Â RasmusÀÇ °³ÀÎÀÌ ¾Æ´Ñ ÆÀ¿¡ ÀÇÇØ °³¹ßµÇ°í ÀÖ´Ù. »õ ÆÄ¼­´Â Zeev Suraski¿Í Andi Gutmans°¡ Àç ÀÛ¼ºµÇ¾ú°í, PHP Version 3¶ó´Â À̸§À¸·Î ³ªÅ¸³µ´Ù. ¸¹Àº PHP/FIÀÇ ±â´ÉµéÀÌ ¿Å°Ü¿Ô°í, ±×¿Ü¿¡µµ ¸¹Àº ±â´ÉµéÀÌ »õ·Î ÀÛ¼ºµÇ¾ú´Ù.

1998³â Áß¹ÝÀÎ ÇöÀç PHP/FI³ª PHP3´Â C2ÀÇ StrongHold web server³ª RedHat Linux°°Àº ¿©·¯ »ó¾÷ÀûÀÎ Á¦Ç°°ú ÇÔ²² Á¦°øµÇ°í ÀÖÀ¸¸ç, Àü¼¼°èÀûÀ¸·Î ÃÖ¼ÒÇÑ 150,000°³ÀÇ À¥»çÀÌÆ®°¡ »ç¿ëÇϰí ÀÖ´Ù. ÀÌ ¼ö´Â ÀÎÅͳݿ¡¼­ Netscape's flagship Enterprise serverÀÇ »ç¿ë¼öº¸´Ù ¸¹´Ù.

ÀÌ ±ÛÀÌ ¾²¿©Áö°í ÀÖ´Â °¡¿îµ¥, PHPÀÇ Â÷±â ¹öÀüÀÌ Á¦À۵ǰí ÀÖ´Ù. »õ·Î¿î PHP´Â Zend °°Àº È¿À²ÀûÀÎ ½ºÅ©¸³Æ® ¿£Áø°ú ApacheÀÌ¿ÜÀÇ À¥¼­¹ö¿¡¼­µµ ¸ðµâ·Î ½ÇÇàµÉ ¼ö ÀÖµµ·Ï Á¦À۵ǰí ÀÖ´Ù.


Chapter 2. ¼³Ä¡ (Installation)


ÃֽйöÀü ³»·Á¹Þ±â (Downloading the latest version)

¿©·¯ºÐÀº ÃֽŹöÀüÀÇ ¼Ò½º¿Í (À©µµ¿ìÁ Æ÷ÇÔÇÑ)¿©·¯ Ç÷§ÆûÀÇ ¹èÆ÷ÆÇÀ» http://www.php.net¿¡¼­ ³»·Á ¹ÞÀ» ¼ö ÀÖ´Ù.


Unix¿¡¼­ ¼Ò½º·Î ¼³Ä¡ (Installing From Source on UNIX)

ÀÌ ÀåÀº PHP¸¦ ¼³Ä¡ÇÏ°í ¼³Á¤ÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ ¼³¸íÇϰí ÀÖ´Ù. ÇÊ¿äÇÑ Áö½Ä°ú ¼ÒÇÁÆ®¿þ¾î :


ºü¸¥ ¼³Ä¡ ¹æ¹ý (Apache Module Version)

 

  1 
  2 1.  gunzip apache_1.3.x.tar.gz
  3 2.  tar xvf apache_1.3.x.tar
  4 3.  gunzip php-3.0.x.tar.gz
  5 4.  tar xvf php-3.0.x.tar
  6 5.  cd apache_1.3.x
  7 6.  ./configure --prefix=/www
  8 7.  cd ../php-3.0.x
  9 8.  ./configure --with-mysql --with-apache=../apache_1.3.x --enable-track-vars
 10 9.  make
 11 10. make install
 12 11. cd ../apache_1.3.x
 13 12. ./configure --prefix=/www --activate-module=src/modules/php3/libphp3.a
 14 13. make
 15 14. make install
 16 
 17      ÀÌ ´Ü°è ´ë½Å httpd ÀÌÁø ÆÄÀÏÀ» ±âÁ¸ÀÇ ÆÄÀÏ¿¡ µ¤¾î ¾µ ¼öµµ ÀÖ´Ù.
 18      ÀÌ ÀÛ¾÷À» ÇÏ·Á¸é ¿ì¼± httpd ¼­¹ö¸¦ ²ô´Â °ÍÀ» ÀØÁö ¸»µµ·Ï ÇÏÀÚ.
 19
 20 
 21 15. cd ../php-3.0.x
 22 16. cp php3.ini-dist /usr/local/lib/php3.ini
 23 
 24      ¿©·¯ºÐÀº ÀÌÁ¦ PHPÀÇ ¼³Á¤À» °íÄ¡±âÀ§ÇØ /usr/local/lib/php3.ini¸¦ ¼öÁ¤ÇÏ¸é µÈ´Ù.
 25      ¸¸¾à ÀÌ ÆÄÀÏÀÇ À§Ä¡¸¦ ¿Å±â°í ½Í´Ù¸é À§ÀÇ 8´Ü°è¿¡¼­ --with-config-file=/path ¿É¼ÇÀ» ÁØ´Ù.
 26 
 27 
 28 17. Edit your httpd.conf or srm.conf file and add: 
 29       
 30             AddType application/x-httpd-php3 .php3
 31  
 32     ¿©±â¼­ ¿©·¯ºÐÀº .php3¿Ü¿¡ ´Ù¸¥ È®ÀåÀÚ¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ´Ù.
 33     ÇÏÁö¸¸ ¸¹Àº »ç¶÷µéÀÌ »ç¿ëÇϴ´ë·Î ±×³É .php3¸¦ »ç¿ëÇÒ °ÍÀ» ±ÇÇÑ´Ù.
 34
 35 18. ÀϹÝÀûÀÎ ¹æ½Ä´ë·Î Apache ¼­¹ö¸¦ ½ÃÀÛÇÑ´Ù. 
 36     (¹Ýµå½Ã stop°ú startÇÏ¿© Àç½Ãµ¿ÇÏ¿©¾ßÇÑ´Ù. 
 37      HUPÀ̳ª USR1°°Àº signalÀ» ÁÖ´Â µîÀÇ reload¸¸ ÇØ¼­´Â ¼Ò¿ëÀÌ ¾ø´Ù.)
 38       



¼³Á¤ (Configuration)

PHP¸¦ ¼³Á¤ÇÏ´Â ¹æ¹ý¿¡´Â Å©°Ô µÎ°¡Áö°¡ ÀÖ´Ù.

´ÙÀ½Àº ¿©·¯ °¡Áö ¼³Á¤ ¿É¼ÇµéÀÇ ÀÚ¼¼ÇÑ ³»¿ëÀÌ´Ù.


Apache ¸ðµâ

PHP¸¦ ¾ÆÆÄÄ¡ ¸ðµâ·Î ¸¸µé·Á¸é, "Build as an Apache module?"ÀÇ Áú¹®¿¡ "yes"·Î ´äÇϰí, Apache ¹èÆ÷º»ÀÇ base µð·ºÅ丮¸¦ ¸í½ÃÇØ ÁÖ¸é µÈ´Ù. (configure¿¡¼­´Â --with-apache=DIR ¿É¼ÇÀ» ÁÖ¸é µÈ´Ù.) ¸¸¾à ¿©·¯ºÐÀÇ Apache ¼Ò½ºÀÇ ¹èÆ÷º»À» /usr/local/src/apache_1.3.3¿¡ Ç®¾î ³õ¾Ò´Ù¸é, ÀÌ µð·ºÅ丮°¡ Apache ¹èÆ÷º»ÀÇ base µð·ºÅ丮°¡ µÈ´Ù. ±âº» µð·ºÅ丮´Â /usr/local/etc/httpdÀÌ´Ù.


fhttpd ¸ðµâ

PHP¸¦ fhttpd ¸ðµâ·Î ¸¸µé·Á¸é, "Build as an fhttpd module?"ÀÇ Áú¹®¿¡ "yes"·Î ´äÇϰí, fhttpd ¼Ò½ºÀÇ base µð·ºÅ丮¸¦ ¸í½ÃÇØ ÁÖ¸é µÈ´Ù. (configure¿¡¼­´Â --with-fhttpd=DIR ¿É¼ÇÀ» ÁÖ¸é µÈ´Ù.) ±âº» µð·ºÅ丮´Â /usr/local/src/fhttpdÀÌ´Ù. ¿©·¯ºÐÀÌ fhttpd¸¦ ¿î¿µÁß¿¡ ÀÖ´Ù¸é, ÀÌ ¸ðµâ·Î ¸¸µé¾î ½ÇÇàÇÏ´Â °ÍÀÌ ´õ ÁÁÀº ¼º´ÉÀ» Á¦°øÇϸç, ¶ÇÇÑ Á¦¾î¿Í ¿ø°Ý ½ÇÇà ´É·Âµµ Çâ»óµÈ´Ù.


CGI version

PHP´Â ±âº»ÀûÀ¸·Î CGI ÇÁ·Î±×·¥À¸·Î ¸¸µé¾î Áø´Ù. ¸¸¾à ¿©·¯ºÐÀÌ PHP°¡ ¸ðµâ·Î Á¦°øµÇ´Â À¥ ¼­¹ö¸¦ ¿î¿µÁßÀ̶ó¸é, ÇØ´ç ¸ðµâ·Î »ç¿ëÇÏ´Â °ÍÀÌ ÀϹÝÀûÀ¸·Î ÁÁÀº ¼º´ÉÀ» ³¾ ¼ö ÀÖ´Ù. ÇÏÁö¸¸, CGI ¹öÀüÀº ¾ÆÆÄÄ¡ »ç¿ëÀڵ鿡°Ô ´Ù¸¥ user-id¸¦ »ç¿ëÇÏ¿© º°µµÀÇ PHP-enabled ÆäÀÌÁö¸¦ ½ÇÇàÇÒ ¼ö ÀÖµµ·Ï ÇØ ÁØ´Ù. ¸¸¾à PHP¸¦ CGI·Î ½ÇÇàÇÏ°í ½Í´Ù¸é Security chapter¸¦ ¹Ýµå½Ã Àо±â ¹Ù¶õ´Ù.


Database Áö¿ø ¿É¼Ç

PHP´Â ´ÙÀ½ÀÇ databaseµé¿¡ ´ëÇÑ °íÀ¯ÀÇ Áö¿øÀ» Á¦°øÇÑ´Ù. (ODBCµµ Á¦°øÇÑ´Ù.)


Adabas D

      --with-adabas=DIR

Adabas D Áö¿øÀ¸·Î ÄÄÆÄÀÏÇÑ´Ù. DIRÀº Adabas D°¡ ¼³Ä¡µÈ DirectoryÀ̰í, ±âº»°ªÀº /usr/local/adabasdÀÌ´Ù.

Adabas home page


dBase

      --with-dbase

DBaseÁö¿øÀ¸·Î ÄÄÆÄÀÏ ÇÑ´Ù. º°µµÀÇ ¶óÀ̺귯¸®´Â ÇÊ¿ä ¾ø´Ù.


filePro

      --with-filepro 

¹øµéµÈ Àбâ Àü¿ë filePro(bundled read-only filePro)¸¦ Áö¿øÇϵµ·Ï ÇØ ÁØ´Ù. º°µµÀÇ ¶óÀ̺귯¸®´Â ÇÊ¿ä ¾ø´Ù.


mSQL

      --with-msql=DIR     

mSQLÀ» Áö¿øÇϵµ·Ï ÇÑ´Ù. DIRÀº mSQLÀÌ ¼³Ä¡µÈ µð·ºÅ丮ÀÌ°í ±âº»°ªÀº /usr/local/HughesÀÌ´Ù. ÀÌ µð·ºÅ丮´Â mSQL 2.0 ¹èÆ÷º»ÀÇ ±âº» µð·ºÅ丮ÀÌ´Ù. configure´Â ÇöÀç ÀÛµ¿ÁßÀÎ mSQLÀÇ ¹öÀüÀ» ÀÚµ¿À¸·Î ŽÁöÇÏ¿© 1.0°ú 2.0Áß Çϳª¸¦ Áö¿øÇϵµ·Ï ÇÑ´Ù. ¸¸¾à PHP°¡ mSQL 1.0Áö¿øÀ¸·Î ÄÄÆÄÀϵǾú´Ù¸é, ¿©·¯ºÐÀº mSQL 2.0 database´Â »ç¿ëÇÏÁö ¸øÇÑ´Ù. ¸¶Âù°¡Áö·Î 2.0À¸·Î ÄÄÆÄÀÏ µÇ¾ú´Ù¸é 1.0 database´Â »ç¿ëÇÒ ¼ö ¾ø´Ù.

See also mSQL Configuration Directives in the configuration file.

mSQL home page


MySQL

      --with-mysql=DIR     

MySQLÀ» Áö¿øÇϵµ·Ï ÇÑ´Ù. DIRÀº MySQLÀÌ ¼³Ä¡µÈ µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/localÀÌ´Ù. ÀÌ µð·ºÅ丮´Â MySQL ¹èÆ÷º»ÀÇ ±âº» µð·ºÅ丮 ÀÌ´Ù.

See also MySQL Configuration Directives in the configuration file.

MySQL home page


iODBC

      --with-iodbc=DIR     

iODBCÁö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. ÀÌ ±â´ÉÀº iODBC µå¶óÀ̹ö °ü¸®ÀÚ¸¦ À§ÇØ ¸Ç ¸ÕÀú °³¹ßµÇ¾ú´Âµ¥, ÀÌ iODBC µå¶óÀ̹ö °ü¸®ÀÚ ¸¹Àº UNIXÇÏ¿¡¼­ µ¹¾Æ°¡´Â ¹«·á ¹èÆ÷°¡ °¡´ÉÇÑ ODBC µå¶óÀ̹ö °ü¸®ÀÚÀÌ´Ù. DIRÀº iODBC°¡ ¼³Ä¡µÈ µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/localÀÌ´Ù.

FreeODBC home page or iODBC home page


OpenLink ODBC

      --with-openlink=DIR 

OpenLink ODBC Áö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. DIRÀº OpenLink ODBC°¡ ¼³Ä¡µÈ µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/local/openlinkÀÌ´Ù.

OpenLink Software's home page


Oracle

      --with-oracle=DIR     

¿À¶óŬ Áö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. ¿À¶óŬ ¹öÀü 7.0¿¡¼­ 7.3±îÁö´Â µ¿ÀÛÀ» Å×½ºÆ®ÇÏ¿© ¹®Á¦°¡ ¾ø¾ú´Ù. DIRÀº ORACLE_HOME µð·ºÅ丮ÀÌ´Ù. ¿À¶óŬ ȯ°æÀÌ ÀÌ¹Ì ¼³Á¤µÇ¾î ÀÖ´Ù¸é, DIRÀ» ¹Ýµå½Ã Á¤ÇØÁÙ ÇÊ¿ä´Â ¾ø´Ù.

Oracle home page


PostgreSQL

      --with-pgsql=DIR     

IPostgreSQLÁö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. DIRÀº PostgreSQLÀÌ ¼³Ä¡µÈ base µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/local/pgsqlÀÌ´Ù.

See also Postgres Configuration Directives in the configuration file.

PostgreSQL home page


Solid

      --with-solid=DIR     

SolidÁö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. =DIRÀº Solid°¡ ¼³Ä¡µÈ µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/local/solidÀÌ´Ù.

Solid home page


Sybase

      --with-sybase=DIR     

SybaseÁö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. DIRÀº Sybase°¡ ¼³Ä¡µÈ µð·ºÅ丮À̰í, ±âº»°ªÀº /home/sybaseÀÌ´Ù.

See also Sybase Configuration Directives in the configuration file.

Sybase home page


Sybase-CT

      --with-sybase-ct=DIR     

Sybase-CTÁö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. DIRÀº Sybase-CT°¡ ¼³Ä¡µÈ µð·ºÅ丮À̰í, ±âº»°ªÀº /home/sybaseÀÌ´Ù.

See also Sybase-CT Configuration Directives in the configuration file.


Velocis

      --with-velocis=DIR     

VelocisÁö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. DIRÀº Velocis°¡ ¼³Ä¡µÈ µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/local/velocisÀÌ´Ù.

Velocis home page


A custom ODBC library

      --with-custom-odbc=DIR     

»ç¿ëÀÚ ÁöÁ¤ÀÇ ODBC ¶óÀ̺귯¸® Áö¿øÀ» Æ÷ÇÔÇϵµ·Ï ÇÑ´Ù. DIRÀº base µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/localÀÌ´Ù.

ÀÌ ¿É¼ÇÀ» »ç¿ëÇÏ·Á¸é ¿©·¯ºÐÀº configure ½ºÅ©¸³Æ®¸¦ ½ÇÇàÇÒ ¶§ CUSTOM_ODBC_LIBS¸¦ ÀÌ¹Ì Á¤ÀÇÇØ ÁÖ¾ú¾î¾ß ÇÑ´Ù. ¶ÇÇÑ, ¿©·¯ºÐÀÇ include path¿¡´Â ÀûÇÕÇÑ odbc.h¶ó´Â Çì´õ ÆÄÀÏÀÌ ¹Ýµå½Ã ÀÖ¾î¾ß ÇÑ´Ù. ¸¸¾à ¾ø´Ù¸é, ¿©·¯ºÐÀÌ ¸¸µé¾î¼­ Æ÷ÇÔ½ÃÄÑ¾ß ÇÑ´Ù. Çì´õ¿¡´Â Á» Ưº°ÇÑ Á¤ÀǵéÀÌ ÇÊ¿äÇÏ°Ô µÇ´Âµ¥, ƯÈ÷ ±×°ÍÀÌ multiplatformÀÏ °æ¿ì´Â »ó¼¼È÷ Àû¾îÁÖ¾î¾ß ÇÑ´Ù. ±× Á¤ÀÇ´ÂCFLAGS ¿É¼Ç¿¡ Àû¾îÁØ´Ù.

¿¹¸¦µé¾î ´ÙÀ½°ú °°Àº ¿É¼ÇÀ¸·Î QNX ÇÏ¿¡¼­ Sybase SQL Anywhere¸¦ »ç¿ëÇÒ¼ö ÀÖ´Ù. : CFLAGS=-DODBC_QNX LDFLAGS=-lunix CUSTOM_ODBC_LIBS="-ldblib -lodbc" ./configure --with-custom-odbc=/usr/lib/sqlany50


Unified ODBC

      --disable-unified-odbc 

Unified ODBC ¸ðµâÀ» »ç¿ëÇÏÁö ¾Êµµ·ÏÇÑ´Ù. ÀÌ Unified ODBC ¸ðµâÀº Solid³ª Adabas D°°Àº ODBC±â ¹ÝÀÇ ÀÎÅÍÆäÀ̽º(ODBC-based interface)¸¦ °¡Áö°í ÀÖ´Â ¸ðµç databaseÀÇ °øÅëÀÇ interfaceÀÌ´Ù. ¶ÇÇÑ ÀÌ ¸ðµâÀº º¸ÅëÀÇ ODBC ¶óÀ̺귯¸®¸¦ À§ÇØ µ¿ÀÛÇÑ´Ù. ÀÌ ¿É¼ÇÀº iODBC¿Í Solid, Adabas D, Sybase SQL Anywhere¿¡¼­ ½ÃÇèÀ» °ÅÃÆ´Ù. ÀÌ ¿É¼ÇÀ» »ç¿ëÇÏ·Á ¸é À§ÀÇ ¸ðµâµé Áß Çϳª(¹Ýµå½Ã Çϳª¸¸)°Å³ª, vELOCIS ¸ðµâÀÌ enabledµÇ¾î Àְųª custom ODBC library°¡ ¼³Á¤µÇ¾î ÀÖ¾î¾ß ÇÑ´Ù. Áï, ÀÌ ¿É¼ÇÀº ´ÙÀ½°ú °°Àº ¿É¼ÇÁß Çϳª°¡ »ç¿ëµÇ¾úÀ» °æ¿ì¸¸ »ç¿ëÀÌ °¡´ÉÇÏ´Ù. : --with-iodbc, --with-solid, --with-adabas, --with-velocis, --with-custom-odbc.

See also Unified ODBC Configuration Directives in the configuration file.


LDAP

      --with-ldap=DIR     

LDAP (Lightweight Directory Access Protocol) Áö¿øÀ» Æ÷ÇÔÇÑ´Ù. DIRÀº LDAP°¡ ¼³Ä¡µÈ base µð·ºÅ丮À̰í, ±âº»°ªÀº /usr/local/ldapÀÌ´Ù.

LDAP¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ¼³¸íÀº RFC1777 °ú RFC1778¿¡¼­ ãÀ» ¼ö ÀÖ´Ù.


±âŸ ¼³Á¤ ¿É¼Ç


--with-mcrypt=DIR

      --with-mcrypt

mcrypt ¶óÀ̺귯¸®¸¦ Æ÷ÇÔÇÑ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº mcrypt documentationÀ» º¸ÀÚ. DIR ¿É¼ÇÀ» ÁְԵǸé PHP´Â DIR/include¿¡¼­ mcrypt.h¸¦ ã´Â´Ù.


--enable-sysvsem

      --enable-sysvsem

´ëºÎºÐÀÇ UNIX¿¡¼­ Áö¿øÇÏ´Â Sys V ¼¼¸¶Æ÷¾îÀÇ Áö¿øÀ» Æ÷ÇÔÇÑ´Ù. ÀÚ¼¼ÇÑ Á¤º¸´Â Semaphore and Shared Memory documentationÀ» ÀÐ¾î º¸µµ·Ï ÇÑ´Ù.


--enable-sysvshm

      --enable-sysvshm

´ëºÎºÐÀÇ UNIX¿¡¼­ Áö¿øÇÏ´Â Sys V ÀÇ °øÀ¯ ¸Þ¸ð¸®(shared memory) Áö¿øÀ» Æ÷ÇÔÇÑ´Ù. ÀÚ¼¼ÇÑ Á¤º¸´Â Semaphore and Shared Memory documentationÀ» ÀÐ¾î º¸µµ·Ï ÇÑ´Ù.


--with-xml

      --with-xml     

James ClarkÀÇ expat library¸¦ »ç¿ëÇÑ, ¾ÆÁ÷ °øÀιÞÁö ¸øÇÑ XML parser¸¦ »ç¿ëÇϵµ·Ï ÇÑ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº XML function referenceÀ» º¸ÀÚ.


--enable-maintainer-mode

      --enable-maintainer-mode

PHP°³¹ßÀÚµéÀ» À§ÇÑ ÄÄÆÄÀÏ·¯ ÁÖÀÇ ¸Þ½ÃÁö³ª, extra dependencie ¸Þ½ÃÁöµîÀ» Ãâ·ÂÇÏ°Ô ÇÑ´Ù.


--with-system-regex

      --with-system-regex

Á¤±Ô Ç¥Çö½Ä(regular expression) ¶óÀ̺귯¸®¸¦ PHP¿Í °°ÀÌ Á¦°øµÈ °ÍÀÌ ¾Æ´Ñ, ½Ã½ºÅÛÀÇ °ÍÀ» »ç¿ëÇϵµ·Ï ÇÑ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ PHP¸¦ ¼­¹ö ¸ðµâ·Î ¸¸µç´Ù¸é, ¿©·¯ºÐÀº ¼­¹ö¸¦ ¸¸µé ¶§¿Í °°Àº ¶óÀ̺귯¸®¸¦ PHP¸¦ ¸¸µé ¶§µµ »ç¿ëÇÏ¿©¾ß ÇÑ´Ù. ¸¸¾à ½Ã½ºÅÛÀÇ ¶óÀ̺귯¸®°¡ ¿©·¯ºÐÀÌ ¿øÇϴ Ưº°ÇÑ ±â´ÉÀ» °¡Áö°í ÀÖ´Ù¸é ÀÌ ¿É¼ÇÀ» Enable½Ã۵µ·Ï ÇÏÀÚ. ±×·¯³ª, °¡´ÉÇϸé PHP¿Í °°ÀÌ Á¦°øµÈ ¶óÀ̺귯¸®¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ±ÇÀåµÈ´Ù.


--with-config-file-path

      --with-config-file-path=DIR     

PHP°¡ ½ÃÀÛµÉ ¶§ »ç¿ëÇÒ configuration file(php3.ini)À» ãÀ» µð·ºÅ丮¸¦ Á¤ÇØÁØ´Ù.


--with-exec-dir

      --with-exec-dir=DIR     

¾ÈÀü ¸ðµå(safe mode)ÀÏ ¶§, ¿©±â¼­ ÁöÁ¤ÇØ ÁØ =DIR¾ÈÀÇ ½ÇÇà ÆÄÀϸ¸ ½ÇÇàÀÌ °¡´ÉÇÏ´Ù. ±âº»°ªÀº /usr/local/binÀÌ´Ù. ÀÌ ¿É¼ÇÀº ´ÜÁö Default°ªÀ» ÁöÁ¤ÇØ ÁÖ´Â °Í »ÓÀ̰í, configuration fileÀÇ safe_mode_exec_dir Áö½ÃÀÚ¿¡ ÀÇÇØ¼­ ³ªÁß¿¡ ¹Ù²ð ¼ö ÀÖ´Ù.


--disable-debug

      --disable-debug     

¶óÀ̺귯¸®³ª ½ÇÇà ÆÄÀÏ¿¡ µð¹ö±× Á¤º¸¸¦ Æ÷ÇÔ½ÃŰÁö ¾Ê´Â´Ù. µð¹ö±× Á¤º¸´Â ¹ö±×ÀÇ À§Ä¡¸¦ Á¤È®ÇÏ°Ô ³ªÅ¸³»´Âµ¥ µµ¿òÀ» ÁØ´Ù. µû¶ó¼­, PHP°¡ alpha³ª beta»óÅÂÀÏ °æ¿ì¿¡´Â µð¹ö±× Á¤º¸¸¦ Æ÷ÇÔ½ÃŰ´Â °ÍÀÌ ÁÁ´Ù.


--enable-safe-mode

      --enable-safe-mode     

±âº»°ªÀ¸·Î "¾ÈÀü ¸ðµå"(safe mode)¸¦ ÁöÁ¤ÇÑ´Ù. ¾ÈÀü ¸ðµå´Â ¹®¼­ÀÇ root¿¡ ÀÖ´Â ÆÄÀϸ¸À» ¿­¼ö ÀÖ°Ô ÇÏ´Â µî, PHP°¡ ÇÒ ¼ö ÀÖ´Â ÀÛ¾÷¿¡ ¿©·¯ °¡Áö Á¦¾àÀ» °¡ÇÑ´Ù. ´õ ÀÚ¼¼ÇÑ Á¤º¸´Â Security chapter¸¦ Àо±â ¹Ù¶õ´Ù. CGI»ç¿ëÀÚµéÀº ¾ðÁ¦³ª secure mode¿¡¼­ »ç¿ëÇÏ¿©¾ß ÇÑ´Ù. ÀÌ ¿É¼ÇÀº ´ÜÁö Default °ªÀ» Á¤ÇÏ´Â °Í »ÓÀ̰í, ÈÄ¿¡ configuration fileÀÇ safe_mode Áö½ÃÀÚ¿¡ ÀÇÇØ Enable/Disable µÉ ¼ö ÀÖ´Ù.


--enable-track-vars

      --enable-track-vars     

HTTP_GET_VARS, HTTP_POST_VARS, HTTP_COOKIE_VARS ¹è¿­¿¡ µé¾îÀÖ´Â GET / POST / cookie º¯¼öµéÀÌ ¾îµð¼­ ¿Ô´ÂÁö ±â¾ïÇϰí ÀÖ°Ô ¸¸µç´Ù. ÀÌ ¿É¼ÇÀº ´ÜÁö Default °ªÀ» Á¤ÇÏ´Â °Í »ÓÀ̰í, ÈÄ¿¡ configuration fileÀÇ track_vars Áö½ÃÀÚ¿¡ ÀÇÇØ Enable/Disable µÉ ¼ö ÀÖ´Ù.


--enable-magic-quotes

      --enable-magic-quotes     

magic quotesÀÇ ±âº»°ªÀ» Enable·Î ÇÑ´Ù. ÀÌ ¿É¼ÇÀº ´ÜÁö Default °ªÀ» Á¤ÇÏ´Â °Í »ÓÀ̰í, ÈÄ¿¡ configuration fileÀÇ magic_quotes_runtimeÁö½ÃÀÚ¿¡ ÀÇÇØ Enable/Disable µÉ ¼ö ÀÖ´Ù.

magic_quotes_gpc ¿Í magic_quotes_sybase Áö½ÃÀÚ¸¦ ÂüÁ¶ÇÏ¿© º¸±â ¹Ù¶õ´Ù.


--enable-debugger

      --enable-debugger     

³»ÀåµÈ PHP µð¹ö°Å Áö¿øÀ» °¡´ÉÇÏ°Ô ÇÑ´Ù. ÀÌ ±â´ÉÀº ¾ÆÁ÷ ½ÇÇèÀûÀÎ »óÅÂÀÌ´Ù.

configuration fileÀÇ Debugger Configuration Áö½ÃÀÚ¸¦ »ìÆìº¸ÀÚ.


--enable-discard-path

      --enable-discard-path     

¸¸¾à À̰ÍÀÌ EnabledµÇ¸é, PHP CGI ½ÇÇàÆÄÀÏÀÌ À¥ Æ®¸® ¹Û¿¡ ¾ÈÀüÇÏ°Ô À§Ä¡ÇÒ ¼ö ÀÖ°Ô µÇ¾î »ç¿ëÀÚµéÀÌ .htaccess security¸¦ ÇÇÇÒ ¼ö ¾ø°Ô µÈ´Ù. ÀÚ¼¼ÇÑ »çÇ×Àº section in the security chapter¸¦ Àо±â ¹Ù¶õ´Ù.


--enable-bcmath

      --enable-bcmath     

bc Çü½ÄÀÇ ¼öÀÇ Á¤¹Ðµµ(precision)¸¦ ¸¶À½´ë·Î Á¶Á¤ÇÒ ¼ö ÀÖ´Â ¼öÇÐ ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼ö ÀÖ°Ô ÇØ ÁØ´Ù.

See also the bcmath.scale option in the configuration file.


--enable-force-cgi-redirect

      --enable-force-cgi-redirect     

³»ºÎÀûÀÎ ¼­¹ö ¸®µð·ºÆ®(internal server redirects) ½Ã¿¡ º¸¾È °Ë»ç(security check)¸¦ Çϵµ·Ï ÇÑ´Ù. ¿©·¯ºÐÀÌ Apache¿Í ÇÔ²² CGI ¹öÀüÀ» »ç¿ëÇÑ´Ù¸é ¹Ýµå½Ã ÀÌ ¿É¼ÇÀ» »ç¿ëÇÏ¿©¾ß ÇÑ´Ù.

GI binaryÇüÅ·ΠPHP¸¦ »ç¿ëÇÒ ¶§, PHP´Â ±âº»ÀûÀ¸·Î ±×°ÍÀÌ ¸®µð·º¼ÇÀ¸·Î »ç¿ëµÇ¾ú´Â°¡¸¦ ¿ì¼± °Ë»çÇÑ´Ù(¿¹¸¦ µé¾î, Apache¿¡¼­ Action directives¸¦ »ç¿ëÇÑ °æ¿ìÀÌ´Ù). ÀÌ ¿É¼ÇÀ» »ç¿ëÇϸé http://my.host/cgi-bin/php/secret/doc.html°ú °°Àº ¹æ¹ýÀ¸·Î PHP binary¸¦ Á÷Á¢ È£ÃâÇÏ¿© Ç¥ÁØ web server authentication ÀýÂ÷¸¦ ȸÇÇÇÏ´Â ¹æ¹ýÀ» »ç¿ëÇÒ ¼ö ¾ø°Ô µÈ´Ù. ÀÌ ¿¹´Â http://my.host/secret/doc.html¿¡ Á¢±ÙÇÒ ¼ö ÀÖÁö¸¸, httpd°¡ /secretµð·ºÅ丮¿¡ ¼³Á¤ÇÑ ¾î¶°ÇÑ º¸¾È ¼³Á¤¿¡µµ ¿µÇâÀ» ¹ÞÁö ¾Ê°Ô µÈ´Ù.

ÀÌ ¿É¼ÇÀ» EnableÇÏÁö ¾ÊÀ¸¸é httpddÀÇ º¸¾È°ú ÀÎÁõ ¼³Á¤À» üũÇÏÁö ¾Ê°í, ȸÇǰ¡ °¡´ÉÇÏ°Ô µÈ´Ù. ÀÌ ¿É¼ÇÀº ¼­¹ö ¼ÒÇÁÆ®¿þ¾î°¡ ¾ÈÀüÇÑ ¸®µð·º¼ÇÀÌ µÇ¾î ÀÖ´Ù´Â °ÍÀ» ³ªÅ¸³»´Â °ÍÀÌ ºÒ°¡´ÉÇϰí, document root¿Í »ç¿ëÀÚ µð·ºÅ丮 ¾Æ·¡ÀÇ ¸ðµç ÆÄÀÏÀÌ ´©±¸¿¡°Ô³ª °³¹æµÇ¾î ÀÖÀ» ¶§¸¸ »ç¿ëÇÏÀÚ.

ÀÌ ¿É¼Ç¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ¼³¸íÀº section in the security chapterÀ» Àо±â ¹Ù¶õ´Ù


--disable-short-tags

      --disable-short-tags     

short form <? ?> PHP ű×ÀÇ »ç¿ëÀ» ºÒ°¡´ÉÇÏ°Ô ÇÑ´Ù. ¿©·¯ºÐÀº PHP¿Í XMLÀ» ÇÔ²² »ç¿ëÇÒ °æ¿ì short formÀÇ »ç¿ëÀ» ºÒ°¡´ÉÇÏ°Ô ÇÏ¿©¾ß ÇÑ´Ù. ªÀº ű×ÀÇ »ç¿ëÀÌ ºÒ°¡´ÉÇÏ´Ù¸é, PHPÀÇ ÄÚµå´Â ű״ <?php ?> »ÓÀÌ´Ù. ÀÌ ¿É¼ÇÀº ´ÜÁö Default °ªÀ» Á¤ÇÏ´Â °Í »ÓÀ̰í, ÈÄ¿¡ configuration fileÀÇ short_open_tag Áö½ÃÀÚ¿¡ ÀÇÇØ Enable/Disable µÉ ¼ö ÀÖ´Ù.


--enable-url-includes

      --enable-url-includes     

include()ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© PHP¿¡¼­ Á÷Á¢ ´Ù¸¥ HTTP³ª FTP¼­¹ö¿¡ ÀÖ´Â Äڵ带 ½ÇÇà½Ãų¼ö ÀÖµµ·Ï ÇÑ´Ù.

See also the include_path option in the configuration file.


--disable-syntax-hl

      --disable-syntax-hl 

syntax highlighting ±â´ÉÀ» ²ö´Ù.


CPPFLAGS and LDFLAGS

PHP¸¦ ¼³Ä¡ÇÒ ¶§ ´Ù¸¥ µð·ºÅ丮¿¡ ÀÖ´Â Çì´õ³ª ¶óÀ̺귯¸®¸¦ ã¾Æ¼­ ¸¸µé·Á¸é, CPPFLAGS ¿Í LDFLAGS ȯ°æº¯¼ö¸¦ °¢°¢ ¼öÁ¤ÇØ ÁÖ¾î¾ß ÇÑ´Ù. ¿©·¯ºÐÀÌ ÀϹÝÀûÀÎ ½©À» »ç¿ëÇϰí ÀÖ´Ù¸é ´ÙÀ½°ú °°ÀÌ »ç¿ëÇÏ´Â °ÍÀÌ °¡´ÉÇÒ °ÍÀÌ´Ù. LDFLAGS=-L/my/lib/dir CPPFLAGS=-I/my/include/dir ./configure


Building

PHPÀÇ ¼³Á¤ÀÌ ¿Ï·áµÇ¸é ¿©·¯ºÐÀº PHP ¶óÀ̺귯¸®³ª CGI ½ÇÇà ÆÄÀÏÀ» »ý¼ºÇÒ Áغñ°¡ ³¡³­ °ÍÀÌ´Ù. make ¸í·ÉÀ¸·Î ¿©·¯ºÐÀº ±×°ÍÀ» ¸¸µé ¼ö ÀÖ´Ù. ¸¸¾à ¸¸µé ¼ö ¾ø°í ±× ÀÌÀ¯¸¦ ¸ð¸¦ °æ¿ì¿¡´Â Problems sectionÀ» »ìÆìº¸±â ¹Ù¶õ´Ù.

( ¿ªÀÚÁÖ : PHP¸¦ Apache ¸ðµâ·Î ¸¸µé¾ú´Ù¸é restart°¡ ¾Æ´Ñ stopÈÄ startÇÏ¿©¾ß ÇÕ´Ï´Ù.)


Testing

PHP¸¦ CGI ÇÁ·Î±×·¥ ÇüÅ·Π¸¸µé¾ú´Ù¸é, ¿©·¯ºÐÀº make test¶ó°í ÀÔ·ÂÇÏ¿© Å×½ºÆ®ÇØ º¼ ¼ö ÀÖ´Ù. ÀÌ ¹æ¹ýÀº °á°ú¹°À» Å×½ºÆ®ÇÏ´Â ¾ðÁ¦³ª ÁÁÀº ¹æ¹ýÀÌ´Ù. ÀÌ ¹æ¹ýÀº ¿©·¯ºÐÀÇ ½Ã½ºÅÛ È¯°æ¿¡¼­ ³ªÁß¿¡ ¹®Á¦·Î °ñÄ¡ ½âÀÌÁö ¾Ê°í ¹Ì¸® PHPÀÇ ¹®Á¦¸¦ ¹ß°ßÇÒ ¼ö ÀÖ°Ô ÇØ ÁØ´Ù.


Benchmarking

PHP¸¦ CGI ÇÁ·Î±×·¥ ÇüÅ·Π¸¸µé¾ú´Ù¸é, ¿©·¯ºÐÀº make bench¶ó°í ÀÔ·ÂÇÏ¿© º¥Ä¡¸¶Å© Å×½ºÆ®¸¦ ÇÒ ¼ö ÀÖ´Ù. ¾ÈÀü ¸ðµå(safe mode)ÀÇ ±âº»°ªÀÌ on µÇ¾î ÀÖÀ» ¶§´Â, ÀÛ¾÷ÀÌ Çã¿ëµÈ 30ÃÊ º¸´Ù ¸¹ÀÌ °É¸®°Ô µÇ¸é º¥Ä¡¸¶Å©¸¦ ³¡³¾ ¼ö ¾ø´Ù. À̰ÍÀº ¾ÈÀü ¸ðµå¿¡¼­´Â set_time_limit() ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼ö ¾ø±â ¶§¹®ÀÌ´Ù. ½ºÅ©¸³Æ®¿¡¼­ max_execution_timeÀ» Á¶ÀýÇÏ¿© ÀÌ ½Ã°£ °£°ÝÀ» Á¶ÀýÇÑ´Ù. make bench´Â configuration fileÀ» ¹«½ÃÇÑ´Ù.


PHP Installation Guide for Windows

ÀÌ ¼³Ä¡ ¾È³»¼­´Â ¿©·¯ºÐ¿¡°Ô PHP¸¦ Windows 9x/NT À¥¼­¹ö¿¡¼­ ¼³Ä¡ÇÏ°í ¼³Á¤Çϴµ¥ µµ¿òÀ» ÁÙ °ÍÀÔ´Ï´Ù. ÀÌ ¾È³»¼­´Â Bob Silva¿¡ ÀÇÇØ ÀÛ¼ºµÇ¾ú½À´Ï´Ù. µû¶ó¼­ °¡Àå ÃÖ½ÅÀÇ °³Á¤ÆÇÀº http://www.umesd.k12.or.us/php/win32install.html¿¡¼­ ãÀ» ¼ö ÀÖÀ» °ÍÀÔ´Ï´Ù.

ÀÌ ¾È³»¼­´Â ´ÙÀ½°ú °°Àº À¥¼­¹ö¸¦ ´ë»óÀ¸·Î ÇÕ´Ï´Ù.


ÀϹÝÀûÀÎ ¼³Ä¡ °úÁ¤

À¥ ¼­¹öÀÇ Á¾·ù¿Í °ü°è¾øÀÌ ´ÙÀ½ÀÇ ¼³Ä¡ °úÁ¤µéÀÌ ¿Ï·áµÇ¾î¾ß ÇÑ´Ù.

PHP È®ÀåÀ» À§ÇÑ DLLµéÀº 'php3_'·Î ½ÃÀÛÇÑ´Ù. À̰ÍÀº PHP È®ÀåÀ» À§ÇÑ DLLµé°ú ÀÚüÀûÀÎ Áö¿øÀ» À§ÇÑ DLLµé°£ÀÇ È¥¶õÀ» ¹æÁöÇϱâ À§Çؼ­ÀÌ´Ù.


Windows 95/98/NT¿Í PWS/IIS 3

ÀÌ ¼­¹öµé¿¡¼­ÀÇ ¼³Á¤Àº ¹èÆ÷ÆÇÀÇ INF ÆÄÀÏ(php_iis_reg.inf)À» »ç¿ëÇÏ´Â °ÍÀ» ±ÇÇÑ´Ù. ¿©·¯ºÐÀº ÀÌ ÆÄÀÏÀ» ¼öÁ¤ÇÏ¿© ¿©·¯ºÐÀÌ ¿øÇÏ´Â PHP ¼³Ä¡ µð·ºÅ丮¿Í È®Àå ³»¿ëµéÀ» ¼³Á¤ÇÒ ¼ö ÀÖ´Ù. ¸¸¾à ¼öµ¿À¸·Î ¼³Á¤ÇÏ°í ½Í´Ù¸é ´ÙÀ½°ú °°ÀÌ ÇÕ´Ï´Ù.

ÁÖÀÇ : ÀÌ °úÁ¤Àº À©µµ¿ìÀÇ resistry¸¦ Á÷Á¢ ´Ù·ì´Ï´Ù. ÇϳªÀÇ ½Ç¼ö°¡ ¿©·¯ºÐÀÇ ½Ã½ºÅÛ Àüü¸¦ ºÒ¾ÈÇÑ »óÅ·Π¸¸µé ¼ö ÀÖ½À´Ï´Ù. ¿ì¸®´Â ¿©·¯ºÐÀÌ registry¸¦ ÆíÁýÇϱâ Àü¿¡ ¹Ýµå½Ã ÆíÁý ÀüÀÇ registry¸¦ ¹é¾÷ÇØ ³õÀ» °Í. PHP °³¹ßÆÀÀº ¾î¶°ÇÑ registryÀÇ ÆÄ¼Õµµ Ã¥ÀÓÁöÁö ¾Ê½À´Ï´Ù. ¸¸¾à registry¿¡ ¼Õ»óÀÌ °¥ °æ¿ì OS¸¦ »õ·Î ±ò±â Àü¿¡´Â ºÎÆÃµÇÁö ¾ÊÀ» ¼öµµ ÀÖ½À´Ï´Ù.

PWS¿Í IIS 3 »ç¿ëÀÚµéÀº ÇöÀç ¿ÏÀüÇÑ ¿î¿µÁßÀÎ ½Ã½ºÅÛÀ» °®°í ÀÖ½À´Ï´Ù. IIS 3 »ç¿ëÀÚµéÀº Steven Genusa°¡ ÀÛ¼ºÇÑ ½ºÅ©¸³Æ® ¸ÊÀ» ¼³Á¤ÇÏ´Â ¸Å·ÂÀûÀÎ toolÀ» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.


Windows NT¿Í IIS 4

PHP¸¦ IIS 4°¡ ¿î¿µÁßÀÎ NT Server¿¡ ¼³Ä¡ÇÏ·Á¸é ´ÙÀ½ °úÁ¤À» µû¸¥´Ù.


Windows 9x/NT¿Í Apache 1.3.x

Apache¸¦ PHP CGI binary¿Í ÇÔ²² ½ÇÇàÇϵµ·Ï ¼³Á¤ÇÏ·Á¸é srm.confÀ̳ª httpd.conf¸¦ ´ÙÀ½°ú °°ÀÌ ¼öÁ¤ÇÏ¿©¾ß ÇÑ´Ù.

ºñ·Ï ApacheÇÏ¿¡¼­ PHPÀÇ ¼³Á¤ÀÌ ¾à°£ Â÷À̰¡ ÀÖÀ»Áö ¸ð¸£Áö¸¸, ÀÌ ¼³Á¤Àº Ãʺ¸ÀÚµµ ÇÒ ¼ö ÀÖÀ» Á¤µµ·Î ½±´Ù. ¿©±â¿¡ ³ª¿Â °Í ÀÌ»óÀÇ ¼³Á¤ Áö½ÃÀÚ´Â Apache Docs¸¦ ÂüÁ¶Çϵµ·Ï ÇÏÀÚ.

¼Ò½º ÄÚµå ÇÏÀ̶óÀÌÆÃ ±â´É(¼Ò½º¿¡ »ö±òÀ» ³Ö¾î¼­ º¸±â ÁÁ°Ô Ãâ·ÂÇØ ÁÖ´Â ±â´É)À» »ç¿ëÇϱâ À§Çؼ­´Â ´ÙÀ½°ú °°Àº ³»¿ëÀ» °¡Áö´Â ½ºÅ©¸³Æ®¸¦ ¸¸µé¾îÁÖ¸é µÈ´Ù. : <?php show_source ("original_php_script.php3"); ?>. ¿©±â¼­ original_php_script.php3¸¦ ¿©·¯ºÐÀÌ ¿øÇÏ´Â ¼Ò½º ÄÚµåÀÇ À̸§À¸·Î ¹Ù²ãÁÖ¸é µÈ´Ù.

Note: Win-Apache¿¡¼­ "c:\directory\file.ext"¿Í °°ÀÌ path¿¡ »ç¿ëµÇ´Â ¸ðµç ¹é½½·¡½Ã(\)´Â ÀÏ¹Ý ½½·¡½Ã(/)·Î ¹Ù²ã¾ß ÇÕ´Ï´Ù.


Windows¿¡¼­ Omni HTTPd 2.0b1

ÀÌ ¼³Á¤Àº ¸Å¿ì ½¬¿î ÆíÀÌ´Ù.

Step 1: Omni server¸¦ ¼³Ä¡ÇÑ´Ù.

Step 2: system trayÀÇ Çª¸¥»ö OmniHTTPd ¾ÆÀÌÄÜ¿¡¼­ ¿À¸¥ÂÊ ¹öưÀ» Ŭ¸¯ÇÏ¿© Properties(µî·ÏÁ¤º¸)¸¦ ¼±ÅÃÇÑ´Ù.

Step 3: Web Server Global SettingsÀ» Ŭ¸¯ÇÑ´Ù.

Step 4: 'External' ÅÇ¿¡¼­ ´ÙÀ½À» ÀÔ·ÂÇÑ´Ù. : virtual = .php3 | actual = c:\path-to-php-dir\php.exe

Step 5: Mime ÅÇ¿¡¼­ ´ÙÀ½À» ÀÔ·ÂÇÑ´Ù. : virtual = wwwserver/stdcgi | actual = .php3

Step 6: OK¸¦ Ŭ¸¯ÇÑ´Ù.

PHPÀÇ ¸ðµç È®ÀåÀÚ¿¡ ´ëÇØ steps 2 - 6À» ¹Ýº¹ÇÑ´Ù.


PHP Modules

Table 2-1. PHP Modules

php3_calendar.dll

Calendar conversion functions

php3_crypt.dll

Crypt functions

php3_dbase.dll

DBase functions

php3_dbm.dll

GDBM emulation via Berkely DB2 library

php3_filepro.dll

READ ONLY access to filepro databases

php3_gd.dll

GD Library functions for gif manipulation

php3_hyperwave.dll

HyperWave functions

php3_imap4r2.dll

IMAP 4 functions

php3_ldap.dll

LDAP functions

php3_msql1.dll

mSQL 1 client

php3_msql2.dll

mSQL 2 client

php3_mssql.dll

MSSQL client (requires MSSQL DB-Libraries)

php3_mysql.dll

MySQL functions

php3_nsmail.dll

Netscape mail functions

php3_oci73.dll

Oracle functions

php3_snmp.dll

SNMP get and walk functions (NT only!)

php3_zlib.dll

ZLib functions


Problems?


Read the FAQ

ÀϺΠÁú¹®µéÀº °øÅëÀûÀÎ °ÍÀÌ ¸¹´Ù. PHP FAQ¿¡ ÀÌ °øÅëÀûÀÎ Áú¹®µéÀÌ ¸ð¿©ÀÖÀ¸´Ï ã¾Æº¸ÀÚ. ÀÌ ¹®¼­´Â http://www.php.net/FAQ.php3¿¡¼­ ãÀ» ¼ö ÀÖ´Ù.

(¿ªÀÚÁÖ : FAQÀÇ ¹ø¿ªº»Àº http://w3.to/regina/FAQ.htm¿¡ ¹ø¿ªµÇ¾î ÀÖÀ¸³ª ÃֽůÇÀº ¾Æ´Ï´Ù.)


Bug reports

¸¸¾à ¿©·¯ºÐÀÌ Bug¶ó°í »ý°¢µÇ´Â °ÍÀÌ ¹ß°ßµÉ °æ¿ì À̰ÍÀ» ¹Ýµå½Ã º¸°íÇØ Áֱ⠹ٶõ´Ù. PHPÀÇ °³¹ßÀÚµéÀº ¾Æ¸¶ ±× ¹ö±×¿¡ ´ëÇØ ¿©·¯ºÐÀÌ ¾Ë·ÁÁÖ±â Àü¿¡´Â ¸ð¸£°í ÀÖÀ» °ÍÀÌ´Ù. ¿©·¯ºÐÀÇ ¹ö±× ·¹Æ÷Æ®·Î ±× ¹ö±×µéÀ» ÀâÀ» ¼ö ÀÖ´Ù. ¹ö±× º¸°í¿ë ÆûÀÌ PHP »çÀÌÆ®¿¡ ÀÖ´Ù. ÁÖ¿ä ¾ç½ÄÀº http://ca.php.net/bugs.php3¿¡¼­ ãÀ» ¼ö ÀÖÀ» °ÍÀÌ´Ù. (¿ªÀÚÁÖ: ¹ö±× ·¹Æ÷Æ®´Â ¿µ¾î·Î ½á¾ß °ÚÁö¿ä. Hi)


Other problems

¸¸¾à ¿©·¯ºÐÀÌ ¾ÆÁ÷µµ °í»ýÇϰí ÀÖ´Ù¸é, PHPÀÇ ¸ÞÀϸµ ¸®½ºÆ®(mailing list)°¡ µµ¿òÀ» ÁÙ ¼ö ÀÖÀ» °ÍÀÌ´Ù. ¿©·¯ºÐÀÌ ¸¸¾à ¾î¶² Áú¹®À» Çϱâ Àü¿¡ ¿ì¼± º¸°ü ¹®¼­(archive)¸¦ ã¾Æº¸¾Æ °°Àº ¹®Á¦¿¡ ´ëÇÑ ÇØ´äÀÌ ÀÖ´ÂÁö ã¾Æº¸´Â °ÍÀ» ÀØÁö ¸»µµ·Ï ÇÏÀÚ. º¸°ü ¹®¼­´Â http://www.php.net/¿¡¼­ ã¾Æ º¼ ¼ö ÀÖ´Ù. PHP ¸ÞÀϸµ ¸®½ºÆ®¿¡ Âü°¡ÇÏ·Á¸é php3-subscribe@lists.php.netÀ¸·Î ºó ÆíÁö¸¦ Çϳª º¸³»¸é µÈ´Ù. mailing list ÁÖ¼Ò´Â php3@lists.php.netÀÌ´Ù.

¸¸¾à ¿©·¯ºÐÀÌ mailing list¸¦ ÅëÇØ¼­ ¾î¶² µµ¿òÀ» ¹Þ°í ½Í´Ù¸é, Áú¹®½Ã¿¡ ÀÚ¼¼ÇÏ°í ¸íÈ®ÇÑ Áú¹®°ú ÇÔ²², ¿©·¯ºÐÀÇ ¿î¿µ ȯ°æ¿¡ ´ëÇÑ ¼¼ºÎÇ׸ñÀ» ÷ºÎÇÏ´Â °ÍÀÌ ÁÁ´Ù (¿î¿µÃ¼°è, PHP ¹öÀü, À¥¼­¹öÀÇ Á¾·ù¿Í ¹öÀü, PHP¸¦ CGI·Î ¾²°í ÀÖ´ÂÁö ¸ðµâ·Î ¾²°í ÀÖ´ÂÁö µî). ¶ÇÇÑ ¿©·¯ºÐÀÌ ´ç¸éÇÑ ¹®Á¦¸¦ ÀçÇöÇÒ ¼ö ÀÖ´Â Äڵ带 Æ÷ÇÔ½ÃŰ¸é ´õ¿í ÁÁ´Ù. (¿ªÀÚÁÖ: À̰͵µ ´ç¿¬È÷ ¿µ¾î·Î ½á¾ß °ÚÁö¿ä. Hi)


Chapter 3. ¼³Á¤(Configuration)


The configuration file

¼³Á¤ ÆÄÀÏ(configuration file)Àº (PHP 3.0¿¡¼­´Â php3.ini À̰í, PHP 4.0¿¡¼­´Â php.ini ÀÌ´Ù.) PHP°¡ ½ÃÀÛµÉ ¶§ ÀÐÇôÁø´Ù. ¼­¹ö ¸ðµâ ÇüÅÂÀÇ PHP´Â ÀÌ ÀÛ¾÷À» ¼­¹ö°¡ ½ÇÇà µÉ ¶§ Çѹø¸¸ ÇÏ°Ô µÈ´Ù. CGIÇüÅÂÀÇ °æ¿ì´Â ºÒ·ÁÁú ¶§¸¶´Ù ¸Å¹ø ÀϾ´Ù.

PHP¸¦ ¾ÆÆÄÄ¡ ¸ðµâ·Î »ç¿ëÇÒ ¶§´Â, PHPÀÇ ¼³Á¤À» Apache configuration ÆÄÀϰú .htaccess ÆÄÀÏ¿¡¼­ ÁöÁ¤ÇÏ¿© ¼³Á¤ÇÒ ¼öµµ ÀÖ´Ù.

PHP 3.0¿¡¼­´Â, PHPÀÇ Áö½ÃÀÚ(directive)µé°ú ÀÏÄ¡ÇÏ´Â Apache httpd.conf Áö½ÃÀÚ°¡ ÀÖ´Ù. httpd.conf¿¡¼­ÀÇ Áö½ÃÀÚ À̸§Àº php3.iniÀÇ Áö½ÃÀÚ À̸§ ¾Õ¿¡ "php3_"¸¦ ºÙÀÎ °ÍÀÌ´Ù.

PHP 4.0¿¡¼­´Â ´ÙÀ½°ú °°Àº ¸î °³ÀÇ Apache Áö½ÃÀÚ¸¸À¸·Î PHP ¼³Á¤À» ¹Ù²Ü ¼ö ÀÖ´Ù.

php_value name value
ÁöÁ¤µÈ º¯¼ö¿¡ ¿øÇÏ´Â °ªÀ» ¼³Á¤ÇÑ´Ù.
php_flag name on|off
Boolean °ªÀ» °¡Áö´Â ¼³Á¤ ¿É¼ÇÀÇ °ªÀ» ¼³Á¤ÇÑ´Ù.
php_admin_value name value
ÁöÁ¤µÈ º¯¼ö¿¡ ¿øÇÏ´Â °ªÀ» ¼³Á¤ÇÑ´Ù. "Admin" À¸·Î ÁöÁ¤µÈ ¼³Á¤Àº main Apache ¼³Á¤ÆÄÀÏ¿¡¼­¸¸ ¼³Á¤ÀÌ °¡´ÉÇÏ´Ù. .htaccess ÆÄÀÏ¿¡¼­ ±× ³»¿ëÀ» º¯°æÇÏ´Â °ÍÀº ºÒ°¡´ÉÇÏ´Ù.
php_admin_flag name on|off
Boolean °ªÀ» °¡Áö´Â ¼³Á¤ ¿É¼ÇÀÇ °ªÀ» ¼³Á¤ÇÑ´Ù.

( ¿ªÀÚÁÖ : PHP¸¦ ¾ÆÆÄÄ¡ ¸ðµâ·Î »ç¿ëÇÒ °æ¿ì httpd.conf¿¡ Àû¾îÁØ ¿É¼Ç¸¸ ÀÛµ¿ÇÑ´Ù°í ÇÑ´Ù. )
( ¿ªÀÚÁÖ : httpd.conf¿¡ ¿É¼ÇÀ» Àû´Â ¹æ¹ýÀº Á¶±Ý ´Ù¸£´Ù. "="À» »ç¿ëÇÏÁö¸»°í ±×³É ÇÑÄ­À» ¶ç°í Àû¾îÁÖ¸é µÈ´Ù.
include_path ¿É¼ÇÀ» ¼³Á¤ÇÏ´Â ¿¹´Â ´ÙÀ½°ú °°´Ù. php3_include_path .:/home/httpd/php-lib )

ÇöÀç ¼³Á¤µÈ ¼³Á¤°ªÀº phpinfo()ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© È®ÀÎÇØ º¼ ¼ö ÀÖ´Ù. ¶ÇÇÑ °³°³ÀÇ ¼³Á¤ ³»¿ëÀ» È®ÀÎÇϱâ À§Çؼ­´Â get_cfg_var()ÇÔ¼ö¸¦ »ç¿ëÇÏ¸é µÈ´Ù.


General Configuration Directives

asp_tags boolean
ÀϹÝÀûÀÎ <?php ?> Åà ´ë½Å¿¡ ASP ½ºÅ¸ÀÏÀÇ <% %> ÅÃÀ» Ãß°¡ÀûÀ¸·Î »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÑ´Ù. ¶ÇÇÑ º¯¼ö°ª Ãâ·Â¹®ÀÎ <%= $value %> ÇüÅÂÀÇ Áö¿øµµ Æ÷ÇÔÇÑ´Ù. ÀÚ¼¼ÇÑ Á¤º¸´Â Escaping from HTML ºÎºÐÀ» ÂüÁ¶ÇÏÀÚ.

Note: ASP-style tags Áö¿øÀº 3.0.4 ¹öÀü¿¡¼­ Ãß°¡µÇ¾ú´Ù.

auto_append_file string
main ÆÄÀÏ ÈÄ¿¡ ÀÚµ¿À¸·Î ÇØ¼®µÉ ÆÄÀÏÀÇ À̸§À» ¸í½ÃÇÑ´Ù. ±× ÆÄÀÏÀº include()ÇÔ¼ö¸¦ ÅëÇØ¼­ Æ÷ÇԵǹǷΠinclude_path Áö½ÃÀÚ°¡ »ç¿ëµÈ´Ù.

none °ªÀ» ÁÖ°Ô µÇ¸é auto-appendingÀÌ disableµÈ´Ù.

NOTE: ¸¸¾à ½ºÅ©¸³Æ®°¡ exit()·Î Á¾·áµÇ°Ô µÇ¸é auto-append´Â ÀϾÁö ¾Ê´Â´Ù.

auto_prepend_file string
main ÆÄÀÏ Àü¿¡ ÀÚµ¿À¸·Î ÇØ¼®µÉ ÆÄÀÏÀÇ À̸§À» ¸í½ÃÇÑ´Ù. ±× ÆÄÀÏÀº include() ÇÔ¼ö¸¦ ÅëÇØ¼­ Æ÷ÇԵǹǷΠinclude_path Áö½ÃÀÚ°¡ »ç¿ëµÈ´Ù.

none °ªÀ» ÁÖ°Ô µÇ¸é auto-prependingÀÌ disableµÈ´Ù.

 
cgi_ext string
 
 
display_errors boolean
ÀÌ °áÁ¤ÀÚ(determine)´Â ¿¡·¯°¡ »ý°åÀ» ¶§ HTML Á¶°¢ÀÇ Ãâ·ÂÀ» ½ºÅ©¸°À¸·Î º¸ÀÏ °ÍÀΰ¡ ¾Æ´Ñ°¡¸¦ °áÁ¤ÇÑ´Ù.
 
doc_root string
PHPÀÇ "root directory"¸¦ ÁöÁ¤ÇÑ´Ù. ¹Ýµå½Ã °ªÀ» °¡Á®¾ß ÇÑ´Ù. PHP°¡ ¾ÈÀü¸ðµå(safe mode)·Î ¼³Á¤µÇ¾î ÀÖÀ» °æ¿ì, ÀÌ µð·ºÅ丮 ¹Û¿¡ ÀÖ´Â ÆÄÀÏÀº »ç¿ëÇÒ ¼ö ¾ø´Ù.
 
engine boolean
ÀÌ Áö½ÃÀÚ´Â ¾ÆÆÄÄ¡ ¸ðµâ ¹öÀüÀÇ PHP¿¡¼­¸¸ À¯È¿ÇÏ´Ù. À̰ÍÀº »çÀÌÆ®¿¡¼­ µð·ºÅ丮 ´ÜÀ§³ª, Virtual ¼­¹ö ´ÜÀ§¸¦ ±â¹ÝÀ¸·Î PHP ÆÄ½Ì ±â´ÉÀ» ÄѰųª ²ôµµ·Ï ÇÑ´Ù. httpd.conf ÆÄÀÏÀÇ Àû´çÇÑ À§Ä¡¿¡ php3_engine off¶ó°í ¸í½ÃÇÔÀ¸·Î½á, PHP¸¦ °¡´ÉÇϰųª ºÒ°¡´ÉÇÏ°Ô ÇÒ ¼ö ÀÖ´Ù.
 
error_log string
½ºÅ©¸³Æ® ¿¡·¯°¡ ·Î±×µÉ ÆÄÀÏ À̸§À» Á¤ÇÑ´Ù. ·Î±× ÆÄÀÏ·Î ½Ã½ºÅÛ ·Î±×¸¦ »ç¿ëÇϱâ À§Çؼ­ syslog¶ó´Â Ưº°ÇÑ °ªÀÌ ÀÌ¿ëµÈ´Ù. À¯´Ð½º¿¡¼­´Â syslog(3)À̰í, Windows NT¿¡¼­´Â Event log°¡ µÈ´Ù. Windows 95¿¡¼­´Â ½Ã½ºÅÛ ·Î±×¸¦ Áö¿øÇÏÁö ¾Ê´Â´Ù.
 
error_reporting integer
¿¡·¯ ·¹Æ÷ÆÃÀÇ ·¹º§À» ¼³Á¤ÇÑ´Ù. ÀÌ ÆÄ¶ó¸ÞŸ °ªÀº ºñÆ® ´ÜÀ§·Î ¼³Á¤ÇÑ´Ù. ´ÙÀ½ Áß¿¡ ¿øÇÏ´Â ¿¡·¯ ·¹Æ÷ÆÃ ·¹º§ÀÇ °ªÀ» ´õÇØÁÖ¸é µÈ´Ù.

Table 3-1. Error Reporting Levels

bit value

enabled reporting

1

normal errors

2

normal warnings

4

parser errors

8

non-critical style-related warnings

±âº»°ªÀº 7 ÀÌ´Ù(normal errors¿Í normal warnings, parser errors°¡ ·¹Æ÷Æ® µÈ´Ù).

 
open_basedir string
PHP°¡ ¿­¾îº¼ ¼ö ÀÖ´Â ÆÄÀÏÀ» ƯÁ¤ µð·ºÅ丮 ÀÌÇÏ·Î Á¦ÇÑÇÑ´Ù.

¿¹¸¦ µé¾î ¾î¶² ½ºÅ©¸³Æ®°¡ fopenÀ̳ª gzopenÀ¸·Î ÆÄÀÏÀ» ¿­·Á°í ÇÒ ¶§ ±× ÆÄÀÏÀÌ ÁöÁ¤µÈ À§Ä¡¿¡ Àִ°¡ °Ë»çÇÑ´Ù. ¸¸¾à ÆÄÀÏÀÌ ÁöÁ¤µÈ µð·ºÆ¼¸®¹Û¿¡ ÀÖ´Ù¸é, PHP´Â ÀÌ ¿­±â µ¿ÀÛÀ» °ÅºÎÇÑ´Ù. ¸ðµç symbolic linkµéÀº ¿ø·¡ÀÇ À̸§À¸·Î ¹Ù²î¾î ÇØ¼®µÈ´Ù. µû¶ó¼­ ÀÌ Á¦ÇÑÀ» ÇÇÇϱâ À§ÇØ symbolic link¸¦ »ç¿ëÇÏ´Â °ÍÀ» ¹æÁöÇÒ ¼ö ÀÖ´Ù.

.À̶ó´Â ÁöÁ¤µÈ °ªÀ» ÁÖ¸é ½ºÅ©¸³Æ® ÆÄÀÏÀÌ ÀÖ´Â µð·ºÅ丮°¡ base-directory·Î ÁöÁ¤µÈ´Ù.

Windows¿¡¼­´Â ¼¼¹ÌÄÝ·Ð(;)À» »ç¿ëÇϰí, ´Ù¸¥ OS¿¡¼­´Â ÄÝ·Ð(:)À¸·Î ±¸ºÐÇÑ´Ù. As an Apache module, open_basedir paths from parent directories are now automatically inherited

NOTE: PHP 3.0.7 ºÎÅÍ, ÇÑ °³ ÀÌ»óÀÇ µð·ºÅ丮¸¦ ÁöÁ¤ÇÒ ¼ö ÀÖµµ·Ï µÇ¾ú´Ù.

±âº»°ªÀº ¸ðµç ÆÄÀÏÀ» ¿­ ¼ö ÀÖ´Â °ÍÀÌ´Ù.

 
gpc_order string
GET / POST / COOKIE º¯¼öµéÀÇ ÇØ¼® ¼ø¼­¸¦ Á¤ÇÑ´Ù. ±âº»°ªÀº "GPC"ÀÌ´Ù. ¿¹¸¦µé¾î "GP"¶ó°í ¼³Á¤ÇÑ´Ù¸é, PHP´Â cookieµéÀº ¿ÏÀüÈ÷ ¹«½ÃÇϰí, °°Àº À̸§À» °¡Áö POST º¯¼ö°¡ ÀÖ´Â GET º¯¼ö´Â POST º¯¼öÀÇ °ªÀ¸·Î µ¤¾î ¾²¿©Áö°Ô µÈ´Ù.
 
ignore_user_abort string
±âº»°ªÀº OffÀÌ´Ù. ¸¸¾à ÀÌ °ªÀÌ OnÀ̸é, ¿ø°Ý Ŭ¶óÀÌ¾ðÆ®°¡ Áß°£¿¡ ¿¬°áÀ» ²÷¾îµµ ½ºÅ©¸³Æ®°¡ ³¡±îÁö ¼öÇàµÈ´Ù.

See also ignore_user_abort().

 
include_path string
require()¿Í include(), fopen_with_path() ÇÔ¼öµéÀÌ »ç¿ëÇÏ´Â ÆÄÀÏÀ» ãÀ» À§Ä¡(path)¸¦ ¸í½ÃÇÑ´Ù. stringÀÇ Çü½ÄÀº ½Ã½ºÅÛ È¯°æº¯¼öÀÎ PATH ÀÇ ¼³Á¤°ú ºñ½ÁÇÏ´Ù. UNIX¿¡¼­´Â ÄÝ·ÐÀ¸·Î ³ª´µ¾îÁø µð·ºÅ丮µéÀÇ ¸®½ºÆ®À̰í, Windows¿¡¼­´Â ¼¼¹ÌÄÝ·ÐÀ» »ç¿ëÇÑ´Ù.

Example 3-1. UNIX include_path

  1 
  2 include_path=.:/home/httpd/php-lib
  3 

Example 3-2. Windows include_path

  1 
  2 include_path=".;c:\www\phplib"
  3 

±âº»°ªÀº .ÀÌ´Ù. (ÇöÀç µð·ºÅ丮¸¸)

 
isapi_ext string
 
 
log_errors boolean
½ºÅ©¸³Æ® ¿¡·¯ ¸Þ½ÃÁö°¡ ¼­¹öÀÇ ¿¡·¯ ·Î±×¿¡ ·Î±×µÇ´Â °¡¸¦ Á¤ÇÑ´Ù. ÀÌ ¿É¼ÇÀº ¼­¹ö¿¡ µû¶ó ´Ù¸£°Ô µ¿ÀÛÇÑ´Ù.
 
magic_quotes_gpc boolean
GPC (Get/Post/Cookie) µ¿ÀÛ Áß¿¡ ÀϾ´Â magic_quotes ±â´ÉÀ» ¼³Á¤ÇÑ´Ù. magic_quotes°¡ ¼³Á¤µÇ¾î ÀÖÀ¸¸é GPC¿¡¼­ ÀÔ·ÂµÈ ¸ðµç ' (single-quote)¿Í " (double quote), \ (backslash), NUL µéÀÇ ¾Õ¿¡ ¹é½½·¡½Ã(\)°¡ ÀÚµ¿À¸·Î ºÙ°Ô µÈ´Ù. ¶ÇÇÑ, magic_quotes_sybaseµµ °°ÀÌ ¼³Á¤µÇ¾î ÀÖÀ¸¸é '(single-quote)´Â ¹é½½·¡½Ã(\)°¡ ¾Æ´Ñ single-quote(')°¡ ¾Õ¿¡ ºÙ°Ô µÈ´Ù.
 
magic_quotes_runtime boolean
¸¸¾à magic_quotes_runtimeÀÌ ¼³Á¤µÇ¾î ÀÖ´Ù¸é, database¿Í text ÆÄÀÏ¿¡¼­ ÀÐ¾î µéÀÌ´Â ¸ðµç µ¥ÀÌÅÍ¿¡ ÀÖ´Â ' (single-quote)¿Í " (double quote), \ (backslash), NUL µéÀÇ ¾Õ¿¡ ¹é½½·¡½Ã(\)¸¦ ºÙÀ̵µ·Ï ÇÑ´Ù. ¶ÇÇÑ, magic_quotes_sybaseµµ °°ÀÌ ¼³Á¤µÇ¾î ÀÖÀ¸¸é '(single-quote)´Â ¹é½½·¡½Ã(\)°¡ ¾Æ´Ñ single-quote(')°¡ ¾Õ¿¡ ºÙ°Ô µÈ´Ù.
 
magic_quotes_sybase boolean
¸¸¾à magic_quotes_gpc³ª magic_quotes_runtime ÀÌ ¼³Á¤µÇ¾î ÀÖ°í, magic_quotes_sybaseµµ °°ÀÌ ¼³Á¤µÇ¾î ÀÖÀ¸¸é '(single-quote)´Â ¹é½½·¡½Ã(\)°¡ ¾Æ´Ñ single-quote(')°¡ ¾Õ¿¡ ºÙ°Ô µÈ´Ù.
 
max_execution_time integer
±¸¹®Çؼ®±â(parser)°¡ ÇÑ ½ºÅ©¸³Æ®¸¦ ó¸®Çϴµ¥ °É¸®´Â ÃÖ´ë ½Ã°£À» ¼³Á¤ÇÑ´Ù. À̰ÍÀº ºÒ¿ÏÀüÇÑ ½ºÅ©¸³Æ®·ÎºÎÅÍ ¼­¹ö°¡ ¸ðµÎ Á¡À¯´çÇÏ´Â °ÍÀ» ¹æÁöÇϴµ¥ µµ¿òÀÌ µÈ´Ù.
 
memory_limit integer
ÇÑ ½ºÅ©¸³Æ®°¡ ÇÒ´ç¹ÞÀ» ¼ö ÀÖ´Â ¸Þ¸ð¸®ÀÇ ÃÖ´ë Å©±â¸¦ ÁöÁ¤ÇÑ´Ù. À̰ÍÀº ºÒ¿ÏÀüÇÑ ½ºÅ©¸³Æ®·ÎºÎÅÍ ¼­¹ö ÀüüÀÇ ¸Þ¸ð¸®°¡ ÀâÇô ¸ÔÈ÷´Â °ÍÀ» ¹æÁöÇÑ´Ù.
 
nsapi_ext string
 
 
short_open_tag boolean
PHPÀÇ Open ű׷Πshort form (<? ?>)ÀÇ »ç¿ëÀ» Çã°¡Çϰųª ºÒÇãÇÑ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ PHP¿Í XMLÀ» ÇÔ²² »ç¿ëÇÑ´Ù¸é short formÀÇ »ç¿ëÀ» ºÒ°¡´ÉÇÏ°Ô ÇÏ¿©¾ß ÇÑ´Ù. ªÀº ű×ÀÇ »ç¿ëÀÌ ºÒ°¡´ÉÇÏ´Ù¸é, PHPÀÇ Open ű׷δ long form(<?php ?>)¸¸À» »ç¿ëÇÏ¿©¾ß ÇÑ´Ù.
 
sql.safe_mode boolean
 
 
track_errors boolean
ÀÌ Áö½ÃÀÚ°¡ ¼³Á¤µÇ¾î ÀÖÀ¸¸é $php_errormsgÀ̶ó´Â Àü¿ª º¯¼ö¿¡ ¸¶Áö¸·À¸·Î ¹ß»ýÇÑ ¿¡·¯ ¸Þ½ÃÁö°¡ µé¾îÀÖ°Ô µÈ´Ù.
 
track_vars boolean
ÀÌ Áö½ÃÀÚ°¡ ¼³Á¤µÇ¸é, °¢°¢ HTTP_GET_VARS, HTTP_POST_VARS, HTTP_COOKIE_VARSÀÇ Àü¿ª ¹è¿­¿¡ GET / POST / cookie º¯¼öµéÀÇ ÀÔ·ÂÀ» ÀúÀåÇÏ°Ô µÈ´Ù.
 
upload_tmp_dir string
ÆÄÀÏ ¾÷·Îµå½Ã ÆÄÀÏÀ» ÀúÀåÇÒ Àӽà µð·ºÅ丮¸¦ ÁöÁ¤ÇÑ´Ù. PHP°¡ µ¿ÀÛÇϰԵǴ User ID¿¡ ´ëÇØ ¾²±â ±ÇÇÑÀÌ ÀÖ¾î¾ß ÇÑ´Ù.
 
user_dir string
PHP ÆÄÀϵéÀ» À§ÇÑ »ç¿ëÀÚÀÇ È¨ µð·ºÅ丮ÀÇ base À̸§À» ÁöÁ¤ÇÑ´Ù. (Ex. public_html)
 
warn_plus_overloading boolean
À̰ÍÀÌ ¼³Á¤µÇ¸é, ¹®ÀÚ¿­¿¡ ´õÇϱâ(+) ¿¬»êÀÚ°¡ »ç¿ëµÉ ¶§ PHP°¡ ÁÖÀÇ ¸Þ½ÃÁö¸¦ Ãâ·ÂÇÏ°Ô ¸¸µç´Ù. ÀÌ ¿É¼ÇÀº ½ºÅ©¸³Æ®ÀÇ ´õÇϱ⠿¬»êÀÚ¸¦ ¹®ÀÚ¿­ concatenator(.)·Î ´Ù½Ã ÀÛ¼ºÇϴµ¥ µµ¿òÀ» ÁØ´Ù.


Mail Configuration Directives

SMTP string
Windowsȯ°æ¿¡¼­ PHP°¡ »ç¿ëÇÒ SMTP ¼­¹öÀÇ DNS À̸§À̳ª IP ¹øÈ£. mail() ÇÔ¼ö·Î ÆíÁö¸¦ º¸³»·Á¸é ÀÌ ¿É¼ÇÀ» ¹Ýµå½Ã ¼³Á¤ÇØ ÁÖ¾î¾ß ÇÑ´Ù.
 
sendmail_from string
Windowsȯ°æ¿¡¼­ PHP°¡ ÆíÁö¸¦ º¸³¾ ¶§ "From:"¿¡ »ç¿ëµÉ ¸ÞÀÏ ¾îµå·¹½º.
 
sendmail_path string
sendmail ÇÁ·Î±×·¥À» ãÀ» Path. º¸ÅëÀº/usr/sbin/sendmail À̳ª /usr/lib/sendmail ¿¡ ÀÖ´Ù. configure ÇÁ·Î±×·¥ÀÌ sendmailÀÇ À§Ä¡¸¦ ã¾Æ À̰ÍÀ» ±âº»°ªÀ¸·Î ¼³Á¤ÇØ ÁÖÁö¸¸, ±×°ÍÀÌ ÀßµÇÁö ¾Ê¾Ò°Å³ª ¿À·ù°¡ ÀÖÀ» ¶§, ¿©·¯ºÐÀº ¿©±â¼­ Á÷Á¢ ÁöÁ¤ÇØ ÁÙ ¼ö ÀÖ´Ù.

sendmailÀ» »ç¿ëÇÏÁö ¾Ê´Â ½Ã½ºÅÛÀÇ °æ¿ì ÇöÀç Á¦°øµÇ°í ÀÖ´Â ´Ù¸¥ ¸ÞÀÏ ½Ã½ºÅÛÀÇ sendmail ȣȯ ¸í·É(wrapper/replacement)À¸·Î ¼³Á¤ÇØ ÁÖ¾î¾ß ÇÑ´Ù. ¿¹¸¦µé¾î Qmail »ç¿ëÀÚ´Â º¸Åë /var/qmail/bin/sendmail·Î ¼³Á¤ÇØ ÁÖ¸é µÈ´Ù.


Safe Mode Configuration Directives

safe_mode boolean
PHP¸¦ ¾ÈÀü ¸ðµå(safe mode)·Î ÀÛµ¿µÇ°Å ÇÑ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº Security chapter¸¦ »ìÆìº¸±â ¹Ù¶õ´Ù.
 
safe_mode_exec_dir string
PHP°¡ ¾ÈÀü ¸ðµå¿¡¼­ ÀÛµ¿ÇÒ ¶§, system() À̳ª ±âŸ ´Ù¸¥ ÇÁ·Î±×·¥À» ½ÇÇà ½ÃŰ´Â ÇÔ¼öµéÀº ÀÌ µð·ºÅ丮¿¡ ÀÖ´Â ÇÁ·Î±×·¥ÀÌ ¾Æ´Ï¸é ÀÛ¾÷À» °ÅºÎÇÑ´Ù.


Debugger Configuration Directives

debugger.host string
µð¹ö°Å°¡ »ç¿ëÇÒ hostÀÇ DNS name À̳ª IP address
 
debugger.port string
µð¹ö°Å°¡ »ç¿ëÇÒ Port ¹øÈ£
 
debugger.enabled boolean
µð¹ö°Å¸¦ ÀÛµ¿½ÃŲ´Ù.


Extension Loading Directives

enable_dl boolean
ÀÌ Áö½ÃÀÚ´Â PHP¸¦ ¾ÆÆÄÄ¡ ¸ðµâ·Î ½ÇÇàÇÒ ¶§¸¸ È¿·ÂÀ» °¡Áø´Ù. ¿©·¯ºÐÀº PHP¿¡¼­ dl() À» »ç¿ëÇÏ¿© extensionÀ» dynamic loadingÇÏ´Â ±â´ÉÀ» virtual server³ª µð·ºÅ丮 º°·Î °¡´ÉÇÏ°Ô Çϰųª ºÒ°¡´ÉÇÏ°Ô ÇÒ ¼ö ÀÖ´Ù.

dynamic loadingÀ» ºÒ°¡´ÉÇÏ°Ô Çϴ ù ¹ø ° ÀÌÀ¯´Â º¸¾È»óÀÇ ÀÌÀ¯ÀÌ´Ù. dynamic loading¿¡¼­´Â ¸ðµç safe_mode ¼³Á¤°ú open_basedir ¼³Á¤ÀÌ ¹«½ÃµÉ ¼ö Àֱ⠶§¹®ÀÌ´Ù.

±âº»°ªÀº ¸ðµç dynamic loadingÀ» Çã¿ëÇÏ´Â °ÍÀÌ´Ù. ´Ü, safe-mode¸¦ »ç¿ëÇÏ´Â Áß¿¡´Â Ç×»ó dl()ÀÇ »ç¿ëÀÌ ºÒ°¡´ÉÇØ Áø´Ù.

 
extension_dir string
µ¿ÀûÀ¸·Î ÀûÀç °¡´ÉÇÑ(dynamically loadable) extensionÀ» ãÀ» µð·ºÅ丮¸¦ ¼³Á¤ÇÑ´Ù.
 
extension string
PHP°¡ ½ÃÀÛµÉ ¶§ ·ÎµåÇÒ dynamically loadable extensionµéÀ» ¼³Á¤ÇÑ´Ù.


MySQL Configuration Directives

mysql.allow_persistent boolean
¿µ±¸À¸·Î(persistent) MySQLÀ» Á¢¼ÓÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
 
mysql.default_host string
µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡ ¿¬°áÇÒ ¶§ º°µµÀÇ host ÁöÁ¤ÀÌ ¾øÀ» °æ¿ì »ç¿ëµÇ´Â ±âº» ¼­¹ö È£½ºÆ®¸¦ ÁöÁ¤ÇÑ´Ù.
 
mysql.default_user string
µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡ ¿¬°áÇÒ ¶§ º°µµÀÇ »ç¿ëÀÚ ID ÁöÁ¤ÀÌ ¾øÀ» °æ¿ì »ç¿ëµÇ´Â ±âº» »ç¿ëÀÚ ID¸¦ ÁöÁ¤ÇÑ´Ù.
 
mysql.default_password string
µ¥ÀÌÅͺ£À̽º ¼­¹ö¿¡ ¿¬°áÇÒ ¶§ º°µµÀÇ ¾ÏÈ£ ÁöÁ¤ÀÌ ¾øÀ» °æ¿ì »ç¿ëµÇ´Â ±âº» ¾ÏÈ£¸¦ ÁöÁ¤ÇÑ´Ù.
 
mysql.max_persistent integer
ÇÁ·Î¼¼½º´ç ¿µ±¸ÀûÀÎ(persistent) MySQL Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
mysql.max_links integer
¿µ±¸ÀûÀÎ(persistent) Á¢¼ÓÀ» Æ÷ÇÔÇÑ ÇÁ·Î¼¼½º´ç MySQL Á¢¼ÓÀÇ ÃÖ´ë °³¼ö


mSQL Configuration Directives

msql.allow_persistent boolean
¿µ±¸ÀûÀ¸·Î(persistent) mSQLÀ» Á¢¼ÓÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
 
msql.max_persistent integer
ÇÁ·Î¼¼½º´ç ¿µ±¸ÀûÀÎ(persistent) mSQL Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
msql.max_links integer
¿µ±¸ÀûÀÎ(persistent) Á¢¼ÓÀ» Æ÷ÇÔÇÑ ÇÁ·Î¼¼½º´ç mSQL Á¢¼ÓÀÇ ÃÖ´ë °³¼ö


Postgres Configuration Directives

pgsql.allow_persistent boolean
¿µ±¸ÀûÀ¸·Î(persistent) Postgres¸¦ Á¢¼ÓÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
 
pgsql.max_persistent integer
ÇÁ·Î¼¼½º´ç ¿µ±¸ÀûÀÎ(persistent) Postgres Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
pgsql.max_links integer
¿µ±¸ÀûÀÎ(persistent) Á¢¼ÓÀ» Æ÷ÇÔÇÑ ÇÁ·Î¼¼½º´ç Postgres Á¢¼ÓÀÇ ÃÖ´ë °³¼ö


Sybase Configuration Directives

sybase.allow_persistent boolean
¿µ±¸ÀûÀ¸·Î(persistent) Sybase¸¦ Á¢¼ÓÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
 
sybase.max_persistent integer
ÇÁ·Î¼¼½º´ç ¿µ±¸ÀûÀÎ(persistent) Sybase Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
sybase.max_links integer
¿µ±¸ÀûÀÎ(persistent) Á¢¼ÓÀ» Æ÷ÇÔÇÑ ÇÁ·Î¼¼½º´ç Sybase Á¢¼ÓÀÇ ÃÖ´ë °³¼ö


Sybase-CT Configuration Directives

sybct.allow_persistent boolean
¿µ±¸ÀûÀ¸·Î(persistent) Sybase-CT¸¦ Á¢¼ÓÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
 
sybct.max_persistent integer
ÇÁ·Î¼¼½º´ç ¿µ±¸ÀûÀÎ(persistent) Sybase-CT Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
sybct.max_links integer
¿µ±¸ÀûÀÎ(persistent) Á¢¼ÓÀ» Æ÷ÇÔÇÑ ÇÁ·Î¼¼½º´ç Sybase-CT Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
sybct.min_server_severity integer
severity¸¦ °¡Áö´Â ¼­¹ö ¸Þ½ÃÁö °³¼ö°¡ sybct.min_server_severity¿¡ ¼³Á¤ÇÑ °ªº¸´Ù Å©°Å³ª °°¾ÆÁö¸é warningÀ» ·¹Æ÷Æ®ÇÑ´Ù. ÀÌ °ªÀº ½ºÅ©¸³Æ®¿¡¼­ sybase_min_server_severity()ÇÔ¼ö¸¦ ÅëÇØ ¼³Á¤ÇÒ ¼öµµ ÀÖ´Ù. ±âº» °ªÀº 10ÀÌ´Ù.
 
sybct.min_client_severity integer
severity¸¦ °¡Áö´Â Ŭ¶óÀÌ¾ðÆ® ¶óÀ̺귯¸® ¸Þ½ÃÁö °³¼ö°¡ sybct.min_server_severity¿¡ ¼³Á¤ÇÑ °ªº¸´Ù Å©°Å³ª °°¾ÆÁö¸é warningÀ» ·¹Æ÷Æ®ÇÑ´Ù. ÀÌ °ªÀº ½ºÅ©¸³Æ®¿¡¼­ sybase_min_client_severity()ÇÔ¼ö¸¦ ÅëÇØ ¼³Á¤ÇÒ ¼öµµ ÀÖ´Ù. ±âº» °ªÀº 10ÀÌ´Ù.
 
sybct.login_timeout integer
¼­¹ö¿¡ ¿¬°áÀ» ½ÃµµÇÏ°í ±â´Ù¸®´Â ÃÖ´ë ½Ã°£. ´ÜÀ§´Â ÃÊÀ̰í ÁöÁ¤µÈ ½Ã°£¿¡ ¿¬°áÀÌ ¿Ï·áµÇÁö ¸øÇÏ¸é ¿¬°á µ¿ÀÛÀº ½ÇÆÐÇÏ´Â °ÍÀÌ´Ù. ¸¸¾à ¿¬°á½Ãµµ Áß max_execution_timeÀÇ ¼³Á¤À» ÃʰúÇÏ°Ô µÇ¸é ½ºÅ©¸³Æ®´Â ¿¬°á ½ÇÆÐ¸¦ ¾Ë¸®±â Àü¿¡ Á¾·áµÇ¾î ¹ö¸°´Ù. ±âº»°ªÀº 1ºÐÀÌ´Ù.
 
sybct.timeout integer
select_db³ª queryµîÀÇ ¸í·ÉÀ» ÁÖ°í ÀÀ´äÀ» ±â´Ù¸®´Â ÃÖ´ë ½Ã°£. ´ÜÀ§´Â ÃÊÀ̰í ÁöÁ¤µÈ ½Ã°£¾È¿¡ ÀÀ´äÀÌ ¾øÀ¸¸é ÀÌ µ¿ÀÛÀº ½ÇÆÐÇÏ´Â °ÍÀÌ´Ù. ¸¸¾à ¿¬°á½Ãµµ Áß max_execution_timeÀÇ ¼³Á¤À» ÃʰúÇÏ°Ô µÇ¸é ½ºÅ©¸³Æ®´Â µ¿ÀÛ ½ÇÆÐ¸¦ ¾Ë¸®±â Àü¿¡ Á¾·áµÇ¾î ¹ö¸°´Ù. ±âº»°ªÀº ¾ø°í, ¹«ÇÑÁ¤ ±â´Ù¸®´Â °ÍÀÌ´Ù.
 
sybct.hostname string
sp_who¿¡ ÀÇÇØ Ç¥½ÃµÉ ¿¬°áÀ» ¿äûÇÏ´Â hostÀÇ À̸§. ±âº»°ªÀº ¾ø´Ù.


Informix Configuration Directives

ifx.allow_persistent boolean
¿µ±¸ÀûÀ¸·Î(persistent) Informix¸¦ Á¢¼ÓÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
 
ifx.max_persistent integer
ÇÁ·Î¼¼½º´ç ¿µ±¸ÀûÀÎ(persistent) Informix Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
ifx.max_links integer
¿µ±¸ÀûÀÎ(persistent) Á¢¼ÓÀ» Æ÷ÇÔÇÑ ÇÁ·Î¼¼½º´ç Informix Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
ifx.default_host string
ifx_connect()À̳ª ifx_pconnect() ÇÔ¼ö¿¡ È£½ºÆ®°¡ ÁöÁ¤µÇÁö ¾Ê¾ÒÀ» °æ¿ì »ç¿ëÇÒ ±âº» È£½ºÆ®.
 
ifx.default_user string
ifx_connect()À̳ª ifx_pconnect() ÇÔ¼ö¿¡ user id°¡ ÁöÁ¤µÇÁö ¾Ê¾ÒÀ» °æ¿ì »ç¿ëÇÒ ±âº» user id.
 
ifx.default_password string
ifx_connect()À̳ª ifx_pconnect() ÇÔ¼ö¿¡ password°¡ ÁöÁ¤µÇÁö ¾Ê¾ÒÀ» °æ¿ì »ç¿ëÇÒ ±âº» password.
 
ifx.blobinfile boolean
Set to true if you want to return blob columns in a file, false if you want them in memory. You can override the setting at runtime with ifx_blobinfile_mode().
 
ifx.textasvarchar boolean
select ¹®¿¡¼­ TEXT Ä÷³ÀÇ ³»¿ëÀ» ÀϹÝÀûÀÎ ¹®ÀÚ¿­·Î ¹ÝȯÇÏ°í ½Í´Ù¸é True, blob id ÆÄ¶ó¸ÞÅ͸¦ »ç¿ëÇÏ°í ½Í´Ù¸é False¸¦ ¼³Á¤ÇÑ´Ù. ÀÌ ¼³Á¤Àº ifx_textasvarchar() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ½ÇÇà Áß º¯°æÇÒ ¼ö ÀÖ´Ù.
 
ifx.byteasvarchar boolean
select ¹®¿¡¼­ BYTE Ä÷³ÀÇ ³»¿ëÀ» ÀϹÝÀûÀÎ ¹®ÀÚ¿­·Î ¹ÝȯÇÏ°í ½Í´Ù¸é True, blob id ÆÄ¶ó¸ÞÅ͸¦ »ç¿ëÇÏ°í ½Í´Ù¸é False¸¦ ¼³Á¤ÇÑ´Ù. ÀÌ ¼³Á¤Àº ifx_textasvarchar() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ½ÇÇà Áß º¯°æÇÒ ¼ö ÀÖ´Ù.
 
ifx.charasvarchar boolean
µ¥ÀÌÅ͸¦ °¡Á®¿Ã ¶§ CHAR Ä÷³ÀÇ µÚÂÊ °ø¹éÀ» ÀÚµ¿À¸·Î Àß¶ó³»·Á¸é True¸¦ ¼³Á¤ÇÑ´Ù.
 
ifx.nullformat boolean
NULL Ä÷³¿¡ ´ëÇÏ¿© "NULL"À̶ó´Â ¹®ÀÚ¿­À» ¹ÝȯÇÏ·Á¸é True, °ø¹é ¹®ÀÚ¿­("")À» ¹ÝȯÇÏ·Á¸é False¸¦ ¼³Á¤ÇÑ´Ù. ÀÌ ¼³Á¤Àº ifx_nullformat() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ½ÇÇà Áß º¯°æÇÒ ¼ö ÀÖ´Ù.


BC Math Configuration Directives

bcmath.scale integer
bc ¼öÇÐ ÇÔ¼öµéÀÌ »ç¿ëÇÏ´Â ½ÊÁø ÀÚ¸®¼ö.


Browser Capability Configuration Directives

browscap string
browser ±â´É(capabilities) ÆÄÀÏÀÇ À̸§


Unified ODBC Configuration Directives

uodbc.default_db string
odbc_connect()³ª odbc_pconnect()¿¡¼­ noneÀ¸·Î ¼³Á¤µÇ¾î ÀÖÀ» ¶§ »ç¿ëÇÒ ODBC Data Source¸¦ ÁöÁ¤ÇÑ´Ù.
 
uodbc.default_user string
odbc_connect()³ª odbc_pconnect()¿¡¼­ noneÀ¸·Î ¼³Á¤µÇ¾î ÀÖÀ» ¶§ »ç¿ëÇÒ User À̸§À» ÁöÁ¤ÇÑ´Ù.
 
uodbc.default_pw string
odbc_connect()³ª odbc_pconnect()¿¡¼­ noneÀ¸·Î ¼³Á¤µÇ¾î ÀÖÀ» ¶§ »ç¿ëÇÒ Password¸¦ ÁöÁ¤ÇÑ´Ù.
 
uodbc.allow_persistent boolean
¿µ±¸ÀûÀ¸·Î(persistent) ODBC¸¦ Á¢¼ÓÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
 
uodbc.max_persistent integer
ÇÁ·Î¼¼½º´ç ¿µ±¸ÀûÀÎ(persistent) ODBC Á¢¼ÓÀÇ ÃÖ´ë °³¼ö
 
uodbc.max_links integer
¿µ±¸ÀûÀÎ(persistent) Á¢¼ÓÀ» Æ÷ÇÔÇÑ ÇÁ·Î¼¼½º´ç ODBC Á¢¼ÓÀÇ ÃÖ´ë °³¼ö


Chapter 4. º¸¾È (Security)

PHP´Â °­·ÂÇÑ ¾ð¾îÀ̵ð. ±× ÀÎÅÍÇÁ¸®ÅÍ´Â À¥¼­¹öÀÇ ¸ðµâ·Î µÇ¾î ÀÖ°Ç CGI binary·Î µÇ¾î ÀÖ°Ç °£¿¡, ÆÄÀÏÀ» »ç¿ëÇÒ ¼ö ÀÖ°í, ´Ù¸¥ ¸í·ÉÀ̳ª ÇÁ·Î±×·¥À» ½ÇÇàÇÒ ¼ö ÀÖ°í, ¼­¹ö·Î ³×Æ®¿÷ ¿¬°áÀ» ÇÒ ¼öµµ ÀÖ´Ù. ÀÌ·± Ư¼ºµéÀº ±âº»ÀûÀ¸·Î ¾î¶² ÇÁ·Î±×·¥ÀÌµç ½ÇÇà½ÃÄÑ À¥¼­¹ö¸¦ ºÒ¾ÈÇÑ »óÅ·Π¸¸µé ¼ö ÀÖ´Ù. PHP´Â ºÐ¸íÈ÷ PerlÀ̳ª Cº¸´Ù Á»´õ ¾ÈÀüÇÑ CGI ÇÁ·Î±×·¥À» ¸¸µé ¼ö ÀÖ´Ù. ÄÄÆÄÀϽóª ½ÇÇà½Ã ¼³Á¤ ¿É¼ÇµéÀ» ÀûÀýÈ÷ ¼±ÅÃÇÔÀ¸·Î, ¿©·¯ºÐÀº ¿øÇÏ´Â Á¤µµÀÇ ÀÚÀ¯·Î¿ò°ú º¸¾È»óÀÇ Á¦¾àÀ» Á¶È­½Ãų ¼ö ÀÖ´Ù.

PHP´Â ¼ö¸¹Àº ¹æ¹ýÀ¸·Î ÀÌ¿ëÀÌ °¡´ÉÇϰí, ÀÌ¿¡ µû¸¥ ¿©·¯ °¡Áö ¼³Á¤ ¿É¼ÇÀÌ ÀÖÀ» ¼ö ÀÖ´Ù. ¸¹Àº ¿É¼Ç ¼±Åà »çÇ×µéÀº PHP¸¦ º¸´Ù ¸¹Àº ¸ñÀûÀ¸·Î »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÏÁö¸¸, ÀÌ ¿É¼ÇµéÀÇ Á¶ÇÕ°ú ¼­¹öÀÇ ¼³Á¤¿¡ µû¶ó º¸¾È»óÀÇ ÇãÁ¡À» ³ëÃâ½Ãų ¼öµµ ÀÖ´Ù. ÀÌ ÀåÀº ´Ù¸¥ ¿É¼ÇÀÇ Á¶ÇÕ ¹æ¹ý°ú À̰ÍÀ» ¾ÈÀüÇÏ°Ô »ç¿ëÇÏ´Â »óȲÀ» ¼³¸íÇÑ´Ù.


CGI binary


°¡´ÉÇÑ °ø°Ý (Possible attacks)

CGI binary ÇüÅÂÀÇ PHP´Â ¾î¶² ÀÌÀ¯·Î ¼­¹ö ¼ÒÇÁÆ®¿þ¾î(¾ÆÆÄÄ¡ °°Àº)ÀÇ ¸ðµâ·Î »ç¿ëµÇ±â¸¦ ¿øÇÏÁö ¾Ê´Â °æ¿ì¿¡ »ç¿ëÇÒ ¼ö ÀÖ°í, PHP¸¦ ´Ù¸¥ Á¾·ùÀÇ CGI wrapper¿Í ÇÔ²² ¾ÈÀüÇÑ chroot¿Í setuid ȯ°æÀ» ¸¸µé¾î ³»´Â °÷¿¡ ¶§¿¡ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ÀÌ ¼³Á¤Àº º¸Åë ½ÇÇàÇÒ PHP binary¸¦ À¥¼­¹öÀÇ cgi-binµð·ºÅ丮¿¡ ¼³Ä¡ÇØ¾ß ÇÑ´Ù. CERT ±Ç°í»çÇ× CA-96.11¿¡ µû¸£¸é ¸ðµç ÀÎÅÍÇÁ¸®Å͵éÀº cgi-bin¿¡ ¼³Ä¡Çϵµ·Ï ±Ç°íµÈ´Ù. ºñ·Ï PHP binary°¡ µ¶¸³ÀûÀÎ ÀÎÅÍÇÁ¸®ÅÍ·Î »ç¿ëµÈ´Ù ÇÒÁö¶óµµ, PHP´Â ÀÌ ¼³Á¤ÀÌ ¸¸µé¾î³¾ °¡´ÉÇÑ °ø°ÝÀ» ´ÙÀ½°ú °°ÀÌ ¸·¾Æ³»µµ·Ï ¼³°èµÇ¾î ÀÖ´Ù. :


Case 1: °ø¿ë ÆÄÀϸ¸ Á¦°øÇϱâ (only public files served)

¸¸¾à ¿©·¯ºÐÀÇ ¼­¹ö°¡ password ³ª ip ±âÁØÀÇ Á¢±Ù ÅëÁ¦¿¡ °üÇÑ ¾î¶°ÇÑ »çÇ×µµ ¾ø´Ù¸é, ÀÌ·¯ÇÑ ¼³Á¤ ¿É¼ÇµéÀº ÇÊ¿ä ¾ø´Ù. ¸¸¾à ¿©·¯ºÐÀÇ À¥¼­¹ö°¡ ¸®µð·ºÆ®¸¦ Çã¿ëÇÏÁö ¾Ê°Å³ª, ¼­¹ö°¡ ÇØ´ç ¿ä±¸°¡ ¾ÈÀüÇÏ°Ô ¸®µð·ºÆ®µÈ ¿ä±¸ÀÎÁö ´ëÇØ PHP binary¿Í Åë½ÅÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀÌ ¾øÀ» °æ¿ì, ¿©·¯ºÐÀº ½ºÅ©¸³Æ®¸¦ ¼³Á¤Çϱâ À§ÇØ --disable-force-cgi-redirect ¿É¼ÇÀ» ¸í½ÃÇÒ ¼ö ÀÖ´Ù. ¿©·¯ºÐÀº ¿©ÀüÈ÷ ¿©·¯ºÐÀÇ PHP ½ºÅ©¸³Æ®°¡, http://my.host/cgi-bin/php/dir/script.php3ó·³ Á÷Á¢ Á¢±ÙÇÏ´Â °Íµµ ¾Æ´Ï°í http://my.host/dir/script.php3°°ÀÌ ¸®µð·º¼Ç¿¡ ÀÇÇØ¼­µµ ¾Æ´Ñ, ´Ù¸¥ ¹ÏÁö ¸øÇÒ ¹æ¹ý¿¡ ÀÇÇØ ºÒ·Á Áú ¶§¸¦ ´ëºñÇÏ¿© ´ëÃ¥À» °­±¸ÇØ µÎ¾î¾ß ÇÕ´Ï´Ù.

¸®µð·º¼ÇÀº ¿¹¸¦µé¾î Apache¿¡¼­´Â AddHandle°ú Action Áö½ÃÀÚ¸¦ »ç¿ëÇÏ¿© ¼³Á¤ÇÒ ¼ö ÀÖ½À´Ï´Ù. (¾Æ·¡¸¦ º¸¼¼¿ä.)


Case 2: --enable-force-cgi-redirect ¿É¼Ç »ç¿ë (using --enable-force-cgi-redirect)

ÀÌ ÄÄÆÄÀϽÃÀÇ ¿É¼ÇÀº »ç¿ëÀÚ°¡ http://my.host/cgi-bin/php/secretdir/script.php3¿Í °°ÀÌ PHP¸¦ Á÷Á¢ È£ÃâÇÏ´Â °ÍÀ» ¸·¾ÆÁØ´Ù. ´ë½Å, ÀÌ ¸ðµå¿¡¼­ PHP´Â ±×°ÍÀÌ À¥¼­¹öÀÇ ¸®µð·ºÆ® ±ÔÄ¢À» Åë°úÇÑ °æ¿ì¿¡¸¸ parse ÀÛ¾÷À» ÇÒ °ÍÀÌ´Ù.

ÀϹÝÀûÀ¸·Î ¾ÆÆÄÄ¡ ¼³Á¤¿¡¼­ ¸®µð·ºÆ® ¼³Á¤Àº ´ÙÀ½°ú °°ÀÌ Áö½ÃÀÚ¸¦ »ç¿ëÇÏ¿© ÇÑ´Ù. :

Action php3-script /cgi-bin/php
AddHandler php3-script .php3

ÀÌ ¿É¼ÇÀº ¾ÆÆÄÄ¡ À¥¼­¹ö¿¡¼­ ½ÃÇèÀ» °ÅÃÆ°í, ¾ÆÆÄÄ¡´Â ¸®µð·ºÆ®µÈ ¿ä±¸¿¡ ´ëÇØ¼­´Â REDIRECT_STATUS ¶ó´Â ºñ Ç¥ÁØ CGI ȯ°æ º¯¼ö¸¦ ¼³Á¤ÇÑ´Ù. ¸¸¾à ´ç½ÅÀÇ À¥¼­¹ö°¡ ¹®¼­ ¿ä±¸°¡ Á÷Á¢(direct)ÀÎÁö ¸®µð·ºÆ®(redirect)ÀÎÁö ±¸º°ÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀ» Á¦°øÇÏÁö ¾Ê´Â´Ù¸é ¿©·¯ºÐÀº ÀÌ ¿É¼ÇÀ» »ç¿ëÇÒ ¼ö ¾ø´Ù. µû¶ó¼­, ¿©·¯ºÐÀº ÀÌ ¹®¼­¿¡ ¾º¿©Á® ÀÖ´Â CGI ¹öÀüÀÇ ´Ù¸¥ ½ÇÇà ¹æ¹ýÀ» »ç¿ëÇØ¾ß ÇÒ °ÍÀÌ´Ù.


Case 3: doc_root³ª user_dirÀÇ ¼³Á¤ (setting doc_root or user_dir)

À¥¼­¹ö ¹®¼­ µð·ºÅ丮¿¡ script³ª ½ÇÇàÆÄÀÏ °°Àº Active content¸¦ Æ÷ÇÔÇÏ´Â °ÍÀº Á¾Á¾ ºÒ¾ÈÇÏ´Ù°í »ý°¢µÇ¾î Áø´Ù. ¸¸¾à ¾à°£ÀÇ ¼³Á¤ ¿À·ù·Î ½ºÅ©¸³Æ®°¡ ½ÇÇàµÇÁö ¾Ê°í HTML ¹®¼­Ã³·³ ±×´ë·Î Ãâ·Â µÈ´Ù¸é, °¢Á¾ ÁöÀû Àç»êÀ̳ª Password°°Àº º¸¾È»óÀÇ Á¤º¸°¡ ´©¼³µÇ´Â °á°ú°¡ ÃÊ·¡µÉ Áöµµ ¸ð¸¥´Ù. ±×·¯¹Ç·Î ¸¹Àº ½Ã½ºÅÛ °ü¸®ÀÚµéÀº ½ºÅ©¸³Æ®¸¦ À§ÇÑ º°µµÀÇ µð·ºÅ丮¸¦ ¸¸µé¾î ³õ°í, ÀÌ µð·ºÅ丮´Â PHP CGI¸¦ ÅëÇØ¼­¸¸ Á¢±ÙÀÌ °¡´ÉÇϵµ·Ï ¸¸µé¾î ³õ¾Æ ½ÇÇàÀº °¡´ÉÇÏÁö¸¸ º¸¿©ÁöÁö´Â ¾Êµµ·Ï ÇÑ´Ù.

¶ÇÇÑ, ÀüÀå¿¡¼­ ±â¼úÇÑ ¹Ù¿Í °°ÀÌ, ¿ä±¸°¡ ¸®µð·ºÆ®µÈ °ÍÀÌ ¾Æ´Ï¶ó°í È®ÀÎÇØÁÖ´Â ¹æ¹ýÀÌ ¾ø´Ù¸é, À¥ ¹®¼­ÀÇ root¿Í´Â ´Ù¸¥ ½ºÅ©¸³Æ®ÀÇ doc_root¸¦ ¼³Á¤ÇØ ÁÖ´Â °ÍÀÌ ¹Ýµå½Ã ÇÊ¿äÇÏ´Ù.

¿©·¯ºÐÀº php3.iniÀÇ doc_root Áö½ÃÀÚ¸¦ ¼³Á¤Çϰųª, PHP_DOCUMENT_ROOT¶ó´Â ȯ°æº¯¼ö °ª¿¡ ¼³Á¤ÇØ ÁÖ¾î, PHP ½ºÅ©¸³Æ® ¹®¼­ÀÇ root¸¦ ¼³Á¤ÇÒ ¼ö ÀÖ´Ù. ¸¸¾à À̰ÍÀÌ ¼³Á¤µÇ¾î ÀÖ´Ù¸é, CGI ¹öÀüÀÇ PHP´Â ¾ðÁ¦³ª ÀÌ doc_root¿Í request¿¡ ÀÖ´Â °æ·Î Á¤º¸¸¦ °¡Áö°í Á¢±ÙÇÏ·Á´Â ÆÄÀÏÀÇ À̸§À» ¸¸µç´Ù. µû¶ó¼­ ¿©·¯ºÐÀº ÀÌ µð·ºÅ丮 ¹Û¿¡¼­´Â ¾î¶°ÇÑ ½ºÅ©¸³Æ®µµ ½ÇÇàµÉ ¼ö ¾øµµ·Ï ¸¸µé°Ô µÈ´Ù. (¾Æ·¡¿¡ ÀÖ´Â user_dir ¸¸Àº ¿¹¿ÜÀÌ´Ù)

À̰÷¿¡¼­ ¶Ç Çϳª »ç¿ëÇÒ ¼ö ÀÖ´Â ¿É¼ÇÀº user_dirÀÌ´Ù. user_dirÀÌ ¼³Á¤µÇ¾î ÀÖÁö ¾ÊÀ¸¸é Á¢±Ù °¡´ÉÇÑ ÆÄÀÏÀ» doc_root¿¡ ÀÖ´Â °Í »ÓÀÌ´Ù. http://my.host/~user/doc.php3°°Àº url·Î´Â user home directory¿¡ ÀÖ´Â ÆÄÀÏÀ» ¿­ ¼ö ¾ø´Ù. ´ÜÁö doc_root¾Æ·¡ÀÇ ~user/doc.php3 ÆÄÀÏÀ» ºÎ¸¦ »ÓÀÌ´Ù. (¹°·Ð Æ¿µ¥[~]·Î ½ÃÀÛÇÏ´Â "~user"¶ó´Â µð·ºÅ丮ÀÌ´Ù.)

¸¸¾à user_dirÀÌ ¿¹¸¦ µé¾î public_php·Î ¼³Á¤µÇ¾î ÀÖ´Ù¸é, http://my.host/~user/doc.php3¿Í °°Àº ¿ä±¸´Â userÀÇ home µð·ºÅ丮 ¹ØÀÇ public_php¶ó´Â µð·ºÅ丮 ¹ØÀÇ doc.php3¶ó´Â ÆÄÀÏÀ» È£Ãâ ÇÒ °ÍÀÌ´Ù. ¸¸¾à »ç¿ëÀÚÀÇ homeÀÌ /home/user¶ó¸é, ½ÇÇàµÇ´Â ÆÄÀÏÀº /home/user/public_php/doc.php3ÀÌ µÈ´Ù.

user_dir È®ÀåÀº doc_root ¼³Á¤°ú °ü·Ã¾øÀÌ ¹ß»ýÇϹǷÎ, ¿©·¯ºÐÀº document root¿Í user directory Á¢±Ù ÅëÁ¦¸¦ º°µµ·Î ÇÒ ¼ö ÀÖ´Ù.


Case 4: À¥ Æ®¸® ¹Û¿¡ PHP parser (PHP parser outside of web tree)

¸Å¿ì ½Å·ÚÇÒ¼ö ÀÖ´Â ¿É¼ÇÀ¸·Î PHP parser binary¸¦ À¥ Æ®¸® ¹Û¿¡´Ù µÎ´Â ¹æ¹ýÀÌ´Ù. ¿¹¸¦ µé¾î /usr/local/bin °°Àº °÷¿¡ µÐ´Ù. ÀÌ ¿É¼ÇÀÇ ½ÇÁúÀûÀÎ ´ÜÁ¡Àº, ¸ðµç PHP ÅÃÀ» Æ÷ÇÔÇϰí ÀÖ´Â ÆÄÀÏÀÇ Ã¹¹øÂ° ¶óÀο¡ ´ÙÀ½°ú ºñ½ÁÇÏ°Ô Àû¾îÁÖ´Â °Í »ÓÀÌ´Ù. :

#!/usr/local/bin/php

¶ÇÇÑ ÆÄÀÏÀ» ½ÇÇà °¡´ÉÀ¸·Î ¸¸µé¾î ÁÖ¾î¾ß ÇÑ´Ù. Áï, ÀÚ½ÅÀÇ ½ÇÇàÀ» À§Çؼ­ #! shell-escape ¸ÞÄ«´ÏÁòÀ» »ç¿ëÇÏ´Â PerlÀ̳ª sh ȤÀº ´Ù¸¥ ½ºÅ©¸³Æ® ¾ð¾î¿Í °°Àº ¹æ½ÄÀ¸·Î ´Ù·ç´Â °ÍÀÌ´Ù.

ÀÌ ¼³Á¤¿¡¼­ PHP°¡ PATH_INFO¿Í PATH_TRANSLATEDÁ¤º¸¸¦ ¿Ã¹Ù¸£°Ô ´Ù·ç·Á¸é, php parser°¡ --enable-discard-path ¼³Á¤ ¿É¼ÇÀ¸·Î ÄÄÆÄÀÏ µÇ¾î¾ß ÇÑ´Ù.


Apache module

PHP°¡ ¾ÆÆÄÄ¡ÀÇ ¸ðµâ·Î »ç¿ëµÉ ¶§´Â ¾ÆÆÄÄ¡ÀÇ »ç¿ëÀÚ permissionÀ» °è½Â¹Þ´Â´Ù. (ÀϹÝÀûÀ¸·Î "nobody"·Î ¼³Á¤µÇ¾î ÀÖ´Ù.)


II. Language Reference

Table of Contents
5. ±âº»¹®¹ý (Basic syntax)
6. º¯¼öÇüÅ (Types)
7. º¯¼ö (Variables)
8. »ó¼ö (Constants)
9. Ç¥Çö½Ä (Expressions)
10. ¿¬»êÀÚ (Operators)
11. Á¦¾î ±¸Á¶ (Control Structures)
12. ÇÔ¼ö (Functions)
13. Ŭ·¡½º¿Í °´Ã¼ (Classes and Objects)


Chapter 5. ±âº» ¹®¹ý(Basic Syntax)


HTML·ÎºÎÅÍ ºüÁ®³ª¿À±â(Escaping from HTML)

HTML·ÎºÎÅÍ ºüÁ®³ª¿Í "PHP code mode"·Î µé¾î°¡´Â ¹æ¹ýÀº ´ÙÀ½ 4°¡Áö°¡ ÀÖ´Ù :

 

Example 5-1. Ways of escaping from HTML

  1 
  2 1.  <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
  3  
  4 2.  <?php echo("if you want to serve XML documents, do like this\n"); ?>
  5 
  6 3.  <script language="php"> 
  7         echo ("some editors (like FrontPage) don't
  8               like processing instructions");
  9     </script>
 10 
 11 4.  <% echo ("You may optionally use ASP-style tags"); %>
 12     <%= $variable; # This is a shortcut for "<%echo .." %>
 13       

ù ¹øÂ° ¹æ¹ýÀº short tags°¡ enableµÇ¾î ÀÖ¾î¾ß »ç¿ë°¡´ÉÇÏ´Ù. short_tags()¸¦ È£ÃâÇϰųª, short_tags run-time ¼³Á¤¿¡¼­ °¡´ÉÇϰí, ÄÄÆÄÀϽÿ¡ --enable-short-tags ¿É¼ÇÀ» ÁÖ¾î ÄÄÆÄÀÏÇÏ¿© enableÇÒ ¼öµµ ÀÖ´Ù.

³× ¹øÂ° ¹æ¹ýÀº ASP-style tags°¡ enableµÇ¾î ÀÖ¾î¾ß »ç¿ë°¡´ÉÇÏ´Ù. asp_tags run-time ¼³Á¤¿¡¼­ °¡´ÉÇϰí, ÄÄÆÄÀϽÿ¡ --enable-asp_tags ¿É¼ÇÀ» ÁÖ¾î ÄÄÆÄÀÏÇÏ¿© enableÇÒ ¼öµµ ÀÖ´Ù.

Note: ASP-style tags´Â 3.0.4ºÎÅÍ Áö¿øµÈ´Ù.

´Ý´Â °ýÈ£´Â newlineÀ» Æ÷ÇÔÇÑ´Ù.


¸í·É ±¸ºÐ (Instruction separation)

°¢°¢ÀÇ ¸í·ÉÀº C³ª Perl°ú ¸¶Âù°¡Áö·Î ±¸ºÐµÈ´Ù. °¢ ¹®ÀåÀº ;(¼¼¹ÌÄÝ·Ð)À¸·Î Á¾·áµÈ´Ù.

PHPÀÇ Á¾·áÅÃÀÎ ?>´Â ¹®ÀåÀÇ ³¡À̶ó´Â Àǹ̵µ ÇÔ²² °¡Áö°í ÀÖ´Ù. µû¶ó¼­ ´ÙÀ½ µÎ °³ÀÇ ¹®ÀåÀº µ¿ÀÏÇÏ´Ù.

  1 
  2 <?php
  3     echo "This is a test";
  4 ?>
  5 
  6 <?php echo "This is a test" ?>
  7       

 


ÁÖ¼®¹® (Comments)

PHP´Â 'C'¿Í 'C++', Unix shell ÇüÅÂÀÇ ÁÖ¼®¹®À» Á¦°øÇÑ´Ù. ¿¹¸¦ µé¾î :

  1 
  2 <?php
  3     echo "This is a test"; // This is a one-line c++ style comment
  4     /* This is a multi line comment
  5        yet another line of comment */
  6     echo "This is yet another test";
  7     echo "One Final Test"; # This is shell-style style comment
  8 ?>
  9      

"one-line" ÁÖ¼®¹®Àº ¶óÀÎÀÇ ³¡À̳ª, Çö php ÄÚµå ºí·ÏÀÇ ³¡¿¡¼­ ³¡³­´Ù.

  1 
  2 <h1>This is an <?# echo "simple";?> example.</h1>
  3 <p>The header above will say 'This is an example'.
  4 

'C' ÇüÅÂÀÇ ÁÖ¼®¹®Àº Áߺ¹Çؼ­ »ç¿ëÇÏÁö ¸»¾Æ¾ß ÇÑ´Ù.

  1 
  2 <?php
  3  /* 
  4     echo "This is a test"; /* ÀÌ ÁÖ¼®¹®Àº ¹®Á¦°¡ µÈ´Ù. */
  5  */
  6 ?>
  7     
    


Chapter 6. º¯¼ö ÇüÅ (Types)

PHP´Â ´ÙÀ½ ÇüÅÂÀÇ typeÀ» Áö¿øÇÑ´Ù. :

( ¿ªÀÚÁÖ : ³»ºÎÀûÀ¸·Î´Â ÇÔ¼ö¿Í Ŭ·¡½ºµµ º¯¼ö·Î Á¤ÀǵDZâ´Â ÇÏÁö¸¸ À̰͵éÀº ÀϹÝÀûÀÎ º¯¼ö·Î üũµÇÁö ¾Ê´Â´Ù. )

º¯¼öŸÀÔÀº º¸Åë ÇÁ·Î±×·¡¸Ó°¡ ¼±ÅÃÇÒ Çʿ䰡 ¾ø´Ù. ´ë½Å, PHP°¡ ½ÇÇàÁß¿¡ º¯¼öÀÇ °ªÀÇ ³»¿ë¿¡ µû¶ó ÀÚµ¿ÀûÀ¸·Î ¹Ù²Ù¾î ÁØ´Ù.

¸¸¾à ¿©·¯ºÐÀÌ Æ¯Á¤ÇÑ º¯¼ö ŸÀÔÀ¸·Î ÁöÁ¤ÇÏ°í ½Í´Ù¸é º¯¼ö¸¦ cast Çϰųª, settype() ÇÔ¼ö¸¦ »ç¿ëÇÑ´Ù.

Á¾Á¾ º¯¼öµéÀº ½ÇÇà½Ã ¾î¶² ŸÀÔÀ¸·Î µÇ¾î ÀÖ´À³Ä¿¡ µû¶ó ƯÁ¤ÇÑ »óȲ¿¡¼­ ¿øÇÏ´Â ´ë·Î µ¿ÀÛÇÏÁö ¾ÊÀ» ¶§°¡ ÀÖ´Ù. Type Juggling ÆíÀ» º¸¸é ÀÚ¼¼È÷ ¾Ë ¼ö ÀÖ´Ù.


Á¤¼öÇü (Integers)

Á¤¼öÇüÀº ´ÙÀ½°ú °°Àº ÇüÅÂÀÇ ¹®ÀåÀ¸·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.

  1 
  2 $a = 1234; # decimal number
  3 $a = -123; # a negative number
  4 $a = 0123; # octal number (equivalent to 83 decimal)
  5 $a = 0x12; # hexadecimal number (equivalent to 18 decimal)
  6      

 


½Ç¼öÇü (Floating point numbers)

½Ç¼öÇü("doubles")Àº ´ÙÀ½°ú °°Àº ÇüÅÂÀÇ ¹®ÀåÀ¸·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.

  1  
  2 $a = 1.234; $a = 1.2e3;
  3      

 


¹®ÀÚ¿­ (Strings)

¹®ÀÚ¿­Àº µÎ °³ÀÇ delimiters¸¦ »ç¿ëÇØ ³ªÅ¸³½´Ù.

¹®ÀÚ¿­ÀÌ Å« µû¿ÈÇ¥(")·Î µÑ·¯½ÎÀÌ°Ô Ç¥½ÃµÇ¸é, ´ÙÀ½°ú °°ÀÌ Æ¯¼ö ¹®ÀÚµéÀ» Æ÷ÇÔÇÒ ¼ö ÀÖ´Ù. C³ª Perl¿¡¼­Ã³·³ ¹é½½·¡½Ã(\)¸¦ »ç¿ëÇÏ¿© Ư¼ö ±âÈ£¸¦ Ç¥½ÃÇÏ°Ô µÈ´Ù.

Table 6-1. Escaped characters

sequence

meaning

\n

newline

\r

carriage

\t

horizontal tab

\\

backslash

\$

dollar sign

\"

double-quote

¶§·Î´Â ´Ù¸¥ escape¸¦ »ç¿ëÇÒ ¼ö ÀÖÁö¸¸, worningÀÌ ¹ß»ýÇÏ°Ô µÈ´Ù.

¹®ÀÚ¿­À» Ç¥ÇöÇÏ´Â ¶Ç ´Ù¸¥ ¹æ¹ýÀº Å« µû¿ÈÇ¥(") ´ë½Å ÀÛÀº µû¿ÈÇ¥(')¸¦ »ç¿ëÇÏ´Â °ÍÀÌ´Ù. À̰ÍÀº \\°ú \'ÀÇ µÎ °³¸¸À» ¹é½½·¡½Ã ó¸®ÇÏ°í ³ª¸ÓÁö´Â ±×³É µÐ´Ù. ÀÛÀº µû¿ÈÇ¥¸¦ »ç¿ëÇÏ´Â ¹®ÀÚ¿­ ³»¿¡¼­´Â º¯¼ö¸¦ »ç¿ëÇÏ¿© ±× °ªÀ» Ãâ·ÂÇÏ´Â ±â´ÉÀ» »ç¿ëÇÒ ¼ö ¾ø´Ù.

¹®ÀÚ¿­À» ¼±¾ðÇÏ´Â ´Ù¸¥ ¹æ¹ýÀº  here doc ±¸¹®("<<<")À» »ç¿ëÇÏ´Â °ÍÀÌ´Ù. <<< µÚ¿¡ Àû´çÇÑ identifier¸¦ Àû¾îÁÖ°í, ¿øÇÏ´Â ¹®ÀÚ¿­ÀÇ ³»¿ëÀ» ÀûÀº ÈÄ¿¡, ¾Õ¿¡ ÀûÀº identifier·Î ¹®ÀÚ¿­À» ³¡¸ËÀ¸¸é µÈ´Ù. ³¡¸Ë´Â identifier´Â ÇØ´ç ¶óÀÎÀÇ Ã¹¹øÂ° Ä­¿¡¼­ ½ÃÀÛÇØ¾ß ÇÑ´Ù.

Example 6-1. Here doc string quoting example

  1 
  2 $str = <<<EOD
  3 Example of string
  4 spanning multiple lines
  5 using heredoc syntax.
  6 EOD;
  7      

Note: Here docÀº PHP 4¿¡¼­ºÎÅÍ Áö¿øµÈ´Ù.

¹®ÀÚ¿­Àº '.' (Á¡) ¿¬»êÀÚ·Î ¿¬°áÇÒ ¼ö ÀÖ´Ù. '+' (´õÇϱâ) ¿¬»êÀÚ´Â »ç¿ëÇÒ ¼ö ¾ø´Ù. ÀÚ¼¼ÇÑ Á¤º¸´Â String operators ºÎºÐÀ» ÂüÁ¶Çϱ⠹ٶõ´Ù.

¹®ÀÚ¿­³»ÀÇ °³°³ÀÇ ¹®ÀÚ´Â, C ¾ð¾î¿¡¼­ÀÇ ¹®ÀÚÀÇ ¹è¿­·ÎµÈ ¹®ÀÚ¿­Ã³·³ ¹è¿­¿¡ ¼ýÀÚ À妽º¸¦ ÅëÇØ Á¢±ÙÀÌ °¡´ÉÇÏ´Ù. ¾Æ·¡ ±× ¿¹°¡ ÀÖ´Ù.

Example 6-2. Some string examples

  1 
  2 <?php
  3 /* Assigning a string. */
  4 $str = "This is a string";
  5 
  6 /* Appending to it. */
  7 $str = $str . " with some more text";
  8 
  9 /* Another way to append, includes an escaped newline. */
 10 $str .= " and a newline at the end.\n";
 11 
 12 /* This string will end up being '<p>Number: 9</p>' */
 13 $num = 9;
 14 $str = "<p>Number: $num</p>";
 15 
 16 /* This one will be '<p>Number: $num</p>' */
 17 $num = 9;
 18 $str = '<p>Number: $num</p>';
 19 
 20 /* Get the first character of a string  */
 21 $str = 'This is a test.';
 22 $first = $str[0];
 23 
 24 /* Get the last character of a string. */
 25 $str = 'This is still a test.';
 26 $last = $str[strlen($str)-1];
 27 ?>	  
 28      

 


¹®ÀÚ¿­ º¯È¯ (String conversion)

¹®ÀÚ¿­ÀÌ ¼ýÀÚ·Î ´Ù·ç¾îÁú ¶§, °á°ú °ª°ú typeÀº ´ÙÀ½°ú °°ÀÌ °áÁ¤µÈ´Ù.

¸¸¾à ¹®ÀÚ¿­ ¾È¿¡ '.' À̳ª 'e', 'E'ÀÇ ¹®ÀÚ°¡ ÀÖÀ» °æ¿ì ±× typeÀº doubleÀÌ µÈ´Ù. ±×·¸Áö ¾Ê´Ù¸é Á¤¼ö °ªÀÌ´Ù

±× °ªÀº ¹®ÀÚ¿­ÀÇ °¡´ÉÇÑ ºÎºÐ±îÁö¸¸ »ç¿ëµÈ´Ù. ¹®ÀÚ¿­ÀÌ ¿Ã¹Ù¸¥ ¼ýÀÚ µ¥ÀÌÅÍ·Î ½ÃÀÛÇÏÁö ¾ÊÀ¸¸é ±× °ªÀº 0ÀÌ´Ù. ¿Ã¹Ù¸¥ ¼ýÀÚ µ¥ÀÌÅÍ´Â '+'/'-', '0'-'9','.'°ú ¼ýÀÚ µÚÀÇ 'e'³ª 'E' Ç¥½ÃÀÌ´Ù.

ù ¹øÂ° Ç¥Çö½ÄÀÌ stringÀÎ °æ¿ì, º¯¼öÀÇ typeÀº ù ¹øÂ°°¡ ¾Æ´Ñ µÎ ¹øÂ° Ç¥Çö½Ä¿¡ ÀÇÇØ °áÁ¤µÈ´Ù.

  1 
  2 $foo = 1 + "10.5";              // $foo is double (11.5)
  3 $foo = 1 + "-1.3e3";            // $foo is double (-1299)
  4 $foo = 1 + "bob-1.3e3";         // $foo is integer (1)
  5 $foo = 1 + "bob3";              // $foo is integer (1)
  6 $foo = 1 + "10 Small Pigs";     // $foo is integer (11)
  7 $foo = 1 + "10 Little Piggies"; // $foo is integer (11)
  8 $foo = "10.0 pigs " + 1;        // $foo is integer (11)
  9 $foo = "10.0 pigs " + 1.0;      // $foo is double (11)     
 10      

ÀÌ º¯È¯¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ¼³¸íÀºUnix manual pageÀÇ strtod(3)À» º¸¾Æ¶ó.

¸¸¾à ¿©·¯ºÐÀÌ À§ÀÇ ¿¹Á¦¸¦ ½ÇÁ¦ ½ÇÇèÇϰíÀÚ ÇÑ´Ù¸é, À§ÀÇ ¿¹Á¦¸¦ Àß¶ó ºÙÀÎ ÈÄ¿¡, ¾î¶² ÀÏÀÌ ÀϾ´Â °¡¸¦ ¾Ë±â À§ÇØ ¾Æ·¡ÀÇ ÁÙÀ» »ðÀÔÇÑ´Ù.

  1 
  2 echo "\$foo==$foo; type is " . gettype( $foo ) . "<br>\n";
  3       

 


¹è¿­ (Arrays)

¹è¿­À» ½ÇÁ¦·Î hash tables (associative arrays) °ú indexed arrays (vectors)ÀÇ µÎ°¡Áö·Î µ¿½Ã¿¡ »ç¿ëµÈ´Ù.


ÀÏÂ÷¿ø ¹è¿­ (Single Dimension Arrays)

PHP´Â scalar ¹è¿­°ú associative ¹è¿­ÀÇ µÎ °¡Áö¸¦ Áö¿øÇÑ´Ù. »ç½Ç µÎ °¡ÁöÀÇ Â÷ÀÌ´Â ¾ø´Ù. ¿©·¯ºÐÀº list()³ª array() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ¹è¿­À» ¸¸µé°Å³ª, °¢ ¿ø¼ÒÀÇ °ªÀ» Á¤ÇØ ÁÖ¾î ¹è¿­À» ¸¸µé ¼ö ÀÖ´Ù.

  1  
  2 $a[0] = "abc"; 
  3 $a[1] = "def"; 
  4 $b["foo"] = 13;
  5       

¶ÇÇÑ ´ÙÀ½°ú °°ÀÌ º¯¼ö¿¡ °ªÀ» ´õÇØÁÖ´Â °Í¸¸À¸·Î ¹è¿­À» ¸¸µé ¼öµµ ÀÖ´Ù.

  1  
  2 $a[] = "hello"; // $a[2] == "hello"
  3 $a[] = "world"; // $a[3] == "world" 
  4       

¹è¿­Àº Á¤·ÄÀ» ¿øÇÏ´Â Çü½Ä¿¡ µû¶ó asort(), arsort(), ksort(), rsort(), sort(), uasort(), usort(), uksort() ÇÔ¼öµéÀ» ÀÌ¿ëÇØ ¼ø¼­´ë·Î Á¤·ÄÇÒ ¼ö ÀÖ´Ù.

count() ÇÔ¼ö¸¦ »ç¿ëÇÏ¸é ¹è¿­ÀÇ ¿ø¼Ò °³¼ö¸¦ ¼¿ ¼ö ÀÖ´Ù.

next()¿Í prev() ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¿© ¹è¿­ÀÇ ³»¿ëÀ» Ž»öÇÒ ¼ö ÀÖ´Ù. ¹è¿­ÀÇ ³»¿ëÀ» Ž»öÇÏ´Â ¹æ¹ýÀ¸·Î each() ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ´Ù.


´ÙÂ÷¿ø ¹è¿­ (Multi-Dimensional Arrays)

´ÙÂ÷¿ø ¹è¿­À̶ó ÇÏ´õ¶óµµ ½ÇÁ¦·Î ¸Å¿ì °£´ÜÇÑ´Ù. ¹è¿­ÀÇ °¢ Â÷¿ø¿¡ ´ëÇÏ¿© ´ÜÁö [key]°ªÀ» µÚ¾î ºÙ¿©ÁÖ¸é µÈ´Ù.

  1  
  2 $a[1]      = $f;               # one dimensional examples
  3 $a["foo"]  = $f;   
  4 
  5 $a[1][0]     = $f;             # two dimensional
  6 $a["foo"][2] = $f;             # (you can mix numeric and associative indices)
  7 $a[3]["bar"] = $f;             # (you can mix numeric and associative indices)
  8 
  9 $a["foo"][4]["bar"][0] = $f;   # four dimensional!
 10       

PHP3¿¡¼­, ¹®ÀÚ¿­ ³»¿¡¼­ ´ÙÂ÷¿ø ¹è¿­ÀÇ °ªÀ» Á÷Á¢ Á¢±ÙÇÏ´Â °ÍÀº ºÒ°¡´ÉÇÏ´Ù. ¿¹¸¦µé¾î ´ÙÀ½°ú °°Àº ¹®ÀåÀº ¿øÇÏ´Â °á°ú¸¦ ¾òÁö ¸øÇÒ °ÍÀÌ´Ù.

  1  
  2 $a[3]['bar'] = 'Bob';
  3 echo "This won't work: $a[3][bar]";
  4       

PHP3¿¡¼­ À§ÀÇ Ãâ·ÂÀº won't work: Array[bar] ÀÏ °ÍÀÌ´Ù. ¿øÇÏ´Â °á°ú¸¦ ¾òÀ¸·Á¸é ¹®ÀÚ¿­ ¿¬°á ¿¬»êÀÚ(.)¸¦ »ç¿ëÇÏ¿©¾ß ÇÒ °ÍÀÌ´Ù.

  1 
  2 $a[3]['bar'] = 'Bob';
  3 echo "This will work: " . $a[3][bar];
  4       

PHP4¿¡¼­´Â Á¢±ÙÇÏ·Á´Â ¹è¿­½ÄÀ» Áß°ýÈ£({})·Î µÑ·¯½ÓÀ¸·Î½á À̰ÍÀ» °¡´ÉÇÏ°Ô ÇÒ ¼öµµ ÀÖ´Ù.

  1 
  2 $a[3]['bar'] = 'Bob';
  3 echo "This will work: {$a[3][bar]}";
  4       

¿©·¯ °¡Áö ¹æ¹ýÀ¸·Î ÀÌ ´ÙÂ÷¿ø ¹è¿­¿¡ °ªÀ» ³ÖÀ» ¼ö ÀÖÀ¸³ª, associative ¹è¿­¿¡ °ªÀ» ÀúÀåÇÏ´Â °£´ÜÇÑ ¹æ¹ýÀ¸·Î array() ¸í·ÉÀ» »ç¿ëÇÏ´Â ¹æ¹ýÀÌ ÀÖ´Ù. ¿ì¼± ´ÙÀ½ÀÇ µÎ°¡Áö ÄÚµå´Â ÀÏÂ÷¿ø ¹è¿­¿¡ °ªÀ» ÀúÀåÇÏ´Â ¹æ¹ýÀ¸·Î °á°ú´Â µ¿ÀÏÇÏ´Ù.

  1  
  2 # Example 1:
  3 
  4 $a["color"]	= "red";
  5 $a["taste"]	= "sweet";
  6 $a["shape"]	= "round";
  7 $a["name"]	= "apple";
  8 $a[3]		= 4;
  9 
 10 # Example 2:
 11 $a = array(
 12      "color" => "red",
 13      "taste" => "sweet",
 14      "shape" => "round",
 15      "name"  => "apple",
 16      3       => 4
 17 );
 18       

array() ÇÔ¼ö´Â ´ÙÂ÷¿ø ¹è¿­¿¡ ´ëÇØ¼­µµ ´ÙÀ½°ú °°ÀÌ »ç¿ëÇÒ ¼ö ÀÖ´Ù. :

  1  
  2 <?
  3 $a = array(
  4      "apple"  => array(
  5           "color"  => "red",
  6           "taste"  => "sweet",
  7           "shape"  => "round"
  8      ),
  9      "orange"  => array(
 10           "color"  => "orange",
 11           "taste"  => "tart",
 12           "shape"  => "round"
 13      ),
 14      "banana"  => array(
 15           "color"  => "yellow",
 16           "taste"  => "paste-y",
 17           "shape"  => "banana-shaped"
 18      )
 19 );
 20 
 21 echo $a["apple"]["taste"];    # will output "sweet"
 22 ?>
 23       
 


°´Ã¼ (Objects)


°´Ã¼ ÃʱâÈ­ (Object Initialization)

°´Ã¼(Object)¸¦ ÃʱâÈ­ÇÏ´Â ¹æ¹ýÀº new ¸í·ÉÀ» »ç¿ëÇÏ¿© object¸¦ º¯¼ö¿¡ ÀνºÅϽº ½ÃŰ´Â °ÍÀÌ´Ù.

  1 
  2 class foo {
  3     function do_foo () { 
  4         echo "Doing foo."; 
  5     }
  6 }
  7 
  8 $bar = new foo;
  9 $bar->do_foo();
 10       
 


Type Àüȯ (Type juggling)

PHP´Â º¯¼ö ¼±¾ð¿¡ À־ ¸íÈ®ÇÑ Á¤ÀǸ¦ ÇÒ Çʿ䵵 ¾ø°í Áö¿øÇÏÁöµµ ¾Ê´Â´Ù. º¯¼öÀÇ Çü½ÄÀº º¯¼ö°¡ »ç¿ëµÇ´Â ¹®Àå ¼Ó¿¡¼­ °áÁ¤µÈ´Ù. ´Ù¸¥ ¸»·Î Çϸé, ¸¸¾à ¿©·¯ºÐÀÌ varÀ̶ó´Â º¯¼ö¿¡ ¹®ÀÚ¿­ °ªÀ» ÇÒ´çÇϸé var´Â ¹®ÀÚ¿­ º¯¼ö°¡ µÇ´Â °ÍÀ̰í, Á¤¼ö °ªÀ» ÇÒ´çÇϸé Á¤¼ö º¯¼ö°¡ µÇ´Â °ÍÀÌ´Ù.

PHPÀÇ ÀÚµ¿ Çü º¯È¯ ¿¹´Â '+' ¿¬»ê¿¡¼­ ãÀ» ¼ö ÀÖ´Ù. ¾î¶² ÇÑ ÇÇ ¿¬»êÀÚ°¡ doubleÀÌ¸é ³ª¸ÓÁö ¸ðµç ÇÇ¿¬»êÀÚÀÇ Çüµµ double·Î ¹Ù²î¾î °á°úµµ doubleÇüÀÌ µÈ´Ù. ¸¸¾à ÇÇ¿¬»êÀÚµéÀÌ Á¤¼öÇüÀÌ¸é °á°úµµ Á¤¼öÇüÀÌ´Ù. ¿©±â¼­ Áß¿äÇÑ °ÍÀº ÇÇ¿¬»êÀÚ ÀÚ½ÅÀÇ ÇüÀº ¹Ù²îÁö ¾Ê´Â´Ù´Â °ÍÀÌ´Ù.

  1 
  2 $foo = "0";  // $foo is string (ASCII 48)
  3 $foo++;      // $foo is the string "1" (ASCII 49)
  4 $foo += 1;   // $foo is now an integer (2)
  5 $foo = $foo + 1.3;  // $foo is now a double (3.3)
  6 $foo = 5 + "10 Little Piggies"; // $foo is integer (15)
  7 $foo = 5 + "10 Small Pigs";     // $foo is integer (15)
  8      

¸¶Áö¸· µÎ °³ÀÇ ¿¹°¡ ÀǾÆÇÑ »ç¶÷Àº String conversionÀ» º¸±â ¹Ù¶õ´Ù.

¸¸¾à º¯¼ö¸¦ ¾î¶² ƯÁ¤ÇÑ typeÀ¸·Î ÁöÁ¤ÇÏ¿© °è»êµÇ°Ô ÇÏ°í ½Í´Ù¸é, Type casting ÆíÀ» º¸±â ¹Ù¶õ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ º¯¼öÀÇ typeÀ» ¹Ù²Ù°í ½Í´Ù¸é settype().À» º¸±â ¹Ù¶õ´Ù.

¸¸¾à ¿©·¯ºÐÀÌ À§ÀÇ ¿¹Á¦¸¦ ½ÇÁ¦ ½ÇÇèÇϰíÀÚ ÇÑ´Ù¸é, À§ÀÇ ¿¹Á¦¸¦ Àß¶ó ºÙÀÎ ÈÄ¿¡, ¾î¶² ÀÏÀÌ ÀϾ´Â °¡¸¦ ¾Ë±â À§ÇØ ¾Æ·¡ÀÇ ÁÙÀ» »ðÀÔÇÑ´Ù.

  1 
  2 echo "\$foo==$foo; type is " . gettype( $foo ) . "<br>\n";
  3      

Note: ¹è¿­·ÎÀÇ ÀÚµ¿ º¯È¯Àº ÇöÀç Á¤ÀǵǾî ÀÖÁö ¾Ê´Ù.

  1 
  2 $a = 1;       // $a is an integer
  3 $a[0] = "f";  // $a becomes an array, with $a[0] holding "f"
  4       

À§ÀÇ ¿¹¿¡¼­´Â $aÀÇ °á°ú°¡ ù ¹øÂ° ¿ä¼Ò·Î 'f'¸¦ °¡Áö´Â ¹è¿­ÀÌ µÉ °ÍÀ̶ó°í ¾Ë ¼ö ÀÖ´Ù. ÇÏÁö¸¸ ´ÙÀ½À» º¸ÀÚ. :

  1 
  2 $a = "1";     // $a is a string
  3 $a[0] = "f";  // What about string offsets? What happens?
  4       

PHP°¡ ¹®ÀÚ¿­³»ÀÇ ¹®ÀÚ¸¦ indexingÇØ¼­ Á¢±ÙÇÏ´Â °ÍÀÌ °¡´ÉÇϹǷΠÀ§ÀÇ ¿¹Á¦´Â $aÀÇ ¹®ÀÚ¿­ÀÇ Ã¹ ¹øÂ° ¹®ÀÚ¸¦ "f"·Î Ç϶ó´Â °ÍÀÎÁö, $a¸¦ "f"¶ó´Â ¹®ÀÚ¿­À» ù ¹øÂ° ¿ø¼Ò·Î °¡Áø ¹è¿­·Î ¸¸µé¶ó´Â °ÍÀÎÁö ¾Ë ¼ö ¾ø´Ù.

ÀÌ·± ÀÌÀ¯¿¡¼­ PHP 3.0.12 ¿Í PHP 4.0b3-RC4¿¡¼­´Â ÀÌ ºÎºÐ¿¡¼­ÀÇ ÀÚµ¿ º¯È¯Àº Á¤ÀǵǾî ÀÖÁö ¾Ê´Ù. ÀÌ ¹®Á¦ÀÇ ÇØ°áÀº ÇöÀç ³íÀÇÁßÀÌ´Ù.


Type casting

PHPÀÇ Type castingÀº C¿¡¼­¿Í °°Àº ¹æ¹ýÀ¸·Î ÇÑ´Ù : º¯È¯ÇÏ·Á´Â º¯¼ö ¾Õ¿¡ ¿øÇÏ´Â type À̸§À» °ýÈ£ ¾È¿¡ ½áÁÖ¸é µÈ´Ù.

  1 
  2 $foo = 10;   // $foo is an integer
  3 $bar = (double) $foo;   // $bar is a double
  4       

´ÙÀ½°ú °°Àº º¯È¯ÀÌ °¡´ÉÇÏ´Ù. :

Åǰú °ø¹éÀº °ýÈ£¾È¿¡¼­´Â ¹«½ÃµÈ´Ù. Áï ´ÙÀ½ µÎ °³ÀÇ ¹®ÀåÀº µ¿ÀÏÇÏ´Ù. :

  1 
  2 $foo = (int) $bar;
  3 $foo = ( int ) $bar;
  4       

ƯÁ¤ ŸÀÔ°£ÀÇ Çüº¯È¯Àº ±× °á°ú¸¦ ¸íÈ®ÇÏ°Ô ¾Ë ¼ö ¾ø´Â °æ¿ì°¡ ÀÖ´Ù. ´ÙÀ½°ú °°Àº ³»¿ëµéÀ» ¾Ë¾ÆµÎµµ·Ï ÇÏÀÚ.

½ºÄ®¶ó°ªÀ̳ª ¹®ÀÚ¿­À» ¹è¿­·Î Çü º¯È¯Çϸé, ±× °ªÀº ÇØ´ç ¹è¿­ÀÇ Ã¹ ¹øÂ° ¿ø¼ÒÀÇ °ªÀÌ µÈ´Ù.

  1 
  2 $var = 'ciao';
  3 $arr = (array) $var;
  4 echo $arr[0];  // outputs 'ciao'  
  5       

½ºÄ®¶ó°ªÀ̳ª ¹®ÀÚ¿­À» °´Ã¼·Î Çü º¯È¯Çϸé, ±× °ªÀº ÇØ´ç °´Ã¼ÀÇ 'scalar'¶ó´Â ¼Ó¼ºÀÇ °ªÀÌ µÈ´Ù.

  1 
  2 $var = 'ciao';
  3 $obj = (object) $var;
  4 echo $obj->scalar;  // outputs 'ciao'
  5       

 


Chapter 7. º¯¼ö (Variables)


¹Ì¸® Á¤ÀÇµÈ º¯¼ö (Predefined variables)

PHP´Â ¸ðµç ½ºÅ©¸³Æ®¿¡ ±×°ÍÀÌ ½ÇÇà µÉ ¶§ ´Ù¼öÀÇ ¹Ì¸® Á¤ÀÇµÈ º¯¼öµéÀ» Á¦°øÇÑ´Ù. ÀÌ º¯¼öµéÁß ¼­¹öÀÇ Á¾·ù³ª ¹öÀü, ±âŸ ´Ù¸¥ ¿äÀÎÀ¸·ÎÀÎÇØ ´Þ¶óÁö´Â ¸¹Àº º¯¼öµéÀÌ À̰÷¿¡ ¹®¼­È­ µÇÁö ¾Ê¾Ò´Ù. ¶ÇÇÑ ÀÌ º¯¼öµéÁß ¸¹Àº °ÍÀÌ PHP°¡ command-lineÀ¸·Î µ¿ÀÛÇÒ ¶§´Â »ç¿ëÇÒ ¼ö ¾ø´Ù.

ÀÌ·± ¿©·¯ ¿äÀεéÀÌ ÀÖÁö¸¸ À̰÷¿¡¼­´Â °¡Àå ÀϹÝÀûÀΠȯ°æÀÎ Apache (1.3.6)¿¡¼­ ¸ðµâ·Î PHP3¸¦ ¼³Ä¡ÇÑ È¯°æ¿¡¼­ÀÇ ¹Ì¸® Á¤ÀÇµÈ º¯¼öµéÀ» »ìÆìº¸µµ·Ï ÇÏÀÚ.

¿©·¯ºÐÀÌ »ç¿ëÇÏ´Â ½Ã½ºÅÛÀÇ ¸ðµç ¹Ì¸® Á¤ÀÇµÈ º¯¼öµéÀ» º¸·Á¸é phpinfo() ÇÔ¼ö¸¦ »ç¿ëÇϵµ·ÏÇÏÀÚ. (ÀÌ ÇÔ¼ö´Â ´Ù¸¥ ¿©·¯ À¯¿ëÇÑ Á¤º¸µµ ¾Ë·ÁÁØ´Ù.)

Note: ÀÌ ¸ñ·ÏÀº ¿ÏÀüÇÏÁö ¾Ê´Ù. (¿Ïº®ÇÒ »ý°¢µµ ¾ø´Ù.) ÀÌ ¸ñ·ÏÀº ´Ü¼øÈ÷ ¿©·¯ºÐÀÇ ½ºÅ©¸³Æ®¿¡¼­ ¾î¶² Á¾·ùÀÇ ¹Ì¸® Á¤ÀÇµÈ º¯¼öµéÀÌ »ç¿ëµÉ ¼ö Àִ°¡ÀÇ ¿¹½ÃÀÏ »ÓÀÌ´Ù.

Apache variables

ÀÌ º¯¼öµéÀº Apache À¥¼­¹ö·ÎºÎÅÍ »ý¼ºµÈ °ÍÀÌ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ ´Ù¸¥ À¥¼­¹ö¸¦ »ç¿ëÇϰí ÀÖ´Ù¸é ÀÌ¿Í µ¿ÀÏÇÑ º¯¼öµéÀÌ »ý¼ºµÈ´Ù°í º¸ÀåÇÒ ¼ö ¾ø´Ù. ¾Æ¸¶µµ ÀϺδ ¾ø¾îÁö°í, ¿©±â¿¡ ÀÖ´Â º¯¼öµéÀÌ »õ·Î »ý±æ °ÍÀÌ´Ù. ¿©±â¿¡ ÀÖ´Â º¯¼öÁß ´Ù¼ö´Â CGI 1.1 specification¿¡¼­ ³ª¿Â °ÍÀ̰í, ±× ³»¿ë´ë·Î »ç¿ëµÈ´Ù.

À̰÷ÀÇ º¯¼öÁß PHP°¡ command lineÀ¸·Î µ¿ÀÛÇÒ °æ¿ì »ç¿ëµÉ ¼ö ÀÖ´Â º¯¼ö´Â °ÅÀÇ ¾ø´Ù.

GATEWAY_INTERFACE
¼­¹ö°¡ »ç¿ëÇϰí ÀÖ´Â CGI specificationÀÇ revision. ¿¹: 'CGI/1.1'.
 
SERVER_NAME
ÇöÀç ½ºÅ©¸³Æ®°¡ ½ÇÇàµÇ°í Àִ ȣ½ºÆ®ÀÇ À̸§. ¸¸¾à ½ºÅ©¸³Æ®°¡ °¡»ó È£½ºÆ®¿¡¼­ ½ÇÇàµÇ°í ÀÖ´Ù¸é, ÀÌ °ªÀº °¡»ó È£½ºÆ®·Î Á¤ÀÇµÈ °ªÀÌ µÉ °ÍÀÌ´Ù.
 
SERVER_SOFTWARE
¿ä±¸¿¡´ëÇÑ ´ë´äÀÇ Çì´õ¿¡ »ç¿ëÇÒ ¼­¹ö identification ¹®ÀÚ¿­
 
SERVER_PROTOCOL
ÆäÀÌÁö°¡ ¿ä±¸µÇ¾îÁú ¶§ »ç¿ëÇÑ ÇÁ·ÎÅäÄÝÀÇ À̸§°ú ¸®ºñÁ¯. ¿¹: 'HTTP/1.0';
 
REQUEST_METHOD
ÇØ´ç ÆäÀÌÁö¸¦ ¿ä±¸ÇÒ ¶§ »ç¿ëÇÑ ¹æ¹ý(method). ¿¹: 'GET', 'HEAD', 'POST', 'PUT'.
 
QUERY_STRING
ÇØ´ç ÆäÀÌÁö¸¦ Á¢±ÙÇÒ ¶§ »ç¿ëµÈ query string.
 
DOCUMENT_ROOT
ÇöÀç ½ºÅ©¸³Æ®°¡ »øÇàÁßÀÎ document root µð·ºÅ丮. ¼­¹öÀÇ ¼³Á¤ ÆÄÀÏ¿¡ Á¤ÀǵǾî ÀÖ´Ù.
 
HTTP_ACCEPT

Contents of the Accept: header from the current request, if there is one.

HTTP_ACCEPT_CHARSET

Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.

HTTP_ENCODING

Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'.

HTTP_ACCEPT_LANGUAGE

Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'.

HTTP_CONNECTION

Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.

HTTP_HOST

Contents of the Host: header from the current request, if there is one.

HTTP_REFERER

The address of the page (if any) which referred the browser to the current page. This is set by the user's browser; not all browsers will set this.

HTTP_USER_AGENT

Contents of the User_Agent: header from the current request, if there is one. This is a string denoting the browser software being used to view the current page; i.e. Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's functionality to the capabilities of the user's browser.

REMOTE_ADDR

The IP address from which the user is viewing the current page.

REMOTE_PORT

The port being used on the user's machine to communicate with the web server.

SCRIPT_FILENAME

The absolute pathname of the currently executing script.

SERVER_ADMIN

The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host.

SERVER_PORT

The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for instance, will change this to whatever your defined secure HTTP port is.

SERVER_SIGNATURE

String containing the server version and virtual host name which are added to server-generated pages, if enabled.

PATH_TRANSLATED

Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.

SCRIPT_NAME

Contains the current script's path. This is useful for pages which need to point to themselves.

REQUEST_URI

The URI which was given in order to access this page; for instance, '/index.html'.

Environment variables

These variables are imported into PHP's global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. Please see your shell's documentation for a list of defined environment variables.

Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor.

PHP variables

These variables are created by PHP itself.

argv

Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.

argc

Contains the number of command line parameters passed to the script (if run on the command line).

PHP_SELF

The filename of the currently executing script, relative to the document root. If PHP is running as a command-line processor, this variable is not available.

HTTP_COOKIE_VARS

An associative array of variables passed to the current script via HTTP cookies. Only available if variable tracking has been turned on via either the track_vars configuration directive or the <?php_track_vars?> directive.

HTTP_GET_VARS

An associative array of variables passed to the current script via the HTTP GET method. Only available if variable tracking has been turned on via either the track_vars configuration directive or the <?php_track_vars?> directive.

HTTP_POST_VARS

An associative array of variables passed to the current script via the HTTP POST method. Only available if variable tracking has been turned on via either the track_vars configuration directive or the <?php_track_vars?> directive.


º¯¼ö »ç¿ë ¹üÀ§ (Variable Scope)

º¯¼ö°¡ »ç¿ë°¡´ÉÇÑ °÷Àº ±× º¯¼ö°¡ ¼±¾ðµÈ °÷ ¾È¿¡¼­ ¸¸ÀÌ´Ù. PHP º¯¼öÀÇ ´ëºÎºÐÀº ÇÑ °³ÀÇ ¹üÀ§(single scope)¸¸À» °¡Áö°í ÀÖ´Ù. ÀÌ ¹üÀ§´Â include³ª require ÆÄÀÏ¿¡µµ µ¿ÀÏÇÏ°Ô Àû¿ëµÈ´Ù. ¿¹¸¦µé¾î :

  1 
  2 $a = 1;
  3 include "b.inc";
  4     

À§¿¡¼­ $aº¯¼ö´Â b,inc ½ºÅ©¸³Æ®¿¡¼­µµ »ç¿ëÇÒ ¼ö ÀÖ´Ù.

±âº»ÀûÀ¸·Î ÇÔ¼ö ¾È¿¡¼­ ¼±¾ðµÈ °ÍÀº ÇÔ¼ö ¾È¿¡¼­¸¸ »ç¿ëµÇ´Â Áö¿ª º¯¼öÀÌ´Ù. ¶ÇÇÑ ÇÔ¼ö ¾È¿¡¼­ »ç¿ëµÇ´Â ÇÔ¼öµéÀº ±âº»ÀûÀ¸·Î Áö¿ª º¯¼ö¶ó°í °¡Á¤Çϰí ã°Ô µÈ´Ù. ¿¹¸¦ µé¾î:

  1  
  2 $a = 1; /* global scope */ 
  3 
  4 Function Test () { 
  5     echo $a; /* reference to local scope variable */ 
  6 } 
  7 
  8 Test ();
  9     

ÀÌ ½ºÅ©¸³Æ®´Â ÇÔ¼ö ¾ÈÀÇ $a º¯¼ö¸¦ Áö¿ªº¯¼ö·Î °¡Á¤ÇÏ¿´°í, Áö¿ªº¯¼ö $a¿¡´Â ¾Æ¹« °ªµµ ´ëÀÔµÇÁö ¾Ê¾Ò±â ¶§¹®¿¡ ¾Æ¹«·± Ãâ·Âµµ ³ªÅ¸³ªÁö ¾Ê´Â´Ù. À̰ÍÀº C¿Í´Â ¾à°£ Â÷À̰¡ ³ª´Â ºÎºÐÀÌ´Ù. PHP¿¡¼­ Àü¿ªº¯¼ö¸¦ »ç¿ëÇÏ·Á¸é »ç¿ëÇÏ°í ½ÍÀº Àü¿ª º¯¼ö¸¦ ÇÔ¼ö ¾È¿¡ global ¼±¾ðÀ» ÇØ ÁÖ¾î¾ß ÇÑ´Ù. ¿¹¸¦ µé¾î :

  1 
  2 $a = 1;
  3 $b = 2;
  4 
  5 Function Sum () {
  6     global $a, $b;
  7 
  8     $b = $a + $b;
  9 } 
 10 
 11 Sum ();
 12 echo $b;
 13     

À§ÀÇ ½ºÅ©¸³Æ®´Â "3"À» Ãâ·ÂÇÒ °ÍÀÌ´Ù. ÇÔ¼ö ³»¿¡¼­ $a and $b¸¦ global·Î ¼±¾ðÇßÀ¸¹Ç·Î, ÀÌ ÇÔ¼ö³»ÀÇ $a, $b´Â Àü¿ª º¯¼ö¸¦ ÂüÁ¶ÇÏ°Ô µÈ´Ù. ÇÔ¼ö ³»¿¡¼­ ´Ù·ê ¼ö ÀÖ´Â Àü¿ªº¯¼öÀÇ °³¼ö¿¡´Â Á¦ÇÑÀÌ ¾ø´Ù.

Àü¿ª º¯¼ö¸¦ ÂüÁ¶ÇÏ´Â µÎ ¹øÂ° ¹æ¹ýÀº PHP¿¡¼­ Ưº°È÷ Á¤ÀÇÇϰí ÀÖ´Â $GLOBALS¶ó´Â ¹è¿­À» »ç¿ëÇÏ´Â °ÍÀÌ´Ù. À§ÀÇ ¿¹¸¦ ´ÙÀ½°ú °°ÀÌ ¹Ù²ã ¾µ ¼ö ÀÖ´Ù. :

  1 
  2 $a = 1;
  3 $b = 2;
  4 
  5 Function Sum () {
  6     global $a, $b;
  7 
  8     $b = $a + $b;
  9 } 
 10 
 11 Sum ();
 12 echo $b;
 13     

$GLOBALS ¹è¿­Àº º¯¼öÀ̸§ÀÌ Key°¡ µÇ°í, ±× º¯¼öÀÇ ³»¿ëÀÌ °ªÀÌ µÇ´Â ¿ø¼Ò¸¦ °¡Áø associative ¹è¿­ÀÌ´Ù.

º¯¼ö ¹üÀ§¿¡¼­ ¶Ç ´Ù¸¥ Áß¿äÇÑ °ÍÀº Á¤Àû º¯¼ö(static variable)ÀÌ´Ù. Á¤Àû º¯¼ö´Â Áö¿ª ÇÔ¼ö ³»¿¡¼­¸¸ Á¸ÀçÇÏÁö¸¸ Áö¿ª ÇÔ¼ö°¡ Á¾·áµÇ¾îµµ ±× °ªÀ» Àоî¹ö¸®Áö ¾Ê°í °¡Áö°í ÀÖ´Ù. ´ÙÀ½ ¿¹¸¦ º¸ÀÚ :

  1 
  2 Function Test () {
  3     $a = 0;
  4     echo $a;
  5     $a++;
  6 }
  7     

À§ÀÇ ÇÔ¼ö´Â Test()¸¦ ºÎ¸¦ ¶§ ¸¶´Ù $a°¡ 0À¸·Î ´ëÀԵǹǷΠ0À» Ãâ·ÂÇÑ´Ù.

  1 
  2 Function Test () {
  3     static $a = 0;
  4     echo $a;
  5     $a++;
  6 }
  7     

À§ÀÇ ÇÔ¼ö´Â Test()¸¦ ºÎ¸¦ ¶§¸¶´Ù óÀ½¿¡´Â 0, ´ÙÀ½¿¡´Â 1, ±× ´ÙÀ½¿¡´Â 2ÇÏ´Â ½ÄÀ¸·Î Çϳª¾¿ Áõ°¡µÈ ¼ö¸¦ Ãâ·ÂÇØ ÁØ´Ù. Áï, $aÀÇ °ªÀÌ º¸Á¸µÇ´Â °ÍÀÌ´Ù.

¶ÇÇÑ Á¤Àû º¯¼ö´Â ´ÙÀ½°ú °°ÀÌ recursion¿¡¼­ ¹Ýµå½Ã ÇÊ¿äÇÏ´Ù. Àç±ÍÀûÀÎ ÇÔ¼ö´Â ÀÚ±â ÀÚ½ÅÀÇ ÇÔ¼ö¸¦ È£ÃâÇÏ´Â °ÍÀ» ¸»ÇÑ´Ù. Àç±ÍÀûÀÎ ÇÔ¼ö¸¦ »ç¿ëÇÒ ¶§´Â ¹«ÇÑ ·çÇÁ¿¡ ºüÁú ¼ö Àֱ⠶§¹®¿¡ ¸Å¿ì ÁÖÀǸ¦ ¿äÇÑ´Ù. µû¶ó¼­ ¿©·¯ºÐÀº Àç±Í È£ÃâÀ» ³¡³»´Â ÀûÀýÇÑ ¹æ¹ýÀ» ¸¶·ÃÇØ µÎ¾î¾ß ÇÑ´Ù. ´ÙÀ½ÀÇ °£´ÜÇÑ ¿¹Á¦´Â 10¹øÀÇ Àç±ÍÀû È£ÃâÀ» ÇÑ´Ù. :

  1 
  2 Function Test () {
  3     static $a = 0;
  4     echo $a;
  5     $a++;
  6 }
  7     

 


°¡º¯ º¯¼ö (Variable variables)

°¡²û º¯¼öÀÇ À̸§À» º¯°æÇÒ ¼ö ÀÖ´Ù¸é Æí¸®ÇÏ´Ù°í ´À³¥ ¶§°¡ ÀÖ´Ù. À̰÷¿¡¼­´Â º¯¼öÀÇ À̸§À» ¹Ù²Ù¾î »ç¿ëÇÏ´Â ¹æ¹ýÀ» ¾Ë¾Æº¸ÀÚ. º¸ÅëÀÇ º¯¼ö ¼±¾ðÀº ´ÙÀ½°ú °°´Ù. :

  1 
  2 $a = "hello";
  3     

¿©±â¼­ ÀÌ °¡º¯ º¯¼öÀº º¯¼öÀÇ °ªÀ» °¡Áú ¼öµµ ÀÖ°í, ¶ÇÇÑ ÀÌ °ªÀ» º¯¼öÀÇ À̸§À¸·Î ´Ù·ê ¼öµµ ÀÖ´Ù. À§ÀÇ ¿¹¿¡¼­ hello´Â $$¸¦ ¾Õ¿¡ ºÙÀÌ¸é º¯¼ö À̸§À¸·Î »ç¿ëÇÒ ¼ö ÀÖ´Â °ÍÀÌ´Ù. ¿¹ :

  1 
  2 $$a = "world";
  3     

ÀÌ·¸°Ô Çϸé PHPÀÇ symbol tree¿¡´Â "hello"¶ó´Â °ªÀ» °¡Áö´Â $a¿Í "world"¶ó´Â °ªÀ» °¡Áö´Â $helloÀÇ µÎ °³ÀÇ º¯¼ö°¡ »ý±â°Ô µÈ´Ù. ±×·¯¹Ç·Î ´ÙÀ½°ú °°Àº ¹®ÀåÀº :

  1 
  2 echo "$a ${$a}";
  3     

´ÙÀ½ ¹®Àå°ú ¶È °°Àº Ãâ·ÂÀ» ³ªÅ¸³»°Ô µÈ´Ù.:

  1 
  2 echo "$a $hello";
  3     

ie. µÑÀÇ Ãâ·Â: hello world.

°¡º¯ º¯¼ö¸¦ ¹è¿­°ú ÇÔ²² »ç¿ëÇÏ·Á¸é, ÇѰ¡Áö ¸ðÈ£¼º ¹®Á¦¸¦ ÇØ°áÇØ¾ß ÇÑ´Ù. ±×°ÍÀº, ¸¸¾à ¿©·¯ºÐÀÌ $$a[1]À̶ó°í ½èÀ¸¸é, $a[1]À» ÇϳªÀÇ º¯¼ö·Î º¼ °ÍÀÎÁö, ¾Æ´Ï¸é $$a¸¦ º¯¼ö·Î º¸°í ±× º¯¼ö¿¡ [1]ÀÇ À妽º¸¦ ÇØ ÁÙ °ÍÀΰ¡ ÇÏ´Â ¹®Á¦ÀÌ´Ù. ´ÙÀ½°ú °°ÀÌ ÇÏ¿© ¸ðÈ£¼ºÀ» ÇØ°áÇÏÀÚ. ÀüÀÚÀÇ °æ¿ì ${$a[1]}¶ó°í ¾²°í, ÈÄÀÚÀÇ °æ¿ì´Â ${$a}[1]¶ó°í ¾²¸é µÈ´Ù. ( ¿ªÀÚÁÖ: °¡º¯ º¯¼ö¸¦ ³ªÅ¸³¾ ¶§´Â Ç×»ó { }·Î µÑ·¯ ½Î´Â °ÍÀÌ º¸±â ÁÁ°í ¿À·ùµµ ¾ø¾Ù ¼ö ÀÖ´Ù.)


PHP ¹Û¿¡¼­ ¿Â º¯¼öµé (Variables from outside PHP)

HTML Forms (GET and POST)

ÆûÀÌ PHP ½ºÅ©¸³Æ®·Î submitµÇ¸é Æû¿¡ ÀÖ´Â ¸ðµç ³»¿ëµéÀÌ ÀÚµ¿ÀûÀ¸·Î ¸¸µé¾îÁø PHP º¯¼ö·Î µé¾î¿Â´Ù. ´ÙÀ½ÀÇ ÆûÀ» º¸ÀÚ :

Example 7-1. Simple form variable

  1 
  2 <form action="foo.php3" method="post">
  3     Name: <input type="text" name="name"><br>
  4     <input type="submit">
  5 </form>
  6       

À§ÀÇ ÆûÀÌ submitµÇ¸é PHP´Â $nameº¯¼ö¸¦ ¸¸µé°í, ÀÌ º¯¼ö¿¡ ÆûÀÇ Name: Çʵ忡 ÀÔ·ÂµÈ ¸ðµç ³»¿ëÀ» ÀúÀåÇÑ´Ù.

PHP´Â Æû¿¡ 1Â÷¿ø ¹è¿­ º¯¼öµµ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ¿¹¸¦µé¾î, ¿©·¯ºÐÀº ¿©·¯ º¯¼ö¸¦ ÇÔ²² »ç¿ëÇÏ´Â ±×·ì °ü·Ã º¯¼ö(group related variables)³ª multi select º¯¼öÀÇ ³»¿ëµéÀ» °Ë»öÇÒ ¼ö ÀÖ´Ù. :

Example 7-2. More complex form variables

  1 
  2 <form action="array.php" method="post">
  3     Name: <input type="text" name="personal[name]"><br>
  4     Email: <input type="text" name="personal[email]"><br>
  5     Beer: <br>
  6     <select multiple name="beer[]">
  7         <option value="warthog">Warthog
  8         <option value="guinness">Guinness
  9         <option value="stuttgarter">Stuttgarter Schwabenbräu
 10         </select>
 11     <input type="submit">
 12 </form>
 13       

¸¸¾à track_vars ¼³Á¤ÀÌ on µÇ¾î Àְųª, <?php_track_vars?> Áö½ÃÀÚ°¡ ¼³Á¤µÇ¾î ÀÖ´Ù¸é, POST³ª GETÀ¸·Î Àü¼ÛµÇ´Â ¸ðµç º¯¼öµé°ú ±× ³»¿ëÀº Àü¿ª ¹è¿­ º¯¼öÀÎ $HTTP_POST_VARS°ú $HTTP_GET_VARS¿¡¼­ ãÀ» ¼ö ÀÖ´Ù.


IMAGE SUBMITÀÇ º¯¼ö À̸§

ÆûÀº submitÇÒ ¶§ ÀϹÝÀûÀ¸·Î »ç¿ëÇÏ´Â submit ¹öư´ë½Å ´ÙÀ½°ú °°ÀÌ ±×¸²À» »ç¿ëÇÒ ¼öµµ ÀÖ´Ù. :

  1 
  2 <input type=image src="image.gif" name="sub">

»ç¿ëÀÚ°¡ image¸¦ Ŭ¸¯Çϸé, ÆûÀº sub_x¿Í sub_yÀÇ µÎ °³ÀÇ º¯¼ö°¡ Ãß°¡µÇ¾î ¼­¹ö¿¡ Àü¼ÛµÈ´Ù. ÀÌ µÎ º¯¼ö´Â À̹ÌÁö¿¡¼­ »ç¿ëÀÚ°¡ clickÇÑ À§Ä¡ Á¤º¸¸¦ ´ã°í ÀÖ´Ù. ÀϺΠºê¶ó¿ìÀú¿¡¼­´Â ¹ØÁÙ(_)´ë½Å ¸¶Ä§Ç¥(.)¸¦ »ç¿ëÇÏ´Â °æ¿ìµµ Àִµ¥, PHP´Â ÀÌ·± °æ¿ì ÀÚµ¿ÀûÀ» ¸¶Ä§Ç¥(.)¸¦ ¹ØÁÙ(_)·Î ¹Ù²ãÁØ´Ù.


HTTP Cookies

PHP´Â HTTP Äí۸¦ Netscape's SpecÀÇ Á¤ÀÇ¿¡ µû¶ó Á¦°øÇÑ´Ù. Cookie ¸ÞÄ«´ÏÁòÀº Æ®·¡Å·À̳ª »ç¿ëÀÚ ½Äº° µîÀ» À§ÇØ ¿ø°Ý browser¿¡ ÀúÀåµÈ µ¥ÀÌÅ͸¦ µ¹·Á ¹Þ´Â °úÁ¤À» ¸»ÇÑ´Ù. ¿©·¯ºÐÀº cookie¸¦ ¼³Á¤Çϱâ À§ÇØ SetCookie() ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. Cookie´Â HTTP Çì´õÀÇ ÇÑ ºÎºÐÀ̹ǷÎ, SetCookie() ÇÔ¼ö´Â ºê¶ó¿ìÀú·Î º¸³»´Â ¾î¶² µ¥ÀÌÅͺ¸´Ùµµ ¾Õ¿¡ »ç¿ëÇØ¾ß ÇÑ´Ù. ÀÌ Á¦¾àÀº Header() ÇÔ¼ö¿Í °°Àº Á¦¾àÀ¸·Î º¸¸é µÈ´Ù. ´ç½ÅÀÌ º¸³»ÁØ ¸ðµç cookie´Â ÀÚµ¿ÀûÀ¸·Î GETÀ̳ª POST ¹æ½Ä µ¥ÀÌÅÍ¿Í °°Àº PHP º¯¼ö·Î º¯È¯µÈ´Ù.

¸¸¾à ¿©·¯ºÐÀÌ µ¿ÀÏÇÑ cookie¿¡ ¿©·¯ °ªÀ» ÀúÀåÇÏ°í ½Í´Ù¸é CookieÀ̸§¿¡ []¸¦ ´õÇÏ¸é µÈ´Ù. ¿¹¸¦ µé¾î :

  1 
  2 SetCookie ("MyCookie[]", "Testing", time()+3600);
  3      

ÄíŰ´Â »õ·Î ¼³Á¤Çϸé path³ª µµ¸ÞÀÎÀÌ ´Ù¸£Áö ¾Ê´Â ÇÑ ÀÌÀüÀÇ Äí۸¦ µ¤¾î¾²°Ô µÈ´Ù. ±×·¯¹Ç·Î ¼îÇΠīƮ °°Àº ÀÀ¿ë ÇÁ·Î±×·¥¿¡¼­´Â Ä«¿îÅ͸¦ À¯ÁöÇϰí, À̰ÍÀ» ±âÁØÀ¸·Î Cookie¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ÁÁ´Ù. ¿¹ :

Example 7-3. SetCookie Example

  1 
  2 $Count++;
  3 SetCookie ("Count", $Count, time()+3600);
  4 SetCookie ("Cart[$Count]", $item, time()+3600);
  5      

 


ȯ°æ º¯¼ö (Environment variables)

PHP´Â ÀÚµ¿ÀûÀ¸·Î ȯ°æ º¯¼öµéÀ» ÀϹÝÀûÀÎ PHP º¯¼ö·Î ¸¸µç´Ù.

  1 
  2 echo $HOME;  /* Shows the HOME environment variable, if set. */
  3       

GET, POST and Cookie ¸ÞÄ«´ÏÁòÀ» ÅëÇØ¼­ Á¤º¸°¡ µé¾î ¿Â Á¤º¸·ÎºÎÅÍ ÀÚµ¿ÀûÀ¸·Î PHP º¯¼ö°¡ »ý±â¹Ç·Î, ÀÌ ¹æ¹ýÀº ¶§¶§·Î ¿Ã¹Ù¸¥ ¹öÀüÀ» È®ÀÎÇϱâ À§ÇØ È¯°æÀ¸·ÎºÎÅÍ º¯¼ö¸¦ ÀÐ¾î µéÀ̱⿡ °¡Àå ÁÁ´Ù. À̸¦ À§ÇØ getenv() ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ´Ù. ¿©·¯ºÐÀº ȯ°æ º¯¼ö¸¦ ¼³Á¤Çϱâ À§ÇØ putenv() ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ´Ù.


¿ÜºÎ º¯¼ö¸í¿¡ ÀÖ´Â '.' (Dots in incoming variable names)

ÀϹÝÀûÀ¸·Î PHP´Â º¯¼ö¸¦ ½ºÅ©¸³Æ®·Î °¡Á®¿Ã ¶§ º¯¼ö¸íÀ» ¹Ù²ÙÁö ¾Ê´Â´Ù. ±×·¯³ª, PHPÀÇ º¯¼ö¸í¿¡´Â '.' (Á¡)À» »ç¿ëÇÒ ¼ö ¾ø´Ù. ´ÙÀ½°ú °°Àº °æ¿ì¸¦ º¸ÀÚ. :
  1 
  2 $varname.ext;  /* invalid variable name */
  3      

À§ÀÇ °æ¿ì ÆÄ¼­´Â $varnameÀ̶ó´Â º¯¼ö¿Í, ¿¬°á ¿¬»êÀÚ, 'ext'(µû¿ÈÇ¥°¡ ¾ø´Â °æ¿ì ±×°ÍÀÌ ¾î¶² ¾Ë·ÁÁø Ű³ª ¿¹¾à¾î°¡ ¾Æ´Ï¸é ¹®ÀÚ¿­·Î Ãë±ÞµÈ´Ù.)·Î ÇØ¼®ÇÑ´Ù. µû¶ó¼­ À̰ÍÀº ¿ì¸®°¡ ¿øÇÏ´Â °á°ú°¡ ¾Æ´Ï´Ù.

À§¿Í °°Àº ÀÌÀ¯·Î PHP´Â ¿ÜºÎ¿¡¼­ ºÒ·¯µéÀÎ º¯¼öÀÇ À̸§¿¡ '.'ÀÌ ÀÖÀ¸¸é '_'(¹ØÁÙ)·Î ¹Ù²Ù¾î ÀоîµéÀδÙ.


º¯¼öÀÇ Type ÆÇ´Ü (Determining variable types)

PHP°¡ º¯¼öÀÇ typeÀ» Á¤Çϰí (ÀϹÝÀûÀ¸·Î) ÇÊ¿äÇÑ °æ¿ì¿¡´Â ±× typeÀ» ¹Ù²Ù¹Ç·Î, ƯÁ¤ ½ÃÁ¡¿¡ ±× º¯¼ö ¾î¶² typeÀÎÁö´Â ½±°Ô ¾Ë ¼ö ¾ø´Ù. PHP´Â º¯¼öÀÇ typeÀ» ¾Ë¾Æº¸±â À§ÇØ ¿©·¯°³ÀÇ ÇÔ¼ö¸¦ °¡Áö°í ÀÖ´Ù. gettype(), is_long(), is_double(), is_string(), is_array(), and is_object()°¡ ±×°ÍµéÀÌ´Ù.


Chapter 8. »ó¼ö(Constants)

PHP´Â ¾à°£ÀÇ ±âº»ÀûÀÎ »ó¼öµéÀ» Á¦°øÇϰí, ½ÇÇà½Ã »ó¼ö¸¦ ¼³Á¤ÇÒ ¼ö ÀÖ´Â ¸ÞÄ«´ÏÁòÀ» Áö¿øÇÑ´Ù. »ó¼ö´Â º¯¼ö¿Í ºñ½ÁÇÏ´Ù. ±×·¯³ª define()ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ¼±¾ðÇÑ´Ù´Â °Í°ú ³ªÁß¿¡ ´Ù¸¥ °ªÀ¸·Î ¹Ù²Ü ¼ö ¾ø´Ù´Â Á¡ÀÌ Â÷À̰¡ ÀÖ´Ù.

¹Ì¸® ÁöÁ¤µÈ »ó¼ö´Â ´ÙÀ½°ú °°´Ù.

__FILE__
ÇöÀç ó¸®ÁßÀÎ ½ºÅ©¸³Æ®ÀÇ ÆÄÀϸí. ÇöÀç ÆÄÀÏÀÌ include³ª require·Î Æ÷ÇÔµÈ ÆÄÀÏÀ̶ó¸é, includeÇÔ¼öµîÀ» È£ÃâÇÑ ºÎ¸ð ÆÄÀÏÀÌ ¾Æ´Ñ, Æ÷ÇÔµÈ ÆÄÀÏÀÇ À̸§À» °¡Áø´Ù.
 
__LINE__
ÇöÀç ó¸®ÁßÀÎ ¸í·ÉÀÇ ½ºÅ©¸³Æ®³»¿¡¼­ÀÇ ¶óÀÎ ¹øÈ£. ÇöÀç ÆÄÀÏÀÌ include³ª require·Î Æ÷ÇÔµÈ ÆÄÀÏÀ̶ó¸é, includeÇÔ¼öµîÀ» È£ÃâÇÑ ºÎ¸ð ÆÄÀÏÀÌ ¾Æ´Ñ, Æ÷ÇÔµÈ ÆÄÀϳ»¿¡¼­ÀÇ ¶óÀÎ ¹øÈ£¸¦ °¡Áø´Ù.
 
PHP_VERSION
ÇöÀç »ç¿ëÁßÀÎ PHP ÆÄ¼­ÀÇ ¹öÀü. (¿¹ : '3.0.8-dev')
 
PHP_OS
PHP ÆÄ¼­°¡ ½ÇÇàµÇ°í ÀÖÀÀ OSÀÇ À̸§. (¿¹ : 'Linux')
 
TRUE
Âü(TRUE) °ª
 
FALSE
°ÅÁþ(FALSE) °ª
 
E_ERROR
¹®¹ý ¿À·ù°¡ ¾Æ´Ñ º¹±¸°¡ ºÒ°¡´ÉÇÑ ¿¡·¯¸¦ Ç¥½ÃÇÑ´Ù.
 
E_WARNING
PHP°¡ ¾î¶² °è¼Ó ¼öÇà °¡´ÉÇÑ ¿À·ù¸¦ °¨Áö ÇßÀ½À» Ç¥½ÃÇÑ´Ù. ¿¹¸¦µé¾î ereg()¿¡ regexp°¡ À߸øµÈ °æ¿ì µîÀÌ´Ù.
 
E_PARSE
ÆÄ¼­°¡ ½ºÅ©¸³Æ® ÆÄÀÏ¿¡¼­ ¹®¹ýÀûÀ¸·Î À߸øµÈ ¸í·ÉÀ» ¸¸³­ °æ¿ìÀÌ´Ù. º¹±¸´Â ºÒ°¡´ÉÇÏ´Ù.
 
E_NOTICE
¿¡·¯´Â ¾Æ´ÏÁö¸¸ ¾î¶² ¾Ë·ÁÁú »çÇ×ÀÌ ÀÖÀ½À» ³ªÅ¸³½´Ù. ½ÇÇàÀº °è¼ÓµÈ´Ù. ¿¹¸¦µé¾î hash À妽º¿¡ µû¿ÈÇ¥°¡ ¾ø´Â ¹®ÀÚ¿­ÀÌ »ç¿ëµÇ¾ú´Ù´øÁö, ÀÌÀü¿¡ ¼±¾ðµÇÁö ¾ÊÀº º¯¼öÀÇ °ªÀ» Àд´ٴøÁö ÇÏ´Â °æ¿ìÀÌ´Ù.

E_* »ó¼ö´Â ´ë°³ error_reporting() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© reporting ·¹º§À» Á¤ÇÒ ¶§ ÈçÈ÷ »ç¿ëµÈ´Ù.

¶ÇÇÑ ¿©·¯ºÐÀº define()ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© Ãß°¡ÀûÀÎ »ó¼ö¸¦ Á¤ÀÇÇÒ ¼ö ÀÖ´Ù.

ÁÖÀÇÇÒ Á¡Àº »ó¼ö´Â C¿¡¼­ÀÇ macro °ªÀº °ÍÀÌ ¾Æ´Ï´Ù. ´ÜÁö scalar °ªÀ» °¡Áú ¼ö ÀÖÀ» »ÓÀÌ´Ù.

Example 8-1. Defining Constants

  1 
  2 <?php
  3 define("CONSTANT", "Hello world.");
  4 echo CONSTANT; // outputs "Hello world."
  5 ?>
  6      

Example 8-2. Using __FILE__ and __LINE__

  1 
  2 <?php
  3 function report_error($file, $line, $message) {
  4     echo "An error occured in $file on line $line: $message.";
  5 }
  6 
  7 report_error(__FILE__,__LINE__, "Something went wrong!");
  8 ?>
  9      

 


Chapter 9. Ç¥Çö½Ä (Expressions)

Ç¥Çö½ÄÀº PHP¿¡¼­ ¸Å¿ì Áß¿äÇÑ ³»¿ëÀÌ´Ù. PHP¿¡¼­ ¿©·¯ºÐÀÌ ÀÛ¼ºÇÏ´Â °ÅÀÇ ¸ðµç °ÍÀº Ç¥Çö½ÄÀÌ´Ù. °£´ÜÈ÷ Ç¥Çö½ÄÀÇ Á¤ÀǸ¦ ¾ö¹ÐÇÏ°Ô ¸»ÇÑ´Ù¸é "°ªÀ» °¡Áö°í ÀÖ´Â ¸ðµç °Í"("anything that has a value")ÀÌ´Ù.

°£´ÜÇÑ ¿¹Á¦·Î "$a = 5"¿Í °°Àº °ÍÀÌ ÀÖ´Ù. À̰ÍÀº 5¶ó´Â °ªÀ» $a¶ó´Â º¯¼ö¿¡ ´ëÀÔÇÏ´Â ¹®ÀåÀÌ´Ù. ¿©±â¼­ 5¶ó´Â Ç¥Çö½ÄÀº 5ÀÇ °ªÀ̶ó´Â Àǹ̰¡ µÈ´Ù. À§ÀÇ ¹®Àå ´ÙÀ½¿¡ "$b = $a"¶ó´Â ¹®ÀåÀÌ ÀÖ´Ù¸é ¿©±â¼­ $a¶ó´Â Ç¥Çö½ÄÀº ±× º¯¼ö°¡ °¡Áø 5¶ó´Â °ªÀ» Ç¥ÇöÇÑ´Ù.

Á¶±Ý º¹ÀâÇÑ °æ¿ì´Â ÇÔ¼öÀÌ´Ù. ´ÙÀ½ ÇÔ¼ö¸¦ º¸ÀÚ. :

  1 
  2 function foo () {
  3     return 5;
  4 }
  5      

$c = 5¶ó´Â ¹®Àå¿¡¼­ foo()´Â 5¸¦ µ¹·ÁÁÙ °ÍÀ̱⠶§¹®¿¡ 'foo()'¶ó´Â Ç¥Çö½ÄÀº 5¸¦ Ç¥ÇöÇÑ´Ù°í ¸»ÇÒ ¼ö ÀÖ´Ù.

PHP´Â Á¤¼ö°ª(integer values), ½Ç¼ö°ª(floating point values), ¹®ÀÚ¿­(string values)ÀÇ 3°¡Áö ½ºÄ®¶ó typeÀ» °¡Áö°í ÀÖ´Ù. (½ºÄ®¶ó °ªÀ̶õ ´õ ÀÌ»ó ÀÛÀº °ªÀ¸·Î Âɰ³Áú ¼ö ¾ø´Â °ªÀ» ¸»ÇÑ´Ù.) ¶ÇÇÑ PHP´Â ¹è¿­(array)°ú °´Ã¼(object)ÀÇ 2°¡Áö È¥ÇÕ(composite, non-scalar) typeÀ» Áö¿øÇÑ´Ù. ÀÌ typeµéÀº º¯¼ö¿¡ °ªÀ» ÇÒ´çÇÒ ¼ö ÀÖ°í, ÇÔ¼ö¿¡ ÀÇÇØ °ªÀ» µ¹·ÁÁÙ ¼ö ÀÖ´Ù.

¿©±â±îÁö´Â PHP/FI 2 »ç¿ëÀÚµéÀº ¾Æ¹«°Íµµ ¹Ù²îÁö ¾Ê¾Ò´Ù°í ´À³¥ °ÍÀÌ´Ù. PHP´Â °ÅÀÇ ¸ðµç °ÍÀÌ Ç¥Çö½ÄÀ¸·Î Ç¥ÇöµÈ´Ù´Â Á¡¿¡¼­, Ç¥Çö Á᫐ ¾ð¾î (expression-oriented language)¶ó°í ºÒ¸± ¼ö ÀÖ´Ù. Ç¥Çö Áß½ÉÀÇ ÁÁÀº ¿¹´Â ´ëÀÔ¹®ÀÌ´Ù. PHP¿¡¼­´Â C¿Í °°ÀÌ ´ëÀÔ¹®µµ ÇϳªÀÇ Ç¥Çö½ÄÀ¸·Î º»´Ù. µû¶ó¼­ '$a=5; $b=5;'´Â '$a = ($b=5);' ȤÀº '$a = $b = 5;'·Î Ç¥Çö °¡´ÉÇÏ´Ù.

Ç¥Çö Áß½ÉÀÇ ´Ù¸¥ ÁÁÀº ¿¹·Î´Â ++¿Í --ÀÌ´Ù. In PHP/FI 2¿¡¼­´Â '$a++'¿Í °°Àº ¹®ÀåÀº ¾Æ¹« °ªµµ °¡ÁöÁö ¾Ê¾Ò´Ù. Áï, Ç¥Çö½ÄÀÌ ¾Æ´Ï¾ú´Ù. µû¶ó¼­ ÀÌ °ªÀ» ´Ù¸¥ °÷¿¡ ´ëÀÔÇÏ´Â °ÍÀº ºÒ°¡´ÉÇß´Ù. ±×·¯³ª PHP 3¿¡¼­´Â À̰ÍÀÌ °¡´ÉÇØÁ³´Ù. C¿¡¼­¿Í °°ÀÌ ++/--¸¦ »ç¿ëÇÏ´Â ¹æ¹ý¿¡´Â ¾Õ¿¡ ºÙÀÌ´Â °Í°ú µÚ¿¡ ºÙÀÌ´Â °Í µÎ°¡Áö°¡ ÀÖ´Ù. µÑ ¸ðµÎ º¯¼öÀÇ °ªÀÌ Áõ°¡µÈ´Ù´Â Á¡Àº °°À¸³ª, '++$variable'Àº ±× º¯¼öÀÇ Áõ°¡µÈ °ªÀÌ Ç¥Çö½ÄÀÇ °ªÀÌ µÇ°í, '$variable++'´Â º¯¼öÀÇ Áõ°¡µÇ±â ÀüÀÇ °ªÀÌ Ç¥Çö½ÄÀÇ °ªÀÌ µÈ´Ù.

ºñ±³ Ç¥Çö½ÄÀº 0À̳ª 1ÀÇ °ªÀ» °¡Áø´Ù. 0Àº ºÎÁ¤(FALSE)À» 1Àº ±àÁ¤(TRUE)¸¦ ³ªÅ¸³½´Ù. PHP´Â > (bigger than), >= (bigger than or equal to), == (equal),< (smaller than), <= (smaller than or equal to)¸¦ Áö¿øÇÑ´Ù.

¸¶Áö¸· ¿¹´Â °áÇÕµÈ ¿¬»ê-´ëÀÔ Ç¥Çö½Ä(combined operator-assignment expression)ÀÌ´Ù. ¹¹ º¹ÀâÇÑ ¾ê±â´Â ¾Æ´Ï°í '$a = $a + 3'Àº Ç¥Çö½ÄÀ» '$a += 3'À¸·Î Ç¥ÇöÇÒ ¼ö ÀÖ´Â °ÍÀÌ´Ù. -=, *=, /=, .= µîµµ »ç¿ëÇÒ ¼ö ÀÖ´Ù.

´ÙÀ½¿¹¸¦ º¸¸é µµ¿òÀÌ µÉ °ÍÀÌ´Ù. :

 

  1 
  2 function double($i) {
  3     return $i*2;
  4 }
  5 $b = $a = 5;          /* $a¿Í $b ¿¡ 5 ´ëÀÔ */
  6 $c = $a++;            /* post-increment, $c ¿¡´Â $aÀÇ ¿ø·¡ °ªÀÎ 5°¡ ´ëÀԵǰí $a´Â 6ÀÌ µÈ´Ù */
  7 $e = $d = ++$b;       /* pre-increment, $d¿Í $e´Â Áõ°¡µÈ $bÀÇ °ª 6ÀÌ ´ëÀԵȴÙ. */
  8  
  9 /* ¿©±âºÎÅÍ $d¿Í $eÀÇ °ªÀº 6ÀÌ´Ù. */
 10 $f = double($d++);    /* $f´Â $d°¡ Áõ°¡µÇ±â ÀüÀÇ °ªÀÎ 6À» µÎ ¹èÇÑ °ªÀ» °¡Áø´Ù. 2*6 = 12 */
 11 $g = double($++e);    /* $g´Â $e°¡ Áõ°¡µÈ ÈÄÀÇ °ªÀÎ 7À» µÎ¹èÇѰªÀ» °¡Áø´Ù. 2*7 = 14 */
 12 $h = $g += 10;        /* $g´Â 14¿¡ 10À» ´õÇØ 24ÀÇ °ªÀ» °¡Áø ÈÄ ±× °ªÀ» $h¿¡ ´ëÀÔÇÑ´Ù. µÑ´Ù 24 */
 13 

±×·¯³ª, ÇϳªÀÇ Ç¥Çö½ÄÀÌ ÇϳªÀÇ ¹®ÀåÀº ¾Æ´Ï´Ù. Ç¥Çö½ÄÀÌ ¼¼¹ÌÄÝ·Ð ';'À¸·Î ³¡³ª¾ß ÇϳªÀÇ ¹®ÀåÀÌ µÇ´Â °ÍÀÌ´Ù. Áï '$b=$a=5;'¿¡¼­ $a=5´Â Ç¥Çö½ÄÀÌÁö¸¸ ¹®ÀåÀº ¾Æ´Ï´Ù.

PHP¿¡¼­ Âü/°ÅÁþÀÇ ÆÇ´ÜÀº Perl°ú ºñ½ÁÇÏ´Ù. 0ÀÌ ¾Æ´Ñ ¼ýÀÚ´Â ¸ðµÎ TRUEÀ̰í, 0Àº FALSEÀÌ´Ù. ºó ¹®ÀÚ¿­À̳ª ¹®ÀÚ¿­ "0"Àº FALSEÀÌ´Ù. ´Ù¸¥ ¸ðµç ¹®ÀÚ¿­Àº TRUEÀÌ´Ù. ¹è¿­À̳ª °´Ã¼´Â ¿ø¼Ò°¡ Çϳªµµ ¾ø´Ù¸é FALSE¸¦ ÀǹÌÇϰí, ³ª¸ÓÁöÀÇ °æ¿ì´Â TRUEÀÌ´Ù.

¾ÕÀ¸·Î ÀÌ ¸Å´º¾ó¿¡¼­ 'expr'À̶ó°í ¾²¿©Áø ºÎºÐÀº PHPÀÇ ¿Ã¹Ù¸¥ Ç¥Çö½ÄÀ̶ó´Â ÀǹÌÀÌ´Ù.


Chapter 10. ¿¬»êÀÚ (Operators)


»ê¼ú ¿¬»êÀÚ (Arithmetic Operators)

Çб³¿¡¼­ ¹è¿î »ê¼ú ¿¬»ê(°¡°¨½ÂÁ¦)À» ±â¾ïÇϴ°¡? ÀÌ »ê¼ú ¿¬»êÀÚ´Â ±×°Íµéó·³ µ¿ÀÛÇÑ´Ù.

Table 10-1. Arithmetic Operators

¿¹

À̸§

°á°ú

$a + $b

µ¡¼À(Addition)

$a¿Í $bÀÇ ÇÕ.

$a - $b

»¬¼À(Subtraction)

$a¿¡¼­ $b¸¦ »« °ª.

$a * $b

°ö¼À(Multiplication)

$a¿Í $bÀÇ °ö.

$a / $b

³ª´°¼À(Division)

$a¿¡¼­ $b¸¦ ³ª´« °ª(Ȥ Àº ¸ò).

$a % $b

³ª¸ÓÁö(Modulus)

$a¿¡¼­ $b¸¦ ³ª´« ³ª¸ÓÁö.


´ëÀÔ ¿¬»êÀÚ (Assignment Operators)

±âº» ´ëÀÔ ¿¬»êÀÚ´Â "="ÀÌ´Ù. ÀÌ ¿¬»êÀÚ¸¦ óÀ½ º¸¾ÒÀ» ¶§´Â "°°´Ù"¶ó´Â ¿¬»êÀÚ·Î »ý°¢Çϱ⠽±Áö¸¸ ÀüÇô ¾Æ´Ï´Ù. À̰ÍÀÇ Àǹ̴ ¿À¸¥ÂÊÀÇ Ç¥Çö½ÄÀ» °è»êÇÏ¿© ±× °ªÀ» ¿ÞÂÊ¿¡ ÀÖ´Â ÇÇ¿¬»êÀÚÀÇ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù´Â ÀǹÌÀÌ´Ù. (À̰ÍÀ» "gets set to"¶ó°í ÇÑ´Ù.)

´ëÀÔ ¿¬»êÀÚÀÇ °ªÀº ¿ÞÂÊÀ¸·Î ´ëÀÔµÈ °ªÀÌ´Ù. Áï, "$a = 3"ÀÇ °ªÀº 3ÀÌ µÈ´Ù. À̰ÍÀº ¿©·¯ºÐ¿¡°Ô ¾à°£ÀÇ Æ®¸¯ÀÌ °¡´ÉÇϵµ·ÏÇÑ´Ù.

  1 
  2 $a = ($b = 4) + 5; // $a´Â 9, $b´Â 4ÀÇ °ªÀ» °¡Áø´Ù.
  3 

±âº»ÀûÀÎ ´ëÀÔ ¿¬»êÀÚ ¿Ü¿¡ ¸ðµç Bit ´ÜÀ§ ¿¬»êÀÚ, »ê¼ú ¿¬»êÀÚ¿Í °áÇÕÇÑ º¹ÇÕ ´ëÀÔ ¿¬»êÀÚµµ ÀÖ´Ù. °áÇÕµÈ ¿¬»êÀڴ ǥÇö½Ä¿¡¼­ ÇØ´ç ¿¬»êÀ¸·Î »ç¿ëµÇ°í, ±× ¿¬»ê °ªÀ» ¿ÞÂÊ¿¡ ÀÖ´Â ÇÇ¿¬»êÀÚ¿¡ ´ëÀÔÇÑ´Ù. ¿¹¸¦ µé¾î :

  1 
  2 $a = 3;
  3 $a += 5; // $a´Â 8ÀÌ´Ù. $a = $a + 5; ¿Í µ¿ÀÏÇÏ´Ù.
  4 $b = "Hello ";
  5 $b .= "There!"; // $b´Â "Hello There!"°¡ µÈ´Ù. $b = $b . "There!";¿Í °°´Ù.
  6 

 


Bit ´ÜÀ§ ¿¬»êÀÚ (Bitwise Operators)

ºñÆ® ´ÜÀ§ ¿¬»êÀÚ´Â Á¤¼öÀÇ °³º° ºñÆ®ÀÇ °ªÀ» on, off ÇÒ ¼ö ÀÖ´Ù.

Table 10-2. Bitwise Operators

example

name

result

$a & $b

And

$a¿Í $b°¡ ¸ðµÎ 1ÀÎ ºñÆ®¸¸ 1ÀÌ µÈ´Ù.

$a | $b

Or

$a¿Í $bÁß Çϳª¶óµµ 1ÀÎ ºñÆ®´Â 1ÀÌ µÈ´Ù.

$a ^ $b

Xor

$a¿Í $bÁß Çϳª´Â 1À̰í, ´Ù¸¥ Çϳª´Â 0ÀÎ ºñÆ®¸¸ 1À̵ǰí, ³ª¸ÓÁö´Â 0ÀÌ µÈ´Ù.

~ $a

Not

$a¿¡¼­ 1ÀÎ ºñÆ®´Â 0À¸·Î, 0ÀÎ ºñÆ®´Â 1·Î µÈ´Ù.

$a << $b

Shift left

$aÀÇ ºñÆ®µéÀ» $b step ¸¸Å­ ¿ÞÂÊÀ¸·Î shift ÇÑ´Ù. (ÇÑ stepÀº 2¸¦ ÇÑ ¹ø °öÇÏ´Â ¸¸Å­ÀÇ È¿°ú°¡ ÀÖ´Ù.)

$a >> $b

Shift right

$aÀÇ ºñÆ®µéÀ» $b step ¸¸Å­ ¿À¸¥À¸·Î shift ÇÑ´Ù. (ÇÑ stepÀº 2¸¦ ÇÑ ¹ø ³ª´©´Â ¸¸Å­ÀÇ È¿°ú°¡ ÀÖ´Ù.)


ºñ±³ ¿¬»êÀÚ (Comparison Operators)

ºñ±³ ¿¬»êÀÚ´Â À̸§¿¡¼­ ¾Ë ¼ö ÀÖµíÀÌ µÎ °³ÀÇ °ªÀ» ºñ±³ÇÏ´Â ¿¬»êÀÚÀÌ´Ù.

Table 10-4. Comparson Operators

example

name

result

$a == $b

Equal

$a¿Í $b°¡ °°À¸¸é true.

$a === $b

Identical

$a¿Í $b°¡ °°À¸¸é true. $a¿Í $bÀÇ type±îÁö µ¿ÀÏÇØ¾ß ÇÑ´Ù. (PHP4 only)

$a != $b

Not equal

$a¿Í $b°¡ ´Ù¸£¸é true.

$a < $b

Less than

$a°¡ $bº¸´Ù ÀÛÀ¸¸é true.

$a > $b

Greater than

$a°¡ $bº¸´Ù Å©¸é true.

$a <= $b

Less than or equal to

$a°¡ $bº¸´Ù À۰ųª °°À¸¸é true.

$a >= $b

Greater than or equal to

$a°¡ $bº¸´Ù Å©°Å³ª °°À¸¸é true.

¶Ç´Ù¸¥ Á¶°Ç ¿¬»êÀÚ·Î C³ª ´Ù¸¥ ¾ð¾î¿¡ ÀÖ´Â "?:" ¿¬»êÀÚ°¡ ÀÖ´Ù.

  1 
  2 (expr1) ? (expr2) : (expr3);
  3 

ÀÌ Ç¥Çö½ÄÀº expr1ÀÇ °á°ú°¡  Âü¿©¸é expr2¸¦ ¹ÝȯÇϰí, °ÅÁþÀ̸é expr3¸¦ ¹ÝȯÇÑ´Ù.


¿À·ù Á¦¾î ¿¬»êÀÚ (Error control Operators)

PHP´Â @(at Ç¥½Ã)À̶ó´Â ÇÑ °³ÀÇ ¿À·ù Á¦¾î ¿¬»êÀÚ¸¦ Á¦°øÇÑ´Ù. PHPÀÇ Ç¥Çö½Ä ¾Õ¿¡ ÀÌ Ç¥½Ã°¡ ºÙÀ¸¸é, ÇØ´ç Ç¥Çö½Ä¿¡¼­ ¹ß»ýÇÑ ¸ðµç ¿¡·¯ ¸Þ½ÃÁö°¡ ¹«½ÃµÈ´Ù.

¸¸¾à track_errors ±â´ÉÀÌ È°¼ºÈ­ µÇ¾î ÀÖ´Ù¸é, ÇØ´ç Ç¥Çö½Ä¿¡¼­ ¹ß»ýÇÑ ¸ðµç ¿¡·¯ ¸Þ½ÃÁö´Â $php_errormsg ¶ó´Â Àü¿ª º¯¼ö¿¡ ÀúÀåµÉ °ÍÀÌ´Ù. ÀÌ º¯¼öÀÇ °ªÀº ¸Å¹ø ¿¡·¯°¡ ¹ß»ýÇÒ ¶§¸¶´Ù »õ·Î ¼³Á¤µÈ´Ù. µû¶ó¼­ ¸¸¾à ¿©·¯ºÐÀÌ ÀÌ º¯¼ö¸¦ »ç¿ëÇÏ·Á¸é ¿¡·¯°¡ ¹ß»ýÇÑ Á÷ÈÄ¿¡ ÃÖ´ëÇÑ »¡¸® »ç¿ëÇÏ¿©¾ß ÇÑ´Ù.

  1 
  2 <?php
  3 /* Intentional SQL error (extra quote): */
  4 $res = @mysql_query( "select name, code from 'namelist" ) or
  5    die( "Query failed: error was '$php_errormsg'" );
  6 ?>
  7      

See also error_reporting().


½ÇÇà ¿¬»êÀÚ (Execution Operators)

PHP´Â ÇÑ °³ÀÇ ½ÇÇà ¿¬»êÀÚ¸¦ Á¦°øÇÑ´Ù. (``) ÀÏ¹Ý ÀÛÀº µû¿ÈÇ¥°¡ ¾Æ´ÔÀ» ÁÖÀÇÇÏÀÚ! PHP´Â ÀÌ »çÀÌ¿¡ ÀÖ´Â ¸í·ÉÀ» shell ¸í·É¾î·Î ½ÇÇàÇÏ°í ±× °á°ú¸¦ ¹ÝȯÇÑ´Ù. (½ÇÇà °á°ú¸¦ ´Ü¼øÈ÷ Ãâ·ÂÇÏ´Â °ÍÀÌ ¾Æ´Ï°í, º¯È¯ÇÏ¿© º¯¼ö¿¡ ÀúÀåÇÒ ¼öµµ ÀÖ´Ù.)

  1 
  2 $output = `ls -al`;
  3 echo "<pre>$output</pre>";
  4 	 

See also system(), passthru(), exec(), popen(), and escapeshellcmd().


Áõ°¡/°¨¼Ò ¿¬»êÀÚ (Incrementing/Decrementing Operators)

PHP´Â C ÇüÅÂÀÇ ¾Õ, µÚ¿¡ ºÙ´Â Áõ°¡³ª °¨¼Ò ¿¬»êÀÚ¸¦ Á¦°øÇÑ´Ù.

Table 10-4. Increment/decrement Operators

example name effect
++$a Pre-increment $a ¸¦ 1 Áõ°¡½ÃŲ ÈÄ, $a¸¦ ¹ÝȯÇÑ´Ù.
$a++ Post-increment $a¸¦ ¹ÝȯÇÑ ÈÄ,$a ¸¦ 1 Áõ°¡½ÃŲ´Ù.
--$a Pre-decrement $a ¸¦ 1 °¨°¡½ÃŲ ÈÄ, $a¸¦ ¹ÝȯÇÑ´Ù.
$a-- Post-decrement $a¸¦ ¹ÝȯÇÑ ÈÄ,$a ¸¦ 1 °¨¼Ò½ÃŲ´Ù.

¿©±â °£´ÜÇÑ ¿¹Á¦°¡ ÀÖ´Ù. :

  1 
  2 <?php
  3 echo "<h3>Postincrement</h3>";
  4 $a = 5;
  5 echo "Should be 5: " . $a++ . "<br>\n";
  6 echo "Should be 6: " . $a . "<br>\n";
  7 
  8 echo "<h3>Preincrement</h3>";
  9 $a = 5;
 10 echo "Should be 6: " . ++$a . "<br>\n";
 11 echo "Should be 6: " . $a . "<br>\n";
 12 
 13 echo "<h3>Postdecrement</h3>";
 14 $a = 5;
 15 echo "Should be 5: " . $a-- . "<br>\n";
 16 echo "Should be 4: " . $a . "<br>\n";
 17 
 18 echo "<h3>Predecrement</h3>";
 19 $a = 5;
 20 echo "Should be 4: " . --$a . "<br>\n";
 21 echo "Should be 4: " . $a . "<br>\n";
 22 ?>	  
 23 	 

 


Logical Operators

Table 10-3. Logical Operators

example

name

result

$a and $b

And

$a¿Í $b°¡ ¸ðµÎ true À̸é true

$a or $b

Or

$a¿Í $bÁß Çϳª¶óµµ trueÀ̸é true

$a xor $b

Xor

$a¿Í $bÁß Çϳª¸¸ trueÀ̾î¾ß true

! $a

Not

$a°¡ true°¡ ¾Æ´Ï¸é true

$a && $b

And

$a¿Í $b°¡ ¸ðµÎ true À̸é true

$a || $b

Or

$a¿Í $bÁß Çϳª¶óµµ trueÀ̸é true

"and"¿Í "or" ¿¬»êÀÚ°¡ µÎ°¡ÁöÀÇ ´Ù¸¥ ÇüŸ¦ °¡Áö°í ÀÖ´Â ÀÌÀ¯´Â ÀÌ ¿¬»êÀÚµéÀÌ ¼­·Î ´Ù¸¥ ¿ì¼±¼øÀ§¸¦ °¡Áö°í Àֱ⠶§¹®ÀÌ´Ù. (¾Æ·¡¸¦ º¸¶ó.)


¿¬»êÀÚ ¿ì¼± ¼øÀ§ (Precedence)

¿¬»êÀÚµéÀÇ ¿ì¼±¼øÀ§´Â µÎ °³ÀÇ Ç¥Çö½ÄÁß ¾î´À°ÍÀÌ ´õ ´Ü´ÜÈ÷ ¹­¿© Àִ°¡¸¦ ¸í±âÇÑ´Ù. ¿¹¸¦µé¾î 1 + 5 * 3Àº 16À» ¹ÝȯÇÏÁö 18À» ¹ÝȯÇÏÁö ¾Ê´Â´Ù. ¿Ö³ÄÇÏ¸é °öÇϱâ("*")¿¬»êÀÚ°¡ ´õÇϱâ("+")¿¬»êÀÚº¸´Ù ¿ì¼±¼øÀ§°¡ ³ô±â ¶§¹®ÀÌ´Ù.

´ÙÀ½ Ç¥´Â ¿¬»êÀÚÀÇ ¿ì¼±¼øÀ§¸¦ ³ªÅ¸³½´Ù °¡Àå À§¿¡ ÀÖ´Â ¿¬»êÀÚÀÇ ¿ì¼±¼øÀ§°¡ °¡Àå ³·´Ù.

Table 10-6. Operator Precedence

Associativity Operators
left ,
left or
left xor
left and
right print
left = += -= *= /= .= %= &= |= ^= ~= <<= >>=
left ? :
left ||
left &&
left |
left ^
left &
non-associative == != ===
non-associative < <= > >=
left << >>
left + - .
left * / %
right ! ~ ++ -- (int) (double) (string) (array) (object) @
right [
non-associative new

 

¹®ÀÚ¿­ ¿¬»êÀÚ (String Operators)

¹®ÀÚ¿­ ¿¬»êÀÚ¿¡´Â µÎ°³°¡ ÀÖ´Ù. ù ¹øÂ°´Â ¿À´ÏÂʰú ¿À¸¥ÂÊÀÇ µÎ ¹®ÀÚ¿­À» ¿¬°áÇÏ´Â ¿¬°á(concatenation) ¿¬»êÀÚ (".") °¡ ÀÖ´Ù. µÎ ¹ø¤Š·Î´Â ¿¬°á ´ëÀÔ ¿¬»êÀÚ (".=") °¡ ÀÖ´Ù. ÀÌ¿¡ ´ëÇØ¼­´Â ´ëÀÔ¿¬»êÀÚ(Assugnment Operator) ºÎºÐÀ» ÀоÀÚ.

  1 
  2 $a = "Hello ";
  3 $b = $a . "World!"; // now $b contains "Hello World!"
  4 
  5 $a = "Hello ";
  6 $a .= "World!"; // now $a contains "Hello World!"
  7      
$a = "Hello ";
$b = $a . "World!"; // now $b = "Hello World!"


Chapter 11. Á¦¾î ±¸Á¶ (Control Structures)

¸ðµç PHP ½ºÅ©¸³Æ®´Â ÀÏ·ÃÀÇ ±¸¹®À¸·Î ÀÌ·ç¾î Áø´Ù. ÇϳªÀÇ ±¸¹®Àº ´ëÀÔ¹®ÀÌ µÉ ¼öµµ ÀÖ°í, ÇÔ¼ö È£Ãâ, ¹Ýº¹¹®, Á¶°Ç¹®ÀÌ µÉ ¼öµµ ÀÖÀ¸¸ç ½ÉÁö¾î´Â ¾Æ¹« ³»¿ëÀÌ ¾ø´Â ºó ¹®ÀåÀÏ ¼öµµ ÀÖ´Ù. ÇÑ ±¸¹®Àº ÀϹÝÀûÀ¸·Î ¼¼¹ÌÄÝ·Ð(;)À¸·Î ³¡³­´Ù. ¶ÇÇÑ ¿©·¯°³ÀÇ ±¸¹®À» Áß°ýÈ£({,})¸¦ »ç¿ëÇÏ¿© ÇϳªÀÇ ±×·ìÀ¸·Î ¸¸µé¾î »ç¿ëÇÒ ¼öµµ ÀÖ´Ù. ÀÌ ±¸¹®-±×·ìÀº ±× ±×·ìÀÇ ¸ðµç ±¸¹®µéÀÌ ÇϳªÀÇ ±¸¹®ÀÎ °Íó·³ ÀνĵȴÙ. ¿©±â¼­´Â ¿©·¯ °¡Áö ±¸¹®ÇüÅ¿¡ ´ëÇØ ¾Ë¾Æº»´Ù.


if

PHPÀÇ IF¹®Àº C¿Í ºñ½ÁÇÏ´Ù.

  1 
  2 if (expr)
  3     statement
  4      

exprÀ» Æò°¡ÇÏ¿© TRUEÀ̸é statement¸¦ ½ÇÇàÇÑ´Ù. FALSEÀÌ¸é ¹«½ÃÇÑ´Ù.

´ÙÀ½ ¿¹Á¦´Â $a°¡ $bº¸´Ù Å©¸é "a is bigger than b"¸¦ Ãâ·ÂÇÑ´Ù.

  1 
  2 if ($a > $b)
  3     print "a is bigger than b";
  4      

¿©·¯ ¹®ÀåÀ» ½ÇÇà½ÃŰ·Á¸é Áß°ýÈ£( { } )¸¦ »ç¿ëÇÏ¿© º¹¹®À¸·Î ¸¸µé¸éµÈ´Ù. :

  1 
  2 if ($a > $b) {
  3     print "a is bigger than b";
  4     $b = $a;
  5 }
  6      

 


else

ELSE´Â IF¹®ÀÇ Æò°¡½ÄÀÌ FALSEÀÏ °æ¿ì ½ÇÇàÇÏ´Â ¹®ÀåÀ» ÁöÁ¤ÇÑ´Ù. :

  1 
  2 if ($a > $b) {
  3     print "a is bigger than b";
  4 } else {
  5     print "a is NOT bigger than b";
  6 }
  7      

 


elseif

ELSEIF´Â ELSE¿Í IF¸¦ ÇÕÃijõÀº °Í°ú °°´Ù. :

  1 
  2 if ($a > $b) {
  3     print "a is bigger than b";
  4 } elseif ($a == $b) {
  5     print "a is equal to b";
  6 } else {
  7     print "a is smaller than b";
  8 }
  9      

ÇÑ IF¹®¿¡´Â ¿©·¯°³ÀÇ ELSEIF¹®ÀÌ ÀÖÀ» ¼ö ÀÖ´Ù. ELSEIF¹®Àº ¼ø¼­´ë·Î Æò°¡ÇÏ¿© TRUEÀÎ °÷À» ½ÇÇàÇÑ´Ù. Áï, ¾î¶² ELSEIF¹®ÀÌ ½ÇÇà µÇ·Á¸é IF¹®ÀÇ Æò°¡½Ä°ú ±× ¾ÕÀÇ ¸ðµç ELSEIF¹®ÀÇ Æò°¡½ÄÀÌ FALSEÀ̾î¾ß ÇÑ´Ù. À̰ÍÀº 'else if'¶ó°í µÎ °³ÀÇ ¹®ÀåÀ¸·Î ½áµµ µÈ´Ù(¹®¹ýÀûÀÎ Àǹ̴ ¾à°£ ´Ù¸£Áö¸¸).


Á¦¾î±¸Á¶ÀÇ ´Ù¸¥ Ç¥Çö (Alternative syntax for control structures)

PHP 3´Â Áß°ýÈ£({ })¸¦ ¾²´Â ´ë½Å IF(expr)µÚ¿¡ ÄÝ·Ð( : )À» Âï°í, Çϳª ÀÌ»óÀÇ ¹®ÀåÀ» ³ª¿­ÇÑ ÈÄ¿¡ ENDIF;·Î ³¡³»´Â ¹æ¹ýÀ» Á¦°øÇÑ´Ù. ÀÌ ¹æ¹ýÀº ƯÈ÷ IF¹® ¾È¿¡ HTML ºí·°À» »ðÀÔÇϴµ¥ À¯¿ëÇÏ°Ô »ç¿ëµÉ ¼ö ÀÖ´Ù. ´ÙÀ½ ¿¹¸¦ º¸ÀÚ. :

  1 
  2  <?php if ($a == 5): ?>
  3  A is equal to 5
  4  <?php endif; ?>
  5      

À§ÀÇ ¿¹¿¡¼­ "A = 5"¶ó´Â HTML ºí·ÏÀÌ IF¹® ¾È¿¡ »ç¿ëµÇ°í ÀÖ´Ù. À§ÀÇ HTML ºí·ÏÀº $a°¡ 5ÀÏ °æ¿ì¿¡¸¸ Ç¥½ÃµÈ´Ù.

´ÙÀ½°ú °°ÀÌ ELSE¿Í ELSEIF (expr)µµ »ç¿ëÇÒ ¼ö ÀÖ´Ù. :

  1 
  2 if ($a == 5):
  3     print "a equals 5";
  4     print "...";
  5 elseif ($a == 6):
  6     print "a equals 6";
  7     print "!!!";
  8 else:
  9     print "a is neither 5 nor 6";
 10 endif;
 11      

 


while

WHILE ·çÇÁ´Â PHP 3ÀÇ °¡Àå °£´ÜÇÑ ÇüÅÂÀÌ´Ù. À̰ÍÀº C¿Í µ¿ÀÏÇÏ°Ô ÀÛµ¿ÇÑ´Ù. ±âº» ÇüÅ´ ´ÙÀ½°ú °°´Ù. :

  1 
  2 while (expr) statement
  3      

IF¹®°ú ¸¶Âù°¡Áö·Î ´ÙÀ½°ú °°Àº ¹®Àå ÇüÅ·ΠÁß°ýÈ£( { } )¸¦ »ç¿ëÇÏÁö ¾Ê´Â ¹æ¹ýµµ ÀÖ´Ù. :.

  1 
  2 while (expr): statement ... endwhile;
  3      

´ÙÀ½µÎ°³ÀÇ ¿¹Á¦´Â µ¿ÀÏÇÑ ¿¹Á¦ÀÌ´Ù. 1ºÎÅÍ 10±îÁö Ãâ·ÂÇÑ´Ù.:

  1 
  2 /* example 1 */
  3 
  4 $i = 1;
  5 while ($i <= 10) {
  6     print $i++;  /* the printed value would be
  7                     $i before the increment
  8                     (post-increment) */
  9 }
 10  
 11 /* example 2 */
 12  
 13 $i = 1;
 14 while ($i <= 10):
 15     print $i;
 16     $i++;
 17 endwhile;
 18      

 


do..while

DO..WHILE ·çÇÁ´Â ºñ±³½ÄÀÌ ¾ÕÀÌ ¾Æ´Ñ ¸Ç µÚ¿¡ ÀÖ´Ù´Â Á¡À» Á¦¿ÜÇϸé WHILE ·çÇÁ¿Í ºñ½ÁÇÏ´Ù. µû¶ó¼­ WHILE Á¶°ÇÀýÀº DO ¹®ÀåÀÌ ½ÇÇàµÈ ÈÄ¿¡ Æò°¡µÇ¹Ç·Î, DO ÀÌÈÄÀÇ ¹®ÀåÀº ¹«Á¶°Ç ÇѹøÀº ½ÇÇàµÈ´Ù.

´ÙÀ½°ú °°Àº DO..WHILE ·çÇÁ¿¡¼­µµ ÇѹøÀº Ãâ·ÂÀÌ µÈ´Ù. :

  1 
  2 $i = 0;
  3 do {
  4    print $i;
  5 } while ($i>0);
  6      

 


for

FOR´Â PHPÀÇ °¡Àå º¹ÀâÇÑ ·çÇÁÀÌ´Ù. À̰ÍÀº C¿Í À¯»çÇÏ´Ù. FOR ·çÇÁÀÇ ÇüÅ´ ´ÙÀ½°ú °°´Ù. :

  1 
  2 for (expr1; expr2; expr3) statement
  3      

ù ¹øÂ° Ç¥Çö½Ä(expr1)Àº ·çÇÁ¸¦ ½ÃÀÛÇÒ ¶§ ¹«Á¶°Ç Çѹø Æò°¡(½ÇÇà)µÈ´Ù.

¸Å ¹Ýº¹ÀÇ ½ÃÀÛ ¶§¸¶´Ù expr2°¡ Æò°¡µÈ´Ù. ¸¸¾à À̰ÍÀÌ TRUE¸é ·çÇÁ´Â °è¼ÓµÇ°í statement°¡ ½ÇÇàµÈ´Ù. expr2°¡ FALSEÀÌ¸é ·çÇÁ´Â Á¾·áµÈ´Ù.

¸Å ¹Ýº¹ÀÌ ³¡³¯ ¶§ expr3°¡ Æò°¡(½ÇÇà)µÈ´Ù.

°¢ Æò°¡½ÄÀº ºñ¿öµÑ ¼ö ÀÖ´Ù.expr2°¡ ºñ¾îÀÖÀ¸¸é ¹«ÇÑ ·çÇÁ¸¦ ¶æÇÑ´Ù. (PHP´Â C¿Í °°ÀÌ ºñ¾îÀÖÀ¸¸é TRUE·Î ÀνÄÇÑ´Ù.) ÀÌ°Ç º°·Î ÁÁÀº ¹æ¹ýÀÌ ¾Æ´ÏÁö¸¸, Á¾Á¾ BREAK¸¦ »ç¿ëÇÏ¿© Á¾·áÇÏ´Â ¹æ¹ýµµ ÀÖ´Ù.

´ÙÀ½ ¿¹´Â 1¿¡¼­ 10±îÁö Ãâ·ÂÇÏ´Â ¿¹ÀÌ´Ù. :

  1 
  2 /* example 1 */
  3  
  4 for ($i = 1; $i <= 10; $i++) {
  5     print $i;
  6 }
  7  
  8 /* example 2 */
  9  
 10 for ($i = 1;;$i++) {
 11     if ($i > 10) {
 12         break;
 13     }
 14     print $i;
 15 }
 16  
 17 /* example 3 */
 18  
 19 $i = 1;
 20 for (;;) {
 21     if ($i > 10) {
 22         break;
 23     }
 24     print $i;
 25     $i++;
 26 }
 27  
 28 /* example 4 */
 29  
 30 for ($i = 1; $i <= 10; print $i, $i++) ;
 31      

¹°·Ð óÀ½°ÍÀÌ °¡Àå ÁÁ¾Æº¸ÀδÙ. ±×·¯³ª ³ª¸ÓÁöµµ °¡´ÉÇÏ´Ù´Â °ÍÀ» ¾Ë¾Æ¾ß ÇÑ´Ù.

PHP´Â FOR ·çÇÁ¿¡ ´ëÇØ¼­µµ ´ÙÀ½°ú °°Àº "colon syntax"¸¦ Áö¿øÇÑ´Ù.

  1 
  2 for (expr1; expr2; expr3): statement; ...; endfor;
  3      

ÀϺΠ´Ù¸¥ ¾ð¾îµéÀº ¹è¿­À» Ž»öÇϱâ À§ÇÏ¿© foreach ¹®ÀåÀ» Á¦°øÇϱ⵵ ÇÑ´Ù. ±×·¯³ª PHP´Â À̸¦ À§ÇØ list()¿Í each() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© while ·çÇÁ·Î ÇØ°áÇÑ´Ù. ÀÌ ÇÔ¼öµé¿¡ ´ëÇØ¼­´Â ¿¹Á¦¸¦ ÂüÁ¶ÇÏÀÚ.


foreach

PHP4(PHP3´Â ¾Æ´Ï´Ù)´Â perl µîÀÇ ´Ù¸¥ ¾ð¾î°¡ Á¦°øÇÏ´Â foreach ±¸Á¶¸¦ Á¦°øÇÑ´Ù. ÀÌ ±¸Á¶´Â ¹è¿­¿¡ À־ ¹Ýº¹ÀûÀÎ ÀÛ¾÷À» Çϴµ¥ À¯¿ëÇÏ´Ù. À̰Ϳ¡´Â µÎ°¡Áö ¹®¹ýÀÌ Àִµ¥, µÎ ¹øÂ° °ÍÀº ù ¹øÂ° °ÍÀÇ ºÎºÐ È®ÀåÀ̳ª ¸Å¿ì À¯¿ëÇÏ°Ô »ç¿ëµÈ´Ù.

  1 
  2 foreach(array_expression as $value) statement
  3 foreach(array_expression as $key => $value) statement
  4      

ù ¹øÂ° ¸ð¾çÀº array_expression À¸·Î  ÁÖ¾îÁø ¹è¿­¿¡ ´ëÇØ ¼øÈ¯ÀÛ¾÷(loop)À» ¼öÇàÇÑ´Ù. °³°³ÀÇ ¼øÈ¯ÀÛ¾÷¿¡¼­, ¹è¿­ÀÇ ¿ø¼Ò´Â $value¿¡ ÀúÀåµÇ°í ³»ºÎ ¹è¿­ Æ÷ÀÎÅÍ(internal array pointer)´Â Çϳª ÀüÁøÇÏ¿© ´ÙÀ½ ÀÛ¾÷½Ã¿¡ »õ·Î¿î ¿ø¼Ò¸¦¤© °¡Á®¿Àµµ·Ï ÇÑ´Ù.

µÎ ¹øÂ° ¸ð¾çÀº ù ¹øÂ°¿Í µ¿ÀÏÇÑ ÀÛ¾÷À» ÇÏÁö¸¸, $key¿¡ ÇØ´ç ¿ø¼ÒÀÇ Å°°ªÀ» ÀúÀåÇÏ°Ô µÈ´Ù.

foreach ¹®ÀÌ Ã³À½ ¼öÇàµÉ ¶§, ³»ºÎ ¹è¿­ Æ÷ÀÎÅÍ(internal array pointer)´Â ÀÚµ¿ÀûÀ¸·Î ¹è¿­ÀÇ Ã¹¹øÂ° ¿ø¼Ò·Î ¼³Á¤µÈ´Ù. À̸»ÀÇ Àǹ̴ ¿©·¯ºÐÀÌ foreach ¹®À» »ç¿ëÇÒ ¶§ reset()À» ¹Ì¸® È£ÃâÇÒ ÇÊ¿ä´Â ¾ø´Ù´Â °ÍÀÌ´Ù.

µû¶ó¼­ ¾Æ·¡ÀÇ µÎ °³ÀÇ ¹®ÀåÀº µ¿ÀÏÇÑ °á°ú¸¦ ¸¸µç´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖÀ» °ÍÀÌ´Ù. :

  1 
  2 reset ($arr);
  3 while (list(, $value) = each ($arr)) {
  4     echo "Value: $value<br>\n";
  5 }
  6 
  7 foreach ($arr as $value) {
  8     echo "Value: $value<br>\n";
  9 }
 10      

 

´ÙÀ½ µÎ °³ÀÇ ¹®ÀåÀº ±â´ÉÀûÀ¸·Î µ¿ÀÏÇÑ ¹®ÀåÀÌ´Ù. :

  1 
  2 reset ($arr);
  3 while (list($key, $value) = each ($arr)) {
  4     echo "Key: $key; Value: $value<br>\n";
  5 }
  6 
  7 foreach ($arr as $key => $value) {
  8     echo "Key: $key; Value: $value<br>\n";
  9 }
 10      

Ãß°¡ÀûÀ¸·Î ¸î °³ÀÇ ¿¹Á¦¸¦ º¸ÀÚ. :

  1 
  2 /* foreach example 1: value only */
  3 
  4 $a = array (1, 2, 3, 17);
  5 
  6 foreach ($a as $v) {
  7    print "Current value of \$a: $v.\n";
  8 }
  9 
 10 /* foreach example 2: value (with key printed for illustration) */
 11 
 12 $a = array (1, 2, 3, 17);
 13 
 14 $i = 0; /* for illustrative purposes only */
 15 
 16 foreach($a as $v) {
 17     print "\$a[$i] => $k.\n";
 18 }
 19 
 20 /* foreach example 3: key and value */
 21 
 22 $a = array (
 23     "one" => 1,
 24     "two" => 2,
 25     "three" => 3,
 26     "seventeen" => 17
 27 );
 28 
 29 foreach($a as $k => $v) {
 30     print "\$a[$k] => $v.\n";
 31 }
 32      

 


break

break´Â ÇöÀç ·çÇÁ¿¡¼­ ºüÁ® ³ª°¡´Â ¸í·ÉÀÌ´Ù.

break¿¡´Â ¼ýÀÚ ¿É¼ÇÀ» ÁÙ ¼ö Àִµ¥, À̰ÍÀº Çѹø¿¡ ºüÁ® ³ª°¥ Á¦¾î ±¸Á¶ÀÇ ¼ö¸¦ ÀǹÌÇÑ´Ù.

  1 
  2 $i = 0;
  3 while ($i < 10) {
  4     if ($arr[$i] == "stop") {
  5         break;  /* You could also write 'break 1;' here. */
  6     }
  7     $i++;
  8 }
  9 
 10 /* Using the optional argument. */
 11 
 12 $i = 0;
 13 while ( ++$i ) {
 14     switch ( $i ) {
 15     case 5:
 16         echo "At 5<br>\n";
 17         break 1;  /* Exit only the switch. */
 18     case 10:
 19         echo "At 10; quitting<br>\n";
 20         break 2;  /* Exit the switch and the while. */
 21     default:
 22         break;
 23     }
 24 }
 25      

continue

CONTINUE ´Â ÇöÀç ·çÇÁÀÇ Ã³À½À¸·Î °¡µµ·Ï ÇÏ´Â ¸í·ÉÀÌ´Ù.

continueµµ ¼ýÀÚ ¿É¼ÇÀ» ÁÙ ¼ö Àִµ¥, À̰ÍÀº Çѹø¿¡ óÀ½À¸·Î °¥ Á¦¾î ±¸Á¶ÀÇ ¼ö¸¦ ÀǹÌÇÑ´Ù.

  1 
  2 while (list ($key, $value) = each ($arr)) {
  3    if (!($key % 2)) { // skip odd members
  4        continue;
  5    }
  6    do_something_odd ($value);
  7 }
  8 
  9 $i = 0;
 10 while ($i++ < 5) {
 11     echo "Outer<br>\n";
 12     while (1) {
 13         echo "  Middle<br>\n";
 14         while (1) {
 15              echo "  Inner<br>\n";
 16              continue 3;
 17         }
 18         echo "This never gets output.<br>\n";
 19     }
 20     echo "Neither does this.<br>\n";
 21 }
 22      

 


switch

SWITCH¹®Àº µ¿ÀÏÇÑ Ç¥Çö½ÄÀÇ IF¹®ÀÇ ³ª¿­°ú ºñ½ÁÇÏ´Ù. ´ÙÀ½ ¿¹´Â µ¿ÀÏÇÑ °ÍÀº IF¹®°ú SWITCH¹®À¸·Î Ç¥ÇöÇÑ °ÍÀÌ´Ù. :

  1 
  2 if ($i == 0) {
  3     print "i equals 0";
  4 }
  5 if ($i == 1) {
  6     print "i equals 1";
  7 }
  8 if ($i == 2) {
  9     print "i equals 2";
 10 }
 11  
 12 switch ($i) {
 13     case 0:
 14         print "i equals 0";
 15         break;
 16     case 1:
 17         print "i equals 1";
 18         break;
 19     case 2:
 20         print "i equals 2";
 21         break;
 22 }
 23      

SWITCH¹®Àº ¹®Àå ´ÜÀ§·Î ½ÇÇàµÈ´Ù. SWITCH¿¡ ÀÖ´Â Æò°¡½Ä°ú ÀÏÄ¡ÇÏ´Â CASE¹®À» ã¾Æ ±× ÀÌÈÄ SWITCHºí·°ÀÌ ³¡³¯ ¶§ ±îÁö ½ÇÇàÇÑ´Ù. µû¶ó¼­ ¿øÇÏ´Â °æ¿ì BREAK·Î ½ÇÇàÀ» ÁßÁö½Ãų Çʿ䰡 ÀÖ´Ù. ´ÙÀ½ ¿¹¸¦ º¸ÀÚ. :

  1 
  2 switch ($i) {
  3     case 0:
  4         print "i equals 0";
  5     case 1:
  6         print "i equals 1";
  7     case 2:
  8         print "i equals 2";
  9 }
 10      

¿©±â¼­ $i°¡ 0ÀÌ¸é ¸ðµç print¹®À» ½ÇÇàÇÒ °ÍÀÌ´Ù. ¸¸¾à $i°¡ 1ÀÌ¸é ¸¶Áö¸· µÎ°³ÀÇ print¹®À» ½ÇÇàÇÑ´Ù. µû¶ó¼­ ¿©·¯ºÐÀÌ ¿øÇÏ´Â °á°ú¸¦ ¾òÀ¸·Á¸é BREAK¹®À» ÀØÁö ¾Ê´Â °ÍÀÌ Áß¿äÇÑ´Ù.

Ưº°ÇÑ case·Î default case°¡ ÀÖ´Ù. ÀÌ °ÍÀº ´Ù¸¥ ¾î¶² case¿¡µµ ¸ÂÁö ¾Ê´Â °æ¿ì¸¦ ÀǹÌÇÑ´Ù. ¿¹¸¦ µé¾î :

  1 
  2 switch ($i) {
  3     case 0:
  4         print "i equals 0";
  5         break;
  6     case 1:
  7         print "i equals 1";
  8         break;
  9     case 2:
 10         print "i equals 2";
 11         break;
 12     default:
 13         print "i is not equal to 0, 1 or 2";
 14 }
 15      

´Ù¸¥ Áß¿äÇÑ Á¡Àº CASE Ç¥Çö½Ä¿¡´Â Á¤¼ö, ½Ç¼ö, ¹®ÀÚ¿­ÀÇ ½ºÄ®¸® ŸÀÔÀ¸·Î Æò°¡µÇ´Â ¾î¶² Ç¥Çö½ÄÀ̿͵µ µÈ´Ù´Â °ÍÀÌ´Ù. ¹è¿­À̳ª °´Ã¼µµ ¹®Á¦¸¦ ÀÏÀ¸Å°Áö´Â ¾Ê´Â´Ù. ±×·¯³ª ±×°ÍÀº ¹®Àå¿¡¼­ Àǹ̰¡ ¾ø´Ù.

switch ¹®¿¡ ´ëÇØ¼­µµ Alternative syntax°¡ Áö¿øµÈ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº Alternative syntax for control structures ¸¦ »ìÆìº¸ÀÚ

  1 
  2 switch ($i):
  3     case 0:
  4         print "i equals 0";
  5         break;
  6     case 1:
  7         print "i equals 1";
  8         break;
  9     case 2:
 10         print "i equals 2";
 11         break;
 12     default:
 13         print "i is not equal to 0, 1 or 2";
 14 endswitch;
 15      


require

require() ¹®Àº C preprocessorÀÇ #include¿Í ºñ½ÁÇϰÔ, ÀÚ½ÅÀ» ÁöÁ¤µÈ ÆÄÀÏ·Î ´ëüÇÑ´Ù.

include() µÇ°Å³ª require() µÇ¾î ÀÐÇôÁö´Â ÆÄÀÏÀº Æ÷ÇÔµÈ ÆÄÀÏÀÇ Ã³À½¿¡ PHP¸ðµå¿¡¼­ ºüÁ®³ª¿Í HTML¸ðµå·Î µé¾î°¡°í, ¸¶Áö¸·¿¡ PHP¸ðµå·Î º¹±ÍÇÑ´Ù. µû¶ó¼­ Æ÷Ç﵃ ÆÄÀÏÀÇ PHP ÄÚµå´Â ÀûÀýÇÑ PHP ½ÃÀÛ, Á¾·á Åÿ¡ µÑ·¯½Î¿© ÀÖ¾î¾ß ÇÑ´Ù.

À̰ÍÀº require()¹®À» ·çÇÁ ±¸Á¶ ¾È¿¡ µÎ¾î, ¸Å¹ø ´Ù¸¥ ÆÄÀÏÀ» ÀоîµéÀÏ ¼ö ¾ø´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù. ÀÌ·± µ¿ÀÛÀ» À§Çؼ­´Â INCLUDE ¹®À» »ç¿ëÇ϶ó.

require('header.inc');

require()´Â »ç½Ç ÇÔ¼ö°¡ ¾Æ´Ï¶ó Á¦¾î±¸Á¶ÀÌ´Ù. µû¶ó¼­ À̰ÍÀº ÇÔ¼ö¿Í´Â ´Ù¸¥ ±ÔÄ¢À» µû¸¥´Ù. À̸¦Å׸é require()´Â ´Ù¸¥ ¾î¶² Á¦¾î±¸Á¶¿Íµµ »ç¿ëÇÒ ¼ö ¾ø´Ù. ¶ÇÇÑ, À̰ÍÀº ¹Ýȯ°ªÀÌ ¾ø´Ù. (¹Ýȯ°ªÀ» µ¹·Á¹ÞÀ¸·ÁÇÏ¸é ÆÄ½Ì ¿¡·¯°¡ ³­´Ù.)

include()¿Í ´Ù¸£°Ô, require()´Â ¾ðÁ¦³ª ÇØ´ç ÆÄÀÏÀ» Àоî¿Â´Ù. ½ÉÁö¾î ÇØ´ç ¶óÀÎÀÌ ÀüÇô ½ÇÇàµÇÁö ¾Ê¾Æµµ Àоî¿Â´Ù. ¸¸¾à ¿©·¯ºÐÀÌ Á¶°Ç¿¡ µû¶ó ÆÄÀÏÀ» Æ÷ÇÔ½ÃŰ°í ½Í´Ù¸é include()¹®À» »ç¿ëÇÏ¿©¾ß ÇÑ´Ù. Á¶°ÇÀýÀº require()¿¡ ¾Æ¹« ¿µÇâÀ» ¹ÌÄ¡Áö ¸øÇÑ´Ù. ±×·¯³ª, require()¹®ÀÌ ÀÖ´Â ÁÙÀÌ ½ÇÇàµÇÁö ¾Ê´Â´Ù¸é ÇØ´ç ÆÄÀÏÀÇ ¾î¶² Äڵ嵵 ½ÇÇàµÇÁö ¾Ê´Â´Ù.

ºñ½ÁÇϰÔ, ¼øÈ¯¹® ¶ÇÇÑ require()¿¡ ¿µÇâÀ» ÁÖÁö ¸øÇÑ´Ù. ÇØ´ç ÆÄÀÏ¿¡ ÀÖ´Â ³»¿ëÀÌ ·çÇÁÀÇ ³»¿ëÀ̶ó ÇÏ´õ·¯µµ require()¹®Àº ´ÜÁö Çѹø¸¸ ³ªÅ¸³ª´Â °ÍÀ¸·Î µÈ´Ù.

À̰ÍÀº require() ¹®À» ¼øÈ¯¹® ¾È¿¡ »ç¿ëÇÒ ¼ö ¾ø´Ù´Â °ÍÀ» ÀǹÌÇϰí, ¸Å ¼øÈ¯½Ã¸¶´Ù ´Ù¸¥ ÆÄÀÏÀ» Àоî¿À·Á¸é include()¹®À» »ç¿ëÇÏ¿©¾ß ÇÑ´Ù´Â °ÍÀÌ´Ù.

  1 
  2 require ('header.inc');
  3      

include()¿Í require() ¸ðµÎ È£ÃâÇÑ ½ºÅ©¸³Æ®¾ÈÀ¸·Î ¿øÇÏ´Â ÆÄÀÏÀÇ ³»¿ë ÀÚü¸¦ ²ø¾îµéÀÌ´Â(pull) °ÍÀÌÁö, HTTP³ª ±×¿Í ºñ½ÁÇÑ ¹æ½ÄÀ¸·Î ÇØ´ç Ÿ°ÙÀ» callÇÏ´Â °ÍÀº ¾Æ´Ï´Ù. µû¶ó¼­ ÇöÀç ¹üÀ§¾È¿¡ ¼±¾ðµÈ ¸ðµç º¯¼öµéÀº Æ÷ÇÔÇÒ ÆÄÀÏ ¾È¿¡¼­µµ ±×´ë·Î »ç¿ëµÈ´Ù.

  1 
  2 require ("file.inc?varone=1&vartwo=2"); /* Won't work. */
  3 
  4 $varone = 1;
  5 $vartwo = 2;
  6 require ("file.inc");  /* $varone and $vartwo will be available in file.inc */
  7      

¿©·¯ºÐÀº remote files ±â´ÉÀ» »ç¿ëÇÏ¿© HTTP¸¦ ÅëÇÑ ¿ø°Ý ÆÄÀÏÀ» includeÇϰųª requireÇÒ ¶§ À§ÀÇ ³»¿ëÀ» ¸íÈ®È÷ ¾Ë¾ÆµÑ Çʿ䰡 ÀÖ´Ù.

PHP3¿¡¼­´Â require()·Î Æ÷ÇÔµÈ ÆÄÀϾȿ¡¼­ return ¹®À» »ç¿ëÇÒ ¼ö ÀÖ¾ú´Ù. ´Ü, return ¹®ÀÌ Æ÷ÇÔµÈ ÆÄÀÏÀÇ global scope¿¡¼­ ³ªÅ¸³ª´Â °æ¿ì¸¸ °¡´ÉÇϰí, ¾î¶°ÇÑ ºí·Ï³»({} ³»ºÎ)¿¡¼­µµ »ç¿ëÇÒ ¼ö ¾ø´Ù. ±×·¯³ª, PHP4¿¡¼­´Â ÀÌ·± ±â´É ÀÚü°¡ ¾ø¾îÁ® ¹ö·È´Ù. ¸¸¾à ¿©·¯ºÐÀÌ ÀÌ·± ±â´ÉÀ» »ç¿ëÇÏ°í ½Í´Ù¸é include() ¹®À» »ç¿ëÇϱ⠹ٶõ´Ù.


include

INCLUDE¹®Àº ÁöÁ¤ÇÑ ÆÄÀÏÀ» ÀÐ°í ½ÇÇàÇÑ´Ù.

include() µÇ°Å³ª require() µÇ¾î ÀÐÇôÁö´Â ÆÄÀÏÀº Æ÷ÇÔµÈ ÆÄÀÏÀÇ Ã³À½¿¡ PHP¸ðµå¿¡¼­ ºüÁ®³ª¿Í HTML¸ðµå·Î µé¾î°¡°í, ¸¶Áö¸·¿¡ PHP¸ðµå·Î º¹±ÍÇÑ´Ù. µû¶ó¼­ Æ÷Ç﵃ ÆÄÀÏÀÇ PHP ÄÚµå´Â ÀûÀýÇÑ PHP ½ÃÀÛ, Á¾·á Åÿ¡ µÑ·¯½Î¿© ÀÖ¾î¾ß ÇÑ´Ù.

ÀÌ µ¿ÀÛÀº ½ÇÇàÁß include() ¹®À» ¸¸³¯ ¶§ ¸¸´Ù ÀϾ´Ù. µû¶ó¼­ ¿©·¯ºÐÀº include() ¹®À» ·çÇÁ ±¸Á¶ ¾È¿¡ µÎ¾î ¸Å¹ø ´Ù¸¥ ÆÄÀÏÀ» ÀÐ¾î µéÀ̵µ·Ï ÇÒ ¼ö ÀÖ´Ù.

  1 
  2 $files = array ('first.inc', 'second.inc', 'third.inc');
  3 for ($i = 0; $i < count($files); $i++) {
  4     include $files[$i];
  5 }
  6      

include()´Â ÀÌ ¹®ÀåÀ» ¸¸³¯ ¶§ ¸¶´Ù ¸Å¹ø ÀçÆò°¡µÇ¾î Àç½ÇÇàµÈ´Ù´Â Á¡¿¡¼­ require()¿Í ´Ù¸£´Ù. ¹Ý¸é¿¡ require()¹®Àº ÁöÁ¤µÈ ÆÄÀÏÀÇ ³»¿ëÀÌ ½ÇÇàµÇ´Â°¡¿¡ °ü°è¾øÀÌ(¿¹¸¦µé¾î if ¹® ¾È¿¡ µé¾îÀÖ°í »óŰ¡ °ÅÁþÀÎ °æ¿ì¿¡µµ), ÀÌ ¹®ÀåÀ» óÀ½ ¸¸³¯À» ¶§ ÁöÁ¤µÈ ÆÄÀÏ·Î ´ëüµÈ´Ù.

include()´Â Ưº°ÇÑ ±¸Á¶À̹ǷÎ, ¸¸¾à À̰ÍÀÌ Á¶ÀüÀý ¾È¿¡ ³õ¿©ÀÖ´Ù¸é ¹Ýµå½Ã {}(statement block)À¸·Î µÑ·¯½Î¾ß ÇÑ´Ù.

  1 
  2 /* This is WRONG and will not work as desired. */
  3  
  4 if ($condition)
  5     include($file);
  6 else
  7     include($other);
  8  
  9 /* This is CORRECT. */
 10  
 11 if ($condition) {
 12     include($file);
 13 } else {
 14     include($other);
 15 }
 16      

PHP3, PHP4 ¸ðµÎ include() µÈ ÆÄÀÏ ³»¿¡¼­, ÀÌ ÆÄÀÏÀÇ ¼öÇàÀ» Á¾·áÇϰí, ÀÌ ÆÄÀÏÀ» ºÎ¸¥ ½ºÅ©¸³Æ®·Î º¹±ÍÇϱâ À§ÇØ return ¹®À» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ¾à°£ ´Ù¸¥Á¡ÀÌ ÀÖ±â´ÂÇÏ´Ù. ¿ì¼±, PHP3¿¡¼­´Â ÇØ´ç ºí·ÏÀÌ ÇÔ¼öÀÇ ºí·ÏÀÌ ¾Æ´ÑÇÑ return ¹®ÀÌ ºí·Ï¾È¿¡ ¿Ã ¼ö ¾ø´Ù. (ÇÔ¼öÀÇ ºí·Ï ¾È¿¡ ÀÖ´Â °æ¿ì´Â ÇØ´ç ÇÔ¼ö¿¡¼­ return ÇÏ´Â °ÍÀÌÁö ÇöÀç ÆÄÀÏ¿¡¼­ return ÇÏ´Â °ÍÀº ¾Æ´Ï´Ù.) ±×·¯³ª, PHP4¿¡¼­´Â ÀÌ Á¦ÇÑÀÌ ¾ø´Ù. ¤¨¶ÇÇÑ PHP4¿¡¼­´Â include() ÆÄÀÏÀÇ return½Ã¿¡ ¸®ÅϰªÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ¿©·¯ºÐÀº include() ¹®À» ÀÏ¹Ý ÇÔ¼öó·³ ¹Ýȯ°ªÀ» ¹ÞÀ» ¼ö ÀÖ´Ù. (À̰ÍÀº PHP3¿¡¼­´Â ±¸¹®¿¡·¯¸¦ ¹ß»ý½ÃŲ´Ù.)

Example 11-1. include() in PHP3 and PHP4

´ÙÀ½ÀÇ test.inc ¶ó´Â ÆÄÀÏÀÌ ¸ÞÀÎ ÆÄÀϰú µ¿ÀÏÇÑ µð·ºÅ丮¿¡ ÀÖ´Ù°í °¡Á¤ÇÑ´Ù. :
  1 
  2 <?php
  3 echo "Before the return <br>\n";
  4 if (1) {
  5     return 27;
  6 }
  7 echo "After the return <br>\n";
  8 ?>
  9      

main.html À̶ó´Â ¸ÞÀÎÆÄÀÏÀÇ ³»¿ëÀº ´ÙÀ½°ú °°´Ù. :
  1 
  2 <?php
  3 $retval = include ('test.inc');
  4 echo "File returned: '$retval'<br>\n";
  5 ?>
  6      

main.html ÀÌ PHP3¿¡¼­ ºÒ·ÁÁö¸é, ÀÌ ÆÄÀÏÀº µÎ ¹øÂ° ÁÙ¿¡¼­ "you can't take the value of an include()" ¶ó´Â ±¸¹® ¿¡·¯¸¦ ¹ß»ý½ÃŲ´Ù. ±×·¯³ª, PHP4¿¡¼­´Â ´ÙÀ½µÂ °°Àº °á°ú¸¦ Ãâ·ÂÇÑ´Ù. :

Before the return
File returned: '27'
     

ÀÌÁ¦ main.html À» ´ÙÀ½°ú °°Àº ³»¿ëÀ¸·Î °íÃļ­ ½ÇÇàÇØ º¸ÀÚ. :
  1 
  2 <?php
  3 include ('test.inc');
  4 echo "Back in main.html<br>\n";
  5 ?>
  6      

PHP4¿¡¼­´Â ´ÙÀ½°ú °°Àº °á°ú°¡ Ãâ·ÂµÈ´Ù. :
Before the return
Back in main.html
     

±×·¯³ª PHP3¿¡¼­´Â ´ÙÀ½°ú °°Àº °á°ú°¡ ³ª¿Â´Ù. :

Before the return 
27Back in main.html

Parse error: parse error in /home/torben/public_html/phptest/main.html on line 5
     

À§ÀÇ ±¸¹® ¿¡·¯´Â test.inc¿¡¼­ return ¹®ÀÌ ÇÔ¼öºí·ÏÀÌ¿ÜÀÇ ºí·Ï¾È¿¡ »ç¿ëµÇ¾ú±â ¶§¹®¿¡ »ý±ä´Ù. return À» ºí·Ï ¹ÛÀ¸·Î ²¨³»¸é ´ÙÀ½°ú °°Àº °æ°ú°¡ Ãâ·ÂµÈ´Ù. :
Before the return
27Back in main.html
     

À§ÀÇ '27'ÀÌ Ãâ·ÂµÈ °ÍÀº PHP3°¡ includeÆÄÀÏ·Î ºÎÅÍÀÇ °ªÀÇ ¹ÝȯÀ» Áö¿øÇÏÁö ¾Ê±â ¶§¹®ÀÌ´Ù.

include()¿Í require() ¸ðµÎ È£ÃâÇÑ ½ºÅ©¸³Æ®¾ÈÀ¸·Î ¿øÇÏ´Â ÆÄÀÏÀÇ ³»¿ë ÀÚü¸¦ ²ø¾îµéÀÌ´Â(pull) °ÍÀÌÁö, HTTP³ª ±×¿Í ºñ½ÁÇÑ ¹æ½ÄÀ¸·Î ÇØ´ç Ÿ°ÙÀ» callÇÏ´Â °ÍÀº ¾Æ´Ï´Ù. µû¶ó¼­ ÇöÀç ¹üÀ§¾È¿¡ ¼±¾ðµÈ ¸ðµç º¯¼öµéÀº Æ÷ÇÔÇÒ ÆÄÀÏ ¾È¿¡¼­µµ ±×´ë·Î »ç¿ëµÈ´Ù.

  1 
  2 include ("file.inc?varone=1&vartwo=2"); /* Won't work. */
  3 
  4 $varone = 1;
  5 $vartwo = 2;
  6 include ("file.inc");  /* $varone and $vartwo will be available in file.inc */
  7      

¿©·¯ºÐÀº remote files ±â´ÉÀ» »ç¿ëÇÏ¿© HTTP¸¦ ÅëÇÑ ¿ø°Ý ÆÄÀÏÀ» includeÇϰųª requireÇÒ ¶§ À§ÀÇ ³»¿ëÀ» ¸íÈ®È÷ ¾Ë¾ÆµÑ Çʿ䰡 ÀÖ´Ù.

See also readfile(), require(), virtual().


Chapter 12. Functions

User-defined functions

ÇÔ¼ö´Â ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÑ´Ù. :

  1 
  2 function foo ($arg_1, $arg_2, ..., $arg_n) {
  3     echo "Example function.\n";
  4     return $retval;
  5 }
  6      

ÇÔ¼ö ¾È¿¡´Â ´Ù¸¥ ÇÔ¼ö³ª classÀÇ ¼±¾ð µîÀ» Æ÷ÇÔÇÑ ¸ðµç °¡´ÉÇÑ PHP Äڵ尡 »ç¿ëµÉ ¼ö ÀÖ´Ù.

PHP3¿¡¼­´Â ÇÔ¼ö´Â ±× ÇÔ¼ö°¡ »ç¿ëµÇ±â ÀÌÀü¿¡ ¼±¾ðµÇ¾î ÀÖ¾î¾ß ÇÏ¿´À¸³ª PHP4¿¡¼­´Â ÀÌ·± Á¦¾àÀÌ ¾ø¾îÁ³´Ù.

PHP´Â function overloadingÀ» Áö¿øÇÏÁö ¾Ê°í, ÀÌ¹Ì Á¤ÀÇµÈ ÇÔ¼ö¸¦ ÀçÁ¤ÀÇÇϰųª ¾ø¾ÖÁö ¸øÇÑ´Ù.

PHP3¿¡¼­´Â ÇÔ¼ö ÆÄ¶ó¸ÞÅÍÀÇ ±âº»°ªÀ» ¼³Á¤ÇØÁÖ´Â °Í(default argument values¸¦ º¸ÀÚ.)Àº °¡´ÉÇØµµ, ÆÄ¶ó¸ÞÅÍÀÇ °³¼ö¸¦ °¡º¯À¸·Î ¼³Á¤ÇÏ´Â °ÍÀº ºÒ°¡´ÉÇßÁö¸¸, PHP4´Â µÎ°¡Áö ¸ðµÎ °¡´ÉÇÏ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº Variable-length argument lists ¿Í func_num_args(), func_get_arg(), func_get_args() ÀÇ ÇÔ¼ö ¼³¸íÀ» º¸±â ¹Ù¶õ´Ù.

 


Function arguments

argument list¸¦ ÅëÇØ ÇÔ¼ö¿¡ ¾î¶² Á¤º¸¸¦ ³Ñ°ÜÁÙ ¼ö ÀÖ´Ù. ÀÌ argument list´Â ½°Ç¥(,)·Î ³ªÀ§¾îÁø º¯¼ö³ª »ó¼öÀÇ listÀÌ´Ù.

PHP´Â passing by value(±âº»ÀûÀ¸·Î À̰ÍÀ» »ç¿ë)¿Í passing by reference, default argument valuesÀÇ 3°¡Áö ¹æ¹ýÀ» Á¦°øÇÑ´Ù. °¡º¯ ±æÀÌ(Variable-length) argument list´Â PHP4ÀÌÈÄ¿¡¼­¸¸ Á¦°øµÈ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº Variable-length argument lists ¿Í func_num_args(), func_get_arg(), func_get_args() ÀÇ ÇÔ¼ö ¼³¸íÀ» º¸±â ¹Ù¶õ´Ù. ±×·¯³ª PHP3¿¡¼­µµ ¹è¿­À» ÅëÇÑ Àü´ÞÀ» »ç¿ëÇÑ´Ù¸é ºñ½ÁÇÑ È¿°ú¸¦ ³¾ ¼ö ÀÖ´Ù.

  1 
  2 function takes_array($input) {
  3     echo "$input[0] + $input[1] = ", $input[0]+$input[1];
  4 }
  5      

Making arguments be passed by reference

±âº»ÀûÀ¸·Î ÇÔ¼öÀÇ Àμö(argument)µéÀº °ªÀ¸·Î Àü´ÞµÈ´Ù(passed by value). ÇÔ¼ö³»¿¡¼­ º¯È­½ÃŲ °ªÀ» ±×´ë·Î À¯ÁöÇÏ·Á¸é pass by reference·Î Àμö¸¦ ³Ñ°Ü¾ß ÇÑ´Ù.

¿©·¯ºÐÀÌ ¾î¶² ÇÔ¼öÀÇ Àμö¸¦ Ç×»ó pass by reference·Î ³Ñ±â·Á ÇÑ´Ù¸é, ¿©·¯ºÐÀº ÇÔ¼ö¸¦ ¼±¾ðÇÒ ¶§ ampersand(&)¸¦ ÀμöÀÇ ¾Õ¿¡ ºÙ¿©ÁÖ¸é µÈ´Ù. :

  1 
  2 function add_some_extra(&$string) {
  3     $string .= 'and something extra.';
  4 }
  5 $str = 'This is a string, ';
  6 add_some_extra($str);
  7 echo $str;    // outputs 'This is a string, and something extra.'
  8       

¸¸¾à ±âº»Àº by value ·Î ÇÏÁö¸¸ Çʿ信 µû¶ó by reference·Î È£ÃâÇÏ°í ½Í´Ù¸é ÇÔ¼ö È£Ã⠽ÿ¡ ÀμöÀÇ ¾Õ¿¡ &¸¦ ºÙÀÌ¸é µÈ´Ù. :

  1 
  2 function foo ($bar) {
  3     $bar .= ' and something extra.';
  4 }
  5 $str = 'This is a string, ';
  6 foo ($str);
  7 echo $str;    // outputs 'This is a string, '
  8 foo (&$str);
  9 echo $str;    // outputs 'This is a string, and something extra.'
 10       

Default argument values

½ºÄ®¶ó Àμö´Â ´ÙÀ½°ú °°ÀÌ C++ °ú ºñ½ÁÇÏ°Ô ±âº»°ªÀ» Á¤ÇØÁÙ ¼ö ÀÖ´Ù. :

  1 
  2 function makecoffee ($type = "cappucino") {
  3     return "Making a cup of $type.\n";
  4 }
  5 echo makecoffee ();
  6 echo makecoffee ("espresso");
  7       

À§ÀÇ ÄÚµåÀÇ ½ÇÇà °á°ú´Â ´ÙÀ½°ú °°´Ù :

Making a cup of cappucino.
Making a cup of espresso.
     

default °ªÀº ¹Ýµå½Ã »ó¼öÀ̾î¾ß ÇÑ´Ù. (¿¹¸¦µé¾î) º¯¼ö³ª classÀÇ ¸â¹ö¸¦ »ç¿ëÇØ¼­´Â ¾ÈµÈ´Ù.

PHP 4.0¿¡¼­´Â default argument·Î unsetÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù. À̰ÍÀº ÇØ´ç argument¿¡ °ªÀÌ Á¦°øµÇÁö ¾ÊÀ¸¸é, Àý´ë·Î °ªÀ» ¼³Á¤ÇÏÁö ¾Ê´Â °ÍÀ» ÀǹÌÇÑ´Ù.

default argument¸¦ »ç¿ëÇÒ ¶§, default°¡ µÇ´Â ÀμöµéÀº non-defaultÀÎ Àμöµéº¸´Ù ¿À¸¥ÂÊ¿¡ À§Ä¡ÇØ¾ß ÇÑ´Ù. ±×·¸Áö ¾ÊÀ¸¸é ¿øÇÏ´Â °á°ú°¡ ³ª¿ÀÁö ¾Ê´Â´Ù. ´ÙÀ½À» º¸ÀÚ. :

  1 
  2 function makeyogurt ($type = "acidophilus", $flavour) {
  3     return "Making a bowl of $type $flavour.\n";
  4 }
  5  
  6 echo makeyogurt ("raspberry");   // won't work as expected
  7       

À§ ÄÚµåÀÇ ½ÇÇà °á°ú´Â ´ÙÀ½°ú °°´Ù :

Warning: Missing argument 2 in call to makeyogurt() in 
/usr/local/etc/httpd/htdocs/php3test/functest.html on line 41
Making a bowl of raspberry .
     

±×·¯¸é ÀÌÁ¦ À§ÀÇ °Í°ú ¾Æ·¡°ÍÀ» ºñ±³ÇØ º¸ÀÚ. :

  1 
  2 function makeyogurt ($flavour, $type = "acidophilus") {
  3     return "Making a bowl of $type $flavour.\n";
  4 }
  5  
  6 echo makeyogurt ("raspberry");   // works as expected
  7       

ÀÌ ¿¹Á¦ÀÇ ½ÇÇà °á°ú´Â ´ÙÀ½°ú °°´Ù. :

Making a bowl of acidophilus raspberry.
     

 


Variable-length argument lists

PHP4¿¡¼­´Â »ç¿ëÀÚ Á¤ÀÇ ÇÔ¼ö¿¡ °¡º¯ ±æÀÌ(Variable-length) argument list¸¦ Á¦°øÇÑ´Ù. func_num_args(), func_get_arg(), func_get_args() ÀÇ ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ½±°Ô »ç¿ëÇÒ ¼ö ÀÖ´Ù.

Ưº°ÇÑ ¹®¹ýÀÌ »ç¿ëµÇÁöµµ ¾Ê°í, ÇÔ¼öÀÇ Á¤Àǽóª »ç¿ë½Ã argument list´Â º¸ÅëÀÇ °æ¿ì¿Í µ¿ÀÏÇÏ°Ô »ç¿ëÇÏ¸é µÈ´Ù.


Returning values

ÇÔ¼ö´Â return ¹®À» ÅëÇØ ÇÔ¼ö°ªÀ» µ¹·ÁÁÙ ¼ö ÀÖ´Ù. list¿Í object¸¦ Æ÷ÇÔÇÑ ¾î¶² typeµµ µ¹·ÁÁú ¼ö ÀÖ´Ù.

  1 
  2 function square ($num) {
  3     return $num * $num;
  4 }
  5 echo square (4);   // outputs '16'.
  6      

¿©·¯°ªÀ» µ¹·ÁÁÖ´Â ÀÏÀº ÇÒ ¼ö ¾ø´Ù. ±×·¯³ª list¸¦ µ¹·ÁÁÜÀ¸·Î½á ºñ½ÁÇÑ ÀÏÀ» ÇÒ ¼ö ÀÖ´Ù. :

  1 
  2 function small_numbers() {
  3     return array (0, 1, 2);
  4 }
  5 list ($zero, $one, $two) = small_numbers();
  6      

 


old_function

OLD_FUNCTION ¹®ÀåÀº PHP/FI2¿¡¼­ µ¿ÀÏÇÑ ÇÔ¼ö »ç¿ë¹ýÀ» Á¦°øÇÑ´Ù. (function´ë½Å old_functionÀ» »ç¿ëÇÑ´Ù´Â Á¡Àº Á¦¿ÜÇϰí)

À̰ÍÀ» »ç¿ëÇÏ´Â °ÍÀº ÁÁÁö ¾ÊÀº ¹æ¹ýÀÌ´Ù. À̰ÍÀÌ »ç¿ëµÉ ¶§´Â PHP/FI2->PHP3 º¯È¯±â¿¡¼­ »ÓÀÌ´Ù.

ÁÖÀÇ

OLD_FUNCTIONÀ¸·Î Á¤ÀÇµÈ ÇÔ¼öµéÀº PHPÀÇ ³»ºÎ Äڵ忡¼­ È£ÃâµÉ ¼ö ¾ø´Ù. ÀÌ ¸»Àº usort()³ª array_walk(), register_shutdown_function()°°Àº ÇÔ¼ö¿¡ »ç¿ëÇÒ ¼ö ¾ø´Ù´Â ÀǹÌÀÌ´Ù. À̸¦ ÇØ°áÇϱâ À§Çؼ­´Â ÀÌ OLD_FUNCTIONÀ¸·Î ¼±¾ðµÈ ÇÔ¼ö¸¦ È£ÃâÇÏ´Â PHP3 ÇüÅÂÀÇ ÇÔ¼ö¸¦ ¸¸µé¾î »ç¿ëÇÏ´Â °ÍÀÌ´Ù.

 


Variable functions

PHP´Â °¡º¯ ÇÔ¼ö(variable functions) °³³äÀ» Áö¿øÇÑ´Ù. À̰ÍÀº º¯¼ö¸í µÚ¿¡ °ýÈ£°¡ ¿ÔÀ» ¶§, PHP´Â ±× À̸§À» °¡Áø ÇÔ¼ö¸¦ ã¾Æ ½ÇÇàÇÑ´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù. ÀÌ ±â´ÉÀº  callbacks, function table µîÀÇ ±â´É¿¡ »ç¿ëÇÏ¸é ¸Å¿ì À¯¿ëÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖ´Ù.

Example 12-1. Variable function example

  1 
  2 <?php
  3 function foo() {
  4     echo "In foo()<br>\n";
  5 }
  6 
  7 function bar( $arg = '' ) {
  8     echo "In bar(); argument was '$arg'.<br>\n";
  9 }
 10 
 11 $func = 'foo';
 12 $func();
 13 $func = 'bar';
 14 $func( 'test' );
 15 ?>
 16      

 


Chapter 13. Classes and Objects

( ¿ªÀÚÁÖ : Class ¹®ÀåÀº JavaÀÇ subsetÀ̶ó ÇÒ¸¸Å­ µ¿ÀÏÇÏ´Ù. )

class

Ŭ·¡½º´Â ÀÏ·ÃÀÇ º¯¼ö¿Í ÀÌ º¯¼öµéÀ» »ç¿ëÇÏ´Â ÇÔ¼öµéÀÇ ¸ðÀ½ÀÌ´Ù. Ŭ·¡½º´Â ´ÙÀ½°ú °°Àº ÇüÅ·Π¼±¾ðµÈ´Ù.

  1 
  2 <?php
  3 class Cart {
  4     var $items;  // Items in our shopping cart
  5    
  6     // Add $num articles of $artnr to the cart
  7  
  8     function add_item ($artnr, $num) {
  9         $this->items[$artnr] += $num;
 10     }
 11    
 12     // Take $num articles of $artnr out of the cart
 13  
 14     function remove_item ($artnr, $num) {
 15         if ($this->items[$artnr] > $num) {
 16             $this->items[$artnr] -= $num;
 17             return true;
 18         } else {
 19             return false;
 20         }   
 21     }
 22 }
 23 ?>
 24      

ÀÌ ¼±¾ðÀº Cart¶ó´Â À̸§ÀÇ Å¬·¡½º·Î, īƮ¾È¿¡ µé¾îÀÖ´Â ¹°Ç°À» À§ÇÑ ÇÑ °³ÀÇ ¹è¿­ º¯¼ö¿Í cart¿¡ ¹°°ÇÀ» ³Ö°Å³ª »©´Â µÎ °³ÀÇ ÇÔ¼ö·Î ±¸¼ºµÇ¾î ÀÖ´Ù.

Classe´Â TypeÀ¸·Î, ½ÇÁ¦ º¯¼öµéÀÇ Ã»»çÁøÀ̶ó ÇÒ ¼ö ÀÖ´Ù. ¿©·¯ºÐÀº new ¿¬»êÀÚ¸¦ »ç¿ëÇÏ¿© ¿øÇÏ´Â typeÀÇ º¯¼ö¸¦ »ý¼ºÇÏ¿©¾ß ÇÑ´Ù.

  1 
  2  $cart = new Cart;
  3  $cart->add_item("10", 1);
  4     

À§¿¡ ÀÖ´Â ¿¹´Â Cart Ŭ·¡½ºÀÇ $cart¶ó´Â object¸¦ ¸¸µå´Â °ÍÀÌ´Ù. ÀÌ objectÀÇ add_item() ÇÔ¼ö¸¦ È£ÃâÇÏ¿© ¹°Ç° ¹øÈ£ "10"¹øÀÇ ¹°Ç° 1°³¸¦ īƮ¿¡ ³Ö´Â´Ù.

Ŭ·¡½º´Â ´Ù¸¥ Ŭ·¡½º·Î È®Àå µÉ ¼ö ÀÖ´Ù. È®Àå ȤÀº ÆÄ»ýµÈ(extended or derived) Ŭ·¡½º´Â base °¡ µÇ´Â Ŭ·¡½ºÀÇ ¸ðµç º¯¼öµé°ú ÇÔ¼öµéÀ» ±×´ë·Î °¡Á¦°Ô µÇ°í, ¿©·¯ºÐÀº ¿©±â¿¡ Ãß°¡·Î È®ÀåµÈ ¼±¾ðÀ» ÇÒ ¼ö ÀÖ´Ù. À̸¦ À§ÇØ "extends"¶ó´Â Ű¿öµå°¡ »ç¿ëµÈ´Ù.

  1 
  2 class Named_Cart extends Cart {
  3     var $owner;
  4   
  5     function set_owner ($name) {
  6         $this->owner = $name;
  7     }
  8 }
  9     

À§ÀÇ ¿¹´Â Cart Ŭ·¡½ºÀÇ º¯¼ö¿Í ÇÔ¼ö¿¡ $owner º¯¼ö¿Í set_owner() ÇÔ¼ö¸¦ Ãß°¡ÇÑ Named_Cart¶ó´Â Ŭ·¡½ºÀÇ ¼±¾ðÀÌ´Ù. ¿©·¯ºÐÀº À̸§ºÙÀº īƮ(named cart)¸¦ »ç¿ëÇÏ¿© īƮÀÇ ÁÖÀÎÀ» ¼³Á¤Çϰí ã¾Æº¼ ¼ö ÀÖ´Ù. ¶ÇÇÑ ±âÁ¸ÀÇ ÀÏ¹Ý Ä«Æ®(normal cart)¿¡ ÀÖ´ø ÇÔ¼öµµ »ç¿ëÇÒ ¼ö ÀÖ´Ù.

  1 
  2 $ncart = new Named_Cart;    // Create a named cart
  3 $ncart->set_owner ("kris"); // Name that cart
  4 print $ncart->owner;        // print the cart owners name
  5 $ncart->add_item ("10", 1); // (inherited functionality from cart)
  6     

Ŭ·¡½º ³»ºÎ¿¡ ÀÖ´Â ÇÔ¼ö¿¡¼­ $this ¶ó´Â º¯¼ö´Â ÀÚ±â ÀڽŠobject¸¦ ÀǹÌÇÑ´Ù. ¿©·¯ºÐÀº $this->something ÀÇ ÇüÅ·ΠÇöÀç objectÀÇ º¯¼ö³ª ÇÔ¼ö¸¦ »ç¿ëÇÏ¿©¾ß ÇÑ´Ù.

»ý¼ºÀÚ(Constructor)´Â ÇØ´ç Ŭ·¡½ºÀÇ »õ ÀνºÅϽº(»õ·Î ¸¸µç º¯¼ö¶ó°í »ý°¢ÇØ µÎÀÚ)¸¦ ¸¸µé ¶§ ÀÚµ¿ÀûÀ¸·Î ½ÇÇàµÇ´Â ÇÔ¼ö¸¦ ÀǹÌÇÑ´Ù. Ŭ·¡½ºÀÇ À̸§°ú °°Àº À̸§ÀÇ ÇÔ¼ö°¡ »ý¼ºÀÚ°¡ µÈ´Ù.

  1 
  2 class Auto_Cart extends Cart {
  3     function Auto_Cart () {
  4         $this->add_item ("10", 1);
  5     }
  6 }
  7     

À§ÀÇ ¿¹´Â Cart Ŭ·¡½º¿¡ ¹°Ç°¹øÈ£ 10¹øÀÇ ¹°Ç°À» ÇÑ °³ ÀÚµ¿À¸·Î Ãß°¡ÇÏ´Â »ý¼ºÀÚ¸¦ Ãß°¡ÇÑ Auto_Cart¶ó´Â Ŭ·¡½ºÀÇ ¼±¾ðÀÌ´Ù. Auto_Cart´Â "new"·Î »ý¼ºµÈ´Ù. »ý¼ºÀÚ´Â ¶ÇÇÑ Àμö(argument)¸¦ °¡Áú ¼ö ÀÖ°í, ÀÌ ÀμöµéÀº default°ªÀ» °¡Áø ¿É¼ÇÀ¸·Î ¼±¾ð ÇÒ ¼ö ÀÖ´Ù. ÀÌ ±â´ÉÀº ¸Å¿ì À¯¿ëÇÏ°Ô »ç¿ëµÈ´Ù.

  1 
  2 class Constructor_Cart extends Cart {
  3     function Constructor_Cart ($item = "10", $num = 1) {
  4         $this->add_item ($item, $num);
  5     }
  6 }
  7  
  8 // Shop the same old boring stuff.
  9  
 10 $default_cart   = new Constructor_Cart;
 11  
 12 // Shop for real...
 13  
 14 $different_cart = new Constructor_Cart ("20", 17);
 15     

 

Caution

ÆÄ»ýµÈ(derived) Ŭ·¡½ºÀÇ °æ¿ì, ÀÌ Å¬·¡½ºÀÇ »ý¼ºÀÚ°¡ È£ÃâµÉ ¶§ ºÎ¸ð Ŭ·¡½ºÀÇ »ý¼ºÀÚ´Â ÀÚµ¿À¸·Î È£ÃâµÇÁö ¾Ê´Â´Ù.

 


III. ±â´É (Features)

Table of Contents
14. Error handling
15. Creating GIF images
16. HTTP authentication with PHP
17. Cookies
18. Handling file uploads
19. Using remote files
20. Connection handling
21. Persistent database connections


Chapter 14. Error handling

PHP¿¡´Â ´ÙÀ½°ú °°Àº 4°¡ÁöÀÇ ¿¡·¯¿Í °æ°í ÇüŰ¡ ÀÖ´Ù.

error reporting levelÀº À§ÀÇ 4°³ÀÇ ¼ýÀÚ°¡ ´õÇØÁ®¼­ °áÁ¤µÈ´Ù. ±âº» error reporting level Àº 7·Î 1+2+4°¡ µÇ°í, ÀÌ´Â Notice¸¦ Á¦¿ÜÇÑ ¸ðµç °ÍÀ» ·¹Æ÷Æ®Ç϶ó´Â ÀǹÌÀÌ´Ù. ÀÌ ·¹º§Àº php3.ini ÆÄÀÏ¿¡¼­ error_reporting Áö½ÃÀÚ·Î °áÁ¤ÇÒ ¼ö ÀÖ´Ù. ȤÀº, ¾ÆÆÄÄ¡ÀÇ httpd.conf ÆÄÀÏ¿¡¼­ php3_error_reporting Áö½ÃÀÚ·Î °áÁ¤Çϰųª, ½ºÅ©¸³Æ® ½ÇÇà Áß¿¡ error_reporting() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ¹Ù²ãÁÙ ¼öµµ ÀÖ´Ù.

¸ðµç PHP Ç¥Çö½Ä(expression)Àº "@"¸¦ ¾Õ¿¡ ºÙÀ̰í È£ÃâµÇ¸é error reportingÀ» ÇÏÁö ¾Ê´Â´Ù. ¸¸¾à track_errors ±â´ÉÀÌ Enabled·Î µÇ¾î Àִµ¥ ÇØ´ç ¹®Àå¿¡¼­ ¿¡·¯°¡ ¹ß»ýÇß´Ù¸é, $php_errormsg¶ó´Â Àü¿ªº¯¼ö¿¡¼­ ¿¡·¯ ¸Þ½ÃÁö¸¦ ãÀ» ¼ö ÀÖÀ» °ÍÀÌ´Ù.


Chapter 15. PHP¿¡¼­ GIFÀÇ »ý¼º (Creating GIF images)

PHP´Â ´ÜÁö HTMLÃâ·ÂÀ» ¸¸µå´Â °Í¸¸ ÇÒ ¼ö ÀÖ´Â °ÍÀÌ ¾Æ´Ï´Ù. PHP´Â GIF image fileµµ ¸¸µé ¼ö ÀÖÀ» ÀÖÀ» »Ó¾Æ´Ï¶ó, »ç¿ëÇϱ⿡ Æí¸®ÇÑ GIF image stream±îÁö ¸¸µé ¼ö ÀÖ´Ù. À̸¦ À§Çؼ­ ¿©·¯ºÐÀº PHP¸¦ ÄÄÆÄÀÏ ÇÒ ¶§, image ÇÔ¼ö¸¦ °¡Áö°í ÀÖ´Â GD ¶óÀ̺귯¸®¸¦ Æ÷ÇÔÇÏ¿©¾ß ÇÑ´Ù.

Example 15-1. GIF creation with PHP

  1 
  2 <?php
  3     Header("Content-type: image/gif");
  4     $string=implode($argv," ");
  5     $im = imagecreatefromgif("images/button1.gif");
  6     $orange = ImageColorAllocate($im, 220, 210, 60);
  7     $px = (imagesx($im)-7.5*strlen($string))/2;
  8     ImageString($im,3,$px,9,$string,$orange);
  9     ImageGif($im);
 10     ImageDestroy($im);
 11 ?>
 12     

À§ÀÇ ¿¹Á¦´Â <img src="button.php3?text">¿Í °°Àº tagÀÌ ÀÖ´Â ÆäÀÌÁö·ÎºÎÅÍ ºÒ·ÁÁö°Ô µÉ °ÍÀÌ´Ù. ±×·¯¸é À§¿¡ÀÖ´Â button.php ½ºÅ©¸³Æ®´Â "text"¶ó´Â ¹®ÀÚ¿­À» "images/button1.gif"¿¡ ¿À¹ö·¹ÀÌ ½ÃÄÑ °á°ú image¿¡ Ãâ·ÂÇÑ´Ù. ÀÌ·¸°Ô ÇÏ¸é ¹öư¿¡ µé¾î°¡´Â ±Û¾¾¸¦ ¸Å¹ø ¼Õ½±°Ô ¹Ù²ã ¾µ ¼ö ÀÖ°í, ¶ÇÇÑ ¸Å¹ø À̹ÌÁö ÆÄÀÏÀ» ¸¸µé Çʿ䰡 ¾ø¾î È¿À²ÀûÀÌ°í °£´ÜÇÏ´Ù.


Chapter 16. HTTP ÀÎÁõ (HTTP authentication with PHP)

(¿ªÀÚÁÖ. HTTP authenticationÀ̶õ Web Client¿¡°Ô ID¿Í Password¸¦ ÀԷ¹޾Æ, ±× ID¿Í Password·Î Web¹®¼­¿¡ Á¢±ÙÀ» Çã°¡, ºÒÇãÇÏ´Â ±â´ÉÀ» ¸»ÇÑ´Ù. ÀÚ¼¼È÷ ¾Ë°í ½Í´Ù¸é RFC1945ÀÇ Authentication ºÎºÐÀ» Âü°íÇϱ⠹ٶõ´Ù. http://pec.etri.re.kr/!qkim/HTTP/¿¡ ÇÑ±Û ¹ø¿ª ¹®¼­µµ ÀÖÀ¸´Ï ÂüÁ¶ÇÏÀÚ.)

PHP¸¦ »ç¿ëÇÑ HTTP ÀÎÁõÀº Apache ¸ðµâ·Î »ç¿ëµÉ ¶§¸¸ µ¿ÀÛÇÑ´Ù. Apache ¸ðµâÀÇ PHP ½ºÅ©¸³Æ®¿¡¼­ Header()¶ó´Â ÇÔ¼ö¸¦ »ç¿ëÇϸé Client ºê¶ó¿ìÀú¿¡°Ô Username°ú Password¸¦ ÀԷ¹޴ À©µµ¿ì¸¦ ¶ç¿ìµµ·Ï ÇÏ´Â "ÀÎÁõ ¿ä±¸"("Authentication Required") ¸Þ½ÃÁö¸¦ º¸³»°Ô µÈ´Ù. ÀÏ´Ü »ç¿ëÀÚ°¡ Username°ú Password¸¦ ÀÔ·ÂÇϸé, user name, password, authentication typeÀÇ °ªÀ» °¡Áö´Â $PHP_AUTH_USER, $PHP_AUTH_PW, $PHP_AUTH_TYPEÀÇ 3°³ÀÇ º¯¼ö¸¦ °¡Áö°í ÇØ´ç URL(PHP ½ºÅ©¸³Æ®¸¦ Æ÷ÇÔÇÑ)ÀÌ ´Ù½Ã ºÒ¸®¿öÁø´Ù. ÇöÀç authentication typeÀº "Basic"¸¸ÀÌ Áö¿øµÈ´Ù.

client authenticationÀ» »ç¿ëÇÏ¿© ±× ÀÔ·ÂµÈ °ªÀ» Ãâ·ÂÇÏ´Â ¿¹Á¦°¡ ¾Æ·¡¿¡ ÀÖ´Ù. :

Example 16-1. HTTP Authentication example

  1 
  2 <?php
  3   if(!isset($PHP_AUTH_USER)) {
  4     Header("WWW-Authenticate: Basic realm=\"My Realm\"");
  5     Header("HTTP/1.0 401 Unauthorized");
  6     echo "Text to send if user hits Cancel button\n";
  7     exit;
  8   } else {
  9     echo "Hello $PHP_AUTH_USER.<P>";
 10     echo "You entered $PHP_AUTH_PW as your password.<P>";
 11   }
 12 ?>
 13     

¿©·¯ºÐÀº $PHP_AUTH_USER ¿Í $PHP_AUTH_PW¸¦ ´Ü¼øÈ÷ Ãâ·ÂÇÏ´Â ´ë½Å, »ç¿ëÀÚÀÇ ½Äº°À» À§ÇØ username°ú password¸¦ »ç¿ëÇϱ⸦ ¿øÇÒ °ÍÀÌ´Ù. À̶§´Â Database¿¡ QueryÇϰųª Á÷Á¢ dbm ÆÄÀÏ¿¡¼­ ã¾Æº¸¸é °¡´ÉÇÒ °ÍÀÌ´Ù.

Internet Explorer browser¿¡¼­´Â ¹ö±×·Î ÀÎÇØ HeaderÀÇ ¼ø¼­°¡ ¸Å¿ì ±î´Ù·Ó´Ù. WWW-authenticate header¸¦ HTTP/1.0 401 headerº¸´Ù ¸ÕÀú º¸³»´Â °ÍÀÌ ÇöÀç °¡´ÉÇÑ ¿ä·ÉÀ¸·Î º¸ÀδÙ.

ºñ¹Ð¹øÈ£ÀÇ À¯ÃâÀ» ¿ì·ÁÇÏ¿© HTTP¿¡¼­ Á¦°øÇÏ´Â ÀÎÁõÀ» »ç¿ëÇÏ´Â ´ë½Å ±âÁ¸ÀÇ ¿ÜºÎ ¸ÞÄ«´ÏÁòÀ» »ç¿ëÇÒ °æ¿ì¿¡´Â ¹°·Ð PHP_AUTH º¯¼ö´Â ¼³Á¤µÇÁö ¾Ê´Â´Ù.

À¯ÀÇÇÒ Á¡Àº ÀÎÁõÀÌ ÇÊ¿äÇÑ ÆäÀÌÁö¿Í ÀÎÁõÀÌ ÇÊ¿ä¾ø´Â ÆäÀÌÁö°¡ °°Àº ¼­¹ö»ó¿¡ Á¸ÀçÇÒ ¶§, ÀÎÁõÀÌ ÇÊ¿ä¾ø´Â URLÀ» controlÇÒ ¼ö ÀÖ´Â ´©±º°¡°¡, ÀÎÁõÀÌ ÇÊ¿äÇÑ URLÀÇ ¾ÏÈ£¸¦ ÈÉÃ帴 °ÍÀº ¸·À» ¼ö ¾ø´Ù´Â Á¡ÀÌ´Ù.

Netscape¿Í Internet Explorer ¸ðµÎ 401ÀÀ´ä Äڵ带 ¼­¹ö¿¡¼­ ¹Þ°ÔµÇ¸é local browser windowÀÇ authentication cache¸¦ clearÇÑ´Ù. Áï, À̰ÍÀº "log out"°³³äÀÌ µÇ´Â °ÍÀ¸·Î, »ç¿ëÀÚµé·Î ÇÏ¿©±Ý username°ú ¾ÏÈ£¸¦ ´Ù½Ã ÀÔ·ÂÇÏ°Ô ÇÑ´Ù. ÀϺδ À̰ÍÀ» loginÀÇ "time out"À̳ª "log-out"¹öưÀ» ¸¸µå´Âµ¥ »ç¿ëÇÑ´Ù

Example 16-2. HTTP Authentication example forcing a new name/password

  1 
  2 <?php
  3   function  authenticate()  {
  4     Header( "WWW-authenticate:  basic  realm='Test  Authentication  System'");
  5     Header( "HTTP/1.0  401  Unauthorized");
  6     echo  "You  must  enter  a  valid  login  ID  and  password  to  access  this  resource\n";
  7     exit;
  8   }
  9 
 10   if(!isset($PHP_AUTH_USER)  ||  ($SeenBefore ==  1  &&  !strcmp($OldAuth,  $PHP_AUTH_USER))  )  {
 11     authenticate();
 12   }  
 13   else  {
 14     echo  "Welcome:  $PHP_AUTH_USER<BR>";
 15     echo  "Old:  $OldAuth";
 16     echo  "<FORM  ACTION=\"$PHP_SELF\"  METHOD=POST>\n";
 17     echo  "<INPUT  TYPE=HIDDEN  NAME=\"SeenBefore\"  VALUE=\"1\">\n";
 18     echo  "<INPUT  TYPE=HIDDEN  NAME=\"OldAuth\"  VALUE=\"$PHP_AUTH_USER\">\n";
 19     echo  "<INPUT  TYPE=Submit  VALUE=\"Re  Authenticate\">\n";
 20     echo  "</FORM>\n";
 21 
 22 }
 23 ?>
 24   

ÀÌ µ¿ÀÛÀº HTTP Basic authentication ±âÁØ¿¡ ¿ä±¸µÇ´Â °ÍÀº ¾Æ´Ï¹Ç·Î ¿©·¯ºÐÀº À̰Ϳ¡ ÀÇÁ¸ÇÏ¿©¼­´Â ¾ÈµÈ´Ù. Lynx¿¡¼­´Â 401 ¼­¹ö ÀÀ´äÀ» ¹Þ¾Æµµ authentication Á¤º¸¸¦ clearÇÏÁö ¾Ê´Â´Ù. µû¶ó¼­ BackÀ» ´©¸£°í ´Ù½Ã Forward ¹öưÀ» ´­·¯¼­ ´Ù½Ã Á¢±ÙÇÒ ¼ö ÀÖ´Ù.

¶ÇÇÑ ÀÌ Authentication ±â´ÉÀº Microsoft's IIS server¿¡¼­ CGI versionÀÇ PHP¸¦ »ç¿ëÇÒ °æ¿ì¿¡´Â IISÀÇ Á¦¾àÀ¸·ÎÀÎÇØ µ¿ÀÛÇÏÁö ¾Ê´Â´Ù.


Chapter 17. Cookies

PHP´Â HTTP Cookie¸¦ Åõ¸íÇϰÔ(transparently) Áö¿øÇÑ´Ù. Cookie ¸ÞÄ«´ÏÁòÀº Æ®·¡Å·À̳ª »ç¿ëÀÚ ½Äº° µîÀ» À§ÇØ ¿ø°Ý browser¿¡ ÀúÀåµÈ µ¥ÀÌÅ͸¦ µ¹·Á ¹Þ´Â °úÁ¤À» ¸»ÇÑ´Ù. ¿©·¯ºÐÀº cookie¸¦ ¼³Á¤Çϱâ À§ÇØ setcookie() ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. Cookie´Â HTTP Çì´õÀÇ ÇÑ ºÎºÐÀ̹ǷÎ, SetCookie() ÇÔ¼ö´Â ºê¶ó¿ìÀú·Î º¸³»´Â ¾î¶² µ¥ÀÌÅͺ¸´Ùµµ ¾Õ¿¡ »ç¿ëÇØ¾ß ÇÑ´Ù. ÀÌ Á¦¾àÀº Header() ÇÔ¼ö¿Í °°Àº Á¦¾àÀ¸·Î º¸¸é µÈ´Ù.

´ç½ÅÀÌ º¸³»ÁØ ¸ðµç cookie´Â ÀÚµ¿ÀûÀ¸·Î GETÀ̳ª POST ¹æ½Ä µ¥ÀÌÅÍ¿Í °°Àº PHP º¯¼ö·Î º¯È¯µÈ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ µ¿ÀÏÇÑ cookie¿¡ ¿©·¯ °ªÀ» ÀúÀåÇÏ°í ½Í´Ù¸é CookieÀ̸§¿¡ []¸¦ ´õÇÏ¸é µÈ´Ù. ÀÚ¼¼ÇÑ °ÍÀº setcookie() ÇÔ¼ö ¼³¸íÀ» ÂüÁ¶ÇÏÀÚ.


Chapter 18. Handling file uploads


POST method uploads

PHP´Â RFC-1867À» Áö¿øÇÏ´Â ºê¶ó¿ìÀú·ÎºÎÅÍ ÆÄÀÏÀ» ¾÷·Îµå ¹ÞÀ» ¼ö ÀÖ´Â ±â´ÉÀÌ ÀÖ´Ù. ÀÌ ±â´ÉÀ» »ç¿ëÇϸé TextºÐ¾Æ´Ï¶ó BinaryÆÄÀϵµ ¾÷·Îµå°¡ °¡´ÉÇÏ´Ù. ¿©·¯ºÐÀº PHP's authetication°ú ³í¸®ÀûÀÎ ÇÔ¼öµéÀ» »ç¿ëÇÏ¿©, Upload°¡ °¡´ÉÇÑ »ç¿ëÀÚ¿Í, ÆÄÀÏÀÌ UploadµÈ ÈÄ¿¡ ÇØ¾ß ÇÒ ÀÏÀ» ¹Ýµå½Ã Á¤ÇØ µÎ¾î¾ß ÇÑ´Ù. (¿ªÀÚÁÖ. RFC-1867Àº Netscape 3.0ÀÌ»ó, Explorer 4.0À̻󿡼­ Áö¿øÇÑ´Ù. Netscape 2.x´ëÀÇ ÀϺΠ»óÀ§¹öÁ¯µµ Áö¿øÇϰí, Explorer 3.02´Â Patch°¡ ³ª¿Í ÀÖÀ¸¹Ç·Î patch½ÃŰ¸é °¡´ÉÇÏ´Ù.)

PHP´Â ¶ÇÇÑ Netscape Composer ¿Í W3C's Amaya clients¸¦ »ç¿ëÇÒ °æ¿ì PUT-method ÀÇ ÆÄÀÏ ¾÷·Îµåµµ Áö¿øÇÑ´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº PUT Method Support ¸¦ Àо±â¹Ù¶õ´Ù.

ÆÄÀÏ ¾÷·Îµå È­¸éÀº ´ÙÀ½°ú °°Àº Á» Ưº°ÇÑ ÆûÀ» ¸¸µé¾î ¶ç¿ï ¼ö ÀÖ´Ù. :

Example 18-1. File Upload Form

  1 
  2 <FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST>
  3 <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000">
  4 Send this file: <INPUT NAME="userfile" TYPE="file">
  5 <INPUT TYPE="submit" VALUE="Send File">
  6 </FORM>
  7     

¿©±â¼­_URL_Àº PHP htmlÆÄÀÏÀ̾î¾ß ÇÕ´Ï´Ù. hidden ÇʵåÀÎ MAX_FILE_SIZE´Â File input Çʵåµéº¸´Ù ¼±ÇàµÇ¾î¾ß ÇÕ´Ï´Ù. ÀÌ °ªÀº PHP htmlÀÌ ¹Þ¾ÆµéÀÌ´Â ÃÖ´ë ÆÄÀÏ Å©±â¸¦ Byte´ÜÀ§·Î ³ªÅ¸³À´Ï´Ù. ¾÷·Îµå°¡ ¼º°øÀûÀ¸·Î µÇ¸é ÁöÁ¤µÈ ÆÄÀÏ¿¡´Â ´ÙÀ½°ú °°Àº º¯¼öµéÀÌ Á¤ÀǵǾî Áø´Ù. :

À§ º¯¼öÀÇ "$userfile"ºÎºÐÀº upload form¿¡¼­ TYPE=filedÀ» °¡Áø INPUT ÇʵåÀÇ À̸§ÀÌ µÈ´Ù. À§ÀÇ ¿¹Á¦¿¡¼­ ¿ì¸®´Â ±× À̸§Àº "userfile"À̶ó°í Á¤Çß´Ù.

FileÀº ±âº»ÀûÀ¸·Î ¿ì¼± ¼­¹öÀÇ default temporary directory¿¡ ÀúÀåµÈ´Ù. ÀÌ µðÆúÆ® µð·ºÅ丮´Â PHP°¡ µ¹¾Æ°¡´Â ÄÄÇ»ÅÍÀÇ È¯°æº¯¼ö "TMPDIR"À» ¼³Á¤ÇÏ¿© º¯°æÇÒ ¼ö ÀÖ´Ù. À̸¦ PHP ½ºÅ©¸³Æ® ¾È¿¡¼­ putenv() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© º¯°æÇÏ´Â °ÍÀº µ¿ÀÛÇÏÁö ¾Ê´Â´Ù.

¾÷·ÎµåµÈ ÆÄÀÏÀ» ´Ù·ç´Â PHP ½ºÅ©¸³Æ®´Â ÇØ´ç ÆÄÀÏÀ» °¡Áö°í ÇÏ´Â ÀÛ¾÷À» ¼³Á¤ÇØ ÁÙ Çʿ䰡 ÀÖ´Ù. ¿¹¸¦µé¾î, ¿©·¯ºÐÀº $file_sizeº¯¼ö¸¦ »ç¿ëÇÏ¿© ³Ê¹« À۰ųª Å« ÆÄÀÏÀ» ¹ö¸± ¼öµµ ÀÖ´Ù. ¶ÇÇÑ ¿©·¯ºÐÀº $file_typeº¯¼ö¸¦ °¡Áö°í ƯÁ¤ÇÑ Å¸ÀÔ¿¡ ¸ÂÁö ¾Ê´Â ÆÄÀÏÀ» ¹ö¸± ¼ö ÀÖ´Ù. ¾î¶² ·ÎÁ÷ÀÌ´ø, ¿©·¯ºÐÀº Àӽà µð·ºÅ丮¿¡ ÀÖ´Â ÆÄÀÏÀ» Áö¿ì°Å³ª ³ªÁß¿¡ ÇÊ¿äÇÒ °æ¿ì¿¡´Â ´Ù¸¥ °÷¿¡ À̵¿½ÃÄÑ¾ß ÇÑ´Ù.

¸¸¾à Àӽà µð·ºÅ丮¿¡ ÀÖ´Â ÆÄÀÏÀ» ÇØ´ç request°¡ ³¡³¯ ¶§ ±îÁöµµ Áö¿ì°Å³ª À̵¿½ÃŰÁö ¾Ê¾Ò´Ù¸é, ÀÌ ÆÄÀÏÀº ÇØ´ç request°¡ Á¾·áµÇ´Â ½ÃÁ¡¿¡¼­ ÀÚµ¿À¸·Î Áö¿öÁø´Ù.


ÀϹÝÀûÀÎ ÁÖÀÇ»çÇ× (Common Pitfalls)

MAX_FILE_SIZE ¾ÆÀÌÅÛÀÇ °ªÀº PHP3.ini¿¡ ¼³Á¤µÈ upload_max_filesizeÀÇ °ªÀ̳ª Apache .conf¿¡ ¼³Á¤ÇÑ php3_upload_max_filesizeÀÇ °ªº¸´Ù Å©°Ô ¼³Á¤ÇÒ ¼ö ¾ø´Ù. ±âº»°ªÀº 2¸Þ°¡ ¹ÙÀÌÆ®ÀÌ´Ù.

CERN httpd ¼­¹ö´Â client·ÎºÎÅÍ ÀԷ¹ÞÀº mime headerÀÇ ¾ÕÂÊ ¿©¹éÀ» ¸ðµÎ strip off ½ÃÄѹö¸®¹Ç·Î, CERN httpd ¼­¹ö¿¡¼­´Â File Upload ±â´ÉÀÌ µ¿ÀÛÇÏÁö ¾Ê´Â´Ù.


¿©·¯ ÆÄÀÏÀ» UploadÇϱâ (Uploading multiple files)

Çѹø¿¡ ¿©·¯°³ÀÇ ÆÄÀÏÀ» µ¿½Ã¿¡ Àü¼ÛÇÏ´Â °Íµµ °¡´ÉÇÏ´Ù. À̶§ PHP´Â ÀÌ ÆÄÀϵ鿡 ´ëÇÑ Á¤º¸¸¦ ¹è¿­·Î Àü´ÞÇÑ´Ù. µû¶ó¼­ ÀÌ·± °æ¿ì¿¡´Â ¿©·¯°³¸¦ ¼±ÅÃÇÏ´Â select³ª checkbox ¶§Ã³·³ HTMLÀÇ formÀÇ ¾ÆÀÌÅÛ¿¡ µ¿ÀÏÇÑ array¸íÀ» Àû¾îÁÖ¾î¾ß ÇÑ´Ù.

Note: ¿©·¯ ÆÄÀÏ Àü¼Û ±â´ÉÀº 3.0.10ºÎÅÍ Ãß°¡µÈ ±â´ÉÀÌ´Ù. (¿ªÀÚÁÖ: php 4.0.0Àº ¹ö±×·Î ÀÎÇØ ÀÌ ±â´ÉÀÌ µ¿ÀÛÇÏÁö ¾Ê´Â´Ù)

Example 18-2. Uploading multiple forms

  1 
  2 <form action="file-upload.html" method="post" enctype="multipart/form-data">
  3   Send these files:<br>
  4   <input name="userfile[]" type="file"><br>
  5   <input name="userfile[]" type="file"><br>
  6   <input type="submit" value="Send files">
  7 </form>
  8      

À§ÀÇ ÆûÀÌ Àü¼ÛµÉ ¶§ $userfile, $userfile_name, $userfile_sizeÀÇ ¹è¿­ÀÌ Àü¿ª º¯¼ö·Î ¸¸µé¾îÁø´Ù. ($HTTP_POST_VARS¿¡µµ ¸¸µé¾îÁø´Ù.) ÀÌ ¹è¿­µéÀº Àü¼ÛµÈ ÆÄÀÏÀÇ Á¤º¸¸¦ °¡Áö°í ÀÖ°í, °¢ ¹è¿­µéÀº ¹øÈ£·Î À妽ºµÇ¾î ÀÖ´Ù.

¿¹¸¦ µé¾î, À§ÀÇ ¿¹¿¡¼­ /home/test/review.html °ú /home/test/xwp.out ÀÇ µÎ °³ÀÇ ÆÄÀÏÀ» Àü¼ÛÇß´Ù¸é $userfile_name[0]¿¡´Â review.htmlÀ̶ó´Â °ªÀÌ, $userfile_name[1]¿¡´Â xwp.outÀ̶ó´Â °ªÀÌ ÀúÀåµÇ°Ô µÈ´Ù. µ¿½Ã¿¡, $userfile_size[0] ¿¡´Â review.htmlÀÇ ÆÄÀÏ Å©±â°¡ ÀúÀåµÇ´Â ½ÄÀÌ µÈ´Ù.


PUT Method Support

PHP´Â Netscape Composer³ª W3C Amaya°°Àº Ŭ¸®ÀÌ¾ðÆ®¿¡ ´ëÇØ HTTP PUT ¹æ½Ä(method)À» Áö¿øÇÑ´Ù. PUT ¿ä±¸(request)´Â file uploadº¸´Ù ÈξÀ ½±´Ù. ´ÜÁö ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µÈ´Ù. :

  1 
  2 PUT /path/filename.html HTTP/1.1
  3     

À̰ÍÀº º¸Åë ¿ø°Ý Ŭ¶óÀÌ¾ðÆ®°¡ º¸³½ ³»¿ëÀ» À¥ Æ®¸® ¹ØÀÇ /path/filename.html·Î ÀúÀåÇ϶ó´Â ÀǹÌÀÌ´Ù. ±×·±µ¥ ¿©·¯ºÐÀÇ À¥ Æ®¸®¹Ø¿¡ ÀÖ´Â ÆÄÀϵéÀ» ¾Æ¹«³ª µ¤¾î ¾µ ¼ö ÀÖ´Ù´Â °ÍÀº Apache³ª PHP¿¡ À־ È®½ÇÈ÷ ÁÁÁö ¾ÊÀº »ý°¢ÀÌ´Ù. µû¶ó¼­ ÀÌ¿Í °°Àº ¿ä±¸¸¦ ´Ù·ç±â Àü¿¡, ¿ì¼± À¥ ¼­¹ö¿¡°Ô ÀÌ·± ¿ä±¸¸¦ ´Ù·ç´Â PHP ½ºÅ©¸³Æ®¸¦ ¹Ì¸® ÁöÁ¤ÇØ ÁÖ¾î¾ß ÇÑ´Ù. ¾ÆÆÄÄ¡¿¡¼­´Â Script Áö½ÃÀÚ·Î ±× ³»¿ëÀ» ÁöÁ¤ÇÑ´Ù. ÀÌ Áö½ÃÀÚ´Â Apache ¼³Á¤ ÆÄÀÏÁßÀÇ ¾î´À À§Ä¡¿¡ À־ ±¦ÂúÀ¸³ª, º¸Åë <Directory> ºí·Ï ¾ÈÀ̳ª <Virtualhost> ºí·Ï ¾È¿¡ À§Ä¡ÇÏ´Â °ÍÀÌ ÀϹÝÀûÀÌ´Ù. º¸Åë ´ÙÀ½°ú °°ÀÌ ¾²¿©Áø´Ù. :

  1 
  2 Script PUT /put.php3
  3     

À̰ÍÀº ÀÌ ¶óÀÎÀ» À§Ä¡½ÃŲ ºí·ÏÀÇ URI¿¡ ÇØ´çµÇ´Â ¸ðµç PUT ¿ä±¸¸¦ put.php3 ½ºÅ©¸³Æ®¿¡°Ô Àü´ÞÇ϶ó°í Apache¿¡°Ô ¾Ë·Á ÁØ´Ù. ¹°·Ð ÀÌ °æ¿ì .php3 È®ÀåÀÚ¿¡ ´ëÇÏ¿© PHP¼³Á¤ÀÌ ¿Ï·áµÇ¾î ÀÖ°í, PHP°¡ ÀÛµ¿ÁßÀ̾î¾ß ÇÑ´Ù.

put.php3 ÆÄÀϳ»¿¡¼­´Â º¸Åë ´ÙÀ½°ú °°ÀÌ »ç¿ëÇÒ ¼ö ÀÖ´Ù. :

  1 
  2 <? copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?>
  3     

À§ÀÇ ¸í·ÉÀº ÇØ´ç ÆÄÀÏÀ» ¿ø°Ý Ŭ¶óÀÌ¾ðÆ®°¡ ¿äûÇÑ À§Ä¡¿¡ º¹»çÇÏ´Â °ÍÀÌ´Ù. ¾Æ¸¶ ¿©·¯ºÐÀº º¹»çÇϱâ Àü¿¡ »ç¿ëÀÚ¸¦ È®ÀÎÇϰųª ÆÄÀÏÀ» °Ë»çÇÏ´Â µîÀÇ ±â´ÉÀ» ¿øÇÒ °ÍÀÌ´Ù. ¿©±â¼­ ¾Ë ¼ö ÀÖ´Â °ÍÀº PHP°¡ PUT-methodÀÇ ¿ä±¸¸¦ ¹Þ¾ÒÀ» ¶§ POST-method±â´É°ú ¸¶Âù°¡Áö·Î Àӽà ÆÄÀÏ¿¡ ÇØ´ç ³»¿ëÀ» ÀúÀåÇÑ´Ù´Â °ÍÀÌ´Ù. Áï, ¿ä±¸°¡ ³¡³ª°Ô µÇ¸é ÀÓ½ÃÆÄÀÏÀº Áö¿öÁø´Ù. µû¶ó¼­ PUTÀ» ´Ù·ç´Â PHP ½ºÅ©¸³Æ®´Â ÇØ´ç ÆÄÀÏÀ» ¾îµð ´Ù¸¥ °÷¿¡ º¹»çÇØ µÎ¾î¾ß ÇÑ´Ù. ÀÓ½ÃÆÄÀÏÀÇ À̸§Àº $PHP_PUT_FILENAME À̶ó´Â º¯¼ö¿¡ ÀúÀåµÇ°í, $REQUEST_URI º¯¼ö¿¡ Ŭ¶óÀÌ¾ðÆ®¿¡¼­ º¸³»¿Â ÀúÀåÇÒ ÆÄÀÏÀÇ °æ·Î¿Í À̸§ÀÌ ÀúÀåµÈ´Ù.(Apache°¡ ¾Æ´Ñ À¥¼­¹ö¿¡¼­´Â ¸ð¾çÀÌ Á¶±Ý ´Þ¶óÁø´Ù.) ¹°·Ð ¿©·¯ºÐÀº ÀÌ °æ·Î¸í°ú ÆÄÀϸíÀÌ ¾Æ´Ñ ÀüÇô ´Ù¸¥ À§Ä¡¿¡ ´Ù¸¥ ÆÄÀϸíÀ» »ç¿ëÇÒ ¼öµµ ÀÖ´Ù.


Chapter 19. Using remote files

¿©·¯ºÐÀÌ PHP¸¦ ¼³Á¤ÇÒ ¶§ "URL fopen wrapper"¸¦ enable·Î ¼³Á¤ÇÏ¿´´Ù¸é(ÀÌ ¼³Á¤Àº --disable-url-fopen-wrapper·Î ¸í½ÃÇÏÁö ¾ÊÀ¸¸é ¼³Á¤µÈ´Ù.), ¿©·¯ºÐÀº ´ëºÎºÐ ÇÔ¼öÀÇ ÆÄ¶ó¸ÞŸ·Î ÀÖ´Â ÆÄÀÏÀ̸§(filename)¿¡ HTTP³ª FTP URLÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ½ÉÁö¾î require()³ª include() ÇÔ¼ö¿¡µµ »ç¿ëÀÌ °¡´ÉÇÏ´Ù.

Note: ´Ü, Windowsȯ°æÀÇ include()¿Í require() ÇÔ¼ö¿¡¼­´Â »ç¿ëÇÒ ¼ö ¾ø´Ù.

¿¹¸¦ µé¾î, ¿©·¯ºÐÀº ÀÌ ±â´ÉÀ» »ç¿ëÇÏ¿© ¿ø°Ý À¥ ¼­¹ö°¡ Ãâ·ÂÇÏ´Â ³»¿ëÀ» ÆÄÀÏ·Î ¿­°í, ±× Ãâ·Â ³»¿ë¿¡¼­ ¿©·¯ºÐÀÌ ¿øÇÏ´Â µ¥ÀÌŸ¸¦ ºÐ¼®ÇÏ¿©, ÀÌ ¿øÇÏ´Â µ¥ÀÌŸ·Î µ¥ÀÌŸº£À̽º ÁúÀÇ¿¡ »ç¿ëÇϰųª, ¿©·¯ºÐÀÇ À¥ »çÀÌÆ®¿¡ ¸Â´Â ¸ð¾çÀ¸·Î º¯Çü ½ÃÄÑ Ãâ·ÂÇÒ ¼ö ÀÖ´Ù.

Example 19-1. Getting the title of a remote page

  1 
  2 <?php
  3   $file = fopen("http://www.php.net/", "r");
  4   if (!$file) {
  5     echo "<p>Unable to open remote file.\n";
  6     exit;
  7   }
  8   while (!feof($file)) {
  9     $line = fgets($file, 1024);
 10     /* This only works if the title and its tags are on one line. */
 11     if (eregi("<title>(.*)</title>", $line, $out)) {
 12       $title = $out[1];
 13       break;
 14     }
 15   }
 16   fclose($file);
 17 ?>
 18     

¿©·¯ºÐÀº ÇØ´ç ¼­¹ö¿¡ ±ÇÇÑÀÌ ÀÖ´Â »ç¿ëÀÚ·Î Á¢¼ÓÇϰí, ÇØ´ç ÆÄÀÏÀÌ Á¸ÀçÇÏÁö ¾Ê´Â´Ù¸é, FTP¸¦ ÀÌ¿ëÇÑ ÆÄÀÏ·Î ¾µ ¼öµµ ÀÖ´Ù. 'anonymous'°¡ ¾Æ´Ñ »ç¿ëÀÚ·Î Á¢¼ÓÇÏ·Á¸é, URL³»¿¡ usernameÀ» (ÇÊ¿äÇÏ´Ù¸é passwordµµ) ´ÙÀ½°ú °°ÀÌ ¸í½ÃÇØ¾ß ÇÑ´Ù : 'ftp://user:password@ftp.example.com/path/to/file'. (¶ÇÇÑ HTTP¿¡¼­ Basic authenticationÀ» »ç¿ëÇÑ ÀÎÁõÀ» ¿ä±¸ÇÏ´Â °æ¿ì¿¡µµ ÀÌ¿Í °°Àº ¹®¹ýÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù.)

Example 19-2. Storing data on a remote server

  1 
  2 <?php
  3   $file = fopen("ftp://ftp.php.net/incoming/outputfile", "w");
  4   if (!$file) {
  5     echo "<p>Unable to open remote file for writing.\n";
  6     exit;
  7   }
  8   /* Write the data here. */
  9   fputs($file, "$HTTP_USER_AGENT\n");
 10   fclose($file);
 11 ?>
 12     

Note: ¿©·¯ºÐÀº À§ÀÇ ¿¹Á¦¸¦ º¸°í, ÀÌ Å×Å©´ÐÀ» »ç¿ëÇÏ¿© remote log¸¦ ÀÛ¼ºÇÒ ¼ö ÀÖ°Ú´Ù°í »ý°¢ÇÒ ¼öµµ ÀÖ´Ù. ±×·¯³ª À§¿¡ ¾ð±ÞÇÑ´ë·Î URL fopen() wrapper´Â »õ ÆÄÀÏ¿¡¸¸ ¾µ ¼ö ÀÖ´Ù. ¿©·¯ºÐÀÌ ¿øÇÏ´Â ´ë·Î ºÐ»êµÈ log¸¦ ÇÏ°í ½Í´Ù¸é syslog()ÀÇ ³»¿ëÀ» »ìÆìº¸¶ó.


Chapter 20. Connection handling

Note: ÀÌ ±â´ÉÀº PHP version 3.0.7 ÀÌÈĺÎÅÍ Àû¿ëµÈ °ÍµéÀÌ´Ù.

³»ºÎÀûÀ¸·Î PHP´Â ¿¬°áÀÇ »óŸ¦ ´ÙÀ½ 3°¡ÁöÁß Çϳª·Î ¼³Á¤ÇÑ´Ù. :

PHP ½ºÅ©¸³Æ®°¡ ÀϹÝÀûÀ¸·Î ½ÇÇàµÇ°í ÀÖÀ» ¶§´Â NORMAL »óŰ¡ activeµÈ´Ù. ¸¸¾à ¿ø°Ý Ŭ¶óÀÌ¾ðÆ®°¡ ¿¬°áÀ» ²÷°ÔµÇ¸é ABORTED »óÅ flag°¡ ÄÑÁö°Ô µÈ´Ù. º¸Åë Ŭ¶óÀÌ¾ðÆ®°¡ ¿¬°áÀ» ²÷´Â °ÍÀº »ç¿ëÀÚ°¡ STOP ¹öưÀ» ´­·¶À» ¶§ ÀϾ´Ù. ¸¸¾à PHP°¡ ¼³Á¤ÇÑ ½Ã°£ Á¦ÇÑ¿¡ (set_time_limit()À» º¸¶ó) °É¸®°Ô µÇ¸é TIMEOUT »óÅ flag°¡ ÄÑÁö°Ô µÈ´Ù.

¿©·¯ºÐÀº Ŭ¶óÀÌ¾ðÆ®°¡ ¿¬°áÀ» ²÷¾úÀ» ¶§ ½ºÅ©¸³Æ®°¡ ¼öÇàÀ» Áß´ÜÇÒ °ÍÀΰ¡ ¾Æ´Ñ°¡¸¦ °áÁ¤ÇÏ¿©¾ß ÇÑ´Ù. ¶§¶§·Î ¿ø°Ý ºê¶ó¿ìÀú°¡ ¾î¶² °á°úµµ ¹Þ¾ÆµéÀÌÁö ¾Ê´õ¶óµµ ½ºÅ©¸³Æ®¸¦ ³¡±îÁö ½ÇÇàÇÏ´Â °ÍÀÌ Æí¸®ÇÒ ¶§°¡ ¸¹´Ù. ±âº» µ¿ÀÛÀº Ŭ¶óÀÌ¾ðÆ®°¡ ¿¬°áÀ» ²÷À¸¸é ½ºÅ©¸³Æ®µµ ÁߴܵǴ °ÍÀÌ´Ù. ÀÌ µ¿ÀÛÀº ignore_user_abort¶ó´Â php3.ini Áö½ÃÀÚ(directive)³ª, php3_ignore_user_abort¶ó´Â Apache .confÀÇ Áö½ÃÀÚ·Î ¼³Á¤ÀÌ °¡´ÉÇϰí, ignore_user_abort() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ¼³Á¤ÇÒ ¼öµµ ÀÖ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ PHP¿¡°Ô »ç¿ëÀÚ°¡ ³»¸° ÁßÁö ¸í·ÉÀ» ¹«½ÃÇ϶ó°í ¸»ÇØÁÖÁö ¾Ê¾Ò´Ù¸é, »ç¿ëÀÚÀÇ ÁßÁö ½ÅÈ£´Â ¿©·¯ºÐÀÇ ½ºÅ©¸³Æ®¸¦ Á¾·á½ÃŲ´Ù. ´Ü, register_shutdown_function()À» »ç¿ëÇÏ¿© shutdown ÇÔ¼ö¸¦ µî·ÏÇØ³õÀº °æ¿ì´Â ¿¹¿Ü°¡ µÈ´Ù. shutdown ÇÔ¼ö¸¦ »ç¿ëÇϸé, »ç¿ëÀÚ°¡ STOP¹öưÀ» ´­·¶À» ¶§, ¿©·¯ºÐÀÇ ½ºÅ©¸³Æ®´Â ³²Àº Ãâ·ÂÀ» ÇÏ·Á°í Çϰí, PHP´Â ¿¬°áÀÌ ÁߴܵǾúÀ½À» ÀÎÁöÇÏ¿© shutdown ÇÔ¼ö¸¦ È£ÃâÇÏ°Ô µÈ´Ù. shutdown ÇÔ¼ö´Â ¿©·¯ºÐÀÇ ½ºÅ©¸³Æ®°¡ Á¤»óÀûÀ¸·Î Á¾·áµÇ¾úÀ» ¶§µµ È£Ã⠵ȴÙ. µû¶ó¼­ Ŭ¶óÀ̾ðÆ®ÀÇ ¿¬°á Áß´Ü ¶§¿Í ÀϹÝÀûÀÎ Á¾·á½Ã¿¡ ´Ù¸¥ µ¿ÀÛÀ» ¿øÇÑ´Ù¸é connection_aborted() ÇÔ¼ö¸¦ »ç¿ëÇÏ¸é µÈ´Ù. ÀÌ ÇÔ¼ö´Â ¿¬°áÀÌ ÁߴܵǾú´Ù¸é true¸¦ ¹ÝȯÇÑ´Ù.

¿©·¯ºÐÀÇ ½ºÅ©¸³Æ®´Â ³»ÀåµÈ ŸÀ̸ӿ¡ ÀÇÇØ Á¾·áµÉ ¼ö ÀÖ´Ù. ±âº» timeout ½Ã°£Àº 30ÃÊ·Î µÇ¾î ÀÖ´Ù. À̰ÍÀº max_execution_timeÀ̶ó´Â php3.ini Áö½ÃÀÚ(directive)³ª µ¿ÀÏÇÑ ³»¿ëÀÇ php3_max_execution_timeÀ̶ó´Â Apache .conf Áö½ÃÀÚ¿¡ ÀÇÇØ ´Ù¸£°Ô ¼³Á¤ÀÌ °¡´ÉÇϰí set_time_limit() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© ¼³Á¤ÇÒ ¼öµµ ÀÖ´Ù. ½Ã°£ÀÌ ´Ù µÇ¸é ½ºÅ©¸³Æ®´Â Áߴܵǰí, ÀÌ ½ºÅ©´Â À§¿¡¼­ ¼³¸íÇÑ Å¬¶óÀÌ¾ðÆ®¿ÍÀÇ ¿¬°áÀÌ Á¾·áµÈ °Íó·³ µ¿ÀÛÇÑ´Ù. µû¶ó¼­ shutdown ÇÔ¼ö°¡ µî·ÏµÇ¾î ÀÖ´Ù¸é ÀÌ ÇÔ¼ö°¡ ½ÇÇàµÈ´Ù. shutdown ÇÔ¼ö³»¿¡¼­ ÀÌ ÇÔ¼ö°¡ timeout¿¡ ÀÇÇØ È£ÃâµÈ °ÍÀΰ¡¸¦ ÆÇ´ÜÇÏ·Á¸é connection_timeout() ÇÔ¼ö¸¦ »ç¿ëÇÏ¸é µÈ´Ù. ÀÌ ÇÔ¼ö´Â timeout¿¡ ÀÇÇØ shutdown ÇÔ¼ö°¡ È£ÃâµÇ¾ú´Ù¸é true¸¦ ¹ÝȯÇÑ´Ù.

ÇѰ¡Áö À¯ÀÇÇÒ »çÇ×Àº ABORTED¿Í TIMEOUT »óÅ´ µÎ °³°¡ µ¿½Ã¿¡ activeµÉ ¼ö ÀÖ´Ù´Â °ÍÀÌ´Ù. À̰ÍÀº PHP°¡ »ç¿ëÀÚ Áß´ÜÀ» ¹«½ÃÇϵµ·Ï ¼³Á¤ÇØ ³õ¾ÒÀ» ¶§ °¡´ÉÇÏ´Ù. ¶Ç ´Ù¸¥ °æ¿ì´Â »ç¿ëÀÚ°¡ ¿¬°áÀ» ²÷Áö´Â ¾Ê¾ÒÁö¸¸ ¿¬°á¿¡ ¾î¶² ¹®Á¦°¡ »ý°Ü ¿¬°áÀÌ ¸Á°¡Áø °æ¿ì·Î, ÀÌ ¶§µµ ½ºÅ©¸³Æ®´Â °è¼Ó ½ÇÇàµÈ´Ù. ÀÌ·± °æ¿ì¿¡ ½ºÅ©¸³Æ®´Â °è¼Ó½ÇÇàµÇ°í, ½Ã°£ Á¦ÇÑ¿¡ °É·Á ½ºÅ©¸³Æ®ÀÇ ¼öÇàÀÌ Áߴܵǰí shutdown ÇÔ¼ö°¡ È£ÃâµÇ¸é, connection_timeout()°ú connection_aborted() ÇÔ¼ö ¸ðµÎ true¸¦ ¹ÝȯÇÏ°Ô µÈ´Ù. ¿©·¯ºÐÀº connection_status() ¶ó´Â ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© µÎ°¡Áö »óÅ ¸ðµÎ¸¦ °Ë»çÇÒ ¼ö ÀÖ´Ù. ÀÌ ÇÔ¼ö´Â °¢ »óÅ¿¡ ´ëÇÑ Á¤º¸¸¦ bit´ÜÀ§·Î °¡Áö°í ÀÖ´Ù. ¿¹¸¦µé¾î À§¿Í°°ÀÌ ABORT¿Í TIMEOUT µÎ °³ÀÇ »óŰ¡ ¸ðµÎ activeµÇ¾î ÀÖ´Ù¸é ÀÌ ÇÔ¼ö´Â 3À» ¹ÝȯÇÑ´Ù.


Chapter 21. ¿µ±¸ÀûÀÎ µ¥ÀÌÅͺ£À̽º Á¢¼Ó (Persistent database connections)

¿µ±¸ÀûÀÎ Á¢¼Ó(Persistent connection)Àº ¿©·¯ºÐÀÇ ½ºÅ©¸³Æ®°¡ Á¾·áµÇ¾îµµ SQL link¸¦ ´ÝÁö ¾Ê´Â Á¢¼ÓÀ» ¸»ÇÑ´Ù. ¿µ±¸ÀûÀÎ Á¢¼ÓÀÌ ¿äûµÇ¸é, PHP´Â ±âÁ¸ÀÇ (ÀÌÀü¿¡ ¿­¾î µÎ¾ú´ø) µ¿ÀÏÇÑ(identical) ¿µ±¸ÀûÀÎ Á¢¼ÓÀÌ Àִ°¡¸¦ °Ë»çÇÑ´Ù. ¸¸¾à ÀÖ´Ù¸é ±âÁ¸ÀÇ °ÍÀ» »ç¿ëÇϰí, ¾ø´Ù¸é »õ·Î¿î link¸¦ ¸¸µç´Ù. 'µ¿ÀÏÇÑ(identical)' Á¢¼ÓÀ̶õ °°Àº È£½ºÆ®¿¡ °°Àº »ç¿ëÀÚ¸í(username)°ú °°Àº ¾ÏÈ£(password)¸¦ »ç¿ëÇÑ Á¢¼ÓÀ» ¸»ÇÑ´Ù.

°¡²û À¥¼­¹öÀÇ ÀÛµ¿°ú ÀÛ¾÷ÀÇ ÇÒ´ç¿¡ ´ëÇØ Àß ¾Ë°í ÀÖÁö ¸øÇÑ »ç¶÷µéÀº ¿µ±¸ÀûÀÎ Á¢¼ÓÀÌ »ç½ÇÀº º° °Í ¾Æ´Ï¶ó°í ¿ÀÇØÇϱ⵵ ÇÑ´Ù. ƯÈ÷, ¿µ±¸ÀûÀÎ Á¢¼ÓÀÌ µ¿ÀÏÇÑ SQL link¿¡¼­ 'user sessions'¸¦ ¿©´Âµ¥ º° ³ªÀ» °Íµµ ¾ø´Ù´ø°¡, transactionÀ» È¿À²ÀûÀ¸·Î ó¸®ÇÏ´Â °Íµµ ¾Æ´Ï¶ó´Ù´ø°¡, ȤÀº ´Ù¸¥ ¾î¶² ÀÛ¾÷À» ÇÏÁö ¸øÇÑ´Ù°íµµ ÇÑ´Ù. »ç½Ç, ÀÌ·± ¸»µé¿¡ ´ëÇØ ¸í¹éÈ÷ ¸»ÇÏÀÚ¸é, ¿µ±¸ÀûÀÎ Á¢¼ÓÀº ºñ¿µ±¸ÀûÀÎ Á¢¼Ó¿¡ ºñÇØ ¾î¶°ÇÑ ±â´ÉÀûÀÎ Çâ»óµµ ÁÖÁö ¸øÇÑ´Ù.

¿Ö?

À̰ÍÀº À¥¼­¹öÀÇ µ¿ÀÛ ¹æ¹ý´ë·Î µ¿ÀÛÇÑ´Ù. ¿©·¯ºÐÀÇ À¥¼­¹ö°¡ À¥ ÆäÀÌÁö¸¦ ¸¸µé±âÀ§ÇØ PHP¸¦ ÀÌ¿ëÇϴµ¥´Â 3°¡Áö ¹æ¹ýÀÌ ÀÖ´Ù.

ù ¹øÂ° ¹æ¹ýÀº PHP¸¦ CGI "wrapper"ÀÌ ÇüÅ·Π»ç¿ëÇÏ´Â °ÍÀÌ´Ù. ÀÌ ¹æ¹ýÀÇ °æ¿ì, À¥¼­¹ö¿¡ ¸Å PHP ÆäÀÌÁö°¡ ¿ä±¸µÉ ¶§ ¸¶´Ù, PHP ÀÎÅÍÇÁ¸®ÅÍÀÇ ½ÇÇàÀÌ ¸¸µé¾îÁö°í Á¾·áµÈ´Ù. µû¶ó¼­ ¸Å ¿ä±¸°¡ Á¾·áµÉ ¶§¸¶´Ù ÀÎÅÍÇÁ¸®ÅÍÀÇ ½ÇÇàÀÌ Á¾·áµÇ¹Ç·Î, ½ÇÇà Áß ¸¸µé¾ú´ø (SQL link¸¦ Æ÷ÇÔÇÑ) ¸ðµç ÀÚ¿øÀº ½ÇÇà Á¾·á¿Í ´õºÒ¾î ÇØÁ¦µÈ´Ù. ÀÌ °æ¿ì ¿©·¯ºÐÀº ¿µ±¸ÀûÀÔ Á¢¼ÓÀ» »ç¿ëÇÏ¿© ¾î¶² À̵浵 ¾òÀ» ¼ö ¾ø´Ù. ´Ù¸£°Ô ¸»Çϸé ÀÌ °æ¿ì´Â ¿µ±¸ÀûÀÎ Á¢¼ÓÀ» ÇØµµ ¿µ±¸ÀûÀÌ ¾Æ´Ï´Ù.

µÎ ¹øÂ° ¹æ¹ýÀº °¡Àå ´ëÁßÀûÀÎ ¹æ¹ýÀε¥, PHP¸¦ ´ÙÁßÇÁ·Î¼¼½º(multiprocess) À¥¼­¹öÀÇ ¸ðµâ·Î »ç¿ëÇÏ´Â °ÍÀÌ´Ù. (ÇöÀç´Â Apache°¡ À¯ÀÏÇÏ´Ù.) ´ÙÁßÇÁ·Î¼¼½º ¼­¹ö´Â º¸Åë ÇÑ °³ÀÇ ºÎ¸ð(parent) ÇÁ·Î¼¼½º¿Í, ÀÌ¿Í À¯±âÀûÀ¸·Î ¿¬°áµÇ¾î À¥ ÆäÀÌÁö¸¦ ½ÇÁ¦·Î ¸¸µå´Â ÀÛ¾÷À» ÇÏ´Â ¿©·¯°³ÀÇ ÀÚ½Ä(child) ÇÁ·Î¼¼½ºµéÀ» °¡Áö°í ÀÖ´Ù. Ŭ¶óÀÌ¾ðÆ®·ÎºÎÅÍ µé¾î¿À´Â °³º° ¿ä±¸´Â ´Ù¸¥ Ŭ¶óÀ̾ðÆ®ÀÇ ·á±¸¸¦ ó¸®Çϰí ÀÖÁö ¾ÊÀº ³²´Â ÀÚ½Ä ÇÁ·Î¼¼½º·Î ³Ñ°ÜÁø´Ù. À̰ÍÀº µ¿ÀÏÇÑ Å¬¶óÀÌ¾ðÆ®°¡ ¼­¹ö¿¡ µÎ ¹øÂ° ¿ä±¸¸¦ º¸³¾ ¶§, º¸Åë óÀ½°ú ´Ù¸¥ ÀÚ½Ä ÇÁ·Î¼¼½º¿¡¼­ 󸮵ȴٴ °ÍÀ» ÀǹÌÇÑ´Ù. ÀÌ °æ¿ì ¿µ±¸ÀûÀÎ Á¢¼ÓÀ» »ç¿ëÇÏ¸é °¢°¢ÀÇ ÀÚ½Ä ÇÁ·Î¼¼½ºµéÀº óÀ½ ¿ä±¸¿¡¼­¸¸ SQL ¼­¹ö¿¡ Á¢¼ÓÇÏ°Ô µÈ´Ù. ´Ù¸¥ ÆäÀÌÁö¿¡¼­ SQL ¼­¹ö¿¡ÀÇ Á¢¼Ó ¿ä±¸½Ã´Â ±âÁ¸¿¡ ¸¸µé¾îÁø Á¢¼ÓÀ» ´Ù½Ã »ç¿ëÇÏ°Ô µÈ´Ù.

¸¶Áö¸· ¹æ¹ýÀº PHP¸¦ ¸ÖƼ¾²·¹µå(multithreaded) À¥¼­¹öÀÇ Ç÷¯±×-ÀÎÀÇ ÇüÅ·ΠÀÛµ¿½ÃŰ´Â °ÍÀε¥, ÇöÀç À̹æ¹ýÀº ÀÌ·ÐÀûÀ¸·Î¸¸ Á¸ÀçÇϰí, ½ÇÁ¦·Î ¸¸µé¾î Áø °ÍÀº ¾ø´Ù. ISAPI, WSAPI, NSAPI (Windows¿¡¼­) µîÀÇ ¹æ¹ýÀ» »ç¿ëÇÏ¿© Netscape FastTrack, Microsoft's Internet Information Server (IIS), O'Reilly's WebSite Pro µîÀÇ ¸ÖƼ¾²·¹µå À¥¼­¹ö¿¡¼­ PHP¸¦ Ç÷¯±×-ÀÎÀ¸·Î µ¿ÀÛ½ÃŰ·Á´Â ÀÛ¾÷ÀÌ ÇöÀç ÁøÇàÁßÀÌ´Ù. ÀÌ °æ¿ì ±âº» µ¿ÀÛÀº À§¿¡¼­ ¾ð±ÞÇÑ ´ÙÁßÇÁ·Î¼¼½º ¸ðµ¨°ú µ¿ÀÏÇÏ°Ô µ¿ÀÛÇÑ´Ù.

¿µ±¸ÀûÀÎ Á¢¼ÓÀÌ ½ÇÁ¦·Î ¾Æ¹«·± ±â´ÉÀÇ Çâ»óµµ ÁÖÁö ¸øÇÑ´Ù¸é, À̰ÍÀ» »ç¿ëÇØ ¾î¶² ÀÌÁ¡ÀÌ ÀÖ³ª¿ä?

À̰Ϳ¡ ´ëÇÑ °£´ÜÇÑ ´äÀº È¿À²¼ºÀÌ´Ù. ¿µ±¸ÀûÀÎ Á¢¼ÓÀº SQL ¼­¹ö¿ÍÀÇ link¸¦ ¸¸µå´Â °Í¿¡ µû¸¥ overhead°¡ Ŭ °æ¿ì¿¡ À¯¿ëÇÏ´Ù. ÀÌ  overhead´Â ¸¹Àº ¿äÀο¡ µû¶ó Ä¿Áö±âµµ Çϰí ÀÛ¾ÆÁö±âµµ ÇÑ´Ù. ¾î¶² Á¾·ùÀÇ µ¥ÀÌÅͺ£À̽ºÀΰ¡? À¥¼­¹ö¿Í °°Àº ÄÄÇ»ÅÍ¿¡ µ¥ÀÌÅͺ£À̽º ¼­¹ö°¡ Àִ°¡? SQL ¼­¹ö°¡ ¾î¶»°Ô »ç¿ëµÇ°í Àִ°¡? µî¿¡ µû¶ó Å©°Ô ´Þ¶óÁø´Ù. Á¢¼Ó¿¡ µû¸¥ overhead°¡ Ŭ °æ¿ì¿¡ ¿µ±¸ÀûÀÎ Á¢¼ÓÀº ¿©·¯ºÐ¿¡°Ô ÀûÁö ¾ÊÀº µµ¿òÀ» ÁÙ °ÍÀÌ´Ù. À̰ÍÀº ÀÚ½Ä process¿¡¼­ SQL ¼­¹ö¿¡ Á¢¼ÓÀ» ¿äûÇÒ ¶§ ¸¶´Ù Á¢¼ÓÀ» ¸¸µå´Â ´ë½Å, ÀÌ ÇÁ·Î¼¼½º°¡ Á¾·áµÉ ¶§ ±îÁö »ì¾ÆÀÖ´Â ÇÑ °³ÀÇ Á¢¼Ó ¸¸À» »ç¿ëÇÑ´Ù. À̰ÍÀº ¸ðµç ¿µ±¸ÀûÀÎ Á¢¼ÓÀ» »ç¿ëÇÑ ÇÁ·Î¼¼½º´Â, ±×¿¡ ÇØ´çÇÏ´Â ÇÑ ´ëÀÇ ¿µ±¸ÀûÀÎ Á¢¼ÓÀ» °¡Áö°í ÀÖ´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù. ¿¹¸¦ µé¾î SQL ¼­¹ö¿¡ ´ëÇÏ¿© ¿µ±¸ÀûÀÎ Á¢¼ÓÀ» »ç¿ëÇÏ´Â ½ºÅ©¸³Æ®¸¦ ½ÇÇàÇÏ¿´´ø 20°³ÀÇ ´Ù¸¥ ÀÚ½Ä ÇÁ·Î¼¼½º°¡ ÀÖ´Ù¸é, ¾Æ¸¶µµ °¢°¢ÀÇ ÀÚ½Ä ÇÁ·Î¼¼½º¿¡´ëÇØ 1°³¾¿, 20°³ÀÇ SQL Á¢¼ÓÀÌ ÀÖÀ» °ÍÀÌ´Ù.

Áß¿äÇÑ ¿ä¾à ÇѰ¡Áö. ¿µ±¸ÀûÀÎ Á¢¼ÓÀº ÀϹÝÀûÀÎ Á¢¼Ó¿¡ 1´ë1·Î ´ëÀÀµÇµµ·Ï ¼³°èµÇ¾ú´Ù. À̰ÍÀº ½ºÅ©¸³Æ®ÀÇ ±â´ÉÀº ±×´ë·Î µÎ°í, ¾ðÁ¦¶óµµ ºñ¿µ±¸ÀûÀÎ ¿¬°áÀ» ¿µ±¸ÀûÀÎ ¿¬°á·Î ´ëÄ¡ÇÒ ¼ö ÀÖ´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù. À̰ÍÀ¸·Î ¿©·¯ºÐÀº ¾Æ¸¶µµ ½ºÅ©¸³Æ®ÀÇ È¿À²À» Çâ»ó½Ãų ¼ö ÀÖÀ» °ÍÀÌ´Ù.


IV. Function Reference

(¿ªÀÚÁÖ: ÀÌ Reference ºÎºÐÀº ºñ±³Àû °£´ÜÇÑ ³»¿ëµéÀ̰í, ³»¿ëÀÇ Á¤È®¼ºÀ» ±âÇϱâ À§ÇØ Æ¯º°ÇÑ °æ¿ì¸¦ Á¦¿ÜÇϰí´Â Á¦¸ñ ºÎºÐ¸¸ ¹ø¿ªÇÏ¿´´Ù.)

Table of Contents
I. Apache-specific functions
II. Arbitrary precision mathematics functions
III. Array functions
IV. Aspell functions
V. Calendar functions
VI. COM support functions for Windows
VII. Class/Object Functions
VIII. ClibPDF functions
IX. Cybercash payment functions
X. DOM XML functions
XI. Compression functions
XII. Database (dbm-style) abstraction layer functions
XIII. Date and Time functions
XIV. dBase functions
XV. dbm functions
XVI. Directory functions
XVII. Dynamic Loading functions
XVIII. Encryption functions
XIX. filePro functions
XX. Filesystem functions
XXI. Forms Data Format functions
XXII. FTP functions
XXIII. GNU Gettext
XXIV. Hash functions
XXV. HTTP functions
XXVI. Hyperwave functions
XXVII. Image functions
XXVIII. IMAP, POP3, and NNTP functions
XXIX. Informix functions
XXX. InterBase functions
XXXI. LDAP functions
XXXII. Mail functions
XXXIII. Mathematical functions
XXXIV. MCAL functions
XXXV. Microsoft SQL Server functions
XXXVI. Miscellaneous functions
XXXVII. mSQL functions
XXXVIII. MySQL functions
XXXIX. Network functions
XL. NIS functions
XLI. ODBC functions
XLII. Oracle functions
XLIII. Oracle 8 functions
XLIV. PDF functions
XLV. Perl-compatible Regular Expression functions
XLVI. PHP options & information
XLVII. POSIX functions
XLVIII. PostgreSQL functions
XLIX. Program Execution functions
L. GNU Recode functions
LI. Regular expression functions
LII. Semaphore and shared memory functions
LIII. Session handling functions
LIV. SNMP functions
LV. String functions
LVI. Shockwave Flash functions
LVII. Sybase functions
LVIII. URL functions
LIX. Variable functions
LX. Vmailmgr functions
LXI. WDDX functions
LXII. XML parser functions


I. Apache Specific functions

Table of Contents
apache_lookup_uri ¡¦ Perform a partial request for the specified URI and return all info about it
apache_note ¡¦ Get and set apache request notes
getallheaders ¡¦ Fetch all HTTP request headers
virtual ¡¦ Perform an Apache sub-request

apache_lookup_uri

apache_lookup_uri -- ƯÁ¤ URI¿¡ ´ëÇÑ ºÎºÐÀûÀÎ ¿äû(partial request)À» ¼öÇàÇÏ°í ±×°Í¿¡ ´ëÇÑ ¸ðµç Á¤º¸¸¦ µ¹·ÁÁØ´Ù.

Description

class apache_lookup_uri(string filename);

This performs a partial request for a URI. It goes just far enough to obtain all the important information about the given resource and returns this information in a class. The properties of the returned class are:

status

the_request

status_line

method

content_type

handler

uri

filename

path_info

args

boundary

no_cache

no_local_copy

allowed

send_bodyct

bytes_sent

byterange

clength

unparsed_uri

mtime

request_time

apache_note

apache_note -- apache request note¸¦ ¼³Á¤Çϰųª Àоî¿Â´Ù.

Description

string apache_note(string note_name, string [note_value]);

apache_note() is an Apache-specific function which gets and sets values in a request's notes table. If called with one argument, it returns the current value of note note_name. If called with two arguments, it sets the value of note note_name to note_value and returns the previous value of note note_name.

getallheaders

getallheaders -- ¸ðµç HTTP request header¸¦ ºÐ¼®ÇÏ¿© Àоî¿Â´Ù.

Description

array getallheaders(void);

This function returns an associative array of all the HTTP headers in the current request.

Example 1. getallheaders() Example

  1 
  2 $headers = getallheaders();
  3 while (list($header, $value) = each($headers)) {
  4     echo "$header: $value<br>\n";
  5 }
  6       

This example will display all the request headers for the current request.

Note: GetAllHeaders() ´Â PHP°¡ ¸ðµâ·Î ¼³Ä¡µÇ¾úÀ» °æ¿ì¸¸ µ¿ÀÛÇÑ´Ù.

virtual

virtual -- Apache sub-request¸¦ ¼öÇàÇÑ´Ù.

Description

int virtual(string filename);

virtual() is an Apache-specific function which is equivalent to <!--#include virtual...--> in mod_include. It performs an Apache sub-request. It is useful for including CGI scripts or .shtml files, or anything else that you would parse through Apache. Note that for a CGI script, the script must generate valid CGI headers. At the minimum that means it must generate a Content-type header. For PHP files, you need to use include() or require(); virtual() cannot be used to include a document which is itself a PHP file.

II. Arbitrary precision mathematics functions

ÀÌ BC ÇÔ¼öµéÀº PHP°¡ --enable-bcmath ¼³Á¤ ¿É¼ÇÀ¸·Î ÄÄÆÄÀÏ µÈ °æ¿ì¿¡¸¸ »ç¿ëÀÌ °¡´ÉÇÏ´Ù.

Table of Contents
bcadd ¡¦ Add two arbitrary precision numbers.
bccomp ¡¦ Compare two arbitrary precision numbers.
bcdiv ¡¦ Divide two arbitrary precision numbers.
bcmod ¡¦ Get modulus of an arbitrary precision number.
bcmul ¡¦ Multiply two arbitrary precision number.
bcpow ¡¦ Raise an arbitrary precision number to another.
bcscale ¡¦ Set default scale parameter for all bc math functions.
bcsqrt ¡¦ Get the square root of an arbitray precision number.
bcsub ¡¦ Subtract one arbitrary precision number from another.

bcadd

bcadd -- µÎ °³ÀÇ arbitrary precision number¸¦ ´õÇÑ´Ù.

Description

string bcadd(string left operand, string right operand, int [scale]);

Adds the left operand to the right operand and returns the sum in a string. The optional scale parameter is used to set the number of digits after the decimal place in the result.

See also bcsub().

bccomp

bccomp -- µÎ arbitrary precision numbers¸¦ ºñ±³ÇÑ´Ù.

Description

int bccomp(string left operand, string right operand, int [scale]);

Compares the left operand to the right operand and returns the result as an integer. The optional scale parameter is used to set the number of digits after the decimal place which will be used in the comparion. The return value is 0 if the two operands are equal. If the left operand is larger than the right operand the return value is +1 and if the left operand is less than the right operand the return value is -1.

bcdiv

bcdiv -- µÎ arbitrary precision number¸¦ ³ª´«´Ù.

Description

string bcdiv(string left operand, string right operand, int [scale]);

Divides the left operand by the right operand and returns the result. The optional scale sets the number of digits after the decimal place in the result.

See also bcmul().

bcmod

bcmod -- arbitrary precision numberÀÇ ³ª¸ÓÁö¸¦ ±¸ÇÑ´Ù.

Description

string bcmod(string left operand, string modulus);

Get the modulus of the left operand using modulus.

See also bcdiv().

bcmul

bcmul -- µÎ arbitrary precision number¸¦ °öÇÑ´Ù.

Description

string bcmul(string left operand, string right operand, int [scale]);

Multiply the left operand by the right operand and returns the result. The optional scale sets the number of digits after the decimal place in the result.

See also bcdiv().

bcpow

bcpow -- arbitrary precision numberÀÇ n Á¦°öÇÑ´Ù.

Description

string bcpow(string x, string y, int [scale]);

Raise x to the power y. The scale can be used to set the number of digits after the decimal place in the result.

See also bcsqrt().

bcscale

bcscale -- ¸ðµç bc ¼öÇÐ ÇÔ¼öÀÇ ±âº» scale parameter¸¦ Á¤ÇÑ´Ù.

Description

string bcscale(int scale);

This function sets the default scale parameter for all subsequent bc math functions that do not explicitly specify a scale parameter.

bcsqrt

bcsqrt -- arbitray precision numberÀÇ Á¦°ö±ÙÀ» ±¸ÇÑ´Ù.

Description

string bcsqrt(string operand, int scale);

Return the square root of the operand. The optional scale parameter sets the number of digits after the decimal place in the result.

See also bcpow().

bcsub

bcsub -- arbitrary precision number ¸¦ »«´Ù.

Description

string bcsub(string left operand, string right operand, int [scale]);

Subtracts the right operand from the left operand and returns the result in a string. The optional scale parameter is used to set the number of digits after the decimal place in the result.

See also bcadd().


III. Array functions

Table of Contents
array ¡¦ Create an array
array_count_values ¡¦ Counts all the values of an array
array_flip ¡¦ Flip all the values of an array
array_keys ¡¦ Return all the keys of an array
array_merge ¡¦ Merge two or more arrays
array_pad ¡¦ Pad array to the specified length with a value
array_pop ¡¦ Pop the element off the end of array
array_push ¡¦ Push one or more elements onto the end of array
array_reverse ¡¦ Return an array with elements in reverse order
array_shift ¡¦ Pop an element of the beginning of array
array_slice ¡¦ Extract a slice of the array
array_splice ¡¦ Remove a portion of the array and replace it with something else
array_unshift ¡¦ Push one or more elements onto the beginning of array
array_values ¡¦ Return all the values of an array
array_walk ¡¦ Apply a user function to every member of an array.
arsort ¡¦ Sort an array in reverse order and maintain index association
asort ¡¦ Sort an array and maintain index association
compact ¡¦ Create array containing variables and their values
count ¡¦ count elements in a variable
current ¡¦ return the current element in an array
each ¡¦ return next key/value pair from an array
end ¡¦ set internal pointer of array to last element
extract ¡¦ Import variables into the symbol table from an array
in_array ¡¦ Return true if a value exists in an array
key ¡¦ fetch a key from an associative array
krsort ¡¦ Sort an array by key in reverse order
ksort ¡¦ Sort an array by key.
list ¡¦ assign variables as if they were an array
next ¡¦ advance the internal array pointer
pos ¡¦ return the current element in an array
prev ¡¦ rewind internal array pointer
range ¡¦ Create an array containing a range of integers
reset ¡¦ set internal pointer of array to first element
rsort ¡¦ Sort an array in reverse order
shuffle ¡¦ Shuffle an array
sizeof ¡¦ get size of array
sort ¡¦ Sort an array
uasort ¡¦ Sort an array with a user-defined comparison function and maintain index association
uksort ¡¦ Sort an array by keys using a user-defined comparison function
usort ¡¦ Sort an array by values using a user-defined comparison function

array

array -- ¹è¿­À» ¸¸µç´Ù.

Description

array array(...);

Returns an array of the parameters. The parameters can be given an index with the => operator.

Note: array() is a language construct used to represent literal arrays, and not a regular function.

The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.

Example 1. array() example

  1 
  2 $fruits = array (
  3     "fruits"  => array("a"=>"orange", "b"=>"banana", "c"=>"apple"),
  4     "numbers" => array(1, 2, 3, 4, 5, 6),
  5     "holes"   => array("first", 5 => "second", "third")
  6 );
  7       

See also: list().

array_count_values

array_count_values -- ¹è¿­ÀÇ ¸ðµç °³°³ÀÇ °ªÀÇ °¹¼ö¸¦ ¼¾´Ù.

Description

array array_count_values(array input);

array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.

Example 1. array_count_values() example

  1 
  2 $array = array(1, "hello", 1, "world", "hello");
  3 array_count_values($array); // returns array(1=>2, "hello"=>2, "world"=>1)
  4       

Note: This function was added in PHP 4.0.

array_flip

array_flip -- ¹è¿­ °ªµéÀÇ ¼ø¼­¸¦ ¹Ý´ë·Î ÇÑ´Ù.

Description

array array_flip(array trans);

array_flip() returns an array in flip order.

Example 1. array_flip() example

  1 
  2 $trans = array_flip ($trans);
  3 $original = strtr ($str, $trans);
  4       

Note: This function was added in PHP 4.0.

array_keys

array_keys -- ¹è¿­ÀÇ ¸ðµç ۵éÀ» ¹ÝȯÇÑ´Ù,

Description

array array_keys(array input, mixed [search_value] );

array_keys() returns the keys, numeric and string, from the input array.

If the optional search_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the input are returned.

Example 1. array_keys() example

  1 
  2 $array = array(0 => 100, "color" => "red");
  3 array_keys ($array);       // returns array (0, "color")
  4 
  5 $array = array(1, 100, 2, 100);
  6 array_keys ($array, 100);  //  returns array (0, 2) 
  7       

See also array_values().

Note: This function was added in PHP 4.0.

array_merge

array_merge -- µÎ °³ ÀÌ»óÀÇ ¹è¿­À» Çϳª·Î ÇÕÄ£´Ù.

Description

array array_merge(array array1, array array2, [ ...] );

array_merge() merges the elements of two or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

If the input arrays had the same string keys, then the later value for that key will overwrite previous one. If, however, the arrays have the same numeric key, this does not happen since the values are appended.

Example 1. array_merge() example

  1 
  2 $array1 = array ("color" => "red", 2, 4);
  3 $array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid");
  4 array_merge ($array1, $array2);
  5       

Resulting array will be array("color" => "green", 2, 4, "a", "b", "shape" => "trapezoid").

Note: This function was added in PHP 4.0.

array_pad

array_pad -- ¹è¿­À» ÁÖ¾îÁø ±æÀ̸¸Å­ ÁÖ¾îÁø °ªÀ¸·Î ä¿î´Ù.

Description

array array_pad(array input, int pad_size, mixed pad_value);

array_pad() returns a copy of the input padded to size specified by pad_size with value pad_value. If pad_size is positive then the array is padded on the right, if it's negative then on the left. If the absolute value of pad_size is less than or equal to the length of the input then no padding takes place.

Example 1. array_pad() example

  1 
  2 $input = array (12, 10, 9);
  3 
  4 $result = array_pad ($input, 5, 0);
  5 // result is array (12, 10, 9, 0, 0)
  6 
  7 $result = array_pad ($input, -7, -1);
  8 // result is array (-1, -1, -1, -1, 12, 10, 9)
  9 
 10 $result = array_pad ($input, 2, "noop");
 11 // not padded
 12       

array_pop

array_pop -- ¹è¿­ÀÇ ¸Ç µÚ¿¡ ÀÖ´Â ¿ø¼Ò¸¦ ²¨³»°í ±× ¿ø¼Ò¸¦ »èÁ¦ÇÑ´Ù.

Description

mixed array_pop(array array);

array_pop() pops and returns the last value of the array, shortening the array by one element.

Example 1. array_pop() example

  1 
  2 $stack = array ("orange", "apple", "raspberry");
  3 $fruit = array_pop ($stack);
  4       

After this, $stack has only 2 elements: "orange" and "apple", and $fruit has "raspberry".

See also array_push(), array_shift(), and array_unshift().

Note: This function was added in PHP 4.0.

array_push

array_push -- ¹è¿­ÀÇ ¸Ç µÚ¿¡ ÇÑ °³³ª ±× ÀÌ»óÀÇ ¿ø¼Ò¸¦ ÷°¡ÇÑ´Ù.

Description

int array_push(array array, mixed var, [...] );

array_push() treats array as a stack, and pushes the passed variables onto the end of array. The length of array increases by the number of variables pushed. Has the same effect as:
  1 
  2 $array[] = $var;
  3      
repeated for each var.

Returns the new number of elements in the array.

Example 1. array_push() example

  1 
  2 $stack = array (1, 2);
  3 array_push($stack, "+", 3);
  4       
This example would result in $stack having 4 elements: 1, 2, "+", and 3.

See also array_pop(), array_shift(), and array_unshift().

Note: This function was added in PHP 4.0.

array_reverse

array_reverse -- ÁÖ¾îÁø ¹è¿­ÀÇ ¿ø¼ÒÀÇ ¼ø¼­¸¦ ¹Ý´ë·Î ÇÑ ¹è¿­À» µ¹·ÁÁØ´Ù.

Description

array array_reverse(array array);

array_reverse() takes input array and returns a new array with the order of the elements reversed.

Example 1. array_reverse() example

  1 
  2 $input = array ("php", 4.0, array ("green", "red"));
  3 $result = array_reverse ($input);
  4       
This makes $result have array (array ("green", "red"), 4.0, "php").

Note: This function was added in PHP 4.0 Beta 3.

array_shift

array_shift -- ¹è¿­ÀÇ ¸Ç ¾Õ¿¡ ÀÖ´Â ¿ø¼Ò¸¦ ²¨³»°í ±× ¿ø¼Ò¸¦ »èÁ¦ÇÑ´Ù.

Description

mixed array_shift(array array);

array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down.

Example 1. array_shift() example

  1 
  2 $args = array ("-v", "-f");
  3 $opt = array_shift ($args);
  4       
This would result in $args having one element "-f" left, and $opt being "-v".

See also array_unshift(), array_push(), and array_pop().

Note: This function was added in PHP 4.0.

array_slice

array_slice -- ¹è¿­ÀÇ ÀϺθ¦ ÃßÃâÇÑ´Ù.

Description

array array_slice(array array, int offset, int [length] );

array_slice() returns a sequence of elements from the array specified by the offset and length parameters.

If offset is positive, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.

If length is given and is positive, then the sequence will have that many elements in it. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.

Example 1. array_slice() examples

  1 
  2 $input = array ("a", "b", "c", "d", "e");
  3 
  4 $output = array_slice ($input, 2);      // returns "c", "d", and "e"
  5 $output = array_slice ($input, 2, -1);  // returns "c", "d"
  6 $output = array_slice ($input, -2, 1);  // returns "d"
  7 $output = array_slice ($input, 0, 3);   // returns "a", "b", and "c"
  8       

See also array_splice().

Note: This function was added in PHP 4.0.

array_splice

array_splice -- ¹è¿­ÀÇ ÀϺθ¦ »èÁ¦Çϰí, ±× À§Ä¡¿¡ ´Ù¸¥ ³»¿ëÀ» ³¢¿ö ³Ö´Â´Ù.

Description

array array_splice(array input, int offset, int [length] , array [replacement] );

array_splice() removed the elements designated by offset and length from the input array, and replaces them with the elements of the replacement array, if supplied.

If offset is positive then the start of removed portion is at that offset from the beginning of the input array. If offset is negative then it starts that far from the end of the input array.

If length is omitted, removes everything from offset to the end of the array. If length is specified and is positive, then that many elements will be removed. If length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. Tip: to remove everything from offset to the end of the array when replacement is also specified, use count($input) for length.

If replacement array is specified, then the removed elements are replaced with elements from this array. If offset and length are such that nothing is removed, then the elements from the replacement array are inserted in the place specified by the offset. Tip: if the replacement is just one element it is not necessary to put array() around it, unless the element is an array itself.

The following equivalences hold:
  1 
  2 array_push($input, $x, $y)     array_splice($input, count($input), 0, array($x, $y))
  3 array_pop($input)              array_splice($input, -1)
  4 array_shift($input)            array_splice($input, 0, 1)
  5 array_unshift($input, $x, $y)  array_splice($input, 0, 0, array($x, $y))
  6 $a[$x] = $y                    array_splice($input, $x, 1, $y)
  7      

Returns the array consisting of removed elements.

Example 1. array_splice() examples

  1 
  2 $input = array("red", "green", "blue", "yellow");
  3 
  4 array_splice($input, 2);      // $input is now array("red", "green")
  5 array_splice($input, 1, -1);  // $input is now array("red", "yellow")
  6 array_splice($input, 1, count($input), "orange");  
  7                               // $input is now array("red", "orange")
  8 array_splice($input, -1, 1, array("black", "maroon")); 
  9                               // $input is now array("red", "green", 
 10                               //          "blue", "black", "maroon")
 11       

See also array_slice().

Note: This function was added in PHP 4.0.

array_unshift

array_unshift -- ¹è¿­ÀÇ ¸Ç ¾Õ¿¡ ÇÑ °³³ª ±× ÀÌ»óÀÇ ¿ø¼Ò¸¦ ÷°¡ÇÑ´Ù.

Description

int array_unshift(array array, mixed var, [...] );

array_unshift() prepends passed elements to the front of the array. Note that the list of elements is prepended as a whole, so that the prepended elements stay in the same order.

Returns the new number of elements in the array.

Example 1. array_unshift() example

  1 
  2 $queue = array("p1", "p3");
  3 array_unshift($queue, "p4", "p5", "p6");
  4       
This would result in $queue having 5 elements: "p4", "p5", "p6", "p1", and "p3".

See also array_shift(), array_push(), and array_pop().

Note: This function was added in PHP 4.0.

array_values

array_values -- ¹è¿­ÀÇ ¸ðµç °ªµéÀ» ¹ÝȯÇÑ´Ù.

Description

array array_values(array input);

array_values() returns all the values from the input array.

Example 1. array_values() example

  1 
  2 $array = array("size" => "XL", "color" => "gold");
  3 array_values($array);    // returns array("XL", "gold")
  4       

Note: This function was added in PHP 4.0.

array_walk

array_walk -- ¹è¿­ÀÇ °³°³ÀÇ ¿ø¼Ò¿¡ ƯÁ¤ ÇÔ¼ö¸¦ Àû¿ëÇÏ¿© ¼öÇàÇÑ´Ù.

Description

int array_walk(array arr, string func, mixed userdata);

Applies the function named by func to each element of arr. func will be passed array value as the first parameter and array key as the second parameter. If userdata is supplied, it will be passed as the third parameter to the user function.

If func requires more than two or three arguments, depending on userdata, a warning will be generated each time array_walk() calls func. These warnings may be suppressed by prepending the '@' sign to the array_walk() call, or by using error_reporting().

Note: If func needs to be working with the actual values of the array, specify that the first parameter of func should be passed by reference. Then any changes made to those elements will be made in the array itself.

Note: Passing the key and userdata to func was added in 4.0.

In PHP 4 reset() needs to be called as necessary since array_walk() does not reset the array by default.

Example 1. array_walk() example

  1 
  2 $fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
  3 
  4 function test_alter (&$item1, $key, $prefix) {
  5    $item1 = "$prefix: $item1";
  6 }
  7 
  8 function test_print ($item2, $key) {
  9    echo "$key. $item2<br>\n";
 10 }
 11 
 12 array_walk ($fruits, 'test_print');
 13 reset ($fruits);
 14 array_walk ($fruits, 'test_alter', 'fruit');
 15 reset ($fruits);
 16 array_walk ($fruits, 'test_print');
 17       

See also each() and list().

arsort

arsort -- ¹è¿­À» ¿ª¼øÀ¸·Î Á¤·ÄÇϰí index associationÀ» À¯ÁöÇÑ´Ù.

Description

void arsort(array array);

This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant.

Example 1. arsort() example

  1 
  2 $fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
  3 arsort ($fruits);
  4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
  5     echo "fruits[$key] = ".$fruits[$key]."\n";
  6 }
  7       
This example would display: fruits[a] = orange fruits[d] = lemon fruits[b] = banana fruits[c] = apple The fruits have been sorted in reverse alphabetical order, and the index associated with each element has been maintained.

See also: asort(), rsort(), ksort(), and sort().

asort

asort -- ¹è¿­À» Á¤·ÄÇϰí index associationÀ» À¯ÁöÇÑ´Ù.

Description

 

void asort(array array);

This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant.

Example 1. asort() example

  1 
  2 $fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
  3 asort ($fruits);
  4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
  5     echo "fruits[$key] = ".$fruits[$key]."\n";
  6 }
  7       
This example would display: fruits[c] = apple fruits[b] = banana fruits[d] = lemon fruits[a] = orange The fruits have been sorted in alphabetical order, and the index associated with each element has been maintained.

See also arsort(), rsort(), ksort(), and sort().

compact

compact -- ÁÖ¾îÁø ¿©·¯ º¯¼öÀÇ À̸§°ú °ªÀ» °¡Áö´Â ¹è¿­À» ¸¸µç´Ù.

Description

array compact(string varname | array varnames, [...] );

compact() takes a variable number of parameters. Each parameter can be either a string containing the name of the variable, or an array of variable names. The array can contain other arrays of variable names inside it; compact() handles it recursively.

For each of these, compact() looks for a variable with that name in the current symbol table and adds it to the output array such that the variable name becomes the key and the contents of the variable become the value for that key. In short, it does the opposite of extract(). It returns the output array with all the variables added to it.

Example 1. compact() example

  1 
  2 $city = "San Francisco";
  3 $state = "CA";
  4 $event = "SIGGRAPH";
  5 
  6 $location_vars = array ("city", "state");
  7 
  8 $result = compact ("event", $location_vars);
  9       

After this, $result will be array ("event" => "SIGGRAPH", "city" => "San Francisco", "state" => "CA").

See also extract().

Note: This function was added in PHP 4.0.

count

count -- ¹è¿­ º¯¼öÀÇ ¿ø¼Ò °³¼ö¸¦ ±¸ÇÑ´Ù.

Description

int count(mixed var);

Returns the number of elements in var, which is typically an array (since anything else will have one element).

Returns 1 if the variable is not an array.

Returns 0 if the variable is not set.

Warning

count() may return 0 for a variable that isn't set, but it may also return 0 for a variable that has been initialized with an empty array. Use isset() to test if a variable is set.

See also: sizeof(), isset(), and is_array().

current

current -- ¹è¿­ÀÇ ÇöÀç ¿ø¼Ò¸¦ µ¹·ÁÁØ´Ù.

Description

mixed current(array array);

°¢°¢ÀÇ ¹è¿­ º¯¼ö´Â ±×°ÍÀÇ ¿ø¼Ò¸¦ °¡¸£Å°´Â ³»ºÎÀûÀÎ pointer¸¦ °¡Áö°í ÀÖ´Ù. °Ô´Ù°¡, ¹è¿­ÀÇ ¸ðµç ¿ø¼ÒµéÀº °Ë»öÀÌ ¿ëÀÌÇϵµ·Ï ¾ç¹æÇâ linked list·Î ¿¬°áµÇ¾î ÀÖ´Ù. ÀÌ ³»ºÎÀûÀÎ pointer´Â ´Ù¸¥ ¾î¶² Á¶ÀÛÀ» Çϱâ Àü¿¡´Â Ç×»ó ù ¹øÂ° ¿ä¼Ò¸¦ °¡¸£Å°°í ÀÖ´Ù.

current() ÇÔ¼ö´Â ´Ü¼øÈ÷ ³»ºÎÀûÀÎ Pointer°¡ °¡¸£Å°°í ÀÖ´Â ¿ø¼Ò¸¦ ¹ÝȯÇÒ »ÓÀÌ´Ù. ¸¸¾à ÀÌ pointer°¡ ¿ø¼Ò listÀÇ ¹üÀ§¸¦ ³Ñ¾î¼­ Áö½ÃÇϰí ÀÖ´Ù¸é current()´Â false¸¦ ¹ÝȯÇÑ´Ù.

Warning

current()´Â ÇöÀç ¿ø¼Ò°¡ 0À̳ª ""(ºó ¹®ÀÚ¿­)ÀÇ °ªÀ» °¡Áö°í ÀÖÀ¸¸é falseÀ» ¹ÝȯÇÑ´Ù. µû¶ó¼­ ÀÌ current() ÇÔ¼ö´Â ¿ø¼ÒÀÇ °ªÀÌ 0Àΰ¡ ¾Æ´Ï¸é ¹è¿­ÀÇ ¹üÀ§¸¦ ³Ñ¾ú´Â°¡¸¦ ÆÇ´ÜÇÒ ¼ö ¾ø´Ù. current()¸¦ »ç¿ëÇÑ loop ÄÚµùº¸´Ù´Â  each() ÇÔ¼ö¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ÁÁ´Ù.

See also: end(), next(), prev() and reset().

each

each -- ¹è¿­¿¡¼­ ´ÙÀ½ key/value ½ÖÀ» µ¹·ÁÁØ´Ù.

Description

array each(array array);

array ¹è¿­¿¡¼­ ´ÙÀ½ key/value ½ÖÀ» ¹ÝȯÇÑ´Ù. ÀÌ ½ÖÀº ³× °³ÀÇ ¿ø¼Ò¸¦ °¡Áø ¹è¿­·Î ¹ÝȯµÇ´Âµ¥ ÀÌ ³× °³ÀÇ ¿ø¼ÒÀÇ key´Â 0, 1, key, valueÀÌ´Ù. 0°ú key ¿ø¼Ò´Â °¢°¢ º¯¼öÀÇ key À̸§À» °¡Áö°í, 1°ú value´Â ±× °ªÀ» °¡Áö°í ÀÖ´Ù.

Example 1. each() examples

  1 
  2 $foo = array ("bob", "fred", "jussi", "jouni", "egon", "marliese");
  3 $bar = each ($foo);
  4       

$bar now contains the following key/value pairs:

  • 0 => 0
  • 1 => 'bob'
  • key => 0
  • value => 'bob'
  1 
  2 $foo = array ("Robert" => "Bob", "Seppo" => "Sepi");
  3 $bar = each ($foo);
  4        

$bar now contains the following key/value pairs:

  • 0 => 'Robert'
  • 1 => 'Bob'
  • key => 'Robert'
  • value => 'Bob'

º¸Åë each()´Â list() ÇÔ¼ö¿Í ÇÔ²² ¹è¿­À» Ž»öÇϴµ¥ »ç¿ëµÈ´Ù. ¿¹¸¦ µé¾î ´ÙÀ½°ú °°ÀÌ $HTTP_POST_VARS¿Í °°Àº ¹è¿­À» Ž»öÇϴµ¥ ¸¹ÀÌ »ç¿ëµÈ´Ù

Example 2. Traversing $HTTP_POST_VARS with each()

  1 
  2 echo "Values submitted via POST method:<br>";
  3 reset ($HTTP_POST_VARS);
  4 while (list ($key, $val) = each ($HTTP_POST_VARS)) {
  5     echo "$key => $val<br>";
  6 }
  7       

After each() has executed, the array cursor will be left on the next element of the array, or on the last element if it hits the end of the array.

See also key(), current(), reset(), next(), and prev().

end

end -- ¹è¿­ÀÇ ³»ºÎÀûÀÎ(internal) pointer¸¦ ¸Ç ¸¶Áö¸· ¿ø¼Ò·Î ¿Å±ä´Ù.

Description

end(array array);

end() advances array's internal pointer to the last element.

See also: current(), end() next() and reset()

extract

extract -- ¹è¿­ÀÇ ³»¿ëÀ» ½Éº¼ Å×À̺í·Î Àоîµé¿© ÀϹÝÀûÀÎ º¯¼ö·Î ¸¸µç´Ù.

Description

void extract(array var_array, int [extract_type] , string [prefix] );

This function is used to import variables from an array into the current symbol table. It takes associative array var_array and treats keys as variable names and values as variable values. For each key/value pair it will create a variable in the current symbol table, subject to extract_type and prefix parameters.

extract() checks for colissions with existing variables. The way collisions are treated is determined by extract_type. It can be one of the following values:

EXTR_OVERWRITE

If there is a collision, overwrite the existing variable.

EXTR_SKIP

If there is a collision, don't overwrite the existing variable.

EXTR_PREFIX_SAME

If there is a collision, prefix the new variable with prefix.

EXTR_PREFIX_ALL

Prefix all variables with prefix.

If extract_type is not specified, it is assumed to be EXTR_OVERWRITE.

Note that prefix is only required if extract_type is EXTR_PREFIX_SAME or EXTR_PREFIX_ALL.

extract() checks each key to see if it constitues a valid variable name, and if it does only then does it proceed to import it.

A possible use for extract is to import into symbol table variables contained in an associative array returned by wddx_deserialize().

Example 1. Extract() example

  1 
  2 <php?
  3 
  4 /* Suppose that $var_array is an array returned from
  5    wddx_deserialize */
  6 
  7 $size = "large";
  8 $var_array = array ("color" => "blue",
  9                     "size"  => "medium",
 10                     "shape" => "sphere");
 11 extract ($var_array, EXTR_PREFIX_SAME, "wddx");
 12 
 13 print "$color, $size, $shape, $wddx_size\n";
 14 
 15 ?>
 16       

The above example will produce:
  1 
  2 blue, large, sphere, medium
  3      

The $size wasn't overwritten, becaus we specified EXTR_PREFIX_SAME, which resulted in $wddx_size being created. If EXTR_SKIP was specified, then $wddx_size wouldn't even have been created. EXTR_OVERWRITE would have cause $size to have value "medium", and EXTR_PREFIX_ALL would result in new variables being named $wddx_color, $wddx_size, and $wddx_shape.

in_array

in_array -- ¹è¿­¿¡ ã´Â °ªÀÌ ÀÖÀ¸¸é true¸¦ ¹ÝȯÇÑ´Ù.

Description

bool in_array(mixed needle, array haystack);

Searches haystack for needle and returns true if it is found in the array, false otherwise.

Example 1. in_array() example

  1 
  2 $os = array ("Mac", "NT", "Irix", "Linux");
  3 if (in_array ("Irix", $os))
  4     print "Got Irix";
  5       

Note: This function was added in PHP 4.0.

key

key --¹è¿­(associative array)¿¡¼­ ³»ºÎÀûÀÎ(internal) pointer°¡ °¡¸®Å°°í ÀÖ´Â ¿ø¼ÒÀÇ key °ªÀ» °¡Á®¿Â´Ù.

Description

mixed prev(array array);

key() returns the index element of the current array position.

See also: current() next()

krsort

krsort -- key ¼øÀ¸·Î ¹è¿­À» Å«°Í¼­ ÀÛÀº¼ø¼­·Î Á¤·ÄÇÑ´Ù.

Description

int krsort(array array);

Sorts an array by key in reverse order, maintaining key to data correlations. This is useful mainly for associative arrays.

Example 1. krsort() example

  1 
  2 $fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
  3 krsort ($fruits);
  4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
  5     echo "fruits[$key] = ".$fruits[$key]."\n";
  6 }
  7       
This example would display: fruits[d] = lemon fruits[c] = apple fruits[b] = banana fruits[a] = orange

See also asort(), arsort(), ksort(), sort(), and rsort().

ksort

ksort -- key ¼øÀ¸·Î ¹è¿­À» Á¤·ÄÇÑ´Ù.

Description

int ksort(array array);

Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays.

Example 1. ksort() example

  1 
  2 $fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
  3 ksort ($fruits);
  4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
  5     echo "fruits[$key] = ".$fruits[$key]."\n";
  6 }
  7       
This example would display: fruits[a] = orange fruits[b] = banana fruits[c] = apple fruits[d] = lemon

See also asort(), arsort(), sort(), and rsort().

list

list -- º¯¼ö¸¦ ¹è¿­ÀÎ °Íó·³ ¸¸µç´Ù.

Description

void list(...);

Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.

Example 1. list() example

  1 
  2 <table>
  3  <tr>
  4   <th>Employee name</th>
  5   <th>Salary</th>
  6  </tr>
  7 
  8 <?php
  9 
 10 $result = mysql($conn, "SELECT id, name, salary FROM employees");
 11 while (list($id, $name, $salary) = mysql_fetch_row($result)) {
 12     print(" <tr>\n".
 13           "  <td><a href=\"info.php3?id=$id\">$name</a></td>\n".
 14           "  <td>$salary</td>\n".
 15           " </tr>\n");
 16 }
 17 
 18 ?>
 19 
 20 </table>
 21       

See also: array().

next

next -- ¹è¿­ÀÇ internal pointer¸¦ Çϳª ÀüÁø½ÃŲ´Ù.

Description

mixed next(array array);

Returns the array element in the next place that's pointed by the internal array pointer, or false if there are no more elements.

next() behaves like current(), with one difference. It advances the internal array pointer one place forward before returning the element. That means it returns the next array element and advances the internal array pointer by one. If advancing the internal array pointer results in going beyond the end of the element list, next() returns false.

Warning

If the array contains empty elements then this function will return false for these elements as well. To properly traverse an array which may contain empty elements see the each() function.

See also: current(), end() prev() and reset()

pos

pos -- ¹è¿­ÀÇ ÇöÀç ¿ø¼Ò¸¦ returnÇÑ´Ù.

Description

mixed pos(array array);

This is an alias for current().

See also: end(), next(), prev() and reset().

prev

prev -- ¹è¿­ÀÇ internal pointer¸¦ Çϳª µÚ·Î ÈÄÁø½ÃŲ´Ù.

Description

mixed prev(array array);

Returns the array element in the previous place that's pointed by the internal array pointer, or false if there are no more elements.

Warning

If the array contains empty elements then this function will return false for these elements as well. To properly traverse an array which may contain empty elements see the each() function.

prev() behaves just like next(), except it rewinds the internal array pointer one place instead of advancing it.

See also: current(), end() next() and reset()

range

range -- ÀÏÁ¤ ¹üÀ§¿¡ ÀÖ´Â Á¤¼ö°ªÀ» ÀÏ·Ä·Î °¡Áø ¹è¿­À» ¸¸µç´Ù.

Description

array range(int low, int high);

range() returns an array of integers from low to high, inclusive.

ÀÌ ÇÔ¼öÀÇ »ç¿ë ¿¹´Â shuffle()¿¡ ³ª¿ÍÀÖ´Ù.

reset

reset -- ¹è¿­ÀÇ internal pointer¸¦ ¸Ç óÀ½ ¿ø¼Ò·Î ¼³Á¤ÇÑ´Ù.

Description

mixed reset(array array);

reset() rewinds array's internal pointer to the first element.

reset() returns the value of the first array element.

See also: current(), next() prev() and reset()

rsort

rsort -- ¹è¿­À» ¿ª¼øÀ¸·Î Á¤·ÄÇÑ´Ù.

Description

void rsort(array array);

This function sorts an array in reverse order (highest to lowest).

Example 1. rsort() example

  1 
  2 $fruits = array ("lemon", "orange", "banana", "apple");
  3 rsort ($fruits);
  4 for (reset ($fruits); list ($key, $value) = each ($fruits); ) {
  5     echo "fruits[$key] = ", $value, "\n";
  6 }
  7       
This example would display: fruits[0] = orange fruits[1] = lemon fruits[2] = banana fruits[3] = apple The fruits have been sorted in reverse alphabetical order.

See also arsort(), asort(), ksort(), and sort().

shuffle

shuffle -- ¹è¿­ÀÇ ³»¿ëÀ» µÚ¼¯´Â´Ù.

Description

void shuffle(array array);

This function shuffles (randomizes the order of the elements in) an array.

Example 1. shuffle() example

  1 
  2 $numbers = range (1,20);
  3 srand (time());
  4 shuffle ($numbers);
  5 while (list(, $number) = each ($numbers)) {
  6     echo "$number ";
  7 }
  8       

See also arsort(), asort(), ksort(), rsort(), sort() and usort().

sizeof

sizeof -- ¹è¿­ÀÇ Å©±â¸¦ ±¸ÇÑ´Ù. ¿ø¼ÒÀÇ °³¼ö°¡ ±¸ÇØÁø´Ù.

Description

int sizeof(array array);

Returns the number of elements in the array.

See also: count()

sort

sort -- ¹è¿­À» Á¤·ÄÇÑ´Ù.

Description

void sort(array array);

This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.

Example 1. sort() example

  1 
  2 $fruits = array ("lemon", "orange", "banana", "apple");
  3 sort ($fruits);
  4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
  5     echo "fruits[$key] = ".$fruits[$key]."\n";
  6 }
  7       
This example would display: fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange The fruits have been sorted in alphabetical order.

 See also arsort(), asort(), ksort(), rsort(), and usort().

uasort

uasort -- »ç¿ëÀÚ°¡ ÁöÁ¤ÇÑ ºñ±³ ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© Á¤·ÄÇϰí index associationÀ» À¯ÁöÇÑ´Ù.

Description

void uasort(array array, function cmp_function);

This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. The comparison function is user-defined.

uksort

uksort -- »ç¿ëÀÚ°¡ ÁöÁ¤ÇÑ ºñ±³ ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© key ¼øÀ¸·Î Á¤·ÄÇÑ´Ù.

Sort an array by keys using a user-defined comparison function

Description

void uksort(array array, function cmp_function);

This function will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.

Example 1. uksort() example

  1 
  2 function mycompare ($a, $b) {   
  3     if ($a == $b) return 0;
  4     return ($a > $b) ? -1 : 1;
  5 }
  6 $a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
  7 uksort ($a, mycompare);
  8 while (list ($key, $value) = each ($a)) {
  9     echo "$key: $value\n";
 10 }
 11       
This example would display: 20: twenty 10: ten 4: four 3: three

See also arsort(), asort(), uasort(), ksort(), rsort() and sort().

usort

usort -- »ç¿ëÀÚ°¡ ÁöÁ¤ÇÑ ºñ±³ ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© value ¼øÀ¸·Î Á¤·ÄÇÑ´Ù.

Description

 void usort(array array, function cmp_function);

This function will sort an array by its values using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.

The comparison function 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. If two members compare as equal, their order in the sorted array is undefined.

Example 1. usort() example

  1 
  2 function cmp ($a, $b) {   
  3     if ($a == $b) return 0;
  4     return ($a > $b) ? -1 : 1;
  5 }
  6 $a = array (3, 2, 5, 6, 1);
  7 usort ($a, cmp);
  8 while (list ($key, $value) = each ($a)) {
  9     echo "$key: $value\n";
 10 }
 11       
This example would display: 0: 6 1: 5 2: 3 3: 2 4: 1

Note: Obviously in this trivial case the rsort() function would be more appropriate.

Warning

The underlying quicksort function in some C libraries (such as on Solaris systems) may cause PHP to crash if the comparison function does not return consistent values.

See also arsort(), asort(), ksort(), rsort() and sort().


IV. Aspell functions

aspell() ÇÔ¼öµéÀº ¿©·¯ºÐ¿¡°Ô ´Ü¾îÀÇ Ã¶ÀÚ¸¦ °Ë»çÇÏ°í ¼öÁ¤»çÇ×À» Á¶¾ðÇØ ÁØ´Ù.

ÀÌ ÇÔ¼öµéÀ» »ç¿ëÇÏ·Á¸é aspell ¶óÀ̺귯¸®°¡ ÇÊ¿äÇÏ´Ù. ´ÙÀ½ »çÀÌÆ®¿¡¼­ ãÀ» ¼ö ÀÖÀ» °ÍÀÌ´Ù. : http://metalab.unc.edu/kevina/aspell/

Table of Contents
aspell_new ¡¦ load a new dictionary
aspell_check ¡¦ check a word
aspell_check-raw ¡¦ check a word without changing its case or trying to trim it
aspell_suggest ¡¦ suggest spellings of a word

aspell_new

aspell_new -- »õ »çÀüÀ» ÀÐ¾î ¿Â´Ù.

Description

int aspell_new(string master, string personal);

aspell_new() opens up a new dictionary and returns the dictionary link identifier for use in other aspell functions.

Example 1. aspell_new

  1 
  2 $aspell_link=aspell_new("english");
  3       

aspell_check

aspell_check -- ´Ü¾î¸¦ °Ë»çÇÑ´Ù.

Description

boolean aspell_check(int dictionary_link, string word);

aspell_check() checks the spelling of a word and returns true if the spelling is correct, false if not.

Example 1. aspell_check

  1 
  2 $aspell_link=aspell_new("english");
  3 if (aspell_check($aspell_link,"testt")) {
  4     echo "This is a valid spelling";
  5 } else {
  6     echo "Sorry, wrong spelling";
  7 }
  8       

aspell_check-raw

aspell_check-raw -- ´Ü¾îÀÇ ´ë/¼Ò¹®ÀÚ¸¦ º¯È¯ÇÏÁö ¾Ê°í, ¾ÕµÚÀÇ °ø¹éµµ Á¦°ÅÇÏÁö ¾ÊÀº ä·Î °Ë»çÇÑ´Ù.

Description

boolean aspell_check_raw(int dictionary_link, string word);

aspell_check_raw() checks the spelling of a word, without changing its case or trying to trim it in any way and returns true if the spelling is correct, false if not.

Example 1. aspell_check_raw

  1 
  2 $aspell_link=aspell_new("english");
  3 if (aspell_check_raw($aspell_link,"testt")) {
  4     echo "This is a valid spelling";
  5 } else {
  6     echo "Sorry, wrong spelling";
  7 }
  8       

aspell_suggest

aspell_suggest -- ´Ü¾îÀÇ Ã¶ÀÚ¸¦ Á¶¾ðÇØ ÁØ´Ù.

Description

array aspell_suggest(int dictionary_link, string word);

aspell_suggest() returns an array of possible spellings for the given word.

Example 1. aspell_suggest

  1 
  2 $aspell_link=aspell_new("english");
  3 
  4 if (!aspell_check($aspell_link,"testt")) {
  5     $suggestions=aspell_suggest($aspell_link,"testt");
  6 
  7     for($i=0; $i < count($suggestions); $i++) {
  8        echo "Possible spelling: " . $suggestions[$i] . "<br>"; 
  9     }
 10 }
 11       


V. Calendar functions

PHP¿¡´Â ¼­·Î ´Ù¸¥ ³¯Â¥(´Þ·Â) ÇüŸ¦ º¯È¯½ÃÄÑ ÁÖ´Â ÇÔ¼öµéÀ» Á¦°øÇÑ´Ù. Julian Day Count°¡ ±âº»ÀÌ µÈ´Ù. À̰ÍÀº BC4000³âÀÇ ¾î´À ½ÃÁ¡À» ±âÁØÀ¸·Î Àâ¾Æ ±×°÷¿¡¼­ºÎÅÍ ¾ó¸¶ÀÇ ³¯Â¥°¡ Áö³µ´ÂÁö¸¦ ±âÁØÀ¸·Î »ï´Â °ÍÀÌ´Ù. ÀÌ Julian Day Count´Â ÀϹÝÀûÀ¸·Î »ç¿ëÇÏ´Â Julian ´Þ·Â°ú´Â ´Ù¸£´Ù´Â °ÍÀ» ¾Ë¾ÆµÎÀÚ. Calendar ½Ã½ºÅÛ¿¡ ´ëÇØ ÀÚ¼¼È÷ ¾Ë°í ½Í´Ù¸é http://genealogy.org/~scottlee/cal-overview.html¸¦ ¹æ¹®ÇÏ¿© º¸¶ó. ÀÌ ¼³¸í¼­Áß¿¡¼­´Â À§ÀÇ ÆäÀÌÁö¿¡¼­ ¹ßÃéµÈ ³»¿ëÀ» ""·Î µÑ·¯ ½Î°í ÀÖ´Ù.

( ¿ªÀÚÁÖ : ÀÌ ÇÔ¼öµéÀº dl/calender extensionÀ» LoadÇÑ ÈÄ¿¡ »ç¿ë°¡´ÉÇÏ´Ù. dl/README ÆÄÀÏÀ» Àо¶ó. )

Table of Contents
JDToGregorian ¡¦ Converts Julian Day Count to Gregorian date
GregorianToJD ¡¦ Converts a Gregorian date to Julian Day Count
JDToJulian ¡¦ Converts a Julian Calendar date to Julian Day Count
JulianToJD ¡¦ Converts a Julian Calendar date to Julian Day Count
JDToJewish ¡¦ Converts a Julian Day Count to the Jewish Calendar
JewishToJD ¡¦ Converts a date in the Jewish Calendar to Julian Day Count
JDToFrench ¡¦ Converts a Julian Day Count to the French Republican Calendar
FrenchToJD ¡¦ Converts a date from the French Republican Calendar to a Julian Day Count
JDMonthName ¡¦ Returns a month name
JDDayOfWeek ¡¦ Returns the day of the week
easter_date ¡¦ get UNIX timestamp for midnight on Easter of a given year
easter_days ¡¦ get number of days after March 21 on which Easter falls for a given year

JDToGregorian

JDToGregorian -- Julian Day Count¸¦ Gregorian date·Î º¯È¯

Description

string jdtogregorian(int julianday);

Converts Julian Day Count to a string containing the Gregorian date in the format of "month/day/year"

GregorianToJD

GregorianToJD -- Gregorian date¸¦ Julian Day Count·Î º¯È¯

Description

int gregoriantojd(int month, int day, int year);

Valid Range for Gregorian Calendar 4714 B.C. to 9999 A.D.

Although this software can handle dates all the way back to 4714 B.C., such use may not be meaningful. The Gregorian calendar was not instituted until October 15, 1582 (or October 5, 1582 in the Julian calendar). Some countries did not accept it until much later. For example, Britain converted in 1752, The USSR in 1918 and Greece in 1923. Most European countries used the Julian calendar prior to the Gregorian.

Example 1. Calendar functions

  1 
  2 <?php
  3 $jd = GregorianToJD(10,11,1970);
  4 echo("$jd\n");
  5 $gregorian = JDToGregorian($jd);
  6 echo("$gregorian\n");
  7 ?>
  8 

JDToJulian

JDToJulian -- Julian Day Count¸¦ Julian Calendar date·Î º¯È¯

Description

string jdtojulian(int julianday);

Converts Julian Day Count to a string containing the Julian Calendar Date in the format of "month/day/year".

JulianToJD

JulianToJD -- Julian Calendar date¸¦ Julian Day Count·Î º¯È¯

Description

int juliantojd(int month, int day, int year);

Valid Range for Julian Calendar 4713 B.C. to 9999 A.D.

Although this software can handle dates all the way back to 4713 B.C., such use may not be meaningful. The calendar was created in 46 B.C., but the details did not stabilize until at least 8 A.D., and perhaps as late at the 4th century. Also, the beginning of a year varied from one culture to another - not all accepted January as the first month.

JDToJewish

JDToJewish -- Julian Day Count¸¦ the À¯´ë Calendar·Î º¯È¯.

Description

string jdtojewish(int julianday);

Converts a Julian Day Count the the Jewish Calendar.

JewishToJD

JewishToJD -- À¯´ë Calendar¸¦ Julian Day Count·Î º¯È¯.

Description

int jewishtojd(int month, int day, int year);

Valid Range Although this software can handle dates all the way back to the year 1 (3761 B.C.), such use may not be meaningful.

The Jewish calendar has been in use for several thousand years, but in the early days there was no formula to determine the start of a month. A new month was started when the new moon was first observed.

JDToFrench

JDToFrench -- Julian Day Count¸¦ French Republican Calendar·Î º¯È¯.

Description

string jdtofrench(int month, int day, int year);

Converts a Julian Day Count to the French Republican Calendar.

FrenchToJD

FrenchToJD -- French Republican Calendar¸¦ Julian Day Count·Î º¯È¯.

Description

int frenchtojd(int month, int day, int year);

Converts a date from the French Republican Calendar to a Julian Day Count

These routines only convert dates in years 1 through 14 (Gregorian dates 22 September 1792 through 22 September 1806). This more than covers the period when the calendar was in use.

JDMonthName

JDMonthName -- ¿ùÀÇ À̸§À» ¹Ýȯ

Description

string jdmonthname(int julianday, int mode);

Returns a string containing a month name. mode tells this function which calendar to convert the Julian Day Count to, and what type of month names are to be returned.

Table 1. Calendar modes

Mode

Meaning

0

Gregorian - apreviated

1

Gregorian

2

Julian - apreviated

3

Julian

4

Jewish

5

French Republican

JDDayOfWeek

JDDayOfWeek -- ÇØ´ç ³¯Â¥ÀÇ ¿äÀÏÀ» ¹ÝȯÇÑ´Ù.

Description

mixed jddayofweek(int julianday, int mode);

Returns the day of the week. Can return a string or an int depending on the mode.

Table 1. Calendar week modes

Mode

Meaning

0

returns the day number as an int (0=sunday, 1=monday, etc)

1

returns string containing the day of week (english-gregorian)

2

returns a string containing the abreviated day of week (english-gregorian)

easter_date

easter_date -- ÁÖ¾îÁø ¿¬µµÀÇ ºÎȰÀýÀÇ ÀÚÁ¤¿¡ ´ëÇÑ UNIX timestamp¸¦ ¾ò´Â´Ù.

Description

int easter_date(int year);

Returns the UNIX timestamp corresponding to midnight on Easter of the given year. If no year is specified, the current year is assumed.

Warning: This function will generate a warning if the year is outside of the range for UNIX timestamps (i.e. before 1970 or after 2037).

Example 1. easter_date() example

  1 
  2 echo date( "M-d-Y", easter_date(1999) );        /* "Apr-04-1999" */
  3 echo date( "M-d-Y", easter_date(2000) );        /* "Apr-23-2000" */
  4 echo date( "M-d-Y", easter_date(2001) );        /* "Apr-15-2001" */
  5 

The date of Easter Day was defined by the Council of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. The Equinox is assumed to always fall on 21st March, so the calculation reduces to determining the date of the full moon and the date of the following Sunday. The algorithm used here was introduced around the year 532 by Dionysius Exiguus. Under the Julian Calendar (for years before 1753) a simple 19-year cycle is used to track the phases of the Moon. Under the Gregorian Calendar (for years after 1753 - devised by Clavius and Lilius, and introduced by Pope Gregory XIII in October 1582, and into Britain and its then colonies in September 1752) two correction factors are added to make the cycle more accurate.

(The code is based on a C program by Simon Kershaw, <webmaster@ely.anglican.org>)

See easter_days() for calculating Easter before 1970 or after 2037.

easter_days

easter_days -- ÁÖ¾îÁø ¿¬µµÀÇ ºÎȰÀýÀÌ 3¿ù 21ÀϷκÎÅÍ ¸çÄ¥ÀÌ Áö³­ °ÍÀÎÁö¸¦ ¾ò´Â´Ù.

Description

int easter_days(int year);

Returns the number of days after March 21 on which Easter falls for a given year. If no year is specified, the current year is assumed.

This function can be used instead of easter_date() to calculate Easter for years which fall outside the range of UNIX timestamps (i.e. before 1970 or after 2037).

Example 1. easter_date() example

  1 
  2 echo easter_days(1999);        /* 14, i.e. April 4   */
  3 echo easter_days(1492);        /* 32, i.e. April 22  */
  4 echo easter_days(1913);        /*  2, i.e. March 23  */
  5 

The date of Easter Day was defined by the Council of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. The Equinox is assumed to always fall on 21st March, so the calculation reduces to determining the date of the full moon and the date of the following Sunday. The algorithm used here was introduced around the year 532 by Dionysius Exiguus. Under the Julian Calendar (for years before 1753) a simple 19-year cycle is used to track the phases of the Moon. Under the Gregorian Calendar (for years after 1753 - devised by Clavius and Lilius, and introduced by Pope Gregory XIII in October 1582, and into Britain and its then colonies in September 1752) two correction factors are added to make the cycle more accurate.

(The code is based on a C program by Simon Kershaw, <webmaster@ely.anglican.org>)

See also easter_date().


VI. COM support functions for Windows

ÀÌ ÇÔ¼öµéÀº À©µµ¿ì ¹öÀüÀÇ PHP¿¡¼­¸¸ ÀÛµ¿ÇÑ´Ù. ÀÌ ÇÔ¼öµéÀº PHP4¿¡¼­ Ãß°¡µÇ¾ú´Ù.

Table of Contents
com_load ¡¦ ???
com_invoke ¡¦ ???
com_propget ¡¦ ???
com_get ¡¦ ???
com_propput ¡¦ ???
com_propset ¡¦ ???
com_set ¡¦ ???

com_load

(PHP3 >= 3.0.3, PHP4 )

com_load -- ???

Description

string com_load (string module name [, string server name])

com_invoke

(PHP3 >= 3.0.3, PHP4 )

com_invoke -- ???

Description

mixed com_invoke (resource object, string function_name [, mixed function parameters, ...])

com_propget

(PHP3 >= 3.0.3, PHP4 )

com_propget -- ???

Description

mixed com_propget (resource object, string property)

com_get

(PHP3 >= 3.0.3, PHP4 )

com_get -- ???

Description

mixed com_get (resource object, string property)

com_propput

(PHP3 >= 3.0.3, PHP4 )

com_propput -- ???

Description

void com_propput (resource object, string property, mixed value)

com_propset

(PHP3 >= 3.0.3, PHP4 )

com_propset -- ???

Description

void com_propset (resource object, string property, mixed value)

This function is an alias for com_propput().

com_set

(PHP3 >= 3.0.3, PHP4 )

com_set -- ???

Description

void com_set (resource object, string property, mixed value)

This function is an alias for com_set().


VII. Class/Object Functions

Table of Contents
get_class_methods ¡¦ Returns an array of class methods' names
get_class_vars ¡¦ Returns an array of default properties of the class
get_object_vars ¡¦ Returns an array of object properties
method_exists ¡¦ Checks if the class method exists

get_class_methods

(PHP4 >= 4.0RC1)

get_class_methods -- Å¬·¡½ºÀÇ methods À̸§À» ¹è¿­·Î ¹ÝȯÇÑ´Ù.

Description

array get_class_methods (string class_name)

This function returns an array of method names defined for the class specified by class_name.

get_class_vars

(PHP4 >= 4.0RC1)

get_class_vars -- Å¬·¡½ºÀÇ default properties À̸§À» ¹è¿­·Î ¹ÝȯÇÑ´Ù.

Returns an array of default properties of the class

Description

array get_class_vars (string class_name)

This function will return an array of default properties of the class.

get_object_vars

(PHP4 >= 4.0RC1)

get_object_vars -- °´Ã¼(object)ÀÇ properties¸¦ ¹è¿­·Î ¹ÝȯÇÑ´Ù.

Description

array get_class_vars (object obj)

This function returns an array of object properties for the specified object obj.

method_exists

(PHP4 >= 4.0b2)

method_exists -- ÇØ´ç Ŭ·¡½ºÀÇ method °¡ Á¸ÀçÇϴ°¡¸¦ °Ë»çÇÑ´Ù.

Checks if the class method exists

Description

bool method_exists (object object, string method_name)

This function returns true if the method given by method_name has been defined for the given object, false otherwise.


VIII. ClibPDF functions

ClibPDF´Â PHP¿¡¼­ pdf ¹®¼­¸¦ ¸¸µé ¼ö ÀÖ°Ô ÇØ ÁØ´Ù. À̰ÍÀº FastIO¿¡¼­ ±¸ÇÒ ¼ö ÀÖÀ¸³ª ¹«·á(free software)´Â ¾Æ´Ï´Ù. ¿©·¯ºÐÀº ClibPDF¸¦ »ç¿ëÇϱâ Àü¿¡ ¶óÀ̼¾½º¸¦ ÀÚ¼¼È÷ ÀоîºÁ¾ß ÇÒ °ÍÀÌ´Ù. ¸¸¾à ¿©·¯ºÐÀÌ ÀÌ ¶óÀ̼¾½º¿¡ µ¿ÀÇÇϱ⸦ ¿øÇÏÁö ¾ÊÀ¸¸é Thomas MerzÀÇ pdflibÀÇ »ç¿ëÀ» °í·Á ÇÒ ¼öµµ ÀÖ´Ù. pdflibµµ ¿ª½Ã °­·ÂÇÑ ±â´ÉÀ» °¡Áö°í ÀÖ´Ù. ClibPDF´Â Thomas MerzÀÇ pdflib¿Í ±â´ÉÀ̳ª API°¡ ¸Å¿ì À¯»çÇÏÁö¸¸, FastIO¿¡ µû¸£¸é ClibPDF´Â ¹®¼­¸¦ ´õ ÀÛÀº Å©±â·Î ´õ ºü¸£°Ô ¸¸µé ¼ö ÀÖ´Ù°í ÇÑ´Ù. ClibPDF´Â pdflib »õ·Î¿î 2.0 ¹öÀü¿¡¼­ º¯È­µÈ °Í °°´Ù. °£´ÜÇÑ ¿¹Á¦(pdflib 2.0ÀÇ pdfclock.c¸¦ php ½ºÅ©¸³Æ®·Î °íÄ£ °Í)¿¡¼­´Â ½ÇÁúÀûÀÎ ¼ÓµµÀÇ Â÷ÀÌ´Â ¾ø¾ú´Ù. ¶ÇÇÑ ¾ÐÃà±â´ÉÀ» ²¨ ³õÀ¸¸é µÎ °³ÀÇ ÆÄÀÏ Å©±âµµ ºñ½ÁÇÏ´Ù.

¿©±âÀÇ ¼³¸éÀº ClibPDFÀÇ ¸Å´º¾ó°ú °°ÀÌ Àд °ÍÀÌ ÁÁÀ» °ÍÀÌ´Ù. ÀÌ ¸Å´º¾óÀº ¶óÀ̺귯¸®¿¡ ´ëÇÑ ´õ ÀÚ¼¼ÇÑ ¼³¸íÀ» Çϰí ÀÖ´Ù. ClibPDFÀÇ ¸Å´º¾óÀÇ ³»¿ëÀ» ÀÌÇØ¿©¾ß ¿©·¯ºÐÀº PHP¿¡¼­ ÀÌ ¶óÀ̺귯¸®¸¦ »ç¿ëÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù.

´ëºÎºÐÀÇ PHP ¸ðµâÀÇ ÇÔ¼öÀ̸§Àº ClibPDF °íÀ¯ÀÇ ÇÔ¼ö(pdflibµµ ¸¶Âù°¡Áö°í) À̸§°ú µ¿ÀÏÇÏ´Ù. cpdf_open() À» Á¦¿ÜÇÑ ¸ðµç ÇÔ¼öµéÀº ù ¹øÂ° Àμö·Î ÀÛ¾÷ÇÒ ¹®¼­ÀÇ ÇÚµéÀ» °¡Áö°Ô µÈ´Ù. ÇöÀç ClibPDF°¡ µ¿½Ã¿¡ ¿©·¯°³ÀÇ PDF ¹®¼­¸¦ ¸¸µéÁö ¸øÇϱ⠶§¹®¿¡ ÀÌ ÇÚµéÀº ³»ºÎÀûÀ¸·Î ¾Æ¹« Àǹ̰¡ ¾ø´Ù. ±×·¯³ª À̸¦ ½ÃÇèÇÏÁö´Â ¸»¶ó. ¾î¶² °á°ú°¡ ³ª¿ÃÁö ¾Ë ¼ö ¾ø´Ù. ´õ±¸³ª ¸ÖƼ ¾²·¹µå ȯ°æ¿¡¼­´Â Áß´ëÇÑ ¿À·ù°¡ »ý±æ ¼öµµ ÀÖ´Ù. ClibPDFÀÇ Á¦ÀÛÀÚ¿¡ µû¸£¸é ÀÌ ³»¿ëÀº ´ÙÀ½ ¹öÀü¿¡¼­ ¼öÁ¤µÉ °ÍÀ̶ó°í ÇÑ´Ù.(ÇöÀç ¹öÀüÀº 1.10ÀÌ´Ù.) ¿©·¯¹®¼­¸¦ µ¿½Ã¿¡ ¸¸µå´Â ±â´ÉÀÌ ÇÊ¿äÇÏ´Ù¸é pdflib moduleÀ» »ç¿ëÇϵµ·Ï Ç϶ó.

pdflib¿¡ ºñÇØ¼­ ClibPDFÀÇ °¡Àå Å« ÀåÁ¡Àº pdf ¹®¼­¸¦ Àӽà ÆÄÀÏÀ» »ç¿ëÇÏÁö ¾Ê°í ¸Þ¸ð¸® »ó¿¡¼­ ¸¸µé ¼ö ÀÖ´Ù´Â Á¡ÀÌ´Ù. ¶ÇÇÑ ClibPDF´Â ¹Ì¸® Á¤ÀÇµÈ À¯´Ö ±æÀÌÀÇ ÁÂÇ¥¸¦ ³Ñ°ÜÁÙ ¼ö ÀÖ´Ù. À̰ÍÀº ¸ÅÀ¯ Æí¸®ÇÑ ±â´ÉÀÌÁö¸¸ pdflib¿¡¼­µµ pdf_translate()¸¦ »ç¿ëÇÏ¸é ºñ½ÁÇÑ ±â´ÉÀ» ÇÒ ¼ö ÀÖ´Ù.

´ëºÎºÐÀÇ ÇÔ¼öµéÀº »ç¿ëÇϱ⠽±´Ù. °£´ÜÇÑ pdf ¹®¼­¸¦ Çϳª ¸¸µé¾îº¸¸é º°·Î ¾î·ÆÁö ¾Ê´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖÀ» °ÍÀÌ´Ù. ´ÙÀ½ ¿¹¸¦ º¸¸é ½±°Ô ½ÃÀÛÇÒ ¼ö ÀÖ´Ù. À̰ÍÀº ÇÑ ÀåÂ¥¸® test.pdf¶ó´Â ÆÄÀÏÀ» ¸¸µå´Â °ÍÀÌ´Ù. ÀÌ ÆäÀÌÁö¿¡´Â ¿Ü°û¼± 30ptÀÇ "Times-Roman" ÆùÆ®ÀÇ text°¡ ¾²¿©Áø´Ù. ÀÌ text´Â ¹ØÁÙÀÌ ±×¾îÁø´Ù.

Example 1. Simple ClibPDF Example

  1 
  2 <?php
  3 $cpdf = cpdf_open(0);
  4 cpdf_page_init($cpdf, 1, 0, 595, 842);
  5 cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1");
  6 cpdf_set_font($cpdf, "Times-Roman", 30, "WinAnsiEncoding");
  7 cpdf_set_text_rendering($cpdf, 1);
  8 cpdf_text($cpdf, "Times Roman outlined", 50, 750);
  9 cpdf_moveto($cpdf, 50, 740);
 10 cpdf_lineto($cpdf, 330, 740);
 11 cpdf_stroke($cpdf);
 12 cpdf_finalize($cpdf);
 13 Header("Content-type: application/pdf");
 14 cpdf_output_buffer($cpdf);
 15 cpdf_close($cpdf);
 16 ?>
 17     

pdflib ¹èÆ÷º»¿¡ º¸¸é ¾Æ³ª·Î±× ½Ã°è°¡ Æ÷ÇÔµÈ ¿©·¯ ÆäÀÌÁöÀÇ ¹®¼­¸¦ ¸¸µå´Â Á¶±ÝÀº º¹ÀâÇÑ ¿¹Á¦°¡ ÀÖ´Ù. ¿©±â ±× ¿¹Á¦¸¦ ClibPDF È®ÀåÀ» »ç¿ëÇÑ PHP·Î º¯È¯ÇÑ ¿¹°¡ ÀÖ´Ù.

Example 2. pdfclock example from pdflib 2.0 distribution

  1 
  2 <?php
  3 $radius = 200;
  4 $margin = 20;
  5 $pagecount = 40;
  6 
  7 $pdf = cpdf_open(0);
  8 cpdf_set_creator($pdf, "pdf_clock.php3");
  9 cpdf_set_title($pdf, "Analog Clock");
 10   
 11 while($pagecount-- > 0) {
 12   cpdf_page_init($pdf, $pagecount+1, 0, 2 * ($radius + $margin), 2 * ($radius + $margin), 1.0);
 13   
 14   cpdf_set_page_animation($pdf, 4, 0.5, 0, 0, 0);  /* wipe */
 15   
 16   cpdf_translate($pdf, $radius + $margin, $radius + $margin);
 17   cpdf_save($pdf);
 18   cpdf_setrgbcolor($pdf, 0.0, 0.0, 1.0);
 19   
 20   /* minute strokes */
 21   cpdf_setlinewidth($pdf, 2.0);
 22   for ($alpha = 0; $alpha < 360; $alpha += 6)
 23     {
 24     cpdf_rotate($pdf, 6.0);
 25     cpdf_moveto($pdf, $radius, 0.0);
 26     cpdf_lineto($pdf, $radius-$margin/3, 0.0);
 27     cpdf_stroke($pdf);
 28     }
 29   
 30   cpdf_restore($pdf);
 31   cpdf_save($pdf);
 32  
 33   /* 5 minute strokes */
 34   cpdf_setlinewidth($pdf, 3.0);
 35   for ($alpha = 0; $alpha < 360; $alpha += 30)
 36   {
 37     cpdf_rotate($pdf, 30.0);
 38     cpdf_moveto($pdf, $radius, 0.0);
 39     cpdf_lineto($pdf, $radius-$margin, 0.0);
 40     cpdf_stroke($pdf);
 41   }
 42 
 43   $ltime = getdate();
 44 
 45   /* draw hour hand */
 46   cpdf_save($pdf);
 47   cpdf_rotate($pdf, -(($ltime['minutes']/60.0) + $ltime['hours'] - 3.0) * 30.0);
 48   cpdf_moveto($pdf, -$radius/10, -$radius/20);
 49   cpdf_lineto($pdf, $radius/2, 0.0);
 50   cpdf_lineto($pdf, -$radius/10, $radius/20);
 51   cpdf_closepath($pdf);
 52   cpdf_fill($pdf);
 53   cpdf_restore($pdf);
 54 
 55   /* draw minute hand */
 56   cpdf_save($pdf);
 57   cpdf_rotate($pdf, -(($ltime['seconds']/60.0) + $ltime['minutes'] - 15.0) * 6.0);
 58   cpdf_moveto($pdf, -$radius/10, -$radius/20);
 59   cpdf_lineto($pdf, $radius * 0.8, 0.0);
 60   cpdf_lineto($pdf, -$radius/10, $radius/20);
 61   cpdf_closepath($pdf);
 62   cpdf_fill($pdf);
 63   cpdf_restore($pdf);
 64 
 65   /* draw second hand */
 66   cpdf_setrgbcolor($pdf, 1.0, 0.0, 0.0);
 67   cpdf_setlinewidth($pdf, 2);
 68   cpdf_save($pdf);
 69   cpdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
 70   cpdf_moveto($pdf, -$radius/5, 0.0);
 71   cpdf_lineto($pdf, $radius, 0.0);
 72   cpdf_stroke($pdf);
 73   cpdf_restore($pdf);
 74 
 75   /* draw little circle at center */
 76   cpdf_circle($pdf, 0, 0, $radius/30);
 77   cpdf_fill($pdf);
 78 
 79   cpdf_restore($pdf);
 80 
 81   cpdf_finalize_page($pdf, $pagecount+1);
 82 }
 83 
 84 cpdf_finalize($pdf);
 85 Header("Content-type: application/pdf");
 86 cpdf_output_buffer($pdf);
 87 cpdf_close($pdf);
 88 ?>
 89     

Table of Contents
cpdf_global_set_document_limits ¡¦ Sets document limits for any pdf document
cpdf_set_creator ¡¦ Sets the creator field in the pdf document
cpdf_set_title ¡¦ Sets the title field of the pdf document
cpdf_set_subject ¡¦ Sets the subject field of the pdf document
cpdf_set_keywords ¡¦ Sets the keywords field of the pdf document
cpdf_open ¡¦ Opens a new pdf document
cpdf_close ¡¦ Closes the pdf document
cpdf_page_init ¡¦ Starts new page
cpdf_finalize_page ¡¦ Ends page
cpdf_finalize ¡¦ Ends document
cpdf_output_buffer ¡¦ Outputs the pdf document in memory buffer
cpdf_save_to_file ¡¦ Writes the pdf document into a file
cpdf_set_current_page ¡¦ Sets current page
cpdf_begin_text ¡¦ Starts text section
cpdf_end_text ¡¦ ends text section
cpdf_show ¡¦ Output text at current position
cpdf_show_xy ¡¦ Output text at position
cpdf_text ¡¦ Output text with parameters
cpdf_set_font ¡¦ Select the current font face and size
cpdf_set_leading ¡¦ Sets distance between text lines
cpdf_set_text_rendering ¡¦ Determines how text is rendered
cpdf_set_horiz_scaling ¡¦ Sets horizontal scaling of text
cpdf_set_text_rise ¡¦ Sets the text rise
cpdf_set_text_matrix ¡¦ Sets the text matrix
cpdf_set_text_pos ¡¦ Sets text position
cpdf_set_char_spacing ¡¦ Sets character spacing
cpdf_set_word_spacing ¡¦ Sets spacing between words
cpdf_continue_text ¡¦ Output text in next line
cpdf_stringwidth ¡¦ Returns width of text in current font
cpdf_save ¡¦ Saves current enviroment
cpdf_restore ¡¦ Restores formerly saved enviroment
cpdf_translate ¡¦ Sets origin of coordinate system
cpdf_scale ¡¦ Sets scaling
cpdf_rotate ¡¦ Sets rotation
cpdf_setflat ¡¦ Sets flatness
cpdf_setlinejoin ¡¦ Sets linejoin parameter
cpdf_setlinecap ¡¦ Sets linecap aparameter
cpdf_setmiterlimit ¡¦ Sets miter limit
cpdf_setlinewidth ¡¦ Sets line width
cpdf_setdash ¡¦ Sets dash pattern
cpdf_moveto ¡¦ Sets current point
cpdf_rmoveto ¡¦ Sets current point
cpdf_curveto ¡¦ Draws a curve
cpdf_lineto ¡¦ Draws a line
cpdf_rlineto ¡¦ Draws a line
cpdf_circle ¡¦ Draw a circle
cpdf_arc ¡¦ Draws an arc
cpdf_rect ¡¦ Draw a rectangle
cpdf_closepath ¡¦ Close path
cpdf_stroke ¡¦ Draw line along path
cpdf_closepath_stroke ¡¦ Close path and draw line along path
cpdf_fill ¡¦ Fill current path
cpdf_fill_stroke ¡¦ Fill and stroke current path
cpdf_closepath_fill_stroke ¡¦ Close, fill and stroke current path
cpdf_clip ¡¦ Clips to current path
cpdf_setgray_fill ¡¦ Sets filling color to gray value
cpdf_setgray_stroke ¡¦ Sets drawing color to gray value
cpdf_setgray ¡¦ Sets drawing and filling color to gray value
cpdf_setrgbcolor_fill ¡¦ Sets filling color to rgb color value
cpdf_setrgbcolor_stroke ¡¦ Sets drawing color to rgb color value
cpdf_setrgbcolor ¡¦ Sets drawing and filling color to rgb color value
cpdf_add_outline ¡¦ Adds bookmark for current page
cpdf_set_page_animation ¡¦ Sets duration between pages
cpdf_import_jpeg ¡¦ Opens a JPEG image
cpdf_place_inline_image ¡¦ Places an image on the page
cpdf_add_annotation ¡¦ Adds annotation

cpdf_global_set_document_limits

(PHP4 >= 4.0b4)

cpdf_global_set_document_limits -- ¸ðµç pdf ¹®¼­¿¡ ´ëÇÑ Á¦ÇÑÀ» ¼³Á¤ÇÑ´Ù.

Description

void cpdf_global_set_document_limits (int maxpages, int maxfonts, int maximages, int maxannotations, int maxobjects)

The cpdf_global_set_document_limits() function sets several document limits. This function has to be called before cpdf_open() to take effect. It sets the limits for any document open afterwards.

See also cpdf_open().

cpdf_set_creator

cpdf_set_creator -- pdf ¹®¼­¿¡¼­ creator Çʵ带 ¼³Á¤ÇÑ´Ù.

Description

void cpdf_set_creator(string creator);

The cpdf_set_creator() function sets the creator of a pdf document.

See also cpdf_set_subject(), cpdf_set_title(), cpdf_set_keywords().

cpdf_set_title

cpdf_set_title -- pdf ¹®¼­¿¡¼­ title Çʵ带 ¼³Á¤ÇÑ´Ù.

Description

void cpdf_set_title(string title);

The cpdf_set_title() function sets the title of a pdf document.

See also cpdf_set_subject(), cpdf_set_creator(), cpdf_set_keywords().

cpdf_set_subject

cpdf_set_subject -- pdf ¹®¼­¿¡¼­ subject Çʵ带 ¼³Á¤ÇÑ´Ù.

Description

void cpdf_set_subject(string subject);

The cpdf_set_subject() function sets the subject of a pdf document.

See also cpdf_set_title(), cpdf_set_creator(), cpdf_set_keywords().

cpdf_set_keywords

cpdf_set_keywords -- pdf ¹®¼­¿¡¼­ keywords Çʵ带 ¼³Á¤ÇÑ´Ù.

Description

void cpdf_set_keywords(string keywords);

The cpdf_set_keywords() function sets the keywords of a pdf document.

See also cpdf_set_title(), cpdf_set_creator(), cpdf_set_subject().

cpdf_open

cpdf_open -- »õ pdf ¹®¼­¸¦ ¿¬´Ù.

Description

int cpdf_open(int compression, string filename);

The cpdf_open() 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 cpdf_save_to_file() or written to standard output with cpdf_output_buffer().

Note: The return value will be needed in futher versions of ClibPDF as the first parameter in all other functions which are writing to the pdf document.

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 cpdf_output_buffer() to output the pdf document.

See also cpdf_close(), cpdf_output_buffer().

cpdf_close

cpdf_close -- pdf ¹®¼­¸¦ ´Ý´Â´Ù.

Description

void cpdf_close(int pdf document);

The cpdf_close() function closes the pdf document. This should be the last function even after cpdf_finalize(), cpdf_output_buffer() and cpdf_save_to_file().

See also cpdf_open().

cpdf_page_init

cpdf_page_init -- »õ page¸¦ ½ÃÀÛÇÑ´Ù.

Description

void cpdf_page_init(int pdf document, int page number, int orientation, double height, double width, double unit);

The cpdf_page_init() function starts a new page with height height and width width. The page has number page number and orientation orientation. orientation can be 0 for portrait and 1 for landscape. The last optional parameter unit sets the unit for the koordinate 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.

See also cpdf_set_current_page().

cpdf_finalize_page

cpdf_finalize_page -- page¸¦ ³¡³½´Ù.

Description

void cpdf_finalize_page(int pdf document, int page number);

The cpdf_finalize_page() function ends the page with page number page number. This function is only for saving memory. A finalized page takes less memory but cannot be modified anymore.

See also cpdf_page_init().

cpdf_finalize

cpdf_finalize -- ¹®¼­¸¦ ³¡³½´Ù.

Description

void cpdf_finalize(int pdf document);

The cpdf_finalize() function ends the document. You still have to call cpdf_close().

See also cpdf_close().

cpdf_output_buffer

cpdf_output_buffer -- ¸Þ¸ð¸® ¹öÆÛÀÇ PDF ¹®¼­¸¦ Ãâ·ÂÇÑ´Ù.

Description

void cpdf_output_buffer(int pdf document);

The cpdf_output_buffer() function outputs the pdf document to stdout. The document has to be created in memory which is the case if cpdf_open() has been called with no filename parameter.

See also cpdf_open().

cpdf_save_to_file

cpdf_save_to_file -- PDF¹®¼­¸¦ ÆÄÀÏ·Î Ãâ·ÂÇÑ´Ù.

Description

void cpdf_save_to_file(int pdf document, string filename);

The cpdf_save_to_file() function outputs the pdf document into a file if it has been created in memory. This function is not needed if the pdf document has been open by specifying a filename as a parameter of cpdf_open().

See also cpdf_output_buffer(), cpdf_open().

cpdf_set_current_page

cpdf_set_current_page -- ÇöÀç page¸¦ ¼³Á¤ÇÑ´Ù.

Description

void cpdf_set_current_page(int pdf document, int page number);

The cpdf_set_current_page() function set the page on which all operations are performed. One can switch between pages until a page is finished with cpdf_finalize_page().

See also cpdf_finalize_page().

cpdf_begin_text

cpdf_begin_text -- text sectionÀ» ½ÃÀÛÇÑ´Ù.

Description

void cpdf_begin_text(int pdf document);

The cpdf_begin_text() function starts a text section. It must be ended with cpdf_end_text().

Example 1. Text output

<?php cpdf_begin_text($pdf);
cpdf_set_font($pdf, 16, "Helvetica", 4);
cpdf_text($pdf, 100, 100, "Some text");
cpdf_end_text($pdf) ?>

See also cpdf_end_text().

cpdf_end_text

cpdf_end_text -- text sectionÀ» ³¡³½´Ù.

Description

void cpdf_end_text(int pdf document);

The cpdf_end_text() function ends a text section which was started with cpdf_begin_text().

Example 1. Text output

<?php cpdf_begin_text($pdf);
cpdf_set_font($pdf, 16, "Helvetica", 4);
cpdf_text($pdf, 100, 100, "Some text");
cpdf_end_text($pdf) ?>

See also cpdf_begin_text().

cpdf_show

cpdf_show -- ÇöÀç À§Ä¡¿¡ text¸¦ Ãâ·ÂÇÑ´Ù.

Description

void cpdf_show(int pdf document, string text);

The cpdf_show() function outputs the string in text at the current position.

See also cpdf_text(), cpdf_begin_text(), cpdf_end_text().

cpdf_show_xy

cpdf_show_xy -- ÁöÁ¤ÇÑ À§Ä¡¿¡ text¸¦ Ãâ·ÂÇÑ´Ù.

Description

void cpdf_show_xy(int pdf document, string text, double x-koor, double y-koor, int mode);

The cpdf_show_xy() function outputs the string text at position with coordinates (x-koor, y-koor). The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

Note: The function cpdf_show_xy() is identical to cpdf_text().

See also cpdf_text().

cpdf_text

cpdf_text -- ÁöÁ¤µÈ ÆÄ¶ó¸ÞÅÍ´ë·Î text¸¦ Ãâ·ÂÇÑ´Ù.

Description

void cpdf_text(int pdf document, string text, double x-koor, double y-koor, int mode, double orientation, int alignmode);

The cpdf_text() function outputs the string text at position with coordinates (x-koor, y-koor). The optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit. The optional parameter orientation is the rotation of the text in degree. The optional parameter alignmode determines how the text is align. See the ClibPDF documentation for possible values.

See also cpdf_show_xy().

cpdf_set_font

cpdf_set_font -- ÇöÀç »ç¿ëÇÒ ÆùÆ® ¸ð¾ç°ú Å©±â¸¦ ¼±ÅÃÇÑ´Ù.

Description

void cpdf_set_font (int pdf document, string font name, double size, string encoding)

The cpdf_set_font() function sets the the current font face, font size and encoding. Currently only the standard postscript fonts are supported. The last parameter encoding can take the following values: "MacRomanEncoding", "MacExpertEncoding", "WinAnsiEncoding", and "NULL". "NULL" stands for the font's built-in encoding. See the ClibPDF Manual for more information, especially how to support asian fonts.

cpdf_set_leading

cpdf_set_leading -- text ÁÙ°£°ÝÀ» ÁöÁ¤ÇÑ´Ù.

Description

void cpdf_set leading(int pdf document, double distance);

The cpdf_set_leading() function sets the distance between text lines. This will be used if text is output by cpdf_continue_text().

See also cpdf_continue_text().

cpdf_set_text_rendering

cpdf_set_text_rendering -- textÀÇ rendering ¹æ¹ýÀ» °áÁ¤ÇÑ´Ù.

Description

void cpdf_set_text_rendering(int pdf document, int mode);

The cpdf_set_text_rendering() function determines how text is rendered. The possible values for mode are 0=fill text, 1=stroke text, 2=fill and stroke text, 3=invisible, 4=fill text and add it to cliping path, 5=stroke text and add it to clipping path, 6=fill and stroke text and add it to cliping path, 7=add it to clipping path.

cpdf_set_horiz_scaling

cpdf_set_horiz_scaling -- textÀÇ ¼öÆò È®´ë°ªÀ» Á¤ÇÑ´Ù.

Description

void cpdf_set_horiz_scaling(int pdf document, double scale);

The cpdf_set_horiz_scaling() function sets the horizontal scaling to scale percent.

cpdf_set_text_rise

cpdf_set_text_rise -- text¸¦ ¼Ú¾Æ ¿À¸¥ ¸ð¾ç(rise)À¸·Î ¸¸µç´Ù.

Description

void cpdf_set_text_rise(int pdf document, double value);

The cpdf_set_text_rise() function sets the text rising to value units.

cpdf_set_text_matrix

cpdf_set_text_matrix -- text¸¦ Çà¿­ÀÇ ÇüÅ·Π¼³Á¤ÇÑ´Ù.

Description

void cpdf_set_text_matrix(int pdf document, array matrix);

The cpdf_set_text_matrix() function sets a matrix which describes a transformation applied on the current text font.

cpdf_set_text_pos

cpdf_set_text_pos -- text À§Ä¡¸¦ Á¤ÇÑ´Ù.

Description

void cpdf_set_text_pos(int pdf document, double x-koor, double y-koor, int mode);

The cpdf_set_text_pos() function sets the position of text for the next cpdf_show() function call. The optional parameter mode

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_show(), cpdf_text().

cpdf_set_char_spacing

cpdf_set_char_spacing -- ±ÛÀÚ°£ÀÇ °£°ÝÀ» Á¤ÇÑ´Ù.

Description

void cpdf_set_char_spacing(int pdf document, double space);

The cpdf_set_char_spacing() function sets the spacing between characters.

See also cpdf_set_word_spacing(), cpdf_set_leading().

cpdf_set_word_spacing

cpdf_set_word_spacing -- ´Ü¾î°£ÀÇ °£°ÝÀ» Á¤ÇÑ´Ù.

Description

void cpdf_set_word_spacing(int pdf document, double space);

The cpdf_set_word_spacing() function sets the spacing between words.

See also cpdf_set_char_spacing(), cpdf_set_leading().

cpdf_continue_text

cpdf_continue_text -- ´ÙÀ½ÁÙ¿¡ text¸¦ Ãâ·ÂÇÑ´Ù.

Description

void cpdf_continue_text(int pdf document, string text);

The cpdf_continue_text() function outputs the string in text in the next line.

See also cpdf_show_xy(), cpdf_text(), cpdf_set_leading(), cpdf_set_text_pos().

cpdf_stringwidth

cpdf_stringwidth -- ÇöÀç ÆùÆ®¸¦ »ç¿ëÇÑ ÇØ´ç textÀÇ ³ÐÀ̸¦ ¹ÝȯÇÑ´Ù.

Description

double cpdf_stringwidth(int pdf document, string text);

The cpdf_stringwidth() function returns the width of the string in text. It requires a font to be set before.

See also cpdf_set_font().

cpdf_save

cpdf_save -- ÇöÀçÀÇ È¯°æÀ» ÀúÀåÇÑ´Ù.

Description

void cpdf_save(int pdf document);

The cpdf_save() function saves the current enviroment. It works like the postscript command gsave. Very useful if you want to translate or rotate an object without effecting other objects.

See also cpdf_restore().

cpdf_restore

cpdf_restore -- ÀÌÀü¿¡ ÀúÀåÇß´ø ȯ°æÀ¸·Î Àç¼³Á¤ÇÑ´Ù.

Description

void cpdf_restore(int pdf document);

The cpdf_restore() function restores the enviroment saved with cpdf_save(). It works like the postscript command grestore. Very useful if you want to translate or rotate an object without effecting other objects.

Example 1. Save/Restore

<?php cpdf_save($pdf);
// do all kinds of rotations, transformations, ...
cpdf_restore($pdf) ?>

See also cpdf_save().

cpdf_translate

cpdf_translate -- ÁÂÇ¥ ½Ã½ºÅÛÀÇ ¿øÁ¡À» ÁöÁ¤ÇÑ´Ù.

Description

void cpdf_translate(int pdf document, double x-koor, double y-koor, int mode);

The cpdf_translate() function set the origin of coordinate system to the point (x-koor, y-koor).

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

cpdf_scale

cpdf_scale -- È­´ë/Ãà¼Ò°ªÀ» Á¤ÇÑ´Ù.

Description

void cpdf_scale(int pdf document, double x-scale, double y-scale);

The cpdf_scale() function set the scaling factor in both directions.

cpdf_rotate

cpdf_rotate -- ȸÀü Á¤µµ(rotation )¸¦ Á¤ÇÑ´Ù.

Description

void cpdf_rotate(int pdf document, double angle);

The cpdf_rotate() function set the rotation in degress to angle.

cpdf_setflat

cpdf_setflat -- flatness¸¦ Á¤ÇÑ´Ù.

Description

void cpdf_setflat(int pdf document, double value);

The cpdf_setflat() function set the flatness to a value between 0 and 100.

cpdf_setlinejoin

cpdf_setlinejoin -- linejoin ÆÄ¶ó¸ÞÅ͸¦ ¼³Á¤ÇÑ´Ù.

Description

void cpdf_setlinejoin(int pdf document, long value);

The cpdf_setlinejoin() function set the linejoin parameter between a value of 0 and 2. 0 = miter, 1 = round, 2 = bevel.

cpdf_setlinecap

cpdf_setlinecap -- linecap ÆÄ¶ó¸ÞÅ͸¦ ¼³Á¤ÇÑ´Ù.

Description

void cpdf_setlinecap(int pdf document, int value);

The cpdf_setlinecap() function set the linecap parameter between a value of 0 and 2. 0 = butt end, 1 = round, 2 = projecting square.

cpdf_setmiterlimit

cpdf_setmiterlimit -- miter ÇѰ踦 ¼³Á¤ÇÑ´Ù.

Description

void cpdf_setmiterlimit(int pdf document, double value);

The cpdf_setmiterlimit() function set the miter limit to a value greater or equal than 1.

cpdf_setlinewidth

cpdf_setlinewidth -- ÁÙÀÇ µÎ²²¸¦ Á¤ÇÑ´Ù.

Description

void cpdf_setlinewidth(int pdf document, double width);

The cpdf_setlinewidth() function set the line width to width.

cpdf_setdash

cpdf_setdash -- ¼±À̳ª Á¡¼±ÀÇ ÇüŸ¦ Á¤ÇÑ´Ù.

Description

void cpdf_setdash(int pdf document, double white, double black);

The cpdf_setdash() function set the dash pattern white white units and black black units. If both are 0 a solid line is set.

cpdf_moveto

cpdf_moveto -- ÇöÀç À§Ä¡¸¦ Á¤ÇÑ´Ù.

Description

void cpdf_moveto(int pdf document, double x-koor, double y-koor, int mode);

The cpdf_moveto() function set the current point to the coordinates x-koor and y-koor.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

cpdf_rmoveto

cpdf_rmoveto -- ÇöÀç À§Ä¡¸¦ Á¤ÇÑ´Ù. (ÇöÀç À§Ä¡¿¡¼­ »ó´ëÀûÀÎ °ªÀ» ÁØ´Ù.)

Description

void cpdf_rmoveto(int pdf document, double x-koor, double y-koor, int mode);

The cpdf_rmoveto() function set the current point relative to the coordinates x-koor and y-koor.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_moveto().

cpdf_curveto

cpdf_curveto -- °î¼±À» ±×¸°´Ù.

Description

void cpdf_curveto(int pdf document, double x1, double y1, double x2, double y2, double x3, double y3, int mode);

The cpdf_curveto() function draws a Bezier curve from the current point to the point (x3, y3) using (x1, y1) and (x2, y2) as control points.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_moveto(), cpdf_rmoveto(), cpdf_rlineto(), cpdf_lineto().

cpdf_lineto

cpdf_lineto -- Á÷¼±À» ±×¸°´Ù.

Description

void cpdf_lineto(int pdf document, double x-koor, double y-koor, int mode);

The cpdf_lineto() function draws a line from the current point to the point with coordinates (x-koor, y-koor).

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_moveto(), cpdf_rmoveto(), cpdf_curveto().

cpdf_rlineto

cpdf_rlineto -- Á÷¼±À» ±×¸°´Ù. (ÇöÀç À§Ä¡¿¡¼­ »ó´ëÀûÀÎ À§Ä¡°ªÀ¸·Î ±×¸°´Ù.)

Description

void cpdf_rlineto(int pdf document, double x-koor, double y-koor, int mode);

The cpdf_rlineto() function draws a line from the current point to the relative point with coordinates (x-koor, y-koor).

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_moveto(), cpdf_rmoveto(), cpdf_curveto().

cpdf_circle

cpdf_circle -- À©À» ±×¸°´Ù.

Description

void cpdf_circle(int pdf document, double x-koor, double y-koor, double radius, int mode);

The cpdf_circle() function draws a circle with center at point (x-koor, y-koor) and radius radius.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_arc().

cpdf_arc

cpdf_arc -- ¿øÈ£¸¦ ±×¸°´Ù.

Description

void cpdf_arc(int pdf document, double x-koor, double y-koor, double radius, double start, double end, int mode);

The cpdf_arc() function draws an arc with center at point (x-koor, y-koor) and radius radius, starting at angle start and ending at angle end.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_circle().

cpdf_rect

cpdf_rect -- Á÷»ç°¢ÇüÀ» ±×¸°´Ù.

Description

void cpdf_rect(int pdf document, double x-koor, double y-koor, double width, double height, int mode);

The cpdf_rect() function draws a rectangle with its lower left corner at point (x-koor, y-koor). This width is set to widgth. This height is set to height.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

cpdf_closepath

cpdf_closepath -- path¸¦ ´Ý´Â´Ù.

Description

void cpdf_closepath(int pdf document);

The cpdf_closepath() function closes the current path.

cpdf_stroke

cpdf_stroke -- path¸¦ µû¶ó ¼±À» ±×¸°´Ù.

Description

void cpdf_stroke(int pdf document);

The cpdf_stroke() function draws a line along current path.

See also cpdf_closepath(), cpdf_closepath_stroke().

cpdf_closepath_stroke

cpdf_closepath_stroke -- path¸¦ ´Ý°í ÇØ´ç path¿¡ µû¶ó ¼±À» ±×¸°´Ù.

Description

void cpdf_closepath_stroke(int pdf document);

The cpdf_closepath_stroke() function is a combination of cpdf_closepath() and cpdf_stroke(). Than clears the path.

See also cpdf_closepath(), cpdf_stroke().

cpdf_fill

cpdf_fill -- ÇöÀç pathÀÇ ³»ºÎ¸¦ ä¿î´Ù.

Description

void cpdf_fill(int pdf document);

The cpdf_fill() function fills the interior of the current path with the current fill color.

See also cpdf_closepath(), cpdf_stroke(), cpdf_setgray_fill(), cpdf_setgray(), cpdf_setrgbcolor_fill(), cpdf_setrgbcolor().

cpdf_fill_stroke

cpdf_fill_stroke -- ÇöÀç path¸¦ ä¿ì°í ¼±À» ±×¸°´Ù.

Description

void cpdf_fill_stroke(int pdf document);

The cpdf_fill_stroke() function fills the interior of the current path with the current fill color and draws current path.

See also cpdf_closepath(), cpdf_stroke(), cpdf_fill(), cpdf_setgray_fill(), cpdf_setgray(), cpdf_setrgbcolor_fill(), cpdf_setrgbcolor().

cpdf_closepath_fill_stroke

cpdf_closepath_fill_stroke -- ÇöÀç path¸¦ ´ÝÀº ÈÄ, ä¿ì°í ¼±À» ±×¸°´Ù.

Description

void cpdf_closepath_fill_stroke(int pdf document);

The cpdf_closepath_fill_stroke() function closes, fills the interior of the current path with the current fill color and draws current path.

See also cpdf_closepath(), cpdf_stroke(), cpdf_fill(), cpdf_setgray_fill(), cpdf_setgray(), cpdf_setrgbcolor_fill(), cpdf_setrgbcolor().

cpdf_clip

cpdf_clip -- ÇöÀç path¸¦ µû³½´Ù.(clip)

Description

void cpdf_clip(int pdf document);

The cpdf_clip() function clips all drawing to the current path.

cpdf_setgray_fill

cpdf_setgray_fill -- ä¿ì´Â »öÀ» Èæ¹é°ªÀ¸·Î Á¤ÇÑ´Ù.

Description

void cpdf_setgray_fill(int pdf document, double value);

The cpdf_setgray_fill() function sets the current gray value to fill a path.

See also cpdf_setrgbcolor_fill().

cpdf_setgray_stroke

cpdf_setgray_stroke -- (¼±À̳ª ±ÛÀÚ¸¦) ±×¸®´Â »öÀ» Èæ¹é°ªÀ¸·Î Á¤ÇÑ´Ù.

Description

void cpdf_setgray_stroke(int pdf document, double gray value);

The cpdf_setgray_stroke() function sets the current drawing color to the given gray value.

See also cpdf_setrgbcolor_stroke().

cpdf_setgray

cpdf_setgray -- ä¿ì´Â »ö°ú ±×¸®´Â »öÀÇ Èæ¹é°ª Á¤µµ¸¦ Á¤ÇÑ´Ù.

Description

void cpdf_setgray(int pdf document, double gray value);

The cpdf_setgray_stroke() function sets the current drawing and filling color to the given gray value.

See also cpdf_setrgbcolor_stroke(), cpdf_setrgbcolor_fill().

cpdf_setrgbcolor_fill

cpdf_setrgbcolor_fill -- ä¿ì´Â »öÀ» rgb color °ªÀ¸·Î Á¤ÇÑ´Ù.

Description

void cpdf_setrgbcolor_fill(int pdf document, double red value, double green value, double blue value);

The cpdf_setrgbcolor_fill() function sets the current rgb color value to fill a path.

See also cpdf_setrgbcolor_fill().

cpdf_setrgbcolor_stroke

cpdf_setrgbcolor_stroke -- ±×¸®´Â »öÀ» rgb color °ªÀ¸·Î Á¤ÇÑ´Ù.

Description

void cpdf_setrgbcolor_stroke(int pdf document, double red value, double green value, double blue value);

The cpdf_setrgbcolor_stroke() function sets the current drawing color to the given rgb color value.

See also cpdf_setrgbcolor_stroke().

cpdf_setrgbcolor

cpdf_setrgbcolor -- ä¿ì´Â »ö°ú ±×¸®´Â »öÀÇ rgb color °ªÀ» Á¤ÇÑ´Ù.

Description

void cpdf_setrgbcolor(int pdf document, double red value, double green value, double blue value);

The cpdf_setrgbcolor_stroke() function sets the current drawing and filling color to the given rgb color value.

See also cpdf_setrgbcolor_stroke(), cpdf_setrgbcolor_fill().

cpdf_add_outline

cpdf_add_outline -- ÇöÀç page¿¡ bookmark¸¦ Ãß°¡ÇÑ´Ù.

Description

void cpdf_add_outline(int pdf document, string text);

The cpdf_add_outline() function adds a bookmark with text text that points to the current page.

Example 1. Adding a page outline

<?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);
?>
    

cpdf_set_page_animation

cpdf_set_page_animation -- page°£¿¡ ³Ñ¾î°¡´Â ¹æ¹ýÀ» Á¤ÇÑ´Ù.

Description

void cpdf_set_page_animation(int pdf document, int transition, double duration);

The cpdf_set_page_animation() function set the transition between following pages.

The value of transition can be

0 for none,

1 for two lines sweeping across the screen reveal the page,

2 for multiple lines sweeping across the screen reveal the page,

3 for a box reveals the page,

4 for a single line sweeping across the screen reveals the page,

5 for the old page dissolves to reveal the page,

6 for the dissolve effect moves from one screen edge to another,

7 for the old page is simply replaced by the new page (default)

The value of duration is the number of seconds between page flipping.

cpdf_import_jpeg

cpdf_import_jpeg -- JPEG À̹ÌÁö¸¦ ¿¬´Ù.

Description

int cpdf_open_jpeg(int pdf document, string file name, double x-koor, double y-koor, double angle, double width, double height, double x-scale, double y-scale, int mode);

The cpdf_import_jpeg() function opens an image stored in the file with the name file name. The format of the image has to be jpeg. The image is placed on the current page at position (x-koor, y-koor). The image is rotated by angle degres.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_place_inline_image(),

cpdf_place_inline_image

cpdf_place_inline_image -- À̹ÌÁö¸¦ ÇØ´ç ÆäÀÌÁö¿¡ À§Ä¡½ÃŲ´Ù.

Description

void cpdf_place_inline_image(int pdf document, int image, double x-koor, double y-koor, double angle, double width, double height, int mode);

The cpdf_place_inline_image() function places an image created with the php image functions on the page at postion (x-koor, y-koor). The image can be scaled at the same time.

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.

See also cpdf_import_jpeg()

cpdf_add_annotation

cpdf_add_annotation -- ÁÖ¼®(annotation)À» ´Ü´Ù.

Description

void cpdf_add_annotation(int pdf document, double llx, double lly, double urx, double ury, string title, string content, int mode);

The cpdf_add_annotation() adds a note with the lower left corner at (llx, lly) and the upper right corner at (urx, ury).

The last optional parameter determines the unit length. If is 0 or omitted the default unit as specified for the page is used. Otherwise the koodinates are measured in postscript points disregarding the current unit.


IX. Cybercash payment functions

ÀÌ ÇÔ¼öµéÀº PHP¸¦ ÄÄÆÄÀÏÇÒ ¶§ --with-cybercash=[DIR] ¿É¼ÇÀ» ÁÖ°í ÄÄÆÄÀÏÇÑ °æ¿ì¿¡¸¸ »ç¿ë°¡´ÉÇÏ´Ù. ÀÌ ÇÔ¼öµéÀº PHP4¿¡ Ãß°¡µÇ¾ú´Ù.

Table of Contents
cybercash_encr ¡¦ ???
cybercash_decr ¡¦ ???
cybercash_base64_encode ¡¦ ???
cybercash_base64_decode ¡¦

cybercash_encr

(PHP4 >= 4.0b4)

cybercash_encr -- ???

Description

array cybercash_encr (string wmk, string sk, string inbuff)

The function returns an associative array with the elements "errcode" and, if "errcode" is false, "outbuff" (string), "outLth" (long) and "macbuff" (string).

cybercash_decr

(PHP4 >= 4.0b4)

cybercash_decr -- ???

Description

array cybercash_decr (string wmk, string sk, string inbuff)

The function returns an associative array with the elements "errcode" and, if "errcode" is false, "outbuff" (string), "outLth" (long) and "macbuff" (string).

cybercash_base64_encode

(PHP4 >= 4.0b4)

cybercash_base64_encode -- ???

Description

string cybercash_base64_encode (string inbuff)

cybercash_base64_decode

(PHP4 >= 4.0b4)

cybercash_base64_decode -- 

Description

string cybercash_base64_decode (string inbuff)

X. DOM XML functions

ÀÌ ÇÔ¼öµéÀº GNOME xml ¶óÀ̺귯¸®¸¦ »ç¿ëÇϰí, PHP¸¦ ¼³Á¤ÇÒ ¶§ --with-dom=[DIR] ¿É¼ÇÀ» ÁÖ¾úÀ» °æ¿ì¿¡¸¸ »ç¿ë°¡´ÉÇÏ´Ù. ÀÌ ÇÔ¼öµéÀº PHP4¿¡ Ãß°¡µÇ¾ú´Ù.

ÀÌ ¸ðµâÀº ´ÙÀ½°ú °°Àº »ó¼öµéÀ» ¹Ì¸® Á¤ÀÇÇØ ³õ°í ÀÖ´Ù.

Table 1. XML constants

Constant Value Description
XML_ELEMENT_NODE 1  
XML_ATTRIBUTE_NODE 2  
XML_TEXT_NODE 3  
XML_CDATA_SECTION_NODE 4  
XML_ENTITY_REF_NODE 5  
XML_ENTITY_NODE 6  
XML_PI_NODE 7  
XML_COMMENT_NODE 8  
XML_DOCUMENT_NODE 9  
XML_DOCUMENT_TYPE_NODE 10  
XML_DOCUMENT_FRAG_NODE 11  
XML_NOTATION_NODE 12  
XML_GLOBAL_NAMESPACE 1  
XML_LOCAL_NAMESPACE 2  

This module defines a number of classes. The DOM XML functions return a parsed tree of the XML document with each node being an object belonging to one of these classes.

Table of Contents
xmldoc ¡¦ Creates a DOM object of an XML document
xmldocfile ¡¦ Creates a DOM object from XML file
xmltree ¡¦ Creates a tree of php objects from XML document

xmldoc

(PHP4 >= 4.0b4)

xmldoc -- XML ¹®¼­·ÎºÎÅÍ DOM °´Ã¼¸¦ ¸¸µé¾î³½´Ù.

Description

object xmldoc (string str)

The function parses the XML document in str and returns an object of class "Dom document", having the properties "doc" (resource), "version" (string) and "type" (long).

xmldocfile

(PHP4 >= 4.0b4)

xmldocfile -- XML ÆÄÀϷκÎÅÍ DOM °´Ã¼¸¦ ¸¸µé¾î³½´Ù.

Description

object xmldocfile (string filename)

The function parses the XML document in the file named filename and returns an object of class "Dom document", having the properties "doc" (resource), "version" (string).

xmltree

(PHP4 >= 4.0b4)

xmltree --  XML ¹®¼­·ÎºÎÅÍ PHP °´Ã¼µéÀÇ tree¸¦ ¸¸µé¾î³½´Ù.

Description

object xmltree (string str)

The function parses the XML document in str and returns a tree PHP objects as the parsed document.


XI. Compression functions

ÀÌ ¸ðµâÀº gzip(.gz)À¸·Î ¾ÐÃàµÈ ÆÄÀÏÀ» Åõ¸íÇϰÔ(¾ÐÃàµÇÁö ¾ÊÀº °Íó·³) ÀÐ°í ¾²±â À§ÇØ Jean-loup Gailly¿Í Mark Adler¿¡ ÀÇÇÑ zlib >= 1.0.9 (http://www.cdrom.com/pub/infozip/zlib/) ÇÔ¼öµéÀ» »ç¿ëÇÑ´Ù.

ÀÌ ¸ðµâÀº (socketÀ» Á¦¿ÜÇÑ) ´ëºÎºÐÀÇ ÆÄÀϰü¸®(filesystem)ÇÔ¼ö¿¡ gzip-¾ÐÃà°ú ¾ÐÃàÇØÁ¦ ±â´ÉÀ» ´õÇÑ ³»¿ëÀÇ ÇÔ¼öµéÀ» Á¦°øÇÑ´Ù.

¿¹Á¦

ÀÓ½ÃÆÄÀÏÀ» ¿­¾î ¹®ÀÚ¿­À» ¾´ ÈÄ¿¡, ±× ÆÄÀÏ¿¡ ÀÖ´Â ³»¿ëÀ» ´Ù¸¥ ¹æ¹ýÀ¸·Î µÎ ¹ø Ãâ·ÂÇÏ´Â ¿¹Á¦ÀÌ´Ù.

Example 1. Small Zlib example

  1 
  2 <?php
  3   $filename = tempnam('/tmp', 'zlibtest').'.gz';
  4   print "<html>\n<head></head>\n<body>\n<pre>\n";
  5   $s = "Only a test, test, test, test, test, test, test, test!\n";
  6   // open file for writing with maximum compression
  7   $zp = gzopen($filename, "w9");
  8   // write string to file
  9   gzwrite($zp, $s);
 10   // close file
 11   gzclose($zp);
 12   // open file for reading
 13   $zp = gzopen($filename, "r");
 14   // read 3 char
 15   print gzread($zp, 3);
 16   // output until end of the file and close it.
 17   gzpassthru($zp);
 18   print "\n";
 19   // open file and print content (the 2nd time).
 20   if (readgzfile($filename) != strlen($s)) {
 21           echo "Error with zlib functions!";
 22   }
 23   unlink($filename);
 24   print "</pre>\n</h1></body>\n</html>\n";
 25 ?>
 26 
Table of Contents
gzclose ¡¦ close an open gz-file pointer
gzeof ¡¦ test for end-of-file on a gz-file pointer
gzfile ¡¦ read entire gz-file into an array
gzgetc ¡¦ get character from gz-file pointer
gzgets ¡¦ get line from file pointer
gzgetss ¡¦ get line from gz-file pointer and strip HTML tags
gzopen ¡¦ open gz-file
gzpassthru ¡¦ output all remaining data on a gz-file pointer
gzputs ¡¦ write to a gz-file pointer
gzread ¡¦ Binary-safe gz-file read
gzrewind ¡¦ rewind the position of a gz-file pointer
gzseek ¡¦ seek on a gz-file pointer
gztell ¡¦ tell gz-file pointer read/write position
gzwrite ¡¦ Binary-safe gz-file write
readgzfile ¡¦ output a gz-file
gzcompress ¡¦ gz-compress a string
gzuncompress ¡¦ uncompress a gz-compressed string
 

gzclose

gzclose -- gz-file pointer¸¦ ´Ý´Â´Ù.

Description

int gzclose(int zp);

The gz-file pointed to by zp is closed.

Returns true on success and false on failure.

The gz-file pointer must be valid, and must point to a file successfully opened by gzopen().

gzeof

gzeof -- gz-file pointer°¡ end-of-file¿¡ Àִ°¡ °Ë»çÇÑ´Ù.

Description

int gzeof(int zp);

Returns true if the gz-file pointer is at EOF or an error occurs; otherwise returns false.

The gz-file pointer must be valid, and must point to a file successfully opened by gzopen().

gzfile

gzfile -- gz-fileÀÇ ³»¿ëÀ» ¹è¿­·Î Àд´Ù.

Description

array gzfile(string filename);

Identical to readgzfile(), except that gzfile() returns the file in an array.

See also readgzfile(), and gzopen().

gzgetc

gzgetc -- gz-file pointer¿¡¼­ ÇÑ ¹®ÀÚ¸¦ Àд´Ù.

Description

string gzgetc(int zp);

Returns a string containing a single (uncompressed) character read from the file pointed to by zp. Returns FALSE on EOF (as does gzeof()).

The gz-file pointer must be valid, and must point to a file successfully opened by gzopen().

See also gzopen(), and gzgets().

gzgets

gzgets -- gz-file pointer¿¡¼­ ÇÑ ÁÙÀ» Àд´Ù.

Description

string gzgets(int zp, int length);

Returns a (uncompressed) string of up to length - 1 bytes read from the file pointed to by fp. Reading ends when length - 1 bytes have been read, on a newline, or on EOF (whichever comes first).

If an error occurs, returns false.

The file pointer must be valid, and must point to a file successfully opened by gzopen().

See also gzopen(), and gzgetc().

gzgetss

gzgetss -- gz-file pointer¿¡¼­ ÇÑ ÁÙÀ» Àоî HTML tagµéÀ» stripÇÑ´Ù.

Description

string gzgetss(int zp, int length);

Identical to gzgets(), except that gzgetss attempts to strip any HTML and PHP tags from the text it reads.

See also gzgets(), and gzopen().

gzopen

gzopen -- gz-fileÀ» ¿¬´Ù.

Description

int gzopen(string filename, string mode);

Opens a gzip (.gz) file for reading or writing. The mode parameter is as in fopen() ("rb" or "wb") but can also include a compression level ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman only compression as in "wb1h". (See the description of deflateInit2 in zlib.h for more information about the strategy parameter.)

Gzopen can be used to read a file which is not in gzip format; in this case gzread will directly read from the file without decompression.

Gzopen returns a file pointer to the file opened, after that, everything you read from this file descriptor will be transparently decompressed and what you write gets compressed.

If the open fails, the function returns false.

Example 1. gzopen() example

$fp = gzopen("/tmp/file.gz", "r");

See also gzclose().

gzpassthru

gzpassthru -- gz-file pointer¿¡¼­ºÎÅÍ µÚ¿¡ ³²¾ÆÀÖ´Â ¸ðµç µ¥ÀÌŸ¸¦ Ãâ·Â(output)ÇÑ´Ù.

Description

int gzpassthru(int zp);

Reads to EOF on the given gz-file pointer and writes the (uncompressed) results to standard output.

If an error occurs, returns false.

The file pointer must be valid, and must point to a file successfully opened by gzopen().

The gz-file is closed when gzpassthru() is done reading it (leaving zp useless).

gzputs

gzputs -- gz-file pointer¿¡ ¾´´Ù.

Description

int gzputs(int zp, string str, int [length]);

gzputs() is an alias to gzwrite(), and is identical in every way.

gzread

gzread -- gz-file¿¡¼­ ÀÌÁø µ¥ÀÌŸ·Î Àд´Ù.

Description

string gzread(int zp, int length);

gzread() reads up to length bytes from the gz-file pointer referenced by zp. Reading stops when length (uncompressed) bytes have been read or EOF is reached, whichever comes first.

// get contents of a gz-file into a string
$filename = "/usr/local/something.txt.gz";
$zd = gzopen( $filename, "r" );
$contents = gzread( $zd, 10000 );
gzclose( $zd );

See also gzwrite(), gzopen(), gzgets(), gzgetss(), gzfile(), and gzpassthru().

gzrewind

gzrewind -- gz-file pointerÀÇ À§Ä¡¸¦ ¸Ç ¾ÕÀ¸·Î °¡Á®°£´Ù.

Description

int gzrewind(int zp);

Sets the file position indicator for zp to the beginning of the file stream.

If an error occurs, returns 0.

The file pointer must be valid, and must point to a file successfully opened by gzopen().

See also gzseek() and gztell().

gzseek

gzseek -- gz-file pointer¸¦ ¿Å±ä´Ù.

Description

int gzseek(int zp, int offset);

Sets the file position indicator for the file referenced by zp to offset bytes into the file stream. Equivalent to calling (in C) gzseek( zp, offset, SEEK_SET ).

If the file is opened for reading, this function is emulated but can be extremely slow. If the file is opened for writing, only forward seeks are supported; gzseek then compresses a sequence of zeroes up to the new starting position.

Upon success, returns 0; otherwise, returns -1. Note that seeking past EOF is not considered an error.

See also gztell() and gzrewind().

gztell

gztell -- gz-file pointerÀÇ Àаí, ¾µ À§Ä¡¸¦ ¹ÝȯÇÑ´Ù.

Description

int gztell(int zp);

Returns the position of the file pointer referenced by zp; i.e., its offset into the file stream.

If an error occurs, returns false.

The file pointer must be valid, and must point to a file successfully opened by gzopen().

See also gzopen(), gzseek() and gzrewind().

gzwrite

gzwrite -- gz-file¿¡ ÀÌÁø µ¥ÀÌŸ¸¦ ¾´´Ù.

Description

int gzwrite(int zp, string string, int [length]);

gzwrite() writes the contents of string to the gz-file stream pointed to by zp. If the length argument is given, writing will stop after length (uncompressed) bytes have been written or the end of string is reached, whichever comes first.

Note that if the length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from string.

See also gzread(), gzopen(), and gzputs().

readgzfile

readgzfile -- gz-fileÀ» Ãâ·Â(output)ÇÑ´Ù.

Description

int readgzfile(string filename);

Reads a file, decompresses it and writes it to standard output.

Readgzfile() can be used to read a file which is not in gzip format; in this case readgzfile() will directly read from the file without decompression.

Returns the number of (uncompressed) bytes read from the file. If an error occurs, false is returned and unless the function was called as @readgzfile, an error message is printed.

The file filename will be opened from the filesystem and its contents written to standard output.

See also gzpassthru(), gzfile(), and gzopen().

gzcompress

gzcompress -- ¹®ÀÚ¿­À» gz-¾ÐÃà(compress) ÇÑ´Ù.

Description

string gzcompress (string data [, int level])

This function returns a gzip-compressed version of the input data or false on errors. The optional parameter level can be given as 0 for no compression up to 9 for maximum compression.

See also gzuncompress().

gzuncompress

gzuncompress -- gz-¾ÐÃà(compress)µÈ ¹®ÀÚ¿­À» ÇØÁ¦(uncompress)ÇÑ´Ù.

Description

string gzcompress (string data [, int length])

This function takes data compressed by gzcompress() and returns the orignial uncompressed data or false on error. The function will return an error if the uncompressed data is more than 256 times the lenght of the compressed input data or more than the optional parameter length.

See also gzcompress().


XII. Database (dbm-style) abstraction layer functions

ÀÌ ÇÔ¼öµéÀº Berkeley DB ÇüÅÂÀÇ µ¥ÀÌÅͺ£À̽º¸¦ Á¢±ÙÇϱâ À§ÇÑ °ÍÀÌ´Ù.

À̰ÍÀº ¿©·¯ file-based µ¥ÀÌÅͺ£À̽ºÀÇ ÀϹÝÀûÀÎ abstraction layerÀÌ´Ù. ±â´ÉÀûÀ¸·Î À̰ÍÀº Sleepycat Software's DB2 °°Àº Çö´ëÀûÀÎ µ¥ÀÌÅͺ£À̽º ±â´ÉÀÇ ºÎºÐ ÁýÇÕ(subset)ÀÌ µÈ´Ù. (IBMÀÇ DB2¿Í È¥µ·ÇÏÁö ¸»±â ¹Ù¶õ´Ù. IBMÀÇ DB2´Â ODBC¸¦ ÅëÇØ Áö¿øµÈ´Ù.)

±âÃʰ¡ µÇ´Â µ¥ÀÌÅͺ£À̽ºÀÇ ±¸Çö¿¡ µû¶ó ¾ó¸¶³ª ´Ù¾çÇÏ°Ô »ç¿ëµÉ ¼ö Àִ°¡°¡ °áÁ¤µÈ´Ù. dba_optimize()³ª dba_sync() °°Àº ÇÔ¼ö´Â ´ÜÁö ÇÑ µ¥ÀÌÅͺ£À̽º¿¡ ´ëÇØ ÀÛµ¿µÇ°í ´Ù¸¥ µ¥ÀÌÅͺ£À̽º¿¡ ´ëÇØ¼­´Â ¾Æ¹« ¿µÇâÀ» ¹ÌÄ¡Áö ¸øÇÑ´Ù.

´ÙÀ½°ú °°Àº handler¸¦ Áö¿øÇÑ´Ù. :

Example 1. DBA example

  1 
  2 <?php
  3 
  4 $id = dba_open("/tmp/test.db", "n", "db2");
  5 
  6 if(!$id) {
  7     echo "dba_open failed\n";
  8     exit;
  9 }
 10 
 11 dba_replace("key", "This is an example!", $id);
 12 
 13 if(dba_exists("key", $id)) {
 14     echo dba_fetch("key", $id);
 15     dba_delete("key", $id);
 16 }
 17 
 18 dba_close($id);
 19 ?>
 20 

DBA´Â binary safeÇÏ°í ¾î¶² ¾î¶² arbitrary limitµµ °¡Áö°í ÀÖÁö ¾Ê´Ù. À̰ÍÀÇ Á¦ÇÑÀº ±âÃʰ¡ µÇ´Â µ¥ÀÌÅͺ£À̽º ±¸Çö¿¡ µû¸¥ ÇѰ迡¼­ ¿Â °ÍÀÌ´Ù.

¸ðµç ÆÄÀÏ ±â¹Ý(file-based) µ¥ÀÌÅͺ£À̽º´Â »õ·Î ¸¸µé¾îÁø µ¥ÀÌÅͺ£À̽º¿¡ ´ëÇÏ¿© ÆÄÀÏ ¸ðµå¸¦ ÁöÁ¤ÇÏ´Â ¹æ¹ýÀ» Á¦°øÇØ¾ß ÇÑ´Ù. ÀϹÝÀûÀ¸·Î ÆÄÀÏ ¸ðµå´Â dba_open()À̳ª dba_popen()ÀÇ ³× ¹øÂ° Àμö·Î Àü´ÞÇÏ°Ô µÈ´Ù.

¿©·¯ºÐÀº dba_firstkey()°ú dba_nextkey()ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© Àüü µ¥ÀÌÅ͸¦ ¼øÂ÷ÀûÀ¸·Î Á¢±ÙÇÒ ¼ö ÀÖ´Ù. ±×¸®°í, µ¥ÀÌÅͺ£À̽º¸¦ Ž»öÇÏ´Â µ¿¾ÈÀº µ¥ÀÌÅͺ£À̽ºÀÇ ³»¿ëÀ» ¹Ù²Ü ¼ö ¾ø´Ù.

Example 2. Traversing a database

  1 
  2 <?php
  3 
  4 # ...open database...
  5 
  6 $key = dba_firstkey($id);
  7 
  8 while($key != false) {
  9     if(...) { # remember the key to perform some action later
 10         $handle_later[] = $key;
 11     }
 12     $key = dba_nextkey($id);
 13 }
 14 
 15 for($i = 0; $i < count($handle_later); $i++)
 16     dba_delete($handle_later[$i], $id);
 17 
 18 ?>
 19 	 

Table of Contents
dba_close ¡¦ Close database
dba_delete ¡¦ Delete entry specified by key
dba_exists ¡¦ Check whether key exists
dba_fetch ¡¦ Fetch data specified by key
dba_firstkey ¡¦ Fetch first key
dba_insert ¡¦ Insert entry
dba_nextkey ¡¦ Fetch next key
dba_popen ¡¦ Open database persistently
dba_open ¡¦ Open database
dba_optimize ¡¦ Optimize database
dba_replace ¡¦ Replace or insert entry
dba_sync ¡¦ Synchronize database

dba_close

dba_close -- µ¥ÀÌÅͺ£À̽º¸¦ ´Ý´Â´Ù.

Description

void dba_close(int handle);

dba_close() closes the established database and frees all resources specified by handle.

handle is a database handle returned by dba_open().

dba_close() does not return any value.

See also: dba_open() dba_popen()

dba_delete

dba_delete -- ÁöÁ¤µÈ key°ªÀ» °¡Áö´Â entry¸¦ Áö¿î´Ù.

Description

string dba_delete(string key, int handle);

dba_delete() deletes the entry specified by key from the database specified with handle.

key is the key of the entry which is deleted.

handle is a database handle returned by dba_open().

dba_delete() returns true or false, if the entry is deleted or not deleted, respectively.

See also: dba_exists() dba_fetch() dba_insert() dba_replace()

dba_exists

dba_exists -- ÁöÁ¤µÈ key°¡ Àִ°¡ °Ë»çÇÑ´Ù.

Description

bool dba_exists(string key, int handle);

dba_exists() checks whether the specified key exists in the database specified by handle.

key is the key the check is performed for.

handle is a database handle returned by dba_open().

dba_exists() returns true or false, if the key is found or not found, respectively.

See also: dba_fetch() dba_delete() dba_insert() dba_replace()

dba_fetch

dba_fetch -- ÁöÁ¤µÈ key°ªÀÇ data¸¦ °¡Á®¿Â´Ù.

Description

string dba_fetch(string key, int handle);

dba_fetch() fetches the data specified by key from the database specified with handle.

key is the key the data is specified by.

handle is a database handle returned by dba_open().

dba_fetch() returns the associated string or false, if the key/data pair is found or not found, respectively.

See also: dba_exists() dba_delete() dba_insert() dba_replace()

dba_firstkey

dba_firstkey -- ù ¹øÂ° keyÀÇ °ªÀ» °¡Á®¿Â´Ù.

Description

string dba_firstkey(int handle);

dba_firstkey() returns the first key of the database specified by handle and resets the internal key pointer. This permits a linear search through the whole database.

handle is a database handle returned by dba_open().

dba_firstkey() returns the key or false depending on whether it succeeds or fails, respectively.

See also: dba_nextkey()

dba_insert

dba_insert -- entry¸¦ »ðÀÔÇÑ´Ù.

Description

bool dba_insert(string key, string value, int handle);

dba_insert() inserts the entry described with key and value into the database specified by handle. It fails, if an entry with the same key already exists.

key is the key of the entry to be inserted.

value is the value to be inserted.

handle is a database handle returned by dba_open().

dba_insert() returns true or false, depending on whether it succeeds of fails, respectively.

See also: dba_exists() dba_delete() dba_fetch() dba_replace()

dba_nextkey

dba_nextkey -- ´ÙÀ½ key°ªÀ» °¡Á®¿Â´Ù.

Description

string dba_nextkey(int handle);

dba_nextkey() returns the next key of the database specified by handle and increments the internal key pointer.

handle is a database handle returned by dba_open().

dba_nextkey() returns the key or false depending on whether it succeeds or fails, respectively.

See also: dba_firstkey()

dba_popen

dba_popen -- µ¥ÀÌÅͺ£À̽º¸¦ ¿µ±¸ÀûÀ¸·Î ¿¬´Ù.

Description

int dba_popen(string path, string mode, string handler, [...]);

dba_popen() establishes a persistent database instance for path with mode using handler.

path is commonly a regular path in your filesystem.

mode is "r" for read access, "w" for read/write access to an already existing database, "c" for read/write access and database creation if it doesn't currently exist, and "n" for create, truncate and read/write access.

handler is the name of the handler which shall be used for accessing path. It is passed all optional parameters given to dba_popen() and can act on behalf of them.

dba_popen() returns a positive handler id or false, in the case the open is successful or fails, respectively.

See also: dba_open() dba_close()

dba_open

dba_open -- µ¥ÀÌÅͺ£À̽º¸¦ ¿¬´Ù.

Description

int dba_open(string path, string mode, string handler, [...]);

dba_open() establishes a database instance for path with mode using handler.

path is commonly a regular path in your filesystem.

mode is "r" for read access, "w" for read/write access to an already existing database, "c" for read/write access and database creation if it doesn't currently exist, and "n" for create, truncate and read/write access.

handler is the name of the handler which shall be used for accessing path. It is passed all optional parameters given to dba_open() and can act on behalf of them.

dba_open() returns a positive handler id or false, in the case the open is successful or fails, respectively.

See also: dba_popen() dba_close()

dba_optimize

dba_optimize -- µ¥ÀÌÅͺ£À̽º¸¦ ÃÖÀûÈ­(Optimize)ÇÑ´Ù.

Description

bool dba_optimize(int handle);

dba_optimize() optimizes the underlying database specified by handle.

handle is a database handle returned by dba_open().

dba_optimize() returns true or false, if the optimization succeeds or fails, respectively.

See also: dba_sync()

dba_replace

dba_replace -- entry¸¦ ´ëÄ¡(replace)Çϰųª »ðÀÔÇÑ´Ù.

Description

bool dba_replace(string key, string value, int handle);

dba_replace() replaces or inserts the entry described with key and value into the database specified by handle.

key is the key of the entry to be inserted.

value is the value to be inserted.

handle is a database handle returned by dba_open().

dba_replace() returns true or false, depending on whether it succeeds of fails, respectively.

See also: dba_exists() dba_delete() dba_fetch() dba_insert()

dba_sync

dba_sync -- µ¥ÀÌÅͺ£À̽º¸¦ µ¿±âÈ­(Synchronize)ÇÑ´Ù.

Description

bool dba_sync(int handle);

dba_sync() synchronizes the database specified by handle. This will probably trigger a physical write to disk, if supported.

handle is a database handle returned by dba_open().

dba_sync() returns true or false, if the synchronization succeeds or fails, respectively.

See also: dba_optimize()


XIII. Date and Time functions

Table of Contents
checkdate ¡¦ validate a date/time
date ¡¦ format a local time/date
getdate ¡¦ get date/time information
gettimeofday ¡¦ get current time
gmdate ¡¦ format a GMT/CUT date/time
gmmktime ¡¦ get UNIX timestamp for a GMT date
gmstrftime ¡¦ format a GMT/CUT time/date according to locale settings
localtime ¡¦ Get the local time
microtime ¡¦ return current UNIX timestamp with microseconds
mktime ¡¦ get UNIX timestamp for a date
strftime ¡¦ format a local time/date according to locale settings
time ¡¦ return current UNIX timestamp
strtotime ¡¦ Parse about any english textual datetime description into a UNIX timestamp

checkdate

checkdate -- date/time°ªÀÌ ¿Ã¹Ù¸¥°¡ °Ë»çÇÑ´Ù.

Description

int checkdate(int month, int day, int year);

Returns true if the date given is valid; otherwise returns false. Checks the validity of the date formed by the arguments. A date is considered valid if:

date

date -- local timeÀ» ÁöÁ¤µÈ ÇüÅ·Π¸¸µé¾î ¹ÝȯÇÑ´Ù.

Description

string date(string format, int timestamp);

Returns a string formatted according to the given format string using the given timestamp or the current local time if no timestamp is given.

The following characters are recognized in the format string:

Unrecognized characters in the format string will be printed as-is. The "Z" format will always return "0" when using gmdate().

Example 1. Date() example

  1 
  2 print (date ("l dS of F Y h:i:s A"));
  3 print ("July 1, 2000 is on a " . date ("l", mktime(0,0,0,7,1,2000)));
  4       

It is possible to use date() and mktime() together to find dates in the future or the past.

Example 2. Date() and mktime() example

  1 
  2 $tomorrow  = mktime (0,0,0,date("m")  ,date("d")+1,date("Y"));
  3 $lastmonth = mktime (0,0,0,date("m")-1,date("d"),  date("Y"));
  4 $nextyear  = mktime (0,0,0,date("m"),  date("d"),  date("Y")+1);
  5       

To format dates in other languages, you should use the setlocale() and strftime() functions.

See also gmdate() and mktime().

getdate

getdate -- date/time Á¤º¸¸¦ ¾ò´Â´Ù.

Description

array getdate(int timestamp);

Returns an associative array containing the date information of the timestamp as the following array elements:

gettimeofday

gettimeofday -- ÇöÀç ½Ã°¢À» ¾ò´Â´Ù.

Description

array gettimeofday(void);

This is an interface to gettimeofday(2). It returns an associative array containing the data returned from the system call.

gmdate

gmdate -- GMT/CUT date/timeÀ» ÁöÁ¤µÈ ÇüÅ·Π¸¸µé¾î ¹ÝȯÇÑ´Ù.

Description

string gmdate(string format, int timestamp);

Identical to the date() function except that the time returned is Greenwich Mean Time (GMT). For example, when run in Finland (GMT +0200), the first line below prints "Jan 01 1998 00:00:00", while the second prints "Dec 31 1997 22:00:00".

Example 1. Gmdate() example

  1 
  2 echo date ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
  3 echo gmdate ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
  4       

See also date(), mktime() and gmmktime().

gmmktime

gmmktime -- GMT ³¯Â¥¸¦ °¡Áö°í timestamp¸¦ ¸¸µç´Ù.

Description

int gmmktime(int hour, int minute, int second, int month, int day, int year);

Identical to mktime() except the passed parameters represents a GMT date.

gmstrftime

gmstrftime -- GMT/CUT time/date¸¦ locale ¼³Á¤¿¡ µû¸¥ ÇüÅ·Π¸¸µé¾î ¹ÝȯÇÑ´Ù.

Description

string gmstrftime(string format, int timestamp);

Behaves the same as strftime() except that the time returned is Greenwich Mean Time (GMT). For example, when run in Eastern Standard Time (GMT -0500), the first line below prints "Dec 31 1998 20:00:00", while the second prints "Jan 01 1999 01:00:00".

Example 1. Gmstrftime() example

  1 
  2 setlocale ('LC_TIME', 'en_US');
  3 echo strftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n";
  4 echo gmstrftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n";
  5       

See also strftime().

localtime

(PHP4 >= 4.0RC2)

localtime -- ÇöÀç Áö¿ªÀÇ ½Ã°£À» ¾ò´Â´Ù.

Description

array localtime ([int timestamp [, bool is_associative]])

The localtime() function returns an array identical to that of the structure returned by the C function call. The first argument to localtime() is the timestamp, if this is not given the current time is used. The second argument to the localtime() is the is_associative, if this is set to 0 or not supplied than the array is returned as a regular, numerically indexed array. If the argument is set to 1 then localtime() is an associative array containing all the different elements of the structure returned by the C function call to localtime. The names of the different keys of the associative array are as follows:

microtime

microtime -- ÇöÀç ½Ã°¢ÀÇ timestamp¸¦ 1000ºÐÀÇ 1ÃÊ ´ÜÀ§±îÁö ¹ÝȯÇÑ´Ù.

Description

string microtime(void);

Returns the string "msec sec" where sec is the current time measured in the number of seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT), and msec is the microseconds part. This function is only available on operating systems that support the gettimeofday() system call.

See also time().

mktime

mktime -- ÁöÁ¤µÈ ³¯Â¥¸¦ date()ÇÔ¼ö µîÀÌ »ç¿ëÇÏ´Â timestamp·Î ¸¸µç´Ù.

Description

int mktime (int hour, int minute, int second, int month, int day, int year [, int is_dst])

Warning: Note the strange order of arguments, which differs from the order of arguments in a regular UNIX mktime() call and which does not lend itself well to leaving out parameters from right to left (see below). It is a common error to mix these values up in a script.

Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970) and the time specified.

Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time.

Is_dst can be set to 1 if the time is during daylight savings time, 0 if it is not, or -1 (the default) if it is unknown whether the time is within daylight savings time or not.

Note: Is_dst was added in 3.0.10.

Mktime() is useful for doing date arithmetic and validation, as it will automatically calculate the correct value for out-of-range input. For example, each of the following lines produces the string "Jan-01-1998".

Example 1. Mktime() example

  1 
  2 echo date ("M-d-Y", mktime (0,0,0,12,32,1997));
  3 echo date ("M-d-Y", mktime (0,0,0,13,1,1997));
  4 echo date ("M-d-Y", mktime (0,0,0,1,1,1998));
  5 echo date ("M-d-Y", mktime (0,0,0,1,1,98));
  6       
Year may be a two or four digit value, with values between 0-69 mapping to 2000-2069 and 70-99 to 1970-1999 (on systems where time_t is a 32bit signed integer, as most common today, the valid range for year is somewhere between 1902 and 2037).

The last day of any given month can be expressed as the "0" day of the next month, not the -1 day. Both of the following examples will produce the string "The last day in Feb 2000 is: 29".

Example 2. Last day of next month

  1 
  2 $lastday = mktime (0,0,0,3,0,2000);
  3 echo strftime ("Last day in Feb 2000 is: %d", $lastday);
  4      
  5 $lastday = mktime (0,0,0,4,-31,2000);
  6 echo strftime ("Last day in Feb 2000 is: %d", $lastday);
  7       

( ¿ªÀÚÁÖ : ´ÙÀ½°ú °°ÀÌ date() ÇÔ¼ö¸¦ °°ÀÌ »ç¿ëÇÏ¸é °ú°Å³ª ¹Ì·¡ÀÇ Æ¯Á¤ÀÏÀ» ¾Ë ¼ö ÀÖ´Ù.
$tomorrow = mktime(0,0,0,date("d")+1,date("m"), date("Y"));
$lastmonth = mktime(0,0,0,date("d"),date("m")-1,date("Y"));
$nextyear = mktime(0,0,0,date("d"),date("m"),date("Y")+1); )

See also date() and time().

strftime

strftime -- ÇöÀç ½Ã°£/³¯Â¥¸¦ ÁöÁ¤ÇÑ ÇüÅ·Πº¯È¯ÇÑ´Ù.

Description

string strftime(string format, int timestamp);

Returns a string formatted according to the given format string using the given timestamp or the current local time if no timestamp is given. Month and weekday names and other language dependent strings respect the current locale set with setlocale().

The following conversion specifiers are recognized in the format string:

Example 1. Strftime() example

  1 
  2 setlocale ("LC_TIME", "C");
  3 print (strftime ("%A in Finnish is "));
  4 setlocale ("LC_TIME", "fi_FI");
  5 print (strftime ("%A, in French "));
  6 setlocale ("LC_TIME", "fr_CA");
  7 print (strftime ("%A and in German "));
  8 setlocale ("LC_TIME", "de_DE");
  9 print (strftime ("%A.\n"));
 10       

This example works if you have the respective locales installed in your system.

See also setlocale() and mktime() and the Open Group specification of strftime() .

time

time -- ÇöÀç ½Ã°¢ÀÇ timestamp¸¦ ¹ÝȯÇÑ´Ù.

Description

int time(void);

Returns the current time measured in the number of seconds since the Unix Epoch (January 1, 1970).

See also date().

strtotime

(PHP3 >= 3.0.12, PHP4 >= 4.0b2)

strtotime --  °¡´ÉÇÑ ¿©·¯ ÇüÅÂÀÇ ¿µ¹® ³¯Â¥/½Ã°£À» Ç¥½ÃÇÏ´Â ¹®ÀÚ¿­À» ºÐ¼®ÇÏ¿© UNIX timestamp·Î ¸¸µç´Ù.

Description

int strtotime (string time [, int now])

The function expects to be given a string containing an english date format and will try to parse that format into a UNIX timestamp.

Example 1. Strtotime() example

  1 
  2 echo strtotime ("10 march 2000") . "\n";
  3       


XIV. dBase functions

ÀÌ ÇÔ¼öµéÀº dBase ÇüÅÂÀÇ databse(dbf)¿¡ ÀúÀåµÈ ·¹ÄÚµåµéÀ» Á¢±ÙÇÒ ¼ö ÀÖ°Ô ÇØ ÁØ´Ù.

index¿Í memo Çʵå´Â Áö¿øÇÏÁö ¾Ê´Â´Ù. ¶ÇÇÑ lockingµµ Áö¿øÇÏÁö ¾Ê´Â´Ù. µÎ °³ÀÇ À¥¼­¹ö ÇÁ·Î¼¼½º°¡ µ¿½Ã¿¡ °°Àº dBase ÆÄÀÏÀ» ¼öÁ¤ÇÏ·Á ÇÑ´Ù¸é, database ÀÚü°¡ ¸Á°¡Áú ¼öµµ ÀÖ´Ù.

SQL µ¥ÀÌÅͺ£À̽º¿Í ´Ù¸£°Ô dBase µ¥ÀÌÅͺ£À̽º´Â »ý¼ºÈÄ¿¡ ±× ±¸Á¶¸¦ ¹Ù²Ü ¼ö ¾ø´Ù. ÇÑ ÆÄÀÏÀÌ »ý¼ºµÇ¸é ÇØ´ç µ¥ÀÌÅͺ£À̽ºÀÇ ¼±¾ðÀº °íÁ¤µÈ´Ù. ¼Óµµ Çâ»ó µîÀ» À§ÇØ »ç¿ëÇÏ´Â indexµµ Áö¿øÇÏÁö ¾Ê´Â´Ù. dBase´Â °íÁ¤µÈ ±æÀÌÀÇ ·¹Äڵ带 °¡Áø ´Ü¼øÇÑ ¼øÂ÷ ÆÄÀÏÀÌ´Ù. »õ·¹ÄÚµå´Â ÆÄÀÏÀÇ ¸Ç µÚ¿¡ ºÙ°í, »èÁ¦µÈ ·¹ÄÚµå´Â dbase_pack()ÀÌ ¼öÇàµÇ±â Àü¿¡´Â µ¥ÀÌÅÍ ÀÚü´Â À¯ÁöµÈ´Ù.

¿ì¸®´Â dBase ÆÄÀÏÀº »ç¿ëÇÏÁö ¸»±â¸¦ ±ÇÇÑ´Ù. ´ë½Å ÁøÂ¥ SQL ¼­¹ö¸¦ »ç¿ëÇϱ⸦ ±ÇÇÑ´Ù. MySQLÀ̳ª PostgreSQLÀÌ PHP¿Í °°ÀÌ ¸¹¤· »ç¿ëµÈ´Ù. dBase Áö¿øÀº ´ÜÁö ¿©·¯ºÐÀÌ »ç¿ëÇÏ´Â µ¥ÀÌÅͺ£À̽º¿¡ µ¥ÀÌÅ͸¦ ÀоîµéÀ̰ųª ³»º¸³¾ ¶§¸¸ »ç¿ëÇÏ´Â °ÍÀÌ ÁÁ´Ù. dBase Æ÷¸ËÀº ´ëºÎºÐÀÇ Windows¿ë ÇÁ·Î±×·¥ÀÌ »ç¿ë°¡´ÉÇÑ µ¥ÀÌÅÍ Æ÷¸ËÀ̱⠶§¹®ÀÌ´Ù.

Table of Contents
dbase_create ¡¦ creates a dBase database
dbase_open ¡¦ opens a dBase database
dbase_close ¡¦ close a dBase database
dbase_pack ¡¦ packs a dBase database
dbase_add_record ¡¦ add a record to a dBase database
dbase_replace_record ¡¦ replace a record in a dBase database
dbase_delete_record ¡¦ deletes a record from a dBase database
dbase_get_record ¡¦ gets a record from a dBase database
dbase_get_record_with_names ¡¦ Gets a record from a dBase databaseas an associative array
dbase_numfields ¡¦ find out how many fields are in a dBase database
dbase_numrecords ¡¦ find out how many records are in a dBase database

dbase_create

dbase_create -- dBase database¸¦ »ý¼ºÇÑ´Ù.

Description

int dbase_create(string filename, array fields);

The fields parameter is an array of arrays, each array describing the format of one field in the database. Each field consists of a name, a character indicating the field type, a length, and a precision.

The types of fields available are:

If the database is successfully created, a dbase_identifier is returned, otherwise false is returned.

Example 1. Creating a dBase database file

// "database" name
$dbname = "/tmp/test.dbf";
// database "definition"
$def =
    array(
        array("date",     "D"),
        array("name",     "C",  50),
        array("age",      "N",   3, 0),
        array("email",    "C", 128),
        array("ismember", "L")
    );
// creation
if (!dbase_create($dbname, $def))
    print "<strong>Error!</strong>";

dbase_open

dbase_open -- dBase database¸¦ ¿¬´Ù.

Description

int dbase_open(string filename, int flags);

The flags correspond to those for the open() system call. (Typically 0 means read-only, 1 means write-only, and 2 means read and write.)

Returns a dbase_identifier for the opened database, or false if the database couldn't be opened.

dbase_close

dbase_close -- dBase database¸¦ ´Ý´Â´Ù.

Description

bool dbase_close(int dbase_identifier);

Closes the database associated with dbase_identifier.

dbase_pack

dbase_pack -- dBase database¸¦ packÇÑ´Ù.

Description

bool dbase_pack(int dbase_identifier);

Packs the specified database (permanently deleting all records marked for deletion using dbase_delete_record().

dbase_add_record

dbase_add_record -- dBase database¿¡ ÇÑ record¸¦ ´õÇÑ´Ù.

Description

bool dbase_add_record(int dbase_identifier, array record);

Adds the data in the record to the database. If the number of items in the supplied record isn't equal to the number of fields in the database, the operation will fail and false will be returned.

dbase_replace_record

dbase_replace_record -- dBase databaseÀÇ ÇÑ ·¹ÄÚµåÀÇ ³»¿ëÀ» ¹Ù²Û´Ù.

Description

bool dbase_replace_record(int dbase_identifier, array record, int dbase_record_number);

Replaces the data associated with the record record_number with the data in the record in the database. If the number of items in the supplied record is not equal to the number of fields in the database, the operation will fail and false will be returned.

dbase_record_number is an integer which spans from 1 to the number of records in the database (as returned by dbase_numrecords()).

dbase_delete_record

dbase_delete_record -- dBase database¿¡¼­ ÇÑ record¸¦ »èÁ¦ÇÑ´Ù

Description

bool dbase_delete_record(int dbase_identifier, int record);

Marks record to be deleted from the database. To actually remove the record from the database, you must also call dbase_pack().

dbase_get_record

dbase_get_record -- dBase database¿¡¼­ ÇÑ record¸¦ Àоî¿Â´Ù.

Description

array dbase_get_record(int dbase_identifier, int record);

Returns the data from record in an array. The array is indexed starting at 0, and includes an associative member named 'deleted' which is set to 1 if the record has been marked for deletion (see dbase_delete_record().

Each field is converted to the appropriate PHP type. (Dates are left as strings.)

dbase_get_record_with_names

(PHP3 >= 3.0.4, PHP4 )

dbase_get_record_with_names --  dBase database¿¡¼­ ÇÑ record¸¦ associative ¹è¿­·Î Àоî¿Â´Ù.

Description

array dbase_get_record_with_names (int dbase_identifier, int record)

Returns the data from record in an associative array. The array also includes an associative member named 'deleted' which is set to 1 if the record has been marked for deletion (see dbase_delete_record()).

Each field is converted to the appropriate PHP type. (Dates are left as strings.)

dbase_numfields

dbase_numfields -- dBase databaseÀÇ fieldÀÇ °³¼ö¸¦ ±¸ÇÑ´Ù.

Description

int dbase_numfields(int dbase_identifier);

Returns the number of fields (columns) in the specified database. Field numbers are between 0 and dbase_numfields($db)-1, while record numbers are between 1 and dbase_numrecords($db).

Example 1. Using dbase_numfields()

  1 
  2 $rec = dbase_get_record($db, $recno);
  3 $nf  = dbase_numfields($db);
  4 for ($i=0; $i < $nf; $i++) {
  5     print $rec[$i]."<br>\n";
  6 }
  7       

dbase_numrecords

dbase_numrecords -- fdBase databaseÀÇ recordÀÇ °³¼ö¸¦ ±¸ÇÑ´Ù.

Description

int dbase_numrecords(int dbase_identifier);

Returns the number of records (rows) in the specified database. Record numbers are between 1 and dbase_numrecords($db), while field numbers are between 0 and dbase_numfields($db)-1.


XV. dbm functions

ÀÌ ÇÔ¼öµéÀº dbm ÇüÅÂÀÇ databse(dbf)¿¡ ÀúÀåµÈ ·¹ÄÚµåµéÀ» Á¢±ÙÇÒ ¼ö ÀÖ°Ô ÇØ ÁØ´Ù. ÀÌ ÇüÅÂÀÇ database´Â Berkeley db, gdbm µî°ú ³»ÀåµÈ flatfile ¶óÀ̺귯¸® °°Àº ÀϺΠsystem ¶óÀ̺귯¸® µîÀÌ Áö¿øÇϴµ¥, ÀϹÝÀûÀÎ relational databases¿Í ´Þ¸® key/valueÀÇ ½ÖÀ¸·Î data¸¦ ÀúÀåÇÑ´Ù.

Example 1. dbm example

  1 
  2 $dbm = dbmopen("lastseen", "w");
  3 if (dbmexists($dbm, $userid)) {
  4   $last_seen = dbmfetch($dbm, $userid);
  5 } else {
  6   dbminsert($dbm, $userid, time());
  7 }
  8 do_stuff();
  9 dbmreplace($dbm, $userid, time());
 10 dbmclose($dbm);
 11 

Table of Contents
dbmopen ¡¦ opens a dbm database
dbmclose ¡¦ closes a dbm database
dbmexists ¡¦ tells if a value exists for a key in a dbm database
dbmfetch ¡¦ fetches a value for a key from a dbm database
dbminsert ¡¦ inserts a value for a key in a dbm database
dbmreplace ¡¦ replaces the value for a key in a dbm database
dbmdelete ¡¦ deletes the value for a key from a dbm database
dbmfirstkey ¡¦ retrieves the first key from a dbm database
dbmnextkey ¡¦ retrieves the next key from a dbm database
dblist ¡¦ describes the dbm-compatible library being used

dbmopen

dbmopen -- dbm database¸¦ ¿¬´Ù.

Description

int dbmopen(string filename, int flags);

The first argument is the full-path filename of the dbm file to be opened and the second is the file open mode which is one of "r", "n", "c" or "w" for read-only, new (implies read-write, and most likely will truncate an already-existing database of the same name), create (implies read-write, and will not truncate an already-existing database of the same name) and read-write respectively.

Returns an identifer to be passed to the other dbm functions on success, or false on failure.

If ndbm support is used, ndbm will actually create filename.dir and filename.pag files. gdbm only uses one file, as does the internal flat-file support, and Berkeley db creates a filename.db file. Note that PHP does its own file locking in addition to any file locking that may be done by the dbm library itself. PHP does not delete the .lck files it creates. It uses these files simply as fixed inodes on which to do the file locking. For more information on dbm files, see your Unix man pages, or obtain GNU's gdbm.

dbmclose

dbmclose -- dbm database¸¦ ´Ý´Â´Ù.

Description

bool dbmclose(int dbm_identifier);

Unlocks and closes the specified database.

dbmexists

dbmexists -- dbm database¿¡ ÁÖ¾îÁø key¿¡ ÇØ´çÇÏ´Â °ªÀÌ ÀÖ´ÂÁö ¾Ë¾Æº»´Ù.

Description

bool dbmexists(int dbm_identifier, string key);

Returns true if there is a value associated with the key.

dbmfetch

dbmfetch -- dbm database¿¡¼­ ÁÖ¾îÁø keyÀÇ value¸¦ Àоî¿Â´Ù.

Description

string dbmfetch(int dbm_identifier, string key);

Returns the value associated with key.

dbminsert

dbminsert -- dbm database¿¡ keyÀÇ value¸¦ »ðÀÔÇÑ´Ù.

Description

int dbminsert(int dbm_identifier, string key, string value);

Adds the value to the database with the specified key.

Returns -1 if the database was opened read-only, 0 if the insert was successful, and 1 if the specified key already exists. (To replace the value, use dbmreplace().)

dbmreplace

dbmreplace -- dbm database¿¡¼­ keyÀÇ value¸¦ ¹Ù²Û´Ù.

Description

bool dbmreplace(int dbm_identifier, string key, string value);

Replaces the value for the specified key in the database.

This will also add the key to the database if it didn't already exist.

dbmdelete

dbmdelete -- dbm database¿¡¼­ keyÀÇ value¸¦ »èÁ¦ÇÑ´Ù.

Description

bool dbmdelete(int dbm_identifier, string key);

Deletes the value for key in the database.

Returns false if the key didn't exist in the database.

dbmfirstkey

dbmfirstkey -- dbm databaseÀÇ Ã¹ ¹øÂ° key¸¦ °Ë»öÇÑ´Ù.

Description

string dbmfirstkey(int dbm_identifier);

Returns the first key in the database. Note that no particular order is guaranteed since the database may be built using a hash-table, which doesn't guarantee any ordering.

dbmnextkey

dbmnextkey -- dbm databaseÀÇ ´ÙÀ½ key¸¦ °Ë»öÇÑ´Ù.

Description

string dbmnextkey(int dbm_identifier, string key);

Returns the next key after key. By calling dbmfirstkey() followed by successive calls to dbmnextkey() it is possible to visit every key/value pair in the dbm database. For example:

Example 1. Visiting every key/value pair in a dbm database.

  1 
  2 $key = dbmfirstkey($dbm_id);
  3 while ($key) {
  4     echo "$key = " . dbmfetch($dbm_id, $key) . "\n";
  5     $key = dbmnextkey($dbm_id, $key);
  6 }
  7      

dblist

dblist -- »ç¿ëÁßÀÎ dbm-compatible library¿¡ ´ëÇÑ Á¤º¸¸¦ Ç¥½ÃÇÑ´Ù.

Description

string dblist(void);


XVI. Directory functions

Table of Contents
chdir ¡¦ change directory
dir ¡¦ directory class
closedir ¡¦ close directory handle
opendir ¡¦ open directory handle
readdir ¡¦ read entry from directory handle
rewinddir ¡¦ rewind directory handle

chdir

chdir -- ÇöÀç directory¸¦ ¹Ù²Û´Ù.

Description

int chdir(string directory);

Changes PHP's current directory to directory. Returns FALSE if unable to change directory, TRUE otherwise.

dir

dir -- directory class

Description

new dir(string directory);

A pseudo-object oriented mechanism for reading a directory. The given directory is opened. Two properties are available once directory has been opened. The handle property can be used with other directory functions such as readdir(), rewinddir() and closedir(). The path property is set to path the directory that was opened. Three methods are available: read, rewind and close.

Example 1. Dir() Example

  1 
  2 $d = dir("/etc");
  3 echo "Handle: ".$d->handle."<br>\n";
  4 echo "Path: ".$d->path."<br>\n";
  5 while($entry=$d->read()) {
  6     echo $entry."<br>\n";
  7 }
  8 $d->close();
  9       

closedir

closedir -- directory handleÀ» ´Ý´Â´Ù.

Description

void closedir(int dir_handle);

Closes the directory stream indicated by dir_handle. The stream must have previously been opened by opendir().

opendir

opendir -- directory handleÀ» ¿¬´Ù.

Description

int opendir(string path);

Returns a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() calls.

readdir

readdir -- directory handle·Î ºÎÅÍ Ç׸ñÀ» Àоî¿Â´Ù.

Description

string readdir(int dir_handle);

Returns the filename of the next file from the directory. The filenames are not returned in any particular order.

Example 1. List all files in the current directory

  1 
  2 <?php
  3 $handle=opendir('.');
  4 echo "Directory handle: $handle\n";
  5 echo "Files:\n";
  6 while ($file = readdir($handle)) {
  7     echo "$file\n";
  8 }
  9 closedir($handle); 
 10 ?>
 11       

rewinddir

rewinddir -- directory handleÀ» directoryÀÇ ½ÃÀÛ À§Ä¡·Î µÇµ¹¸°´Ù.

Description

void rewinddir(int dir_handle);

Resets the directory stream indicated by dir_handle to the beginning of the directory.


XVII. Dynamic Loading functions

Table of Contents
dl ¡¦ load a PHP extension at runtime

dl

dl -- PHP extensionÀ» ½ÇÇàÁß¿¡ loadÇÑ´Ù.

Description

int dl(string library);

Loads the PHP extension defined in library. See also the extension_dir configuration directive.


XXVIII. Encryption functions

ÀÌ ÇÔ¼öµéÀº mcrypt¿Í °°ÀÌ µ¿ÀÛÇϱâÀ§ÇØ ¸¸µé¾ú´Ù.

À̰ÍÀº mcrypt ¶óÀ̺귯¸®¿¡ ´ëÇÑ ÀÎÅÍÆäÀ̽ºÀÌ´Ù. mcrypt´Â ´ÙÀ½°ú °°Àº ±¤¹üÀ§ÇÑ block ¾Ë°í¸®ÁòÀ» Áö¿øÇÑ´Ù. : DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes Ãß°¡·Î Áö¿øÇÏ´Â RC6¿Í IDEA´Â ¹«·á°¡ ¾Æ´Ï´Ù.

À̰ÍÀ» »ç¿ëÇϱâ À§Çؼ­´Â ¿ì¼± ftp://argeas.cs-net.gr/pub/unix/mcrypt/¿¡¼­ libmcrypt-x.x.tar.gzÀ» ´Ù¿î¹ÞÀº ÈÄ¿¡ Æ÷ÇÔµÈ ¼³Ä¡ ¼³¸í¼­ ´ë·Î ¼³Ä¡ÇÑ ÈÄ¿¡, PHP¸¦ --with-mcrypt ¼³Á¤À» ÁÖ¾î ÀÌ È®ÀåÀ» Ȱ¼ºÈ­ÇÏ¿© ÄÄÆÄÀÏ ÇÏ¿©¾ß ÇÑ´Ù.

mcrypt´Â À§¿¡¼­ ¾ð±ÞµÈ ¾ÏÈ£¹æ½Ä(cipher)À¸·Î ¾ÏȣȭÇϰųª ÇØµ¶ÇÒ ¼ö ÀÖ´Ù. mcrypt_cbc(), mcrypt_cfb(), mcrypt_ecb() mcrypt_ofb()ÀÇ ³×°¡Áö Áß¿äÇÑ mcrypt ¸í·ÉÀº °¢°¢ MCRYPT_ENCRYPT¿Í MCRYPT_DECRYPT·Î ¸í¸íµÈ µÎ°¡Áö ¸ðµå·Î µ¿ÀÛÇÑ´Ù.

Example 1. Encrypt an input value with TripleDES in ECB mode

  1 
  2 <?php
  3 $key = "this is a very secret key";
  4 $input = "Let us meet at 9 o'clock at the secret place.";
  5 
  6 $encrypted_data = mcrypt_ecb(MCRYPT_TripleDES, $key, $input, MCRYPT_ENCRYPT);
  7 ?>
  8      

À§ÀÇ ¿¹Á¦¿¡¼­ ¿©·¯ºÐÀº $encrypted_data¿¡ ¾ÏȣȭµÈ ¹®ÀÚ¿­ µ¥ÀÌÅ͸¦ ¾ò°Ô µÈ´Ù.

mcrypt´Â CBC, OFB, CFB, ECBÀÇ 4°¡Áö ¾ÏÈ£ ¸ðµå·Î µ¿ÀÛÇÑ´Ù. ¿©±â¼­´Â °³°³ÀÇ ¸ðµå¿¡ ´ëÇÑ °£·«ÇÑ ¼³¸í¸¸À» ÇϰڴÙ. º¸´Ù ÀÚ¼¼ÇÑ ³»¿ëÀº SchneierÀÇ Applied Cryptography (ISBN 0-471-11709-9)¸¦ º¸±â ¹Ù¶õ´Ù.

PHP´Â ÇöÀç bit stream¿¡ ´ëÇØ¼­´Â ¾ÏȣȭÇϰųª ÇØµ¶ÇÒ ¼ö ¾ø´Ù. ÇöÀçÀÇ PHP´Â ´ÜÁö ¹®ÀÚ¿­À» Áö¿øÇÒ »ÓÀÌ´Ù.

Áö¿øµÇ´Â ¾ÏÈ£¹æ½ÄÀÇ Àüü ¸®½ºÆ®´Â mcrypt.h ÆÄÀÏÀÇ ¸¶Áö¸·¿¡ ÀÖ´Ù. PHP¿¡¼­ ¾ÏÈ£¹æ½Ä(cipher)À» »ç¿ëÇÏ´Â ÀϹÝÀûÀÎ ¹ýÄ¢Àº "MCRYPT_¾ÏÈ£¹æ½ÄÀ̸§"ÀÇ ÇüÅÂÀÌ´Ù.

¾Æ·¡´Â ÇöÀç PHP/mcrypt¿¡¼­ Áö¿øÇÏ´Â ¾ÏÈ£¹æ½ÄÀÇ °£´ÜÇÑ ListÀÌ´Ù. mcrypt¿¡¼­ Áö¿øÇÑ´Ù°í Ç¥½ÃµÇ¾î ÀÖÀ¸³ª, ¿©±â¿¡ ³ª¿ÍÀÖÁö ¾ÊÀº °ÍÀº ÀÌ ¸Å´º¾ó ÀÌÈÄ¿¡ Ãß°¡·Î Áö¿øµÈ °ÍÀ̹ǷΠ¾È½ÉÇÏ°í »ç¿ëÇÏ¿©µµ µÈ´Ù.

CFB¿Í OFB ¸ðµå¿¡¼­´Â ¹Ýµå½Ã °¢°¢ÀÇ ¾Ïȣȭ ÇÔ¼ö¿¡ ´ëÇØ initialization vector (IV)¸¦ ÁÖ¾î¾ß ÇÑ´Ù. CBC ¸ðµå¿¡¼­´Â ¿É¼ÇÀ¸·Î ÁÙ ¼ö ÀÖ´Ù. IV´Â À¯ÀÏÇÏ¿©¾ß Çϰí, ¾ÏÈ£/ÇØÁ¦½Ã¿¡ µ¿ÀÏÇÏ¿©¾ß ÇÑ´Ù. ¾ÏȣȭµÇ¾î ÀúÀåµÈ µ¥ÀÌÅ͸¦ °¡Áö°í, µ¥ÀÌÅͰ¡ ÀúÀåµÈ°÷ÀÇ index¸¦ ¾î¶² ÇÔ¼ö¸¦ Àû¿ëÇÏ¿© ¿© ¾òÀº °ªÀ» »ç¿ëÇÒ ¼ö µµ ÀÖ´Ù. (¿¹, ÆÄÀÏÀ̸§ÀÇ MD5 Ű) ´Ù¸¥ ´ë¾ÈÀ¸·Î IV¸¦ ¾ÏȣȭµÈ µ¥ÀÌÅÍ¿Í ÇÔ²² º¸³»´Â ¹æ¹ýÀÌ ÀÖ´Ù. (¿©±â¿¡ ´ëÇØ¼­´Â SchneierÀÇ Applied CryptographyÀÇ chapter 9.3À» º¸¶ó.)

Table of Contents
mcrypt_get_cipher_name Get the name of the specified cipher
mcrypt_get_block_size Get the block size of the specified cipher
mcrypt_get_key_size Get the key size of the specified cipher
mcrypt_create_iv Create an initialization vector (IV) from a random source
mcrypt_cbc Encrypt/decrypt data in CBC mode
mcrypt_cfb Encrypt/decrypt data in CFB mode
mcrypt_ecb Encrypt/decrypt data in ECB mode
mcrypt_ofb Encrypt/decrypt data in OFB mode

mcrypt_get_cipher_name

mcrypt_get_cipher_name -- ƯÁ¤ ¾ÏÈ£¹æ½Ä(cipher)ÀÇ À̸§À» ±¸ÇÑ´Ù.

Description

string mcrypt_get_cipher_name (int cipher)

Mcrypt_get_cipher_name() is used to get the name of the specified cipher.

Mcrypt_get_cipher_name() takes the cipher number as an argument and returns the name of the cipher or false, if the cipher does not exist.

Example 1. Mcrypt_get_cipher_name() example

  1 
  2 <?php
  3 $cipher = MCRYPT_TripleDES;
  4 
  5 print mcrypt_get_cipher_name ($cipher);
  6 ?>
  7       

The above example will produce:
  1 
  2 TripleDES
  3      

mcrypt_get_block_size

mcrypt_get_block_size -- ƯÁ¤ ¾ÏÈ£¹æ½Ä(cipher)ÀÇ ºí·Ï Å©±â¸¦ ±¸ÇÑ´Ù.

Description

int mcrypt_get_block_size(int cipher);

mcrypt_get_block_size() is used to get the size of a block of the specified cipher.

mcrypt_get_block_size() takes one argument, the cipher and returns the size in bytes.

See also: mcrypt_get_key_size()

mcrypt_get_key_size

mcrypt_get_key_size -- ƯÁ¤ ¾ÏÈ£¹æ½Ä(cipher)ÀÇ keyÀÇ ±æÀ̸¦ ±¸ÇÑ´Ù.

Description

int mcrypt_get_key_size(int cipher);

mcrypt_get_key_size() is used to get the size of a key of the specified cipher.

mcrypt_get_key_size() takes one argument, the cipher and returns the size in bytes.

See also: mcrypt_get_block_size()

mcrypt_create_iv

mcrypt_create_iv -- ·£´ý ¼Ò½º¿¡¼­ initialization vector(IV)¸¦ ¸¸µç´Ù.

Description

string mcrypt_create_iv (int size, int source)

Mcrypt_create_iv() is used to create an IV.

mcrypt_create_iv() takes two arguments, size determines the size of the IV, source specifies the source of the IV.

The source can be MCRYPT_RAND (system random number generator), MCRYPT_DEV_RANDOM (read data from /dev/random) and MCRYPT_DEV_URANDOM (read data from /dev/urandom). If you use MCRYPT_RAND, make sure to call srand() before to initialize the random number generator.

Example 1. Mcrypt_create_iv() example

  1 
  2 <?php
  3 $cipher = MCRYPT_TripleDES;
  4 $block_size = mcrypt_get_block_size ($cipher);
  5 $iv = mcrypt_create_iv ($block_size, MCRYPT_DEV_RANDOM);
  6 ?>
  7       

mcrypt_cbc

mcrypt_cbc -- CBC ¸ðµå·Î µ¥ÀÌÅ͸¦ ¾ÏȣȭÇϰųª ÇØÁ¦ ÇÑ´Ù.

Description

int mcrypt_cbc(int cipher, string key, string data, int mode, string [iv]);

mcrypt_cbc() encrypts or decrypts (depending on mode) the data with cipher and key in CBC cipher mode and returns the resulting string.

cipher is one of the MCRYPT_ciphername constants.

key is the key supplied to the algorithm. It must be kept secret.

data is the data which shall be encrypted/decrypted.

mode is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.

iv is the optional initialization vector.

See also: mcrypt_cfb(), mcrypt_ecb(), mcrypt_ofb()

mcrypt_cfb

mcrypt_cfb -- CFB ¸ðµå·Î µ¥ÀÌÅ͸¦ ¾ÏȣȭÇϰųª ÇØÁ¦ ÇÑ´Ù.

Description

int mcrypt_cfb(int cipher, string key, string data, int mode, string iv);

mcrypt_cfb() encrypts or decrypts (depending on mode) the data with cipher and key in CFB cipher mode and returns the resulting string.

cipher is one of the MCRYPT_ciphername constants.

key is the key supplied to the algorithm. It must be kept secret.

data is the data which shall be encrypted/decrypted.

mode is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.

iv is the initialization vector.

See also: mcrypt_cbc(), mcrypt_ecb(), mcrypt_ofb()

mcrypt_ecb

mcrypt_ecb -- ECB ¸ðµå·Î µ¥ÀÌÅ͸¦ ¾ÏȣȭÇϰųª ÇØÁ¦ ÇÑ´Ù.

Description

int mcrypt_ecb(int cipher, string key, string data, int mode);

mcrypt_ecb() encrypts or decrypts (depending on mode) the data with cipher and key in ECB cipher mode and returns the resulting string.

cipher is one of the MCRYPT_ciphername constants.

key is the key supplied to the algorithm. It must be kept secret.

data is the data which shall be encrypted/decrypted.

mode is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.

See also: mcrypt_cbc(), mcrypt_cfb(), mcrypt_ofb()

mcrypt_ofb

mcrypt_ofb -- OFB ¸ðµå·Î µ¥ÀÌÅ͸¦ ¾ÏȣȭÇϰųª ÇØÁ¦ ÇÑ´Ù.

Description

int mcrypt_ofb(int cipher, string key, string data, int mode, string iv);

mcrypt_ofb() encrypts or decrypts (depending on mode) the data with cipher and key in OFB cipher mode and returns the resulting string.

cipher is one of the MCRYPT_ciphername constants.

key is the key supplied to the algorithm. It must be kept secret.

data is the data which shall be encrypted/decrypted.

mode is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.

iv is the initialization vector.

See also: mcrypt_cbc(), mcrypt_cfb(), mcrypt_ecb()


XIX. filePro functions

ÀÌ ÇÔ¼öµéÀº filePro ÇüÅÂÀÇ databse(dbf)¿¡ ÀúÀåµÈ ·¹ÄÚµåµéÀ» read-only·Î Á¢±ÙÇÒ ¼ö ÀÖ°Ô ÇØ ÁØ´Ù.

filePro´Â Fiserv, Inc.ÀÇ trademark·Î µî·ÏµÇ¾î ÀÖ´Ù. ¿©·¯ºÐÀº http://www.fileproplus.com/¿¡¼­ filePro¿¡ °üÇÑ ´õ ¸¹Àº Á¤º¸¸¦ ¾òÀ» ¼ö ÀÖ´Ù.

Table of Contents
filepro ¡¦ read and verify the map file
filepro_fieldname ¡¦ gets the name of a field
filepro_fieldtype ¡¦ gets the type of a field
filepro_fieldwidth ¡¦ gets the width of a field
filepro_retrieve ¡¦ retrieves data from a filePro database
filepro_fieldcount ¡¦ find out how many fields are in a filePro database
filepro_rowcount ¡¦ find out how many rows are in a filePro database

filepro

filepro -- map fileÆÄÀÏÀ» ÀÐ°í °ËÁõÇÑ´Ù.

Description

bool filepro(string directory);

This reads and verifies the map file, storing the field count and info.

No locking is done, so you should avoid modifying your filePro database while it may be opened in PHP.

filepro_fieldname

filepro_fieldname -- fieldÀÇ À̸§À» ±¸ÇÑ´Ù.

Description

string filepro_fieldname(int field_number);

Returns the name of the field corresponding to field_number.

filepro_fieldtype

filepro_fieldtype -- fieldÀÇ typeÀ» ±¸ÇÑ´Ù.

Description

string filepro_fieldtype(int field_number);

Returns the edit type of the field corresponding to field_number.

filepro_fieldwidth

filepro_fieldwidth -- fieldÀÇ Å©±â(width)¸¦ ±¸ÇÑ´Ù.

Description

int filepro_fieldwidth(int field_number);

Returns the width of the field corresponding to field_number.

filepro_retrieve

filepro_retrieve -- filePro database¿¡¼­ µ¥ÀÌŸ¸¦ °Ë»öÇÑ´Ù.

Description

string filepro_retrieve(int row_number, int field_number);

Returns the data from the specified location in the database.

filepro_fieldcount

filepro_fieldcount -- filePro databaseÀÇ fieldÀÇ °³¼ö¸¦ ±¸ÇÑ´Ù.

Description

int filepro_fieldcount(void);

Returns the number of fields (columns) in the opened filePro database.

See also filepro().

filepro_rowcount

filepro_rowcount -- filePro databaseÀÇ rowÀÇ °³¼ö¸¦ ±¸ÇÑ´Ù.

Description

int filepro_rowcount(void);

Returns the number of rows in the opened filePro database.

See also filepro().


XX. Filesystem functions

Table of Contents
basename ¡¦ return filename component of path
chgrp ¡¦ change file group
chmod ¡¦ change file mode
chown ¡¦ change file owner
clearstatcache ¡¦ clear file stat cache
copy ¡¦ copy file
delete ¡¦ a dummy manual entry
dirname ¡¦ return directory name component of path
diskfreespace ¡¦ return available space in directory
fclose ¡¦ close an open file pointer
feof ¡¦ test for end-of-file on a file pointer
fgetc ¡¦ get character from file pointer
fgetcsv ¡¦ get line from file pointer and parse for CSV fields
fgets ¡¦ get line from file pointer
fgetss ¡¦ get line from file pointer and strip HTML tags
file ¡¦ read entire file into an array
file_exists ¡¦ Check whether a file exists.
fileatime ¡¦ get last access time of file
filectime ¡¦ get inode change time of file
filegroup ¡¦ get file group
fileinode ¡¦ get file inode
filemtime ¡¦ get file modification time
fileowner ¡¦ get file owner
fileperms ¡¦ get file permissions
filesize ¡¦ get file size
filetype ¡¦ get file type
flock ¡¦ portable advisory file locking
fopen ¡¦ open file or URL
fpassthru ¡¦ output all remaining data on a file pointer
fputs ¡¦ write to a file pointer
fread ¡¦ Binary-safe file read
fseek ¡¦ seek on a file pointer
ftell ¡¦ tell file pointer read/write position
ftruncate ¡¦ Truncate a file to a given length.
fwrite ¡¦ Binary-safe file write
set_file_buffer ¡¦ Sets file buffering on the given file pointer
is_dir ¡¦ tells whether the filename is a directory
is_executable ¡¦ tells whether the filename is executable
is_file ¡¦ tells whether the filename is a regular file
is_link ¡¦ tells whether the filename is a symbolic link
is_readable ¡¦ tells whether the filename is readable
is_writeable ¡¦ tells whether the filename is writeable
link ¡¦ Create a hard link
linkinfo ¡¦ Get information about a link
mkdir ¡¦ make directory
pclose ¡¦ close process file pointer
popen ¡¦ open process file pointer
readfile ¡¦ output a file
readlink ¡¦ Return the target of a symbolic link
rename ¡¦ rename a file
rewind ¡¦ rewind the position of a file pointer
rmdir ¡¦ remove directory
stat ¡¦ give information about a file
lstat ¡¦ give information about a file or symbolic link
symlink ¡¦ Create a symbolic link
tempnam ¡¦ create unique file name
touch ¡¦ set modification time of file
umask ¡¦ changes the current umask
unlink ¡¦ Delete a file

basename

basename -- pathÁß name ºÎºÐÀ» ±¸ÇÑ´Ù.

Description

string basename(string path);

Given a string containing a path to a file, this function will return the base name of the file.

On Windows, both slash (/) and backslash (\) are used as path separator character. In other environments, it is the forward slash (/).

Example 1. basename() example

$path = "/home/httpd/html/index.php3";
$file = basename($path); // $file is set to "index.php3"

See also: dirname()

chgrp

chgrp -- ÆÄÀÏÀÇ groupÀ» ¹Ù²Û´Ù.

Description

int chgrp(string filename, mixed group);

Attempts to change the group of the file filename to group. Only the superuser may change the group of a file arbitrarily; other users may change the group of a file to any group of which that user is a member.

Returns true on success; otherwise returns false.

On Windows, does nothing and returns true.

See also chown() and chmod().

chmod

chmod -- ÆÄÀÏÀÇ mode¸¦ ¹Ù²Û´Ù.

Description

int chmod(string filename, int mode);

Attempts to change the mode of the file specified by filename to that given in mode.

Note that mode is not automatically assumed to be an octal value. To ensure the expected operation, you need to prefix mode with a zero (0):

chmod( "/somedir/somefile", 755 );   // decimal; probably incorrect
chmod( "/somedir/somefile", 0755 );  // octal; correct value of mode

Returns true on success and false otherwise.

See also chown() and chgrp().

chown

chown -- ÆÄÀÏÀÇ owner¸¦ ¹Ù²Û´Ù.

Description

int chown(string filename, mixed user);

Attempts to change the owner of the file filename to user user. Only the superuser may change the owner of a file.

Returns true on success; otherwise returns false.

NOTE: On Windows, does nothing and returns true.

See also chown() and chmod().

clearstatcache

clearstatcache -- ÆÄÀÏÀÇ stat cache¸¦ ¹Ù²Û´Ù.

Description

void clearstatcache(void);

Invoking the stat() or lstat() system call on most systems is quite expensive. Therefore, the result of the last call to any of the status functions (listed below) is stored for use on the next such call using the same filename. If you wish to force a new status check, for instance if the file is being checked many times and may change or disappear, use this function to clear the results of the last call from memory.

This value is only cached for the lifetime of a single request.

Affected functions include stat(), lstat(), file_exists(), is_writeable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype(), and fileperms().

copy

copy -- ÆÄÀÏÀ» º¹»çÇÑ´Ù.

Description

int copy(string source, string dest);

Makes a copy of a file. Returns true if the copy succeeded, false otherwise.

Example 1. copy() example

if (!copy($file, $file.'.bak')) {
    print("failed to copy $file...<br>\n");
}

See also: rename()

delete

delete -- ½ÇÁ¦·Î´Â ¾ø´Â ¸í·É

Description

void delete(string file);

ÀÌ ¸í·ÉÀ» ã´Â »ç¶÷µéÀº ¾Æ¸¶ unlink()³ª unset() ¸í·ÉÀ» »ç¿ëÇÏ´Â ±â´ÉÀ» ¿øÇÒ °ÍÀÌ´Ù.

See also: ÆÄÀÏÀ» Áö¿ì±â À§Çؼ­´Â unlink(), º¯¼ö¸¦ Áö¿ì±â À§Çؼ­´Â unset()

dirname

dirname -- pathÀÇ DirectoryºÎºÐÀ» µ¹·ÁÁØ´Ù.

Description

string dirname(string path);

Given a string containing a path to a file, this function will return the name of the directory.

On Windows, both slash (/) and backslash (\) are used as path separator character. In other environments, it is the forward slash (/).

Example 1. dirname() example

$path = "/etc/passwd";
$file = dirname($path); // $file is set to "/etc"

See also: basename()

diskfreespace

diskfreespace -- ÇØ´ç µð·ºÅ丮¿¡ ÀúÀå °¡´ÉÇÑ ³²Àº ¿ë·®À» ¹ÝȯÇÑ´Ù.

Description

float diskfreespace(string directory);

Given a string containing a directory, this function will return the number of bytes available on the corresponding disk.

Example 1. diskfreespace() example

$df = diskfreespace("/"); // $df contains the number of bytes available on "/"

fclose

fclose -- ÁöÁ¤µÈ file pointer¸¦ ´Ý´Â´Ù.

Description

int fclose(int fp);

The file pointed to by fp is closed.

Returns true on success and false on failure.

The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen().

feof

feof -- file pointer°¡ end-of-file¿¡ Àִ°¡ °Ë»çÇÑ´Ù.

Description

int feof(int fp);

Returns true if the file pointer is at EOF or an error occurs; otherwise returns false.

The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen().

fgetc

fgetc -- file pointer¿¡¼­ ¹®ÀÚ¸¦ Àд´Ù.

Description

string fgetc(int fp);

Returns a string containing a single character read from the file pointed to by fp. Returns FALSE on EOF (as does feof()).

The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen().

See also fread(), fopen(), popen(), fsockopen(), and fgets().

fgetcsv

fgetcsv -- ÆÄÀÏÀÇ ÇöÀç À§Ä¡¿¡¼­ CSV Çʵå·Î µÈ ÁÙÀ» Àоî¿Í¼­ parseÇÑ´Ù.

Description

array fgetcsv(int fp, int length, string [delimiter]);

Similar to fgets() except that fgetcsv() parses the line it reads for fields in CSV format and returns an array containing the fields read. The field delimiter is a comma, unless you specifiy another delimiter with the optional third parameter.

fp must be a valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen()

length must be greater than the longest line to be found in the CSV file (allowing for trailing line-end characters).

fgetcsv() returns false on error, including end of file.

NB A blank line in a CSV file will be returned as an array comprising just one single null field, and will not be treated as an error.

Example 1. fgetcsv() example - Read and print entire contents of a CSV file

$row=1;
$fp = fopen("test.csv","r");
while ($data = fgetcsv($fp,1000)) {
        $num = count($data);
        print "<p> $num fields in line $row: <br>";
        $row++;
        for ( $c=0; $c<$num; $c++ ) print $data[$c] . "<br>";
}
fclose($fp);

fgets

fgets -- file pointer¿¡¼­ ÇÑ ÁÙÀ» ÀÐ¾î ¿Â´Ù.

Description

string fgets(int fp, int length);

Returns a string of up to length - 1 bytes read from the file pointed to by fp. Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first).

If an error occurs, returns false.

Common Pitfalls:

People used to the 'C' semantics of fgets should note the difference in how EOF is returned.

The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen().

A simple example follows:

Example 1. Reading a file line by line

$fd = fopen("/tmp/inputfile.txt", "r");
while ($buffer = fgets($fd, 4096)) {
  echo $buffer;
}
fclose($fd);

See also fread(), fopen(), popen(), fgetc(), and fsockopen().

fgetss

fgetss -- file pointer¿¡¼­ ÇÑ ÁÙÀ» Àоî¿Í HTML tagµéÀ» stripÇÑ´Ù.

Description

string fgetss(int fp, int length);

Identical to fgets(), except that fgetss attempts to strip any HTML and PHP tags from the text it reads.

See also fgets(), fopen(), fsockopen(), popen(), and strip_tags().

file

file -- ÆÄÀÏ Àüü¸¦ Àо ¹è¿­¿¡ ÀúÀåÇÑ´Ù.

Description

array file(string filename);

Identical to readfile(), except that file() returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached.

See also readfile(), fopen(), and popen().

file_exists

file_exists -- ÆÄÀÏÀÌ Á¸ÀçÇÏ´ÂÁö °Ë»çÇÑ´Ù.

Description

int file_exists(string filename);

Returns true if the file specified by filename exists; false otherwise.

The results of this function are cached. See clearstatcache() for more details.

fileatime

fileatime -- ÆÄÀÏ¿¡ ¸¶Áö¸·À¸·Î Á¢±ÙÇÑ ½Ã°£À» ±¸ÇÑ´Ù.

Description

int fileatime(string filename);

Returns the time the file was last accessed, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details.

filectime

filectime -- ÆÄÀÏÀÇ inode°¡ º¯°æµÈ ½Ã°£À» ±¸ÇÑ´Ù.

Description

int filectime(string filename);

Returns the time the file was last changed, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details.

filegroup

filegroup -- ÆÄÀÏÀÇ groupÀ» ±¸ÇÑ´Ù.

Description

int filegroup(string filename);

Returns the group ID of the owner of the file, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details.

fileinode

fileinode -- ÆÄÀÏÀÇ inode¸¦ ±¸ÇÑ´Ù.

Description

int fileinode(string filename);

Returns the inode number of the file, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details.

filemtime

filemtime -- ÆÄÀÏÀÌ ¼öÁ¤µÈ ½Ã°£À» ±¸ÇÑ´Ù.

Description

int filemtime(string filename);

Returns the time the file was last modified, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details. error.

fileowner

fileowner -- ÆÄÀÏÀÇ owner¸¦ ±¸ÇÑ´Ù.

Description

int fileowner(string filename);

Returns the user ID of the owner of the file, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details. error.

fileperms

fileperms -- ÆÄÀÏÀÇ permissionÀ» ±¸ÇÑ´Ù.

Description

int fileperms(string filename);

Returns the permissions on the file, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details.

filesize

filesize -- ÆÄÀÏÀÇ Å©±â¸¦ ±¸ÇÑ´Ù.

Description

int filesize(string filename);

Returns the size of the file, or false in case of an error.

The results of this function are cached. See clearstatcache() for more details.

filetype

filetype -- ÆÄÀÏÀÇ typeÀ» ±¸ÇÑ´Ù.

Description

string filetype(string filename);

Returns the type of the file. Possible values are fifo, char, dir, block, link, file, and unknown.

Returns false if an error occurs.

The results of this function are cached. See clearstatcache() for more details.

flock

flock -- portable ÆÄÀÏ locking

Description

bool flock(int fp, int operation);

PHP supports a portable way of locking complete files in an advisory way (which means all accessing programs have to use the same way of locking or it will not work).

flock() operates on fp which must be an open file pointer. operation is one of the following values:

flock() allows you to perform a simple reader/writer model which can be used on virtually every platform (including most Unices and even Windows).

flock() returns true on success and false on error (e.g. when a lock could not be acquired).

fopen

fopen -- ÆÄÀÏÀ̳ª URLÀ» ¿¬´Ù.

Description

int fopen(string filename, string mode);

If filename begins with "http://" (not case sensitive), an HTTP 1.0 connection is opened to the specified server and a file pointer is returned to the beginning of the text of the response.

Does not handle HTTP redirects, so you must include trailing slashes on directories.

If filename begins with "ftp://" (not case sensitive), an ftp connection to the specified server is opened and a pointer to the requested file is returned. If the server does not support passive mode ftp, this will fail. You can open files for either reading and writing via ftp (but not both simultaneously).

If filename begins with anything else, the file will be opened from the filesystem, and a file pointer to the file opened is returned.

If the open fails, the function returns false.

mode may be any of the following:

As well, mode may contain the letter 'b'. This is useful only on systems which differentiate between binary and text files (i.e., it's useless on Unix). If not needed, this will be ignored.

Example 1. fopen() example

$fp = fopen("/home/rasmus/file.txt", "r");
$fp = fopen("http://www.php.net/", "r");
$fp = fopen("ftp://user:password@example.com/", "w");

If you are experiencing problems with reading and writing to files and you're using the server module version of PHP, remember to make sure that the files and directories you're using are accessible to the server process.

On the Windows platform, be careful to escape any backslashes used in the path to the file, or use forward slashes.

$fp = fopen("c:\\data\\info.txt", "r");

See also fclose(), fsockopen(), and popen().

fpassthru

fpassthru -- file pointer¿¡¼­ºÎÅÍ ³²¾Æ ÀÖ´Â ¸ðµç µ¥ÀÌŸ¸¦ Ãâ·ÂÇÑ´Ù.

Description

int fpassthru(int fp);

Reads to EOF on the given file pointer and writes the results to standard output.

If an error occurs, fpassthru() returns false.

The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen(). The file is closed when fpassthru() is done reading it (leaving fp useless).

If you just want to dump the contents of a file to stdout you may want to use the readfile(), which saves you the fopen() call.

See also readfile(), fopen(), popen(), and fsockopen()

fputs

fputs -- file pointer¿¡ ¾´´Ù.

Description

int fputs(int fp, string str, int [length]);

fputs() is an alias to fwrite(), and is identical in every way. Note that the length parameter is optional and if not specified the entire string will be written.

fread

fread -- ÆÄÀÏÀ» binary·Î Àоî¿Â´Ù.

Description

string fread(int fp, int length);

fread() reads up to length bytes from the file pointer referenced by fp. Reading stops when length bytes have been read or EOF is reached, whichever comes first.

// get contents of a file into a string
$filename = "/usr/local/something.txt";
$fd = fopen( $filename, "r" );
$contents = fread( $fd, filesize( $filename ) );
fclose( $fd );

See also fwrite(), fopen(), fsockopen(), popen(), fgets(), fgetss(), file(), and fpassthru().

fseek

fseek -- file pointer¸¦ ¿Å±ä´Ù.

Description

int fseek(int fp, int offset);

Sets the file position indicator for the file referenced by fp to offset bytes into the file stream. Equivalent to calling (in C) fseek( fp, offset, SEEK_SET ).

Upon success, returns 0; otherwise, returns -1. Note that seeking past EOF is not considered an error.

May not be used on file pointers returned by fopen() if they use the "http://" or "ftp://" formats.

See also ftell() and rewind().

ftell

ftell -- file pointerÀÇ read/write À§Ä¡¸¦ ±¸ÇÑ´Ù.

Description

int ftell(int fp);

Returns the position of the file pointer referenced by fp; i.e., its offset into the file stream.

If an error occurs, returns false.

The file pointer must be valid, and must point to a file successfully opened by fopen() or popen().

See also fopen(), popen(), fseek() and rewind().

ftruncate

(PHP4 >= 4.0RC1)

ftruncate --  ÆÄÀÏÀ» ÁÖ¾îÁø Å©±â·Î ¸¸µç´Ù.

Description

int ftruncate (int fp, int size)

Takes the filepointer, fp, and truncates the file to length, size. This function returns true on success and false on failure.

fwrite

fwrite -- ÆÄÀÏÀ» Binary·Î ¾´´Ù.

Description

int fwrite(int fp, string string, int [length]);

fwrite() writes the contents of string to the file stream pointed to by fp. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.

Note that if the length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from string.

See also fread(), fopen(), fsockopen(), popen(), and fputs().

set_file_buffer

set_file_buffer -- ÇØ´ç ÆÄÀÏ Æ÷ÀÎÅÍ¿¡¼­ ÆÄÀÏ ¹öÆÛ¸µ(buffering)À» ÁöÁ¤ÇÑ´Ù.

Description

int fwrite(int fp, int buffer);

set_file_buffer() sets the buffering for write operations on the given filepointer fp to buffer bytes. If buffer is 0 then write operations are unbuffered.

The function returns 0 on success, or EOF if the request cannot be honored.

Note that the default for any fopen with calling set_file_buffer is 8K.

See also fopen().

is_dir

is_dir -- ÁöÁ¤µÈ ÆÄÀϸíÀÌ directoryÀΰ¡ ¾Ë·ÁÁØ´Ù.

Description

bool is_dir(string filename);

Returns true if the filename exists and is a directory.

The results of this function are cached. See clearstatcache() for more details.

See also is_file() and is_link().

is_executable

is_executable -- ÁöÁ¤µÈ ÆÄÀϸíÀÌ ½ÇÇà°¡´É ÆÄÀÏÀΰ¡ ¾Ë·ÁÁØ´Ù.

Description

bool is_executable(string filename);

Returns true if the filename exists and is executable.

The results of this function are cached. See clearstatcache() for more details.

See also is_file() and is_link().

is_file

is_file -- ÁöÁ¤µÈ ÆÄÀϸíÀÌ º¸ÅëÆÄÀÏÀΰ¡ ¾Ë·ÁÁØ´Ù.

Description

bool is_file(string filename);

Returns true if the filename exists and is a regular file.

The results of this function are cached. See clearstatcache() for more details.

See also is_dir() and is_link().

is_link

is_link -- ÁöÁ¤µÈ ÆÄÀϸíÀÌ symbolic linkÀΰ¡ ¾Ë·ÁÁØ´Ù.

Description

bool is_link(string filename);

Returns true if the filename exists and is a symbolic link.

The results of this function are cached. See clearstatcache() for more details.

See also is_dir() and is_file().

is_readable

is_readable -- ÁöÁ¤µÈ ÆÄÀϸíÀÌ Àб⠰¡´ÉÀΰ¡ ¾Ë·ÁÁØ´Ù.

Description

bool is_readable(string filename);

Returns true if the filename exists and is readable.

Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often 'nobody'). Safe mode limitations are not taken into account.

The results of this function are cached. See clearstatcache() for more details.

See also is_writeable().

is_writeable

is_writeable -- ÁöÁ¤µÈ ÆÄÀϸíÀÌ ¾²±â °¡´ÉÀΰ¡ ¾Ë·ÁÁØ´Ù.

Description

bool is_readable(string filename);

Returns true if the filename exists and is writeable. The filename argument may be a directory name allowing you to check if a directory is writeable.

Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often 'nobody'). Safe mode limitations are not taken into account.

The results of this function are cached. See clearstatcache() for more details.

See also is_readable().

link

link -- hard link¸¦ ¸¸µç´Ù.

Description

int link(string target, string link);

Link() creates a hard link.

See also the symlink() to create soft links, and readlink() along with linkinfo().

linkinfo

linkinfo -- link¿¡ ´ëÇÑ Á¤º¸¸¦ ±¸ÇÑ´Ù.

Description

int linkinfo(string path);

Linkinfo() returns the st_dev field of the UNIX C stat structure returned by the lstat system call. This function is used to verify if a link (pointed to by path) really exists (using the same method as the S_ISLNK macro defined in stat.h). Returns 0 or FALSE in case of error.

See also symlink(), link(), and readlink().

mkdir

mkdir -- directory¸¦ ¸¸µç´Ù.

Description

int mkdir(string pathname, int mode);

Attempts to create the directory specified by pathname.

Note that you probably want to specify the mode as an octal number, which means it should have a leading zero.

mkdir("/path/to/my/dir", 0700);

Returns true on success and false on failure.

See also rmdir().

pclose

pclose -- process file pointer¸¦ ´Ý´Â´Ù.

Description

int pclose(int fp);

Closes a file pointer to a pipe opened by popen().

The file pointer must be valid, and must have been returned by a successful call to popen().

Returns the termination status of the process that was run.

See also popen().

popen

popen -- process file pointer¸¦ ¿¬´Ù.

Description

int popen(string command, string mode);

Opens a pipe to a process executed by forking the command given by command.

Returns a file pointer identical to that returned by fopen(), except that it is unidirectional (may only be used for reading or writing) and must be closed with pclose(). This pointer may be used with fgets(), fgetss(), and fputs().

If an error occurs, returns false.

       $fp = popen( "/bin/ls", "r" );
      

See also pclose().

readfile

readfile -- fileÀ» Àоî Ãâ·ÂÇÑ´Ù.

Description

int readfile(string filename);

Reads a file and writes it to standard output.

Returns the number of bytes read from the file. If an error occurs, false is returned and unless the function was called as @readfile, an error message is printed.

If filename begins with "http://" (not case sensitive), an HTTP 1.0 connection is opened to the specified server and the text of the response is written to standard output.

Does not handle HTTP redirects, so you must include trailing slashes on directories.

If filename begins with "ftp://" (not case sensitive), an ftp connection to the specified server is opened and the requested file is written to standard output. If the server does not support passive mode ftp, this will fail.

If filename begins with neither of these strings, the file will be opened from the filesystem and its contents written to standard output.

See also fpassthru(), file(), fopen(), include(), require(), and virtual().

readlink

readlink -- symbolic linkÀÇ ´ë»óÀ» ¹ÝȯÇÑ´Ù.

Description

int readlink(string path);

Readlink() does the same as the readlink C function and returns the contents of the symbolic link path or 0 in case of error.

See also symlink(), readlink() and linkinfo().

rename

rename -- ÆÄÀϸíÀ» ¹Ù²Û´Ù.

Description

int rename(string oldname, string newname);

Attempts to rename oldname to newname.

Returns true on success and false on failure.

rewind

rewind -- file pointer¸¦ ÆÄÀÏÀÇ Ã³À½ À§Ä¡·Î ¼³Á¤ÇÑ´Ù.

Description

int rewind(int fp);

Sets the file position indicator for fp to the beginning of the file stream.

If an error occurs, returns 0.

The file pointer must be valid, and must point to a file successfully opened by fopen().

See also fseek() and ftell().

rmdir

rmdir -- directory¸¦ Áö¿î´Ù.

Description

int rmdir(string dirname);

Attempts to remove the directory named by pathname. The directory must be empty, and the relevant permissions must permit this.

If an error occurs, returns 0.

See also mkdir().

stat

stat -- ÆÄÀÏÀÇ stat Á¤º¸¸¦ ±¸ÇÑ´Ù.

Description

array stat(string filename);

Gathers the statistics of the file named by filename.

Returns an array with the statistics of the file with the following elements:

* - only valid on systems supporting the st_blksize type--other systems (i.e. Windows) return -1

The results of this function are cached. See clearstatcache() for more details.

lstat

lstat -- ÆÄÀÏÀ̳ª symbolic linkÀÇ stat Á¤º¸¸¦ ±¸ÇÑ´Ù.

Description

array lstat(string filename);

Gathers the statistics of the file or symbolic link named by filename. This function is identical to the stat() function except that if the filename parameter is a symbolic link, the status of the symbolic link is returned, not the status of the file pointed to by the symbolic link.

Returns an array with the statistics of the file with the following elements:

* - only valid on systems supporting the st_blksize type--other systems (i.e. Windows) return -1

The results of this function are cached. See clearstatcache() for more details.

symlink

symlink -- symbolic link¸¦ ¸¸µç´Ù.

Description

int symlink(string target, string link);

symlink() creates a symbolic link from the existing target with the specified name link.

See also link() to create hard links, and readlink() along with linkinfo().

tempnam

tempnam -- À¯ÀÏÇÑ ÆÄÀϸíÀ» ¸¸µç´Ù.

Description

string tempnam(string dir, string prefix);

Creates a unique temporary filename in the specified directory. If the directory does not exist, tempnam() may generate a filename in the system's temporary directory.

The behaviour of the tempnam() function is system dependent. On Windows the TMP environment variable will override the dir parameter, on Linux the TMPDIR environment variable has precedence, while SVR4 will always use your dir parameter if the directory it points to exists. Consult your system documentation on the tempnam(3) function if in doubt.

Returns the new temporary filename, or the null string on failure.

Example 1. tempnam() example

$tmpfname = tempnam( "/tmp", "FOO" );

touch

touch -- ÆÄÀÏÀÇ ¼öÁ¤ ½Ã°¢À» ¼³Á¤ÇÑ´Ù.

Description

int touch(string filename, int time);

Attempts to set the modification time of the file named by filename to the value given by time. If the option time is not given, uses the present time.

If the file does not exist, it is created.

Returns true on success and false otherwise.

umask

umask -- ÇöÀçÀÇ umask¸¦ º¯°æÇÑ´Ù.

Description

int umask(int mask);

Umask() sets PHP's umask to mask & 0777 and returns the old umask. When PHP is being used as a server module, the umask is restored when each request is finished.

Umask() without arguments simply returns the current umask.

unlink

unlink -- ÆÄÀÏÀ» Áö¿î´Ù.

Description

int unlink(string filename);

Deletes filename. Similar to the Unix C unlink() function.

Returns 0 or FALSE on an error.

See also rmdir() for removing directories.


XXI. Forms Data Format functions

À̰ÍÀº PHP¿¡¼­ Forms Data Format (FDF)À» Áö¿øÇϱâÀ§ÇÑ Ã¹ ¹øÂ° ½ÃµµÀÌ´Ù. FDF¿Í À̰ÍÀÇ »ç¿ë¹ý¿¡ ´ëÇØ ¾Ë°í ½Í´Ù¸é http://partners.adobe.com/asn/developer/acrosdk/forms.htmlÀ» Àо¾Æ¾ß ÇÒ °ÍÀÌ´Ù.

Note: ÇöÀç Adobe´Â Linux¿ëÀ¸·Î libc5¿¡ ȣȯµÇ´Â ¹öÀü¸¸À» Á¦°øÇÑ´Ù. glibc2¿¡¼­ Å×½ºÆ® ÇØ º¸¾ÒÀ¸³ª segmentation fault°¡ ¹ß»ýÇÏ¿´´Ù. ¸¸¾à ´©±º°¡ À̰ÍÀ» °¡´ÉÇÏ°Ô ÇÑ »ç¶÷ÀÌ ÀÖ´Ù¸é ¾ð±ÞÇØ Áֱ⸦ ¹Ù¶õ´Ù.

Note: ¸¸¾à php¸¦ fdftk Áö¿øÀ¸·Î ¼³Á¤ÇÏ´Â °ÍÀÌ Àß ¾ÈµÇ´Â °æ¿ì, Çì´õ ÆÄÀÏÀÎ FdfTk.h¿Í libFdfTk.so ¶óÀ̺귯¸® ÆÄÀÏÀÌ Á¦ÀÚ¸®¿¡ Àִ°¡ºÎÅÍ È®ÀÎÇØ º¸ÀÚ. µÎ ÆÄÀÏÀº °¢°¢ fdftk-dir/include¿Í fdftk-dir/lib µð·ºÅ丮¿¡ ÀÖ¾î¾ß ÇÑ´Ù. ¿©·¯ºÐÀÌ FdfTk ¹èÆ÷º»À» Ç®¾î³õ±â¸¸ ÇÑ °æ¿ì ¾Æ¸¶µµ ÀÌ µÎ ÆÄÀÏÀº Á¦ À§Ä¡¿¡ ÀÖÁö ¾ÊÀ» °ÍÀÌ´Ù.

FDFÀÇ ¾ÆÀ̵ð¾î´Â HTML Æû°ú ºñ½ÁÇÏ´Ù. ±âº»ÀûÀ¸·Î ´Ù¸¥ °ÍÀº submit ¹öưÀÌ ´­·ÁÁ³À» ¶§ ¼­¹ö¿¡ Àü¼ÛµÇ´Â Æ÷¸Ë(½ÇÁ¦·Î À̰ÍÀÌ Form Data FormatÀÌ´Ù)°ú, Æû ÀÚüÀÇ ÇüÅÂ(À̰ÍÀº Portable Document Format, PDFÀÌ´Ù)ÀÌ´Ù. FDF µ¥ÀÌÅ͸¦ ó¸®ÇÏ´Â °ÍÀÌ fdf ÇÔ¼öµéÀÌ Á¦°øÇÏ´Â ±â´ÉÁß ÇϳªÀÌ´Ù. ÇÏÁö¸¸ ±×°ÍÀÌ ÀüºÎ´Â ¾Æ´Ï´Ù. À̰ÍÀº ±âÁ¸ÀÇ PDF Æû¿¡ ÀÌ Æû ÀÚü¸¦ ¼öÁ¤ÇÏÁö ¾Ê°íµµ input Çʵå¿Í µ¥ÀÌÅ͸¦ Ãß°¡ÇÒ ¼ö ÀÖ´Ù. ÀÌ·± °æ¿ì FDF ¹®¼­¸¦ »ý¼ºÇÏ¿© (fdf_create()) °¢°¢ÀÇ input Çʵ忡 °ªÀ» ¼³Á¤Çϰí (fdf_set_value()), À̰ÍÀ» PDF Æû¿¡ ¹èÄ¡½ÃŰ¸é µÈ´Ù. (fdf_set_file()) ¸¶Áö¸·À¸·Î À̰ÍÀº application/vnd.fdf¶ó´Â MimeTypeÀ» °¡Áö°í ºê¶ó¿ìÀú·Î Àü¼ÛµÇ¾î¾ß ÇÑ´Ù. ¿©·¯ºÐÀÇ ºê¶ó¿ìÀú¿¡ ÀÖ´Â Acrobat reader pluginÀº ÀÌ ¸¶ÀÓ Å¸ÀÔÀ» ÀνÄÇϰí, ÀÌ °áÇÕµÈ PDF formÀ» Àоî FDF ¹®¼­·ÎºÎÅÍ µ¥ÀÌÅ͸¦ ÀÐ¾î µ¥ÀÌÅ͸¦ ä¿î´Ù.

´ÙÀ½Àº form data¸¦ »ç¿ëÇØº¸´Â ¿¹Á¦ÀÌ´Ù.

Example 1. Evaluating a FDF document

  1 
  2 <?php
  3 // Save the FDF data into a temp file
  4 $fdffp = fopen("test.fdf", "w");
  5 fwrite($fdffp, $HTTP_FDF_DATA, strlen($HTTP_FDF_DATA));
  6 fclose($fdffp);
  7 
  8 // Open temp file and evaluate data
  9 // The pdf form contained several input text fields with the names
 10 // volume, date, comment, publisher, preparer, and two checkboxes
 11 // show_publisher and show_preparer.
 12 $fdf = fdf_open("test.fdf");
 13 $volume = fdf_get_value($fdf, "volume");
 14 echo "The volume field has the value '<B>$volume</B>'<BR>";
 15 
 16 $date = fdf_get_value($fdf, "date");
 17 echo "The date field has the value '<B>$date</B>'<BR>";
 18 
 19 $comment = fdf_get_value($fdf, "comment");
 20 echo "The comment field has the value '<B>$comment</B>'<BR>";
 21 
 22 if(fdf_get_value($fdf, "show_publisher") == "On") {
 23   $publisher = fdf_get_value($fdf, "publisher");
 24   echo "The publisher field has the value '<B>$publisher</B>'<BR>";
 25 } else
 26   echo "Publisher shall not be shown.<BR>";
 27 
 28 if(fdf_get_value($fdf, "show_preparer") == "On") {
 29   $preparer = fdf_get_value($fdf, "preparer");
 30   echo "The preparer field has the value '<B>$preparer</B>'<BR>";
 31 } else
 32   echo "Preparer shall not be shown.<BR>";
 33 fdf_close($fdf);
 34 ?>
 35      
Table of Contents
fdf_open ¡¦ Opens a new fdf document
fdf_close ¡¦ Closes the fdf document
fdf_create ¡¦ Creates a new fdf document
fdf_save ¡¦ Saves a fdf document
fdf_get_value ¡¦ Gets the value of a field
fdf_set_value ¡¦ Sets the value of a field
fdf_next_field_name ¡¦ Next field name
fdf_set_ap ¡¦ Sets the appearence of a field
fdf_set_status ¡¦ Sets the value of the /STATUS key
fdf_get_status ¡¦ Gets the value of the /STATUS key
fdf_set_file ¡¦ Sets the value of the /F key
fdf_get_file ¡¦ Gets the value of the /F key

fdf_open

fdf_open -- »õ fdf document¸¦ ¿¬´Ù

Description

int pdf_open(string filename);

The fdf_open() function opens a file with form data. This file must contain the data as returned from a PDF form. Currently, the file has to be created 'manually' by using fopen() and writing the content of HTTP_FDF_DATA with fwrite() into it. A mechanism like for HTML form data where for each input field a variable is created does not exist.

Example 1. Accessing the form data

<?php
// Save the FDF data into a temp file
$fdffp = fopen("test.fdf", "w");
fwrite($fdffp, $HTTP_FDF_DATA, strlen($HTTP_FDF_DATA));
fclose($fdffp);
// Open temp file and evaluate data
$fdf = fdf_open("test.fdf");
...
fdf_close($fdf);
?>
     

See also fdf_close().

fdf_close

fdf_close -- fdf document¸¦ ´Ý´Â´Ù.

Description

void fdf_close(int fdf_document);

The fdf_close() function closes the fdf document.

See also fdf_open().

fdf_create

fdf_create -- »õ fdf document¸¦ ¸¸µç´Ù.

Description

int fdf_create(void );

The fdf_create() creates a new FDF document. This function is needed if one would like to populate input fields in a PDF document with data.

Example 1. Populating a PDF document

<?php
$outfdf = fdf_create();
fdf_set_value($outfdf, "volume", $volume, 0);
fdf_set_file($outfdf, "http:/testfdf/resultlabel.pdf");
fdf_save($outfdf, "outtest.fdf");
fdf_close($outfdf);
Header("Content-type: application/vnd.fdf");
$fp = fopen("outtest.fdf", "r");
fpassthru($fp);
unlink("outtest.fdf");
?>
     

See also fdf_close(), fdf_save(), fdf_open().

fdf_save

fdf_save -- fdf document¸¦ ÀúÀåÇÑ´Ù.

Description

int fdf_save(string filename);

The fdf_save() function saves a FDF document. The FDF Toolkit provides a way to output the document to stdout if the parameter filename is '.'. This does not work if PHP is used as an apache module. In such a case one will have to write to a file and use e.g. fpassthru(). to output it.

See also fdf_close() and example for fdf_create().

fdf_get_value

fdf_get_value -- ÇÑ ÇʵåÀÇ °ªÀ» Àоî¿Â´Ù.

Description

string fdf_get_value(int fdf_document, string fieldname);

The fdf_get_value() function returns the value of a field.

See also fdf_set_value().

fdf_set_value

fdf_set_value -- ÇÑ ÇʵåÀÇ °ªÀ» ¼³Á¤ÇÑ´Ù.

Description

void fdf_set_value(int fdf_document, string fieldname, string value, int isName);

The fdf_set_value() function sets the value of a field. The last parameter determines if the field value is to be converted to a PDF Name (isName = 1) or set to a PDF String (isName = 0).

See also fdf_get_value().

fdf_next_field_name

fdf_next_field_name -- ´ÙÀ½ ÇʵåÀÇ À̸§À» ¹ÝȯÇÑ´Ù.

Description

string fdf_next_field_name(int fdf_document, string fieldname);

The fdf_next_field_name()