21-05-2004
ÐíåõìáôéêÜ Äéêáéþìáôá © 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 the PHP Documentation Group
Copyright
Copyright © 1997 - 2003 áðü ôï PHP Documentation Group. Ôï õëéêü áõôü ìðïñåß íá äéáìïéñáóôåß ìüíï êÜôù áðü ôïõò üñïõò êáé ôéò óõíèÞêåò ðïõ ïñßæïíôáé áðü ôçí Open Publication License, v1.0 Þ íåüôåñç (ç ôåëåõôáßá Ýêäïóç åßíáé äéáèÝóéìç óôï http://www.opencontent.org/openpub/).
ÄéáíïìÞ ïõóéáóôéêÜ áëëáãìÝíùí åêäüóåùí áõôïý ôïõ åããñÜöïõ áðáãïñåýåôáé ÷ùñßò ôçí åéäéêÞ Üäåéá ôïõ copyright holder.
ÄéáíïìÞ ôïõ Ýñãïõ Þ ðáñáãþãùí ôçò äïõëåéÜò óå ïðïéïäÞðïôå ìïñöÞ êïéíïý âéâëßïõ (÷áñôéïý) áðáãïñåýåôáé ÷ùñßò ðñïçãïýìåíç Üäåéá ôïõ copyright holder.
Ôá ìÝëç ôïõ PHP Documentation Group áíáãñÜöïíôáé óôï åîþöõëëï áõôïý ôïõ manual. Óå ðåñßðôùóç ðïõ èÝëåôå íá åðéêïéíùíÞóåôå ìå ôï group, ðáñáêáëïýìå ãñÜøôå óôï phpdoc@lists.php.net.
Ç åíüôçôá 'Extending PHP 4.0' áõôïý ôïõ manual åßíáé copyright © 2000 áðü ôçí Zend Technologies, Ltd. Áõôü ôï õëéêü ìðïñåß íá äéáìïéñáóôåß ìüíï êÜôù áðü ôïõò üñïõò êáé ôéò óõíèÞêåò ðïõ ïñßæåé ç Open Publication License, v1.0 Þ íåüôåñç (ç ôåëåõôáßá Ýêäïóç åßíáé åðß ôïõ ðáñüíôïò äéáèÝóéìç óôï http://www.opencontent.org/openpub/).
Ç PHP, ôçò ïðïßáò ôá áñ÷éêÜ áíôéðñïóùðåýïõí ôï "PHP: Hypertext Preprocessor" åßíáé ìéá åõñÝùò ÷ñçóéìïðïéïýìåíç, áíïé÷ôïý êþäéêá, ãåíéêïý óêïðïý scripting ãëþóóá ðñïãñáììáôéóìïý, ç ïðïßá åßíáé åéäéêÜ êáôÜëëçëç ãéá áíÜðôõîç åöáñìïãþí ãéá ôï Web êáé ìðïñåß íá åíóùìáôùèåß óôçí HTML. Ç óýíôáîç ôçò ðáßñíåé óôïé÷åßá ôùí C, Java, êáé Perl êáé åßíáé åýêïëç óôçí ìÜèçóç. Ï êýñéïò óôü÷ïò ôçò ãëþóóáò åßíáé íá åðéôñÝðåé óå web developers íá ãñÜöïõí äõíáìéêÜ ðáñáãüìåíåò óåëßäåò (webpages) ãñÞãïñá, áëëÜ êáíåßò ìðïñåß íá êÜíåé ðïëý ðåñéóóüôåñá ìå ôçí PHP.
Áõôü ôï manual (åã÷åéñßäéï) áðïôåëåßôáé ðñùôßóôùò áðü Ýíá êáôÜëïãï óå ðáñáðïìðÝò óõíáñôÞóåùí (function reference) áëëÜ åðßóçò ðåñéÝ÷åé ìéá ðáñáðïìðÞ ãëþóóáò (language reference), åðåîçãÞóåéò ôùí ðéï êýñéùí ÷áñáêôçñéóôéêþí ôçò PHP êáé Üëëåò óõìðëçñùìáôéêÝò ðëçñïöïñßåò.
Ìðïñåßôå íá êÜíåôå download (áíáêôÞóåôå) áõôü ôï manual óå äéÜöïñåò ìïñöÝò óôï http://www.php.net/docs.php. Ôá download áíáíåþíïíôáé êáèþò ôá ðåñéå÷üìåíá áëëÜæïõí. Ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôï ðþò áõôü ôï manual áíáðôýóóåôáé, ìðïñïýí íá âñåèïýí óôï ðáñÜñôçìá Ó÷åôéêÜ ìå ôï manual.
Tçí åëëçíéêÞ ìåôÜöñáóç ôïõ åã÷åéñéäßïõ ôçò PHP åðéìåëÞèçêå ï ÄçìÞôñçò ÃëÝæïò. Ãéá ôç ìåôÜöñáóç åñãÜóôçêáí ïé ÄçìÞôñçò ÃëÝæïò, ÈåìéóôïêëÞò ÌáõñïåéäÞò, ÄÜöíç Ìðïýóéïõ, Ãéþñãïò ÊïíôáîÞò êáé Ãéþñãïò Êåñáìßäáò.
Äåßôå åðßóçò ôçí Éóôïñßá ôçò PHP.
Ç PHP, ôçò ïðïßáò ôá áñ÷éêÜ áíôéðñïóùðåýïõí ôï "PHP: Hypertext Preprocessor" åßíáé ìéá åõñÝùò ÷ñçóéìïðïéïýìåíç, áíïé÷ôïý êþäéêá, ãåíéêïý óêïðïý scripting ãëþóóá ðñïãñáììáôéóìïý, ç ïðïßá åßíáé åéäéêÜ êáôÜëëçëç ãéá áíÜðôõîç åöáñìïãþí ãéá ôï Web êáé ìðïñåß íá åíóùìáôùèåß óôçí HTML.
ÁðëÞ áðÜíôçóç, áëëÜ ôé óçìáßíåé; ¸íá ðáñÜäåéãìá:
ÐáñáôçñÞóôå ðùò áõôü åßíáé äéáöïñåôéêü áðü Ýíá script ãñáììÝíï óå Üëëåò ãëþóóåò ðñïãñáììáôéóìïý üðùò ç Perl Þ ç C : Áíôß íá ãñÜöåôå Ýíá ðñüãñáììá ìå ðïëëÝò åíôïëÝò ãéá íá åîÜãåôå HTML, ãñÜöåôå Ýíá HTML script ìå êÜðïéï åíóùìáôùìÝíï êþäéêá ãéá íá êÜíåé êÜôé (óå áõôÞ ôçí ðåñßðôùóç, íá åìöáíßæåé êÜðïéï êåßìåíï). Ï êþäéêáò PHP åßíáé åóþêëåéóôïò óå åéäéêÜ tags (åôéêÝôåò) áñ÷Þò êáé ôÝëïõò ðïõ óáò åðéôñÝðïõí íá ìåôáöÝñåóôå ìÝóá êáé Ýîù áðü ôï "PHP mode" (PHP ôñüðï ëåéôïõñãßáò).
Áõôü ðïõ äéá÷ùñßæåé ôçí PHP áðü êÜôé óáí client-side Javascript åßíáé üôé ï êþäéêáò åêôåëåßôáé óôïí server (åîçðçñåôçôÞ). Áí åß÷áôå Ýíá script óáí ôï ðáñáðÜíù óôïí server óáò, ï client èá Ýðáéñíå ôá áðïôåëÝóìáôá ôçò åêôÝëåóçò áõôïý ôïõ script, ÷ùñßò íá õðÜñ÷åé êáíÝíáò ôñüðïò íá êáôáëÜâåé ôé êþäéêáò õðÜñ÷åé áðü êÜôù. Ìðïñåßôå áêüìç íá ñõèìßóåôå ôïí web server óáò íá ÷åéñßæåôáé üëá ôá HTML áñ÷åßá óáò ìå ôçí PHP, êáé ôüôå ðñáãìáôéêÜ äåí õðÜñ÷åé ôñüðïò ï ÷ñÞóôçò íá êáôáëÜâåé ôé Ý÷åôå êÜôù áðü ôï ìáíßêé óáò.
Ôá êáëýôåñï ðñÜãìá óôçí PHP åßíáé üôé åßíáé åîáéñåôéêÜ áðëÞ ãéá Ýíá íåïöåñìÝíï áëëÜ ðñïóöÝñåé ðïëëÝò ðñïçãìÝíá ÷áñáêôçñéóôéêÜ ãéá Ýíá åðáããåëìáôßá ðñïãñáììáôéóôÞ. Ìçí ôñïìÜæåôå üôáí äéáâÜæåôå ôçí ìáêñïóêåëÞ ëßóôá ìå ôá ÷áñáêôçñéóôéêÜ ôçò PHP. Ìðïñåßôå íá åîïéêåéùèåßôå ìÝóá óå ðïëý ëßãï ÷ñüíï êáé íá áñ÷ßóåôå íá ãñÜöåôå áðëÜ script óå ëßãåò þñåò.
Áí êáé ç áíÜðïôõîç ôçò PHP åóôéÜæåôáé óå server-side scripting, ìðïñåßôå íá êÜíåôå ðïëý ðåñéóóüôåñá ìå áõôÞ. ÄéáâÜóôå ðáñáêÜôù êáé äåßôå ðåñéóóüôåñá óôçí ðáñÜãñáöï Ôé ìðïñåß íá êÜíåé ç PHP;.
ÏôéäÞðïôå. Ç PHP åðéêåíôñþíåôáé êõñßùò óôï server-side scripting, Ýôóé ìðïñåßôå íá êÜíåôå ïôéäÞðïôå Ýíá Üëëï CGI ðñüãñáììá ìðïñåß íá êÜíåé, üðùò íá ìáæÝøåé äåäïìÝíá, íá ðáñÜãåé äõíáìéêü ðåñéå÷üìåíï óåëßäùí, Þ íá óôåßëåé êáé íá ðÜñåé cookies. ÁëëÜ ç PHP ìðïñåß íá êÜíåé ðïëý ðåñéóóüôåñá.
ÕðÜñ÷ïõí ôñåéò êýñéïé ôïìåßò ðïõ ÷ñçóéìïðïéåßôáé Ýíá PHP script.
Server-side scripting. Áõôü åßíáé ôï ðéï ðáñáäïóéáêü êáé ôï êýñéï ðåäßï ãéá ôçí PHP. ×ñåéÜæåóôå ôñßá ðñÜãìáôá ãéá íá äïõëÝøåé áõôü. Ôïí PHP ìåôáãëùôôéóôÞ (parser) (CGI Þ server module), Ýíá webserver (åîçðçñåôçôÞ óåëßäùí) êáé Ýíá web browser ("öõëëïìåôñçôÞ"). ÐñÝðåé íá ôñÝîåôå ôïí webserver, ìå ìéá óõíäåäåìÝíç åãêáôÜóôáóç ôçò PHP. Ìðïñåßôå íá ðñïóðåëÜóåôå ôá áðïôåëÝóìáôá ôïõ PHP ðñïãñÜììáôïò ìå Ýíá web browser, âëÝðïíôáò ôçí óåëßäá PHP ìÝóá áðü ôïí server. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äåßôå ôçí ðáñÜãñáöï ïäçãßåò åãêáôÜóôáóçò.
Command line scripting. Ìðïñåßôå íá öôéÜîåôå Ýíá PHP script ãéá íá ôï ôñÝ÷åôå ÷ùñßò server Þ browser. ×ñåéÜæåóôå ìüíï ôïí PHP ìåôáãëùôôéóôÞ ãéá íá ôçí ÷ñçóéìïðïéÞóåôå ìå áõôü ôïí ôñüðï. Áõôüò ï ôýðïò åßíáé éäáíéêüò ãéá script ðïõ åêôåëïýíôáé óõ÷íÜ ìå ôç ÷ñÞóç ôçò cron (óå *nix Þ Linux) Þ ìå ôïí Task Scheduler (óôá Windows). ÁõôÜ ôá script ìðïñïýí åðßóçò íá ÷ñçóéìïðïéçèïýí ãéá áðëÝò åñãáóßåò åðåîåñãáóßåò êåéìÝíïõ. Äåßôå ôçí åíüôçôá ó÷åôéêÜ ìå ôçí Command line ÷ñÞóç ôçò PHP ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
ÅããñáöÞ client-side GUI åöáñìïãþí (ÃñáöéêÜ ðåñéâÜëëïíôá ÷ñçóôþí). Ç PHP ßóùò íá ìçí åßíáé ç ðéï êáëÞ ãëþóóá ãéá íá ãñÜøåé êáíåßò ðáñáèõñéáêÝò åöáñìïãÝò, áëëÜ áí îÝñåôå PHP ðïëý êáëÜ êáé èÝëåôå íá ÷ñçóéìïðïéÞóåôå êÜðïéá ðñï÷ùñçìÝíá ÷áñáêôçñéóôéêÜ ôçò PHP óôéò client-side åöáñìïãÝò óáò, ìðïñåßôå åðßóçò íá ÷ñçóéìïðïéÞóåôå ôï PHP-GTK ãéá áõôïý ôïõ åßäïõò ôá ðñïãñÜììáôá. ¸÷åôå åðßóçò ôç äõíáôüôçôá íá ãñÜöåôå cross-platform åöáñìïãÝò ìå áõôü ôïí ôñüðï. Ôï PHP-GTK åßíáé ìéá åðÝêôáóç ôçò PHP êáé äåí óõìðåñéëáìâÜíåôáé óôçí êýñéá äéáíïìÞ. Áí åíäéáöÝñåóôå ãéá ôï PHP-GTK, åðéóêåöôåßôå ôçí äéêÞ ôïõ éóôïóåëßäá.
Ç PHP ìðïñåß íá ÷ñçóéìïðïéçèåß óå üëá ôá êýñéá ëåéôïõñãéêÜ óõóôÞìáôá, óõìðåñéëáìâáíïìÝíïõ ôïõ Linux, ðïëëþí åêäï÷þí ôïõ Unix (HP-UX, Solaris êáé OpenBSD), Microsoft Windows, Mac OS X, RISC OS êáé ðéèáíþò óå Üëëá. Ç PHP õðïóôçñßæåé åðßóçò ôïõò Apache, Microsoft Internet Information Server, Personal Web Server, Netscape êáé iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, êáé ðïëëïýò Üëëïõò webserver. Ãéá ôçí ðëåéïøçößá ôùí server ç PHP Ý÷åé Ýíá module, ãéá ôïõò õðüëïéðïõò ç PHP ìðïñåß íá ëåéôïõñãÞóåé ùò Ýíáò CGI åðåîåñãáóôÞò.
¸ôóé ìå ôçí PHP Ý÷åôå ôçí åëåõèåñßá åðéëïãÞò åíüò ëåéôïõñãéêïý óõóôÞìáôïò êáé åíüò web server. ÅðéðëÝïí, Ý÷åôå åðßóçò ôçí åëåõèåñßá íá ÷ñçóéìïðïéÞóåôå óõíáñôçóéáêü (procedural) Þ áíôéêåéìåíïóôñåöÞ (object oriented) ðñïãñáììáôéóìü Þ ìéá áíÜìåéîç ôïõò. Áí êáé ç ðáñïýóá Ýêäïóç äåí õðïóôçñßæåé üëá ôá ðñüôõðá ÷áñáêôçñéóôéêÜ, ìåãÜëåò âéâëéïèÞêåò êþäéêá êáé ìåãÜëåò åöáñìïãÝò (óõìðåñéëáìâáíïìÝíçò êáé ôçò âéâëéïèÞêçò PEAR) åßíáé ãñáììÝíåò ìüíï ìå áíôéêåéìåíïóôñåöÞ êþäéêá.
Ìå ôçí PHP äåí åßóôå ðåñéïñéóìÝíïé íá åîÜãåôå HTML. Ïé äõíáôüôçôåò ôçò PHP óõìðåñéëáìâÜíïõí ôçí åîáãùãÞ åéêüíùí, áñ÷åßùí PDF, áêüìç êáé ôáéíßåò Flash (÷ñçóéìïðïéþíôáò ôá libswf êáé Ming) ðáñÜãïíôáé áìÝóùò. Ìðïñåßôå åðßóçò íá åîÜãåôå åýêïëá ïðïéïäÞðïôå êåßìåíï üðùò XHTML êáé ïðïéïäÞðïôå Üëëï XML áñ÷åßï. Ç PHP ìðïñåß íá äçìéïõñãåß áõôüìáôá áõôÜ ôá áñ÷åßá êáé íá ôá áðïèçêåýåé óôï óýóôçìá áñ÷åßùí, áíôß íá ôá åêôõðþíåé, áðïôåëþíôáò Ýôóé ìéá server-side cache ãéá ôï äõíáìéêü óáò ðåñéå÷üìåíï.
¸íá áðü ôá ðéï äõíáôÜ êáé óçìáíôéêÜ ÷áñáêôçñéóôéêÜ ôçò PHP åßíáé ç õðïóôÞñéîç ðïõ Ý÷åé ãéá Ýíá ìåãÜëï óýíïëï âÜóåùí äåäïìÝíùí. Ç óõããñáöÞ ìéáò óåëßäáò ðïõ õðïóôçñßæåé âÜóåéò äåäïìÝíùí åßíáé åîáéñåôéêÜ áðëÞ. Ïé åîÞò âÜóåéò äåäïìÝíùí õðïóôçñßæïíôáé ìÝ÷ñé óôéãìÞòó:
¸÷ïõìå åðßóçò ìéá áöáéñåôéêÞ åðÝêôáóç DBX âÜóåùí äåäïìÝíùí (DBX database abstraction extension) ðïõ óáò åðéôñÝðåé äéÜöáíá íá ÷ñçóéìïðïéåßôå ïðïéáäÞðïôå âÜóç äåäïìÝíùí õðïóôçñßæåôáé áðü áõôÞ ôçí åðÝêôáóç. ÅðéðëÝïí ç PHP õðïóôçñßæåé ôï ODBC, ôï Open Database Connection standard (Áíïé÷ôü ðñüôõðï Óýíäåóçò ÂÜóåùí äåäïìÝíùí) Ýôóé ìðïñåßôå íá óõíäåèåßôå óå ïðïéáäÞðïôå âÜóç äåäïìÝíùí ðïõ õðïóôçñßæåé áõôü ôï ðáãêüóìéï ðñüôõðï.
Adabas D Ingres Oracle (OCI7 and OCI8) dBase InterBase Ovrimos Empress FrontBase PostgreSQL FilePro (read-only) mSQL Solid Hyperwave Direct MS-SQL Sybase IBM DB2 MySQL Velocis Informix ODBC Unix dbm
Ç PHP Ý÷åé åðßóçò õðïóôÞñéîç ãéá åðéêïéíùíßá ìå Üëëåò õðçñåóßåò ÷ñçóéìïðïéþíôáò ðñùôüêïëëá üðùò LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (óôá Windows) êáé áìÝôñçôá Üëëá. Ìðïñåßôå åðßóçò íá áíïßîåôå raw network sockets êáé íá áëëçëåðéäñÜóåôå ìå ïðïéïäÞðïôå Üëëï ðñùôüêïëëï. Ç PHP Ý÷åé áêüìç õðïóôÞñéîç ãéá ôçí ðåñßðëïêç áíôáëëáãÞ äåäïìÝíùí WDDX ìåôáîý ó÷åäüí üëùí ôùí Web programming ãëùóóþí. Ìéëþíôáò ãéá äéá-åðéêïéíùíßá, ç PHP õðïóôçñßæåé instantiation áíôéêåéìÝíùí Java êáé ôá ÷ñçóéìïðïéåß äéÜöáíá óáí áíôéêåßìåíá PHP. Ìðïñåßôå åðßóçò íá ÷ñçóéìïðïéÞóåôå ôçí CORBA åðÝêôáóç ìáò ãéá íá ðñïóðåëÜóåôå remote (áðïìáêñõóìÝíá) áíôéêåßìåíá.
Ç PHP Ý÷åé åîáéñåôéêÜ ÷ñÞóéìá ÷áñáêôçñéóôéêÜ åðåîåñãáóßáò êåéìÝíùí, áðü ôçí POSIX åðÝîôáóç Þ ôéò Perl regular expressions ìÝ÷ñé XML parsing áñ÷åßùí. Ãéá ôç ìåôáãëþôôéóç êáé ôçí ðñüóâáóç áñ÷åßùí XML, õðïóôçñßæïõìå ôá ðñüôõðá SAX êáé DOM. Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí XSLT åðÝêôáóç ìáò ãéá íá ìåôáôñÝðåôå ôá XML áñ÷åßá óå Üëëåò ìïñöÝò.
Êáèþò ÷ñçóéìïðïéåßôå ôçí PHP óôïí ôïìÝá ôïõ ecommerce, èá âñåßôå ôéò Cybercash payment, CyberMUT, VeriSign Payflow Pro êáé CCVS óõíáñôÞóåéò ÷ñÞóéìåò ãéá ôá online ðñïãñÜììáôá ðëçñùìÞò óáò.
Ôåëåõôáßï áëëÜ óçìáíôéêü, Ý÷ïõìå ðïëëÝò Üëëåò åíäéáöÝñïõóåò åðåêôÜóåéò, ôéò mnoGoSearch search engine óõíáñôÞóåéò, ðïëëÜ åñãáëåßá óõìðßåóçò (gzip, bz2), ìåôáôñïðÝò çìåñïëïãßïõ, ìåôáöñÜóåéò...
¼ðùò âëÝðåôå áõôÞ ç óåëßäá äåí åßíáé áñêåôÞ ãéá íá áðáñéèìÞóåé üëá ôá ÷áñáêôçñéóôéêÜ êáé ðëåïíåêôÞìáôá ôçò PHP. ÄéáâÜóôå ôéò ðáñáêÜôù ðáñáãñÜöïõò ó÷åôéêÜ ìå ôçí åãêáôÜóôáóç ôçò PHP êáé äåßôå ôï ìÝñïò ìå ôçí ðáñáðïìðÞ óõíáñôÞóåùí ãéá åðåîÞãçóç ôùí åðåêôÜóåùí ðïõ áíáöÝñïíôáé åäþ.
Åäþ èÝëïõìå íá óáò äåßîïõìå ôá ðïëý âáóéêÜ ôçò PHP óå Ýíá ìéêñü êáé áðëü ìÜèçìá. Áõôü ôï êåßìåíï äåß÷íåé ìüíï äõíáìéêÞ äçìéïõñãßá éóôïóåëßäùí ìå ôçí PHP áëëÜ ç PHP åßíáé éêáíÞ íá êÜíåé êáé ðïëëÜ Üëëá ðñÜãìáôá áðü ôçí äçìéïõñãßá éóôïóåëßäùí. Äåßôå ôçí åíüôçôá ìå ôßôëï Ôé ìðïñåß íá êÜíåé ç PHP ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Ïé PHP-éêáíÝò óåëßäåò áíôéìåôùðßæïíôáé óáí óõíçèéóìÝíåò HTML óåëßäåò êáé ìðïñåßôå íá ôéò äçìéïõñãÞóåôå êáé íá ôéò ìïñöïðïéÞóåôå ìå ôïí ßäéï ôñüðï ðïõ óõíÞèùò äçìéïõñãåßôå êáíïíéêÝò HTML óåëßäåò.
Óå áõôü ôï tutorial õðïèÝôïõìå ðùò ï server óáò Ý÷åé åíåñãÞ ôçí õðïóôÞñéîç ãéá PHP êáé ðùò üëá ôá áñ÷åßá ðïõ Ý÷ïõí êáôÜëçîç .php ôá ÷åéñßæåôáé ç PHP. Óôïõò ðåñéóóüôåñïõò server áõôÞ åßíáé ç ðñïêáèïñéóìÝíç åðÝêôáóç ãéá ôá PHP áñ÷åßá, áëëÜ ñùôÞóôå ôïí äéá÷åéñéóôÞ ôïõ server ãéá íá åßóôå óßãïõñïé. Áí ï server óáò õðïóôçñßæåé PHP, ôüôå äåí ÷ñåéÜæåôå íá êÜíåôå ôßðïôá. ÁðëÜ äçìéïõñãåßôå ôá .php áñ÷åßá êáé ôá ôïðïèåôåßôå óôçí web directory êáé ï server èá ôá ìåôáãëùôôßóåé ìáãéêÜ ãéá óáò. Äåí ÷ñåéÜæåôáé íá êÜíåôå compile ôßðïôá ïýôå íá åãêáôáóôÞóåôå åðéðëÝïí åñãáëåßá. Óêåöôåßôå áõôÝò ôéò PHP-éêáíÝò óåëßäåò ùò áðëÜ HTML áñ÷åßá ìå ìéá ìåãÜëç ïéêïãÝíåéá êáéíïýñéùí ìáãéêþí tags ðïõ óáò åðéôñÝðïõí íá êÜíåôå üëùí ôùí åéäþí ôá ðñÜãìáôá.
ÄçìéïõñãÞóôå Ýíá áñ÷åßï ìå üíïìá hello.php êÜôù áðü ôçí webserver root directory ìå ôï áêüëïõèï ðåñéå÷üìåíï:
ÐñïóÝîôå ðùò áõôü äåí åßíáé óáí Ýíá CGI script. Ôï áñ÷åßï äåí ÷ñåéÜæåôáé íá åßíáé åêôåëÝóéìï ìå ïðïéïäÞðïôå ôñüðï. Óêåöôåßôå ôï óáí Ýíá êáíïíéêü HTML áñ÷åßï ðïõ ôõã÷áßíåé íá Ý÷åé Ýíá óåô áðü åéäéêÜ tags ðïõ åßíáé äéáèÝóéìá óå óáò ðïõ êÜíïõí ðïëëÜ êáé åíäéáöÝñïíôá ðñÜãìáôá.
Áõôü ôï ðñüãñáììá åßíáé åîáéñåôéêÜ áðëü êáé ðñáãìáôéêÜ äåí ÷ñåéÜæåóôå ôçí PHP ãéá íá äçìéïõñãÞóåôå ìéá óåëßäá óáí êáé áõôÞ. Ôï ìüíï ðïõ êÜíåé åßíáé íá åìöáíßæåé: Hello World ÷ñçóéìïðïéþíôáò ôçí óõíÜñôçóç echo() ôçò PHP.
Áí äïêéìÜóáôå áõôü ôï ðáñÜäåéãìá êáé äåí åß÷å êáìßá Ýîïäï Þ óáò ðñïÝôñåøå óå Ýíá download, Þ âëÝðåôå üëï ôï áñ÷åßï ùò êåßìåíï, ïé ðéèáíüôçôåò åßíáé ðùò ï server ðïõ ÷ñçóéìïðïéåßôå äåí Ý÷åé åíåñãïðïéçìÝíç ôçí PHP. ÆçôÞóôå áðü ôïí äéá÷åéñéóôÞ íá ôçí åíåñãïðïéÞóåé ÷ñçóéìïðïéþíôáò ôï êåöÜëáéï ÅãêáôÜóôáóç áõôïý ôïõ manual. Áí èÝëåôå íá áíáðôýóóåôå PHP scripts ôïðéêÜ, äåßôå ôçí åíüôçôá downloads. Ìðïñåßôå íá áíáðôýóóåôå ôïðéêÜ óå ïðïéïäÞðïôå ëåéôïõñãéêü óýóôçìá áëëÜ óéãïõñåõôåßôå üôé åãêáôáóôÞóáôå êáé Ýíá êáôÜëëçëï web server.
Ôï íüçìá ôïõ ðáñáäåßãìáôïò åßíáé íá äåßîåé ôçí åéäéêÞ ìïñöÞ ôïõ PHP tag (ôçò PHP åôéêÝôáò). Óå áõôü ôï ðáñÜäåéãìá ÷ñçóéìïðïéÞóáìå ôï <?php ãéá íá äåßîïõìå ôçí áñ÷Þ åíüò PHP tag. ¸ðåéôá âÜëáìå ôçí PHP ðñüôáóç êáé áöÞóáìå PHP ëåéôïõñãßá ðñïèÝôïíôáò ôï tag êëåéóßìáôïò ?>. Ìðïñåßôå íá ðçäÜôå ìÝóá êáé Ýîù áðü ôçí PHP ëåéôïõñãßá óå Ýíá HTML áñ÷åßï üóï èÝëåôå.
Ìéá óçìåßùóç óôïõò text editors: ÕðÜñ÷ïõí ðïëëïß text editors (êåéìåíïãñÜöïé) êáé Integrated Development Environments (IDEs) (ÏëïêëçñùìÝíá ðåñéâÜëëïíôá áíÜðôõîçò) ðïõ ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ãéá íá äçìéïõñãÞóåôå, íá ìïñöïðïéÞóåôå êáé íá ÷åéñéóôåßôå áñ÷åßá PHP. Ìéá ìéêñÞ ëßóôá áõôþí ôùí åñãáëåßùí äéáôçñåßôáé óôï PHP Editor's List. Áí èÝëåôå íá ðñïôåßíåôå Ýíá óõíôÜêçô, ðáñáêáëïýìå åðéóêåöôåßôå ôçí ðáñáðÜíù óåëßäá êáé æçôÞóôå áðü ôïí äéá÷åéñéóôÞ ôçò óåëßäåò íá ðñïóèÝóåé ôïí óõíôÜêôç óôçí ëßóôá.
Ìéá óçìåßùóç ãéá ôïõò Word Processors: Ïé word processors (åðåîåñãáóôÝò êåéìÝíïõ) üðùò ôá Openoffice.org, StarOffice Writer, Microsoft Word êáé Abiword äåí åßíáé êáëÞ åðéëïãÞ ãéá ôçí ìïñöïðïßçóç áñ÷åßùí PHP.
Áí åðéèõìåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá áðü áõôïýò ãéá áõôü ôï äïêéìáóôéêü script óéãïõñåõôåßôå ðùò èá áðïèçêåýóåôå ôï áñ÷åßï ùò ÁÐËÏ ÊÅÉÌÅÍÏ áëëéþò ç PHP äåí èá åßíáé éêáíÞ íá åêôåëÝóåé ôï script.
Ìéá óçìåßùóç ãéá ôï Windows Notepad: Áí ãñÜöåôå ôá PHP scripts ÷ñçóéìïðïéþíôáò ôï Windows Notepad, èá ðñÝðåé íá óéãïõñåõôåßôå ðùò ôá áñ÷åßá óáò áðïèçêåýïíôáé ìå ôçí åðÝêôáóç .php. (Ôï Notepad ðñïóèÝôåé ìéá .txt åðÝêôáóç óôá áñ÷åßá áõôüìáôá åêôüò êáé áí ðñïâåßôå óå Ýíá áðü ôá áêüëïõèá êåßìåíá ãéá íá ôï áðïöýãåôå.)
¼ôáí áðïèçêåýôåôå ôï áñ÷åßï êáé óáò æçôåßôáé íá ïñßóåôå Ýíá üíïìá ãéá ôï áñ÷åßï, âÜëôå ôï üíïìá ôïõ áñ÷åßï óå åéóáãùãéêÜ (äçë. "hello.php").
ÅíáëëáêôéêÜ, ìðïñåßôå íá êÜíåôå êëéê óôï 'Text Documetns' drop-down menu óôï ðáñÜèõñï áðïèÞêåõóçò áñ÷åßïõ êáé íá áëëÜîåôå ôçí åðéëïãÞ óå "All files". Ìðïñåßôå ôüôå íá åéóÜãåôå ôï üíïìá ôïõ áñ÷åßïõ ÷ùñßò åéóáãùãéêÜ.
Áò êÜíïõìå êÜôé ëßãï ðéï ÷ñÞóéìï ôþñá. Èá åëÝãîåôå ôé åßäïõò browser ÷ñçóéìïðïéåß ôï Üôïìï ðïõ âëÝðåé ôç óåëßäá. Ãéá íá ôï êÜíïõìå áõôü, åëÝã÷ïõìå ôï user agent string ðïõ óôÝëíåé ï browser óáí ìÝñïò ôïõ HTTP request (áéôÞìáôïò). ÁõôÞ ç ðëçñïöïñßá áðïèçêåýåôáé óå ìéá ìåôáâëçôÞ. Ïé ìåôáâëçôÝò ðÜíôá áñ÷ßæïõí ìå Ýíá óýìâïëï äïëëáñßïõ óôçí PHP. Ç ìåôáâëçôÞ ðïõ ìáò åíäéáöÝñåé ôþñá åßíáé $_SERVER["HTTP_USER_AGENT"].
Óçìåßùóç ãéá ôéò PHP Autoglobals: Ç $_SERVER åßíáé ìéá åéäéêÞ äåóìåõìÝíç ìåôáâëçôÞ ôçò PHP ç ïðïßá ðåñéÝ÷åé üëåò ôéò ðëçñïöïñßåò ôïõ web server. Åßíáé ãíùóôÞ ùò ìéá Autoglobal (Þ Superglobal). Äåßôå ôçí ó÷åôéêÞ óåëßäá ôïõ manual ãéá ôéò Autoglobals ãéá ðåñéóóüôåñåò ðëçñïöïñßåò. ÁõôÝò ïïé åéäéêÝò ìåôáâëçôÝò åéóçãÞèçêáí óôçí PHP 4.1.0. Ðñéí áðü ÷ñçóéìïðïéïýóáìå áíôß áõôïý ôïí ðáëáéüôåñï array $HTTP_*_VARS, üðùò ç $HTTP_SERVER_VARS. Áí êáé îåðåñáóìÝíåò, áõôÝò ïé ðáëáéüôåñåò ìåôáâëçôÝò áêüìç õðÜñ÷ïõí. (Äåßôå åðßóçò ôçí óçìåßùóç óôïí ðáëéü êþäéêá.)
Ãéá íá åìöáíßóïõìå áõôÞ ôçí ìåôáâëçôÞ, ìðïñïýìå áðëÜ íá êÜíïõìå:
ÕðÜñ÷ïõí ðïëëÜ åßäç ôýðùí ìåôáâëçôþí óôçí PHP. Óôï ðáñáðÜíù ðáñÜäåéãìá åêôõðþóáìå Ýíá óôïé÷åßï åíüò Array (ðßíáêá). Ôá arrays åßíáé ðïëý ÷ñÞóéìïé ôýðïé ìåôáâëçôþí.
Ç $_SERVER åßíáé áêüìç ìéá ìåôáâëçôÞ ðïõ ãßíåôáé áõôüìáôá äéáèÝóéìç óå óáò áðü ôçí PHP. Ìðïñåßôå íá äåßôå ìéá ëßóôá óôçí åíüôçôá ÄåóìåõìÝíåò ìåôáâëçôÝò ôïõ manual Þ ìðïñåßôå íá ðÜñåôå ìéá ðëÞñç ëßóôá áõôþí, äçìéïõñãþíôáò Ýíá áñ÷åßï ðïõ åßíáé êÜðùò Ýôóé:
Áí öïñôþóåôå áõôü ôï áñ÷åßï óôïí browser óáò èá äåßôå ìéá óåëßäá ãåìÜôç ìå ðëçñïöïñßåò ãéá ôçí PHP ìáæß ìå ìéá ëßóôá üëùí ôùí ìåôáâëçôþí ðïõ åßíáé äéáèÝóéìåò óå óáò.
Ìðïñåßôå íá ôïðïèåôÞóåôå ðïëëáðëÝò ðñïôÜóåéò PHP óå Ýíá tag ôçò PHP êáé íá äçìéïõñãÞóåôå ìéêñÜ ìðëïê êþäéêá ðïõ êÜíïõí ðåñéóóüôåñá áðü ìéá áðëÞ echo. Ãéá ðáñÜäåéãìá, áí èÝëáìå íá åëÝãîïõìå ãéá ôçí ÷ñÞóç ôïõ Internet Explorer èá ìðïñïýóáìå íá êÜíïõìå êÜôé óáí êáé áõôü:
ÐáñÜäåéãìá 2-4. ÐáñÜäåéãìá: ÄïìÝò åëÝã÷ïõ (control structures) êáé ÓõíáñôÞóåéò
¸íá ðáñÜäåéãìá åîüäïõ áõôïý ôïõ script ìðïñåß íá åßíáé:
|
Åäþ åéóÜãïõìå ìåñéêÝò êáéíïýñéåò Ýííïéåò. ¸÷ïõìå ìéá ðñüôáóç if. Áí åßóôå ãíþñéìïé ìå ôçí âáóéêÞ óýíôáîç ðïõ ÷ñçóéìïðïéåßôáé áðü ôçí ãëþóóá ðñïãñáììáôéóìïý C, ôüôå áõôü èá óáò öáíåß ëïãéêü. Áí äåí îÝñåôå áñêåôÞ C Þ êÜðïéá Üëëç ãëþóóá ðñïãñáììáôéóìïý ðïõ ÷ñçóéìïðïéåßôáé ç ðáñáðÜíù óýíôáîç, ßóùò ÷ñåéáóôåßôå íá äéáëÝîåôå Ýíá åéóáãùãéêü âéâëßï PHP êáé íá äéáâÜóåôå ôá ðñþôá êåöÜëáéá, Þ íá äéáâÜóåôå ôï êïììÜôé ÁíáöïñÜ óôçí Ãëþóóá áõôïý ôïõ manual. Ìðïñåßôå íá âñåßôå ìéá ëßóôá âéâëßùí ãéá PHP óôï http://www.php.net/books.php.
Ç äåýôåñç Ýííïéá ðïõ åéóÜãåôáé åßíáé ç êëÞóç ôçò óõíÜñôçóçò strstr(). Ç strstr() åßíáé ìéá óõíÜñôçóç åíóùìáôùìÝíç ìÝóá óôçí PHP ðïõ øÜ÷íåé Ýíá string ãéá íá âñåß ìÝóá ôïõ Ýíá Üëëï string. Óå áõôÞ ôçí ðåñßðôùóç øÜ÷íïõìå ãéá ôï "MSIE" ìÝóá óôï $_SERVER["HTTP_USER_AGENT"]. Áí ôï string âñåèåß, ç óõíÜñôçóç åðéóôñÝöåé TRUE êáé áí äåí âñåèåß, åðéóôñÝöåé FALSE. Áí åðéóôñÝøåé TRUE, ç ðñüôáóç if ãßíåôáé êáé áõôÞ TRUE êáé ï êþäéêáò ìÝóá óôá {Üãêéóôñá} åêôåëåßôáé. Áëëéþò, äåí åêôåëåßôáé. ÄçìéïõñãÞóôå êáé åóåßò ðáñüìïéá ðáñáäåßãìáôá ìå if , else êáé Üëëåò óõíáñôÞóåéò üðùò ôéò strtoupper() êáé strlen(). ÊÜèå ó÷åôéæüìåíç óåëßäá ôïõ manual ðåñéÝ÷åé ðáñáäåßãìáôá åðßóçò.
Ìðïñïýìå íá ðñï÷ùñÞóïõìå Ýíá âÞìá ðáñáðÝñá êáé íá äåßîïõìå ðùò ìðïñïýìå íá ìðáßíïõìå êáé íá âãáßíïõìå áðü ôçí PHP-ëåéôïõñãßá (PHP-mode) áêüìç êáé óôç ìÝóç åíüò PHP ìðëïê:
Áíôß íá ÷ñçóéìïðïéïýìå ìéá PHP echo ðñüôáóç ãéá íá åîÜãïõìå êÜôé, âãÞêáìå áðü ôçí PHP ëåéôïõñãßá PHP ëåéôïõñãßá êáé óôåßëáìå áðëÞ HTML. Ôï óçìáíôéêü êáé äõíáôü óôïé÷åßï ðïõ ðñÝðåé íá ðñïóÝîïõìå åäþ åßíáé üôé ç ëïãéêÞ ñïÞ ôïõ script ðáñáìÝíåé áíÝðáöç. Ìüíï Ýíá áðü ôá ðáñáðÜíù HTML ìðëïê èá óôáëåß óôïí èåáôÞ, áíÜëïãá ìå ôï áí ç strstr() åðÝóôñåøå TRUE Þ FALSE. Ìå Üëëá ëüãéá, áí ôï string MSIE Ý÷åé âñåèåß Þ ü÷é.
¸íá áðü ôá ðéï éó÷õñÜ ÷áñáêôçñéóôéêÜ ôçò PHP åßíáé ï ôñüðïò ðïõ ÷åéñßæåôáé ôéò HTML öüñìåò (forms). Ç âáóéêÞ éäÝá ðïõ åßíáé óçìáíôéêÞ íá êáôáëÜâåôå åßíáé ðùò ïðïéïäÞðïôå óôïé÷åßï ôçò öüñìáò èá ãßíåé äéáèÝóéìï óôï PHP script óáò. ÄéáâÜóôå ôçí åíüôçôá ôïõ manual ãéá ôéò ÌåôáâëçôÝò áðü Ýîù áðü ôçí PHP ãéá ðåñéóóüôåñåò ðëçñïöïñßåò óôï ðùò íá ÷ñçóéìïðïéåßôå öüñìåò ìå ôçí PHP. ¸íá ðáñÜäåéãìá ìéáò HTML öüñìáò:
Äåí õðÜñ÷åé ôßðïôá åéäéêü ó÷åôéêÜ ìå áõôÞ ôç öüñìá. Åßíáé ìéá áðëÞ HTML öüñìá ÷ùñßò åéäéêÜ tags ïðïéïõäÞðïôå åßäïõò. ¼ôáí ï ÷ñÞóôçò ãåìßóåé áõôÞ ôç öüñìá êáé ðáôÞóåé ôï êïõìðß submit (õðïâïëÞ), ç óåëßäá action.php êáëåßôáé. Óå áõôü ôï áñ÷åßï, èá Ý÷åôå êÜôé óáí êáé áõôü:
ÐñÝðåé íá åßíáé åìöáíÝò ôï ôé êÜíåé. Äåí õðÜñ÷åé ôßðïôá Üëëï åêôüò áðü áõôü. Ïé ìåôáâëçôÝò $_POST["name"] êáé $_POST["age"] áõôüìáôá ïñßæïíôáé ãéá óáò áðü ôçí PHP. Íùñßôåñá ÷ñçóéìïðïéÞóáìå ôçí $_SERVER autoglobal, ôþñá ðáñáðÜíù ìüëéò ÷ñçóéìïðïéÞóáìå ôçí $_POST autoglobal ðïõ ðåñéÝ÷åé üëá ôá äåäïìÝíá POST. ÐñïóÝîôå ðùò ç method (ìÝèïäïò) óôçí öüñìá ìáò åßíáé ç POST. Áí ÷ñçóéìïðïéïýóáìå ôçí GET method, ôüôå ïé ðëçñïöïñßåò ôçò öüñìáò ìáò èá æïýóáí áíôßóôïé÷á ìÝóá óôçí $_GET autoglobal. Ìðïñåßôå åðßóçò íá ÷ñçóéìïðïéÞóåôå ôçí $_REQUEST autoglobal áí äåí íïéÜæåóôå ãéá ôçí ðçãÞ ôùí äåäïìÝíùí óáò. ÐåñéÝ÷åé ìéá áíÜìéîç áðü GET, POST, COOKIE êáé FILE äåäïìÝíùí. Äåßôå åðßóçò ôçí óõíÜñôçóç import_request_variables().
Ôþñá ðïõ ç PHP Ý÷åé ìåãáëþóåé êáé åßíáé ìéá äçìïöéëÞò scripting ãëþóóá, õðÜñ÷ïõí ðåñéóóüôåñïé ðüñïé åêåß Ýîù ïé ïðïßïé Ý÷ïõí êáôáëüãïõò áðü êþäéêá ðïõ ìðïñåßôå íá åðáíá÷ñçóéìïðïéÞóåôå óôá äéêÜ óáò scripts. Óôï ìåãáëýôåñï ìÝñïò, ïé PHP developers (ðñïãñáììáôéóôÝò) ôçò ãëþóóáò PHP ðñïóðÜèçóáí íá åßíáé ðñïò-ôá-ðßóù óõìâáôïß (backwards compatible), ïýôùò þóôå Ýíá script ãñáììÝíï ãéá ìéá ðéï ðáëéÜ Ýêäïóç èá ôñÝ÷åé (éäáíéêÜ) ÷ùñßò áëëáãÝò óå ìéá íåüôåñç Ýêäïóç ôçò PHP. ÐñáêôéêÜ üìùò, êÜðïéåò áëëáãÝò èá ÷ñåéáóôïýí íá ãßíïõí.
Äýï áðü ôéò ðéï óçìáíôéêÝò áëëáãÝò ðïõ åðéñåÜæïõí ðáëáéüôåñï êþäéêá åßíáé:
Ôï ðáëéü array $HTTP_*_VARS Ý÷åé îåðåñáóôåß (ôï ïðïßï ÷ñåéÜæåôáé íá áíáãñáöåß ùò global üôáí ÷ñçóéìïðïéåßôáé óå ìéá function Þ method). Ïé åîÞò autoglobal arrays åéóÞ÷èçóáí óôçí PHP 4.1.0. Åßíáé ïé: $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_REQUEST, and $_SESSION. Ôá ðáëáéüôåñá $HTTP_*_VARS arrays, üðùò ôï $HTTP_POST_VARS, õðÜñ÷ïõí áêüìç áðü ôçí PHP 3.
Ïé åîùôåñéêÝò ìåôáâëçôÝò äåí ãßíïíôáé register (êáôá÷ùñïýíôáé) ùò global åî ïñéóìïý. Ìå Üëëá ëüãéá, áðü ôçí PHP 4.2.0 ôï PHP directive register_globals åßíáé åî ïñéóìïý off óôï in php.ini. Ç ìÝèïäïò ðïõ ðñïôéìåßôáé ãéá ðñïóðÝëáóç áõôþí ôùí ôéìþí åßíáé ìÝóá áðü ôá autoglobal arrays ðïõ áíáöÝñèçêáí íùñßôåñá. Ðáëáéüôåñá scripts, âéâëßá êáé tutorials (ìáèÞìáôá) ìðïñåß íá óôçñßæïíôáé óå áõôÞ ôçí ñýèìéóç íá åßíáé åíåñãïðïéçìÝíç (on). Áí åßíáé åíåñãïðïéçìÝíç, ãéá ðáñÜäåéãìá, êÜðïéïò èá ìðïñïýóå íá ÷ñçóéìïðïéÞóåé ôï $id áðü ôï URL http://www.example.com/foo.php?id=42. Åßôå on åßôå off, ç $_GET['id'] åßíáé äéáèÝóéìç.
Áðü áõôÜ ðïõ îÝñåôå ôþñá, èá åßóôå éêáíïß íá êáôáëÜâåôå ôá ðåñéóóüôåñá áðü áõôü ôï manual êáé åðßóçò ôá äéÜöïñá scripts ðïõ åßíáé äéáèÝóéìá ùò ðáñáäåßãìáôá óôá archives (áñ÷åßá-êáôáëüãïõò) ðáñáäåéãìÜôùí. Ìðïñåßôå åðßóçò íá âñåßôå Üëëá ðáñáäåßãìáôá óôá óôçí óåëßäá php.net, óôçí åíüôçôá ôùí links: http://www.php.net/links.php.
Ðñéí ôçí åãêáôÜóôáóç, ÷ñåéÜæåôáé íá îÝñåôå ãéá ðéï óêïðü èÝëåôå íá ÷ñçóéìïðïéÞóåôå ôçí PHP. ÕðÜñ÷ïõí ôñåéò ôïìåßò ðïõ ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí PHP, üðùò ðåñéãñÜöïíôáé óôçí åíüôçôá Ôé ìðïñåß íá êÜíåé ç PHP?:
Server-side scripting
Command line scripting
ÅöáñìïãÝò Client-side GUI
Ãéá ôçí ðñþôç êáé ðéï óõ÷íÞ ìïñöÞ, ÷ñåéÜæåóôå ôñßá ðñÜãìáôá: Ôçí ßäéá ôçí PHP, Ýíá web server êáé Ýíá web browser. Ðéèáíþò íá Ý÷åôå Þäç Ýíá web browser êáé áíÜëïãá ìå ôçí åãêáôÜóôáóç ôïõ ëåéôïõñãéêïý óáò óõóôÞìáôïò, ìðïñåß íá Ý÷åôå åðßóçò êáé Ýíá web server (ð.÷. Apache óôï Linux Þ IIS óôá Windows). Ìðïñåß åðßóçò íá íïéêéÜæåôå ÷þñï óå êÜðïéá åôáéñßá. Ìå áõôü ôïí ôñüðï, äåí ÷ñåéÜæåôáé íá åãêáôáóôÞóåôå ôßðïôá áðü ìüíïé óáò, áðëÜ ãñÜöåôå ôá php script óáò, ôá êÜíåôå upload óôïí server ðïõ íïéêéÜæåôå êáé âëÝðåôå ôá áðïôåëÝóìáôá óôïí browser óáò.
Êáèþò åãêáèéóôÜôå ôïí server êáé ôçí PHP ìüíïé óáò, Ý÷åôå äýï ôñüðïõò ãéá ôç ìÝèïäï ðïõ èá óõíäÝåôáé ç PHP ìå ôïí server. Ãéá ðïëëïýò servers ç PHP Ý÷åé Ýíá Üìåóï module interface (óõ÷íÜ êáëïýìåíï ùò SAPI). Ìåñéêïß áðü áõôïýò ôïõò servers åßíáé ïé Apache, Microsoft Internet Information Server, Netscape êáé iPlanet servers. Ðïëëïß Üëëïé servers Ý÷ïõí õðïóôÞñéîç ãéá ISAPI, ôï Microsoft module interface (ôï OmniHTTPd ãéá ðáñÜäåéãìá). Áí ç PHP äåí Ý÷åé õðïóôÞñéîç module ãéá ôïí web server óáò, ìðïñåßôå ðÜíôá íá ôçí ÷ñçóéìïðïéÞóåôå óáí Ýíá åðåîåñãáóôÞ CGI. Áõôü óçìáßíåé ðùò èá ñõèìßóåôå ôïí server óáò íá ÷ñçóéìïðïéåß ôï command line åêôåëÝóéìï ôçò PHP (php.exe óôá Windows) ãéá íá åðåîåñãÜæåôáé üëåò ôéò áðáéôÞóåéò ôùí PHP áñ÷åßùí óôïí server.
Áí åíäéáöÝñåóôå åðßóçò ãéá íá ÷ñçóéìïðïéÞóåôå ôçí PHP ãéá command line scripting (ð.÷. íá ãñÜöåôå scripts ôá ïðïßá ðáñÜãïõí áõôüìáôá êÜðïéåò åéêüíåò ãéá óáò offline, Þ íá åðåîåñãÜæïíôáé áñ÷åßá êåßìåíïõ áíÜëïãá ìå êÜðïéá arguments ðïõ ôïõò ðåñíÜôå), ðÜíôá ÷ñåéÜæåóôå ôï command line åêôåëÝóéìï. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äéáâÜóôå ôçí åíüôçôá ó÷åôéêÜ ìå ôçí åããñáöÞ command line åöáñìïãþí PHP. Óå áõôÞ ôçí ðåñßðôùóç, äåí ÷ñåéÜæåóôå server Þ browser.
Ìå ôçí PHP ìðïñåßôå åðßóçò íá ãñÜöåôå client side GUI åöáñìïãÝò ÷ñçóéìïðïéþíôáò ôçí åðÝêôáóç PHP-GTK. ÁõôÞ åßíáé ìéá åíôåëþò äéáöïñåôéêÞ ðñïóÝããéóç áðü ôçí åããñáöÞ éóôïóåëßäùí, ìéá êáé äåí Ý÷åôå HTML óôçí Ýîïäï, áëëÜ ÷åéñßæåóôå ðáñÜèõñá êáé áíôéêåßìåíá. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôï PHP-GTK, ðáñáêáëïýìå åðéóêåöôåßôå ôçí éóôïåëßäá áöéåñïìÝíç óå áõôÞ ôçí åðÝêôáóç. Ç åðÝêôáóç PHP-GTK äåí óõìðåñéëáìâÜíåôáé óôçí åðßóçìç äéáíïìÞ ôçò PHP.
Áðü 'äù êáé ìðñïò, áõôÞ ç åíüôçôá äéáðñáãìáôåýåôáé ôçí ñýèìéóç ôçò PHP ìå web servers óå Unix êáé Windows ìå server module interfaces êáé CGI åêôåëÝóéìá.
Ìðïñåßôå íá êÜíåôå download ôçí PHP, ôï source code (ðçãáßïò êþäéêáò) êáé binary äéáíïìÝò ãéá Windows óôï http://www.php.net/. Ðñïôåßíïõìå íá åðéëÝîåôå Ýíá êïíôéíü óáò mirror ãéá íá êÜíåôå download ôéò äéáíïìÝò.
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé õðïäåßîåéò óõãêåêñéìÝíá ãéá åãêáôÜóôáóç ôçò PHP óå óõóôÞìáôá HP-UX.
ÐáñÜäåéãìá 3-1. Ïäçãßåò åãêáôÜóôáóçò ãéá HP-UX 10
|
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé õðïäåßîåéò óõãêåêñéìÝíåò ãéá åãêáôáóôÜóåéò ôçò PHP óå äéáíïìÝò Linux.
ÐïëëÝò Linux äéáíïìÝò (distributions) Ý÷ïõí êÜðïéï åßäïò åãêáôÜóôáóçò ìÝóù ðáêÝôùí, üðùò ôï RPM. ÁõôÜ ìðïñïýí íá óáò âïçèÞóïõí íá ñõèìßóåôå ìéá êáíïíéêÞ åãêáôÜóôáóç, áëëÜ áí ÷ñåéÜæåóôå Ýíá äéáöïñåôéêü óýíïëï áðü ÷áñáêôçñéóôéêÜ (üðùò Ýíá secure server, Þ Ýíá äéáöïñåôéêü database driver), ìðïñåß íá ÷ñåéáóôåß íá êÜíåôå build ôçí PHP Þ êáé ôïí webserver óáò. Áí äåí åßóôå åîïéêåéùìÝíïé óôçí äéáäéêáóßá ôïõ building êáé compiling ôïõ äéêïý óáò ëïãéóìéêïý, ìðïñåß íá áîßæåé íá øÜîåôå áí êÜðïéïò Ý÷åé Þäç êÜíåé build Ýíá ðáêÝôï ìå ôçí Ýêäïóç ôçò PHP êáé ìå ôéò ñõèìßóåéò ðïõ ÷ñåéÜæåóôå.
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé õðïäåßîåéò óõãêåêñéìÝíåò ãéá åãêáôáóôÜóåéò ôçò PHP óôïí Mac OS X Server.
ÕðÜñ÷ïõí ìåñéêÝò pre-packaged êáé pre-compiled åêäüóåéò ôçò PHP ãéá ôï Mac OS X. ÁõôÝò ìðïñïýí íá óáò âïçèÞóïõí íá ñõèìßóåôå ìéá êáíïíéêÞ åãêáôÜóôáóç, áëëÜ áí ÷ñåéÜæåóôå Ýíá äéáöïñåôéêü óýíïëï áðü ÷áñáêôçñéóôéêÜ (üðùò Ýíá secure server, Þ Ýíá äéáöïñåôéêü database driver), ìðïñåß íá ÷ñåéáóôåß íá êÜíåôå build ôçí PHP Þ êáé ôïí webserver óáò. Áí äåí åßóôå åîïéêåéùìÝíïé óôçí äéáäéêáóßá ôïõ building êáé compiling ôïõ äéêïý óáò ëïãéóìéêïý, ìðïñåß íá áîßæåé íá øÜîåôå áí êÜðïéïò Ý÷åé Þäç êÜíåé build Ýíá ðáêÝôï ìå ôçí Ýêäïóç ôçò PHP êáé ìå ôéò ñõèìßóåéò ðïõ ÷ñåéÜæåóôå.
ÕðÜñ÷ïõí äýï åëáöñÜ äéáöïñåôéêÝò åêäüóåéò ôïõ Mac OS X, ç client êáé ç server. Ôá ðáñáêÜôù éó÷ýïõí ãéá ôïí OS X Server.
ÐáñÜäåéãìá 3-2. ÅãêáôÜóôáóç óôïí Mac OS X server
|
ÁõôÝò ïé õðïäåßîåéò äüèçêáí åõãåíéêÜ áðü ôïí Marc Liyanage.
Ôï PHP module ãéá ôïí Apache web server ðåñéëáìâÜíïíôáé óôïí Mac OS X. ÁõôÞ ç Ýêäïóç ðåñéëáìâÜíåé õðïóôÞñéîç ãéá ôéò MySQL êáé PostgreSQL âÜóåéò äåäïìÝíùí.
Óçìåßùóç: Äþóôå ðñïóï÷Þ üôáí ôï êÜíåôå áõôü, ìðïñåß íá ÷áëÜóåôå ôéò ñõèìßóåéò ôïõ Apache web server óáò!
ÊÜíôå ôá åîÞò ãéá íá åãêáôáóôáèåß:
1. Áíïßîôå Ýíá terminal window
2. ÃñÜøôå "wget http://www.diax.ch/users/liyanage/software/macosx/libphp4.so.gz", êáé ðåñéìÝíåôå íá ôåëåéþóåé ôï download.
3. ÃñÜøôå "gunzip libphp4.so.gz"
4. ÃñÜøôå "sudo apxs -i -a -n php4 libphp4.so"
#AddType application/x-httpd-php .php #AddType application/x-httpd-php-source .phps |
ÔÝëïò, ãñÜøôå "sudo apachectl graceful" ãéá íá åðáíåêêéíÞóåôå (restart) ôïí web server.
Ç PHP ðñÝðåé ôþñá íá åßíáé åíåñãÞ êáé íá ôñÝ÷åé. Ìðïñåßôå íá ôï åëÝãîåôå áõôü áöÞíïíôáò Ýíá áñ÷åßï óôïí êáôÜëïãï "Sites" ðïõ íá ëÝãåôáé "test.php". ÌÝóá óå áõôü ôï áñ÷åßï ãñÜøôå áõôÞ ôç ãñáììÞ: "<?php phpinfo() ?>".
Ôþñá áíïßîôå ôï 127.0.0.1/~your_username/test.php ìÝóá óôïí web browser óáò. Èá ðñÝðåé íá äåßôå Ýíáí ðßíáêá ìå ðëçñïöïñßåò ãéá ôï PHP module.
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé õðïäåßîåéò óõãêåêñéìÝíåò ãéá åãêáôáóôÜóåéò ôçò PHP óôï OpenBSD 3.2.
Ç ÷ñÞóç binary packages ãéá íá åãêáôáóôÞóåôå ôçí PHP óôï OpenBSD åßíáé ç ðñïôåéíüìåíç êáé áðëïýóôåñç ìÝèïäïò. Ôï core package Ý÷åé ÷ùñéóôåß áðü ôá äéÜöïñá modules, êáé êáèÝíá ìðïñåß íá åãêáôáóôáèåß êáé íá áöáéñåèåß áíåîÜñôçôá áðü ôá Üëëá. Ôá áñ÷åßá ðïõ ÷ñåéÜæåóôå ìðïñïýí íá âñåèïýí óôï OpenBSD CD óáò Þ óôï FTP site.
Ôï êýñéï ðáêÝôï ðïõ ÷ñåéÜæåóôå íá åãêáôáóôÞóåôå åßíáé ôï php4-core-4.2.3.tgz, ôï ïðïßï ðåñéÝ÷åé ôçí âáóéêÞ engine (êáé ôá gettext êáé iconv). ¸ðåéôá, êïéôÜîôå óôá module packages, üðùò ôá php4-mysql-4.2.3.tgz Þ php4-imap-4.2.3.tgz. Åßíáé áðáñáßôçôï íá ÷ñçóéìïðïéÞóåôå ôçí phpxs åíôïëÞ ãéá íá åíåñãïðïéÞóåôå êáé íá áðåíåñãïðïéÞóåôå áõôÜ ôá modules ìÝóá óôï php.ini óáò.
ÐáñÜäåéãìá 3-3. ÐáñÜäåéãìá åãêáôÜóôáóçò ôïõ OpenBSD ðáêÝôïõ
|
ÄéáâÜóôå ôçí packages(7) manual page ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå binary packages óôï OpenBSD.
Ìðïñåßôå åðßóçò íá êÜíåôå compile ôçí PHP áðü ôï source ÷ñçóéìïðïéþíôáò ôï ports tree. ÁëëÜ áõôü ðñïôåßíåôáé óå ÷ñÞóôåò ðïõ åßíáé åîïéêåéùìÝíïé ìå ôï OpenBSD. Ôï PHP4 port åßíáé ÷ùñéóìÝíï óå ôñåéò õðïêáôáëüãïõò Ôïõò core, extensions êáé pear. Ôï extensions directory äçìéïõñãåß sub-packages ãéá üëá ôá õðïóôçñéæüìåíá PHP modules. Áí äåßôå ðùò äåí èÝëåôå íá äçìéïõñãÞóåôå êÜðïéá áðü áõôÜ ôá modules, ÷ñçóéìïðïéÞóôå ôï no_* FLAVOR. Ãéá ðáñÜäåéãìá, ãéá íá ðáñáëåßøåôå ôçí äçìéïõñãßá ôïõ imap module, ïñßóôå ôï FLAVOR óå no_imap.
Ðáëáéüôåñåò åêäüóåéò ôïõ OpenBSD ÷ñçóéìïðïéïýóáí ôï FLAVORS óýóôçìá ãéá íá êÜíïõí compile ìéá statically (óôáôéêÜ) linked PHP. Ìéá êáé åßíáé äýóêïëï íá äçìéïõñãçèïýí binary ðáêÝôá ÷ñçóéìïðïéþíôáò áõôÞ ôç ìÝèïäï, Ý÷åé ðëÝïí îåðåñáóôåß. Ìðïñåßôå áêüìç íá ÷ñçóéìïðïéÞóåôå ôï ðáëéü êáé óôáèåñü ports trees áí èÝëåôå, áëëÜ äåí õðïóôçñßæïíôáé áðü ôçí ïìÜäá ôïõ OpenBSD. Áí Ý÷åôå êÜðïéá ó÷üëéá ãéá áõôü ôï èÝìá, ôï port óõíôçñåßôáé óÞìåñá áðü ôïí Anil Madhavapeddy.
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé õðïäåßîåéò óõãêåêñéìÝíåò ãéá åãêáôáóôÜóåéò ôçò PHP óå óõóôÞìáôá Solaris.
Ïé åãêáôáóôÜóåéò ôïõ Solaris óõíÞèùò óôåñïýíôáé áðü C compilers êáé ôá ó÷ôéêÜ åñãáëåßá. Ôï áðáéôïýìåíï ëïãéóìéêü Ý÷åé ùò åîÞò:
gcc (ðñïôåßíåôáé, Üëëïé C compilers ìðïñåß íá äïõëåýïõí)
make
flex
bison
m4
autoconf
automake
perl
gzip
tar
GNU sed
ÁõôÞ ç åíüôçôá èá óáò êáèïäçãÞóåé ìÝóá áðü ôçí ãåíéêÞ ñýèìéóç êáé åãêáôÜóôáóç ôçò PHP se Unix óõóôÞìáôá. Óéãïõñåõôåßôå íá øÜîåôå êÜðïéá åíüôçôá åéäéêÜ ãñáììÝíç ãéá ôçí ðëáôöüñìá Þ ôïí webserver ðñéí îåêéíÞóåôå áõôÞ ôç äéáäéêáóßá.
Ðñïáðáéôïýìåíç ãíþóç êáé ëïãéóìéêü:
ÂáóéêÝò UNIX éêáíüôçôåò (÷åéñéóìüò ôïõ "make" êáé åíüò C compiler, áí êÜíåôå compile)
¸íá ANSI C compiler (áí êÜíåôå compile)
flex (ãéá ôï compiling)
bison (ãéá ôï compiling)
¸íá web server
ÏðïéïäÞðïôå óõãêåêñéìÝíï module component (üðùò ç gd, pdf libs, êëð.)
ÕðÜñ÷ïõí áñêåôïß ôñüðïé íá åãêáôáóôáèåß ç PHP ãéá ôçí Unix ðëáôöüñìá, åßôå ìå Ýíá compile êáé configure äéáäéêáóßá, Þ ìÝóá áðü äéÜöïñåò ðñïðáêåôáñéóìÝíåò ìåèüäïõò. Áõôü ôï documentation åóôéÜæåôáé êõñßùò ãýñù áðü ôç äéáäéêáóßá ôïõ compile êáé ôçò ñýèìéóçò ôçò PHP.
Ç áñ÷éêÞ ñýèìéóç ôçò PHP åëÝã÷åôáé áðü ôçí ÷ñÞóç ôùí commandline options ôïõ configure script. ÁõôÞ ç óåëßäá ðåñéãñÜöåé óýíôïìá ôéò ðéï óõíçèéóìÝíåò åðéëïãÝò, áëëÜ õðÜñ÷ïõí ðïëëÝò Üëëåò íá ðáßîåôå ìáæß ôïõò. ÊïéôÜîôå ôïí ðëÞñç êáôÜëïãï ôùí åðéëïãþí ôïõ configure ãéá ìéá åîáíôëçôéêÞ ðåñéãñáöÞ. ÕðÜñ÷ïõí áñêåôïß ôñüðïé ãéá íá åãêáôáóôÞóåôå ôçí PHP:
Óáí Ýíá Apache module
Óáí Ýíá fhttpd module
Ãéá ÷ñÞóç ìå ôïõò AOLServer, NSAPI, phttpd, Pi3Web, Roxen, thttpd, or Zeus.
Óáí Ýíá CGI executable
Ç PHP ìðïñåß íá åãêáôáóôáèåß ìå áñêåôïýò äéáöïñåôéêïýò ôñüðïò, áëëÜ Ýíáò áðü ôïõò ðéï äçìïöéëåßò åßíáé óáí Ýíá Apache module. Áêïëïõèåß ìéá ãñÞãïñç ìáôéÜ óôç äéáäéêáóßá åãêáôÜóôáóçò.
ÐáñÜäåéãìá 3-4. ÃñÞãïñåò ïäçãßåò åãêáôÜóôáóçò ãéá ôçí PHP 4 (Apache Module Version)
|
¼ôáí ñõèìéóôåß ç PHP ìå ôï configure, åßóôå Ýôïéìïé íá êÜíåôå build ôï CGI executable (åêôåëÝóéìï). Ç åíôïëÞ make èá ôï áíáëÜâåé áõôü. Áí áðïôý÷åé êáé äåí ìðïñåßôå íá êáôáëÜâåôå ãéáôß, äåßôå ôçí åíüôçôá ÐñïâëÞìáôá.
ÁõôÞ ç åíüôçôá áíáöÝñåôáé óå Windows 95/98/Me êáé Windows NT/2000/XP. Ìçí ðåñéìÝíåôå ôçí PHP íá äïõëåýåé óå 16 bit ðëáôöüñìåò üðùò Windows 3.1. ÊÜðïôå ðñïôéìïýìå íá áíáöÝñïõìå ôéò õðïóôçñéæüìåíåò Windows ðëáôöüñìåò ùò Win32.
ÕðÜñ÷ïõí äõï êýñéïé ôñüðïé íá åãêáôáóôáèåß ç PHP óôá Windows: åßôå manually åßôå ÷ñçóéìïðïéþíôáò ôïí InstallShield installer.
Áí Ý÷åôå ôï Microsoft Visual Studio, ìðïñåßôå åðßóçò íá êÜíåôå build ôçí PHP áðü ôï original source code.
¼ôáí Ý÷åôå åãêáôáóôÞóåé ôçí PHP ðÜíù óôï Windows óýóôçìá óáò, ìðïñåß åðßóçò íá èÝëåôå íá öïñôþóåôå äéÜöïñåò åðåêôÜóåéò ãéá åðéðñüóèåôç ëåéôïõñãéêüôçôá.
Ï Windows PHP installer ðïõ åßíáé äéáèÝóéìïò áðü ôçí óåëßäá ôùí downloads óôï http://www.php.net/, åãêáèéóôÜ ôçí CGI Ýêäïóçôçò PHP êáé, ãéá ôïí IIS, PWS, and Xitami, ñõèìßæåé åðßóçò ôïí web server. Åðßóçò óçìåéþóôå, ðùò åíþ ï InstallShield installer åßíáé Ýíáò åýêïëïò ôñüðïò ãéá íá êÜíåôå ôçí PHP íá äïõëÝøåé, ðåñéïñßæåôáé óå ðïëëïýò ôïìåßò, üðùò ãéá ðáñÜäåéãìá ç áõôüìáôç ñýèìéóç ôùí extensions äåí õðïóôçñßæåôáé.
ÅãêáôáóôÞóôå ôïí åðéëåãìÝíï óáò HTTP server óôï óýóôçìá óáò êáé óéãïõñåõôåßôå üôé äïõëåýåé.
ÔñÝîôå ôïí åêôåëÝóéìï installer êáé áêïëïõèÞóôå ôéò ïäçãßåò ðïõ äßíïíôáé áðü ôïí installation wizard (ïäçãüò åãêáôÜóôáóçò). Õðïóôçñßæïíôáé äýï ôýðïé åãêáôÜóôáóçò - ï standard (óõíçèéóìÝíïò), ï ïðïßïò äßíåé ëïãéêÝò êáé óõíåôÝò ðñïêáèïñéóìÝíåò ôéìÝò óå üëåò ôéò ñõèìßóåéò ðïõ ìðïñåß, êáé ï advanced (ðñï÷ùñçìÝíïò), ï ïðïßïò æçôÜåé ôéò ôéìÝò êáèþò ç äéáäéêáóßá ðñï÷ùñÜåé.
Ï ïäçãüò åãêáôÜóôáóçò ìáæåýåé áñêåôÝò ðëçñïöïñßåò ãéá íá ñõèìßóåé ôïí web server þóôå íá ÷ñçóéìïðïéåß ôçí PHP. Ãéá ôïí IIS êáé åðßóçò ãéá ôïí PWS óôá NT Workstation, ìéá ëßóôá ìå üëá ôá nodes óôïí server ìå ôá script map settings åìöáíßæåôáé, êáé ìðïñåßôå íá åðéëÝîåôå áõôïýò ôïõò êüìâïõò ðïõ ìðïñåßôå íá ðñïóèÝóåôå ôá PHP script mappings.
¼ôáí ç åãêáôÜóôáóç ïëïêëçñùèåß, ï installer èá óáò åíçìåñþóåé ãéá ôï üôé ðñÝðåé íá åðáíåêêéíÞóåôå ôï óýóôçìá óáò, íá åðáíåêêéíÞóåé ôïí server, Þ áðëÜ íá áñ÷ßóåôå íá ÷ñçóéìïðïéåßôå ôçí PHP.
Ðñïåéäïðïßçóç |
Ðñïóï÷Þ, áõôüò ï ôñüðïò ñýèìéóçò ôçò PHP äåí åßíáé áóöáëÞò. Áí èá èÝëáôå Ýíá áóöáëÞ ôñüðï ñýèìéóçò ôçò PHP, êáëýôåñá íá åðéëÝîåôå íá êÜíåôå ôéò ñõèìßóåéò ìå ôï ÷Ýñé êáé íá ïñßóåôå êÜèå ôéìÞ ðñïóåêôéêÜ. Áõôüò ï ôñüðïò ìðïñåß íá ñõèìßæåé áõôüìáôá ìéá åãêáôÜóôáóç ôçò PHP ðïõ äïõëåýåé, áëëÜ äåí åßíáé ðñïïñéóìÝíïò ãéá ÷ñÞóç óå online servers. |
Áõôüò ï ïäçãüò åãêáôÜóôáóçò èá óáò âïçèÞóåé íá åãêáôáóôÞóåôå êáé íá ñõèìßóåôå manually ôçí PHP óôïí Windows webserver óáò. ×ñåéÜæåóôå íá êÜíåôå download ôï zip binary distribution (óõìðéåóìÝíï áñ÷åßï ôçò Ýêäïóçò) áðü ôçí óåëßäá downloads óôï http://www.php.net/. Ç ðñùôüôõðç Ýêäïóç áõôïý ôïõ ïäçãïý Ýãéíå compile áðü ôïí Bob Silva, êáé ìðïñåß íá âñåèåß óôï http://www.umesd.k12.or.us/php/win32install.html.
Áõôüò ï ïäçãüò äßíåé õðïóôÞñéîç ãéá ÷åéñïêßíçôç åãêáôÜóôáóç ãéá:
Personal Web Server 3 and 4 Þ íåüôåñï
Internet Information Server 3 and 4 Þ íåüôåñï
Apache 1.3.x
OmniHTTPd 2.0b1 êáé ðÜíù
Oreilly Website Pro
Xitami
Netscape Enterprise Server, iPlanet
Ç PHP 4 Ýñ÷åôáé óå äýï ãåýóåéò ãéá Windows - Ýíá CGI executable (php.exe), êáé äéÜöïñá SAPI modules (ãéá ðáñÜäåéãìá: php4isapi.dll). Ç ôåëåõôáßá ìïñöÞ åßíáé êáéíïýñéá óôçí PHP 4, êáé äßíåé óçìáíôéêÜ âåëôéùìÝíç áðüäïóç êáé êÜðïéá íÝá ëåéôïõñãéêüôçôá.
Ðñïåéäïðïßçóç |
Ôá SAPI modules Ý÷ïõí âåëôéùèåß óçìáíôéêÜ óôçí Ýêäïóç 4.1, áëëÜ, ìðïñåß íá óõíáíôÞóåôå êÜðïéá server errors Þ Üëëá server modules üðùò ôï ASP íá áðïôõã÷Üíïõí, óå ðáëáéüôåñá óõóôÞìáôá. |
Áí åðéëÝîåôå Ýíá áðü ôá SAPI modules êáé ÷ñçóéìïðïéåßôå Windows 95, óéãïõñåõôåßôå íá êÜíåôå download ôï DCOM update áðü ôéò óåëßäåò ôïõ Microsoft DCOM. Ãéá ôï ISAPI module, Ýíáò ISAPI 4.0 óõìâáôüò Web server ÷ñåéÜæåôáé (äïêéìáóìÝíï óôïõò IIS 4.0, PWS 4.0 êáé IIS 5.0). Ï IIS 3.0 ÄÅÍ õðïóôçñßæåôáé. Èá ðñÝðåé íá êÜíåôå download êáé íá åãêáôáóôÞóåôå ôï Windows NT 4.0 Option Pack ìå ôïí IIS 4.0 áí èÝëåôå native PHP õðïóôÞñéîç.
Ôá ðáñáêÜôù âÞìáôá ðñÝðåé íá åêôåëïýíôáé óå üëåò ôéò åãêáôáóôÜóåéò ðñéí áðü ôéò ïäçãßåò ðïõ åßíáé óõãêåêñéìÝíåò ãéá ôïí server.
ÁðïóõìðéÝóôå ôï áñ÷åßï ôïõ distribution óå Ýíá êáôÜëïãï ôçò åðéëïãÞò óáò. Ï êáôÜëïãïò c:\php\ åßíáé ìéá êáëÞ áñ÷Þ. Ðéèáíþò íá ìçí èÝëåôå Ýíá path ðïõ ðåñéÝ÷åé êåíÜ (ãéá ðáñÜäåéãìá: Ôï c:\program files\php äåí åßíáé êáëÞ éäÝá). Ìðïñåß íá ìçí áñÝóåé áõôü óå êÜðïéïõò webservers.
ÐñÝðåé íá óéãïõñåõôåßôå ðùò ôá DLL ôá ïðïßá ç PHP ÷ñçóéìïðïéåß ìðïñïýí íá âñåèïýí. Ôá áêñéâÞ DLL ðïõ åìðëÝêïíôáé åîáñôþíôáé áðü ôïí web server ðïõ ÷ñçóéìïðïéåßôå êáé êáôÜ ðüóïí èÝëåôå ôçí PHP íá ôñÝ÷åé óáí CGI Þ óáí Ýíá server module. Ôï php4ts.dll ÷ñçóéìïðïéåßôáé ðÜíôá. Áí ÷ñçóéìïðïéåßôå êÜðïéï server module (ð.÷. ISAPI Þ Apache) ôüôå èá ÷ñåéáóôåßôå ôçí ó÷åôéêÞ DLL áðü ôïí êáôÜëïãï sapi. Áí ÷ñçóéìïðïéåßôå ïðïéïäÞðïôå PHP extension DLLs ôüôå èá ÷ñåéáóôåßôå êáé åêåßíá. Ãéá íá óéãïõñåõôåßôå ðùò ôá DLLs ìðïñïýí íá âñåèïýí, ìðïñåßôå åßôå íá ôá áíôéãñÜøåôå óôï system directory (ð.÷. winnt/system32 Þ windows/system) Þ ìðïñåßôå íá óéãïõñåõôåßôå ðùò âñßóêïíôáé óôïí ßäéï êáôÜëïãï üðùò ôï êõñßùò PHP executable Þ ôï DLL ðïõ èá ÷ñçóéìïðïéÞóåé ï web server óáò (ð.÷. php.exe, php4apache.dll).
Ôï PHP binary, ôá SAPI modules, êáé êÜðïéá extensions óôçñßæïíôáé óå åîùôåñéêÜ DLLs ãéá åêôÝëåóç. Óéãïõñåõôåßôå ðùò áõôÜ ôá DLLs ìÝóá óôï distribution õðÜñ÷ïõí óå Ýíá directory ðïõ âñßóêåôáé ìÝóá óôï Windows PATH óáò. Ãéá íá åßóôå óßãïõñïé, ôï êáëýôåñï åßíáé íá áíôéãñÜøåôå ôá ðáñáêÜôù áñ÷åßá ìÝóá óôï system directory, ôï ïðïßï ôõðéêÜ åßíáé:
c:\windows\system ãéá Windows 9x/ME |
c:\winnt\system32 ãéá Windows NT/2000 |
c:\windows\system32 ãéá Windows XP |
php4ts.dll, áí õðÜñ÷åé Þäç åêåß, êÜíôå ôï áíôéêáôáóôÞóôå ôï (overwrite) |
Ôá áñ÷åßá ìÝóá óôïí êáôÜëïãï 'dlls' ôïõ distribution óáò. Áí ôá Ý÷åôå Þäç åãêáôåóôçìÝíá óôï óýóôçìá óáò, áíôéêáôáóôÞóôå ôá ìüíï áí êÜôé äåí äïõëåýåé óùóôÜ (ðñéí ôá áíôéêáôáóôÞóåôå, ìéá êáëÞ éäÝá èá Þôáí íá ðÜñåôå Ýíá áíôßãñáöï áðü áõôÜ, Þ íá ôá ìåôáêéíÞóåôå óå êÜðïéï Üëëï êáôÜëïãï - ãéá êáëü êáé ãéá êáêü, ìÞðùò êáé êÜôé ðÜåé óôñáâÜ. |
ÊÜíôå download ôçí ôåëåõôáßá Ýêäïóç ôïõ Microsoft Data Access Components (MDAC) ãéá ôçí ðëáôöüñìá óáò, åéäéêÜ áí ÷ñçóéìïðïéåßôå Microsoft Windows 9x/NT4. Ôï MDAC åßíáé äéáèÝóéìï óôï http://msdn.microsoft.com/data/.
ÁíôéãñÜøôå ôï åðéëåãìÝíï áñ÷åßï ini (äåßôå ðáñáêÜôù) óôïí êáôÜëïãï '%WINDOWS%' óôá Windows 9x/Me Þ óôïí êáôÜëïãï '%SYSTEMROOT%' óôá Windows NT/2000/XP êáé ìåôïíïìÜóôå ôï óå php.ini. Ï '%WINDOWS%' Þ ï '%SYSTEMROOT%' êáôÜëïãïò óáò åßíáé ôõðéêÜ:
c:\windows ãéá Windows 9x/ME/XP |
c:\winnt Þ c:\winnt40 ãéá NT/2000 servers |
ÕðÜñ÷ïõí äýï áñ÷åßá ini ðïõ äßíïíôáé ìÝóá óôï áñ÷åßï zip, ôï php.ini-dist êáé ôï php.ini-optimized. Óõíéóôïýìå íá ÷ñçóéìïðïéÞóåôå ôï php.ini-optimized, åðåéäÞ åßíáé âåëôéóôïðïéçìÝíï óôéò ðñïêáèïñéóìÝíåò ñõèìßóåéò óå áõôü ôï áñ÷åßï ãéá áðüäïóç êáé áóöÜëåéá. Ôï êáëýôåñï åßíáé íá ìåëåôÞóåôå üëåò ôéò ñõèìßóåéò ini êáé íá ïñßóåôå êÜèå óôïé÷åßï ÷åéñïêßíçôá åóåßò. Áí èÝëåôå íá ðåôý÷åôå ôçí êáëýôåñç áóöÜëåéá, ôüôå áõôüò åßíáé ï äñüìïò ãéá óáò, áí êáé ç PHP äïõëåýåé êáëÜ êáé ìå ôá ðñïêáèïñéóìÝíá áñ÷åßá ini.
ÊÜíôå edit ôï êáéíïýñéï óáò php.ini áñ÷åßï:
Èá ÷ñåéáóôåß íá áëëÜîåôå ôçí ñýèìéóç 'extension_dir' þóôå íá äåß÷íåé óôï php-install-dir óáò, Þ üðïõ âÜëáôå ôá php_*.dll áñ÷åßá óáò. Ìçí îå÷Üóåôå ôçí ôåëåõôáßá backslash. ð.÷.: c:\php\extensions\
Áí ÷ñçóéìïðïéåßôå OmniHTTPd, ìçí áêïëïõèÞóåôå ôï åðüìåíï âÞìá. Ïñßóôå ôï 'doc_root' þóôå íá äåß÷íåé óôï document_root ôïõ webserver óáò. Ãéá ðáñÜäåéãìá: c:\apache\htdocs Þ c:\webroot
ÅðéëÝîôå ðïéåò åðåêôÜóåéò èá èÝëáôå íá öïñôþíïíôáé üôáí ç PHP îåêéíÜ. Äåßôå ôçí åíüôçôá ó÷åôéêÜ ìå ôá Windows extensions, ãéá ôï ðùò íá ñõèìßóåôå Ýíá êáé ãéá ôï ôé åßíáé Þäç built in. Óçìåéþóôå ðùò óå ìéá íÝá åãêáôÜóôáóç óõíéóôÜôáé ðñþôá íá êÜíåôå ôçí PHP íá äïõëåýåé êáé íá ôçí äïêéìÜóåôå ÷ùñßò êáíÝíá extension ðñéí íá ôá åíåñãïðïéÞóåôå óôï php.ini.
Óôïí PWS êáé óôïí IIS, ìðïñåßôå íá ïñßóåôå ôï browscap.ini íá äåß÷íåé óôï c:\windows\system\inetsrv\browscap.ini óôá Windows 9x/Me, óôï c:\winnt\system32\inetsrv\browscap.ini óôá NT/2000, êáé óôï c:\windows\system32\inetsrv\browscap.ini óôá XP.
Óçìåéþóôå ðùò ï êáôÜëïãïò mibs ðïõ äßíåôáé ìå ôçí äéáíïìÞ ôùí Windows ðåñéÝ÷åé áñ÷åßá õðïóôÞñéîçò ãéá SNMP. Áõôüò ï êáôÜëïãïò èá ðñÝðåé íá ìåôáöåñèåß óôï DRIVE:\usr\mibs (¼ðïõ DRIVE åßíáé ï ïäçãüò (drive) üðïõ åãêáôáóôÜèçêå ç PHP.)
Áí ÷ñçóéìïðïéåßôå NTFS óå Windows NT, 2000 Þ XP, óéãïõñåõôåßôå ðùò ï ÷ñÞóôçò ðïõ ôñÝ÷åé ôïí webserver Ý÷åé read permissions (åðßôñåøç áíÜãíùóçò) óôï php.ini (ð.÷. íá åßíáé readable áðü üëïõò).
Ãéá ôïí PWS äþóôå execution permission óôïí webroot:
ÎåêéíÜôå ôïí PWS Web Manager
Ïñßóôå ôéò Properties ôïõ êáôáëüãïõ "Home"
ÅðéëÝîôå ôï "execute"-Checkbox
Ðñéí áñ÷ßóåôå, áîßæåé íá áðáíôÞóåôå óôçí åñþôçóç: "Ãéáôß ôï build óôá Windows åßíáé ôüóï äýóêïëï?" Äýï áðáíôÞóåéò Ýñ÷ïíôáé óôï ìõáëü:
Ôá Windows äåí Ý÷ïõí (áêüìç) áðïëáýóåé ìéá ìåãÜëç êïéíüôçôá áðü developers ïé ïðïßïé åßíáé ðñüèõìïé íá ìïéñÜóïõí åëåýèåñá ôïí êþäéêá ôïõò. ¢ìåóï áðïôÝëåóìá áõôïý, åßíáé ç Ýëëåéøç ôçò áðáñáßôçôçò åðÝíäõóçò óå õðïäïìÞ ðïõ áðáéôåßôáé ãéá ôçí õðïóôÞñéîç ôÝôïéáò áíÜðôõîçò ðñïãñáììÜôùí. ÃåíéêÜ, ü,ôé åßíáé äéáèÝóéìï, Ýãéíå äõíáôü ìÝóù ìåôáöïñÜò ôùí áðáñáßôçôùí åñãáëåßùí áðü ôï Unix. Ìçí åêðëÞóóåóôå üôáí êÜðïéá áðü áõôÞ ôçí êëçñïíïìéÜ åìöáíßæåôáé áðü êáéñïýò óå êáéñïýò.
ÁñêåôÝò áðü ôéò ïäçãßåò ðïõ áêïëïõèïýí åßíáé ôçò éäÝáò ôïõ åßäïõò "set and forget" (ñýèìéóå ôï êáé îÝ÷áóÝ ôï). ¸ôóé êáèÞóôå ðßóù êáé äïêéìÜóôå ôéò ïäçãßåò ðáñáêÜôù üóï ðéï ðéóôÜ ìðïñåßôå.
Ðñéí áñ÷ßóåôå, Ý÷åôå áñêåôÜ íá êÜíåôå download...
Ãéá áñ÷Þ, ðÜñôå ôï Cygwin toolkit áðü ôï ðéï êïíôéíü óáò cygwin mirror site. Áõôü èá óáò ðñïìçèåýóåé ìå ôá ðéï äçìïöéëÞ åñãáëåßá GNU ðïõ ÷ñçóéìïðïéïýíôáé áðü ôçí äéáäéêáóßá ôïõ build.
ÊÜíôå download ôá õðüëïéðá build åñáëåßá ðïõ ÷ñåéÜæåóôå áðü ôï PHP site óôï http://www.php.net/extra/win32build.zip.
ÐÜñôå ôï source code ãéá ôï DNS name resolver ðïõ ÷ñçóéìïðïéåß ç PHP óôï http://www.php.net/extra/bindlib_w32.zip. Áõôü åßíáé áíôéêáôÜóôáóôï ãéá ôçí âéâëéïèÞêç resolv.lib ðïõ óõìðåñéëáìâÜíåôáé óôï win32build.zip.
Áí äåí Ý÷åôå Ýíá åñãáëåßï ãéá unzip, èá ÷ñåéáóôåßôå Ýíá. Ìéá äùñåÜí Ýêäïóç åßíáé äéáèÝóéìç áðü ôï InfoZip.
Áí óêïðåýåôå íá êÜíåôå compile ôçí PHP óáí Ýíá static Apache module èá ÷ñåéáóôåßôå åðßóçò ôá Apache sources ôçò Ýêäïóçò ôïõ Apache óáò.
ÔÝëïò, èá ÷ñåéáóôåßôå ôï source ôçò ßäéáò ôçò PHP 4. Ìðïñåßôå íá ðÜñåôå ôçí ôåëåõôáßá development Ýêäïóç ÷ñçóéìïðïéþíôáò anonymous CVS. Áí ðÜñåôå Ýíá snapshot Þ Ýíá source tarball, äåí ÷ñåéÜæåôáé áðëÜ íá ôï êÜíåôå untar êáé ungzip, áëëÜ èá ðñÝðåé íá ìåôáôñÝøåôå ôá áðëÜ linefeeds óå crlf ìÝóá óôá áñ÷åßá *.dsp êáé *.dsw ðñéí ç Microsoft Visual C++ êÜíåé ïôéäÞðïôå ìå áõôÜ.
Óçìåßùóç: ÔïðïèåôÞóôå ôïõò êáôáëüãïõò Zend êáé TSRM ìÝóá óôïí êáôÜëïãï php4 þóôå ôá projects íá âñåèïýí óôï äéÜóôçìá ôçò build äéáäéêáóßáò.
ÁêïëïõèÞóôå ôéò ïäçãßåò ãéá íá åãêáôáóôÞóåôå ôï åñãáëåßï óõìðßåóçò ôçò åðéëïãÞò óáò.
ÅêôåëÝóôå ôï setup.exe êáé áêïëïõèÞóôå ôéò ïäçãßåò åãêáôÜóôáóçò. Áí åðéèõìåßôå íá ôï åãêáôáóôÞóåôå óå Ýíá êáôÜëïãï åêôüò áðü ôïí c:\cygnus, óéãïõñåõôåßôå ðùò ç äéáäéêáóßá ôïõ build èá ôï îÝñåé, ïñßæïíôáò ôçí Cygwin environment ìåôáâëçôÞ. Óôá Windows 95/98 ï ïñéóìüò ìéáò environment ìåôáâëçôÞò ìðïñåß íá ãßíåé ôïðïèåôþíôáò ìéá ãñáììÞ ìÝóá óôï autoexec.bat áñ÷åßï óáò. Óôá Windows NT, ðçãáßíåôå óôï My Computer => Control Panel => System êáé åðéëÝîôå ôï environment tab.
Ðñïåéäïðïßçóç |
ÄçìéïõñãÞóôå Ýíá ðñïóùñéíü êáôÜëïãï ãéá íá ÷ñçóéìïðïéÞóåé ôï Cygwin, áëëéþò ðïëëÝò åíôïëÝò (åéäéêÜ ôï bison) èá áðïôý÷ïõí. Óôá Windows 95/98, mkdir C:\TMP. Óôá Windows NT, mkdir %SystemDrive%\tmp. |
ÖôéÜîôå Ýíá êáôÜëïãï êáé áðïóõìðéÝóôå ôï win32build.zip ìÝóá óå áõôÞ.
Áíïßîôå ôï Microsoft Visual C++, êáé áðü ôï ìåíïý åðéëÝîôå Tools => Options. Óå áõôü ôï dialog (ðáñÜèõñï äéáëüãïõ), åðéëÝîôå ôï directories tab. Áêïëïýèùò áëëÜîôå ôï dropdown óå Executables, Includes, êáé Library files, êáé óéãïõñåõôåßôå ðùò ôá cygwin\bin, win32build\include, êáé win32build\lib åßíáé óå êÜèå ëßóôá, áíôßóôïé÷á. (Ãéá íá ðñïóèÝóåôå ìéá êáôá÷þñçóç, åðéëÝîôå ìéá Üäåéá ãñáììÞ óôï ôÝëïò ôçò ëßóôáò êáé áñ÷ßóôå íá ãñÜöåôå). ÔõðéêÝò êáôá÷ùñÞóåéò èá åßíáé ùò åîÞò:
c:\cygnus\bin
c:\php-win32build\include
c:\php-win32build\lib
ÐáôÞóôå OK, êáé êëåßóôå ôçí Visual C++.
ÄçìéïõñãÞóôå áêüìç Ýíá êáôÜëïãï êáé áðïóõìðéÝóôå ôï bindlib_w32.zip ìÝóá. Áðïöáóßóôå áí èÝëåôå íá Ý÷åôå debug symbols äéáèÝóéìá (bindlib - Win32 Debug) Þ ü÷é (bindlib - Win32 Release). ÊÜíôå build ôï áíÜëïãï óåô ñõèìßóåùí:
Ãéá ÷ñÞóôåò GUI, áíïßîôå ôï VC++, êáé ôüôå åðéëÝîôå File => Open Workspace êáé åðéëÝîôå bindlib. Ôüôå åðéëÝîôå Build=>Set Active Configuration êáé åðéëÝîôå ôçí åðéèõìçôü óåô ñõèìßóåùí. ÔÝëïò, åðéëÝîôå Build=>Rebuild All.
Ãéá ÷ñÞóôåò ôïõ command line, óéãïõñåõôåßôå ðùò åßôå Ý÷åôå ïñßóåé ôéò C++ environment ìåôáâëçôÝò, åßôå Ý÷åôå ôñÝîåé ôï vcvars.bat, êáé ôüôå åêôåëÝóáôå Ýíá áðü ôá áêüëïõèá:
msdev bindlib.dsp /MAKE "bindlib - Win32 Debug"
msdev bindlib.dsp /MAKE "bindlib - Win32 Release"
Óå áõôü ôï óçìåßï, èá ðñÝðåé íá Ý÷åôå Ýíá ÷ñçóéìïðïéÞóéìï resolv.lib óå Ýíá áðü ôïõò Debug Þ Release õðïêáôáëüãïõò. ÁíôéãñÜøôå áõôü ôï áñ÷åßï ìÝóá óôïí êáôÜëïãï win32build\lib ðÜíù áðü ôï áñ÷åßï ìå ôï ßäéï üíïìá ðïõ èá âñåèåß åêåß.
Ï êáëýôåñïò ôñüðïò íá îåêéíÞóåôå åßíáé íá êÜíåôå build ôçí standalone/CGI Ýêäïóç.
Ãéá ÷ñÞóôåò GUI, îåêéíÞóôå ôï VC++, êáé åðéëÝîôå File => Open Workspace êáé åðéëÝîôå php4ts. Ôüôå åðéëÝîôå Build=>Set Active Configuration êáé åðéëÝîôå ôï åðéèõìçôü óåô ñõèìßóåùí. ÔÝëïò, åðéëÝîôå Build=>Rebuild All.
Ãéá ÷ñÞóôåò ôïõ command line, óéãïõñåõôåßôå ðùò åßôå Ý÷åôå ïñßóåé ôéò C++ environment ìåôáâëçôÝò åßôå Ý÷åôå ôñÝîåé ôï vcvars.bat, êáé ôüôå åêôåëÝóáôå Ýíá áðü ôá áêüëïõèá:
msdev php4ts.dsp /MAKE "php4ts - Win32 Debug_TS"
msdev php4ts.dsp /MAKE "php4ts - Win32 Release_TS"
Óå áõôü ôï óçìåßï, èá ðñÝðåé íá Ý÷åôå Ýíá ÷ñçóéìïðïéÞóéìï php.exe åßôå óôïí õðïêáôÜëïãï Debug_TS åßôå óôïí Release_TS.
ÅðáíáëÜâåôå ôá ðáñáðÜíù âÞìáôá ìå ôï php4isapi.dsp (ôï ïðïßï ìðïñåß íá âñåèåß óôï sapi\isapi) ãéá íá êÜíåôå build ôùí áðáñáßôçôï êþäéêá þóôå íá åíóùìáôùèåß ç PHP óôïí Microsoft IIS.
Åßíáé äõíáôüí íá ãßíïõí ìéêñÝò ðñïóáñìïãÝò óôç äéáäéêáóßá ôïõ build áëëÜæïíôáò ôï áñ÷åßï main/config.win32.h.in.
ÌåôÜ ôçí åãêáôÜóôáóç ôçò PHP êáé åíüò webserver óôá Windows, ðéèáíüí íá ÷ñåéáóôåß íá åãêáôáóôÞóåôå êÜðïéåò åðåêôÜóåéò ãéá ðñüóèåôç ëåéôïõñãéêüôçôá. Ï áêüëïõèïò ðßíáêáò ðåñéãñÜöåé êÜðïéåò áðü ôçò äéáèÝóéìåò åðåêôÜóåéò. Ìðïñåßôå íá åðéëÝîåôå ðïéåò èÝëåôå íá öïñôþóåôå üôáí îåêéíÜ ç PHP âãÜæïíôáò áðü ó÷üëéá ôéò ãñáììÝò: 'extension=php_*.dll' óôï php.ini. Ìðïñåßôå åðßóçò íá öïñôþóåôå äõíáìéêÜ Ýíá module óôá script óáò ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç dl().
Ôá DLL ãéá ôéò åðåêôÜóåéò ôçò PHP Ý÷ïõí ðñüèåìá 'php_' óôçí PHP 4 (êáé 'php3_' óôç PHP 3). Áõôü áðïôñÝðåé óýã÷éóç ìåôáîý ôùí åðåêôÜóåùí ôçò PHP êáé ôùí âéâëéïèçêþí õðïóôÞñéîçò ôïõò.
Óçìåßùóç: Óôçí PHP 4.0.6, ç õðïóôÞñéîç ãéá ôá BCMath, Calendar, COM, FTP, MySQL, ODBC, PCRE, Session, WDDX êáé XML åßíáé åíóùìáôùìÝíç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéåò ðñüóèåôåò åðåêôÜóåéò ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò. Äåßôå ôï áñ÷åßï README.txt ôçò äéáíïìÞò óáò Þ ôï install.txt ãéá Ýíá êáôÜëïãï ôùí åíóùìáôùìÝíùí modules.
Óçìåßùóç: ÌåñéêÝò áðü áõôÝò ôéò åðåêôÜóåéò ÷ñåéÜæïíôáé åðéðëÝïí DLL ãéá íá äïõëÝøïõí. ÌåñéêÝò áðü áõôÝò ìðïñïýí íá âñåèïýí ìÝóá óôï ðáêÝôï äéáíïìÞò, óôïí êáôÜëïãï 'dlls' áëëÜ êÜðïéåò, üðùò ãéá ðáñÜäåéãìá ç Oracle (php_oci8.dll) ÷ñåéÜæïíôáé DLL ôá ïðïßá äåí åßíáé óõóêåõáóìÝíç ìå ôï ðáêÝôï äéáíïìÞò.
ÁíôéãñÜøôå ôá óõóêåõáóìÝíá DLL áðü ôïí êáôÜëïãï 'DLLs' óôï Windows PATH, áóöáëÞ ìÝñç åßíáé:
Áí ôá Ý÷åôå Þäç åãêáôåóôçìÝíá óôï óýóôçìá óáò, êÜíôå ôá overwrite ìüíï üôáí êÜôé äåí äïõëåýåé óùóôÜ (ðñéí íá ôá êÜíåôå overwite, êáëÞ éäÝá åßíáé íá êñáôÞóåôå Ýíá áíôßãñáöï ôïõò, Þ íá ôá ìåôáêéíÞóåôå óå êÜðïéï Üëëï êáôÜëïãï - ìÞðùò êáé ðÜåé êÜôé óôñáâÜ).
c:\windows\system ãéá ôá Windows 9x/Me c:\winnt\system32 ãéá ôá Windows NT/2000 c:\windows\system32 ãéá ôá Windows XP
Ðßíáêáò 3-1. ÅðåêôÜóåéò ôçò PHP
ÅðÝêôáóç | ÐåñéãñáöÞ | Óçìåéþóåéò |
---|---|---|
php_bz2.dll | bzip2: ÓõíáñôÞóåéò óõìðßåóçò | Êáìßá |
php_calendar.dll | Calendar: ÓõíáñôÞóåéò ìåôáôñïðÞò çìåñïëïãßïõ | ÅíóùìáôùìÝíåò áðü ôç PHP 4.0.3 |
php_cpdf.dll | ClibPDF óõíáñôÞóåéò | Êáìßá |
php_crack.dll | Crack óõíáñôÞóåéò | Êáìßá |
php3_crypt.dll | Crypt óõíáñôÞóåéò | Üãíùóôï |
php_ctype.dll | ctype-ïéêïãÝíåéáò óõíáñôÞóåéò | Êáìßá |
php_curl.dll | CURL, Client URL óõíáñôÞóåéò âéâëéïèÞêçò | Áðáéôåß: libeay32.dll, ssleay32.dll (óõóêåõáóìÝíá) |
php_cybercash.dll | Cybercash óõíáñôÞóåéò ðëçñùìÞò | Êáìßá |
php_db.dll | DBM óõíáñôÞóåéò | ÎåðåñáóìÝíåò. Áíôß áõôþí, ÷ñçóéìïðïéÞóôå ôéò DBA (php_dba.dll) |
php_dba.dll | DBA: DataBase (dbm-åßäïõò) Abstraction layer (áöáéñåôéêïý åðéðÝäïõ) óõíáñôÞóåéò | Êáìßá |
php_dbase.dll | dBase óõíáñôÞóåéò | Êáìßá |
php3_dbm.dll | Berkeley DB2 âéâëéïèÞêç | Üãíùóôï |
php_domxml.dll | DOM XML óõíáñôÞóåéò | Áðáéôåß: libxml2.dll (óõóêåõáóìÝíï) |
php_dotnet.dll | .NET óõíáñÞóåéò | Êáìßá |
php_exif.dll | Read EXIF: ÁíÜãíùóç JPEG headers (åðéêåöáëßäåò) | Êáìßá |
php_fbsql.dll | FrontBase óõíáñôÞóåéò | Êáìßá |
php_fdf.dll | FDF: Forms Data Format óõíáñôÞóåéò | Áðáéôåß: fdftk.dll (óõóêåõáóìÝíï) |
php_filepro.dll | filePro óõíáñôÞóåéò | Ðñüóâáóç Read-only (Ìüíï-áíÜãíùóç) |
php_ftp.dll | FTP óõíáñôÞóåéò | ÅíóùìáôùìÝíåò áðü ôç PHP 4.0.3 |
php_gd.dll | GD: ÓõíáñôÞóåéò âéâëéïèÞêçò åéêüíùí GD | Êáìßá |
php_gettext.dll | Gettext óõíáñôÞóåéò | Áðáéôåß: gnu_gettext.dll (óõóêåõáóìÝíï) |
php_hyperwave.dll | HyperWave óõíáñôÞóåéò | Êáìßá |
php_iconv.dll | ICONV: ÌåôáôñïðÞ characterset | Áðáéôåß: iconv-1.3.dll (óõóêåõáóìÝíï) |
php_ifx.dll | Informix óõíáñôÞóåéò | Áðáéôåß: ÂéâëéïèÞêåò Informix |
php_iisfunc.dll | IIS óõíáñôÞóåéò äéá÷åßñçóçò | Êáìßá |
php_imap.dll | IMAP POP3 êáé NNTP óõíáñôÞóåéò | PHP 3: php3_imap4r1.dll |
php_ingres.dll | Ingres II óõíáñôÞóåéò | Áðáéôåß: ÂéâëéïèÞêåò Ingres II |
php_interbase.dll | InterBase óõíáñôÞóåéò | Áðáéôåß: gds32.dll (óõóêåõáóìÝíï) |
php_java.dll | Java åðÝêôáóç | Áðáéôåß: jvm.dll (óõóêåõáóìÝíï) |
php_ldap.dll | LDAP óõíáñôÞóåéò | Áðáéôåß: libsasl.dll (óõóêåõáóìÝíï) |
php_mhash.dll | Mhash óõíáñôÞóåéò | None |
php_ming.dll | Ming óõíáñôÞóåéò ãéá Flash | Êáìßá |
php_msql.dll | mSQL óõíáñôÞóåéò | Áðáéôåß: msql.dll (óõóêåõáóìÝíï) |
php3_msql1.dll | mSQL 1 client | Üãíùóôï |
php3_msql2.dll | mSQL 2 client | Üãíùóôï |
php_mssql.dll | MSSQL óõíáñôÞóåéò | Áðáéôåß: ntwdblib.dll (óõóêåõáóìÝíï) |
php3_mysql.dll | MySQL óõíáñôÞóåéò | ÅíóùìáôùìÝíï óôçí PHP 4 |
php3_nsmail.dll | Netscape mail óõíáñôÞóåéò | Üãíùóôï |
php3_oci73.dll | Oracle óõíáñôÞóåéò | Üãíùóôï |
php_oci8.dll | Oracle 8 óõíáñôÞóåéò | Áðáéôåß: ÂéâëéïèÞêåò Oracle 8 client |
php_openssl.dll | OpenSSL óõíáñôÞóåéò | Áðáéôåß: libeay32.dll (óõóêåõáóìÝíï) |
php_oracle.dll | Oracle óõíáñôÞóåéò | Áðáéôåß: ÂéâëéïèÞêåò Oracle 7 client |
php_pdf.dll | PDF óõíáñôÞóåéò | Êáìßá |
php_pgsql.dll | PostgreSQL óõíáñôÞóåéò | Êáìßá |
php_printer.dll | Printer óõíáñôÞóåéò | Êáìßá |
php_xslt.dll | XSLT óõíáñôÞóåéò | Áðáéôåß: sablot.dll (óõóêåõáóìÝíï) |
php_snmp.dll | SNMP get and walk óõíáñôÞóåéò | Ìüíï NT! |
php_sybase_ct.dll | Sybase óõíáñôÞóåéò | Áðáéôåß: ÂéâëéïèÞêåò Sybase client |
php_yaz.dll | YAZ óõíáñôÞóåéò | Êáìßá |
php_zlib.dll | ZLib óõíáñôÞóåéò óõìðßåóçò | Êáìßá |
Ç ðñïåðéëïãÞ åßíáé íá ãßíåé build ç PHP óáí Ýíá CGI ðñüãñáììá. Áõôü äçìéïõñãåß Ýíá commandline interpreter (ìåôáöñáóôÞ), ï ïðïßïò ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá åðåîåñãáóßá CGI Þ ãéá PHP scripting ðïõ äåí Ý÷åé ó÷Ýóç ìå ôï web. Áí ôñÝ÷åôå Ýíá web server ãéá ôïí ïðïßï ç PHP Ý÷åé õðïóôÞñéîç module, ãåíéêþò èá ðñÝðåé íá åðéëÝãåôå áõôÞ ôç ëýóç ãéá ëüãïõò áðüäïóçò. Åí ôïýôïéò, ç CGI Ýêäïóç åðéôñÝðåé óôïõò ÷ñÞóôåò ôïõ Apache íá ôñÝ÷ïõí äéáöïñåôéêÝò PHP óåëßäåò êÜôù áðü äéáöïñåôéêÜ user-id. Ðáñáêáëïýìå äéáâÜóôå ðñþôá ôï êåöÜëáéï ó÷åôéêÜ ìå ôçí ÁóöÜëåéá áí óêïðåýåôå íá ôñÝîåôå ôçí PHP óáí CGI.
Áðü ôçí PHP 4.3.0, êÜðïéá óçìáíôéêÜ ðñÜãìáôá ðñïóôÝèçêáí óôçí PHP. ¸íá íÝï SAPI ìå üíïìá CLI õðÜñ÷åé åðßóçò êáé Ý÷åé ôï ßäéï üíïìá ìå ôï CGI binary. Áõôü ðïõ åãêáèßóôáôáé óôï {PREFIX}/bin/php åîáñôÜôáé áðü ôçí configure ãñáììÞ êáé áõôü ðåñéãñÜöåôáé ìå ëåðôïìÝñåéá óôçí åíüôçôá ôïõ manual ìå ôßôëï ×ñçóéìïðïéþíôáò ôçí PHP áðü ôçí command line. Ãéá ðåñéóóüôåñåò ëåðôïìÝñåéåò ðáñáêáëïýìå äéáâÜóôå åêåßíç ôçí åíüôçôá ôïõ manual.
If you have built PHP as a CGI program, you may test your build by typing make test. It is always a good idea to test your build. This way you may catch a problem with PHP on your platform early instead of having to struggle with it later.
If you have built PHP 3 as a CGI program, you may benchmark your build by typing make bench. Note that if safe mode is on by default, the benchmark may not be able to finish if it takes longer then the 30 seconds allowed. This is because the set_time_limit() can not be used in safe mode. Use the max_execution_time configuration setting to control this time for your own scripts. make bench ignores the configuration file.
Óçìåßùóç: make bench is only available for PHP 3.
Some server supplied enviroment variables are not defined in the current CGI/1.1 specification. Only the following variables are defined there; everything else should be treated as 'vendor extensions': AUTH_TYPE, CONTENT_LENGTH, CONTENT_TYPE, GATEWAY_INTERFACE, PATH_INFO, PATH_TRANSLATED, QUERY_STRING, REMOTE_ADDR, REMOTE_HOST, REMOTE_IDENT, REMOTE_USER, REQUEST_METHOD, SCRIPT_NAME, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL and SERVER_SOFTWARE
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò åéäéêÜ ãéá åãêáôáóôÜóåéò ôçò PHP ìå ôïí Apache, ôüóï ãéá Unix üóï êáé ãéá Windows åêäüóåéò.
Ìðïñåßôå íá åðéëÝîåôå arguments ãéá íá ðñïóèÝóåôå óôçí åíôïëÞ configure óôç ãñáììÞ 10 ðáñáêÜôù, áðü ôïí ÐëÞñç êáôÜëïãï ôùí åðéëïãþí ôïõ configure. Ïé áñéèìïß åêäüóåùí Ý÷ïõí ðáñáëçöèåß åäþ, ãéá íá äéáóöáëéóôåß ç ïñèüôçôá ôùí ïäçãéþí. Èá ÷ñåéáóôåß íá áíôéêáôáóôÞóåôå ôá 'xxx' ìå ôéò óùóôÝò ôéìÝò áðü ôá áñ÷åßá óáò.
ÐáñÜäåéãìá 3-5. Ïäçãßåò ÅãêáôÜóôáóçò (¸êäïóç Apache Shared Module) ãéá ôçí PHP 4
|
Depending on your Apache install and Unix variant, there are many possible ways to stop and restart the server. Below are some typical lines used in restarting the server, for different apache/unix installations. You should replace /path/to/ with the path to these applications on your systems.
1. Several Linux and SysV variants: /etc/rc.d/init.d/httpd restart 2. Using apachectl scripts: /path/to/apachectl stop /path/to/apachectl start 3. httpdctl and httpsdctl (Using OpenSSL), similar to apachectl: /path/to/httpsdctl stop /path/to/httpsdctl start 4. Using mod_ssl, or another SSL server, you may want to manually stop and start: /path/to/apachectl stop /path/to/apachectl startssl |
Different examples of compiling PHP for apache are as follows:
This will create a libphp4.so shared library that is loaded into Apache using a LoadModule line in Apache's httpd.conf file. The PostgreSQL support is embedded into this libphp4.so library.
This will create a libphp4.so shared library for Apache, but it will also create a pgsql.so shared library that is loaded into PHP either by using the extension directive in php.ini file or by loading it explicitly in a script using the dl() function.
This will create a libmodphp4.a library, a mod_php4.c and some accompanying files and copy this into the src/modules/php4 directory in the Apache source tree. Then you compile Apache using --activate-module=src/modules/php4/libphp4.a and the Apache build system will create libphp4.a and link it statically into the httpd binary. The PostgreSQL support is included directly into this httpd binary, so the final result here is a single httpd binary that includes all of Apache and all of PHP.
Same as before, except instead of including PostgreSQL support directly into the final httpd you will get a pgsql.so shared library that you can load into PHP from either the php.ini file or directly using dl().
When choosing to build PHP in different ways, you should consider the advantages and drawbacks of each method. Building as a shared object will mean that you can compile apache separately, and don't have to recompile everything as you add to, or change, PHP. Building PHP into apache (static method) means that PHP will load and run faster. For more information, see the Apache webpage on DSO support.
Óçìåßùóç: Apache's default http.conf currently ships with a section that looks like this:
Unless you change that to "Group nogroup" or something like that ("Group daemon" is also very common) PHP will not be able to open files.
Óçìåßùóç: Make sure you specify the installed version of apxs when using --with-apxs=/path/to/apxs. You must NOT use the apxs version that is in the apache sources but the one that is actually installed on your system.
There are two ways to set up PHP to work with Apache 1.3.x on Windows. One is to use the CGI binary (php.exe), the other is to use the Apache module DLL. In either case you need to stop the Apache server, and edit your srm.conf or httpd.conf to configure Apache to work with PHP.
It is worth noting here that now the SAPI module has been made more stable under windows, we recommend it's use above the CGI binary, since it is more transparent and secure.
Although there can be a few variations of configuring PHP under Apache, these are simple enough to be used by the newcomer. Please consult the Apache Docs for further configuration directives.
If you unziped the PHP package to c:\php\ as described in the Manual Installation Steps section, you need to insert these lines to your Apache configuration file to set up the CGI binary:
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php .phtml
Action application/x-httpd-php "/php/php.exe"
Ðñïåéäïðïßçóç |
By using the CGI setup, your server is open to several possible attacks. Please read our CGI security section to learn how to defend yourself from attacks. |
If you would like to use PHP as a module in Apache, be sure to move php4ts.dll to the windows/system (for Windows 9x/Me) or winnt/system32 (for Windows NT/2000/XP) directory, overwriting any older file. Then you should add the following two lines to you Apache conf file:
LoadModule php4_module c:/php/sapi/php4apache.dll
AddType application/x-httpd-php .php .phtml
After changing the configuration file, remember to restart the server, for example, NET STOP APACHE followed by NET START APACHE, if you run Apache as a Windows Service, or use your regular shortcuts.
Óçìåßùóç: You may find after using the windows installer for Apache that you need to define the AddModule directive for mod_php4.c in the configuration file (httpd.conf). This is done by adding AddModule mod_php4.c to the AddModule list, near the beginning of the configuration file. This is especially important if the ClearModuleList directive is defined. Failure to do this may mean PHP will not be registered as an Apache module.
There are 2 ways you can use the source code highlighting feature, however their ability to work depends on your installation. If you have configured Apache to use PHP as an ISAPI module, then by adding the following line to your configuration file you can use this feature: AddType application/x-httpd-php-source .phps
If you chose to configure Apache to use PHP as a CGI binary, you will need to use the show_source() function. To do this simply create a PHP script file and add this code: <?php show_source ("original_php_script.php"); ?>. Substitute original_php_script.php with the name of the file you wish to show the source of.
Óçìåßùóç: On Win-Apache all backslashes in a path statement such as "c:\directory\file.ext", must be converted to forward slashes, as "c:/directory/file.ext".
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò åéäéêÜ ãéá åãêáôáóôÜóåéò ôçò PHP ìå ôïí Apache 2.0, ôüóï ãéá Unix üóï êáé ãéá Windows åêäüóåéò.
Ðñïåéäïðïßçóç |
Ìçí ÷ñçóéìïðïéåßôå ôïí Apache 2.0 êáé ôçí PHP óå Ýíá production ðåñéâÜëëïí ïýôå óå Unix üõôå óå Windows. |
Ðñïôåßíåôáé Ýíôïíá íá ñßîåôå ìéá ìáôéÜ óôï Apache Documentation ãéá íá Ý÷åôå ìéá âáóéêÞ êáôáíüçóç ôïõ Apache 2.0 Server.
Ïé ðáñáêÜôù åêäüóåéò ôçò PHP åßíáé ãíùóôü íá äïõëåýïõí ìå ôçí ðéï ðñüóöáôç Ýêäïóç ôïõ Apache 2.0:
Óçìåßùóç: Ç õðïóôÞñéîç ôïõ Apache 2.0 ãéá SAPI Üñ÷éóå áðü ôçí PHP 4.2.0. Ç PHP 4.2.3 äïõëåýåé ìå ôïí Apache 2.0.39, ìçí ÷ñçóéìïðïéÞóåôå Üëëç Ýêäïóç ôïõ Apache ìå ôçí PHP 4.2.3. Ùóôüóï, ç ðñïôåéíüìåíç åãêáôÜóôáóç åßíáé ìå ôçí PHP 4.3.0 Þ íåüôåñç ìå ôçí ðéï ðñüóöáôç Ýêäïóç ôïõ Apache2.
¼ëåò ïé åêäüóåéò ôçò PHP ðïõ áíáöÝñèçêáí èá äïõëåýïõí ìå ôïí Apache 1.3.x.
ÊÜíôå download ôçí ðéï ðñüóöáôå Ýêäïóç ôïõ Apache 2.0 êáé ìéá êáôÜëëçëç Ýêäïóç ôçò PHP áðü ôéò ôïðïèåóßåò ðïõ áíáöÝñèçêáí ðéï ðñéí. Áõôüò ï ãñÞãïñïò ïäçãüò êáëýðôåé üëá ôá âáóéêÜ ãéá íá áñ÷ßóåôå ìå ôïí Apache 2.0 êáé ôçí PHP. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò äéáâÜóôå ôï Apache Documentation. Ïé áñéèìïß ôùí åêäüóåùí Ý÷ïõí ðáñáëçöèåß åäþ, þóôå ïé ïäçãßåò íá ìçí åßíáé áíáëçèåßò. Èá ÷ñåéáóôåß íá áíôéêáôáóôÞóåôå ôá 'NN' ìå ôéò óùóôÝò ôéìÝò áðü ôá áñ÷åßá óáò.
ÐáñÜäåéãìá 3-6. Ïäçãßåò ÅãêáôÜóôáóçò (¸êäïóç Apache 2 Shared Module)
|
Áêïëïõèþíôáò ôá âÞìáôá ðáñáðÜíù èá Ý÷åôå Ýíá Apache 2.0 ðïõ èá ôñÝ÷åé ìå õðïóôÞñéîç ãéá PHP üðùò ôï SAPI module. ÖõóéêÜ õðÜñ÷ïõí ðïëý ðåñéóóüôåñåò åðéëïãÝò ñýèìéóçò äéáèÝóéìåò ôüóï ãéá ôïí Apache üóï êáé ãéá ôçí PHP. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ÷ñçóéìïðïéÞóôå ôï ./configure --help óôï áíÜëïãï source tree. Óå ðåñßðôùóç ðïõ èÝëåôå íá êÜíåôå build ìéá multithreaded (ðïëõíçìáôéêÞ) Ýêäïóç ôïõ Apache 2.0 ðñÝðåé íá êÜíåôå overwrite ôï êïéíü MPM-Module prefork ìå Ýíá áðü ôá worker Þ perchild. Ãéá íá ôï êÜíåôå áõôü, ðñïóèÝóôå óôçí configure ãñáììÞ óáò óôï âÞìá 6, Ýíá áðü ôá --with-mpm=worker Þ --with-mpm=perchild. ËÜâåôå õðüøéí ôéò óõíÝðåéåò êáé êáôáíïÞóôå ôï ôé êÜíåôå. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò äéáâÜóôå ôï Apache documentation ó÷åôéêÜ ìå ôá MPM-Modules.
Óçìåßùóç: Ãéá íá êÜíåôå build ìéá multithreaded Ýêäïóç ôïõ Apache, ôï óýóôçìá óáò ðñÝðåé íá õðïóôçñßæåé threads (íÞìáôá). Áõôü õðïäçëþíåé íá êÜíåôå build ôçí PHP ìå ôï ðåéñáìáôéêü Zend Thread Safety (ZTS). ¸ôóé, äåí èá åßíáé üëåò ïé åðåêôÜóåéò äéáèÝóéìåò. Ç ðñïôåéíüìåíç åãêáôÜóôáóç åßíáé íá êÜíåôå build ôïí Apache ìå ôï êïéíü prefork MPM-Module.
ËÜâåôå õðüøéí ôï íá äéáâÜóåôå ôéò Óçìåéþóåéò åéäéêÜ ãéá Windows ãéá ôïí Apache 2.0.
Ðñïåéäïðïßçóç |
Ï Apache 2.0 ó÷åäéÜóôçêå ãéá íá ôñÝ÷åé óå Windows NT 4.0, Windows 2000 Þ Windows XP. ÁõôÞ ôç óôéãìÞ, ç õðïóôÞñéîç ãéá Windows 9x åßíáé áôåëÞò. Ï Apache 2.0 äåí áíáìÝíåôáé íá äïõëåýåé óå áõôÜ ôá óõóôÞìáôá ôþñá. |
ÊÜíôå download ôçí ðéï ðñüóöáôå Ýêäïóç ôïõ Apache 2.0 êáé ìéá êáôÜëëçëç Ýêäïóç ôçò PHP áðü ôéò ôïðïèåóßåò ðïõ áíáöÝñèçêáí ðéï ðÜíù. ÁêïëïõèÞóôå ôá ÂÞìáôá ×åéñïêßíçôçò ÅãêáôÜóôáóçò êáé åëÜôå ðßóù ãéá íá ðñï÷ùñÞóåôå óôçí óõíåñãáóßá ôçò PHP êáé ôïõ Apache.
ÕðÜñ÷ïõí äýï ôñüðïé íá ñõèìßóåôå ôçí PHP íá äïõëåýåé ìå ôïí Apache 2.0 óôá Windows. Ï Ýíáò åßíáé íá ÷ñçóéìïðïéÞóåôå ôï CGI binary, ï Üëëïò åßíáé íá ÷ñçóéìïðïéÞóåôå ôï Apache module DLL. Óå êÜèå ðåñßðôùóç ðñÝðåé íá óôáìáôÞóåôå ôïí Apache server êáé íá ìïñöïðïéÞóåôå ôï httpd.conf óáò ãéá íá ñõèìßóåôå ôïí Apache þóôå íá äïõëåýåé ìå ôçí PHP.
ÐñÝðåé íá åéóÜãåôå áõôÝò ôéò ôñåéò ãñáììÝò óôï httpd.conf áñ÷åßï ñõèìßóåùí ôïõ Apache óáò ãéá íá ñõèìßóåôå ôï CGI binary:
Áí èÝëåôå íá ÷ñçóéìïðïéÞóåôå ôçí PHP óáí Ýíá module óôïí Apache 2.0, ìåôáêéíÞóåôå ôï php4ts.dll óôï winnt/system32 (ãéá ôá Windows NT/2000) Þ óôï windows/system32 (for Windows XP), êÜíïíôáò overwriting ôõ÷üí ðáëáéüôåñï áñ÷åßï. ÐñÝðåé íá åéóÜãåôå áõôÝò ôéò äõï ãñáììÝò óôï áñ÷åßï ñõèìßóåùí httpd.conf ôïõ Apache óáò ãéá íá ñõèìßóåôå ôï PHP-Module ãéá ôïí Apache 2.0:
Óçìåßùóç: Èõìçèåßôå íá áíôéêáôáóôÞóåôå ôï c:/php/ ìå ôï ðñáãìáôéêü óáò path óôï PHP óôá ðáñáðÜíù ðáñáäåßãìáôá. ÐñïóÝîôå íá ÷ñçóéìïðïéÞóåôå ôï php4apache2.dll óôï LoadModule directive óáò êáé ü÷é ôï php4apche.dll. Ôï ôåëåõôáßï Ý÷åé ó÷åäéáóôåß ãéá íá ôñÝ÷åé ìå ôïí Apache 1.3.x.
Ðñïåéäïðïßçóç |
Ìçí áíáãêáôåýåôå ôéò åãêáôáóôÜóåéò óáò ìå áñ÷åßá dll áðü äéáöïñåôéêÝò åêäüóåéò PHP . Ç ìüíç óáò åðéëïãÞ åßíáé íá ÷ñçóéìïðïéÞóåôå ôá dll êáé ôéò åðåôêÜóåéò ðïõ Ýñ÷ïíôáé ìå ôçí Ýêäïóç ôçò PHP ðïõ Ý÷åôå êÜíåé download. |
Ç PHP 4 ìðïñåß íá ãßíåé build óáí Ýíá Pike module ãéá ôïí Caudium webserver. Óçìåéþóôå üôé áõôü äåí õðïóôçñßæåôáé ìå ôçí PHP 3. ÁêïëïõèÞóôå ôéò áðëÝò ïäçãßåò ðáñáêÜôù ãéá íá åãêáôáóôÞóåôå ôçí PHP 4 ãéá ôï Caudium.
ÐáñÜäåéãìá 3-9. Ïäçãßåò ÅãêáôÜóôáóçò ãéá ôï Caudium
|
Ìðïñåßôå öõóéêÜ íá íá êÜíåôå compile ôï Caudium module óáò ìå õðïóôÞñéîç ãéá ôéò äéÜöïñåò åðåêôÜóåéò äéáèÝóéìåò óôçí PHP 4. Äåßôå ôïí ðëÞñç êáôÜëïãï ôùí åðéëïãþí ôïõ configure ãéá ìéá åîáíôëçôéêÞ áíáóêüðéóç.
Óçìåßùóç: ¼ôáí êÜíåôå compile ôçí PHP 4 ìå õðïóôÞñéîç ãéá MySQL ðñÝðåé íá óéãïõñåõôåßôå ðùò ÷ñçóéìïðïéåßôáé ï êáíïíéêüò êþäéêáò ôïõ MySQL client. Áëëéþò ìðïñåß íá õðÜñ÷ïõí conflict áí ôï Pike óáò Ý÷åé Þäç õðïóôÞñéîç MySQL. Áõôü ôï êÜíåôå ïñßæïíôáò Ýíá êáôÜëïãï åãêáôÜóôáóçò ôçò MySQL ÷ñçóéìïðïéþíôáò ôçí åðéëïãÞ --with-mysql.
Ãéá íá êÜíåôå build ôçí PHP óáí Ýíá fhttpd module, áðáíôÞóôå "yes" óôï "Build as an fhttpd module?" (ç åðéëïãÞ --with-fhttpd=DIR ôïõ configure) êáé ïñßóôå Ýíá fhttpd source base êáôÜëïãï. Ï ðñïåðéëåãìÝíïò êáôÜëïãïò åßíáé/usr/local/src/fhttpd. Áí ôñÝ÷åôå fhttpd, ôï íá êÜíåôå build ôçí PHP óáí module èá äþóåé êáëýôåñç áðüäïóç, ðåñéóóüôåñï Ýëåã÷ï êáé äõíáôüôçôåò remote (áðïìáêñõóìÝíçò) åêôÝëåóçò.
Óçìåßùóç: Ç õðïóôÞñéîç ãéá ôï fhttpd äåí åßíáé ðëÝïí äéáèÝóéìç áðü ôçí PHP 4.3.0.
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò åéäéêÜ ãéá ôïí IIS (Microsoft Internet Information Server), óõãêåêñéìÝíá ãéá ôïí PWS/IIS 3, PWS 4 Þ íåüôåñåò êáé IIS 4 Þ íåüôåñåò åêäüóåéò.
Óçìáíôéêü ãéá ÷ñÞóôåò CGI: ÄéáâÜóôå ôï faq ó÷åôéêÜ ìå ôï cgi.force_redirect ãéá óçìáíôéêÝò ëåðôïìÝñåéåò. Áõôü ôï directive áðáéôåßôáé íá ïñéóôåß óå 0.
Ç ðñïôåéíüìåíç ìÝèïäïò ãéá ôçí ñýèìéóç áõôþí ôùí server åßíáé íá ÷ñçóéìïðïéÞóåôå ôï áñ÷åßï REG ðïõ óõìðåñéëáìâÜíåôáé ìå ôçí äéáíïìÞ óáò (pws-php4cgi.reg). Èá èÝëåôå íá ìïñöïðïéÞóåôå áõôü ôï áñ÷åßï êáé íá óéãïõñåõôåßôå ðùò ïé åðåêôÜóåéò êáé ïé êáôÜëïãïé åãêáôÜóôáóçò ôçò PHP ôáéñéÜæïõí ìå ôéò ñõèìßóåéò óáò. ¹ ìðïñåßôå íá áêïëïõèÞóåôå ôá âÞìáôá ðáñáêÜôù ãéá íá ôï êÜíåôå ÷åéñïêßíçôá.
Ðñïåéäïðïßçóç |
ÁõôÜ ôá âÞìáôá ðåñéÝ÷ïõí êáô' åõèåßáí ìïñöïðïßçóç ìÝóù ôïõ Windows registry. ¸íá ëÜèïò åäþ êáé ìðïñåß ôï óýóôçìá óáò íá ìåßíåé óå áóôáèÞ êáôÜóôáóç. Ðñïôåßíïõìå Ýíôïíá íá êñáôÞóåôå Ýíá áíôßãñáöï ôçò registry óáò. Ç ïìÜäá áíÜðôõîçò ôçò PHP äåí èá èåùñåßôáé õðåýèõíç áí êáôáóôñÝøåôå ôçí registry óáò. |
ÔñÝîôå ôï Regedit.
Ðçãáßíåôå óôï: HKEY_LOCAL_MACHINE /System /CurrentControlSet /Services /W3Svc /Parameters /ScriptMap.
Óôï edit menu åðéëÝîôå:New->String Value.
ÃñÜøôå ôçí åðÝêôáóç ðïõ èÝëåôå íá ÷ñçóéìïðïéÞóåôå ãéá ôá php scripts óáò. Ãéá ðáñÜäåéãìá .php
ÊÜíôå äéðëü êëéê óôï new string value åéóÜãåôå ôï path ãéá ôï php.exe ìÝóá óôï ðåäßï. ð.÷.: c:\php\php.exe.
ÅðáíáëÜâåôå áõôÜ ôá âÞìáôá ãéá êÜèå åðÝêôáóç ðïõ èÝëåôå íá óõíäõÜóåôå ìå ôá PHP script óáò.
Ôá áêüëïõèá âÞìáôá äåí åðéñåÜæïõí ôçí åãêáôÜóôáóç ôïõ web server êáé éó÷ýïõí ìüíï áí ôá php script óáò èá åêôåëïýíôáé áðü ôï command line (ð.÷. ôñÝ÷ïíôáò c:\myscripts\test.php) Þ êÜíïíôáò äéðëü êëéê ðÜíù ôïõò óå Ýíá ðáñÜèõñï åìöÜíéóçò êáôáëüãïõ. Ìðïñåß íá èÝëåôå íá ôá ðáñáëåßøåôå áí ðñïôéìÜôå ôá PHP áñ÷åßá óáò íá öïñôþíïíôáé óå Ýíá text editor üôáí êÜíåôå äéðëü êëéê ðÜíù ôïõò.
Ðçãáßíåôå óôï: HKEY_CLASSES_ROOT
Óôï edit menu åðéëÝîôå: New->Key.
ÏíïìÜóôå ôï êëåéäß ìå ôçí åðÝêôáóç ðïõ Ý÷åôå ïñßóåé óôçí ðñïçãïýìåíç åíüôçôá. ð.÷.: .php
ÊÜíôå highlight ôï íÝï êëåéäß êáé óôï äåîß side pane, êÜíôå äéðëü êëéê óôï "default value" êáé ãñÜøôå phpfile.
ÅðáíáëÜâåôå ôï ôåëåõôáßï âÞìá ãéá êÜèå åðÝêôáóç ðïõ Ý÷åôå ïñßóåé óôçí ðñïçãïýìåíç åíüôçôá
Ôþñá äçìéïõñãÞóôå áêüìç Ýíá New->Key óôï HKEY_CLASSES_ROOT êáé ïíïìÜóôå ôï phpfile.
ÊÜíôå highlight ôï íÝï êëåéäß êáé óôï äåîß side pane, êÜíôå äéðëü êëéê óôï "default value" êáé ãñÜøôå PHP script.
ÊÜíôå äåîß êëéê óôï phpfile key êáé åðéëÝîôå New->Key êáé ïíïìÜóôå ôï Shell.
ÊÜíôå äåîß êëéê óôï Shell key êáé åðéëÝîôå New->Key êáé ïíïìÜóôå ôï open.
ÊÜíôå äåîß êïõìðß óôï open key êáé åðéëÝîôå New->Key êáé ïíïìÜóôå ôï command.
ÊÜíôå highlight óôï íÝï êëåéäß command êáé óôï äåîéÜ side pane, êÜíôå äéðëü êëéê óôï "default value" êáé ãñÜøôå ôï path óôï php.exe. ð.÷.: c:\php\php.exe -q %1. (ìçí îå÷Üóåôå ôï %1).
Âãåßôå áðü ôï Regedit.
Áí ÷ñçóéìïðïéåßôå PWS óôá Windows, êÜíôå reboot êáé îáíáöïñôþóôå ôï registry.
Ïé ÷ñÞóôåò ôùí PWS êáé IIS 3 ôþñá Ý÷ïõí Ýíá ðëÞñåò ëåéôïõñãÞóéìï óýóôçìá. Ïé ÷ñÞóôåò ôïõ IIS 3 ìðïñïýí íá ÷ñçóéìïðïéïýí Ýíá êïìøü åñãáëåßï áðü ôïí Steven Genusa ãéá íá ñõèìßæïõí ôá script maps ôïõò.
¼ôáí åãêáèéóôÜôå ôçí PHP óôá Windows ìå ôï PWS 4 Þ íåüôåñç Ýêäïóç, Ý÷åôå äýï åðéëïãÝò. Ç ìßá åßíáé íá ñõèìßóåôå ôï PHP CGI binary, ç Üëëç íá ÷ñçóéìïðïéÞóåôå ôçí ISAPI module DLL âéâëéïèÞêç.
Áí åðéëÝîåôå ôï CGI binary, êÜíôå ôá áêüëïõèá:
ÊÜíôå edit ôï áñ÷åßï pws-php4cgi.reg (êïéôÜîôå ìÝóá óôïí êáôÜëïãï SAPI) ãéá íá áíôáíáêëÜ ôçí ôïðïèåóßá ôïõ php.exe áñ÷åßïõ. Ôá backslashes ðñÝðåé íá ãßíïíôáé escape, ãéá ðáñÜäåéãìá: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="c:\\php\\php.exe" Ôþñá åíþóôå áõôü ôï áñ÷åßï registry óôï óýóôçìá óáò êÜíïíôáò äéðëü êëéê ðÜíù ôïõ.
ÌÝóá óôï PWS Manager, êÜíôå äéðëü êëéê óå Ýíá directory ðïõ èÝëåôå íá ðñïóèÝóåôå õðïóôÞñéîç PHP êáé åðéëÝîôå Properties. ÅðéëÝîôå ôï 'Execute' checkbox êáé åðéâåâáéþóôå.
Áí åðéëÝîåôå ôï ISAPI module, êÜíôå ôá áêüëïõèá:
ÊÜíôå edit ôï pws-php4isapi.reg áñ÷åßï (êïéôÜîôå óôïí êáôÜëïãï SAPI) ãéá íá áíôáíáêëÜ ôçí ôïðïèåóßá ôïõ áñ÷åßïõ php4isapi.dll. Ôá backslash ðñÝðåé íá ãßíïíôáé escape, ãéá ðáñÜäåéãìá: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="c:\\php\\sapi\\php4isapi.dll" Ôþñá åíþóôå áõôü ôï áñ÷åßï registry óôï óýóôçìá óáò êÜíïíôáò äéðëü êëéê ðÜíù ôïõ.
ÌÝóá óôï PWS Manager, êÜíôå äéðëü êëéê óå Ýíá äåäïìÝíï directory ðïõ èÝëåôå íá ðñïóèÝóåôå õðïóôÞñéîç PHP, êáé åðéëÝîôå Properties. ÅëÝãîôå ôï 'Execute' checkbox êáé åðéâåâáéþóôå.
Ãéá íá åãêáôáóôÞóåôå ôçí PHP óå Ýíá NT/2000/XP Server ðïõ ôñÝ÷åé IIS 4 Þ íåüôåñï, áêïëïõèÞóôå áõôÝò ôéò ïäçãßåò. ¸÷åôå äýï åðéëïãÝò ãéá íá ñõèìßóåôå ôçí PHP, ÷ñçóéìïðïéþíôáò ôï CGI binary (php.exe) Þ ìå ôï ISAPI module.
Óå êÜèå ðåñßðôùóç, ðñÝðåé íá îåêéíÞóåôå ôï Microsoft Management Console (ìðïñåß íá åìöáíßæåôáé ùò 'Internet Services Manager', åßôå ìÝóá óôï Windows NT 4.0 Option Pack branch Þ óôï Control Panel=>Administrative Tools óôá Windows 2000/XP). Ôüôå êÜíôå äåîß êëéê óôï Web server node óáò (áõôü ðéèáíþò íá åìöáíßæåôáé ùò 'Default Web Server'), êáé åðéëÝîôå 'Properties'.
Áí èÝëåôå íá ÷ñçóéìïðïéÞóåôå ôï CGI binary, êÜíôå ôá áêüëïõèá:
Óôï 'Home Directory', 'Virtual Directory', Þ 'Directory', êÜíôå êëéê óôï êïõìðß 'Configuration', êáé ôüôå åéóÜãåôå ôï App Mappings tab.
ÅðéëÝîôå Add, êáé óôï êïõôß Executable, ðëçêôñïëïãÞóôå: c:\php\php.exe (õðïèÝôïíôáò ðùò Ý÷åôå êÜíåé unzip ôçí PHP óôï c:\php\).
Óôï êïõôß Extension (åðÝêôáóç), ãñÜøôå ôçí åðÝêôáóç ðïõ èÝëåôå íá êÜíåôå associate (óõíäõÜóåôå) ìå ôá PHP scripts. ÁöÞóôå ôï 'Method exclusions' êåíü êáé åðéëÝîôå ôï Script engine checkbox. Ìðïñåßôå åðßóçò íá åðéëÝîåôå ôï 'check that file exists' êïõôß - ãéá ìéá ìéêñÞ ðïéíÞ áðüäïóçò ï IIS (Þ ï PWS) èá åëÝãîïõí üôé ôï script áñ÷åßï õðÜñ÷åé êáé èá ôáêôïðïéÞóïõí ôï authentication ðñéí îåêéíÞóïõí ôçí php. Áõôü óçìáßíåé ðùò èá ðáßñíåôå ëïãéêÜ ìçíýìáôá óöáëìÜôùí ôïõ óôõë ôïõ 404 áíôß óöÜëìáôá ðïõ ðáñáðïíéïýíôáé ðùò ç php äåí åß÷å äåäïìÝíá óôçí Ýîïäï ôçò.
ÐñÝðåé íá îáíáñ÷ßóåôå áðü ôï ðñïçãïýìåíï âÞìá ãéá êÜèå åðÝêôáóç ðïõ èÝëåôå íá ôçí óõíäõÜóåôå ìå ôá PHP script. Ôá .php êáé .phtml åßíáé óõ÷íÜ, áí êáé ôï .php3 ìðïñåß íá ÷ñåéÜæåôáé ãéá ðáëéÝò åöáñìïãÝò.
Ïñßóôå ôçí áðáñáßôçôç áóöÜëåéá. (Áõôü ãßíåôáé óôï Internet Service Manager), êáé áí ï NT Server óáò ÷ñçóéìïðïéåß NTFS file system, ðñïóèÝóôå äéêáéþìáôá åêôÝëåóçò óôïí I_USR_ óôïí êáôÜëïãï ðïõ ðåñéÝ÷åé php.exe.
Ãéá íá ÷ñçóéìïðïéÞóåôå ôï ISAPI module, êÜíôå ôá áêüëïõèá:
Áí äåí èÝëåôå íá ðñáãìáôïðïéåßôå HTTP Authentication ìå ôçí PHP, ìðïñåßôå (êáé èá ðñÝðåé) íá ðáñáëåßøåôå áõôü ôï âÞìá. ÊÜôù áðü ôá ISAPI Filters (ößëôñá), ðñïóèÝóôå Ýíá íÝï ößëôñï ISAPI. ×ñçóéìïðïéÞóôå ôçí PHP óáí üíïìá ößëôñïõ êáé ïñßóôå Ýíá path óôï php4isapi.dll.
ÊÜôù áðü ôï 'Home Directory', êÜíôå êëéê óôï êïõìðß 'Configuration'. ÐñïóèÝóôå ìéá íÝá êáôá÷þñçóç óôï Application Mappings. ×ñçóéìïðïéÞóôå ôï path óôï php4isapi.dll óáí Executable, ïñßóôå ôï .php ãéá ôçí åðÝêôáóç, áöÞóôå ôï Method exclusions êåíü êáé åðéëÝîôå ôï Script engine checkbox.
ÓôáìáôÞóôå ôåëåßùò ôïí IIS (NET STOP iisadmin)
ÎåêéíÞóôå îáíÜ ôïí IIS (NET START w3svc)
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò óõãêåêñéìÝíá ãéá ôéò Netscape êáé iPlanet åãêáôáóôÜóåéò ôçò PHP, ôüóï ãéá ôçí Sun Solaris üóï ãéá ôçí Windows Ýêäïóç.
Ìðïñåßôå íá âñåßôå ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôçí ñýèìéóç ôçò PHP ãéá ôïí Netscape Enterprise Server åäþ: http://benoit.noss.free.fr/php/install-php4.html
Ãéá íá êÜíåôå build ôçí PHP ìå ôïõò NES Þ iPlanet web servers, åéóÜãåôå ôïí óùóôü êáôÜëïãï åãêáôÜóôáóçò óôçí åðéëïãÞ --with-nsapi = DIR. Ï ðñïåðéëåãìÝíïò êáôÜëïãïò åßíáé óõíÞèùò /opt/netscape/suitespot/. Ðáñáêáëïýìå äéáâÜóôå åðßóçò ôï /php-xxx-version/sapi/nsapi/nsapi-readme.txt.
ÐáñÜäåéãìá 3-10. ÐáñÜäåéãìá åãêáôÜóôáóçò ãéá ôïí Netscape Enterprise óå Solaris
|
Ðñþôá ìðïñåß íá ÷ñåéáóôåß íá ðñïóèÝóåôå êÜðïéá paths óôï LD_LIBRARY_PATH environment ãéá íá âñåé üëåò ôéò shared libs ï Netscape. Áõôü ìðïñåß íá ãßíåé êáëýôåñá óôï start script ãéá ôïí Netscape server óáò. Ïé ÷ñÞóôåò ôùí Windows ìðïñïýí ðéèáíþò íá ðáñáëåßøïõí áõôü ôï âÞìá. Ôï start script óõ÷íÜ âñßóêåôáé óôï: /path/to/server/https-servername/start
Ìðïñåß íá ÷ñåéáóôåß åðßóçò íá êÜíåôå edit ôá áñ÷åßá ñõèìßóåùí ðïõ âñßóêïíôáé óôï:/path/to/server/https-servername/config/.
ÐáñÜäåéãìá 3-11. ÐáñÜäåéãìá ñýèìéóçò ãéá ôïí Netscape Enterprise
|
Áí ôñÝ÷åôå Netscape Enterprise 4.x, ôüôå èá ðñÝðåé íá ÷ñçóéìïðïéÞóåôå ôá áêüëïõèá:
ÐáñÜäåéãìá 3-12. ÐáñÜäåéãìá ñýèìéóçò ãéá ôïí Netscape Enterprise 4.x
|
Ãéá íá åãêáôáóôÞóåôå ôçí PHP óáí CGI (ãéá ôïí Netscape Enterprise Server, iPlanet, ßóùò Fastrack), êÜíôå ôá áêüëïõèá:
ÁíôéãñÜøôå ôï php4ts.dll óôï systemroot óáò (ôïí êáôÜëïãï ðïõ Ý÷åôå åãêáôáóôÞóåé ôá windows)
ÄçìéïõñãÞóôå Ýíá file association áðü ôï command line. ÐëçêôñïëïãÞóôå ôéò áêüëïõèåò äýï ãñáììÝò:
assoc .php=PHPScript ftype PHPScript=c:\php\php.exe %1 %* |
Óôï Netscape Enterprise Administration Server äçìéïõñãÞóôå Ýíá dummy shellcgi êáôÜëïãï êáé áöáéñÝóôå ôïí áìÝóùò ìåôÜ (áõôü ôï âÞìá äçìéïõñãåß 5 óçìáíôéêÝò ãñáììÝò óôï obj.conf êáé åðéôñÝðåé óôïí web server íá ÷åéñßæåôáé shellcgi scripts).
Óôï Netscape Enterprise Administration Server äçìéïõñãÞóôå Ýíá íÝï mime type (Category: type, Content-Type: magnus-internal/shellcgi, File Suffix:php).
ÊÜíôå ôï ãéá êÜèå web server instance ðïõ èÝëåôå íá ôñÝ÷åé ç php
Ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôç ñýèìéóç ôçò PHP óáí CGI executable ìðïñïýí íá âñåèïýí åäþ: http://benoit.noss.free.fr/php/install-php.html
Ãéá íá åãêáôáóôÞóåôå ôçí PHP óáí NSAPI (ãéá ôïí Netscape Enterprise Server, iPlanet, ßóùò Fastrack, êÜíôå ôá áêüëïõèá:
ÁíôéãñÜøôå ôï php4ts.dll óôï systemroot óáò (ôïí êáôÜëïãï ðïõ Ý÷åôå åãêáôáóôÞóåé ôá windows)
ÄçìéïõñãÞóôå Ýíá file association áðü ôï command line. ÐëçêôñïëïãÞóôå ôéò áêüëïõèåò äýï ãñáììÝò:
assoc .php=PHPScript ftype PHPScript=c:\php\php.exe %1 %* |
Óôï Netscape Enterprise Administration Server äçìéïõñãÞóôå Ýíá íÝï mime type (Category: type, Content-Type: magnus-internal/x-httpd-php, File Suffix:php).
ÓôáìáôÞóôå ôï web service óáò êáé êÜíôå edit ôï obj.conf. Óôï ôÝëïò ôçò åíüôçôáò Init, ôïðïèåôÞóôå áõôÝò ôéò äýï ãñáììÝò (áðáñáßôçôá ìåôÜ ôï mime type init!):
Init fn="load-modules" funcs="php4_init,php4_close,php4_execute,php4_auth_trans" shlib="c:/php/sapi/php4nsapi.dll" Init fn="php4_init" errorString="Failed to initialise PHP!" |
ÌÝóá óôçí åíüôçôá < Object name="default" > ôïðïèåôÞóôå áõôÞ ôç ãñáììÞ áðáñáßôçôá ìåôÜ áðü üëá ôá 'ObjectType' êáé ðñéí áðü üëåò ôéò 'AddLog' ãñáììÝò:
Service fn="php4_execute" type="magnus-internal/x-httpd-php" |
Óôï ôÝëïò ôïõ áñ÷åßïõ, äçìéïõñãÞóôå Ýíá íÝï áíôéêåßìåíï ìå üíïìá x-httpd-php, ôïðïèåôþíôáò áõôÝò ôéò ãñáììÝò:
<Object name="x-httpd-php"> ObjectType fn="force-type" type="magnus-internal/x-httpd-php" Service fn=php4_execute </Object> |
ÅðáíåêêéíÞóôå ôï web service êáé åöáñìüóôå ôéò áëëáãÝò
ÊÜíôå ôï áõôü ãéá êÜèå web server instance ðïõ èÝëåôå íá ôñÝ÷åé ç PHP
Ðåñéóóüôåñåò ðëçñïöïñßåò ãéá íá ñõèìßóåôå ôçí PHP óáí Ýíá NSAPI filter ìðïñïýí íá âñåèïýí åäþ: http://benoit.noss.free.fr/php/install-php4.html
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò óõãêåêñéìÝíá ãéá ôïí OmniHTTPd.
Ç ïëïêëÞñùóç ôùí ðáñáêÜôù âçìÜôùí áðáéôåßôáé ãéá íá êÜíåôå ôçí PHP íá äïõëåýåé ìå ôïí OmniHTTPd. ÁõôÞ åßíáé ìéá CGI executable åãêáôÜóôáóç. Ôï SAPI õðïóôçñßæåôáé áðü ôïí OmniHTTPd, áëëÜ êÜðïéåò äïêéìÝò Ýäåéîáí ðùò äåí åßíáé óôáèåñÞ ç ÷ñÞóç ôçò PHP óáí ISAPI module.
Óçìáíôéêü ãéá ôïõò ÷ñÞóôåò CGI: ÄéáâÜóôå ôï faq ó÷åôéêÜ ìå ôï cgi.force_redirect ãéá óçìáíôéêÝò ëåðôïìÝñåéåò. Áõôü ôï directive áðáéôåßôáé íá ïñéóôåß óå 0.
ÂÞìá 1: ÅãêáôáóôÞóôå ôïí OmniHTTPd server.
ÂÞìá 2: ÊÜíôå äåîß êëéê óôï ìðëå åéêïíßäéï ôïõ OmniHTTPd icon óôï system tray êáé åðéëÝîôå Properties
ÂÞìá 3: ÊÜíôå êëéê óôï Web Server Global Settings
ÂÞìá 4: Óôï 'External' tab, âÜëôå: virtual = .php | actual = c:\path-to-php-dir\php.exe êáé ÷ñçóéìïðïéÞóôå ôï êïõìðß Add.
ÂÞìá 5: Óôï Mime tab, ãñÜøôå: virtual = wwwserver/stdcgi | actual = .php, êáé ÷ñçóéìïðïéÞóôå ôï êïõìðß Add.
ÂÞìá 6: ÊÜíôå êëéê óôï OK
ÅðáíáëÜâåôå ôá âÞìáôá 2 - 6 ãéá êÜèå åðÝêôáóç ðïõ èÝëåôå íá óõíäõÜóåôå ìå ôçí PHP.
Óçìåßùóç: ÊÜðïéá ðáêÝôá ôïõ OmniHTTPd Ýñ÷ïíôáé ìå åíóùìáôùìÝíç õðïóôÞñéîç ãéá PHP. Ìðïñåßôå íá åðéëÝîåôå êáôÜ åãêáôÜóôáóç íá ãßíåé ðñïóáñìïãÞ (custom setup) êáé íá ìçí åðéëÝîåôå ôï PHP component. Ðñïôåßíïõìå íá ÷ñçóéìïðïéåßôå ôá ôåëåõôáßá PHP binaries. ÊÜðïéïé OmniHTTPd servers Ýñ÷ïíôáé ìå PHP 4 beta äéáíïìÝò, ãé' áõôü èá ðñÝðåé íá ìçí åðéëÝîåôå ôçí åíóùìáôùìÝíç õðïóôÞñéîç, áëëÜ íá åãêáôáóôÞóåôå ôç äéêÞ óáò. Áí ï server åßíáé Þäç óôï ìç÷Üíçìá óáò, ÷ñçóéìïðïéÞóôå ôï êïõìðß Replace óôá âÞìáôá 4 êáé 5 ãéá íá ïñßóåôå ôç íÝá, óùóôÞ ðëçñïöïñßá.
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò óõãêåêñéìÝíá ãéá ôo Oreilly Website Pro.
Áõôüò ï êáôÜëïãïò ðåñéãñÜöåé ðþò íá ñõèìßóåôå ôï PHP CGI binary Þ ôï ISAPI module ãéá íá äïõëåýïõí ìå ôï Oreilly Website Pro óôá Windows.
ÊÜíôå edit ôï Server Properties êáé åðéëÝîôå ôï tab "Mapping".
Áðü ôïí êáôÜëïãï åðéëÝîôå "Associations" êáé åéóÜãåôå ôçí åðéèõìçôÞ åðÝêôáóç (.php) êáé ôï path óôï CGI exe (ð.÷. c:\php\php.exe) Þ óôï ISAPI DLL áñ÷åßï (ð.÷. c:\php\sapi\php4isapi.dll).
ÅðéëÝîôå "Content Types" êáé ðñïóèÝóôå ôçí ßäéá åðÝêôáóç (.php) êáé åéóÜãåôå ôï content type. Áí åðéëÝîôå ôï CGI executable áñ÷åßï, åéóÜãåôå 'wwwserver/shellcgi', áí åðéëÝîáôå ôï ISAPI module, åéóÜãåôå 'wwwserver/isapi' (êáé ôá äýï ÷ùñßò quotes).
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò óõãêåêñéìÝíá ãéá ôïí Sambar server ãéá Windows.
Áõôüò ï êáôÜëïãïò ðåñéãñÜöåé ðþò íá ñõèìßóåôå ôï ISAPI module íá äïõëåýåé ìå ôïí Sambar server óôá Windows.
Âñåßôå ôï áñ÷åßï ìå üíïìá mappings.ini (ìÝóá óôïí êáôÜëïãï config) óôïí êáôÜëïãï åãêáôÜóôáóçò ôïõ Sambar.
Áíïßîôå ôï mappings.ini êáé ðñïóèÝóôå ôçí áêüëïõèç ãñáììÞ êÜôù áðü ôï [ISAPI]:
(ÁõôÞ ç ãñáììÞ õðïèÝôåé üôé ç PHP Ý÷åé åãêáôáóôáèåß óôï c:\php.)Ôþñá åðáíåêêéíÞóôå ôïí Sambar server ãéá íá åíåñãïðïéçèïýí ïé áëëáãÝò.
ÁõôÞ ç åíüôçôá ðåñéÝ÷åé óçìåéþóåéò êáé óõìâïõëÝò óõãêåêñéìÝíá ãéá ôïí Xitami.
Áõôüò ï êáôÜëïãïò ðåñéãñÜöåé ðþò íá ñõèìßóåôå ôï PHP CGI binary Þ ôï ISAPI module ãéá íá äïõëåýïõí ìå ôï Oreilly Website Pro óôá Windows.
Important for CGI users: ÄéáâÜóôå ôï faq ó÷åôéêÜ ìå ôï cgi.force_redirect ãéá óçìáíôéêÝò ëåðôïìÝñåéåò. Áõôü ôï directive áðáéôåßôáé íá ïñéóôåß óå 0.
Óéãïõñåõôåßôå ðùò ï webserver óáò ôñÝ÷åé êáé ðëïçãÞóôå ôïí browser óáò óôï xitamis admin console (óõíÞèùò http://127.0.0.1/admin), êáé êÜíôå êëéê óôï Configuration.
Ðçãáßíåôå óôá Filters, êáé âÜëôå ôçí åðÝêôáóç ôçí ïðïßá ç PHP èá ìåôáöñÜæåé (ð.÷. .php) óôï ðåäßï File extensions (.xxx).
Óôï Filter command or script âÜëôå ôï path êáé ôï üíïìá ôïõ php åêôåëÝóéìïõ ð.÷. c:\php\php.exe.
ÐáôÞóôå ôï åéêïíßäéï 'Save'.
ÅðáíåêêéíÞóôå ôïí server ãéá íá öáíïýí ïé áëëáãÝò.
Ç PHP ìðïñåß íá ãßíåé build ãéá íá õðïóôçñßæåé ìåãÜëï áñéèìü áðü web servers. Ðáñáêáëïýìå äåßôå ôéò ñõèìßóåéò ó÷åôéêÝò ìå ôïí Server ãéá Ýíá ðëÞñç êáôÜëïãï áðü åðéëïãÝò óôï configure. options. Ôá PHP CGI binaries åßíáé óõìâáôÜ ó÷åäüí ìå üëïõò ôïõò webservers ðïõ õðïóôçñßæïõí ôï ðñüôõðï CGI.
ÊÜðïéá ðñïâëÞìáôá åßíáé ðéï óõ÷íÜ áðü Üëëá. Ôá ðéï óõ÷íÜ âñßóêïíôáé óôçí åíüôçôá PHP FAQ áõôïý ôïõ manual.
Áí áêüìç åßóôå êïëëçìÝíïé, êÜðïéïò óôçí PHP installation mailing list ìðïñåß íá óáò âïçèÞóåé. Èá ðñÝðåé íá åëÝãîåôå ðñþôá ôï éóôïñéêü (archive), óå ðåñßðôùóç ðïõ êÜðïéïò Ý÷åé Þäç áðáíôÞóåé êÜðïéïõ Üëëïõ ðïõ åß÷å ôï ßäéï ðñüâëçìá ìå óáò. Ôï éóôïñéêü åßíáé äéáèÝóéìï áðü ôç óåëßäá õðïóôÞñéîçò óôï http://www.php.net/. Ãéá íá ãñáöôåßôå óôçí PHP installation mailing list, óôåßëôå Ýíá êåíü email óôï php-install-subscribe@lists.php.net. Ç äéåýèõíóç ôçò mailing list åßíáé php-install@lists.php.net.
Áí èÝëåôå íá óáò âïçèÞóïõí óôçí mailing list, ðáñáêáëïýìå ðñïóðáèÞóôå íá åßóôå áêñéâÞò êáé íá äþóåôå ôéò áðáñáßôçôåò ëåðôïìÝñåéò ãéá ôï ðåñéâÜëëïí óáò (ôé ëåéôïõñãéêü, Ýêäïóç PHP, web server Ý÷åôå, áí ôñÝ÷åôå ôçí PHP óáí CGI Þ server module, safe mode, êëð...) êáé êáôÜ ðñïôßìçóç áñêåôü êþäéêá ãéá íá ìðïñïýí Üëëïé íá áíáðáñáãÜãïõí êáé íá äïêéìÜóïõí ôï ðñüâëçìá óáò.
Áí ðéóôåýåôå ðùò âñÞêáôå Ýíá bug óôçí PHP, ðáñáêáëïýìå áíáöÝñåôå ôï. Ïé PHP developers ðéèáíüí íá ìçí ôï îÝñïõí êáé, åêôüò êáé áí ôï áíáöÝñåôå, ïé ðéèáíüôçôåò åßíáé íá ìçí öôéá÷ôåß. Ìðïñåßôå íá áíáöÝñåôå bugs ÷ñçóéìïðïéþíôáò ôï bug-tracking óýóôçìá óôï http://bugs.php.net/. Ðáñáêáëïýìå ìçí óôÝëíåôå áíáöïñÝò ãéá bug óôçí mailing list Þ óå ðñïóùðéêÜ email. To bug system åßíáé åðßóçò êáôÜëëçëï ãéá íá êáôá÷ùñïýíôáé áéôÞóåéò ãéá íÝá ÷áñáêôçñéóôéêÜ.
ÄéáâÜóôå ôï Ýããñáöï íÐùò áíáöÝñù Ýíá bug ðñéí óôåßëåôå êÜðïéá áíáöïñÜ ãéá bug!
ÐáñáêÜôù ìðïñåßôå íá âñåßôå Ýíá ìÝñïò ôùí åðéëïãþí ôïõ configure ðïõ ÷ñçóéìïðïéïýíôáé áðü ôá configure scripts ôçò PHP üôáí ãßíåôáé compile óå Unix-like ðåñéâÜëëïíôá. Ïé ðåñéóóüôåñåò åðéëïãÝò ôïõ configure åßíáé êáôá÷ùñçìÝíá óôéò óùóôÝò ôïðïèåóßåò êáé ü÷é åäþ. Ãéá Ýíá ðëÞñç up-to-date êáôÜëïãï ôùí åðéëïãþí ôïõ configure, ôñÝîôå ôï ./configure --help óôïí êáôÜëïãï ìå ôùí êþäéêá ôçò PHP ìåôÜ ðïõ ôñÝîáôå ôï autoconf (äåßôå åðßóçò ôï êåöÜëáéï ÅãêáôÜóôáóçò). Ìðïñåß åðßóçò íá åíäéáöÝñåóôå óôçí áíÜãíùóç ôïõ GNU configure documentation ãéá ðëçñïöïñßåò ãéá åðéðëåüí åðéëïãÝò ôïõ configure üðùò ç --prefix=PREFIX.
Óçìåßùóç: ÁõôÝò ÷ñçóéìïðïéïýíôáé ìüíï êáôÜ ôçí þñá ôïõ compile. Áí èÝëåôå íá áëëÜîåôå ôéò runtime (ôñÝ÷ïõóåò) ñõèìßóåéò ôçò PHP, ðáñáêáëïýìå äåßôå ôçí åíüôçôá ãéá ôéò Ñõèìßóåéò.
Óçìåßùóç: ÁõôÝò ïé åðéëïãÝò ÷ñçóéìïðïéïýíôáé ìüíï óôçí PHP 4 áðü ôçí PHP 4.1.0. ÊÜðïéåò åßíáé äéáèÝóéìåò óå ðáëáéüôåñåò åêäüóåéò ôçò PHP 4, êÜðïéåò áêüìç óôçí PHP 3, êÜðïéåò ìüíï óôçí PHP 4.1.0. Áí èÝëåôå íá êÜíåôå compile ìéá ðáëáéüôåñç Ýêäïóç, êÜðïéåò åðéëïãÝò ðéèáíüí íá ìçí åßíáé äéáèÝóéìåò.
Ç åðÝêôáóç imagick Ý÷åé ìåôáöåñèåß óôï PECL óôï PEAR êáé ìðïñåß íá âñåèåß åäþ. Ïäçãßåò åãêáôÜóôáóçò ãéá ôçí PHP 4 ìðïñïýí íá âñåèïýí óôçí éóôïóåëßäá ôïõ PEAR.
Ôï áðëü --with-imagick õðïóôçñßæåôáé ìüíï óôçí PHP 3 åêôüò êáé áí áêïëïõèÞóåôå ôéò ïäçãßåò óôçí éóôïóåëßäá ôïõ PEAR.
Åíåñãïðïßçóç ôïõ åëÝã÷ïõ áóöÜëåéáò ãéá åóùôåñéêÜ server redirects. ÐñÝðåé íá ôï ÷ñçóéìïðïéåßôå áí ôñÝ÷åôå ôçí CGI Ýêäïóç ìå ôïí Apache.
Áí áõôü åßíáé åíåñãïðïéçìÝíï, ôï PHP CGI binary ìðïñåß íá ôïðïèåôçèåß ìå áóöÜëåéá Ýîù áðü ôï web tree êáé äåí ç áóöÜëåéá ôïõ .htaccess äåí èá ðáñáêÜìðôåôáé.
Íá ãßíåé build ç PHP óáí ìéá åöáñìïãÞ FastCGI.
Íá ãßíåé compile ìå debugging symbols.
Ïñßæåé ðùò ôá åãêáôåóôçìÝíá áñ÷åßá èá ãßíïõí laid out. Ï Ôýðïò (Type) åßíáé Ýíá áðü ôá PHP (ðñïåðéëïãÞ) Þ GNU.
ÅãêáôÜóôáóç ôïõ PEAR óôï DIR (ðñïêáèïñéóìÝíï PREFIX/lib/php).
Íá ìçí åãêáôáóôáèåß ôï PEAR.
Åíåñãïðïßçóç ôïõ SIGCHLD handler ôçò ßäéáò ôçò PHP.
Áðåíåñãïðïßçóç ôïõ ðåñÜóìáôïò åðéðëÝïí runtime library search paths.
Åíåñãïðïßçóç ñçôïý linking ìå ôçí libgcc.
Óõìðåñßëçøç äïêéìáóôéêþí php streams. Ìçí ôá ÷ñçóéìïðïéåßôå åêôüò êáé áí äïêéìÜæåôå ôïí êþäéêá!
Ïñßæåé ôçí ôïðïèåóßá ôïõ êáôÜëïãïõ åãêáôÜóôáóçò ôçò zlib.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá ASPELL.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá CCVS.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá CyberCash. Ôï DIR åßíáé ï êáôÜëïãïò åãêáôÜóôáóçò ôçò CyberCash MCK.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá ICAP.
Path ãéá ôï ircg-config script.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá ircg.
Åíåñãïðïßçóç õðïóôÞñéîçò ãéá mailparse.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá muscat.
Åíåñãïðïßçóç õðïóôÞñéîçò ãéá CORBA ìÝóù ôïõ Satellite (ÄÏÊÉÌÁÓÔÉÊÏ). Ôï DIR åßíáé ï âáóéêüò êáôÜëïãïò ôïõ ORBit.
Åíåñãïðïßçóç äéÜöáíçò äéÜäïóçò ôïõ session id.
×ñÞóç ôçò âéâëéïèÞêçò óõóôÞìáôïò ãéá regex (îåðåñáóìÝíç).
Óõìðåñßëçøç õðïóôÞñéîçò ãéá vpopmail.
×ñÞóç POSIX threads (ðñïåðéëïãÞ).
ÅãêáôÜóôáóç shared âéâëéïèçêþí [ðñïåðéëïãÞ=yes].
ÅãêáôÜóôáóç static âéâëéïèçêþí [ðñïåðéëïãÞ=yes].
Âåëôéóôïðïßçóç ãéá ãñÞãïñç åãêáôÜóôáóç [ðñïåðéëïãÞ=yes].
ÕðïèÝôåé ðùò ï C compiler ÷ñçóéìïðïéåß ôï GNU ld [ðñïåðéëïãÞ=no].
ÁðïöõãÞ êëåéäþìáôïò (ìðïñåß íá êáôáóôñÝøåé ðáñÜëëçëá build).
Ðñïóðáèåß íá ÷ñçóéìïðïéåß ìüíï PIC/non-PIC áíôéêåßìåíá [ðñïåðéëïãÞ=use both].
Íá ãßíåé compile ìå õðïóôÞñéîç ãéá üñéï ìíÞìçò (memory limit).
Áðåíåñãïðïßçóç ôïõ URL-aware fopen wrapper ôï ïðïßï åðéôñÝðåé ðñüóâáóç áñ÷åßùí ìÝóù HTTP Þ FTP.
Íá ãßíïõí export ìüíï ôá áðáñáßôçôá óýìâïëá (symbols). Äåßôå ôï áñ÷åßï INSTALL ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá IMSp (ôï DIR åßíáé ôï IMSP's include dir êáé ôï libimsp.a dir). Ìüíï ãéá PHP 3!
Óõìðåñßëçøç õðïóôÞñéîçò ãéá Cybercash MCK support. Ôï DIR åßíáé ï êáôÜëïãïò build ôïõ cybercash mck, ìå ðñïåðéëïãÞ ôï /usr/src/mck-3.2.0.3-linux. Ãéá âïÞèåéá êïéôÜîôå óôï extra/cyberlib. Ìüíï ãéá PHP 3!
Óõìðåñßëçøç õðïóôÞñéîçò ãéá DAV ìÝóù ôïõ mod_dav ôïõ Apache, ôï DIR åßíáé ï êáôÜëïãïò åãêáôÜóôáóçò ôïõ mod_dav (ìüíï ãéá ôçí Apache module Ýêäïóç!) Ìüíï ãéá PHP 3!
Íá ãßíåé compile ìå remote (áðïìáêñõóìÝíåò) óõíáñôÞóåéò debugging. Ìüíï ãéá PHP 3!
ÅêìåôÜëëåõóç ôïõ versioning êáé ôïõ scoping ðïõ ðñïìçèåýåé ôï Solaris 2.x êáé ôï Linux. Ìüíï ãéá PHP 3!
Åíåñãïðïßçóç êáíüíùí ôïõ make êáé dependencies ðïõ äåí åßíáé ÷ñÞóéìåò (êáé êÜðïôå ìðåñäåõôéêÝò) óôïí óõíÞèç Üíèñùðï ðïõ êÜíåé åãêáôÜóôáóç.
Ïñßæåé ôï path óôï ïðïßï íá ãßíåôáé Ýëåã÷ïò ãéá ôï php.ini, ç ðñïåðéëïãÞ åßíáé PREFIX/lib.
Åíåñãïðïéåß ôï safe mode ùò ðñïåðéëïãÞ.
ÅðéôñÝðåé åêôåëÝóéìá óôï DIR üôáí åßíáé óå safe mode, ç ðñïåðéëïãÞ åßíáé /usr/local/php/bin.
Åíåñãïðïßçóç ôùí magic quotes ùò ðñïåðéëïãÞ.
Áðåíåñãïðïßçóç ôïõ ôçò óýíôïìåò ìïñöÞò <? ôïõ start tag by default.
Ïñßæåé ôï path óôïí åãêáôåóôçìÝíï AOLserver.
Íá ãßíåé build shared Apache module. Ôï FILE åßíáé Ýíá ðñïáéñåôéêü pathname óôï åñãáëåßï Apache apxs, Ý÷åé ùò ðñïåðéëïãÞ ôï apxs. Óéãïõñåõôåßôå ðùò ïñßæåôå ìéá Ýêäïóç ôïõ apxs ç ïðïßá óôçí ðñáãìáôéêüôçôá åßíáé åãêáôåóôçìÝíç óôï óýóôçìá óáò êáé Ï×É åêåßíç ç ïðïßá õðÜñ÷åé óôï apache source tarball.
Íá ãßíåé build Apache module. Ôï DIR åßíáé ôï top-level ôïõ êáôÜëïãïõ ôïõ Apache build, ç ðñïåðéëïãÞ åßíáé ôï /usr/local/apache.
Åíåñãïðïßçóç ôùí ðéíÜêùí ìåôáöïñÜò ãéá ôï mod_charset (Rus Apache).
Íá ãßíåé build Ýíá shared Apache 2.0 module. Ôï FILE åßíáé Ýíá ðñïáéñåôéêü pathname óôï åñãáëåßï Apache apxs; ç ðñïåðéëïãÞ åßíáé ôï apxs.
Íá ãßíåé build Ýíá fhttpd module. Ôï DIR åßíáé ï êáôÜëïãïò ôùí fhttpd sources, ç ðñïåðéëïãÞ åßíáé ôï /usr/local/src/fhttpd.
Íá ãßíåé build ç PHP óáí Ýíá ISAPI module ãéá ÷ñÞóç ìå ôï Zeus.
Ïñßæåé ôï path óôïí åãêáôåóôçìÝíï Netscape Server.
Äåí õðÜñ÷ïõí ðëçñïöïñßåò áêüìç.
Íá ãßíåé build ç PHP óáí module ãéá ÷ñÞóç ìå ôï Pi3Web.
Íá ãßíåé build ç PHP óáí Ýíá Pike module. Ôï DIR åßíáé ï âáóéêüò êáôÜëïãïò ôïõ Roxen, óõíÞèùò /usr/local/roxen/server.
Íá ãßíåé build ôï Roxen module ÷ñçóéìïðïéþíôáò ôï Zend Thread Safety.
Óõìðåñßëçøç õðïóôÞñéîçò ãéá servlet. Ôï DIR åßíáé ï âáóéêüò êáôÜëïãïò åãêáôÜóôáóçò ãéá ôï JSDK. Áõôü ôï SAPI ðñïûðïèÝôåé ôçí åðÝêôáóç java íá åßíáé åãêáôåóôçìÝíç óáí Ýíá shared dll.
Íá ãßíåé ç PHP build óáí thttpd module.
Íá ãßíåé build ç PHP óáí Ýíá TUX module (ìüíï ãéá Linux).
Ôï áñ÷åßï ñõèìßóåùí (ìå üíïìá php3.ini óôçí PHP 3.0, êáé áðëÜ php.ini áðü ôçí PHP 4.0) äéáâÜæåôáé üôáí îåêéíÜ ç PHP. Ãéá ôéò server module åêäüóåéò ôçò PHP, áõôü óõìâáßíåé ìüíï üôáí îåêéíÜ ï web server. Ãéá ôéò CGI êáé CLI åêäüóåéò, óõìâáßíåé óå êÜèå êëÞóç.
Ç ðñïåðéëåãìÝíç ôïðïèåóßá ôïõ php.ini åßíáé ìéá åðéëïãÞ ðïõ ïñßæåôáé êáôÜ ôï compile (äåßôå ôçí êáôá÷þñçóç óôï FAQ), áëëÜ ìðïñåß íá áëëá÷ôåß ãéá ôéò CGI êáé CLI åêäüóåéò ìå ôï -c switch ðïõ äßíåôáé óôï command line, äåßôå ôï êåöÜëáéï ó÷åôéêÜ ìå ôçí ÷ñÞóç ôçò PHP áðü ôï command line. Ìðïñåßôå åðßóçò íá ÷ñçóéìïðïéÞóåôå ôçí ìåôáâëçôÞ ðåñéâÜëëïíôïò PHPRC ãéá Ýíá åðéðëÝïí path ãéá íá áíáæçôçèåß Ýíá áñ÷åßï php.ini.
Óçìåßùóç: Ï Apache web server áëëÜæåé ôïí êáôÜëïãï óôï root óå êÜèå åêêßíçóç ðñïêáëþíôáò ôçí PHP íá ðñïóðáèåß íá äéáâÜóåé ôï php.ini áðü ôï root filesystem áí õðÜñ÷åé.
Äåí åßíáé üëá ôá PHP directive (åðéëïãÝò) ôåêìçñéùìÝíåò ðáñáêÜôù. Ãéá Ýíá êáôÜëïãï üëòí ôùí directives, ðáñáêáëïýìå äéáâÜóôå ôï êáëÜ ôåêìçñéùìÝíï áñ÷åßï php.ini. Ìðïñåß íá èÝëåôå íá äåßôå ôï ðéï ðñüóöáôï php.ini åäþ áðü ôï CVS.
Óçìåßùóç: Ç ðñïåðéëåãìÝíç ôéìÞ ãéá ôï PHP directive register_globals Üëëáîå áðü on óå off (áðü åíåñãü óå áíåíåñãü) óôçí PHP 4.2.0.
ÐáñÜäåéãìá 4-1. ÐáñÜäåéãìá åíüò php.ini
|
¼ôáí ÷ñçóéìïðïéåßôå ôçí PHP óáí Ýíá Apache module, ìðïñåßôå áêüìç íá áëëÜîåôå ôéò åðéëïãÝò ñõèìßóåùí ÷ñçóéìïðïéþíôáò directives óôá áñ÷åßá ñõèìßóåùí ôïõ Apache (ð.÷. httpd.conf) êáé ôá áñ÷åßá .htaccess (Èá ÷ñåéáóôåß íá ïñßóåôå ôá "AllowOverride Options" Þ "AllowOverride All" äéêáéþìáôá)
Ìå ôçí PHP 4.0, õðÜñ÷ïõí áñêåôÜ Apache directives ðïõ óáò åðéôñÝðïõí íá áëëÜîåôå ôéò ñõèìßóåéò ôçò PHP ìÝóá áðü ôá áñ÷åßá ñõèìßóåùí ôïõ Apache. Ãéá Ýíá ðëÞñç êáôÜëïãï ôùí ðïéþí directives åßíáé ôá PHP_INI_ALL, PHP_INI_PERDIR, or PHP_INI_SYSTEM, ñßîôå ìéá ìáôéÜ óôïí ðßíáêá ðïõ ìðïñåß íá âñåèåß óôçí ôåêìçñßùóç ôïõ ini_set().
Óçìåßùóç: Ìå ôçí PHP 3.0, õðÜñ÷ïõí Apache directive ðïõ áíôáðïêñßíïíôáé óå êÜèå åðéëïãÞ ñýèìéóçò ìÝóá óôï php3.ini, åêôüò ôá ïíüìáôá ðïõ Ý÷ïõí ðñüèåìá ôï "php3_".
Ïñßæåé ôçí ôéìÞ ãéá ôï directive ðïõ Ý÷åé ïñéóôåß. Ìðïñåß íá ÷ñçóéìïðïéçèåß ìüíï ìå ôá directive ôýðïõ PHP_INI_ALL êáé PHP_INI_PERDIR. Ãéá íá êáèáñéóôåß ìéá ðñïçãïýìåíç ôéìÞ ðïõ Ý÷åé ïñéóôåß, ÷ñçóéìïðïéÞóôå ôï none óáí ôçí ôéìÞ.
Óçìåßùóç: Ìçí ÷ñçóéìïðïéåßôå ôï php_value ãéá íá ïñßóåôå boolen ôéìÝò. Áíôß áõôïý, ôï php_flag (äåßôå ðáñáêÜôù) ðñÝðåé íá ÷ñçóéìïðïéåßôáé..
×ñçóéìïðïéåßôáé ãéá íá ïñéóôåß Ýíá Boolean directive ñýèìéóçò. Ìðïñåß íá ÷ñçóéìïðïéçèåß ìüíï ìå ôá directive ôýðïõ PHP_INI_ALL êáé PHP_INI_PERDIR.
Ïñßæåé ôçí ôéìÞ ôïõ áíáöåñüìåíïõ directive. Áõôü ÄÅÍ ìðïñåß íá ÷ñçóéìïðïéçèåß óå áñ÷åßá .htaccess. ÊáíÝíá directive ðïõ Ý÷åé type set ìå php_admin_value äåí ìðïñåß íá ðáñáâéáóôåß áðü êÜðïéï .htaccess Þ virtualhost directive. Ãéá íá êáèáñéóôåß ìéá ðñïçãïýìåíç ôéìÞ ðïõ Ý÷åé ïñéóôåß, ÷ñçóéìïðïéÞóôå ôï none óáí ôçí ôéìÞ.
×ñçóéìïðïéåßôáé ãéá íá ïñßóåé Ýíá Boolean directive ñýèìéóçò. Áõôü ÄÅÍ ìðïñåß íá ÷ñçóéìïðïéçèåß óå áñ÷åßá .htaccess. ÊáíÝíá directive ðïõ Ý÷åé type set ìå php_admin_value äåí ìðïñåß íá ðáñáâéáóôåß áðü êÜðïéï .htaccess Þ virtualhost directive.
Óçìåßùóç: Ïé óôáèåñÝò ôçò PHP äåí õðÜñ÷ïõí Ýîù áðü ôçí PHP. Ãéá ðáñÜäåéãìá, óôï httpd.conf äåí ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå óôáèåñÝò ôçò PHP üðùò ïé E_ALL Þ E_NOTICE ãéá íá ïñßóåôå ôï error_reporting directive ãéáôß äåí èá Ý÷ïõí óçìáóßá êáé èá áðïôéìïýíôáé óå 0. Áíôß áõôïý, ÷ñçóéìïðïéÞóôå ôï associated bitmask ôéìÝò. ÁõôÝò ïé óôáèåñÝò ìðïñïýí íá ÷ñçóéìïðïéçèïýí óôï php.ini.
ÁíåîÜñôçôá áðü ôï interface óôç PHP ìðïñåßôå íá áëëÜîåôå ïñéóìÝíåò ôéìÝò êáôÜ ôçí åêôÝëåóç ôùí script óáò ìÝóù ôçò ini_set(). Ï áêüëïõèïò ðßíáêáò ðñïóöÝñåé ìéá ðåñéãñáöÞ óå ðïéï åðßðåäï ìðïñåß íá ïñéóôåß/áëëá÷èåß Ýíá directive.
Ðßíáêáò 4-1. Ïñéóìüò PHP_INI_* óôáèåñþí
ÓôáèåñÜ | ÔéìÞ | Íüçìá |
---|---|---|
PHP_INI_USER | 1 | Ìðïñåß íá ïñéóôåß óå user scripts |
PHP_INI_PERDIR | 2 | Ìðïñåß íá ïñéóôåß óôá php.ini, .htaccess Þ httpd.conf |
PHP_INI_SYSTEM | 4 | Ìðïñåß íá ïñéóôåß óôá php.ini Þ httpd.conf |
PHP_INI_ALL | 7 | Ìðïñåß íá ïñéóôåß ïðïõäÞðïôå |
Ìðïñåßôå íá äåßôå ôéò ñõèìßóåéò ôùí ôéìþí óôçí Ýîïäï ôçò phpinfo(). Ìðïñåßôå åðßóçò íá ðñïóðåëÜóåôå ôéò ôéìÝò ôïõ êÜèå directives ñýèìéóçò ÷ñçóéìïðïéþíôáò ôéò ini_get() Þ get_cfg_var().
Áõôüò äåí åßíáé ðëÞñçò êáôÜëïãïò ôùí PHP directives. Ôá Directives ìðïñïýí íá âñåèïýí óôéò êáôÜëëçëåò ôïðïèåóßåò. Ãéá ðáñÜäåéãìá, ïé ðëçñïöïñßåò ãéá ôá session directives âñßóêïíôáé óôï êåöÜëáéï ãéá ôá sessions.
Ðßíáêáò 4-3. ÅðéëïãÝò Ñõèìßóåùí Ãëþóóáò êáé ¢ëëùí
¼íïìá | ÐñïåðéëïãÞ | Ìåôáâëçôü |
---|---|---|
short_open_tag | On | PHP_INI_SYSTEM|PHP_INI_PERDIR |
asp_tags | Off | PHP_INI_SYSTEM|PHP_INI_PERDIR |
precision | "14" | PHP_INI_ALL |
y2k_compliance | Off | PHP_INI_ALL |
allow_call_time_pass_reference | On | PHP_INI_SYSTEM|PHP_INI_PERDIR |
expose_php | On | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Ïñßæåé áí ç óýíôïìç ìïñöÞ (<? ?>) ôïõ open tag ôçò PHP èá åðéôñÝðåôáé. Áí èÝëåôå íá ÷ñçóéìïðïéåßôå ôçí PHP óå óõíäéáóìü ìå XML, ìðïñåßôå íá áðåíåñãïðïéÞóåôå áõôÞ ôçí åðéëïãÞ ãéá íá ÷ñçóéìïðïéåßôå ôï <?xml ?> inline. Áëëéþò, ìðïñåßôå íá ôï åêôõðþíåôå ìå ôçí PHP, ãéá ðáñÜäåéãìá: <?php echo '<?xml version="1.0"'; ?>. Åðßóçò áí åßíáé áíåíåñãïðïéçìÝíï, èá ðñÝðåé íá ÷ñçóéìïðïéåßôå ôçí ìåãÜëç ìïñöÞ ôïõ PHP open tag (<?php ?>).
Óçìåßùóç: Áõôü ôï directive åðßóçò åðéñåÜæåé ôï "óõíôïìïãñáöéêü" <?=, ôï ïðïßï åßíáé ßäéï ìå ôï <? echo. Ç ÷ñÞóç áõôþí ôùí óõíôïìåýóåùí ðñïûðïèÝôåé ôï short_open_tag íá åßíáé åíåñãïðïéçìÝíï.
ÅðéôñÝðåé ôç ÷ñÞóç ôùí ASP-like <% %> tags åðéðñüóèåôá óôá óõíçèéóìÝíá <?php ?> tags. Áõôü óõìðåñéëìâÜíåé ôçí óýíôïìç variable-value åêôýðùóç <%= $value %>. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äåßôå ôï Âãáßíïíôáò áðü ôçí HTML.
Óçìåßùóç: Ç õðïóôÞñéîç ãéá tags ôïõ óôõë ôçò ASP ðñïóôÝèçêå óôçí Ýêäïóç 3.0.4.
Ï áñéèìüò ôùí óçìáíôéêþí øçößùí (significant digits) ðïõ èá ðáñïõóéÜæåôáé óôïõò áñéèìïýò êéíçôÞò õðïäéáóôïëÞò.
ÅðéâÜëëåé year 2000 compliance (óõìâáôüôçôá) (èá Ý÷åé ðñïâëÞìáôá ìå ìç óõìâáôïýò browsers)
ÅëÝã÷åé êáôÜ ðüóïí èá õðÜñ÷åé ç éêáíüôçôá íá åðéâÜëëåôáé ôï ðÝñáóìá ìå áíáöïñÜ (by reference) ôùí ïñéóìÜôùí êáôÜ ôç êëÞóç ìéáò óõíÜñôçóçò. ÁõôÞ ç ìÝèïäïò Ý÷åé îåðåñáóôåß êáé ðéèáíüí íá ìçí õðïóôçñßæåôáé óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP/Zend. Ç ìÝèïäïò ðïõ õðïóôçñßæåôáé åßíáé íá ïñßæïíôáé ðïéá ïñßóìáôá èá ðåñíéïýíôáé by reference íá âñßóêåôáé óôïí ïñéóìü ôçò óõíÜñôçóçò. Åíèáññýíåóôå íá äïêéìÜóåôå íá áðåíåñãïðïéÞóåôå áõôÞ ôçí åðéëïãÞ þóôå íá óéãïõñåõôåßôå ðùò ôá script óáò äïõëåýïõí ãéá íá äåßôå üôé èá äïõëåýïõí êáé ìå ìåëëïíôéêÝò åêäüóåéò ôçò ãëþóóáò (èá ëáìâÜíåôå ìéá ðñïåéäïðïßçóç êÜèå öïñÜ ðïõ ôï ÷ñçóéìïðïéåßôå êáé ôï üñéóìá èá ðåñíéÝôáé by value áíôß by reference).
Äåßôå åðßóçò ôï ÅðåîÞãçóç Áíáöïñþí.
Áðïöáóßæåé áí ç PHP èá öáíåñþíåé ôï üôé åßíáé åãêáôåóôçìÝíç óôïí server (ð.÷. ðñïóèÝôïíôáò ôçí õðïãñáöÞ ôçò óôïí Web server header). Äåí áðïôåëåß ñßóêï áóöÜëåéáò ìå ïðïéïäÞðïôå ôñüðï, áëëÜ êáèéóôÜ éêáíÞ ôçí áíáãíþñéóç ôïõ áí ÷ñçóéìïðïéåßôå PHP óôïí server óáò Þ ü÷é.
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Ïñßæåé ôï ìÝãéóôï ìÝãåèïò ìíÞìçò óå bytes ôï ïðïßï åðéôñÝðåôáé íá ÷ñçóéìïðïéÞóåé Ýíá script. Áõôü âïçèÜ íá áðïöåýãåôáé ôï åíäå÷üìåíï öôù÷Ü ãñáììÝíá scripts íá ôñþíå üëç ôç äéáèÝóéìç ìíÞìç óå Ýíá server. Ãéá íá ÷ñçóéìïðïéÞóåôå áõôü ôï directive ðñÝðåé íá ôï åíåñãïðïéÞóåôå óôç óôéãìÞ ôïõ compile. ¸ôóé, ç configure ãñáììÞ èá ðåñéåß÷å: --enable-memory-limit. Óçìåéþóôå ðùò ðñÝðåé íá ôï ïñßóåôå óå -1 áí äåí èÝëåôå ïðïéïäÞðïôå üñéï ãéá ôç ìíÞìç óáò.
Äåßôå åðßóçò: max_execution_time.
Ðßíáêáò 4-5. ÅðéëïãÝò Ñõèìßóåùí ×åéñéóìïý ÄåäïìÝíùí
¼íïìá | ÐñïåðéëïãÞ | Ìåôáâëçôü |
---|---|---|
track-vars | "On" | PHP_INI_?? |
arg_separator.output | "&" | PHP_INI_ALL |
arg_separator.input | "&" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
variables_order | "EGPCS" | PHP_INI_ALL |
register_globals | "Off" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
register_argc_argv | "On" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
post_max_size | "8M" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
gpc_order | "GPC" | PHP_INI_ALL |
auto_prepend_file | "" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
auto_append_file | "" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
default_mimetype | "text/html" | PHP_INI_ALL |
default_charset | "iso-8859-1" | PHP_INI_ALL |
always_populate_raw_post_data | "0" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
allow_webdav_methods | "0" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
¼ôáí åßíáé åíåñãïðïéçìÝíç, ïé Environment, GET, POST, Cookie, êáé Server ìåôáâëçôÝò ìðïñïýí íá âñåèïýí óôá global associative arrays $_ENV, $_GET, $_POST, $_COOKIE, êáé $_SERVER.
Óçìåéþóôå ðùò áðü ôçí PHP 4.0.3, ôï track_vars åßíáé ðÜíôá åíåñãïðïéçìÝíï.
Ï äéá÷ùñéóôÞò (separator) ðïõ ÷ñçóéìïðïéåßôáé óôá URL ðïõ äçìéïõñãïýíôáé áðü ôç PHP ãéá íá îå÷ùñßæïõí ìåôáîý ôïõò ôá arguments.
Ëßóôá áðü äéá÷ùñéóôÝò(Þ) ðïõ ÷ñçóéìïðïéåß ç PHP ãéá íá ìåôöñÜóåé ôá URL åéóüäïõ óå ìåôáâëçôÝò.
Óçìåßùóç: ÊÜèå ÷áñáêôÞñáò áõôïý ôïõ directive èåùñåßôáé Ýíáò äéá÷ùñéóôÞò (separator)!
Ïñßæåé ôç óåéñÜ ôçò EGPCS (Environment, GET, POST, Cookie, Server) áíÜëõóçò ìåôáâëçôþí. Ç ðñïåðéëåãìÝíç ñýèìéóç áõôïý ôïõ directive åßíáé "EGPCS". Ïñßæïíôáò ôï óå "GP", ãéá ðáñÜäåéãìá, èá êÜíåé ôçí PHP íá áãíïÞóåé ôåëåßùò ôéò ìåôáâëçôÝò ðåñéâÜëëïíôïò (E), ôá cookies and êáé ôéò ìåôáâëçôÝò ôïõ server, êáé íá êÜíåé overwrite üóåò GET method ìåôáâëçôÝò ìå ôéò POST-method ìåôáâëçôÝò ðïõ Ý÷ïõí ôï ßäéï üíïìá.
Äåßôå åðßóçò ôï register_globals.
Ïñßæåé áí èá êáôá÷ùñçèïýí ïé EGPCS (Environment, GET, POST, Cookie, Server) ìåôáâëçôÝò óáí global ìåôáâëçôÝò. Ãéá ðáñÜäåéãìá: Áí ôï register_globals = on, ôï url http://www.example.com/test.php?id=3 èá ðáñÜîåé ôï $id. ¹, ôï $DOCUMENT_ROOT áðü ôï $_SERVER['DOCUMENT_ROOT']. Ìðïñåß íá èÝëåôå íá ôï êÜíåôå off áí äåí èÝëåôå íá ãåìßóåôå ôï global scope ôùí script óáò ìå äåäïìÝíá ôùí ÷ñçóôþí. Áðü ôçí PHP 4.2.0, áõôü ôï directive Ý÷åé ðñïåðéëïãÞ ôï off. ÐñïôéìÜôáé áíôß áõôïý, íá ðçãáßíåôå ìÝóù ôùí ÐñïêáèïñéóìÝíùí Ìåôáâëçôþí ôçò PHP, üðùò ôá superglobals: $_ENV, $_GET, $_POST, $_COOKIE, êáé $_SERVER. Ðáñáêáëïýìå äéáâÜóôå ôï êåöÜëáéï ðåñß áóöÜëåéáò êáé ôï ×ñçóéìïðïéþíôáò ôï register_globals ãéá ó÷åôéêÝò ðëçñïöïñßåò.
Ðáñáêáëïýìå óçìåéþóôå ðùò ôï register_globals äåí ìðïñåß íá ïñéóôåß óôï runtime (ini_set()). Ùóôüóï, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôï .htaccess áí ï web server óáò ôï õðïóôçñßæåé üðùò ðåñéãñÜöåôáé ðáñáðÜíù. ¸íá ðáñÜäåéãìá êáôá÷þñçóçò óôï .htaccess: php_flag register_globals on.
Óçìåßùóç: Ôï register_globals åðéñåÜæåôáé áðü ôï variables_order directive.
Ïñßæåé áí ç PHP èá äçëþóåé ôéò argv & argc ìåôáâëçôÝò (ðïõ èá ðåñéÝ÷ïõí ôéò GET ðëçñïöïñßåò).
Äåßôå åðßóçò ôï command line. Åðßóçò, áõôü ôï directive Ýãéíå äéáèÝóéìï óôçí PHP 4.0.0 êáé ðñéí áðü áõôÞ ôçí Ýêäïóç Þôáí ðÜíôá åíåñãïðïéçìÝíï.
Ïñßæåé ôï ìÝãéóôï ìÝãåèïò ôùí post äåäïìÝíùí ðïõ åðéôñÝðåôáé. ÁõôÞ ç ñýèìéóç åðßóçò åðéñåÜæåé ôï upload áñ÷åßùí. Ãéá íá åðéôñÝðåôáé upload ìåãÜëùí áñ÷åßùí, áõôÞ ç ôéìÞ ðñÝðåé íá åßíáé ìåãáëýôåñç áðü ôï upload_max_filesize.
Áí ôï üñéï ìíÞìçò åßíáé åíåñãïðïéçìÝíï áðü ôï configure script, ôï memory_limit åðßóçò åðéñåÜæåé ôï upload áñ÷åßùí. Ãåíéêþò, ôï memory_limit ðñÝðåé íá åßíáé ìåãáëýôåñï áðü ôï post_max_size.
Ïñßæåé ôç óåéñÜ ôçò áíÜëõóçò ôùí GET/POST/COOKIE ìåôáâëçôþí. Ç ðñïåðéëåãìÝíç ñýèìéóç áõôïý ôïõ directive åßíáé "GPC". Ïñßæïíôáò áõôü óå "GP", ãéá ðáñÜäåéãìá, èá êÜíåé ôçí PHP íá áãíïÞóåé åíôåëþò ôá cookies êáé íá êÜíåé overwrite üóåò GET method ìåôáâëçôÝò ìå ôéò POST-method ìåôáâëçôÝò ðïõ Ý÷ïõí ôï ßäéï üíïìá.
Óçìåßùóç: ÁõôÞ ç åðéëïãÞ äåí åßíáé äéáèÝóéìç óôçí PHP 4. ×ñçóéìïðïéÞóôå ôï variables_order áíôß áõôïý.
Ïñßæåé ôï üíïìá åíüò áñ÷åßïõ ðïõ èá ìåôáöñÜæåôáé áõôüìáôá ðñéí ôï êõñßùò áñ÷åßï. Ôï áñ÷åßï ãßíåôáé include óáí íá åß÷å êáëåóôåß ìå ôç óõíÜñôçóç include(), Ýôóé ôï include_path ÷ñçóéìïðïéåßôáé.
Ç åéäéêÞ ôéìÞ none áðåíåñãïðïéåß ôï áõôüìáôï prepend.
Ïñßæåé ôï üíïìá åíüò áñ÷åßïõ ðïõ èá ìåôáöñÜæåôáé áõôüìáôá ìåôÜ ôï êõñßùò áñ÷åßï. Ôï áñ÷åßï ãßíåôáé include óáí íá åß÷å êáëåóôåß ìå ôç óõíÜñôçóç include(), Ýôóé ôï include_path ÷ñçóéìïðïéåßôáé.
Ç åéäéêÞ ôéìÞ none áðåíåñãïðïéåß ôï áõôüìáôï prepend.
Óçìåßùóç: Áí ôï script ôåñìáôéóôåß ìå ôçí exit(), ôï auto-append äåí èá óõìâåß.
Áðü ôçí 4.0b4, ç PHP ðÜíôá âãÜæåé Ýíá character encoding óôï Content-type: header. Ãéá íá áðåíåñãïðïéÞóåôå ôçí áðïóôïëÞ ôïõ charset, áðëÜ ïñßóôå ôï íá åßíáé êåíü.
ÐÜíôá íá ãíùóôïðïéåßôáé ç ìåôáâëçôÞ $HTTP_RAW_POST_DATA.
ÅðéôñÝðåé ôï ÷åéñéóìü ôùí WebDAV http áéôÞóåùí ìÝóá áðü PHP scripts (ð.÷. PROPFIND, PROPPATCH, MOVE, COPY, êëð..) Áí èÝëåôå íá ðÜñåôå ôá post data áõôþí ôùí requests, ðñÝðåé íá ïñßóåôå ôï always_populate_raw_post_data åðßóçò.
Äåßôå åðßóçò ôá: magic_quotes_gpc, magic-quotes-runtime, êáé magic_quotes_sybase.
Ðßíáêáò 4-6. ÅðéëïãÝò Ñõèìßóåùí ãéá Paths êáé Êáôáëüãïõò
¼íïìá | ÐñïåðéëïãÞ | Ìåôáâëçôü |
---|---|---|
include_path | PHP_INCLUDE_PATH | PHP_INI_ALL |
doc_root | PHP_INCLUDE_PATH | PHP_INI_SYSTEM |
user_dir | NULL | PHP_INI_SYSTEM |
extension_dir | PHP_EXTENSION_DIR | PHP_INI_SYSTEM |
cgi.force_redirect | "1" | PHP_INI_SYSTEM |
cgi.redirect_status_env | "" | PHP_INI_SYSTEM |
fastcgi.impersonate | "0" | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Ïñßæåé ìéá ëßóôá áðü êáôÜëïãïõò üðïõ ïé require(), include() êáé fopen_with_path() óõíáñôÞóåéò øÜ÷íïõí ãéá áñ÷åßá. Ôï ó÷Þìá åßíáé óáí ôçí PATH ìåôáâëçôÞ ðåñéâÜëëïíôïò ôïõ óõóôÞìáôïò ÷ùñéóìÝíåò ìå Ýíá óýìâïëï Üíù êáé êÜôù ôåëåßáò óôï UNIX Þ åëëçíéêïý åñùôçìáôéêïý óôá Windows.
×ñçóéìïðïéþíôáò ìéá . óôï include path óáò åðéôñÝðåé relative includes áöïý õðïíïåß ôïí ôñÝ÷ùí êáôÜëïãï.
Ôï "root directory" ôçò PHP óôïí server. ×ñçóéìïðïéåßôáé ìüíï áí äåí åßíáé êåíü. Áí ç PHP ãßíåé configured ìå ôï safe mode, äåí åîõðçñåôïýíôáé áñ÷åßá Ýîù áðü áõôü ôïí êáôÜëïãï. Áí ç PHP äåí Ý÷åé ãßíåé compiled ìå FORCE_REDIRECT, ÐÑÅÐÅÉ íá ïñßóåôå ôï doc_root áí ôñÝ÷åôå ôçí PHP óáí CGI êÜôù áðü ïðïéïíäÞðïôå web server (åêôüò ôïí IIS) Ç åíáëëáêôéêÞ åðéëïãÞ åßíáé íá ÷ñçóéìïðïéÞóåôå ôçí cgi.force_redirect ñýèìéóç ðáñáêÜôù.
Ôï âáóéêü üíïìá ôïõ êáôáëüãïõ ðïõ ÷ñçóéìïðïéåßôáé óôï home directory êÜðïéïõ ÷ñÞóôç ãéá ôá PHP áñ÷åßá, ãéá ðáñÜäåéãìá public_html.
Ïñßæåé óå ðïéü êáôÜëïãï ç PHP èá øÜ÷íåé ãéá äõíáìéêÜ öïñôþóéìåò åðåêôÜóåéò (dynamically loadable extensions). Äåßôå åðßóçò ôá: enable_dl, êáé dl().
ÐïéÝò äõíáìéêÜ öïñôþóéìåò åðåêôÜóåéò íá öïñôþèïýí üôáí îåêéíÜ ç PHP.
Ôï cgi.force_redirect åßíáé áðáñáßôçôï ãéá íá ðñïóöÝñåé áóöÜëåéá üôáí ç PHP ôñÝ÷åé óáí CGI êÜôù áðü ôïõò ðåñéóóüôåñïõò web servers. Áí äåí ïñéóôåß, ç PHP ôï åíåñãïðïéåß áðü ìüíç ôçò. Ìðïñåßôå íá ôï áðåíåñãïðïéÞóåôå ÌÅ ÄÉÊÏ ÓÁÓ ÑÉÓÊÏ.
Óçìåßùóç: ×ñÞóôåò Windows: ÌÐÏÑÅÉÔÅ ìå áóöÜëåéá íá ôï áðåíåñãïðïéÞóåôå áõôü ãéá ôïí IIS, ìÜëéóôá, ÐÑÅÐÅÉ íá ôï êÜíåôå. Ãéá íá êÜíåôå ôïí OmniHTTPD Þ ôïí Xitami íá äïõëÝøïõí ÐÑÅÐÅÉ íá ôï áðåíåñãïðïéÞóåôå.
Áí ôï cgi.force_redirect åßíáé åíåñãïðïéçìÝíï, êáé äåí ôñÝ÷åôå êÜôù áðü Apache Þ Netscape (iPlanet) web servers, ÌÐÏÑÅÉ íá ÷ñåéáóôåß íá ïñßóåôå Ýíá üíïìá ìåôáâëçôÞò ðåñéâÜëëïíôïò ðïõ ç PHP èá øÜ÷íåé ãéá íá îÝñåé ðùò åßíáé åíôÜîåé íá óõíå÷ßóåé ôçí åêôÝëåóç
Óçìåßùóç: Ïñßæïíôáò áõôÞ ôç ìåôáâëçôÞ ÌÐÏÑÅÉ íá äçìéïõñãÞóåé èÝìáôá áóöÜëåéáò, ÍÁ ÎÅÑÅÔÅ ÔÉ ÊÁÍÅÔÅ ÐÑÙÔÁ.
Ôï FastCGI êÜôù áðü ôïí IIS (óå ÏÓ âáóéóìÝíá óå WINNT) õðïóôçñßæåé ôçí éêáíüôçôá íá ðáñéóôÜíåé tokens áóöÜëåéáò ôïõ êáëïýíôïò client. Áõôü åðéôñÝðåé óôïí IIS íá ïñßóåé ôï ðåñéå÷üìåíï áóöÜëåéáò êÜôù áðü ôçí ïðïßá ôñÝ÷åé ôï request. To mod_fastcgi óôïí Apache äåí õðïóôçñßæåé ðñïò ôï ðáñþí áõôü ôï ÷áñáêôçñéóôéêü (03/17/2002) Ïñßóôå ôï óå 1 áí ôñÝ÷åôå êÜôù áðü IIS. Ç ðñïåðéëïãÞ åßíáé ìçäÝí.
Ðßíáêáò 4-7. ÅðéëïãÝò Ñõèìßóåùí ãéá Upload Áñ÷åßùí
¼íïìá | ÐñïåðéëïãÞ | Ìåôáâëçôü |
---|---|---|
file_uploads | "1" | PHP_INI_SYSTEM |
upload_tmp_dir | NULL | PHP_INI_SYSTEM |
upload_max_filesize | "2M" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Ïñßæåé áí èá åðéôñáðïýí HTTP upload áñ÷åßùí. Äåßôå åðßóçò ôá upload_max_filesize, upload_tmp_dir, êáé post_max_size directives.
Ï ðñïóùñéíüò êáôÜëïãïò ðïõ ÷ñçóéìïðïéåßôáé ãéá áðïèÞêåõóç áñ÷åßùí üôáí ãßíåôáé Ýíá upload áñ÷åßïõ. ÐñÝðåé íá åßíáé writable (åããñÜøéìïò) áðü ïðïéïäÞðïôå ÷ñÞóôç ôñÝ÷åé óáí áõôüí ç PHP. Áí äåí ïñéóôåß, ç PHP èá ÷ñçóéìïðïéÞóåé ôçí ðñïåðéëïãÞ ôïõ óõóôÞìáôïò.
Ôï ìÝãéóôï ìÝãåèïò áñ÷åßï åíüò áñ÷åßïõ ðïõ èá ãßíåé upload.
Ðßíáêáò 4-8. ÅðéëïãÝò Ñõèìßóåùí ÃåíéêÜ ãéá SQL
¼íïìá | ÐñïåðéëïãÞ | Ìåôáâëçôü |
---|---|---|
sql.safe_mode | "0" | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
¼ôáí n PHP ìåôáãëùôßæåé (parses) Ýíá áñ÷åßï, áðëÜ êÜíåé Ýíá ðÝñáóìá óôï êåßìåíï ôïõ áñ÷åßïõ ìÝ÷ñé íá óõíáíôÞóåé Ýíá áðü ôá åéäéêÜ tags ðïõ ôçò ëÝíå íá áñ÷ßóåé íá ìåôáöñÜæåé ôï êåßìåíï ùò êþäéêá PHP. Ï parser (ìåôáãëùôôéóôÞò) ôüôå åêôåëåß ïëüêëçñï ôïí êþäéêá ðïõ âñßóêåé, ìÝ÷ñé íá óõíáíôÞóåé ôï åðüìåíï PHP tag êëåéóßìáôïò, ôï ïðïßï ëÝåé óôïí parser íá áñ÷ßóåé íá êÜíåé îáíÜ, áðëÜ Ýíá ðÝñáóìá óôï êåßìåíï. Áõôüò åßíáé ï ìç÷áíéóìüò ðïõ óáò åðéôñÝðåé íá ðñïóèÝôåôå PHP êþäéêá ìÝóá óå HTML: ï,ôéäÞðïôå âñßóêåôáé Ýîù áðü ôá tags ôçò PHP ìÝíåé ôåëåßùò ìüíï, åíþ ïôéäÞðïôå ìÝóá ìåôáãëùôôßæåôáé ùò êþäéêáò.
ÕðÜñ÷ïõí ôÝóóåñá óýíïëá áðü tags ðïõ ìðïñïýí íá ÷ñçóéìïðïéçèïýí ãéá íá äçëþóïõìå ôá êïììÜôéá ðïõ Ý÷ïõí êþäéêá óå PHP. Áðü áõôÜ, ìüíï äýï (<?php. . .?> and <script language="php">. . .</script>) åßíáé ðÜíôá äéáèÝóéìá. Ôá Üëëá ìðïñïýí íá åíåñãïðïéçèïýí êáé íá áðåíåñãïðïéçèïýí áðü ôï php.ini áñ÷åßï ñõèìßóåùí. Åíþ ôá short-form tags êáé ôá tags ðïõ ìïéÜæïõí ìå áõôÜ ôçò ASP ìðïñåß íá åßíáé âïëéêÜ, äåí åßíáé ôüóï portable üóï ïé ìáêñýôåñåò åêäüóåéò. Åðßóçò, áí óêïðåýåôå íá ðñïóèÝóåôå PHP êþäéêá óå XML Þ XHTML, èá ÷ñåéáóôåß íá ÷ñçóéìïðïéÞóåôå ôçí <?php. . .?> öüñìá ãéá íá ðñïóáñìïóôåß óôçí XML.
Ôá tags ðïõ õðïóôçñßæïíôáé áðü ôçí PHP åßíáé:
ÐáñÜäåéãìá 5-1. Ôñüðïé ãéá íá âãåßôå (escape) áðü ôçí HTML
|
Ï ðñþôïò ôñüðïò, <?php. . .?>, åßíáé êáé ï ðñïôéìüôåñïò, êáèþò åðéôñÝðåé ôç ÷ñÞóç ôçò PHP óå êþäéêá óõìâáôü ìå ôçí XML üðùò ç XHTML.
Ï äåýôåñïò ôñüðïò äåí åßíáé ðÜíôá äéáèÝóéìïò. Ôá óýíôïìá tags åßíáé äéáèÝóéìá ìüíï üôáí Ý÷ïõí åíåñãïðïéçèåß. Áõôü ìðïñåß íá ãßíåé ìÝóù ôçò óõíÜñôçóçò short_tags() (ìüíï óôçí PHP 3), åíåñãïðïéþíôáò ôçí åðéëïãÞ ñýèìéóçò short_open_tag óôï áñ÷åßï ñõèìßóåùí ôçò PHP, Þ êÜíïíôáò compile ôçí PHP ìå ôçí åðéëïãÞ --enable-short-tags óôï configure. Áêüìç êáé áí åßíáé åíåñãïðïéçìÝíï ùò ðñïåðéëïãÞ óôï php.ini-dist, ç ÷ñÞóç ôùí short tags äåí ðñïôéìÜôáé.
Ï ôÝôáñôïò ôñüðïò åßíáé äéáèÝóéìïò ìüíï áí ôá ASP-style tags Ý÷ïõí åíåñãïðïéçèåß ÷ñçóéìïðïéþíôáò ôçí asp_tags åðéëïãÞ ñõèìßóåùí.
Óçìåßùóç: ÕðïóôÞñéîç ãéá ôá ASP-style tags ðñïóôÝèçêå óôçí Ýêäïóç 3.0.4.
Óçìåßùóç: Ç ÷ñÞóç ôùí short tags èá ðñÝðåé íá áðïöåýãåôáé êáôÜ ôçí áíÜðôõîç åöáñìïãþí Þ âéâëéïèçêùí (libraries) ðïõ ðñïïñßæïíôáé ãéá äéáíïìÞ (redistribution), Þ åöáñìïãÞ óå PHP servers ðïõ äåí ôïõò ÷åéñßæåóôå ïé éäéïé, åðåéäç ôá short tags ìðïñåß íá ìçí õðïóôçñßæïíôáé áðü ôïí ôåëéêü server. Ãéá ìåôáöÝñóéìï (portable), êþäéêá ðïõ èá ðñïïñßæåôáé ãéá ÷ñÞóç êáé áðü Üëëïõò, âåâáéùèåßôå üôé äåí êÜíåôå ÷ñÞóç ôùí short tags.
Ôï tag êëåéóßìáôïò ãéá ôï block èá óõìðåñéëÜâåé ôï áìÝóùò åðüìåíï trailing newline áí õðÜñ÷åé. Åðßóçò, ôï tag êëåéóßìáôïò áõôüìáôá õðïäçëþíåé êáé Ýíá åñùôçìáôéêü. Äåí ÷ñåéÜæåôáé íá Ý÷åôå åñùôçìáôéêü ãéá íá ôåñìáôßóåôå ôçí ôåëåõôáßá ãñáììÞ åíüò PHP block.
Ç PHP óáò åðéôñÝðåé íá ÷ñçóéìïðïéÞóåôå äïìÝò óáí áõôÞ:
Ïé åíôïëÝò äéá÷ùñßæïíôáé ìå ôïí ßäéï ôñüðï üðùò êáé óôçí C Þ ôçí Perl - ôåñìáôßæïõìå êÜèå åíôïëÞ ìå Ýíá åñùôçìáôéêü.
Ôï tag êëåéóßìáôïò (?>) åðßóçò õðïäçëþíåé ôï ôÝëïò ìéáò Ýêöñáóçò-äçëùóçò, óõíåðþò ôá áêüëïõèá åßíáé éóïäýíáìá:
Ç PHP õðïóôçñßæåé ó÷üëéá óáí ôçò 'C', 'C++' êáé ôïõ Unix shell. Ãéá ðáñÜäåéãìá:
<?php echo "This is a test"; // This is a one-line c++ style comment /* This is a multi line comment yet another line of comment */ echo "This is yet another test"; echo "One Final Test"; # This is shell-style style comment ?> |
Ôï ó÷üëéï "ìéá ãñáììÞò" ó÷ïëéÜæåé ìüíï ìÝ÷ñé ôï ôÝëïò ìéáò ãñáììÞò Þ ôïõ ôñÝ÷ïíôïò block óôïí êþäéêá ôçò PHP, üðïéï åßíáé ðñþôï.
<h1>This is an <?php # echo "simple";?> example.</h1> <p>The header above will say 'This is an example'. |
ÐñÝðåé íá ðñïóÝ÷åôå íá ìçí åìöùëåýåôå ó÷üëéá óáí áõôÜ ôçò 'C', êÜôé ðïõ åßíáé ðéèáíü íá óõìâåß üôáí ó÷ïëéÜæåôå ìåãÜëá blocks.
Ôï ó÷üëéï ìéáò ãñáììÞò óôçí ðñáãìáôéêüôçôá ó÷ïëéÜæåé ìÝ÷ñé ôï ôÝëïò ìéáò ãñáììÞò Þ ôïõ ôñÝ÷ïíôïò block óôïí êþäéêá ôçò PHP, üðïéï åßíáé ðñþôï. Áõôü óçìáßíåé ðùò ï HTML êþäéêáò ðïõ áêïëïõèåß ôï // ?> Èá åêôõðùèåß. Ôï tag ?> îåöåýãåé áðü ôçí êáôÜóôáóç ôçò PHP êáé åðéóôñÝöåé óôçí HTML, êáé ôï // äåí ìðïñåß íá ôï åðçñåÜóåé.
Ç PHP õðïóôçñßæåé ï÷ôþ ðñùôáñ÷éêïýò ôýðïõò.
Ãéá âáèìùôïýò ôýðïõò:
Äýï óýíèåôïõò ôýðïõò:array (ðßíáêåò)
object (áíôéêåßìåíá)
Ï ôýðïò ìéáò ìåôáâëçôÞò äåí êáèïñßæåôáé óõíÞèùò áðü ôïí ðñïãñáììáôéóôÞ, áëëÜ ìÜëëïí êáèïñßæåôáé êáôÜ ôç äéáñêåéá åêôÝëåóçò áðü ôçí PHP áíÜëïãá ìå ôï ðåñéå÷üìåíï ìå ôï ïðïßï ÷ñçóéìïðïéåßôáé áõôÞ ç ìåôáâëçôÞ.
Óçìåßùóç: Áí èÝëåôå íá åëÝíîåôå ôïí ôýðï êáé ôçí ôéìÞ ìéáò óõãêåêñéìÝíçò Ýêöñáóçò, ÷ñçóéìïðïéåßóôå ôçí var_dump().
Óçìåßùóç: Áí èÝëåôå áðëÜ ìéá áíáðáñÜóôáóç ôïõ ôýðïõ, ðïõ íá ìðïñåß åýêïëá íá äéáâáóôåß ãéá ôï debugging, ÷ñçóéìïðïéåßóôå ôçí gettype(). Ãéá ôïí Ýëåã÷ï åíüò óõãêåêñéìÝíï ôýðïõ, ìçí ÷ñçóéìïðïéåßôå ôçí gettype(), áëëÜ ôéò is_typeóõíáñôÞóåéò. ÌåñéêÜ ðáñáäåßãìáôá:
<?php $bool = TRUE; // a boolean $str = "foo"; // a string $int = 12; // an integer echo gettype($bool); // prints out "boolean" echo gettype($str); // prints out "string" // If this is an integer, increment it by four if (is_int($int)) { $int += 4; } // If $bool is a string, print it out // (does not print out anything) if (is_string($bool)) { echo "String: $bool"; } ?>
Áí èÝëåôå íá áíáãêÜóåôå ìéá ìåôáâëçôÞ íá ìåôáôñáðåß óå Ýíáí óõãêåêñéìÝíï ôýðï, ìðïñåßôå åßôå íá ÷ñçóéìïðïéÞóåôå ôçí cast óôçí ìåôáâëçôÞ Þ ôçí settype() óõíÜñôçóç ðÜíù ôçò.
Óçìåéþóôå üôé ç ìåôáâëçôÞ ìðïñåß íá õðïëïãéóôåß ìå äéáöïñåôéêÝò ôéìÝò óå óõãêåêñéìÝíåò ðåñéðôþóåéò, áíÜëïãá ìå ôï ôé ôýðïõ åßíáé êÜèå öïñÜ. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äåßôå ôï êïììÜôé ó÷åôéêÜ ìå ôï Type Juggling. Åðßóçò, ßóùò óáò åíäéáöÝñåé íá äåßôå ôïõò ðßíáêåò óýãêñéóçò ôýðùí, êáèþò äåß÷íïõí ðáñáäåßãìáôá áðü óõãêñßóåéò ó÷åôéêÝò ìå äéÜöïñïõò ôýðïõò.
Áõôüò åßíáé ï åõêïëüôåñïò ôýðïò. ¸íáò boolean åêöñÜæåé ìéá áëçèéíÞ ôéìÞ. Ìðïñåß íá åßíáé åßôå TRUE åßôå FALSE.
Óçìåßùóç: Ï ôýðïò boolean åéóÞ÷èç óôçí PHP 4.
Ãéá íá êáèïñßóåôå Ýíá boolean ëåêôéêü (literal), ÷ñçóéìïðïéåßóôå åßôå ôç ëÝîç êëåéäß TRUE Þ ôçí FALSE. Êáé ïé äõï åßíáé case-insensitive.
ÓõíÞèùò ÷ñçóéìïðïéåßôå êÜðïéï åßäïò ôåëåóôÞ ï ïðïßïò åðéóôñÝöåé ìéá boolean ôéìÞ, êáé ìåôÜ ôçí ðåñíÜåé ðÜíù óå ìéá äïìÞ åëÝã÷ïõ.
Ãéá íá ìåôáôñÝøåôå ìéá ôéìÞ óå ôýðï boolean, ÷ñçóéìïðïéåßóôå åßôå ôçí (bool) Þ ôçí (boolean) ãéá cast (ìåôáôñïðÞ). ÐÜíôùò, óôéò ðåñéóóüôåñåò ðåñéðôþóåéò äåí ÷ñåéÜæåôáé íá ÷ñçóéìïðïéåßôå ôçí cast, áöïý ìéá ôéìÞ èá ìåôáôñáðåß áõôüìáôá áí ï ôåëåóôÞò, ç óõíÜñôçóç Þ ìéá äïìÞ åëÝã÷ïõ áðáéôåß ìéá ðáñÜìåôñï ôýðïõ boolean.
Äåßôå åðßóçò ôï Type Juggling.
¼ôáí ìåôáôñÝðïíôáé óå boolean, ïé áêüëïõèåò ôéìÝò åßíáé FALSE
Ç ßäéá ç boolean ãßíåôáé FALSE
o integer 0 (ìçäÝí)
ï float 0.0 (ìçäÝí)
Ýíáò array ìå êáíÝíá óôïé÷åßï
Ýíá object ìå êáíÝíá ìÝëïò
ï åéäéêüò ôýðïò NULL (óõìðåñéëáìâáíïìÝíïõ ôùí unset variables)
Ðñïåéäïðïßçóç |
Ôï -1 èåùñåßôáé TRUE, üðùò êáé ïðïéïäÞðïôå Üëëï ìç-ìçäåíéêüò (åßôå èåôéêüò åßôå áñíçôéêüò) áñéèìüò! |
<?php echo gettype((bool) ""); // bool(false) echo gettype((bool) 1); // bool(true) echo gettype((bool) -2); // bool(true) echo gettype((bool) "foo"); // bool(true) echo gettype((bool) 2.3e5); // bool(true) echo gettype((bool) array(12)); // bool(true) echo gettype((bool) array()); // bool(false) ?> |
¸íáò integer åßíáé Ýíáò áñéèìüò ôïõ óõíüëïõ Z = {..., -2, -1, 0, 1, 2, ...}.
Äåßôå åðßóçò: ÁêÝñáéïé áõèáßñåôïõ ìåãÝèïõò / GMP, Áñéèìïý êéíçôÞò õðïäéáóôïëÞò, êáé Áõèáßñåôç áêñßâåéá / BCMath
Ïé áêÝñáéïé ìðïñïýí íá êáèïñéóôïýí óôï äåêáäéêü (ìå âÜóç ôï 10), äåêáåîáäéêü (ìå âÜóç ôï 16) Þ ïêôáäéêü (ìå âÜóç ôï 8) óýóôçìá, êáé ðñïáéñåôéêÜ ìðïñåß íá ðñïóôåèåß ôï ðñüóçìï (- Þ +).
Áí ÷ñçóéìïðïéåßôå ôï ïêôáäéêü óýóôçìá, ðñÝðåé íá ãñÜöåôå ðñéí ôï áñéèìü ôï 0 (ìçäÝí), êáé áí ÷ñçóéìïðïéåßôå ôï äåêáåîáäéêü ðñÝðåé íá ãñÜöåôå ðñéí ôïí áñéèìü ôï 0x.
Áí ðñïóäéïñßóåôå Ýíáí áñéèìüò åêôüò ôùí ïñßùí ôïõ ôýðïõ integer, èá äéåñìçíåõôåß ùò float (êéíçôÞò õðïäéáóôïëÞò). Åðßóçò, áí êÜíåôå ìéá ðñÜîç ôï áðïôÝëåóìá ôçò ïðïßáò äßíåé áñéèìü ðÝñá áðü ôá üñéá ôïõ ôýðïõ integer, èá åðéóôñáöåß áñéèìüò ôýðïõ float (êéíçôÞò õðïäéáóôïëÞò).
<?php $large_number = 2147483647; var_dump($large_number); // output: int(2147483647) $large_number = 2147483648; var_dump($large_number); // output: float(2147483648) // this goes also for hexadecimal specified integers: var_dump( 0x80000000 ); // output: float(2147483648) $million = 1000000; $large_number = 50000 * $million; var_dump($large_number); // output: float(50000000000) ?> |
Ðñïåéäïðïßçóç |
Äõóôõ÷þò, õðÞñ÷å Ýíá bug óôçí PHP ìå áðïôÝëåóìá áõôü íá ìçí ëåéôïõñãåß ðáíôá óùóôÜ üôáí õðÜñ÷ïõí áñíçôéêïß áñéèìïß. Ãéá ðáñÜäåéãìá: üôáí êÜíåôå -50000 * $million, ôï áðïôÝëåóìá èá åßíáé -429496728. Óå ðåñßðôùóç âÝâáéá ðïõ êáé ïé äõï ôåëåóôÝò åßíáé èåôéêïß äåí õðÜñ÷åé ðñüâëçìá. Áõôü ëýèçêå óôçí PHP 4.1.0. |
Äåí õðÜñ÷åé ôåëåóôÞò äéáßñåóçò óôçí PHP. Ôï 1/2 ìåôáôñÝðåôáé óôïí áñéèìü float 0.5. Ìðïñåßôå íá ìåôáôñÝøåôå ôçí ôéìÞ óå áêÝñáéï íá ôï óôñïããõëïðïéÞóåôå ðñïò ôá êÜôù, Þ íá ÷ñçóéìïðïéÞóåôå ôç óõíÜñôçóç round() .
Ãéá íá ìåôáôñÝøåôå ñçôÜ ìéá ôéìÞ óå integer, ÷ñçóéìïðïéÞóôå åßôå ôï (int) åßôå ôï (integer) ãéá ôç ìåôáôñïðÞ (cast). ÐÜíôùò, óôéò ðåñéóóüôåñåò ðåñéðôþóåéò äåí ÷ñåéÜæåôáé íá ÷ñçóéìïðïéÞóåôå ôçí cast, áöïý ç ôéìÞ èá ìåôáôñáðåß áõôüìáôá áí Ýíáò ôåëåóôÞò, ìéá óõíÜñôçóç Þ ìéá äïìÞ åëÝã÷ïõ áðáéôåß ìéá ðáñÜìåôñï ôýðïõ integer . Ìðïñåßôå åðßóçò íá ìåôáôñÝøåôå ìéá ôéìÞ óå áêÝñáéï ìÝóá óôç óõíÜñôçóç intval().
Äåßôå åðßóçò type-juggling.
¼ôáí ãßíåôáé ìåôáôñïðÞ áðü áñéèìïý êéíçôÞò õðïäéáóôïëÞò óå áêÝñáéï, ï áñéèìüò èá óôñïããõëåõôåß ðñïò ôï ìçäÝí.
Áí ï áñéèìüò êéíçôÞò õðïäéáóôïëÞò åßíáé åêôüò ôùí ïñßùí ôïõ áêåñáßïõ (óõíÞèùò +/- 2.15e+9 = 2^31), ôï áðïôÝëåóìá åßíáé áðñïóäéüñéóôï, áöïý ï áñéèìüò êéíçôÞò õðïäéáóôïëÞò äåí Ý÷åé áñêåôÞ áêñßâåéá ãéá íá äþóåé Ýíá áêñéâÝò áêÝñáéï áðïôÝëåóìá. ÊáìéÜ ðñïåéäïðïßçóç, ïýôå êÜðïéá Üëëç õðåíèýìéóç ãßíåôáé óå ôÝôïéåò ðåñéðôþóåéò!
Ðñïåéäïðïßçóç |
ÐïôÝ ìçí áëëÜæåôå ôïí ôýðï ìéáò ðáñÜóôáóçò óå integer, áöïý áõôü ìðïñåß ìåñéêÝò öïñÝò íá ïäçãÞóåé óå ìç áíáìåíüìåíá áðïôåëÝóìáôá. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò äåßôå ó÷åôéêÜ ìå ôéòðñïåéäïðïéÞóåéò ãéá ôçí áêñßâåéá áñéèìþí êéíçôÞò õðïäéáóôïëÞò. |
Ðñïóï÷Þ |
Ï ôñüðïò ìå ôïí ïðïßï ãßíåôáé ç ìåôáôñïðÞ óå áêÝñáéï äåí åßíáé êáèïñéóìÝíïò ãéá Üëëïõò ôýðïõò. Ðñïò ôï ðáñüí, ç ìåôáôñïðÞ ãßíåôáé èåùñþíôáò üôé ç ôéìÞ ðñþôá ìåôáôñÝðåôáé óå boolean. ÐÜíôùò, ìçí âáóßæåóôå óå áõôüí ôïí ôñüðï, áöïý ìðïñåß íá áëëÜîåé ÷ùñßò ðñïåéäïðïßçóç. |
Áñéèìïß êéíçôÞò õðïäéáóôïëÞò (óõìâïëßæïíôáé êáé ùò "floats", "doubles" or "real numbers") ìðïñïýí íá ðñïóäéïñéóôïýí ÷ñçóéìïðïéþíôáò ïðïéïíäÞðïôå áðü ôïõò áêüëïõèïõò ôñüðïõò óýíôáîçò:
Formally:LNUM [0-9]+ DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? {LNUM}) |
Áêñßâåéá áñéèìþí êéíçôÞò õðïäéáóôïëÞò |
Óõíçèßæåôáé óå áðëÝò äåêáäéêÝò ðáñáóôÜóåéò üðùò 0.1 Þ 0.7 íá ìçí åßíáé åöéêôÞ ç ìåôáôñïðÞ ôïõò óå åóùôåñéêÞ äõáäéêÞ áíôéóôïß÷éóç ÷ùñßò Ýíá ìéêñü ÷Üóéìï óå áêñßâåéá. Áõôü ìðïñåß íá ïäçãÞóåé óå äéöïñïýìåíá áðïôåëÝóìáôá: ãéá ðáñÜäåéãìá, ç floor((0.1+0.7)*10) óõíÞèùò åðéóôñÝöåé 7 óå áíôßèåóç ìå ôï áíáìåíüìåíï 8 áöïý ôï áðïôÝëåóìá ôçò åóùôåñéêÞò áíáðáñÜóôáóçò åßíáé êÜôé óáí 7.9999999999.... Áõôü ó÷åôßæåôáé ìå ôï ãåãïíüò üôé åßíáé áäýíáôï íá åêöñÜóïõìå áêñéâþò ìåñéêÝò ðáñáóôÜóåéò óå äåêáäéêÞ ìïñöÞ ìå Ýíáí ðåðåñáóìÝíï áñéèìü øçößùí. Ãéá ðáñÜäåéãìá, ôï 1/3 óôç äåêáäéêÞ ìïñöÞ ãßíåôáé 0.3333333. . .. Óõíåðþò ìçí åìðéóôåýåóôå ðïôÝ áðïôåëÝóìáôá áñéèìþí êéíçôÞò õðïäéáóôïëÞò ìÝ÷ñé ôï ôåëåõôáßï øçößï êáé ðïôÝ ìç óõãêñßíåôáé ãéá éóüôçôá áñéèìïýò êéíçôÞò õðïäéáóôïëÞò. Áí èÝëåôå ðñáãìáôéêÜ ìåãáëýôåñç áêñßâåéá, èá ðñÝðåé íá ÷ñçóéìïðïéåßôå ôéò óõíáñôÞóåéò áõèáßñåôçò ìáèçìáôéêÞò áêñßâåéáò Þ ôç óõíÜñôçóç gmp . |
Ãéá ðåñéóóüôåñò ðëçñïöïñßåò ó÷åôéêÜ ìå ôï ðüôå êáé ðþò ôá strings ìåôáôñÝðïíôáé óå áñéèìïýò êéíçôÞò õðïäéáóôïëÞò, äåßôå ôï ôìÞìá ìå ôïí ôßôëï ÌåôáôñïðÞ ôùí strings óå áñéèìïýò. Ãéá ôéìÝò Üëëùí ôýðùí, ç ìåôáôñïðÞ åßíáé ç ßäéá ìå áõôÞ ðïõ èá åß÷å ç ôéìÞ áí ìåôáôñåðüôáí ðñþôá óå áêÝñáéï êáé ìåôÜ óå áñéèìü êéíçôÞò õðïäéáóôïëÞò. Äåßôå ôï ôìÞìá ÌåôáôñÝðïíôáò óå áêÝñáéï ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
¸íá string åßíáé ìéá óåéñÜ ÷áñáêôÞñùí. Óôçí PHP, Ýíáò ÷áñáêôÞñáò åßáíé ôï ßäéï ìå Ýíá byte, äçëáäÞ, õðÜñ÷ïõí áêñéâþò 256 äéáöïñåôéêïß ðéèáíïß ÷áñáêôÞñåò. Áõôü åðßóçò óçìáßíåé üôé ç PHP äåí õðïóôçñßæåé Unicode. Äåßôå ôçí utf8_encode() êáé ôçí utf8_decode() ó÷åôéêÜ ìå õðïóôÞñéîç Unicode.
Óçìåßùóç: Äåí õðÜñ÷åé ðñüâëçìá ãéá Ýíá string íá ãßíåé ðïëý ìåãÜëï. Äåí õðÜñ÷åé ðñáêôéêÜ êÜðïéï üñéï ãéá ôï ìÝãåèïò ôùí strings ðïõ íá åðéâÜëëåé ç PHP, óõíåðþò äåí õðÜñ÷åé ëüãïò íá áíçóõ÷åßôå ãéá ìåãÜëá strings.
¸íá ëåêôéêü string ìðïñåß íá ðñïóäéïñéóôåß ìå ôñåéò äéáöïñåôéêïýò ôñüðïõò.
Ï åõêïëüôåñïò ôñüðïò ãéá íá ïñßóåôå Ýíá áðëü string åßíáé íá ôï âÜëåôå ìÝóá óå ìïíÜ åéóáãùãéêÜ (äçëáäÞ óôïí ÷áñáêôÞñá ').
Ãéá íá ïñßóåôå Ýíá áðëü åéóáãùãéêü, èá ÷ñåéáóôåß íá ðñïóèÝóåôå Ýíá backslash (\), üðùò êáé óå ðïëëÝò Üëëåò ãëþóóåò. Áí ôï backslash ðñÝðåé íá åìöáíéóôåß ðñéí áðü Ýíá áðëü åéóáãùãéêü Þ óôï ôÝëïò ôïõ string, èá ÷ñåéáóôåß íá ôï äéðëáóéÜóåôå. Óçìåéþóôå üôé áí ðñïóðáèÞóåôå íá áðïöýãåôå (escape) ïðïéïíäÞðïôå Üëëï ÷áñáêôÞñá, ôï backslash èá ôõðùèåß! ÓõíÞèùò äåí õðÜñ÷åé áíÜãêç íá èÝëïõìå íá áðïöýãïõìå (escape) ôçí åìöÜíéóç ôïõ ßäéïõ ôïõ backslash.
Óçìåßùóç: Óôçí PHP 3, üôáí óõìâáßíåé áõôü èá åìöáíéóôåß ìéá ðñïåéäïðïßçóç óôï åðßðåäï E_NOTICE .
Óçìåßùóç: Óå áíôßèåóç ìå ôéò äýï Üëëåò óõíôÜîåéò, ïé ìåôáâëçôÝò êáé ïé áêïëïõèßåò áðü escape ãéá åéäéêïýò ÷áñáêôÞñåò äåí èá åðåêôáèåß üôáí åìöáíßæïíôáé óå strings ðïõ ïñßæïíôáé áðü áðëÜ åéóáãùãéêÜ.
<?php echo 'this is a simple string'; echo 'You can also have embedded newlines in strings this way as it is okay to do'; // Outputs: Arnold once said: "I'll be back" echo 'Arnold once said: "I\'ll be back"'; // Outputs: You deleted C:\*.*? echo 'You deleted C:\\*.*?'; // Outputs: You deleted C:\*.*? echo 'You deleted C:\*.*?'; // Outputs: This will not expand: \n a newline echo 'This will not expand: \n a newline'; // Outputs: Variables do not $expand $either echo 'Variables do not $expand $either'; ?> |
Áí ôï string ðåñéêëåßåôáé óå äéðëÜ åéóáãùãéêÜ ("), ç PHP êáôáëáâáßíåé ðåñéóóüôåñåò áêïëïõèßåò áðü escape (escape sequences) ãéá åéäéêïýò ÷áñáêôÞñåò:
Ðßíáêáò 6-1. ×áñáêôÞñåò ðïõ åîáéñïýíôáé (Escaped characters)
sequence | meaning |
---|---|
\n | linefeed (LF or 0x0A (10) in ASCII) |
\r | carriage return (CR or 0x0D (13) in ASCII) |
\t | horizontal tab (HT or 0x09 (9) in ASCII) |
\\ | backslash |
\$ | dollar sign |
\" | double-quote |
\[0-7]{1,3} | ç áêïëïõèßá ôùí ÷áñáêôÞñùí ðïõ ôáéñéÜæïõí óôçí êáíïíéêÞ Ýêöñáóç åßíáé Ýíáò ÷áñáêôÞñáò óôï ï÷ôáäéêü óýóôçìá |
\x[0-9A-Fa-f]{1,2} | ç áêïëïõèßá ôùí ÷áñáêôÞñùí ðïõ ôáéñéÜæïõí óôçí êáíïíéêÞ Ýêöñáóç åßíáé Ýíáò ÷áñáêôÞñáò óôï äåêáåîáäéêü óýóôçìá |
ÅðáíáëáìâÜíïõìå üôé áí ðñïóðáèÞóåôå íá áðïöýãåôå (escape) ïðïéïäÞðïôå Üëëï ÷áñáêôÞñá, ôï backslash èá ôõðùèåß!
ÁëëÜ ôï ðéï óçìáíôéêü ÷áñáêôçñéóôéêü ôùí strings ðïõ ïñßæïíôáé óå äéðëÜ åéóáãùãéêÜ åßíáé ôï ãåãïíüò üôé ôá ïíüìáôá ôùí ìåôáâëçôþí èá åðåêôáèïýí. Äåßôå ôï string parsing ãéá ëåðôïìÝñåéåò.
¸íáò Üëëïò ôñüðïò ãéá íá ïñßóïõìå strings åßíáé ÷ñçóéìïðïéþíôáò ôç óýíôáîç heredoc ("<<<"). Èá ðñÝðåé íá ðñïóèÝóïõìå Ýíáí identifier ìåôÜ ôá <<<, óôç óõíÝ÷åéá ôï string, êáé ìåôÜ ôïí ßäéï identifier ãéá íá êëåßóïõìå ôçí áíáöïñÜ.
Ï identifier êëåéóßìáôïò ðñÝðåé íá áñ÷ßæåé óôçí ðñþôç óôÞëç ôçò ãñáììÞò. Åðßóçò, ï identifier ðïõ ÷ñçóéìïðïéåßôáé ðñÝðåé íá áêïëïõèåß ôïõò ßäéïõò êáíüíåò ïíïìáôïëïãßáò üðùò êáé ïðïéïäÞðïôå Üëëï label óôçí PHP: ðñÝðåé íá ðåñéÝ÷åé ìüíï áëöáñéèìçôéêïýò ÷áñáêôÞñåò êáé underscores, êáé ðñÝðåé íá áñ÷ßæåé ìå Ýíá ìç áñéèìçôéêü ÷áñáêôÞñá Þ underscore.
Ðñïåéäïðïßçóç |
Åßíáé ðïëý óçìáíôéêü íá óçìåéþóïõìå üôé ç ãñáììÞ ìå ôïí identifier êëåéóßìáôïò äåí ðåñéÝ÷åé Üëëïõò ÷áñáêôÞñåò, åêôüò ßóùò áðü Ýíá åëëçíéêü åñùôçìáôéêü (;). Áõôü óçìáßíåé éäéáßôåñá üôé ï identifier ìðïñåß íá ìçí âñßóêåôáé óå åóï÷Þ (quote), êáé ìðïñåß íá ìçí õðÜñ÷ïõí spaces Þ tabs ìåôÜ Þ ðñéí ôï åëëçíéêü åñùôçìáôéêü. Åßíáé åðßóçò óçìáíôéêü íá óõíåéäçôïðïéÞóåôå üôé ï ðñþôïò ÷áñáêôÞñáò ðñéí ôïí identifier êëåéóßìáôïò ðñÝðåé íá åßíáé ìéá êáéíïýñéá ãñáììÞ (newline) üðùò áõôÞ ïñßæåôáé áðü ôï ëåéôïõñãéêü óáò óýóôçìá. Áõôü åßíáé ôï \r óôï Macintosh ãéá ðáñÜäåéãìá. Áí áõôüò ï êáíüíáò äåí ôçñåßôáé êáé ï identifier êëåéóßìáôïò äåí åßíáé "îåêÜèáñïò" ôüôå äåí èåùñåßôáé üôé åßíáé identifier êëåéóßìáôïò êáé ç PHP èá óõíå÷ßóåé íá øÜ÷íåé ãéá Ýíáí ôÝôïéï. Áí ó'áõôÞ ôçí ðåñßðôùóç Ýíáò êáôÜëëçëïò identifier êëåéóßìáôïò äåí âñåèåß ôüôå Ýíá parse error èá åìöáíéóôåß ìå ôïí áñéèìü ôçò ãñáììÞò ðïõ ôåëåéþíåé ôï script. |
Ôï Heredoc text óõìðåñéöÝñåôáé áêñéâþò üðùò ôï double-quoted string, ÷ùñßò üìùò ôá double-quotes. Áõôü óçìáßíåé ðùò äåí ÷ñåéÜæåôáé íá ðñïóðáèåßôå íá êÜíåôå escape quotes óôá Ýããñáöá óáò åäþ, áëëÜ ìðïñåßôå íá ÷ñçóéìïðïéåßôå ôïõò êþäéêåò ãéá escape ðïõ áíáöÝñèçêáí ðáñáðÜíù. Ïé ìåôáâëçôÝò åðåêôåßíïíôáé, áëëÜ ç ßäéá ðñïóï÷Þ ðñÝðåé íá äßíåôáé üôáí åêöñÜæïõìå óýíèåôåò ìåôáâëçôÝò ìÝóá óå Ýíá ôÝôïéï Ýããñáöï üðùò êáé ìå ôá strings.
ÐáñÜäåéãìá 6-2. ÐáñÜäåéãìá Heredoc string quoting
|
Óçìåßùóç: Ç õðïóôÞñéîç Heredoc ðñïóôÝèçêå óôçí PHP 4.
¼ôáí Ýíá string ïñßæåôáé óå double quotes Þ ìå heredoc, ïé ìåôáâëçôÝò ìåôáãëùôôßæïíôáé ìÝóá ó'áõôü.
ÕðÜñ÷ïõí äõï ôñüðïé óýíôáîçò, ï áðëüò êáé ï óýíèåôïò . Ï áðëüò ôñüðïò óýíôáîçò åßíáé ï ðéï êïéíüò êáé âïëéêüò, ðáñÝ÷åé Ýíáí ôñüðï ãéá ìåôáãëþôôéóç ìåôáâëçôÞò, ìéáò ôéìÞò åíüò array, Þ ìéá éäéüôçôáò áíôéêåéìÝíïõ.
Ï óýíèåôïò ôñüðïò óýíôáîçò åéóÞ÷èç óôçí PHP 4, êáé ìðïñåß íá áíáãíùñéóôåß áðü ôá curly braces (Üãêéóôñá) ðïõ ðåñéâÜëïõí ôçí Ýêöñáóç.
Áí ôï óýìâïëï ôïõ äïëáñßïõ ($) åìöáíéóôåß, ï parser (ìåôáãëùôôéóôÞò) èá ðÜñåé üóï ðéï ðïëëÜ tokens ìðïñåß ãéá íá ó÷çìáôßóåé Ýíá Ýãêõñï üíïìá ìåôáâëçôÞò. ÂÜëôå ôï üíïìá ôçò ìåôáâëçôÞò óå curly braces áí èÝëåôå íá êáèïñßóåôå ñçôÜ ôï ôÝëïò ôïõ ïíüìáôïò.
<?php $beer = 'Heineken'; echo "$beer's taste is great"; // works, "'" is an invalid character for varnames echo "He drank some $beers"; // won't work, 's' is a valid character for varnames echo "He drank some ${beer}s"; // works echo "He drank some {$beer}s"; // works ?> |
Ïìïéþò, ìðïñåßôå íá Ý÷åôå Ýíá array index Þ ìßá éäéüôçôá áíôéêåéìÝíïõ ãéá ìåôáãëþôôéóç. Óôá åõñåôÞñéá ðéíÜêùí, ç áãêýëç êëåéóßìáôïò (]) ïñßæåé ôï ôÝëïò ôïõ åõñåôçñßïõ. Ãéá ôéò éäéüôçôåò áíôéêåéìÝíùí ïé ßäéïé êáíüíåò åöáñìüæïíôáé üðùò êáé óôéò áðëÝò ìåôáâëçôÝò, åíþ ìå ôéò éäéüôçôåò áíôéêåéìÝíùí äåí õðÜñ÷åé ôÝôïéï trick üðùò áõôü ìå ôéò ìåôáâëçôÝò.
<?php // These examples are specific to using arrays inside of strings. // When outside of a string, always quote your array string keys // and do not use {braces} when outside of strings either. // Let's show all errors error_reporting(E_ALL); $fruits = array('strawberry' => 'red', 'banana' => 'yellow'); // Works but note that this works differently outside string-quotes echo "A banana is $fruits[banana]."; // Works echo "A banana is {$fruits['banana']}."; // Works but PHP looks for a constant named banana first // as described below. echo "A banana is {$fruits[banana]}."; // Won't work, use braces. This results in a parse error. echo "A banana is $fruits['banana']."; // Works echo "A banana is " . $fruits['banana'] . "."; // Works echo "This square is $square->width meters broad."; // Won't work. For a solution, see the complex syntax. echo "This square is $square->width00 centimeters broad."; ?> |
Ãéá êÜôé ðéï ðïëýðëïêï, èá ðñÝðåé íá ÷ñçóéìïðïéåßôå ôç óýíèåôç óýíôáîç.
Ç óýíôáîç áõôÞ äåí êáëåßôáé óýíèåôç åðåéäÞ åßíáé ç ßäéá óýíèåôç, áëëÜ åðåéäÞ ìðïñåßôå íá óõìðåñéëÜâåôå óýíèåôåò åêöñÜóåéò ìå áõôüí ôïí ôñüðï.
Óôçí ðñáãìáôéêüôçôá, ìðïñåßôå íá óõìðåñéëÜâåôå ïðïéáäÞðïôå ôéìÞ õðÜñ÷åé óôï namespace ôùí strings ìå áõôÞ ôç óýíôáîç. ÁðëÜ ãñÜöåôå ôçí Ýêöñáóç ìå ôïí ßäéï ôñüðï ðïõ èá ôç ãñÜöáôå Ýîù áðü ôï string, êáé óôç óõíÝ÷åéá íá ôçí óõìðåñéëÜâåôå óôá { êáé }. Áöïý äåí ìðïñåßôå íá êÜíåôå escape óôï '{', áõôÞ ç óýíôáîç èá áíáãíùñßæåôáé ìüíï üôáí ôï $ áêïëïõèåß áìÝóùò ôï {. (×ñçóéìïðïéåßóôå ôï "{\$" Þ ôï "\{$" ãéá íá ðÜñåôå ôï ëåêôéêü "{$"). ÌåñéêÜ ðáñáäåßãìáôá ãéá íá ôï êÜíïõí ðéï îåêÜèáñï:
<?php // Let's show all errors error_reporting(E_ALL); $great = 'fantastic'; // Won't work, outputs: This is { fantastic} echo "This is { $great}"; // Works, outputs: This is fantastic echo "This is {$great}"; echo "This is ${great}"; // Works echo "This square is {$square->width}00 centimeters broad."; // Works echo "This works: {$arr[4][3]}"; // This is wrong for the same reason as $foo[bar] is wrong // outside a string. In otherwords, it will still work but // because PHP first looks for a constant named foo, it will // throw an error of level E_NOTICE (undefined constant). echo "This is wrong: {$arr[foo][3]}"; // Works. When using multi-dimensional arrays, always use // braces around arrays when inside of strings echo "This works: {$arr['foo'][3]}"; // Works. echo "This works: " . $arr['foo'][3]; echo "You can even write {$obj->values[3]->name}"; echo "This is the value of the var named $name: {${$name}}"; ?> |
Ïé ÷áñáêôÞñåò ìÝóá óå strings ìðïñïýí íá ðñïóðåëáóôïýí ïñßæïíôáò ôï zero-based offset ôïõ åðéèõìçôïý ÷áñáêôÞñá ìåôÜ ôï string óå curly braces.
Óçìåßùóç: Ãéá ðñïò ôá ðßóù óõìâáôüôçôá, ìðïñåßôå áêüìç íá ÷ñçóéìïðïéåßôå array-braces ãéá ôïí ßäéï óêïðü. ÐÜíôùò, áõôÞ ç óýíôáîç äåí óõíßóôáôáé óôçí PHP 4.
Ôá strings ìðïñïýí íá óõííåíùèïýí ÷ñçóéìïðïéþíôáò ôïí ôåëåóôÞ '.' (ôåëåßá). Óçìåéþóôå üôé ï '+' (óõí) ôåëåóôÞò äå èá äïõëÝøåé ó'áõôÞ ôçí ðåñßðôùóç. Ðáñáêáëþ äåßôå ôï ÔåëåóôÝò ãéá Strings ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
ÕðÜñ÷ïõí ðïëëÝò ÷ñÞóéìåò óõíáñôÞóåéò ãéá áëëáãÝò óôá strings.
Äåßôå ôï ôìÞìá ãéá óõíáñôÞóåéò ôùí strings ãéá ãåíéêÝò óõíáñôÞóåéò, ôéò óõíáñôÞóåéò êáíïíéêþí åêöñÜóåùí ãéá ðñï÷ùñçìÝíç áíáæÞôçóç&áíôéêáôÜóôáóç (óå äõï åêäüóåéò: Perl êáé POSIX extended).
ÕðÜñ÷ïõí åðßóçò óõíáñôÞóåéò ãéá URL-strings, êáé óõíáñôÞóåéò ãéá êñõðôïãñÜöçóç/áðïêñõðôïãñÜöçóç strings (mcrypt êáé mhash).
ÔÝëïò, áí áêüìç äåí âñÞêáôå áõôü ðïõ øÜ÷íáôå, äåßôå åðßóçò ôéò óõíáñôÞóåéò ãéá ôýðïõò ÷áñáêôÞñùí.
Ìðïñåßôå íá ìåôáôñÝøåôå ìéá ôéìÞ óå string ÷ñçóéìïðïéþíôáò ôçí (string) cast (ìåáôñïðÞ), Þ ôç óõíÜñôçóç strval(). Ç ìåôñáôïðÞ óå String ãßíåôáé áõôüìáôá ãéá óáò óôçí åìâÝëåéá ôçò Ýêöñáóçò üôáí áðáéôåßôáé Ýíá string. Áõôü óõìâáßíåé üôáí ÷ñçóéìïðïéåßôå ôéò echo() Þ print() óõíáñôÞóåéò, Þ üôáí óõãêñßíåôå ìéá ìåôáâëçôÞ ôéìÞ ìå Ýíá string. ÄéáâÜóôå óôï manual ôá ôìÞìáôá ó÷åôéêÜ ìå Ôýðïõò êáé Type Juggling ãéá íá êáôáëÜâåôå êáëýôåñá. Äåßôå åðßóçò settype().
Ìéá boolean TRUE ôéìÞ ìåôáôñÝðåôáé óôï string "1", åíþ ç FALSE ôéìÞ áíáðáñßóôáôáé áðü ôï "" (êåíü string). Ì'áõôüí ôïí ôñüðï ìðïñåßôå íá ìåôáôñÝøåôå ôéò ôéìÝò áðü boolean óå string êáé áíôéóôñüöùò.
¸íáò integer Þ Ýíáò áñéèìüò êéíçôÞò õðïäéáóôïëÞò (float) üôáí ìåôáôñÝðåôáé string áíáðáñßóôáôáé áðü ôïí áñéèìü ìå ôá øçößá ôïõ (óõìðåñéëáìâÜíåôáé ôï ìÝñïò ôïõ åêèÝôç ãéá ôïõò áñéèìïýò êéíçôÞò õðïäéáóôïëÞò).
Ïé Arrays ìåôáôñÝðïíôáé ðÜíôá óôï string "Array", Ýôóé äåí ìðïñåßôå íá åìöáíßóåôå ôï ðåñéå÷üìåíï åíüò array ìå ôçí echo() Þ ôçí print() ãéá íá äåßôå ôé õðÜñ÷åé ìÝóá ó'áõôïýò. Ãéá íá äåßôå Ýíá óôïé÷åßï, èá êÜíåôå êÜôé üðùò echo $arr['foo']. Äåßôå ðáñáêÜôù ãéá tips ó÷åôéêÜ ìå ôçí åìöÜíéóç ïëüêëçñïõ ôïõ ðåñéå÷ïìÝíïõ.
Ôá Objects ìåôáôñÝðïíôáé ðÜíôá óôï string "Object". Áí èÝëåôå íá åêôõðþóåôå ôç ôéìÞ åíüò ìÝëïõò ôçò ìåôáâëçôÞò åíüò object ãéá ëüãïõò debugging, äéáâÜóôå ôéò ðáñáêÜôù ðáñáãñÜöïõò. Áí èÝëåôå íá âñåßôå ôï üíïìá ôçò êëÜóçò ôçò ïðïßáò Ýíá object åßíáé óôéãìéüôõðï (instance), ÷ñçóéìïðïéåßóôå ôçí get_class().
Ôá Resources ðÜíôá ìåôáôñÝðïíôáé óå strings ìå ôç äïìÞ "Resource id #1" üðïõ ôï 1 åßíáé ï ìïíáäéêüò áñéèìüò ôïõ resource ðïõ áíáôßèåôáé áðü ôçí PHP êáôÜ ôç äéÜñêåéá ôçò åêôÝëåóçò. Áí èÝëåôå íá ðÜñåôå ôïí ôýðï ôïõ resource, ÷ñçóéìïðïéåßóôå ôçí get_resource_type().
Ôï NULL ìåôáôñÝðåôáé ðÜíôá óå êåíü string.
¼ðùò ìðïñåßôå íá äåßôå ðáñáðÜíù, ç åêôýðùóç ôùí arrays, ôùí objects Þ ôùí resources äåí óáò ðáñÝ÷åé ÷ñÞóéìåò ðëçñïöïñßåò ó÷åôéêÜ ôéò ßäéåò ôéò ôéìÝò. Äåßôå ôéò óõíáñôÞóåéò print_r() êáé var_dump() ãéá êáëýôåñïõò ôñüðïõò åìöÜíéóçò ôùí ôéìþí ãéá ôï debugging.
Ìðïñåßôå åðßóçò íá ìåôáôñÝøåôå ôéò ôéìÝò ôçò PHP óå strings êáé íá ôéò áðïèçêåýóåôå ìüíéìá. ÁõôÞ ç ìÝèïäïò ïíïìÜæåôáé serialization, êáé ìðïñåß íá ãßíåé ìå ôç óõíÜñôçóç serialize(). Ìðïñåßôå åðßóçò íá êÜíåôå serialize ôéò PHP values óå XML äïìÝò, áí Ý÷åôå ðñïóèÝóåé õðïóôÞñéîç ãéá WDDX êáôÜ ôç äéÜñêåéá ôïõ setup ôçò PHP.
¼ôáí Ýíá string õðïëïãßæåôáé óáí áñéèìçôéêÞ ôéìÞ, ç ôéìÞ ðïõ ðñïêýðôåé êáé ï ôýðïò ôçò ïñßæïíôáé ùò áêïëïýèùò.
Ôï string èá õðïëïãéóôåß ùò float áí ðåñéÝ÷åé ïðïéïäÞðïôå áðü ôïõò ÷áñáêôÞñåò '.', 'e', or 'E'. ÄéáöïñåôéêÜ, èá õðïëïãéóôåß ùò áêÝñáéïò.
Ç ôéìÞ äßíåôáé áðü ôï áñ÷éêü ìÝñïò ôïõ string. Áí ôï string áñ÷ßæåé ìå Ýíá Ýãêõñï áñéèìçôéêü äåäïìÝíï, áõôÞ èá åßíáé êáé ç ôéìÞ ðïõ èá ÷ñçóéìïðïéçèåß. ÄéáöïñåôéêÜ, ç ôéìÞ èá åßíáé 0 (ìçäÝí). Ôá Ýãêõñá áñéèìçôéêÜ äåäïìÝíá åßíáé Ýíá ðñïáéñåôéêü óýìâïëï, áêïëïõèïýìåíï áðü Ýíá Þ ðåñéóóüôåñá øçößá (ðñïáéñåôéêÜ ðåñéëáìâÜíïõí Ýíá äåêáäéêü óçìåßï), áêïëïõèïýìåíï áðü Ýíá ðñïáéñåôéêü åêèåôéêü. Ôï åêèåôéêü åßíáé ôï 'e' Þ ôï 'E' áêïëïõèïýìåíï áðü Ýíá Þ ðåñéóóüôåñá øçößá.
<?php $foo = 1 + "10.5"; // $foo is float (11.5) $foo = 1 + "-1.3e3"; // $foo is float (-1299) $foo = 1 + "bob-1.3e3"; // $foo is integer (1) $foo = 1 + "bob3"; // $foo is integer (1) $foo = 1 + "10 Small Pigs"; // $foo is integer (11) $foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2) $foo = "10.0 pigs " + 1; // $foo is float (11) $foo = "10.0 pigs " + 1.0; // $foo is float (11) ?> |
Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå áõôÞ ôç ìåôáôñïðÞ, äåßôå ôï manual ôïõ Unix óôç óåëßäá ãéá strtod(3).
Áí èÝëåôå íá åëÝíîåôå êÜðïéï áðü ôá ðáñáäåßãìáôá ó'áõôü ôï ôìÞìá, ìðïñåßôå íá êÜíåôå cut êáé paste óôá ðáñáäåßãìáôá êáé íá åéóÜãåôå ôçí áêüëïõèç ãñáììÞ ãéá íá äåßôå ìüíïé óáò ôé óõìâáßíåé:
Ìçí ðåñéìÝíåôå íá ðÜñåôå ôïí êþäéêá áðü Ýíáí ÷áñáêôÞñá áðëÜ ìåôáôñÝðïíôáò ôïí óå áêÝñáéï (üðùò èá êÜíáôå óôç C ãéá ðáñÜäåéãìá). ×ñçóéìïðïéÞóôå ôéò óõíáñôÞóåéò ord() êáé chr() ãéá ìåôáôñïðÝò áíÜìåóá óå charcodes êáé characters.
¸íáò array óôçí PHP åßíáé óôçí ðñáãìáôéêüôçôá Ýíáò ôáîéíïìçìÝíïò ÷Üñôçò (map). ¸íáò ÷Üñôçò åßíáé Ýíáò ôýðïò ðïõ áíôéóôïé÷åß ôéò ôéìÝò óå êëåéäéÜ. Áõôüò ï ôýðïò Ý÷åé âåëôéóôïðïéçèåß ìå ðïëëïýò ôñüðïõò, Ýôóé þóôå íá ìðïñåßôå íá ôïí ÷ñçóéìïðïéÞóåôå óáí ðñáãìáôéêü array, Þ ùò ëßóôá (vector), hashtable (ôï ïðïßï åßíáé ìéá õëïðïßçóç åíüò map), åõñåôÞñéï, óõëëïãÞ, óôïßâá, ïõñÜ êáé ðéèáíþò êáé Üëëá. ÅðåéäÞ ìðïñåßôå íá Ý÷åôå êáé Üëëïí PHP-array ùò ôéìÞ, ìðïñåßôå åðßóçò ó÷åôéêÜ åýêïëá íá ðñïóïìïéþóåôå äÝíôñá (trees).
Ç åîÞãçóç ôÝôïéùí äïìþí åßíáé ðÝñá áðü ôïõò óêïðïýò áõôïý ôïõ manual, áëëÜ èá âñåßôå ôïõëÜ÷éóôï Ýíá ðáñÜäåéãìá ãéá êÜèå ìéá áðü áõôÝò ôéò äïìÝò. ÃÉá ðåñéóóüôåñåò ðëçñïöïñßåò óáò ðáñáðÝìðïõìå óå åîùôåñéêÞ âéâëéïãñáößá ó÷åôéêÜ ìå áõôü ôï åõñý èÝìá.
¸íáò array ìðïñåß íá äçìéïõñãçèåß áðü ôç ãëùóóéêÞ äïìÞ (language-construct) array(). Áðáéôåßôáé Ýíáò ïñéóìÝíïò áñéèìüò áðü key => æåýãç ôéìþí ðïõ ÷ùñßæïíôáé ìå êüììáôá.
array( [key =>] value , ... ) // key may be an integer or string // value may be any value |
¸íá êëåéäß (key) åßíáé åßôå integer åßôå string. Áí Ýíá key åßíáé ç standard áíáðáñÜóôáóç åíüò integer, ôüôå èá åñìçíåõèåß ùò ôÝôïéá (ð.÷. ôï "8" èá åñìçíåõèåß ùò 8, åíþ ôï "08" èá åñìçíåõèåß ùò "08"). Äåí õðÜñ÷ïõí äéáöïñåôéêïß indexed êáé associative ôýðïé áðü arrays óôçí PHP, õðÜñ÷åé ìüíï Ýíáò ôýðïò array, ðïõ ìðïñåß íá ðåñéÝ÷åé ôüóï áêÝñáéá üóï êáé string åõñåôÞñéá.
Ìéá ôéìÞ ìðïñåß íá åßíáé ïðïéïõäÞðïôå PHP ôýðïõ.
<?php $arr = array("somearray" => array(6 => 5, 13 => 9, "a" => 42)); echo $arr["somearray"][6]; // 5 echo $arr["somearray"][13]; // 9 echo $arr["somearray"]["a"]; // 42 ?> |
Áí ðáñáëÝéøåôå Ýíá êëåéäß, ôï ìÝãéóôï ôïõ áêÝñáéïõ-åõñåôçñßïõ ëáìâÜíåôáé, êáé ôï íÝï êëåéäß èá åßíáé áõôü ôï ìÝãéóôï + 1. Áí êáèïñßóåôå Ýíá êëåéäß ðïõ ôïõ Ý÷åé Þäç áíáôåèåß ìéá ôéìÞ, áõôÞ ç ôéìÞ èá åðéêáëõöèåß áðü ôç íÝá (overwritten).
<?php // This array is the same as ... array(5 => 43, 32, 56, "b" => 12); // ...this array array(5 => 43, 6 => 32, 7 => 56, "b" => 12); ?> |
Ðñïåéäïðïßçóç |
¼óïí áöïñÜ ôçí PHP 4.3.0, ç óõìðåñéöïñÜ ðáñáãùãÞò ôïõ index ðïõ ðåñéãñÜöçêå ðáñáðÜíù Ý÷åé áëëÜîåé. Ôþñá, áí ðñïóèÝóåôå óå Ýíáí ðßíáêá ôïõ ïðïßïõ ôï ôñÝ÷ïí ìÝãéóôï êëåéäß åßíáé áñíçôéêü, ôüôå ôï åðüìåíï êëåéäß ðïõ èá äçìéïõñãçèåß èá åßíáé ìçäÝí (0). Ðáëéüôåñá, ôï êáéíïýñéï index èá åß÷å ïñéóôåß óôï ìåãáëýôåñï õðÜñ÷ïí êëåéäß + 1, üðùò óõìâáßíåé êáé ìå ôéò èåôéêÝò ôéìÝò. |
×ñçóéìïðïéþíôáò ôï TRUE ùò êëåéäß èá õðïëïãéóôåß ï áêÝñáéïò 1 ùò êëåéäß. ×ñçóéìïðïéþíôáò ôï FALSE ùò êëåéäß èá õðïëïãéóôåß ï áêÝñáéïò 0 ùò êëåéäß. ×ñçóéìïðïéþíôáò ôï NULL ùò êëåéäß èá Ý÷ïõìå ùò áðïôÝëåóìá Ýíá êåíü string. ×ñçóéìïðïéþíôáò Ýíá êåíü string ùò êëåéäß èá äçìéïõñãçèåß (Þ åðáíåããñáöåß) Ýíá êëåéäß ìå Ýíá êåíü string êáé ç ôéìÞ ôïõ äå èá åßíáé ç ßäéá ìå áõôÞ ðïõ èá åß÷áìå áí ÷ñçóéìïðïéïýóáìå êåíÝò ðáñåíèÝóåéò.
Äåí ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå arrays Þ objects ùò êëåéäéÜ. Áí ôï êÜíåôå èá åìöáíéóôåß ç ðñïåéäïðïßçóç: Illegal offset type.
Ìðïñåßôå åðßóçò íá áëëÜîåôå Ýíáí õðÜñ÷ïí array, ïñßæïíôáò ñçôÜ ôéìÝò ó'áõôüí.
Áõôü ãßíåôáé áíáèÝôïíôáò ôéìÝò óôïí array åíþ óõã÷ñüíùò êáèïñßæåôáé ôï êëåéäß óôéò ðáñåíèÝóåéò. Ìðïñåßôå âÝâáéá íá ðáñáëÞøåôå ôï êëåéäß êáé íá ðñïóèÝóåôå Ýíá êåíü æåõãÜñé áðü ðáñåíèÝóåéò ("[]") óôï üíïìá ôçò ìåôáâëçôÞò óôçí ðåñßðôùóç áõôÞ.
$arr[key] = value; $arr[] = value; // key is either string or nonnegative integer // value can be anything |
<?php $arr = array(5 => 1, 12 => 2); $arr[] = 56; // This is the same as $arr[13] = 56; // at this point of the script $arr["x"] = 42; // This adds a new element to // the array with key "x" unset($arr[5]); // This removes the element from the array unset($arr); // This deletes the whole array ?> |
Óçìåßùóç: ¼ðùò Ý÷åé ðñïáíáöåñèåß, áí ãñÜøåôå ôéò ðáñáíåèÝóåéò ÷ùñßò íá ïñßóåôå êÜðïéï êëåéäß, ôüôå ï ìÝãéóôïò áðü ôïõò õðÜñ÷ïíôåò áêåñáßïõò ëáìâÜíåôáé, êáé ôï êáéíïýñéï êëåéäß èá åßíáé áõôÞ ç ìÝãéóôç ôéìÞ + 1 . Áí äåí õðÜñ÷åé êÜðïéïò áêÝñáéïò áêüìç, ôï êëåéäß èá åßíáé 0 (ìçäÝí). Áí ïñßóåôå Ýíá êëåéäß ðïõ Ý÷åé Þäç ìéá ôéìÞ áõôÞ ç ôéìÞ èá ãñáöôåß áðü ðÜíù (overwritten).
Ðñïåéäïðïßçóç ¼óïí áöïñÜ ôçí PHP 4.3.0, ç óõìðåñéöïñÜ ðáñáãùãÞò ôïõ index ðïõ ðåñéãñÜöçêå ðáñáðÜíù Ý÷åé áëëÜîåé. Ôþñá, áí ðñïóèÝóåôå óå Ýíáí ðßíáêá ôïõ ïðïßïõ ôï ôñÝ÷ïí ìÝãéóôï êëåéäß åßíáé áñíçôéêü, ôüôå ôï åðüìåíï êëåéäß ðïõ èá äçìéïõñãçèåß èá åßíáé ìçäÝí (0). Ðáëéüôåñá, ôï êáéíïýñéï index èá åß÷å ïñéóôåß óôï ìåãáëýôåñï õðÜñ÷ïí êëåéäß + 1, üðùò óõìâáßíåé êáé ìå ôéò èåôéêÝò ôéìÝò.
Óçìåéþóôå üôé ôï ìÝãéóôï áêÝñáéï êëåéäß ðïõ ÷ñçóéìïðïéåßôáé äåí ÷ñåéÜæåôáé áðáñáéôÞôùò íá õðÜñ÷åé óôïí ðßíáêá. ÁðëÜ ðñÝðåé íá õðÞñ÷å óôïí ðßíáêá êÜðïéá óôéãìÞ áðü ôçí ôåëåõôáßá öïñÜ ðïõ Ýãéíå óôïí ðßíáêá áíáôáîéíüìçóç (re-index). Ôï áêüëïõèï ðáñÜäåéãìá äåß÷íåé ôá ðáñáðÜíù:
<?php // Create a simple array. $array = array(1, 2, 3, 4, 5); print_r($array); // Now delete every item, but leave the array itself intact: foreach ($array as $i => $value) { unset($array[$i]); } print_r($array); // Append an item (note that the new key is 5, instead of 0 as you // might expect). $array[] = 6; print_r($array); // Re-index: $array = array_values($array); $array[] = 7; print_r($array); ?>Ôï ðáñáðÜíù ðáñÜäåéãìá èá ðáñÞãáãå ôï áêüëïõèï áðïôÝëåóìá:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Array ( ) Array ( [5] => 6 ) Array ( [0] => 6 [1] => 7 )
ÕðÜñ÷ïõí áñêåôÝò ÷ñÞóéìåò óõíáñôÞóåéò ãéá íá äïõëÝøåôå ìå arrays, äåßôå ôï ôìÞìá ÓõíáñôÞóåéò ãéá arrays .
Óçìåßùóç: Ç óõíÜñôçóç unset() óáò åðéôñÝðåé íá êÜíåôå unset óôá êëåéäéÜ åíüò array. ÐñÝðåé íá ëÜâåôå õðüøç üôé ï array ÄÅÍ èá îáíáôáîéíïìçèåß. Ìüíï áí ÷ñçóéìïðïéÞóåôå ôï "usual integer indices" (áñ÷ßæïíôáò áðü ôï ìçäÝí, êáé áõîÜíïíôáò êáôÜ Ýíá), èá ìðïñÝóåôå íá ðåôý÷åôå ôçí áíáôáîéíüìçóç ÷ñçóéìïðïéþíôáò ôçí array_values().
Ç äïìÞ åëÝã÷ïõ foreach õðÜñ÷åé åéäéêÜ ãéá ôïõò arrays. ÐáñÝ÷åé Ýíáí åýêïëï ôñüðï ãéá íá ðñïóðåëáýíåôå Ýíáí array.
ÐñÝðåé ðÜíôá íá ÷ñçóéìïðïéåßôå åéóáãùãéêÜ Ýîù áðü Ýíá åõñåôÞñéï åíüò associative array. Ãéá ðáñÜäåéãìá, ÷ñçóéìïðïéÞóôå ôçí $foo['bar'] êáé ü÷é ôçí $foo[bar]. ÁëëÜ ãéáôß åßíáé ç $foo[bar] ëáíèáóìÝíç; ºóùò Ý÷åôå äåé ôïí áêüëïõèï ôñüðï óýíôáîçò óå ðáëéüôåñá scripts:
Áõôü åßíáé ëÜèïò, áëëÜ äïõëåýåé. Ôüôå, ãéáôß åßíáé ëÜèïò? Ï ëüãïò åßíáé üôé áõôüò ï êþäéêáò Ý÷åé ìéá áðñïóäéüñéóôç óôáèåñÜ (ôçí bar) ðáñÜ Ýíá string ('bar' - ðñïóÝîôå ôá åéóáãùãéêÜ), êáé ç PHP ßóùò ìåëëïíôéêÜ ïñßóåé óôáèåñÝò ïé ïðïßåò, äõóôõ÷þò ãéá ôïí êþäéêá óáò, Ý÷ïõí ôï ßäéï üíïìá. Äïõëåýåé, åðåéäÞ ç PHP áõôüìáôá ìåôáôñÝðåé Ýíá bare string (åßíáé Ýíá string ÷ùñßò åéóáãùãéêÜ ðïõ äåí áíôéóôïé÷åß óå êÜðïéï ãíùóôü óýìâïëï) óå string ðïõ ðåñéÝ÷åé ôï bare string. Ãéá ðáñÜäåéãìá, áí äåí õðÜñ÷åé êÜðïéï ïñéóìÝíç óôáèåñÜ ìå ôï üíïìá bar, ôüôå ç PHP èá áíôéêáôáóôÞóåé ôï string 'bar' êáé èá ÷ñçóéìïðïéåß áõôü.Óçìåßùóç: Áõôü äå óçìáßíåé íá âÜæåôå ðÜíôáalways åéóáãùãéêÜ óôï êëåéäß. Äåí èÝëåôå íá âÜæåôå åéóáãùãéêÜ óôá êëåéäéÜ ðïõ åßíáé óôáèåñÝò Þ ìåôáâëçôÝò, êáèþò áõôü èá åìðïäßæåé ôçí PHP áðü ôï íá ôá ìåôáãëùôôßóåé.
<?php error_reporting(E_ALL); ini_set('display_errors', true); ini_set('html_errors', false); // Simple array: $array = array(1, 2); $count = count($array); for ($i = 0; $i < $count; $i++) { echo "\nChecking $i: \n"; echo "Bad: " . $array['$i'] . "\n"; echo "Good: " . $array[$i] . "\n"; echo "Bad: {$array['$i']}\n"; echo "Good: {$array[$i]}\n"; } ?>Óçìåßùóç: Ôï áðïôÝëåóìá áðü ôï ðáñáðÜíù èá åßíáé:
Checking 0: Notice: Undefined index: $i in /path/to/script.html on line 9 Bad: Good: 1 Notice: Undefined index: $i in /path/to/script.html on line 11 Bad: Good: 1 Checking 1: Notice: Undefined index: $i in /path/to/script.html on line 9 Bad: Good: 2 Notice: Undefined index: $i in /path/to/script.html on line 11 Bad: Good: 2
Ðåñéóóüôåñá ðáñáäåßãìáôá ãéá íá äåßîïõí ôï ðáñáðÜíù:
<?php // Let's show all errors error_reporting(E_ALL); $arr = array('fruit' => 'apple', 'veggie' => 'carrot'); // Correct print $arr['fruit']; // apple print $arr['veggie']; // carrot // Incorrect. This works but also throws a PHP error of // level E_NOTICE because of an undefined constant named fruit // // Notice: Use of undefined constant fruit - assumed 'fruit' in... print $arr[fruit]; // apple // Let's define a constant to demonstrate what's going on. We // will assign value 'veggie' to a constant named fruit. define('fruit', 'veggie'); // Notice the difference now print $arr['fruit']; // apple print $arr[fruit]; // carrot // The following is okay as it's inside a string. Constants are not // looked for within strings so no E_NOTICE error here print "Hello $arr[fruit]"; // Hello apple // With one exception, braces surrounding arrays within strings // allows constants to be looked for print "Hello {$arr[fruit]}"; // Hello carrot print "Hello {$arr['fruit']}"; // Hello apple // This will not work, results in a parse error such as: // Parse error: parse error, expecting T_STRING' or T_VARIABLE' or T_NUM_STRING' // This of course applies to using autoglobals in strings as well print "Hello $arr['fruit']"; print "Hello $_GET['foo']"; // Concatenation is another option print "Hello " . $arr['fruit']; // Hello apple ?> |
¼ôáí åíåñãïðïéÞóåôå ôï error_reporting() íá åìöáíßæåé E_NOTICE ãéá level errors (üðùò ôï íá ôåèåß óôç óôáèåñÜ E_ALL) ôüôå èá äåßôå áõôÜ ôá ëÜèç. Ç ðñïêáèïñéóìÝíç ñýèìéóç åßíáé, ôï error_reporting íá ìçí Ý÷åé åíåñãïðïéçìÝíç ôç ñýèìéóç ãéá åìöÜíéóç ôïõò.
¼ðùò Ý÷åé äçëùèåß óôï ôìÞìá óýíôáîçò , ðñÝðåé íá õðÜñ÷åé ìéá Ýêöñáóç ìåôáîý óôéò áãêýëåò ('[' êáé ']'). Áõôü óçìáßíåé üôé ìðïñåßôå íá ãñÜøåôå ðñÜãìáôá üðùò áõôü:
Áõôü åßíáé Ýíá ðáñÜäåéãìá ÷ñÞóçò ìéáò óõíÜñôçóçò ðïõ åðéóôñÝöåé êÜðïéá ôéìÞ ùò äåßêôç ðßíáêá (array index). Ç PHP åðßóçò ãíùñßæåé ôéò óôáèåñÝò, üðùò èá Ý÷åôå äåé E_* êáé ðñïçãïõìÝíùò.<?php $error_descriptions[E_ERROR] = "A fatal error has occured"; $error_descriptions[E_WARNING] = "PHP issued a warning"; $error_descriptions[E_NOTICE] = "This is just an informal notice"; ?> |
<?php $error_descriptions[1] = "A fatal error has occured"; $error_descriptions[2] = "PHP issued a warning"; $error_descriptions[8] = "This is just an informal notice"; ?> |
¼ðùò Ý÷ïõìå Þäç åîçãÞóåé óå ðñïçãïýìåíá ðáñáäåßãìáôá, ç $foo[bar] äïõëåýåé áêüìç áëëÜ åßíáé ëÜèïò. Äïõëåýåé, åðåéäÞ bar åîáéôßáò ôçò óýíôáîçò ôçò áíáìÝíåôáé íá åßíáé ìéá óôáèåñÞ Ýêöñáóç. ÐÜíôùò, ó'áõôÞ ôçí ðåñßðôùóç êáìßá óôáèåñÜ ìå ôï üíïìá bar äåí õðÜñ÷åé. Ç PHP ôþñá õðïèÝôåé üôé åííïïýóáôå ôçí bar êõñéïëåêôéêÜ, üðùò ôï string "bar", áëëÜ Ý÷åôå îå÷Üóåé íá ãñÜøåôå ôá åéóáãùãéêÜ.
Óå êÜðïéá óôéãìÞ óôï ìÝëëïí, ç ïìÜäá ôçò PHP ßóùò èåëÞóåé íá ðñïóèÝóåé êáé êÜðïéá Üëëç óôáèåñÜ Þ keyword, Þ ìðïñåß åóåßò íá èÝëåôå íá åéóÜãåôå êÜðïéá óôáèåñÜ óôçí åöáñìïãÞ óáò, êáé ôüôå íá áíôéìåôùðßóåôå ðñüâëçìá. Ãéá ðáñÜäåéãìá, äåí ìðïñåßôå Þäç íá ÷ñçóéìïðïéÞóåôå ôéò ëÝîåéò empty êáé default ì'áõôüí ôïí ôñüðï, áöïý åßíáé éäéáßôåñåò äåóìåõìÝíåò ëÝîåéò.
Óçìåßùóç: Ãéá åðáíÜëçøç, ìÝóá óå Ýíá string ìå äéðëá åéóáãùãéêÜ, åßíáé Ýãêõñï íá ìçí ðåñéëáìâÜíåôå array indexes ìå åéóáãùãéêÜ, óõíåðþò ôï "$foo[bar]" åßíáé Ýãêõñï. Äåßôå ôá ðáñáðÜíù ðáñáäåßãìáôá ãéá ëåðôïìÝñåéåò ó÷åôéêÜ ìå ôï ãéáôß üðùò åðßóçò ôï ôìÞìá ó÷åôéêÜ ìå ôï ðÝñáóìá ìåôáâëçôþí óå strings.
Ãéá ïðïéïäÞðïôå áðü ôïõò ôýðïõò: integer, float, string, boolean êáé resource, áí ìåôáôñÝøåôå ìéá ôéìÞ óå array, ðáßñíåôå Ýíáí array ìå Ýíá óôïé÷åßï (ìå index 0), ôï ïðïßï åßíáé ç âáèìùôÞ ôéìÞ ìå ôçí ïðïßá áñ÷ßóáôå.
Áí ìåôáôñÝøåôå Ýíá object óå Ýíáí array, ðáßñíåôå ôéò éäéüôçôåò (ìåôáâëçôÝò ìåëþí) áõôïý ôïõ áíôéêåéìÝíïõ ùò óôïé÷åßá ôïõ array. Ôá êëåéäéÜ åßíáé ôá ïíüìáôá ôùí ìåôáâëçôþí ìåëþí.
Áí ìåôáôñÝøåôå ìéá NULL ôéìÞ óå array, ðáßñíåôå Ýíáí êåíü array.
Ï ôýðïò array óôçí PHP åßíáé ðïëý åõðñïóÜñìïóôïò, Ýôóé åäþ èá äåßôå ìåñéêÜ ðáñáäåßãìáôá ðïõ èá óáò äåßîïõí ôéò ðïëëÝò äõíáôüôçôåò ôùí arrays.
<?php // this $a = array( 'color' => 'red', 'taste' => 'sweet', 'shape' => 'round', 'name' => 'apple', 4 // key will be 0 ); // is completely equivalent with $a['color'] = 'red'; $a['taste'] = 'sweet'; $a['shape'] = 'round'; $a['name'] = 'apple'; $a[] = 4; // key will be 0 $b[] = 'a'; $b[] = 'b'; $b[] = 'c'; // will result in the array array(0 => 'a' , 1 => 'b' , 2 => 'c'), // or simply array('a', 'b', 'c') ?> |
ÐáñÜäåéãìá 6-4. ×ñçóéìïðïéþíôáò ôçí array()
|
Óçìåéþóôå üôé ðñïò ôï ðáñüí äåí åßíáé äõíáôü íá áëëÜîïõìå ôéò ôéìÝò ôïõ array Üìåóá óå Ýíá ôÝôïéï loop. Äåßôå ôï áêüëïõèï:
Áõôü ôï ðáñÜäåéãìá äçìéïõñãåß Ýíáí one-based array.
Ïé arrays åßíáé äéáôåôáãìÝíïé. Ìðïñåßôå åðßóçò íá áëëÜîåôå ôç óåéñÜ ÷ñçóéìïðïéþíôáò äéÜöïñåò óõíáñôÞóåéò ôáîéíüìçóçò. Äåßôå ôï ôìÞìá óõíáñôÞóåéò ãéá arrays ãéá ðåñéóóüôåñåò ðëçñïöïñßåò. Ìðïñåßôå íá ìåôñÞóåôå ôïí áñéèìü ôùí óôïé÷åßùí óå Ýíá array ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç count() .
ÅðåéäÞ ç ôéìÞ åíüò array ìðïñåß íá åßíáé ïôéäÞðïôå, ìðïñåß åðßóçò íá åßíáé Ýíáò Üëëïò array. Ì'áõôüí ôïí ôñüðï ìðïñåßôå íá êÜíåôå áíáäñïìéêïýò êáé ðïëõäéÜóôáôïõò arrays.
ÐáñÜäåéãìá 6-10. Áíáäñïìéêïé êáé ðïëõäéÜóôáôïé arrays
|
ÐñÝðåé íá ðñïóÝ÷åôå åðåéäÞ ïé áíáèÝóåéò ôùí array ðÜíôá åìðëÝêïõí áíôéãñáöÞ ôéìþí. Èá ÷ñåéáóôåß íá ÷ñçóéìïðïéÞóåôå ôïí ôåëåóôÞ áíáöïñÜò ãéá íá áíôéãñÜøåôå Ýíáí array ìå áíáöïñÜ.
Ãéá íá áñ÷éêïðïéÞóåôå Ýíá áíôéêåßìåíï, ÷ñçóéìïðïéåßôå ôç äÞëùóç new ãéá íá äçìéïõñãÞóåôå Ýíá óôéãìéüôõðï ôïõ áíôéêåéìÝíïõ óå ìéá ìåôáâëçôÞ.
Ãéá ìéá ðëÞñç áíÜëõóç, ðáñáêáëþ äéáâÜóôå ôï ôìÞìá ó÷åôéêÜ ìå Classes êáé Objects.
Áí Ýíá object ìåôáôñÝðåôáé óå Üëëï object, áõôü óçìáßíåé üôé äåí áëëÜæåé. Áí ìéá ôéìÞ ïðïéïäÞðïôå Üëëïõ ôýðïõ ìåôáôñÝðåôáé óå object, ôüôå Ýíá êáéíïýñéï óôéãìéüôõðï ôïõ stdClass built óôçí class äçìéïõñãåßôáé. Áí ç ôéìÞ Þôáí null, ôï íÝï óôéãìéüôõðï èá åßíáé êåíü. Ãéá ïðïéáäÞðïôå Üëëç ôéìÞ, ìéá ìåôáâëçôÞ ìÝëïõò ïíïìáæüìåíç scalar èá ðåñéÝ÷åé ôçí ôéìÞ.
Ìéá resource åßíáé ìéá åéäéêÞ ìåôáâëçôÞ, ðïõ êñáôÜåé ìéá áíáöïñÜ óå ìéá åîùôåñéêÞ resource. Ïé resources äçìéïõñãïýíôáé êáé ÷ñçóéìïðïéïýíôáé áðü åéäéêÝò óõíáñôÞóåéò. Äåßôå ôï appendix ãéá ìéá ëßóôá üëùí áõôþí ôùí óõíáñôÞóåùí êáé ôùí áíôßóôïé÷ùí resource ôýðùí.
Óçìåßùóç: Ï ôýðïò resource åéóÞ÷èç óôçí PHP 4
ÅðåéäÞ ïé resource ôýðïé Ý÷ïõí åéäéêïýò handlers ãéá áíïéãìÝíá áñ÷åßá, database connections, image canvas areas êáé ðáñüìïéá, äåí ìðïñåßôå íá ìåôáôñÝøåôå ïðïéáäÞðïôå ôéìÞ óå resource.
Åîáéôßáò ôïõ reference-counting óõóôÞìáôïò ðïõ åéóÞ÷èç ìå ôçí Zend-engine ôçò PHP4, ãßíåôáé áõôüìáôç áíß÷íåõóç ðüôå óôáìáôÜåé íá ãßíåôáé áíáöïñÜ óå Ýíá resource (üðùò êáé óôç Java). Ó'áõôÞ ôçí ðåñßðôùóç, üëåò ïé resources ðïõ ÷ñçóéìïðïéïýíôáí ãé'áõôÞ ôç resource åëåõèåñþíïíôáé áðü ôïí garbage collector. Ãé'áõôü ôï ëüãï, åßíáé óðÜíéá áíáãêáßï íá åëåõèåñþóåôå ôç ìíÞìç manually ÷ñçóéìïðïéþíôáò êÜðïéá óõíÜñôçóç üðùò ôç free_result.
Óçìåßùóç: Ôá Persistent database links åßíáé éäéáßôåñá, äåí êáôáóôñÝöïíôáé áðü ôïí garbage collector. Äåßôå åðßóçò ôï ôìÞìá ó÷åôéêÜ ìå óôáèåñÝò (persistent) óõíäÝóåéò.
Ç åéäéêÞ ôéìÞ NULL óçìáßíåé üôé ìéá ìåôáâëçôÞ äåí Ý÷åé ôéìÞ. Ç NULL åßíáé ç ìüíç ðéèáíÞ ôéìÞ ôïõ ôýðïõ NULL.
Óçìåßùóç: Ï ôýðïò null åéóÞ÷èç óôçí PHP 4
Ìéá ìåôáâëçôÞ èåùñåßôáé üôé åßíáé NULL áí
Ý÷åé áíáôåèåß óôç óôáèåñÜ NULL.
äåí ôçò Ý÷åé ôåèåß áêüìç êáìßá ôéìÞ.
ôçò Ý÷åé ãßíåé unset().
mixed äåß÷íåé üôé ìéá ðáñÜìåôñïò ìðïñåß íá äå÷èåß ðïëëáðëïýò (áëëÜ ü÷é áðáñáßôçôá üëïõò) ôýðïõò.
Ç gettype() ãéá ðáñÜäåéãìá èá äå÷èåß üëïõò ôïõò ôýðïõò ôçò PHP, åíþ ç str_replace() èá äå÷èåß ìüíï strings êáé arrays.
ÌåéñêÝò óõíáñôÞóåéò üðùò ç call_user_function() Þ ç usort() äÝ÷ïíôáé callback óõíáñôÞóåéò ïñéæüìåíåò áðü ôï ÷ñÞóôç ùò ðáñÜìåôñïé. Ïé callback óõíáñôÞóåéò äåí ìðïñïýí íá åßíáé áðëÝò óõíáñôÞóåéò áëëÜ åðßóçò object methods ðïõ ðåñéÝ÷ïõí static class methods.
Ìéá óõíÜñôçóç óå PHP êáëåßôáé áðëÜ ìå ôï üíïìá ôçò ùò string. Ìðïñåßôå íá ðåñÜóåôå ïðïéáäÞðïôå builtin Þ ïñéæüìåíç áðü ôï ÷ñÞóôç óõíÜñôçóç ÷ñçóéìïðïéþíôáò exception áðü array(), echo(), empty(), eval(), exit(), isset(), list(), print() êáé unset().
Ìéá ìÝèïäïò åíüò áíôéêåéìÝíïõ ðïõ Ý÷åé êÜðïéï óôéãìéüôõðï ðåñíéÝôáé ùò array ðïõ ðåñéÝ÷åé Ýíá object ùò óôïé÷åßï ìå index 0 êáé Ýíá üíïìá ìåèüäïõ ùò óôïé÷åßï ìå index 1.
Ïé Static class methods ìðïñïýí åðßóçò íá ðåñáóôïýí ÷ùñßò íá äçìéïõñãÞóïõìå óôéãìéüôõðï åíüò object áõôÞò ôçò class ðåñíþíôáò ôï üíïìá ôçò êëÜóçò áíôß ãéá Ýíá object üðùò ôï element ìå index 0.
ÐáñÜäåéãìá 6-11. Ðáñáäåßãìáôá ãéá Callback óõíáñôÞóåéò
|
Ç PHP äåí áðáéôåß (Þ õðïóôçñßæåé) óáöÞ äÞëùóç ôýðùí êáôÜ ôç äÞëùóç ìåôáâëçôþí. ¸íáò ôýðïò ìåôáâëçôÞò êáèïñßæåôáé áðü ôï ðåñéå÷üìåíï ìå ôï ïðïßï áõôÞ ç ìåôáâëçôÞ èá ÷ñçóéìïðïéçèåß. ÄçëáäÞ, áí ïñßóåôå ìéá ôéìÞ string óå ìéá ìåôáâëçôÞ $var, ç $var ãßíåôáé string. Áí óôç óõíÝ÷åéá áíáèÝóåôå ìéá integer ôéìÞ óôç $var, ôüôå ãßíåôáé integer.
¸íá ðáñÜäåéãìá ôçò áõôüìáôçò ìåôáôñïðÞò ôýðïõ óôçí PHP åßíáé ï ôåëåóôÞò ðñüóèåóçò '+'. Áí ïðïéïóäÞðïôå áðü ôá ôåëïýìåíá åßíáé float, ôüôå üëá õðïëïãßæïíôáé ùò floats, êáé ôï áðïôÝëåóìá èá åßíáé float. ÄéáöïñåôéêÜ, ôá ôåëïýìåíá èá åñìçíåýïíôáé ùò integers, êáé ôï áðïôÝëåóìá èá åßíáé åðßóçò integer. Óçìåéþóôå üôé áõôü ÄÅÍ áëëÜæåé ôïõò ôýðïõò ôùí ßäéùí ôùí ôåëïýìåíùí. Ç ìüíç áëëáãÞ åßíáé óôï ðþò õðïëïãßæïíôáé ôá ôåëïýìåíá.
<?php $foo = "0"; // $foo is string (ASCII 48) $foo += 2; // $foo is now an integer (2) $foo = $foo + 1.3; // $foo is now a float (3.3) $foo = 5 + "10 Little Piggies"; // $foo is integer (15) $foo = 5 + "10 Small Pigs"; // $foo is integer (15) ?> |
Áí ôá ôåëåõôáßá äõï ðáñáäåßãìáôá óáò öÜíçêáí ðåñßåñãá, äåßôå ôï ÌåôáôñïðÞ ôïõ String óå number.
Áí åðéèõìåßôå íá áíáãêÜóåôå ìéá ìåôáâëçôÞ íá õðïëïãéóôåß óáí íá Þôáí åíüò óõãêåêñéìÝíïõ ôýðïõ, äåßôå ôï ôìÞìá ó÷åôéêÜ ìå Type casting. Áí åðéèõìåßôå íá áëëÜîåôå ôïí ôýðï ìéáò ìåôáâëçôÞò, äåßôå ôï settype().
Áí èÝëåôå íá åëÝãîåôå ïðïéïäÞðïôå áðü áõôÜ ôá ðáñáäåßãìáôá ó'áõôü ôï ôìÞìá, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôç óõíÜñôçóç var_dump().
Óçìåßùóç: Ç óõìðåñéöïñÜ ìéáò áõôüìáôçò ìåôáôñïðÞò óå array åßíáé ðñïò ôï ðáñüí áðñïóäéüñéóôç.
Áöïý ç PHP (ãéá éóôïñéêïýò ëüãïõò) õðïóôçñßæåé indexing óå strings ìÝóù offsets ÷ñçóéìïðïéþíôáò ôçí ßäéá óýíôáîç üðùò êáé óôï indexing ôùí arrays, ôï ðáñÜäåéãìá ðáñáðÜíù ïäçãåß óå Ýíá ðñüâëçìá: èá ðñÝðåé ôï $a íá ãßíåé array ìå ôï ðñþôï óôïé÷åßï ôïõ íá åßíáé ôï "f", Þ èá ðñÝðåé ôï "f" íá ãßíåé ï ðñþôïò ÷áñáêôÞñáò ôïõ string $a?
Ïé ôñÝ÷ïõóåò åêäüóåéò ôçò PHP ìåôáãëùôôßæïõí ôç äåýôåñç áíÜèåóç ùò string offset ðéóôïðïßçóç, óõíåðþò ç $a ãßíåôáé "f", ôï áðïôÝëåóìá üìùò áõôÞò ôçò áõôüìáôçò ìåôáôñïðÞò èá ðñÝðåé íá èåùñçèåß áðñïóäéüñéóôï. Ç PHP 4 åéóÞãáãå ôç íÝá óýíôáîç ÷ñçéìïðïéþíôáò curly bracket ãéá íá áðïêôÞóåé ðñüóâáóç óå ÷áñáêôÞñåò åíüò string, óõíåðþò ÷ñçóéìïðïéÞóôå áõôÞ ôç óýíôáîç áíôß áõôÞò ðïõ ðáñïõóéÜóôçêå ðáñáðÜíù:
Äåßôå ôï ôìÞìá ìå ôßôëï Ðñüóâáóç ôùí String ìå ÷áñáêôÞñåò ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Ç ìåôáôñïðÞ ôýðùí (Þ Type casting) óôçí PHP äïõëåýåé ó÷åäüí üðùå êáé óôç C: ôï üíïìá ôïõ åðéèõìçôïý ôýðïõ ãñÜöåôå óå ðáñåíèÝóåéò ðñéí áðü ôç ìåôáâëçôÞ óôçí ïðïßá èá ãßíåé ôï cast.
Ôá åðéôñåðüìåíá casts åßíáé ôá:
(int), (integer) - cast óå integer
(bool), (boolean) - cast óå boolean
(float), (double), (real) - cast óå float
(string) - cast óå string
(array) - cast óå array
(object) - cast óå object
Óçìåéþóôå üôé ôá tabs êáé ôá spaces åðéôñÝðïíôáé ìÝóá óôéò ðáñåíèÝóåéò, óõíåðþò ôá áêüëïõèá åßíáé åîßóïõ ëåéôïõñãéêÜ:
Óçìåßùóç: Áíôß íá êÜíïõìå cast ìéáò ìåôáâëçôÞò óå string, ìðïñåßôå åðßóçò íá êëåßóåôå ôç ìåôáâëçôÞ óå äéðëÜ åéóáãùãéêÜ.
ºóùò äåí åßíáé áêñéâþò ðñïöáíÝò ôé èá óõìâåß üôáí ãßíåôáé casting ìåôáîý óõãêåêñéìÝíùí ôýðùí. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äåßôå áõôÜ ôá ôìÞìáôá:
Ïé ìåôáâëçôÝò óôçí PHP áíáðáñßóôáíôáé áðü ôï óýìâïëï ôïõ äïëáñßïõ áêïëïõèïýìåíï áðü ôï üíïìá ôçò ìåôáâëçôÞò. Ôï üíïìá ôçò ìåôáâëçôÞò åßíáé case-sensitive.
Ôá ïíüìáôá ôùí ìåôáâëçôþí áêïëïõèïýí ôïõò ßäéïõò êáíüíåò üðùò êáé ïé labels óôçí PHP. ¸íá Ýãêõñï üíïìá ìåôáâëçôÞò áñ÷ßæåé ìå Ýíá ãñÜììá Þ underscore, áêïëïõèïýìåíï áðü ïðïéïíäÞðïôå áñéèìü áðü ãñÜììáôá, áñéèìïýò, Þ underscores. Ùò êáíïíéêÞ Ýêöñáóç èá ãñáöüôáí ùò åîÞò: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
Óçìåßùóç: Ãéá ôïõò óêïðïýò ìáò åäþ, Ýíá ãñÜììá åßíáé áðü a-z, A-Z, êáé ïé ASCII ÷áñáêôÞñåò áðü ôï 127 ùò ôï 255 (0x7f-0xff).
<?php $var = "Bob"; $Var = "Joe"; echo "$var, $Var"; // outputs "Bob, Joe" $4site = 'not yet'; // invalid; starts with a number $_4site = 'not yet'; // valid; starts with an underscore $täyte = 'mansikka'; // valid; 'ä' is (Extended) ASCII 228. ?> |
Óôçí PHP 3, ïé ìåôáâëçôÝò áíáôßèåíôáé ðÜíôá ìå ôéìÞ. ÄçëáäÞ, üôáí áíáèÝôåôå ìéá Ýêöñáóç óå ìéá ìåôáâëçôÞ, ïëüêëçñç ç ôéìÞ ôçò áñ÷éêÞ Ýêöñáóçò áíôéãñÜöåôáé óôç ìåôáâëçôÞ ðñïïñéóìïý. Áõôü óçìáßíåé, ãéá ðáñÜäåéãìá, üôé áöïý áíáèÝóåôå ôçí ôéìÞ ìéáò ìåôáâëçôÞò óå ìéá Üëëç, áëëÜæïíôáò ìéá áðü áõôÝò ôéò ìåôáâëçôÝò äå èá åðçñåáóôåß ç Üëëç. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ãé'áõôïý ôïõ åßäïõò ôçí áíÜèåóç, äåßôå ôï êåöÜëáéï ó÷åôéêÜ ìå ÅêöñÜóåéò.
Ç PHP 4 ðñïóöÝñåé Ýíáí Üëëï ôñüðï ãéá íá áíáèÝóåôå ôéìÝò óå ìåôáâëçôÝò: áíÜèåóç ìå áíáöïñÜ. Áõôü óçìáßíåé üôé ç íÝá ìåôáâëçôÞ áðëÜ áíáöÝñåôáé (ìå Üëëá ëüãéá, "ãßíåôáé alias ãéá" Þ "äåß÷íåé óå") óôçí áñ÷éêÞ ìåôáâëçôÞ. ÁëëáãÝò óôç íÝá ìåôáâëçôÞ åðçñåÜæïõí ôçí áñ÷éêÞ, êáé áíôéóôñüöùò. Áõôü óçìáßíåé åðßóçò üôé äå ãßíåôáé áíôéãñáöÞ. Óõíåðþò, ç áíÜèåóç óõìâáßíåé ðéï ãñÞãïñá. ÐÜíôùò, ïðïéïóäÞðïôå ôñüðïò åðéôÜ÷õíóçò èá ãßíåé åìöáíÞò ìüíï óå tight loops Þ üôáí ãßíåôáé áíÜèåóç ìåãÜëùí arrays Þ objects.
Ãéá íá áíáèÝóïõìå ìå áíáöïñÜ, áðëÜ âÜæïõìå ìðñïóôÜ Ýíá ampersand (&) óôçí áñ÷Þ ôçò ìåôáâëçôÞò óôçí ïðïßá ãßíåôáé ç áíÜèåóç (ç áñ÷éêÞ ìåôáâëçôÞ). Ãéá ðáñÜäåéãìá, ôï áêüëïõèï êïììÜôé êþäéêá äßíåé ôï áðïôÝëåóìá 'My name is Bob' äýï öïñÝò:
<?php $foo = 'Bob'; // Assign the value 'Bob' to $foo $bar = &$foo; // Reference $foo via $bar. $bar = "My name is $bar"; // Alter $bar... echo $bar; echo $foo; // $foo is altered too. ?> |
¸íá óçìáíôéêü ðñÜãìá ðïõ ðñÝðåé íá óçìåéþóïõìå åßíáé üôé ìüíï ïé ìåôáâëçôÝò ìå üíïìá ìðïñïýí íá áíáôåèïýí ìå áíáöïñÜ.
Ç PHP ðáñÝ÷åé Ýíáí ìåãÜëï áñéèìü áðü ðñïêáèïñéóìÝíåò ìåôáâëçôÝò óå ïðïéïäÞðïôå script ôñÝ÷åé. ÁñêåôÝò áðü áõôÝò ôéò ìåôáâëçôÝò ðÜíôùò, äåí ìðïñïýí íá ôåêìçñéùèïýí åíôåëþò áöïý åîáñôþíôáé áðü ôïí server óôïí ïðïßï ôñÝ÷ïõí, ôçí Ýêäïóç êáé ôï setup ôïõ server, êáèþò êáé áðü Üëëïõò ðáñÜãïíôåò. ÌåñéêÝò áðü áõôÝò ôéò ìåôáâëçôÝò äå èá åßíáé äéáèÝóéìåò üôáí ç PHP ôñÝ÷åé óå command line. Ãéá ìéá ëßóôá áõôþí ôùí ìåôáâëçôþí, ðáñáêáëþ äåßôå ôï ôìÞìá ÄåóìåõìÝíåò ðñïêáèïñéóìÝíåò ìåôáâëçôÝò.
Ðñïåéäïðïßçóç |
Óôçí PHP 4.2.0 êáé ìåôÜ, ç ðñïêáèïñéóìÝíç ôéìÞ ãéá ôçí íôéñåêôßâá ôçò PHP register_globals åßíáé off. ÁõôÞ åßíáé ìéá óçìáíôéêÞ áëëáãÞ ãéá ôçí PHP. ¸÷ïíôáò ôéò register_globals off åðçñåÜæåôáé ôï óýíïëï ôùí ðñïêáèïñéóìÝíùí ìåôáâëçôþí ðïõ åßíáé äéáèÝóéìåò óå global åìâÝëåéá. Ãéá ðáñÜäåéãìá ãéá íá ðÜñåôå ôï DOCUMENT_ROOT èá ÷ñçóéìïðïéÞóåôå ôçí $_SERVER['DOCUMENT_ROOT'] áíôß ãéá ôçí $DOCUMENT_ROOT, Þ $_GET['id'] áðü ôï URL http://www.example.com/test.php?id=3 áíôß ãéá ôçí $id, Þ ôçí $_ENV['HOME'] áíôß ãéá ôçí $HOME. Ãéá ðëçñïöïñßåò ó÷åôéêÝò ì'áõôÞ ôçí áëëáãÞ, äéáâÜóôå ôï configuration entry ãéá register_globals, ôï êåöÜëáéï ãéá áóöÜëåéá ×ñçóéìïðïéþíôáò Register Globals , êáèþò åðßóçò êáé ôçí PHP 4.1.0 êáé 4.2.0 Release Announcements. Åßíáé ðñïôéìüôåñï íá ÷ñçóéìïðïéåßôå ôéò äéáèÝóéìåò PHP Reserved Predefined ÌåôáâëçôÝò, üðùò ôçí superglobal arrays. |
Áðü ôçí Ýêäïóç 4.1.0 êáé ìåôÜ, ç PHP ðáñÝ÷åé Ýíá åðéðñüóèåôï óýíïëï áðü ðñïêáèïñéóìÝíïõò arrays ðïõ ðåñéÝ÷ïõí ìåôáâëçôÝò áðü ôïí web server (áí åßíáé äõíáôü), ôï environment (ðåñéâÜëëïí), êáé áõôÜ ðïõ åéóÜãåé ï ÷ñÞóôçò. Áõôïß ïé íÝïé arrays åßíáé ìÜëëïí éäéáßôåñïé áðü ôçí Üðïøç üôé åßíáé áõôüìáôá global--ð.÷., áõôüìáôá äéáèÝóéìïé ãéá êÜèå åìâÝëåéá. Ãé'áõôü ôï óêïðü, åßíáé óõ÷íÜ ãíùóôïß êáé ùò 'autoglobals' Þ 'superglobals'. (Äåí õðÜñ÷åé ìç÷áíéóìüò óôçí PHP ãéá superglobals ðïõ ìðïñåß íá ïñßóåé ï ÷ñÞóôçò.) Ïé superglobals ðáñáôßèåíôáé ðáñáêÜôù. ÐÜíôùò, ãéá ìéá ëßóôá ôùí ðåñéå÷ïìÝíùí ôïõò êáé ðåñåôáßñù óõæÞôçóç ðÜíù óôéò ðñïêáèïñéóìÝíåò ìåôáâëçôÝò ôçò PHP êáé óôç öýóç ôïõò, ðáñáêáëþ äåßôå ôï ôìÞìá ÄåóìåõìÝíåò ðñïêáèïñéóìÝíåò ìåôáâëçôÝò. Åðßóçò, èá ðáñáôçñÞóåôå ðþò ïé ðáëéüôåñåò ðñïêáèïñéóìÝíåò ìåôáâëçôÝò ($HTTP_*_VARS) õðÜñ÷ïõí áêüìç. Áðü ôçí PHP 5.0.0, ôá ìåãÜëá ðñïêáèïñéóìÝíá óôáèåñÜ array ìðïñïýí íá áðåíåñãïðïéçèïýí ìå ôï register_long_arrays directive.
ÌåôáâëçôÝò ìåôáâëçôþí: Ïé superglobals äåí ìðïñïýí íá ÷ñçóéìïðïéçèïýí ùò ìåôáâëçôÝò ìåôáâëçôþí.
Áí ìéá óõãêåêñéìÝíç ìåôáâëçôÞ óôçí variables_order äåí Ý÷åé ïñéóôåß, ïé êáôÜëëçëïé ðñïêáèïñéóìÝíïé arrays ôçò PHP ìÝíïõí êåíïß.
PHP Superglobals
ÐåñéÝ÷ïõí ìéá áíáöïñÜ óå êÜèå ìåôáâëçôÞ ðïõ åßíáé äéáèÝóéìç ìÝóá óôçí global åìâÝëåéá ôïõ script. Ôá êëåéäéÜ áõôïý ôïõ array åßíáé ôá ïíüìáôá ôùí global ìåôáâëçôþí. Ç $GLOBALS õðÜñ÷åé áðü ôçí PHP 3.
Åßíáé ïé ìåôáâëçôÝò ðïõ ïñßæïíôáé áðü ôïí web server Þ äéáöïñåôéêÜ åßíáé Üìåóá óõíäåäåìÝíåò ìå ôï ðåñéâÜëëïí åêôÝëåóçò ôïõ ôñÝ÷ïíôïò script. Åßíáé áíÜëïãåò ìå ôïí ðáëéü $HTTP_SERVER_VARS array (ï ïðïßïò åßíáé áêüìç äéáèÝóéìïò, áëëÜ äå óõíéóôÜôáé).
Åßíáé ïé ìåôáâëçôÝò ðïõ ðáñÝ÷ïíôáé óôï script ìÝóù ôïõ HTTP GET. Åßíáé áíÜëïãåò ìå ôïí ðáëéü $HTTP_GET_VARS array (ï ïðïßïò åßíáé áêüìç äéáèÝóéìïò, áëëÜ äå óõíéóôÜôáé).
Åßíáé ïé ìåôáâëçôÝò ðïõ ðáñÝ÷ïíôáé óôï script ìÝóù ôïõ HTTP POST. Åßíáé áíÜëïãåò ìå ôïí ðáëéü $HTTP_POST_VARS array (ï ïðïßïò åßíáé áêüìç äéáèÝóéìïò, áëëÜ äå óõíéóôÜôáé).
Åßíáé ïé ìåôáâëçôÝò ðïõ ðáñÝ÷ïíôáé óôï script ìÝóù ôçò HTTP cookies. Åßíáé áíÜëïãåò ìå ôïí ðáëéü $HTTP_COOKIE_VARS array (ï ïðïßïò åßíáé áêüìç äéáèÝóéìïò, áëëÜ äå óõíéóôÜôáé).
Åßíáé ïé ìåôáâëçôÝò ðïõ ðáñÝ÷ïíôáé óôï script ìÝóù ôïõ HTTP post file uploads. Åßíáé áíÜëïãåò ìå ôïí $HTTP_POST_FILES array (ï ïðïßïò åßíáé áêüìç äéáèÝóéìïò, áëëÜ äå óõíéóôÜôáé). Äåßôå ôï POST method uploads ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Åßíáé ïé ìåôáâëçôÝò ðïõ ðáñÝ÷ïíôáé óôï script ìÝóù ôïõ environment. Åßíáé áíÜëïãåò ìå ôïí ðáëéü $HTTP_ENV_VARS array (ï ïðïßïò åßíáé áêüìç äéáèÝóéìïò, áëëÜ äå óõíéóôÜôáé).
Åßíáé ïé ìåôáâëçôÝò ðïõ ðáñÝ÷ïíôáé óôï script ìÝóù ôïõ ìç÷áíéóìïý åéóáãùãÞò äåäïìÝíùí áðü ôï ÷ñÞóôçî, êáé óõíåðþò äåí åßíáé áîéüðéóôåò. Ç ðáñïõóßá êáé óåéñÜ ôùí ìåôáâëçôþí ðïõ ðåñéÝ÷ïíôáé óôïí array êáèïñßæåôáé óýìöùíá ìå ôçí variables_order íôéñåêôßâá ãéá configuration. Áõôüò ï ðßíáêáò äåí åßíáé áíÜëïãïò ìå êÜðïéïí Üëëïí óå ðñïçãïýìåíåò åêäüóåéò ôçí PHP ðñïí ôçí 4.1.0. Äåßôå åðßóçò ôçí import_request_variables().
Ðñïóï÷Þ |
Áðü ôçí PHP 4.3.0, ç ðëçñïöïñßá ãéá ôçí FILE áðü ôçí $_FILES äåí õðÜñ÷åé ðéá óôçí $_REQUEST. |
Óçìåßùóç: ¼ôáí ôñÝ÷ïõìå óå command line , áõôü äåí èá óõìðåñéëÜâåé ôçí argv êáé ôçí argc åéóüäïõò. ÁõôÝò åßíáé ðáñïýóåò óôïí $_SERVER ðßíáêá.
Åßíáé ïé ìåôáâëçôÝò ðïõ åßíáé ðñïò ôï ðáñüí åããåãñáììÝíåò óå Ýíá session åíüò script. Åßíáé áíÜëïãåò ìå ôïí ðáëéü $HTTP_SESSION_VARS array (ï ïðïßïò åßíáé áêüìç äéáèÝóéìïò, áëëÜ äå óõíéóôÜôáé). Äåßôå ôï ôìÞìá ×ñçóéìïðïéþíôáò óõíáñôÞóåéò ãéá sessions ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Ç åìâÝëåéá ôùí ìåôáâëçôþí êáèïñßæåôáé áðü ôï ðåñéå÷üìåíï ìÝóá óôï ïðïßï ïñßæåôáé. Ãéá ôçí ðëåéïøçößá ôùí ìåôáâëçôþí ôçò PHP õðÜñ÷åé ìüíï åíüò åßäïõò åìâÝëåéá. ÁõôÞ ç åìâÝëåéá ðåñéÝ÷åé ôüóï ôá áñ÷åßá ðïõ ðåñéÝ÷ïíôáé üóï êáé áõôÜ ðïõ áðáéôïýíôáé. Ãéá ðáñÜäåéãìá:
Åäþ ç ìåôáâëçôÞ $a èá åßíáé äéáèÝóéìç ìÝóá óôï åìðåñéå÷üìåíï b.inc script. ÐÜíôùò, ìÝóá óå óõíáñôÞóåéò ðïõ ïñßæïíôáé áðü ôï ÷ñÞóôç åéóÜãåôáé åìâÝëåéá ôïðéêÞò óõíÜñôçóçò (local function scope). ÏðïéáäÞðïôå ìåôáâëçôÞ ÷ñçóéìïéðïéåßôáé ìÝóá óå ìéá óõíÜñôçóç åßíáé åê ôùí ðñïôÝñùí ðåñéïñéóìÝíç óå åìâÝëåéá ôïðéêÞò óõíÜñôçóçò. Ãéá ðáñÜäåéãìá:
<?php $a = 1; /* global scope */ function Test() { echo $a; /* reference to local scope variable */ } Test(); ?> |
Áõôü ôï script äå èá äþóåé êÜðïéï áðïôÝëåóìá åðåéäÞ ç echo äÞëùóç áíáöÝñåôáé óå ìéá ôïðéêÞ Ýêäïóç ôçò $a ìåôáâëçôÞò, êáé äåí ôçò Ý÷åé áíáôåèåß ìéá ôéìÞ ìÝóá ó'áõôÞ ôçí åìâÝëåéá. ºóùò ðáñáôçñåßóåôå üôé åßíáé ëßãï äéáöïñåôéêÞ áðü ôç C ãëþóóá áðü ôçí Üðïøç üôé ïé global ìåôáâëçôÝò óôç C åßíáé Üìåóá äéáèÝóéìåò óå óõíáñôÞóåéò åêôüò êáé áí åðéêáëýðôïíôáé áõôüìáôá áðü êÜðïéá ôïðéêÞ áíáöïñÜ. Áõôü ìðïñåß íá ðñïêáëÝóåé ìåñéêÜ ðñïâëÞìáôá áí êÜðïéïé, áêïýóéá, áëëÜîïõí ìéá global ìåôáâëçôÞ. Óôçí PHP ïé global ìåôáâëçôÝò ðñÝðåé íá ïñéóôïýí ùò global ìÝóá óôç óõíÜñôçóç áí ðñüêåéôáé íá ÷ñçóéìïðïéçèïýí ó'áõôÞ ôç óõíÜñôçóç. ¸íá ðáñÜäåéãìá :
Ðñþôá, Ýíá ðáñÜäåéãìá áðü ôç ÷ñÞóç ôçò global:
Ôï ðáñáðÜíù script èá äþóåé "3". Äçëþíïíôáò ôçí $a êáé ôçí $b ùò global ìÝóá óå ìéá óõíÜñôçóç, üëåò ïé áíáöïñÝò óå ïðïéáäÞðïôå áðü ôéò ìåôáâëçôÝò èá áíáöÝñïíôáé óôçí global Ýêäïóç. Äåí õðÜñ÷åé ðåñéïñéóìüò óôïí áñéèìü ôùí global ìåôáâëçôþí ðïõ ìðïñåß íá ÷åéñéóôåß ìéá óõíÜñôçóç.
¸íáò äåýôåñïò ôñüðïò ãéá íá ðñïóðåëÜóïõìå ìåôáâëçôÝò áðü global åìâÝëåéá åßíáé íá ÷ñçóéìïðïéÞóïõìå ôïí åéäéêÜ ïñéóìÝíï áðü ôçí PHP $GLOBALS array. Ôï ðñïçãïýìåíï ðáñÜäåéãìá ìðïñåß íá îáíáãñáöôåß ùò:
Ï ðßíáêáò $GLOBALS åßíáé Ýíáò associative array ìå ôï üíïìá ôçò global ìåôáâëçôÞò íá åßíáé ôï êëåéäß êáé ôá ðåñéå÷üìåíá áõôÞò ôçò ìåôáâëçôÞò íá åßíáé ç ôéìÞ ôïõ óôïé÷åßïõ ôïõ array. Óçìåéþóôå ðþò ç $GLOBALS õðÜñ÷åé óå êÜèå åìâÝëåéá, êÜôé ôï ïðïßï óõìâáßíåé åðåéäÞ ç $GLOBALS åßíáé ìéá superglobal. Äåßôå Ýíá ðáñÜäåéãìá ðïõ äåß÷íåé ôç äýíáìç ôùí superglobals:
ÐáñÜäåéãìá 7-3. ÐáñÜäåéãìá ðïõ äåß÷íåé ôéò superglobals êáé ôçí åìâÝëåéá
|
¸íá åðéðëÝïí óçìáíôéêü ÷áñáêôçñéóôéêü ôçò åìâÝëåéáò ìåôáâëçôþí åßíáé ç static ìåôáâëçôÞ. Ìéá óôáôéêÞ ìåôáâëçôÞ õðÜñ÷åé ìüíï óå åìâÝëåéá ôïðéêÞò óõíÜñôçóçò, áëëÜ äåí ÷Üíåé ôçí ôéìÞ ôçò üôáí ç åêôÝëåóç ôïõ ðñïãñÜììáôïò áöÞíåé áõôÞ ôçí åìâÝëåéá. Èåùñåßóôå ôï áêüëïõèï ðáñÜäåéãìá:
ÁõôÞ ç óõíÜñôçóç åßíáé ó÷åäüí Ü÷ñçóôç áöïý êÜèå öïñÜ ðïõ êáëåßôáé èÝôåé ôçí $a óå 0 êáé ôõðþíåé "0". Ç $a++ ç ïðïßá áõîÜíåé ôç ìåôáâëçôÞ äåí åîõðçñåôåß êÜðïéï óêïðü áöïý ìüëéò ç óõíÜñôçóç ôåëåéþóåé ç ìåôáâëçôÞ $a åîáöáíßæåôáé. Ãéá íá öôéÜîïõìå ìéá ÷ñÞóéìç óõíÜñôçóç ìÝôñçóçò ç ïðïßá äåí èá ÷Üíåé ôïí ôñÝ÷ïíôá õðïëïãéóìü, ç ìåôáâëçôÞ $a äçëþíåôáé ùò óôáôéêÞ:
Ôþñá, êÜèå öïñÜ ðïõ èá êáëåßôáé ç óõíÜñôçóç Test() èá ôõðþíåé ôçí ôéìÞ ôçò $a êáé èá ôçí áõîÜíåé.
Ïé óôáôéêÝò ìåôáâëçôÝò åðßóçò ðáñÝ÷ïõí Ýíáí ôñüðï ãéá íá ÷åéñéóôïýìå áíáäñïìéêÝò óõíáñôÞóåéò. Ìéá áíáäñïìéêÞ óõíÜñôçóç åßíáé áõôÞ ðïõ êáëåß ôïí åáõôü ôçò. ÐñÝðåé íá äßíåôáé ðñïóï÷Þ üôáí ãñÜöïõìå ìéá áíáäñïìéêÞ óõíÜñôçóç åðåéäÞ åßíáé ðéèáíü íá ôçí êÜíïõìå íá åðáíáëáìâÜíåôáé áôÝñìïíá. ÐñÝðåé íá âåâáéùèåßôå üôé Ý÷åôå Ýíáí åðáñêÞ ôñüðï ãéá íá ôåñìáôßóåôå ôçí áíáäñïìÞ. Ç áêüëïõèç áðëÞ óõíÜñôçóç áíáäñïìéêÜ ìåôñÜåé ùò ôï 10, ÷ñçóéìïðïéþíôáò ôçí óôáôéêÞ ìåôáâëçôÞ $count ãéá íá îÝñåé ðüôå èá óôáìáôÞóåé:
Ç Zend Engine 1, ðïõ ïäçãåß ôçí PHP4, õëïðïéåß ôïí óôáôéêü êáé global modifier ãéá ôéò ìåôáâëçôÝò üóïí áöïñÜ ôéò áíáöïñÝò. Ãéá ðáñÜäåéãìá ìéá ðñáãìáôéêÞ global ìåôáâëçôÞ ðïõ åéóÜãåôå ìÝóá óå ìéá åìâÝëåéá óõíÜñôçóçò ìå ôç äÞëùóç global óôçí ðñáãìáôéêüôçôá äçìéïõñãåß ìéá áíáöïñÜ óôçí global ìåôáâëçôÞ. Áõôü ìðïñåß íá ïäçãÞóåé óå ìç áíáìåíüìåíç óõìðåñéöïñÜ ðïõ öáßíåôáé óôï áêüëïõèï ðáñÜäåéãìá:
<?php function test_global_ref() { global $obj; $obj = &new stdclass; } function test_global_noref() { global $obj; $obj = new stdclass; } test_global_ref(); var_dump($obj); test_global_noref(); var_dump($obj); ?> |
Åêôåëþíôáò ôï ðáñÜäåéãìá èá Ý÷ïõìå ôï áêüëïõèï áðïôÝëåóìá:
NULL object(stdClass)(0) { } |
Ìéá ðáñüìïéá óõìðåñéöïñÜ åöáñìüæåôáé óôç óôáôéêÞ äÞëùóç. Ïé áíáöïñÝò äåí áðïèçêåýïíôáé óôáôéêÜ:
<?php function &get_instance_ref() { static $obj; echo "Static object: "; var_dump($obj); if (!isset($obj)) { // Assign a reference to the static variable $obj = &new stdclass; } $obj->property++; return $obj; } function &get_instance_noref() { static $obj; echo "Static object: "; var_dump($obj); if (!isset($obj)) { // Assign the object to the static variable $obj = new stdclass; } $obj->property++; return $obj; } $obj1 = get_instance_ref(); $still_obj1 = get_instance_ref(); echo "\n"; $obj2 = get_instance_noref(); $still_obj2 = get_instance_noref(); ?> |
Åêôåëþíôáò ôï ðáñÜäåéãìá èá Ý÷ïõìå ôï áêüëïõèï áðïôÝëåóìá:
Static object: NULL Static object: NULL Static object: NULL Static object: object(stdClass)(1) { ["property"]=> int(1) } |
Áõôü ôï ðáñÜäåéìá äåß÷íåé ðùò üôáí áíáèÝôïõìå ìéá áíáöïñÜ óå ìéá óôáôéêÞ ìåôáâëçôÞ, äåí ìÝíåé óôç ìíÞìç üôáí êáëåßôå ôç óõíÜñôçóç &get_instance_ref() ãéá äåýôåñç öïñÜ.
ÌåñéêÝò öïñÝò åßíáé âïëéêü íá ìðïñïýìå íá Ý÷ïõìå ìåôáâëçôÜ ïíüìáôá ìåôáâëçôþí. Áõôü óçìáßíåé ðùò, Ýíá üíïìá ìåôáâëçôÞò ìðïñåß íá ïñéóôåß êáé íá ÷ñçóéìïðïéçèåß äõíáìéêÜ. Ìéá êáíïíéêÞ ìåôáâëçôÞ ïñßæåôáé ìå ìéá äÞëùóç üðùò:
Ìéá ìåôáâëçôÞ ìåôáâëçôÞò ðáßñíåé ôçí ôéìÞ ìéáò ìåôáâëçôÞò êáé ôçò óõìðåñéöÝñåôáé ùò üíïìá ìåôáâëçôÞò. Óôï ðáñáðÜíù ðáñÜäåéãìá, ç hello, ìðïñåß íá ÷ñçóéìïðïéçèåß ùò ôï üíïìá ôçò ìåôáâëçôÞò ÷ñçóéìïðïéþíôáò ôï óýìâïëï ôïõ äïëáñßïõ äõï öïñÝò. ð.÷.
Ó'áõôü ôï óçìåßï äõï ìåôáâëçôÝò Ý÷ïõí ïñéóôåß êáé áðïèçêåõôåß óôï äÝíôñï óõìâüëùí (symbol tree) ôçò PHP : ç $a ìå ðåñéå÷üìåíï "hello" êáé ç $hello ìå ðåñéå÷üìåíï "world". Óõíåðþò, áõôÞ ç äÞëùóç:
ðáñÜãåé áêñéâþò ôï ßäéï áðïôÝëåóìá üðùò ç:
ð.÷. êáé ïé äõï ðáñÜãïõí: hello world.
ÐñïêåéìÝíïõ íá ÷ñçóéìïðïéÞóåôå ìåôáâëçôÝò ìåôáâëçôþí ìå arrays, ðñÝðåé íá ëýóåôå ôï ðñüâëçìá ôçò áóÜöåéáò. ÄçëáäÞ, áí ãñÜöåôå $$a[1] ôüôå ï parser ÷ñåéÜæåôáé íá îÝñåé áí èÝëåôå íá ÷ñçóéìïðïéÞóåôå ôçí $a[1] ùò ìåôáâëçôÞ, Þ áí èÝëåôå ôçí $$a ùò ìåôáâëçôÞ êáé óõíåðþò ôï [1] index áðü áõôÞ ôç ìåôáâëçôÞ. Ç óýíôáîç ãéá íá ëýóïõìå áõôÞ ôçí áóÜöåéá åßíáé: ${$a[1]} ãéá ôçí ðñþôç ðåñßðôùóç êáé ${$a}[1] ãéá ôç äåýôåñç.
Ðñïåéäïðïßçóç |
Ðáñáêáëþ óçìåéþóôå üôé ïé ìåôáâëçôÝò ìåôáâëçôþí äåí ìðïñïýí íá ÷ñçóéìïðïéçèïýí ìå ôïõò Superglobal arrays ôçò PHP. Áõôü óçìáßíåé üôé äåí ìðïñåßôå íá êÜíåôå ðñÜãìáôá üðùò ${$_GET}. Áí øÜ÷íåôå Ýíáí ôñüðï ãéá íá ÷åéñéóôåßôå ôç äéáèåóéìüôçôá ôùí superglobals êáé ôçò ðáëéÜò HTTP_*_VARS, ßóùò ðñÝðåé íá ÷ñçóéìïðïéÞóåôå ôçí áíáöïñÜ ìåôáîý áõôþí. |
¼ôáí ìéá öüñìá åéóÜãåôáé óå Ýíá PHP script, ç ðëçñïöïñßá áðü ôç öüñìá ãßíåôáé áõôüìáôá äéáèÝóéìç óôï script. ÕðÜñ÷ïõí ðïëëïß ôñüðïé ãéá íá ðñïóðåëÜóåôå ôçí ðëçñïöïñßá, ãéá ðáñÜäåéãìá:
ÁíÜëïãá ìå ôï éäéáßôåñï setup êáé ôéò ðñïóùðéêÝò ðñïôéìÞóåéò, õðÜñ÷ïõí ðïëëïß ôñüðïé ãéá íá ðñïóðåëÜóåôå ôá äåäïìÝíá áðü ôéò HTML öüñìåò óáò. ÌåñéêÜ ðáñáäåßãìáôá åßíáé:
ÐáñÜäåéãìá 7-8. Ðñïóðåëáýíïíôáò äåäïìÝíá áðü ìéá áðëÞ POST HTML öüñìá
|
Ç ÷ñÞóç ìéáò GET öüñìáò åßíáé ðáñüìïéá åêôüò áðü ôï üôé ðñÝðåé íá ÷ñçóéìïðïéÞóåôå ôçí êáôÜëëçëç ðñïêáèïñéóìÝíç ìåôáâëçôÞ GET. Ç GET åðßóçò ÷ñçóéìïðïéåßôáé óôï QUERY_STRING (ç ðëçñïöïñßá ìåôÜ ôï '?' óå Ýíá URL). Óõíåðþò, ãéá ðáñÜäåéãìá ç http://www.example.com/test.php?id=3 ðåñéÝ÷åé GET äåäïìÝíá ôá ïðïßá åßíáé ðñïóðåëÜóéìá ìå ôçí $_GET['id']. Äåßôå åðßóçò ôçí $_REQUEST êáé ôçí import_request_variables().
Óçìåßùóç: Ïé superglobal arrays, üðùò ï $_POST êáé ï $_GET, Ýãéíáí äéáèÝóéìïé óôçí PHP 4.1.0
¼ðùò äåßîáìå, ðñéí ôçí PHP 4.2.0 ç ðñïêáèïñéóìÝíç ôéìÞ ãéá ôç register_globals Þôáí on. Êáé óôçí PHP 3 Þôáí ðÜíôá on. Ç êïéíüôçôá ôçò PHP åíèáññýíåé üëïõò íá ìçí âáóßæïíôáé ó'áõôÞ ôçí íôéñåêôßâá êáèþò ðñïôéìÜôáé íá õðïèÝôïõìå üôé åßíáé off êáé íá ãñÜöïõìå êþäéêá óýìöùíá ìå áõôÞ ôçí õðüèåóç.
Óçìåßùóç: Ç magic_quotes_gpc configuration íôéñåêôßâá åðçñåÜæåé ôéò ôéìÝò ôçò Get, ôçò Post êáé ôçò Cookie. Áí ãßíåé on, ç ôéìÞ (It's "PHP!") èá ãßíåé áõôüìáôá (It\'s \"PHP!\"). ×ñåéÜæåôáé íá ãßíåé escape ãéá åéóáãùãÞ åéóáãùãéêþí. Äåßôå åðßóçò ôéò addslashes(), stripslashes() êáé magic_quotes_sybase.
Ç PHP åðßóçò êáôáëáâáßíåé arrays ó÷åôéêÜ ìå ôï ðåñéå÷üìåíï áðü ôéò ìåôáâëçôÝò öïñìþí (äåßôå ôï ó÷åôéêü faq). ºóùò, ãéá ðáñÜäåéãìá ïìáäïðïéÞóåôå ó÷åôéêÝò ìåôáâëçôÝò ìáæß, Þ ÷ñçóéìïðïéÞóåôå áõôü ôï ÷áñáêôçñéóôéêü ãéá íá ðÜñåôå ôéìÝò áðü Ýíá multiple select input. Ãéá ðáñÜäåéãìá, áò óôåßëïõìå ìéá öüñìá óôïí åáõôü ôçò êáé ìåôÜ ôçí õðïâïëÞ åìöáíéóôïýí ôá äåäïìÝíá:
ÐáñÜäåéãìá 7-9. Ðåñéóóüôåñåò óýíèåôåò ìåôáâëçôÝò öïñìþí
|
Óôçí PHP 3, ç ÷ñÞóç ôçò ìåôáâëçôÞò array ôçò öüñìáò åßíáé ðåñéïñéóìÝíç óå ìïíïäéÜóôáôïõò arrays. Óôçí PHP 4, äåí åöáñìüæïíôáé ôÝôïéïé ðåñéïñéóìïß.
¼ôáí åéóÜãåôå ìéá öüñìá, åßíáé äõíáôü íá ÷ñçóéìïðïéÞóåôå ìéá åéêüíá áíôß ãéá ôï êáèéåñùìÝíï êïõìðß õðïâïëÞò ìå Ýíá tag óáí êáé áõôü:
¼ôáí ï ÷ñÞóôçò êÜíåé êëßê êÜðïõ óôçí åéêüíá, ç áêüëïõèç öüñìá èá ìåôáöåñèåß óôïí server ìå äõï åðéðñüóèåôåò ìåôáâëçôÝò, ôçí sub_x êáé ôçí sub_y. ÁõôÝò ðåñéÝ÷ïõí ôéò óõíôåôáãìÝíåò ôïõ óçìåßïõ ðïõ Ýêáíå êëéê ï ÷ñÞóôçò ìÝóá óôçí åéêüíá. Ï Ýìðåéñïò ÷ñÞóôçò ßóùò ðáñáôçñÞóåé üôé ôá ðñáãìáôéêÜ ïíüìáôá ìåôáâëçôþí ðïõ óôÜëèçêáí áðü ôïí browser ðåñéÝ÷ïõí ìéá period ðáñÜ Ýíá underscore, áëëÜ ç PHP ìåôáôñÝðåé áõôÞ ôçí period óå Ýíá underscore áõôüìáôá.
Ç PHP ìå äéáöÜíåéá õðïóôçñßæåé ôá HTTP cookies üðùò Ý÷ïõí ïñéóôåß óôï Netscape's Spec. Ôá cookies åßíáé Ýíáò ìç÷áíéóìüò áðïèÞêåõóçò äåäïìÝíùí óå Ýíáí áðïìáêñõóìÝíï browser ãéá ôïí åíôïðéóìü êáé áíáãíþñéóç ÷ñçóôþí ðïõ îáíáåðéóêÝðôïíôáé óôï site. Ìðïñåßôå íá ïñßóåôå cookies ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç setcookie() . Ôá cookies åßíáé ìÝñïò ôïõ HTTP header, óõíåðþò ç óõíÜñôçóç SetCookie ðñÝðåé íá êáëåßôáé ðñéí ôï áðïôÝëåóìá óôáëåß óôïí browser. Áõôü Ý÷åé ôïõò ßäéïõò ðåñéïñéóìïýò üðùò êáé óôç óõíÜñôçóç header(). Ôá äåäïìÝíá ôùí cookies åßíáé åí óõíå÷åßá äéáèÝóéìá óôïõò êáôÜëëçëïõò cookie data arrays, üðùò ï $_COOKIE, ï $HTTP_COOKIE_VARS êáèùå åðßóçò êáé ï $_REQUEST. Äåßôå ôçí setcookie() óôç óåëßäá ôïõ manual ãéá ðåñéóóüôåñåò ðëçñïöïñßåò êáé ðáñáäåßãìáôá.
Áí åðéèõìåßôå íá áíáèÝóåôå ðïëëáðëÝò ôéìÝò óå ìéá ìüíï ìåôáâëçôÞ cookie, ìðïñåßôå íá êÜíåôå ôçí áíÜèåóç áõôÞ üðùò êáé óå Ýíáí array. Ãéá ðáñÜäåéãìá:
<?php setcookie("MyCookie[foo]", "Testing 1", time()+3600); setcookie("MyCookie[bar]", "Testing 2", time()+3600); ?> |
Áõôü èá äçìéïõñãÞóåé äõï äéáöïñåôéêÜ cookies ðáñüëïõ ðïõ ôï MyCookie èá åßíáé ôþñá Ýíá áðëü array óôï script óáò. Áí èÝëåôå íá ïñßóåôå áêüìç Ýíá cookie ìå ðïëëáðëÝò ôéìÝò, ÷ñçóéìïðïéåßóôå ôçí serialize() Þ ôçí explode() ðñþôá óôçí ôéìÞ.
Óçìåéþóôå üôé Ýíá cookie èá áíôéêáôáóôÞóåé Ýíá ðñïçãïýìåíï cookie ìå ôï ßäéï üíïìá óôïí browser óáò åêôüò êáé áí ôï path Þ ôï domain åßíáé äéáöïñåôéêü. Óõíåðþò, ãéá ìéá åöáñìïãÞ åíüò shopping cart ßóùò ÷ñåéáóôåß íá êñáôÞóåôå Ýíáí ìåôñçôÞ êáé íá ôïí ðåñÜóåôå. ð.÷.
ÐáñÜäåéãìá 7-10. ¸íá ðáñÜäåéãìá ìå ôçí setcookie()
|
ÔõðéêÜ, ç PHP äåí áëëÜæåé ôá ïíüìáôá ôùí ìåôáâëçôþí üôáí áõôÜ ðåñíéïýíôáé óå Ýíá script. ÐÜíôùò, ðñÝðåé íá óçìåéùèåß üôé ç ôåëåßá dot (period, full stop) äåí åßíáé Ýíáò Ýãêõñïò ÷áñáêôÞñáò óôçí PHP ãéá ïíüìáôá ìåôáâëçôþí. Ãé'áõôü ôï ëüãï, äåßôå áõôü:
<?php $varname.ext; /* invalid variable name */ ?> |
Ãé'áõôü ôï ëüãï, åßíáé óçìáíôéêü íá óçìåéþóïõìå üôé ç PHP èá áíôéêáôáóôÞóåé áõôüìáôá üëåò ôéò ôåëåßåò óå åóùôåñéêÜ ïíüìáôá ìåôáâëçôþí, ìå underscores.
ÅðåéäÞ ç PHP êáèïñßæåé ôïõò ôýðïõò ôùí ìåôáâëçôþí êáé ôïõò ìåôáôñÝðåé (ãåíéêÜ) üðùò ÷ñåéÜæåôáé, äåí åßíáé ðÜíôá ðñïöáíÝò ôé ôýðïõ åßíáé ìéá äåäïìÝíç ìåôáâëçôÞ ïðïéáäÞðïôå óôéãìÞ. Ç PHP ðåñéÝ÷åé äéÜöïñåò óõíáñôÞóåéò ïé ïðïßåò âñßóêïõí ôé ôýðï Ý÷åé êÜèå ìåôáâëçôÞ, üðùò ïé: gettype(), is_array(), is_float(), is_int(), is_object(), êáé ç is_string(). Äåßôå åðßóçò ôï êåöÜëáéï ó÷åôéêÜ ìå ôïõò Ôýðïõò.
Ìéá óôáèåñÜ åßíáé Ýíáò identifier (üíïìá) ãéá ìéá áðëÞ ôéìÞ. ¼ðùò öáßíåôáé êáé áðü ôï üíïìá, áõôÞ ç ôéìÞ äåí ìðïñåß íá áëëÜîåé êáôÜ ôçí åêôÝëåóç ôïõ script. (Ïé 'ìáãéêÝò óôáèåñÝò' __FILE__ êáé __LINE__ öáßíåôáé íá åßíáé åîáßñåóç ó'áõôüí ôïí êáíüíá, áëëÜ äåí åßíáé ðñáãìáôéêÝò óôáèåñÝò.) Åßíáé ðñïêáèïñéóìÝíï ðùò ìéá óôáèåñÜ åßíáé case-sensitive. ÊáôÜ óõíèÞêç ïé constant identifiers åßíáé ðÜíôá óôá êåöáëáßá.
Ôï üíïìá ìéáò óôáèåñÜò áêïëïõèåß ôïõò ßäéïõò êáíüíåò üðùò êáé ïðïéáäÞðïôå åôéêÝôá (label) óôçí PHP. ¸íá Ýãêõñï üíïìá óôáèåñÜò áñ÷ßæåé ìå Ýíá ãñÜììá Þ underscore, áêïëïõèïýìåíï áðü ïðïéïíäÞðïôå áñéèìü ãñáììÜôùí, áñéèìþí Þ underscore. Ùò regular expression, èá åêöñáæüôáí ùò åîÞò: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
Óçìåßùóç: Ãéá ôïõò óêïðïýò ìáò åäþ, Ýíá ãñÜììá åßíáé áðü ôï a-z, A-Z, êáé ïé ASCII ÷áñáêôÞñåò áðü ôï 127 ìÝ÷ñé ôï 255 (0x7f-0xff).
¼ðùò ïé superglobals, ç åìâÝëåéá (scope) ìéáò óôáèåñÜò åßíáé global. Ìðïñåßôå íá Ý÷åôå ðñüóâáóç ó' áõôÞ áðü ïðïéïäÞðïôå ìÝñïò óôï script ÷ùñßò íá ëáìâÜíåôå õðüøç ôçí åìâÝëåéá. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôçí åìâÝëåéá, äéáâÜóôå ôï ôìÞìá ôïõ manual ó÷åôéêÜ ìå ôçí åìâÝëåéá ôùí ìåôáâëçôþí.
Ìðïñåßôå íá ïñßóåôå ìéá óôáèåñÜ ÷ñçóéìïðïéþíôáò ôçí define()-óõíÜñôçóç. Ìüëéò ìéá óôáèåñÜ ïñéóôåß, äåí ìðïñåß ðïôÝ íá áëëÜîåé Þ íá ìçí åßíáé ïñéóìÝíç.
Ìüíï scalar (âáèìùôÜ) äåäïìÝíá (boolean, integer, float êáé string) ìðïñïýí íá óõìðåñéëáìâÜíïíôáé óôéò óôáèåñÝò.
Ìðïñåßôå íá ðÜñåôå ôçí ôéìÞ ìéáò óôáèåñÜò áðëÜ êáëþíôáò ôçí ìå ôï üíïìá ôçò. Óå áíôßèåóç ìå ôéò ìåôáâëçôÝò, äåí èá ðñÝðåé íá âÜæåôå ìðñïóôÜ áðü ìéá óôáèåñÜ ôï $. Ìðïñåßôå åðßóçò íá ÷ñçóéìïðïéÞóåôå ôç óõíÜñôçóç constant(), ãéá íá äéáâÜóåôå ôçí ôéìÞ ìéáò óôáèåñÜò, áí èÝëåôå íá ðÜñåôå ôï üíïìá ìéáò óôáèåñÜò äõíáìéêÜ. ×ñçóéìïðïéåßóôå ôçí get_defined_constants() ãéá íá ðÜñåôå ìéá ëßóôá üëùí ôùí óôáèåñþí ðïõ Ý÷ïõí ïñéóôåß.
Óçìåßùóç: Ïé óôáèåñÝò êáé ïé (global) ìåôáâëçôÝò åßíáé óå äéáöïñåôéêü namespace. Áõôü óçìáßíåé ðùò ãéá ðáñÜäåéãìá ôï TRUE êáé ôï $TRUE åßíáé ãåíéêþò äéáöïñåôéêÜ.
Áí ÷ñçóéìïðïéåßôå ìßá ìç êáèïñéóìÝíç óôáèåñÜ, ç PHP õðïèÝôåé üôé åííïåßôå ôï üíïìá ôçò ßäéáò ôçò óôáèåñÜò, óáí íá åß÷áôå êáëÝóåé ùò string (CONSTANT åíáíôßïí "CONSTANT"). ¸íá ëÜèïò åðéðÝäïõ E_NOTICE èá åìöáíéóôåß üôáí áõôü óõìâåß. Äåßôå åðßóçò êáé ôï manual ó÷åôéêÜ ìå ôï ãéáôß $foo[bar] åßíáé ëáíèáóìÝíï (åêôüò êáé áí ðñþôá Ý÷åôå ïñßóåé, define(), ôçí bar ùò óôáèåñÜ). Áí áðëÜ èÝëåôå íá åëÝíîåôå áí ç óôáèåñÜ Ý÷åé ïñéóôåß, ÷ñçóéìïðïéåßóôå ôç óõíÜñôçóç defined().
Oé äéáöïñÝò ìåôáîý óôáèåñþí êáé ìåôáâëçôþí åßíáé ïé åîÞò:
Ïé óôáèåñÝò äåí Ý÷ïõí ôï óýìâïëï ôïõ äïëáñßïõ ($) ìðñïóôÜ ôïõò.
Ïé óôáèåñÝò ìðïñïýí íá ïñéóôïýí ìüíï ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç define() êáé ü÷é ìå áðëÞ áíÜèåóç.
Ïé óôáèåñÝò ìðïñïýí íá ïñéóôïýí êáé íá ðñïóðåëáóôïýí áðü ïðïõäÞðïôå ÷ùñßò íá ëÜâïõìå õðüøç ôïõò êáíüíåò åìâÝëåéáò ìåôáâëçôþí.
Ïé óôáèåñÝò äåí ìðïñïýí íá ïñéóôïýí îáíÜ Þ íá ìçí åßíáé êáèïñéóìÝíåò áðü ôç óôéãìÞ ðïõ Ý÷ïõí ïñéóôåß.
Ïé óôáèåñÝò ìðïñïýí íá õðïëïãßóïõí ìüíï âáèìùôÝò ôéìÝò.
Ç PHP ðáñÝ÷åé Ýíá ìåãÜëï áñéèìü áðü ðñïêáèïñéóìÝíåò óôáèåñÝò óå ïðïéïäÞðïôå script ðïõ åêôåëåßôáé. ¼ìùò, ðïëëÝò áðü áõôÝò ôéò óôáèåñÝò äçìéïõñãïýíôáé áðü äéÜöïñåò åðåêôÜóåéò, êáé åìöáíßæïíôáé ìüíï üôáí áõôÝò ïé åðåêôÜóåéò åßíáé äéáèÝóéìåò, åßôå ìÝóù äõíáìéêïý öïñôþìáôïò (dynamic loading) åßôå åðåéäÞ Ý÷ïõí ìåôáãëùôôéóôåß.
ÕðÜñ÷ïõí ôÝóóåñéò ìáãéêÝò óôáèåñÝò ðïõ áëëÜæïõí áíÜëïãá ìå ôï ðïý ÷ñçóéìïðïéïýíôáé. Ãéá ðáñÜäåéãìá, ç ôéìÞ ôçò __LINE__ åîáñôÜôáé áðü ôç ãñáììÞ ðïõ ÷ñçóéìïðïéåßôáé óôï script. ÁõôÝò ïé éäéáßôåñåò óôáèåñÝò åßíáé case-insensitive êáé Ý÷ïõí ùò áêïëïýèùò:
Ðßíáêáò 8-1. ÌåñéêÝò "ìáãéêÝò" óôáèåñÝò ôçò PHP
¼íïìá | ÐåñéãñáöÞ |
---|---|
__LINE__ | Ï ôñÝ÷ïí áñéèìüò ãñáììÞò ôïõ áñ÷åßïõ. |
__FILE__ | Ïëüêëçñç ç äéåýèõíóç (full path) êáé ôï üíïìá ôïõ áñ÷åßïõ. |
__FUNCTION__ | Ôï üíïìá ôçò óõíÜñôçóçò. (Áõôü ðñïóôÝèçêå óôçí PHP 4.3.0.) |
__CLASS__ | The class name. (This was added in PHP 4.3.0.) |
__METHOD__ | Ôï üíïìá ôçò êëÜóçò. (Áõôü ðñïóôÝèçêå óôçí PHP 4.3.0.) |
Ìéá ëßóôá ðñïêáèïñéóìÝíùí óôáèåñþí åßíáé äéáèÝóéìç óôçí ðáñÜãñáöï ãéá ôéò ÄåóìåõìÝíåò ðñïêáèïñéóìÝíåò óôáèåñÝò.
Ïé åêöñÜóåéò (expressions) åßíáé ôï ðéï óçìáôéêü êïììÜôé ôçò PHP. Óôçí PHP, ó÷åäüí üëá üóá ãñÜöåôå åßíáé åêöñÜóåéò. Ï áðëïýóôåñïò êáé óõã÷ñüíùò ï ðéï áêñéâÞò ôñüðïò ãéá íá ïñßóïõìå ìéá Ýêöñáóç åßíáé "ïôéäÞðïôå Ý÷åé ôéìÞ".
Ïé ðéï âáóéêÝò ìïñöÝò åêöñÜóåùí åßíáé ïé óôáèåñÝò êáé ïé ìåôáâëçôÝò. ¼ôáí ãñÜöåôå "$a = 5", áíáèÝôå ôçí ôéìÞ '5' óôç ìåôáâëçôÞ $a. Ôï '5', ðñïöáíþò, Ý÷åé ôçí ôéìÞ 5, Þ ìå Üëëá ëüãéá ôï '5' åßíáé ìéá Ýêöñáóç ìå ôçí ôéìÞ 5 (ó'áõôÞ ôçí ðåñßðôùóç, ôï '5' åßíáé ìéá áêÝñáéá óôáèåñÜ).
ÌåôÜ áðü áõôÞ ôçí áíÜèåóç, èá ðåñéìÝíáôå ç ôéìÞ ôïõ $a íá åßíáé åðßóçò 5, Ýôóé þóôå áí ãñÜøåôå $b = $a, èá ðåñéìÝíåôå íá Ý÷åôå ôï ßäéï áðïôÝëåóìá ìå ôï áõôü ðïõ èá åß÷áôå áí ãñÜöáôå üôé $b = 5. Ìå Üëëá ëüãéá, ç $a åßíáé ìéá Ýêöñáóç ìå ôçí ôéìÞ 5 åðßóçò. Áí üëá äïõëÝøïõí óùóôÜ, áõôü áêñéâþò èá óõìâåß.
Åëáöñþò ðéï ðåñßðëïêá ðáñáäåßãìáôá óôéò åêöñÜóåéò åßíáé ïé óõíáñôÞóåéò. Ãéá ðáñÜäåéãìá, èåùñåßóôå ôçí áêüëïõèç óõíÜñôçóç:
ÕðïèÝôïíôáò üôé åßóôå åîïéêåéùìÝíïé ìå ôçí Ýííïéá ôùí óõíáñôÞóåùí (áí äåí åßóôå áíáôñÝîôå óôï êåöÜëáéï ôï ó÷åôéêü ìå ôéò óõíáñôÞóåéò), èá õðïèÝóåôå üôé ãñÜöïíôáò $c = foo() åßíáé ïõóéáóôéêÜ ßäéï ìå ôï íá ãñÜøåôå $c = 5, êáé Ý÷åôå äßêéï. Ïé óõíáñôÞóåéò åßíáé åêöñÜóåéò ìå ôçí ôéìÞ ôçò åðéóôñåöüìåíçò ôéìÞò. Áöïý ôï foo() åðéóôñÝöåé 5, ç ôéìÞ ôçò Ýêöñáóçò 'foo()' åßíáé 5. ÓõíÞèùò ïé óõíáñôÞóåéò äåí åðéóôñÝöïõí áðëÜ ìéá óôáôéêÞ ôéìÞ áëëÜ õðïëïãßæïõí êÜôé.
ÖõóéêÜ, ïé ôéìÝò óôçí PHP äåí åßíáé õðï÷ñåùôéêÜ áêÝñáéïé, êáé ðïëý óõ÷íÜ äåí åßíáé. Ç PHP õðïóôçñßæåé ôñåéò âáèìùôïýò ôýðïõò: áêÝñáéåò ôéìÝò, ôéìÝò êéíçôÞò õðïäéáóôïëÞò êáé óõìâïëïóåéñÝò (ïé âáèìùôÝò ôéìÝò åßíáé ôéìÝò ðïõ äåí ìðïñïýìå íá "óðÜóïõìå" óå ìéêñüôåñá êïììÜôéá, óå áíôßèåóç ìå ôïõò ðßíáêåò, ãéá ðáñÜäåéãìá). Ç PHP åðßóçò õðïóôçñßæåé äõï óýíèåôïõò (ìç âáèìùôïýò) ôýðïõò: ôïõò ðßíáêåò (arrays) êáé ôá áíôéêåßìåíá (objects). Ï êÜèå Ýíáò áðü áõôïýò ôïõò ôýðïõò ôéìþí ìðïñåß íá áíáôåèåß óå ìåôáâëçôÝò Þ íá åðéóôñáöåß (returned) áðü óõíáñôÞóåéò.
ÌÝ÷ñé óôéãìÞò, ïé ÷ñÞóôåò ôçò PHP/FI 2 äå èá âñïýí êÜðïéá äéáöïñÜ. Ðáñ' üëá áõôÜ, ç PHP ðñï÷ùñÜåé ôéò åêöñÜóåéò ðéï ìáêñéÜ, êáôÜ ôïí ßäéï ôñüðï ðïõ ôï êÜíïõí êáé Üëëåò ãëþóóåò. Ç PHP åßíáé ìéá ãëþóóá ðñïóáíáôïëéóìÝíç óôéò åêöñÜóåéò (expression-oriented), ìå ôçí Ýííïéá üôé ó÷åäüí ôá ðÜíôá åßíáé åêöñÜóåéò. Èåùñåßóôå ôï ðáñÜäåéãìá ìå ôï ïðïßï Ý÷ïõìå Þäç áó÷ïëçèåß, '$a = 5'. Åßíáé åýêïëï íá äåßôå üôé õðÜñ÷ïõí äýï ôéìÝò åäþ, ç ôéìÞ ôçò áêÝñáéáò óôáèåñÜò '5', êáé ç ôéìÞ ôçò ìåôáâëçôÞò $a ç ïðïßá ðáßñíåé åðßóçò ôçí ôéìÞ 5. ÁëëÜ ç áëÞèåéá åßíáé üôé õðÜñ÷åé ìéá åðéðñüóèåôç ôéìÞ ðïõ åìðëÝêåôáé åäþ, êáé áõôÞ åßíáé ç ôéìÞ ôçò ßäéáò ôçò áíÜèåóçò. Ç ßäéá ç áíÜèåóç (assignment) ðáßñíåé ôçí áíáôéèÝìåíç ôéìÞ, ðïõ óôçí ðåñßðôùóç ìáò åßíáé ç 5. ÐñáêôéêÜ, áõôü óçìáßíåé üôé '$a = 5',áó÷Ýôùò áðü ôï ôé êÜíåé, åßíáé ìéá Ýêöñáóç ìå ôéìÞ ßóç ìå 5. Óõíåðþò, ãñÜöïíôáò êÜôé óáí '$b = ($a = 5)' åßíáé óá íá ãñÜöïõìå '$a = 5; $b = 5;' (ôï åñùôçìáôéêü ïñßæåé ôï ôÝëïò ìéáò Ýêöñáóçò). Áöïý ïé áíáèÝóåéò ìåôáãëùôßæïíôáé áðü äåîéÜ ðñïò ôá áñéóôåñÜ, ìðïñåßôå åðßóçò íá ãñÜøåôå '$b = $a = 5'.
¸íá áêüìç êáëü ðáñÜäåéãìá ó÷åôéêÜ ìå åêöñÜóåéò åßíáé ç ðñéí (pre-) êáé ìåôÜ (post-) áýîçóç êáé ìåßùóç. Ïé ÷ñÞóôåò ôçò PHP/FI 2 êáé ðïëëþí Üëëùí ãëùóóþí ßóùò Ý÷ïõí êÜðïéá ïéêåéüôçôá ìå ôç ìïñöÞ variable++ êáé variable--. Áõôïß åßíáé ïé ôåëåóôÝò áýîçóçò êáé ìåßùóçò. Óôçí PHP/FI 2, ç äÞëùóç '$a++' äåí Ý÷åé ôéìÞ (äåí åßíáé Ýêöñáóç), êáé óõíåðþò äåí ìðïñåßôå íá ôçí áíáèÝóåôå ïýôå íá ôçí ÷ñçóéìïðïéÞóåôå. Ç PHP áõîÜíåé ôéò äõíáôüôçôåò áýîçóçò/ìåßùóçò ÷ñçóéìïðïéþíôáò áõôÝò ôçò åêöñÜóåéò üðùò êáé ç C. Óôçí PHP, üðùò êáé óôç C, õðÜñ÷ïõí äõï ôýðïé áýîçóçò - ç (ðñï) pre-increment êáé ç (ìåôÜ) post-increment. Êáé ïé äõï ïõóéáóôéêÜ áõîÜíïõí ôçí ôéìÞ ôçò ìåôáâëçôÞò, êáé ç åðßäñáóç ôïõò óôçí ìåôáâëçôÞ åßíáé ç ßäéá. Ç äéáöïñÜ åßíáé óôçí ôéìÞ ôçò ìåôáâëçôÞò ðïõ áõîÜíåôáé. Ç pre-increment, ç ïðïßá ãñÜöåôáé '++$variable', ðáßñíåé ôçí áõîáíüìåíç ôéìÞ (ç PHP áõîÜíåé ôç ìåôáâëçôÞ ðñéí äéáâÜóåé ôçí ôéìÞ ôçò, åîïý êáé (ðñï)'pre-increment'). Ç post-increment, ç ïðïßá ãñÜöåôáé '$variable++' ðáßñíåé ôçí áñ÷éêÞ ôéìÞ ôçò ìåôáâëçôÞò $variable, ðñéí áõôÞ áõîçèåß (ç PHP áõîÜíåé ôç ìåôáâëçôÞ áöïý äéáâÜóåé ôçí ôéìÞ ôçò, åîïý êáé ôï üíïìá (ìåôÜ) 'post-increment')
¸íáò ðïëý êïéíüò ôýðïò åêöñÜóåùí åßíáé ïé óõãêñßóåéò. ÁõôÝò ïé åêöñÜóåéò ðáßñíïõí åßôå ôçí ôéìÞ 0 åßôå ôçí ôéìÞ 1, äçëáäÞ FALSE Þ TRUE (áíôßóôïé÷á). Ç PHP õðïóôçñßæåé ôá > (ìåãáëýôåñï áðü), >= (ìåãáëýôåñï áðü Þ ßóï ìå), == (ßóï), != (ü÷é ßóï), < (ìéêñüôåñï áðü) êáé <= (ìéêñüôåñï Þ ßóï ìå). ÁõôÝò ïé åêöñÜóåéò ÷ñçóéìïðïéïýíôáé óõíÞèùò ìÝóá óå õðïèÝóåéò, üðùò ïé if äçëþóåéò.
Ôï ôåëåõôáßï ðáñÜäåéãìá åêöñÜóåùí ìå ôï ïðïßï èá áó÷ïëçèïýìå åßíáé ïé óýíèåôåò åêöñÜóåéò ôåëåóôþí-áíáèÝóåùí. Èá îÝñåôå Þäç üôé áí èÝëåôå íá áõîÞóåôå ôï $a êáôÜ 1, ìðïñåßôå áðëÜ íá ãñÜøåôå '$a++' Þ '++$a'. ÁëëÜ ôé ãßíåôáé íá èÝëåôå íá ðñïóèÝóåôå ðåñéóóüôåñá áðü Ýíá, 3 ãéá ðáñÜäåéãìá? Èá ìðïñïýóáôå íá ãñÜøåôå '$a++' ðïëëÝò öïñÝò, áëëÜ áõôü ðñïöáíþò äåí åßíáé Ýíáò ðïëý áðïôåëåóìáôéêüò Þ Üíåôïò ôñüðïò. Ìéá ðéï êïéíÞ ôáêôéêÞ åßíáé íá ãñÜøåôå '$a = $a + 3'. Ôï '$a + 3' õðïëïãßæåé ôçí ôéìÞ ôïõ $a óõí 3, êáé áíáèÝôåé ôçí ôéìÞ áõôÞ ðßóù óôçí $a, ç ïðïßá êáôáëÞãåé óôï íá áõîçèåß êáôÜ 3. Óôçí PHP, üðùò êáé óå ðïëëÝò Üëëåò ãëþóóåò óõìðåñéëáìâáíïìÝíçò êáé ôçò C, ìðïñåßôå íá ãñÜøåôå ôï ðáñáðÜíù ìå Ýíá óõíôïìüôåñï ôñüðï, ôï ïðïßï èá ãßíåé ðéï îåêÜèáñï êáé ðéï ãñÞãïñï óôï íá ôï êáôáëÜâåôå êáëÜ. Ç ðñüóèåóç ôïõ 3 óôçí ôñÝ÷ïõóá ôéìÞ ôïõ $a ìðïñåß íá ãñáöåß ùò '$a += 3'. Áõôü áêñéâþò óçìáßíåé "ðÜñå ôçí ôéìÞ ôïõ $a, ðñüóèåóå 3 ó' áõôÞí, êáé áíÜèåóå ôçí ðÜëé óôçí $a". ÐñïêåéìÝíïõ íá ãßíïõìå ðéï ãñÞãïñïé êáé ðéï óáöåßò, ì'áõôüí ôïí ôñüðï êáôáëÞãïõìå óå ôá÷ýôåñç åêôÝëåóç. Ç ôéìÞ ôïõ '$a += 3', üðùò êáé ç ôéìÞ ìéáò êáíïíéêÞò (regular) áíÜèåóçò, åßíáé ç ôéìÞ ðïõ Ý÷åé áíáôåèåß. Óçìåéþóôå üôé ÄÅÍ åßíáé 3, áëëÜ ç ôéìÞ ôçò $a óõí 3 (áõôÞ åßíáé ç ôéìÞ ðïõ áíáôßèåôáé óôçí $a). ÏðïéïóäÞðïôå äõï-èÝóåùí ôåëåóôÞò ìðïñåß íá ÷ñçóéìïðïéçèåß ó' áõôÞ ôçí êáôÜóôáóç ôåëåóôÞ-áíÜèåóçò, ãéá ðáñÜäåéãìá '$a -= 5' (áöáéñåßôáé ôï 5 áðü ôçí ôéìÞ ôïõ $a), '$b *= 7' (ðïëëáðëáóéÜæåôáé ç ôéìÞ ôçò $b ìå ôï 7), êôë.
ÕðÜñ÷åé áêüìç ìéá Ýêöñáóç ðïõ ßóùò öáíåß ðåñßåñãç áí äåí ôçí Ý÷åôå äåé óå Üëëåò ãëþóóåò, ï ôñéáäéêüò õðïèåôéêüò ôåëåóôÞò:
Áí ç ôéìÞ ôçò ðñþôçò õðü-Ýêöñáóçò åßíáé TRUE (ü÷é ìçäÝí), ôüôå ãßíåôáé õðïëïãéóìüò ôçò ôéìÞò ôçò äåýôåñçò õðü-Ýêöñáóçò, êáé áõôü åßíáé ôï áðïôÝëåóìá ôçò õðïèåôéêÞò Ýêöñáóçò. ÄéáöïñåôéêÜ, ç ôñßôç õðïÝêöñáóç õðïëïãßæåôáé êáé áõôÞ åßíáé êáé ç ôéìÞ.
Ôï ðáñáêÜôù ðáñÜäåéãìá èá óáò âïçèÞóåé íá êáôáëÜâåôå êáëýôåñá ôçí ðñï- (pre-) êáé ìåôÜ- (post-) áýîçóç êáé ôéò åêöñÜóåéò ãåíéêüôåñá:
<?php function double($i) { return $i*2; } $b = $a = 5; /* assign the value five into the variable $a and $b */ $c = $a++; /* post-increment, assign original value of $a (5) to $c */ $e = $d = ++$b; /* pre-increment, assign the incremented value of $b (6) to $d and $e */ /* at this point, both $d and $e are equal to 6 */ $f = double($d++); /* assign twice the value of $d before the increment, 2*6 = 12 to $f */ $g = double(++$e); /* assign twice the value of $e after the increment, 2*7 = 14 to $g */ $h = $g += 10; /* first, $g is incremented by 10 and ends with the value of 24. the value of the assignment (24) is then assigned into $h, and $h ends with the value of 24 as well. */ ?> |
Óôçí áñ÷Þ ôïõ êåöáëáßïõ, åßðáìå üôé èá ðåñéãñÜøïõìå ôïõò äéÜöïñïõò ôýðïò äçëþóåùí, êáé üðùò õðïó÷åèÞêáìå, ïé åêöñÜóåéò ìðïñïýí íá ãßíïõí äçëþóåéò. ¼ðùò êáé íá Ý÷åé, äåí åßíáé êÜèå Ýêöñáóç êáé äÞëùóç. Ó' áõôÞ ôçí ðåñßðôùóç, ìéá äÞëùóç Ý÷åé ôç ìïñöÞ 'expr' ';' ôï ïðïßï åßíáé ìéá Ýêöñáóç ðïõ áêïëïõèåßôáé áðü Ýíá åëëçíéêü åñùôçìáôéêü. Óôï '$b=$a=5;', ôï $a=5 åßíáé ìéá Ýãêõñç Ýêöñáóç, áëëÜ äåí åßíáé áðü ìüíç ôçò ìéá Ýêöñáóç. Ðáñüëáõôá ç Ýêöñáóç '$b=$a=5;' åßíáé ìéá Ýãêõñç äÞëùóç.
¸íá ôåëåõôáßï ðñÜãìá ðïõ áîßæåé íá áíáöÝñïõìå åßíáé ç áëçèéíÞ áîßá ôùí åêöñÜóåùí. Óå ðïëëÜ óõìâÜíôá, êõñßùò óå loops õðïèåôéêÜ êáé åêôÝëåóçò, äåí åíäéáöÝñåóôå ãéá ôç óõãêåêñéìÝíç ôéìÞ ôçò Ýêöñáóçò, áëëÜ ìüíï ãéá ôï ôé óçìáßíåé TRUE Þ FALSE. Ïé óôáèåñÝò TRUE êáé FALSE (åßíáé case-insensitive) åßíáé ïé äõï ðéèáíÝò boolean ôéìÝò. ¼ôáí ÷ñåéÜæåôáé, ìéá Ýêöñáóç áõôüìáôá ìåôáôñÝðåôáé óå boolean. Äåßôå ôï ôìÞìá ó÷åôéêÜ ìå type-casting (ìåôáôñïðÞ ôýðïõ) ãéá ëåðôïìÝñåéåò ó÷åôéêÜ ìå ôïí ôñüðï.
Ç PHP ðáñÝ÷åé ìéá ðëÞñç êáé äõíáôÞ õëïðïßçóç ôùí åêöñÜóåùí, êáé ç ôåêìçñßùóç ôçò åßíáé ðÝñá áðü ôï óêïðü áõôïý ôïõ åã÷åéñéäßïõ. Ôá ðáñáðÜíù ðáñáäåßãìáôá åßíáé ãéá íá óáò äþóïõí ìéá éäÝá ó÷åôéêÜ ìå ôï ôé åßíáé ïé åêöñÜóåéò êáé ðþò ìðïñåßôå íá ó÷çìáôßóåôå ÷ñÞóéìåò åêöñÜóåéò. Óôï õðüëïéðï manual èá ãñÜöïõìå expr ãéá íá óõìâïëßóïõìå êÜèå Ýãêõñç Ýêöñáóç óôçí PHP.
Ç ðñïôåñáéüôçôá ôùí ôåëåóôþí êáèïñßæåé ôï ðüóï "óöé÷ôÜ" óõíäÝïíôáé äõï åêöñÜóåéò ìáæß. Ãéá ðáñÜäåéãìá, óôçí Ýêöñáóç 1 + 5 * 3, ç áðÜíôçóç åßíáé 16 êáé ü÷é 18 åðåéäÞ ï ôåëåóôÞò ôïõ ðïëëáðëáóéáóìïý ("*") Ý÷åé ðñïôåñáéüôçôá óå ó÷Ýóç ìå ôïí ôåëåóôÞ ôçò ðñüóèåóçò ("+"). Ïé ðáñåíèÝóåéò ìðïñïýí íá ÷ñçóéìïðïéçèïýí ãéá íá áëëÜîïõí ôéò ðñïôåñáéüôçôåò, áí ÷ñåéÜæåôáé. Ãéá ðáñÜäåéãìá: Ôï (1 + 5) * 3 Ý÷åé ùò áðïôÝëåóìá ôï 18.
Ï áêüëïõèïò ðßíáêáò ðáñáèÝôåé ôçí ðñïôåñáéüôçôá ôùí ôåëåóôþí ìå ôçí ÷áìçëüôåñç ðñïôåñáéüôçôá íá ðáñáôßèåôáé ðñþôç.
Ðßíáêáò 10-1. Operator Precedence
Ó÷åôéêüôçôá | ÔåëåóôÝò |
---|---|
áñéóôåñÞ | , |
áñéóôåñÞ | or |
áñéóôåñÞ | xor |
áñéóôåñÞ | and |
äåîéÜ | |
áñéóôåñÞ | = += -= *= /= .= %= &= |= ^= <<= >>= |
áñéóôåñÞ | ? : |
áñéóôåñÞ | || |
áñéóôåñÞ | && |
áñéóôåñÞ | | |
áñéóôåñÞ | ^ |
áñéóôåñÞ | & |
×ùñßò óýíäåóç | == != === !== |
×ùñßò óýíäåóç | < <= > >= |
ÁñéóôåñÞ | << >> |
ÁñéóôåñÞ | + - . |
ÁñéóôåñÞ | * / % |
ÄåîéÜ | ! ~ ++ -- (int) (float) (string) (array) (object) @ |
ÄåîéÜ | [ |
×ùñßò óýíäåóç | new |
Óçìåßùóç: Ðáñüëï ðïõ ôï ! Ý÷åé ðñïôåñáéüôçôá Ýíáíôé ôïõ =, ç PHP åðéôñÝðåé åêöñÜóåéò ðáñüìïéåò ìå ôçí áêüëïõèç: if (!$a = foo()), êáé óå êÜèå ðåñßðôùóç ôï áðïôÝëåóìá áðü ôçí foo() ôïðïèåôåßôáé óôçí $a.
ÈõìÜóôå ôç âáóéêÞ áñéèìçôéêÞ áðü ôï ó÷ïëåßï; ÁõôÜ äïõëÝõïõí áêñéâþò üðùò åêåßíç.
Ðßíáêáò 10-2. Áñéèìçôéêïß ÔåëåóôÝò
ÐáñÜäåéãìá | ¼íïìá | ÁðïôÝëåóìá |
---|---|---|
$a + $b | Ðñüóèåóç | ÁðïôÝëåóìá ôïõ $a êáé ôïõ $b. |
$a - $b | Áöáßñåóç | ÄéáöïñÜ ôïõ $a êáé ôïõ $b. |
$a * $b | Ðïëëáðëáóéáóìüò | Ãéíüìåíï ôïõ $a êáé ôïõ $b. |
$a / $b | Äéáßñåóç | ÁðïôÝëåóìá ôïõ $a êáé ôïõ $b. |
$a % $b | Modulus | Õðüëïéðï ôïõ $a äéáéñåìÝíïõ áðü ôï $b. |
Ï ôåëåóôÞò äéáßñåóçò ("/") åðéóôñÝöåé ìéá ôéìÞ êéíçôÞò õðïäéáóôïëÞò êÜèå öïñÜ, áêüìç êáé áí ïé äõï ôåëåóôÝò åßíáé áêÝñáéïé (Þ strings ðïõ ìåôáôñÝðïíôáé óå áêåñáßïõò).
Äåßôå åðßóçò ôï êåöÜëáéï ó÷åôéêÜ ìå ôéò ÌáèçìáôéêÝò ÓõíáñôÞóåéò.
Ï âáóéêüò ôåëåóôÞò áíÜèåóçò åßíáé ï "=". Ç ðñþôç óáò óêÝøç ßóùò åßíáé üôé áõôü åßíáé ôï ßäéï ìå ôï "éóïýôáé ìå". ÁëëÜ äåí åßíáé. Áõôü ðïõ ðñáãìáôéêÜ óçìáßíåé åßíáé üôé ôï áñéóôåñü ìÝñïò ôïõ ôåëåóôÞ ðáßñíåé ôçí ôéìÞ ôçò Ýêöñáóçò óôá äåîéÜ (äçëáäÞ, "áíáôßèåôáé óå").
Ç ôéìÞ ìéáò Ýêöñáóçò áíÜèåóçò åßíáé ç ôéìÞ ðïõ ôçò áíáôßèåôáé. ÄçëáäÞ, ç ôéìÞ ôïõ "$a = 3" åßíáé 3. Áõôü óáò åðéôñÝðåé íá êÜíåôå ìåñéêÜ ðåñßðëïêá ðñÜãìáôá:
ÐÝñá áðü ôï âáóéêü ôåëåóôÞ áíÜèåóçò, õðÜñ÷ïõí "óýíèåôïé ôåëåóôÝò" ãéá üëïõò ôïõò äõáäéêïýò áñéèìçôéêïýò êáé áëöáñéèìçôéêïýò ôåëåóôÝò ðïõ óáò åðéôñÝðïõí íá ÷ñçóéìïðïéÞóåôå ìéá Ýêöñáóç êáé óôç óõíÝ÷åéá íá èÝóåôå ôçí ôéìÞ óôï áðïôÝëåóìá ôçò Ýêöñáóçò. Ãéá ðáñÜäåéãìá:
$a = 3; $a += 5; // sets $a to 8, as if we had said: $a = $a + 5; $b = "Hello "; $b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!"; |
Óçìåéþóôå üôé ç áíÜèåóç áíôéãñÜöåé ôçí áñ÷éêÞ ìåôáâëçôÞ óôçí êáéíïýñéá (áíÜèåóç ìå ôéìÞ), óõíåðþò áëëáãÝò óôï Ýíá äå èá åðçñåÜóïõí ôï Üëëï. Áõôü ìðïñåß åðßóçò íá Ý÷åé ó÷Ýóç áí ÷ñåéáóôåß íá áíôéãñÜøåôå êÜôé üðùò Ýíáí ìåãÜëï ðßíáêá ìÝóá óå Ýíá óôåíü loop. Ç PHP 4 õðïóôçñßæåé ôçí áíÜèåóç ìå áíáöïñÜ, ÷ñçóéìïðïéþíôáò ôç $var = &$othervar; óýíôáîç, áëëÜ áõôü äåí åßíáé äõíáôü óôçí PHP 3. 'ÁíÜèåóç ìå áíáöïñÜ' óçìáßíåé ðùò êáé ïé äõï ìåôáâëçôÝò êáôáëÞãïõí óôï íá äåß÷íïõí óôá ßäéá äåäïìÝíá, êáé ôßðïôá äåí áíôéãñÜöåôáé ðïõèåíÜ. Ãéá íá ìÜèåôå ðåñéóóüôåñá ãéá ôéò áíáöïñÝò, äéáâÜóôå ôï ÅðåîÞãçóç ôùí áíáöïñþí.
Ïé äõáäéêïß ôåëåóôÝò óáò åðéôñÝðïõí íá åíåñãïðïéÞóåôå Þ íá áðåíåñãïðïéÞóåôå óõãêåêñéìÝíá bits ìÝóá óå êÜðïéï áêÝñáéï. Áí êáé ïé äýï ðáñÜìåôñïé (áñéóôåñÞ êáé äåîéÜ) åßíáé strings, ï äõáäéêüò ôåëåóôÞò èá åíåñãÞóåé óôïõò ÷áñáêôÞñåò áõôïý ôïõ string.
<?php echo 12 ^ 9; // Outputs '5' echo "12" ^ "9"; // Outputs the Backspace character (ascii 8) // ('1' (ascii 49)) ^ ('9' (ascii 57)) = #8 echo "hallo" ^ "hello"; // Outputs the ascii values #0 #4 #0 #0 #0 // 'a' ^ 'e' = #4 ?> |
Ðßíáêáò 10-3. Äõáäéêïß ÔåëåóôÝò
ÐáñÜäåéãìá | ¼íïìá | ÁðïôÝëåóìá |
---|---|---|
$a & $b | And | Ôá bits ðïõ åßíáé 1 ôüóï óôï $a üóï êáé óôï $b, åíåñãïðïéïýíôáé. |
$a | $b | Or | Ôá bits ðïõ åßíáé 1 åßôå óôï $a åßôå óôï $b, åíåñãïðïéïýíôáé. |
$a ^ $b | Xor | Ôá bits ðïõ åßíáé 1 åßôå óôï $a åßôå óôï $b, áëëÜ ü÷é êáé óôá äýï, åíåñãïðïéïýíôáé. |
~ $a | Not | Ôá bits ðïõ äåí åßíáé åíåñãïðïéçìÝíá óôï $a, åíåñãïðïéïýíôáé, êáé áíôßóôñïöá. |
$a << $b | Shift left | Ìåôáêßíçóç (óéöôÜñéóìá) ôùí bits ôïõ $a êáôÜ $b âÞìáôá ðñïò ôá áñéóôåñÜ (êÜèå âÞìá óçìáßíåé "ðïëëáðëáóéáóìüò åðß äýï") |
$a >> $b | Shift right | Ìåôáêßíçóç (óéöôÜñéóìá) ôùí bits ôïõ $a êáôÜ $b âÞìáôá ðñïò ôá äåîéÜ (êÜèå âÞìá óçìáßíåé "äéáßñåóç åðß äýï") |
Ïé ôåëåóôÝò óýãêñéóçò, üðùò ëÝåé êáé ôï üíïìá ôïõò, óáò åðéôñÝðïõí íá óõãêñßíåôå äõï ôéìÝò. ºóùò áêüìç åíäéáöÝñåóôå íá äåßôå óõíäÝóìïõò ó÷åôéêÜ ìå ôïí ðßíáêá óýãêñéóçò ôýðùí, áöïý äåß÷íïõí ðáñáäåßãìáôá ìå óõãêñßóåéò ðïõ Ý÷ïõí ó÷Ýóç ìå ôýðïõò.
Ðßíáêáò 10-4. ÔåëåóôÝò Óýãêñéóçò
ÐáñÜäåéãìá | ¼íïìá | ÁðïôÝëåóìá |
---|---|---|
$a == $b | Éóüôçôá | TRUE áí ôï $a åßíáé ßóï ìå ôï $b. |
$a === $b | Ïìïéüôçôá | TRUE áí ôï $a åßíáé ßóï ìå ôï $b, êáé åßíáé åðéðëÝïí ôïõ ßäéïõ ôýðïõ. (Óôçí PHP 4 ìüíï) |
$a != $b | ¢íéóá | TRUE áí ôï $a äåí åßíáé ßóï ìå ôï $b. |
$a <> $b | ¼÷é ßóá | TRUE áí ôï $a äåí åßíáé ßóï ìå ôï $b. |
$a !== $b | Áíüìïéá | TRUE áí ôï $a äåí åßíáé ßóï ìå ôï $b, Þ áí äåí åßíáé ôïõ ßäéïõ ôýðïõ. (óôçí PHP 4 ìüíï) |
$a < $b | Ìéêñüôåñï áðü | TRUE áí ôï $a åßíáé áêñéâþò ìéêñüôåñï áðü ôï $b. |
$a > $b | Ìåãáëýôåñï áðü | TRUE áí ôï $a åßíáé áõóôçñþò ìåãáëýôåñï áðü ôï $b. |
$a <= $b | Ìéêñüôåñï áðü Þ ßóï ìå | TRUE áí ôï $a åßíáé ìéêñüôåñï áðü Þ ßóï ìå ôï $b. |
$a >= $b | Ìåãáëýôåñï áðü Þ ßóï ìå | TRUE áí ôï $a åßíáé ìåãáëýôåñï áðü Þ ßóï ìå ôï $b. |
Áêüìç Ýíáò ôåëåóôÞò õðüèåóçò åßíáé ï "?:" (Þ ôñéáäéêüò) ôåëåóôÞò, ï ïðïßïò ëåéôïõñãåß üðùò êáé óôç C êáé óå ðïëëÝò Üëëåò ãëþóóåò.
<?php // Example usage for: Ternary Operator $action = (empty($_POST['action'])) ? 'default' : $_POST['action']; // The above is identical to this if/else statement if (empty($_POST['action'])) { $action = 'default'; } else { $action = $_POST['action']; } ?> |
Äåßôå åðßóçò ôçí strcasecmp(), strcmp(), êáé ôï ôìÞìá ôïõ åã÷åéñéäßïõ ó÷åôéêÜ ìå ôïõò Ôýðïõò.
Ç PHP õðïóôçñßæåé Ýíáí ôåëåóôÞ åëÝã÷ïõ ëáèþí: ôï óýìâïëï (@). ¼ôáí ðñïçãåßôáé óå ìéá Ýêöñáóç óôçí PHP, ïðïéïäÞðïôå ìÞíõìá ëÜèïõò ðïõ ßóùò äçìéïõñãçèåß áðü áõôÞ ôçí Ýêöñáóç èá áãíïçèåß.
Áí ôï ÷áñáêôçñéóôéêü ôùí track_errors Ý÷åé åíåñãïðïéçèåß, ïðïéïäÞðïôå ìÞíõìá ëÜèïõò ðïõ èá äçìéïõñãçèåß áðü ôçí Ýêöñáóç èá áðïèçêåõôåß óôç ìåôáâëçôÞ $php_errormsg. ÁõôÞ ç ìåôáâëçôÞ èá áëëÜæåé áíÜëïãá ìå êÜèå ëÜèïò, óõíåðþò èá ðñÝðåé íá ôçí åëÝã÷åôå óõ÷íÜ áí èÝëåôå íá ôç ÷ñçóéìïðïéåßôå.
<?php /* Intentional file error */ $my_file = @file ('non_existent_file') or die ("Failed opening file: error was '$php_errormsg'"); // this works for any expression, not just functions: $value = @$cache[$key]; // will not issue a notice if the index $key doesn't exist. ?> |
Óçìåßùóç: Ï ôåëåóôÞò @ äïõëåýåé ìüíï óôéò åêöñÜóåéò. ¸íáò áðëüò êáíüíáò åßíáé ï åîÞò: áí ìðïñåßôå íá ðÜñåôå ôçí ôéìÞ áðü êÜôé, ìðïñåßôå íá âÜëåôå ùò ðñüèåìá ó'áõôü, ôï @. Ãéá ðáñÜäåéãìá, ìðïñåßôå íá ôï ðñïóèÝóåôå óôéò ìåôáâëçôÝò, óôéò óõíáñôÞóåéò êáé óôéò êëÞóåéò ôïõ include() , óôéò óôáèåñÝò ê.ï.ê. Äåí ìðïñåßôå íá ôï ðñïóèÝóåôå óôïõò ïñéóìïýò óõíáñôÞóåùí Þ êëÜóåùí, Þ õðïèåôéêþí äïìþí üðùò ôéò if êáé foreach ê.ï.ê.
Äåßôå åðßóçò ôçí error_reporting() êáé ôï ôìÞìá ôïõ åã÷åéñéäßïõ ÓõíáñôÞóåéò åëÝã÷ïõ ëáèþí êáé óýíäåóçò.
Óçìåßùóç: Ôï ðñüèåìá ôïõ ôåëåóôÞ åëÝã÷ïõ ëáèþí "@" äå èá áðïôñÝøåé ôçí åìöÜíéóç ôùí ìçíõìÜôùí ðïõ åßíáé áðïôÝëåóìá áðü ëÜèç ìåôáãëþôôéóçò.
Ðñïåéäïðïßçóç |
Ðñïò ôï ðáñüí, ôï ðñüèåìá åëÝã÷ïõ ëáèþí "@" èá áðïôñÝøåé áêüìç êáé ôçí áíáöïñÜ ëáèþí ãéá êñßóéìá ëÜèç ðïõ èá ôåñìáôßóïõí ôçí åêôÝëåóç ôïõ êþäéêá. ÁíÜìåóá óå Üëëá, áõôü óçìáßíåé üôé áí ÷ñçóéìïðïéåßôå ôï "@" ãéá íá åîáöáíßóåôå ôá ëÜèç áðü ìéá óõãêåêñéìÝíç óõíÜñôçóç ôüôå áí äåí åßíáé äéáèÝóéìï Þ äåí Ý÷åé ãñáöåß óùóôÜ, ôï script èá óôáìáôÞóåé áìÝóùò åêåß ÷ùñßò êÜðïéá Ýíäåéîç ãéá ôçí áéôßá. |
Ç PHP õðïóôçñßæåé Ýíáí ôåëåóôÞ åêôÝëåóçò: ôá backticks (``). Óçìåéþóôå üôé áõôÜ äåí åßíáé ìïíÜ åéóáãùãéêÜ (single-quotes)! Ç PHP èá ðñïóðáèÞóåé íá åêôåëÝóåé ôï ðåñéå÷üìåíï ôùí backticks óáí åíôïëÞ shell. Ôï áðïôÝëåóìá èá åðéóôñáöåß (ð.÷., äå èá ðåôá÷ôåß áðëÜ óôçí Ýîïäï, áëëÜ ìðïñåß íá áíáôåèåß óå ìéá ìåôáâëçôÞ). Ç ÷ñÞóç ôïõ backtick ôåëåóôÞ åßíáé üìïéá ìå ôç shell_exec().
Óçìåßùóç: Ï backtick ôåëåóôÞò åßíáé áðåíåñãïðïéçìÝíïò üôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï Þ ç shell_exec() åßíáé áðåíåñãïðïéçìÝíç.
Äåßôå åðßóçò ôá ôìÞìáôá ôïõ åã÷åéñéäßïõ ÓõíáñôÞóåéò ÅêôÝëåóçò ÐñïãñáììÜôùí, popen() proc_open(), êáé ×ñçóéìïðïéþíôáò ôçí PHP áðü commandline.
Ç PHP õðïóôçñßæåé ôåëåóôÝò ðñü- êáé ìåôÜ- áýîçóçò üðùò ç C.
Ðßíáêáò 10-5. ÔåëåóôÝò Áýîçóçò/Ìåéþóçò
ÐáñÜäåéãìá | ¼íïìá | ÁðïôÝëåóìá |
---|---|---|
++$a | Ðñï-áýîçóç | ÁõîÜíåé ôï $a êáôÜ Ýíá êáé åðéóôñÝöåé ôï $a. |
$a++ | ÌåôÜ-áýîçóç | ÅðéóôñÝöåé ôï $a, êáé ìåôÜ áõîÜíåé ôï $a êáôÜ Ýíá. |
--$a | Ðñï-ìåßùóç | Ìåéþíåé ôï $a êáôÜ Ýíá, êáé ìåôÜ åðéóôñÝöåé ôï $a. |
$a-- | ÌåôÜ-ìåßùóç | ÅðéóôñÝöåé ôï $a, êáé ìåôÜ ìåéþíåé ôï $a êáôÜ Ýíá. |
Åäþ Ý÷ïõìå Ýíá áðëü ðáñÜäåéãìá êþäéêá:
<?php echo "<h3>Postincrement</h3>"; $a = 5; echo "Should be 5: " . $a++ . "<br />\n"; echo "Should be 6: " . $a . "<br />\n"; echo "<h3>Preincrement</h3>"; $a = 5; echo "Should be 6: " . ++$a . "<br />\n"; echo "Should be 6: " . $a . "<br />\n"; echo "<h3>Postdecrement</h3>"; $a = 5; echo "Should be 5: " . $a-- . "<br />\n"; echo "Should be 4: " . $a . "<br />\n"; echo "<h3>Predecrement</h3>"; $a = 5; echo "Should be 4: " . --$a . "<br />\n"; echo "Should be 4: " . $a . "<br />\n"; ?> |
Ç PHP áêïëïõèåß ôéò óõíèÞêåò ôçò Perl üôáí äéá÷åéñßæåôáé áñéèìçôéêÝò ðñÜîåéò óå ìåôáâëçôÝò ÷áñáêôÞñùí êáé ü÷é áõôÝò ôéò C. Ãéá ðáñÜäåéãìá, óôçí Perl ôï 'Z'+1 åðéóôñÝöåé 'AA', åíþ óôç C ôï 'Z'+1 åðéóôñÝöåé '[' ( ord('Z') == 90, ord('[') == 91 ). Óçìåéþóôå üôé ïé ìåôáâëçôÝò ÷áñáêôÞñùí ìðïñïýí íá áõîçèïýí áëëÜ ü÷é íá ìåéùèïýí.
Ðßíáêáò 10-6. Ëïãéêïß ÔåëåóôÝò
ÐáñÜäåéãìá | ¼íïìá | ÁðïôÝëåóìá |
---|---|---|
$a and $b | And | TRUE áí êáé ôï $a êáé ôï $b åßíáé TRUE. |
$a or $b | Or | TRUE áí åßôå ôï $a åßôå ôï $b åßíáé TRUE. |
$a xor $b | Xor | TRUE áí åßôå ôï $a åßôå ôï $b åßíáé TRUE, áëëÜ ü÷é êáé ôá äõï. |
! $a | Not | TRUE áí ôï $a äåí åßíáé TRUE. |
$a && $b | And | TRUE áí êáé ôï $a êáé ôï $b åßíáé TRUE. |
$a || $b | Or | TRUE áí åßôå ôï $a åßôå ôï $b åßíáé TRUE. |
Ç åîÞãçóç ãéá ôéò äõï äéáöïñåôéêÝò ìïñöÝò ôùí "and" êáé ôùí "or" ôåëåóôþí åßíáé üôé ëåéôïõñãïýí ìå äéáöïñåôéêÝò ðñïôåñáéüôçôåò. (ÂëÝðå Ðñïôåñáéüôçôá Ôåëåóôþí.)
ÕðÜñ÷ïõí äýï ôåëåóôÝò ãéá strings (áëöáñéèìçôéêþí). Ï ðñþôïò åßíáé ï ôåëåóôÞò óýíäåóçò ('.'), ï ïðïßïò åðéóôñÝöåé ôç óýíäåóç ôùí áñéóôåñþí êáé ôùí äåîéþí ðáñáìÝôñùí. Ï äåýôåñïò åßíáé ï ôåëåóôÞò áíÜèåóçò óýíäåóçò ('.='), ï ïðïßïò ðñïóèÝôåé ôçí ðáñÜìåôñï ôçò äåîéÜ ðëåõñÜ óôçí ðáñÜìåôñï ôçò áñéóôåñÞò ðëåõñÜò. Ðáñáêáëþ äéáâÜóôå ôçíÁíÜèåóç Ôåëåóôþí ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
$a = "Hello "; $b = $a . "World!"; // now $b contains "Hello World!" $a = "Hello "; $a .= "World!"; // now $a contains "Hello World!" |
Äåßôå åðßóçò ôï ôìÞìá ôïõ åã÷åéñéäßïõ ãéá ôïõò Ôýðïõò Áëöáñéèìçôéêþí êáé ãéá ôéò ÓõíáñôÞóåéò Áëöáñéèìçôéêþí.
Ï ìüíïò ôåëåóôÞò ðßíáêá óôçí PHP åßíáé ï + ôåëåóôÞò. Áõôüò ðñïóèÝôåé ôç äåîéÜ ìåñéÜ ôïõ ðßíáêá óôçí áñéóôåñÞ ìåñéÜ, åíþ ôá äéðëÜ êëåéäéÜ ÄÅÍ ãßíïíôáé overwrite (äåí ãñÜöïíôáé áðü ðÜíù).
$a = array("a" => "apple", "b" => "banana"); $b = array("a" =>"pear", "b" => "strawberry", "c" => "cherry"); $c = $a + $b; var_dump($c); |
array(3) { ["a"]=> string(5) "apple" ["b"]=> string(6) "banana" ["c"]=> string(6) "cherry" } |
Äåßôå åðßóçò ôï ôìÞìá ôïõ åã÷åéñéäßïõ ãéá ôïõò Ôýðïõò ÐéíÜêùí êáé ãéá ôéò ÓõíáñôÞóåéò ÐéíÜêùí.
ÏðïéïäÞðïôå script óå PHP åßíáé äïìçìÝíï áðü ìéá óåéñÜ äçëþóåùí (statements). Ìéá äÞëùóç ìðïñåß íá åßíáé ìéá áíÜèåóç, Ýíá êÜëåóìá óõíÜñôçóçò, Ýíá loop, ìéá õðïèåôéêÞ óõíèÞêç áêüìç êáé ìéá äÞëùóçò ðïõ äåí êÜíåé ôßðïôá (ìéá Üäåéá äÞëùóç). Ïé äçëþóåéò óõíÞèùò ôåñìáôßæïíôáé ìå Ýíá åëëçíéêü åñùôçìáôéêü. ÅðéðëÝïí, ïé äçëþóåéò ìðïñïýí íá áðïôåëÝóïõí óýíïëï (statement-group) åìðåñéêëåßïíôáò ôåò óå áãêýëåò. ¸íá statement-group áðïôåëåß ôï ßäéï ìéá äÞëùóç. Ïé äéáöïñåôéêïý ôýðïõ äçëþóåéò ðåñéãñÜöïíôáé ó'áõôü ôï êåöÜëáéï.
Ç äïìÞ if åßíáé Ýíá áðü ôá ðéï óçìáíôéêÜ ÷áñáêôçñéóôéêÜ óå ðïëëÝò ãëþóóåò, óõìðåñéëáìâáíïìÝíçò êáé ôçò PHP. ÅðéôñÝðåé ôçí õðï óõíèÞêç åêôÝëåóç êïììáôéþí êþäéêá. Ç PHP Ý÷åé ìéá äïìÞ if ðáñüìïéá ìå áõôÞ ôçò C:
¼ðùò ðåñéãñÜöçêå óôï ôìÞìá ó÷åôéêÜ ìå ôéò åêöñÜóåéò, ç expr õðïëïãßæåôáé óôçí Boolean ôéìÞ ôçò. Áí ç expr åßíáé TRUE, ç PHP èá åêôåëÝóåé ôç äÞëùóç, êáé áí åßíáé FALSE - èá ôçí áãíïÞóåé. Ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôï ðïéåò ôéìÝò éóïäõíáìïýí ìå FALSE ìðïñåßôå íá âñåßôå óôï 'ÌåôáôñÝðïíôáò óå boolean' ôìÞìá.
Ôï áêüëïõèï ðáñÜäåéãìá èá åìöÜíéæå üôé ôï a åßíáé ìåãáëýôåñï áðü ôï b áí üíôùò ôï $a åßíáé ìåãáëýôåñï áðü ôï $b:
Óõ÷íÜ èá èÝëåôå íá åêôåëåßôå ðåñéóóüôåñåò áðü ìßá äçëþóåéò óå ìéá õðïèåôéêÞ óõíèÞêç. ÖõóéêÜ, äåí ÷ñåéÜæåôáé íá åìðåñéêëåßåôå êÜèå äÞëùóç ìÝóá óå ìéá if äïìÞ. ÁíôéèÝôùò, ìðïñåßôå íá óõìðåñéëÜâåôå áñêåôÝò äçëþóåéò óå Ýíá statement group. Ãéá ðáñÜäåéãìá, áõôüò ï êþäéêáò èá åìöÜíéæå a is bigger than b áí ôï $a åßíáé ìåãáëýôåñï áðü ôï $b, êáé ôüôå èá áíÝèåôå ôçí ôéìÞ ôïõ $a óôç ìåôáâëçôÞ $b:
Ïé äçëþóåéò ìå If ìðïñïýí íá åìöùëåõôïýí áðåñéüñéóôá ìÝóá óå Üëëåò äçëþóåéò if , êÜôé ôï ïðïßï óáò äßíåé ìåãÜëç åõåëéîßá ãéá ôçí õðï óõíèÞêç åêôÝëåóç ðïëëþí ìåñþí ôïõ ðñïãñÜììáôïò óáò.
Óõ÷íÜ èá èÝëåôå íá åêôåëÝóåôå ìéá äÞëùóç áí ðëçñåßôáé ìéá óõãêåêñéìÝíç óõíèÞêç, êáé ìéá äéáöïñåôéêÞ äÞëùóç áí áõôü äå óõìâáßíåé. Ãé'áõôü ôï ëüãï ÷ñçóéìïðïéåßôáé ôï else. Ôï else åßíáé åðÝêôáóç ìéáò äÞëùóçò if êáé åêôåëåß ìéá äÞëùóç óôçí ðåñßðôùóç ðïõ ç Ýêöñáóç óôç äÞëùóç if åßíáé FALSE. Ãéá ðáñÜäåéãìá, ï áêüëïõèïò êþäéêáò èá åìöÜíéæå a is bigger than b áí ôï $a åßíáé ìåãáëýôåñï áðü ôï $b, êáé a is NOT bigger than b óôçí áíôßèåôç ðåñßðôùóç:
Ç óõíèÞêç else åêôåëåßôáé ìüíï áí ç ôéìÞ ôçò Ýêöñáóçò if ðÜñåé ôçí ôéìÞ FALSE, êáé áí õðÜñ÷ïõí åêöñÜóåéò elseif - ìüíï áí ðÜñïõí êáé áõôÝò ôçí ôéìÞ FALSE (âëÝðå elseif).Ç åíôïëÞ elseif, üðùò ëÝåé êáé ôï üíïìá ôçò, åßíáé Ýíáò óõíäõáóìüò ôùí if êáé else. 'Ïðùò ôï êáé else, Ý÷åé ùò åðÝêôáóç ìßá if Ýêöñáóç ìå óêïðü íá åêôåëÝóåé ìéá äéáöïñåôéêÞ Ýêöñáóç óå ðåñßðôùóç ðïõ ç áñ÷éêÞ if óõíèÞêç ðÜñåé ôçí ôéìÞ FALSE. Ðáñüëáõôá, óå áíôßèåóç ìå ôï else, èá åêôåëÝóåé áõôÞ ôçí åíáëëáêôéêÞ Ýêöñáóç ìüíï áí ç elseif õðïèåôéêÞ óõíèÞêç ðÜñåé ôçí ôéìÞ TRUE. Ãéá ðáñÜäåéãìá, ôï áêüëïõèï êïììÜôé êþäéêá èá åìöáíßóåé a is bigger than b, a equal to b or a is smaller than b:
<?php if ($a > $b) { print "a is bigger than b"; } elseif ($a == $b) { print "a is equal to b"; } else { print "a is smaller than b"; } ?> |
Ìðïñïýí íá õðÜñ÷ïõí ðïëëÜ elseifs ìÝóá óôçí ßäéá Ýêöñáóç if. Ç ðñþôç elseif Ýêöñáóç (áí õðÜñ÷åé) ðïõ èá ðÜñåé ôçí ôéìÞ TRUE èá åßíáé êáé áõôÞ ðïõ èá åêôåëåóôåß. Óôçí PHP, ìðïñåßôå åðßóçò íá ãñÜøåôå 'else if' (óå äõï ëÝîåéò) êáé ç óõìðåñéöïñÜ íá åßíáé üìïéá ìå áõôÞ ôïõ 'elseif' (ìßá ëÝîç). Ç óõíôáêôéêÞ Ýííïéá åßíáé åëáöñþò äéáöïñåôéêÞ (áí Ý÷åôå ïéêåéüôçôá ìå ôç C, åßíáé áêñéâþò ç ßäéá óõìðåñéöïñÜ) áëëÜ ôï ôåëéêü áðïôÝëåóìá åßíáé üôé êáé ïé äõï åêöñÜóåéò èá êáôáëÞîïõí óôçí ßäéá áêñéâþò óõìðåñéöïñÜ.
Ç Ýêöñáóç elseif åêôåëåßôáé ìüíï áí ç ðñïçãïýìåíç Ýêöñáóç if êáé ïðïéåóäÞðïôå ðñïçãïýìåíåò åêöñÜóåéò elseif Ý÷ïõí ðÜñåé ôçí ôéìÞ FALSE, êáé ç ôñÝ÷ïõóá Ýêöñáóç elseif ðÜñåé ôçí ôéìÞ TRUE.
Ç PHP ðñïóöÝñåé ìéá åíáëëáêôéêÞ óýíôáîç ãéá ïñéóìÝíåò áðü ôéò äïìÝò åëÝã÷ïõ ôçò, äçëáäÞ ãéá ôéò, if, while, for, foreach, êáé switch. Óå êÜèå ðåñßðôùóç, ç âáóéêÞ ìïñöÞ ôçò åíáëëáêôéêÞò óýíôáîçò åßíáé ç áëëáãÞ ôçò ðáñÝíèåóçò áíïßãìáôïò ìå ôçí Üíù êáé êÜôù ôåëåßá (:) êáé ôçò ðáñÝíèåóçò êëåéóßìáôïò ìå ôá endif;, endwhile;, endfor;, endforeach;, Þ endswitch;, áíôßóôïé÷á.
Óôï ðáñáðÜíù ðáñÜäåéãìá, ôï ìðëïê ôçò "A is equal to 5" åßíáé åìöùëåõìÝíï ìÝóá óå ìéá Ýêöñáóç if ãñáììÝíç ìå ôïí åíáëëáêôéêü ôñüðï óýíôáîçò. Ôï ìðëïê ôçò HTML èá åìöáíéóôåß ìüíï áí ç $a åßíáé ßóç ìå 5.
Ç åíáëëáêôéêÞ óýíôáîç åöáñìüæåôáé êáé óôï else êáé elseif . Ç áêüëïõèç äïìÞ åßíáé ìéá äïìÞ if ìå elseif êáé else ìå ôçí åíáëëáêôéêÞ óýíôáîç:
<?php if ($a == 5): print "a equals 5"; print "..."; elseif ($a == 6): print "a equals 6"; print "!!!"; else: print "a is neither 5 nor 6"; endif; ?> |
ÂëÝðå åðßóçò ôá while, for, êáé if ãéá åðéðëÝïí ðáñáäåßãìáôá.
Ôá loops (âñüã÷ïé) while åßíáé ï áðëïýóôåñïò ôýðïò loop óôçí PHP. ÓõìðåñéöÝñïíôáé áêñéâþò üðùò êáé óôç C. Ç âáóéêÞ ìïñöÞ ìéá äÞëùóçò while åßíáé ç åîÞò:
Ôï íïÞìá ìéáò äÞëùóçò while åßíáé áðëü. ËÝåé óôçí PHP íá åêôåëÝóåé ôçí åìöùëåõìÝíç óõíèÞêç(åò) óõíÝ÷åéá, ìÝ÷ñé ç Ýêöñáóç while íá ðÜñåé ôçí ôéìÞ TRUE. Ç ôéìÞ ôçò Ýêöñáóçò åëÝã÷åôáé êÜèå öïñÜ óôçí áñ÷Þ ôïõ loop, Ýôóé þóôå áêüìç êáé áí áõôÞ ç ôéìÞ áëëÜîåé êáôÜ ôç äéÜñêåéá ôçò åêôÝëåóçò ôùí åìöùëåõìÝíùí óõíèçêþí, ç åêôÝëåóç äå èá óôáìáôÞóåé ìÝ÷ñé ôï ôÝëïò ôçò åðáíÜëçøçò (êÜèå öïñÜ ðïõ ç PHP åêôåëåß ôéò åêöñÜóåéò óôï loop áðïôåëåß ìéá åðáíÜëçøç). ÌåñéêÝò öïñÝò, áí ç Ýêöñáóç while ðÜñåé ôçí ôéìÞ FALSE áðü ôçí áñ÷Þ, ç åìöùëåõìÝíç åíôïëÞ-Ýêöñáóç äå èá åêôåëåóôåß ïýôå ìéá öïñÜ.
¼ðùò êáé óôç äÞëùóç if , ìðïñåßôå íá âÜëåôå ðïëëÝò óõíèÞêåò ìÝóá óôï ßäéï while loop åóùêëåßïíôáò ôåò ìÝóá óå { }, Þ ÷ñçóéìïðïéþíôáò ôçí åíáëëáêôéêÞ óýíôáîç:
Ôá ðáñáêÜôù ðáñáäåßãìáôá åßíáé üìïéá, êáé ôá äõï åêôõðþíïõí ôïõò áñéèìïýò áðü ôï 1 ùò ôï 10:
Ôï do..while loop åßíáé áñêåôÜ üìïéï ìå ôï while loop, åêôüò áðü ôï üôé ç Ýêöñáóç áëÞèåéáò åëÝã÷åôáé óôï ôÝëïò êÜèå åðáíÜëçøçò êáé ü÷é óôçí áñ÷Þ. Ç êýñéá äéáöïñÜ áðü ôá êáíïíéêÜ while loops åßíáé üôé ç ðñþôç åðáíÜëçøç åíüò do..while loop åããõÜôáé ôçí åêôÝëåóç ôïõ (ç áëÞèåéá ôçò Ýêöñáóçò åëÝã÷åôáé ìüíï óôï ôÝëïò ôçò åðáíÜëçøçò, åíþ ìðïñåß íá ìçí åßíáé áíáãêáßï íá åêôåëåóôåß óå Ýíá êáíïíéêü while loop (ç áëÞèåéá ôçò Ýêöñáóçò åëÝã÷åôáé óôçí áñ÷Þ êÜèå åðáíÜëçøçò, êáé áí ðÜñåé ôçí ôéìÞ FALSE áðü ôçí áñ÷Þ, ç åêôÝëåóç ôïõ loop èá óôáìáôÞóåé áìÝóùò).
ÕðÜñ÷åé ìüíï ìéá óýíôáîç ãéá ôá do..while loops:
Ôï ðáñáðÜíù loop èá ôñÝîåé áêñéâþò ìéá öïñÜ, áöïý ìåôÜ ôçí ðñþôç åðáíÜëçøç, üôáí ç Ýêöñáóç áëçèåßáò åëÝã÷åôáé, ðáßñíåé ôçí ôéìÞ FALSE (ôï $i äåí åßíáé ìåãáëýôåñï áðü ôï 0) êáé ç åêôÝëåóç ôïõ loop óôáìáôÜ.
Ïé ðñï÷ùñçìÝíïé ÷ñÞóôåò ôçò C ßóùò Ý÷ïõí ïéêåéüôçôá ìå ìéá äéáöïñåôéêÞ ÷ñÞóç ôïõ do..while loop, ãéá íá åðéôñÝøïõí ôï óôáìÜôçìá ôçò åêôÝëåóçò óôç ìÝóç ôïõ block ôïõ êþäéêá, åìöùëåýïíôáò ôï óôï do..while(0), êáé ÷ñçóéìïðïéþíôáò ôç break äÞëùóç. Áõôü öáßíåôáé óôï ðáñáêÜôù êïììÜôé êþäéêá:
<?php do { if ($i < 5) { print "i is not big enough"; break; } $i *= $factor; if ($i < $minimum_limit) { break; } print "i is ok"; /* process i */ } while(0); ?> |
Ìçí áíçóõ÷åßôå áí äåí êáôáëáâáßíåôå áõôü áìÝóùò Þ êáé êáèüëïõ. Ìðïñåßôå íá ãñÜøåôå êþäéêá êáé äõíáôÜ êïììÜôéá êþäéêá ÷ùñßò íá ÷ñçóéìïðïéÞóåôå áõôü ôï '÷áñáêôçñéóôéêü'.
Ôá for loops åßíáé ôá ðéï ðåñßðëïêá loops óôçí PHP. ÓõìðåñéöÝñïíôáé üðùò ôá áíôßóôïé÷á êïììÜôéá ôçò C. Ç óýíôáîç åíüò for loop åßíáé:
Ç ðñþôç Ýêöñáóç (expr1) åêôåëåßôáé ÷ùñßò íá ëÜâïõìå õðüøç êÜðïéá óõíèÞêç óôçí áñ÷Þ ôïõ loop.
Óôçí áñ÷Þ êÜèå åðáíÜëçøçò, ç expr2 õðïëïãßæåôáé. Áí ðÜñåé ôçí ôéìÞ TRUE, ôï loop óõíå÷ßæåé êáé ïé åìöùëåõìÝíåò åíôïëÝò åêôåëïýíôáé. Áí ðÜñåé ôçí ôéìÞ FALSE, ç åêôÝëåóç ôïõ loop óôáìáôÜ.
Óôï ôÝëïò êÜèå åðáíÜëçøçò, õðïëïãßæåôáé ç ôéìÞ ôçò expr3.
ÊÜèå ìéá áðü ôéò åêöñÜóåéò ìðïñåß íá åßíáé êåíÞ. Áí ç expr2 åßíáé êåíÞ óçìáßíåé ðùò ôï loop èá åêôåëåßôáé áôÝñìïíá (ç PHP áõôüìáôá èåùñåß ðùò Ý÷åé ôçí ôéìÞ TRUE, üðùò êáé óôç C). Áõôü äåí åßíáé ôüóï Ü÷ñçóôï üóï öáßíåôáé áöïý óõ÷íÜ èÝëïõìå íá ôåñìáôßæïõìå Ýíá loop ÷ñçóéìïðïéþíôáò ìéá óå õðïèÝóç (condition) break äÞëùóç áíôß íá ÷ñçóéìïðïéÞóïõìå ôçí truth Ýêöñáóç ôçò for .
Èåùñåßóôå ôá áêüëïõèá ðáñáäåßãìáôá. ¼ëá åìöáíßæïõí áñéèìïýò áðü ôï 1 ùò ôï 10:
<?php /* example 1 */ for ($i = 1; $i <= 10; $i++) { print $i; } /* example 2 */ for ($i = 1; ; $i++) { if ($i > 10) { break; } print $i; } /* example 3 */ $i = 1; for (;;) { if ($i > 10) { break; } print $i; $i++; } /* example 4 */ for ($i = 1; $i <= 10; print $i, $i++); ?> |
ÖõóéêÜ, ôï ðñþôï ðáñÜäåéãìá åßíáé ôï êáëýôåñï (Þ ßóùò ôï ôÝôáñôï), áëëÜ ßóùò äåßôå ðùò Ý÷ïíôáò ôç äõíáôüôçôá íá ÷ñçóéìïðïéåßôå êåíÝò åêöñÜóåéò óôá for loops åßíáé ðïëý åý÷ñçóôï óå ðïëëÝò ðåñéðôþóåéò.
Ç PHP åðßóçò õðïóôçñßæåé ôçí åíáëëáêôéêÞ "óýíôáîç ìå ÷ñÞóç ôçò Üíù êáé êÜôù ôåëåßáò" óôá for loops.
¢ëëåò ãëþóóåò Ý÷ïõí ìéá äÞëùóç foreach ãéá íá ðñïóðåëÜóïõí Ýíáí array Þ Ýíá hash. Ç PHP 3 äåí Ý÷åé ôÝôïéåò äïìÝò; Ç PHP 4 Ý÷åé (âëÝðå foreach). Óôçí PHP 3, ìðïñåßôå íá óõíäõÜóåôå ôï while ìå ôç list() êáé ôçí each() óõíÜñôçóç ðñïêåéìÝíïõ íá ðåôý÷åôå ôï ßäéï áðïôÝëåóìá. Äåßôå ôï documentation ãé'áõôÝò ôéò óõíáñôÞóåéò ãéá ðáñÜäåéãìá.
Óôçí PHP 4 (êáé ï÷é óôçí PHP 3) óõìðåñéëáìâÜíåôáé ç äïìÞ foreach , üðùò óôçí Perl êáé óå ìåñéêÝò Üëëåò ãëþóóåò. Áõôü áðëÜ äßíåé Ýíáí åýêïëï ôñüðï íá ðñïóðåëáýíåôå ôïõò ðßíáêåò (arrays). Ç foreach ÷ñçóéìïðïéåßôáé ìüíï ìå ðßíáêåò, êáé èá åìöáíéóôåß ëÜèïò áí ðñïóðáèÞóåôå íá ôç ÷ñçóéìïðïéÞóåôå óå ìéá ìåôáâëçôÞ äéáöïñåôéêïý ôýðïõ Þ óå ìéá ìåôáâëçôÞ ðïõ äåí Ý÷åé áñ÷éêïðïéçèåß. ÕðÜñ÷ïõí äõï ôñüðïé óýíôáîçò. Ï äåýôåñïò åßíáé ìéá åëÜ÷éóôç áëëÜ ðïëý óçìáíôéêÞ âåëôßùóç ôïõ ðñþôïõ:
foreach (array_expression as $value) statement foreach (array_expression as $key => $value) statement |
Ç ðñþôç öüñìá ðñïóðåëáýíåé ôïí array óýìöùíá ìå ôçí array_expression. Óå êÜèå loop, ç ôéìÞ ôïõ ôñÝ÷ïíôïò óôïé÷åßïõ áíáôßèåôáé óôçí $value êáé ï åóùôåñéêüò äåßêôçò ôïõ ðßíáêá áõîÜíåôáé êáôÜ Ýíá (Ýôóé þóôå óôï åðüìåíï loop, èá ìðïñåßôå íá äåßôå ôï åðüìåíï óôïé÷åßï).
Ç äåýôåñç öüñìá êÜíåé ôï ßäéï ðñÜãìá, åêôüò áðü ôï üôé ôï ôñÝ÷ïí óôïé÷åßï ôïõ êëåéäéïý èá áíáôßèåôáé óôç ìåôáâëçôÞ $key óå êÜèå loop.
Óçìåßùóç: ¼ôáí ç foreach áñ÷ßæåé áñ÷éêÜ íá åêôåëåßôáé, ï åóùôåñéêüò äåßêôçò ôïõ ðßíáêá áõôüìáôá ðçãáßíåé óôï ðñþôï óôïé÷åßï ôïõ ðßíáêá. Áõôü óçìáßíåé üôé äåí ÷ñåéÜæåôáé íá êáëÝóåôå ôç óõíÜñôçóç reset() ðñéí áðü êÜèå foreach loop.
Óçìåßùóç: Åðßóçò, óçìåéþóôå üôé ç foreach åêôåëåßôáé óå Ýíá áíôßãñáöï ôïõ óõãêåêñéìÝíïõ ðßíáêá, ü÷é óôïí ßäéï ôïí ðßíáêá, óõíåðþò ï äåßêôçò ôïõ ðßíáêá äåí áëëÜæåé üðùò ìå ôç äïìÞ each() êáé áëëáãÝò óôï óôïé÷åßï ôïõ ðßíáêá ðïõ åðéóôñÝöåôáé äåí åðçñåÜæïõí ôïí áñ÷éêü ðßíáêá. Ðáñüëáõôá, ï åóùôåñéêüò äåßêôçò ôïõ áñ÷éêïý ðßíáêá áõîÜíåôáé êáèþò åðåîåñãáæüìáóôå ôïí ðßíáêá. ÕðïèÝôïíôáò üôé ôï foreach loop ïëïêëçñþíåôáé, ï åóùôåñéêüò äåßêôçò ôïõ ðßíáêá èá åßíáé óôï ôÝëïò ôïõ ðßíáêá.
Óçìåßùóç: Ç foreach äåí õðïóôçñßæåé ôç äõíáôüôçôá íá êáôáóôåßëåé ôá ìçíýìáôá ëÜèïõò ÷ñçóéìïðïéþíôáò ôï '@'.
ºóùò Ý÷åôå ðáñáôçñÞóåé üôé ôá áêüëïõèá Ý÷ïõí ôçí ßäéá ëåéôïõñãßá:
<?php $arr = array("one", "two", "three"); reset ($arr); while (list(, $value) = each ($arr)) { echo "Value: $value<br>\n"; } foreach ($arr as $value) { echo "Value: $value<br>\n"; } ?> |
<?php reset ($arr); while (list($key, $value) = each ($arr)) { echo "Key: $key; Value: $value<br>\n"; } foreach ($arr as $key => $value) { echo "Key: $key; Value: $value<br>\n"; } ?> |
ÌåñéêÜ áêüìç ðáñáäåßãìáôá ãéá íá êáôáëÜâåôå ôç ÷ñÞóç:
<?php /* foreach example 1: value only */ $a = array (1, 2, 3, 17); foreach ($a as $v) { print "Current value of \$a: $v.\n"; } /* foreach example 2: value (with key printed for illustration) */ $a = array (1, 2, 3, 17); $i = 0; /* for illustrative purposes only */ foreach ($a as $v) { print "\$a[$i] => $v.\n"; $i++; } /* foreach example 3: key and value */ $a = array ( "one" => 1, "two" => 2, "three" => 3, "seventeen" => 17 ); foreach ($a as $k => $v) { print "\$a[$k] => $v.\n"; } /* foreach example 4: multi-dimensional arrays */ $a[0][0] = "a"; $a[0][1] = "b"; $a[1][0] = "y"; $a[1][1] = "z"; foreach ($a as $v1) { foreach ($v1 as $v2) { print "$v2\n"; } } /* foreach example 5: dynamic arrays */ foreach (array(1, 2, 3, 4, 5) as $v) { print "$v\n"; } ?> |
Ç break ôåñìáôßæåé ôçí åêôÝëåóç ôçò ôñÝ÷ïõóáò åíôïëÞò for, foreach while, do..while Þ ôçò äïìÞò switch .
Ç break äÝ÷åôáé Ýíá ðñïáéñåôéêü áñéèìü ðáñáìÝôñùí ï ïðïßïò ôçò ëÝåé ðüóåò åìöùëåõìÝíåò äïìÝò ðñÝðåé íá äéáêïðïýí-óðÜóïõí.
<?php $arr = array ('one', 'two', 'three', 'four', 'stop', 'five'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { break; /* You could also write 'break 1;' here. */ } echo "$val<br>\n"; } /* Using the optional argument. */ $i = 0; while (++$i) { switch ($i) { case 5: echo "At 5<br>\n"; break 1; /* Exit only the switch. */ case 10: echo "At 10; quitting<br>\n"; break 2; /* Exit the switch and the while. */ default: break; } } ?> |
Ç continue ÷ñçóéìïðïéåßôáé ìÝóá óå äïìÝò loop ðñïêåéìÝíïõ íá ðñïóðåñÜóåé ôï õðüëïéðï ôçò åðáíÜëçøçò ôïõ ôñÝ÷ïíôïò loop êáé íá óõíå÷ßóåé ôçí åêôÝëåóç óôçí áñ÷Þ ôçí åðüìåíçò åðáíÜëçøçò.
Óçìåßùóç: Óçìåéþóôå üôé óôçí PHP ç äÞëùóç switch èåùñåßôáé ìéá äïìÞ loop ãéá ôïõò óêïðïýò ôçò continue.
Ç continue äÝ÷åôáé Ýíáí ðñïáéñåôéêü áñéèìü ðáñáìÝôñùí ï ïðïßïò ôçò ëÝåé ðüóá åðßðåäá åìðåñéêëåéïìÝíùí loops ðñÝðåé íá ðñïóðåñÜóåé ìÝ÷ñé ôï ôÝëïò.
<?php while (list ($key, $value) = each ($arr)) { if (!($key % 2)) { // skip odd members continue; } do_something_odd ($value); } $i = 0; while ($i++ < 5) { echo "Outer<br>\n"; while (1) { echo " Middle<br>\n"; while (1) { echo " Inner<br>\n"; continue 3; } echo "This never gets output.<br>\n"; } echo "Neither does this.<br>\n"; } ?> |
Ç äÞëùóç switch åßíáé ðáñüìïéá ìå ìéá óåéñÜ áðü IF äçëþóåéò ðÜíù óôçí ßäéá Ýêöñáóç. Óå ðïëëÝò ðåñéðôþóåéò, ßóùò èÝëåôå íá óõãêñßíåôå ôçí ßäéá ìåôáâëçôÞ (Þ Ýêöñáóç) ìå ðïëëÝò äéáöïñåôéêÝò ôéìÝò, êáé íá åêôåëÝóåôå Ýíá äéáöïñåôéêü êïììÜôé êþäéêá áíÜëïãá ìå ôçí ôéìÞ ìå ôçí ïðïßá éóïýôáé ç ìåôáâëçôÞ óáò. Áõôü áêñéâþò êÜíåé ç äÞëùóç switch.
Óçìåßùóç: Óçìåéþóôå üôé óå áíôßèåóç ìå ìåñéêÝò ãëþóóåò, ç äÞëùóç continue åöáñìüæåôáé óôçí switch êáé åíåñãåß ðáñüìïéá ìå ôçí break. Áí Ý÷åôå ìéá switch ìÝóá óå Ýíá loop êáé èÝëåôå íá óõíå÷ßóåôå óôçí åðüìåíç åðáíÜëçøç ôïõ åîùôåñéêïý loop, ÷ñçóéìïðïéåßóôå ôçí continue 2.
Ôá áêüëïõèá äõï ðáñáäåßãìáôá åßíáé äõï äéáöïñåôéêïß ôñüðïé ãéá íá ãñÜøåôå ôï ßäéï ðñÜãìá, ï Ýíáò ÷ñçóéìïðïéåß ìéá óåéñÜ áðü äçëþóåéò if, êáé ï Üëëïò ÷ñçóéìïðïéåß ôç äÞëùóç switch :
<?php if ($i == 0) { print "i equals 0"; } elseif ($i == 1) { print "i equals 1"; } elseif ($i == 2) { print "i equals 2"; } switch ($i) { case 0: print "i equals 0"; break; case 1: print "i equals 1"; break; case 2: print "i equals 2"; break; } ?> |
Åßíáé óçìáíôéêü íá êáôáëÜâåôå ðþò ç äÞëùóç switch åêôåëåßôáé ðñïêåéìÝíïõ íá áðïöåõ÷èïýí ëÜèç. Ç switch åêôåëåßôáé ãñáììÞ-ãñáììÞ (ãéá ôçí áêñßâåéá, äÞëùóç - äÞëùóç). Áñ÷éêÜ äåí åêôåëåßôáé êÜðïéïò êþäéêáò. Ìüíï üôáí ìéá äÞëùóç case âñåèåß ìå ôéìÞ ðïõ ôáéñéÜæåé ôçí ôéìÞ ôçò switch Ýêöñáóçò, ç PHP áñ÷ßæåé íá åêôåëåß ôéò äçëþóåéò. Ç PHP óõíå÷ßæåé íá åêôåëåß ôéò äçëþóåéò ìÝ÷ñé ôï ôÝëïò ôïõ switch block, Þ ôçí ðñþôç öïñÜ ðïõ èá óõíáíôÞóåé ìéá break äÞùóç. Áí äåí ãñÜøåôå ìéá break äÞëùóç óôï ôÝëïò ôçò ëßóôáò äçëþóåùí ôçò case, ç PHP èá óõíå÷ßóåé íá åêôåëåß ôéò äçëþóåéò ôçò åðüìåíçò case. Ãéá ðáñÜäåéãìá:
<?php switch ($i) { case 0: print "i equals 0"; case 1: print "i equals 1"; case 2: print "i equals 2"; } ?> |
Åäþ, áí ç $i éóïýôáé ìå 0, ç PHP èá åêôåëÝóåé üëåò ôéò åíôïëÝò print! Áí ç $i éóïýôáé ìå 1, ç PHP èá åêôåëÝóåé ôéò ôåëåõôáßåò äýï åíôïëÝò print. Èá åß÷áôå ôçí áíáìåíüìåíç óõìðåñéöïñÜ ('ç i éóïýôáé ìå 2' èá åìöáíéæüôáí) ìüíï áí ç $i éóïýôáé ìå 2. Óõíåðþò, åßíáé óçìáíôéêü íá ìçí îå÷íÜôå ôéò åíôïëÝò break (áêüìç êáé áí èÝëåôå íá áðïöýãåôå íá ôéò ôïðïèåôÞóåôå áðü ðñïèåóç êÜôù áðü ïñéóìÝíåò óõíèÞêåò).
Óå ìéá switch åíôïëÞ, ç óõíèÞêç õðïëïãßæåôáé ìüíï ìéá öïñÜ êáé ôï áðïôÝëåóìá óõãêñßíåôáé ìå êÜèå case åíôïëÞ. Óå ìéá elseif åíôïëÞ, ç óõíèÞêç õðïëïãßæåôáé îáíÜ. Áí ç óõíèÞêç óáò åßíáé ðéï ðåñßðëïêç áðü ìéá áðëÞ óýãêñéóç êáé/Þ åßíáé óå Ýíá óôåíü loop, ìéá switch ßóùò åßíáé ôá÷ýôåñç.
Ç ëßóôá ôùí äçëþóåùí ãéá ìéá case ìðïñåß åðßóçò íá åßíáé Üäåéá, ç ïðïßá áðëÜ ðåñíÜ ôïí Ýëåã÷ï óôç ëßóôá ôùí äçëþóåùí ãéá ôçí åðüìåíç case.
<?php switch ($i) { case 0: case 1: case 2: print "i is less than 3 but not negative"; break; case 3: print "i is 3"; } ?> |
Ìéá éäéáßôåñç case åßíáé ç default case. ÁõôÞ ç case ôáéñéÜæåé óå ïôéäÞðïôå äåí ôáéñéÜæïõí ïé Üëëåò cases, êáé èá ðñÝðåé íá åßíáé ç ôåëåõôáßá case åíôïëÞ. Ãéá ðáñÜäåéãìá:
<?php switch ($i) { case 0: print "i equals 0"; break; case 1: print "i equals 1"; break; case 2: print "i equals 2"; break; default: print "i is not equal to 0, 1 or 2"; } ?> |
Ç Ýêöñáóç case ìðïñåß íá åßíáé ìéá Ýêöñáóç ç ïðïßá õðïëïãßæåôáé óå Ýíáí áðëü ôýðï, ï ïðïßïò åßíáé áêÝñáéïò (integer) Þ êéíçôÞò õðïäéáóôïëÞò (floating-point), áñéèìïß Þ ãñáììáôïóåéñÝò (strings). Ðßíáêåò êáé áíôéêåßìåíá (objects) äåí ìðïñïýí íá ÷ñçóéìïðïéçèïýí åäþ, åêôüò êáé áí áíá÷èïýí óå Ýíáí áðëïýóôåñï ôýðï.
Ç åíáëëáêôéêÞ óýíôáîç ãéá äïìÝò åëÝã÷ïõ õðïóôçñßæåôáé áðü ôéò switches. Ãéá ðåñéóóüôåñåò ðëçñïïöïñßåò, äåßôå ÅíáëëáêôéêÞ óýíôáîç ãéá äïìÝò åëÝã÷ïõ .
Ç äïìÞ declare ÷ñçóéìïðïéåßôáé ãéá íá èÝóåé íôéñåêôßâåò åêôÝëåóçò (execution directives) ãéá Ýíá block êþäéêá. Ç óýíôáîç ôçò declare åßíáé ðáñüìïéá ìå ôç óýíôáîç Üëëùò äïìþí åëÝã÷ïõ ñïÞò:
Ôï êïììÜôé ôçò directive åðéôñÝðåé ôç óõìðåñéöïñÜ ôïõ declare block íá áñ÷éêïðïéçèåß. Ðñïò ôï ðáñüí ìüíï ìßá directive áíáãíùñßæåôáé: ç ticks directive. (Äåßôå ðáñáêÜôù ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôçí ticks directive)
Ôï ìÝñïò äçëþóåùí ôïõ block ôçò declare èá åêôåëåóôåß -- ðþò åêôåëåßôáé êáé ôé side effects åìöáíßæïíôáé êáôÜ ôçí åêôÝëåóç åîáñôÜôáé áðü ðþò èá ôåèåß ç directive óôï block ôçò directive.
Ç äïìÞ declare ìðïñåß åðßóçò íá ÷ñçóéìïðïéçèåß óå global åìâÝëåéá, åðçñåÜæïíôáò ïëüêëçñï ôïí êþäéêá ðïõ áêïëïõèåß.
<?php // these are the same: // you can use this: declare(ticks=1) { // entire script here } // or you can use this: declare(ticks=1); // entire script here ?> |
¸íá tick åßíáé Ýíá event ðïõ åìöáíßæåôáé ãéá êÜèå N low-level äÞëùóç ðïõ åêôåëåßôáé áðü ôïí ìåôáãëùôôéóôÞ ìÝóá óôï declare block. Ç ôéìÞ ãéá ôï N åßíáé óõãêåêñéìÝíç ÷ñçóéìïðïéþíôáò ticks=N ìÝóá óôá declare blocks ôïõ ôìÞìáôïò ôçò directive.
Ôá event(s) ðïõ åìöáíßæïíôáé óå êÜèå tick åßíáé óõãêåêñéìÝíá ÷ñçóéìïðïéþíôáò ôçí register_tick_function(). Äåßôå ôï ðáñáêÜôù ðáñÜäåéãìá ãéá ðåñéóóüôåñåò ëåðôïìÝñåéåò. Óçìåéþóôå üôé ðåñéóóüôåñá áðü Ýíá event ìðïñïýí íá åìöáíéóôïýí ãéá êÜèå tick.
ÐáñÜäåéãìá 11-1. Ôï ðñïößë Ýíïò ôìÞìáôïò êþäéêá PHP
|
Ôá ticks ôáéñéÜæïõí ùñáßá óôï debugging, õëïðïéþíôáò áðëÝò multitasking êáé backgrounded I/O åñãáóßåò êáèþò êáé äéÜöïñåò Üëëåò.
Äåßôå åðßóçò ôéò register_tick_function() êáé unregister_tick_function().
Áí êëçèåß ìÝóá áðü ìéá óõíÜñôçóç, ç äÞëùóç return() áìÝóùò ôåñìáôßæåé ôçí åêôÝëåóç ôçò ôñÝ÷ïõóáò óõíÜñôçóçò, êáé åðéóôñÝöåé ôçí ðáñÜìåôñï ôçò ùò ôéìÞ ôçò óõíÜñôçóçò ðïõ êëÞèçêå. Ç return() èá ôåñìáôßóåé åðßóçò êáé ôçí åêôÝëåóç ìéáò eval() óõíÜñôçóçò ôïõ script áñ÷åßïõ.
Áí êëçèåß áðü ðåñéï÷Þ ìå global åìâÝëåéá, ôüôå ç åêôÝëåóç ôïõ ôñÝ÷ïíôïò script ôïõ áñ÷åßïõ ôåñìáôßæåé. Áí ôï ôñÝ÷ïí script ôïõ áñ÷åßïõ Þôáí include()ed Þ require()ed, ôüôå ï Ýëåã÷ïò ðåñíÜåé ðÜëé óôï áñ÷åßïõ ðïõ åêôåëåß ôçí êëÞóç. ÅðéðëÝïí, áí ôï ôñÝ÷ïí script ôïõ áñ÷åßïõ Þôáí include()ed (óõìðåñéåëáìâáíüôáí), ôüôå ç ôéìÞ ðïõ äßíåôáé óôç return() èá åðéóôñÝöåôáé ùò ç ôéìÞ ôçò êëÞóçò ôçò include(). Áí ç return() êáëåßôáé áðü ôï êõñßùò script ôïõ áñ÷åßïõ, ôüôå ç åêôÝëåóç ôïõ script ôåñìáôßæåé. Áí ôï ôñÝ÷ïí script ôïõ áñ÷åßïõ ðÞñå ôï üíïìá áðü ôçí auto_prepend_file Þ ôçí auto_append_file åðéëïãÝò ãéá configuration óôï php.ini, ôüôå ç åêôÝëåóç ôïõ script ôïõ áñ÷åßïõ ôåñìáôßæåé.
Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äåßôå ÅðéóôñÝöïíôáò ôéìÝò.
Óçìåßùóç: Óçìåéþóôå üôé áöïý ç return() åßíáé ìéá ãëùóóéêÞ äïìÞ êáé ü÷é ìéá óõíÜñôçóç, ïé ðáñåíèÝóåéò ðïõ ðåñéêëåßïõí ôéò ðáñáìÝôñïõò ôçò äåí áðáéôïýíôáé--óôçí ðñáãìáôéêüôçôá, óõ÷íÜ ìÝíïõí åêôüò êáé äåí ÷ñçóéìïðïéïýíôáé, ðáñüëï ðïõ äåí Ý÷åé óçìáóßá áí èá êÜíïõìå ôï Ýíá Þ ôï Üëëï.
Ç äÞëùóç require() ðåñéêëåßåé êáé õðïëïãßæåé ôï óõãêåêñéìÝíï áñ÷åßï.
Ç require() ðåñéëáìâÜíåé êáé õðïëïãßæåé Ýíá óõãêåêñéìÝíï áñ÷åßï. Ëåðôïìåñåßò ðëçñïöïñßåò ó÷åôéêÜ ìå ôïí ðþò óõìðåñéëáìâÜíåôáé Ýíá áñ÷åßï äßíïíôáé óôï documentation ãéá ôçí include().
Ç require() êáé ç include() åßíáé üìïéåò óå êÜèå ðåñßðôùóç åêôüò áðü ôï ðþò ÷åéñßæïíôáé ôçí failure (áðïôõ÷ßá). Ç include() ðáñÜãåé Ýíá Warning åíþ ç require() êáôáëÞãåé óå Ýíá Fatal Error. Ìå Üëëá ëüãéá, ìç äéóôÜóåôå íá ÷ñçóéìïðïéÞóåôå ôçí require() áí èÝëåôå Ýíá ÷áìÝíï áñ÷åßï íá óôáìáôÞóåé ôçí åðåîåñãáóßá ôçò óåëßäáò. Ç include() äåí óõìðåñéöÝñåôáé ìå áõôüí ôïí ôñüðï, ôï script èá óõíå÷ßóåé íá åêôåëåßôáé. Âåâáéùèåßôå üôé Ý÷åôå ïñßóåé óùóôÜ ôï include_path.
ÐáñÜäåéãìá 11-2. ÂáóéêÜ ðáñáäåßãìáôá ôçò require()
|
Äåßôå ôï documentation ãéá ôçí include() ãéá ðåñéóóüôåñá ðáñáäåßãìáôá.
Óçìåßùóç: Óôçí PHP 4.0.2, åöáñìüæåôáé ôï áêüëïõèï: ç require() ðÜíôá èá ðñïóðáèåß íá äéáâÜóåé ôï áñ÷åßï ðñïïñéóìïý, áêüìç êáé áí ç ãñáììÞ óôçí ïðïßá âñßóêåôáé äåí åêôåëåßôáé ðïôÝ. Ç õðïèåôéêÞ óõíèÞêç äå èá åðçñåÜóåé ôçí require(). Ðáñüëáõôá, áí ç ãñáììÞ óôçí ïðïßá åìöáíßæåôáé ç require() äåí åêôåëåóôåß, äå èá åêôåëåóôåß êáé êáíÝíá êïììÜôé êþäéêá óôï áñ÷åßï ðñïïñéóìïý. Ïìïßùò, ïé äïìÝò åðáíÜëçøçò äåí åðçñåÜæïõí ôç óõìðåñéöïñÜ ôçò require(). Ðáñüëï ðïõ ï êþäéêáò ðïõ ðåñéÝ÷åôáé óôï áñ÷åßï ðñïïñéóìïý õðüêåéôáé áêüìç óôï loop, ç ßäéá ç require() óõìâáßíåé ìüíï ìéá öïñÜ.
Óçìåßùóç: ÅðåéäÞ áõôü åßíáé ìéá äïìÞ ôçò ãëþóóáò êáé ü÷é ìéá óõíÜñôçóç, äåí ìðïñåß íá êáëåóôåß ÷ñçóéìïðïéþíôáò óõíáñôÞóåéò ìåôáâëçôþí
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
Äåßôå åðßóçò ôéò include(), require_once(), include_once(), eval(), file(), readfile(), virtual() êáé ôçí include_path.
Ç äÞëùóç include() óõìðåñéëáìâÜíåé êáé õðïëïãßæåé ôï óõãêåêñéìÝíï áñ÷åßï.
Ôï ðáñáêÜôù áñ÷åßï åöáñìüæåôáé êáé óôçí require(). Ïé äõï äïìÝò åßíáé üìïéåò óå êÜèå ðåñßðôùóç åêôüò áðü ôï ðþò ÷åéñßæïíôáé ôçí failure (áðïôõ÷ßá). Ç include() ðáñÜãåé Ýíá Warning åíþ ç require() êáôáëÞãåé óå Ýíá Fatal Error. Ìå Üëëá ëüãá, ÷ñçóéìïðïéÞóôå ôçí require() áí èÝëåôå Ýíá ÷áìÝíï áñ÷åßï íá óôáìáôÞóåé ôçí åðåîåñãáóßá ìéáò óåëßäáò. Ç include() äåí óõìðåñéöÝñåôáé ì'áõôüí ôïí ôñüðï, Ýôóé ôï script èá óõíå÷éóôåß. Âåâáéùèåßôå üôé Ý÷åôå ïñßóåé ôï include_path óùóôÜ.
¼ôáí óõìðåñéëáìâÜíåôáé Ýíá áñ÷åßï, ï êþäéêáò ðïõ ðåñéÝ÷åé êëçñïíïìåß ôçí variable scope (åìâÝëåéá ôçò ìåôáâëçôÞò) óôç ãñáììÞ óôçí ïðïßá åìöáíßæåôáé ôï include. ¼ðïéåò ìåôáâëçôÝò åßíáé äéáèÝóéìåò óôç ãñáììÞ åêåßíç óôï áñ÷åßï ðïõ êáëåß, èá åßíáé äéáèÝóéìåò êáé ìÝóá óôï êáëïýìåíï áñ÷åßï, áðü ôï óçìåßï åêåßíï êáé ìåôÜ.
ÐáñÜäåéãìá 11-3. ÂáóéêÜ ðáñáäåßãìáôá ôçò include()
|
Áí ôï include ãßíåé ìÝóá óå ìéá óõíÜñôçóç ôïõ áñ÷åßïõ ðïõ êÜíåé ôçí êëÞóç, ôüôå ïëüêëçñïò ï êþäéêáò ðïõ ðåñéëáìâÜíåôáé óôï êáëïýìåíï áñ÷åßï èá óõìðåñéöÝñåôáé óáí íá åß÷å ïñéóôåß ìÝóá ó'áõôÞ ôç óõíÜñôçóç. Óõíåðþò, èá Ý÷åé êáé ôçí åìâÝëåéá ôçò ìåôáâëçôÞò áõôÞò ôçò óõíÜñôçóçò.
ÐáñÜäåéãìá 11-4. ¼ôáí ãßíåôáé Include ìÝóá óå óõíáñôÞóåéò
|
¼ôáí Ýíá áñ÷åßï óõìðåñéëáìâÜíåôáé, êáôÜ ôç äéÜñêåéá ôïõ parsing âãáßíåé åêôüò PHP mode êáé åßíáé óå HTML mode óôçí áñ÷Þ ôïõ áñ÷åßïõ ðñïïñéóìïý, êáé óõíå÷ßæåé îáíÜ óôï ôÝëïò. Ãé'áõôü ôï ëüãï, ïðïéïäÞðïôå êïììÜôé êþäéêá ìÝóá óôï áñ÷åßï ðñïïñéóìïý ôï ïðïßï èÝëïõìå íá åêôåëåßôáé ùò PHP êþäéêáò ðñÝðåé íá âñßóêåôáé ìÝóá óå Ýãêõñá tags Ýíáñîçò êáé ôåñìáôéóìïý ôçò PHP.
Áí ôá "URL fopen wrappers" åßíáé åíåñãïðïéçìÝíá óôçí PHP (ôï ïðïßï åßíáé êáé ç ðñïêáèïñéóìÝíç åðéëïãÞ), ìðïñåßôå íá ðñïóäéïñßóåôå ôï áñ÷åßï ðïõ èá óõìðåñéëÜâåôå ÷ñçóéìïðïéþíôáò ôï URL ôïõ (äéáìÝóïõ HTTP Þ Üëëïí wrapper ðïõ õðïóôçñßæåôáé - âëÝðå ÐáñÜñôçìá J ãéá ìéá ëßóôá ðñùôïêüëùí) óå áíôßèåóç ìå ôï ôïðéêü pathname. Áí ï target server äéåñìçíåýåé ôï áñ÷åßï ðñïïñéóìïý ùò PHP êþäéêá, ïé ìåôáâëçôÝò ìðïñïýí íá ðåñáóôïýí óôï áñ÷åßï ðïõ óõìðåñéëáìâÜíåôáé ÷ñçóéìïðïéþíôáò Ýíá URL request string üðùò ÷ñçóéìïðïéåßôáé ìå ôçí HTTP GET. Áõôü äåí åßíáé áðüëõôá ôï ßäéï ìå ôï íá óõìðåñéëÜâïõìå ôï áñ÷åßï êáé íá ôï êÜíïõìå íá êëçñïíïìåß ôçí åìâÝëåéá ôùí ìåôáâëçôþí ôïõ áñ÷åßïõ-ãïíéïý. Ôï script óôçí ðñáãìáôéêüôçôá åêôåëåßôáé óôïí áðïìáêñõóìÝíï server êáé ôï áðïôÝëåóìá óôç óõíÝ÷åéá óõìðåñéëáìâÜíåôáé óôï ôïðéêü script.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
ÐáñÜäåéãìá 11-5. Ç include() ìÝóù HTTP
|
ÅðåéäÞ ç include() êáé ç require() åßíáé éäéáßôåñåò ãëùóóéêÝò äïìÝò, ðñÝðåé íá ôéò óõìðåñéëÜâåôå ìÝóá óå Ýíá ìðëïê äçëþóåùí áí âñßóêïíôáé ìÝóá ó'åíá ìðëïê õðüèåóçò.
×ñçóéìïðïéþíôáò ôá Returns: Åßíáé ðéèáíü íá åêôåëåóôåß ìéá äÞëùóç return() ìÝóá óå Ýíá åìðåñéå÷üìåíï áñ÷åßï ðñïêåéìÝíïõ íá ôåñìáôéóôåß ç åðåîåñãáóßá óå åêåßíï ôï áñ÷åßï êáé íá åðéóôñÝøïõìå óôï script ðïõ ôï êÜëåóå. Åðßóçò, åßíáé ðéèáíü íá åðéóôñÝøïõìå ôéìÝò áðü óõìðåñéëáìâáíüìåíá áñ÷åßá. Ìðïñåßôå íá ðÜñåôå ôçí ôéìÞ áðü ôçí êëÞóç ôçò include üðùò èá êÜíáôå êáé ìå ìéá êáíïíéêÞ óõíÜñôçóç.
Óçìåßùóç: Óôçí PHP 3, ç return ìðïñåß íá ìçí åìöáíéóôåß ìÝóá óå Ýíá ìðëïê åêôüò êáé áí åßíáé Ýíá ìðëïê óõíÜñôçóçò, üðïõ ç return() åöáñìüæåôáé óôçí óõãêåêñéìÝíç óõíÜñôçóç êáé ü÷é óå ïëüêëçñï ôï áñ÷åßï.
Ç $bar Ý÷åé ôçí ôéìÞ 1 åðåéäÞ ç include Þôáí åðéôõ÷Þò. Ðáñáôçñåßóôå ôéò äéáöïñÝò óôá ðáñáðÜíù äõï ðáñáäåßãìáôá. Ôï ðñþôï ÷ñçóéìïðïéåß ôçí return() ìÝóá óôï óõìðåñéåëáìâáíüìåíï áñ÷åßï åíþ ôï Üëëï äåí ôï êÜíåé. Ìåñéêïß Üëëïé ôñüðïé ãéá íá "óõìðåñéëÜâïõìå" áñ÷åßá ìÝóá óå ìåôáâëçôÝò åßíáé ìå ôéò fopen(), file() Þ ÷ñçóéìïðïéþíôáò ôçí include() ìáæß ìå ôéò Output Control Functions.
Óçìåßùóç: ÅðåéäÞ áõôü åßíáé ìéá äïìÞ ôçò ãëþóóáò êáé ü÷é ìéá óõíÜñôçóç, äåí ìðïñåß íá êáëåóôåß ÷ñçóéìïðïéþíôáò óõíáñôÞóåéò ìåôáâëçôþí
Äåßôå åðßóçò ôéò require(), require_once(), include_once(), readfile(), virtual(), êáé ôçí include_path.
Ç äÞëùóç require_once() ðåñéëáìâÜíåé êáé õðïëïãßæåé ôï óõãêåêñéìÝíï áñ÷åßï êáôÜ ôç äéÜñêåéá ôçò åêôÝëåóçò ôïõ script. ÁõôÞ ç óõìðåñéöïñÜ åßíáé üìïéá ìå ôç äÞëùóç require() , ìå ôç ìüíç äéáöïñÜ üôé áí ï êþäéêáò áðü Ýíá áñ÷åßï Ý÷åé Þäç óõìðåñéëçöèåß, ôüôå äå èá îáíáóõìðåñéëçöèåß. Äåßôå ôï documentation ãéá ôçí require() ãéá ðåñéóóüôåñåò ðëçñïïöïñßåò ó÷åôéêÜ ìå ôï ðþò äïõëåýåé áõôÞ ç äÞëùóç.
Ç require_once() èá ðñÝðåé íá ÷ñçóéìïðïéåßôáé óå ðåñéðôþóåéò ðïõ õðÜñ÷åé ç ðéèáíüôçôá íá îáíáóõìðåñéëÜâïõìå êáé íá îáíáûðïëïãßóïõìå ôï ßäéï áñ÷åßï ðåñéóóüôåñåò áðü ìéá öïñÝò êáôÜ ôç äéÜñêåéá ôçò åêôÝëåóçò åíüò óõãêåêñéìÝíïõ script, êáé èÝëïõìå íá åßìáóôå óßãïõñïé üôé óõìðåñéëáìâÜíåôáé áêñéâþò ìéá öïñÜ ðñïêåéìÝíïõ íá áðïöýãïõìå ðñïâëÞìáôá ìå åðáíáêáèïñéóìü óõíáñôÞóåùí, áíáèÝóåéò ôéìþò óå ìåôáâëçôÝò, êá.
Ãéá ðáñáäåßãìáôá óôç ÷ñÞóç ôùí require_once() êáé include_once(), êïéôÜîôå ôï PEAR êþäéêá ðïõ óõìðåñéëáìâÜíåôáé óôçí ôåëåõôáßá Ýêäïóç ôïõ source code ôçò PHP.
Óçìåßùóç: Ç require_once() ðñïóôÝèçêå óôçí PHP 4.0.1pl2
Óçìåßùóç: ÐñïóÝîôå üôé ç óõìðåñéöïñÜ ôçò require_once() êáé ôçò include_once() ìðïñåß íá ìçí åßíáé áõôÞ ðïõ ðåñéìÝíåôå óå Ýíá ëåéôïõñãéêü óýóôçìá ðïõ äåí åßíáé case sensitive (üðùò ôá Windows).
ÐáñÜäåéãìá 11-8. Ç require_once() åßíáé case sensitive
<?php require_once("a.php"); // this will include a.php require_once("A.php"); // this will include a.php again on Windows! ?>
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
Äåßôå åðßóçò: require(), include(), include_once(), get_required_files(), get_included_files(), readfile(), êáé virtual().
Ç äÞëùóç include_once() ðåñéëáìâÜíåé êáé õðïëïãßæåé ôï óõãêåêñéìÝíï áñ÷åßï êáôÜ ôç äéÜñêåéá ôçò åêôÝëåóçò ôïõ script. ÁõôÞ ç óõìðåñéöïñÜ åßíáé üìïéá ìå ôç äÞëùóç include() , ìå ôç ìüíç äéáöïñÜ üôé áí ï êþäéêáò áðü Ýíá áñ÷åßï Ý÷åé Þäç óõìðåñéëçöèåß, äå èá îáíáóõìðåñéëçöèåß. ¼ðùò ëÝåé êáé ôï üíïìá ôïõ, èá óõìðåñéëçöèåß ìüíï ìéá öïñÜ.
Ç include_once() ðñÝðåé íá ÷ñçóéìïðïéåßôáé óå ðåñéðôþóåéò ðïõ ôï ßäéï áñ÷åßï ìðïñåß íá óõìðåñéëçöèåß êáé íá õðïëïãéóôåß ðåñéóóüôåñåò áðü ìéá öïñÝò êáôÜ ôçí åêôÝëåóç åíüò óõãêåêñéìÝíïõ script, êáé èÝëåôå íá åßóôå óßãïõñïé üôé óõìðåñéëáìâÜíåôáé áêñéâþò ìßá öïñÜ ðñïêåéìÝíïõ íá áðïöýãåôå ðñïâëÞìáôá ìå åðáíáðñïóäéïñéóìü óõíáñôÞóåùí, íÝá áíÜèåóç ôéìþò óôéò ìåôáâëçôÝò, êá.
Ãéá ðåñéóóüôåñá ðáñáäåßãìáôá ó÷åôéêÜ ìå ôç ÷ñÞóç ôçò require_once() êáé ôçò include_once(), äåßôå óôï PEAR êïììÜôé êþäéêá ðïõ óõìðåñéëáìâÜíåôáé óôçí ôåëåõôáßá Ýêäïóç ôïõ source code ôçò PHP.
Óçìåßùóç: Ç include_once() ðñïóôÝèçêå óôçí PHP 4.0.1pl2
Óçìåßùóç: ÐñïóÝîôå üôé ç óõìðåñéöïñÜ ôçò require_once() êáé ôçò include_once() ìðïñåß íá ìçí åßíáé áõôÞ ðïõ ðåñéìÝíåôå óå Ýíá ëåéôïõñãéêü óýóôçìá ðïõ äåí åßíáé case sensitive (üðùò ôá Windows).
ÐáñÜäåéãìá 11-9. Ç include_once() åßíáé case sensitive
<?php include_once("a.php"); // this will include a.php include_once("A.php"); // this will include a.php again on Windows! ?>
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
Äåßôå åðßóçò ôéòinclude(), require(), require_once(), get_required_files(), get_included_files(), readfile(), êáé virtual().
Ìéá óõíÜñôçóç ìðïñåß íá ïñéóôåß ÷ñçóéìïðïéþíôáò ôçí áêüëïõèç óýíôáîç:
ÏðïéïóäÞðïôå Ýãêõñïò PHP êþäéêáò ìðïñåß íá åìöáíéóôåß óå ìéá óõíÜñôçóç, áêüìç êáé óå Üëëåò óõíáñôÞóåéò êáé óå ïñéóìïýò êëÜóåùí (class).
Óôçí PHP 3, ïé óõíáñôÞóåéò ðñÝðåé íá ïñßæïíôáé ðñéí ãßíåé êÜðïéá áíáöïñÜ ó' áõôÝò. ÔÝôïéá áðáßôçóç äåí õðÜñ÷åé óôçí PHP 4. Åêôüò áí ç óõíÜñôçóç ïñßæåôáé óå ìéá õðüèåóç üðùò ìðïñåßôå íá äåßôå óôá ðáñáêÜôù äýï ðáñáäåßãìáôá.
¼ôáí ìéá óõíÜñôçóç ïñßæåôáé ìå õðïèåôéêü ôñüðï üðùò óôá äõï ðáñáêÜôù ðáñáäåßãìáôá ï ïñéóìüò ôçò ðñÝðåé íá ðñïçãåßôáé áðü ôï óçìåßï óôï ïðïßï êáëåßôáé.
ÐáñÜäåéãìá 12-2. ÕðïèåôéêÝò óõíáñôÞóåéò
|
Ç PHP äåí õðïóôçñßæåé õðåñöüñôùóç óõíáñôÞóåùí (function overloading), ïýôå åßíáé äõíáôü íá õðÜñ÷ïõí ìç-êáèïñéóìÝíåò Þ îáíÜ-êáèïñéóìÝíåò óõíáñôÞóåéò ðïõ Ý÷ïõí äçëùèåß ðñïçãïõìÝíùò.
Óçìåßùóç: Ôá ïíüìáôá ôùí óõíáñôÞóåùí åßíáé case-insensitive, áëëÜ ãåíéêÜ åßíáé êáëÞ ôáêôéêÞ íá êáëïýìå ôéò óõíáñôÞóåéò üðùò åìöáíßæïíôáé óôç äÞëùóç ôïõò.
Ç PHP 3 äåí õðïóôçñßæåé ìåôáâëçôÝò áñéèìþí Þ ðáñáìÝôñïõò óôéò óõíáñôÞóåéò, ðáñüëï ðïõ ïé ðñïêáèïñéóìÝíåò ðáñÜìåôñïé õðïóôçñßæïíôáé (âëÝðå ÔéìÝò ðñïêáèïñéóìÝíùí ðáñáìÝôñùí ãéá ðåñéóóüôåñåò ðëçñïöïñßåò). Ç PHP 4 õðïóôçñßæåé êáé ôá äõï: âëÝðå Ëßóôåò ìåôáâëçôïý ìÞêïõò ðáñáìÝôñùí êáé ôéò áíáöïñÝò óôéò óõíáñôÞóåéò ãéá ôéò func_num_args(), func_get_arg(), êáé func_get_args() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Ç ðëçñïöïñßá ìðïñåß íá ðåñÜóåé óôéò óõíáñôÞóåéò äéáìÝóïõ ôçò ëßóôáò ðáñáìÝôñùí, ç ïðïßá åßíáé ìéá ëßóôá ìåôáâëçôþí Þ/êáé óôáèåñþí ðïõ äéá÷ùñßæïíôáé ìå êüììáôá.
Ç PHP õðïóôçñßæåé ôï ðÝñáóìá ôùí ðáñáìÝôñùí ìå ôéìÞ (ôï ðñïêáèïñéóìÝíï), ðÝñáóìá ìå áíáöïñÜ, êáé ðñïêáèïñéóìÝíåò ôéìÝò ðáñáìÝôñùí. Ïé ëßóôåò ðáñáìÝôñùí ìåôáâëçôïý ìÞêïõò õðïóôçñßæïíôáé ìüíï áðü ôçí PHP 4 êáé ìåôÜ. ÂëÝðå ëßóôåò ðáñáìÝôñùí ìåôáâëçôïý ìÞêïõò êáé ôéò áíáöïñÝò óõíáñôÞóåùí ãéá ôéò func_num_args(), func_get_arg(), êáé func_get_args() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò. ¸íá ðáñüìïéï áðïôÝëåóìá ìðïñåß íá åðéôåõ÷èåß óôçí PHP 3 ðåñíþíôáò Ýíáò ðßíáêá ðáñáìÝôñùí óôç óõíÜñôçóç:
Åßíáé ðñïêáèïñéóìÝíï üôé ïé ðáñÜìåôñïé ôùí óõíáñôÞóåùí ìåôáâéâÜæïíôáé ìå ôéìÞ (by value) (Ýôóé þóôå áí áëëÜîåôå ôçí ôéìÞ ìéáò ðáñáìÝôñïõ ìÝóá óôç óõíÜñôçóç, áõôÞ äåí áëëÜæåé Ýîù áðü ôç óõíÜñôçóç). Áí èÝëåôå íá åðéôñÝøåôå óå ìéá óõíÜñôçóç íá áëëÜîåé ôéò ðáñáìÝôñïõò ôçò, èá ðñÝðåé íá ôéò ðåñÜóåôå ìå áíáöïñÜ.
Áí èÝëåôå ìéá ðáñÜìåôñïò óõíÜñôçóçò íá ôçí ðåñíÜôå ðÜíôá ìå áíáöïñÜ, ìðïñåßôå íá âÜëåôå ùò ðñüèåìá Ýíá ampersand (&) óôï üíïìá ôçò ðáñáìÝôñïõ óôüí ïñéóìü ôçò óõíÜñôçóçò:
Ìéá óõíÜñôçóç ìðïñåß íá ïñßóåé ðñïêáèïñéóìÝíåò ôéìÝò óáí ôç C++ ãéá âáèìùôÝò ðáñáìÝôñïõò ùò áêïëïýèùò:
Ôï áðïôÝëåóìá ôïõ ðáñáêÜôù êþäéêá åßíáé:
Making a cup of cappuccino. Making a cup of espresso. |
Ç ðñïêáèïñéóìÝíç ôéìÞ ðñÝðåé íá åßíáé ìéá óôáèåñÞ Ýêöñáóç, ü÷é (ãéá ðáñÜäåéãìá) ìéá ìåôáâëçôÞ Þ Ýíá ìÝëïò ìéáò êëÜóçò.
Óçìåéþóôå üôé üôáí ÷ñçóéìïðïéïýìå ðñïêáèïñéóìÝíåò ðáñáìÝôñïõò, ïðïéåóäÞðïôå ðñïêáèïñéóìÝíåò èá ðñÝðåé íá åßíáé óôç äåîéÜ ìåñéÜ áðü ïðïéåóäÞðïôå ìç êáèïñéóìÝíåò ðáñáìÝôñïõò, äéáöïñåôéêÜ, ôá ðñÜãìáôá äå èá äïõëÝøïõí üðùò ðåñéìÝíïõìå. Èåùñåßóôå ôï áêüëïõèï êïììÜôé êþäéêá:
Ôï áðïôÝëåóìá ôïõ ðáñáðÜíù ðáñáäåßãìáôïò åßíáé:
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 . |
Ôþñá, óõãêñßíåôå ôï ðáñáðÜíù ìå áõôü:
Ôï áðïôÝëåóìá óõôïý ôïõ ðáñáäåßãìáôïò åßíáé:
Making a bowl of acidophilus raspberry. |
Ç PHP 4 õðïóôçñßæåé ëßóôåò ðáñáìÝôñùí ìåôáâëçôïý ìÞêïõò óôéò óõíáñôÞóåéò ðïõ êáèïñßæïíôáé áðü ôïí ÷ñÞóôç. Áõôü åßíáé áñêåôÜ åýêïëï, ÷ñçóéìïðïéþíôáò ôéò func_num_args(), func_get_arg(), êáé func_get_args() óõíáñôÞóåéò.
Äåí áðáéôåßôáé êÜðïéá éäéáßôåñç óýíôáîç, êáé ïé ëßóôåò ðáñáìÝôñùí ìðïñïýí ìå óáöÞíåéá íá ðáñá÷èïýí ìå ôïõò ïñéóìïýò ôùí óõíáñôÞóåùí êáé íá óõìðåñéöÝñïíôáé êáíïíéêÜ.
Ïé ôéìÝò åðéóôñÝöïíôáé ÷ñçóéìïðïéþíôáò ôçí ðñïáéñåôéêÞ äÞëùóç åðéóôñïöÞò (return). ÏðïéóäÞðïôå ôýðïò ìðïñåß íá åðéóôñáöåß, óõìðåñéëáìâáíïìÝíïõ ëßóôåò êáé áíôéêåßìåíá. Áõôü ðñïêáëåß ôç óõíÜñôçóç íá óôáìáôÞóåé ôçí åêôÝëåóç ôçò áìÝóùò êáé íá ðåñÜóåé ï Ýëåã÷ïò ðßóù óôç ãñáììÞ áðü ôçí ïðïßá ôçí êáëÝóáìå. ÂëÝðå return() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
ÐáñÜäåéãìá 12-9. ×ñÞóç ôçò return()
|
Äåí ìðïñïýí íá óáò åðéóôñáöïýí ðïëëÝò ôéìÝò áðü ìéá óõíÜñôçóç, áëëÜ ðáñüìïéá áðïôåëÝóìáôá ìðïñïýí íá åðéôåõ÷èïýí åðéóôñÝöïíôáò Ýíá ðßíáêá.
Ãéá íá åðéóôñÝøåôå ìéá áíáöïñÜ áðü ìéá óõíÜñôçóç, ðñÝðåé íá ÷ñçóéìïðïéÞóåôå ôïí ôåëåóôÞ áíáöïñÜò & ôüóï óôç äÞëùóç ôçò óõíÜñôçóçò üóï êáé üôáí áíáèÝôå ôçí åðéóôñåöüìåíç ôéìÞ óå ìéá ìåôáâëçôÞ:
Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò óôéò áíáöïñÝò, äåßôå ôï êåöÜëáéï ÅðåîÞãçóç áíáöïñþí.
Ç PHP õðïóôçñßæåé ôçí Ýííïéá ôùí ìåôáâëçôþí óõíáñôÞóåùí. Áõôü óçìáßíåé ðùò áí Ýíá üíïìá ìåôáâëçôÞò Ý÷åé ðáñåíèÝóåéò, ç PHP èá øÜîåé ãéá ìéá óõíÜñôçóç ìå ôï ßäéï üíïìá ðïõ ðïõ ôçò äßíåé ç ìåôáâëçôÞ êáé èá ðñïóðáèÞóåé íá ôï åêôåëÝóåé. ÁíÜìåóá óôá Üëëá ðñÜãìáôá, áõôü ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá ôçí õëïðïßçóç callbacks, ðßíáêåò óõíáñôÞóåùí ê.á.
Ïé ìåôáâëçôÝò óõíáñôÞóåéò äå èá äïõëÝøïõí ìå äïìÝò ãëþóóáò üðùò ïé echo(), print(), unset(), isset(), empty(), include(), require() êáé Üëëåò ðáñüìïéåò. ×ñåéÜæåôå íá ÷ñçóéìïðïéÞóåôå ôç äéêÞ óáò wrapper óõíÜñôçóç ãéá íá ÷ñçóéìïðïéÞóåôå ïðïéáäÞðïôå áðü ôéò äïìÝò ùò ìåôáâëçôÞ óõíÜñôçóç.
ÐáñÜäåéãìá 12-12. ÐáñÜäåéãìá ìåôáâëçôÞò óõíÜñôçóçò
|
Ìðïñåßôå åðßóçò íá êáëÝóåôå ôç ìÝèïäï åíüò áíôéêåéìÝíïõ ÷ñçóéìïðïéþíôáò ôï ÷áñáêôçñéóôéêü ôùí ìåôáâëçôþí óõíáñôÞóåùí.
Äåßôå åðßóçò ôá êåöÜëáéá ó÷åôéêÜ ìå ôá call_user_func(), ìåôáâëçôÝò ìåôáâëçôÝò êáé function_exists().
Ç PHP Ýñ÷åôáé ìå ðïëëÝò óõíáñôÞóåéò êáé äïìÝò. ÕðÜñ÷ïõí üìùò êáé óõíáñôÞóåéò ðïõ áðáéôïýí åéäéêÝò ìåôáãëùôôéóìÝíåò åðåêôÜóåéò (extensions) ôçò PHP äéáöïñåôéêÜ èá ðÜñåôå ëÜèç ó÷åôéêÜ ìå "ìç ïñéóìÝíåò óõíáñôÞóåéò". Ãéá ðáñÜäåéãìá, ãéá íá ÷ñçóéìïðïéÞóåôå óõíáñôÞóåéò image üðùò ç imagecreatetruecolor(), èá ÷ñåéáóôåß íá ìåôáãëùôôßóåôå ôçí PHP ìå GD õðïóôÞñéîç. ¹, ãéá íá ÷ñçóéìïðïéÞóåôå ôçí mysql_connect() èá ÷ñåéáóôåß íá ìåôáãëùôôßóåôå ôçí PHP ìå õðïóôÞñéîç MySQL. ÕðÜñ÷ïõí ðïëëÝò âáóéêÝò óõíáñôÞóåéò ðïõ óõìðåñéëáìâÜíïíôáé óå êÜèå Ýêäïóç ôçò PHP üðùò ïé string êáé ïé variable ÓõíáñôÞóåéò. Ìéá êëÞóç óôçí phpinfo() Þ óôçí get_loaded_extensions() èá óáò äåßîåé ðïéåò åðåêôÜóåéò Ý÷ïõí öïñôùèåß óôç äéêÞ óáò PHP. Åðßóçò, óçìåéþóôå üôé ðïëëÝò åðåêôÜóåéò åßíáé åíåñãïðïéçìÝíåò êáé üôé ôï PHP manual åßíáé äéá÷ùñéóìÝíï áíÜ åðÝêôáóç. Äåßôå ôá êåöÜëáéá ãéá configuration, installation, êáèþò êáé ãéá åðåêôÜóåéò, ãéá íá ðëçñïöïñçèåßôå ó÷åôéêÜ ìå ôï ðþò íá åãêáôáóôÞóåôå ôçí PHP.
Ôï íá äéáâÜóåôå êáé íá êáôáíïÞóåôå Ýíá ðñùôüôõðï óõíÜñôçóçò åîçãåßôáé ìÝóá óôï ôìÞìá ôïõ manual ìå ôïí ôßôëï ðþò íá äéáâÜóåôå ôïí ïñéóìü ìéáò óõíÜñôçóçò. Åßíáé óçìáíôéêü íá êáôáëÜâåôå ôé åðéóôñÝöåé ìéá óõíÜñôçóç Þ áí ìéá óõíÜñôçóç äïõëåýåé êáôåõèåßáí ðÜíù óå ìéá ôéìÞ ðïõ ôçò Ý÷åé ðåñáóôåß. Ãéá ðáñÜäåéãìá, ç str_replace() èá åðéóôñÝøåé ôï ôñïðïðïéçìÝíï string åíþ ç usort() åíåñãåß ðÜíù óôçí ßäéá ìåôáâëçôÞ ðïõ ðåñÜóáìå. ÊÜèå óåëßäá ôïõ manual Ý÷åé åðßóçò óõãêåêñéìÝíåò ðëçñïöïñßåò ãéá êÜèå óõíÜñôçóç üðùò ðëçñïöïñßåò ðÜíù óôéò ðáñáìÝôñïõò ôùí óõíáñôÞóåùí, áëëáãÞ óôç óõìðåñéöïñÜ, ôéìÝò ðõï åðéôñÝöïíôáé ôüóï áí åðéôý÷åé üóï êáé áí áðïôý÷åé, êáé ðëçñïöïñßá äéáèåóéìüôçôáò. Ç ãíþóç áõôþí ôùí óçìáíôéêþí (áëëÜ ðáñüëáõôá ìéêñþí) äéáöïñþí åßíáé êñßóéìï óôï íá ãñÜöïõìå óùóôü PHP êþäéêá.
Äåßôå åðßóçò ôéò function_exists(), the function reference, get_extension_funcs(), êáé dl().
Ìßá êëÜóç (class) åßíáé ìéá óõëëïãÞ ìåôáâëçôþí êáé óõíáñôÞóåùí ðïõ äïõëåýïõí ì'áõôÝò ôéò ìåôáâëçôÝò. Ìßá class ïñßæåôáé óýìöùíá ìå ôçí áêüëïõèç óýíôáîç:
<?php class Cart { var $items; // Items in our shopping cart // Add $num articles of $artnr to the cart function add_item ($artnr, $num) { $this->items[$artnr] += $num; } // Take $num articles of $artnr out of the cart function remove_item ($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } else { return false; } } } ?> |
Áõôü ïñßæåé ìéá class ìå ôï üíïìá Cart ç ïðïßá áðïôåëåßôáé áðü Ýíáí óõó÷åôéóôéêü ðßíáêá (associative array) áðü Üñèñá óôï êáëÜèé (cart) êáé äõï óõíáñôÞóåéò ïé ïðïßåò ðñïóèÝôïõí êáé áöáéñïýí áíôéêåßìåíá áðü ôï êáëÜèé.
Ðñïåéäïðïßçóç |
ÄÅÍ ìðïñåßôå íá óðÜóåôå ôïí ïñéóìü ìéáò class definition óå ðïëëÜ áñ÷åßá, Þ ðïëëÜ PHP blocks. Ôï áêüëïõèï äå èá äïõëÝøåé:
|
Ïé áêüëïõèåò ðñïôåéíüìåíåò óçìåéþóåéò éó÷ýïõí ãéá ôçí PHP 4.
Ðñïóï÷Þ |
Ôï üíïìá stdClass ÷ñçóéìïðïéåßôáé áðü ôçí Zend êáé óõíåðþò åßíáé äåóìåõìÝíï. Äåí ìðïñåßôå íá Ý÷åôå êëÜóåéò ìå ôï üíïìá stdClass óôçí PHP. |
Ðñïóï÷Þ |
Ïé óõíáñôÞóåéò ìå ôá ïíüìáôá __sleep êáé __wakeup åßíáé ìáãéêÝò êëÜóåéò ôçò PHP. Äåí ìðïñåßôå íá Ý÷åôå óõíáñôÞóåéò ìå áõôÜ ôá ïíüìáôá óå êáìßá áðü ôéò êëÜóåéò óáò åêôüò êáé áí èÝëåôå íá ôéò ÷ñçóéìïðïéÞóåôå. Äåßôå ðáñáêÜôù ãéá ðåñéóóüôåñåò ðëçñïöïñßåò. |
Ðñïóï÷Þ |
Ç PHP äåóìåýåé üëåò ôéò óõíáñôÞóåéò ðïõ ôá ïíüìáôá ôïõò áñ÷ßæïõí ìå ôï __ ùò ìáãéêÝò. ÓõíéóôÜôáé íá ìçí ÷ñçóéìïðïéåßôå óõíáñôÞóåéò ìå üíïìáôá ðïõ áñ÷ßæïõí áðü __ in PHP åêôüò êáé áí èÝëåôå íá ÷ñçóéìïðïéÞóåôå ôéò ìáãéêÝò äõíáôüôçôåò ôïõò. |
Óôçí PHP 4, ìüíï áñ÷éêïðïéÞóåéò ìå óôáèåñÝò åðéôñÝðïíôáé ãéá ôéò var ìåôáâëçôÝò. Ãéá íá áñ÷éêïðïéÞóåôå ìåôáâëçôÝò ìå ìç-óôáèåñÝò ôéìÝò, ÷ñåéÜæåóôå ìéá óõíÜñôçóç áñ÷éêïðïßçóçò ç ïðïßá êáëåßôáé áõôüìáôá üôáí Ýíá áíôéêåßìåíï äçìéïõñãåßôáé áðü ìßá êëÜóç. Ìéá ôÝôïéá óõíÜñôçóç êáëåßôáé constructor (äåßôå ðáñáêÜôù).
<?php /* None of these will work in PHP 4. */ class Cart { var $todays_date = date("Y-m-d"); var $name = $firstname; var $owner = 'Fred ' . 'Jones'; var $items = array("VCR", "TV"); } /* This is how it should be done. */ class Cart { var $todays_date; var $name; var $owner; var $items; function Cart() { $this->todays_date = date("Y-m-d"); $this->name = $GLOBALS['firstname']; /* etc. . . */ } } ?> |
Ïé êëÜóåéò åßíáé ôýðïé, áõôü ðñáãìáôéêÜ åßíáé, åßíáé ó÷åäéáãñÜììáôá ãéá ôéò ðñáãìáôéêÝò ìåôáâëçôÝò. Ãéá íá äçìéïõñãÞóåôå ìéá ìåôáâëçôÞ ôïõ åðéèõìçôïý ôýðïõ ðñÝðåé íá ÷ñçóéìïðïéÞóåôå ôïí ôåëåóôÞnew.
<?php $cart = new Cart; $cart->add_item("10", 1); $another_cart = new Cart; $another_cart->add_item("0815", 3); ?> |
Áõôü äçìéïõñãåß ôá áíôéêåßìåíá $cart êáé $another_cart, êáé ôá äõï óôçí class Cart. Ç óõíÜñôçóç add_item() ôïõ $cart áíôéêåéìÝíïõ êáëåßôáé ãéá íá ðñïóèÝóïõìå 1 áíôéêåßìåíï ôïõ Üñèñïõ ìå íïýìåñï 10 óôï $cart. 3 áíôéêåßìåíá ôïõ Üñèñïõ ìå íïýìåñï 0815 ðñïóôßèåíôáé óôçí $another_cart.
Ôüóï ç $cart üóï êáé ç$another_cart, Ý÷ïõí ôéò óõíáñôÞóåéò add_item(), remove_item() êáé óôïé÷åßá ìåôáâëçôþí. ÁõôÜ åßíáé äéáêñéôÝò óõíáñôÞóåéò êáé ìåôáâëçôÝò. Ìðïñåßôå íá èåùñÞóåôå ôá áíôéêåßìåíá ùò êÜôé ðáñüìïéï ìå ôá directories óå Ýíá filesystem. Óå Ýíá filesystem ìðïñåßôå íá Ý÷åôå äõï äéáöïñåôéêÜ áñ÷åßá README.TXT, ìå ôçí ðñïûðüèåóç üôé âñßóêïíôáé óå äéáöïñåôéêÜ directories. ¼ðùò êáé óôá directories üðïõ ðñÝðåé íá ðëçêôñïëïãÞóåôå ïëüêëçñï ôï üíïìá ôïõ path ðñïêåéìÝíïõ íá ðñïóðåëÜóåôå Ýíá áñ÷åßï áðü ôï áñ÷éêü directory, Ýôóé ðñÝðåé íá ðñïóäéïñßóåôå ïëüêëçñï ôï üíïìá ôçò óõíÜñôçóçò ðïõ èÝëåôå íá êáëÝóåôå: ìå üñïõò ôçò PHP, ôï áñ÷éêü directory èá åßíáé ôï global namespace, êáé ôï äéá÷ùñéóôéêü ôïõ ïíüìáôïò ôïõ path èá åßíáé ôï ->. Óõíåðþò, ôá ïíüìáôá $cart->items êáé $another_cart->items êáôïíïìÜæïõí äõï äéáöïñåôéêÝò ìåôáâëçôÝò. Óçìåéþóôå üôé ç ìåôáâëçôÞ ïíïìÜæåôáé $cart->items, êáé ü÷é $cart->$items, ôï ïðïßï åßíáé üíïìá ìåôáâëçôÞò óôçí PHP áöïý Ý÷åé ôï óýìâïëï ôïõ äïëáñßïõ.
<?php // correct, single $ $cart->items = array("10" => 1); // invalid, because $cart->$items becomes $cart->"" $cart->$items = array("10" => 1); // correct, but may or may not be what was intended: // $cart->$myvar becomes $cart->items $myvar = 'items'; $cart->$myvar = array("10" => 1); ?> |
ÊáôÜ ôïí ïñéóìü ìéáò êëÜóçò, äåí ãíùñßæåôå ìå ðïéï üíïìá ôï áíôéêåßìåíï èá ðñïóðåëáýíåôáé áðü ôï ðñüãñáììá óáò. Ôç óôéãìÞ ðïõ ãñÜöôçêå ç êëÜóç Cart, Þôáí Üãíùóôï üôé ôï áíôéêåßìåíï èá ïíïìáæüôáí $cart Þ $another_cartáñãüôåñá. Óõíåðþò, äåí ìðïñåßôå íá ãñÜøåôå ôçí $cart->items ìÝóá óôçí ßäéá ôçí êëÜóç Cart. Áíôßèåôá, ðñïêåéìÝíïõ íá ðñïóðåëÜóåôå ôéò óõíáñôÞóåéò ôçò êáé ôéò ìåôáâëçôÝò ìÝóá óå ìéá êëÜóç, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí øåõäïìåôáâëçôÞ $this ç ïðïßá ìðïñåß íá äéáâáóôåß ùò 'ôï äéêü ìïõ' Þ ôï 'ôñÝ÷ïí áíôéêåßìåíï'. Óõíåðþò, ç '$this->items[$artnr] += $num' ìðïñåß íá äéáâáóôåß ùò 'ðñüóèåóå ôçí $num óôïí ìåôñçôÞ $artnr ôùí äéêþí ìïõ áíôéêåéìÝíùí ôïõ ðßíáêá' Þ 'ðñüóèåóå ôçí $num óôïí ìåôñçôÞ $artnr ïõ ðßíáêá áíôéêåéìÝíùí ìÝóá óôï ôñÝ÷ïí áíôéêåßìåíï'.
Óçìåßùóç: ÕðÜñ÷ïõí ìåñéêÝò ùñáßåò óõíáñôÞóåéò ðïõ ÷åéñßæïíôáé êëÜóåéò êáé áíôéêåßìåíá. ºóùò èÝëåôå íá ñßîåôå ìéá ìáôéÜ óôï ÓõíáñôÞóåéò ÊëÜóåùí/ÁíôéêåéìÝíùí
Óõ÷íÜ ÷ñåéÜæåóôå êëÜóåéò ìå ðáñüìïéåò ìåôáâëçôÝò êáé óõíáñôÞóåéò ìå Üëëåò õðÜñ÷ïõóåò êëÜóåéò. Óôçí ðñáãìáôéêüôçôá, åßíáé êáëÞ ôáêôéêÞ íá ïñßæåôå ìéá ðñùôáñ÷éêÞ êëÜóç ðïõ ìðïñåß íá ÷ñçóéìïðïéçèåß áðü üëá ôá projects óáò êáé íá ìðïñåßôå íá ðñïóáñìüæåôå áõôÞ ôçí êëÜóç óôéò áíÜãêåò ôïõ êÜèå óõãêåêñéìÝíïõ project. Ãéá íá ôï êÜíåôå áõôü åýêïëá, ïé êëÜóåéò ìðïñïýí íá åßíáé åðåêôÜóåéò áðü Üëëåò êëÜóåéò. Ç êëÜóç ðïõ Ý÷åé åðåêôáèåß Þ Ý÷åé ðñïêýøåé Ý÷åé üëåò ôéò ìåôáâëçôÝò êáé ôéò óõíáñôÞóåéò ôçò ðñùôáñ÷éêÞò êëÜóçò (áõôü êáëåßôáé 'êëçñïíïìéêüôçôá' ðáñÜ ôï ãåãïíüò üôé êáíÝíáò äåí ðåèáßíåé) êáé ü,ôé Ý÷åôå ðñïóèÝóåé óôçí åðåêôáìÝíç êëÜóç. Äåí åßíáé äõíáôü íá áöáéñÝóåôå áðü ìéá êëÜóç, äçëáäÞ, íá êáôáóôåß áðñïóäéüñéóôç ìéá õðÜñ÷ïõóá óõíÜñôçóç Þ ìåôáâëçôÞ. Ìéá åðåêôåôáìÝíç êëÜóç åßíáé ðÜíôá åîáñôþìåíç áðü ìéá êëÜóç áñ÷éêÞ, óõíåðþò, ðïëëáðëÞ êëçñïíïìéêüôçôá äåí õðïóôçñßæåôáé. Ïé êëÜóåéò åðåêôåßíïíôáé ÷ñçóéìïðïéþíôáò ôç ëÝîç 'extends'.
<?php class Named_Cart extends Cart { var $owner; function set_owner ($name) { $this->owner = $name; } } ?> |
Ôï ðáñáðÜíù ïñßæåé ìéá êëÜóç ìå ôï üíïìá Named_Cart ç ïðïßá Ý÷åé üëåò ôéò ìåôáâëçôÝò êáé ôéò óõíáñôÞóåéò ôçò Cart, ìéá åðéðëÝïí ìåôáâëçôÞ ôçí$owner êáé ìéá åðéðñüóèåôç óõíÜñôçóç ôçí set_owner(). Äçìéïõñãåßôå Ýíá cart ìå ôïí óõíçèéóìÝíï ôñüðï êáé ìðïñåßôå ôþñá íá èÝóåôå êáé íá ðÜñåôå ôïí owner ôïõ cart. Ìðïñåßôå áêüìç íá ÷ñçóéìïðïéÞóåôå ôéò êáíïíéêÝò óõíáñôÞóåéò ôçò cart óå ðñïóäéïñéóìÝíá carts:
<?php $ncart = new Named_Cart; // Create a named cart $ncart->set_owner("kris"); // Name that cart print $ncart->owner; // print the cart owners name $ncart->add_item("10", 1); // (inherited functionality from cart) ?> |
Áõôü êáëåßôáé åðßóçò ó÷Ýóç "ãïíÝá-ðáéäéïý". Äçìéïõñãåßôå ìéá êëÜóç, ôïí ãïíéü, êáé ÷ñçóéìïðïéåßôå ôçí extends ãéá íá äçìéïõñãÞóåôå ìéá íÝá êëÜóç âáóéóìÝíç óôçí áñ÷éêÞ êëÜóç: ôçí êëÜóç ðáéäß. Ìðïñåßôå áêüìç íá ÷ñçóéìïðïéÞóåôå áõôÞ ôç íÝá êëÜóç-ðáéäß êáé íá äçìéïõñãÞóåôå áêüìç ìéá êëÜóç âáóéóìÝíç ó'áõôÞ ôçí êëÜóç-ðáéäß.
Óçìåßùóç: Ïé êëÜóåéò ðñÝðåé íá ïñßæïíôáé ðñéí ÷ñçóéìïðïéçèïýí! Áí èÝëåôå ôçí êëÜóç Named_Cart íá åßíáé åðÝêôáóç ôçò Cart, èá ðñÝðåé íá ïñßóåôå ôçí êëÜóç Cart ðñþôá. Áí èÝëåôå íá äçìéïõñãÞóåôå Üëëç ìéá êëÜóç, ôçí Yellow_named_cart ç ïðïßá âáóßæåôå óôçí êëÜóç Named_Cart ðñÝðåé íá ïñßóåôå ôçí Named_Cart ðñþôá. ÄçëáäÞ: ç óåéñÜ ìå ôçí ïðïßá ïñßæïíôáé ïé êëÜóåéò åßíáé óçìáíôéêÞ.
Ðñïóï÷Þ |
Óôçí PHP 3 êáé óôçí PHP 4 ïé constructors óõìðåñéöÝñïíôáé äéáöïñåôéêÜ. Óôçí PHP 4 ðñïôéìïýíôáé ôá semantics. |
Ïé constructors åßíáé óõíáñôÞóåéò óå ìéá êëÜóç ðïõ êáëïýíôáé áõôüìáôá üôáí äçìéïñãåßôå Ýíá êáéíïýñéï óôéãìéüôõðï (instance) ìéáò êëÜóçò ìå ôçí new. Óôçí PHP 3, ìéá óõíÜñôçóç ãßíåôáé constructor üôáí Ý÷åé ôï ßäéï üíïìá ìå ôçí êëÜóç. Óôçí PHP 4, ìéá óõíÜñôçóç ãßíåôáé constructor, üôáí Ý÷åé ôï ßäéï üíïìá ìå ôçí êëÜóç üðùò áõôÞ ïñßæåôáé - ç äéáöïñÜ åßíáé ìéêñÞ, áëëÜ óçìáíôéêÞ (äåßôå ðáñáêÜôù).
<?php // Works in PHP 3 and PHP 4. class Auto_Cart extends Cart { function Auto_Cart() { $this->add_item ("10", 1); } } ?> |
Ôï ðáñáðÜíù ïñßæåé ôçí êëÜóç Auto_Cart ç ïðïßá åßíáé ç Cart ìå åðéðëÝïí Ýíáí constructor ï ïðïßïò áñ÷éêïðïéåß ôï cart ìå Ýíá óôïé÷åßï áðü ôï Üñèñï ìå íïýìåñï "10" êÜèå öïñÜ ðïõ Ýíá íÝï Auto_Cart äçìéïõñãåßôáé ìå ôçí "new". Ïé Constructors ìðïñïýí íá ðÜñïõí ðáñáìÝôñïõò êáé áõôÝò ïé ðáñÜìåôñïé ìðïñïýí íá åßíáé ðñïáéñåôéêÝò, ãåãïíüò ôï ïðïßï ôéò êÜíåé ðéï ÷ñÞóéìåò. Ãéá íá áðïêôÞóïõìå ôç äõíáôüôçôá íá ÷ñçóéìïðïéïýìå ôçí êëÜóç ÷ùñßò ðáñáìÝôñïõò, üëåò ïé ðáñÜìåôñïé óôïõò constructors ðñÝðåé íá ãßíïõí ðñïáéñåôéêÝò ðáñÝ÷ïíôáò ôéò ðñïêáèïñéóìÝíåò ôéìÝò.
<?php // Works in PHP 3 and PHP 4. class Constructor_Cart extends Cart { function Constructor_Cart($item = "10", $num = 1) { $this->add_item ($item, $num); } } // Shop the same old boring stuff. $default_cart = new Constructor_Cart; // Shop for real... $different_cart = new Constructor_Cart("20", 17); ?> |
Ìðïñåßôå åðßóçò íá ÷ñçóéìïðïéÞóåôå ôïí ôåëåóôÞ @ ãéá íá óôáìáôÞóåôå (mute) ôçí åìöÜíéóç ëáèþí ðïõ óõìâáßíïõí óôïõò constructor, ð.÷. @new.
Ðñïóï÷Þ |
Óôçí PHP 3, ïé ðñïêýðôïõóåò êëÜóåéò êáé ïé constructors Ý÷ïõí Ýíá ðëÞèïò ðåñéïñéóìþí. Ôá áêüëïõèá ðáñáäåßãìáôá èá ðñÝðåé íá äéáâáóôïýí ðñïóåêôéêÜ ãéá íá ãßíïõí êáôáíïçôïß áõôïß ïé ðåñéïñéóìïß. |
<?php class A { function A() { echo "I am the constructor of A.<br>\n"; } } class B extends A { function C() { echo "I am a regular function.<br>\n"; } } // no constructor is being called in PHP 3. $b = new B; ?> |
Óôçí PHP 3, äåí êáëåßôáé êáíÝíáò constructor óôï ðáñáðÜíù ðáñÜäåéãìá. Ï êáíüíáò óôçí PHP 3 åßíáé: '¸íáò constructor åßíáé ìéá óõíÜñôçóç ôïõ ßäéïõ ïíüìáôïò ìå ôçí êëÜóç.'. Ôï üíïìá ôçò êëÜóçò åßíáé B, êáé äåí õðÜñ÷åé óõíÜñôçóç ìå ôï üíïìá B() óôçí êëáóç B. Ôßðïôá äåí óõìâáßíåé.
Áõôü Ý÷åé äéïñèùèåß óôçí PHP 4 åéóÜãïíôáò Ýíáí Üëëï êáíüíá: Áí ìéá êëÜóç äåí Ý÷åé constructor, ï constructor ôçò âáóéêÞò êëÜóçò êáëåßôáé, áí áõôüò õðÜñ÷åé. Ôï ðáñáðÜíù ðáñÜäåéãìá èá åß÷å åêôõðþóåé 'I am the constructor of A.<br>' óôçí PHP 4.
<?php class A { function A() { echo "I am the constructor of A.<br>\n"; } function B() { echo "I am a regular function named B in class A.<br>\n"; echo "I am not a constructor in A.<br>\n"; } } class B extends A { function C() { echo "I am a regular function.<br>\n"; } } // This will call B() as a constructor. $b = new B; ?> |
Óôçí PHP 3, ç óõíÜñôçóç B() óôçí êëáóç A èá ãßíåé îáöíéêÜ constructor óôçí êëÜóç B, ðáñüëï ðïõ äåí õðÞñîå ðïôÝ ç ðñüèåóç íá ãßíåé áõôü. Ï êáíüíáò óôçí PHP 3 åßíáé: '¸íáò constructor åßíáé ìéá óõíÜñôçóç ìå ôï ßäéï üíïìá ìå ôçí êëÜóç.'. Ç PHP 3 äåí åíäéáöÝñåôáé áí ç óõíÜñôçóç ïñßæåôáé óôçí êëÜóç B, Þ áí Ý÷åé êëçñïíïìçèåß.
Áõôü Ý÷åé äéïñèùèåß óôçí PHP 4 áëëÜæïíôáò ôïí êáíüíá óå: '¸íáò constructor åßíáé ìéá óõíÜñôçóç ôïõ ßäéïõ ïíüìáôïò ìå ôçí êëÜóç óôçí ïðïßá ïñßóôçêå.'. Óõíåðþò óôçí PHP 4, ç êëÜóç B äå èá Ý÷åé óõíÜñôçóç ãéá äçìéïõñãßá constructor áðü ìüíç ôçò êáé ï constructor ôçò âáóéêÞò êëÜóçò èá êëçèåß, åêôõðþíïíôáò ôï 'I am the constructor of A.<br>'.
Ðñïóï÷Þ |
Ïýôå ç PHP 3 ïýôå ç PHP 4 êáëïýí constructors ôçò âáóéêÞò êëÜóçò áõôüìáôá áðü Ýíá constructor êëÜóçò ðïõ Ý÷åé ðáñá÷èåß. Åßíáé äéêÞ óáò åõèýíç íá ðåñÜóåôå ôçí êëÞóç óôïõò constructors üðïõ ÷ñåéÜæåôáé. |
Óçìåßùóç: Äåí õðÜñ÷ïõí destructors óôçí PHP 3 Þ óôçí PHP 4. Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí register_shutdown_function() áíô'áõôïý ðñïêåéìÝíïõ íá ðñïóïìïéþóåôå ôï áðïôÝëåóìá ôùí destructors.
Ïé Destructors åßíáé óõíáñôÞóåéò ðïõ êáëïýíôáé áõôüìáôá üôáí Ýíá áíôéêåßìåíï êáôáóôñÝöåôáé, åßôå ìå ôçí unset() Þ áðëÜ âãÜæïíôáò åêôüò åìâÝëåéáò. Äåí õðÜñ÷ïõí destructors óôçí PHP.
Ðñïóï÷Þ |
Ôï áêüëïõèï éó÷ýåé ìüíï óôçí PHP 4. |
ÌåñéêÝò öïñÝò åßíáé ÷ñÞóéìï íá áíáöåñüìáóôå óå óõíáñôÞóåéò êáé ìåôáâëçôÝò ôùí âáóéêþí êëÜóåùí Þ íá áíáöåñüìáóôå óå óõíáñôÞóåéò êëÜóåùí ðïõ äåí Ý÷ïõí áêüìç óôéãìéüôõðï. Ï ôåëåóôÞò :: ÷ñçóéìïðïéåßôáé ãé'áõôü ôï óêïðü.
<?php class A { function example() { echo "I am the original function A::example().<br>\n"; } } class B extends A { function example() { echo "I am the redefined function B::example().<br>\n"; A::example(); } } // there is no object of class A. // this will print // I am the original function A::example().<br> A::example(); // create an object of class B. $b = new B; // this will print // I am the redefined function B::example().<br> // I am the original function A::example().<br> $b->example(); ?> |
Ôï ðáñáðÜíù ðáñÜäåéãìá êáëåß ôç óõíÜñôçóç example() óôçí êëÜóç A, áëëÜ äåí õðÜñ÷åé áíôéêåßìåíï ôçò êëÜóçò A, óõíåðþò äåí ìðïñïýìå íá ãñÜøïõìå $a->example() Þ êÜôé áíôßóôïé÷ï. ÁíôéèÝôùò êáëïýìå ôçí example() ùò 'óõíÜñôçóç êëÜóçò', äçëáäÞ, óáí óõíÜñôçóç ôçò ßäéáò ôçò êëÜóçò, ü÷é ùò áíôéêåßìåíï ôçò êëÜóçò.
ÕðÜñ÷ïõí óõíáñôÞóåéò êëÜóåùí, áëëÜ äåí õðÜñ÷ïõí ìåôáâëçôÝò êëÜóåùí. Óôçí ðñáãìáôéêüôçôá, äåí õðÜñ÷åé êáíÝíá áíôéêåßìåíï ôç óôéãìÞ ôçò êëÞóçò. Óõíåðþò, ìéá óõíÜñôçóç êëÜóçò ìðïñåß íá ìçí ÷ñçóéìïðïéåß êáìßá ìåôáâëçôÞ áíôéêåéìÝíïõ (áëëÜ ìðïñåß íá ÷ñçóéìïðïéåß ôïðéêÝò êáé global ìåôáâëçôÝò), êáé ìðïñåß íá ìçí ÷ñçóéìïðïéåß ôï $this êáèüëïõ.
Óôï ðáñáðÜíù ðáñÜäåéãìá, ç êëÜóç B åðáíáðñïóäéïñßæåé ôç óõíÜñôçóç example(). Ï áñ÷éêüò ïñéóìüò ôçò êëÜóçò Á åðéóêéÜæåôáé êáé äåí åßíáé ðëÝïí äéáèÝóéìïò, åêôüò êáé áí áíáöÝñåóôå óõãêåêñéìÝíá óôçí õëïðïßçóç ôçò example() óôçí êëÜóç Á ÷ñçóéìïðïéþíôáò ôïí ôåëåóôÞ ::. ÃñÜøôå A::example() ãéá íá ôï êÜíåôå áõôü (óôçí ðñáãìáôéêüôçôá, èá Ýðñåðå íá ãñÜøåôå parent::example(), üðùò èá äåßôå óôï åðüìåíï ôìÞìá).
Ó'áõôü õðÜñ÷åé Ýíá ôñÝ÷ïí áíôéêåßìåíï ôï ïðïßï ìðïñåß íá Ý÷åé ìåôáâëçôÝò áíôéêåéìÝíùí. Óõíåðþò, üôáí ÷ñçóéìïðïéåßôáé ÌÅÓÁ áðü ìéá óõíÜñôçóç áíôéêåéìÝíïõ, ìðïñåßôå íá ÷ñçóéìïðïéåßôå ôçí $thisêáé ôéò ìåôáâëçôÝò áíôéêåéìÝíùí.
Ìðïñåß íá ôý÷åé íá ãñÜøåôå êþäéêá ðïõ èá áíáöÝñåôáé óå ìåôáâëçôÝò êáé óõíáñôÞóåéò óôéò âáóéêÝò êëÜóåéò. Áõôü åßíáé åí ìÝñåé áëÞèåéá áí ïé ðñïêýðôïõóåò êëÜóåéò åßíáé ìéá åêëÝðôõíóç ôïõ êþäéêá ôçò âáóéêÞò óáò êëÜóçò.
Áíôß íá ÷ñçóéìïðïéåßôå ôï êáíïíéêü üíïìá ôçò âáóéêÞò óáò êëÜóçò óôïí êþäéêá óáò, èá ðñÝðåé íá ÷ñçóéìïðïéåßôå ôï éäéáßôåñï üíïìá parent, ôï ïðïßï áíáöÝñåôáé óôï üíïìá ôçò âáóéêÞò óáò êëÜóçò üðùò áõôÞ äßíåôáé óôç äÞëùóç extends ôçò êëÜóçò óáò. ÊÜíïíôáò ôï áõôü, áðïöåýãåôå íá ÷ñçóéìïðïéÞóåôå ôï üíïìá ôçò âáóéêÞò óáò êëÜóçò óå ðåñéóóüôåñá áðü Ýíá ìÝñç. Óå ðåñßðôùóç ðïõ áëëÜîåé ôï äÝíôñï êëçñïíïìéêüôçôáò êáôÜ ôç äéÜñêåéá ôçò õëïðïßçóçò, ç áëëáãÞ ãßíåôáé åýêïëá áðëÜ áëëÜæïíôáò ôç äÞëùóç extends ôçò êëÜóçò óáò.
<?php class A { function example() { echo "I am A::example() and provide basic functionality.<br>\n"; } } class B extends A { function example() { echo "I am B::example() and provide additional functionality.<br>\n"; parent::example(); } } $b = new B; // This will call B::example(), which will in turn call A::example(). $b->example(); ?> |
Óçìåßùóç: Óôçí PHP 3, ôá áíôéêåßìåíá èá ÷Üóïõí ôï óýíäåóìï ôïõò ìå ôçí êëÜóç êáôÜ ôç äéáäéêáóßá ôïõ serialization êáé ôïõ unserialization. Ç ìåôáâëçôÞ ðïõ ðñïêýðôåé åßíáé ôýðïõ áíôéêåéìÝíïõ, áëëÜ äåí Ý÷åé êëÜóåéò êáé ìåèüäïõò. Óõíåðþò åßíáé ó÷åôéêÜ Ü÷ñçóôç (Ý÷åé ãßíåé óáí ðßíáêáò ìå áóôåßá-ðåñßåñãç óýíôáîç).
Ðñïóï÷Þ |
Ç áêüëïõèç ðëçñïöïñßá éó÷ýåé ìüíï ãéá ôçí PHP 4. |
Ç serialize() åðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ìéá byte-stream áíáðáñÜóôáóç ïðïéáóäÞðïôå ôéìÞò ðïõ ìðïñåß íá áðïèçêåõôåß óôçí PHP. Ç unserialize() ìðïñåß íá ÷ñçóéìïðïéÞóåé áõôü ôï string ãéá íá îáíáäçìéïõñãÞóåé ôéò áñ÷éêÝò ôéìÝò ôçò ìåôáâëçôÞò. ×ñçóéìïðïéþíôáò ôçí serialize ãéá íá áðïèçêåýóïõìå Ýíá áíôéêåßìåíï, èá åðéôý÷ïõìå ôçí áðïèÞêåõóç üëùí ôùí ìåôáâëçôþí óå Ýíá áíôéêåßìåíï. Ïé óõíáñôÞóåéò åíüò áíôéêåéìÝíïõ äå èá áðïèçêåõôïýí, ìüíï ôï üíïìá ôçò êëÜóçò.
ÐñïêåéìÝíïõ íá ìðïñïýìå íá unserialize() Ýíá áíôéêåßìåíï, ç êëÜóç áõôïý ôïõ áíôéêåéìÝíïõ ðñÝðåé íá ðñïóäéïñéóôåß. ÄçëáäÞ, áí Ý÷åôå Ýíá áíôéêåßìåíï $a ìéá êëÜóçò A óôçí page1.php êáé êÜíåôå serialize ó'áõôü, èá ðÜñåôå Ýíá string ðïõ áíáöÝñåôå óôçí êëÜóç A êáé ðåñéÝ÷åé üëåò ôéò ôéìÝò ìåôáâëçôþí ðïõ ðåñéÝ÷ïíôáé óôçí $a. Áí èÝëåôå íá ìðïñåßôå íá êÜíåôå unserialize áõôü óôçí page2.php, îáíáäçìéïõñãþíôáò ôçí $a ôçò êëÜóçò A, ï ðñïóäéïñéóìüò ôçò êëÜóçò A ðñÝðåé íá õðÜñ÷åé óôçí page2.php. Áõôü ìðïñåß íá ãßíåé ãéá ðáñÜäåéãìá áðïèçêåýïíôáò ôïí ïñéóìü ôçò êëÜóçò A óå Ýíá åìðåñéå÷üìåíï áñ÷åßï êáé óõìðåñéëáìâÜíïíôáò ôï áñ÷åßï áõôü ôüóï óôçí page1.php üóï êáé óôçí page2.php.
<?php // classa.inc: class A { var $one = 1; function show_one() { echo $this->one; } } // page1.php: include("classa.inc"); $a = new A; $s = serialize($a); // store $s somewhere where page2.php can find it. $fp = fopen("store", "w"); fputs($fp, $s); fclose($fp); // page2.php: // this is needed for the unserialize to work properly. include("classa.inc"); $s = implode("", @file("store")); $a = unserialize($s); // now use the function show_one() of the $a object. $a->show_one(); ?> |
Áí ÷ñçóéìïðïéåßôå sessions êáé ôçí session_register() ãéá íá êÜíåôå register áíôéêåßìåíá, áõôÜ ôá áíôéêåßìåíá ãßíïíôáé serialize áõôüìáôá óôï ôÝëïò êÜèå óåëßäáò PHP, êáé ãßíïíôáé unserialize áõôüìáôá óå êÜèå ìéá áðü ôéò áêüëïõèåò óåëßäåò. Áõôü âáóéêÜ óçìáßíåé üôé áõôÜ ôá áíôéêåßìåíá ìðïñïýí íá åìöáíéóôïýí óå ïðïéáäÞðïôå áðü ôéò óåëßäåò óáò ìüëéò ãßíïõí ìÝñïò ôïõ session.
Óõíßóôáôáé áíåðéöýëáêôá íá óõìðåñéëÜâåôå ôïõò ïñéóìïýò ôùí êëÜóåùí üëùí áõôþí ôùí registered áíôéêåéìÝíùí óå üëåò ôéò óåëßäåò óáò, áêüìç êáé áí äåí ÷ñçóéìïðïéåßôå áõôÝò ôéò êëÜóåéò óôéò óåëßäåò óáò. Áí äåí ôï êÜíåôå êáé Ýíá áíôéêåßìåíï ãßíåé unserialize ÷ùñßò íá åßíáé ðáñüí ï ïñéóìüò ôçò êëÜóçò ôçò, èá ÷Üóåé ôç óýíäåóç ôçò ìå ôçí êëÜóç êáé èá ãßíåé Ýíá áíôéêåßìåíï ôçò êëÜóçò stdClass ÷ùñßò êáìßá óõíÜñôçóç äéáèÝóéìç äçëáäÞ, èá ãßíåé ó÷åäüí Üñ÷çóôï.
Óõíåðþò, áí óôï ðáñáðÜíù ðáñÜäåéãìá ôï $a ãßíåé ìÝñïò ìéáò session ôñÝ÷ïíôáò ôçí session_register("a"), èá ðñÝðåé íá óõíðåñéëÜâåôå ôï áñ÷åßï classa.inc óå üëåò ôéò óåëßäåò óáò, ü÷é ìüíï óôçí page1.php êáé page2.php.
Ç serialize() åëÝã÷åé áí ç êëÜóç óáò Ý÷åé ìéá óõíÜñôçóç ìå ôï ìáãéêü üíïìá __sleep. Áí Ý÷åé, áõôÞ ç óõíÜñôçóç ôñÝ÷åé ðñéí áðü ïðïéïäÞðïôå Üëëï serialization. Ìðïñåß íá îåêáèáñßóåé ôï áíôéêåßìåíï êáé åðéóôñÝöåé Ýíáí ðßíáêá ìå ôá ïíüìáôá üëùí ôùí ìåôáâëçôþí ôïõ áíôéêåéìÝíïõ ðïõ èá Ýðñåðå íá ãßíåé serialization.
Ç èåìéôÞ ÷ñÞóç ôçò __sleep åßíáé íá êëåßóåé êÜèå óýíäåóç ìå âÜóç ðïõ ìðïñåß íá Ý÷åé Ýíá áíôéêåßìåíï, íá åêôåëÝóåé äåäïìÝíá ðïõ åêêñåìïýí Þ íá ðñáãìáôïðïéÞóåé ðáñüìïéåò cleanup åíÝñãåéåò. Åðßóçò, ç óõíÜñôçóç åßíáé ÷ñÞóéìç áí Ý÷åôå ðïëý ìåãÜëá áíôéêåßìåíá ðïõ äåí ÷ñåéÜæåôáé íá áðïèçêåõôïýí åíôåëþò.
Áíôßèåôá, ç unserialize() åëÝã÷åé ãéá ôçí ðáñïõóßá ìéáò óõíÜñôçóçò ìå ôï ìáãéêü üíïìá __wakeup. Áí õðÜñ÷åé, áõôÞ ç óõíÜñôçóç ìðïñåß íá áíáêáôáóêåõÜóåé üðïéáäÞðïôå resources ðïõ ìðïñåß íá Ý÷åé Ýíá áíôéêåßìåíï.
Ç åðéèõìçôÞ ÷ñÞóç ôçò __wakeup åßíáé íá îáíáåãêáôáóôÞóåé ïðïéåóäÞðïôå óõíäÝóåéò âÜóåùí ðïõ ìðïñåß íá Ý÷ïõí ÷áèåß êáôÜ ôç äéÜñêåéá ôïõ serialization êáé íá åêôåëÝóåé Üëëåò äéáäéêáóßåò åðáíáñ÷éêïðïßçóçò.
Ç äçìéïõñãßá references ìÝóá óå Ýíáí constructor ìðïñåß íá ïäçãÞóåé óå ìðåñäåìÝíá áðïôåëÝóìáôá. Áõôü ôï ôìÞìá ôïõ åã÷åéñéäßïõ èá óáò âïçèÞóåé íá áðïöýãåôå ôÝôïéá ðñïâëÞìáôá.
<?php class Foo { function Foo($name) { // create a reference inside the global array $globalref global $globalref; $globalref[] = &$this; // set name to passed value $this->setName($name); // and put it out $this->echoName(); } function echoName() { echo "<br>",$this->name; } function setName($name) { $this->name = $name; } } ?> |
Áí åëÝíîïõìå áí õðÜñ÷åé äéáöïñÜ ìåôáîý ôçò $bar1 ç ïðïßá äçìéïõñãÞèçêå ÷ñçóéìïðïéþíôáò Ýíá áíôßãñáöï ôïõ ôåëåóôÞ = êáé ôçò $bar2 ðïõ äçìéïõñãÞèçêå ÷ñçóéìïðïéþíôáò ìéá áíáöïñÜ ìå ôïí ôåëåóôÞ =&...
<?php $bar1 = new Foo('set in constructor'); $bar1->echoName(); $globalref[0]->echoName(); /* output: set in constructor set in constructor set in constructor */ $bar2 =& new Foo('set in constructor'); $bar2->echoName(); $globalref[1]->echoName(); /* output: set in constructor set in constructor set in constructor */ ?> |
Ìå ôçí ðñþôç ìáôéÜ äåí õðÜñ÷åé äéáöïñÜ, áëëÜ óôçí ðñáãìáôéêüôçôá õðÜñ÷åé ìéá ðïëý óçìáíôéêÞ: ç $bar1 êáé ç $globalref[0] ÄÅÍ_áëëçëïáíáöÝñïíôáé, ÄÅÍ åßíáé ç ßäéá ìåôáâëçôÞ. Áõôü óõìâáßíåé ãéáôß ç "new" äåí åðéóôñÝøåé ìéá áíáöïñÜ ðÜíôá, áëëÜ áíôßèåôá åðéóôñÝöåé Ýíá áíôßãñáöï.
Óçìåßùóç: Äåí õðÜñ÷åé ÷Üóéìï óôçí áðüäïóç (áöïý ç PHP 4 êáé ìåôÜ ÷ñçóéìïðïéïýí ìåôñçôÞ áíáöïñÜò) åðéóôñÝöïíôáò áíôßãñáöá áíôß ãéá áíáöïñÝò. ÁíôéèÝôùò åßíáé óõ÷íÜ êáëýôåñï íá äïõëåýïõìå ìå áíôßãñáöá áíôß ãéá áíáöïñÝò, åðåéäÞ ç äçìéïõñãßá áíáöïñþí ðáßñíåé êÜðïéï ÷ñüíï åíþ ç äçìéïõñãßá áíôßãñáöùí éäåáôÜ äå èÝëåé êáèüëïõ ÷ñüíï (åêôüò êáé áí Ýíá áðü áõôÜ åßíáé Ýíáò ìåãÜëïò ðßíáêáò Þ áíôéêåßìåíï êáé Ýíá áðü áõôÜ áëëÜæåé êáèþò êáé ôá Üëëá óôç óõíÝ÷åéá, ôüôå èá Þôáí óïöüôåñï íá ÷ñçóéìïðïéÞóïõìå áíáöïñÝò ãéá íá ôá áëëÜîïõìå üëá óõã÷ñüíùò).
<?php // now we will change the name. what do you expect? // you could expect that both $bar1 and $globalref[0] change their names... $bar1->setName('set from outside'); // as mentioned before this is not the case. $bar1->echoName(); $globalref[0]->echoName(); /* output: set from outside set in constructor */ // let us see what is different with $bar2 and $globalref[1] $bar2->setName('set from outside'); // luckily they are not only equal, they are the same variable // thus $bar2->name and $globalref[1]->name are the same too $bar2->echoName(); $globalref[1]->echoName(); /* output: set from outside set from outside */ ?> |
Áêüìç Ýíá ôåëéêü ðáñÜäåéãìá, ðñïóðáèÞóôå íá ôï êáôáíïÞóåôå.
<?php class A { function A($i) { $this->value = $i; // try to figure out why we do not need a reference here $this->b = new B($this); } function createRef() { $this->c = new B($this); } function echoValue() { echo "<br>","class ",get_class($this),': ',$this->value; } } class B { function B(&$a) { $this->a = &$a; } function echoValue() { echo "<br>","class ",get_class($this),': ',$this->a->value; } } // try to undestand why using a simple copy here would yield // in an undesired result in the *-marked line $a =& new A(10); $a->createRef(); $a->echoValue(); $a->b->echoValue(); $a->c->echoValue(); $a->value = 11; $a->echoValue(); $a->b->echoValue(); // * $a->c->echoValue(); /* output: class A: 10 class B: 10 class B: 10 class A: 11 class B: 11 class B: 11 */ ?> |
Óôçí PHP 4, ôá áíôéêåßìåíá óõãêñßíïíôáé óå Ýíáí ðïëý áðëü ôñüðï, äçëáäÞ: äõï óôéãìéüôõðá áíôéêåéìÝíùí åßíáé ßóá áí Ý÷ïõí ôéò ßäéåò ôéìÝò êáé ôá ßäéá attributes, êáé åßíáé óôéãìéüôõðá ôçò ßäéáò êëÜóçò. Ðáñüìïéïé êáíüíåò åöáñìüæïíôáé üôáí óõãêñßíïíôáé äõï áíôéêåßìåíá ÷ñçóéìïðïéþíôáò ôïí ôåëåóôÞ ôáõôüôçôáò (===).
Áí åß÷áìå íá åêôåëÝóïõìå ôïí êþäéêá óôï ðáñáêÜôù ðáñÜäåéãìá:
ÐáñÜäåéãìá 13-1. ÐáñÜäåéãìá óýãêñéóçò áíôéêåéìÝíïõ óôçí PHP 4
|
Compare instances created with the same parameters o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE Compare instances created with different parameters o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE Compare an instance of a parent class with one from a subclass o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE |
Áêüìç êáé óôéò ðåñéðôþóåéò üðïõ Ý÷ïõìå óýíèåóç áíôéêåéìÝíïõ, ïé ßäéïé êáíüíåò óýãêñéóçò åöáñìüæïíôáé. Óôï ðáñáêÜôù ðáñÜäåéãìá äçìéïõñãïýìå ìéá container êëÜóç ç ïðïßá áðïèçêåýåé Ýíáí associative ðßíáêá áðü Flag áíôéêåßìåíá.
ÐáñÜäåéãìá 13-2. Compound óõãêñßóåéò áíôéêåéìÝíùí óôçí PHP 44
|
Composite objects u(o,p) and v(q,p) o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE u(o,p) and w(q) o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE |
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
Óôçí PHP 5, ç óýãêñéóç áíôéêåéìÝíùí åßíáé ðéï ðåñßðëïêç áð'ïôé óôçí PHP 4 êáé ðåñéóóüôåñï óå óõìöùíßá ìå áõôü ðïõ èá ðåñéìÝíåé áðü ìéá áíôéêåéìåíïóôñáöÞ ãëþóóá. (ü÷é üôé ç PHP 5 åßíáé ìéá ôÝôïéá ãëþóóá).
¼ôáí ÷ñçóéìïðïéïýìå ôïí ôåëåóôÞ óýãêñéóçò (==), ïé ìåôáâëçôÝò ôùí áíôéêåéìÝíùí óõãêñßíïíôáé ìå Ýíáí áðëü ôñüðï, äçëáäÞ: äõï óôéãìéüôõðá ìåôáâëçôþí åßíáé ßóá áí Ý÷ïõí ôá ßäéá attributes êáé ôéò ßäéåóò ôéìÝò, êáé åßíáé óôéãìéüôõðá ôçò ßäéáò êëÜóçò, ðïõ ïñßæåôáé óôï ßäéï namespace.
Áðü ôçí Üëëç, üôáí ÷ñçóéìïðïéåßôáé ï ôåëåóôÞò ôáõôüôçôáò (===), ïé ìåôáâëçôÝò áíôéêåéìÝíùí åßíáé üìïéåò ìüíï êáé ìüíï áí áíáöÝñïíôáé óôï ßäéï óôéãìéüôõðï ôçò ßäéáò êëÜóçò (óå Ýíá éäéáßôåñï namespace).
¸íá ðáñÜäåéãìá èá îåêáèáñßóåé áõôïýò ôïõò êáíüíåò.
ÐáñÜäåéãìá 13-3. ÐáñÜäåéãìá óýãêñéóçò áíôéêåéìÝíùí óôçí PHP 5
|
Two instances of the same class o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : FALSE o1 !== o2 : TRUE Two references to the same instance o1 == o2 : TRUE o1 != o2 : FALSE o1 === o2 : TRUE o1 !== o2 : FALSE Instances of similarly named classes in different namespaces o1 == o2 : FALSE o1 != o2 : TRUE o1 === o2 : FALSE o1 !== o2 : TRUE |
Ïé áíáöïñÝò óôçí PHP åßíáé Ýíáò ôñüðïò ãéá íá Ý÷ïõìå ðñüóâáóç ôï ßäéï ðåñéå÷üìåíï ôçò ìåôáâëçôÞò ìå äéáöïñåôéêÜ üìùò ïíüìáôá. Äåí åßíáé óáí ôïõò äåßêôåò óôçí C, åßíáé óõìâïëéêÜ øåõäþíõìá ðéíÜêùí. Óçìåéþóôå üôé óôçí PHP, ôï üíïìá ôçò ìåôáâëçôÞò êáé ôï ðåñéå÷üìåíï ôçò åßíáé äéáöïñåôéêÜ, óõíåðþò ôï ßäéï ðåñéå÷üìåíï ìðïñåß íá Ý÷åé äéáöïñåôéêÜ ïíüìáôá. Ç ðéï êáëÞ áíáëïãßá åßíáé ìå ôá ïíüìáôá áñ÷åßùí êáé ôá áñ÷åßá óôï Unix: ôá ïíüìáôá ôùí ìåôáâëçôþí åßíáé êáôá÷ùñÞóåéò êáôáëüãùí (directory entries), åíþ ôï ðåñéå÷üìåíï ôùí ìåôáâëçôþí åßíáé ôï ßäéï ôï áñ÷åßï. Ïé áíáöïñÝò ìðïñïýí íá èåùñçèïýí ùò hardlinking óôï Unix filesystem.
Ïé áíáöïñÝò óôçí PHP óáò åðéôñÝðïõí íá êÜíåôå äõï ìåôáâëçôÝò íá áíáöÝñïíôáé óôï ßäéï ðåñéå÷üìåíï. ÄçëáäÞ, üôáí ãñÜöåôå:
óçìáßíåé üôé ç $a êáé ç $b äåß÷íïõí óôçí ßäéá ìåôáâëçôÞ.Óçìåßùóç: Ç $a êáé ç $b åßíáé ôåëåßùò ßóåò åäþ, áöïý ç $a äåí äåß÷íåé óôçí $b Þ áíôéóôñüöùò, áëëÜ ôüóï ç $a üóï êáé ç $b äåß÷íïõí óôï ßäéï ìÝñïò.
Ç ßäéá óýíôáîç ìðïñåß íá ÷ñçóéìïðïéçèåß ìå óõíáñôÞóåéò, ïé ïðïßåò åðéóôñÝöïõí áíáöïñÝò, êáé ìå ôïí ôåëåóôÞ new (óôçí PHP 4.0.4 êáé ìåôÜ):
Óçìåßùóç: Ç ìç ÷ñÞóç ôïõ ôåëåóôÞ & äçìéïõñãåß Ýíá áíôßãñáöï ôïõ áíôéêåéìÝíïõ ðïõ èá ãßíåé. Áí ÷ñçóéìïðïéåßôå ôï $this óå ìéá êëÜóç, áõôü èá åíåñãÞóåé ðÜíù óôï ôñÝ÷ïí óôéãìéüôõðï (instance) ôçò êëÜóçò. Ç áíÜèåóç ÷ùñßò ôï & èá áíôéãñÜøåé ôï óôéãìéüôõðï (ð.÷. ôï áíôéêåßìåíï) êáé ôï $this èá åíåñãÞóåé ó' áõôü ôï áíôßãñáöï, ôï ïðïßï äåí åßíáé ôï åðéèõìçôü. ÓõíÞèùò èÝëåôå íá Ý÷åôå Ýíá ìüíï óôéãìéüôõðï íá äïõëåýåôå, åîáéôßáò èåìÜôùí áðüäïóçò êáé êáôáíÜëùóçò ìíÞìçò.
Åíþ ìðïñåßôå íá ÷ñçóéìïðïéåßôå ôïí ôåëåóôÞ @ ãéá íá óôáìáôÜôå (mute) ëÜèç óôïí constructor, üôáí ôï ÷ñçóéìïðïéåßôå ùò @new, äå èá äïõëÝøåé üôáí êÜíåôå ÷ñÞóç êáé ôçò äÞëùóçò &new. Áõôü åßíáé Ýíáò ðåñéïñéóìüò ôçò Zend Engine êáé óõíåðþò èá êáôáëÞîåé óå ëÜèïò ôïõ ìåôáãëùôôéóôÞ.
Ôï äåýôåñï ðñÜãìá ðïõ êÜíïõí ïé áíáöïñÝò åßíáé íá ðåñíÜíå ìåôáâëçôÝò ìå áíáöïñÜ (by-reference). Áõôü ãßíåôáé äçìéïõñãþíôáò ìéá ôïðéêÞ ìåôáâëçôÞ óå ìéá óõíÜñôçóç êáé ìéá ìåôáâëçôÞ ìå åìâÝëåéá ôÝôïéá þóôå íá ìðïñïýìå íá ôçí êáëÝóïõìå, êáé ç ïðïßá áíáöÝñåôáé óôï ßäéï ðåñéå÷üìåíï. Ãéá ðáñÜäåéãìá:
Ôï ðáñáðÜíù ðáñÜäåéãìá èá äþóåé óôçí $a ôçí ôéìÞ 6. Áõôü óõìâáßíåé ãéáôß óôç óõíÜñôçóç foo ç ìåôáâëçôÞ $var áíáöÝñåôáé óôï ßäéï ðåñéå÷üìåíï üðùò êáé ç $a. Äåßôå ðéï ëåðôïìåñÞ åîÞãçóç óôï ðÝñáóìá ìå áíáöïñÜ (passing by reference).Ôï ôñßôï ðñÜãìá ðïõ êÜíïõí ïé áíáöïñÝò åßíáé ç åðéóôñïöÞ ìå áíáöïñÜ (return by reference).
¼ðùò Ý÷åé åéðùèåß, ïé áíáöïñÝò äåí åßíáé äåßêôåò. Áõôü óçìáßíåé üôé, ç áêüëïõèç äïìÞ äåí èá êÜíåé áõôü ðïõ ðåñéìÝíåôå:
Áõôü ðïõ óõìâáßíåé åßíáé üôé ç $var óôçí foo èá "äåèåß" ìå ôçí $bar óôçí êëÞóç, áëëÜ ôüôå èá îáíáóõíäåèåß ìå ôçí $GLOBALS["baz"]. Äåí õðÜñ÷åé ôñüðïò íá óõíäÝóïõìå ôçí $bar óôçí åìâÝëåéá êëÞóçò óå êÜôé Üëëï ÷ñçóéìïðïéþíôáò ôï ìç÷áíéóìü ìå áíáöïñÜ, áöïý ç $bar äåí åßíáé äéáèÝóéìç óôç óõíÜñôçóç foo (áíáðáñßóôáôáé áðü ôçí $var, áëëÜ ç $var Ý÷åé ìüíï ôá ðåñéå÷üìåíá ôçò ìåôáâëçôÞò êáé ü÷é óýíäåóç ïíüìáôïò-ìå-ôéìÞ óôïí ðßíáêá êëÞóçò óõìâüëùí).
Ìðïñåßôå íá ðåñÜóåôå ìåôáâëçôÝò óå óõíáñôÞóåéò ìå áíáöïñÜ, Ýôóé þóôå ç óõíÜñôçóç íá ìðïñåß íá ôñïðïðïéÞóåé ôá ïñßóìáôá ôçò. Ç óýíôáîç Ý÷åé ùò áêïëïýèùò:
Óçìåéþóôå üôé äåí õðÜñ÷åé êÜðïéï óçìÜäé áíáöïñÜò óôçí êëÞóç ôçò óõíÜñôçóçò - ìüíï óôïí ïñéóìü ôçò óõíÜñôçóçò. Ï ïñéóìüò ôçò óõíÜñôçóçò áðü ìüíïò ôïõ åßíáé áñêåôüò ãéá íá ðåñÜóåé óùóôÜ ôá ïñßóìáôá ìå áíáöïñÜ.Ôá áêüëïõèá ìðïñïýí íá ðåñáóôïýí ìå áíáöïñÜ:
Ç ìåôáâëçôÞ, ð.÷. foo($a)
Ìéá íÝá äÞëùóç, ð.÷. foo(new foobar())
ÁíáöïñÜ, ðïõ åðéóôñÝöåôáé áðü ìéá óõíÜñôçóç, ð.÷.:
Äåßôå åðßóçò åîçãÞóåéò ó÷åôéêÜ ìå åðéóôñïöÞ ìå áíáöïñÜ (returning by reference).ÏðïéáäÞðïôå Üëëç Ýêöñáóç äåí èá ðñÝðåé íá ÷ñçóéìïðïéåßôáé óôï ðÝñáóìá ìå áíáöïñÜ, áöïý ôï áðïôÝëåóìá ðïõ èá ðñïêýðôåé íá åßíáé áðñïóäéüñéóôï. Ãéá ðáñÜäåéãìá, ôá áêüëïõèá ðáñáäåßãìáôá ðåñÜóìáôïò ìå áíáöïñÜ äåí åßíáé Ýãêõñá:
ÁõôÝò ïé áðáéôÞóåéò éó÷ýïõí ãéá ôçí PHP 4.0.4 êáé ìåôÜ.Ç åðéóôñïöÞ ìå áíáöïñÜ åßíáé ÷ñÞóéìç üôáí èÝëåôå íá ÷ñçóéìïðïéÞóåôå ìéá óõíÜñôçóç ãéá íá âñåßôå ìå ðïéá ìåôáâëçôÞ ìéá áíáöïñÜ ðñÝðåé íá óõíäåèåß. ¼ôáí ãßíåôáé åðéóôñïöÞ ìå áíáöïñÜ, ÷ñçóéìïðïéåßóôå ôçí áêüëïõèç óýíôáîç:
<?php function &find_var ($param) { ...code... return $found_var; } $foo =& find_var ($bar); $foo->x = 2; ?> |
Óçìåßùóç: Óå áíôßèåóç ìå ôï ðÝñáóìá ðáñáìÝôñùí, åäþ ðñÝðåé íá ÷ñçóéìïðïéåßôå ôï & êáé óôá äõï ìÝñç - Ýôóé èá äåßîåôå üôé ãßíåôáé åðéóôñïöÞ ìå áíáöïñÜ, ü÷é ìå áíôßãñáöï ùò óõíÞèùò, êáé íá äåßîåôå üôé ç óýíäåóç áíáöïñÜò, óå áíôßèåóç ìå ôç óõíÞèç áíÜèåóç, ðñÝðåé íá ãßíåôáé ãéá ôçí $foo.
¼ôáí ãßíåôáé áêýñùóç ôçò áíÜèåóçò ìå áíáöïñÜ, áðëÜ äéáêüðôåôáé ï óýíäåóìïò áíÜìåóá óôï üíïìá ôçò ìåôáâëçôÞò êáé ôï ðåñéå÷üìåíï ôçò. Áõôü äå óçìáßíåé üôé ôï ðåñéå÷üìåíï ôçò ìåôáâëçôÞò èá êáôáóôñáöåß. Ãéá ðáñÜäåéãìá:
Ôï ðáñáðÜíù äåí èá áêõñþóåé ôçí áíÜèåóç óôçí $b, áðëÜ óôçí $a.ÎáíÜ, ßóùò åßíáé ÷ñÞóéìï íá ôï óêåöôåßôå ùò áíÜëïãï ìå ôçí êëÞóç ôïõ Unix unlink.
ÐïëëÝò óõíôáêôéêÝò äïìÝò óôçí PHP õëïðïéïýíôáé ìÝóù ìç÷áíéóìþí áíáöïñÜò, óõíåðþò ü,ôé Ý÷åé áíáöåñèåß ðáñáðÜíù ó÷åôéêÜ ìå ôçí áíáöïñÜ óýíäåóçò åðßóçò éó÷ýåé êáé ãéá áõôÝò ôéò äïìÝò. ÌåñéêÝò äïìÝò, üðùò ôï ðÝñáóìá êáé ç åðéóôñïöÞ ìå áíáöïñÜ, Ý÷ïõí áíáöåñèåß ðáñáðÜíù. ¢ëëåò äïìÝò ðïõ ÷ñçóéìïðïéïýí áíáöïñÝò åßíáé:
PHP is a powerful language and the interpreter, whether included in a web server as a module or executed as a separate CGI binary, is able to access files, execute commands and open network connections on the server. These properties make anything run on a web server insecure by default. PHP is designed specifically to be a more secure language for writing CGI programs than Perl or C, and with correct selection of compile-time and runtime configuration options, and proper coding practices, it can give you exactly the combination of freedom and security you need.
As there are many different ways of utilizing PHP, there are many configuration options controlling its behaviour. A large selection of options guarantees you can use PHP for a lot of purposes, but it also means there are combinations of these options and server configurations that result in an insecure setup.
The configuration flexibility of PHP is equally rivalled by the code flexibility. PHP can be used to build complete server applications, with all the power of a shell user, or it can be used for simple server-side includes with little risk in a tightly controlled environment. How you build that environment, and how secure it is, is largely up to the PHP developer.
This chapter starts with some general security advice, explains the different configuration option combinations and the situations they can be safely used, and describes different considerations in coding for different levels of security.
A completely secure system is a virtual impossibility, so an approach often used in the security profession is one of balancing risk and usability. If every variable submitted by a user required two forms of biometric validation (such as a retinal scan and a fingerprint), you would have an extremely high level of accountability. It would also take half an hour to fill out a fairly complex form, which would tend to encourage users to find ways of bypassing the security.
The best security is often unobtrusive enough to suit the requirements without the user being prevented from accomplishing their work, or over-burdening the code author with excessive complexity. Indeed, some security attacks are merely exploits of this kind of overly built security, which tends to erode over time.
A phrase worth remembering: A system is only as good as the weakest link in a chain. If all transactions are heavily logged based on time, location, transaction type, etc. but the user is only verified based on a single cookie, the validity of tying the users to the transaction log is severely weakened.
When testing, keep in mind that you will not be able to test all possibilities for even the simplest of pages. The input you may expect will be completely unrelated to the input given by a disgruntled employee, a cracker with months of time on their hands, or a housecat walking across the keyboard. This is why it's best to look at the code from a logical perspective, to discern where unexpected data can be introduced, and then follow how it is modified, reduced, or amplified.
The Internet is filled with people trying to make a name for themselves by breaking your code, crashing your site, posting inappropriate content, and otherwise making your day interesting. It doesn't matter if you have a small or large site, you are a target by simply being online, by having a server that can be connected to. Many cracking programs do not discern by size, they simply trawl massive IP blocks looking for victims. Try not to become one.
Using PHP as a CGI binary is an option for setups that for some reason do not wish to integrate PHP as a module into server software (like Apache), or will use PHP with different kinds of CGI wrappers to create safe chroot and setuid environments for scripts. This setup usually involves installing executable PHP binary to the web server cgi-bin directory. CERT advisory CA-96.11 recommends against placing any interpreters into cgi-bin. Even if the PHP binary can be used as a standalone interpreter, PHP is designed to prevent the attacks this setup makes possible:
Accessing system files: http://my.host/cgi-bin/php?/etc/passwd
The query information in a URL after the question mark (?) is passed as command line arguments to the interpreter by the CGI interface. Usually interpreters open and execute the file specified as the first argument on the command line.
When invoked as a CGI binary, PHP refuses to interpret the command line arguments.
Accessing any web document on server: http://my.host/cgi-bin/php/secret/doc.html
The path information part of the URL after the PHP binary name, /secret/doc.html is conventionally used to specify the name of the file to be opened and interpreted by the CGI program. Usually some web server configuration directives (Apache: Action) are used to redirect requests to documents like http://my.host/secret/script.php to the PHP interpreter. With this setup, the web server first checks the access permissions to the directory /secret, and after that creates the redirected request http://my.host/cgi-bin/php/secret/script.php. Unfortunately, if the request is originally given in this form, no access checks are made by web server for file /secret/script.php, but only for the /cgi-bin/php file. This way any user able to access /cgi-bin/php is able to access any protected document on the web server.
In PHP, compile-time configuration option --enable-force-cgi-redirect and runtime configuration directives doc_root and user_dir can be used to prevent this attack, if the server document tree has any directories with access restrictions. See below for full the explanation of the different combinations.
If your server does not have any content that is not restricted by password or ip based access control, there is no need for these configuration options. If your web server does not allow you to do redirects, or the server does not have a way to communicate to the PHP binary that the request is a safely redirected request, you can specify the option --enable-force-cgi-redirect to the configure script. You still have to make sure your PHP scripts do not rely on one or another way of calling the script, neither by directly http://my.host/cgi-bin/php/dir/script.php nor by redirection http://my.host/dir/script.php.
Redirection can be configured in Apache by using AddHandler and Action directives (see below).
This compile-time option prevents anyone from calling PHP directly with a URL like http://my.host/cgi-bin/php/secretdir/script.php. Instead, PHP will only parse in this mode if it has gone through a web server redirect rule.
Usually the redirection in the Apache configuration is done with the following directives:
Action php-script /cgi-bin/php AddHandler php-script .php |
This option has only been tested with the Apache web server, and relies on Apache to set the non-standard CGI environment variable REDIRECT_STATUS on redirected requests. If your web server does not support any way of telling if the request is direct or redirected, you cannot use this option and you must use one of the other ways of running the CGI version documented here.
To include active content, like scripts and executables, in the web server document directories is sometimes considered an insecure practice. If, because of some configuration mistake, the scripts are not executed but displayed as regular HTML documents, this may result in leakage of intellectual property or security information like passwords. Therefore many sysadmins will prefer setting up another directory structure for scripts that are accessible only through the PHP CGI, and therefore always interpreted and not displayed as such.
Also if the method for making sure the requests are not redirected, as described in the previous section, is not available, it is necessary to set up a script doc_root that is different from web document root.
You can set the PHP script document root by the configuration directive doc_root in the configuration file, or you can set the environment variable PHP_DOCUMENT_ROOT. If it is set, the CGI version of PHP will always construct the file name to open with this doc_root and the path information in the request, so you can be sure no script is executed outside this directory (except for user_dir below).
Another option usable here is user_dir. When user_dir is unset, only thing controlling the opened file name is doc_root. Opening a URL like http://my.host/~user/doc.php does not result in opening a file under users home directory, but a file called ~user/doc.php under doc_root (yes, a directory name starting with a tilde [~]).
If user_dir is set to for example public_php, a request like http://my.host/~user/doc.php will open a file called doc.php under the directory named public_php under the home directory of the user. If the home of the user is /home/user, the file executed is /home/user/public_php/doc.php.
user_dir expansion happens regardless of the doc_root setting, so you can control the document root and user directory access separately.
A very secure option is to put the PHP parser binary somewhere outside of the web tree of files. In /usr/local/bin, for example. The only real downside to this option is that you will now have to put a line similar to:
as the first line of any file containing PHP tags. You will also need to make the file executable. That is, treat it exactly as you would treat any other CGI script written in Perl or sh or any other common scripting language which uses the #! shell-escape mechanism for launching itself.To get PHP to handle PATH_INFO and PATH_TRANSLATED information correctly with this setup, the PHP parser should be compiled with the --enable-discard-path configure option.
When PHP is used as an Apache module it inherits Apache's user permissions (typically those of the "nobody" user). This has several impacts on security and authorization. For example, if you are using PHP to access a database, unless that database has built-in access control, you will have to make the database accessible to the "nobody" user. This means a malicious script could access and modify the database, even without a username and password. It's entirely possible that a web spider could stumble across a database administrator's web page, and drop all of your databases. You can protect against this with Apache authorization, or you can design your own access model using LDAP, .htaccess files, etc. and include that code as part of your PHP scripts.
Often, once security is established to the point where the PHP user (in this case, the apache user) has very little risk attached to it, it is discovered that PHP is now prevented from writing any files to user directories. Or perhaps it has been prevented from accessing or changing databases. It has equally been secured from writing good and bad files, or entering good and bad database transactions.
A frequent security mistake made at this point is to allow apache root permissions, or to escalate apache's abilitites in some other way.
Escalating the Apache user's permissions to root is extremely dangerous and may compromise the entire system, so sudo'ing, chroot'ing, or otherwise running as root should not be considered by those who are not security professionals.
There are some simpler solutions. By using open_basedir you can control and restrict what directories are allowed to be used for PHP. You can also set up apache-only areas, to restrict all web based activity to non-user, or non-system, files.
PHP is subject to the security built into most server systems with respect to permissions on a file and directory basis. This allows you to control which files in the filesystem may be read. Care should be taken with any files which are world readable to ensure that they are safe for reading by all users who have access to that filesystem.
Since PHP was designed to allow user level access to the filesystem, it's entirely possible to write a PHP script that will allow you to read system files such as /etc/passwd, modify your ethernet connections, send massive printer jobs out, etc. This has some obvious implications, in that you need to ensure that the files that you read from and write to are the appropriate ones.
Consider the following script, where a user indicates that they'd like to delete a file in their home directory. This assumes a situation where a PHP web interface is regularly used for file management, so the Apache user is allowed to delete files in the user home directories.
ÐáñÜäåéãìá 15-2. ... A filesystem attack
|
Only allow limited permissions to the PHP web user binary.
Check all variables which are submitted.
ÐáñÜäåéãìá 15-3. More secure file name checking
|
ÐáñÜäåéãìá 15-4. More secure file name checking
|
Depending on your operating system, there are a wide variety of files which you should be concerned about, including device entries (/dev/ or COM1), configuration files (/etc/ files and the .ini files), well known file storage areas (/home/, My Documents), etc. For this reason, it's usually easier to create a policy where you forbid everything except for what you explicitly allow.
Nowadays, databases are cardinal components of any web based application by enabling websites to provide varying dynamic content. Since very sensitive or secret information can be stored in a database, you should strongly consider protecting your databases.
To retrieve or to store any information you need to connect to the database, send a legitimate query, fetch the result, and close the connection. Nowadays, the commonly used query language in this interaction is the Structured Query Language (SQL). See how an attacker can tamper with an SQL query.
As you can surmise, PHP cannot protect your database by itself. The following sections aim to be an introduction into the very basics of how to access and manipulate databases within PHP scripts.
Keep in mind this simple rule: defense in depth. The more places you take action to increase the protection of your database, the less probability of an attacker succeeding in exposing or abusing any stored information. Good design of the database schema and the application deals with your greatest fears.
The first step is always to create the database, unless you want to use one from a third party. When a database is created, it is assigned to an owner, who executed the creation statement. Usually, only the owner (or a superuser) can do anything with the objects in that database, and in order to allow other users to use it, privileges must be granted.
Applications should never connect to the database as its owner or a superuser, because these users can execute any query at will, for example, modifying the schema (e.g. dropping tables) or deleting its entire content.
You may create different database users for every aspect of your application with very limited rights to database objects. The most required privileges should be granted only, and avoid that the same user can interact with the database in different use cases. This means that if intruders gain access to your database using your applications credentials, they can only effect as many changes as your application can.
You are encouraged not to implement all the business logic in the web application (i.e. your script), instead do it in the database schema using views, triggers or rules. If the system evolves, new ports will be intended to open to the database, and you have to re-implement the logic in each separate database client. Over and above, triggers can be used to transparently and automatically handle fields, which often provides insight when debugging problems with your application or tracing back transactions.
You may want to estabilish the connections over SSL to encrypt client/server communications for increased security, or you can use ssh to encrypt the network connection between clients and the database server. If either of these is used, then monitoring your traffic and gaining information about your database will be difficult for a would-be attacker.
SSL/SSH protects data travelling from the client to the server, SSL/SSH does not protect the persistent data stored in a database. SSL is an on-the-wire protocol.
Once an attacker gains access to your database directly (bypassing the webserver), the stored sensitive data may be exposed or misused, unless the information is protected by the database itself. Encrypting the data is a good way to mitigate this threat, but very few databases offer this type of data encryption.
The easiest way to work around this problem is to first create your own encryption package, and then use it from within your PHP scripts. PHP can assist you in this with several extensions, such as Mcrypt and Mhash, covering a wide variety of encryption algorithms. The script encrypts the data before inserting it into the database, and decrypts it when retrieving. See the references for further examples of how encryption works.
In case of truly hidden data, if its raw representation is not needed (i.e. not be displayed), hashing may also be taken into consideration. The well-known example for the hashing is storing the MD5 hash of a password in a database, instead of the password itself. See also crypt() and md5().
ÐáñÜäåéãìá 15-5. Using hashed password field
|
Many web developers are unaware of how SQL queries can be tampered with, and assume that an SQL query is a trusted command. It means that SQL queries are able to circumvent access controls, thereby bypassing standard authentication and authorization checks, and sometimes SQL queries even may allow access to host operating system level commands.
Direct SQL Command Injection is a technique where an attacker creates or alters existing SQL commands to expose hidden data, or to override valuable ones, or even to execute dangerous system level commands on the database host. This is accomplished by the application taking user input and combining it with static parameters to build a SQL query. The following examples are based on true stories, unfortunately.
Owing to the lack of input validation and connecting to the database on behalf of a superuser or the one who can create users, the attacker may create a superuser in your database.
ÐáñÜäåéãìá 15-6. Splitting the result set into pages ... and making superusers (PostgreSQL and MySQL)
|
// in case of PostgreSQL 0; insert into pg_shadow(usename,usesysid,usesuper,usecatupd,passwd) select 'crack', usesysid, 't','t','crack' from pg_shadow where usename='postgres'; -- // in case of MySQL 0; UPDATE user SET Password=PASSWORD('crack') WHERE user='root'; FLUSH PRIVILEGES; |
Óçìåßùóç: It is common technique to force the SQL parser to ignore the rest of the query written by the developer with -- which is the comment sign in SQL.
A feasible way to gain passwords is to circumvent your search result pages. The only thing the attacker needs to do is to see if there are any submitted variables used in SQL statements which are not handled properly. These filters can be set commonly in a preceding form to customize WHERE, ORDER BY, LIMIT and OFFSET clauses in SELECT statements. If your database supports the UNION construct, the attacker may try to append an entire query to the original one to list passwords from an arbitrary table. Using encrypted password fields is strongly encouraged.
SQL UPDATE's are also susceptible to attack. These queries are also threatened by chopping and appending an entirely new query to it. But the attacker might fiddle with the SET clause. In this case some schema information must be possessed to manipulate the query successfully. This can be acquired by examining the form variable names, or just simply brute forcing. There are not so many naming conventions for fields storing passwords or usernames.
<?php // $uid == ' or uid like'%admin%'; -- $query = "UPDATE usertable SET pwd='...' WHERE uid='' or uid like '%admin%'; --"; // $pwd == "hehehe', admin='yes', trusted=100 " $query = "UPDATE usertable SET pwd='hehehe', admin='yes', trusted=100 WHERE ...;"; ?> |
A frightening example how operating system level commands can be accessed on some database hosts.
<?php $query = "SELECT * FROM products WHERE id LIKE '%a%' exec master..xp_cmdshell 'net user test testpass /ADD'--"; $result = mssql_query($query); ?> |
Óçìåßùóç: Some of the examples above is tied to a specific database server. This does not mean that a similar attack is impossible against other products. Your database server may be similarly vulnerable in another manner.
You may plead that the attacker must possess a piece of information about the database schema in most examples. You are right, but you never know when and how it can be taken out, and if it happens, your database may be exposed. If you are using an open source, or publicly available database handling package, which may belong to a content management system or forum, the intruders easily produce a copy of a piece of your code. It may be also a security risk if it is a poorly designed one.
These attacks are mainly based on exploiting the code not being written with security in mind. Never trust any kind of input, especially that which comes from the client side, even though it comes from a select box, a hidden input field or a cookie. The first example shows that such a blameless query can cause disasters.
Never connect to the database as a superuser or as the database owner. Use always customized users with very limited privileges.
Check if the given input has the expected data type. PHP has a wide range of input validating functions, from the simplest ones found in Variable Functions and in Character Type Functions (e.g. is_numeric(), ctype_digit() respectively) and onwards to the Perl compatible Regular Expressions support.
If the application waits for numerical input, consider verifying data with is_numeric(), or silently change its type using settype(), or use its numeric representation by sprintf().
ÐáñÜäåéãìá 15-10. A more secure way to compose a query for paging
|
Quote each non numeric user input which is passed to the database with addslashes() or addcslashes(). See the first example. As the examples shows, quotes burnt into the static part of the query is not enough, and can be easily cracked.
Do not print out any database specific information, especially about the schema, by fair means or foul. See also Error Reporting and Error Handling and Logging Functions.
You may use stored procedures and previously defined cursors to abstract data access so that users do not directly access tables or views, but this solution has another impacts.
Besides these, you benefit from logging queries either within your script or by the database itself, if it supports logging. Obviously, the logging is unable to prevent any harmful attempt, but it can be helpful to trace back which application has been circumvented. The log is not useful by itself, but through the information it contains. More detail is generally better than less.
With PHP security, there are two sides to error reporting. One is beneficial to increasing security, the other is detrimental.
A standard attack tactic involves profiling a system by feeding it improper data, and checking for the kinds, and contexts, of the errors which are returned. This allows the system cracker to probe for information about the server, to determine possible weaknesses. For example, if an attacker had gleaned information about a page based on a prior form submission, they may attempt to override variables, or modify them:
The PHP errors which are normally returned can be quite helpful to a developer who is trying to debug a script, indicating such things as the function or file that failed, the PHP file it failed in, and the line number which the failure occured in. This is all information that can be exploited. It is not uncommon for a php developer to use show_source(), highlight_string(), or highlight_file() as a debugging measure, but in a live site, this can expose hidden variables, unchecked syntax, and other dangerous information. Especially dangerous is running code from known sources with built-in debugging handlers, or using common debugging techniques. If the attacker can determine what general technique you are using, they may try to brute-force a page, by sending various common debugging strings:
Regardless of the method of error handling, the ability to probe a system for errors leads to providing an attacker with more information.
For example, the very style of a generic PHP error indicates a system is running PHP. If the attacker was looking at an .html page, and wanted to probe for the back-end (to look for known weaknesses in the system), by feeding it the wrong data they may be able to determine that a system was built with PHP.
A function error can indicate whether a system may be running a specific database engine, or give clues as to how a web page or programmed or designed. This allows for deeper investigation into open database ports, or to look for specific bugs or weaknesses in a web page. By feeding different pieces of bad data, for example, an attacker can determine the order of authentication in a script, (from the line number errors) as well as probe for exploits that may be exploited in different locations in the script.
A filesystem or general PHP error can indicate what permissions the webserver has, as well as the structure and organization of files on the web server. Developer written error code can aggravate this problem, leading to easy exploitation of formerly "hidden" information.
There are three major solutions to this issue. The first is to scrutinize all functions, and attempt to compensate for the bulk of the errors. The second is to disable error reporting entirely on the running code. The third is to use PHP's custom error handling functions to create your own error handler. Depending on your security policy, you may find all three to be applicable to your situation.
One way of catching this issue ahead of time is to make use of PHP's own error_reporting(), to help you secure your code and find variable usage that may be dangerous. By testing your code, prior to deployment, with E_ALL, you can quickly find areas where your variables may be open to poisoning or modification in other ways. Once you are ready for deployment, by using E_NONE, you insulate your code from probing.
Perhaps the most controversial change in PHP is when the default value for the PHP directive register_globals went from ON to OFF in PHP 4.2.0. Reliance on this directive was quite common and many people didn't even know it existed and assumed it's just how PHP works. This page will explain how one can write insecure code with this directive but keep in mind that the directive itself isn't insecure but rather it's the misuse of it.
When on, register_globals will inject (poison) your scripts will all sorts of variables, like request variables from HTML forms. This coupled with the fact that PHP doesn't require variable initialization means writing insecure code is that much easier. It was a difficult decision, but the PHP community decided to disable this directive by default. When on, people use variables yet really don't know for sure where they come from and can only assume. Internal variables that are defined in the script itself get mixed up with request data sent by users and disabling register_globals changes this. Let's demonstrate with an example misuse of register_globals:
ÐáñÜäåéãìá 15-14. Example misuse with register_globals = on
|
When register_globals = on, our logic above may be compromised. When off, $authorized can't be set via request so it'll be fine, although it really is generally a good programming practice to initialize variables first. For example, in our example above we might have first done $authorized = false. Doing this first means our above code would work with register_globals on or off as users by default would be unauthorized.
Another example is that of sessions. When register_globals = on, we could also use $username in our example below but again you must realize that $username could also come from other means, such as GET (through the URL).
ÐáñÜäåéãìá 15-15. Example use of sessions with register_globals on or off
|
It's even possible to take preventative measures to warn when forging is being attempted. If you know ahead of time exactly where a variable should be coming from, you can check to see if the submitted data is coming from an inappropriate kind of submission. While it doesn't guarantee that data has not been forged, it does require an attacker to guess the right kind of forging. If you don't care where the request data comes from, you can use $_REQUEST as it contains a mix of GET, POST and COOKIE data. See also the manual section on using variables from outside of PHP.
ÐáñÜäåéãìá 15-16. Detecting simple variable poisoning
|
Of course, simply turning off register_globals does not mean your code is secure. For every piece of data that is submitted, it should also be checked in other ways. Always validate your user data and initialize your variables! To check for unitialized variables you may turn up error_reporting() to show E_NOTICE level errors.
Superglobals: óçìåßùóç äéáèåóéìüôçôáò: Áðü ôçí PHP 4.1.0, superglobal arrays üðùò ôï $_GET , $_POST, $_SERVER, êëð. åßíáé äéáèÝóéìá. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äéáâÜóôå ôçí åíüôçôá ôïõ manual ó÷åôéêÜ ìå ôá superglobals
The greatest weakness in many PHP programs is not inherent in the language itself, but merely an issue of code not being written with security in mind. For this reason, you should always take the time to consider the implications of a given piece of code, to ascertain the possible damage if an unexpected variable is submitted to it.
ÐáñÜäåéãìá 15-17. Dangerous Variable Usage
|
Will this script only affect the intended files?
Can unusual or undesirable data be acted upon?
Can this script be used in unintended ways?
Can this be used in conjunction with other scripts in a negative manner?
Will any transactions be adequately logged?
You may also want to consider turning off register_globals, magic_quotes, or other convenience settings which may confuse you as to the validity, source, or value of a given variable. Working with PHP in error_reporting(E_ALL) mode can also help warn you about variables being used before they are checked or initialized (so you can prevent unusual data from being operated upon).
In general, security by obscurity is one of the weakest forms of security. But in some cases, every little bit of extra security is desirable.
A few simple techniques can help to hide PHP, possibly slowing down an attacker who is attempting to discover weaknesses in your system. By setting expose_php = off in your php.ini file, you reduce the amount of information available to them.
Another tactic is to configure web servers such as apache to parse different filetypes through PHP, either with an .htaccess directive, or in the apache configuration file itself. You can then use misleading file extensions:
PHP, like any other large system, is under constant scrutiny and improvement. Each new version will often include both major and minor changes to enhance and repair security flaws, configuration mishaps, and other issues that will affect the overall security and stability of your system.
Like other system-level scripting languages and programs, the best approach is to update often, and maintain awareness of the latest versions and their changes.
Ç HTTP áíáãíþñéóç ìå ôçí PHP åßíáé äéáèÝóéìç ìüíï üôáí åêôåëåßôáé óáí Apache module êáé Ýôóé äåí åßíáé äéáèÝóéìç óôçí CGI Ýêäïóç. Óå Ýíá Apache module PHP script, åßíáé äõíáôüí íá ÷ñçóéìïðïéçèåß ç header() óõíÜñôçóç ãéá íá óôáëåß Ýíá "Authentication Required" ìÞíõìá óôïí browser ôïõ client áíáãêÜæïíôáò ôïí íá ðåôÜîåé Ýíá Username/Password ðáñÜèõñï åéóüäïõ. ¼ôáí ï ÷ñÞóôçò åéóÜãåé Ýíá username êáé Ýíá password, ôï URL ðïõ ðåñéÝ÷åé ôï PHP script èá êáëåóôåß îáíÜ ìå ôéò ðñïêáèïñéóìÝíåò ìåôáâëçôÝò PHP_AUTH_USER, PHP_AUTH_PW, êáé AUTH_TYPE ïñéóìÝíåò óôï username, password êáé ôïí ôýðï ôïõ authentication áíôßóôïé÷á. ÁõôÝò ïé ðñïêáèïñéóìÝíåò ìåôáâëçôÝò âñßóêïíôáé óôïõò $_SERVER êáé $HTTP_SERVER_VARS ðßíáêåò. Ìüíï ç "Basic" áíáãíþñéóç õðïóôçñßæåôáé. Äåßôå ôçí header() óõíÜñôçóç ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Óçìåßùóç ãéá ôéò PHP åêäüóåéò: Ïé Autoglobals, üðùò ç $_SERVER, Ýãéíáí äéáèÝóéìåò óôçí PHP Ýêäïóç 4.1.0. Ç $HTTP_SERVER_VARS åßíáé äéáèÝóéìç áðü ôçí PHP 3.
¸íá ðááñÜäåéãìá åíüò êïììÜôéïý åíüò script ôï ïðïßï åðéâÜëëåé client authentication óå ìéá óåëßäá áêïëïõèåß:
ÐáñÜäåéãìá 16-1. ÐáñÜäåéãìá HTTP Authentication
|
Óçìåßùóç Óõìâáôüôçôáò: Ðáñáêáëïýìå íá åßóôå ðñïóåêôéêïß üôáí ðñïãñáììáôßæåôå ôéò HTTP header ãñáììÝò óáò. Ãéá íá åããõçèåßôå óõìâáôüôçôá ìå üëïõò ôïõò client, ç ëÝîç-êëåéäß "Basic" ðñÝðåé íá ãñÜöåôáé ìå êåöáëáßï "B", ôï realm string ðñÝðåé íá åßíáé åóþêëåéóôï óå äéðëÜ (ü÷é ìïíÜ) åéóáãùãéêÜ (quotes), êáé áêñéâþò Ýíáò êåíüò ÷áñáêôÞñáò ðñÝðåé íá ðñïçãåßôáé ôïõ 401 êùäéêïý óôçí HTTP/1.0 401 header ãñáììÞ.
Áíôß íá åêôõðþíåôå áðëÜ ôá PHP_AUTH_USER êáé PHP_AUTH_PW, üðùò ãßíåôáé óôï ðáñáðÜíù ðáñÜäåéãìá, ìðïñåß íá èÝëåôå íá åëÝãîåôå ôçí åãêõñüôçôá ôïõ username êáé ôïõ password. ºóùò óôÝëíïíôáò ìéá åñþôçóç óå ìéá âÜóç äåäïìÝíùí, Þ áíáæçôþíôáò ôïí ÷ñÞóôç óå Ýíá dbm áñ÷åßï.
ÐñïóÝîôå ãéá åëáôôùìáôéêïýò Internet Explorer browser åêåß Ýîù. Öáßíïíôáé ðïëý åðéëåêôéêïß ãéá ôç óåéñÜ ôùí header. Ç áðïóôïëÞ ôïõ WWW-Authenticate header ðñéí ôïõ HTTP/1.0 401 header öáßíåôáé íá êÜíåé ôï êüëðï ðñïò ôï ðáñþí.
Áðü ôçí PHP 4.3.0, ãéá íá åìðïäßæåôáé êÜðïéïò íá ãñÜöåé Ýíá script ôï ïðïßï áðïêáëýðôåé ôï password ãéá ìéá óåëßäá ç ïðïßá Ý÷åé áíáãíùñéóôåß ìÝóá áðü êÜðïéï ðáñáäïóéáêü åîùôåñéêü ìç÷áíéóìü, ïé PHP_AUTH ìåôáâëçôÝò äåí èá ïñßæïíôáé áí ôï åîùôåñéêü authentication åßíáé åíåñãïðïéçìÝíï ãéá ôç óõãêåêñéìÝíç óåëßäá êáé ôï safe mode åßíáé åíåñãïðïéçìÝíï. ¼ðùò êáé íá'÷åé, ôï REMOTE_USER ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá áíáãíùñßóåôå ôïí åîùôåñéêÜ-authenticated ÷ñÞóôç. ¸ôóé, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôï $_SERVER['REMOTE_USER'].
Óçìåßùóç Ñõèìßóåùí: Ç PHP ÷ñçóéìïðïéåß ôçí ðáñïõóßá åíüò AuthType directive ãéá íá ðñïóäéïñßóåé áí åßíáé åí åíåñãåßá êÜðïéï åîùôåñéêü authentication.
Óçìåéþóôå, ùóôüóï, ðùò ôï ðáñáðÜíù äåí åìðïäßæåé êÜðïéïí ï ïðïßïò åëÝã÷åé Ýíá non-authenticated URL áðü ôï íá êëÝâåé êùäéêïýò áðü áíáãíùñéóìÝíá URL óôïí ßäéï server.
Ôüóï ï Netscape Navigator üóï êáé ï Internet Explorer èá êáèáñßóïõí ôï cache ôïõ ôïðéêïý browser ãéá Ýíá realm üôáí ëÜâïõí ìéá áðÜíôçóç áðü ôïí server ôýðïõ 401. Áõôü ðñáêôéêÜ êÜíåé "log out" Ýíá ÷ñÞóôç, áíáãêÜæïíôáò ôïõò íá åðáíá-åéóÜãïõí ôá username êáé password ôïõò. ÊÜðïéïé Üíèñùðïé ôï ÷ñçóéìïðïéïýí áõôü ãéá íá êÜíïõí "time out" ôá login, Þ íá ðñïóöÝñïõí êÜðïéï "log-out" êïõìðß.
ÐáñÜäåéãìá 16-2. ÐáñÜäåéãìá ãéá HTTP Authentication áíáãêÜæïíôáò íÝá name/password
|
ÁõôÞ ç óõìðåñéöïñÜ äåí áðáéôåßôáé áðü ôï HTTP Basic authentication ðñüôõðï, Ýôóé äåí ðñÝðåé ðïôÝ íá óôçñßæåóôå óå áõôü. ÄïêéìÝò ìå ôï Lynx Ýäåéîáí ðùò ôï Lynx äåí êáèáñßæåé ôá ðéóôïðïéçôéêÜ áíáãíþñéóçò ìå ìéá áðÜíôçóç ôïõ server ôýðïõ 401, Ýôóé ðáôþíôáò back êáé ìåôÜ forward îáíÜ èá áíïßîåé ôçí óýíäåóç ìéá êáé ïé áðáéôÞóåéò áíáãíùñéóôéêþí äåí Üëëáîáí. Ï ÷ñÞóôçò ìðïñåß íá ðáôÞóåé ôï '_' êïõìðß ãéá íá êáèáñßóåé ôéò ðëçñïöïñßåò áíáãíþñéóçò, ùóôüóï.
Åðßóçò óçìåéþóôå ðùò áõôü äåí ëåéôïõñãåß ìå ôïí Microsoft IIS server êáé ôçí CGI Ýêäïóç ôçò PHP ëüãù êÜðïéïõ ðåñéïñéóìïý ôïõ IIS. Áí ÷ñçóéìïðïéåßôå ôï IIS module (ISAPI), ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí HTTP_AUTHORIZATION ìåôáâëçôÞ ãéá ðáñÜäåéãìá: list($user, $pw) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
Óçìåßùóç: Áí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ôï uid ôïõ script ðñïóôßèåôáé óôï realm êïììÜôé ôïõ WWW-Authenticate header.
Ç PHP Ý÷åé äéáöáíÞ õðïóôÞñéîç ãéá HTTP cookies. Ôá cookies åßíáé Ýíáò ìç÷áíéóìüò ãéá áðïèÞêåõóç äåäïìÝíùí óôïí áðïìáêñõóìÝíï browser êáé Ýôóé åíôïðßæïíôáé Þ áíáãíùñßæïíôáé ÷ñÞóôåò ðïõ åðéóôñÝöïõí. Ìðïñåßôå íá ïñßóåôå cookies ÷ñçóéìïðïéþíôáò ôçí óõíÜñôçóç setcookie(). Ôá cookies åßíáé ìÝñïò ôïõ HTTP header, Ýôóé ç setcookie() ðñÝðåé íá êáëåóôåß ðñéí ïðïéáäÞðïôå Ýîïäïò óôáëåß óôïí browser. Áõôüò åßíáé ï ßäéïò ðåñéïñéóìüò ðïõ Ý÷åé ç óõíÜñôçóç header(). Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôéò output buffering óõíáñôÞóåéò ãéá íá êáèõóôåñÞóåôå ôçí Ýîïäï ôïõ script óáò ìÝ÷ñé íá áðïöáóßóåôå áí èá èÝóåôå êÜðïéï cookie Þ óôåßëåôå êÜðïéïõò headers.
ÏðïéáäÞðïôå cookies óôÝëïíôáé óå óáò áðü ôïí client èá ìåôáôñÝðïíôáé áõôüìáôá óå PHP ìåôáâëçôÝò üðùò ôá äåäïìÝíá ôùí GET êáé POST ìåèüäùí, áíÜëïãá ìå ôéò register_globals êáé variables_order ìåôáâëçôÝò ñõèìßóåùí. Áí åðéèõìåßôå íá êáèïñßóåôå ðïëëÝò ôéìÝò óå Ýíá ìïíáäéêü cookie, áðëÜ ðñïóèÝóôå [] óôï üíïìá ôïõ cookie.
Áðü ôçí PHP 4.1.0, ôï $_COOKIE auto-global array èá ðåñéÝ÷åé ðÜíôá ïðïéáäÞðïôå cookies óôÝëïíôáé áðü ôïí client. Ôï $HTTP_COOKIE_VARS ïñßæåôáé åðßóçò óå íåüôåñåò åêäüóåéò ôçò PHP üôáí ç åðéëïãÞ ñýèìéóçò track_vars ïñßæåôáé.
Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, óõìðåñéëáìâáíïìÝíïõ óçìåéþóåéò ãéá bug ôùí browser, äåßôå ôçí setcookie() óõíÜñôçóç.
Ç PHP åßíáé éêáíÞ ãéá íá ëáìâÜíåé upload áñ÷åßùí áðü ïðïéïäÞðïôå RFC-1867 óõìâáôü browser (áõôü óõìðåñéëáìâÜíåé ôïõò Netscape Navigator 3 Þ ìåãáëýôåñï, Microsoft Internet Explorer 3 ìå Ýíá patch áðü ôç Microsoft, Þ ìåãáëýôåñï ÷ùñßò êÜðïéï patch). Áõôü ôï ÷áñáêôçñéóôéêü åðéôñÝðåé óôïõò áíèñþðïõò íá êÜíïõí upload ôüóï êåéìÝíïõ, üóï êáé binary áñ÷åßá. Ìå ôéò óõíáñôÞóåéò áíáãíþñéóçò êáé ÷åéñéóìïý áñ÷åßùí ôçò PHP, Ý÷åôå ðëÞñç Ýëåã÷ï óôï ðïéüò åðéôñÝðåôáé íá êÜíåé upload êáé ôé èá ãßíåé ìå ôï áñ÷åßï áðü ôç óôéãìÞ ðïõ Ý÷åé ãßíåé upload êáé ìåôÜ.
Ó÷åôéêÝò Óçìåéþóåéò Ñõèìßóåùí: Äåßôå åðßóçò ôá file_uploads, upload_max_filesize, upload_tmp_dir, êáé post_max_size directives óôï php.ini
Óçìåéþóôå ðùò ç PHP åðßóçò õðïóôçñßæåé upload áñ÷åßùí ìå ôçí PUT ìÝèïäï üðùò ÷ñçóéìïðïéïýíôáé áõôÜ áðü ôïõò Netscape Composer êáé W3C's Amaya clients. Äåßôå ôï êåöÜëáéï ÕðïóôÞñéîç ôçò PUT Ìåèüäïõ ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Ìéá ïèüíç ãéá upload áñ÷åßïõ ìðïñåß íá öôéá÷ôåß äçìéïõñãþíôáò ìéá åéäéêÞ öüñìá ç ïðïßá ìïéÜæåé êÜðùò Ýôóé:
Ðñïåéäïðïßçóç |
Ôï MAX_FILE_SIZE åßíáé åíçìåñùôéêü ãéá ôïí browser. Åßíáé åýêïëï íá ðáñáêáìöèåß áõôÞ ç ìÝãéóôç ôéìÞ. ¸ôóé ìçí óôçñßæåóôå üôé ï browser õðáêïýåé ôçí åðéèõìßá óáò! Ïé PHP-ñõèìßóåéò üìùò, ãéá ôï ìÝãéóôï ìÝãåèïò (maximum-size), äåí ìðïñïýí íá îåãåëáóôïýí. Êáëýôåñá íá ðñïóèÝôåôå ôï MAX_FILE_SIZE ïýôùò Þ Üëëùò ãéáôß ðñïóôáôåýåé ôïõò ÷ñÞóôåò áðü ôïí êüðï íá ðåñéìÝíïõí ãéá Ýíá ìåãÜëï áñ÷åßï íá ìåôáöåñèåß ìüíï êáé ìüíï ãéá íá ìÜèïõí ðùò Þôáí ðïëý ìåãÜëï ìåôÜ. |
Ïé ìåôáâëçôÝò ðïõ ïñßæïíôáé ãéá áñ÷åßá ðïõ Ý÷ïõí ãßíåé upload áëëÜæïõí áíÜëïãá ìå ôçí Ýêäïóç ôçò PHP êáé ôéò ñõèìßóåéò. Ç autoglobal ìåôáâëçôÞ $_FILES õðÜñ÷åé áðü ôçí PHP 4.1.0. Ôï $HTTP_POST_FILES array õðÜñ÷åé áðü ôçí PHP 4.0.0. Áõôïß ïé ðßíáêåò èá ðåñéÝ÷ïõí üëåò ôéò ðëçñïöïñßåò ôùí áñ÷åßùí ðïõ Ý÷ïõí ãßíåé upload. Ç ÷ñÞóç ôçò $_FILES ðñïôéìÜôáé. Áí ôï PHP directive register_globals åßíáé åíåñãïðïéçìÝíï, ôá ó÷åôéêÜ ïíüìáôá ôùí ìåôáâëçôþí èá õðÜñ÷ïõí åðßóçò. Ôï register_globals Ý÷åé ùò ðñïåðéëïãÞ íá åßíáé áðåíåñãïðïéçìÝíï áðü ôçí PHP 4.2.0.
Ôá ðåñéå÷üìåíá ôçò $_FILES áðü ôï ðáñÜäåéãìá ìáò åßíáé ùò áêïëïýèùò. Óçìåéþóôå ðùò áõôü õðïèÝôåé ôç ÷ñÞóç ôïõ ïíüìáôïò áñ÷åßïõ íá åßíáé userfile, üðùò ÷ñçóéìïðïéåßôáé óôï ðáñÜäåéãìá ðáñáðÜíù.
Ôï áñ÷éêü üíïìá ôïõ áñ÷åßïõ óôï ìç÷Üíçìá ôïõ client.
Ôï mime type ôïõ áñ÷åßïõ, áí ï browser Ý÷åé äþóåé áõôÞ ôç ðëçñïöïñßá. ¸íá ðáñÜäåéãìá èá Þôáí "image/gif".
Ôï ìÝãåèïò, óå byte, ôïõ áñ÷åßïõ ðïõ Ý÷åé ãßíåé upload.
Ôï ðñïóùñéíü üíïìá ôïõ áñ÷åßïõ óôï ïðïßï Ý÷åé áðïèçêåõôåß ôï áñ÷åßï ðïõ Ý÷åé ãßíåé upload óôïí server.
Ï êùäéêüò óöÜëìáôïò ðïõ ó÷åôßæåôáé ìå áõôü ôï upload áñ÷åßïõ. Ôï ['error'] Ý÷åé ðñïóôåèåß óôçí PHP 4.2.0
Óçìåßùóç: Óôéò åêäüóåéò ôçò PHP ðñéí ôçí 4.1.0 áõôü Ý÷åé üíïìá $HTTP_POST_FILES êáé äåí åßíáé ìéá autoglobal ìåôáâëçôÞ üðùò åßíáé ç $_FILES. Ç PHP 3 äåí Ý÷åé õðïóôÞñéîç ãéá ôçí $HTTP_POST_FILES.
¼ôáí ôï register_globals åßíáé åíåñãïðïéçìÝíï óôï php.ini, åðéðëÝïí ìåôáâëçôÝò åßíáé äéáèÝóéìåò. Ãéá ðáñÜäåéãìá, ç $userfile_name èá éóïýôáé ìå ôçí $_FILES['userfile']['name'], ç $userfile_type èá éóïýôáé ìå ôçí $_FILES['userfile']['type'], êëð. ¸÷åôå õð' üøéí óáò ðùò áðü ôçí PHP 4.2.0, ôï register_globals åßíáé ðñïåðéëåãìÝíá áðåíåñãïðïéçìÝíï. ÐñïôéìÜôáé íá ìçí óôçñßæåóôå óå áõôü ôï directive.
Ôá áñ÷åßá ðñïåðéëåãìÝíá èá áðïèçêåýïíôáé óôïí ðñïóùñéíü êáôÜëïãï ôïõ server, åêôüò êáé áí êÜðïéá Üëëç ôïðïèåóßá äïèåß ìå ôï upload_tmp_dir directive óôï php.ini. Ï ðñïåðéëåãìÝíïò êáôÜëïãïò ìðïñåß íá áëëá÷èåß ïñßæïíôáò ôçí ìåôáâëçôÞ ðåñéâÜëëïíôïò TMPDIR óôï ðåñéâÜëëïí óôï ïðïßï åêôåëåßôáé ç PHP. Ïñßæïíôáò ôï ìå ôçí putenv() ìÝóá áðü Ýíá PHP script äåí èá äïõëÝøåé. ÁõôÞ ç ìåôáâëçôÞ ðåñéâÜëëïíôïò ìðïñåß åðéðëÝïí íá ÷ñçóéìïðïéçèåß ãéá íá óéãïõñåõôåßôå ðùò êáé Üëëåò åíÝñãåéåò åðéôåëïýíôáé óôá áñ÷åßá ðïõ Ý÷ïõí ãßíåé upload, åðéðëåüí.
ÐáñÜäåéãìá 18-2. Åðéêýñùóç upload áñ÷åßùí Äåßôå åðßóçò ôéò êáôá÷ùñÞóåéò óõíáñôÞóåùí ãéá ôéò is_uploaded_file() êáé move_uploaded_file() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò. Ôï ðáñáêÜôù ðáñÜäåéãìá èá åðåîåñãáóôåß Ýíá upload áñ÷åßïõ ðïõ ðñïÝñ÷åôáé áðü ìéá öüñìá.
|
Ôï PHP script ôï ïðïßï ëáìâÜíåé ôï áñ÷åßï ðñÝðåé íá åêôåëÝóåé ïðïéáäÞðïôå ëïãéêÞ åßíáé áðáñáßôçôç ãéá íá áðïöáóßóåé ôé èá ãßíåé ìå ôá áñ÷åßá. Ìðïñåßôå ãéá ðáñÜäåéãìá íá ÷ñçóéìïðïéÞóåôå ôçí÷ñçóéìïðïé $_FILES['userfile']['size'] ìåôáâëçôÞ ãéá íá ðåôÜîåôå ïðïéáäÞðïôå áñ÷åßá åßíáé åßôå ðïëý ìéêñÜ åßôå ðïëý ìåãÜëá. Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí $_FILES['userfile']['type'] ìåôáâëçôÞ ãéá íá ðåôÜîåôå ïðïéáäÞðïôå áñ÷åßá äåí ôáéñéÜæïõí óå ïñéóìÝíá êñéôÞñéá ôïõ ôýðïõ ôïõ áñ÷åßïõ. Áðü ôçí PHP 4.2.0, ìðïñåßôå íá ÷ñçóéìïðïéåßôå ôçí $_FILES['userfile']['error'] êáé íá ðñïãñáììáôßæåôå ôç ëïãéêÞ óáò óýìöùíá ìå ôïõò êùäéêïýò óöáëìÜôùí. ÏðïéáäÞðïôå ç ëïãéêÞ, èá ðñÝðåé åßôå íá äéáãñÜøåôå ôï áñ÷åßï áðü ôïí ðñïóùñéíü êáôÜëïãï Þ íá ôï ìåôáêéíÞóåôå êÜðïõ áëëïý.
Ôï áñ÷åßï èá äéáãñáöåß áðü ôïí ðñïóùñéíü êáôÜëïãï óôï ôÝëïò ôïõ request áí äåí Ý÷åé ìåôáêéíçèåß Þ äéáãñáöåß.
Áðü ôçí PHP 4.2.0, ç PHP åðéóôñÝöåé Ýíá áíÜëïãï êùäéêü óöÜëìáôïò ìáæß ìå ôï array ôïõ áñ÷åßïõ. Ï êùäéêüò óöÜëìáôïò ìðïñåß íá âñåèåß óôï ['error'] ôìÞìá ôïõ array ôïõ áñ÷åßïõ ðïõ äçìéïõñãåßôáé êáôÜ ôï upload ôïõ áñ÷åßïõ áðü ôçí PHP. Ìå Üëëá ëüãéá, ôï óöÜëìá ìðïñåß íá âñåèåß óôï $_FILES['userfile']['error'].
ÔéìÞ: 0; Äåí õðÜñ÷åé óöÜëìá, ôï áñ÷åßï Ý÷åé ãßíåé upload ìå åðéôõ÷ßá.
ÔéìÞ: 1; Ôï áñ÷åßï ðïõ Ý÷åé ãßíåé upload õðåñâáßíåé ôï upload_max_filesize directive óôï php.ini.
ÔéìÞ: 2; Ôï áñ÷åßï ðïõ Ý÷åé ãßíåé upload õðåñâáßíåé ôï MAX_FILE_SIZE directive ðïõ Ý÷åé ïñéóôåß óôçí html öüñìá.
ÔéìÞ: 3; Ôï áñ÷åßï ðïõ ãéíüôáí upload äåí ïëïêëÞñùóå ôçí áðïóôïëÞ ôïõ.
ÔéìÞ: 4; Äåí Ý÷åé ãßíåé êáíÝíá áñ÷åßï upload.
Óçìåßùóç: ÁõôÝò ïé ìåôáâëçôÝò Ýãéíáí óôáèåñÝò ôçò PHP óôçí PHP 4.3.0.
Ôï MAX_FILE_SIZE äåí ìðïñåß íá ïñßóåé ìÝãåèïò áñ÷åßïõ ìåãáëýôåñï áðü ôï ìÝãåèïò áñ÷åßïõ ðïõ Ý÷åé ïñéóôåß óôçí upload_max_filesize ini-ñýèìéóç. Ôï ðñïåðéëåãìÝíï åßíáé 2 Megabyte.
Áí ôï üñéï ìíÞìçò åßíáé ïñéóìÝíï, ìåãáëýôåñï memory_limit ìðïñåß íá ÷ñåéáóôåß. Óéãïõñåõôåßôå ðùò Ý÷åôå ïñßóåé ôï memory_limit áñêåôÜ ìåãÜëï.
Áí ôï max_execution_time ïñéóôåß íá åßáíé ðïëý ìéêñü, ç åêôÝëåóç ôïõ script ìðïñåß íá õðåñâåß ôçí ôéìÞ. Óéãïõñåõôåßôå ðùò Ý÷åôå ïñßóåé ôï max_execution_time áñêåôÜ ìåãÜëï.
Óçìåßùóç: Ôï max_execution_time åðçñåÜæåé ìüíï ôïí ÷ñüíï åêôÝëåóçò ôïõ ßäéïõ ôïõ script. ÏðïéïóäÞðïôå ÷ñüíïò îïäåýåôáé óå åíÝñãåéåò ðïõ óõìâáßíïõí Ýîù áðü ôçí åêôÝëåóç ôïõ script üðùò êëÞóåéò óõóôÞìáôïò ÷ñçóéìïðïéþíôáò ôéò system(), sleep() óõíáñôÞóåéò, åñùôÞóåéò âÜóåùí äåäïìÝíùí, ÷ñüíï ðïõ îïäåýåôáé áðü ôçí äéáäéêáóßá ôïõ upload ôïõ áñ÷åßïõ, êëð. äåí óõìðåñéëáìâÜíåôáé üôáí ïñßæåôáé ï ìÝãéóôïò ÷ñüíïò ðïõ åêôåëåßôáé ôï script.
Áí ôï post_max_size ïñéóôåßõ ðïëý ìéêñü, ìåãÜëá áñ÷åßá äåí ìðïñïýí íá ãßíïõí upload. Óéãïõñåõôåßôå ðùò Ý÷åôå ïñßóåé ôï post_max_size áñêåôÜ ìåãÜëï.
Áí äåí åðéêõñþíåôå óå ðïéÜ áñ÷åßá åðåíåñãåßôå, õðÜñ÷åé ðéèáíüôçôá êÜðïéïò ÷ñÞóôçò íá ìðïñÝóåé íá ðñïóðåëÜóåé åõáßóèçôåò ðëçñïöïñßåò óå Üëëïõò êáôáëüãïõò.
Óçìåéþóôå ðùò ï httpd ôïõ CERN äåß÷íåé íá áöáéñåß ïôéäÞðïôå áñ÷ßæåé óôï ðñþôï whitespace óôï content-type mime header ðïõ ëáìâÜíåé áðü ôïí client. ¼óï èá Ý÷ïõí Ýôóé ôá ðñÜãìáôá, ôï CERN httpd äåí èá õðïóôçñßæåé upload áñ÷åßùí.
Ëüãù ôïõ ìåãÜëïõ ìåãÝèïõò ôùí listing styles óôïõò êáôáëüãïõò, äåí åããõïýìáóôå ðùò áñ÷åßá ìå åîùôéêÜ ïíüìáôá (üðùò ôï íá ðåñéÝ÷ïõí êåíÜ) èá ÷åéñßæïíôáé óùóôÜ.
ÐïëëáðëÜ áñ÷åßá ìðïñïýí íá ãßíïõí upload ÷ñçóéìïðïéþíôáò äéáöïñåôéêÜ name ãéá input (ïíüìáôá ãéá åßóïäï).
Åßíáé åðßóçò äõíáôüí íá êÜíåôå upload ðïëëÜ áñ÷åßá ôáõôü÷ñïíá êáé íá Ý÷åôå ôçí ðëçñïöïñßá ïñãáíùìÝíç áõôüìáôá óå arrays ãéá óáò. Ãéá íá ôï êÜíåôå áõôü, ðñÝðåé íá ÷ñçóéìïðïéÞóåôå ôçí ßäéá óýíôáîç õðïâïëÞò ôïõ array óôçí HTML öüñìá óáò, üðùò êÜíåôå ìå ðïëëáðëÜ select êáé checkbox:
Óçìåßùóç: ÕðïóôÞñéîç ãéá ðïëëáðëÜ upload áñ÷åßùí ðñïóôÝèçêå óôçí 3.0.10.
¼ôáí ç ðáñáðÜíù öüñìá õðïâëçèåß, ôá array $_FILES['userfile'], $_FILES['userfile']['name'], êáé $_FILES['userfile']['size'] èá áñ÷éêïðïéçèïýí (üðùò åðßóçò óôï $HTTP_POST_FILES ãéá PHP åêäüóåéò ðñéí ôçí 4.1.0). ¼ôáí ôï register_globals åßíáé åíåñãïðïéçìÝíï, ôá globals ãéá áñ÷åßá ðïõ Ý÷ïõí ãßíåé upload èá áñ÷éêïðïéçèïýí åðßóçò. ÊáèÝíá áðü áõôÜ èá åßáíé Ýíá áñéèìçìÝíá indexed array ôùí áíÜëïãùí ôéìþí ãéá ôá áñ÷åßá ðïõ Ý÷ïõí õðïâëçèåß.
Ãéá ðáñÜäåéãìá, õðïèÝóôå ðùò ôá áñ÷åßá ìå ïíüìáôá /home/test/review.html êáé /home/test/xwp.out õðïâÜëëïíôáé. Óå áõôÞ ôçí ðåñßðôùóç, ôï $_FILES['userfile']['name'][0] èá ðåñéÝ÷åé ôçí ôéìÞ review.html, êáé ôï $_FILES['userfile']['name'][1] èá ðåñéÝ÷åé ôçí ôéìÞ xwp.out. Ðáñüìïéá, ôï $_FILES['userfile']['size'][0] èá ðåñéÝ÷åé ôï ìÝãåèïò ôïõ review.html, ê.ï.ê.
Ôá $_FILES['userfile']['name'][0], $_FILES['userfile']['tmp_name'][0], $_FILES['userfile']['size'][0], êáé $_FILES['userfile']['type'][0] åðßóçò ïñßæïíôáé.
Ç õðïóôÞñéîç ãéá ôçí PUT ìÝèïäï Ý÷åé áëëÜîåé ìåôáîý ôçò PHP 3 êáé ôçò PHP 4. Óôçí PHP 4, ðñÝðåé íá ÷ñçóéìïðïéåßôå ôï standard input stream ãéá íá äéáâÜóåôå ôá ðåñéå÷üìåíá åíüò HTTP PUT.
ÐáñÜäåéãìá 18-4. Áðïèçêåýïíôáò HTTP PUT áñ÷åßá ìå ôçí PHP 4
|
Óçìåßùóç: ¼ëç ç ôåêìçñßùóç ðïõ áêïëïõèåß éó÷ýåé ãéá ôçí PHP 3 ìüíï.
Ç PHP ðñïóöÝñåé õðïóôÞñéîç ãéá ôçí HTTP PUT ìÝèïäï ðïõ ÷ñçóéìïðïéåßôáé áðü client óáí ôïõò Netscape Composer êáé W3C Amaya. Ïé PUT request åßíáé áñêåôÜ áðëïýóôåñåò áðü Ýíá upload áñ÷åßïõ êáé ìïéÜæïõí êÜðùò Ýôóé:
Áõôü êáíïíéêÜ óçìáßíåé ðùò ï remote client èá Þèåëå íá áðïèçêåýóåé ôá ðåñéå÷üìåíá ðïõ áêïëïõèïýí: /path/filename.html óôï web tree óáò. Ðñïöáíþò äåí åßíáé êáé ôüóï êáëÞ éäÝá ï Apache Þ ç PHP íá áöÞíïõí áõôüìáôá ïðïéïíäÞðïôå íá êÜíåé overwrite áñ÷åßá óôï web tree óáò. ¸ôóé, ãéá íá ÷åéñéóôåßôå Ýíá ôÝôïéï request ðñÝðåé ðñþôá íá ðåßôå óôïí web server óáò ðùò èÝëåôå Ýíá óõãêåêñéìÝíï PHP script íá ÷åéñéóôåß ôï request. Óôïí Apache ôï êÜíåôå áõôü ìå ôï Script directive. Ìðïñåß íá ôïðïèåôçèåß ó÷åäüí ïðïõäÞðïôå ìÝóá óôï áñ÷åßï ñõèìßóåùí ôïõ Apache. ¸íá óõíçèéóìÝíï ìÝñïò åßíáé ìÝóá óå Ýíá <Directory> ìðëïê Þ ðéèáíþò ìÝóá óå Ýíá <Virtualhost> ìðëïê. Ìéá ãñáììÞ óáí êáé áõôÞ èá êÜíåé ôï êüëðï:
Áõôü ëÝåé óôïí Apache íá óôÝëíåé üëá ôá PUT request ãéá URI ðïõ ôáéñéÜæïõí óôï ðåñéå÷üìåíï óôï ïðïßï ôïðïèåôÞóáôå áõôÞ ôç ãñáììÞ óôï put.php script óáò. Áõôü õðïèÝôåé, öõóéêÜ, ðùò Ý÷åôå ôçí PHP óõíäåäåìÝíç ãéá ôçí .php åðÝêôáóç êáé ðùò ç PHP åßíáé åíåñãïðïéçìÝíç.
ÌÝóá óôï put.php áñ÷åßï óáò èá èÝëåôå íá êÜíåôå êÜôé ôÝôïéï:
Áõôü èá áíôéãñÜøåé ôï áñ÷åßï óôçí ôïðïèåóßá ðïõ æçôÞèçêå áðü ôïí remote client. Èá èÝëåôå ðéèáíþò íá êÜíåôå êÜðïéïõò Ýëåã÷ïõò Þ/êáé íá áíáãíùñßóåôå ôùí ÷ñÞóôç ðñéí íá åêôåëÝóåé áõôÞ ôçí áíôéãñáöÞ ôïõ áñ÷åßïõ. Ôï ìüíï êüëðï åäþ åßíáé ðùò üôáí ç PHP äåé Ýíá request ìÝóù PUT ìåèüäïõ áðïèçêåýåé ôï áñ÷åßï ðïõ Ý÷åé ãßíåé upload óå Ýíá ðñïóùñéíü áñ÷åßï üðùò åêßíá ðïõ ÷åéñßæåôáé ç POST-ìÝèïäïò. ¼ôáí ôï request ôåëåéþóåé, áõôü ôï ðñïóùñéíü áñ÷åßï äéáãñÜöåôáé. ¸ôóé, ôï PHP script óáò ðïõ ÷åéñßæåôáé ôï PUT ðñÝðåé íá áíôéãÜøåé ôï áñ÷åßï áõôü êÜðïõ áëëïý. Ôï üíïìá ôïõ ðñïóùñéíïý áõôïý áñ÷åßïõ åßíáé ìÝóá óôçí $PHP_PUT_FILENAME ìåôáâëçôÞ, êáé ìðïñåßôå íá äåßôå ôï ðñïôåéíüìåíï üíïìá ðñïïñéóìïý óôï $REQUEST_URI (ìðïñåß íá äéáöÝñåé óå web server åêôüò ôïõ Apache). Áõôü ôï üíïìá áñ÷åßïõ ðñïïñéóìïý åßíáé áõôü ðïõ ï remote client ïñßæåé. Äåí ÷ñåéÜæåôáé íá áêïýóåôå ôïí client. Èá ìðïñïýóáôå, ãéá ðáñÜäåéãìá, íá áíôéãñÜöåôå üëá ôá áñ÷åßá ðïõ ãßíïíôáé upload óå Ýíá åéäéêü êáôÜëïãï ãéá ôá upload.
¼óï ôï allow_url_fopen åßíáé åíåñãïðïéçìÞíï óôï php.ini, ìðïñåßôå íá ÷ñçóéìïðïéåßôå ôá HTTP êáé FTP URL ìå ôéò ðåñéóóüôåñåò óõíáñôÞóåéò ðïõ ðáßñíïõí Ýíá üíïìá áñ÷åßïõ óáí ðáñÜìåôñï. ÅðéðëÝïí, ôá URL ìðïñïýí íá ÷ñçóéìïðïéçèïýí ìå ôéò include(), include_once(), require() êáé require_once() äçëþóåéò. Äåßôå ôï ÐáñÜñôçìá J ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôá ðñùôüêïëëá ðïõ õðïóôçñßæïíôáé áðü ôçí PHP.
Óçìåßùóç: Óôçí PHP 4.0.3 êáé ðáëáéüôåñá, ãéá íá ÷ñçóéìïðïéÞóåôå ôáURL wrappers, ÷ñåéáæüôáí íá êÜíåôå configure ôç PHP ÷ñçóéìïðïéþíôáò ôçí åðéëïãÞ ôïõ configure --enable-url-fopen-wrapper.
Óçìåßùóç: Ïé Windows åêäüóåéò ôçò PHP ðñéí ôçí PHP 4.3 äåí õðïóôÞñéæáí ðñüóâáóç áðïìáêñõóìÝíùí áñ÷åßùí ãéá ôéò áêüëïõèåò óõíáñôÞóåéò: include(), include_once(), require(), require_once(), êáé ôéò imagecreatefromXXX óõíáñôÞóåéò óôçí ÁíáöïñÜ XLII, Image óõíáñôÞóåéò åðÝêôáóç.
Ãéá ðáñÜäåéãìá, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôï åîÞò ãéá íá áíïßîåôå Ýíá áñ÷åßï óå Ýíá remote web server, íá äéáâÜóåôå ôá äåäïìÝíá ðïõ èÝëåôå, êáé ìåôÜ íá ÷ñçóéìïðïéÞóåôå ôá äåäïìÝíá óå ìéá åñþôçóç âÜóçò äåäïìÝíùí, Þ áðëÜ íá êÜíåôå output óå Ýíá óôõë ðïõ ôáéñéÜæåé ôçí õðüëïéðç éóôïóåëßäá óáò.
ÐáñÜäåéãìá 19-1. Ðáßñíïíôáò ôïí ôßôëï ìéáò áðïìáêñõóìÝíçò óåëßäáò
|
Ìðïñåßôå åðßóçò íá ãñÜøåôå áñ÷åßá óå Ýíá FTP server (äåäïìÝíïõ ôïõ üôé Ý÷åôå óõíäåèåß óáí Ýíáò ÷ñÞóôçò ìå ôá óùóôÜ äéêáéþìáôá ðñüóâáóçò). Ìðïñåßôå ìüíï íá äçìéïõñãÞóåôå íÝá áñ÷åßá ìå áõôÞ ôç ìÝèïäï, áí ðñïóðáèÞóåôå íá êÜíåôå overwrite Ýíá áñ÷åßï ðïõ õðÜñ÷åé Þäç, ç êëÞóç ôçò fopen() èá áðïôý÷åé.
Ãéá íá óõíäåèåßôå óáí Ýíáò ÷ñÞóôçò Üëëïò áðü ôïí 'anonymous', ðñÝðåé íá ïñßóåôå ôï username (êáé ðéèáíþò ôï password) ìÝóá óôï URL, êÜðùò Ýôóé: 'ftp://user:password@ftp.example.com/path/to/file'. (Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí ßäéá ìïñöÞ óýíôáîçò ãéá íá ðñïóðåëÜóåôå áñ÷åßá ìÝóù ôïõ HTTP üôáí áðáéôïýí âáóéêÞ áíáãíþñéóç.)
ÐáñÜäåéãìá 19-2. ÁðïèÞêåõóç äåäïìÝíùí óå Ýíá áðïìáêñõóìÝíï server
|
Óçìåßùóç: Ìðïñåß íá ðÞñáôå ôçí éäÝá áðü ôï ðáñáðÜíù ðáñÜäåéãìá ðùò ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå áõôÞ ôçí ôå÷íéêÞ ãéá íá ãñÜøåôå óå Ýíá áðïìáêñõóìÝíï logfile. Äõóôõ÷þò áõôü äåí èá äïõëÝøåé åðåéäÞ ç êëÞóç ôçò fopen() èá áðïôý÷åé áí ôï áðïìáêñõóìÝíï áñ÷åßï õðÜñ÷åé Þäç. Ãéá íá êÜíåôå êáôáíåìçìÝíï logging Ýôóé, ðñÝðåé íá ñßîåôå ìéá ìáôéÜ óôçí syslog().
Óçìåßùóç: Ôá áêüëïõèá éó÷ýïõí áðü ôçí 3.0.7 êáé ìåôÜ.
ÅóùôåñéêÜ óôçí PHP Ýíá status óýíäåóçò (connection status) äéáôçñåßôáé. ÕðÜñ÷ïõí 3 äõíáôÝò êáôáóôÜóåéò:
0 - NORMAL
1 - ABORTED
2 - TIMEOUT
¼ôáí Ýíá PHP script åêôåëåßôáé, êáíïíéêÜ ç êáôÜóôáóç NORMAL åßíáé åíåñãÞ. Áí Ýíáò remote (áðïìáêñõóìÝíïò) client áðïóõíäåèåß, ç ABORTED óçìáßá êáôÜóôáóçò åíåñãïðïéåßôáé. Ìéá áðïóýíäåóç åíüò remote client óõíÞèùò ðñïêáëåßôáé üôáí ï ÷ñÞóôçò ðáôÞóåé ôï êïõìðß STOP. Áí ôï üñéï ÷ñüíïõ ôçò PHP (äåßôå ôçí set_time_limit()) ðåñáóôåß, ç TIMEOUT óçìáßá êáôÜóôáóçò åíåñãïðïéåßôáé.
Ìðïñåßôå íá áðïöáóßóåôå áí èÝëåôå ìéá áðïóýíäåóç åíüò client íá ðñïêáëåß ôï script óáò íá óôáìáôÜ. ÊÜðïôå åßíáé âïëéêü íá Ý÷åôå ðÜíôá ôá scripts óáò íá ôñÝ÷ïõí ìÝ÷ñé ôÝëïõò áêüìç êáé áí äåí õðÜñ÷åé êÜðïéïò remote browser íá ëáìâÜíåé ôçí Ýîïäï. Ç ðñïêáèïñéóìÝíç óõìðåñéöïñÜ üìùò åßíáé ôï script óáò íá ôåñìáôßæåé üôáí ï remote client áðïóõíäÝåôáé. ÁõôÞ ç óõìðåñéöïñÜ ìðïñåß íá ïñéóôåß ìÝóù ôïõ ignore_user_abort directive óôï php.ini üðùò êáé ìÝóù ôïõ áíôßóôïé÷ïõ "php_value ignore_user_abort" Apache .conf directive Þ ìå ôçí ignore_user_abort() óõíÜñôçóç. Áí äåí ðåßôå ôçò PHP íá áãíïÞóåé ìéá áðïóýíäåóç åíüò ÷ñÞóôç êáé ï ÷ñÞóôçò áðïóõíäåèåß, ôï script óáò èá ôåñìáôßóåé. Ç ìüíç åîáßñåóç åßíáé áí Ý÷åôå êÜíåé register ìéá shutdown óõíÜñôçóç ÷ñçóéìïðïéþíôáò ôçí register_shutdown_function(). Ìå ìéá shutdown óõíÜñôçóç, üôáí ï remote ÷ñÞóôçò ðáôÞóåé ôï STOP êïõìðß, ôçí åðüìåíç öïñÜ ðïõ ôï script èá ðñïóðáèÞóåé íá Ý÷åé êÜôé óôçí Ýîïäï, ç PHP èá áíé÷íåýóåé ðùò ç óýíäåóç Ý÷åé ôåñìáôéóôåß êáé ç shutdown óõíÜñôçóç èá êáëåóôåß. ÁõôÞ ç shutdown óõíÜñôçóç èá êáëåóôåß óôï ôÝëïò ôçò êáíïíéêÞò åêôÝëåóçò ôïõ script óáò, Ýôóé ãéá íá êÜíåôå êÜôé äéáöïñåôéêü óôçí ðåñßðôùóç ðïõ Ýíáò client áðïóõíäÝåôáé ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí connection_aborted() óõìíÜñôçóç. ÁõôÞ ç óõíÜñôçóç èá åðéôóôñÝøåé TRUE áí ç óýíäåóç Ý÷åé ôåñìáôéóôåß (aborted).
Ôï script óáò ìðïñåß åðßóçò íá ôåñìáôéóôåß áðü ôïí åíóùìáôùìÝíï timer (÷ñïíïìåôñçôÞ) ôùí script. Ï ðñïêáèïñéóìÝíïò timeout ÷ñüíïò åßíáé 30 äåõôåñüëåðôá. Ìðïñåß íá áëëá÷ôåß ÷ñçóéìïðïéþíôáò ôï max_execution_time directive óôï php.ini Þ ôï áíôßóôïé÷ï "php_value max_execution_time" directive óôá Apache .conf üðùò åðßóçò êáé ìå ôçí óõíÜñôçóç set_time_limit(). ¼ôáí ï timer ëÞîåé, ôï script èá ôåñìáôéóôåß êáé, üðùò êáé óôçí ðáñáðÜíù ðåñßðôùóç áðïóýíäåóçò ôïõ client, áí ìéá shutdown óõíÜñôçóç Ý÷åé êáôá÷ùñçèåß (registered) èá êáëåóôåß. ÌÝóá óå áõôÞ ôçí shutdown óõíÜñôçóç ìðïñåßôå íá åëÝãîåôå áí Ýíá timeout Þôáí ôï áßôéï ôçò êëÞóçò ôçò shutdown óõíÜñôçóçò, êáëþíôáò ôçí óõíÜñôçóç connection_timeout(). ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé TRUE áí Ýíá timeout äçìéïýñãçóå ôçí êëÞóç ôçò shutdown óõíÜñôçóçò.
ÊÜôé ðïõ áîßæåé íá óçìåéùèåß åßíáé üôé ôüóï ç ABORTED üóï êáé ç TIMEOUT êáôÜóôáóç ìðïñïýí íá åßíáé åíåñãÝò ôçí ßäéá óôéãìÞ. Áõôü åßíáé ðéèáíüí áí ðåßôå óôçí PHP íá áãíïåß ôá abort ôùí ÷ñçóôþí. Ç PHP áêüìç èá óçìåéþíåé ôï ãåãïíüò üôé êÜðïéïò ÷ñÞóôçò ìðïñåß íá Ý÷åé äéáêüøåé ôç óýíäåóç, áëëÜ ôï script èá óõíå÷ßóåé íá ôñÝ÷åé. Áí ôüôå öôÜóåé ôï üñéï ÷ñüíïõ èá ôåñìáôéóôåß êáé ç shutdown óõíÜñôçóç óáò, áí õðÜñ÷åé, èá êáëåóôåß. Óå áõôü ôï óçìåßï èá âñåßôå üôé ç connection_timeout() êáé ç connection_aborted() åðéóôñÝöïõí TRUE. Ìðïñåßôå åðßóçò íá åëÝãîåôå êáé ôéò äýï êáôáóôÜóåéò óå ìßá êëÞóç ÷ñçóéìïðïéþíôáò ôçí connection_status(). ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé Ýíá ðåäßï ìå bits (bitfield) ôùí åíåñãþí êáôáóôÜóåùí. ¸ôóé, áí êáé ïé äýï êáôáóôÜóåéò åßíáé åíåñãÝò ãéá ðáñÜäåéãìá, èá åðéóôñÝøåé 3.
Persistent connections are SQL links that do not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there's already an identical persistent connection (that remained open from earlier) - and if it exists, it uses it. If it does not exist, it creates the link. An 'identical' connection is a connection that was opened to the same host, with the same username and the same password (where applicable).
Óçìåßùóç: There are other extensions that provide persistent connections, such as the IMAP extension.
People who aren't thoroughly familiar with the way web servers work and distribute the load may mistake persistent connects for what they're not. In particular, they do not give you an ability to open 'user sessions' on the same SQL link, they do not give you an ability to build up a transaction efficiently, and they don't do a whole lot of other things. In fact, to be extremely clear about the subject, persistent connections don't give you any functionality that wasn't possible with their non-persistent brothers.
Why?
This has to do with the way web servers work. There are three ways in which your web server can utilize PHP to generate web pages.
The first method is to use PHP as a CGI "wrapper". When run this way, an instance of the PHP interpreter is created and destroyed for every page request (for a PHP page) to your web server. Because it is destroyed after every request, any resources that it acquires (such as a link to an SQL database server) are closed when it is destroyed. In this case, you do not gain anything from trying to use persistent connections -- they simply don't persist.
The second, and most popular, method is to run PHP as a module in a multiprocess web server, which currently only includes Apache. A multiprocess server typically has one process (the parent) which coordinates a set of processes (its children) who actually do the work of serving up web pages. When each request comes in from a client, it is handed off to one of the children that is not already serving another client. This means that when the same client makes a second request to the server, it may be serviced by a different child process than the first time. What a persistent connection does for you in this case it make it so each child process only needs to connect to your SQL server the first time that it serves a page that makes use of such a connection. When another page then requires a connection to the SQL server, it can reuse the connection that child established earlier.
The last method is to use PHP as a plug-in for a multithreaded web server. Currently PHP 4 has support for ISAPI, WSAPI, and NSAPI (on Windows), which all allow PHP to be used as a plug-in on multithreaded servers like Netscape FastTrack (iPlanet), Microsoft's Internet Information Server (IIS), and O'Reilly's WebSite Pro. The behavior is essentially the same as for the multiprocess model described before. Note that SAPI support is not available in PHP 3.
If persistent connections don't have any added functionality, what are they good for?
The answer here is extremely simple -- efficiency. Persistent connections are good if the overhead to create a link to your SQL server is high. Whether or not this overhead is really high depends on many factors. Like, what kind of database it is, whether or not it sits on the same computer on which your web server sits, how loaded the machine the SQL server sits on is and so forth. The bottom line is that if that connection overhead is high, persistent connections help you considerably. They cause the child process to simply connect only once for its entire lifespan, instead of every time it processes a page that requires connecting to the SQL server. This means that for every child that opened a persistent connection will have its own open persistent connection to the server. For example, if you had 20 different child processes that ran a script that made a persistent connection to your SQL server, you'd have 20 different connections to the SQL server, one from each child.
Note, however, that this can have some drawbacks if you are using a database with connection limits that are exceeded by persistent child connections. If your database has a limit of 16 simultaneous connections, and in the course of a busy server session, 17 child threads attempt to connect, one will not be able to. If there are bugs in your scripts which do not allow the connections to shut down (such as infinite loops), the database with only 16 connections may be rapidly swamped. Check your database documentation for information on handling abandoned or idle connections.
Ðñïåéäïðïßçóç |
There are a couple of additional caveats to keep in mind when using persistent connections. One is that when using table locking on a persistent connection, if the script for whatever reason cannot release the lock, then subsequent scripts using the same connection will block indefinitely and may require that you either restart the httpd server or the database server. Another is that when using transactions, a transaction block will also carry over to the next script which uses that connection if script execution ends before the transaction block does. In either case, you can use register_shutdown_function() to register a simple cleanup function to unlock your tables or roll back your transactions. Better yet, avoid the problem entirely by not using persistent connections in scripts which use table locks or transactions (you can still use them elsewhere). |
An important summary. Persistent connections were designed to have one-to-one mapping to regular connections. That means that you should always be able to replace persistent connections with non-persistent connections, and it won't change the way your script behaves. It may (and probably will) change the efficiency of the script, but not its behavior!
See also fbsql_pconnect(), ibase_pconnect(), ifx_pconnect(), imap_popen(), ingres_pconnect(), msql_pconnect(), mssql_pconnect(), mysql_pconnect(), ociplogon(), odbc_pconnect(), ora_plogon(), pfsockopen(), pg_pconnect(), and sybase_pconnect().
The PHP safe mode is an attempt to solve the shared-server security problem. It is architecturally incorrect to try to solve this problem at the PHP level, but since the alternatives at the web server and OS levels aren't very realistic, many people, especially ISP's, use safe mode for now.
Ðßíáêáò 22-1. Security and Safe Mode Configuration Directives
Name | Default | Changeable |
---|---|---|
safe_mode | "0" | PHP_INI_SYSTEM |
safe_mode_gid | "0" | PHP_INI_SYSTEM |
safe_mode_include_dir | NULL | PHP_INI_SYSTEM |
safe_mode_exec_dir | "" | PHP_INI_SYSTEM |
safe_mode_allowed_env_vars | PHP_ | PHP_INI_SYSTEM |
safe_mode_protected_env_vars | LD_LIBRARY_PATH | PHP_INI_SYSTEM |
open_basedir | NULL | PHP_INI_SYSTEM |
disable_functions | "" | PHP_INI_SYSTEM |
disable_classes | "" | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to enable PHP's safe mode. Read the Security chapter for more information.
By default, Safe Mode does a UID compare check when opening files. If you want to relax this to a GID compare, then turn on safe_mode_gid. Whether to use UID (FALSE) or GID (TRUE) checking upon file access.
UID/GID checks are bypassed when including files from this directory and its subdirectories (directory must also be in include_path or full path must including).
As of PHP 4.2.0, this directive can take a colon (semi-colon on Windows) separated path in a fashion similar to the include_path directive, rather than just a single directory.
The restriction specified is actually a prefix, not a directory name. This means that "safe_mode_include_dir = /dir/incl" also allows access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: "safe_mode_include_dir = /dir/incl/"
If PHP is used in safe mode, system() and the other functions executing system programs refuse to start programs that are not in this directory.
Setting certain environment variables may be a potential security breach. This directive contains a comma-delimited list of prefixes. In Safe Mode, the user may only alter environment variables whose names begin with the prefixes supplied here. By default, users will only be able to set environment variables that begin with PHP_ (e.g. PHP_FOO=BAR).
Óçìåßùóç: If this directive is empty, PHP will let the user modify ANY environment variable!
This directive contains a comma-delimited list of environment variables that the end user won't be able to change using putenv(). These variables will be protected even if safe_mode_allowed_env_vars is set to allow to change them.
Limit the files that can be opened by PHP to the specified directory-tree, including the file itself. This directive is NOT affected by whether Safe Mode is turned On or Off.
When a script tries to open a file with, for example, fopen() or gzopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to open it. All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink.
The special value . indicates that the directory in which the script is stored will be used as base-directory.
Under Windows, separate the directories with a semicolon. On all other systems, separate the directories with a colon. As an Apache module, open_basedir paths from parent directories are now automatically inherited.
The restriction specified with open_basedir is actually a prefix, not a directory name. This means that "open_basedir = /dir/incl" also allows access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: "open_basedir = /dir/incl/"
Óçìåßùóç: Support for multiple directories was added in 3.0.7.
The default is to allow all files to be opened.
This directive allows you to disable certain functions for security reasons. It takes on a comma-delimited list of function names. disable_functions is not affected by Safe Mode.
This directive must be set in php.ini For example, you cannot set this in httpd.conf.
This directive allows you to disable certain classes for security reasons. It takes on a comma-delimited list of class names. disable_classes is not affected by Safe Mode.
This directive must be set in php.ini For example, you cannot set this in httpd.conf.
Availability note: This directive became available in PHP 4.3.2
See also: register_globals, display_errors, and log_errors
When safe_mode is on, PHP checks to see if the owner of the current script matches the owner of the file to be operated on by a file function. For example:
-rw-rw-r-- 1 rasmus rasmus 33 Jul 1 19:20 script.php -rw-r--r-- 1 root root 1116 May 26 18:01 /etc/passwd |
<?php readfile('/etc/passwd'); ?> |
Warning: SAFE MODE Restriction in effect. The script whose uid is 500 is not allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2 |
However, there may be environments where a strict UID check is not appropriate and a relaxed GID check is sufficient. This is supported by means of the safe_mode_gid switch. Setting it to On performs the relaxed GID checking, setting it to Off (the default) performs UID checking.
If instead of safe_mode, you set an open_basedir directory then all file operations will be limited to files under the specified directory For example (Apache httpd.conf example):
<Directory /docroot> php_admin_value open_basedir /docroot </Directory> |
Warning: open_basedir restriction in effect. File is in wrong directory in /docroot/script.php on line 2 |
You can also disable individual functions. Note that the disable_functions directive can not be used outside of the php.ini file which means that you cannot disable functions on a per-virtualhost or per-directory basis in your httpd.conf file. If we add this to our php.ini file:
disable_functions readfile,system |
Warning: readfile() has been disabled for security reasons in /docroot/script.php on line 2 |
This is a still probably incomplete and possibly incorrect listing of the functions limited by safe mode.
Ðßíáêáò 22-2. Safe mode limited functions
Function | Limitations |
---|---|
dbmopen() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
dbase_open() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
filepro() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
filepro_rowcount() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
filepro_retrieve() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
ifx_* | sql_safe_mode restrictions, (!= safe mode) |
ingres_* | sql_safe_mode restrictions, (!= safe mode) |
mysql_* | sql_safe_mode restrictions, (!= safe mode) |
pg_lo_import() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
posix_mkfifo() | ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
putenv() | Obeys the safe_mode_protected_env_vars and safe_mode_allowed_env_vars ini-directives. See also the documentation on putenv() |
move_uploaded_file() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
chdir() | ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
dl() | ÁõôÞ ç óõíÜñôçóç åßíáé áðåíåñãïðïéçìÝíç óôï safe mode. |
backtick operator | ÁõôÞ ç óõíÜñôçóç åßíáé áðåíåñãïðïéçìÝíç óôï safe mode. |
shell_exec() (functional equivalent of backticks) | ÁõôÞ ç óõíÜñôçóç åßíáé áðåíåñãïðïéçìÝíç óôï safe mode. |
exec() | You can only execute executables within the safe_mode_exec_dir. For practical reasons it's currently not allowed to have .. components in the path to the executable. |
system() | You can only execute executables within the safe_mode_exec_dir. For practical reasons it's currently not allowed to have .. components in the path to the executable. |
passthru() | You can only execute executables within the safe_mode_exec_dir. For practical reasons it's currently not allowed to have .. components in the path to the executable. |
popen() | You can only execute executables within the safe_mode_exec_dir. For practical reasons it's currently not allowed to have .. components in the path to the executable. |
fopen() | ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
mkdir() | ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
rmdir() | ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
rename() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
unlink() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
copy() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. (on source and target) |
chgrp() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
chown() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
chmod() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. In addition, you cannot set the SUID, SGID and sticky bits |
touch() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. |
symlink() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. (note: only the target is checked) |
link() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. (note: only the target is checked) |
apache_request_headers() | In safe mode, headers beginning with 'authorization' (case-insensitive) will not be returned. |
header() | In safe mode, the uid of the script is added to the realm part of the WWW-Authenticate header if you set this header (used for HTTP Authentication). |
PHP_AUTH variables | In safe mode, the variables PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE are not available in $_SERVER. Regardless, you can still use REMOTE_USER for the USER. (note: only affected since PHP 4.3.0) |
highlight_file(), show_source() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. (note: only affected since PHP 4.2.1) |
parse_ini_file() | ÅëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. ÅëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé. (note: only affected since PHP 4.2.1) |
set_time_limit() | Has no affect when PHP is running in safe mode. |
max_execution_time | Has no affect when PHP is running in safe mode. |
mail() | In safe mode, the fifth parameter is disabled. (note: only affected since PHP 4.2.3) |
Any function that uses php4/main/fopen_wrappers.c | ?? |
Áðü ôçí Ýêäïóç 4.3.0, ç PHP õðïóôçñßæåé Ýíá íÝï ôýðï SAPI (Server Application Programming Interface) ìå üíïìá CLI ôï ïðïßï óçìáßíåé Command Line Interface. ¼ðùò õðïäçëþíåé ôï üíïìá, ôï åðßêåíôñï áõôïý ôïõ ôýðïõ SAPI åßíáé ç áíÜðôõîç åöáñìïãþí ãéá ôï shell (Þ åðßóçò ãéá desktop) ìå ôçí PHP. ÕðÜñ÷ïõí áñêåôÝò äéáöïñÝò ìåôáîý ôïõ CLI SAPI êáé Üëëùí SAPI ôá ïðïßá åîçãïýíôáé óå áõôü ôï êåöÜëáéï. Áîßæåé íá óçìåéùèåß ðùò ôï CLI êáé ôï CGI åßíáé äéáöïñåôéêÜ SAPI áí êáé ìïéñÜæïíôáé ðïëëÝò ßäéåò óõìðåñéöïñÝò.
Ôï CLI SAPI Ý÷åé êõêëïöïñÞóåé ãéá ðñþôï öïñÜ ìå ôçí PHP 4.2.0, áëëÜ Þôáí áêüìç ðåéñáìáôéêü êáé Ýðñåðå íá åíåñãïðïéçèåß ñçôÜ ìå ôï --enable-cli üôáí Ýôñå÷å ôï ./configure. Áðü ôçí PHP 4.3.0 ôï CLI SAPI äåí åßíáé ðëÝïí ðåéñáìáôéêü êáé ç åðéëïãÞ --enable-cli åßíáé ðñïåðéëåãìÝíá åíåñãïðïéçìÝíç. Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôï --disable-cli ãéá íá ôçí áðåíåñãïðïéÞóåôå.
Áðü ôçí PHP 4.3.0, ôï üíïìá, ôïðïèåóßá êáé ç ýðáñîç ôùí CLI/CGI binaries èá äéáöÝñåé áíÜëïãá ìå ôïí ôñüðï ðïõ åãêáôáóôÜèçêå ç PHP óôï óýóôçìá óáò. Ùò ðñïåðéëïãÞ, üôáí åêôåëåßôáé ôï make, ôüóï ôï CGI üóï êáé ôï CLI ãßíïíôáé build êáé ôïðïèåôïýíôáé ùò sapi/cgi/php êáé sapi/cli/php áíôßóôïé÷á, óôïí êáôÜëïãï ôïõ source ôçò php. Èá ðñïóÝîåôå ðùò êáé ôá äýï Ý÷ïõí üíïìá php. Áõôü ðïõ óõìâáßíåé êáôÜ ôç äéÜñêåéá ôïõ make install åîáñôÜôáé áðü ôç ãñáììÞ ôïõ configure óáò. Áí Ýíá module SAPI åðéëåãåß óôï configure, üðùò ôï apxs, Þ ç åðéëïãÞ --disable-cgi ÷ñçóéìïðïéçèåß, ôï CLI áíôéãñÜöåôáé óôï {PREFIX}/bin/php óôç äéÜñêåéá ôïõ make install áëëéþò ôï CGI ôïðïèåôåßôáé åêåß. ¸ôóé, ãéá ðáñÜäåéãìá, áí ôï --with--apxs âñßóêåôáé óôçí configure ãñáììÞ óáò, ôï CLI áíôéãñÜöåôáé óôï {PREFIX}/bin/php êáôÜ ôç äéÜñêåéá ôïõ make install. Áí èÝëåôå íá ðáñáêÜìøåôå ôçí åãêáôÜóôáóç ôïõ CGI binary, ÷ñçóéìïðïéÞóôå ôï make install-cli ìåôÜ ôï make install. ÅíáëëáêôéêÜ ìðïñåßôå íá ïñßóåôå ôï --disable-cgi óôçí configure ãñáììÞ óáò.
Óçìåßùóç: ÅðåéäÞ ôüóï ôï --enable-cli üóï êáé ôï --enable-cgi åßíáé åíåñãïðïéçìÝíá by default (ùò ðñïåðéëïãÞ), áðëÜ Ý÷ïíôáò ôï --enable-cli óôçí configure ãñáììÞ óáò äåí óçìáßíåé áðáñáßôçôá ðùò ôï CLI èá áíôéãñáöåß ùò {PREFIX}/bin/php êáôÜ ôï make install.
Ôá windows ðáêÝôá ìåôáîý ôçò PHP 4.2.0 êáé ôçò PHP 4.2.3 Ýäéíáí ôï CLI óáí php-cli.exe, Ý÷ïíôáò ôï óôïí ßäéï êáôÜëïãï ìå ôï CGI php.exe. Áðü ôçí PHP 4.3.0 ôï windows ðáêÝôï äßíåé ôï CLI óáí php.exe óå Ýíá îå÷ùñéóôü êáôÜëïãï ìå üíïìá cli, Ýôóé cli/php.exe.
Ôé SAPI Ý÷ù;: Áðü Ýíá shell, ç åíôïëÞ php -v èá óáò ðåé áí ç php åßíáé CGI Þ CLI. Äåßôå åðßóçò ôç óõíÜñôçóç php_sapi_name() êáé ôç óôáèåñÜ PHP_SAPI.
Óçìåßùóç: Ìéá manual óåëßäá ôïõ unix Ý÷åé ðñïóôåèåß óôçí PHP 4.3.2. Ìðïñåßôå íá ôçí äåßôå ãñÜöïíôáò man php óôï shell ðåñéâÜëëïí óáò.
Ïé êýñéåò äéáöïñÝò ôïõ CLI SAPI óõãêñéôéêÜ ìå ôï SAPI åßíáé:
Áíôßèåôá ìå ôï CGI SAPI, äåí åêôõðþíïíôáé headers óôçí Ýîïäï.
Áí êáé ôï CGI SAPI ðñïóöÝñåé Ýíá ôñüðï ãéá íá ìçí öáíïýí HTTP headers, äåí õðÜñ÷åé ðáñüìïéïò äéáêüðôçò ãéá íá ôïõò åíåñãïðïéÞóåé êáíåßò óôï CLI SAPI.
Ôï CLI îåêéíÜ óå quiet mode ùò ðñïåðéëïãÞ, áí êáé ï -q äéáêüðôçò êñáôéÝôáé ãéá óõìâáôüôçôá ãéá íá ìðïñåßôå íá ôï ÷ñçóéìïðïéåßôå óå ðáëáéüôåñá CGI scripts.
Äåí áëëÜæåé ôïí working êáôÜëïãï óå áõôüí ôïõ script. (Ï äéáêüðôçò -C õðÜñ÷åé ãéá óõìâáôüôçôá)
ÁðëÜ ìçíýìáôá ëÜèïõò óå ìïñöÞ êåéìÝíïõ (äåí õðÜñ÷åé HTML ìïñöïðïßçóç).
ÕðÜñ÷ïõí óõãêåêñéìÝíá php.ini directives ôá ïðïßá ãßíïíôáé override áðü ôï CLI SAPI åðåéäÞ äåí Ý÷ïõí íüçìá óå shell ðåñéâÜëëïíôá:
Ðßíáêáò 23-1. php.ini directives ðïõ ãßíïíôáé ïverride
Directive | ÐñïåðéëåãìÝíç ôéìÞ ôïõ CLI SAPI | Ó÷üëéá |
---|---|---|
html_errors | FALSE | Ìðïñåß íá åßíáé áñêåôÜ äýóêïëï íá äéáâáóôïýí ôá ìçíýìáôá óöáëìÜôùí óôï shell üôáí åßíáé ãåìÜôá ìå üëá åêåßíá ôá Üóêïðá HTML tags, Ýôóé áõôü ôï Ý÷åé ùò ðñïåðéëïãÞ ôï FALSE. |
implicit_flush | TRUE | Åßíáé èåìéôü ïðïéáäÞðïôå Ýîïäïò ðñïåñ÷üìåíç áðü ôéò print(), echo() êáé ôïõò ößëïõò ôïõò íá ãñÜöåôáé áìÝóùò óôï output êáé íá ìçí ãßíïíôáé cache óå êÜðïéï buffer. Ìðïñåßôå áêüìç íá ÷ñçóéìïðïéÞóåôåoutput buffering áí èÝëåôå íá áíáâÜëëåôå Þ íá ÷åéñéóôåßôå ôï standard output. |
max_execution_time | 0 (unlimited) | Ëüãù ôùí Üðåéñùí äõíáôïôÞôùí óôç ÷ñÞóç ôçò PHP óå ðåñéâÜëëïíôá shell, ï ìÝãéóôïò ÷ñüíïò åêôÝëåóçò Ý÷åé ïñéóôåß íá åßíáé áðåñéüñéóôïò. Åêåß ðïõ ïé åöáñìïãÝò ãñáììÝíåò ãéá ôï web óõ÷íÜ åêôåëïýíôáé ðïëý ãñÞãïñá, ïé shell åöáñìïãÝò ôåßíïõí íá Ý÷ïõí ðïëý ìåãáëýôåñï ÷ñüíï åêôÝëåóçò. |
register_argc_argv | TRUE |
ÅðåéäÞ áõôÞ ç ñýèìéóç åßíáé TRUE ðÜíôá èá Ý÷åôå ðñüóâáóç óôï argc (ï áñéèìüò ôùí arguments ðïõ ðåñíéïýíôáé óôçí åöáñìïãÞ) êáé ôï argv (array ôùí ßäéùí ôùí argument) óôï CLI SAPI. Áðü ôçí PHP 4.3.0, ïé PHP ìåôáâëçôÝò $argc êáé $argv êáôá÷ùñïýíôáé êáé ôéìïëïãïýíôáé ìå ôéò áíÜëïãåò ôéìÝò üôáí ÷ñçóéìïðïéåßôáé ôï CLI SAPI. Ðñéí áðü áõôÞ ôçí Ýêäïóç, ç äçìéïõñãßá áõôþí ôùí ìåôáâëçôþí óõìðåñéöåñüôáí üðùò ãßíåôáé óôéò CGI êáé MODULE åêäüóåéò ðïõ áðáéôïýí ôï PHP directive register_globals íá åßíáé åíåñãïðïéçìÝíï. ÁíåîÜñôçôá ôçò Ýêäïóçò Þ ôçò register_globals ñýèìéóçò, ìðïñåßôå ðÜíôá íá ðÜôå ìÝóù ôïõ $_SERVER Þ ôïõ $HTTP_SERVER_VARS. Ãéá ðáñÜäåéãìá: $_SERVER['argv'] |
Óçìåßùóç: ÁõôÜ ôá directives äåí ìðïñïýí íá áñ÷éêïðïéçèïýí ìå êÜðïéá Üëëç ôéìÞ áðü ôï áñ÷åßï ñõèìßóåùí php.ini Þ Ýíá ðñïóùðéêü (áí ïñéóôåß). Áõôüò åßíáé Ýíáò ðåñéïñéóìüò åðåéäÞ áõôÝò ïé ôéìÝò åöáñìüæïíôáé ìåôÜ ðïõ áíáëýïíôáé üëá ôá áñ÷åßá ñõèìßóåùí. Ùóôüóï, ïé ôéìÝò ôïõò ìðïñïýí íá áëëá÷ôïýí êáôÜ ôï runtime (êÜôé ôï ïðïßï äåí Ý÷åé íüçìá ãéá üëá åêåßíá ôá directives, ð.÷. register_argc_argv).
Ãéá íá ãßíåé ðéï åýêïëç ç åñãáóßá óôï ðåñéâÜëëïí ôïõ shell, ïé ðáñáêÜôù óôáèåñÝò ïñßæïíôáé:
Ðßíáêáò 23-2. ÓôáèåñÝò åéäéêÝò ãéá ôï CLI
ÓôáèåñÜ | ÐåñéãñáöÞ | |
---|---|---|
STDIN |
¸íá Þäç áíïé÷ôü stream óôï stdin. Áõôü áðïèçêåýåôáé
áíïßãïíôáò ôï ìå ôçí
| |
STDOUT |
¸íá Þäç áíïé÷ôü stream óôï stdout. Áõôü áðïèçêåýåôáé
áíïßãïíôáò ôï ìå ôçí
| |
STDERR |
¸íá Þäç áíïé÷ôü stream óôï stderr. Áõôü áðïèçêåýåôáé
áíïßãïíôáò ôï ìå ôçí
|
ÄåäïìÝíùí ôùí ðáñáðÜíù, áäåí ÷ñåéÜæåóôå íá áíïßîåôå ð.÷. Ýíá stream ãéá ôï stderr ïé ßäéïé, áðëÜ ÷ñçóéìïðïéÞóôå ôç óôáèåñÜ áíôß ôïõ ßäéïõ ôïõ stream resource:
php -r 'fwrite(STDERR, "stderr\n");' |
Ôï CLI SAPI äåí áëëÜæåé ôïí ôñÝ÷ùí êáôÜëïãï óôïí êáôÜëïãï ôïõ script ðïõ åêôåëåßôáé!
ÐáñÜäåéãìá ðïõ äåß÷íåé ôéò äéáöïñÝò óôï CGI SAPI:
<?php /* Our simple test application named test.php*/ echo getcwd(), "\n"; ?> |
¼ôáí ÷ñçóéìïðïéåßôå ôçí CGI Ýêäïóç, ç Ýîïäïò åßíáé:
$ pwd /tmp $ php -q another_directory/test.php /tmp/another_directory |
×ñçóéìïðïéþíôáò ôï CLI SAPI ãßíåôáé:
$ pwd /tmp $ php -f another_directory/test.php /tmp |
Óçìåßùóç: Ôï CGI SAPI õðïóôçñßæåé ôçí CLI SAPI óõìðåñéöïñÜ ìÝóù ôïõ -C switch üôáí åêôåëåßôáé áðü ôçí ãñáììÞ åíôïëþí.
Ç ëßóôá ôùí åðéëïãþí ôïõ command line options ðïõ äßíåôáé ìå ôï PHP binary ìðïñïýí íá åñùôçèïýí áíÜ ðÜóá óôéãìÞ ôñÝ÷ïíôáò ôçí PHP ìå ôï -h switch:
Usage: php [options] [-f] <file> [args...] php [options] -r <code> [args...] php [options] [-- args...] -s Display colour syntax highlighted source. -w Display source with stripped comments and whitespace. -f <file> Parse <file>. -v Version number -c <path>|<file> Look for php.ini file in this directory -a Run interactively -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -z <file> Load Zend extension <file>. -l Syntax check only (lint) -m Show compiled in modules -i PHP information -r <code> Run PHP <code> without using script tags <?..?> -h This help args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin |
Ôï CLI SAPI Ý÷åé ôñåéò äéáöïñåôéêïýò ôñüðïõò ãéá íá ðÜñåé ôïí PHP êþäéêá ðïõ èÝëåôå íá åêôåëÝóåôå:
ËÝãïíôáò ôçò PHP íá åêôåëÝóåé Ýíá óõãêåêñéìÝíï áñ÷åßï.
php my_script.php php -f my_script.php |
Äßíïíôáò ôïí PHP êþäéêá ðñïò åêôÝëåóç êáô' åõèåßáí óôçí ãñáììÞ åíôïëþí.
php -r 'print_r(get_defined_constants());' |
Óçìåßùóç: ÄéáâÜóôå ôï ðáñÜäåéãìá ðñïóåêôéêÜ, äåí õðÜñ÷ïõí tags áñ÷Þò Þ ôÝëïõò! Ôï -r switch áðëÜ äåí ôéò ÷ñåéÜæåôáé. ×ñçóéìïðïéþíôáò ôéò èá ïäçãÞóåé óå Ýíá óöÜëìá ôïõ ìåôáöñáóôÞ.
Äßíïíôáò ôïí PHP êþäéêá ðñïò åêôÝëåóç ìÝóù ôïõ standard input (stdin).
Áõôü äßíåé ôçí éó÷õñÞ äõíáôüôçôá äõíáìéêÞò äçìéïõñãßáò PHP êþäéêá êáé ôñïöïäïóßáò ôïõ óôï binary, üðùò öáßíåôáé óå áõôü ôï (öáíôáóôéêü) ðáñÜäåéãìá:
$ some_application | some_filter | php | sort -u >final_output.txt |
¼ðùò ïðïéáäÞðïôå shell åöáñìïãÞ, ôï PHP binary äÝ÷åôáé Ýíá áñéèìü áðü ïñßóìáôá (arguments) áëëÜ ôï PHP script ìðïñåß åðßóçò íá äå÷ôåß ïñßóìáôá. Ï áñéèìüò ôùí ïñéóìÜôùí ðïõ ìðïñïýí íá ðåñáóôïýí óôï script óáò äåí ðåñéïñßæåôáé áðü ôçí PHP (ôï shell Ý÷åé Ýíá ïñéóìÝíï üñéï ìåãÝèïõò ôïõ áñéèìïý ôùí ÷áñáêôÞñùí ðïõ ìðïñïýí íá ðåñáóôïýí, óõíÞèùò äåí èá öôÜóåôå áõôü ôï üñéï). Ôá arguments ðïõ ðåñíéïýíôáé óôï script óáò åßíáé äéáèÝóéìá ìÝóù ôïõ global array $argv. Ï ìçäåíéêüò äåßêôçò (index) ðÜíôá ðåñéÝ÷åé ôï üíïìá ôïõ script (ôï ïðïßï åßíáé - óå ðåñßðôùóç ðïõ ï PHP êþäéêáò Ýñ÷åôáé áðü åßôå ôï standard input Þ áðü ôï switch ôçò ãñáììÞò åíôïëþí -r). Ç äåýôåñç registered global ìåôáâëçôÞ åßíáé ç $argc ç ïðïßá ðåñéÝ÷åé ôïí áñéèìü ôùí óôïé÷åßùí óôï $argv array (ü÷é ôïí áñéèìü ôùí arguments ðïõ äßíïíôáé óôï script).
¼óï ôá arguments ðïõ èÝëåôå íá ðåñÜóåôå óôï script óáò äåí áñ÷ßæïõí ìå ôïí ÷áñáêôÞñá -, äåí õðÜñ÷åé ôßðïôá éäéáßôåñï ðïõ ðñÝðåé íá ðñïóÝîåôå. Ðåñíþíôáò Ýíá argument óôï script óáò ôï ïðïßï áñ÷ßæåé ìå - èá äçìéïõñãÞóåé ðñïâëÞìáôá åðåéäÞ ç ßäéá ç PHP íïìßæåé ðùò ðñÝðåé íá ôï ÷åéñéóôåß. Ãéá íá ôï áðïöýãåôå áõôü, ÷ñçóéìïðïéÞóôå ôï argument list separator (äéá÷ùñéóôÞò) --. ÌåôÜ ðïõ áíáëýåôáé áõôüò ï äéá÷ùñéóôÞò óôçí PHP, êÜèå argument ðïõ áêïëïõèåß ðåñíéÝôáé áíÝðáöïò óôï script óáò.
# This will not execute the given code but will show the PHP usage $ php -r 'var_dump($argv);' -h Usage: php [options] [-f] <file> [args...] [...] # This will pass the '-h' argument to your script and prevent PHP from showing it's usage $ php -r 'var_dump($argv);' -- -h array(2) { [0]=> string(1) "-" [1]=> string(2) "-h" } |
Ùóôüóï, õðÜñ÷åé áêüìç Ýíáò ôñüðïò ÷ñÞóçò ôçò PHP ãéá shell scripting. Ìðïñåßôå íá ãñÜøåôå Ýíá script üðïõ ç ðñþôç ãñáììÞ áñ÷ßæåé ìå #!/usr/bin/php. Áêïëïõèþíôáò áõôü ìðïñåßôå íá ôïðïèåôÞóåôå êáíïíéêü PHP êþäéêá ìåôáîý ôùí PHP tags áñ÷Þò êáé ôÝëïõò. Áðü ôç óôéãìÞ ðïõ Ý÷åôå ïñßóåé ôá attribute åêôÝëåóçò ôïõ áñ÷åßïõ êáôÜëëçëá (ð.÷. chmod +x test) ôï script óáò ìðïñåß íá åêôåëåóôåß üðùò Ýíá êáíïíéêü shell Þ perl script:
#!/usr/bin/php <?php var_dump($argv); ?> |
$ chmod 755 test $ ./test -h -- foo array(4) { [0]=> string(6) "./test" [1]=> string(2) "-h" [2]=> string(2) "--" [3]=> string(3) "foo" } |
Ðßíáêáò 23-3. ÅðéëïãÝò ãñáììÞò åíôïëþí
ÅðéëïãÞ | ÐåñéãñáöÞ | |||
---|---|---|---|---|
-s |
Åìöáíßæåé êþäéêá ìå ÷ñçìáôéêü syntax highlighting. ÁõôÞ ç åðéëïãÞ ÷ñçóéìïðïéåß ôïí åóùôåñéêü ìç÷áíéóìü áíÜëõóçò ôïõ áñ÷åßïõ êáé ðáñÜãåé ìéá HTML highlighted Ýêäïóç ôïõ êáé ôï ãñÜöåé óôïï standard output. Óçìåéþóôå ðùò ôï ìüíï ðïõ êÜíåé åßíáé íá ðáñÜãåé Ýíá ìðëïê áðü <code> [...] </code> HTML tags, ü÷é HTML headers.
| |||
-w |
Åìöáíßæåé êþäéêá ìå áöáéñåìÝíá ôá ó÷üëéá êáé ôïõò êåíïýò ÷áñáêôÞñåò.
| |||
-f |
ÌåôáöñÜæåé êáé åêôåëåß ôï äïóìÝíï áñ÷åßï óôçí -f åðéëïãÞ. Áõôü ôï switch åßíáé ðñïáéñåôéêü êáé ìðïñåß íá ðáñáëçöèåß. ÁðëÜ ðáñÝ÷ïíôáò ôï üíïìá ôïõ áñ÷åßïõ ðñïò åêôÝëåóç åßíáé áñêåôü. | |||
-v |
ÃñÜöåé ôéò åêäüóåéò ôùí PHP, PHP SAPI, êáé Zend óôï standard output, ð.÷.
| |||
-c |
Ìå áõôÞ ôçí åðéëïãÞ êÜðïéïò ìðïñåß åßôå íá ïñßóåé Ýíá êáôÜëïãï üðïõ èá áíáæçôçèåß ôï php.ini åßôå íá ïñßóåé Ýíá ðñïóùðéêü áñ÷åßï INI áð' åõèåßáò (ôï ïðïßï äåí ÷ñåéÜæåôáé íá ïíïìÜæåôáé php.ini), ð.÷.:
| |||
-a |
ÔñÝ÷åé ôçí PHP interactively. | |||
-d |
ÁõôÞ ç åðéëïãÞ óáò åðéôñÝðåé íá ïñßóåôå ìéá ðñïóùðéêÞ ôéìÞ ãéá ïðïéïäÞðïôå áðü ôá directive ñõèìßóåùí ðïõ åðéôñÝðïíôáé óôï php.ini. Ç óýíôáîç åßíáé:
Ðáñáäåßãìáôá:
| |||
-e |
ÐáñÜãåé åêôåíåßò ðëçñïöïñßåò ãéá ôïí debugger/profiler. | |||
-z |
Öïñôþíåé ôçí Zend åðÝêôáóç. Áí ìüíï Ýíá üíïìá áñ÷åßï äïèåß, ç PHP ðñïóðáèåß íá öïñôþóåé ôçí åðÝêôáóç áðü ôï ðáñþí path âéâëéïèçêþí óôï óýóôçìá óáò (óõíÞèùò ïñßæåôáé ôï /etc/ld.so.conf óôá Linux óõóôÞìáôá). Ðåñíþíôáò Ýíá üíïìá áñ÷åßï ìå Ýíá absolute (áðüëõôï) path äåí èá ÷ñçóéìïðïéèåß ôï path áíáæÞôçóçò âéâëéïèçêþí ôïõ óõóôÞìáôïò. ¸íá relative (ó÷åôéêü) üíïìá áñ÷åßïõ ìå êáôÜëïãï èá êÜíåé ôçí PHP íá ðñïóðáèÞóåé íá öïñôþóåé ôçí åðÝêôáóç óôïí êáôÜëïãï ó÷åôéêÜ (relative) óôïí ôñÝ÷ùí êáôÜëïãï. | |||
-l |
ÁõÞ ç åðéëïãÞ ðñïóöÝñåé Ýíá âïëéêü ôñüðï íá ãßíåôáé áðëÜ Ýíáò Ýëåã÷ïò óýíôáîçò óôïí äïóìÝíï PHP êþäéêá. Óå åðéôõ÷ßá, ôï êåßìåíï No syntax errors detected in <filename> ãñÜöåôáé óôï standard output êáé ôï shell return code åßíáé 0. Óå áðïôõ÷ßá, ôï êåßìåíï Errors parsing <filename> åðéðñüóèåôá óôï êåßìåíï óöáëìÜôùí ôïõ åóùôåñéêïý ìåôáöñáóôÞ ãñÜöåôáé óôï standard output êáé ôï shell return code ïñßæåôáé óå 255. ÁõôÞ ç åðéëïãÞ äåí èá âñåé fatal óöÜëìáôá (üðùò undefined óõíáñôÞóåéò). ×ñçóéìïðïéÞóôå ôï -f áí èÝëåôå íá åëÝãîåôå êáé ãéá fatal óöÜëìáôá.
| |||
-m |
×ñçóéìïðïéþíôáò áõôÞ ôçí åðéëïãÞ, ç PHP åêôõðþíåé ôá built-in (êáé öïñôùìÝíá) PHP êáé Zend modules:
| |||
-i | ÁõôÞ ç command line åðéëïãÞ êáëåß ôçí phpinfo(), êáé åêôõðþíåé ôá áðïôåëÝóìáôá. Áí ç PHP äåí äïõëåýåé óùóôÜ, óõìâïõëåýåóôå íá ÷ñçóéìïðïéÞóåôå ôï php -i êáé íá äåßôå áí ïðïéáäÞðïôå ìçíÞìáôá óöáëìÜôùí åêôõðþíïíôáé ðñéí Þ óôç èÝóç ôùí ðéíÜêùí ðëçñïöïñéþí. ÐñïóÝîôå ðùò ç Ýîïäïò åßíáé óå HTML êáé Ýôóé áñêåôÜ ìåãÜëç. | |||
-r |
ÁõôÞ ç åðéëïãÞ åðéôñÝðåé ôçí åêôÝëåóç ôçò PHP áêñéâþò ìÝóù ôçò ãñáììÞò åíôïëþí. Ôá PHP tags áñ÷Þò êáé ôÝëïõò (<?php êáé ?>) äåí ÷ñåéÜæïíôáé êáé èá ðñïêáëÝóïõí Ýíá óöÜëìá ìåôáöñáóôÞ áí õðÜñ÷ïõí.
| |||
-h | Ìå áõôÞ ôçí åðéëïãÞ, ìðïñåßôå íá ðÜñåôå ðëçñïöïñßåò ó÷åôéêÜ ìå ôçí áêñéâÞ ëßóôá ôùí åðéëïãþí ôçò ãñáììÞò åíôïëþí êáé êÜðïéåò ðåñéãñáöÝò ôçò ìéáò ãñáììÞò ãéá ôï ôé êÜíïõí. |
Ôï åêôåëÝóéìï ôçò PHP ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá ôñÝîïõí script ôçò PHP áðüëõôá áíåîÜñçôá áðü ôïí web server. Áí åßóôå óå Ýíá Unix óýóôçìá, èá ðñÝðåé íá ðñïóèÝóåôå ìéá åéäéêÞ ðñþôç ãñáììÞ óôï PHP script óáò, êáé íá ôï êÜíåôå åêôåëÝóéìï, þóôå ôï óýóôçìá íá îÝñåé, ðïéü ðñüãñáììá èá ðñÝðåé íá ôñÝîåé ôï script. Óå Ýíá Windows óýóôçìá ìðïñåßôå íá óõó÷åôßóåôå ôï php.exe ìå ôçí double click åðéëïãÞ ôùí .php áñ÷åßùí, Þ íá êÜíåôå Ýíá batch áñ÷åßï íá ôñÝ÷åé ôï script ìÝóù ôçò PHP. Ç ðñþôç ãñáììÞ ðïõ ðñïóôßèåôáé óôï script ãéá íá äïõëåýåé óôï Unix äåí èá âëÜøåé óôá Windows, Ýôóé ìðïñåßôå íá ãñÜøåôå cross platform ðñïãñÜììáôá ìå áõôü ôïí ôñüðï. ¸íá áðëü ðáñÜäåéãìá ãñáöÞò åíüò ðñïãñÜììáôïò PHP ôçò ãñáììÞò åíôïëþí ìðïñåß íá âñåèåß ðáñáêÜôù.
ÐáñÜäåéãìá 23-1. ¸íá Script ðïõ ðñïïñßæåôáé íá ôñÝîåé áðü ôçí ãñáììÞ åíôïëþí (script.php)
|
Óôï ðáñáðÜíù script, ÷ñçóéìïðïéÞóáìå ôçí åéäéêÞ ðñþôç ãñáììÞ ãéá íá äåßîïõìå ðùò áõôü ôï áñ÷åßï èá ðñÝðåé íá åêôåëåóôåß áðü ôçí PHP. Äïõëåýïõìå ìå ìéá CLI Ýêäïóç åäþ, Ýôóé äåí èá õðÜñ÷ïõí åêôõðþóåéò áðü HTTP headers. ÕðÜñ÷ïõí äýï ìåôáâëçôÝò ðïõ ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå üôáí ãñÜöåôå åöáñìïãÝò ãñáììÞò åíôïëþí ìå ôçí PHP: Ïé $argc êáé $argv. Ç ðñþôç áðïôåëåß ôïí áñéèìü ôùí argument óõí Ýíá (ôï üíïìá ôïõ script ðïõ åêôåëåßôáé). Ç äåýôåñç åßíáé Ýíá array ôï ïðïßï ðåñéÝ÷åé ôá arguments, áñ÷ßæïíôáò ìå ôï üíïìá ôïõ script óáí ôïí áñéèìü ìçäÝí ($argv[0]).
Óôï ðáñáðÜíù ðñüãñáììá åëÝãîáìå áí õðÜñ÷ïõí ëéãüôåñá Þ ðåñéóóüôåñá áðü Ýíá arguments. Åðßóçò áí ôï argument Þôáí --help, -help, -h Þ -?, åêôõðþóáìå Ýíá ìÞíõìá âïÞèåéáò, åêôõðþíïíôáò ôï üíïìá ôïõ script äõíáìéêÜ. Áí ëáìâÜíáìå êÜðïéá Üëëá argument ôá åêôõðþíáìå êáé áõôÜ.
Áí èÝëáôå íá åêôåëÝóåôå ôï ðáñáðÜíù script óôï Unix, ÷ñåéÜæåôáé íá ôï êÜíåôå åêôåëÝóéìï êáé áðëÜ íá ôï êáëÝóåôå ìå ôï script.php echothis Þ script.php -h. Óôá Windows, ìðïñåßôå íá äçìéïõñãÞóåôå Ýíá batch áñ÷åßï ãéá áõôü ôï óêïðü:
ÕðïèÝôïíôáò ðùò ïíïìÜóáôå ôï ðáñáðÜíù ðñüãñáììá script.php, êáé Ý÷åôå ôï CLI php.exe óáò óôï c:\php\cli\php.exe áõôü ôï batch áñ÷åßï èá åêôåëåóôåß ãéá óáò ìå ôéò åðéðëÝïí åðéëïãÝò: script.bat echothis Þ script.bat -h.
Äåßôå åðßóçò ôï documentation (ôåêìçñßùóç) ôçò Readline åðÝêôáóçò ãéá ðåñéóóüôåñåò óõíáñôÞóåéò ðïõ ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ãéá íá âåëôéþóåôå ôéò åöáñìïãÝò ãñáììÞò åíôïëþí óáò óôçí PHP.
These functions are only available when running PHP as an Apache module.
Óçìåßùóç: PATH_TRANSLATED server variable is no longer set implicitly under Apache 2 SAPI in contrast to the situation in Apache 1, where it is set to the same value as the SCRIPT_FILENAME server variable when it is not populated by Apache. This change was made to comply with the CGI specification. Please refer to bug #23610 for further information.
The behaviour of the Apache PHP module is affected by settings in php.ini. Configuration settings from php.ini may be overridden by php_flag settings in the server configuration file or local .htaccess files.
Ðßíáêáò 1. Apache configuration options
Name | Default | Changeable | Function |
---|---|---|---|
engine | On | PHP_INI_ALL | turns PHP parsing on or off |
child_terminate | Off | PHP_INI_ALL | specify whether PHP scripts may request child process termination on end of request, see also apache_child_terminate() |
last_modified | Off | PHP_INI_ALL | send PHP scripts modification date as Last-Modified: header for this request |
xbithack | Off | PHP_INI_ALL | parse files with executable bit set as PHP regardless of their file ending |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
This directive is really only useful in the Apache module version of PHP. It is used by sites that would like to turn PHP parsing on and off on a per-directory or per-virtual server basis. By putting engine off in the appropriate places in the httpd.conf file, PHP can be enabled or disabled.
apache_child_terminate() will register the Apache process executing the current PHP request for termination once execution of PHP code it is completed. It may be used to terminate a process after a script with high memory consumption has been run as memory will usually only be freed internally but not given back to the operating system.
Óçìåßùóç: The availability of this feature is controlled by the php.ini directive child_terminate, which is set to off by default.
This feature is also not available on multithreaded versions of apache like the win32 version.
See also exit().
This function returns an array with the loaded Apache modules.
apache_get_version() returns the version of Apache as string, or FALSE on failure.
See also phpinfo().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
apache_lookup_uri -- Perform a partial request for the specified URI and return all info about itThis 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 |
ÐáñÜäåéãìá 1. apache_lookup_uri() example
The above example will output something similar with:
|
Óçìåßùóç: apache_lookup_uri() only works when PHP is installed as an Apache module.
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.
apache_request_headers() returns an associative array of all the HTTP headers in the current request. This is only supported when PHP runs as an Apache module.
Óçìåßùóç: Prior to PHP 4.3.0, apache_request_headers() was called getallheaders(). After PHP 4.3.0, getallheaders() is an alias for apache_request_headers().
Óçìåßùóç: You can also get at the value of the common CGI variables by reading them from the environment, which works whether or not you are using PHP as an Apache module. Use phpinfo() to see a list of all of the available environment variables.
Óçìåßùóç: From PHP 4.3.3 on you can use this function with the NSAPI server module in Netscape/iPlanet/SunONE webservers, too.
See also apache_response_headers().
Returns an array of all Apache response headers. This functionality is only available in PHP 4.3.0 and greater.
Óçìåßùóç: From PHP 4.3.3 on you can use this function with the NSAPI server module in Netscape/iPlanet/SunONE webservers, too.
See also apache_request_headers(), and headers_sent().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ascii2ebcdic() is an Apache-specific function which is available only on EBCDIC based operating systems (OS/390, BS2000). It translates the ASCII encoded string ascii_str to its equivalent EBCDIC representation (binary safe), and returns the result.
See also the reverse function ebcdic2ascii()
ebcdic2ascii() is an Apache-specific function which is available only on EBCDIC based operating systems (OS/390, BS2000). It translates the EBCDIC encoded string ebcdic_str to its equivalent ASCII representation (binary safe), and returns the result.
See also the reverse function ascii2ebcdic()
getallheaders() is an alias for apache_request_headers(). It will return an associative array of all the HTTP headers in the current request. Please read the apache_request_headers() documentation for more information on how this function works.
Óçìåßùóç: In PHP 4.3.0, getallheaders() became an alias for apache_request_headers(). Essentially, it was renamed. This is because this function only works when PHP is compiled as an Apache Module.
Óçìåßùóç: From PHP 4.3.3 on you can use this function with the NSAPI server module in Netscape/iPlanet/SunONE webservers, too.
See also apache_request_headers().
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.
To run the sub-request, all buffers are terminated and flushed to the browser, pending headers are sent too.
As of PHP 4.0.6, you can use virtual() on PHP files. However, it is typically better to use include() or require() if you need to include another PHP file.
Óçìåßùóç: From PHP 4.3.3 on you can use this function with the NSAPI server module in Netscape/iPlanet/SunONE webservers, too.
These functions allow you to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables.
Simple and multi-dimensional arrays are supported, and may be either user created or created by another function. There are specific database handling functions for populating arrays from database queries, and several functions return arrays.
Please see the Arrays section of the manual for a detailed explanation of how arrays are implemented and used in PHP. See also Array operators for other ways how to manipulate the arrays.
Ïé ðáñáêÜôù óôáèåñÝò åßíáé ðÜíôá äéáèÝóéìåò ùò ìÝñïò ôïõ ðõñÞíá ôçò PHP.
CASE_LOWER is used with array_change_key_case() and is used to convert array keys to lower case. This is also the default case for array_change_key_case().
CASE_UPPER is used with array_change_key_case() and is used to convert array keys to upper case.
Sorting order flags:
SORT_ASC is used with array_multisort() to sort in ascending order.
SORT_DESC is used with array_multisort() to sort in descending order.
Sorting type flags: used by various sort functions
(PHP 4 >= 4.2.0, PHP 5)
array_change_key_case -- Returns an array with all string keys lowercased or uppercasedarray_change_key_case() changes the keys in the input array to be all lowercase or uppercase. The change depends on the last optional case parameter. You can pass two constants there, CASE_UPPER and CASE_LOWER. The default is CASE_LOWER. The function will leave number indices as is.
If an array has indices that will be the same once run through this function (e.g. "keY" and "kEY"), the value that is later in the array will override other indices.
array_chunk() splits the array into several arrays with size values in them. You may also have an array with less values at the end. You get the arrays as members of a multidimensional array indexed with numbers starting from zero.
By setting the optional preserve_keys parameter to TRUE, you can force PHP to preserve the original keys from the input array. If you specify FALSE new number indices will be used in each resulting array with indices starting from zero. The default is FALSE.
ÐáñÜäåéãìá 1. array_chunk() example
The printout of the above program will be:
|
Returns an array by using the values from the keys array as keys and the values from the values array as the corresponding values.
Returns FALSE if the number of elements for each array isn't equal or if the arrays are empty.
See also array_merge(), array_walk(), and array_values().
array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.
See also count(), array_unique(), array_values(), and count_chars().
(PHP 4 >= 4.3.0, PHP 5)
array_diff_assoc -- Computes the difference of arrays with additional index checkarray_diff_assoc() returns an array containing all the values from array1 that are not present in any of the other arguments. Note that the keys are used in the comparison unlike array_diff().
In our example above you see the "a" => "green" pair is present in both arrays and thus it is not in the ouput from the function. Unlike this, the pair 0 => "red" is in the ouput because in the second argument "red" has key which is 1.
Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same.
Óçìåßùóç: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_diff_assoc($array1[0], $array2[0]);.
See also array_diff(), array_intersect(), and array_intersect_assoc().
(PHP 5)
array_diff_uassoc -- Computes the difference of arrays with additional index check which is performed by a user supplied callback functionarray_diff_uassoc() returns an array containing all the values from array1 that are not present in any of the other arguments. Note that the keys are used in the comparison unlike array_diff(). This comparison is done by a user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. This is unlike array_diff_assoc() where an internal function for comparing the indices is used.
ÐáñÜäåéãìá 1. array_diff_uassoc() example
The result is:
|
In our example above you see the "a" => "green" pair is present in both arrays and thus it is not in the ouput from the function. Unlike this, the pair 0 => "red" is in the ouput because in the second argument "red" has key which is 1.
The equality of 2 indices is checked by the user supplied callback function.
Óçìåßùóç: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_diff_uassoc($array1[0], $array2[0], "key_compare_func");.
See also array_diff(), array_diff_assoc(), array_udiff(), array_udiff_assoc(), array_udiff_uassoc(), array_intersect(), array_intersect_assoc(), array_uintersect(), array_uintersect_assoc() and array_uintersect_uassoc().
array_diff() returns an array containing all the values of array1 that are not present in any of the other arguments. Note that keys are preserved.
ÐáñÜäåéãìá 1. array_diff() example
Multiple occurrences in $array1 are all treated the same way. This will output :
|
Óçìåßùóç: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.
Óçìåßùóç: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_diff($array1[0], $array2[0]);.
Ðñïåéäïðïßçóç |
This was broken in PHP 4.0.4! |
See also array_diff_assoc(), array_intersect(), and array_intersect_assoc().
array_fill() fills an array with num entries of the value of the value parameter, keys starting at the start_index parameter. Note that num must be a number greater than zero, or PHP will throw a warning.
See also str_repeat() and range().
array_filter() iterates over each value in the input array passing them to the callback function. If the callback function returns true, the current value from input is returned into the result array. Array keys are preserved.
ÐáñÜäåéãìá 1. array_filter() example
The printout of the program above will be:
|
Users may not change the array itself from the callback function. e.g. Add/delete an element, unset the array that array_filter() is applied to. If the array is changed, the behavior of this function is undefined.
If the callback function is not supplied, array_filter() will remove all the entries of input that are equal to FALSE. See converting to boolean for more information.
See also array_map(), array_reduce(), and array_walk().
array_flip() returns an array in flip order, i.e. keys from trans become values and values from trans become keys.
Note that the values of trans need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be flipped.
If a value has several occurrences, the latest key will be used as its values, and all others will be lost.
array_flip() returns FALSE if it fails.
See also array_values(), array_keys(), and array_reverse().
(PHP 4 >= 4.3.0, PHP 5)
array_intersect_assoc -- Computes the intersection of arrays with additional index checkarray_intersect_assoc() returns an array containing all the values of array1 that are present in all the arguments. Note that the keys are used in the comparison unlike in array_intersect().
In our example you see that only the pair "a" => "green" is present in both arrays and thus is returned. The value "red" is not returned because in $array1 its key is 0 while the key of "red" in $array2 is 1.
The two values from the key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In otherwords a strict type check is executed so the string representation must be the same.
See also array_intersect(), array_diff() and array_diff_assoc().
array_intersect() returns an array containing all the values of array1 that are present in all the arguments. Note that keys are preserved.
Óçìåßùóç: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.
See also array_intersect_assoc(), array_diff(), and array_diff_assoc().
array_key_exists() returns TRUE if the given key is set in the array. key can be any value possible for an array index.
Óçìåßùóç: The name of this function is key_exists() in PHP 4.0.6.
See also isset(), array_keys(), and in_array().
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.
ÐáñÜäåéãìá 1. array_keys() example
The printout of the program above will be:
|
See also array_values() and array_key_exists().
array_map() returns an array containing all the elements of arr1 after applying the callback function to each one. The number of parameters that the callback function accepts should match the number of arrays passed to the array_map()
ÐáñÜäåéãìá 2. array_map() - using more arrays
This results:
|
Usually when using two or more arrays, they should be of equal length because the callback function is applied in parallel to the corresponding elements. If the arrays are of unequal length, the shortest one will be extended with empty elements.
An interesting use of this function is to construct an array of arrays, which can be easily performed by using NULL as the name of the callback function
The printout of the program above will be:
Array ( [0] => Array ( [0] => 1 [1] => one [2] => uno ) [1] => Array ( [0] => 2 [1] => two [2] => dos ) [2] => Array ( [0] => 3 [1] => three [2] => tres ) [3] => Array ( [0] => 4 [1] => four [2] => cuatro ) [4] => Array ( [0] => 5 [1] => five [2] => cinco ) ) |
See also array_filter(), array_reduce(), and array_walk().
array_merge_recursive() 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 have the same string keys, then the values for these keys are merged together into an array, and this is done recursively, so that if one of the values is an array itself, the function will merge it with a corresponding entry in another array too. If, however, the arrays have the same numeric key, the later value will not overwrite the original value, but will be appended.
ÐáñÜäåéãìá 1. array_merge_recursive() example
The $result will be:
|
See also array_merge().
array_merge() merges the elements of one 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 have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.
If only one array is given and the array is numerically indexed, the keys get reindexed in a continuous way. For associative arrays, duplicate entries will be merged into the last one. See example three for details.
ÐáñÜäåéãìá 1. array_merge() example
The $result is:
|
ÐáñÜäåéãìá 2. Simple array_merge() example
Don't forget that numeric keys will be renumbered!
If you want to completely preserve the arrays and just want to append them to each other, use the + operator:
The numeric key will be preserved and thus the association remains.
|
ÐáñÜäåéãìá 3. array_merge() example
The output is:
|
Óçìåßùóç: Shared keys will be overwritten on a first-come first-served basis.
See also array_merge_recursive(), array_combine() and array operators.
array_multisort() can be used to sort several arrays at once or a multi-dimensional array according by one of more dimensions. Associative (string) keys are maintained while numerical keys are re-indexed.
The input arrays are treated as columns of a table to be sorted by rows - this resembles the functionality of SQL ORDER BY clause. The first array is the primary one to sort by. The rows (values) in that array that compare the same are sorted by the next input array, and so on.
The argument structure of this function is a bit unusual, but flexible. The very first argument has to be an array. Subsequently, each argument can be either an array or a sorting flag from the following lists.
Sorting order flags:
SORT_ASC - sort in ascending order
SORT_DESC - sort in descending order
Sorting type flags:
SORT_REGULAR - compare items normally
SORT_NUMERIC - compare items numerically
SORT_STRING - compare items as strings
No two sorting flags of the same type can be specified after each array. The sorting flags specified after an array argument apply only to that array - they are reset to default SORT_ASC and SORT_REGULAR before each new array argument.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
In this example, after sorting, the first array will contain 10, "a", 100, 100. The second array will contain 1, 1, "2", 3. The entries in the second array corresponding to the identical entries in the first array (100 and 100) were sorted as well.
In this example, after sorting, the first array will contain 10, 100, 100, "a" (it was sorted as strings in ascending order), and the second one will contain 1, 3, "2", 1 (sorted as numbers, in descending order).
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.
See also array_fill() and range().
array_pop() pops and returns the last value of the array, shortening the array by one element. If array is empty (or is not an array), NULL will be returned.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
See also array_push(), array_shift(), and array_unshift().
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:
<?php $array[] = $var; ?> |
Returns the new number of elements in the array.
Óçìåßùóç: If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.
See also array_pop(), array_shift(), and array_unshift().
array_rand() is rather useful when you want to pick one or more random entries out of an array. It takes an input array and an optional argument num_req which specifies how many entries you want to pick - if not specified, it defaults to 1.
If you are picking only one entry, array_rand() returns the key for a random entry. Otherwise, it returns an array of keys for the random entries. This is done so that you can pick random keys as well as values out of the array.
Óçìåßùóç: Áðü ôçí PHP 4.2.0, äåí åßíáé áíÜãêç íá êÜíåôå seed ôçí ãåííÞôñéá ôõ÷áßùí áñéèìþí ìå ôçí srand() Þ ôçí mt_srand() áöïý ôþñá áõôü ãßíåôáé áõôüìáôá.
See also shuffle().
(PHP 4 >= 4.0.5, PHP 5)
array_reduce -- Iteratively reduce the array to a single value using a callback functionarray_reduce() applies iteratively the function function to the elements of the array input, so as to reduce the array to a single value. If the optional initial is available, it will be used at the beginning of the process, or as a final result in case the array is empty.
This will result in $b containing 15, $c containing 1200 (= 1*2*3*4*5*10), and $d containing 1.
See also array_filter(), array_map(), array_unique(), and array_count_values().
array_reverse() takes input array and returns a new array with the order of the elements reversed, preserving the keys if preserve_keys is TRUE.
ÐáñÜäåéãìá 1. array_reverse() example
This makes both $result and $result_keyed have the same elements, but note the difference between the keys. The printout of $result and $result_keyed will be:
|
Óçìåßùóç: The second parameter was added in PHP 4.0.3.
See also array_flip().
(PHP 4 >= 4.0.5, PHP 5)
array_search -- Searches the array for a given value and returns the corresponding key if successfulSearches haystack for needle and returns the key if it is found in the array, FALSE otherwise.
Óçìåßùóç: If needle is a string, the comparison is done in a case-sensitive manner.
Óçìåßùóç: Prior to PHP 4.2.0, array_search() returns NULL on failure instead of FALSE.
If the optional third parameter strict is set to TRUE then the array_search() will also check the types of the needle in the haystack.
If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys() with the optional search_value parameter instead.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
See also array_keys(), array_values(), array_key_exists(), and in_array().
array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array keys will be modified to start counting from zero while literal keys won't be touched. If array is empty (or is not an array), NULL will be returned.
See also array_unshift(), array_push(), and array_pop().
array_slice() returns the sequence of elements from the array array as 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.
Note that array_slice() will ignore array keys, and will calculate offsets and lengths based on the actual positions of elements within the array.
ÐáñÜäåéãìá 1. array_slice() examples
|
See also array_splice() and unset().
array_splice() removes the elements designated by offset and length from the input array, and replaces them with the elements of the replacement array, if supplied. It returns an array containing the extracted elements.
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. array_splice() equivalents
array_push($input, $x, $y) | array_splice($input, count($input), 0, array($x, $y)) |
array_pop($input) | array_splice($input, -1) |
array_shift($input) | array_splice($input, -1) |
array_unshift($input, $x, $y) | array_splice($input, 0, 0, array($x, $y)) |
$a[$x] = $y | array_splice($input, $x, 1, $y) |
Returns the array consisting of removed elements.
ÐáñÜäåéãìá 1. array_splice() examples
|
See also array_slice(), unset(), and array_merge().
array_sum() returns the sum of values in an array as an integer or float.
Óçìåßùóç: PHP versions prior to 4.2.1 modified the passed array itself and converted strings to numbers (which most of the time converted them to zero, depending on their value).
(PHP 5)
array_udiff_assoc -- Computes the difference of arrays with additional index check. The data is compared by using a callback function.array_udiff_assoc() returns an array containing all the values from array1 that are not present in any of the other arguments. Note that the keys are used in the comparison unlike array_diff() and array_udiff(). The comparison of arrays' data is performed by using an user-supplied callback. In this aspect the behaviour is opposite to the behaviour of array_diff_assoc() which uses internal function for comparison.
ÐáñÜäåéãìá 1. array_udiff_assoc() example
The result is:
|
In our example above you see the "1" => new cr(4) pair is present in both arrays and thus it is not in the ouput from the function.
For comparison is used the user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
Óçìåßùóç: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_udiff_assoc($array1[0], $array2[0], "some_comparison_func");.
See also array_diff(), array_diff_assoc(), array_diff_uassoc(), array_udiff(), array_udiff_uassoc(), array_intersect(), array_intersect_assoc(), array_uintersect(), array_uintersect_assoc() and array_uintersect_uassoc().
(PHP 5)
array_udiff_uassoc -- Computes the difference of arrays with additional index check. The data is compared by using a callback function. The index check is done by a callback function alsoarray_udiff_uassoc() returns an array containing all the values from array1 that are not present in any of the other arguments. Note that the keys are used in the comparison unlike array_diff() and array_udiff(). The comparison of arrays' data is performed by using an user-supplied callback : data_compare_func. In this aspect the behaviour is opposite to the behaviour of array_diff_assoc() which uses internal function for comparison. The comparison of keys (indices) is done also by the callback function key_compare_func. This behaviour is unlike what array_udiff_assoc() does, since the latter compares the indices by using an internal function.
ÐáñÜäåéãìá 1. array_udiff_uassoc() example
The result is:
|
In our example above you see the "1" => new cr(4) pair is present in both arrays and thus it is not in the ouput from the function. Keep in mind that you have to supply 2 callback functions.
For comparison is used the user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
Óçìåßùóç: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_udiff_uassoc($array1[0], $array2[0], "data_compare_func", "key_compare_func");.
See also array_diff(), array_diff_assoc(), array_diff_uassoc(), array_udiff(), array_udiff_assoc(), array_intersect(), array_intersect_assoc(), array_uintersect(), array_uintersect_assoc() and array_uintersect_uassoc().
(PHP 5)
array_udiff -- Computes the difference of arrays by using a callback function for data comparison.array_udiff() returns an array containing all the values of array1 that are not present in any of the other arguments. Note that keys are preserved. For the comparison of the data data_compare_func is used. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. This is unlike array_diff() which uses an internal function for comparing the data.
ÐáñÜäåéãìá 1. array_udiff() example
The result is:
|
Óçìåßùóç: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.
Óçìåßùóç: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_udiff($array1[0], $array2[0], "data_compare_func");.
See also array_diff(), array_diff_assoc(), array_diff_uassoc(), array_udiff_assoc(), array_udiff_uassoc(), array_intersect(), array_intersect_assoc(), array_uintersect(), array_uintersect_assoc() and array_uintersect_uassoc().
array_unique() takes input array and returns a new array without duplicate values.
Note that keys are preserved. array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.
Óçìåßùóç: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.
The first element will be used.
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. All numerical array keys will be modified to start counting from zero while literal keys won't be touched.
Returns the new number of elements in the array.
See also array_shift(), array_push(), and array_pop().
array_values() returns all the values from the input array and indexes numerically the array.
See also array_keys().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Applies the user-defined function function to each element of the array array. Typically, function takes on two parameters. The array parameter's value being the first, and the key/index second. If the optional userdata parameter is supplied, it will be passed as the third parameter to the callback function.
If function function requires more parameters than given to it, an error of level E_WARNING will be generated each time array_walk() calls function. These warnings may be suppressed by prepending the PHP error operator @ to the array_walk() call, or by using error_reporting().
Óçìåßùóç: If function needs to be working with the actual values of the array, specify the first parameter of function as a reference. Then, any changes made to those elements will be made in the original array itself.
Óçìåßùóç: Passing the key and userdata to function was added in 4.0.0
array_walk() is not affected by the internal array pointer of array. array_walk() will walk through the entire array regardless of pointer position. To reset the pointer, use reset(). In PHP 3, array_walk() resets the pointer.
Users may not change the array itself from the callback function. e.g. Add/delete elements, unset elements, etc. If the array that array_walk() is applied to is changed, the behavior of this function is undefined, and unpredictable.
ÐáñÜäåéãìá 1. array_walk() example
The printout of the program above will be:
|
See also create_function(), list(), foreach, each(), and call_user_func_array().
Returns an array of the parameters. The parameters can be given an index with the => operator. Read the section on the array type for more information on what an array is.
Óçìåßùóç: array() is a language construct used to represent literal arrays, and not a regular function.
Syntax "index => values", separated by commas, define index and values. index may be of type string or numeric. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.
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.
Note that index '3' is defined twice, and keep its final value of 13. Index 4 is defined after index 8, and next generated index (value 19) is 9, since biggest index was 8.
This example creates a 1-based array.
See also array_pad(), list(), foreach, and range().
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.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The fruits have been sorted in reverse alphabetical order, and the index associated with each element has been maintained.
You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort().
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.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The fruits have been sorted in alphabetical order, and the index associated with each element has been maintained.
You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort().
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.
Any strings that are not set will simply be skipped.
See also extract().
Returns the number of elements in var, which is typically an array (since anything else will have one element).
If var is not an array, 1 will be returned (exception: count(NULL) equals 0).
Óçìåßùóç: The optional mode parameter is available as of PHP 4.2.0.
If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array. The default value for mode is 0.
Ðñïóï÷Þ |
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. |
Please see the Arrays section of the manual for a detailed explanation of how arrays are implemented and used in PHP.
See also is_array(), isset(), and strlen().
Every array has an internal pointer to its "current" element, which is initialized to the first element inserted into the array.
The current() function simply returns the value of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list, current() returns FALSE.
Ðñïåéäïðïßçóç |
If the array contains empty elements (0 or "", the empty string) then this function will return FALSE for these elements as well. This makes it impossible to determine if you are really at the end of the list in such an array using current(). To properly traverse an array that may contain empty elements, use the each() function. |
ÐáñÜäåéãìá 1. Example use of current() and friends
|
(PHP 3, PHP 4 , PHP 5)
each -- Return the current key and value pair from an array and advance the array cursorReturns the current key and value pair from the array array and advances the array cursor. This pair is returned in a four-element array, with the keys 0, 1, key, and value. Elements 0 and key contain the key name of the array element, and 1 and value contain the data.
If the internal pointer for the array points past the end of the array contents, each() returns FALSE.
<?php $foo = array("Robert" => "Bob", "Seppo" => "Sepi"); $bar = each($foo); print_r($bar); ?> |
$bar now contains the following key/value pairs:
Array ( [1] => Bob [value] => Bob [0] => Robert [key] => Robert ) |
each() is typically used in conjunction with list() to traverse an array, here's an example:
After each() has executed, the array cursor will be left on the next element of the array, or past the last element if it hits the end of the array. You have to use reset() if you want to traverse the array again using each.
Ðñïóï÷Þ |
Because assigning an array to another variable resets the original arrays pointer, our example above would cause an endless loop had we assigned $fruit to another variable inside the loop. |
See also key(), list(), current(), reset(), next(), prev(), and foreach.
end() advances array's internal pointer to the last element, and returns its value.
(PHP 3>= 3.0.7, PHP 4 , PHP 5)
extract -- Import variables into the current symbol table from an arrayThis function is used to import variables from an array into the current symbol table. It takes an 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.
Óçìåßùóç: Beginning with version 4.0.5, this function returns the number of variables extracted.
Óçìåßùóç: EXTR_IF_EXISTS and EXTR_PREFIX_IF_EXISTS were introduced in version 4.2.0.
Óçìåßùóç: EXTR_REFS was introduced in version 4.3.0.
extract() checks each key to see whether it has a valid variable name. It also checks for collisions with existing variables in the symbol table. The way invalid/numeric keys and collisions are treated is determined by the extract_type. It can be one of the following values:
If there is a collision, overwrite the existing variable.
If there is a collision, don't overwrite the existing variable.
If there is a collision, prefix the variable name with prefix.
Prefix all variable names with prefix. Beginning with PHP 4.0.5, this includes numeric variables as well.
Only prefix invalid/numeric variable names with prefix. This flag was added in PHP 4.0.5.
Only overwrite the variable if it already exists in the current symbol table, otherwise do nothing. This is useful for defining a list of valid variables and then extracting only those variables you have defined out of $_REQUEST, for example. This flag was added in PHP 4.2.0.
Only create prefixed variable names if the non-prefixed version of the same variable exists in the current symbol table. This flag was added in PHP 4.2.0.
Extracts variables as references. This effectively means that the values of the imported variables are still referencing the values of the var_array parameter. You can use this flag on its own or combine it with any other flag by OR'ing the extract_type. This flag was added in PHP 4.3.0.
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, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS. If the prefixed result is not a valid variable name, it is not imported into the symbol table.
extract() returns the number of variables successfully imported into the symbol table.
Ðñïåéäïðïßçóç |
Do not use extract() on untrusted data, like user-input ($_GET, ...). If you do, for example, if you want to run old code that relies on register_globals temporarily, make sure you use one of the non-overwriting extract_type values such as EXTR_SKIP and be aware that you should extract $_SERVER, $_SESSION, $_COOKIE, $_POST and $_GET in that order. |
A possible use for extract() is to import into the symbol table variables contained in an associative array returned by wddx_deserialize().
ÐáñÜäåéãìá 1. extract() example
The above example will produce:
|
The $size wasn't overwritten, because 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 caused $size to have value "medium", and EXTR_PREFIX_ALL would result in new variables being named $wddx_color, $wddx_size, and $wddx_shape.
You must use an associative array, a numerically indexed array will not produce results unless you use EXTR_PREFIX_ALL or EXTR_PREFIX_INVALID.
See also compact().
Searches haystack for needle and returns TRUE if it is found in the array, FALSE otherwise.
If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
Óçìåßùóç: If needle is a string, the comparison is done in a case-sensitive manner.
Óçìåßùóç: In PHP versions before 4.2.0 needle was not allowed to be an array.
ÐáñÜäåéãìá 3. in_array() with an array as needle
Outputs:
|
See also array_search(), array_key_exists(), and isset().
key() returns the index element of the current array position.
ÐáñÜäåéãìá 1. key() example
|
Sorts an array by key in reverse order, maintaining key to data correlations. This is useful mainly for associative arrays.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort().
See also asort(), arsort(), ksort(), sort(), natsort(), and rsort().
Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort().
See also asort(), arsort(), krsort(), uksort(), sort(), natsort(), and rsort().
Óçìåßùóç: The second parameter was added in PHP 4.
Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.
Óçìåßùóç: list() only works on numerical arrays and assumes the numerical indices start at 0.
ÐáñÜäåéãìá 1. list() examples
|
ÐáñÜäåéãìá 2. An example use of list()
|
Ðñïåéäïðïßçóç |
list() assigns the values starting with the right-most parameter. If you are using plain variables, you don't have to worry about this. But if you are using arrays with indices you usually expect the order of the indices in the array the same you wrote in the list() from left to right; which it isn't. It's assigned in the reverse order. |
ÐáñÜäåéãìá 3. Using list() with array indices
Gives the following output (note the order of the elements compared in which order they were written in the list() syntax):
|
This function implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value associations. This is described as a "natural ordering".
natcasesort() is a case insensitive version of natsort().
ÐáñÜäåéãìá 1. natcasesort() example
The code above will generate the following output:
For more information see: Martin Pool's Natural Order String Comparison page. |
See also sort(), natsort(), strnatcmp(), and strnatcasecmp().
This function implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value associations. This is described as a "natural ordering". An example of the difference between this algorithm and the regular computer string sorting algorithms (used in sort()) can be seen below:
ÐáñÜäåéãìá 1. natsort() example
The code above will generate the following output:
For more information see: Martin Pool's Natural Order String Comparison page. |
See also natcasesort(), strnatcmp(), and strnatcasecmp().
Returns the array value in the next place that's pointed to 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 value. That means it returns the next array value 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.
Ðñïåéäïðïßçóç |
If the array contains empty elements, or elements that have a key value of 0 then this function will return FALSE for these elements as well. To properly traverse an array which may contain empty elements or elements with key values of 0 see the each() function. |
ÐáñÜäåéãìá 1. Example use of next() and friends
|
Returns the array value in the previous place that's pointed to by the internal array pointer, or FALSE if there are no more elements.
Ðñïåéäïðïßçóç |
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.
ÐáñÜäåéãìá 1. Example use of prev() and friends
|
range() returns an array of elements from low to high, inclusive. If low > high, the sequence will be from high to low.
New parameter: The optional step parameter was added in 5.0.0.
If a step value is given, it will be used as the increment between elements in the sequence. step should be given as a positive number. If not specified, step will default to 1.
ÐáñÜäåéãìá 1. range() examples
|
Óçìåßùóç: Prior to PHP 4.1.0, range() only generated incrementing integer arrays. Support for character sequences and decrementing arrays was added in 4.1.0. Character sequence values are limited to a length of one. If a length greater than one is entered, only the first character is used.
Ðñïóï÷Þ |
In PHP versions 4.1.0 through 4.3.2, range() sees numeric strings as strings and not integers. Instead, they will be used for character sequences. For example, "4242" is treated as "4". |
See also shuffle(), array_fill(), and foreach.
reset() rewinds array's internal pointer to the first element and returns the value of the first array element.
ÐáñÜäåéãìá 1. reset() example
|
This function sorts an array in reverse order (highest to lowest).
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The fruits have been sorted in reverse alphabetical order.
You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort().
This function shuffles (randomizes the order of the elements in) an array.
Óçìåßùóç: Áðü ôçí PHP 4.2.0, äåí åßíáé áíÜãêç íá êÜíåôå seed ôçí ãåííÞôñéá ôõ÷áßùí áñéèìþí ìå ôçí srand() Þ ôçí mt_srand() áöïý ôþñá áõôü ãßíåôáé áõôüìáôá.
See also arsort(), asort(), ksort(), rsort(), sort(), and usort().
This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.
Óçìåßùóç: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. sort() example
This example would display:
|
The fruits have been sorted in alphabetical order.
The optional second parameter sort_flags may be used to modify the sorting behavior using these values:
Sorting type flags:
SORT_REGULAR - compare items normally
SORT_NUMERIC - compare items numerically
SORT_STRING - compare items as strings
Óçìåßùóç: The second parameter was added in PHP 4.
See also arsort(), asort(), ksort(), natsort(), natcasesort(), rsort(), usort(), array_multisort(), and uksort().
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
uasort -- Sort an array with a user-defined comparison function and maintain index associationThis 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.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also usort(), uksort(), sort(), asort(), arsort(), ksort(), and rsort().
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
uksort -- Sort an array by keys using a user-defined comparison functionuksort() 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.
Function cmp_function should accept two parameters which will be filled by pairs of array keys. 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.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. uksort() example
This example would display:
|
See also usort(), uasort(), sort(), asort(), arsort(), ksort(), natsort(), and rsort().
(PHP 3>= 3.0.3, PHP 4 , PHP 5)
usort -- Sort an array by values using a user-defined comparison functionThis 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. Up to PHP 4.0.6 the user defined functions would keep the original order for those elements, but with the new sort algorithm introduced with 4.1.0 this is no longer the case as there is no solution to do so in an efficient way.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: Obviously in this trivial case the sort() function would be more appropriate.
ÐáñÜäåéãìá 2. usort() example using multi-dimensional array
When sorting a multi-dimensional array, $a and $b contain references to the first index of the array. This example would display:
|
ÐáñÜäåéãìá 3. usort() example using a member function of an object
This example would display:
|
See also uasort(), uksort(), sort(), asort(), arsort(),ksort(), natsort(), and rsort().
The aspell() functions allows you to check the spelling on a word and offer suggestions.
Óçìåßùóç: This extension has been removed from PHP and is no longer available as of PHP 4.3.0. If you want to use spell-checking capabilities in PHP, use pspell instead. It uses pspell library and works with newer versions of aspell.
aspell works only with very old (up to .27.* or so) versions of aspell library. Neither this module, nor those versions of aspell library are supported any longer. You need the aspell library, available from: http://aspell.sourceforge.net/.
(PHP 3>= 3.0.7, PHP 4 <= 4.2.3)
aspell_check_raw -- Check a word without changing its case or trying to trim it [deprecated]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.
aspell_check() checks the spelling of a word and returns TRUE if the spelling is correct, FALSE if not.
aspell_new() opens up a new dictionary and returns the dictionary link identifier for use in other aspell functions. Returns FALSE on error.
For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.
Since PHP 4.0.4, libbcmath is bundled with PHP. You don't need any external libraries for this extension.
In PHP 4, these functions are only available if PHP was configured with --enable-bcmath. In PHP 3, these functions are only available if PHP was NOT configured with --disable-bcmath.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
For further details and definition of the PHP_INI_* constants see ini_set().
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
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().
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 comparison. 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.
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().
Get the modulus of the left_operand using modulus.
See also bcdiv().
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().
Raise x to the power y. The optional scale can be used to set the number of digits after the decimal place in the result.
See also bcpowmod(), and bcsqrt().
Use the fast-exponentiation method to raise x to the power y with respect to the modulus modulus. The optional scale can be used to set the number of digits after the decimal place in the result.
The following two statements are functionally identical. The bcpowmod() version however, executes in less time and can accept larger parameters.
<?php $a = bcpowmod($x, $y, $mod); $b = bcmod(bcpow($x, $y), $mod); // $a and $b are equal to each other. ?> |
Óçìåßùóç: Because this method uses the modulus operation, non-natural numbers may give unexpected results. A natural number is any positive non-zero integer.
This function sets the default scale parameter for all subsequent bc math functions that do not explicitly specify a scale parameter. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
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().
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().
The bzip2 functions are used to transparently read and write bzip2 (.bz2) compressed files.
This module uses the functions of the bzip2 library by Julian Seward. This module requires bzip2/libbzip2 version >= 1.0.x.
Bzip2 support in PHP is not enabled by default. You will need to use the --with-bz2[=DIR] configuration option when compiling PHP to enable bzip2 support.
This extension defines one resource type: a file pointer identifying the bz2-file to work on.
This example opens a temporary file and writes a test string to it, then prints out the contents of the file.
ÐáñÜäåéãìá 1. Small bzip2 Example
|
Closes the bzip2 file referenced by the pointer bz.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The file pointer must be valid, and must point to a file successfully opened by bzopen().
See also bzopen().
bzcompress() compresses the source string and returns it as bzip2 encoded data.
The optional parameter blocksize specifies the blocksize used during compression and should be a number from 1 to 9 with 9 giving the best compression, but using more resources to do so. blocksize defaults to 4.
The optional parameter workfactor controls how the compression phase behaves when presented with worst case, highly repetitive, input data. The value can be between 0 and 250 with 0 being a special case and 30 being the default value. Regardless of the workfactor, the generated output is the same.
See also bzdecompress().
bzdecompress() decompresses the source string containing bzip2 encoded data and returns it. If the optional parameter small is TRUE, an alternative decompression algorithm will be used which uses less memory (the maximum memory requirement drops to around 2300K) but works at roughly half the speed. See the bzip2 documentation for more information about this feature.
See also bzcompress().
Returns the error number of any bzip2 error returned by the file pointer bz.
See also bzerror() and bzerrstr().
Returns the error number and error string, in an associative array, of any bzip2 error returned by the file pointer bz.
See also bzerrno() and bzerrstr().
Returns the error string of any bzip2 error returned by the file pointer bz.
Forces a write of all buffered bzip2 data for the file pointer bz.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
bzopen() opens a bzip2 (.bz2) file for reading or writing. filename is the name of the file to open. mode is similar to the fopen() function (`r' for read, `w' for write, etc.).
If the open fails, bzopen() returns FALSE, otherwise it returns a pointer to the newly opened file.
See also bzclose().
bzread() reads up to length bytes from the bzip2 file pointer referenced by bz. Reading stops when length (uncompressed) bytes have been read or EOF is reached, whichever comes first. If the optional parameter length is not specified, bzread() will read 1024 (uncompressed) bytes at a time.
bzwrite() writes the contents of the string data to the bzip2 file stream pointed to by bz. If the optional length argument is given, writing will stop after length (uncompressed) bytes have been written or the end of string is reached, whichever comes first.
Ç extension çìåñïëüãéï ðáñïõóéÜæåé ìßá óåéñÜ áðü óõíáñôÞóåéò ãéá ôçí áðëïðïßçóç ôçò ìåôáôñïðÞò ìåôáîý äéáöïñåôéêþí çìåñïëïãéáêþí áíáðáñáóôÜóåùí. Ôï óýóôçìá óôï óôï ïðïßï âáóßæåôáé åßíáé ôï Éïõëéáíü. Ôï óýóôçìá áõôü ìåôñÜ ôéò çìÝñåò îåêéíþíôáò áðü ôçí 1ç Éáíïõáñßïõ ôïõ 4713 ð.×. Ãéá íá ìåôáôñÝøåôå çìåñïëïãéáêÜ óõóôÞìáôá, ðñÝðåé ðñþôá íá êÜíåôå ôç ìåôáôñïðÞ óôï Éïõëéáíü, êáé åí óõíå÷åßá óå áõôü ôçò åðéëïãÞò óáò. Áõôüò ï ôñüðïò ìÝôñçóçò ôùí çìåñþí åßíáé ðïëý äéáöïñåôéêüò áðü ôï Éïõëéáíü Çìåñïëüãéï! Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò óôïí Éïõëéáíü ôñüðï ìÝôñçóçò, åðéóêåöôåßôå ôçí éóôïóåëßäá http://www.hermetic.ch/cal_stud/jdn.htm. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò óôá çìåñïëïãéáêÜ óõóôÞìáôá: http://www.boogle.com/info/cal-overview.html. ÁðïóðÜóìáôá áðü áõôÞ ôç óåëßäá óõìðåñéëáìâÜíïíôáé óå áõôÝò ôéò ïäçãßåò, êáé åßíáé óå quotes.
To get these functions to work, you have to compile PHP with --enable-calendar.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
The following constants are available since PHP 4.3.0 :
Ïé ðáñáêÜôù óôáèåñÝò åßíáé äéáèÝóéìåò áðü ôçí PHP 5.0.0 :
(PHP 4 >= 4.1.0, PHP 5)
cal_days_in_month -- ÅðéóôñïöÞ ôïõ ðëÞèïõò ôùí çìåñþí åíüò ìÞíá ôïõ äïèÝíôïò Ýôïõò êáé çìåñïëïãßïõÁõôÞ ç óõíÜñôçóç èá åðéóôñÝøåé ôï ðëÞèïò ôùí çìåñþí ôïõ month ôïõ äïèÝíôïò year ãéá ôï ðñïóäéïñéóìÝíï calendar.
ÁíáôñÝîôå åðßóçò óôçí jdtounix().
(PHP 4 >= 4.1.0, PHP 5)
cal_from_jd -- ÌåôáôñïðÞ áðü ôï ÉïõëéáíÞ áñßèìçóç çìåñþí óå ìßá Üëëç, õðïóôçñéæüìåíç áñßèìçóç, êáé åðéóôñïöÞ ðëçñïöïñéþí
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
cal_to_jd -- ÌåôáôñÝðåé Ýíáí õðïóôçñéæüìåíï ôýðï çìåñïëïãßïõ óôçí ÉïõëéáíÞ áñßèìçóç çìåñþí
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
easter_date -- ÅðéóôñïöÞ ôïõ UNIX timestamp ãéá ôá ìåóÜíõ÷ôá ôïõ ÐÜó÷á ôïõ äïèÝíôïò ÝôïõòÅðéóôñÝöåé ôï UNIX timestamp ðïõ áíôéóôïé÷åß óôá ìåóÜíõ÷ôá ôïõ ÐÜó÷á ôïõ äïèÝíôïò Ýôïõò.
Áðü ôçí PHP 4.3.0, ç ðáñÜìåôñïò year åßíáé ðñïáéñåôéêÞ êáé åÜí ðáñáëåßðåôáé äåß÷íåé default ôçí ðáñïýóá ÷ñïíéÜ, óõìöùíá ìå ôçí localtime.
Warning: ÁõôÞ ç óõíÜñôçóç èá ðáñÜîåé Ýíá warning åÜí ç ÷ñïíéÜ åßíáé åêôüò ôùí ïñßùí ôïõ UNIX timestamp (ð.÷. ðñéí ôï 1970 Þ ìåôÜ ôï 2037).
Ç çìåñïìçíßá ôçò çìÝñáò ôïõ ÐÜó÷á ïñßóôçêå, áðü ôç Óýíïäï ôçò Íßêáéáò ôï 325 ì.×., ùò ç ÊõñéáêÞ ìåôÜ ôçí ðñþôç ðáíóÝëçíï ìåôÜ Þ óôçí ÅáñéíÞ Éóçìåñßá. Ç éóçìåñßá åßíáé ðÜíôá óôéò 21 Ìáñôßïõ, Ýôóé ï õðïëïãéóìüò ðåñéïñßæåôáé óôïí õðïëïãéóìü ôçò çìåñïìçíßáò ôçò ðáíóÝëçíïõ êáé áõôÞò ôçò áêüëïõèçò ÊõñéáêÞò. Ï áëãüñéèìïò ðïõ ÷ñçóéìïðïéåßôáé åäþ ðñïôÜèçêå ôï 532, ðåñßðïõ, áðü ôïí Dionysius Exiguus. Óôï Éïõëéáíü çìåñïëüãéï (ãéá ÷ñüíéá ðñéí ôï 1753) Ýíáò áðëüò êýêëïò 19 ÷ñüíùí ÷ñçóéìïðïéåßôáé ãéá ôïí õðïëïãéóìü ôùí öÜóåùí ôçò ÓåëÞíçò. Óôï Ãñáãïñéáíü çìåñïëüãéï (for years after 1753 - åðéíïÞèçêå áðü ôïõò Clavius êáé Lilius, åöáñìüóôçêå áðü ôïí ÐÜðá Ãñçãüñéï XIII ôïí Ïêôþâñéï ôïõ 1582, êáé óôç Âñåôáíßá êáé ôéò áðïéêßåò ôçò ôï ÓåðôÝìâñéï ôïõ 1752) ðñïóôÝèçêáí äýï ðáñÜãïíôåò äéüñèùóçò ãéá íá êÜíïõí ôïí êýêëï ðéï áêñéâÞ.
(Ï êþäéêáò åßíáé âáóéóìÝíïò óå Ýíá ðñüãñáììá óå C ôïõ Simon Kershaw, <webmaster@ely.anglican.org>)
ÁíáôñÝîôå åðßóçò óôçí easter_days(), ãéá ôïí õðïëïãéóìü ôïõ ÐÜó÷á ðñéí ôï 1970 êáé ìåôÜ ôï 2037.
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
easter_days -- ÅðéóôñÝöåé ôï ðëÞèï ôùí çìåñþí áðü ôéò 21 Ìáñôéïý Ýùò ôçí çìÝñá ôïõ ÐÜó÷á, ãéá Ýíá äïóìÝíï ÝôïòÅðéóôñÝöåé ôï ðëÞèïò ôùí çìåñþí áðü ôéò 21 Ìáñôéïý Ýùò ôçí çìÝñá ôïõ ÐÜó÷á, ãéá Ýíá äïóìÝíï Ýôïò. ÅÜí äåí ðñïóäéïñéóôåß Ýôïò, èá ÷ñçóéìïðïéçèåß ôï ðáñüí Ýôïò.
Áðü ôçí Ýêäïóç 4.3.0 ôçò PHP, ç ðáñÜìåôñïò year åßíáé ðñïáéñåôéêÞ êáé åÜí ðáñáëçöèåß ôüôå ôßèåôáé default óôï ðáñüí Ýôïò, óýìöùíá ìå ôçí ôïðéêÞ þñá.
Ç ðáñÜìåôñïò method åéóÞ÷èåé åðßóçò óôçí Ýêäïóç 4.3.0 ôçò PHP êáé üôáí ôåèåß CAL_EASTER_ROMAN åðéôñÝðåé ôïí õðïëïãéóìü ôùí çìåñïìçíéþí ôïõ ÐÜó÷á, åíôüò ôçò ðåñéüäïõ 1582 - 1752, âÜóåé ôïõ Ãñçãïñéáíü çìåñïëüãéï. ÁíáôñÝîôå óôéò çìåñïëïãéáêÝò constants ãéá ðåñéóóüôåñåò óôáèåñÝò constants.
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá ÷ñçóéìïðïéçèåß áíôß ôçò easter_date() ãéá ôïí õðïëïãéóìü ôïí çìåñïìçíéþí ôïõ ÐÜó÷á ãéá ôá Ýôç ðïõ åßíáé ôïõ äéáóôÞìáôïò ôïõ UNIX timestamps (ð.÷. ðñéí ôï 1970 Þ ìåôÜ ôï 2037).
Ç çìåñïìçíßá ôçò çìÝñáò ôïõ ÐÜó÷á ïñßóôçêå, áðü ôç Óýíïäï ôçò Íßêáéáò ôï 325 ì.×., ùò ç ÊõñéáêÞ ìåôÜ ôçí ðñþôç ðáíóÝëçíï ìåôÜ Þ óôçí ÅáñéíÞ Éóçìåñßá. Ç éóçìåñßá åßíáé ðÜíôá óôéò 21 Ìáñôßïõ, Ýôóé ï õðïëïãéóìüò ðåñéïñßæåôáé óôïí õðïëïãéóìü ôçò çìåñïìçíßáò ôçò ðáíóÝëçíïõ áèôÞò ôçò áêüëïõèçò ÊõñéáêÞò. Ï áëãüñéèìïò ðïõ ÷ñçóéìïðïéåßôáé åäþ ðñùôÜèçêå ôï 532, ðåñßðïõ, áðü ôïí Dionysius Exiguus. Óôï Éïõëéáíü çìåñïëüãéï (ãéá ÷ñüíéá ðñéí ôï 1753) Ýíáò áðëüò êýêëïò 19 ÷ñüíùí ÷ñçóéìïðïéåßôáé ãéá ôïí õðïëïãéóìü ôùí öÜóåùí ôçò ÓåëÞíçò. Óôï Ãñáãïñéáíü çìåñïëüãéï (for years after 1753 - åðéíïÞèçêå áðü ôïõò Clavius êáé Lilius, åöáñìüóôçêå áðü ôïí ÐÜðá Ãñçãüñéï XIII ôïí Ïêôþâñéï ôïõ 1582, êáé óôç Âñåôáíßá êáé ôéò áðïéêßåò ôçò ôï ÓåðôÝìâñéï ôïõ 1752) ðñïóôÝèçêáí äýï ðáñÜãïíôåò äéüñèùóçò ãéá íá êÜíïõí ôïí êýêëï ðéï áêñéâÞ.
(Ï êþäéêáò åßíáé âáóéóìÝíïò óå Ýíá ðñüãñáììá óå C ôïõ Simon Kershaw, <webmaster@ely.anglican.org>)
ÁíáôñÝîôå åðßóçò óôçí easter_date().
(PHP 3, PHP 4 , PHP 5)
FrenchToJD -- ÌåôáôñÝðåé ìßá çìåñïìçíßá ôïõ Çìåñïëïãßïõ ôçò ÃáëëéêÞò Äçìïêñáôßáò óôï Éïõëéáíü óýóôçìá áñßèìçóçò çìåñþíÌåôáôñÝðåé ìßá çìåñïìçíßá ôïõ Çìåñïëïãßïõ ôçò ÃáëëéêÞò Äçìïêñáôßáò óôï Éïõëéáíü óýóôçìá áñßèìçóçò çìåñþí.
Ïé çìåñïìçíßåò ìåáôñÝðïíôáé ìåôáîý ôùí åôþí 1 Ýùò 14 (äçëáäÞ óå ÃñçãïñéáíÝò çìåñïìçíßåò, áðü 22 Óåðôåìâñßïõ 1792 Ýùò 22 Óåðôåìâñßïõ 1806). Êáëýðôåôáé Ýôóé ç ðåñßïäïò êáôÜ ôçí ïðïßá ÷ñçóéìïðïéïýíôáí.
(PHP 3, PHP 4 , PHP 5)
GregorianToJD -- ÌåôáôñÝðåé ìßá ÃñçãïñéáíÞ çìåñïìçíßá óôï Éïõëéáíü óýóôçìá ìÝôñçóóçò çìåñþí¸ãêõñï ðåäßï åôþí ãéá ôï Ãñçãïñéáíü çìåñïëüãéï 4714 ð.×. Ýùò 9999 ì.×.
ÐáñÜ ôï ãåãïíüò üôé áõôÞ ç óõíÜñôçóçò ìðüñåé íá ÷åéñéóôåß çìåñïìçíßåò áðü ôï 4714 ð.÷., ôÝôïéïéõ åßäïõò ÷ñÞóç ìðïñåß íá èåùñçèåß ÷þñéò íüçìá. Ôï Ãñçãïñéáíü çìåñïëüãéï ôÝèçêå óå éó÷ý óôéò 15 Ïêôþâñéïõ, 1582 (Þ óôéò 5 Ïêôùâñßïõ, 1582 âÜóåé ôïõ Éïõëéáíïý çìåñïëïãßïõ). ÌåñéêÝò ÷þñåò ôï äÝ÷ôçêáí ðïëý áñãüôåñá. Ãéá ðáñÜäåéãìá, ç Âñåôáíßá Üëëáîå ôï 1752, ç ÓïâéåôéêÞ ¸íùóç ôï 1918 êáé ç ÅëëÜäá ôï 1923. Ç ðåñéóóüôåñåò ÅõñùðáúêÝò ÷þñåò ÷ñçóéìïðïéïýóáí ôï Éïõëéáíü çìåñïëüãéï ðñéí ôï Ãñçãïñéáíü.
ÅðéóôñÝöåé ôçí çìÝñá ôçò åâäïìÜäáò. Ìðïñåß íá åðéóôñÝøåé Ýíá string Þ Ýíáí integer áíÜëïãá ìå ôç ñýèìéóç.
Ðßíáêáò 1. Ñõèìßóåéò ãéá ôéò åâäïìÜäåò ôïõ çìåñïëïãßïõ
Ñýèìéóç | ÅîÞãçóç |
---|---|
0 | ÅðéóôñÝöåé ôïí áñéèìü ôçò çìÝñáò óáí int (0=sunday, 1=monday, ê.ï.ê.) |
1 | ÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôçí çìÝñá ôçò åâäïìÜäáò (english-gregorian) |
2 | ÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá ôçò åâäïìÜäáò óõíôåôìçìÝíï (english-gregorian) |
ÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá åíüò ìÞíá. Ç ðáñÜìåôñïò mode ïñßæåé óå ðïéï çìåñïëüãéï èá ìåôáôñáðåß ôï Éïõëéáíü óýóôçìá áñßèìçóçò çìåñþí, êáé ôé ôýðïõ ìÞíá ïíüìáôá èá åðéóôñáöïýí.
Ðßíáêáò 1. Ñõèìßóåéò çìåñïëïãßïõ
Ñýèìéóç | ÅîÞãçóç | ÔéìÝò |
---|---|---|
0 | Ãñçãïñéáíü - óõíôåôìçìÝíá | Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec |
1 | Ãñçãïñéáíü | January, February, March, April, May, June, July, August, September, October, November, December |
2 | Éïõëéáíü - óõíôåôìçìÝíá | Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec |
3 | Éïõëéáíü | January, February, March, April, May, June, July, August, September, October, November, December |
4 | Åâñáúêü | Tishri, Heshvan, Kislev, Tevet, Shevat, AdarI, AdarII, Nisan, Iyyar, Sivan, Tammuz, Av, Elul |
5 | ÃáëëéêÞò Äçìïêñáôßáò | Vendemiaire, Brumaire, Frimaire, Nivose, Pluviose, Ventose, Germinal, Floreal, Prairial, Messidor, Thermidor, Fructidor, Extra |
(PHP 3, PHP 4 , PHP 5)
JDToFrench -- ÌåôáôñÝðåé áðü ôï Éïõëéáíü óõóôÞìá áñßèìçóçò çìåñþí óôï çìåñïëüãéï ôçò ÃáëëéêÞò ÄçìïêñáôßáòÌåôáôñÝðåé áðü ôï Éïõëéáíü óõóôÞìá áñßèìçóçò çìåñþí óôï çìåñïëüãéï ôçò ÃáëëéêÞò Äçìïêñáôßáò.
(PHP 3, PHP 4 , PHP 5)
JDToGregorian -- ÌåôáôñÝðåé ìßá çìåñïìçíßá ôïõ Éïõëéáíïý óõóôÞìáôïò áñßèìçóçò çìåñþí óôï Ãñçãïñéáíü çìåñïëüãéïÌåôáôñÝðåé ôçí çìåñïìçíßá ôïõ Éïõëéáíïý óõóôÞìáôïò áñßèìçóçò óå Ýíá string, ðïõ ðåñéÝ÷åé ôçí áíôßóôïé÷Þ ôçò óôï Ãñçãïñéáíü çìåñïëüãéï, óå ìïñöÞ "ìÞíáò/çìÝñá/Ýôïò".
(PHP 3, PHP 4 , PHP 5)
JDToJewish -- ÌåôáôñïðÞ áðü ôï Éïõëéáíü óýóôçìá áñßèìçóçò çìåñþí óôï Åâñáúêü çìåñïëüãéïÌåôáôñïðÞ áðü ôï Éïõëéáíü óýóôçìá ìÝôñçóçò çìåñþí óôï Åâñáúêü çìåñïëüãéï.
(PHP 3, PHP 4 , PHP 5)
JDToJulian -- ÌåôáôñÝðåé ìßá çìåñïìçíßá ôïõ Éïõëéáíïý óõóôÞìáôïò áñßèìçóçò çìåñþí óôçí áíôßóôïé÷Þ ôçò óôï Éïõëéáíü ÇìåñïëüãéïÌåôñÝðåé ìßá çìåñïìçíßá ôïõ Éïõëéáíïý óõóôÞìáôïò áñßèìçóçò çìåñþí óå ìßá ôïõ Éïõëéáíïý çìåñïëïãßïõ, ôçí ïðïßá áðïèçêåýåé óå string, óå ìïñöÞ "ìÞíáò/çìÝñá/Ýôïò".
Ç óõíÜñôçóç èá åðóôñÝøåé Ýíá UNIX timestamp ðïõ áíôáðïêñßíåôáé óôç äïèåßóá, óôç jday, ÉïõëéáíÞ ÇìåñÜ Þ FALSE åÜí ç jday äåí åßíáé åíôüò ôïõ UNIX epoch (óå ÃñçãïñéáíÜ Ýôç áíôéóôïé÷åß óôçí ðåñßïäï ìÝôáîý 1970 êáé 2037 Þ 2440588 <= jday <= 2465342 ). Ç åðéóôñåöüìåíç þñá åßíáé ôïðéêÞ (êáé ü÷é GMT).
ÁíáôñÝîôå åðßóçò óôçí unixtojd().
(PHP 3, PHP 4 , PHP 5)
JewishToJD -- ÌåôáôñÝðåé ìßá çìåñïìçíßá áðü ôï Åâñáúêü çìåñïëüãéï óôï Éïõëéáíü óýóôçìá áñßèìçóçò çìåñþíÐÜñá ôï ãåãïíüò üôé ç óõíÜñôçóç ÷åéñßæåôáé çìåñïìçíßåò áðü ôï Ýôïò 1 (3761 ð.×.) êáé ìåôÜ, ôÝôïéïõ åßäïõò ÷ñçóç ìðïñåß íá åßíáé ÷ùñßò íüçìá. Ôï Åâñáúêü çìåñïëüãéï ÷ñåéóéìïðïéåßôáé ÷éëéÜäåò ÷ñüíéá, áëëÜ ôüôå ðïõ åðéíïÞèçêå äåí õðÞñ÷å êÜðïéïò ôýðïò ãéá ôïí õðïëïãéóìü ôçò áñ÷Þò åíüò ìÞíá. ¸íáò íÝïò ìÞíáò Üñ÷éæå üôáí ðáñáôçñïýíôáí ç íÝá óåëÞíç.
(PHP 3, PHP 4 , PHP 5)
JulianToJD -- ÌåôáôñÝðåé ìßá çìåñïìçíßá ôïõ Éïõëéáíïý çìåñïëïãßïõ óå ìßá ôïõ Éïõëéáíïý óõóôÞìáôïò áñßèìçóçò çìåñþí¸ãêõñï ðåäßï åôþí ãéá ôï Éïõëéáíü çìåñïëüãéï 4714 ð.×. Ýùò 9999 ì.×.
ÐáñÜ ôï ãåãïíüò üôé áõôÞ ç óõíÜñôçóç ÷åéñßæåôáé çìåñïìçíßáò áðü ôï 4713 ð.×., ôÝôïéïõ åßäïõò ÷ñÞóç ìðïñåß íá åßíáé äß÷ùò íüçìá. Ôï çìåñïëüãéï êáôáóêåõÜóôçêå ôï 46 ð.×., áëëÜ ïé ëåðôïìÝñåéò ôïõ ñõèìßóôçêáí ü÷é íùñßôåñá áðü ôï 8 ì.×., êáé ßóùò äåí åß÷áí óôáèåñïðïéçèåß ðñéí ôïí 4ï áéþíá. Åðßóçò, ç áñ÷Þ åíüò Ýôïõò äéÝöåñå áðü ôïí Ýíá ëáü óôïí Üëëï - Äå äÝ÷ôçêáí üëïé ôï ÃåíÜñç ùò ôïí ðñþôï ìÞíá.
Ðñïóï÷Þ |
Èõìçèåßôå, ôï çìåñïëüãéï ðïõ ÷ñçóéìïðïéåßôáé ôþñá ðáãêïóìßùò åßíáé ôï Ãñçãïñéáíü. Ç gregoriantojd() ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá ôç ìåôáôñïðÞ ôÝôïéùí çìåñïìçíéþí óôï Éïõëéáíü óýóôçìá ìÝôñçóçò çìåñþí. |
ÅðéóôñÝöåé ôçí ÉïõëéáíÞ ÇìÝñá ãéá Ýíá UNIX timestamp (äåõôåñüëåðôá áðü ôçí 1.1.1970), ç ãéá ôçí óçìåñéíÞ çìÝñá áí äå äïèåß ç ðáñÜìåôñïò timestamp.
ÁíáôñÝîôå åðßóçò óôç jdtounix().
These functions interface the CCVS API, allowing you to work directly with CCVS from your PHP scripts. CCVS is RedHat's solution to the "middle-man" in credit card processing. It lets you directly address the credit card clearing houses via your *nix box and a modem. Using the CCVS module for PHP, you can process credit cards directly through CCVS via your PHP Scripts. The following references will outline the process.
Óçìåßùóç: CCVS has been discontinued by Red Hat and there are no plans to issue further keys or support contracts. Those looking for a replacement can consider MCVE by Main Street Softworks as a potential replacement. It is similar in design and has documented PHP support!
This extension has been removed from PHP and is no longer available as of PHP 4.3.0. If you want to use credit card processing features you can use MCVE instead.
To enable CCVS Support in PHP, first verify your CCVS installation directory. You will then need to configure PHP with the --with-ccvs option. If you use this option without specifying the path to your CCVS installation, PHP will attempt to look in the default CCVS Install location (/usr/local/ccvs). If CCVS is in a non-standard location, run configure with: --with-ccvs=[DIR], where DIR is the path to your CCVS installation. Please note that CCVS support requires that DIR/lib and DIR/include exist, and include cv_api.h under the include directory and libccvs.a under the lib directory.
Additionally, a ccvsd process will need to be running for the configurations you intend to use in your PHP scripts. You will also need to make sure the PHP Processes are running under the same user as your CCVS was installed as (e.g. if you installed CCVS as user 'ccvs', your PHP processes must run as 'ccvs' as well.)
RedHat has discontinued support for CCVS; however, a slightly outdated manual is still available at http://redhat.com/docs/manuals/ccvs/.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.0.2 - 4.2.3 only)
ccvs_command -- Performs a command which is peculiar to a single protocol, and thus is not available in the general CCVS API
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.0.2 - 4.2.3 only)
ccvs_count -- Find out how many transactions of a given type are stored in the system
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
COM is an acronym for Component Object Model; it is an object orientated layer (and associated services) on top of DCE RPC (an open standard) and defines a common calling convention that enables code written in any language to call and interoperate with code written in any other language (provided those languages are COM aware). Not only can the code be written in any language, but it need not even be part of the same executable; the code can be loadaed from a DLL, be found in another process running on the same machine, or, with DCOM (Distributed COM), be found in another process on a remote machine, all without your code even needing to know where a component resides.
There is a subset of COM known as OLE Automation which comprises a set of COM interfaces that allow loose binding to COM objects, so that they can be introspected and called at run-time without compile-time knowledge of how the object works. The PHP COM extension utilitizes the OLE Automation interfaces to allow you to create and call compatible objects from your scripts. Technically speaking, this should really be called the "OLE Automation Extension for PHP", since not all COM objects are OLE compatible.
Now, why would or should you use COM? COM is one of the main ways to glue applications and components together on the Windows platform; using COM you can launch Microsoft Word, fill in a document template and save the result as a Word document and send it to a visitor of your web site. You can also use COM to perform administrative tasks for your network and to configure your IIS; these are just the most common uses; you can do much more with COM.
Starting with PHP 5, this extension (and this documentation) was rewritten from scratch and much of the old confusing and bogus cruft has be removed. Additionally, we support the instantiation and creation of .Net assemblies using the COM interoperability layer provided by Microsoft.
Please read this article for an overview of the changes in this extension in PHP 5.
COM functions are only available for the Windows version of PHP.
.Net support requires PHP 5 and the .Net runtime.
Äåí ÷ñåéÜæåôáé åãêáôÜóôáóç ãéá áõôÝò ôéò óõíáñôÞóåéò, åßíáé ìÝñïò ôïõ ðõñÞíá ôçò PHP.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
You are responsible for installing support for the various COM objects that you intend to use (such as MS Word); we don't and can't bundle all of those with PHP.
Starting with PHP 5, you may use PHP's own ôï ôìÞìá ìå üíïìá foreach óå ÊåöÜëáéï 11 statement to iterate over the contents of a standard COM/OLE IEnumVariant. In laymans terms, this means that you can use foreach in places where you would have used For Each in VB/ASP code.
Many COM objects expose their properties as arrays, or using array-style access. In PHP 4, you may use PHP array syntax to read/write such a property, but only a single dimension is allowed. If you want to read a multi-dimensional property, you could instead make the property access into a function call, with each parameter representing each dimension of the array access, but there is no way to write to such a property.
PHP 5 introduces the following new features to make your life easier:
Access multi-dimensional arrays, or COM properties that require multiple parameters using PHP array syntax. You can also write or set properties using this technique.
Iterate SafeArrays ("true" arrays) using the ôï ôìÞìá ìå üíïìá foreach óå ÊåöÜëáéï 11 control structure. This works because SafeArrays include information about their size. If an array-style property implements IEnumVariant then you can also use foreach for that property too; take a look at ôï ôìÞìá ìå üíïìá For Each for more information on this topic.
This extension will throw instances of the class com_exception whenever there is a potentially fatal error reported by COM. All COM exceptions have a well-defined code property that corresponds to the HRESULT return value from the various COM operations. You may use this code to make programmatic decisions on how to handle the exception.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Com configuration options
Name | Default | Changeable |
---|---|---|
com.allow_dcom | "0" | PHP_INI_SYSTEM |
com.autoregister_typelib | "0" | PHP_INI_ALL |
com.autoregister_verbose | "0" | PHP_INI_ALL |
com.autoregister_casesensitive | "1" | PHP_INI_ALL |
com.code_page | "" | PHP_INI_ALL |
com.typelib_file | "" | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
When this is turned on, PHP will be allowed to operate as a D-COM (Distributed COM) client and will allow the PHP script to instantiate COM objects on a remote server.
When this is turned on, PHP will attempt to register constants from the typelibrary of objects that it instantiates, if those objects implement the interfaces required to obtain that information. The case sensitivity of the constants it registers is controlled by the configuration directive.
When this is turned on, any problems with loading a typelibrary during object instantiation will be reported using the PHP error mechanism. The default is off, which does not emit any indication if there was an error finding or loading the type library.
When this is turned on (the default), constants found in auto-loaded type libraries will be registered case sensitively. See com_load_typelib() for more details.
It controls the default character set code-page to use when passing strings to and from COM objects. If set to an empty string, PHP will assume that you want CP_ACP, which is the default system ANSI code page.
If the text in your scripts is encoded using a different encoding/character set by default, setting this directive will save you from having to pass the code page as a parameter to the COM class constructor. Please note that by using this directive (as with any PHP configuration directive), your PHP script becomes less portable; you should use the COM constructor parameter whenever possible.
Óçìåßùóç: This configuration directive was introduced with PHP 5.
When set, this should hold the path to a file that contains a list of typelibraries that should be loaded on startup. Each line of the file will be treated as the type library name and loaded as though you had called com_load_typelib(). The constants will be registered persistently, so that the library only needs to be loaded once. If a type library name ends with the string #cis or #case_insensitive, then the constants from that library will be registered case insensitively.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
For further information on COM read the COM specification or perhaps take a look at Don Box's Yet Another COM Library (YACL). You might find some additional useful information in our FAQ for ÊåöÜëáéï 52. If you're thinking of using MS Office applications on the server side, you should read the information here: Considerations for Server-Side Automation of Office.
The COM class allows you to instantiate an OLE compatible COM object and call its methods and access its properties.
COM class constructor. The parameters have the following meanings:
Can be a ProgID, Class ID or Moniker that names the component to load.
A ProgID is typically the application or DLL name, followed by a period, followed by the object name. e.g: Word.Application.
A Class ID is the UUID that uniquely identifies a given class.
A Moniker is a special form of naming, similar in concept to a URL scheme, that identifies a resource and specifies how it should be loaded. As an example, you could load up Word and get an object representing a word document by specifying the full path to the word document as the module name, or you can use LDAP: as a moniker to use the ADSI interface to LDAP.
The name of the DCOM server on which the component should be loaded and run. If NULL, the object is run using the default for the application. The default is typically to run it on the local machine, although the administrator might have configured the application to launch on a different machine.
If you specify a non-NULL value for server, PHP will refuse to load the object unless the configuration option is set to TRUE.
If server_name is an array, it should contain the following elements (case sensitive!). Note that they are all optional (although you need to specify both Username and Password together); if you omit the Server setting, the default server will be used (as mentioned above), and the instantiation of the object will not be affected by the directive.
Ðßíáêáò 1. DCOM server name
server_name key | type | description |
---|---|---|
Server | string | The name of the server. |
Username | string | The username to connect as. |
Password | string | The password for Username. |
Flags | integer | One or more of the following constants, logically OR'd together: CLSCTX_INPROC_SERVER, CLSCTX_INPROC_HANDLER, CLSCTX_LOCAL_SERVER, CLSCTX_REMOTE_SERVER, CLSCTX_SERVER and CLSCTX_ALL. The default value if not specified here is CLSCTX_SERVER if you also omit Server, or CLSCTX_REMOTE_SERVER if you do specify a server. You should consult the Microsoft documentation for CoCreateInstance for more information on the meaning of these constants; you will typically never have to use them. |
Specifies the codepage that is used to convert strings to unicode-strings and vice versa. The conversion is applied whenever a PHP string is passed as a parameter or returned from a method of this COM object. The code page is sticky in PHP 5, which means that it will propogate to objects and variants returned from the object.
Possible values are CP_ACP (use system default ANSI code page - the default if this parameter is omitted), CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP (use codepage/locale set for the current executing thread), CP_UTF7 and CP_UTF8. You may also use the number for a given codepage; consult the Microsoft documentation for more details on codepages and their numeric values.
The returned object is an overloaded object, which means that PHP does not see any fixed methods as it does with regular classes; instead, any property or method accesses are passed through to COM.
Starting with PHP 5, PHP will automatically detect methods that accept parameters by reference, and will automatically convert regular PHP variables to a form that can be passed by reference. This means that you can call the method very naturally; you needn't go to any extra effort in your code.
In PHP 4, to pass parameters by reference you need to create an instance of the VARIANT class to wrap the byref parameters.
In PHP versions prior to 5, a number of not very pleasant hacks meant that the following method names were not passed through to COM and were handled directly by PHP. PHP 5 eliminates these things; read the details below to determine how to fix your scripts. These magic method names are case insensitive.
void COM::AddRef ( void )Artificially adds a reference count to the COM object.
Ðñïåéäïðïßçóç |
You should never need to use this method. It exists a logical complement to the Release() method below. |
Artificially removes a reference count from the COM object.
Ðñïåéäïðïßçóç |
You should never need to use this method. It's existence in PHP is a bug designed to work around a bug that keeps COM objects running longer than they should. |
These pseudo methods are only available if com_isenum() returns TRUE, in which case, they hide any methods with the same names that might otherwise be provided by the COM object. These methods have all been eliminated in PHP 5, and you should use ôï ôìÞìá ìå üíïìá For Each óå ÁíáöïñÜ VIII, COM and .Net (Windows) instead.
object COM::All ( void )Returns a variant representing a SafeArray that has 10 elements; each element will be an empty/null variant. This function was supposed to return an array containing all the elements from the iterator, but was never completed. Do not use.
object COM::Next ( void )Returns a variant representing the next element available from the iterator, or FALSE when there are no more elements.
object COM::Prev ( void )Returns a variant representing the previous element available from the iterator, or FALSE when there are no more elements.
void COM::Reset ( void )Rewinds the iterator back to the start.
ÐáñÜäåéãìá 1. COM example (1)
|
ÐáñÜäåéãìá 2. COM example (2)
|
The DOTNET class allows you to instantiate a class from a .Net assembly and call its methods and access its properties.
DOTNET class constructor. assembly_name specifies which assembly should be loaded, and class_name specifices which class in that assembly to instantiate. You may optionally specify a codepage to use for unicode string transformations; see the COM class for more details on code pages.
The returned object is an overloaded object, which means that PHP does not see any fixed methods as it does with regular classes; instead, any property or method accesses are passed through to COM and from there to DOTNET. In other words, the .Net object is mapped through the COM interoperability layer provided by the .Net runtime.
Once you have created a DOTNET object, PHP treats it identically to any other COM object; all the same rules apply.
Óçìåßùóç: You need to install the .Net runtime on your web server to take advantage of this feature.
The VARIANT is COM's equivalent of the PHP zval; it is a structure that can contain a value with a range of different possible types. The VARIANT class provided by the COM extension allows you to have more control over the way that PHP passes values to and from COM.
VARIANT class constructor. Parameters:
initial value. if omitted, or set to NULL an VT_EMPTY object is created.
specifies the content type of the VARIANT object. Possible values are one of the VT_XXX ôï ôìÞìá ìå üíïìá ÐñïêáèïñéóìÝíåò ÓôáèåñÝò óå ÁíáöïñÜ VIII, COM and .Net (Windows).
In PHP versions prior to PHP 5, you could force PHP to pass a variant object by reference by OR'ing VT_BYREF with the type. In PHP 5, this hack is not supported; instead, PHP 5 can detect parameters passed by reference automatically; they do not even need to be passed as VARIANT objects.
Consult the MSDN library for additional information on the VARIANT type.
specifies the codepage that is used to convert strings to unicode. See the parameter of the same name in the COM class for more information.
PHP versions prior to PHP 5 define a number of (undocumented) virtual properties for instances of the VARIANT class; these properties have all been removed in PHP 5 in favour of its more natural syntax; these differences are best highlighted by example:
The reason for the change is that, internally, the COM extension sees VARIANT, COM and DOTNET classes as the same thing, and the design philosophy for these classes is that all property and member accesses are passed through to COM with no interference. The new syntax is more natural and less effort, and most of the removed virtual properties didn't make any sense in a PHP context in any case.
Óçìåßùóç: PHP 5 takes a much simpler approach to handling VARIANTs; when returning a value or fetching a variant property, the variant is converted to a PHP value only when there is a direct mapping between the types that would not result in a loss of information. In all other cases, the result is returned as an instance of the VARIANT class. You can force PHP to convert or evaluate the variant as a PHP native type by using a casting operator explicitly, or implicitly casting to a string by print()ing it. You may use the wide range of variant functions to perform arithmetic operations on variants without forcing a conversion or risking a loss of data.
See also variant_get_type().
Increases the components reference counter.
Ðñïåéäïðïßçóç |
You should never need to use this function. |
Óçìåßùóç: This function has gone away in PHP 5.
Generates a Globally Unique Identifier (GUID) and returns it as a string. A GUID is generated in the same way as DCE UUID's, except that the Microsoft convention is to enclose a GUID in curly braces.
See also uuid_create() in the PECL uuid extension.
Instructs COM to sink events generated by comobject into the PHP object sinkobject. PHP will attempt to use the default dispinterface type specified by the typelibrary associated with comobject, but you may override this choice by setting sinkinterface to the name of the dispinterface that you want to use.
sinkobject should be an instance of a class with methods named after those of the desired dispinterface; you may use com_print_typeinfo() to help generate a template class for this purpose.
Be careful how you use this feature; if you are doing something similar to the example below, then it doesn't really make sense to run it in a web server context.
ÐáñÜäåéãìá 1. COM event sink example
|
See also com_print_typeinfo(), com_message_pump().
(no version information, might be only in CVS)
com_get_active_object -- Returns a handle to an already running instance of a COM objectcom_get_active_object() is similar to creating a new instance of a COM object, except that it will only return an object to your script if the object is already running. OLE applications use something known as the Running Object Table to allow well-known applications to be launched only once; this function exposes the COM library function GetActiveObject() to get a handle on a running instance.
progid must be either the ProgID or CLSID for the object that you want to access (for example Word.Application). code_page acts in precisely the same way that it does for the COM class.
If the requestested object is running, it will be returned to your script just like any other COM object. Otherwise a com_exception will be raised. There are a variety of reasons why this function might fail, the most common being that the object is not already running. In that situation, the exception error code will be MK_E_UNAVAILABLE; you can use the getCode method of the exception object to check the exception code.
Ðñïåéäïðïßçóç |
Using com_get_active_object() in a web server context is not always a smart idea. Most COM/OLE applications are not designed to handle more than one client concurrently, even (or especially!) Microsoft Office. You should read Considerations for Server-Side Automation of Office for more information on the general issues involved. |
Returns the value of the property of the COM component referenced by com_object. Returns FALSE on error.
Óçìåßùóç: This function does not exist in PHP 5; instead, you should use the regular and more natural OO syntax to access properties or call methods.
com_invoke() invokes the method named function_name of the COM component referenced by com_object. com_invoke() returns FALSE on error, returns the function_name's return value on success. All the extra parameters function_parameters are passed to the method function_name.
Óçìåßùóç: This function does not exist in PHP 5; instead, you should use the regular and more natural OO syntax to access properties or call methods.
(PHP 4 >= 4.1.0)
com_isenum -- Indicates if a COM object has an IEnumVariant interface for iteration [deprecated]Checks to see if a COM object can be enumerated using the Next() method hack. Returns TRUE if it can, FALSE if it cannot. See COM class for more details on these methods.
Óçìåßùóç: This function does not exist in PHP 5; use the more natural ôï ôìÞìá ìå üíïìá foreach óå ÊåöÜëáéï 11 statement to iterate over the contents of COM objects. See ôï ôìÞìá ìå üíïìá For Each óå ÁíáöïñÜ VIII, COM and .Net (Windows) for more details.
Loads a type-library and registers its constants in the engine, as though they were defined using define(). The case_insensitive behaves in the same way as the parameter with the same name in the define() function.
typelib_name can be one of the following:
The filename of a .tlb file or the executable module that contains the type library.
The type library GUID, followed by its version number, for example {00000200-0000-0010-8000-00AA006D2EA4},2,0.
The type library name, e.g. Microsoft OLE DB ActiveX Data Objects 1.0 Library.
Note that it is much more efficient to use the configuration setting to pre-load and register the constants, although not so flexible.
If you have turned on , then PHP will attempt to automatically register the constants associated with a COM object when you instantiate it. This depends on the interfaces provided by the COM object itself, and may not always be possible.
Equivalent to using the new operator to create an instance of the COM class. You should do that instead of calling this function.
Óçìåßùóç: This function does not exist in PHP 5; use the COM class instead.
(PHP 4 >= 4.2.3, PHP 5)
com_message_pump -- Process COM messages, sleeping for up to timeoutms millisecondsThis function will sleep for up to timeoutms milliseconds, or until a message arrives in the queue. If a message or messages arrives before the timeout, they will be dispatched, and the function will return TRUE. If the timeout occurs and no messages were processed, the return value will be FALSE. If you do not specify a value for timeoutms, then 0 will be assumed. A 0 value means that no waiting will be performed; if there are messages pending they will be dispatched as before; if there are no messages pending, the function will return FALSE immediately without sleeping.
The purpose of this function is to route COM calls between apartments and handle various synchronization issues. This allows your script to wait efficiently for events to be triggered, while still handling other events or running other code in the background. You should use it in a loop, as demonstrated by the example in the com_event_sink() function, until you are finished using event bound COM objects.
(PHP 4 >= 4.2.3, PHP 5)
com_print_typeinfo -- Print out a PHP class definition for a dispatchable interfaceThe purpose of this function is to help generate a skeleton class for use as an event sink. You may also use it to generate a dump of any COM object, provided that it supports enough of the introspection interfaces, and that you know the name of the interface you want to display.
comobject should be either an instance of a COM object, or be the name of a typelibrary (which will be resolved according to the rules set out in com_load_typelib()). dispinterface is the name of an IDispatch descendant interface that you want to display. If wantsink is TRUE, the corresponding sink interface will be displayed instead.
See also com_event_sink(), com_load_typelib().
This function is an alias for com_get().
Óçìåßùóç: This function does not exist in PHP 5; instead, you should use the regular and more natural OO syntax to access properties or call methods.
This function is an alias for com_set().
Óçìåßùóç: This function does not exist in PHP 5; instead, you should use the regular and more natural OO syntax to access properties or call methods.
This function is an alias for com_set().
Óçìåßùóç: This function does not exist in PHP 5; instead, you should use the regular and more natural OO syntax to access properties or call methods.
Decreases the components reference counter.
Ðñïåéäïðïßçóç |
You should never need to use this function. |
Óçìåßùóç: This function has gone away in PHP 5.
Sets the value of the property of the COM component referenced by com_object. Returns the newly set value if succeeded, FALSE on error.
Óçìåßùóç: This function does not exist in PHP 5; instead, you should use the regular and more natural OO syntax to access properties or call methods.
Returns the absolute value of val.
See also abs().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Adds left to right using the following rules (taken from the MSDN library), which correspond to those of Visual Basic:
Ðßíáêáò 1. Variant Addition Rules
If | Then |
---|---|
Both expressions are of the string type | Concatenation |
One expression is a string type and the other a character | Addition |
One expression is numeric and the other is a string | Addition |
Both expressions are numeric | Addition |
Either expression is NULL | NULL is returned |
Both expressions are empty | Integer subtype is returned |
See also variant_sub().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Performs a bitwise AND operation, according to the following truth table; note that this is slightly different from a regular AND operation.
Ðßíáêáò 1. Variant AND Rules
If left is | If right is | then the result is |
---|---|---|
TRUE | TRUE | TRUE |
TRUE | FALSE | FALSE |
TRUE | NULL | NULL |
FALSE | TRUE | FALSE |
FALSE | FALSE | FALSE |
FALSE | NULL | FALSE |
NULL | TRUE | NULL |
NULL | FALSE | FALSE |
NULL | NULL | NULL |
See also variant_or().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
This function makes a copy of variant and then performs a variant cast operation to force the copy to have the type given by type. type should be one of the VT_XXX constants.
This function wraps VariantChangeType() in the COM library; consult MSDN for more information.
See also variant_set_type().
Concatenates left with right and returns the result.
See also ôï ôìÞìá ìå üíïìá ÔåëåóôÝò ãéá strings óå ÊåöÜëáéï 10 for the string concatenation operator; this function is notionally equivalent to $left . $right.
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Compares left with right and returns one of the following values:
Ðßíáêáò 1. Variant Comparision Results
value | meaning |
---|---|
VARCMP_LT | left is less than right |
VARCMP_EQ | left is equal to right |
VARCMP_GT | left is greater than right |
VARCMP_NULL | Either left, right or both are NULL |
This function will only compare scalar values, not arrays or variant records.
lcid is a valid Locale Identifier to use when comparing strings (this affects string collation). flags can be one or more of the following values OR'd together, and affects string comparisons:
Ðßíáêáò 2. Variant Comparision Flags
value | meaning |
---|---|
NORM_IGNORECASE | Compare case insensitively |
NORM_IGNORENONSPACE | Ignore nonspacing characters |
NORM_IGNORESYMBOLS | Ignore symbols |
NORM_IGNOREWIDTH | Ignore string width |
NORM_IGNOREKANATYPE | Ignore Kana type |
NORM_IGNOREKASHIDA | Ignore Arabic kashida characters |
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Converts timestamp from a unix timestamp value into a variant of type VT_DATE. This allows easier interopability between the unix-ish parts of PHP and COM.
See also variant_date_to_timestamp() for the inverse of this operation, mktime(), time().
Converts variant from a VT_DATE (or similar) value into a unix timestamp. This allows easier interopability between the unix-ish parts of PHP and COM.
See also variant_date_from_timestamp() for the inverse of this operation, date(), strftime().
Divides left by right and returns the result, subject to the following rules:
Ðßíáêáò 1. Variant Division Rules
If | Then |
---|---|
Both expressions are of the string, date, character, boolean type | Double is returned |
One expression is a string type and the other a character | Division and a double is returned |
One expression is numeric and the other is a string | Division and a double is returned. |
Both expressions are numeric | Division and a double is returned |
Either expression is NULL | NULL is returned |
right is empty and left is anything but empty | A com_exception with code DISP_E_DIVBYZERO is thrown |
left is empty and right is anything but empty. | 0 as type double is returned |
Both expressions are empty | A com_exception with code DISP_E_OVERFLOW is thrown |
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
If each bit in left is equal to the corresponding bit in right then TRUE is returned, otherwise FALSE is returned.
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
If variant is negative, then the first negative integer greater than or equal to the variant is returned, otherwise returns the integer portion of the value of variant.
See also variant_int(), variant_round(), floor(), ceil(), round().
Ðñïåéäïðïßçóç |
This documentation is based on the MSDN documentation; it appears that this function is either the same as variant_int(), or that there is an error in the MSDN documentation. |
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
This function returns an integer value that indicates the type of variant, which can be an instance of COM, DOTNET or VARIANT classes. The return value can be compared to one of the VT_XXX constants.
The return value for COM and DOTNET objects will usually be VT_DISPATCH; the only reason this function works for those classes is because COM and DOTNET are descendants of VARIANT.
In PHP versions prior to 5, you could obtain this information from instances of the VARIANT class ONLY, by reading a fake type property. See the VARIANT class for more information on this.
Converts left and right to integer values, and then performs integer division according the following rules:
Ðßíáêáò 1. Variant Integer Division Rules
If | Then |
---|---|
Both expressions are of the string, date, character, boolean type | Division and integer is returned |
One expression is a string type and the other a character | Division |
One expression is numeric and the other is a string | Division |
Both expressions are numeric | Division |
Either expression is NULL | NULL is returned |
Both expressions are empty | A com_exception with code DISP_E_DIVBYZERO is thrown |
See also variant_div().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Performs a bitwise implication operation, according to the following truth table:
Ðßíáêáò 1. Variant Implication Table
If left is | If right is | then the result is |
---|---|---|
TRUE | TRUE | TRUE |
TRUE | FALSE | TRUE |
TRUE | NULL | TRUE |
FALSE | TRUE | TRUE |
FALSE | FALSE | TRUE |
FALSE | NULL | TRUE |
NULL | TRUE | TRUE |
NULL | FALSE | NULL |
NULL | NULL | NULL |
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
If variant is negative, then the first negative integer greater than or equal to the variant is returned, otherwise returns the integer portion of the value of variant.
See also variant_fix(), variant_round(), floor(), ceil(), round().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Divides left by right and returns the remainder.
See also variant_div(), variant_idiv().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Multiplies left by right and returns the result, subject to the following rules:
Ðßíáêáò 1. Variant Multiplication Rules
If | Then |
---|---|
Both expressions are of the string, date, character, boolean type | Multiplication |
One expression is a string type and the other a character | Multiplication |
One expression is numeric and the other is a string | Multiplication |
Both expressions are numeric | Multiplication |
Either expression is NULL | NULL is returned |
Both expressions are empty | Empty string is returned |
Boolean values are converted to -1 for FALSE and 0 for TRUE.
See also variant_div(), variant_idiv().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Performs logical negation of variant and returns the result.
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Performs bitwise not negation on variant and returns the result. If variant is NULL, the result will also be NULL.
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Performs a bitwise OR operation, according to the following truth table; note that this is slightly different from a regular OR operation.
Ðßíáêáò 1. Variant OR Rules
If left is | If right is | then the result is |
---|---|---|
TRUE | TRUE | TRUE |
TRUE | FALSE | TRUE |
TRUE | NULL | TRUE |
FALSE | TRUE | TRUE |
FALSE | FALSE | FALSE |
FALSE | NULL | NULL |
NULL | TRUE | TRUE |
NULL | FALSE | NULL |
NULL | NULL | NULL |
See also variant_and(), variant_xor().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Returns the result of left to the power of right.
See also pow().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Returns the value of variant rounded to decimals decimal places.
See also round().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
This function is similar to variant_cast() except that the variant is modified "in-place"; no new variant is created. The parameters for this function have identical meaning to those of variant_cast().
See also variant_cast().
Converts value to a variant and assigns it to the variant object; no new variant object is created, and the old value of variant is freed/released.
(PHP 5)
variant_sub -- subtracts the value of the right variant from the left variant value and returns the resultSubtracts right from left using the following rules:
Ðßíáêáò 1. Variant Subtraction Rules
If | Then |
---|---|
Both expressions are of the string type | Subtraction |
One expression is a string type and the other a character | Subtraction |
One expression is numeric and the other is a string | Subtraction. |
Both expressions are numeric | Subtraction |
Either expression is NULL | NULL is returned |
Both expressions are empty | Empty string is returned |
See also variant_add().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Performs a logical exclusion, according to the following truth table:
Ðßíáêáò 1. Variant XOR Rules
If left is | If right is | then the result is |
---|---|---|
TRUE | TRUE | FALSE |
TRUE | FALSE | TRUE |
FALSE | TRUE | TRUE |
FALSE | FALSE | FALSE |
NULL | NULL | NULL |
See also variant_and(), variant_or().
Óçìåßùóç: As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string, floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants using the same rules as found in the constructor for the VARIANT class. COM and DOTNET objects will have the value of their default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add() in PHP corresponds to VarAdd() in the MSDN documentation.
Ïé óõíáñôÞóåéò áõôÝò óáò åðéôñÝðïõí íá áíáêôÞóåôå ðëçñïöïñßåò ãéá ôéò êëÜóåéò êáé ôá óôéãìéüôõðá ôïõò. Ìðïñåßôå íá áíáêôÞóåôå ôï üíïìá ôçò êëÜóçò óôçí ïðïßá áíÞêåé Ýíá áíôéêåßìåíï, êáèþò êáé ôéò ìåôáâëçôÝò êáé ôéò ìåèüäïõò ôïõ. ×ñçóéìïðïéþíôáò áõôÝò ôéò óõíáñôÞóåéò, ìðïñåßôå íá ìÜèåôå ü÷é ìüíï ôçí êëÜóç åíüò áíôéêåéìÝíïõ, áëëÜ êáé ôéò õðåñêëÜóåéò ôïõ (áðü ðïéÜ êëÜóç êëçñïíïìåß ôï áíôéêåßìåíï).
Óå áõôü ôï ðáñÜäåéãìá, ðñþôá ïñßæïõìå ìéá êëÜóç-âÜóç êáé ìåôÜ ìéá êëÜóç êëçñïíüìï. Ç êëÜóç-âÜóç ðåñéãñÜöåé Ýíá ãåíéêü ëá÷áíéêü, áí åßíáé âñþóéìï Þ ü÷é, êáé ôï ÷ñþìá ôïõ. Ç êëÜóç êëçñïíüìïò Spinach ðñïóèÝôåé ìéá ìÝèïäï ãéá ôï ìáãåßñåìá êáé áêüìá ìéá ðïõ åðéóôñÝöåé áí åßíáé ìáãåéñåìÝíï.
ÐáñÜäåéãìá 1. classes.inc
|
Áêïëïýèùò äçìéïõñãïýìå äõï óôéãìéüôõðá áðü áõôÝò ôéò êëÜóåéò êáé ôõðþíïõìå ðëçñïöïñßåò ãéá áõôÜ, óõìðåñéëáìâáíïìÝíçò ôçò õðåñêëÜóçò ôïõò. Ïñßæïõìå åðßóçò ìåñéêÝò âïçèçôéêÝò óõíáñôÞóåéò, êõñßùò ãéá íá åßíáé êáëáéóèçôéêü ôï ôýðùìá ôùí ìåôáâëçôþí.
ÐáñÜäåéãìá 2. test_script.php
Ìéá óçìáíôéêÞ ðáñáôÞñçóç ó÷åôéêÜ ìå ôï ðéï ðÜíù ðáñÜäåéãìá åßíáé üôé ôï áíôéêåßìåíï $leafy åßíáé Ýíá óôéãìéüôõðï ôçò êëÜóçò Spinach, ç ïðïßá åßíáé õðïêëÜóç ôïõ Vegetable, óõíåðþò ôï ôåëåõôáßï ìÝñïò ôïõ script èá ôõðþóåé:
|
(PHP 4 >= 4.0.5, PHP 5)
call_user_method_array -- Êáëåß ìéá ìÝèïäï ìå Ýíá array áðü ðáñáìÝôñïõò [deprecated]Ðñïåéäïðïßçóç |
Ç óõíÜñôçóç call_user_method_array() åßíáé deprecated áðü ôçí Ýêäïóç PHP 4.1.0, áíôß áõôÞò ÷ñçóéìïðïéÞóôå ôï call_user_func_array() ìå ôç óýíôáîç array(&$obj, "method_name"). |
Êáëåß ôç ìÝèïäï method_name ôïõ ïñéóìÝíïõ áðü ôï ÷ñÞóôç áíôéêåéìÝíïõ obj, ÷ñçóéìïðïéþíôáò ôéò ðáñáìÝôñïõò ìÝóá óôï paramarr array.
Äåßôå åðßóçò: call_user_func_array(), êáé call_user_func().
Ðñïåéäïðïßçóç |
Ç óõíÜñôçóç call_user_method() åßíáé deprecated áðü ôçí Ýêäïóç PHP 4.1.0. Aíôß áõôÞò ÷ñçóéìïðïéÞóôå ôç call_user_func() ìå ôç óýíôáîç array(&$obj, "method_name"). |
Êáëåß ôç ìÝèïäï method_name ôïõ ïñéóìÝíïõ áðü ôï ÷ñÞóôç áíôéêåéìÝíïõ obj. Áêïëïõèåß Ýíá ðáñÜäåéãìá ôçò ÷ñÞóçò ôçò óõíÜñôçóçò, óôï ïðïßï ïñßæïõìå ìéá êëÜóç, äçìéïõñãïýìå Ýíá óôéãìéüôõðï êáé ÷ñçóéìïðïéïýìå ôç óõíÜñôçóç call_user_method() ãéá íá êáëÝóïõìå Ýììåóá ôç ìÝèïäï print_info.
<?php class Country { var $NAME; var $TLD; function Country($name, $tld) { $this->NAME = $name; $this->TLD = $tld; } function print_info($prestr = "") { echo $prestr . "Country: " . $this->NAME . "\n"; echo $prestr . "Top Level Domain: " . $this->TLD . "\n"; } } $cntry = new Country("Peru", "pe"); echo "* Calling the object method directly\n"; $cntry->print_info(); echo "\n* Calling the same method indirectly\n"; call_user_method("print_info", $cntry, "\t"); ?> |
Äåßôå åðßóçò call_user_func_array(), êáé call_user_func().
Ç óõíÜñôçóç åðéóôñÝöåé TRUE åÜí ç êëÜóç class_name Ý÷åé ïñéóôåß, êáé FALSE åÜí ü÷é.
Äåßôå åðßóçò get_declared_classes().
Ç óõíÜñôçóç åðéóôñÝöåé Ýíá array ìå ôá ïíüìáôá ôùí ìåèüäùí ðïõ Ý÷ïõí ïñéóôåß ãéá ôçí êëÜóç class_name.
Óçìåßùóç: Áðü ôçí Ýêäïóç PHP 4.0.6, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ùò ðáñÜìåôñï ôï ßäéï ôï óôéãìéüôõðï áíôß ôïõ ïíüìáôïò ôçò êëÜóçò class_name. Ãéá ðáñÜäåéãìá:
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá get_class_methods()
Èá ôõðþóåé:
|
Äåßôå åðßóçò get_class_vars() and get_object_vars().
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá associative array ôùí ðñïêáèïñéóìÝíùí ìåôáâëçôþí ôçò êëÜóçò. Ôá óôïé÷åßá ôïõ array ðïõ åðéóôñÝöåôáé åßíáé ôçò ìïñöÞò varname => value.
Óçìåßùóç: Ðñéí áðü ôçí Ýêäïóç PHP 4.2.0, ìåôáâëçôÝò ôçò êëÜóçò ðïõ äåí Ý÷ïõí áñ÷éêïðïéçèåß äåí åðéóôñÝöïíôáé áðü ôçí óõíÜñôçóç get_class_vars().
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá get_class_vars()
Èá ôõðþóåé:
|
Äåßôå åðßóçò get_class_methods(), get_object_vars()
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé ôï üíïìá ôçò êëÜóçò ôçò ïðïßáò ôï áíôéêåßìåíï obj åßíáé Ýíá óôéãìéüôõðï. ÅðéóôñÝöåé FALSE áí ôï obj äåí åßíáé áíôéêåßìåíï.
Óçìåßùóç: Ç óõíÜñôçóç get_class() åðéóôñÝöåé óå ìéêñÜ ãñÜììáôá ôéò êëÜóåéò ðïõ Ý÷ïõí ïñéóôåß áðü ôïí ÷ñÞóôç. Ïé êëÜóåéò ðïõ Ý÷ïõí ïñéóôåß áðü ôçí PHP åðéóôñÝöïíôáé ìå ôï áñ÷éêü ôïõò üíïìá, ÷ùñßò áëëáãÞ óôá êåöáëáßá.
ÐáñÜäåéãìá 1. Using get_class()
Èá ôõðþóåé:
|
Äåßôå åðßóçò get_parent_class(), gettype(), êáé is_subclass_of().
(PHP 4 , PHP 5)
get_declared_classes -- ÅðéóôñÝöåé Ýíá array ìå ôá ïíüìáôá ôùí êëÜóåùí ðïõ Ý÷ïõí ïñéóôåßÇ óõíÜñôçóç åðéóôñÝöåé Ýíá array ìå ôá ïíüìáôá ôùí êëÜóåùí ðïõ Ý÷ïõí ïñéóôåß óå áõôü ôï script.
Óçìåßùóç: Óôçí Ýêäïóç PHP 4.0.1pl2, ôñåéò åðéðëÝïí êëÜóåéò åðéóôñÝöïíôáé óôçí áñ÷Þ ôïõ array: stdClass (ïñéóìÝíç óôï Zend/zend.c), OverloadedTestClass (ïñéóìÝíç óôï ext/standard/basic_functions.c) êáé Directory (ïñéóìÝíç óôï ext/standard/dir.c).
Óçìåéþóôå åðßóçò üôé áíáëüãùò ôùí libraries ðïõ Ý÷åôå êÜíåé compile óôçí PHP, åðéðñüóèåôåò êëÜóåéò ìðïñåß íá åßíáé ðáñïýóåò. Áõôü óçìáßíåé üôé äåí èá ìðïñåßôå íá ïñßóåôå äéêÝò óáò êëÜóåéò ìå áõôÜ ôá ïíüìáôá. ÕðÜñ÷åé ìéá ëßóôá ìå ôá ïíüìáôá ôùí ðñïêáèïñéóìÝíùí êëÜóåùí óôï êåöÜëáéï ÐñïêáèïñéóìÝíåò ÊëÜóåéò óôéò ÐñïóèÞêåò.
Äåßôå åðßóçò class_exists().
This function returns an array of the names of the declared interfaces in the current script.
ÐáñÜäåéãìá 1. get_declared_interfaces() example
The above example will output something similar to: :
|
(PHP 4 , PHP 5)
get_object_vars -- ÅðéóôñÝöåé Ýíá associative array ìå ôéò ìåôáâëçôÝò ôïõ áíôéêåéìÝíïõÇ óõíÜñôçóç åðéóôñÝöåé Ýíá associative array ìå ôéò ìåôáâëçôÝò ðïõ Ý÷ïõí ïñéóôåß óôï áíôéêåßìåíïobj.
Óçìåßùóç: Óôéò åêäüóåéò ðñéí áðü ôçí PHP 4.2.0, åÜí ïé ìåôáâëçôÝò ôçò êëÜóçò ôçò ïðïßáò ôï áíôéêåßìåíï obj åßíáé Ýíá óôéãìéüôõðï äåí Ý÷ïõí áñ÷éêïðïéçèåß, ôüôå äåí åðéóôñÝöïíôáé óôï array. Óôéò åêäüóåéò ìåôÜ ôçí PHP 4.2.0, óôï áíôßóôïé÷ï êëåéäß ôïõ array èá áíáôåèåß ç ôéìÞ NULL.
ÐáñÜäåéãìá 1. ×ñÞóç ôçò óõíÜñôçóçò get_object_vars()
Ôï ðéï ðÜíù ðñüãñáììá èá ôõðþóåé:
|
Äåßôå åðßóçò get_class_methods() êáé get_class_vars().
(PHP 4 , PHP 5)
get_parent_class -- ÅðéóôñÝöåé ôï üíïìá ôçò õðåñêëÜóçò ãéá ôï áíôéêåßìåíï Þ ôçí êëÜóçÅÜí ôï obj åßíáé áíôéêåßìåíï, ç óõíÜñôçóç åðéóôñÝöåé ôï üíïìá ôçò õðåñêëÜóçò ôçò êëÜóçò ôçò ïðïßáò ôï obj åßíáé óôéãìéüôõðï.
ÅÜí ôï obj åßíáé string, ç óõíÜñôçóç åðéóôñÝöåé ôï üíïìá ôçò õðåñêëÜóçò ôçò êëÜóçò ìå ôï üíïìá ðïõ õðïäåéêíýåôáé áðü ôï string. Ç ëåéôïõñãéêüôçôá áõôÞ Ý÷åé ðñïóôåèåß áðü ôçí Ýêäïóç PHP 4.0.5.
ÐáñÜäåéãìá 1. ×ñÞóç ôçò óõíÜñôçóçò get_parent_class()
Ôï ðñüãñáììá èá ôõðþóåé:
|
Äåßôå åðßóçò get_class() êáé is_subclass_of().
(PHP 4 >= 4.2.0, PHP 5)
is_a -- ÅðéóôñÝöåé TRUE åÜí ôï áíôéêåßìåíï åßíáé áõôÞò ôçò êëÜóçò Þ åÜí áõôÞ ç êëÜóç åßíáé õðåñêëÜóç ôïõ áíôéêåéìÝíïõ.Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé TRUE åÜí ôï áíôéêåßìåíï åßíáé áõôÞò ôçò êëÜóçò Þ åÜí áõôÞ ç êëÜóç åßíáé õðåñêëÜóç ôïõ áíôéêåéìÝíïõ, åéäÜëëùò åðéóôñÝöåé FALSE.
Äåßôå åðßóçò get_class(), get_parent_class(), êáé is_subclass_of().
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé TRUE åÜí ôï áíôéêåßìåíï object áíÞêåé óå êëÜóç ç ïðïßá åßíáé õðïêëÜóç ôçò class_name, åéäÜëëùò åðéóôñÝöåé FALSE.
Äåßôå åðßóçò get_class(), get_parent_class() êáé is_a().
ClibPDF lets you create PDF documents with PHP. ClibPDF functionality and API are similar to PDFlib. This documentation should be read alongside the ClibPDF manual since it explains the library in much greater detail.
Many functions in the native ClibPDF and the PHP module, as well as in PDFlib, have the same name. All functions except for cpdf_open() take the handle for the document as their first parameter.
Currently this handle is not used internally since ClibPDF does not support the creation of several PDF documents at the same time. Actually, you should not even try it, the results are unpredictable. I can't oversee what the consequences in a multi threaded environment are. According to the author of ClibPDF this will change in one of the next releases (current version when this was written is 1.10). If you need this functionality use the pdflib module.
A nice feature of ClibPDF (and PDFlib) is the ability to create the pdf document completely in memory without using temporary files. It also provides the ability to pass coordinates in a predefined unit length. (This feature can also be simulated by pdf_translate() when using the PDFlib functions.)
Another nice feature of ClibPDF is the fact that any page can be modified at any time even if a new page has been already opened. The function cpdf_set_current_page() allows to leave the current page and presume modifying an other page.
Most of the functions are fairly easy to use. The most difficult part is probably creating a very simple PDF document at all. The following example should help you to get started. It creates a document with one page. The page contains the text "Times-Roman" in an outlined 30pt font. The text is underlined.
Óçìåßùóç: If you're interested in alternative free PDF generators that do not utilize external PDF libraries, see this related FAQ.
In order to use the ClibPDF functions you need to install the ClibPDF package. It is available for download from FastIO, but requires that you purchase a license for commercial use. PHP requires that you use cpdflib >= 2.
To get these functions to work, you have to compile PHP with --with-cpdflib[=DIR]. DIR is the cpdflib install directory, defaults to /usr. In addition you can specify the jpeg library and the tiff library for ClibPDF to use. To do so add to your configure line the options --with-jpeg-dir[=DIR] --with-tiff-dir[=DIR].
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
ÐáñÜäåéãìá 1. Simple ClibPDF Example
|
The pdflib distribution contains a more complex example which creates a series of pages with an analog clock. Here is that example converted into PHP using the ClibPDF extension:
ÐáñÜäåéãìá 2. pdfclock example from pdflib 2.0 distribution
|
The cpdf_add_annotation() adds a note with the lower left corner at (llx, lly) and the upper right corner at (urx, ury). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
The cpdf_add_outline() function adds a bookmark with text text that points to the current page.
The cpdf_arc() function draws an arc with center at point (x-coor, y-coor) and radius radius, starting at angle start and ending at angle end. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_circle().
The cpdf_begin_text() function starts a text section. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. The created text section must be ended with cpdf_end_text().
See also cpdf_end_text().
The cpdf_circle() function draws a circle with center at point (x-coor, y-coor) and radius radius. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_arc().
The cpdf_clip() function clips all drawing to the current path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_close() function closes the pdf document. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. This should be the last function even after cpdf_finalize(), cpdf_output_buffer() and cpdf_save_to_file().
See also cpdf_open().
The cpdf_closepath_fill_stroke() function closes, fills the interior of the current path with the current fill color and draws current path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_closepath(), cpdf_stroke(), cpdf_fill(), cpdf_setgray_fill(), cpdf_setgray(), cpdf_setrgbcolor_fill() and cpdf_setrgbcolor().
The cpdf_closepath_stroke() function is a combination of cpdf_closepath() and cpdf_stroke(). Then clears the path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_closepath() and cpdf_stroke().
The cpdf_closepath() function closes the current path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_continue_text() function outputs the string in text in the next line. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_show_xy(), cpdf_text(), cpdf_set_leading() and cpdf_set_text_pos().
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. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_moveto(), cpdf_rmoveto(), cpdf_rlineto() and cpdf_lineto().
The cpdf_end_text() function ends a text section which was started with cpdf_begin_text(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_begin_text().
The cpdf_fill_stroke() function fills the interior of the current path with the current fill color and draws current path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_closepath(), cpdf_stroke(), cpdf_fill(), cpdf_setgray_fill(), cpdf_setgray(), cpdf_setrgbcolor_fill() and cpdf_setrgbcolor().
The cpdf_fill() function fills the interior of the current path with the current fill color. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_closepath(), cpdf_stroke(), cpdf_setgray_fill(), cpdf_setgray(), cpdf_setrgbcolor_fill() and cpdf_setrgbcolor().
The cpdf_finalize_page() function ends the page with page number page_number. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function is only for saving memory. A finalized page takes less memory but cannot be modified anymore.
See also cpdf_page_init().
The cpdf_finalize() function ends the document. You still have to call cpdf_close(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_close().
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. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_open().
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-coor, y-coor). The image is rotated by angle degrees. gsave should be non-zero to allow this function to operate correctly.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_place_inline_image().
The cpdf_lineto() function draws a line from the current point to the point with coordinates (x-coor, y-coor). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_moveto(), cpdf_rmoveto() and cpdf_curveto().
The cpdf_moveto() function set the current point to the coordinates x-coor and y-coor. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
The cpdf_newpath() starts a new path on the document given by the pdf_document parameter. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
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().
Óçìåßùóç: The return value will be needed in further versions of ClibPDF as the first parameter in all other functions which are writing to the pdf document.
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() and cpdf_output_buffer().
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. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_open().
The cpdf_page_init() function starts a new page with height height and width width. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. 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 coordinate system. The value should be the number of postscript points per unit. Since one inch is equal to 72 points, a value of 72 would set the unit to one inch. The default is also 72.
See also cpdf_set_current_page().
The cpdf_place_inline_image() function places an image created with the PHP image functions on the page at position (x-coor, y-coor). The image can be scaled at the same time. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_import_jpeg().
The cpdf_rect() function draws a rectangle with its lower left corner at point (x-coor, y-coor). This width is set to width. This height is set to height. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
ÐáñÜäåéãìá 1. Drawing a rectangle
|
The cpdf_restore() function restores the environment 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. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_save().
The cpdf_rlineto() function draws a line from the current point to the relative point with coordinates (x-coor, y-coor). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_moveto(), cpdf_rmoveto() and cpdf_curveto().
The cpdf_rmoveto() function set the current point relative to the coordinates x-coor and y-coor. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_moveto().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The cpdf_rotate() function set the rotation in degrees to angle. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_save_to_file() function outputs the pdf document into a file if it has been created in memory. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
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() and cpdf_open().
The cpdf_save() function saves the current environment. It works like the postscript command gsave. Very useful if you want to translate or rotate an object without effecting other objects. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_restore().
The cpdf_scale() function set the scaling factor in both directions. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The cpdf_set_char_spacing() function sets the spacing between characters. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_set_word_spacing() and cpdf_set_leading().
The cpdf_set_creator() function sets the creator of a pdf document. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_set_subject(), cpdf_set_title() and cpdf_set_keywords().
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(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_finalize_page().
(PHP 4 >= 4.0.6, PHP 5)
cpdf_set_font_directories -- Sets directories to search when using external fonts
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.0.6, PHP 5)
cpdf_set_font_map_file -- Sets fontname to filename translation map when using external fonts
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The cpdf_set_font() function sets the current font face, font size and encoding. Currently only the standard postscript fonts are supported. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
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.
The cpdf_set_horiz_scaling() function sets the horizontal scaling to scale percent. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_set_keywords() function sets the keywords of a pdf document. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_set_title(), cpdf_set_creator() and cpdf_set_subject().
The cpdf_set_leading() function sets the distance between text lines. This will be used if text is output by cpdf_continue_text(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_continue_text().
The cpdf_set_page_animation() function set the transition between following pages. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
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.
The cpdf_set_subject() function sets the subject of a pdf document. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_set_title(), cpdf_set_creator() and cpdf_set_keywords().
The cpdf_set_text_matrix() function sets a matrix which describes a transformation applied on the current text font. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_set_text_pos() function sets the position of text for the next cpdf_show() function call. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
See also cpdf_show() and cpdf_text().
The cpdf_set_text_rendering() function determines how text is rendered. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The possible values for rendermode are 0=fill text, 1=stroke text, 2=fill and stroke text, 3=invisible, 4=fill text and add it to clipping path, 5=stroke text and add it to clipping path, 6=fill and stroke text and add it to clipping path, 7=add it to clipping path.
The cpdf_set_text_rise() function sets the text rising to value units. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_set_title() function sets the title of a pdf document. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_set_subject(), cpdf_set_creator() and cpdf_set_keywords().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The cpdf_set_word_spacing() function sets the spacing between words. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_set_char_spacing() and cpdf_set_leading().
The cpdf_setdash() function set the dash pattern white white units and black black units. If both are 0 a solid line is set. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_setflat() function set the flatness to a value between 0 and 100. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_setgray_fill() function sets the current gray value to fill a path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_setrgbcolor_fill().
The cpdf_setgray_stroke() function sets the current drawing color to the given gray value. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_setrgbcolor_stroke().
The cpdf_setgray() function sets the current drawing and filling color to the given gray value. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_setrgbcolor_stroke() and cpdf_setrgbcolor_fill().
The cpdf_setlinecap() function set the linecap parameter between a value of 0 and 2. 0 = butt end, 1 = round, 2 = projecting square. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_setlinejoin() function set the linejoin parameter between a value of 0 and 2. 0 = miter, 1 = round, 2 = bevel. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_setlinewidth() function set the line width to width. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_setmiterlimit() function set the miter limit to a value greater or equal than 1. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The cpdf_setrgbcolor_fill() function sets the current rgb color value to fill a path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The values are expected to be floating point values between 0.0 and 1.0. (i.e black is (0.0, 0.0, 0.0) and white is (1.0, 1.0, 1.0)).
See also cpdf_setrgbcolor_stroke() and cpdf_setrgbcolor().
The cpdf_setrgbcolor_stroke() function sets the current drawing color to the given rgb color value. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The values are expected to be floating point values between 0.0 and 1.0. (i.e black is (0.0, 0.0, 0.0) and white is (1.0, 1.0, 1.0)).
See also cpdf_setrgbcolor_fill() and cpdf_setrgbcolor().
The cpdf_setrgbcolor() function sets the current drawing and filling color to the given rgb color value. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The values are expected to be floating point values between 0.0 and 1.0. (i.e black is (0.0, 0.0, 0.0) and white is (1.0, 1.0, 1.0)).
See also cpdf_setrgbcolor_stroke() and cpdf_setrgbcolor_fill().
The cpdf_show_xy() function outputs the string text at position with coordinates (x-coor, y-coor). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
Óçìåßùóç: The function cpdf_show_xy() is identical to cpdf_text() without the optional parameters.
See also cpdf_text().
The cpdf_show() function outputs the string in text at the current position. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_text(), cpdf_begin_text() and cpdf_end_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().
The cpdf_stroke() function draws a line along current path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also cpdf_closepath() and cpdf_closepath_stroke().
The cpdf_text() function outputs the string text at position with coordinates (x-coor, y-coor). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates 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 aligned.
See the ClibPDF documentation for possible values.
See also cpdf_show_xy().
The cpdf_translate() function set the origin of coordinate system to the point (x-coor, y-coor). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The optional parameter mode determines the unit length. If it is 0 or omitted the default unit as specified for the page is used. Otherwise the coordinates are measured in postscript points disregarding the current unit.
These functions allow you to use the CrackLib library to test the 'strength' of a password. The 'strength' of a password is tested by that checks length, use of upper and lower case and checked against the specified CrackLib dictionary. CrackLib will also give helpful diagnostic messages that will help 'strengthen' the password.
Óçìåßùóç: This extension has been removed as of PHP 5 and moved to the PECL repository.
More information regarding CrackLib along with the library can be found at http://www.crypticide.org/users/alecm/.
In order to use these functions, you must compile PHP with Crack support by using the --with-crack[=DIR] option.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Crack configuration options
Name | Default | Changeable |
---|---|---|
crack.default_dictionary | NULL | PHP_INI_SYSTEM |
This example shows how to open a CrackLib dictionary, test a given password, retrieve any diagnostic messages, and close the dictionary.
ÐáñÜäåéãìá 1. CrackLib example
|
Óçìåßùóç: If crack_check() returns TRUE, crack_getlastmessage() will return 'strong password'.
Returns TRUE if password is strong, or FALSE otherwise.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
crack_check() performs an obscure check with the given password on the specified dictionary . If dictionary is not specified, the last opened dictionary is used.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
crack_closedict() closes the specified dictionary identifier. If dictionary is not specified, the current dictionary is closed.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
crack_getlastmessage() returns the message from the last obscure check.
Returns a dictionary resource identifier on success, or FALSE on failure.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
crack_opendict() opens the specified CrackLib dictionary for use with crack_check().
Óçìåßùóç: Only one dictionary may be open at a time.
See also: crack_check(), and crack_closedict().
PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.
These functions have been added in PHP 4.0.2.
In order to use the CURL functions you need to install the CURL package. PHP requires that you use CURL 7.0.2-beta or higher. PHP will not work with any version of CURL below version 7.0.2-beta. In PHP 4.2.3, you will need CURL version 7.9.0 or higher. From PHP 4.3.0, you will need a CURL version that's 7.9.8 or higher. PHP 5.0.0 will most likely require a CURL version greater than 7.10.5
To use PHP's CURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the "include" directory there should be a folder named "curl" which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the "lib" directory. Beginning with PHP 4.3.0 you can configure PHP to use CURL for URL streams --with-curlwrappers.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy libeay32.dll and ssleay32.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM folder of your Windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM)
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Once you've compiled PHP with CURL support, you can begin using the CURL functions. The basic idea behind the CURL functions is that you initialize a CURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the CURL functions to fetch the example.com homepage into a file:
This function closes a CURL session and frees all resources. The CURL handle, ch, is also deleted.
ÐáñÜäåéãìá 1. Initializing a new CURL session and fetching a webpage
|
See also: curl_init().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns the error number for the last cURL operation on the resource ch, or 0 (zero) if no error occurred.
See also curl_error() and Curl error codes.
(PHP 4 >= 4.0.3, PHP 5)
curl_error -- Return a string containing the last error for the current sessionReturns a clear text error message for the last cURL operation on the resource ch, or '' (the empty string) if no error occurred.
See also curl_errno() and Curl error codes.
This function should be called after you initialize a CURL session and all the options for the session are set. Its purpose is simply to execute the predefined CURL session (given by the ch).
ÐáñÜäåéãìá 1. Initializing a new CURL session and fetching a webpage
|
Óçìåßùóç: If you want to have the result returned instead of it being printed to the browser directly, use the CURLOPT_RETURNTRANSFER option of curl_setopt().
Returns information about the last transfer, opt may be one of the following:
"CURLINFO_EFFECTIVE_URL" - Last effective URL
"CURLINFO_HTTP_CODE" - Last received HTTP code
"CURLINFO_FILETIME" - Remote time of the retrieved document, if -1 is returned the time of the document is unknown
"CURLINFO_TOTAL_TIME" - Total transaction time in seconds for last transfer
"CURLINFO_NAMELOOKUP_TIME" - Time in seconds until name resolving was complete
"CURLINFO_CONNECT_TIME" - Time in seconds it took to establish the connection
"CURLINFO_PRETRANSFER_TIME" - Time in seconds from start until just before file transfer begins
"CURLINFO_STARTTRANSFER_TIME" - Time in seconds until the first byte is about to be transferred
"CURLINFO_REDIRECT_TIME" - Time in seconds of all redirection steps before final transaction was started
"CURLINFO_SIZE_UPLOAD" - Total number of bytes uploaded
"CURLINFO_SIZE_DOWNLOAD" - Total number of bytes downloaded
"CURLINFO_SPEED_DOWNLOAD" - Average download speed
"CURLINFO_SPEED_UPLOAD" - Average upload speed
"CURLINFO_HEADER_SIZE" - Total size of all headers received
"CURLINFO_REQUEST_SIZE" - Total size of issued requests, currently only for HTTP requests
"CURLINFO_SSL_VERIFYRESULT" - Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
"CURLINFO_CONTENT_LENGTH_DOWNLOAD" - content-length of download, read from Content-Length: field
"CURLINFO_CONTENT_LENGTH_UPLOAD" - Specified size of upload
"CURLINFO_CONTENT_TYPE" - Content-type of downloaded object, NULL indicates server did not send valid Content-Type: header
If called without the optional parameter opt an associative array is returned with the following array elements which correspond to opt options:
"url"
"content_type"
"http_encode"
"header_size"
"request_size"
"filetime"
"ssl_verify_result"
"redirect_count"
"total_time"
"namelookup_time"
"connect_time"
"pretransfer_time"
"size_upload"
"size_download"
"speed_download"
"speed_upload"
"download_content_length"
"upload_content_length"
"starttransfer_time"
"redirect_time"
The curl_init() will initialize a new session and return a CURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions. If the optional url parameter is supplied then the CURLOPT_URL option will be set to the value of the parameter. You can manually set this using the curl_setopt() function.
ÐáñÜäåéãìá 1. Initializing a new CURL session and fetching a webpage
|
See also: curl_close(), curl_setopt()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_multi_init(), curl_init(), and curl_multi_remove_handle().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_multi_init() and curl_close().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_multi_init() and curl_exec().
(PHP 5)
curl_multi_getcontent -- Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is setÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_multi_init().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_multi_init().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_init() and curl_multi_close().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_multi_init(), curl_init(), and curl_multi_add_handle().
(PHP 5)
curl_multi_select -- Get all the sockets associated with the cURL extension, which can then be "selected"Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also curl_multi_init().
The curl_setopt() function will set options for a CURL session identified by the ch parameter. The option parameter is the option you want to set, and the value is the value of the option given by the option.
The value should be a long for the following options (specified in the option parameter):
CURLOPT_INFILESIZE: When you are uploading a file to a remote site, this option should be used to tell PHP what the expected size of the infile will be.
CURLOPT_VERBOSE: Set this option to a non-zero value if you want CURL to report everything that is happening.
CURLOPT_HEADER: Set this option to a non-zero value if you want the header to be included in the output.
CURLOPT_NOPROGRESS: Set this option to a non-zero value if you don't want PHP to display a progress meter for CURL transfers.
Óçìåßùóç: PHP automatically sets this option to a non-zero parameter, this should only be changed for debugging purposes.
CURLOPT_NOBODY: Set this option to a non-zero value if you don't want the body included with the output.
CURLOPT_FAILONERROR: Set this option to a non-zero value if you want PHP to fail silently if the HTTP code returned is greater than 300. The default behavior is to return the page normally, ignoring the code.
CURLOPT_UPLOAD: Set this option to a non-zero value if you want PHP to prepare for an upload.
CURLOPT_POST: Set this option to a non-zero value if you want PHP to do a regular HTTP POST. This POST is a normal application/x-www-form-urlencoded kind, most commonly used by HTML forms.
CURLOPT_FTPLISTONLY: Set this option to a non-zero value and PHP will just list the names of an FTP directory.
CURLOPT_FTPAPPEND: Set this option to a non-zero value and PHP will append to the remote file instead of overwriting it.
CURLOPT_NETRC: Set this option to a non-zero value and PHP will scan your ~./netrc file to find your username and password for the remote site that you're establishing a connection with.
CURLOPT_FOLLOWLOCATION: Set this option to a non-zero value to follow any "Location: " header that the server sends as a part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent.)
CURLOPT_PUT: Set this option to a non-zero value to HTTP PUT a file. The file to PUT must be set with the CURLOPT_INFILE and CURLOPT_INFILESIZE.
CURLOPT_MUTE: Set this option to a non-zero value and PHP will be completely silent with regards to the CURL functions.
CURLOPT_TIMEOUT: Pass a long as a parameter that contains the maximum time, in seconds, that you'll allow the CURL functions to take.
CURLOPT_LOW_SPEED_LIMIT: Pass a long as a parameter that contains the transfer speed in bytes per second that the transfer should be below during CURLOPT_LOW_SPEED_TIME seconds for PHP to consider too slow and abort.
CURLOPT_LOW_SPEED_TIME: Pass a long as a parameter that contains the time in seconds that the transfer should be below the CURLOPT_LOW_SPEED_LIMIT for PHP to consider it too slow and abort.
CURLOPT_RESUME_FROM: Pass a long as a parameter that contains the offset, in bytes, that you want the transfer to start from.
CURLOPT_CAINFO: Pass a filename of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with the CURLOPT_SSL_VERIFYPEER option.
CURLOPT_SSL_VERIFYPEER: Pass a long that is set to a zero value to stop curl from verifying the peer's certificate (curl 7.10 starting setting this option to TRUE by default). Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option (added in curl 7.9.8) or a certificate directory can be specified with the CURLOPT_CAPATH option. As of curl 7.10, curl installs a default bundle. CURLOPT_SSL_VERIFYHOST may also need to be set to 1 or 0 if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2).
CURLOPT_SSLVERSION: Pass a long as a parameter that contains the SSL version (2 or 3) to use. By default PHP will try and determine this by itself, although, in some cases you must set this manually.
CURLOPT_SSL_VERIFYHOST: Pass a long if CURL should verify the Common name of the peer certificate in the SSL handshake. A value of 1 denotes that we should check for the existence of the common name, a value of 2 denotes that we should make sure it matches the provided hostname.
CURLOPT_TIMECONDITION: Pass a long as a parameter that defines how the CURLOPT_TIMEVALUE is treated. You can set this parameter to TIMECOND_IFMODSINCE or TIMECOND_ISUNMODSINCE. This is a HTTP-only feature.
CURLOPT_TIMEVALUE: Pass a long as a parameter that is the time in seconds since January 1st, 1970. The time will be used as specified by the CURLOPT_TIMECONDITION option, or by default the TIMECOND_IFMODSINCE will be used.
CURLOPT_RETURNTRANSFER: Pass a non-zero value if you want CURL to directly return the transfer instead of printing it out directly.
The value parameter should be a string for the following values of the option parameter:
CURLOPT_URL: This is the URL that you want PHP to fetch. You can also set this option when initializing a session with the curl_init() function.
CURLOPT_USERPWD: Pass a string formatted in the [username]:[password] manner, for PHP to use for the connection.
CURLOPT_PROXYUSERPWD: Pass a string formatted in the [username]:[password] format for connection to the HTTP proxy.
CURLOPT_RANGE: Pass the specified range you want. It should be in the "X-Y" format, where X or Y may be left out. The HTTP transfers also support several intervals, separated with commas as in X-Y,N-M.
CURLOPT_POSTFIELDS: Pass a string containing the full data to post in an HTTP "POST" operation.
CURLOPT_REFERER: Pass a string containing the "referer" header to be used in an HTTP request.
CURLOPT_USERAGENT: Pass a string containing the "user-agent" header to be used in an HTTP request.
CURLOPT_FTPPORT: Pass a string containing the value which will be used to get the IP address to use for the ftp "POST" instruction. The POST instruction tells the remote server to connect to our specified IP address. The string may be a plain IP address, a hostname, a network interface name (under Unix), or just a plain '-' to use the systems default IP address.
CURLOPT_COOKIE: Pass a string containing the content of the cookie to be set in the HTTP header.
CURLOPT_SSLCERT: Pass a string containing the filename of PEM formatted certificate.
CURLOPT_SSLCERTPASSWD: Pass a string containing the password required to use the CURLOPT_SSLCERT certificate.
CURLOPT_COOKIEFILE: Pass a string containing the name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain HTTP-style headers dumped into a file.
CURLOPT_CUSTOMREQUEST: Pass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing DELETE or other, more obscure, HTTP requests. Valid values are things like GET, POST, and so on; i.e. do not enter a whole HTTP request line here. For instance, entering 'GET /index.html HTTP/1.0\r\n\r\n' would be incorrect.
Óçìåßùóç: Don't do this without making sure your server supports the command first.
CURLOPT_PROXY: Give the name of the HTTP proxy to tunnel requests through.
CURLOPT_INTERFACE: Pass the name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.
CURLOPT_KRB4LEVEL: Pass the KRB4 (Kerberos 4) security level. Any of the following values (in order from least to most powerful) are valid: 'clear', 'safe', 'confidential', 'private'. If the string does not match one of these, then 'private' is used. Setting this Option to NULL, will disable KRB4 security. Currently KRB4 security only works with FTP transactions.
CURLOPT_HTTPHEADER: Pass an array of HTTP header fields to set.
CURLOPT_QUOTE: Pass an array of FTP commands to perform on the server prior to the FTP request.
CURLOPT_POSTQUOTE: Pass an array of FTP commands to execute on the server, after the FTP request has been performed.
The following options expect a file descriptor that is obtained by using the fopen() function:
CURLOPT_FILE: The file where the output of your transfer should be placed, the default is STDOUT.
CURLOPT_INFILE: The file where the input of your transfer comes from.
CURLOPT_WRITEHEADER: The file to write the header part of the output into.
CURLOPT_STDERR: The file to write errors to instead of stderr.
ÐáñÜäåéãìá 1. Initializing a new CURL session and fetching a webpage
|
These functions are only available if the interpreter has been compiled with the --with-cybercash=[DIR].
This extension has been moved from PHP as of PHP 4.3.0 and now CyberCash lives in PECL.
If you have questions as to the latest status of CyberCash then the following CyberCash Faq will be helpful. In short, CyberCash was bought out by VeriSign and although the CyberCash service continues to exist, VeriSign encourages users to switch. See the above faq and PECL link for details.
The function returns an associative array with the elements "errcode" and, if "errcode" is FALSE, "outbuff" (string), "outLth" (long) and "macbuff" (string).
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
To enable Cyrus IMAP support and to use these functions you have to compile PHP with the --with-cyrus option.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ïé ðáñå÷üìåíåò óõíáñôÞóåéò áõôÞò ôçò extension åëÝã÷ïõí åÜí Ýíáò ÷áñáêôÞñáò Þ string áíÞêåé óå ìßá óõãêåêñéìÝíç character class óýöìùíá ìå ôï éó÷ýïí locale (áíáôñÝîôå åðßóçò óôç setlocale()).
¼ôáí êáëïýíôáé ìå ðáñÜìåôñï ôýðïõ integer, óõìðåñéöÝñïíôáé áêñéâþò üðùò ïé áíôßóôïé÷Ýò ôïõò ôçò C óôï header áñ÷åßï "ctype.h".
¼ôáí êáëïýíôáé ìå ðáñÜìåôñï ôýðïõ string, ôï åëÝã÷ïõí êáé åðéóôñÝöïõí TRUE ìüíï åÜí êÜèå ÷ñáêôÞñáò áíôáðïêñßíåôáé óôá äåäïìÝíá êñéôßñéá. ¼ôáí êáëïýíôáé ìå empty string ôï áðïôÝëåóìá åßíáé ðÜíôá TRUE.
Ðåñíþíôáò ïôéäÞðïôå Üëëï åêôüò áðü string Þ integer åðéóôñÝöåôáé áìÝóùò FALSE.
Êáìßá, áðáßôçóç, åêôüò áðü ôéò óõíáñôÞóåéò ôçò standard C library ðïõ åßíáé ðÜíôá äéáèÝóéìåò.
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text åßíáé åßôå ãñÜììá åßôå øçößï, áëëéþò FALSE. Óôç standard C ùò ãñÜììáôá èåùñïýíôáé ôá [A-Za-z]. Ç óõíÜñôçóç åßíáé éóïäýíáìç ìå (ctype_alpha($text) || ctype_digit($text)).
ÁíáôñÝîôå åðßóçò óôéò: ctype_alpha(), ctype_digit(), êáé setlocale().
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text åßíáé åßíáé ãñÜììá, áëëéþò FALSE. Óôç standard C ùò ãñÜììáôá èåùñïýíôáé ôá [A-Za-z]. Ç ctype_alpha() åßíáé éóïäýíáìç ìå (ctype_upper($text) || ctype_lower($text)), ÁëëÜ Üëëåò ãëþóóåò Ý÷ïõí ãñÜììáôá ðïõ äå èåùñïýíôáé ïýôå êåöáëÜéá ïýôå ìéêñÜ.
ÁíáôñÝîôå åðßóçò óôéò: ctype_upper(), ctype_lower(), êáé setlocale().
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text Ý÷åé ìßá óõãêåêñéìÝíç control ëåéôïõñãßá, áëëéþò FALSE. ×áñáêôÞñåò control åßíáé ð.÷. ïé line feed, tab, esc.
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text åßíáé äåêáäéêü øçößï, áëëéþò FALSE.
ÁíáôñÝîôå åðßóçò óôéò: ctype_alnum() êáé ctype_xdigit().
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷ñáêôÞñáò ôçò text åßíáé åêôõðþóéìïò, äßíåé, äçëáäÞ, ìßá ïñáôÞ Ýîïäï (ü÷é ôï space), áëëéþò Ý÷ïõìå FALSE.
ÁíáôñÝîôå åðßóçò óôéò: ctype_alnum(), ctype_print(), êáé ctype_punct().
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text åßíáé ìéêñü ãñÜììá ([a-z]).
ÁíáôñÝîôå åðßóçò óôéò: ctype_alpha() êáé ctype_upper().
ÅðóéôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text äßíåé Ýîïäï (óõðåñéëáìâáíïìÝíùí êáé ôùí êåíþí). ÅðéóôñÝöåé FALSE åÜí ç text ðåñéëáìâÜíåé ÷áñáêôÞñåò control Þ ÷áñáêôÞñåò ðïõ äåí Ý÷ïõí êáèüëïõ Ýîïäï Þ ëåéôïõñãßá control.
ÁíáôñÝîôå åðßóçò óôéò: ctype_cntrl(), ctype_graph(), êáé ctype_punct().
(PHP 4 >= 4.0.4, PHP 5)
ctype_punct -- ¸ëåã÷ïò ãéá êÜèå åêôõðþóéìï ÷áñáêôÞñá ðïõ äåí åßíáé whitespace Þ áëöáñéèìçôéêüÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text åßíáé åêôõðþóéìïò, áëëÜ êáíÝíáò äåí åßíáé ãñÜììá, øçößï Þ êåíü. Óôçí áíôßèåôç ðåñßðôùóç åðéóôñÝöåé FALSE.
ÁíáôñÝîôå åðßóçò óôéò: ctype_cntrl(), ctype_graph(), êáé ctype_punct().
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text äßíåé Ýíá åßäïò white space, áëëéþò FALSE. Åêôüò áðü ôïí ÷áñáêôÞñá blank ðåñéëáìâÜíïíôáé êáé ïé ÷áñáêôÞñåò tab, vertical tab, line feed, carriage return êáé form feed.
ÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text åßíáé êåöáëáßï ãñÜììá ([A-Z]).
ÁíáôñÝîôå åðßóçò óôéò: ctype_alpha() êáé ctype_lower().
(PHP 4 >= 4.0.4, PHP 5)
ctype_xdigit -- ¸ëåã÷ïò ãéá ÷áñáêôÞñåò ðïõ áíáðáñéóôïýí Ýíá äåêáåîáäéêü øçößïÅðéóôñÝöåé TRUE åÜí êÜèå ÷áñáêôÞñáò ôçò text åßíáé Ýíá äåêáåîáäéêü 'øçößï', ðïõ áíáðáñéóôÜôáé áðü Ýíá äåêáäéêü øçößï Þ Ýíá ÷áñáêôÞñá áðü ôïõò [A-Fa-f] , áëëéþò FALSE.
ÁíáôñÝîôå åðßóçò óôç ctype_digit().
These functions build the foundation for accessing Berkeley DB style databases.
This is a general abstraction layer for several file-based databases. As such, functionality is limited to a common subset of features supported by modern databases such as Sleepycat Software's DB2. (This is not to be confused with IBM's DB2 software, which is supported through the ODBC functions.)
The behaviour of various aspects depends on the implementation of the underlying database. Functions such as dba_optimize() and dba_sync() will do what they promise for one database and will do nothing for others. You have to download and install supported dba-Handlers.
Ðßíáêáò 1. List of DBA handlers
Handler | Notes |
---|---|
dbm | Dbm is the oldest (original) type of Berkeley DB style databases. You should avoid it, if possible. We do not support the compatibility functions built into DB2 and gdbm, because they are only compatible on the source code level, but cannot handle the original dbm format. |
ndbm | Ndbm is a newer type and more flexible than dbm. It still has most of the arbitrary limits of dbm (therefore it is deprecated). |
gdbm | Gdbm is the GNU database manager. |
db2 | DB2 is Sleepycat Software's DB2. It is described as "a programmatic toolkit that provides high-performance built-in database support for both standalone and client/server applications. |
db3 | DB3 is Sleepycat Software's DB3. |
db4 | DB4 is Sleepycat Software's DB4. This is available since PHP 4.3.2. |
cdb | Cdb is "a fast, reliable, lightweight package for creating and reading constant databases." It is from the author of qmail and can be found at http://cr.yp.to/cdb.html. Since it is constant, we support only reading operations. And since PHP 4.3.0 we support writing (not updating) through the internal cdb library. |
cdb_make | Since PHP 4.3.0 we support creation (not updating) of cdb files when the bundled cdb library is used. |
flatfile | This is available since PHP 4.3.0 for compatibility with the deprecated dbm extension only and should be avoided. However you may use this where files were created in this format. That happens when configure could not find any external library. |
inifile | This is available since PHP 4.3.3 to be able to modify php.ini files from within PHP scripts. When working with ini files you can pass arrays of the form array(0=>group,1=>value_name) or strings of the form "[group]value_name" where group is optional. As the functions dba_firstkey() and dba_nextkey() return string representations of the key there is a new function dba_key_split() available since PHP 5 which allows to convert the string keys into array keys without loosing FALSE. |
qdbm | This is available since PHP 5.0.0. The qdbm library can be loaded from http://qdbm.sourceforge.net. |
When invoking the dba_open() or dba_popen() functions, one of the handler names must be supplied as an argument. The actually available list of handlers is displayed by invoking phpinfo() or dba_handlers().
By using the --enable-dba=shared configuration option you can build a dynamic loadable module to enable PHP for basic support of dbm-style databases. You also have to add support for at least one of the following handlers by specifying the --with-XXXX configure switch to your PHP configure line.
Ðñïåéäïðïßçóç |
After configuring and compiling PHP you must execute the following test from commandline: php run-tests.php ext/dba. This shows whether your combination of handlers works. Most problematic are dbm and ndbm which conflict with many installations. The reason for this is that on several systems these libraries are part of more than one other library. The configuration test only prevents you from configuring malfaunctioning single handlers but not combinations. |
Ðßíáêáò 2. Supported DBA handlers
Handler | Configure Switch |
---|---|
dbm |
To enable support for dbm add
--with-dbm[=DIR].
|
ndbm |
To enable support for ndbm add
--with-ndbm[=DIR].
|
gdbm | To enable support for gdbm add --with-gdbm[=DIR]. |
db2 |
To enable support for db2 add
--with-db2[=DIR].
|
db3 |
To enable support for db3 add
--with-db3[=DIR].
|
db4 |
To enable support for db4 add
--with-db4[=DIR].
|
cdb |
To enable support for cdb add
--with-cdb[=DIR].
|
flatfile |
To enable support for flatfile add
--with-flatfile.
|
inifile |
To enable support for inifile add
--with-inifile.
|
qdbm |
To enable support for qdbm add
--with-qdbm[=DIR].
|
Óçìåßùóç: Up to PHP 4.3.0 you are able to add both db2 and db3 handler but only one of them can be used internally. That means that you cannot have both file formats. Starting with PHP 5.0.0 there is a configuration check avoid such missconfigurations.
The functions dba_open() and dba_popen() return a handle to the specified database file to access which is used by all other dba-function calls.
DBA is binary safe and does not have any arbitrary limits. However, it inherits all limits set by the underlying database implementation.
All file-based databases must provide a way of setting the file mode of a new created database, if that is possible at all. The file mode is commonly passed as the fourth argument to dba_open() or dba_popen().
You can access all entries of a database in a linear way by using the dba_firstkey() and dba_nextkey() functions. You may not change the database while traversing it.
ÐáñÜäåéãìá 2. Traversing a database
|
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(), and dba_popen()
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(), and dba_replace().
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(), and dba_replace().
dba_fetch() fetches the data specified by key from the database specified with handle.
Key is the key the data is specified by.
Skip is the number of key-value pairs to ignore when using cdb databases. This value is ignored for all other databases which do not support multiple keys with the same name.
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.
Óçìåßùóç: The skip parameter is available since PHP 4.3 to support cdb's capability of multiple keys having the same name.
Óçìåßùóç: When working with inifiles this function accepts arrays as keys where index 0 is the group and index 1 is the value name. See: dba_key_split().
See also dba_exists(), dba_delete(), dba_insert(), dba_replace() and dba_key_split().
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_key_split() and example 2 in the DBA examples
dba_handlers() returns an array with all handlers supported by this extension.
When the internal cdb library is used you will see 'cdb' and 'cdb_make'.
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_key_split() returns an array of the form array(0=>group,1=>value_name). This function will return FALSE if key is NULL or FALSE.
key is the key in string representation.
See also dba_firstkey(), dba_nextkey(), and dba_fetch().
dba_list() returns an associative array with all open database files. This array is in the form: resourceid=>filename.
dba_nextkey() returns the next key of the database specified by handle and advances 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_key_split() and example 2 in the DBA examples
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. Additional you can set the database lock method with the next char. Use "l" to lock the database with an .lck file or "d" to lock the databasefile itself. It is important that all of your applications do this consistently. If you want to test the access and do not want to wait for the lock you can add "t" as third character. When you are absolutely sure that you do not require database locking you can do so by using "-" instead of "l" or "d". When none of "d", "l" or "-" is used dba will lock on the database file as it would with "d".
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 handle or FALSE, in the case the database was opened successfull or fails, respectively.
Óçìåßùóç: There can only be one writer for one database file. When you use dba on a webserver and more than one request requires write operations they can only be done one after another. Also read during write is not allowed. The dba extension uses locks to prevent this. See the following table:
Ðßíáêáò 1. DBA locking
already open mode = "rl" mode = "rlt" mode = "wl" mode = "wlt" mode = "rd" mode = "rdt" mode = "wd" mode = "wdt" not open ok ok ok ok ok ok ok ok mode = "rl" ok ok wait false illegal illegal illegal illegal mode = "wl" wait false wait false illegal illegal illegal illegal mode = "rd" illegal illegal illegal illegal ok ok wait false mode = "wd" illegal illegal illegal illegal wait false wait false
ok: the second call will be successfull. wait: the second call waits until dba_close() is called for the first. false: the second call returns false. illegal: you must not mix "l" and "d" modifiers for mode parameter.
Óçìåßùóç: Since PHP 4.3.0 it is possible to open database files over network connection. However in cases a socket connection will be used (as with http or ftp) the connection will be locked instead of the resource itself. This is important to know since in such cases locking is simply ignored on the resource and other solutions have to be found.
Óçìåßùóç: Locking and the mode modifiers "l", "d", "-" and "t" were added in PHP 4.3.0. In PHP versions before PHP 4.3.0 you must use semaphores to guard against simultaneous database access for any database handler with the exception of GDBM. See System V semaphore support.
Óçìåßùóç: Up to PHP 4.3.5 open mode 'c' is broken for several internal handlers and truncates the database instead of appending data to an existant database. Also dbm and ndbm fail on mode 'c' in typical configurations (this cannot be fixed).
See also dba_popen(), and dba_close()
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_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 handle or FALSE, in the case the open is successful or fails, respectively.
See also: dba_open() dba_close()
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(), and dba_insert().
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()
ÁõôÝò ïé óõíáñôÞóåéò óáò åðéóôñÝðïõí íá ðñïóäéïñßóåôå ôçí çìåñïìçíßá êáé þñá ôïõ server óôïí ïðïßï ôñÝ÷ïõí ôá PHP scripts óáò. Ìðïñåßôå íá ôéò ÷ñçóéìïðïéåßóåôå ãéá íá ðáñïõóéÜóåôå ôçí çìåñïìçíßá êáé þñá ìå ðïéêßëïõò ôñüðïõò.
Óçìåßùóç: Ðáñáêáëåßóôå íá èõìÜóôå üôé ïé óõíáñôÞóåéò áõôÝò åîáñôüíôáé áðü ôéò ôïïðéêÝò ñõèìßóåéò ôïõ server óáò. ËÜâåôáé õðüøéí ôç èåñéíÞ þñá êáé ôá äßóåêôá Ýôç êáèþò ôéò ÷ñçóéìïðïéåßôå.
ÅðéóôñÝöåé TRUE åÜí åßíáé Ýãêõñç ç äïèåßóá çìåñïìçíßá, áëëéþò åðéóôñÝöåé FALSE. Ç åãêõñüôçôá åëÝã÷åôáé ìÝóù ôùí ðáñáìÝôñùí. Ìßá çìåñïìçíßá èåùñåßôáé Ýãêõñç åÜí:
ç year åßíáé ìåôáîý 1 êáé 32767 (óõìðåñéëáìâáíïìÝíùí ôùí Üêñùí)
ç month åßíáé ìåôáîý 1 êáé 12 (óõìðåñéëáìâáíïìÝíùí ôùí Üêñùí)
Ç Day åßíáé ìåôáîý ôïõ áñéèìïý ôùí çìåñþí ôïõ äïèÝíôïò month. Ôá äßóåêôá years ëáìâÜíïíôáé õðüøéí.
ÁíáôñÝîôå åðßóçò óôéò: mktime() êáé strtotime().
ÅðéóôñÝöåé Ýíá string ó÷çìáôéóìÝíï áíÜëïãá ìå ôï äïèÝí format string, ÷ñçóéìïðïéþíôáò ôç äïèåßóá integer ðáñÜìåôñï timestamp Þ ôçí ôïðéêÞ þñá Ýíá äåí Ý÷åé äïèåß timestamp.
Óçìåßùóç: Ôï Ýãêõñï ðåäßï ôéìþí ãéá Ýíá timestamp åßíáé ôõðéêÜ áðü Fri, 13 Dec 1901 20:45:54 GMT Ýùò Tue, 19 Jan 2038 03:14:07 GMT. (ÁõôÝò åßíáé ïé çìåñïìçíßåò ðïõ áíôéóôïé÷ïýí óôçí åëÜ÷éóôç êáé ìÝãéóôç ôéìÞ, áíôßóôïé÷á, åíüò ðñïóçìáóìÝíïõ integer ôùí 32-bit). Óôá windows ôï ðåäßï ðåñéïñßæåôáé áðü ôçí 01-01-1970 Ýùò ôéò 19-01-2038.
Ãéá íá äçìéïõñãåßóåôå Ýíá timestamp áðü ìßá çìåñïìçíßá ðïõ áíáðáñßóôáôáé áðü string, ìðïñåßôå íá ÷ñçóéìïðïéåßóåôå ôç óõíÜñôçóç strtotime(). ÅðéðëÝïí, ìåñéêÝò âÜóåéò äåäïìÝíùí Ý÷ïõí óõíáñôÞóåéò ãéá íá ðåôáôñÝðïõí ôéò çìåñïìçíßåò óå timestamps (üðùò ç óõíÜñôçóç UNIX_TIMESTAMP ôçò MySQL).
Ïé áêüëïõèïé ÷áñáêôÞñåò áíáãíùñßæïíôáé áðü ôï format string:
a - "am" Þ "pm"
A - "AM" Þ "PM"
B - Swatch Internet time
d - çìÝñá ôïõ ìÞíá, 2 øçößá ìå çãåôéêÜ ìçäåíéêÜ ("01" Ýùò "31").
D - çìÝñá ôçò åâäïìÜäáò, ðáñáôßèåôáé ìå 3 ãñÜììáôá. ð.÷. "Fri"
F - ìÞíáò, ðáñáôßèåôáé ôï ðëÞñåò üíïìá. ð.÷. "January"
g - þñá, óå 12ùñç ìïñöÞ ÷ùñßò çãåôéêÜ ìçäåíéêÜ ("1" Ýùò "12").
G - þñá, 24ùñç ìïñöÞ ÷ùñßò çãåôéêÜ ìçäåíéêÜ ("0" Ýùò "23").
h - þñá, 12ùñç ìïñöÞ ("01" Ýùò "12").
H - þñá, 24ùñç ìïñöÞ ("00" Ýùò "23").
i - ëåðôÜ ("00" Ýùò "59").
I (êåöáëáßï i) - "1" åÜí åßíáé ÈåñéíÞ ¿ñá, áëëéþò "0".
j - çìÝñá ôïõ ìÞíá ÷ùñßò çãåôéêÜ ìçäåíéêÜ ("1" Ýùò "31").
l (ìéêñü 'L') - çìÝñá ôçò åâäïìÜäáò, ðáñáôßèåôáé ôï ðëÞñåò üíïìá. ð.÷. "Friday"
L - boolean ãéá ôï áí åßíáé äßóåêôï Ýôïò ("0" Þ "1").
m - ìÞíáò ("01" Ýùò "12").
M - ìÞíáò, ðáñáôßèåôáé ìå 3 ãñÜììáôá. ð.÷. "Jan"
n - ìÞíáò ÷ùñßò çãåôéêÜ ìçäåíéêÜ ("1" Ýùò "12").
O - äéáöïñÜ ìå ôçí Greenwich time óå þñåò. ð.÷. "+0200"
r - çìåñïìçíßá óå ìïñöÞ RFC 822; ð.÷g. "Thu, 21 Dec 2000 16:01:07 +0200" (ðñïóôÝèçêå óôçí PHP 4.0.4)
s - äåõôåñüëåðôá ("00" Ýùò "59")
S - ôï áããëéêï ôáêôéêü åðßèåìá ãéá ôçí çìÝñá ôïõ ìÞíá, 2 ÷ñáêôÞôùí ("st", "nd", "rd" Þ "th").
t - ðëÞèïò çìåñþí óôï äïóìÝíï ìÞíá ("28" Ýùò "31").
T - Ç ñýèìéóç æþíçò þñáò ôçò ìç÷áíÞò; ð.÷. "EST" Þ "MDT"
U - äõôåñüëåðôá áðü ôçí Unix Epoch (January 1 1970 00:00:00 GMT)
w - çìÝñá ôçò åâäïìÜäáò, áñéèìçôéêÜ ("0" (ÊõñéáêÞ) to "6" (ÓÜââáôï)).
W - ðëÞèïò åâäïìÜäùí ôïõ Ýôïò êáôÜ ôï ISO-8601, ïé åâäïìÜäåò áñ÷ßæïõí ÄåõôÝñá (ðñïóôÝèçêå óôçí PHP 4.1.0)
Y - Ýôïò, 4 øçößá; ð.÷. "1999"
y - Ýôïò, 2 øçößá; ð.÷. "99"
z - çìÝñá ôïõ Ýôïõò ("0" Ýùò "365").
Z - äéáöïñÜ ôçò æþíçò þñáò óå äåõôåñüëåðôá ("-43200" Ýùò "43200"). Ç äéáöïñÜ ãéá æþíåò þñáò äõôéêÜ ôïõ UTC åßíáé ðÜíôá áñíçôéêÞ, êáé ãéá áõôÝò áíáôïëéêÜ ôïõ UTC ðÜíôá èåôéêÞ.
Ìðïñåßôå íá áðïôñÝøåôå ôç ëåéôïõñãßá åíüò áíáãíùñßóéìïõ ÷áñáêôÞñá óôï format string ìå ôï íá èÝóåôå Ýíá backslash ðñéí áðü áõôüí. ÅÜí ï ÷áñáêôÞñáò ìå ôï backslash åßíáé Þäç ìßá åßäéêÞ áêïëïõèßá, ìðïñåß íá ÷ñåéáóôåß íá ôïðïèåôÞóåôå Ýíá åðéðëÝïí backslash.
Åßíáé äõíáôü íá ÷ñçóéìïðïéåßóåôå ôçí date() êáé ôç mktime() ãéá íá ðñïóäéïñßóåôå çìåñïìçíßåò óôï ìÝëëïí Þ óôï ðáñåëèüí.
ÐáñÜäåéãìá 3. Ðáñáäåßãìáôá ôïõ óõíäõáóìïý ôùí óõíáñôÞóåùí date() êáé mktime()
|
Óçìåßùóç: Áõôü ìðïñåß íá åßíáé ðéï áîéüðéóôï áðü ôï íá ðñïóèÝôåôå Þ íá áöáéñåßôå ôï ðëÞèïò ôùí äõôåñïëÝðôùí ôçò çìÝñáò Þ ôïõ ìÞíá óå Ýíá timestamp åîáéôßáò ôçò èåñéíÞò þñáò.
ÌåñéêÜ åðéðëÝïí ðáñáäåßãìáôá ôçò date(). Ðñáôçñåßóôå üôé èá ðñÝðåé íá èÝóåôå backslash óå üëïõò ôïõò ÷áñáêôÞñåò, êáèþò ïðïéïóäÞðïôå Ý÷åé ìßá éäéáßôåñç óçìáóßá èá ðáñÜîåé áíåðéèýìçôá áðïôåëÝóìáôá, êáé åðåéäÞ ìðïñåß íá äïèåß íüçìá êáé óå Üëëïõò ÷áñáêôÞñåò óôéò ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ¼ôáí êÜíåôå escape Ýíá ÷áñáêôÞñá, âåâáéùèåßôå üôé ÷ñçóéìïðïéåßôå áðëÜ åéóáãùãéêÜ ãéá ÷áñáêôÞñåò üðùò ï \n, ðïõ èá ãßíåé íÝá ãñáììÞ.
ÐáñÜäåéãìá 4. date() Formatting
|
Ãéá íá äéáìïñöüóåôå çìåñïìçíßåò óå Üëëåò ãëþóóåò, èá ðñÝðåé íá ÷ñçóéìïðïåßóåôå ôéò óõíÜñôçóåéò setlocale() êáé strftime().
ÁíáôñÝîôå åðßóçò óôéò: getlastmod(), gmdate(), mktime(), strftime() êáé time().
ÅðéóôñÝöåé Ýíá array ðïõ ðåñéÝ÷åé ôçí ðëçñïöïñßá ãéá ôçí çìåñïìçíßá ôïõ timestamp, Þ ôçí ôïðéêÞ þñá åÜí äåí Ý÷åé ïñéóôåß timestamp, üðùò óôá áêüëïõèá óôïé÷åßá ôïõ array:
"seconds" - äåõôåñüëåðôá
"minutes" - ëåðôÜ
"hours" - þñåò
"mday" - çìÝñá ôïõ ìÞíá
"wday" - çìÝñá ôçò åâäïìÜäáò, áñéèìçôéêÜ : áðü ôï 0 ùò Sunday Ýùò ôï 6 ùò ÓÜââáôï
"mon" - ìÞíáò, áñéèìçôéêÜ
"year" - Ýôïò, áñéèìçôéêÜ
"yday" - çìÝñá ôïõ Ýôïõò, áñéèìçôéêÜ. ð.÷. "299"
"weekday" - çìÝñá ôçò åâäïìÜäáò, ðáñáôßèåôáé ôï ðëÞñåò üíïìá. ð.÷. "Friday"
"month" - ìÞíáò, ðáñáôßèåôáé ôï ðëÞñåò üíïìá. ð.÷. "January"
Áõôü åßíáé Ýíá interface ôçò gettimeofday(2). ÅðéóôñÝöåé Ýíá array ðïõ ðåñéÝ÷åé ôá äåäïìÝíá ðïõ åðéóôñÝöïíôáé áðü ôçí êëÞóç ôïõ óõóôÞìáôïò.
"sec" - äåõôåñüëåðôá
"usec" - ÷éëéïóôÜ ôïõ äåõôåñïëÝðôïõ
"minuteswest" - ëåðôá äõôéêÜ ôïõ Greenwich
"dsttime" - ôýðïò ôçò äéüñèùóçò dst
Åßíáé áêñéâþò ßäéá ìå ôç óõíÜñôçóç date(), áëëÜ ç åðéóôñåöüìåíç þñá åßíáé ç Greenwich Mean Time (GMT). Ãéá ðáñÜäåéãìá, üôáí ôñå÷ôåß óôç Öéëáíäßá (GMT +0200), ç ðñþôç áðü ôéò áêüëïõèåò ãñáììÝò èá ôõðþóåé "Jan 01 1998 00:00:00", åíþ ç äåýôåñç "Dec 31 1997 22:00:00".
ÁíáôñÝîôå åðßóçò óôéò: date(), mktime(), gmmktime() êáé strftime().
Åßíáé áêñéâþò ç ßäéá óõíÜñôçóç ìå ôç mktime(), áëëÜ ç ðáñÜìåôñïò ðïõ ðåñíéÝôáé áíôéðñïóùðåýåé ìßá GMT çìåñïìçíßá.
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
gmstrftime -- Äéáìïñöþíåé ìßá GMT/CUT þñá/çìåñïìçíßá óýìöùíá ìå ôéò ôïðéêÝò ñõèìßóåéòÓõìðåñéöÝñåôáé ôï ßäéï ìå ôç óõíÜñôçóç strftime(), áëëÜ ç þñá ðïõ åðéóôñÝöåôáé åßíáé ç Greenwich Mean Time (GMT). Ãéá ðáñÜäåéãìá, üôáí ôñå÷ôåß óå Eastern Standard Time (GMT -0500), ç ðñþôç áðü ôéò áêüëïõèåò ãñáììÝò èá ôõðþóåé "Dec 31 1998 20:00:00", åíþ ç äåýôåñç "Jan 01 1999 01:00:00".
ÁíáôñÝîôå åðßóçò óôç strftime().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ç óõíÜñôçóç localtime() åðéóôñÝöåé Ýíá array ðïõ åßíáé áêñéâþò ôï ßäéï ìå áõôü ôçò structure ðïõ åðéóôñÝöåôáé áðü ôçí êëÞóç ôçò áíôßóôïé÷çò óõíÜñôçóçò ôçò C. Ç ðñþôç ðáñÜìåôñïò ôçò localtime() åßíáé ôï timestamp, åÜí äåí äïèåß ÷ñçóéìïðïéåßôáé ç ôñÝ÷ïõóá þñá üðùò áõôÞ åðéóôñÝöåôáé áðü ôçí time(). Ç äåýôåñç ðáñÜìåôñïò ôçò localtime() åßíáé ç is_associative, åÜí ôåèåß óôï 0 Þ äå äïèåß, ôï array åðéóôñÝöåôáé óáí Ýíá êáíïíéêü áñéèìçôéêÜ indexed array. ÅÜí ç ðáñÜìåôñïò åßíáé óôï 1 ôüôå ç localtime() åðéóôñÝöåé Ýíá array ðïõ ðåñéÝ÷åé üëá ôá äéáöïåñåôéêÜ óôïé÷åßá ôçò structure ðïõ åðéóôñÝöåôáé áðü ôçí êëÞóç ôçò óõíÜñôçóçò ôçò C ãéá ôçí localtime. Ôá ïíüìáôá ôùí äéáöüñùí keys ôïõ array åßíáé ôá áêüëïõèá:
"tm_sec" - äõôåñüëåðôá
"tm_min" - ëåðôÜ
"tm_hour" - þñá
"tm_mday" - çìÝñá ôïõ ìÞíá
"tm_mon" - ìÞíáò ôïõ Ýôïõò, îåêéíþíôáò áðü ôï 0 ãéá ôïí ÉáíïõÜñéï
"tm_year" - ¸ôç áðü ôï 1900
"tm_wday" - çìÝñá ôçò åâäïìÜäáò
"tm_yday" - ÇìÝñá ôïõ Ýôïõò
"tm_isdst" - åßíáé ç èåñéíÞ þñá óå éó÷ý
(PHP 3, PHP 4 , PHP 5)
microtime -- ÅðéóôñÝöåé ôï ôñÝ÷ùí UNIX timestamp óå ÷éëéïóôÜ ôïõ äåõôåñïëÝðôïõÅðéóôñÝöåé ôï string "msec sec" üðïõ ôï sec åßíáé ç ôñÝ÷ïõóá þñá ìåôñçìÝíç âÜóåé ôïõ ðëÞèïõò ôùí äåõôåñïëÝðôùí ðïõ ðÝñáóáí áðü ôçí Unix Epoch (0:00:00 January 1, 1970 GMT), êáé ôï msec åßíáé ôï ìÝñïò ôùí ÷éëéïóôþí ôïõ äåõôåñïëÝðôïõ. ÁõôÞ ç óõíÜñôçóç åßíáé äéáèÝóéìç ìüíï óôá ëåéôïõñãéêÜ óõóôÞìáôá ðïõ õðïóôçñßæïõí ôç êëÞóç ôçò gettimeofday().
Êáé ôá äýï ìÝñç ôïõ string åðéóôñÝöïíôáé óå ìïíÜäåò ôïõ äåõôåñïëÝðôïõ.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ôçò microtime()
|
ÁíáôñÝîôå åðßóçò óôçí time().
Ðñïóï÷Þ: Ðáñáôçñåßóôå ôçí ðåñßåñãç óåéñÜ ôùí ïñéóìÜôùí, ç ïðïßá äéáöÝñåé áðü áõôÞí ìßáò óõíÞèïõò êëÞóçò ôçò óõíÜñôçóçò ôïõ UNIX, mktime(), êáé ç ïðïßá äåí åßíáé êáôÜëëçëç üôáí ðáñáëåßðïíôáé ðáñÜìåôñïé áðü äåîéÜ ðñïò ôá áñéóôÝñá. Åßíáé Ýíá óýíçèåò ëÜèïò íá ìðåñäåýïíôáé áõôÝò ïé ôéìÝò óå Ýíá script.
ÅðéóôñÝöåé ôï Unix timestamp ðïõ áíôéóôïé÷åß óôá äïèÝíôá ïñßóìáôá. Áõôü ôï timestamp åßíáé Ýíáò long integer ðïõ ðåñéÝ÷åé ôï ðëÞèïò ôùí äåõôåñïëÝðôùí áðü ôçí Unix Epoch (January 1 1970) ìÝ÷ñé ôçí þñá ðïõ êáèïñßóôçêå.
Ïñßóìáôá ìðïñïýí íá ðáñáëåßðïíôáé ìå óåéñÜ áðü ôá äåîéÜ ðñïò ôá áñéóôåñÜ. ÏðïéáäÞðïôå ïñßóìáôá ðáñáëåßðïíôáé èá ôåèïýí óôéò ôñÝ÷ïõóåò ôéìÝò ôçò ôïðéêÞò çìåñïìçíßáò êáé þñáò.
H is_dst ìðïñåß íá ôåèåß óôï 1 åÜí ç þñá åßíáé èåñéíÞ, 0 åÜí äåí åßíáé, Þ -1 (ôï ðñïêáèïñéóìÝíï) åÜí åßíáé Üãíùóôï ôï ðïõ áíÞêåé. ÅÜí åßíáé Üãíùóôï, ç PHP ðñïóðáèåß íá ôï õðïëïãßóåé áðü ìüíç ôçò. Áõôü ìðïñåß íá ðñïêáëÝóåé áðñüïðôá (áëëÜ ü÷é ëáíèáóìÝíá) áðïôåëÝóìáôá.
Óçìåßùóç: Ç is_dst ðñïóôÝèçêå óôçí Ýêäïóç 3.0.10.
Ç mktime() åßíáé ÷ñÞóéìç ãéá ôçí õëïðïßçóç áñéèìçôéêÞò çìåñïìçíéþí êáé åëÝã÷ïõ åãêõñüôçôáò, êáèþò èá õðïëïãßóåé áõôüìáôá ôç óùóôÞ ôéìÞ ãéá out-of-range input. Ãéá ðáñÜäåéãìá, êÜèå ìßá áðü ôéò áêüëïõèåò ãñáììÝò ðáñÜãåé ôï string "Jan-01-1998".
Windows: ÁñíçôéêÜ timestamp äåí õðïóôçñßæïíôáé áðü ïðïéáäÞðïôå ãíùóôÞ Ýêäïóç ôùí Windows. ¸ôóé, ôï åýñïò ôùí Ýãêõñùí ÷ñüíùí óõìðåñéëáìâÜíïõí ìüíï ôá 1970 ìÝ÷ñé 2038.
Ç ôåëåõôáßá ìÝñá ïðïéïõäÞðïôå äïóìÝíïõ ìÞíá ìðïñåß íá åêöñáóôåß óáí ç çìÝñá "0" ôïõ åðüìåíïõ ìÞíá, êáé ü÷é ç çìÝñá -1. Êáé ôá äýï áêüëïõèá ðáñáäåßãìáôá èá èá ðáñÜîïõí ôï string "The last day in Feb 2000 is: 29".
Ç çìåñïìçíßá ìå ôéò year, month êáé day íá åßíáé ìçäÝí, èåùñåßôáé íüìéìç (áëëéþò èá èåùñïýíôáí ùò 30.11.1999, ôï ïðïßï èá Þôáí ìßá strange behavior).
(PHP 3, PHP 4 , PHP 5)
strftime -- Äéáìïñöþíåé ìéá ôïðéêÞ þñá/çìåñïìçíßá óýìöùíá ìå ôéò ôïðéêÝò ñõèìßóåéòÅðéóôñÝöåé Ýíá string ìå ìïñöÞ óýìöùíç ìå ôï äïóìÝíï format string ÷ñçóéìïðïéþíôáò ôçí ðáñÜìåôñï timestamp Þ ôçí ôñÝ÷ïõóá ôïðéêÞ þñá åÜí äåí Ý÷åé äïèåß timestamp. ÌÞíåò, çìÝñåò ôçò åâäïìÜäáò êáé Üëëá strings ðïõ åîáñôþíôáé áðü ôç ãëþóóá, óõìöùíïýí ìå ôï ôñÝ÷ùí locale set ìå ôç óõíÜñôçóç setlocale().
Ïé áêüëïõèïé ðñïóäéïñéóôÝò áëëáãÞò åðéôñÝðïíôáé óôï format string:
%a - óõíôåôìçìÝíï üíïìá çìÝñáò ôçò åâäïìÜäáò óýìöùíá ìå ôï ôñÝ÷ùí locale
%A - ïëüêëçñï üíïìá çìÝñáò ôçò åâäïìÜäáò óýìöùíá ìå ôï ôñÝ÷ùí locale
%b - óõíôåôìçìÝíï üíïìá ìÞíá óýìöùíá ìå ôï ôñÝ÷ùí locale
%B - ïëüêëçñï üíïìá ìÞíá óýìöùíá ìå ôï ôñÝ÷ùí locale
%c - ðñïôéìüìåíç áíáðáñÜóôáóç çìåñïìçíßáò êáé þñáò ãéá ôï ôñÝ÷ùí locale
%C - áñéèìüò áéþíá (ôï Ýôïò äéáéñåßôáé ìå ôï 100 êáé óôñïããõëïðïéåßôáé óå Ýíá integer, áðü 00 ùò 99)
%d - çìÝñá ôïõ ìÞíá ùò äåêáäéêüò áñéèìüò (áðü 01 ùò 31)
%D - ôï ßäéï ìå %m/%d/%y
%e - çìÝñá ôïõ ìÞíá ùò äåêäéêüò áñéèìüò, Ýíá ìïíü øçößï Ýðåôáé åíüò êåíïý (áðü ' 1' ùò '31')
%g - üðùò ôï %G, áëëÜ ÷ùñßò ôïí áéþíá.
%G - Ôï 4øÞöéï Ýôïò êáôÜ ôïí ISO áñéèìü åâäïìÜäùí(áíáôñÝîôå óôï %V). Áõôü Ý÷åé ôçí ßäéá ìïñöÞ êáé ôéìÞ ìå ôï %Y, åêôüò áí ï êáôÜ ISO áñéèìüò åâäïìÜäùí áíÞêåé óôï ðñïçãïýìåíï Þ åðüìåíï Ýôïò ïðüôå êáé ÷ñçóéìïðïåßôáé.
%h - ôï ßäéï ìå ôï %b
%H - þñá ùò äåêáäéêüò áñéèìüò ÷ñçóéìïðïéþíôáò ñïëüé 24 ùñþí (áðü 00 ùò 23)
%I - þñá ùò äåêáäéêüò áñéèìüò ÷ñçóéìïðïéþíôáò ñïëüé 12 ùñþí (áðü 01 ùò 12)
%j - ìÝñá ôïõ Ýôïõò ùò äåêáäéêüò áñéèìüò (áðü 001 ùò 366)
%m - ìÞíáò ùò äåêáäéêüò áñéèìüò (áðü 01 ùò 12)
%M - ëåðôü ùò äåêáäéêüò áñéèìüò
%n - ï ÷áñáêôÞñáò íÝáò ãñáììÞò
%p - åßôå `am' åßôå `pm' áíÜëïãá ìå ôç äïèåßóá ôéìÞ þñáò, Þ ôá áíôßóôïé÷á strings ãéá ôï ôñÝ÷ùí locale
%r - þñá óå a.m. êáé p.m. ðáñÜóôáóç
%R - þñá óå ðáñÜóôáóç 24 ùñþí
%S - äåõôåñüëåðôï ùò äåêáäéêüò áñéèìüò
%t - ï ÷áñáêôÞñáò tab
%T - ç ôñÝ÷ïõóá þñá, ôï ßäéï ìå ôï %H:%M:%S
%u - çìÝñá ôçò åâäïìÜäáò ùò äåêáäéêüò áñéèìüò [1,7], ìå ôï Ýíá íá ðáñéóôÜíåé ôç ÄåõôÝñá
Ðñïåéäïðïßçóç |
Ôï Sun Solaris îåêéíÜåé ìå ôçí ÊõñéáêÞ ùò 1 êé áò ïñßæåé ôï ISO 9889:1999 (ôï ôñÝ÷ùí C standard) êáèáñÜ üôé ðñÝðåé íá åßíáé ç ÄåõôÝñá. |
%U - áñéèìüò ôçò åâäïìÜäáò ôïõ ôñÝ÷ïíôïò Ýôïõò ùò äåêáäéêüò áñéèìüò, ëáìâÜíïíôáò ôçí ðñþôç ÊõñéáêÞ ùò ôçí ðñþôç ìÝñá ôçò ðñþôçò åâäïìÜäáò
%V - ï êáôÜ ISO 8601:1988 áñéèìüò åâäïìÜäùí ôïõ ôñÝ÷ïíôïò Ýôïõò ùò Ýíáò äåêáäéêüò áñéèìüò, áðü 01 ùò 53, üðïõ ç åâäïìÜäá 1 åßíáé ç ðñþôç åâäïìÜäá ðïõ Ý÷åé ôïõëÜ÷éóôïí 4 ìÝñåò óôï ôñÝ÷ùí Ýôïò, ìå ôç ÄåõôÝñá ùò ôçí ðñþôç ìÝñá ôçò åâäïìÜäáò. (×ñçóéìïðïéåßóôå ôï %G Þ ôï %g ãéá ôï Ýôïò ðïõ áíôáðïêñßíåôáé óôï ðëÞèïò åâäïìÜäùí ðïõ êáèïñßæåôáé óôï timestamp.)
%W - ðëÞèïò åâäïìÜäùí óôï ôñÝ÷ùí Ýôïò ùò äåêáäéêïò áñéèìüò, èåùñþíôáò ôçí ðñþôç ÄåõôÝñá ùò ôçí ðñþôç ìÝñá ôçò ðñþôçò åâäïìÜäáò
%w - çìÝñá ôçò åâäïìÜäáò ùò äåêáäéêüò áñéèìüò, ìå ôçí ÊõñéáêÞ íá åßíáé ôï 0
%x - ðñïôéìüìåíïò ôñüðïò áíáðáñÜóôáóçò ôçò çìåñïìçíßáò ãéá ôï ôñÝ÷ùí locale ÷ùñßò ôçí þñá
%X - ðñïôéìüìåíïò ôñüðïò áíáðáñÜóôáóçò ôçò þñáò ãéá ôï ôñÝ÷ùí locale ÷ùñßò ôçí çìåñïìçíßá
%y - Ýôïò ùò äåêáäéêüò áñéèìüò ÷ùñßò êáíÝíá áéþíá (áðü 00 ùò 99)
%Y - Ýôïò ùò äåêáäéêüò áñéèìüò óõìðåñéëáìâáíïìÝíïõ ôïõ áéþíá
%Z - æþíç þñáò Þ üíïìá Þ óõíôïìïãñáößá
%% - Ýíáò literal `%' ÷áñáêôÞñáò
Óçìåßùóç: Ìðïñåß íá ìçí õðïóôçñßæïíôáé üëïé ïé ðñïóäéïñéóôÝò ìåôáôñïðÞò áðü ôç âéâëéïèÞêç ôçò C, óå áõôÞí ôçí ðåñßðôùóç äå èá õðïóôçñßæïíôáé áðü ôç óõíáñôçóç strftime() ôçò PHP. Áõôü óçìáßíåé üôé ð.÷. ïé %e, %T êáé %D (ìðïñåß íá åßíáé êáé ðáñáðÜíù) äå èá ëåéôïõñãïýí óôá Windows.
ÁíáôñÝîôå åðßóçò óôéò: setlocale() êáé mktime() êáé óôï Open Group specification of strftime().
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
strtotime -- ÌåôáôñÝøôå ó÷åäüí ïðïéáäÞðïôå çìåñïìçíßá Þ þñá ðïõ åßíáé óå ìïñöÞ Áããëéêïý êåéìÝíïõ óå Ýíá UNIX timestampÇ óõíÜñôçóç ðåñéìÝíåé íá ôçò äïèåß Ýíá string ðïõ ðåñéÝ÷åé ìßá çìåñïìçíßá óôá ÁããëéêÜ êáé èá ðñïóðáèÞóåé íá ôç ìåôáôñÝøåé óå Ýíá UNIX timestamp ó÷åôéêü ìå áõôü ðïõ äßíåôáé ìå ôçí ðáñÜìåôñï now, Þ ôçí ôñÝ÷ïõóá þñá åÜí äå äïèåß êáíÝíá. Óå ðåñßðôùóç áðïôõ÷ßáò, Ýíá -1 åðéóôñÝöåôáé.
ÅðåéäÞ ç strtotime() óõìðåñéöÝñåáôé óýìöùíá ìå ôï óõíôáêôéêü çìåñïìçíéþí ôïõ GNU, áíáôñÝîôå óôï manual ôïõ GNU óôç óåëßäá ìå ôßôëï Date Input Formats. Åêåß ðåñéãñÜöåôáé ç Ýãêõñç óýíôáîç ôçò ðáñáìÝôñïõtime.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ôçò strtotime()
|
Óçìåßùóç: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)
ÅðéóôñÝöåé ôçí ôñÝ÷ïõóá þñá ìåôñçìÝíç ìå ôïí áñéèìü ôùí äåõôåñïëÝðôùí ðïõ Ý÷ïõí ðåñÜóåé áðü ôçí Unix Epoch (January 1 1970 00:00:00 GMT).
ÁíáôñÝîôå åðßóçò óôçí date().
These functions allow you to access records stored in dBase-format (dbf) databases.
There is no support for indexes or memo fields. There is no support for locking, too. Two concurrent webserver processes modifying the same dBase file will very likely ruin your database.
dBase files are simple sequential files of fixed length records. Records are appended to the end of the file and delete records are kept until you call dbase_pack().
We recommend that you do not use dBase files as your production database. Choose any real SQL server instead; MySQL or Postgres are common choices with PHP. dBase support is here to allow you to import and export data to and from your web database, because the file format is commonly understood by Windows spreadsheets and organizers.
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.
Closes the database associated with dbase_identifier.
dbase_create() creates a dBase database in the file filename, with the fields 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:
Boolean. These do not have a length or precision.
Memo. (Note that these aren't supported by PHP.) These do not have a length or precision.
Date (stored as YYYYMMDD). These do not have a length or precision.
Number. These have both a length and a precision (the number of digits after the decimal point).
String.
Óçìåßùóç: The fieldnames are limited in length and must not exceed 10 chars, 0 < chars <= 10.
If the database is successfully created, a dbase_identifier is returned, otherwise FALSE is returned.
ÐáñÜäåéãìá 1. Creating a dBase database file
|
Marks record to be deleted from the database. To actually remove the record from the database, you must also call dbase_pack().
Returns information on the column structure of the database referenced by dbase_identifier. For each column in the database, there is an entry in a numerically-indexed array. The array index starts at 0. Each array element contains an associative array of column information. If the database header information cannot be read, FALSE is returned.
The array elements are:
The name of the column
The human-readable name for the dbase type of the column (i.e. date, boolean, etc)
The number of bytes this column can hold
The number of digits of decimal precision for the column
A suggested printf() format specifier for the column
The byte offset of the column from the start of the row
ÐáñÜäåéãìá 1. Showing header information for a dBase database file
|
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
dbase_get_record_with_names -- Gets a record from a dBase database as an associative arrayReturns 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, except:
Dates are left as strings
Integers that would have caused an overflow (> 32 bits) are returned as strings
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, except:
Dates are left as strings
Integers that would have caused an overflow (> 32 bits) are returned as strings
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).
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.
Returns a dbase_identifier for the opened database, or FALSE if the database couldn't be opened.
Parameter flags correspond to those for the open() system call (Typically 0 means read-only, 1 means write-only, and 2 means read and write).
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
Packs the specified database (permanently deleting all records marked for deletion using dbase_delete_record()).
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()).
These functions allow you to store records stored in a dbm-style database. This type of database (supported by the Berkeley DB, GDBM, and some system libraries, as well as a built-in flatfile library) stores key/value pairs (as opposed to the full-blown records supported by relational databases).
Óçìåßùóç: However, dbm support is deprecated and you are encouraged to use the Database (dbm-style) abstraction layer functions instead.
Óçìåßùóç: This extension has been removed as of PHP 5 and moved to the PECL repository.
To use this functions you have to compile PHP with support for an underlying database. See the list of supported Databases.
In order to use these functions, you must compile PHP with dbm support by using the --with-db option. In addition you must ensure support for an underlying database or you can use some system libraries.
The function dbmopen() returns an database identifier which is used by the other dbm-functions.
Deletes the value for key in the database.
Returns FALSE if the key didn't exist in the database.
Returns TRUE if there is a value associated with the key.
Returns the value associated with key.
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.
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().)
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:
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 identifier 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.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
The dbx module is a database abstraction layer (db 'X', where 'X' is a supported database). The dbx functions allow you to access all supported databases using a single calling convention. The dbx-functions themselves do not interface directly to the databases, but interface to the modules that are used to support these databases.
To be able to use a database with the dbx-module, the module must be either linked or loaded into PHP, and the database module must be supported by the dbx-module. Currently, the following databases are supported, but others will follow:
FrontBase (available from PHP 4.1.0).
Sybase-CT (available from PHP 4.2.0).
Oracle (oci8) (available from PHP 4.3.0).
SQLite (CVS only).
Documentation for adding additional database support to dbx can be found at http://www.guidance.nl/php/dbx/doc/.
In order to have these functions available, you must compile PHP with dbx support by using the --enable-dbx option and all options for the databases that will be used, e.g. for MySQL you must also specify --with-mysql=[DIR]. To get other supported databases to work with the dbx-module refer to their specific documentation.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
For further details and definition of the PHP_INI_* constants see ini_set().
Óçìåßùóç: This ini-option is available available from PHP 4.3.0.
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Columns names can be returned "unchanged" or converted to "uppercase" or "lowercase". This directive can be overridden with a flag to dbx_query().
There are two resource types used in the dbx module. The first one is the link-object for a database connection, the second a result-object which holds the result of a query.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: Always refer to the module-specific documentation as well.
See also dbx_connect().
dbx_compare() returns 0 if the row_a[$column_key] is equal to row_b[$column_key], and 1 or -1 if the former is greater or is smaller than the latter one, respectively, or vice versa if the flag is set to DBX_CMP_DESC. dbx_compare() is a helper function for dbx_sort() to ease the make and use of the custom sorting function.
The flags can be set to specify comparison direction:
DBX_CMP_ASC - ascending order
DBX_CMP_DESC - descending order
DBX_CMP_NATIVE - no type conversion
DBX_CMP_TEXT - compare items as strings
DBX_CMP_NUMBER - compare items numerically
ÐáñÜäåéãìá 1. dbx_compare() example
|
See also dbx_sort().
dbx_connect() returns an object on success, FALSE on error. If a connection has been made but the database could not be selected, the connection is closed and FALSE is returned. The persistent parameter can be set to DBX_PERSISTENT, if so, a persistent connection will be created.
The module parameter can be either a string or a constant, though the latter form is preferred. The possible values are given below, but keep in mind that they only work if the module is actually loaded.
DBX_MYSQL or "mysql"
DBX_ODBC or "odbc"
DBX_PGSQL or "pgsql"
DBX_MSSQL or "mssql"
DBX_FBSQL or "fbsql" (available from PHP 4.1.0)
DBX_SYBASECT or "sybase_ct" (available from PHP 4.2.0)
DBX_OCI8 or "oci8" (available from PHP 4.3.0)
DBX_SQLITE or "sqlite" (CVS only)
The host, database, username and password parameters are expected, but not always used depending on the connect functions for the abstracted module.
The returned object has three properties:
It is the name of the currently selected database.
It is a valid handle for the connected database, and as such it can be used in module-specific functions (if required).
It is used internally by dbx only, and is actually the module number mentioned above.
Óçìåßùóç: Always refer to the module-specific documentation as well.
See also dbx_close().
(PHP 4 >= 4.0.6, PHP 5)
dbx_error -- Report the error message of the latest function call in the module (not just in the connection)dbx_error() returns a string containing the error message from the last function call of the abstracted module (e.g. mysql module). If there are multiple connections in the same module, just the last error is given. If there are connections on different modules, the latest error is returned for the module specified by the link_identifier parameter.
Óçìåßùóç: Always refer to the module-specific documentation as well.
The error message for Microsoft SQL Server is actually the result of the mssql_get_last_message() function.
The error message for Oracle (oci8) is not implemented (yet).
(PHP 4 >= 4.3.0, PHP 5)
dbx_escape_string -- Escape a string so it can safely be used in an sql-statement.dbx_escape_string() returns the text, escaped where necessary (such as quotes, backslashes etc). It returns NULL on error.
ÐáñÜäåéãìá 1. dbx_escape_string() example
|
See also dbx_query().
(PHP 5)
dbx_fetch_row -- Fetches rows from a query-result that had the DBX_RESULT_UNBUFFERED flag setdbx_fetch_row() returns a row on success, and 0 on failure (e.g. when no more rows are available). When the DBX_RESULT_UNBUFFERED is not set in the query, dbx_fetch_row() will fail as all rows have already been fetched into the results data property.
As a side effect, the rows property of the query-result object is incremented for each successful call to dbx_fetch_row().
ÐáñÜäåéãìá 1. How to handle the returned value
|
The result_identifier parameter is the result object returned by a call to dbx_query().
The returned array contains the same information as any row would have in the dbx_query result data property, including columns accessible by index or fieldname when the flags for dbx_guery were set that way.
See also dbx_query().
dbx_query() returns an object or 1 on success, and 0 on failure. The result object is returned only if the query given in sql_statement produces a result set (i.e. a SELECT query, even if the result set is empty).
ÐáñÜäåéãìá 1. How to handle the returned value
|
The flags parameter is used to control the amount of information that is returned. It may be any combination of the following constants with the bitwise OR operator (|). The DBX_COLNAMES_* flags override the dbx.colnames_case setting from php.ini.
It is always set, that is, the returned object has a data property which is a 2 dimensional array indexed numerically. For example, in the expression data[2][3] 2 stands for the row (or record) number and 3 stands for the column (or field) number. The first row and column are indexed at 0.
If DBX_RESULT_ASSOC is also specified, the returning object contains the information related to DBX_RESULT_INFO too, even if it was not specified.
It provides info about columns, such as field names and field types.
It effects that the field values can be accessed with the respective column names used as keys to the returned object's data property.
Associated results are actually references to the numerically indexed data, so modifying data[0][0] causes that data[0]['field_name_for_first_column'] is modified as well.
This flag will not create the data property, and the rows property will initially be 0. Use this flag for large datasets, and use dbx_fetch_row() to retrieve the results row by row.
The dbx_fetch_row() function will return rows that are conformant to the flags set with this query. Incidentally, it will also update the rows each time it is called.
The case of the returned column names will not be changed.
The case of the returned column names will be changed to uppercase.
The case of the returned column names will be changed to lowercase.
DBX_RESULT_INDEX
DBX_RESULT_INDEX | DBX_RESULT_INFO
DBX_RESULT_INDEX | DBX_RESULT_INFO | DBX_RESULT_ASSOC - this is the default, if flags is not specified.
The returned object has four or five properties depending on flags:
It is a valid handle for the connected database, and as such it can be used in module specific functions (if required).
These contain the number of columns (or fields) and rows (or records) respectively.
It is returned only if either DBX_RESULT_INFO or DBX_RESULT_ASSOC is specified in the flags parameter. It is a 2 dimensional array, that has two named rows (name and type) to retrieve column information.
This property contains the actual resulting data, possibly associated with column names as well depending on flags. If DBX_RESULT_ASSOC is set, it is possible to use $result->data[2]["field_name"].
ÐáñÜäåéãìá 3. outputs the content of data property into HTML table
|
ÐáñÜäåéãìá 4. How to handle UNBUFFERED queries
|
Óçìåßùóç: Always refer to the module-specific documentation as well.
Column names for queries on an Oracle database are returned in lowercase.
See also dbx_escape_string(), dbx_fetch_row() and dbx_connect().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: It is always better to use ORDER BY SQL clause instead of dbx_sort(), if possible.
ÐáñÜäåéãìá 1. dbx_sort() example
|
See also dbx_compare().
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
db++, made by the German company Concept asa, is a relational database system with high performance and low memory and disk usage in mind. While providing SQL as an additional language interface, it is not really a SQL database in the first place but provides its own AQL query language which is much more influenced by the relational algebra then SQL is.
Concept asa always had an interest in supporting open source languages, db++ has had Perl and Tcl call interfaces for years now and uses Tcl as its internal stored procedure language.
This extension relies on external client libraries so you have to have a db++ client installed on the system you want to use this extension on.
Concept asa provides db++ Demo versions and documentation for Linux, some other Unix versions. There is also a Windows version of db++, but this extension doesn't support it (yet).
In order to build this extension yourself you need the db++ client libraries and header files to be installed on your system (these are included in the db++ installation archives by default). You have to run configure with option --with-dbplus to build this extension.
configure looks for the client libraries and header files under the default paths /usr/dbplus, /usr/local/dbplus and /opt/dblus. If you have installed db++ in a different place you have add the installation path to the configure option like this: --with-dbplus=/your/installation/path.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðßíáêáò 1. DB++ Error Codes
PHP Constant | db++ constant | meaning |
---|---|---|
DBPLUS_ERR_NOERR (integer) | ERR_NOERR | Null error condition |
DBPLUS_ERR_DUPLICATE (integer) | ERR_DUPLICATE | Tried to insert a duplicate tuple |
DBPLUS_ERR_EOSCAN (integer) | ERR_EOSCAN | End of scan from rget() |
DBPLUS_ERR_EMPTY (integer) | ERR_EMPTY | Relation is empty (server) |
DBPLUS_ERR_CLOSE (integer) | ERR_CLOSE | The server can't close |
DBPLUS_ERR_WLOCKED (integer) | ERR_WLOCKED | The record is write locked |
DBPLUS_ERR_LOCKED (integer) | ERR_LOCKED | Relation was already locked |
DBPLUS_ERR_NOLOCK (integer) | ERR_NOLOCK | Relation cannot be locked |
DBPLUS_ERR_READ (integer) | ERR_READ | Read error on relation |
DBPLUS_ERR_WRITE (integer) | ERR_WRITE | Write error on relation |
DBPLUS_ERR_CREATE (integer) | ERR_CREATE | Create() system call failed |
DBPLUS_ERR_LSEEK (integer) | ERR_LSEEK | Lseek() system call failed |
DBPLUS_ERR_LENGTH (integer) | ERR_LENGTH | Tuple exceeds maximum length |
DBPLUS_ERR_OPEN (integer) | ERR_OPEN | Open() system call failed |
DBPLUS_ERR_WOPEN (integer) | ERR_WOPEN | Relation already opened for writing |
DBPLUS_ERR_MAGIC (integer) | ERR_MAGIC | File is not a relation |
DBPLUS_ERR_VERSION (integer) | ERR_VERSION | File is a very old relation |
DBPLUS_ERR_PGSIZE (integer) | ERR_PGSIZE | Relation uses a different page size |
DBPLUS_ERR_CRC (integer) | ERR_CRC | Invalid crc in the superpage |
DBPLUS_ERR_PIPE (integer) | ERR_PIPE | Piped relation requires lseek() |
DBPLUS_ERR_NIDX (integer) | ERR_NIDX | Too many secondary indices |
DBPLUS_ERR_MALLOC (integer) | ERR_MALLOC | Malloc() call failed |
DBPLUS_ERR_NUSERS (integer) | ERR_NUSERS | Error use of max users |
DBPLUS_ERR_PREEXIT (integer) | ERR_PREEXIT | Caused by invalid usage |
DBPLUS_ERR_ONTRAP (integer) | ERR_ONTRAP | Caused by a signal |
DBPLUS_ERR_PREPROC (integer) | ERR_PREPROC | Error in the preprocessor |
DBPLUS_ERR_DBPARSE (integer) | ERR_DBPARSE | Error in the parser |
DBPLUS_ERR_DBRUNERR (integer) | ERR_DBRUNERR | Run error in db |
DBPLUS_ERR_DBPREEXIT (integer) | ERR_DBPREEXIT | Exit condition caused by prexit() * procedure |
DBPLUS_ERR_WAIT (integer) | ERR_WAIT | Wait a little (Simple only) |
DBPLUS_ERR_CORRUPT_TUPLE (integer) | ERR_CORRUPT_TUPLE | A client sent a corrupt tuple |
DBPLUS_ERR_WARNING0 (integer) | ERR_WARNING0 | The Simple routines encountered a non fatal error which was corrected |
DBPLUS_ERR_PANIC (integer) | ERR_PANIC | The server should not really die but after a disaster send ERR_PANIC to all its clients |
DBPLUS_ERR_FIFO (integer) | ERR_FIFO | Can't create a fifo |
DBPLUS_ERR_PERM (integer) | ERR_PERM | Permission denied |
DBPLUS_ERR_TCL (integer) | ERR_TCL | TCL_error |
DBPLUS_ERR_RESTRICTED (integer) | ERR_RESTRICTED | Only two users |
DBPLUS_ERR_USER (integer) | ERR_USER | An error in the use of the library by an application programmer |
DBPLUS_ERR_UNKNOWN (integer) | ERR_UNKNOWN |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function will add a tuple to a relation. The tuple data is an array of attribute/value pairs to be inserted into the given relation. After successful execution the tuple array will contain the complete data of the newly created tuple, including all implicitly set domain fields like sequences.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_aql() will execute an AQL query on the given server and dbpath.
On success it will return a relation handle. The result data may be fetched from this relation by calling dbplus_next() and dbplus_current(). Other relation access functions will not work on a result relation.
Further information on the AQL A... Query Language is provided in the original db++ manual.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_chdir() will change the virtual current directory where relation files will be looked for by dbplus_open(). dbplus_chdir() will return the absolute path of the current directory. Calling dbplus_chdir() without giving any newdir may be used to query the current working directory.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Calling dbplus_close() will close a relation previously opened by dbplus_open().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_curr() will read the data for the current tuple for the given relation and will pass it back as an associative array in tuple.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
See also dbplus_first(), dbplus_prev(), dbplus_next(), and dbplus_last().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_errcode() returns a cleartext error string for the error code passed as errno of for the result code of the last db++ operation if no parameter is given.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_errno() will return the error code returned by the last db++ operation.
See also dbplus_errcode().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_find() will place a constraint on the given relation. Further calls to functions like dbplus_curr() or dbplus_next() will only return tuples matching the given constraints.
Constraints are triplets of strings containing of a domain name, a comparison operator and a comparison value. The constraints parameter array may consist of a collection of string arrays, each of which contains a domain, an operator and a value, or of a single string array containing a multiple of three elements.
The comparison operator may be one of the following strings: '==', '>', '>=', '<', '<=', '!=', '~' for a regular expression match and 'BAND' or 'BOR' for bitwise operations.
See also dbplus_unselect().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_curr() will read the data for the first tuple for the given relation, make it the current tuple and pass it back as an associative array in tuple.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
See also dbplus_curr(), dbplus_prev(), dbplus_next(), and dbplus_last().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_flush() will write all changes applied to relation since the last flush to disk.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_freealllocks() will free all tuple locks held by this client.
See also dbplus_getlock(), dbplus_freelock(), and dbplus_freerlocks().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_freelock() will release a write lock on the given tuple previously obtained by dbplus_getlock().
See also dbplus_getlock(), dbplus_freerlocks(), and dbplus_freealllocks().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_freerlocks() will free all tuple locks held on the given relation.
See also dbplus_getlock(), dbplus_freelock(), and dbplus_freealllocks().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_getlock() will request a write lock on the specified tuple. It will return zero on success or a non-zero error code, especially DBPLUS_ERR_WLOCKED, on failure.
See also dbplus_freelock(), dbplus_freerlocks(), and dbplus_freealllocks().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_getunique() will obtain a number guaranteed to be unique for the given relation and will pass it back in the variable given as uniqueid.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_curr() will read the data for the last tuple for the given relation, make it the current tuple and pass it back as an associative array in tuple.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
See also dbplus_first(), dbplus_curr(), dbplus_prev(), and dbplus_next().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_lockrel() will request a write lock on the given relation. Other clients may still query the relation, but can't alter it while it is locked.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_curr() will read the data for the next tuple for the given relation, will make it the current tuple and will pass it back as an associative array in tuple.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
See also dbplus_first(), dbplus_curr(), dbplus_prev(), and dbplus_last().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The relation file name will be opened. name can be either a file name or a relative or absolute path name. This will be mapped in any case to an absolute relation file path on a specific host machine and server.
On success a relation file resource (cursor) is returned which must be used in any subsequent commands referencing the relation. Failure leads to a zero return value, the actual error code may be asked for by calling dbplus_errno().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_curr() will read the data for the previous tuple for the given relation, will make it the current tuple and will pass it back as an associative array in tuple.
The function will return zero (aka. DBPLUS_ERR_NOERR) on success or a db++ error code on failure. See dbplus_errcode() or the introduction to this chapter for more information on db++ error codes.
See also dbplus_first(), dbplus_curr(), dbplus_next(), and dbplus_last().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rchperm() will change access permissions as specified by mask, user and group. The values for these are operating system specific.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rcreate() will create a new relation named name. An existing relation by the same name will only be overwritten if the relation is currently not in use and overwrite is set to TRUE.
domlist should contain the domain specification for the new relation within an array of domain description strings. ( dbplus_rcreate() will also accept a string with space delimited domain description strings, but it is recommended to use an array). A domain description string consists of a domain name unique to this relation, a slash and a type specification character. See the db++ documentation, especially the dbcreate(1) manpage, for a description of available type specifiers and their meanings.
(4.1.0 - 4.2.3 only)
dbplus_rcrtexact -- Creates an exact but empty copy of a relation including indicesÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rcrtexact() will create an exact but empty copy of the given relation under a new name. An existing relation by the same name will only be overwritten if overwrite is TRUE and no other process is currently using the relation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rcrtexact() will create an empty copy of the given relation under a new name, but with default indices. An existing relation by the same name will only be overwritten if overwrite is TRUE and no other process is currently using the relation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_resolve() will try to resolve the given relation_name and find out internal server id, real hostname and the database path on this host. The function will return an array containing these values under the keys 'sid', 'host' and 'host_path' or FALSE on error.
See also dbplus_tcl().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rkeys() will replace the current primary key for relation with the combination of domains specified by domlist.
domlist may be passed as a single domain name string or as an array of domain names.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_ropen() will open the relation file locally for quick access without any client/server overhead. Access is read only and only dbplus_current() and dbplus_next() may be applied to the returned relation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rquery() performs a local (raw) AQL query using an AQL interpreter embedded into the db++ client library. dbplus_rquery() is faster than dbplus_aql() but will work on local data only.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rrename() will change the name of relation to name.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rsecindex() will create a new secondary index for relation with consists of the domains specified by domlist and is of type type
domlist may be passed as a single domain name string or as an array of domain names.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_unlink() will close and remove the relation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_rzap() will remove all tuples from relation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
A db++ server will prepare a TCL interpreter for each client connection. This interpreter will enable the server to execute TCL code provided by the client as a sort of stored procedures to improve the performance of database operations by avoiding client/server data transfers and context switches.
dbplus_tcl() needs to pass the client connection id the TCL script code should be executed by. dbplus_resolve() will provide this connection id. The function will return whatever the TCL code returns or a TCL error message if the TCL code fails.
See also dbplus_resolve().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_tremove() removes tuple from relation if it perfectly matches a tuple within the relation. current, if given, will contain the data of the new current tuple after calling dbplus_tremove().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Not implemented yet.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_unlockrel() will release a write lock previously obtained by dbplus_lockrel().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Calling dbplus_unselect() will remove a constraint previously set by dbplus_find() on relation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_update() replaces the tuple given by old with the data from new if and only if old completely matches a tuple within relation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_xlockrel() will request an exclusive lock on relation preventing even read access from other clients.
See also dbplus_xunlockrel().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
dbplus_xunlockrel() will release an exclusive lock on relation previously obtained by dbplus_xlockrel().
PHP supports the direct io functions as described in the Posix Standard (Section 6) for performing I/O functions at a lower level than the C-Language stream I/O functions (fopen(), fread(),..). The use of the DIO functions should be considered only when direct control of a device is needed. In all other cases, the standard filesystem functions are more than adequate.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
One resource type is defined by this extension: a file descriptor returned by dio_open().
The function dio_close() closes the file descriptor fd.
See also dio_open().
The dio_fcntl() function performs the operation specified by cmd on the file descriptor fd. Some commands require additional arguments args to be supplied.
args is an associative array, when cmd is F_SETLK or F_SETLLW, with the following keys:
"start" - offset where lock begins
"length" - size of locked area. zero means to end of file
"wenth" - Where l_start is relative to: can be SEEK_SET, SEEK_END and SEEK_CUR
"type" - type of lock: can be F_RDLCK (read lock), F_WRLCK (write lock) or F_UNLCK (unlock)
cmd can be one of the following operations:
F_SETLK - Lock is set or cleared. If the lock is held by someone else dio_fcntl() returns -1.
F_SETLKW - like F_SETLK, but in case the lock is held by someone else, dio_fcntl() waits until the lock is released.
F_GETLK - dio_fcntl() returns an associative array (as described above) if someone else prevents lock. If there is no obstruction key "type" will set to F_UNLCK.
F_DUPFD - finds the lowest numbered available file descriptor greater or equal than args and returns them.
F_SETFL - Sets the file descriptors flags to the value specified by args, which can be O_APPEND,O_NONBLOCK or O_ASYNC. To use O_ASYNC you will need to use the PCNTL extension.
(PHP 4 >= 4.2.0, PHP 5)
dio_open -- Opens a new filename with specified permissions of flags and creation permissions of modedio_open() opens a file and returns a new file descriptor for it, or FALSE if any error occurred. If flags is O_CREAT, the optional third parameter mode will set the mode of the file (creation permissions). The flags parameter can be one of the following options:
O_RDONLY - opens the file for read access.
O_WRONLY - opens the file for write access.
O_RDWR - opens the file for both reading and writing.
O_CREAT - creates the file, if it doesn't already exist.
O_EXCL - if both, O_CREAT and O_EXCL are set, dio_open() fails, if the file already exists.
O_TRUNC - if the file exists, and its opened for write access, the file will be truncated to zero length.
O_APPEND - write operations write data at the end of the file.
O_NONBLOCK - sets non blocking mode.
See also: dio_close().
(PHP 4 >= 4.2.0, PHP 5)
dio_read -- Reads n bytes from fd and returns them, if n is not specified, reads 1k blockThe function dio_read() reads and returns n bytes from file with descriptor fd. If n is not specified, dio_read() reads 1K sized block and returns them.
See also: dio_write().
The function dio_seek() is used to change the file position of the file with descriptor fd. The parameter whence specifies how the position pos should be interpreted:
SEEK_SET - specifies that pos is specified from the beginning of the file.
SEEK_CUR - Specifies that pos is a count of characters from the current file position. This count may be positive or negative.
SEEK_END - Specifies that pos is a count of characters from the end of the file. A negative count specifies a position within the current extent of the file; a positive count specifies a position past the current end. If you set the position past the current end, and actually write data, you will extend the file with zeros up to that position.
Function dio_stat() returns information about the file with file descriptor fd. dio_stat() returns an associative array with the following keys:
"device" - device
"inode" - inode
"mode" - mode
"nlink" - number of hard links
"uid" - user id
"gid" - group id
"device_type" - device type (if inode device)
"size" - total size in bytes
"blocksize" - blocksize
"blocks" - number of blocks allocated
"atime" - time of last access
"mtime" - time of last modification
"ctime" - time of last change
The function dio_tcsetattr() sets the terminal attributes and baud rate of the open resource. The currently available options are
'baud' - baud rate of the port - can be 38400,19200,9600,4800,2400,1800, 1200,600,300,200,150,134,110,75 or 50, default value is 9600.
'bits' - data bits - can be 8,7,6 or 5. Default value is 8.
'stop' - stop bits - can be 1 or 2. Default value is 1.
'parity' - can be 0,1 or 2. Default value is 0.
ÐáñÜäåéãìá 1. Setting the baud rate on a serial port
|
Function dio_truncate() causes the file referenced by fd to be truncated to at most offset bytes in size. If the file previously was larger than this size, the extra data is lost. If the file previously was shorter, it is unspecified whether the file is left unchanged or is extended. In the latter case the extended part reads as zero bytes. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá..
The function dio_write() writes up to len bytes from data to file fd. If len is not specified, dio_write() writes all data to the specified file. dio_write() returns the number of bytes written to fd.
See also dio_read().
Ãéá ó÷åôéêÝò óõíáñôÞóåéò, üðùò ïé dirname(), is_dir(), mkdir(), êáé rmdir(), áíáôñÝîôå óôï Filesystem.
ÁëëÜæåé ôïí ôñÝ÷ïíôá êáôÜëïãï ôçò PHP óå directory. ÅðéóôñÝöåé FALSE åÜí äåí ìðïñåß íá áëëÜîåé êáôÜëïãï, áëëéþò TRUE.
ÁíáôñÝîôå åðßóçò óôçí getcwd().
ÁëëÜæåé ôïí root êáôÜëïãï ôçò ôñÝ÷ïõóáò äéáäéêáóßáò óå directory. ÅðéóôñÝöåé FALSE åÜí äåí åßíáé äõíáôÞ ç áëëáãÞ, áëëéþò TRUE.
Óçìåßùóç: Äåí åßíáé êáëÞ ôáêôéêÞ íá ÷ñçóéìïðïéåßôå áõôÞí ôç óõíÜñôçóç üôáí åßóôå óå ðåñéâÜëëïí webserver, åðåéäÞ äåí åßíáé äõíáôü íá èÝóåôå ðÜëé ôïí root êáôÜëïãï óå / óôï ôÝëïò ôçò áðáßôçóçò. ÁõôÞ ç óõíÜñôçóç èá Ý÷åé óùóôü áðïôÝëåóìá ìüíï üôáí ôñå÷ôåß ìå áõôüí ôïí ôñüðï ùò CGI.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
¸íáò pseudo-object oriented ìç÷áíéóìüò ãéá áíÜãíùóç áðü êáôÜëïãï. Ôï äïèÝí directory áíïßãåé. ÕðÜñ÷ïõí äýï properties åöüóïí åßíáé áíïé÷ôüò ï êáôÜëïãïò. Ç ðñþôç åßíáé ç handle, ðïõ ìðïñåß íá ÷ñçóéìïðïéçèåß ìå Üëëåò óõíáñôÞóåéò ãéá êáôáëüãïõò üðùò ïé readdir(), rewinddir() êáé closedir(). Ç äåýôåñç åßíáé ç path ðïõ äåß÷íåé ôï path ôïõ êáôáëüãïõ ðïõ Üíïéîå. Ôñåéò ìÝèïäïé åßíáé äéáèÝóéìïé: read, rewind êáé close.
Ðáñáêáëþ ðáñáôçñÞóôå ôïí ôñüðï ìå ôïí ïðïßï ç åðéóôñåöüìåíç ôéìÞ ôçò dir() åëÝã÷åôáé óôï áêüëïõèï ðáñÜäåéãìá. ÄïêéìÜæïõìå ëåðôïìåñþò åÜí ç ôéìÞ áõôÞ åßíáé ðáíïìïéüôõðç ìå (ßóç êáé ôïõ ßäéïõ ôýðïõ ìå -- áíáôñÝîôå óôïõò ÔåëåóôÝò Óýãêñéóçò ãéá ðåñéóóüôåñåò ðëçñïöïñßåò) FALSE, áöïý óå Üëëç ðåñßðôùóç ïðïéïäÞðïôå óôïé÷åßï êáôáëüãïõ, ôï üíïìá ôïõ ïðïßïõ äßíåé FALSE èá óôáìáôÞóåé ôï loop.
Óçìåßùóç: Ç óåéñÜ ìå ôçí ïðïßá åðéóôñÝöïíôáé ôá ðåñéå÷üìåíá ôïõ êáôáëüãïõ áðü ôçí read åîáñôÜôáé áðü ôï óýóôçìá.
Óçìåßùóç: Ïñßæåôáé ç internal class Directory, ìå ôçí Ýííïéá üôé äåí ìðïñåßôå íá ïñßóåôå ôéò äéêÝò óáò êëÜóåéò ìå ôï üíïìá áõôü. Ãéá ìßá ðëÞñç ëßóôá ôùí ðñïêáèïñéóìÝíùí êëÜóåùí óôçí PHP, ðáñáêáëþ áíáôñÝîôå óôéòÐñïêáèïñéóìÝíåò êëÜóåéò.
Êëåßíåé ôï stream ôïõ êáôáëüãïõ ðïõ ðñïóäéïñßæåôáé áðü ôçí dir_handle. Ôï stream ðñÝðåé íá Ý÷åé ðñïçãïõìÝíïò áíïé÷ôåß áðü ôçí opendir().
ÅðéóôñÝöåé ôïí êáôáëüãï óôïí ïðïßï ôþñá ãßíåôáé åñãáóßá.
ÁíáôñÝîôå åðßóçò óôçí chdir().
ÅðéóôñÝöåé ôç handle ôïõ êáôáëüãïõ ðïõ ðñüêåéôáé íá ÷ñçóéìïðïéçèåß óå áêüëïõèåò êëÞóåéò ôùí closedir(), readdir(), êáé rewinddir().
ÅÜí ç path äå äåß÷íåé Ýíáí Ýãêõñï êáôÜëïãï Þ ï ôåëåõôáßïò äåí ìðïñåß íá áíïé÷ôåß ëüãù ðåñéïñéóìþí óôá permissions Þ filesystem errors, ç opendir() åðéóôñÝöåé FALSE êáé ðáñÜãåé Ýíá PHP error. Ìðïñåßôå íá åðéëÝîåôå íá ìçí åìöáíßæïíôáé ôá ëÜèç ôçò opendir() ìå ôï íá ôïðïèåôÞóåôå `@' ìðñïóôÜ áðü ôï üíïìá ôçò óõíÜñôçóçò.
ÁíáôñÝîôå åðßóçò óôçí is_dir().
ÅðéóôñÝöåé ôï üíïìá ôïõ åðüìåíïõ áñ÷åßïõ ôïõ êáôáëüãïõ. Ôá ïíüìáôá ôùí áñ÷åßùí åðéóôñÝöïíôáé ìå ôç óåéñÜ êáôÜ ôçí ïðïßá áðïèçêåýïíôáé áðü ôï filesystem.
Ðáñáêáëþ ðáñáôçñÞóôå ôïí ôñüðï ìå ôïí ïðïßï ç åðéóôñåöüìåíç ôéìÞ ôçò readdir() åëÝã÷åôáé óôá áêüëïõèá ðáñáäåßãìáôá. ÄïêéìÜæïõìå ëåðôïìåñþò åÜí ç ôéìÞ áõôÞ åßíáé ðáíïìïéüôõðç ìå (ßóç êáé ôïõ ßäéïõ ôýðïõ ìå -- áíáôñÝîôå óôïõò ÔåëåóôÝò Óýãêñéóçò ãéá ðåñéóóüôåñåò ðëçñïöïñßåò) FALSE áöïý óå Üëëç ðåñßðôùóç ïðïéïäÞðïôå óôïé÷åßï êáôáëüãïõ, ôï üíïìá ôïõ ïðïßïõ äßíåé FALSE èá óôáìáôÞóåé ôï loop (ð.÷. Ýíáò êáôÜëïãïò ïíïìáæüìåíïò "0").
ÐáñÜäåéãìá 1. Ðáñïõóßáóç üëùí ôùí áñ÷åßùí ôïõ êáôáëüãïõ
|
Ðáñáôçñåßóôå üôé ç readdir() èá åðéóôñÝøåé ôá óôïé÷åßá . êáé ... ÅÜí äåí ôá èÝëåôå, áðëÜ ðáñáëåßøôå ôá, üðùò óôï áêüëïõèï ðáñÜäåéãìá
ÁíáôñÝîôå åðßóçò óôçí is_dir().
ÊÜíåé reset ôï stream ôïõ êáôáëüãïõ, ðïõ äåß÷íåôáé áðü ôçí dir_handle óôçí áñ÷Þ áõôïý.
Returns an array of files and directories from the directory. If directory is not a directory, then boolean FALSE is returned, and an error of level E_WARNING is generated.
By default, the sorted order is alphabetical in ascending order. If the optional sorting_order is used (set to 1), then sort order is alphabetical in descending order.
ÐáñÜäåéãìá 1. A simple scandir() example
Outputs something like:
|
ÐáñÜäåéãìá 2. PHP 4 alternatives to scandir()
Outputs something like:
|
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
See also opendir(), readdir(), glob(), is_dir(), and sort().
The DOM extension is the replacement for the domxml extension from PHP 4. The extension still contains many old functions, but they should no longer be used. In particular, functions that are not object-oriented should be avoided.
The extension allows you to operate on an XML document with the DOM API.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðßíáêáò 1. XML constants
Constant | Value | Description |
---|---|---|
XML_ELEMENT_NODE (integer) | 1 | Node is an element |
XML_ATTRIBUTE_NODE (integer) | 2 | Node is an attribute |
XML_TEXT_NODE (integer) | 3 | Node is a piece of text |
XML_CDATA_SECTION_NODE (integer) | 4 | |
XML_ENTITY_REF_NODE (integer) | 5 | |
XML_ENTITY_NODE (integer) | 6 | Node is an entity like |
XML_PI_NODE (integer) | 7 | Node is a processing instruction |
XML_COMMENT_NODE (integer) | 8 | Node is a comment |
XML_DOCUMENT_NODE (integer) | 9 | Node is a document |
XML_DOCUMENT_TYPE_NODE (integer) | 10 | |
XML_DOCUMENT_FRAG_NODE (integer) | 11 | |
XML_NOTATION_NODE (integer) | 12 | |
XML_HTML_DOCUMENT_NODE (integer) | 13 | |
XML_DTD_NODE (integer) | 14 | |
XML_ELEMENT_DECL_NODE (integer) | 15 | |
XML_ATTRIBUTE_DECL_NODE (integer) | 16 | |
XML_ENTITY_DECL_NODE (integer) | 17 | |
XML_NAMESPACE_DECL_NODE (integer) | 18 | |
XML_ATTRIBUTE_CDATA (integer) | 1 | |
XML_ATTRIBUTE_ID (integer) | 2 | |
XML_ATTRIBUTE_IDREF (integer) | 3 | |
XML_ATTRIBUTE_IDREFS (integer) | 4 | |
XML_ATTRIBUTE_ENTITY (integer) | 5 | |
XML_ATTRIBUTE_NMTOKEN (integer) | 7 | |
XML_ATTRIBUTE_NMTOKENS (integer) | 8 | |
XML_ATTRIBUTE_ENUMERATION (integer) | 9 | |
XML_ATTRIBUTE_NOTATION (integer) | 10 |
Ðßíáêáò 2. DOMException constants
Constant | Value | Description |
---|---|---|
DOM_INDEX_SIZE_ERR (integer) | 1 | |
DOMSTRING_SIZE_ERR (integer) | 2 | |
DOM_HIERARCHY_REQUEST_ERR (integer) | 3 | |
DOM_WRONG_DOCUMENT_ERR (integer) | 4 | |
DOM_INVALID_CHARACTER_ERR (integer) | 5 | |
DOM_NO_DATA_ALLOWED_ERR (integer) | 6 | |
DOM_NO_MODIFICATION_ALLOWED_ERR (integer) | 7 | |
DOM_NOT_FOUND_ERR (integer) | 8 | |
DOM_NOT_SUPPORTED_ERR (integer) | 9 | |
DOM_INUSE_ATTRIBUTE_ERR (integer) | 10 | |
DOM_INVALID_STATE_ERR (integer) | 11 | |
DOM_SYNTAX_ERR (integer) | 12 | |
DOM_INVALID_MODIFICATION_ERR (integer) | 13 | |
DOM_NAMESPACE_ERR (integer) | 14 | |
DOM_INVALID_ACCESS_ERR (integer) | 15 | |
DOM_VALIDATION_ERR (integer) | 16 |
The API of the module follows the DOM Level 2 standard as closely as possible. Consequently, the API is fully object-oriented. It is a good idea to have the DOM standard available when using this module.
This module defines a number of classes, which are listed - including their method - in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.
Ðßíáêáò 3. List of classes
Class name | Parent classes |
---|---|
DOMAttr | DOMNode |
DOMCDataSection | DOMText : DOMNode |
DOMCharacterData | DOMNode |
DOMComment | DOMCharacterData : DomNode |
DOMDocument | DOMNode |
DOMDocumentFragment | DOMNode |
DOMDocumentType | DOMNode |
DOMElement | DOMNode |
DOMEntity | DOMNode |
DOMEntityReference | DOMNode |
DOMNode | |
DOMNotation | DOMNode |
DOMProcessingInstruction | DOMNode |
DOMText | DOMCDataSection : DomNode |
DOMException | |
DOMImplementation | |
DOMNamedNodeMap | |
DOMNodeList | |
DOMXPath |
(no version information, might be only in CVS)
DOMCharacterData->appendData -- Append the string to the end of the character data of the node.Append the string data to the end of the character data of the node.
(no version information, might be only in CVS)
DOMCharacterData->deleteData -- Remove a range of characters from the node.Deletes count characters starting from position offset. If the sum of offset and count exceeds the length, then all characters to the end of the data are deleted.
Throws DOMExcpetion if offset is negative or greater than the number of characters in data, or if count is negative.
(no version information, might be only in CVS)
DOMCharacterData->insertData -- Insert a string at the specified 16-bit unit offset.Inserts string data at position offset.
Throws DOMExcpetion if offset is negative or greater than the number of 16-bit units in data.
(no version information, might be only in CVS)
DOMCharacterData->replaceData -- Replace a substring within the DOMCharacterData node.Replace count characters starting from position offset with data. If the sum of offset and count exceeds the length, then all characters to the end of the data are replaced.
Throws DOMExcpetion if offset is negative or greater than the number of characters in data, or if count is negative.
(no version information, might be only in CVS)
DOMCharacterData->substringData -- Extracts a range of data from the node.Returns the specified substring. If the sum of offset and count exceeds the length, then all 16-bit units to the end of the data are returned.
Throws DOMExcpetion if offset is negative or greater than the number of 16-bit units in data, or if count is negative.
This function returns a new instance of class DOMAttr. The name of the attribute is the value of the first parameter. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMDocument->createElement(), DOMNode->appendChild(), DOMDocument->createTextNode(), DOMDocument->createComment() and DOMDocument->createProcessingInstruction().
(no version information, might be only in CVS)
DOMDocument->createAttributeNS -- Create new attribute node with an associated namespaceThis function returns a new instance of class DOMAttr. The tag name and prefix of the attribute is determined by the value of the passed parameter qualifiedName. The URI of the namespace is the value of namespaceURI. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMDocument->createElementNS(), DOMNode->appendChild(), DOMDocument->createElement(), DOMDocument->createTextNode() and DOMDocument->createAttribute().
(no version information, might be only in CVS)
DOMDocument->createCDATASection -- Create new cdata nodeThis function returns a new instance of class DOMCDATASection. The content of the cdata is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMNode->appendChild(), DOMDocument->createElement(), DOMDocument->createTextNode(), DOMDocument->createAttribute(), DOMDocument->createProcessingInstruction().
This function returns a new instance of class DOMComment. The content of the comment is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMNode->appendChild(), DOMDocument->createElement(), DOMDocument->createTextNode(), DOMDocument->createAttribute(), DOMDocument->createProcessingInstruction().
(no version information, might be only in CVS)
DOMDocument->createDocumentFragment -- Create new document fragmentThis function returns a new instance of class DOMAttr. The name of the attribute is the value of the first parameter. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
This function returns a new instance of class DOMElement. The tag name of the element is the value of the name parameter. Optionally, a value for the new element may also be passed in. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMDocument->createElementNS(), DOMNode->appendChild(), DOMDocument->createTextNode(), DOMDocument->createComment(), DOMDocument->createAttribute(), DOMDocument->createProcessingInstruction().
(no version information, might be only in CVS)
DOMDocument->createElementNS -- Create new element node with an associated namespaceThis function returns a new instance of class DOMElement. The tag name and prefix of the element is determined by the value of the passed parameter qualifiedName. The URI of the namespace is the value of the passed parameter namespaceURI. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMNode->appendChild(), DOMDocument->createAttributeNS(), DOMDocument->createElement(), DOMDocument->createAttribute() and DOMDocument->createComment().
(no version information, might be only in CVS)
DOMDocument->createEntityReference -- Create new entity reference nodeThis function returns a new instance of class DOMEntityReference. The content of the entity reference is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMNode->appendChild(), DOMDocument->createElement(), DOMDocument->createAttribute() and DOMDocument->createComment().
(no version information, might be only in CVS)
DOMDocument->createProcessingInstruction -- Creates new PI nodeThis function returns a new instance of class DOMProcessingInstruction. The content of the pi is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMNode->appendChild(), DOMDocument->createElement(), DOMDocument->createAttribute() and DOMDocument->createComment().
This function returns a new instance of class DOMText. The content of the text is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. DOMNode->appendChild().
The return value is FALSE if an error occurred.
See also DOMNode->appendChild(), DOMDocument->createElement(), DOMDocument->createAttribute() and DOMDocument->createComment().
(no version information, might be only in CVS)
DOMDocument->getElementById -- Searches for an element with a certain id.This function is similar to DOMDocument->getElementsByTagName() but searches for an element with a given id. According to the DOM standard this requires a DTD which defines the attribute ID to be of type ID.
(no version information, might be only in CVS)
DOMDocument->getElementsByTagName -- Searches for all elements with given tag name.This function returns a new instance of class DOMNodeList containing the elements with tagnames matching the name parameter. Use "*" for the name to return all elements within the document.
(no version information, might be only in CVS)
DOMDocument->getElementsByTagNameNS -- Searches for all elements with given tag name in specified namespace.This function returns a new instance of class DOMNodeList containing the elements with tagnames matching the localName parameter and in the namespaceURI namespace. Use "*" for the name to return all elements within the document.
(no version information, might be only in CVS)
DOMDocument->importNode -- Import node into current document.This function returns a copy of the node to import and associates it with the current document. DOMExcpetion is thrown if node cannot be imported.
The function parses the XML document in the file named filename. This function may also be called statically to load and create a DOMDocument object. The static invocation may be used when no DOMDocument properties need to be set prior to loading.
See also DOMDocument->loadXML(), DOMDocument->save() and DOMDocument->saveXML().
The function parses the HTML contained in the string source. Unlike loading XML, HTML does not have to be well-formed to load. This function may also be called statically to load and create a DOMDocument object. The static invocation may be used when no DOMDocument properties need to be set prior to loading.
See also DOMDocument->loadHTMLFile(), DOMDocument->saveHTML() and DOMDocument->saveHTMLFile().
The function parses the HTML document in the file named filename. Unlike loading XML, HTML does not have to be well-formed to load.This function may also be called statically to load and create a DOMDocument object. The static invocation may be used when no DOMDocument properties need to be set prior to loading.
See also DOMDocument->loadHTML(), DOMDocument->saveHTML() and DOMDocument->saveHTMLFile().
The function parses the XML contained in the string source. This function may also be called statically to load and create a DOMDocument object. The static invocation may be used when no DOMDocument properties need to be set prior to loading.
See also DOMDocument->load(), DOMDocument->save() and DOMDocument->saveXML().
(no version information, might be only in CVS)
DOMDocument->relaxNGValidate -- Performs relaxNG validation on the document.Performs relaxNG validation on the document based on the file defined by filename.
See also DOMDocument->validate(), DOMDocument->schemaValidate(), DOMDocument->schemaValidateSource() and DOMDocument->relaxNGValidateSource().
(no version information, might be only in CVS)
DOMDocument->relaxNGValidateSource -- Performs relaxNG validation on the document.Performs relaxNG validation on the document based on the file defined in string source.
See also DOMDocument->validate(), DOMDocument->schemaValidate(), DOMDocument->schemaValidateSource() and DOMDocument->relaxNGValidate().
(no version information, might be only in CVS)
DOMDocument->save -- Dumps the internal XML tree back into a fileCreates an XML document from the dom representation. The number of bytes written is returned. This function is usually called after building a new dom document from scratch as in the example below.
ÐáñÜäåéãìá 1. Creating a simple HTML document header
|
See also DOMDocument->load(), DOMDocument->loadXML() and DOMDocument->saveXML().
(no version information, might be only in CVS)
DOMDocument->saveHTML -- Dumps the internal document into a string using HTML formattingCreates an HTML document from the dom representation. This function usually is called after building a new dom document from scratch as in the example below.
ÐáñÜäåéãìá 1. Creating a simple HTML document header
|
See also DOMDocument->loadHTML(), DOMDocument->loadHTMLFile() and DOMDocument->saveHTMLFile().
(no version information, might be only in CVS)
DOMDocument->saveHTMLFile -- Dumps the internal document back into a file using HTML formattingCreates an HTML document from the dom representation. This function usually is called after building a new dom document from scratch as in the example below.
ÐáñÜäåéãìá 1. Creating a simple HTML document header
|
See also DOMDocument->loadHTML(), DOMDocument->loadHTMLFile() and DOMDocument->saveHTML().
(no version information, might be only in CVS)
DOMDocument->saveXML -- Dumps the internal XML tree back into a stringCreates an XML document from the dom representation. This function is usually called after building a new dom document from scratch as in the example below. The node is used to output only the node rather than the entire document.
ÐáñÜäåéãìá 1. Creating a simple HTML document header
|
See also DOMDocument->load(), DOMDocument->loadXML() and DOMDocument->save().
(no version information, might be only in CVS)
DOMDocument->schemaValidate -- Validates a document based on a schema.Validates a document based on a schema defined by filename.
See also DOMDocument->schemaValidateSource(), DOMDocument->relaxNGValidate(), DOMDocument->relaxNGValidateSource() and DOMDocument->validate().
(no version information, might be only in CVS)
DOMDocument->schemaValidateSource -- Validates a document based on a schema.Validates a document based on a schema defined in string source.
See also DOMDocument->schemaValidate(), DOMDocument->relaxNGValidate(), DOMDocument->relaxNGValidateSource() and DOMDocument->validate(),.
(no version information, might be only in CVS)
DOMDocument->validate -- Validates the document based on its DTD.Validates the document based on its DTD.
See also DOMDocument->schemaValidate(), DOMDocument->schemaValidateSource(), DOMDocument->relaxNGValidate(), DOMDocument->relaxNGValidateSource().
(no version information, might be only in CVS)
DOMDocument->xinclude -- Substitutes XIncludes in a DOMDocument Object.(no version information, might be only in CVS)
DOMElement->getAttribute -- Returns value of attributeReturns the value of the attribute with name name for the current node. If no attribute with given name is found, an empty string is returned.
See also DOMElement->setAttribute()
(no version information, might be only in CVS)
DOMElement->getAttributeNode -- Returns attribute nodeReturns the attribute node with name name for the current element.
See also DOMElement->setAttribute()
(no version information, might be only in CVS)
DOMElement->getAttributeNodeNS -- Returns attribute nodeReturns the attribute node in namespace namespaceURI with local name localName for the current node.
See also DOMElement->setAttributeNodeNS()
(no version information, might be only in CVS)
DOMElement->getAttributeNS -- Returns value of attributeReturns the value of the attribute in namespace namespaceURI with local name localName for the current node. If no attribute with given name is found, an empty string is returned.
See also DOMElement->setAttributeNS()
(no version information, might be only in CVS)
DOMElement->getElementsByTagName -- Gets elements by tagnameThis function returns a new instance of class DOMNodeList containing the elements with tagnames matching the name parameter. Use "*" for the name to return all elements within the document.
(no version information, might be only in CVS)
DOMElement->getElementsByTagNameNS -- Get elements by namespaceURI and localNameThis function returns a new instance of class DOMNodeList containing the elements in the namespace namespaceURI having localName. Use "*" for the name to return all elements within the document.
(no version information, might be only in CVS)
DOMElement->hasAttribute -- Checks to see if attribute existsIndicates wether attribute named name exists as a member of the element.
(no version information, might be only in CVS)
DOMElement->hasAttributeNS -- Checks to see if attribute existsIndicates wether attribute in namespace namespaceURI named localName exists as a member of the element.
Removes attribute named name from the element.
Throws DOMExcpetion if node cannot be modified.
Removes attribute oldnode from the element.
Throws DOMExcpetion if node cannot be modified or attribute is not a member of the element node.
Removes attribute is namespace namespaceURI named localName from the element.
Throws DOMExcpetion if node cannot be modified.
Sets an attribute with name name to the given value. If the attribute does not exist, it will be created.
Throws DOMExcpetion if node cannot be modified.
See also DOMElement->getAttribute()
(no version information, might be only in CVS)
DOMElement->setAttributeNode -- Adds new attribute node to elementAdds new attribute node attr to element. Returns old node if attribute replaced.
Throws DOMExcpetion if node cannot be modified.
(no version information, might be only in CVS)
DOMElement->setAttributeNodeNS -- Adds new attribute node to elementAdds new attribute node attr to element. Returns old node if attribute replaced.
Throws DOMExcpetion if node cannot be modified.
Sets an attribute with namespace namespaceURI and name name to the given value. If the attribute does not exist, it will be created.
Throws DOMExcpetion if node cannot be modified.
See also DOMElement->getAttributeNS()
(no version information, might be only in CVS)
DOMImplementation->createDocument -- Creates a DOM Document object of the specified type with its document element.Creates a DOMDocument object of the specified type with its document element. If namespaceURI, qualifiedName, and doctype are null, the returned DOMDocument is empty with no document element
Throws DOMExcpetion if there is an error with the namespace, as determined by namespaceURI and qualifiedName, or if doctype is not valid.
See also DOMImplementation->createDocumentType().
(no version information, might be only in CVS)
DOMImplementation->createDocumentType -- Creates an empty DOMDocumentType object.Creates an empty DOMDocumentType object. Entity declarations and notations are not made available. Entity reference expansions and default attribute additions do not occur.
Throws DOMExcpetion if there is an error with the namespace, as determined by qualifiedName.
See also DOMImplementation->createDocument().
(no version information, might be only in CVS)
DOMImplementation->hasFeature -- Test if the DOM implementation implements a specific feature and version.Test if the DOM implementation implements a specific feature and version.
(no version information, might be only in CVS)
DOMNamedNodeMap->getNamedItem -- Retrieves a node specified by name.(no version information, might be only in CVS)
DOMNamedNodeMap->getNamedItemNS -- Retrieves a node specified by local name and namespace URI.Retrieves a node specified by localName and namespaceURI.
(no version information, might be only in CVS)
DOMNamedNodeMap->item -- Retrieves a node specified by index.Retrieves a node specified by index within the DOMNamedNodeMap object.
(no version information, might be only in CVS)
DOMNode->appendChild -- Adds new child at the end of the childrenThis functions appends a child to an existing list of children or creates a new list of children. The child can be created with e.g. DOMDocument->createElement(), DOMDocument->createTextNode() etc. or simply by using any other node.
Throws DOMException if node cannot be appended.
The following example will add a new element node to a fresh document.
Creates a copy of the node. The paramter deep indicates wether to copy all descedant nodes. This paramter is defaulted to FALSE.
(no version information, might be only in CVS)
DOMNode->hasAttributes -- Checks if node has attributes(no version information, might be only in CVS)
DOMNode->insertBefore -- Adds new child at the end of the childrenThis function inserts the new node newnode right before the node refnode. The return value is the inserted node. If you plan to do further modifications on the appended child you must use the returned node. If refnode is not supplied then newnode is appended to the children.
Throws DOMException if node cannot be inserted.
(no version information, might be only in CVS)
DOMNode->isSameNode -- Indicates if two nodes are the same node.This functions indicates if two nodes are the same node. The comparison is NOT based on content
(no version information, might be only in CVS)
DOMNode->isSupported -- Checks if feature is supported for specified version.Checks if feature is supported for specified version.
(no version information, might be only in CVS)
DOMNode->lookupNamespaceURI -- Returns namespace URI of the node based on the prefix.Returns namespace URI of the node based on the prefix.
(no version information, might be only in CVS)
DOMNode->lookupPrefix -- Returns name space prefix of the node based on namespaceURI.Returns name space prefix of the node based on namespaceURI.
(no version information, might be only in CVS)
DOMNode->removeChild -- Removes child from list of childrenThis functions removes a child from a list of children. If the child could be removed the functions returns the old child.
Throws DOMException if node cannot be removed.
This function replaces the child oldnode with the passed new node. If the new node is already a child it will not be added a second time.If the replacement succeeds the old node is returned.
Throws DOMException if node cannot be replaced.
(no version information, might be only in CVS)
DOMNodelist->item -- Retrieves a node specified by index.Retrieves a node specified by index within the DOMNodelist object.
(no version information, might be only in CVS)
DOMText->isWhitespaceInElementContent -- Indicates whether this text node contains whitespace.Indicates whether this text node contains whitespace. The text node is determined to contain whitespace in element content during the load of the document.
(no version information, might be only in CVS)
DOMText->splitText -- Breaks this node into two nodes at the specified offset.Breaks this node into two nodes at the specified offset, keeping both in the tree as siblings. After being split, this node will contain all the content up to the offset. A new node of the same type, which contains all the content at and after the offset, is returned. If the original node had a parent node, the new node is inserted as the next sibling of the original node. When the offset is equal to the length of this node, the new node has no data.
(no version information, might be only in CVS)
DOMXPath->query -- Evaluates the XPath expression in the given stringReturns a DOMNodelist containing all nodes matching expression. Any expression which do not return nodes will return an empty DOMNodelist.
The optional contextnode can be specified for doing relative XPath queries.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
The DOM XML extension has been overhauled in PHP 4.3.0 to better comply with the DOM standard. The extension still contains many old functions, but they should no longer be used. In particular, functions that are not object-oriented should be avoided.
The extension allows you to operate on an XML document with the DOM API. It also provides a function domxml_xmltree() to turn the complete XML document into a tree of PHP objects. Currently, this tree should be considered read-only - you can modify it, but this would not make any sense since DomDocument_dump_mem() cannot be applied to it. Therefore, if you want to read an XML file and write a modified version, use DomDocument_create_element(), DomDocument_create_text_node(), set_attribute(), etc. and finally the DomDocument_dump_mem() function.
This extension makes use of the GNOME XML library. Download and install this library. You will need at least libxml-2.4.14. To use DOM XSLT features you can use the libxslt library and EXSLT enhancements from http://www.exslt.org/. Download and install these libraries if you plan to use (enhanced) XSLT features. You will need at least libxslt-1.0.18.
This extension is only available if PHP was configured with --with-dom[=DIR]. Add --with-dom-xslt[=DIR] to include DOM XSLT support. DIR is the libxslt install directory. Add --with-dom-exslt[=DIR] to include DOM EXSLT support, where DIR is the libexslt install directory.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy one additional file from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your Windows machine (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32). For PHP <= 4.2.0 copy libxml2.dll, for PHP >= 4.3.0 copy iconv.dll from the DLL folder to your SYSTEM32 folder.
There are quite a few functions that do not fit into the DOM standard and should no longer be used. These functions are listed in the following table. The function DomNode_append_child() has changed its behaviour. It now adds a child and not a sibling. If this breaks your application, use the non-DOM function DomNode_append_sibling().
Ðßíáêáò 1. Deprecated functions and their replacements
Old function | New function |
---|---|
xmldoc | domxml_open_mem() |
xmldocfile | domxml_open_file() |
domxml_new_xmldoc | domxml_new_doc() |
domxml_dump_mem | DomDocument_dump_mem() |
domxml_dump_mem_file | DomDocument_dump_file() |
DomDocument_dump_mem_file | DomDocument_dump_file() |
DomDocument_add_root | DomDocument_create_element() followed by DomNode_append_child() |
DomDocument_dtd | DomDocument_doctype() |
DomDocument_root | DomDocument_document_element() |
DomDocument_children | DomNode_child_nodes() |
DomDocument_imported_node | No replacement. |
DomNode_add_child | Create a new node with e.g. DomDocument_create_element() and add it with DomNode_append_child(). |
DomNode_children | DomNode_child_nodes() |
DomNode_parent | DomNode_parent_node() |
DomNode_new_child | Create a new node with e.g. DomDocument_create_element() and add it with DomNode_append_child(). |
DomNode_set_content | Create a new node with e.g. DomDocument_create_text_node() and add it with DomNode_append_child(). |
DomNode_get_content | Content is just a text node and can be accessed with DomNode_child_nodes(). |
DomNode_set_content | Content is just a text node and can be added with DomNode_append_child(). |
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðßíáêáò 2. XML constants
Constant | Value | Description |
---|---|---|
XML_ELEMENT_NODE (integer) | 1 | Node is an element |
XML_ATTRIBUTE_NODE (integer) | 2 | Node is an attribute |
XML_TEXT_NODE (integer) | 3 | Node is a piece of text |
XML_CDATA_SECTION_NODE (integer) | 4 | |
XML_ENTITY_REF_NODE (integer) | 5 | |
XML_ENTITY_NODE (integer) | 6 | Node is an entity like |
XML_PI_NODE (integer) | 7 | Node is a processing instruction |
XML_COMMENT_NODE (integer) | 8 | Node is a comment |
XML_DOCUMENT_NODE (integer) | 9 | Node is a document |
XML_DOCUMENT_TYPE_NODE (integer) | 10 | |
XML_DOCUMENT_FRAG_NODE (integer) | 11 | |
XML_NOTATION_NODE (integer) | 12 | |
XML_GLOBAL_NAMESPACE (integer) | 1 | |
XML_LOCAL_NAMESPACE (integer) | 2 | |
XML_HTML_DOCUMENT_NODE (integer) | ||
XML_DTD_NODE (integer) | ||
XML_ELEMENT_DECL_NODE (integer) | ||
XML_ATTRIBUTE_DECL_NODE (integer) | ||
XML_ENTITY_DECL_NODE (integer) | ||
XML_NAMESPACE_DECL_NODE (integer) | ||
XML_ATTRIBUTE_CDATA (integer) | ||
XML_ATTRIBUTE_ID (integer) | ||
XML_ATTRIBUTE_IDREF (integer) | ||
XML_ATTRIBUTE_IDREFS (integer) | ||
XML_ATTRIBUTE_ENTITY (integer) | ||
XML_ATTRIBUTE_NMTOKEN (integer) | ||
XML_ATTRIBUTE_NMTOKENS (integer) | ||
XML_ATTRIBUTE_ENUMERATION (integer) | ||
XML_ATTRIBUTE_NOTATION (integer) | ||
XPATH_UNDEFINED (integer) | ||
XPATH_NODESET (integer) | ||
XPATH_BOOLEAN (integer) | ||
XPATH_NUMBER (integer) | ||
XPATH_STRING (integer) | ||
XPATH_POINT (integer) | ||
XPATH_RANGE (integer) | ||
XPATH_LOCATIONSET (integer) | ||
XPATH_USERS (integer) | ||
XPATH_NUMBER (integer) |
The API of the module follows the DOM Level 2 standard as closely as possible. Consequently, the API is fully object-oriented. It is a good idea to have the DOM standard available when using this module. Though the API is object-oriented, there are many functions which can be called in a non-object-oriented way by passing the object to operate on as the first argument. These functions are mainly to retain compatibility to older versions of the extension, and should not be used when creating new scripts.
This API differs from the official DOM API in two ways. First, all class attributes are implemented as functions with the same name. Secondly, the function names follow the PHP naming convention. This means that a DOM function lastChild() will be written as last_child().
This module defines a number of classes, which are listed - including their method - in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.
Ðßíáêáò 3. List of classes
Class name | Parent classes |
---|---|
DomAttribute | DomNode |
DomCData | DomNode |
DomComment | DomCData : DomNode |
DomDocument | DomNode |
DomDocumentType | DomNode |
DomElement | DomNode |
DomEntity | DomNode |
DomEntityReference | DomNode |
DomProcessingInstruction | DomNode |
DomText | DomCData : DomNode |
Parser | Currently still called DomParser |
XPathContext |
Ðßíáêáò 4. DomDocument class (DomDocument : DomNode)
Method name | Function name | Remark |
---|---|---|
doctype | DomDocument_doctype() | |
document_element | DomDocument_document_element() | |
create_element | DomDocument_create_element() | |
create_text_node | DomDocument_create_text_node() | |
create_comment | DomDocument_create_comment() | |
create_cdata_section | DomDocument_create_cdata_section() | |
create_processing_instruction | DomDocument_create_processing_instruction() | |
create_attribute | DomDocument_create_attribute() | |
create_entity_reference | DomDocument_create_entity_reference() | |
get_elements_by_tagname | DomDocument_get_elements_by_tagname() | |
get_element_by_id | DomDocument_get_element_by_id() | |
dump_mem | DomDocument_dump_mem() | not DOM standard |
dump_file | DomDocument_dump_file() | not DOM standard |
html_dump_mem | DomDocument_html_dump_mem() | not DOM standard |
xpath_init | xpath_init | not DOM standard |
xpath_new_context | xpath_new_context | not DOM standard |
xptr_new_context | xptr_new_context | not DOM standard |
Ðßíáêáò 5. DomElement class (DomElement : DomNode)
Method name | Function name | Remark |
---|---|---|
tagname | DomElement_tagname() | |
get_attribute | DomElement_get_attribute() | |
set_attribute | DomElement_set_attribute() | |
remove_attribute | DomElement_remove_attribute() | |
get_attribute_node | DomElement_get_attribute_node() | |
get_elements_by_tagname | DomElement_get_elements_by_tagname() | |
has_attribute | DomElement_has_attribute() |
Ðßíáêáò 6. DomNode class
Method name | Remark |
---|---|
DomNode_node_name() | |
DomNode_node_value() | |
DomNode_node_type() | |
DomNode_last_child() | |
DomNode_first_child() | |
DomNode_child_nodes() | |
DomNode_previous_sibling() | |
DomNode_next_sibling() | |
DomNode_parent_node() | |
DomNode_owner_document() | |
DomNode_insert_before() | |
DomNode_append_child() | |
DomNode_append_sibling() | Not in DOM standard. This function emulates the former behaviour of DomNode_append_child(). |
DomNode_remove_child() | |
DomNode_has_child_nodes() | |
DomNode_has_attributes() | |
DomNode_clone_node() | |
DomNode_attributes() | |
DomNode_unlink_node() | Not in DOM standard |
DomNode_replace_node() | Not in DOM standard |
DomNode_set_content() | Not in DOM standard, deprecated |
DomNode_get_content() | Not in DOM standard, deprecated |
DomNode_dump_node() | Not in DOM standard |
DomNode_is_blank_node() | Not in DOM standard |
Ðßíáêáò 7. DomAttribute class (DomAttribute : DomNode)
Method name | Remark | |
---|---|---|
name | DomAttribute_name() | |
value | DomAttribute_value() | |
specified | DomAttribute_specified() |
Ðßíáêáò 8. DomProcessingInstruction class (DomProcessingInstruction : DomNode)
Method name | Function name | Remark |
---|---|---|
target | DomProcessingInstruction_target() | |
data | DomProcessingInstruction_data() |
Ðßíáêáò 10. XPathContext class
Method name | Function name | Remark |
---|---|---|
eval | XPathContext_eval() | |
eval_expression | XPathContext_eval_expression() | |
register_ns | XPathContext_register_ns() |
Ðßíáêáò 11. DomDocumentType class (DomDocumentType : DomNode)
Method name | Function name | Remark |
---|---|---|
name | DomDocumentType_name() | |
entities | DomDocumentType_entities() | |
notations | DomDocumentType_notations() | |
public_id | DomDocumentType_public_id() | |
system_id | DomDocumentType_system_id() | |
internal_subset | DomDocumentType_internal_subset() |
The classes DomDtd is derived from DomNode. DomComment is derived from DomCData.
Many examples in this reference require an XML string. Instead of repeating this string in every example, it will be put into a file which will be included by each example. This include file is shown in the following example section. Alternatively, you could create an XML document and read it with DomDocument_open_file().
ÐáñÜäåéãìá 1. Include file example.inc with XML string
|
This function returns the name of the attribute.
See also domattribute_value().
(no version information, might be only in CVS)
DomAttribute->specified -- Checks if attribute is specifiedThis function returns the value of the attribute.
See also domattribute_name().
(no version information, might be only in CVS)
DomDocument->add_root -- Adds a root node [deprecated]Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Adds a root element node to a dom document and returns the new node. The element name is given in the passed parameter.
This function returns a new instance of class DomAttribute. The name of the attribute is the value of the first parameter. The value of the attribute is the value of the second parameter. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domnode_append_child(), domdocument_create_element(), domdocument_create_text(), domdocument_create_cdata_section(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().
(no version information, might be only in CVS)
DomDocument->create_cdata_section -- Create new cdata nodeThis function returns a new instance of class DomCData. The content of the cdata is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domnode_append_child(), domdocument_create_element(), domdocument_create_text(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().
(no version information, might be only in CVS)
DomDocument->create_comment -- Create new comment nodeThis function returns a new instance of class DomComment. The content of the comment is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domnode_append_child(), domdocument_create_element(), domdocument_create_text(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().
(no version information, might be only in CVS)
DomDocument->create_element_ns -- Create new element node with an associated namespaceThis function returns a new instance of class DomElement. The tag name of the element is the value of the passed parameter name. The URI of the namespace is the value of the passed parameter uri. If there is already a namespace declaration with the same uri in the root-node of the document, the prefix of this is taken, otherwise it will take the one provided in the optional parameter prefix or generate a random one. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domdocument_create_element_ns(), domnode_add_namespace(), domnode_set_namespace(), domnode_append_child(), domdocument_create_text(), domdocument_create_comment(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().
(no version information, might be only in CVS)
DomDocument->create_element -- Create new element nodeThis function returns a new instance of class DomElement. The tag name of the element is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domdocument_create_element_ns(), domnode_append_child(), domdocument_create_text(), domdocument_create_comment(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().
This function returns a new instance of class DomEntityReference. The content of the entity reference is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domnode_append_child(), domdocument_create_element(), domdocument_create_text(), domdocument_create_cdata_section(), domdocument_create_processing_instruction(), domdocument_create_attribute(), and domnode_insert_before().
(no version information, might be only in CVS)
DomDocument->create_processing_instruction -- Creates new PI nodeThis function returns a new instance of class DomCData. The content of the pi is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domnode_append_child(), domdocument_create_element(), domdocument_create_text(), domdocument_create_cdata_section(), domdocument_create_attribute(), domdocument_create_entity_reference(), and domnode_insert_before().
This function returns a new instance of class DomText. The content of the text is the value of the passed parameter. This node will not show up in the document unless it is inserted with e.g. domnode_append_child().
The return value is FALSE if an error occurred.
See also domnode_append_child(), domdocument_create_element(), domdocument_create_comment(), domdocument_create_text(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().
This function returns an object of class DomDocumentType. In versions of PHP before 4.3 this has been the class Dtd, but the DOM Standard does not know such a class.
See also the methods of class DomDocumentType.
(no version information, might be only in CVS)
DomDocument->document_element -- Returns root element nodeThis function returns the root element node of a document.
The following example returns just the element with name CHAPTER and prints it. The other node -- the comment -- is not returned.
(no version information, might be only in CVS)
DomDocument->dump_file -- Dumps the internal XML tree back into a fileCreates an XML document from the dom representation. This function usually is called after building a new dom document from scratch as in the example below. The format specifies whether the output should be neatly formatted, or not. The first parameter specifies the name of the filename and the second parameter, whether it should be compressed or not.
ÐáñÜäåéãìá 1. Creating a simple HTML document header
|
See also domdocument_dump_mem(), and domdocument_html_dump_mem().
(no version information, might be only in CVS)
DomDocument->dump_mem -- Dumps the internal XML tree back into a stringÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Creates an XML document from the dom representation. This function usually is called after building a new dom document from scratch as in the example below. The format specifies whether the output should be neatly formatted, or not.
ÐáñÜäåéãìá 1. Creating a simple HTML document header
|
Óçìåßùóç: The first parameter was added in PHP 4.3.0.
See also domdocument_dump_file(), and domdocument_html_dump_mem().
(no version information, might be only in CVS)
DomDocument->get_element_by_id -- Searches for an element with a certain idThis function is similar to domdocument_get_elements_by_tagname() but searches for an element with a given id. According to the DOM standard this requires a DTD which defines the attribute ID to be of type ID, though the current implementation simply does an xpath search for "//*[@ID = '%s']". This does not comply to the DOM standard which requires to return null if it is not known which attribute is of type id. This behaviour is likely to be fixed, so do not rely on the current behaviour.
See also domdocument_add_root()
(no version information, might be only in CVS)
DomDocument->html_dump_mem -- Dumps the internal XML tree back into a string as HTMLCreates an HTML document from the dom representation. This function usually is called after building a new dom document from scratch as in the example below.
ÐáñÜäåéãìá 1. Creating a simple HTML document header
|
See also domdocument_dump_file(), and domdocument_html_dump_mem().
(no version information, might be only in CVS)
DomDocument->xinclude -- Substitutes XIncludes in a DomDocument Object.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomDocumentType->internal_subset -- Returns internal subset
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomDocumentType->name -- Returns name of document typeThis function returns the name of the document type.
(no version information, might be only in CVS)
DomDocumentType->notations -- Returns list of notations
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomDocumentType->public_id -- Returns public id of document typeThis function returns the public id of the document type.
The following example echos nothing.
(no version information, might be only in CVS)
DomDocumentType->system_id -- Returns system id of document typeReturns the system id of the document type.
The following example echos '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'.
(no version information, might be only in CVS)
DomElement->get_attribute_node -- Returns value of attribute
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomElement->get_attribute -- Returns value of attributeReturns the attribute with name name of the current node.
(PHP >= 4.3 only) If no attribute with given name is found, an empty string is returned.
See also domelement_set_attribute()
(no version information, might be only in CVS)
DomElement->get_elements_by_tagname -- Gets elements by tagnameThis function returns an array with all the elements which has name as his tagname. Every element of the array is a DomElement.
ÐáñÜäåéãìá 1. Getting a content
|
(no version information, might be only in CVS)
DomElement->has_attribute -- Checks to see if attribute exists
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Sets an attribute with name name to the given value. If the attribute does not exist, it will be created.
See also domelement_get_attribute().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomNode->add_namespace -- Adds a namespace declaration to a node.
See also domdocument_create_element_ns(), and domnode_set_namespace()
(no version information, might be only in CVS)
DomNode->append_child -- Adds new child at the end of the childrenThis functions appends a child to an existing list of children or creates a new list of children. The child can be created with e.g. domdocument_create_element(), domdocument_create_text() etc. or simply by using any other node.
(PHP < 4.3) Before a new child is appended it is first duplicated. Therefore the new child is a completely new copy which can be modified without changing the node which was passed to this function. If the node passed has children itself, they will be duplicated as well, which makes it quite easy to duplicate large parts of an XML document. The return value is the appended child. If you plan to do further modifications on the appended child you must use the returned node.
(PHP 4.3.0/4.3.1) The new child newnode is first unlinked from its existing context, if it's already a child of DomNode. Therefore the node is moved and not copies anymore.
(PHP >= 4.3.2) The new child newnode is first unlinked from its existing context, if it's already in the tree. Therefore the node is moved and not copied. This is the behaviour according to the W3C specifications. If you want to duplicate large parts of an XML document, use DomNode->clone_node() before appending.
The following example will add a new element node to a fresh document and sets the attribute "align" to "left".
ÐáñÜäåéãìá 3. Adding a child
|
See also domnode_insert_before(), and domnode_clone_node().
This functions appends a sibling to an existing node. The child can be created with e.g. domdocument_create_element(), domdocument_create_text() etc. or simply by using any other node.
Before a new sibling is added it is first duplicated. Therefore the new child is a completely new copy which can be modified without changing the node which was passed to this function. If the node passed has children itself, they will be duplicated as well, which makes it quite easy to duplicate large parts of an XML document. The return value is the added sibling. If you plan to do further modifications on the added sibling you must use the returned node.
This function has been added to provide the behaviour of domnode_append_child() as it works till PHP 4.2.
See also domnode_append_before().
This function only returns an array of attributes if the node is of type XML_ELEMENT_NODE.
(PHP >= 4.3 only) If no attributes are found, NULL is returned.
Returns all children of the node.
See also domnode_next_sibling(), and domnode_previous_sibling().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also domdocument_dump_mem().
Returns the first child of the node.
(PHP >= 4.3 only) If no first child is found, NULL is returned.
See also domnode_last_child(), and domnode_next_sibling(), domnode_previous_sibling().
This function returns the content of the actual node.
ÐáñÜäåéãìá 1. Getting a content
|
(no version information, might be only in CVS)
DomNode->has_attributes -- Checks if node has attributesThis function checks if the node has attributes.
See also domnode_has_child_nodes().
(no version information, might be only in CVS)
DomNode->has_child_nodes -- Checks if node has childrenThis function checks if the node has children.
See also domnode_child_nodes().
This function inserts the new node newnode right before the node refnode. The return value is the inserted node. If you plan to do further modifications on the appended child you must use the returned node.
(PHP >= 4.3 only) If newnode already is part of a document, it will be first unlinked from its existing context. If refnode is NULL, then newnode will be inserted at the end of the list of children.
domnode_insert_before() is very similar to domnode_append_child() as the following example shows which does the same as the example at domnode_append_child().
ÐáñÜäåéãìá 1. Adding a child
|
See also domnode_append_child().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns the last child of the node.
(PHP >= 4.3 only) If no last child is found, NULL is returned.
See also domnode_first_child(), and domnode_next_sibling(), domnode_previous_sibling().
(no version information, might be only in CVS)
DomNode->next_sibling -- Returns the next sibling of nodeThis function returns the next sibling of the current node. If there is no next sibling it returns FALSE (< 4.3) or null (>= 4.3). You can use this function to iterate over all children of a node as shown in the example.
ÐáñÜäåéãìá 1. Iterate over children
|
See also domnode_previous_sibling().
Returns name of the node. The name has different meanings for the different types of nodes as illustrated in the following table.
Ðßíáêáò 1. Meaning of value
Type | Meaning |
---|---|
DomAttribute | value of attribute |
DomAttribute | |
DomCDataSection | #cdata-section |
DomComment | #comment |
DomDocument | #document |
DomDocumentType | document type name |
DomElement | tag name |
DomEntity | name of entity |
DomEntityReference | name of entity reference |
DomNotation | notation name |
DomProcessingInstruction | target |
DomText | #text |
Returns the type of the node. All possible types are listed in the table in the introduction.
Returns value of the node. The value has different meanings for the different types of nodes as illustrated in the following table.
Ðßíáêáò 1. Meaning of value
Type | Meaning |
---|---|
DomAttribute | value of attribute |
DomAttribute | |
DomCDataSection | content |
DomComment | content of comment |
DomDocument | null |
DomDocumentType | null |
DomElement | null |
DomEntity | null |
DomEntityReference | null |
DomNotation | null |
DomProcessingInstruction | entire content without target |
DomText | content of text |
(no version information, might be only in CVS)
DomNode->owner_document -- Returns the document this node belongs toThis function returns the document the current node belongs to.
The following example will create two identical lists of children.
See also domnode_insert_before().
(no version information, might be only in CVS)
DomNode->parent_node -- Returns the parent of the nodeThis function returns the parent node.
(PHP >= 4.3 only) If no parent is found, NULL is returned.
The following example will show two identical lists of children.
(no version information, might be only in CVS)
DomNode->previous_sibling -- Returns the previous sibling of nodeThis function returns the previous sibling of the current node. If there is no previous sibling it returns FALSE (< 4.3) or NULL (>= 4.3). You can use this function to iterate over all children of a node as shown in the example.
See also domnode_next_sibling().
(no version information, might be only in CVS)
DomNode->remove_child -- Removes child from list of childrenThis functions removes a child from a list of children. If child cannot be removed or is not a child the function will return FALSE. If the child could be removed the functions returns the old child.
ÐáñÜäåéãìá 1. Removing a child
|
See also domnode_append_child().
(PHP 4.2) This function replaces the child oldnode with the passed new node. If the new node is already a child it will not be added a second time. If the old node cannot be found the function returns FALSE. If the replacement succeeds the old node is returned.
(PHP 4.3) This function replaces the child oldnode with the passed newnode, even if the new node already is a child of the DomNode. If newnode was already inserted in the document it is first unlinked from its existing context. If the old node cannot be found the function returns FALSE. If the replacement succeeds the old node is returned. (This behaviour is according to the W3C specs).
See also domnode_append_child()
(PHP 4.2) This function replaces an existing node with the passed new node. Before the replacement newnode is copied if it has a parent to make sure a node which is already in the document will not be inserted a second time. This behaviour enforces doing all modifications on the node before the replacement or to refetch the inserted node afterwards with functions like domnode_first_child(), domnode_child_nodes() etc..
(PHP 4.3) This function replaces an existing node with the passed new node. It is not copied anymore. If newnode was already inserted in the document it is first unlinked from its existing context. If the replacement succeeds the old node is returned.
See also domnode_append_child()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Sets the namespace of a node to uri. If there is already a namespace declaration with the same uri in one of the parent nodes of the node, the prefix of this is taken, otherwise it will take the one provided in the optional parameter prefix or generate a random one.
See also domdocument_create_element_ns(), and domnode_add_namespace()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomProcessingInstruction->data -- Returns data of pi node
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomProcessingInstruction->target -- Returns target of pi node
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DomXsltStylesheet->process -- Applies the XSLT-Transformation on a DomDocument Object.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also domxml_xslt_stylesheet(), domxml_xslt_stylesheet_file(), and domxml_xslt_stylesheet_doc()
(no version information, might be only in CVS)
DomXsltStylesheet->result_dump_file -- Dumps the result from a XSLT-Transformation into a fileÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function is only available since PHP 4.3
Since DomXsltStylesheet->process() always returns a well-formed XML DomDocument, no matter what output method was declared in <xsl:output> and similar attributes/elements, it's of not much use, if you want to output HTML 4 or text data. This function on the contrary honors <xsl:output method="html|text"> and other output control directives. See the example for instruction of how to use it.
See also domxml_xslt_result_dump_mem(), and domxml_xslt_process()
(no version information, might be only in CVS)
DomXsltStylesheet->result_dump_mem -- Dumps the result from a XSLT-Transformation back into a stringÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function is only available since PHP 4.3
Since DomXsltStylesheet->process() always returns a well-formed XML DomDocument, no matter what output method was declared in <xsl:output> and similar attributes/elements, it's of not much use, if you want to output HTML 4 or text data. This function on the contrary honors <xsl:output method="html|text"> and other output control directives. See the example for instruction of how to use it.
See also domxml_xslt_result_dump_file(), and domxml_xslt_process()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Creates a new dom document from scratch and returns it.
See also domdocument_add_root()
The function parses the XML document in the file named filename and returns an object of class "Dom document", having the properties as listed above. The file is accessed read-only.
See also domxml_open_mem(), and domxml_new_doc().
The function parses the XML document in str and returns an object of class "Dom document", having the properties as listed above. This function, domxml_open_file() or domxml_new_doc() must be called before any other function calls.
See also domxml_open_file(), and domxml_new_doc().
This function returns the version of the XML library version currently used.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function parses the XML document in str and returns a tree PHP objects as the parsed document. This function is isolated from the other functions, which means you cannot access the tree with any of the other functions. Modifying it, for example by adding nodes, makes no sense since there is currently no way to dump it as an XML file. However this function may be valuable if you want to read a file and investigate the content.
(PHP 4 >= 4.2.0)
domxml_xslt_stylesheet_doc -- Creates a DomXsltStylesheet Object from a DomDocument Object.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also domxsltstylesheet->process(), domxml_xslt_stylesheet(), and domxml_xslt_stylesheet_file().
(PHP 4 >= 4.2.0)
domxml_xslt_stylesheet_file -- Creates a DomXsltStylesheet Object from an XSL document in a file.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also domxsltstylesheet->process(), domxml_xslt_stylesheet(), and domxml_xslt_stylesheet_doc()
(PHP 4 >= 4.2.0)
domxml_xslt_stylesheet -- Creates a DomXsltStylesheet Object from an XML document in a string.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also domxsltstylesheet->process(), domxml_xslt_stylesheet_file(), and domxml_xslt_stylesheet_doc()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also xpath_eval().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The optional contextnode can be specified for doing relative XPath queries.
See also xpath_new_context().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also xpath_eval().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
These are functions dealing with error handling and logging. They allow you to define your own error handling rules, as well as modify the way the errors can be logged. This allows you to change and enhance error reporting to suit your needs.
With the logging functions, you can send messages directly to other machines, to an email (or email to pager gateway!), to system logs, etc., so you can selectively log and monitor the most important parts of your applications and websites.
The error reporting functions allow you to customize what level and kind of error feedback is given, ranging from simple notices to customized functions returned during errors.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Errors and Logging Configuration Options
Name | Default | Changeable |
---|---|---|
error_reporting | E_ALL & ~E_NOTICE | PHP_INI_ALL |
display_errors | "1" | PHP_INI_ALL |
display_startup_errors | "0" | PHP_INI_ALL |
log_errors | "0" | PHP_INI_ALL |
log_errors_max_len | "1024" | PHP_INI_ALL |
ignore_repeated_errors | "0" | PHP_INI_ALL |
ignore_repeated_source | "0" | PHP_INI_ALL |
report_memleaks | "1" | PHP_INI_ALL |
track_errors | "0" | PHP_INI_ALL |
html_errors | "1" | PHP_INI_ALL |
docref_root | "" | PHP_INI_ALL |
docref_ext | "" | PHP_INI_ALL |
error_prepend_string | NULL | PHP_INI_ALL |
error_append_string | NULL | PHP_INI_ALL |
error_log | NULL | PHP_INI_ALL |
warn_plus_overloading | NULL | PHP_INI?? |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Set the error reporting level. The parameter is either an integer representing a bit field, or named constants. The error_reporting levels and constants are described in Predefined Constants, and in php.ini. To set at runtime, use the error_reporting() function. See also the display_errors directive.
In PHP 4 and PHP 5 the default value is E_ALL & ~E_NOTICE. This setting does not show E_NOTICE level errors. You may want to show them during development.
Óçìåßùóç: Enabling E_NOTICE during development has some benefits. For debugging purposes: NOTICE messages will warn you about possible bugs in your code. For example, use of unassigned values is warned. It is extremely useful to find typos and to save time for debugging. NOTICE messages will warn you about bad style. For example, $arr[item] is better to be written as $arr['item'] since PHP tries to treat "item" as constant. If it is not a constant, PHP assumes it is a string index for the array.
Óçìåßùóç: In PHP 5 a new error level E_STRICT is available. As E_STRICT is not included within E_ALL you have to explicitly enable this kind of error level. Enabling E_STRICT during development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.
In PHP 3, the default setting is (E_ERROR | E_WARNING | E_PARSE), meaning the same thing. Note, however, that since constants are not supported in PHP 3's php3.ini, the error_reporting setting there must be numeric; hence, it is 7.
This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user.
Óçìåßùóç: This is a feature to support your development and should never be used on production systems (e.g. systems connected to the internet).
Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. It's strongly recommended to keep display_startup_errors off, except for debugging.
Tells whether script error messages should be logged to the server's error log or error_log. This option is thus server-specific.
Óçìåßùóç: You're strongly advised to use error logging in place of error displaying on production web sites.
Set the maximum length of log_errors in bytes. In error_log information about the source is added. The default is 1024 and 0 allows to not apply any maximum length at all.
Do not log repeated messages. Repeated errors must occur in the same file on the same line until ignore_repeated_source is set true.
Ignore source of message when ignoring repeated messages. When this setting is On you will not log errors with repeated messages from different files or sourcelines.
If this parameter is set to Off, then memory leaks will not be shown (on stdout or in the log). This has only effect in a debug compile, and if error_reporting includes E_WARNING in the allowed list
If enabled, the last error message will always be present in the variable $php_errormsg.
Turn off HTML tags in error messages. The new format for HTML errors produces clickable messages that direct the user to a page describing the error or function in causing the error. These references are affected by docref_root and docref_ext.
The new error format contains a reference to a page describing the error or function causing the error. In case of manual pages you can download the manual in your language and set this ini directive to the URL of your local copy. If your local copy of the manual can be reached by '/manual/' you can simply use docref_root=/manual/. Additional you have to set docref_ext to match the fileextensions of your copy docref_ext=.html. It is possible to use external references. For example you can use docref_root=http://manual/en/ or docref_root="http://landonize.it/?how=url&theme=classic&filter=Landon &url=http%3A%2F%2Fwww.php.net%2F"
Most of the time you want the docref_root value to end with a slash '/'. But see the second example above which does not have nor need it.
Óçìåßùóç: This is a feature to support your development since it makes it easy to lookup a function description. However it should never be used on production systems (e.g. systems connected to the internet).
See docref_root.
Óçìåßùóç: The value of docref_ext must begin with a dot '.'.
String to output before an error message.
String to output after an error message.
Name of the file where script errors should be logged. If the special value syslog is used, the errors are sent to the system logger instead. On Unix, this means syslog(3) and on Windows NT it means the event log. The system logger is not supported on Windows 95. See also: syslog().
If enabled, this option makes PHP output a warning when the plus (+) operator is used on strings. This is to make it easier to find scripts that need to be rewritten to using the string concatenator instead (.).
Ïé ðáñáêÜôù óôáèåñÝò åßíáé ðÜíôá äéáèÝóéìåò ùò ìÝñïò ôïõ ðõñÞíá ôçò PHP.
Óçìåßùóç: You may use these constant names in php.ini but not outside of PHP, like in httpd.conf, where you'd use the bitmask values instead.
Ðßíáêáò 2. Errors and Logging
Value | Constant | Description | Note |
---|---|---|---|
1 | E_ERROR (integer) | Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. | |
2 | E_WARNING (integer) | Run-time warnings (non-fatal errors). Execution of the script is not halted. | |
4 | E_PARSE (integer) | Compile-time parse errors. Parse errors should only be generated by the parser. | |
8 | E_NOTICE (integer) | Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. | |
16 | E_CORE_ERROR (integer) | Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP. | since PHP 4 |
32 | E_CORE_WARNING (integer) | Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP. | since PHP 4 |
64 | E_COMPILE_ERROR (integer) | Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine. | since PHP 4 |
128 | E_COMPILE_WARNING (integer) | Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine. | since PHP 4 |
256 | E_USER_ERROR (integer) | User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). | since PHP 4 |
512 | E_USER_WARNING (integer) | User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error(). | since PHP 4 |
1024 | E_USER_NOTICE (integer) | User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error(). | since PHP 4 |
2047 | E_ALL (integer) | All errors and warnings, as supported, except of level E_STRICT. | |
2048 | E_STRICT (integer) | Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. | since PHP 5 |
The above values (either numerical or symbolic) are used to build up a bitmask that specifies which errors to report. You can use the bitwise operators to combine these values or mask out certain types of errors. Note that only '|', '~', '!', '^' and '&' will be understood within php.ini, however, and that no bitwise operators will be understood within php3.ini.
Below we can see an example of using the error handling capabilities in PHP. We define an error handling function which logs the information into a file (using an XML format), and e-mails the developer in case a critical error in the logic happens.
ÐáñÜäåéãìá 1. Using error handling in a script
|
debug_backtrace() generates a PHP backtrace and returns this information as an associative array. The possible returned elements are listed in the following table:
Ðßíáêáò 1. Possible returned elements from debug_backtrace()
Name | Type | Description |
---|---|---|
function | string | The current function name. See also __FUNCTION__. |
line | integer | The current line number. See also __LINE__. |
file | string | The current file name. See also __FILE__. |
class | string | The current class name. See also __CLASS__ |
type | string | The current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned. |
args | array | If inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s). |
The following is a simple example.
ÐáñÜäåéãìá 1. debug_backtrace() example
Results when executing /tmp/b.php:
|
See also trigger_error() and debug_print_backtrace().
debug_print_backtrace() prints a PHP backtrace.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also debug_backtrace().
Sends an error message to the web server's error log, a TCP port or to a file. The first parameter, message, is the error message that should be logged. The second parameter, message_type says where the message should go:
Ðßíáêáò 1. error_log() log types
0 | message is sent to PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the error_log configuration directive is set to. This is the default option. |
1 | message is sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used. This message type uses the same internal function as mail() does. |
2 | message is sent through the PHP debugging connection. This option is only available if remote debugging has been enabled. In this case, the destination parameter specifies the host name or IP address and optionally, port number, of the socket receiving the debug information. |
3 | message is appended to the file destination. |
Óçìåßùóç: When explicitly specifying the message_type as 3, a newline is not automatically added to the end of the message string.
Ðñïåéäïðïßçóç |
Remote debugging via TCP/IP is a PHP 3 feature that is not available in PHP 4. |
ÐáñÜäåéãìá 1. error_log() examples
|
The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script.
error_reporting() sets PHP's error reporting level, and returns the old level. The level parameter takes on either a bitmask, or named constants. Using named constants is strongly encouraged to ensure compatibility for future versions. As error levels are added, the range of integers increases, so older integer-based error levels will not always behave as expected.
ÐáñÜäåéãìá 1. error_reporting() examples
|
The available error level constants are listed below. The actual meanings of these error levels are described in the predefined constants.
Ðßíáêáò 1. error_reporting() level constants and bit values
value | constant |
---|---|
1 | E_ERROR |
2 | E_WARNING |
4 | E_PARSE |
8 | E_NOTICE |
16 | E_CORE_ERROR |
32 | E_CORE_WARNING |
64 | E_COMPILE_ERROR |
128 | E_COMPILE_WARNING |
256 | E_USER_ERROR |
512 | E_USER_WARNING |
1024 | E_USER_NOTICE |
2047 | E_ALL |
2048 | E_STRICT |
Ðñïåéäïðïßçóç |
With PHP > 5.0.0 E_STRICT with value 2048 is available. E_ALL does NOT include error levelE_STRICT. |
See also the display_errors directive and ini_set().
Used after changing the error handler function using set_error_handler(), to revert to the previous error handler (which could be the built-in or a user defined function)
See also error_reporting(), set_error_handler(), trigger_error().
Sets a user function (error_handler) to handle errors in a script. Returns the previously defined error handler (if any), or FALSE on error. This function can be used for defining your own way of handling errors during runtime, for example in applications in which you need to do cleanup of data/files when a critical error happens, or when you need to trigger an error under certain conditions (using trigger_error()).
The second parameter error_types was introduced in PHP 5 and can be used to mask the triggering of the error_handler function just like the error_reporting ini setting controls which errors are shown. Without this mask set the error_handler will be called for every error regardless to the setting of the error_reporting setting.
The user function needs to accept two parameters: the error code, and a
string describing the error. From PHP 4.0.2, three optional
parameters are supplied: the filename in which the error occurred, the
line number in which the error occurred, and the context in which the
error occurred (an array that points to the active symbol table at the
point the error occurred). The function can be shown as:
handler ( int errno, string errstr [, string errfile [, int errline [, array errcontext]]])
The first parameter, errno, contains the level of the error raised, as an integer.
The second parameter, errstr, contains the error message, as a string.
The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string.
The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer.
The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in.
Óçìåßùóç: Instead of a function name, an array containing an object reference and a method name can also be supplied. (Since PHP 4.3.0)
Óçìåßùóç: The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and E_STRICT.
The example below shows the handling of internal exceptions by triggering errors and handling them with a user defined function:
ÐáñÜäåéãìá 1. Error handling with set_error_handler() and trigger_error()
And when you run this sample script, the output will be:
|
It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.
Also note that it is your responsibility to die() if necessary. If the error-handler function returns, script execution will continue with the next statement after the one that caused an error.
Óçìåßùóç: If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time.
Óçìåßùóç: The second parameter error_types was introduced in PHP 5.
See also error_reporting(), restore_error_handler(), trigger_error(), and error level constants.
Used to trigger a user error condition, it can be used by in conjunction with the built-in error handler, or with a user defined function that has been set as the new error handler (set_error_handler()). It only works with the E_USER family of constants, and will default to E_USER_NOTICE.
This function is useful when you need to generate a particular response to an exception at runtime. For example:
Óçìåßùóç: See set_error_handler() for a more extensive example.
Óçìåßùóç: error_msg is limited to 1024 characters in length. Any additional characters beyond 1024 will be truncated.
See also error_reporting(), set_error_handler(), restore_error_handler(), and error level constants.
FAM monitors files and directories, notifying interested applications of changes. More information about FAM is available at http://oss.sgi.com/projects/fam/.
A PHP script may specify a list of files for FAM to monitor using the functions provided by this extension.
The FAM process is started when the first connection from any application to it is opened. It exits after all connections to it have been closed.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
This extension uses the functions of the FAM library, devoloped by SGI. Therefore you have to download and install the FAM library.
To use PHP's FAM support you must compile PHP --with-fam[=DIR] where DIR is the location of the directory containing the lib and include directories.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðßíáêáò 1. FAM event constants
Constant | Description |
---|---|
FAMChanged (integer) | Some value which can be obtained with fstat(1) changed for a file or directory. |
FAMDeleted (integer) | A file or directory was deleted or renamed. |
FAMStartExecuting (integer) | An executable file started executing. |
FAMStopExecuting (integer) | An executable file that was running finished. |
FAMCreated (integer) | A file was created in a directory. |
FAMMoved (integer) | This event never occurs. |
FAMAcknowledge (integer) | An event in response to fam_cancel_monitor(). |
FAMExists (integer) | An event upon request to monitor a file or directory. When a directory is monitored, an event for that directory and every file contained in that directory is issued. |
FAMEndExist (integer) | Event after the last FAMEExists event. |
fam_cancel_monitor() terminates monitoring on a resource previously requested using one of the fam_monitor_...(). In addition an FAMAcknowledge event occurs.
See also fam_monitor_file(), fam_monitor_directory(), fam_monitor_collection(), and fam_suspend_monitor()
fam_close() closes a connection to the FAM service previously opened using fam_open().
fam_monitor_collection() requests monitoring for a collection of files within a directory. The actual files to be monitored are specified by a directory path in dirname, the maximum search depth starting from this directory and a shell pattern mask restricting the file names to look for.
A FAM event will be generated whenever the status of the files change. The possible event codes are described in detail in the constants part of this section.
See also fam_monitor_file(), fam_monitor_directory(), fam_cancel_monitor(), fam_suspend_monitor(), and fam_resume_monitor().
fam_monitor_directory() requests monitoring for a directory and all contained files. A FAM event will be generated whenever the status of the directory (i.e. the result of function stat() on that directory) or its content (i.e. the results of readdir()) change.
The possible event codes are described in detail in the constants part of this section.
See also fam_monitor_file(), fam_monitor_collection(), fam_cancel_monitor(), fam_suspend_monitor(), and fam_resume_monitor().
fam_monitor_file() requests monitoring for a single file. A FAM event will be generated whenever the file status (i.e. the result of function stat() on that file) changes.
The possible event codes are described in detail in the constants part of this section.
See also fam_monitor_directory(), fam_monitor_collection(), fam_cancel_monitor(), fam_suspend_monitor(), and fam_resume_monitor().
fam_next_event() returns the next pending FAM event. The function will block until an event is available which can be checked for using fam_pending().
fam_next_event() will return an array that contains a FAM event code in element 'code', the path of the file this event applies to in element 'filename' and optionally a hostname in element 'hostname'.
The possible event codes are described in detail in the constants part of this section.
See also fam_pending().
fam_open() opens a connection to the FAM service daemon. The optional parameter appname should be set to a string identifying the application for logging reasons.
See also fam_close().
fam_pending() returns TRUE if events are available to be fetched using fam_next_event().
See also fam_next_event().
fam_resume_monitor() resumes monitoring of a resource previously suspend using fam_suspend_monitor().
See also fam_suspend_monitor().
fam_suspend_monitor() temporarily suspend monitoring of a resource previously requested using one of the fam_monitor_...() functions. Monitoring can later be continued using fam_resume_monitor() without the need of requesting a complete new monitor.
See also fam_resume_monitor(), and fam_cancel_monitor().
These functions allow you to access FrontBase database servers. More information about FrontBase can be found at http://www.frontbase.com/.
Documentation for FrontBase can be found at http://www.frontbase.com/cgi-bin/WebObjects/FrontBase.woa/wa/productsPage?currentPage=Documentation.
Frontbase support has been added to PHP 4.0.6.
You must install the FrontBase database server or at least the fbsql client libraries to use this functions. You can get FrontBase from http://www.frontbase.com/.
In order to have these functions available, you must compile PHP with fbsql support by using the --with-fbsql[=DIR] option. If you use this option without specifying the path to fbsql, PHP will search for the fbsql client libraries in the default installation location for the platform. Users who installed FrontBase in a non standard directory should always specify the path to fbsql: --with-fbsql=/path/to/fbsql. This will force PHP to use the client libraries installed by FrontBase, avoiding any conflicts.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. FrontBase configuration options
Name | Default | Changeable |
---|---|---|
fbsql.allow_persistent | "1" | PHP_INI_SYSTEM |
fbsql.generate_warnings | "0" | PHP_INI_SYSTEM |
fbsql.autocommit | "1" | PHP_INI_SYSTEM |
fbsql.max_persistent | "-1" | PHP_INI_SYSTEM |
fbsql.max_links | "128" | PHP_INI_SYSTEM |
fbsql.max_connections | "128" | PHP_INI_SYSTEM |
fbsql.max_results | "128" | PHP_INI_SYSTEM |
fbsql.batchSize | "1000" | PHP_INI_SYSTEM |
fbsql.default_host | NULL | PHP_INI_SYSTEM |
fbsql.default_user | "_SYSTEM" | PHP_INI_SYSTEM |
fbsql.default_password | "" | PHP_INI_SYSTEM |
fbsql.default_database | "" | PHP_INI_SYSTEM |
fbsql.default_database_password | "" | PHP_INI_SYSTEM |
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
(PHP 4 >= 4.0.6, PHP 5)
fbsql_affected_rows -- Get number of affected rows in previous FrontBase operationfbsql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query associated with link_identifier. If the link identifier isn't specified, the last link opened by fbsql_connect() is assumed.
Óçìåßùóç: If you are using transactions, you need to call fbsql_affected_rows() after your INSERT, UPDATE, or DELETE query, not after the commit.
If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero.
Óçìåßùóç: When using UPDATE, FrontBase will not update columns where the new value is the same as the old value. This creates the possibility that fbsql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.
If the last query failed, this function will return -1.
See also: fbsql_num_rows().
fbsql_autocommit() returns the current autocommit status. If the optional OnOff parameter is given the auto commit status will be changed. With OnOff set to TRUE each statement will be committed automatically, if no errors was found. With OnOff set to FALSE the user must commit or rollback the transaction using either fbsql_commit() or fbsql_rollback().
See also: fbsql_commit() and fbsql_rollback()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
fbsql_change_user -- Change logged in user of the active connectionfbsql_change_user() changes the logged in user of the current active connection, or the connection given by the optional parameter link_identifier. If a database is specified, this will default or current database after the user has been changed. If the new user and password authorization fails, the current connected user stays active.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns: TRUE on success, FALSE on error.
fbsql_close() closes the connection to the FrontBase server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.
Using fbsql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.
See also: fbsql_connect() and fbsql_pconnect().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
fbsql_commit() ends the current transaction by writing all inserts, updates and deletes to the disk and unlocking all row and table locks held by the transaction. This command is only needed if autocommit is set to false.
See also: fbsql_autocommit() and fbsql_rollback()
Returns a positive FrontBase link identifier on success, or an error message on failure.
fbsql_connect() establishes a connection to a FrontBase server. The following defaults are assumed for missing optional parameters: hostname = 'NULL', username = '_SYSTEM' and password = empty password.
If a second call is made to fbsql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.
The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling fbsql_close().
See also fbsql_pconnect() and fbsql_close().
Returns: A resource handle to the newly created blob.
fbsql_create_blob() creates a blob from blob_data. The returned resource handle can be used with insert and update commands to store the blob in the database.
ÐáñÜäåéãìá 1. fbsql_create_blob() example
|
See also: fbsql_create_clob(), fbsql_read_blob(), fbsql_read_clob(), and fbsql_set_lob_mode().
Returns: A resource handle to the newly created CLOB.
fbsql_create_clob() creates a clob from clob_data. The returned resource handle can be used with insert and update commands to store the clob in the database.
ÐáñÜäåéãìá 1. fbsql_create_clob() example
|
See also: fbsql_create_blob(), fbsql_read_blob(), fbsql_read_clob(), and fbsql_set_lob_mode().
fbsql_create_db() attempts to create a new database named database_name on the server associated with the specified connection link_identifier.
See also: fbsql_drop_db().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
fbsql_data_seek() moves the internal row pointer of the FrontBase result associated with the specified result identifier to point to the specified row number. The next call to fbsql_fetch_row() would return that row.
Row_number starts at 0.
ÐáñÜäåéãìá 1. fbsql_data_seek() example
|
(PHP 4 >= 4.0.6, PHP 5)
fbsql_database_password -- Sets or retrieves the password for a FrontBase databaseReturns: The database password associated with the link identifier.
fbsql_database_password() sets and retrieves the database password used by the connection. if a database is protected by a database password, the user must call this function before calling fbsql_select_db(). if the second optional parameter is given the function sets the database password for the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if fbsql_connect() was called, and use it.
This function does not change the database password in the database nor can it be used to retrieve the database password for a database.
ÐáñÜäåéãìá 1. fbsql_create_clob() example
|
See also: fbsql_connect(), fbsql_pconnect() and fbsql_select_db().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns: A positive FrontBase result identifier to the query result, or FALSE on error.
fbsql_db_query() selects a database and executes a query on it. If the optional link identifier isn't specified, the function will try to find an open link to the FrontBase server and if no such link is found it'll try to create one as if fbsql_connect() was called with no arguments
See also fbsql_connect().
Returns: An integer value with the current status.
fbsql_db_status() requests the current status of the database specified by database_name. If the link_identifier is omitted the default link_identifier will be used.
The return value can be one of the following constants:
FALSE - The exec handler for the host was invalid. This error will occur when the link_identifier connects directly to a database by using a port number. FBExec can be available on the server but no connection has been made for it.
FBSQL_UNKNOWN - The Status is unknown.
FBSQL_STOPPED - The database is not running. Use fbsql_start_db() to start the database.
FBSQL_STARTING - The database is starting.
FBSQL_RUNNING - The database is running and can be used to perform SQL operations.
FBSQL_STOPPING - The database is stopping.
FBSQL_NOEXEC - FBExec is not running on the server and it is not possible to get the status of the database.
See also: fbsql_start_db() and fbsql_stop_db().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
fbsql_drop_db() attempts to drop (remove) an entire database from the server associated with the specified link identifier.
(PHP 4 >= 4.0.6, PHP 5)
fbsql_errno -- Returns the numerical value of the error message from previous FrontBase operationReturns the error number from the last fbsql function, or 0 (zero) if no error occurred.
Errors coming back from the fbsql database backend don't issue warnings. Instead, use fbsql_errno() to retrieve the error code. Note that this function only returns the error code from the most recently executed fbsql function (not including fbsql_error() and fbsql_errno()), so if you want to use it, make sure you check the value before calling another fbsql function.
<?php fbsql_connect("marliesle"); echo fbsql_errno() . ": " . fbsql_error() . "<br />"; fbsql_select_db("nonexistentdb"); echo fbsql_errno() . ": " . fbsql_error() . "<br />"; $conn = fbsql_query("SELECT * FROM nonexistenttable;"); echo fbsql_errno() . ": " . fbsql_error() . "<br />"; ?> |
See also: fbsql_error() and fbsql_warnings().
(PHP 4 >= 4.0.6, PHP 5)
fbsql_error -- Returns the text of the error message from previous FrontBase operationReturns the error text from the last fbsql function, or '' (the empty string) if no error occurred.
Errors coming back from the fbsql database backend don't issue warnings. Instead, use fbsql_error() to retrieve the error text. Note that this function only returns the error text from the most recently executed fbsql function (not including fbsql_error() and fbsql_errno()), so if you want to use it, make sure you check the value before calling another fbsql function.
<?php fbsql_connect("marliesle"); echo fbsql_errno() . ": " . fbsql_error() . "<br />"; fbsql_select_db("nonexistentdb"); echo fbsql_errno() . ": " . fbsql_error() . "<br />"; $conn = fbsql_query("SELECT * FROM nonexistenttable;"); echo fbsql_errno() . ": " . fbsql_error() . "<br />"; ?> |
See also: fbsql_errno() and fbsql_warnings().
(PHP 4 >= 4.0.6, PHP 5)
fbsql_fetch_array -- Fetch a result row as an associative array, a numeric array, or bothReturns an array that corresponds to the fetched row, or FALSE if there are no more rows.
fbsql_fetch_array() is an extended version of fbsql_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must the numeric index of the column or make an alias for the column.
An important thing to note is that using fbsql_fetch_array() is NOT significantly slower than using fbsql_fetch_row(), while it provides a significant added value.
The optional second argument result_type in fbsql_fetch_array() is a constant and can take the following values: FBSQL_ASSOC, FBSQL_NUM, and FBSQL_BOTH.
For further details, see also fbsql_fetch_row() and fbsql_fetch_assoc().
ÐáñÜäåéãìá 1. fbsql_fetch_array() example
|
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows.
fbsql_fetch_assoc() is equivalent to calling fbsql_fetch_array() with FBSQL_ASSOC for the optional second parameter. It only returns an associative array. This is the way fbsql_fetch_array() originally worked. If you need the numeric indices as well as the associative, use fbsql_fetch_array().
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must use fbsql_fetch_array() and have it return the numeric indices as well.
An important thing to note is that using fbsql_fetch_assoc() is NOT significantly slower than using fbsql_fetch_row(), while it provides a significant added value.
For further details, see also fbsql_fetch_row() and fbsql_fetch_array().
(PHP 4 >= 4.0.6, PHP 5)
fbsql_fetch_field -- Get column information from a result and return as an objectReturns an object containing field information.
fbsql_fetch_field() can be used in order to obtain information about fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by fbsql_fetch_field() is retrieved.
The properties of the object are:
name - column name
table - name of the table the column belongs to
max_length - maximum length of the column
not_null - 1 if the column cannot be NULL
type - the type of the column
ÐáñÜäåéãìá 1. fbsql_fetch_field() example
|
See also fbsql_field_seek().
Returns: An array that corresponds to the lengths of each field in the last row fetched by fbsql_fetch_row(), or FALSE on error.
fbsql_fetch_lengths() stores the lengths of each result column in the last row returned by fbsql_fetch_row(), fbsql_fetch_array() and fbsql_fetch_object() in an array, starting at offset 0.
See also: fbsql_fetch_row().
Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.
fbsql_fetch_object() is similar to fbsql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
The optional argument result_type is a constant and can take the following values: FBSQL_ASSOC, FBSQL_NUM, and FBSQL_BOTH.
Speed-wise, the function is identical to fbsql_fetch_array(), and almost as quick as fbsql_fetch_row() (the difference is insignificant).
See also: fbsql_fetch_array() and fbsql_fetch_row().
Returns: An array that corresponds to the fetched row, or FALSE if there are no more rows.
fbsql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
Subsequent call to fbsql_fetch_row() would return the next row in the result set, or FALSE if there are no more rows.
See also: fbsql_fetch_array(), fbsql_fetch_object(), fbsql_data_seek(), fbsql_fetch_lengths(), and fbsql_result().
(PHP 4 >= 4.0.6, PHP 5)
fbsql_field_flags -- Get the flags associated with the specified field in a resultfbsql_field_flags() returns the field flags of the specified field. The flags are reported as a single word per flag separated by a single space, so that you can split the returned value using explode().
fbsql_field_len() returns the length of the specified field.
fbsql_field_name() returns the name of the specified field index. result must be a valid result identifier and field_index is the numerical offset of the field.
Óçìåßùóç: field_index starts at 0.
e.g. The index of the third field would actually be 2, the index of the fourth field would be 3 and so on.
ÐáñÜäåéãìá 1. fbsql_field_name() example
The above example would produce the following output:
|
Seeks to the specified field offset. If the next call to fbsql_fetch_field() doesn't include a field offset, the field offset specified in fbsql_field_seek() will be returned.
See also: fbsql_fetch_field().
Returns the name of the table that the specified field is in.
fbsql_field_type() is similar to the fbsql_field_name() function. The arguments are identical, but the field type is returned instead. The field type will be one of "int", "real", "string", "blob", and others as detailed in the FrontBase documentation.
ÐáñÜäåéãìá 1. fbsql_field_type() example
|
fbsql_free_result() will free all memory associated with the result identifier result.
fbsql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
fbsql_insert_id() returns the ID generated for an column defined as DEFAULT UNIQUE by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.
fbsql_insert_id() returns 0 if the previous query does not generate an DEFAULT UNIQUE value. If you need to save the value for later, be sure to call fbsql_insert_id() immediately after the query that generates the value.
Óçìåßùóç: The value of the FrontBase SQL function fbsql_insert_id() always contains the most recently generated DEFAULT UNIQUE value, and is not reset between queries.
fbsql_list_dbs() will return a result pointer containing the databases available from the current fbsql daemon. Use the fbsql_tablename() function to traverse this result pointer.
Óçìåßùóç: The above code would just as easily work with fbsql_fetch_row() or other similar functions.
fbsql_list_fields() retrieves information about the given tablename. Arguments are the database name and the table name. A result pointer is returned which can be used with fbsql_field_flags(), fbsql_field_len(), fbsql_field_name(), and fbsql_field_type().
A result identifier is a positive integer. The function returns FALSE if an error occurs. A string describing the error will be placed in $phperrmsg, and unless the function was called as @fbsql() then this error string will also be printed out.
ÐáñÜäåéãìá 1. fbsql_list_fields() example
The above example would produce the following output:
|
fbsql_list_tables() takes a database name and returns a result pointer much like the fbsql_db_query() function. The fbsql_tablename() function should be used to extract the actual table names from the result pointer.
When sending more than one SQL statement to the server or executing a stored procedure with multiple results will cause the server to return multiple result sets. This function will test for additional results available form the server. If an additional result set exists it will free the existing result set and prepare to fetch the words from the new result set. The function will return TRUE if an additional result set was available or FALSE otherwise.
ÐáñÜäåéãìá 1. fbsql_next_result() example
|
fbsql_num_fields() returns the number of fields in a result set.
See also: fbsql_db_query(), fbsql_query(), fbsql_fetch_field(), and fbsql_num_rows().
fbsql_num_rows() returns the number of rows in a result set. This command is only valid for SELECT statements. To retrieve the number of rows returned from a INSERT, UPDATE or DELETE query, use fbsql_affected_rows().
See also: fbsql_affected_rows(), fbsql_connect(), fbsql_select_db(), and fbsql_query().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns: A positive FrontBase persistent link identifier on success, or FALSE on error.
fbsql_pconnect() establishes a connection to a FrontBase server. The following defaults are assumed for missing optional parameters: host = 'localhost', username = "_SYSTEM" and password = empty password.
To set Frontbase server port number, use fbsql_select_db().
fbsql_pconnect() acts very much like fbsql_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use.
This type of links is therefore called 'persistent'.
fbsql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if fbsql_connect() was called with no arguments, and use it.
Óçìåßùóç: The query string shall always end with a semicolon.
fbsql_query() returns TRUE (non-zero) or FALSE to indicate whether or not the query succeeded. A return value of TRUE means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly possible for a query to succeed but affect no rows or return no rows.
The following query is syntactically invalid, so fbsql_query() fails and returns FALSE:
The following query is semantically invalid if my_col is not a column in the table my_tbl, so fbsql_query() fails and returns FALSE:
fbsql_query() will also fail and return FALSE if you don't have permission to access the table(s) referenced by the query.
Assuming the query succeeds, you can call fbsql_num_rows() to find out how many rows were returned for a SELECT statement or fbsql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.
For SELECT statements, fbsql_query() returns a new result identifier that you can pass to fbsql_result(). When you are done with the result set, you can free the resources associated with it by calling fbsql_free_result(). Although, the memory will automatically be freed at the end of the script's execution.
See also: fbsql_affected_rows(), fbsql_db_query(), fbsql_free_result(), fbsql_result(), fbsql_select_db(), and fbsql_connect().
Returns: A string containing the BLOB specified by blob_handle.
fbsql_read_blob() reads BLOB data from the database. If a select statement contains BLOB and/or CLOB columns FrontBase will return the data directly when data is fetched. This default behavior can be changed with fbsql_set_lob_mode() so the fetch functions will return handles to BLOB and CLOB data. If a handle is fetched a user must call fbsql_read_blob() to get the actual BLOB data from the database.
ÐáñÜäåéãìá 1. fbsql_read_blob() example
|
See also: fbsql_create_blob(), fbsql_read_blob(), fbsql_read_clob(), and fbsql_set_lob_mode().
Returns: A string containing the CLOB specified by clob_handle.
fbsql_read_clob() reads CLOB data from the database. If a select statement contains BLOB and/or CLOB columns FrontBase will return the data directly when data is fetched. This default behavior can be changed with fbsql_set_lob_mode() so the fetch functions will return handles to BLOB and CLOB data. If a handle is fetched a user must call fbsql_read_clob() to get the actual CLOB data from the database.
ÐáñÜäåéãìá 1. fbsql_read_clob() example
|
See also: fbsql_create_blob(), fbsql_read_blob(), fbsql_read_clob(), and fbsql_set_lob_mode().
fbsql_result() returns the contents of one cell from a FrontBase result set. The field argument can be the field's offset, or the field's name, or the field's table dot field's name (tabledname.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name.
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than fbsql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
Calls to fbsql_result() should not be mixed with calls to other functions that deal with the result set.
Recommended high-performance alternatives: fbsql_fetch_row(), fbsql_fetch_array(), and fbsql_fetch_object().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
fbsql_rollback() ends the current transaction by rolling back all statements issued since last commit. This command is only needed if autocommit is set to false.
See also: fbsql_autocommit() and fbsql_commit()
fbsql_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if fbsql_connect() was called, and use it.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The client contacts FBExec to obtain the port number to use for the connection to the database. If the database name is a number the system will use that as a port number and it will not ask FBExec for the port number. The FrontBase server can be stared as FRontBase -FBExec=No -port=<port number> <database name>.
Every subsequent call to fbsql_query() will be made on the active database.
if the database is protected with a database password, the user must call fbsql_database_password() before selecting the database.
See also fbsql_connect(), fbsql_pconnect(), fbsql_database_password(), and fbsql_query().
Returns: TRUE on success, FALSE on error.
fbsql_set_lob_mode() sets the mode for retrieving LOB data from the database. When BLOB and CLOB data is stored in FrontBase it can be stored direct or indirect. Direct stored LOB data will always be fetched no matter the setting of the lob mode. If the LOB data is less than 512 bytes it will always be stored directly.
FBSQL_LOB_DIRECT - LOB data is retrieved directly. When data is fetched from the database with fbsql_fetch_row(), and other fetch functions, all CLOB and BLOB columns will be returned as ordinary columns. This is the default value on a new FrontBase result.
FBSQL_LOB_HANDLE - LOB data is retrieved as handles to the data. When data is fetched from the database with fbsql_fetch_row (), and other fetch functions, LOB data will be returned as a handle to the data if the data is stored indirect or the data if it is stored direct. If a handle is returned it will be a 27 byte string formatted as "@'000000000000000000000000'".
See also: fbsql_create_blob(), fbsql_create_clob(), fbsql_read_blob(), and fbsql_read_clob().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
fbsql_start_db()
See also: fbsql_db_status() and fbsql_stop_db().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
fbsql_stop_db()
See also: fbsql_db_status() and fbsql_start_db().
fbsql_tablename() takes a result pointer returned by the fbsql_list_tables() function as well as an integer index and returns the name of a table. The fbsql_num_rows() function may be used to determine the number of tables in the result pointer.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
These functions allow read-only access to data stored in filePro databases.
filePro is a registered trademark of fP Technologies, Inc. You can find more information about filePro at http://www.fptech.com/.
Returns the number of fields (columns) in the opened filePro database.
See also filepro().
Returns the name of the field corresponding to field_number.
Returns the edit type of the field corresponding to field_number.
Returns the width of the field corresponding to field_number.
Returns the data from the specified location in the database. The row_number parameter must be between zero and the total number of rows minus one (0..filepro_rowcount() - 1). Likewise, field_number accepts values between zero and the total number of fields minus one (0..filepro_fieldcount() - 1)
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
Returns the number of rows in the opened filePro database.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
See also filepro().
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.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
No external libraries are needed to build this extension, but if you want PHP to support LFS (large files) on Linux, then you need to have a recent glibc and you need compile PHP with the following compiler flags: -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Filesystem and Streams Configuration Options
Name | Default | Changeable |
---|---|---|
allow_url_fopen | "1" | PHP_INI_SYSTEM |
user_agent | NULL | PHP_INI_ALL |
default_socket_timeout | "60" | PHP_INI_ALL |
from | NULL | ?? |
auto_detect_line_endings | "Off" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
This option enables the URL-aware fopen wrappers that enable accessing URL object like files. Default wrappers are provided for the access of remote files using the ftp or http protocol, some extensions like zlib may register additional wrappers.
Óçìåßùóç: This setting can only be set in php.ini due to security reasons.
Óçìåßùóç: This option was introduced immediately after the release of version 4.0.3. For versions up to and including 4.0.3 you can only disable this feature at compile time by using the configuration switch --disable-url-fopen-wrapper.
Ðñïåéäïðïßçóç |
On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the ÁíáöïñÜ XLII, Image óõíáñôÞóåéò extension. |
Define the user agent for PHP to send.
Default timeout (in seconds) for socket based streams.
Óçìåßùóç: This configuration option was introduced in PHP 4.3.0
Define the anonymous ftp password (your email address).
When turned on, PHP will examine the data read by fgets() and file() to see if it is using Unix, MS-Dos or Macintosh line-ending conventions.
This enables PHP to interoperate with Macintosh systems, but defaults to Off, as there is a very small performance penalty when detecting the EOL conventions for the first line, and also because people using carriage-returns as item separators under Unix systems would experience non-backwards-compatible behaviour.
Óçìåßùóç: This configuration option was introduced in PHP 4.3.0
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
For related functions, see also the Directory and Program Execution sections.
For a list and explanation of the various URL wrappers that can be used as remote files, see also ÐáñÜñôçìá J.
Given a string containing a path to a file, this function will return the base name of the file. If the filename ends in suffix this will also be cut off.
On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
Óçìåßùóç: The suffix parameter was added in PHP 4.1.0.
See also: dirname()
Attempts to change the group of the file filename to group (specified by name or number). 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.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
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, so strings (such as "g+w") will not work properly. To ensure the expected operation, you need to prefix mode with a zero (0):
<?php chmod("/somedir/somefile", 755); // decimal; probably incorrect chmod("/somedir/somefile", "u+rwx,go+rx"); // string; incorrect chmod("/somedir/somefile", 0755); // octal; correct value of mode ?> |
The mode parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'.
<?php // Read and write for owner, nothing for everybody else chmod("/somedir/somefile", 0600); // Read and write for owner, read for everybody else chmod("/somedir/somefile", 0644); // Everything for owner, read and execute for others chmod("/somedir/somefile", 0755); // Everything for owner, read and execute for owner's group chmod("/somedir/somefile", 0750); ?> |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
Óçìåßùóç: When safe mode is enabled, PHP checks whether the files or directories you are about to operate on have the same UID (owner) as the script that is being executed. In addition, you cannot set the SUID, SGID and sticky bits
Attempts to change the owner of the file filename to user user (specified by name or number). Only the superuser may change the owner of a file.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
See also chmod().
When you use stat(), lstat(), or any of the other functions listed in the affected functions list (below), PHP caches the information those functions return in order to provide faster performance. However, in certain cases, you may want to clear the cached information. For instance, if the same file is being checked multiple times within a single script, and that file is in danger of being removed or changed during that script's operation, you may elect to clear the status cache. In these cases, you can use the clearstatcache() function to clear the information that PHP caches about a file.
You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists() on a file that doesn't exist, it will return FALSE until you create the file. If you create the file, it will return TRUE even if you then delete the file.
Óçìåßùóç: This function caches information about specific filenames, so you only need to call clearstatcache() if you are performing multiple operations on the same filename and require the information about that particular file to not be cached.
Affected functions include stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype(), and fileperms().
Makes a copy of the file source to dest. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: As of PHP 4.3.0, both source and dest may be URLs if the "fopen wrappers" have been enabled. See fopen() for more details. If dest is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files.
Ðñïåéäïðïßçóç |
If the destination file already exists, it will be overwritten. |
See also move_uploaded_file(), rename(), and the section of the manual about handling file uploads.
This is a dummy manual entry to satisfy those people who are looking for unlink() or unset() in the wrong place.
See also: unlink() to delete files, unset() to delete variables.
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 directory separator character. In other environments, it is the forward slash (/).
Óçìåßùóç: In PHP 4.0.3, dirname() was fixed to be POSIX-compliant. Essentially, this means that if there are no slashes in path , a dot ('.') is returned, indicating the current directory. Otherwise, the returned string is path with any trailing /component removed. Note that this means that you will often get a slash or a dot back from dirname() in situations where the older functionality would have given you the empty string.
dirname() has changed its behaviour in PHP 4.3.0. Check the following examples:
<?php //before PHP 4.3.0 dirname('c:/'); // returned '.' //after PHP 4.3.0 dirname('c:/'); // returns 'c:' ?> |
See also basename(), pathinfo(), and realpath().
Given a string containing a directory, this function will return the number of bytes available on the corresponding filesystem or disk partition.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
See also disk_total_space()
Given a string containing a directory, this function will return the total number of bytes on the corresponding filesystem or disk partition.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
See also disk_free_space()
The file pointed to by handle is closed.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen().
Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE.
Ðñïåéäïðïßçóç |
feof() will return TRUE only if the connection opened by fsockopen() is closed. This can cause a script to timeout. The workaround for this is to use stream_set_timeout(), so that feof() will return FALSE on timeout. |
The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen().
This function forces a write of all buffered output to the resource pointed to by the file handle handle. Returns TRUE if successful, FALSE otherwise.
The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen().
Returns a string containing a single character read from the file pointed to by handle. Returns FALSE on EOF.
The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé binary-safe.
See also fread(), fopen(), popen(), fsockopen(), and fgets().
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 optional third delimiter parameter defaults as a comma, and the optional enclosure defaults as a double quotation mark. Both delimiter and enclosure are limited to one character. If either is more than one character, only the first character is used.
Óçìåßùóç: The enclosure parameter was added in PHP 4.3.0.
The handle parameter must be a valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen().
The length parameter 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.
Óçìåßùóç: A blank line in a CSV file will be returned as an array comprising a single null field, and will not be treated as an error.
ÐáñÜäåéãìá 1. Read and print the entire contents of a CSV file
|
Returns a string of up to length - 1 bytes read from the file pointed to by handle. 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 no length is specified, the length defaults to 1k, or 1024 bytes.
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:
Óçìåßùóç: The length parameter became optional in PHP 4.2.0, if omitted, it would assume 1024 as the line length. As of PHP 4.3, omitting length will keep reading from the stream until it reaches the end of the line. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length.
Óçìåßùóç: This function is binary safe as of PHP 4.3. Earlier versions were not binary safe.
Óçìåßùóç: Áí Ý÷åôå ðñïâëÞìáôá ìå ôçí PHP íá ìçí áíáãíùñßæåé ôá ôÝëç ãñáììþí üôáí äéáâÜæåé áñ÷åßá óå, Þ äçìéïõñãçìÝíá áðü, Ýíá Macintosh çëåêôñïíéêü õðïëïãéóôÞ, ìðïñåß íá èÝëåôå íá åíåñãïðïéÞóåôå ôçí run-time åðéëïãÞ ñýèìéóçò auto_detect_line_endings.
See also fread(), fgetc(), stream_get_line(), fopen(), popen(), fsockopen(), and stream_set_timeout().
Identical to fgets(), except that fgetss attempts to strip any HTML and PHP tags from the text it reads.
You can use the optional third parameter to specify tags which should not be stripped.
Óçìåßùóç: allowable_tags was added in PHP 3.0.13, PHP 4.0.0.
Óçìåßùóç: Áí Ý÷åôå ðñïâëÞìáôá ìå ôçí PHP íá ìçí áíáãíùñßæåé ôá ôÝëç ãñáììþí üôáí äéáâÜæåé áñ÷åßá óå, Þ äçìéïõñãçìÝíá áðü, Ýíá Macintosh çëåêôñïíéêü õðïëïãéóôÞ, ìðïñåß íá èÝëåôå íá åíåñãïðïéÞóåôå ôçí run-time åðéëïãÞ ñýèìéóçò auto_detect_line_endings.
See also fgets(), fopen(), fsockopen(), popen(), and strip_tags().
Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also is_readable(), is_writable(), is_file() and file().
Identical to file(), except that file_get_contents() returns the file in a string. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé binary-safe.
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Óçìåßùóç: Context support was added with PHP 5.0.0.
Ðñïåéäïðïßçóç |
Some non-standard compliant webservers, such as IIS, send data in a way that causes PHP to raise warnings. When working with such servers you should lower your error_reporting level not to include warnings. |
See also: fgets(), file(), fread(), include(), and readfile().
Identical to calling fopen(), fwrite(), and fclose() successively. The function returns the amount of bytes that were written to the file.
flags can take FILE_USE_INCLUDE_PATH and/or FILE_APPEND, however the FILE_USE_INCLUDE_PATH option should be used with caution.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé binary-safe.
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
See also: fopen(), fwrite(), fclose(), and file_get_contents().
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. Upon failure, file() returns FALSE.
You can use the optional use_include_path parameter and set it to "1", if you want to search for the file in the include_path, too.
<?php // Get a file into an array. In this example we'll go through HTTP to get // the HTML source of a URL. $lines = file('http://www.example.com/'); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; } // Another example, let's get a web page into a string. See also file_get_contents(). $html = implode('', file('http://www.example.com/')); ?> |
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Óçìåßùóç: Each line in the resulting array will include the line ending, so you still need to use rtrim() if you do not want the line ending present.
Óçìåßùóç: Áí Ý÷åôå ðñïâëÞìáôá ìå ôçí PHP íá ìçí áíáãíùñßæåé ôá ôÝëç ãñáììþí üôáí äéáâÜæåé áñ÷åßá óå, Þ äçìéïõñãçìÝíá áðü, Ýíá Macintosh çëåêôñïíéêü õðïëïãéóôÞ, ìðïñåß íá èÝëåôå íá åíåñãïðïéÞóåôå ôçí run-time åðéëïãÞ ñýèìéóçò auto_detect_line_endings.
Óçìåßùóç: As of PHP 4.3.0 you can use file_get_contents() to return the contents of a file as a string.
In PHP 4.3.0 file() became binary safe.
Óçìåßùóç: Context support was added with PHP 5.0.0.
Ðñïåéäïðïßçóç |
Some non-standard compliant webservers, such as IIS, send data in a way that causes PHP to raise warnings. When working with such servers you should lower your error_reporting level not to include warnings. |
See also readfile(), fopen(), fsockopen(), popen(), file_get_contents(), and include().
Returns the time the file was last accessed, or FALSE in case of an error. The time is returned as a Unix timestamp.
Note: The atime of a file is supposed to change whenever the data blocks of a file are being read. This can be costly performancewise when an application regularly accesses a very large number of files or directories. Some Unix filesystems can be mounted with atime updates disabled to increase the performance of such applications; USENET news spools are a common example. On such filesystems this function will be useless.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also filemtime(), fileinode(), and date().
Returns the time the file was last changed, or FALSE in case of an error. The time is returned as a Unix timestamp.
Note: In most Unix filesystems, a file is considered changed when its inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is updated. See also filemtime() (which is what you want to use when you want to create "Last Modified" footers on web pages) and fileatime().
Note also that in some Unix texts the ctime of a file is referred to as being the creation time of the file. This is wrong. There is no creation time for Unix files in most Unix filesystems.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
ÐáñÜäåéãìá 1. fileatime() example
|
See also filemtime()
Returns the group ID of the file, or FALSE in case of an error. The group ID is returned in numerical format, use posix_getgrgid() to resolve it to a group name. Upon failure, FALSE is returned along with an error of level E_WARNING.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also fileowner(), and safe_mode_gid.
Returns the inode number of the file, or FALSE in case of an error.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also stat()
Returns the time the file was last modified, or FALSE in case of an error. The time is returned as a Unix timestamp, which is suitable for the date() function.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.
See also filectime(), stat(), touch(), and getlastmod().
Returns the user ID of the owner of the file, or FALSE in case of an error. The user ID is returned in numerical format, use posix_getpwuid() to resolve it to a username.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also stat()
Returns the permissions on the file, or FALSE in case of an error.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also is_readable(), and stat()
Returns the size of the file in bytes, or FALSE in case of an error.
Óçìåßùóç: Because PHP's integer type is signed and many platforms use 32bit integers, filesize() may return unexpected results for files which are larger than 2GB. For files between 2GB and 4GB in size this can usually be overcome by using sprintf("%u", filesize($file)).
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also file_exists()
Returns the type of the file. Possible values are fifo, char, dir, block, link, file, and unknown.
Returns FALSE if an error occurs. filetype() will also produce an E_NOTICE message if the stat call fails or if the file type is unknown.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also is_dir(), is_file(), is_link(), file_exists(), stat(), and mime_content_type().
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() is mandatory under Windows.
flock() operates on handle which must be an open file pointer. operation is one of the following values:
To acquire a shared lock (reader), set operation to LOCK_SH (set to 1 prior to PHP 4.0.1).
To acquire an exclusive lock (writer), set operation to LOCK_EX (set to 2 prior to PHP 4.0.1).
To release a lock (shared or exclusive), set operation to LOCK_UN (set to 3 prior to PHP 4.0.1).
If you don't want flock() to block while locking, add LOCK_NB (4 prior to PHP 4.0.1) to operation.
flock() allows you to perform a simple reader/writer model which can be used on virtually every platform (including most Unix derivatives and even Windows). The optional third argument is set to TRUE if the lock would block (EWOULDBLOCK errno condition)
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: Because flock() requires a file pointer, you may have to use a special lock file to protect access to a file that you intend to truncate by opening it in write mode (with a "w" or "w+" argument to fopen()).
Ðñïåéäïðïßçóç |
flock() will not work on NFS and many other networked file systems. Check your operating system documentation for more details. On some operating systems flock() is implemented at the process level. When using a multithreaded server API like ISAPI you may not be able to rely on flock() to protect files against other PHP scripts running in parallel threads of the same server instance! flock() is not supported on antiquated filesystems like FAT and its derivates and will therefore always return FALSE under this environments (this is especially true for Windows 98 users). |
fnmatch() checks if the passed string would match the given shell wildcard pattern.
This is especially useful for filenames, but may also be used on regular strings. The average user may be used to shell patterns or at least in their simplest form to '?' and '*' wildcards so using fnmatch() instead of ereg() or preg_match() for frontend search expression input may be way more convenient for non-programming users.
Ðñïåéäïðïßçóç |
For now this function is not available on Windows or other non-POSIX compliant systems. |
See also glob(), ereg(), preg_match() and the Unix manpage on fnmatch(3) for flag names (as long as they are not documented here ).
fopen() binds a named resource, specified by filename, to a stream. If filename is of the form "scheme://...", it is assumed to be a URL and PHP will search for a protocol handler (also known as a wrapper) for that scheme. If no wrappers for that protocol are registered, PHP will emit a notice to help you track potential problems in your script and then continue as though filename specifies a regular file.
If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply.
If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.
Óçìåßùóç: The list of supported protocols can be found in ÐáñÜñôçìá J. Some protocols (also referred to as wrappers) support context and/or php.ini options. Refer to the specific page for the protocol in use for a list of options which can be set. ( i.e. php.ini value user_agent used by the http wrapper) For a description of contexts and the zcontext parameter , refer to ÁíáöïñÜ CVI, Stream Functions.
Óçìåßùóç: Context support was added with PHP 5.0.0.
The mode parameter specifies the type of access you require to the stream. It may be any of the following:
Ðßíáêáò 1. A list of possible modes for fopen() using mode
mode | Description |
---|---|
'r' | Open for reading only; place the file pointer at the beginning of the file. |
'r+' | Open for reading and writing; place the file pointer at the beginning of the file. |
'w' | Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. |
'w+' | Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. |
'a' | Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. |
'a+' | Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. |
'x' | Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files. |
'x+' | Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files. |
Óçìåßùóç: Different operating system families have different line-ending conventions. When you write a text file and want to insert a line break, you need to use the correct line-ending character(s) for your operating system. Unix based systems use \n as the line ending character, Windows based systems use \r\n as the line ending characters and Macintosh based systems use \r as the line ending character.
If you use the wrong line ending characters when writing your files, you might find that other applications that open those files will "look funny".
Windows offers a text-mode translation flag ('t') which will transparently translate \n to \r\n when working with the file. In contrast, you can also use 'b' to force binary mode, which will not translate your data. To use these flags, specify either 'b' or 't' as the last character of the mode parameter.
The default translation mode depends on the SAPI and version of PHP that you are using, so you are encouraged to always specify the appropriate flag for portability reasons. You should use the 't' mode if you are working with plain-text files and you use \n to delimit your line endings in your script, but expect your files to be readable with applications such as notepad. You should use the 'b' in all other cases.
If you do not specify the 'b' flag when working with binary files, you may experience strange problems with your data, including broken image files and strange problems with \r\n characters.
For portability, it is strongly recommended that you always use the 'b' flag when opening files with fopen().
Again, for portability, it is also strongly recommended that you re-write code that uses or relies upon the 't' mode so that it uses the correct line endings and 'b' mode instead.
As of PHP 4.3.2, the default mode is set to binary for all platforms that distinguish between binary and text mode. If you are having problems with your scripts after upgrading, try using the 't' flag as a workaround until you have made your script more portable as mentioned above.
The optional third use_include_path parameter can be set to '1' or TRUE if you want to search for the file in the include_path, too.
If the open fails, the function returns FALSE and an error of level E_WARNING is generated. You may use @ to suppress this warning.
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.
Ðñïåéäïðïßçóç |
Some non-standard compliant webservers, such as IIS, send data in a way that causes PHP to raise warnings. When working with such servers you should lower your error_reporting level not to include warnings. |
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
See also ÐáñÜñôçìá J, fclose(), fgets(), fread(), fwrite(), fsockopen(), file(), file_exists(), is_readable(), stream_set_timeout(), and popen().
Reads to EOF on the given file pointer from the current position and writes the results to the output buffer.
If an error occurs, fpassthru() returns FALSE. Otherwise, fpassthru() returns the number of characters read from handle and passed through to the output.
The file pointer must be valid, and must point to a file successfully opened by fopen(), popen(), or fsockopen(). You may need to call rewind() to reset the file pointer to the beginning of the file if you have already written data to the file. The file is closed when fpassthru() is done reading it (leaving handle useless).
If you just want to dump the contents of a file to the output buffer, without first modifying it or seeking to a particular offset, you may want to use the readfile(), which saves you the fopen() call.
Óçìåßùóç: When using fpassthru() on a binary file on Windows systems, you should make sure to open the file in binary mode by appending a b to the mode used in the call to fopen().
You are encouraged to use the b flag when dealing with binary files, even if your system does not require it, so that your scripts will be more portable.
ÐáñÜäåéãìá 1. Using fpassthru() with binary files
|
See also readfile(), fopen(), popen(), and fsockopen()
fread() reads up to length bytes from the file pointer referenced by handle. Reading stops when length bytes have been read, EOF (end of file) is reached, or (for network streams) when a packet becomes available, whichever comes first.
<?php // get contents of a file into a string $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); ?> |
Ðñïåéäïðïßçóç |
On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter. |
<?php $filename = "c:\\files\\somepic.gif"; $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); ?> |
Ðñïåéäïðïßçóç |
When reading from network streams or pipes, such as those returned when reading remote files or from popen() and fsockopen(), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the example below. |
<?php $handle = fopen("http://www.example.com/", "rb"); $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); ?> |
Óçìåßùóç: If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above.
See also fwrite(), fopen(), fsockopen(), popen(), fgets(), fgetss(), fscanf(), file(), and fpassthru().
The function fscanf() is similar to sscanf(), but it takes its input from a file associated with handle and interprets the input according to the specified format, which is described in the documentation for sprintf(). If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference.
Any whitespace in the format string matches any whitespace in the input stream. This means that even a tab \t in the format string can match a single space character in the input stream.
Óçìåßùóç: Prior to PHP 4.3.0, the maximum number of characters read from the file was 512 (or up to the first \n, whichever came first). As of PHP 4.3.0 arbitrarily long lines will be read and scanned.
See also fread(), fgets(), fgetss(), sscanf(), printf(), and sprintf().
Sets the file position indicator for the file referenced by handle.The new position, measured in bytes from the beginning of the file, is obtained by adding offset to the position specified by whence, whose values are defined as follows:
SEEK_SET - Set position equal to offset bytes. |
SEEK_CUR - Set position to current location plus offset. |
SEEK_END - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.) |
If whence is not specified, it is assumed to be 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.
Óçìåßùóç: The whence argument was added after PHP 4.0.0.
Gathers the statistics of the file opened by the file pointer handle. This function is similar to the stat() function except that it operates on an open file pointer instead of a filename.
Returns an array with the statistics of the file; the format of the array is described in detail on the stat() manual page.
ÐáñÜäåéãìá 1. fstat() example
this will output :
|
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
Returns the position of the file pointer referenced by handle; 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().
Takes the filepointer, handle, and truncates the file to length, size. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
fwrite() writes the contents of string to the file stream pointed to by handle. 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.
fwrite() returns the number of bytes written, or FALSE on error.
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.
Óçìåßùóç: On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter.
ÐáñÜäåéãìá 1. A simple fwrite example
|
See also fread(), fopen(), fsockopen(), and popen().
The glob() function searches for all the pathnames matching pattern according to the rules used by the shell. No tilde expansion or parameter substitution is done.
Returns an array containing the matched files/directories or FALSE on error.
Valid flags:
GLOB_MARK - Adds a slash to each item returned
GLOB_NOSORT - Return files as they appear in the directory (no sorting)
GLOB_NOCHECK - Return the search pattern if no files matching it were found
GLOB_NOESCAPE - Backslashes do not quote metacharacters
GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'
GLOB_ONLYDIR - Return only directory entries which match the pattern
Óçìåßùóç: Before PHP 4.3.3 GLOB_ONLYDIR was not available on Windows and other systems not using the GNU C library.
ÐáñÜäåéãìá 1. Convenient way how glob() can replace opendir() and friends.
Output will look something like:
|
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
See also opendir(), readdir(), closedir(), and fnmatch().
Returns TRUE if the filename exists and is a directory. If filename is a relative filename, it will be checked relative to the current working directory.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
Returns TRUE if the filename exists and is executable.
is_executable() became available with Windows in PHP version 5.0.0.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
Returns TRUE if the filename exists and is a regular file.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
Returns TRUE if the filename exists and is a symbolic link.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also is_dir(), is_file(), and readlink().
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.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also is_writable(), file_exists(), and fgets().
(PHP 3>= 3.0.17, PHP 4 >= 4.0.3, PHP 5)
is_uploaded_file -- Tells whether the file was uploaded via HTTP POSTReturns TRUE if the file named by filename was uploaded via HTTP POST. This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working--for instance, /etc/passwd.
This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.
is_uploaded_file() is available only in versions of PHP 3 after PHP 3.0.16, and in versions of PHP 4 after 4.0.2. If you are stuck using an earlier version, you can use the following function to help protect yourself:
Óçìåßùóç: The following example will not work in versions of PHP 4 after 4.0.2. It depends on internal functionality of PHP which changed after that version.
<?php /* Userland test for uploaded file. */ function is_uploaded_file($filename) { if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { $tmp_file = dirname(tempnam('', '')); } $tmp_file .= '/' . basename($filename); /* User might have trailing slash in php.ini... */ return (ereg_replace('/+', '/', $tmp_file) == $filename); } /* This is how to use it, since you also don't have * move_uploaded_file() in these older versions: */ if (is_uploaded_file($HTTP_POST_FILES['userfile'])) { copy($HTTP_POST_FILES['userfile'], "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack: filename '$HTTP_POST_FILES[userfile]'."; } ?> |
See also move_uploaded_file(), and the section Handling file uploads for a simple usage example.
Returns TRUE if the filename exists and is writable. 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.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also is_readable(), file_exists(), and fwrite().
link() creates a hard link. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí èá äïõëÝøåé óå áðïìáêñõóìÝíá áñ÷åßá áöïý ôï õðü åîÝôáóç áñ÷åßï ðñÝðåé íá åßíáé ðñïóâÜóéìï ìÝóù ôïõ filesystem ôïõ server.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
See also the symlink() to create soft links, and readlink() along with linkinfo().
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.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
See also symlink(), link(), and readlink().
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.
See the manual page for stat() for information on the structure of the array that lstat() returns.
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also stat().
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. The mode is also modified by the current umask, which you can change using umask().
Óçìåßùóç: Mode is ignored on Windows, and became optional in PHP 4.2.0.
The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: As of PHP 5.0.0 mkdir() can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support mkdir().
Óçìåßùóç: The recursive and context parameters were added as of PHP 5.0.0.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
See also rmdir().
This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.
If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.
This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
Óçìåßùóç: move_uploaded_file() is not affected by the normal safe mode UID-restrictions. This is not unsafe because move_uploaded_file() only operates on files uploaded via PHP.
Ðñïåéäïðïßçóç |
If the destination file already exists, it will be overwritten. |
See also is_uploaded_file(), and the section Handling file uploads for a simple usage example.
parse_ini_file() loads in the ini file specified in filename, and returns the settings in it in an associative array. By setting the last process_sections parameter to TRUE, you get a multidimensional array, with the section names and settings included. The default for process_sections is FALSE
Óçìåßùóç: This function has nothing to do with the php.ini file. It is already processed, the time you run your script. This function can be used to read in your own application's configuration files.
Óçìåßùóç: If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes (").
Óçìåßùóç: Since PHP 4.2.1 this function is also affected by safe mode and open_basedir.
Óçìåßùóç: There are reserved words which must not be used as keys for ini files. These include: null, yes, no, true, and false.
The structure of the ini file is similar to that of the php.ini's.
Constants may also be parsed in the ini file so if you define a constant as an ini value before running parse_ini_file(), it will be integrated into the results. Only ini values are evaluated. For example:
ÐáñÜäåéãìá 2. parse_ini_file() example
Would produce:
|
pathinfo() returns an associative array containing information about path. The following array elements are returned: dirname, basename and extension.
Óçìåßùóç: For information on retrieving the current path info, read the section on predefined reserved variables.
See also dirname(), basename(), parse_url() and realpath().
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().
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 fwrite().
If an error occurs, returns FALSE.
Óçìåßùóç: If you're looking for bi-directional support (two-way), use proc_open().
If the command to be executed could not be found, a valid resource is returned. This may seem odd, but makes sense; it allows you to access any error message returned by the shell:
<?php error_reporting(E_ALL); /* Add redirection so we can get stderr. */ $handle = popen('/path/to/spooge 2>&1', 'r'); echo "'$handle'; " . gettype($handle) . "\n"; $read = fread($handle, 2096); echo $read; pclose($handle); ?> |
Óçìåßùóç: When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir. For practical reasons it is currently not allowed to have .. components in the path to the executable.
Ðñïåéäïðïßçóç |
With safe mode enabled, all words following the initial command string are treated as a single argument. Thus, echo y | echo x becomes echo "y | echo x". |
See also pclose(), fopen(), and proc_open().
Reads a file and writes it to the output buffer.
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.
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
You can use the optional second parameter and set it to TRUE, if you want to search for the file in the include_path, too.
See also fpassthru(), file(), fopen(), include(), require(), virtual(), file_get_contents(), and ÐáñÜñôçìá J.
readlink() does the same as the readlink C function and returns the contents of the symbolic link path or FALSE in case of error.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
See also is_link(), symlink(), and linkinfo().
realpath() expands all symbolic links and resolves references to '/./', '/../' and extra '/' characters in the input path and return the canonicalized absolute pathname. The resulting path will have no symbolic link, '/./' or '/../' components.
realpath() returns FALSE on failure, e.g. if the file does not exists.
See also: basename(), dirname(), and pathinfo().
Attempts to rename oldname to newname.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: Prior to PHP 4.3.3, rename() could not rename files across partitions on *nix based systems.
Óçìåßùóç: As of PHP 5.0.0 rename() can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support rename().
Óçìåßùóç: The wrapper used in oldname MUST match the wrapper used in newname.
Óçìåßùóç: The context parameter was added as of PHP 5.0.0.
See also copy(), unlink(), and move_uploaded_file().
Sets the file position indicator for handle to the beginning of the file stream.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The file pointer must be valid, and must point to a file successfully opened by fopen().
Óçìåßùóç: If you have opened the file in append ("a") mode, any data you write to the file will always be appended, regardless of the file position.
Attempts to remove the directory named by dirname. The directory must be empty, and the relevant permissions must permit this. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: As of PHP 5.0.0 rmdir() can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support rmdir().
Óçìåßùóç: The context parameter was added as of PHP 5.0.0.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
Gathers the statistics of the file named by filename. If filename is a symbolic link, statistics are from the file itself, not the symlink. lstat() is identical to stat() except it would instead be based off the symlinks status.
In case of error, stat() returns FALSE. It also will throw a warning.
Returns an array with the statistics of the file with the following elements. This array is zero-based. In addition to returning these attributes in a numeric array, they can be accessed with associative indices, as noted next to each parameter; this is available since PHP 4.0.6:
Ðßíáêáò 1. stat() and fstat() result format
Numeric | Associative (since PHP 4.0.6) | Description |
---|---|---|
0 | dev | device number |
1 | ino | inode number |
2 | mode | inode protection mode |
3 | nlink | number of links |
4 | uid | userid of owner |
5 | gid | groupid of owner |
6 | rdev | device type, if inode device * |
7 | size | size in bytes |
8 | atime | time of last access (Unix timestamp) |
9 | mtime | time of last modification (Unix timestamp) |
10 | ctime | time of last change (Unix timestamp) |
11 | blksize | blocksize of filesystem IO * |
12 | blocks | number of blocks allocated |
Óçìåßùóç: Ôá áðïôåëÝóìáôá áõôÞò ôçò óõíÜñôçóçò Ý÷ïõí ãßíåé cache. Äåßôå ôçí clearstatcache() ãéá ðåñéóóüôåñåò ðëçñïöïñßåò.
Õðüäåéîç: As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support stat() family of functionality.
See also lstat(), fstat(), filemtime(), and filegroup().
symlink() creates a symbolic link from the existing target with the specified name link.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
See also link() to create hard links, and readlink() along with linkinfo().
Creates a file with a unique filename in the specified directory. If the directory does not exist, tempnam() may generate a file in the system's temporary directory, and return the name of that.
Prior to PHP 4.0.6, the behaviour of the tempnam() function was 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.
Óçìåßùóç: If PHP cannot create a file in the specified dir parameter, it falls back on the system default.
Returns the new temporary filename, or the FALSE string on failure.
Óçìåßùóç: This function's behavior changed in 4.0.3. The temporary file is also created to avoid a race condition where the file might appear in the filesystem between the time the string was generated and before the the script gets around to creating the file. Note, that you need to remove the file in case you need it no more, it is not done automatically.
Creates a temporary file with an unique name in write mode, returning a file handle similar to the one returned by fopen(). The file is automatically removed when closed (using fclose()), or when the script ends.
For details, consult your system documentation on the tmpfile(3) function, as well as the stdio.h header file.
See also tempnam().
Attempts to set the access and 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. This is equivalent to what utime (sometimes referred to as utimes) does. If the third option atime is present, the access time of the given filename is set to the value of atime. Note that the access time is always modified, regardless of the number of parameters.
If the file does not exist, it is created. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
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.
Deletes filename. Similar to the Unix C unlink() function. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: As of PHP 5.0.0 unlink() can also be used with some URL wrappers. Refer to ÐáñÜñôçìá J for a listing of which wrappers support unlink().
Óçìåßùóç: The context parameter was added as of PHP 5.0.0.
See also rmdir() for removing directories.
Forms Data Format (FDF) is a format for handling forms within PDF documents. You should read the documentation at http://partners.adobe.com/asn/acrobat/forms.jsp for more information on what FDF is and how it is used in general.
The general idea of FDF is similar to HTML forms. The difference is basically the format how data is transmitted to the server when the submit button is pressed (this is actually the Form Data Format) and the format of the form itself (which is the Portable Document Format, PDF). Processing the FDF data is one of the features provided by the fdf functions. But there is more. One may as well take an existing PDF form and populated the input fields with data without modifying the form itself. In such a case one would create a FDF document (fdf_create()) set the values of each input field (fdf_set_value()) and associate it with a PDF form (fdf_set_file()). Finally it has to be sent to the browser with MimeType application/vnd.fdf. The Acrobat reader plugin of your browser recognizes the MimeType, reads the associated PDF form and fills in the data from the FDF document.
If you look at an FDF-document with a text editor you will find a catalogue object with the name FDF. Such an object may contain a number of entries like Fields, F, Status etc.. The most commonly used entries are Fields which points to a list of input fields, and F which contains the filename of the PDF-document this data belongs to. Those entries are referred to in the FDF documentation as /F-Key or /Status-Key. Modifying this entries is done by functions like fdf_set_file() and fdf_set_status(). Fields are modified with fdf_set_value(), fdf_set_opt() etc..
You need the FDF toolkit SDK available from http://partners.adobe.com/asn/acrobat/forms.jsp. As of PHP 4.3 you need at least SDK version 5.0. The FDF toolkit library is available in binary form only, platforms supported by Adobe are Win32, Linux, Solaris and AIX.
You must compile PHP with --with-fdftk[=DIR].
Óçìåßùóç: If you run into problems configuring PHP with fdftk support, check whether the header file fdftk.h and the library libfdftk.so are at the right place. The configure script supports both the directory structure of the FDF SDK distribution and the usual DIR/include / DIR/lib layout, so you can point it either directly to the unpacked distribution directory or put the header file and the appropriate library for your platform into e.g. /usr/local/include and /usr/local/lib and configure with --with-fdftk=/usr/local.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy fdftk.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32)
Most fdf functions require a fdf resource as their first parameter. A fdf resource is a handle to an opened fdf file. fdf resources may be obtained using fdf_create(), fdf_open() and fdf_open_string().
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
The following examples shows just the evaluation of form data.
ÐáñÜäåéãìá 1. Evaluating a FDF document
|
Adds a script to the FDF, which Acrobat then adds to the doc-level scripts of a document, once the FDF is imported into it. It is strongly suggested to use '\r' for linebreaks within script_code.
ÐáñÜäåéãìá 1. Adding JavaScript code to a FDF
will create a FDF like this:
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The fdf_close() function closes the FDF document.
See also fdf_open().
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.
ÐáñÜäåéãìá 1. Populating a PDF document
|
See also fdf_close(), fdf_save(), fdf_open().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
fdf_errno() returns the error code set by the last fdf_...() function call. This is zero for a successfull operation or a non-zero error code on failure. A textual description may be obtained using the fdf_error() function.
See also fdf_error().
fdf_error() returns a textual description for the fdf error code given in error_code. The function uses the internal error code set by the last operation if no error_code is given, so fdf_error() is a convenient shortcut for fdf_error(fdf_errno()).
See also fdf_errno().
The fdf_get_ap() function gets the appearance of a field (i.e. the value of the /AP key) and stores it in a file. The possible values of face are FDFNormalAP, FDFRolloverAP and FDFDownAP. The appearance is stored in filename.
Extracts a file uploaded by means of the "file selection" field fieldname and stores it under savepath. savepath may be the name of a plain file or an existing directory in which the file is to be created under its original name. Any existing file under the same name will be overwritten.
Óçìåßùóç: There seems to be no other way to find out the original filename but to store the file using a directory as savepath and check for the basename it was stored under.
The returned array contains the following fields:
path - path were the file got stored
size - size of the stored file in bytes
type - mimetype if given in the FDF
The fdf_get_encoding() returns the value of the /Encoding key. An empty string is returned if the default PDFDocEncoding/Unicode scheme is used.
See also fdf_set_encoding().
The fdf_set_file() returns the value of the /F key.
See also fdf_set_file().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The fdf_get_status() returns the value of the /STATUS key.
See also fdf_set_status().
The fdf_get_value() function returns the value for the requested fieldname.
Elements of an array field can be retrieved by passing the optional which, starting at zero. For non-array fields the optional parameter which will be ignored.
Óçìåßùóç: Array support and optional which parameter were added in PHP 4.3.
See also fdf_set_value().
This function will return the fdf version for the given fdf_document, or the toolkit API version number if no parameter is given.
For the current FDF toolkit 5.0 the API version number is '5.0' and the document version number is either '1.2', '1.3' or '1.4'.
See also fdf_set_version().
This is a convenience function to set appropriate HTTP headers for FDF output. It sets the Content-type: to application/vnd.fdf.
The fdf_next_field_name() function returns the name of the field after the field in fieldname or the field name of the first field if the second parameter is NULL.
See also fdf_enum_fields() and fdf_get_value().
The fdf_open_string() function reads form data from a string. fdf_data must contain the data as returned from a PDF form or created using fdf_create() and fdf_save_string().
You can fdf_open_string() together with $HTTP_FDF_DATA to process fdf form input from a remote client.
See also fdf_open(), fdf_close(), fdf_create() and fdf_save_string().
The fdf_open() function opens a file with form data. This file must contain the data as returned from a PDF form or created using fdf_create() and fdf_save().
You can process the results of a PDF form POST request by writing the data received in $HTTP_FDF_DATA to a file and open it using fdf_open(). Starting with PHP 4.3 you can also use fdf_open_string() which handles temporary file creation and cleanup for you.
See also fdf_open_string(), fdf_close(), fdf_create() and fdf_save().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The fdf_save_string() function returns the FDF document as a string.
ÐáñÜäåéãìá 1. Retrieving FDF as a string
will output something like
|
See also fdf_save(), fdf_open_string(), fdf_create() and fdf_close().
The fdf_save() function saves a FDF document. The resulting FDF will be written to filename. Without a filename fdf_save() will write the FDF to the default PHP output stream.
See also fdf_save_string(), fdf_create() and fdf_close().
The fdf_set_ap() function sets the appearance of a field (i.e. the value of the /AP key). The possible values of face are FDFNormalAP, FDFRolloverAP and FDFDownAP.
fdf_set_encoding() sets the character encoding in FDF document fdf_document. encoding should be the valid encoding name. Currently the following values are supported: "Shift-JIS", "UHC", "GBK","BigFive". An empty string resets the encoding to the default PDFDocEncoding/Unicode scheme.
The fdf_set_file() selects a different PDF document to display the form results in then the form it originated from. The url needs to be given as an absolute URL.
The frame to display the document in may be selected using the optional parameter target_frame or the function fdf_set_target_frame().
ÐáñÜäåéãìá 1. Passing FDF data to a second form
|
See also fdf_get_file() and fdf_set_target_frame().
The fdf_set_flags() sets certain flags of the given field fieldname.
See also fdf_set_opt().
fdf_set_javascript_action() sets a javascript action for the given field fieldname.
See also fdf_set_submit_form_action().
The fdf_set_opt() sets options of the given field fieldname.
See also fdf_set_flags().
The fdf_set_status() sets the value of the /STATUS key. When a client receives a FDF with a status set it will present the value in an alert box.
See also fdf_get_status().
The fdf_set_submit_form_action() sets a submit form action for the given field fieldname.
See also fdf_set_javascript_action().
Sets the target frame to display a result PDF defined with fdf_save_file() in.
See also fdf_save_file().
The fdf_set_value() function sets the value for a field named fieldname. The value will be stored as a string unless it is an array. In this case all array elements will be stored as a value array.
Óçìåßùóç: In older versions of the fdf toolkit last parameter determined if the field value was to be converted to a PDF Name (isName = 1) or set to a PDF String (isName = 0). The value is no longer used in the current toolkit version 5.0. For compatibility reasons it is still supported as an optional parameter beginning with PHP 4.3, but ignored internally.
Support for value arrays was added in PHP 4.3.
See also fdf_get_value() and fdf_remove_item().
This function will set the fdf version for the given fdf_document. Some features supported by this extension are only available in newer fdf versions. For the current FDF toolkit 5.0 version may be either '1.2', '1.3' or '1.4'.
See also fdf_get_version().
FriBiDi is a free implementation of the Unicode Bidirectional Algorithm.
To enable FriBiDi support in PHP you must compile --with-fribidi[=DIR] where DIR is the FriBiDi install directory.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ç óõíáñôÞóåéò áõôÞò ôçò extension åöáñìüæïõí ðñüóâáóç client óôïõò file servers ÷ñçóéìïðïéþíôáò ôï File Transfer Protocol (FTP) üðùò ïñßæåôáé óôçí éóôïóåëßäá http://www.faqs.org/rfcs/rfc959.html.
Ãéá íá ÷ñçóéìïðïéÞóåôå ôéò óõíáñôÞóåéò FTP ìå ôçí configuration ôçò PHP, èá ðñÝðåé íá ðñïóôåèåß ç åðéëïãÞ --enable-ftp êáôÜ ôçí åãêáôÜóôáóç ôçò PHP 4 Þ ç --with-ftp áí ÷ñçóéìïðïéåßôå ôçí PHP 3.
ÁõôÞ ç extension ÷ñçóéìïðïéåß Ýíáí ìüíï ôýðï ðüñùí, ï ïðïßïò åßíáé ï link identifier ôçò FTP óýíäåóçò.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ïé áêüëïõèåò constants åéóÞ÷èçóáí óôçí PHP 4.3.0.
ÁíáôñÝîôå åðßóçò óôçí ftp_set_option() ãéá ðëçñïöïñßåò.
Áõôüìáôïò õðïëïãéóìüò ôçò èÝóçò åêêßíçóçò êáé óõíÝ÷éóçò ãéá ôéò áéôÞóåéò GET êáé PUT (ëåéôïõñãåß ìüíï åÜí ç FTP_AUTOSEEK åßíáé enabled)
Ç áóýã÷ñïíç ìåôáöïñÜ Ý÷åé áðïôý÷åé
Ç áóýã÷ñïíç ìåôáöïñÜ Ý÷åé ôåëåéþóåé
Ç áóýã÷ñïíç ìåôáöïñÜ åßíáé áêüìá åíåñãÞ
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá FTP
|
Sends an ALLO command to the remote FTP server to allocate filesize bytes of space. Returns TRUE on success, or FALSE on failure.
Óçìåßùóç: Many FTP servers do not support this command. These servers may return a failure code (FALSE) indicating the command is not supported or a success code (TRUE) to indicate that pre-allocation is not necessary and the client should continue as though the operation were successful. Because of this, it may be best to reserve this function for servers which explicitly require preallocation.
A textual representation of the servers response will be returned by reference in result is a variable is provided.
ÐáñÜäåéãìá 1. ftp_alloc() example
|
See also: ftp_put(), and ftp_fput().
ÁëëÜæåé ðñïò ôï parent directory.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
ÌåôÜâáóç ðñïò ôï äïóìÝíï directory.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
Sets the permissions on the remote file specified by filename to mode given as an octal value.
ÐáñÜäåéãìá 1. ftp_chmod() example
|
Returns the new file permissions on success or FALSE on error.
See also chmod().
Ç ftp_close() ôåñìáôßæåé ôçí ftp_stream êáé áðåëåõèåñþíåé ôç resource. ÌåôÜ ôçí êëÞóç ôçò óõíÜñôçóçò, äåí ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôç óýíäåóç êáé ðñÝðåé íá äçìéïõñãÞóåôå íÝá ìå ôçí ftp_connect().
ÁíáôñÝîôå åðßóçò óôçí ftp_connect()
ÅðéóôñÝöåé Ýíá FTP stream óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
Ç ftp_connect() äçìéïõñãåß ìßá óýíäåóç óôï äïóìÝíï host. Ç ðáñÜìåôñïò port êáèïñßæåé ìßá åíáëëÜêôéêç port ãéá íá óõíäåèåßôå. ÅÜí ðáñáëåßðåôáé Þ ôåèåß óôï ìçäÝí, ôüôå èá ÷ñçóéìïðïéçèåß ç default FTP port, äçëáäÞ ç 21.
Ç ðáñÜìåôñïò timeout ðñïóäéïñßæåé ôï timeout ãéá üëåò ôéò áêüëïõèåò åíÝñãåéåò óôï network. ÅÜí ðáñáëåßðåôáé, ç ðñïêáèïñéóìÝíç ôéìÞ åßíáé ôá 90 äåõôåñüëåðôá. Ôï timeout ìðïñåß íá áëëá÷èåß êáé íá æçôçèåß ïðïéáäÞðïôå óôéãìÞ ìå ôéò ftp_set_option() êáé ftp_get_option().
Óçìåßùóç: Ç ðáñÜìåôñïò timeout åßíáé äéáèÝóéìç áðü ôçí Ýêäïóç 4.2.0 ôçò PHP.
Ç ftp_delete() äéáãñÜöåé ôï ðñïóäéïñéæüìåíï áðü ôï path, áñ÷åßï áðü ôïí FTP server.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
ÓôÝëíåé ìßá áßôçóç SITE EXEC command óôïí FTP server. ÅðéóôñÝöåé ôï áðïôÝëåóìá ôçò åíôïëÞò åÜí åßíáé åðéôõ÷Þò ç åíÝñãåéá, áëëéþò FALSE.
(PHP 3>= 3.0.13, PHP 4 , PHP 5)
ftp_fget -- ÊÜíåé download Ýíá áñ÷åßï áðü ôïí FTP server êáé ôï óþæåé óå Ýíá open fileÇ ftp_fget() áíáêôÜ ôï remote_file áðü ôïí FTP server, êáé ôï áíôéãñÜöåé óôï äïóìÝíï file pointer, fp. Ç ðñïóäéïñéóìÝíç transfer mode ðñÝðåé íá åßíáé åßôå FTP_ASCII åßôå FTP_BINARY.
Óçìåßùóç: Ç ðáñÜìåôñïò resumepos ðñïóôÝèçêå óôçí Ýêäïóç 4.3.0 ôçò PHP.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
ÁíáôñÝîôå åðßóçò óôçí ftp_get().
Ç ftp_fput() êÜíåé upload ôá äåäïìÝíá áðü ôï file pointer fp ìÝ÷ñé íá öôÜóåé óôï ôÝëïò ôïõ áñ÷åßïõ. Ôá áðïôåëÝóìáôá öõëÜóóïíôáé óôï remote_file óôïí FTP server. Ç ðñïóäéïñéóìÝíç transfer mode ðñÝðåé íá åßíáé åßôå FTP_ASCII åßôå FTP_BINARY.
Óçìåßùóç: Ç ðáñÜìåôñïò startpos ðñïóôÝèçêå óôçí Ýêäïóç 4.3.0 ôçò PHP.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
(PHP 4 >= 4.2.0, PHP 5)
ftp_get_option -- ÁíáêôÜ ðïéêßëåò runtime behaviours ôïõ ôñÝ÷ïíôïò FTP streamÓçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé äéáèÝóéìç ìüíï óôï CVS.
Óå ðåñßðôùóç åðéôõ÷ßáò åðéóôñÝöåé ìßá ôéìÞ, áëëéþò FALSE åÜí ç ðáñÜìåôñïò option äåí õðïóôçñßæåôáé. Óôçí ôåëåõôáßá ðåñßðôùóç, åìöáíßæåôáé êáé Ýíá ìÞíõìá warning.
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé ôçí ôéìÞ ãéá ôç æçôïýìåíç option áðü ôï êáèïñéóìÝíï ftp_stream . ÁõôÞ ôç óôéãìÞ, õðïóôçñßæïíôáé ïé áêüëïõèåò åðéëïãÝò:
Ðßíáêáò 1. Õðïóôçñéæüìåíåò runtime FTP åðéëïãÝò
FTP_TIMEOUT_SEC | ÅðéóôñÝöåé ôï ôñÝ÷ïí timeout ðïõ ÷ñçóéìïðïéåßôáé ãéá äéêôõáêÝò ëåéôïõñãßåò. |
Ç ftp_get() áíáêôÜ ôï remote_file áðü ôïí FTP server, êáé ôï óþæåé ôïðéêÜ óôï local_file. Ç ðñïóäéïñéóìÝíç transfer mode ðñÝðåé íá åßíáé åßôå FTP_ASCII åßôå FTP_BINARY.
Óçìåßùóç: Ç ðáñÜìåôñïò resumepos ðñïóôÝèçêå óôçí Ýêäïóç 4.3.0 ôçò PHP.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
ÁíáôñÝîôå åðßóçò óôéò: ftp_fget() êáé ftp_async_get().
ÓõíäÝåôáé óôï äïèÝí FTP stream.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáéFALSE óôçí áðïôõ÷ßá.
(PHP 3>= 3.0.13, PHP 4 , PHP 5)
ftp_mdtm -- ÅðéóôñÝöåé ôçí þñá ôåëåõôáßáò ôñïðïðïßçóçò ôïõ Ýíïò áñ÷åßïõÇ ftp_mdtm() åëÝã÷åé ôçí þñá ôåëåõôáßáò ôñïðïðïßçóçò åíüò áñ÷åßïõ, êáé ôçí åðéóôñÝöåé ìå ôç ìïñöÞ åíüò UNIX timestamp. ÅÜí ðñïêýøåé ëÜèïò, Þ äåí õðÜñ÷åé ôï áñ÷åßï, åðéóôñÝöåôáé ç ôéìÞ -1.
ÅðéóôñÝöåé Ýíá UNIX timestamp óôçí åðéôõ÷ßá, áëëéþò -1.
Óçìåßùóç: Äåí õðïóôçñßæïõí üëïé ïé servers áõôü ôï ÷áñáêôçñéóôéêü!
Óçìåßùóç: Ç ftp_mdtm() äå ëåéôïõñãåß ãéá directories.
Äçìéïõñãåß ôï êáèïñéóìÝíï directory.
ÅðéóôñÝöåé ôï üíïìá ôïõ êáéíïýñéïõ directory óå ðåñßðôùóç åðéôõ÷ßáò, áëëéþò FALSE óôï ëÜèïò.
(PHP 4 >= 4.3.0, PHP 5)
ftp_nb_continue -- Óõíå÷ßæåé ôçí áíÜêôçóç/áðïóôïëÞ åíüò áñ÷åßïõ (non-blocking)Óõíå÷ßæåé ôçí áíÜêôçóç/áðïóôïëÞ åíüò áñ÷åßïõ nbronously
ÅðéóôñÝöåé FTP_FAILED Þ FTP_FINISHED Þ FTP_MOREDATA.
(PHP 4 >= 4.3.0, PHP 5)
ftp_nb_fget -- ÁíáêôÜ Ýíá áñ÷åßï áðü ôïí FTP server êáé ôï óþæåé óå Ýíá open file (non-blocking)Ç ftp_nb_fget() áíáêôÜ ôï remote_file áðü ôïí FTP server, êáé ôï óþæåé óôï äïèÝíôá file pointer, fp. Ç ðñïóäéñïóìÝíç transfer mode ðñÝðåé íá åßíáé åßôå FTP_ASCII åßôå FTP_BINARY. Ç äéáöïñÜ áõôÞò ôçò óõíÜñôçóçò ìå ôçí ftp_fget() åßíáé üôé áíáêôÜ ôï áñ÷åßï áóýã÷ñïíá, Ýôóé ôï ðñüãñáììá óáò ìðïñåß íá åêôåëåß êáé Üëëåò ëåéôïõñãßåò êáôÜ ôç äéÜñêåéá ôïõ downloading.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôçí áðïôõ÷ßá.
ÁíáôñÝîôå åðßóçò óôçí ftp_nb_get().
(PHP 4 >= 4.3.0, PHP 5)
ftp_nb_fput -- Áðïèçêåýåé Ýíá áñ÷åßï áðü Ýíá open file óôïí FTP server (non-blocking)Ç ftp_nb_fput() êÜíåé upload ôá äåäïìÝíá áðü ôïí file pointer fp ìÝ÷ñé ôï ôÝëïò ôïõ áñ÷åßïõ. Ôá áðïôåëÝóìáôá öõëÜóóïíôáé óôï remote_file ôïõ FTP server. Ç ðñïóäéïñéóìÝíç transfer mode ðñÝðåé íá åßíáé Ýéôå FTP_ASCII åßôå FTP_BINARY. Ç äéáöïñÜ áõôÞò ôçò óõíÜñôçóçò ìå ôçí ftp_fput() åßíáé üôé áõôÞ õðïóôçñßæåé áóýã÷ñïíï upload, Ýôóé ôï ðñüãñáììÜ óáò ìðïñåß íá åêôåëåß êáé Üëëåò ëåéôïõñãßåò ðáñÜëëçëá ìå ôï downloading.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôçí áðïôõ÷ßá.
ÁíáôñÝîôå åðßóçò óôéò: ftp_nb_put(), ftp_nb_continue(), ftp_put() êáé ftp_fput().
(PHP 4 >= 4.3.0, PHP 5)
ftp_nb_get -- ÁíáêôÜ Ýíá áñ÷åßï áðü ôïí FTP server êáé ôï óþæåé óå Ýíá local file (non-blocking)Ç ftp_nb_get() áíáêôÜ ôï remote_file áðü ôïí FTP server, êáé ôï áðïèçêåýåé óôï local_file locally. Ç ðñïóäéïñéóìÝíç transfer mode ðñÝðåé íá åßíáé åßôå FTP_ASCII åßôå FTP_BINARY. Ç äéáöïñÜ áõôÞò ôçò óõíÜñôçóçò ìå ôçí ftp_get() åßíáé üôé áíáêôÜ ôï áñ÷åßï áóýã÷ñïíá, Ýôóé ôï ðñüãñáììÜ óáò ìðïñåß íá åêôåëåß êáé Üëëåò ëåéôïõñãßåò ðáñÜëëçëá ìå ôï downloading ôïõ áñ÷åßïõ.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôçí áðïôõ÷ßá.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ôçò ftp_nb_get()
|
ÐáñÜäåéãìá 2. RÓõíå÷ßæïíôáò ôï downloading ìå ôçí ftp_nb_get()
|
ÐáñÜäåéãìá 3. Óõíå÷ßæïíôáò ôï downloading óôç èÝóç 100 óå Ýíá íÝï áñ÷åßï ìå ôçí ftp_nb_get()
|
Óôï ðáñáðÜíù ðáñÜäåéãìá, ôï "newfile" åßíáé100 bytes ìéêñüôåñï áðü ôï "README" ôïõ FTP server åðåéäÞ îåêéíÞóáìå ôï äéÜâáóìá ìå offset 100. ÅÜí äåí Ý÷ïõìå ôçí FTP_AUTOSEEK disabled, ôá ðñþôá 100 bytes ôïõ íÝïõ áñ÷åßïõ èá åßíáé'\0'.
ÁíáôñÝîôå åðßóçò óôéò: ftp_nb_fget(), ftp_nb_continue(), ftp_get() êáé ftp_fget().
Ç ftp_nb_put() áðïèçêåýåé ôï local_file óôïí FTP server, ùò remote_file. Ç ðñïóäéïñéóìÝíç transfer mode ðñÝðåé íá åßíáé åßôå FTP_ASCII åßôå FTP_BINARY. Ç äéáöïñÜ áõôÞò ôçò óõíÜñôçóçò ìå ôçí ftp_put() åßíáé üôé áõôÞ êÜíåé áóýã÷ñïíá uploads áñ÷åßùí, Ýôóé ôï ðñüãñáììÜ óáò ìðïñåß íá åêôåëåß êáé Üëëåò ëåéôïõñãßåò åíþ ãßíåôáé ôï downloading ôïõ áñ÷åßïõ.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôçí áðïôõ÷ßá.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ôçò ftp_nb_put()
|
ÐáñÜäåéãìá 2. Óõíå÷ßæïíôáò ôï upload ìå ôçí ftp_nb_put()
|
ÁíáôñÝîôå åðßóçò óôéò: ftp_nb_fput(), ftp_nb_continue(), ftp_put() êáé ftp_fput().
Óôçí ðåñßðôùóç åðéóôõ÷ßáò åðéóôñÝöåé Ýíá array ìå ôá ïíüìáôá ôùí áñ÷åßùí ðïõ âñßóêïíôáé óôïí êáôÜëïãï, áëëéþò äßíåé FALSE.
Ç ftp_pasv() èÝôåé on ôçí passive mode åÜí ç ðáñÜìåôñïò pasv åßíáé TRUE, êáé off áí ç pasv åßíáé FALSE. Óôçí passive mode, ïé data connections îåêéíïýí áðü ôïí client, ðáñÜ áðü ôï server.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôçí áðïôõ÷ßá.
Ç ftp_put() áðïèçêåýåé ôï local_file óôïí FTP server, ùò remote_file. Ç ðñïóäéïñéóìÝíç transfer mode ðñÝðåé íá åßíáé åßôå FTP_ASCII åßôå FTP_BINARY.
Óçìåßùóç: Ç ðáñÜìåôñïò startpos ðñïóôÝèçêå óôçí PHP 4.3.0.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
ÅðéóôñÝöåé ôïí ôñÝ÷ïíôá êáôÜëïãï Þ FALSE óôçí áðïôõ÷ßá.
Ç ftp_quit() åßíáé ßäéá óå ëåéôïõñãßá ìå ôçí ftp_close().
Sends an arbitrary command to the FTP server. Returns the server's response as an array of strings. No parsing is performed on the response string, nor does ftp_raw() determine if the command succeeded.
See Also: ftp_exec()
(PHP 3>= 3.0.13, PHP 4 , PHP 5)
ftp_rawlist -- ÅðéóôñÝöåé ìßá ëåðôïìåñÞ ëßóôá ôùí áñ÷åßùí ðïõ âñßóêïíôáé óôï äïèÝíôá êáôÜëïãïÇ ftp_rawlist() åêôåëåß ôçí FTP åíôïëÞ LIST, êáé åðéóôñÝöåé ôï áðïôÝëåóìá óå Ýíá array. ÊÜèå óôïé÷åßï ôïõ array áíôéóôïé÷åß óå ìßá ãñáììÞ êåéìÝíïõ. Äåí ãßíåôáé parsing óôçí Ýîïäïò parsed. Ï system type identifier ðïõ åðéóôñÝöåôáé áðü ôçí ftp_systype() ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá ðñïóäéïñéóôåß ôï ðþò ðñÝðåé íá ìåôáöñÜæïíôáé ôá áðïôåëÝóìáôá.
Ç ftp_rename() áëëÜæåé ôï üíïìá åíüò áñ÷åßïõ Þ êáôáëüãïõ, ðïõ åßíáé ôï from, óå Ýíá íÝï, ôï to, ÷ñçóéìïðïéþíôáò ôï FTP stream ftp_stream.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôçí áðïôõ÷ßá.
ÄéáãñÜöåé ôï ðñïóäéïñéóìÝíï directory.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôï ëÜèïò.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé äéáèÝóéìç ìüíï óôï CVS.
ÅðéóôñÝöåé TRUE åÜí ìðïñåß íá ôåèåß ç åðéëïãÞ, êáé FALSE åÜí ü÷é. ¸íá ìÞíõìá warning óôÝëíåôáé åÜí ç option äåí õðïóôçñßæåôáé Þ ç value ðïõ ðåñíéÝôáé äåí ôáéñéÜ÷åé ìå ðñïâëåðüìåíç ôéìÞ ãéá ôç äïèåßóá option.
ÁõôÞ ç óõíÜñôçóç åëÝã÷åé ðïéêßëåò runtime åðéëïãÝò ãéá ôï ðñïóäéïñéóìÝíï FTP stream. Ç ðáñÜìåôñïò value åîáñôÜôáé áðü ôï áí ç option åðéëÝãåôáé íá åßíáé äéáöïñïðïéçìÝíç. ÁõôÞ ôç óôéãìÞ, õðïóôçñßæïíôáé ïé áêüëïõèåò åðéëïãÝò:
Ðßíáêáò 1. Õðïóôçñéæüìåíåò runtime FTP åðéëïãÝò
FTP_TIMEOUT_SEC | ÁëëÜæåé ôï timeout óå äõôåñüëåðôá ðïõ ÷ñçóéìïðïéïýíôáé ãéá üëåò ôçò ó÷åôéêÝò ìå äýêôéá óõáñôÞóåéò. Ç value ðñÝðåé íá åßíáé Ýíáò integer ìåãáëýôåñïò áðü 0. Ôï default timeout åßíáé 90 äåõôåñüëåðôá. |
FTP_AUTOSEEK | ¼ôáí åßíáé enabled, ïé áðáéôÞóåéò GET Þ PUT ìå ìßá resumepos Þ startpos ðáñÜìåôñï èá áíáæçôçèïýí ðñþôåò óôç æçôïýìåíç èÝóç ìåóá óôï áñ÷åßï. ÁõôÞ Ý÷åé ôåèåß default íá åßíáé enabled. |
Ç ftp_site() óôÝëíåé ôçí åíôïëÞ ðïõ ðñïóäéïñßæåôáé áðü ôçí cmd óôïí FTP server. Ïé åíôïëÝò SITE äåí åßíáé standard, êáé ðïéêßëïõí áðü server óå server. Åßíáé ÷ñÞóéìåò ãéá ôç äéá÷åßñéóç ðñáãìÜôùí üðùò file permissions êáé group membership.
ÅðéóôñÝöåé TRUE óôçí åðéôõ÷ßá êáé FALSE óôçí áðïôõ÷ßá.
Ç ftp_size() åðéóôñÝöåé ôï ìÝãåèïò ôïõ áñ÷åßïõ óå bytes. ÅÜí ðñïêýøåé êÜðïéï ëÜèïò, Þ áí äåí õðÜñ÷åé ôï áñ÷åßï, åðéóôñÝöåôáé ç ôéìÞ -1. Äåí õðïóôçñßæïõí üëïé ïé servers áõôü ôï ÷áñáêôçñéóôéêü.
Óå ðåñßðôùóç åðéôõ÷ßáò åðéóôñÝöåé ôï ìÝãåèïò ôïõ áñ÷åßïõ, áëëéþò ôçí ôéìÞ -1.
Returns a SSL-FTP stream on success or FALSE on error.
ftp_ssl_connect() opens a SSL-FTP connection to the specified host. The port parameter specifies an alternate port to connect to. If it's omitted or set to zero then the default FTP port 21 will be used.
The timeout parameter specifies the timeout for all subsequent network operations. If omitted, the default value is 90 seconds. The timeout can be changed and queried at any time with ftp_set_option() and ftp_get_option().
ÐáñÜäåéãìá 1. ftp_ssl_connect() example
|
Why this function may not exist: ftp_ssl_connect() is only available if OpenSSL support is enabled into your version of PHP. If it's undefined and you've compiled FTP support then this is why.
See also ftp_connect().
(PHP 4 >= 4.0.4, PHP 5)
call_user_func_array -- Call a user function given with an array of parametersCall a user defined function given by function, with the parameters in param_arr. For example:
ÐáñÜäåéãìá 1. call_user_func_array() example
|
See also call_user_func().
Call a user defined function given by the function parameter. Take the following:
<?php function barber($type) { echo "You wanted a $type haircut, no problem"; } call_user_func('barber', "mushroom"); call_user_func('barber', "shave"); ?> |
Object methods may also be invoked statically using this function by passing array($objectname, $methodname) to the function parameter.
<?php class myclass { function say_hello() { echo "Hello!\n"; } } $classname = "myclass"; call_user_func(array($classname, 'say_hello')); ?> |
See also: is_callable(), and call_user_func_array()
Creates an anonymous function from the parameters passed, and returns a unique name for it. Usually the args will be passed as a single quote delimited string, and this is also recommended for the code. The reason for using single quoted strings, is to protect the variable names from parsing, otherwise, if you use double quotes there will be a need to escape the variable names, e.g. \$avar.
You can use this function, to (for example) create a function from information gathered at run time:
ÐáñÜäåéãìá 1. Creating an anonymous function with create_function()
|
Or, perhaps to have general handler function that can apply a set of operations to a list of parameters:
ÐáñÜäåéãìá 2. Making a general processing function with create_function()
and when you run the code above, the output will be:
|
But perhaps the most common use for of lambda-style (anonymous) functions is to create callback functions, for example when using array_walk() or usort()
ÐáñÜäåéãìá 3. Using anonymous functions as callback functions
outputs:
an array of strings ordered from shorter to longer
outputs:
sort it from longer to shorter
outputs:
|
Returns the argument which is at the arg_num'th offset into a user-defined function's argument list. Function arguments are counted starting from zero. func_get_arg() will generate a warning if called from outside of a function definition.
If arg_num is greater than the number of arguments actually passed, a warning will be generated and func_get_arg() will return FALSE.
<?php function foo() { $numargs = func_num_args(); echo "Number of arguments: $numargs<br />\n"; if ($numargs >= 2) { echo "Second argument is: " . func_get_arg(1) . "<br />\n"; } } foo (1, 2, 3); ?> |
func_get_arg() may be used in conjunction with func_num_args() and func_get_args() to allow user-defined functions to accept variable-length argument lists.
Óçìåßùóç: This function was added in PHP 4.
Returns an array in which each element is the corresponding member of the current user-defined function's argument list. func_get_args() will generate a warning if called from outside of a function definition.
<?php function foo() { $numargs = func_num_args(); echo "Number of arguments: $numargs<br />\n"; if ($numargs >= 2) { echo "Second argument is: " . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "Argument $i is: " . $arg_list[$i] . "<br />\n"; } } foo(1, 2, 3); ?> |
func_get_args() may be used in conjunction with func_num_args() and func_get_arg() to allow user-defined functions to accept variable-length argument lists.
Óçìåßùóç: This function was added in PHP 4.
Returns the number of arguments passed into the current user-defined function. func_num_args() will generate a warning if called from outside of a user-defined function.
<?php function foo() { $numargs = func_num_args(); echo "Number of arguments: $numargs\n"; } foo(1, 2, 3); // Prints 'Number of arguments: 3' ?> |
func_num_args() may be used in conjunction with func_get_arg() and func_get_args() to allow user-defined functions to accept variable-length argument lists.
Checks the list of defined functions, both built-in (internal) and user-defined, for function_name. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
<?php if (function_exists('imap_open')) { echo "IMAP functions are available.<br />\n"; } else { echo "IMAP functions are not available.<br />\n"; } ?> |
Note that a function name may exist even if the function itself is unusable due to configuration or compiling options (with the image functions being an example). Also note that function_exists() will return FALSE for constructs, such as include_once() and echo().
See also method_exists() and get_defined_functions().
This function returns an multidimensional array containing a list of all defined functions, both built-in (internal) and user-defined. The internal functions will be accessible via $arr["internal"], and the user defined ones using $arr["user"] (see example below).
<?php function myrow($id, $data) { return "<tr><th>$id</th><td>$data</td></tr>\n"; } $arr = get_defined_functions(); print_r($arr); ?> |
Will output something along the lines of:
Array ( [internal] => Array ( [0] => zend_version [1] => func_num_args [2] => func_get_arg [3] => func_get_args [4] => strlen [5] => strcmp [6] => strncmp ... [750] => bcscale [751] => bccomp ) [user] => Array ( [0] => myrow ) ) |
See also get_defined_vars() and get_defined_constants().
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
register_shutdown_function -- Register a function for execution on shutdownRegisters the function named by function to be executed when script processing is complete.
Multiple calls to register_shutdown_function() can be made, and each will be called in the same order as they were registered. If you call exit() within one registered shutdown function, processing will stop completely and no other registered shutdown functions will be called.
The registered shutdown functions are called after the request has been completed (including sending any output buffers), so it is not possible to send output to the browser using echo() or print(), or retrieve the contents of any output buffers using ob_get_contents().
Óçìåßùóç: Typically undefined functions cause fatal errors in PHP, but when the function called with register_shutdown_function() is undefined, an error of level E_WARNING is generated instead. Also, for reasons internal to PHP, this error will refer to Unknown() at line #0.
See also auto_append_file, exit(), and the section on connection handling.
Registers the function named by func to be executed when a tick is called. Also, you may pass an array consisting of an object and a method as the func.
See also declare() and unregister_tick_function().
(PHP 4 >= 4.0.3, PHP 5)
unregister_tick_function -- De-register a function for execution on each tickDe-registers the function named by function_name so it is no longer executed when a tick is called.
The gettext functions implement an NLS (Native Language Support) API which can be used to internationalize your PHP applications. Please see the gettext documentation for your system for a thorough explanation of these functions or view the docs at http://www.gnu.org/software/gettext/manual/gettext.html.
To use these functions you must download and install the GNU gettext package from http://www.gnu.org/software/gettext/gettext.html
To include GNU gettext support in your PHP build you must add the option --with-gettext[=DIR] where DIR is the gettext install directory, defaults to /usr/local.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy gnu_gettext.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32). Starting with PHP 4.2.3 the name changed to libintl-1.dll, this requires also iconv.dll to be copied.
(PHP 4 >= 4.2.0, PHP 5)
bind_textdomain_codeset -- Specify the character encoding in which the messages from the DOMAIN message catalog will be returnedWith bind_textdomain_codeset(), you can set in which encoding will be messages from domain returned by gettext() and similar functions.
The bindtextdomain() function sets the path for a domain. It returns the full pathname for the domain currently being set.
This function allows you to override the current domain for a single message lookup. It also allows you to specify a category.
See also gettext().
This function allows you to override the current domain for a single plural message lookup. It also allows you to specify a category.
See also ngettext().
The dgettext() function allows you to override the current domain for a single message lookup.
See also gettext().
The dngettext() function allows you to override the current domain for a single plural message lookup.
See also ngettext().
This function returns a translated string if one is found in the translation table, or the submitted message if not found. You may use the underscore character '_' as an alias to this function.
ÐáñÜäåéãìá 1. gettext()-check
|
See also setlocale().
ngettext() returns correct plural form of message identified by msgid1 and msgid2 for count n. Some languages have more than one form for plural messages dependent on the count.
This function sets the domain to search within when calls are made to gettext(), usually the named after an application. The previous default domain is returned. Call it with NULL as parameter to get the current setting without changing it.
These functions allow you to work with arbitrary-length integers using the GNU MP library.
These functions have been added in PHP 4.0.4.
Óçìåßùóç: Most GMP functions accept GMP number arguments, defined as resource below. However, most of these functions will also accept numeric and string arguments, given that it is possible to convert the latter to a number. Also, if there is a faster function that can operate on integer arguments, it would be used instead of the slower function when the supplied arguments are integers. This is done transparently, so the bottom line is that you can use integers in every function that expects GMP number. See also the gmp_init() function.
Ðñïåéäïðïßçóç |
If you want to explicitly specify a large integer, specify it as a string. If you don't do that, PHP will interpret the integer-literal first, possibly resulting in loss of precision, even before GMP comes into play. |
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
You can download the GMP library from http://www.swox.com/gmp/. This site also has the GMP manual available.
You will need GMP version 2 or better to use these functions. Some functions may require more recent version of the GMP library.
In order to have these functions available, you must compile PHP with GMP support by using the --with-gmp option.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
More mathematical functions can be found in the sections BCMath Arbitrary Precision Mathematics Functions and Mathematical Functions.
Add two GMP numbers. The result will be a GMP number representing the sum of the arguments.
Clears (sets to 0) bit index in a. The index starts at 0.
Óçìåßùóç: Unlike most of the other GMP functions, gmp_clrbit() must be called with a GMP resource that already exists (using gmp_init() for example). One will not be automatically created.
See also gmp_setbit().
Returns a positive value if a > b, zero if a = b and a negative value if a < b.
Divides a by b and returns the integer result. The result rounding is defined by the round, which can have the following values:
GMP_ROUND_ZERO: The result is truncated towards 0.
GMP_ROUND_PLUSINF: The result is rounded towards +infinity.
GMP_ROUND_MINUSINF: The result is rounded towards -infinity.
This function can also be called as gmp_div().
ÐáñÜäåéãìá 1. gmp_div_q() example
The printout of the above program will be:
|
See also gmp_div_r(), gmp_div_qr()
The function divides n by d and returns array, with the first element being [n/d] (the integer result of the division) and the second being (n - [n/d] * d) (the remainder of the division).
See the gmp_div_q() function for description of the round argument.
See also gmp_div_q(), gmp_div_r().
Calculates remainder of the integer division of n by d. The remainder has the sign of the n argument, if not zero.
See the gmp_div_q() function for description of the round argument.
See also gmp_div_q(), gmp_div_qr()
Divides n by d, using fast "exact division" algorithm. This function produces correct results only when it is known in advance that d divides n.
Calculates factorial (a!) of a.
ÐáñÜäåéãìá 1. gmp_fact() example
The printout of the above program will be:
|
Calculate greatest common divisor of a and b. The result is always positive even if either of, or both, input operands are negative.
Calculates g, s, and t, such that a*s + b*t = g = gcd(a,b), where gcd is the greatest common divisor. Returns an array with respective elements g, s and t.
This function can be used to solve linear Diophantine equations in two variables. These are equations that allow only integer solutions and have the form: a*x + b*y = c. For more information, go to the "Diophantine Equation" page at MathWorld
ÐáñÜäåéãìá 1. Solving a linear Diophantine equation
|
Returns the hamming distance between a and b. Both operands should be non-negative.
See also gmp_popcount(), gmp_xor()
Creates a GMP number from an integer or string. String representation can be decimal or hexadecimal. In the latter case, the string should start with 0x.
Óçìåßùóç: It is not necessary to call this function if you want to use integer or string in place of GMP number in GMP functions, like gmp_add(). Function arguments are automatically converted to GMP numbers, if such conversion is possible and needed, using the same rules as gmp_init().
This function allows to convert GMP number to integer.
Ðñïåéäïðïßçóç |
This function returns a useful result only if the number actually fits the PHP integer (i.e., signed long type). If you want just to print the GMP number, use gmp_strval(). |
ÐáñÜäåéãìá 1. gmp_intval() example
The printout of the above program will be:
|
Computes the inverse of a modulo b. Returns FALSE if an inverse does not exist.
Computes Jacobi symbol of a and p. p should be odd and must be positive.
Compute the Legendre symbol of a and p. p should be odd and must be positive.
Calculates n modulo d. The result is always non-negative, the sign of d is ignored.
Calculates logical inclusive OR of two GMP numbers.
Returns TRUE if a is a perfect square, FALSE otherwise.
ÐáñÜäåéãìá 1. gmp_perfect_square() example
The printout of the above program will be:
|
See also: gmp_sqrt(), gmp_sqrtrm().
Raise base into power exp. The case of 0^0 yields 1. exp cannot be negative.
ÐáñÜäåéãìá 1. gmp_pow() example
The printout of the above program will be:
|
Calculate (base raised into power exp) modulo mod. If exp is negative, result is undefined.
If this function returns 0, a is definitely not prime. If it returns 1, then a is "probably" prime. If it returns 2, then a is surely prime. Reasonable values of reps vary from 5 to 10 (default being 10); a higher value lowers the probability for a non-prime to pass as a "probable" prime.
The function uses Miller-Rabin's probabilistic test.
Generate a random number. The number will be between zero and the number of bits per limb multiplied by limiter. If limiter is negative, negative numbers are generated.
A limb is an internal GMP mechanism. The number of bits in a limb is not static, and can vary from system to system. Generally, the number of bits in a limb is either 16 or 32, but this is not guaranteed.
ÐáñÜäåéãìá 1. gmp_random() example
The printout of the above program might be:
|
Scans a, starting with bit start, towards more significant bits, until the first clear bit is found. Returns the index of the found bit. The index starts from 0.
ÐáñÜäåéãìá 1. gmp_scan0() example
The printout of the above program will be:
|
Scans a, starting with bit start, towards more significant bits, until the first set bit is found. Returns the index of the found bit. If no set bit is found, -1 is returned.
ÐáñÜäåéãìá 1. gmp_scan1() example
The printout of the above program will be:
|
Sets bit index in a. set_clear defines if the bit is set to 0 or 1. By default the bit is set to 1. Index starts at 0.
Óçìåßùóç: Unlike most of the other GMP functions, gmp_setbit() must be called with a GMP resource that already exists (using gmp_init() for example). One will not be automatically created.
See also gmp_clrbit().
Returns 1 if a is positive, -1 if a is negative, and 0 if a is zero.
Calculates square root of a and returns the integer portion of the result.
Returns array where first element is the integer square root of a (see also gmp_sqrt()), and the second is the remainder (i.e., the difference between a and the first element squared).
ÐáñÜäåéãìá 1. gmp_sqrtrem() example
The printout of the above program will be:
|
Convert GMP number to string representation in base base. The default base is 10. Allowed values for the base are from 2 to 36.
Ç header() ÷ñçóéìïðïéåßôáé ãéá íá óôáëèïýí áêáôÝñãáóôïé HTTP headers. Äåßôå ôï HTTP/1.1 specification ãéá ðåñéóóüôåñåò ðëçñïöïñßåò ðÜíù óôïõò HTTP headers.
Ç ðñïáéñåôéêÞ ðáñÜìåôñïò replace äåß÷íåé áí ï header ðñÝðåé íá áíôéêáôáóôÞóåé Ýíáí ðñïçãïýìåíï ðáñüìïéï header, Þ íá ðñïóèÝóåé Ýíáí äåýôåñï header ôïõ ßäéïõ ôýðïõ. Ç ðñïêáèïñéóìÝíç åíÝñãåéá åßíáé ç áíôéêáôÜóôáóç ôïõ, áëëÜ áí ðåñÜóåôå ùò äåýôåñç ðáñÜìåôñï ôï FALSE ìðïñåßôå íá óôåßëåôå ðïëëáðëïýò headers ôïõ ßäéïõ ôýðïõ. Ãéá ðáñÜäåéãìá:
Ç äåýôåñç ðñïáïñåôéêÞ ðáñÜìåôñïò åßíáé ç http_response_code ç ïðïßá åíåñãïðïéåß ôçí HTTP response code óôçí óõãêåêñéìÝíç ôéìÞ. (ÁõôÞ ç ðáñÜìåôñïò åßíáé äéáèÝóéìç áðü ôçí PHP 4.3.0 êáé ìåôÜ.)
ÕðÜñ÷ïõí äýï éäéáßôåñåò êëÞóåéò ãéá headers. Ç ðñþôç åßíáé Ýíáò header ðïõ áñ÷ßæåé ìå ôï string "HTTP/" ôï ïðïßï èá ÷ñçóéìïðïéçèåß ãéá íá âñåèåß ôï HTTP status code ðïõ ðñÝðåé íá óôáëåß. Ãéá ðáñÜäåéãìá, áí Ý÷åôå ðáñáìåôñïðïéÞóåé ôïí Apache íá ÷ñçóéìïðïéåß Ýíá PHP script ãéá íá ÷åéñßæåôáé requests ãéá ÷áìÝíá áñ÷åßá (÷ñçóéìïðïéþíôáò ôçí ErrorDocument íôéñåêôßâá), ßóùò èÝëåôå íá âåâáéùèåßôå üôé ôï script óáò ðáñÜãåé ôïí êáôÜëëçëï status code.
Óçìåßùóç: Ç ãñáììÞ ìå ôïí HTTP status header èá åßíáé ðÜíôá ç ðñþôç ðïõ èá óôÝëíåôáé óôïí client, Üó÷åôá áðü áí ç ðñáãìáôéêÞ êëÞóç ôïõ header() åßíáé ç ðñþôç Þ ü÷é. Ôï status ìðïñåß íá áëëÜîåé êáëþíôáò ôçí header() ìå ìéá íÝá ãñáììÞ status ïðïéáäÞðïôå óôéãìÞ åêôüò êáé áí ïé HTTP headers Ý÷ïõí Þäç óôáëåß.
Óçìåßùóç: Óôçí PHP 3, áõôü äïõëåýåé ìüíï üôáí ç PHP ìåôáãëùôßæåôáé ùò module ôïõ Apache. Ìðïñåßôå íá ðåôý÷åôå ôï ßäéï áðïôÝëåóìá ÷ñçóéìïðïéþíôáò ôï Status header.
Ç äåýôåñç åéäéêÞ ðåñßðôùóç åßíáé ç "Location:" header. Äåí óôÝëíåé ìüíï ôïí header ðßóù óôïí browser, áëëÜ åðßóçò åðéóôñÝöåé Ýíá REDIRECT (302) status code óôïí browser åêôüò êáé áí êÜðïéïò 3xx status code Ý÷åé Þäç ôåèåß.
<?php header("Location: http://www.example.com/"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> |
Óçìåßùóç: Ç HTTP/1.1 áðáéôåß Ýíá áðüëõôï URI ùò ðáñÜìåôñï óôçí Location: ðïõ óõìðåñéëáìâÜíåé ôï ó÷Þìá, ôï hostname êáé ôï áðüëõôï path, ìåñéêïß üìùò clients äÝ÷ïíôáé êáé ó÷åôéêÜ URIs. ÓõíÞèùò ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôéò $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] êáé dirname() ìüíïé óáò, ãéá íá êÜíåôå Ýíá áðüëõôï URI áðü Ýíá ó÷åôéêü:
Ôá PHP scripts óõ÷íÜ ðáñÜãïõí äõíáìéêü ðåñéå÷üìåíï ðïõ äåí ðñÝðåé íá ãßíåé cached áðü ôïí browser ôïõ client Þ áðü ïðïéïíäÞðïôå proxy ðïõ êÜíåé cache áíÜìåóá óôïí server êáé óôïí browser ôïõ client. Áñêåôïß proxies êáé clients ìðïñïýí íá ñõèìéóôïýí Ýôóé þóôå íá áðåíåñãïðïéÞóïõí ôï caching ìå:
<?php // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // always modified header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // HTTP/1.1 header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.0 header("Pragma: no-cache"); ?> |
Óçìåßùóç: ºóùò áíáêáëýøåôå üôé ïé óåëßäåò óáò äåí ãßíïíôáé cache áêüìç êáé áí äåí óôÝëíïíôáé üëïé ïé ðáñáðÜíù headers. ÕðÜñ÷åé Ýíáò áñéèìüò åðéëïãþí ðïõ ïé ÷ñÞóôåò ìðïñïýí íá èÝóïõí óôïí browser êáé íá áëëÜîïõí ôç óõìðåñéöïñÜ ôïõ ó÷åôéêÜ ìå ôï caching. ÓôÝëíïíôáò ôïõò ðáñáðÜíù headers, èá ðñÝðåé íá ðáñáêáìöèïýí ïðïéåóäÞðïôå ñõèìßóåéò ðïõ ßóùò ðñïêáëÝóïõí íá ãßíåé ôï áðïôÝëåóìá ôïõ script óáò, cached.
ÅðéðëÝïí, ïé ñõèìßóåéò session_cache_limiter() êáé session.cache_limiter ìðïñïýí íá ÷ñçóéìïðïéçèïýí ãéá íá ðáñá÷èïýí áõôüìáôá ïé óùóôïß caching-related headers üôáí ÷ñçóéìïðïéïýíôáé sessions.
Èõìçèåßôå üôï ç header() ðñÝðåé íá êáëåßôáé ðñéí óôáëåß ïðïéïäÞðïôå ðñáãìáôéêü áðïôÝëåóìá, åßôå ìå êáíïíéêÜ HTML tags, êåíÝò ãñáììÝò óå Ýíá áñ÷åßï, Þ áðü ôçí PHP. Åßíáé ðïëý óõíçèéóìÝíï ëÜèïò íá äéáâÜæïõìå êþäéêá ìå óõíáñôÞóåéò include(), Þ require(), Þ Üëëåò óõíáñôÞóåéò ðïõ ðñïóðåëáýíïõí áñ÷åßá, êáé Ý÷ïõí êåíÜ Þ Üäåéåò ãñáììÝò ðïõ åßíáé ôï áðïôÝëåóìá ðñéí ôçí êëÞóç ôçò header() . Ôï ßäéï ðñüâëçìá õðÜñ÷åé êáé üôáí ÷ñçóéìïðïéåßôáé Ýíá ìüíï áñ÷åßï PHP/HTML.
<html> <?php /* This will give an error. Note the output * above, which is before the header() call */ header('Location: http://www.example.com/'); ?> |
Óçìåßùóç: Óôçí PHP 4, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå buffering óôï áðïôÝëåóìá ãéá íá áíôéìåôùðßóåôå áõôü ôï ðñüâëçìá, êÜíïíôáò buffer óôïí server ôï overhead ïëüêëçñïõ ôïõ áðïôåëÝóìáôïò (output) óôïí browser ìÝ÷ñé áõôü íá óôáëåß. Ìðïñåßôå íá ôï êÜíåôå áõôü êáëþíôáò ôçí ob_start() êáé ôçí ob_end_flush() óôï script óáò, Þ èÝôïíôáò ôçí output_buffering configuration íôéñåêôßâá óôï php.ini Þ óôá áñ÷åßá configuration ôïõ server.
Áí èÝëåôå íá ðñïôñÝðåôå ôïí ÷ñÞóôç íá óþæåé ôá äåäïìÝíá ðïõ óôÝëíåôå, üðùò Ýíá PDF áñ÷åßï ðïõ Ýåé ðáñá÷èåß, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôïí Content-Disposition header ãéá íá ôïõ äþóåôå Ýíá ðñïôåéíüìåíï üíïìá áñ÷åßïõ êáé íá áíáãêÜóåôå ôïí browser íá åìöáíßóåé ôï ðáñÜèõñï ãéá save.
<?php // We'll be outputting a PDF header("Content-type: application/pdf"); // It will be called downloaded.pdf header("Content-Disposition: attachment; filename=downloaded.pdf"); // The PDF source is in original.pdf readfile('original.pdf'); ?> |
Óçìåßùóç: ÕðÜñ÷åé Ýíá bug óôïí Microsoft Internet Explorer 4.01 ðïõ åìðïäßæåé ôç ëåéôïõñãßá ôïõ ðáñáðÜíù. Êáé äåí ãßíåôáé êÜôé ãé'áõôü. ÕðÜñ÷åé åðßóçò êáé Ýíá bug óôïí Microsoft Internet Explorer 5.5 ðïõ áëëçëåðéäñÜ ìå áõôï, êáé ìðïñåß íá ëõèåß áíáâáèìßæïíôáò ôïí ìå ôï Service Pack 2 êáé ìåôÜ.
Óçìåßùóç: Áí ôï safe mode åßíáé åíåñãïðïéçìÝíï ôüôå ôï uid ôïõ script ðñïóôßèåôáé óôï realm ìÝñïò ôïõ WWW-Authenticate header áí Ý÷åôå åíåñãïðïéÞóåé áõôüí ôïí header (÷ñçóéìïðïéåßôáé ãéá HTTP Authentication).
Äåßôå åðßóçò ôéò headers_sent(), setcookie(), êáé ôï ôìÞìá ó÷åôéêÜ ìå ôçí HTTP authentication.
headers_list() will return a numerically indexed array of headers to be sent to the browser / client. To determine whether or not these headers have been sent yet, use headers_sent().
ÐáñÜäåéãìá 1. Examples using headers_list()
this will output :
|
See Also: headers_sent(), header(), and setcookie().
Ç headers_sent() èá åðéóôñÝøåé FALSE áí äåí Ý÷ïõí óôáëåß HTTP headers êáé TRUE óôçí áíôßèåôç ðåñßðôùóç. Áí ïé ðñïáéñåôéêÝò ðáñÜìåôñïé file êáé line Ý÷ïõí ôåèåß, ç headers_sent() èá âÜëåé ôï üíïìá ôïõ áñ÷åßïõ ôçò php êáé ôïí áñéèìü ôçò ãñáììÞò áð'üðïõ ôï áðïôÝëåóìá Üñ÷éóå, óôéò file êáé line ìåôáâëçôÝò.
Äåí ìðïñåßôå íá ðñïóèÝóåôå Üëëåò ãñáììÝò óôï header ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç header() üôáí ôï ôìÞìá ôïõ header Ý÷åé Þäç óôáëåß. ×ñçóéìïðïéþíôáò áõôÞ ôç óõíÜñôçóç ìðïñåßôå ôïõëÜ÷éóôï íá åìðïäßóåôå íá ðÜñåôå ìçíýìáôá ëÜèïõò ó÷åôéêÜ ìå ôçí HTTP header. Ìéá Üëëç åðéëïãÞ åßíáé íá ÷ñçóéìïðïéÞóåôå ôçí Output Buffering.
Óçìåßùóç: Ïé ðñïáéñåôéêÝò ðáñÜìåôñïé file êáé line ðñïóôÝèçêáí óôçí PHP 4.3.0.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ðïõ ÷ñçóéìïðïéïýí ôçí headers_sent()
|
Äåßôå åðßóçò ôéò ob_start(), trigger_error(), êáé header() ãéá ìéá ðéï ëåðôïìåñÞ óõæÞôçóç óôá èÝìáôá ðïõ ðñáãìáôåýïíôáé.
Ç setcookie() ïñßæåé íá óôáëåß Ýíá cookie ìáæß ìå ôïõò õðüëïéðïõò HTTP headers. ¼ðùò êáé ïé Üëëïé headers, ôá cookies ðñÝðåé íá óôÝëíïíôáé ðñéí áðü ïðïéïäÞðïôå áðïôÝëåóìá (output) ôïõ script óáò (áõôü åßíáé Ýíáò ðåñéïñéóìüò ôïõ ðñùôïêüëïõ). Áõôü ðñïûðïèÝôåé üôé åóåßò ôïðïèåôåßôå ôéò êëÞóåéò áõôÞò ôçò óõíÜñôçóçò ðñéí áðü êÜèå output, óõìðåñéëáìâáíïìÝíùí ôùí <html> êáé <head> tags üðùò åðßóçò êáé ïðéïíäÞðïôå êåíþí. Áí ôï output õðÜñ÷åé ðñéí áðü ôçí êëÞóç áõôÞò ôçò óõíÜñôçóçò, ç setcookie() èá áðïôý÷åé êáé èá åðéóôñÝøåé FALSE. Áí ç setcookie() åêôåëåóôåß åðéôõ÷þò, èá åðéóôñÝøåé TRUE. Áõôü üìùò äåí äåß÷íåé áí ï ÷ñÞóôçò Ý÷åé äå÷èåß ôï cookie.
Óçìåßùóç: Óôçí PHP 4, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå buffering óôï output ãéá íá óôåßëåôå ôï output ðñéí áðü ôçí êëÞóç áõôÞò ôçò óõíÜñôçóçò, êÜíïíôáò buffer óôïí server ôï overhead ïëüêëçñïõ ôïõ output óôïí browser ìÝ÷ñé áõôü íá óôáëåß. Ìðïñåßôå íá ôï êÜíåôå áõôü êáëþíôáò ôçí ob_start() êáé ôçí ob_end_flush() óôï script óáò, Þ èÝôïíôáò ôçí output_buffering configuration íôéñåêôßâá óôï php.ini Þ óôá áñ÷åßá configuration ôïõ server.
¼ëåò ïé ðáñÜìåôñïé åêôüò áðü ôçí ðáñÜìåôñï name åßíáé ðñïáéñåôéêÝò. Ìðïñåßôå åðßóçò íá áíôéêáôáóôÞóåôå ìéá ðáñÜìåôñï ìå Ýíá êåíü string ("") ðñïêåéìÝíïõ íá ðáñáêÜìøåôå áõôÞ ôçí ðáñÜìåôñï. ÅðåéäÞ ïé ðáñÜìåôñïé expire êáé secure åßíáé áêÝñáéïé, äåí ìðïñïýí íá ðáñáêáìöèïýí ìå Ýíá êåíü string, áëëÜ ðñÝðåé íá ÷ñçóéìïðïéÞóåôå ôï ìçäÝí (0). Ï ðáñáêÜôù ðßíáêáò åîçãåß êÜèå ðáñÜìåôñï ôçò óõíÜñôçóçò setcookie(), êáé äéáâÜóôå ôï ôìÞìá Ïñéóìü cookie ãéá Netscape ãéá ïäçãßåò ó÷åôéêÜ ìå ôï ðþò êÜèå ðáñÜìåôñïò setcookie() äïõëåýåé êáé ôï RFC 2965 ãéá åðéðñüóèåôåò ðëçñïöïñßåò ó÷åôéêÜ ìå ôï ðþò ç HTTP cookies äïõëåýåé.
Ðßíáêáò 1. setcookie() åîÞãçóç ðáñáìÝôñùí
ÐáñÜìåôñïò | ÐåñéãñáöÞ | Ðáñáäåßãìáôá |
---|---|---|
name | Ôï üíïìá ôïõ cookie. | ç 'cookiename' êáëåßôáé ùò $_COOKIE['cookiename'] |
value | Ç ôéìÞ ôïõ cookie. Ç ôéìÞ áõôÞ áðïèçêåýåôáé óôïí õðïëïãéóôþí ôùí clients, ãé'áõôü ìçí áðïèçêåýåôå åõáßóèçôåò ðëçñïöïñßåò. | ÕðïèÝôïíôáò üôé ç name åßíáé ç 'cookiename', áõôÞ ç ôéìÞ ðáßñíåôáé ìå ôçí $_COOKIE['cookiename'] |
expire | Ç þñá ëÞîçò ôïõ cookie. Áõôü åßíáé Ýíá unix timestamp Ýôóé åßíáé óå áñéèìü äåõôåñïëÝðôùí áðü ôçí åðï÷Þ (epoch). Ìå Üëëá ëüãéá, åßíáé ðéèáíü üôé èá èÝóåôå áõôü ìå ôç óõíÜñôçóç time() óõí ôïí áñéèìü ôùí äåõôåñïëÝðôùí ðñéí áðü ôç óôéãìÞ ðïõ èÝëåôå íá ëÞîåé. ¹ ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí mktime(). | Ç time()+60*60*24*30 èá ïñßóåé ôï cookie íá ëÞîåé óå 30 ìÝñåò. Áí äåí ôåèåß, ôï cookie èá ëÞîåé óôï ôÝëïò ôïõ session (üôáí êëåßóåé ï browser). |
path | Ôï path óôïí server óôï ïðïßï èá åßíáé äéáèÝóéìï ôï cookie. | Áí ôåèåß óôï '/', ôï cookie èá åßíáé äéáèÝóéìï ìÝóá óå ïëüêëçñï ôï domain. Áí ôåèåß óôï '/foo/', ôï cookie èá åßíáé äéáèÝóéìï ìüíï ìÝóá óôïí êáôÜëïãï /foo/ êáé óå üëïõò ôïõò õðï-êáôáëüãïõò üðùò ïé /foo/bar/ ôïõ domain. Ç ðñïêáèïñéóìÝíç ôéìÞ åßíáé ôï ôñÝ÷ïí directory óôï ïðïßï èÝôåôáé ôï cookie. |
domain | Ôï domain óôï ïðïßï ôï cookie åßíáé äéáèÝóéìï. | Ãéá íá åßíáé ôï cookie äéáèÝóéìï óå üëá ôá subdomains ôïõ example.com èá ðñÝðåé íá ôï èÝóåôå óôï '.example.com'. Ç . äåí áðáéôåßôáé áëëÜ ôï êÜíåé óõìâáôü ìå ðåñéóóüôåñïõò browsers. ÈÝôïíôáò ôï óôï www.example.com èá êÜíåé ôï cookie äéáèÝóéìï ìüíï óôï www subdomain. Áíáöåñèåßôå óôï tail matching óôï spec ãéá ëåðôïìÝñåéåò. |
secure | Äåß÷íåé üôé ôï cookie ìðïñåß ìüíï íá ìåôáäùèåß ìå secure HTTPS óýíäåóç. ¼ôáí ôßèåôáé óôï 1, ôï cookie èá äçìéïõñãçèåß ìüíï áí õðÜñ÷åé ìéá áóöáëÞò óýíäåóç. Ôï ðñïêáèïñéóìÝíï åßíáé ôï 0. | 0 Þ 1 |
Áöïý Ý÷ïõí óôáëåß ôá cookies, ìðïñïýí íá ðñïóðåëáóôïýí êáôÜ ôç öüñôùóç ôçò åðüìåíçò óåëßäáò ìå ôïí ðßíáêá (array) $_COOKIE Þ $HTTP_COOKIE_VARS. Óçìåéþóôå üôé ïé autoglobals üðùò ïé $_COOKIE åßíáé äéáèÝóéìåò áðü ôçí PHP 4.1.0. Ç $HTTP_COOKIE_VARS õðÜñ÷åé áðü ôçí PHP 3. Ïé ôéìÝò ôùí cookies õðÜñ÷ïõí åðßóçò êáé óôçí $_REQUEST.
Óçìåßùóç: Áí ç íôéñåêôßâá ôçò PHP register_globals ôåèåß óôï on ôüôå ïé ôéìÝò ôùí cookies èá ãßíïõí åðßóçò ìåôáâëçôÝò. Óôá ðáñáäåßãìáôá ìáò ðáñáêÜôù, ç $TextCookie èá õðÜñîåé. Óõíéóôïýìå íá ÷ñçóéìïðïéåßôå ôçí $_COOKIE.
Óõ÷íÜ ëÜèç:
Ôá cookies äå èá åßíáé ïñáôÜ ìÝ÷ñé ôï åðüìåíï öüñôùìá ôçò óåëßäáò ãéá ôçí ïðïßá ôï cookie èá ðñÝðåé íá åßíáé ïñáôü. Ãéá íá åëÝíîåôå áí Ýíá cookie Ý÷åé ïñéóôåß ìå åðéôõ÷ßá, åëÝíîôå ôï cookie óôï åðüìåíï öüñôùìá ôçò óåëßäá ðñéí üìùò ôï cookie ëÞîåé. Ç þñá ëÞîçò ïñßæåôáé äéáìÝóïõ ôçò ðáñáìÝôñïõ expire. ¸íáò ùñáßïò ôñüðïò ãéá íá êÜíåôå debug óôçí ýðáñîç ôùí cookies åßíáé êáëþíôáò áðëÜ ôçí print_r($_COOKIE);.
Ôá cookies ðñÝðåé íá äéáãñÜöïíôáé ìå ôéò ßäéåò ðáñáìÝôñïõò ìå ôéò ïðïßåò èÝôïíôáé. Áí ç ôéìÞ ôçò ðáñáìÝôñïõ åßíáé Ýíá êåíü string (""), êáé üëåò ïé Üëëåò ðáñÜìåôñïé ôáéñéÜæïõí óå êÜðïéá ðñïçãïýìåíç êëÞóç ôçò setcookie, ôüôå ôï cookie ìå ôï êáèïñéóìÝíï üíïìá èá äéáãñáöåß áðü ôïí áðïìáêñõóìÝíï client.
Ôá ïíüìáôá ôùí cookies ìðïñïýí íá ôåèïýí ùò ïíüìáôá ðéíÜêùí êáé èá åßíáé äéáèÝóéìá óôá PHP scripts óáò ùò ðßíáêåò áëëÜ îå÷ùñéóôÜ cookies áðïèçêåýïíôáé óôï óýóôçìá ôùí ÷ñçóôþí. Èåùñåßóôå ôçí explode() Þ ôçí serialize() ãéá íá èÝóåôå Ýíá cookie ìå ðïëëáðëÜ ïíüìáôá êáé ôéìÝò.
Óôçí PHP 3, ïé ðïëëáðëÝò êëÞóåéò ôçò setcookie() óôï ßäéï script èá åêôåëåóôïýí ìå áíôßèåôç óåéñÜ. Áí ðñïóðáèÞóåôå íá äéáãñÜøåôå Ýíá cookie ðñéí ðñïóèÝóåôå Üëëï èá ðñÝðåé íá ôïðïèåôÞóåôå ôçí åéóáãùãÞ ðñïí ôçí äéáãñáöÞ. Óôçí PHP 4, ïé ðïëëáðëÝò êëÞóåéò óôçí setcookie() åêôåëïýíôáé ìå ôç óåéñÜ ðïõ êáëïýíôáé.
Áêïëïõèïýí ìåñéêÜ ðáñáäåßãìáôá ó÷åôéêÜ ìå ôï ðþò íá óôÝëíåôå cookies:
Óçìåéþóôå üôé ôï ôìÞìá ðïõ ðåñéÝ÷åé ôçí ôéìÞ ôïõ cookie èá ãßíåé áõôüìáôá urlencoded üôáí óôåßëåôå ôï cookie, êáé üôáí áõôü ðáñáëçöèåß, áðïêùäéêïðïéåßôáé áõôüìáôá êáé áíôßèåôáé óå ìéá ìåôáâëçôÞ ìå ôï ßäéï üíïìá ìå ôï üíïìá ôïõ cookie. Ãéá íá äåßôå ôá ðåñéå÷üìåíá áðü ôï äïêéìáóôéêü cookie ìáò óå Ýíá script, áðëÜ ÷ñçóéìïðïéÞóôå Ýíá áðü ôá ðáñáêÜôù ðáñáäåßãìáôá:
<?php // Print an individual cookie echo $_COOKIE["TestCookie"]; echo $HTTP_COOKIE_VARS["TestCookie"]; // Another way to debug/test is to view all cookies print_r($_COOKIE); ?> |
¼ôáí äéáãñÜöåôå Ýíá cookie ðñÝðåé íá åëÝã÷åôå üôé ç çìåñïìçíßá ëÞîçò áíÞêåé óôï ðáñåëèüí, êáé ôüôå íá åíåñãïðïéåßôáé ôï ìç÷áíéóìü äéáãñáöÞò óôïí browser óáò. Áêïëïõèïýí ðáñáäåßãìáôá ó÷åôéêÜ ìå ôïí ðþò íá äéáöñÜøåôå ôá cookies ðïõ óôÜëèçêáí óôïí ðñïçãïýìåíï ðáñÜäåéãìá:
Ìðïñåßôå åðßóçò íá ïñßóåôå array cookies ÷ñçóéìïðïéþíôáò ìéá óçìåßùóç ðßíáêá (array notation) óôï üíïìá ôïõ cookie. Áõôü Ý÷åé ùò áðïôÝëåóìá íá ìðïñïýìå íá ïñßóïõìå üóá cookies èÝëïõìå áñêåß íá Ý÷ïõìå óôïé÷åßá óôïí ðßíáêá, áëëÜ üôáí ôï cookie ëáìâÜíåôáé áðü ôï script, ïé ôéìÝò ôïðïèåôïýíôáé üëåò óå Ýíáí array ìå ôï üíïìá ôïõ cookie:
ÐáñÜäåéãìá 3. Ç setcookie() êáé ïé ðßíáêåò
|
Óçìåßùóç: Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò óôá cookies, äåßôå ôï cookie specification ôçò Netscape's óôï http://www.netscape.com/newsref/std/cookie_spec.html êáé ôï RFC 2965.
ºóùò ðáñáôçñÞóåôå üôé ç ðáñÜìåôñïò expire ðáßñíåé Ýíá unix timestamp, óå áíôßèåóç ìå ôï date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, áõôü óõìâáßíåé åðåéäÞ ç PHP åêôåëåß áõôÞ ôç ìåôáôñïðÞ åóùôåñéêÜ.
Óçìåßùóç: Ï Microsoft Internet Explorer 4 ìå ôï Service Pack 1 äåí ÷åéñßæåôáé óùóôÜ ôá cookies óôá ïðïßá Ý÷åé ïñéóôåß ç ðáñÜìåôñïò path.
Ïé Netscape Communicator 4.05 êáé Microsoft Internet Explorer 3.x ÷åéñßæïíôáé ôá cookies ìå ìç ïñèü ôñüðï üôáí ôï path êáé ç þñá äåí Ý÷ïõí ïñéóôåß.
setrawcookie() is exactly the same as setcookie() except that the cookie value will not automaticall be urlencoded when send to the browser.
See also header(), setcookie() and the cookies section.
Hyperwave has been developed at IICM in Graz. It started with the name Hyper-G and changed to Hyperwave when it was commercialised (in 1996).
Hyperwave is not free software. The current version, 5.5 is available at http://www.hyperwave.com/. A time limited version can be ordered for free (30 days).
See also the Hyperwave API module.
Hyperwave is an information system similar to a database (HIS, Hyperwave Information Server). Its focus is the storage and management of documents. A document can be any possible piece of data that may as well be stored in file. Each document is accompanied by its object record. The object record contains meta data for the document. The meta data is a list of attributes which can be extended by the user. Certain attributes are always set by the Hyperwave server, other may be modified by the user. An attribute is a name/value pair of the form name=value. The complete object record contains as many of those pairs as the user likes. The name of an attribute does not have to be unique, e.g. a title may appear several times within an object record. This makes sense if you want to specify a title in several languages. In such a case there is a convention, that each title value is preceded by the two letter language abbreviation followed by a colon, e.g. 'en:Title in English' or 'ge:Titel in deutsch'. Other attributes like a description or keywords are potential candidates. You may also replace the language abbreviation by any other string as long as it separated by colon from the rest of the attribute value.
Each object record has native a string representation with each name/value pair separated by a newline. The Hyperwave extension also knows a second representation which is an associated array with the attribute name being the key. Multilingual attribute values itself form another associated array with the key being the language abbreviation. Actually any multiple attribute forms an associated array with the string left to the colon in the attribute value being the key. (This is not fully implemented. Only the attributes Title, Description and Keyword are treated properly yet.)
Besides the documents, all hyper links contained in a document are stored as object records as well. Hyper links which are in a document will be removed from it and stored as individual objects, when the document is inserted into the database. The object record of the link contains information about where it starts and where it ends. In order to gain the original document you will have to retrieve the plain document without the links and the list of links and reinsert them. The functions hw_pipedocument() and hw_gettext() do this for you. The advantage of separating links from the document is obvious. Once a document to which a link is pointing to changes its name, the link can easily be modified accordingly. The document containing the link is not affected at all. You may even add a link to a document without modifying the document itself.
Saying that hw_pipedocument() and hw_gettext() do the link insertion automatically is not as simple as it sounds. Inserting links implies a certain hierarchy of the documents. On a web server this is given by the file system, but Hyperwave has its own hierarchy and names do not reflect the position of an object in that hierarchy. Therefore creation of links first of all requires a mapping from the Hyperwave hierarchy and namespace into a web hierarchy respective web namespace. The fundamental difference between Hyperwave and the web is the clear distinction between names and hierarchy in Hyperwave. The name does not contain any information about the objects position in the hierarchy. In the web the name also contains the information on where the object is located in the hierarchy. This leads to two possibles ways of mapping. Either the Hyperwave hierarchy and name of the Hyperwave object is reflected in the URL or the name only. To make things simple the second approach is used. Hyperwave object with name my_object is mapped to http://host/my_object disregarding where it resides in the Hyperwave hierarchy. An object with name parent/my_object could be the child of my_object in the Hyperwave hierarchy, though in a web namespace it appears to be just the opposite and the user might get confused. This can only be prevented by selecting reasonable object names.
Having made this decision a second problem arises. How do you involve PHP? The URL http://host/my_object will not call any PHP script unless you tell your web server to rewrite it to e.g. http://host/php_script/my_object and the script php_script evaluates the $PATH_INFO variable and retrieves the object with name my_object from the Hyperwave server. Their is just one little drawback which can be fixed easily. Rewriting any URL would not allow any access to other document on the web server. A PHP script for searching in the Hyperwave server would be impossible. Therefore you will need at least a second rewriting rule to exclude certain URLs like all e.g. starting with http://host/Hyperwave This is basically sharing of a namespace by the web and Hyperwave server.
Based on the above mechanism links are insert into documents.
It gets more complicated if PHP is not run as a server module or CGI script but as a standalone application e.g. to dump the content of the Hyperwave server on a CD-ROM. In such a case it makes sense to retain the Hyperwave hierarchy and map in onto the file system. This conflicts with the object names if they reflect its own hierarchy (e.g. by choosing names including '/'). Therefore '/' has to be replaced by another character, e.g. '_'.
The network protocol to communicate with the Hyperwave server is called HG-CSP (Hyper-G Client/Server Protocol). It is based on messages to initiate certain actions, e.g. get object record. In early versions of the Hyperwave Server two native clients (Harmony, Amadeus) were provided for communication with the server. Those two disappeared when Hyperwave was commercialised. As a replacement a so called wavemaster was provided. The wavemaster is like a protocol converter from HTTP to HG-CSP. The idea is to do all the administration of the database and visualisation of documents by a web interface. The wavemaster implements a set of placeholders for certain actions to customise the interface. This set of placeholders is called the PLACE Language. PLACE lacks a lot of features of a real programming language and any extension to it only enlarges the list of placeholders. This has led to the use of JavaScript which IMO does not make life easier.
Adding Hyperwave support to PHP should fill in the gap of a missing programming language for interface customisation. It implements all the messages as defined by the HG-CSP but also provides more powerful commands to e.g. retrieve complete documents.
Hyperwave has its own terminology to name certain pieces of information. This has widely been taken over and extended. Almost all functions operate on one of the following data types.
object ID: An unique integer value for each object in the Hyperwave server. It is also one of the attributes of the object record (ObjectID). Object ids are often used as an input parameter to specify an object.
object record: A string with attribute-value pairs of the form attribute=value. The pairs are separated by a carriage return from each other. An object record can easily be converted into an object array with hw_object2array(). Several functions return object records. The names of those functions end with obj.
object array: An associative array with all attributes of an object. The keys are the attribute names. If an attribute occurs more than once in an object record it will result in another indexed or associative array. Attributes which are language depended (like the title, keyword, description) will form an associative array with the keys set to the language abbreviations. All other multiple attributes will form an indexed array. PHP functions never return object arrays.
hw_document: This is a complete new data type which holds the actual document, e.g. HTML, PDF etc. It is somewhat optimized for HTML documents but may be used for any format.
Several functions which return an array of object records do also return an associative array with statistical information about them. The array is the last element of the object record array. The statistical array contains the following entries:
Number of object records with attribute PresentationHints set to Hidden.
Number of object records with attribute PresentationHints set to CollectionHead.
Number of object records with attribute PresentationHints set to FullCollectionHead.
Index in array of object records with attribute PresentationHints set to CollectionHead.
Index in array of object records with attribute PresentationHints set to FullCollectionHead.
Total: Number of object records.
The Hyperwave extension is best used when PHP is compiled as an Apache module. In such a case the underlying Hyperwave server can be hidden from users almost completely if Apache uses its rewriting engine. The following instructions will explain this.
Since PHP with Hyperwave support built into Apache is intended to replace the native Hyperwave solution based on Wavemaster, we will assume that the Apache server will only serve as a Hyperwave web interface for these examples. This is not necessary but it simplifies the configuration. The concept is quite simple. First of all you need a PHP script which evaluates the $_ENV['PATH_INFO'] variable and treats its value as the name of a Hyperwave object. Let's call this script 'Hyperwave'. The URL http://your.hostname/Hyperwave/name_of_object would than return the Hyperwave object with the name 'name_of_object'. Depending on the type of the object the script has to react accordingly. If it is a collection, it will probably return a list of children. If it is a document it will return the mime type and the content. A slight improvement can be achieved if the Apache rewriting engine is used. From the users point of view it would be more straight forward if the URL http://your.hostname/name_of_object would return the object. The rewriting rule is quite easy:
Now every URL relates to an object in the Hyperwave server. This causes a simple to solve problem. There is no way to execute a different script, e.g. for searching, than the 'Hyperwave' script. This can be fixed with another rewriting rule like the following: This will reserve the directory /usr/local/apache/htdocs/hw for additional scripts and other files. Just make sure this rule is evaluated before the one above. There is just a little drawback: all Hyperwave objects whose name starts with 'hw/' will be shadowed. So, make sure you don't use such names. If you need more directories, e.g. for images just add more rules or place them all in one directory. Before you put those instructions, don't forget to turn on the rewriting engine with You will need scripts:to return the object itself
to allow searching
to identify yourself
to set your profile
one for each additional function like to show the object attributes, to show information about users, to show the status of the server, etc.
As an alternative to the Rewrite Engine, you can also consider using the Apache ErrorDocument directive, but be aware, that ErrorDocument redirected pages cannot receive POST data.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Hyperwave configuration options
Name | Default | Changeable |
---|---|---|
hyperwave.allow_persistent | "0" | PHP_INI_SYSTEM |
hyperwave.default_port | "418" | PHP_INI_ALL |
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
There are still some things to do:
The hw_InsertDocument has to be split into hw_insertobject() and hw_putdocument().
The names of several functions are not fixed, yet.
Most functions require the current connection as its first parameter. This leads to a lot of typing, which is quite often not necessary if there is just one open connection. A default connection will improve this.
Conversion form object record into object array needs to handle any multiple attribute.
Converts an object_array into an object record. Multiple attributes like 'Title' in different languages are treated properly.
See also hw_objrec2array().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns an array of object ids. Each id belongs to a child of the collection with ID objectID. The array contains all children both documents and collections.
Returns an array of object records. Each object record belongs to a child of the collection with ID objectID. The array contains all children both documents and collections.
Returns FALSE if connection is not a valid connection index, otherwise TRUE. Closes down the connection to a Hyperwave server with the given connection index.
Opens a connection to a Hyperwave server and returns a connection index on success, or FALSE if the connection could not be made. Each of the arguments should be a quoted string, except for the port number. The username and password arguments are optional and can be left out. In such a case no identification with the server will be done. It is similar to identify as user anonymous. This function returns a connection index that is needed by other Hyperwave functions. You can have multiple connections open at once. Keep in mind, that the password is not encrypted.
See also hw_pconnect().
(PHP 3>= 3.0.3, PHP 4 )
hw_connection_info -- Prints information about the connection to Hyperwave server
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Copies the objects with object ids as specified in the second parameter to the collection with the id destination id.
The value return is the number of copied objects.
See also hw_mv().
Deletes the object with the given object id in the second parameter. It will delete all instances of the object.
Returns TRUE if no error occurs otherwise FALSE.
See also hw_mv().
Returns an th object id of the document to which anchorID belongs.
Returns an th object record of the document to which anchorID belongs.
Returns the object record of the document.
For backward compatibility, hw_documentattributes() is also accepted. This is deprecated, however.
See also hw_document_bodytag(), and hw_document_size().
Returns the BODY tag of the document. If the document is an HTML document the BODY tag should be printed before the document.
See also hw_document_attributes(), and hw_document_size().
For backward compatibility, hw_documentbodytag() is also accepted. This is deprecated, however.
Returns the content of the document. If the document is an HTML document the content is everything after the BODY tag. Information from the HEAD and BODY tag is in the stored in the object record.
See also hw_document_attributes(), hw_document_size(), and hw_document_setcontent().
Sets or replaces the content of the document. If the document is an HTML document the content is everything after the BODY tag. Information from the HEAD and BODY tag is in the stored in the object record. If you provide this information in the content of the document too, the Hyperwave server will change the object record accordingly when the document is inserted. Probably not a very good idea. If this functions fails the document will retain its old content.
See also hw_document_attributes(), hw_document_size(), and hw_document_content().
Returns the size in bytes of the document.
See also hw_document_bodytag(), and hw_document_attributes().
For backward compatibility, hw_documentsize() is also accepted. This is deprecated, however.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Uploads the text document to the server. The object record of the document may not be modified while the document is edited. This function will only works for pure text documents. It will not open a special data connection and therefore blocks the control connection during the transfer.
See also hw_pipedocument(), hw_free_document(), hw_document_bodytag(), hw_document_size(), hw_output_document(), and hw_gettext().
Returns the last error number. If the return value is 0 no error has occurred. The error relates to the last command.
Returns a string containing the last error message or 'No Error'. If FALSE is returned, this function failed. The message relates to the last command.
Frees the memory occupied by the Hyperwave document.
Returns an array of object ids with anchors of the document with object ID objectID.
Returns an array of object records with anchors of the document with object ID objectID.
Returns the object record for the object with ID objectID. It will also lock the object, so other users cannot access it until it is unlocked.
See also hw_unlock(), and hw_getobject().
Returns an array of object ids. Each object ID belongs to a child collection of the collection with ID objectID. The function will not return child documents.
See also hw_children(), and hw_getchilddoccoll().
Returns an array of object records. Each object records belongs to a child collection of the collection with ID objectID. The function will not return child documents.
See also hw_childrenobj(), and hw_getchilddoccollobj().
Returns array of object ids for child documents of a collection.
See also hw_children(), and hw_getchildcoll().
Returns an array of object records for child documents of a collection.
See also hw_childrenobj(), and hw_getchildcollobj().
Returns the object record for the object with ID objectID if the second parameter is an integer. If the second parameter is an array of integer the function will return an array of object records. In such a case the last parameter is also evaluated which is a query string.
The query string has the following syntax:
<expr> ::= "(" <expr> ")" |
"!" <expr> | /* NOT */
<expr> "||" <expr> | /* OR */
<expr> "&&" <expr> | /* AND */
<attribute> <operator> <value>
<attribute> ::= /* any attribute name (Title, Author, DocumentType ...) */
<operator> ::= "=" | /* equal */
"<" | /* less than (string compare) */
">" | /* greater than (string compare) */
"~" /* regular expression matching */
The query allows to further select certain objects from the list of given objects. Unlike the other query functions, this query may use not indexed attributes. How many object records are returned depends on the query and if access to the object is allowed.
See also hw_getandlock(), and hw_getobjectbyquery().
Searches for objects on the whole server and returns an array of object ids. The maximum number of matches is limited to max_hits. If max_hits is set to -1 the maximum number of matches is unlimited.
The query will only work with indexed attributes.
See also hw_getobjectbyqueryobj().
Searches for objects in collection with ID objectID and returns an array of object ids. The maximum number of matches is limited to max_hits. If max_hits is set to -1 the maximum number of matches is unlimited.
The query will only work with indexed attributes.
See also hw_getobjectbyquerycollobj().
Searches for objects in collection with ID objectID and returns an array of object records. The maximum number of matches is limited to max_hits. If max_hits is set to -1 the maximum number of matches is unlimited.
The query will only work with indexed attributes.
See also hw_getobjectbyquerycoll().
Searches for objects on the whole server and returns an array of object records. The maximum number of matches is limited to max_hits. If max_hits is set to -1 the maximum number of matches is unlimited.
The query will only work with indexed attributes.
See also hw_getobjectbyquery().
Returns an indexed array of object ids. Each object id belongs to a parent of the object with ID objectID.
Returns an indexed array of object records plus an associated array with statistical information about the object records. The associated array is the last entry of the returned array. Each object record belongs to a parent of the object with ID objectID.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns a remote document. Remote documents in Hyperwave notation are documents retrieved from an external source. Common remote documents are for example external web pages or queries in a database. In order to be able to access external sources through remote documents Hyperwave introduces the HGI (Hyperwave Gateway Interface) which is similar to the CGI. Currently, only ftp, http-servers and some databases can be accessed by the HGI. Calling hw_getremote() returns the document from the external source. If you want to use this function you should be very familiar with HGIs. You should also consider to use PHP instead of Hyperwave to access external sources. Adding database support by a Hyperwave gateway should be more difficult than doing it in PHP.
See also hw_getremotechildren().
Returns the children of a remote document. Children of a remote document are remote documents itself. This makes sense if a database query has to be narrowed and is explained in Hyperwave Programmers' Guide. If the number of children is 1 the function will return the document itself formated by the Hyperwave Gateway Interface (HGI). If the number of children is greater than 1 it will return an array of object record with each maybe the input value for another call to hw_getremotechildren(). Those object records are virtual and do not exist in the Hyperwave server, therefore they do not have a valid object ID. How exactly such an object record looks like is up to the HGI. If you want to use this function you should be very familiar with HGIs. You should also consider to use PHP instead of Hyperwave to access external sources. Adding database support by a Hyperwave gateway should be more difficult than doing it in PHP.
See also hw_getremote().
Returns the object records of all anchors pointing to the object with ID objectID. The object can either be a document or an anchor of type destination.
See also hw_getanchors().
Returns the document with object ID objectID. If the document has anchors which can be inserted, they will be inserted already. The optional parameter rootID/prefix can be a string or an integer. If it is an integer it determines how links are inserted into the document. The default is 0 and will result in links that are constructed from the name of the link's destination object. This is useful for web applications. If a link points to an object with name 'internet_movie' the HTML link will be <A HREF="/internet_movie">. The actual location of the source and destination object in the document hierarchy is disregarded. You will have to set up your web browser, to rewrite that URL to for example '/my_script.php3/internet_movie'. 'my_script.php3' will have to evaluate $PATH_INFO and retrieve the document. All links will have the prefix '/my_script.php3/'. If you do not want this you can set the optional parameter rootID/prefix to any prefix which is used instead. Is this case it has to be a string.
If rootID/prefix is an integer and unequal to 0 the link is constructed from all the names starting at the object with the id rootID/prefix separated by a slash relative to the current object. If for example the above document 'internet_movie' is located at 'a-b-c-internet_movie' with '-' being the separator between hierarchy levels on the Hyperwave server and the source document is located at 'a-b-d-source' the resulting HTML link would be: <A HREF="../c/internet_movie">. This is useful if you want to download the whole server content onto disk and map the document hierarchy onto the file system.
This function will only work for pure text documents. It will not open a special data connection and therefore blocks the control connection during the transfer.
See also hw_pipedocument(), hw_free_document(), hw_document_bodytag(), hw_document_size(), and hw_output_document().
Identifies as user with username and password. Identification is only valid for the current session. I do not thing this function will be needed very often. In most cases it will be easier to identify with the opening of the connection.
See also hw_connect().
Checks whether a set of objects (documents or collections) specified by the object_id_array is part of the collections listed in collection_id_array. When the fourth parameter return_collections is 0, the subset of object ids that is part of the collections (i.e., the documents or collections that are children of one or more collections of collection ids or their subcollections, recursively) is returned as an array. When the fourth parameter is 1, however, the set of collections that have one or more objects of this subset as children are returned as an array. This option allows a client to, e.g., highlight the part of the collection hierarchy that contains the matches of a previous query, in a graphical overview.
Returns information about the current connection. The returned string has the following format: <Serverstring>, <Host>, <Port>, <Username>, <Port of Client>, <Byte swapping>
Inserts a new collection with attributes as in object_array into collection with object ID objectID.
Inserts a new document with attributes as in object_record into collection with object ID parentID. This function inserts either an object record only or an object record and a pure ascii text in text if text is given. If you want to insert a general document of any kind use hw_insertdocument() instead.
See also hw_insertdocument(), and hw_inscoll().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Uploads a document into the collection with parent_id. The document has to be created before with hw_new_document(). Make sure that the object record of the new document contains at least the attributes: Type, DocumentType, Title and Name. Possibly you also want to set the MimeType. The functions returns the object id of the new document or FALSE.
See also hw_pipedocument().
Inserts an object into the server. The object can be any valid hyperwave object. See the HG-CSP documentation for a detailed information on how the parameters have to be.
Note: If you want to insert an Anchor, the attribute Position has always been set either to a start/end value or to 'invisible'. Invisible positions are needed if the annotation has no corresponding link in the annotation text.
See also hw_pipedocument(), hw_insertdocument(), hw_insdoc(), and hw_inscoll().
Maps a global object id on any hyperwave server, even those you did not connect to with hw_connect(), onto a virtual object id. This virtual object id can then be used as any other object id, e.g. to obtain the object record with hw_getobject(). The server id is the first part of the global object id (GOid) of the object which is actually the IP number as an integer.
Note: In order to use this function you will have to set the F_DISTRIBUTED flag, which can currently only be set at compile time in hg_comm.c. It is not set by default. Read the comment at the beginning of hg_comm.c
This command allows to remove, add, or modify individual attributes of an object record. The object is specified by the Object ID object_to_change. The first array remove is a list of attributes to remove. The second array add is a list of attributes to add. In order to modify an attribute one will have to remove the old one and add a new one. hw_modifyobject() will always remove the attributes before it adds attributes unless the value of the attribute to remove is not a string or array.
The last parameter determines if the modification is performed recursively. 1 means recursive modification. If some of the objects cannot be modified they will be skipped without notice. hw_error() may not indicate an error though some of the objects could not be modified.
The keys of both arrays are the attributes name. The value of each array element can either be an array, a string or anything else. If it is an array each attribute value is constructed by the key of each element plus a colon and the value of each element. If it is a string it is taken as the attribute value. An empty string will result in a complete removal of that attribute. If the value is neither a string nor an array but something else, e.g. an integer, no operation at all will be performed on the attribute. This is necessary if you want to to add a completely new attribute not just a new value for an existing attribute. If the remove array contained an empty string for that attribute, the attribute would be tried to be removed which would fail since it doesn't exist. The following addition of a new value for that attribute would also fail. Setting the value for that attribute to e.g. 0 would not even try to remove it and the addition will work.
If you would like to change the attribute 'Name' with the current value 'books' into 'articles' you will have to create two arrays and call hw_modifyobject().
Óçìåßùóç: Multilingual attributes, e.g. 'Title', can be modified in two ways. Either by providing the attributes value in its native form 'language':'title' or by providing an array with elements for each language as described above. The above example would than be:
Óçìåßùóç: This will remove all attributes with the name 'Title' and adds a new 'Title' attribute. This comes in handy if you want to remove attributes recursively.
Óçìåßùóç: If you need to delete all attributes with a certain name you will have to pass an empty string as the attribute value.
Óçìåßùóç: Only the attributes 'Title', 'Description' and 'Keyword' will properly handle the language prefix. If those attributes don't carry a language prefix, the prefix 'xx' will be assigned.
Óçìåßùóç: The 'Name' attribute is somewhat special. In some cases it cannot be complete removed. You will get an error message 'Change of base attribute' (not clear when this happens). Therefore you will always have to add a new Name first and than remove the old one.
Óçìåßùóç: You may not surround this function by calls to hw_getandlock() and hw_unlock(). hw_modifyobject() does this internally.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Moves the objects with object ids as specified in the second parameter from the collection with id source_id to the collection with the id destination_id. If the destination id is 0 the objects will be unlinked from the source collection. If this is the last instance of that object it will be deleted. If you want to delete all instances at once, use hw_deleteobject().
The value returned is the number of moved objects.
See also hw_cp(), and hw_deleteobject().
Returns a new Hyperwave document with document data set to document_data and object record set to object_record. The length of the document_data has to passed in document_sizeThis function does not insert the document into the Hyperwave server.
See also hw_free_document(), hw_document_size(), hw_document_bodytag(), hw_output_document(), and hw_insertdocument().
Converts an object_record into an object array. The keys of the resulting array are the attributes names. Multi-value attributes like 'Title' in different languages form its own array. The keys of this array are the left part to the colon of the attribute value. This left part must be two characters long. Other multi-value attributes without a prefix form an indexed array. If the optional parameter is missing the attributes 'Title', 'Description' and 'Keyword' are treated as language attributes and the attributes 'Group', 'Parent' and 'HtmlAttr' as non-prefixed multi-value attributes. By passing an array holding the type for each attribute you can alter this behaviour. The array is an associated array with the attribute name as its key and the value being one of HW_ATTR_LANG or HW_ATTR_NONE.
See also hw_array2objrec().
Prints the document without the BODY tag.
For backward compatibility, hw_outputdocument() is also accepted. This is deprecated, however.
Returns a connection index on success, or FALSE if the connection could not be made. Opens a persistent connection to a Hyperwave server. Each of the arguments should be a quoted string, except for the port number. The username and password arguments are optional and can be left out. In such a case no identification with the server will be done. It is similar to identify as user anonymous. This function returns a connection index that is needed by other Hyperwave functions. You can have multiple persistent connections open at once.
See also hw_connect().
Returns the Hyperwave document with object ID objectID. If the document has anchors which can be inserted, they will have been inserted already. The document will be transferred via a special data connection which does not block the control connection.
See also hw_gettext() for more on link insertion, hw_free_document(), hw_document_size(), hw_document_bodytag(), and hw_output_document().
Returns the object ID of the hyperroot collection. Currently this is always 0. The child collection of the hyperroot is the root collection of the connected server.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Unlocks a document, so other users regain access.
See also hw_getandlock().
Returns an array of users currently logged into the Hyperwave server. Each entry in this array is an array itself containing the elements id, name, system, onSinceDate, onSinceTime, TotalTime and self. 'self' is 1 if this entry belongs to the user who initiated the request.
Hyperwave has been developed at IICM in Graz. It started with the name Hyper-G and changed to Hyperwave when it was commercialised (in 1996).
Hyperwave is not free software. The current version, 5.5, is available at http://www.hyperwave.com/. A time limited version can be ordered for free (30 days).
See also the Hyperwave module.
Hyperwave is an information system similar to a database (HIS, Hyperwave Information Server). Its focus is the storage and management of documents. A document can be any possible piece of data that may as well be stored in file. Each document is accompanied by its object record. The object record contains meta data for the document. The meta data is a list of attributes which can be extended by the user. Certain attributes are always set by the Hyperwave server, other may be modified by the user.
Since 2001 there is a Hyperwave SDK available. It supports Java, JavaScript and C++. This PHP Extension is based on the C++ interface. In order to activate the hwapi support in PHP you will have to install the Hyperwave SDK first.
The integration with Apache and possible other servers is already described in the Hyperwave module which has been the first extension to connect a Hyperwave Server.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Hyperwave API configuration options
Name | Default | Changeable |
---|---|---|
hwapi.allow_persistent | "0" | PHP_INI_SYSTEM |
The API provided by the HW_API extension is fully object oriented. It is very similar to the C++ interface of the Hyperwave SDK. It consist of the following classes.
HW_API
HW_API_Object
HW_API_Attribute
HW_API_Error
HW_API_Content
HW_API_Reason
Each class has certain method, whose names are identical to its counterparts in the Hyperwave SDK. Passing arguments to this function differs from all the other PHP extensions but is close to the C++ API of the HW SDK. Instead of passing several parameters they are all put into an associated array and passed as one parameter. The names of the keys are identical to those documented in the HW SDK. The common parameters are listed below. If other parameters are required they will be documented if needed.
objectIdentifier The name or id of an object, e.g. "rootcollection", "0x873A8768 0x00000002".
parentIdentifier The name or id of an object which is considered to be a parent.
object An instance of class HW_API_Object.
parameters An instance of class HW_API_Object.
version The version of an object.
mode An integer value determine the way an operation is executed.
attributeSelector Any array of strings, each containing a name of an attribute. This is used if you retrieve the object record and want to include certain attributes.
objectQuery A query to select certain object out of a list of objects. This is used to reduce the number of objects which was delivered by a function like hw_api->children() or hw_api->find().
(no version information, might be only in CVS)
hw_api_attribute->langdepvalue -- Returns value for a given languageReturns the value in the given language of the attribute.
See also hwapi_attribute_value().
(no version information, might be only in CVS)
hw_api_attribute->value -- Returns value of the attributeReturns the value of the attribute.
See also hwapi_attribute_key(), hwapi_attribute_values().
(no version information, might be only in CVS)
hw_api_attribute->values -- Returns all values of the attributeReturns all values of the attribute as an array of strings.
See also hwapi_attribute_value().
(no version information, might be only in CVS)
hw_api_attribute -- Creates instance of class hw_api_attributeCreates a new instance of hw_api_attribute with the given name and value.
This function checks in an object or a whole hiearchie of objects. The parameters array contains the required element 'objectIdentifier' and the optional element 'version', 'comment', 'mode' and 'objectQuery'. 'version' sets the version of the object. It consists of the major and minor version separated by a period. If the version is not set, the minor version is incremented. 'mode' can be one of the following values:
Checks in and commits the object. The object must be a document.
If the object to check in is a collection, all children will be checked in recursively if they are documents. Trying to check in a collection would result in an error.
Checks in an object even if it is not under version control.
Check if the new version is different from the last version. Unless this is the case the object will be checked in.
Keeps the time modified from the most recent object.
The object is not automatically committed on check-in.
See also hwapi_checkout().
This function checks out an object or a whole hiearchie of objects. The parameters array contains the required element 'objectIdentifier' and the optional element 'version', 'mode' and 'objectQuery'. 'mode' can be one of the following values:
Checks out an object. The object must be a document.
If the object to check out is a collection, all children will be checked out recursively if they are documents. Trying to check out a collection would result in an error.
See also hwapi_checkin().
Retrieves the children of a collection or the attributes of a document. The children can be further filtered by specifying an object query. The parameter array contains the required elements 'objectIdentifier' and the optional elements 'attributeSelector' and 'objectQuery'.
The return value is an array of objects of type HW_API_Object or HW_API_Error.
See also hwapi_parents().
Reads len bytes from the content into the given buffer.
This function returns the content of a document as an object of type hw_api_content. The parameter array contains the required elements 'objectidentifier' and the optional element 'mode'. The mode can be one of the constants HW_API_CONTENT_ALLLINKS, HW_API_CONTENT_REACHABLELINKS or HW_API_CONTENT_PLAIN. HW_API_CONTENT_ALLLINKS means to insert all anchors even if the destination is not reachable. HW_API_CONTENT_REACHABLELINKS tells hw_api_content() to insert only reachable links and HW_API_CONTENT_PLAIN will lead to document without any links.
This function will make a physical copy including the content if it exists and returns the new object or an error object. The parameter array contains the required elements 'objectIdentifier' and 'destinationParentIdentifier'. The optional parameter is 'attributeSelector'`
See also hwapi_move(), hwapi_link().
(no version information, might be only in CVS)
hw_api->dbstat -- Returns statistics about database server
See also hwapi_dcstat(), hwapi_hwstat(), hwapi_ftstat().
(no version information, might be only in CVS)
hw_api->dcstat -- Returns statistics about document cache server
See also hwapi_hwstat(), hwapi_dbstat(), hwapi_ftstat().
(no version information, might be only in CVS)
hw_api->dstanchors -- Returns a list of all destination anchorsRetrieves all destination anchors of an object. The parameter array contains the required element 'objectIdentifier' and the optional elements 'attributeSelector' and 'objectQuery'.
See also hwapi_srcanchors().
(no version information, might be only in CVS)
hw_api->dstofsrcanchors -- Returns destination of a source anchorRetrieves the destination object pointed by the specified source anchors. The destination object can either be a destination anchor or a whole document. The parameters array contains the required element 'objectIdentifier' and the optional element 'attributeSelector'.
See also hwapi_srcanchors(), hwapi_dstanchors(), hwapi_objectbyanchor().
This functions searches for objects either by executing a key or/and full text query. The found objects can further be filtered by an optional object query. They are sorted by their importance. The second search operation is relatively slow and its result can be limited to a certain number of hits. This allows to perform an incremental search, each returning just a subset of all found documents, starting at a given index. The parameter array contains the 'keyquery' or/and 'fulltextquery' depending on who you would like to search. Optional parameters are 'objectquery', 'scope', 'languages' and 'attributeselector'. In case of an incremental search the optional parameters 'startIndex', numberOfObjectsToGet' and 'exactMatchUnit' can be passed.
(no version information, might be only in CVS)
hw_api->ftstat -- Returns statistics about fulltext server
See also hwapi_dcstat(), hwapi_dbstat(), hwapi_hwstat().
Opens a connection to the Hyperwave server on host hostname. The protocol used is HGCSP. If you do not pass a port number, 418 is used.
See also hwapi_hwtp().
(no version information, might be only in CVS)
hw_api->hwstat -- Returns statistics about Hyperwave server
See also hwapi_dcstat(), hwapi_dbstat(), hwapi_ftstat().
Logs into the Hyperwave Server. The parameter array must contain the elements 'username' and 'password'.
The return value will be an object of type HW_API_Error if identification failed or TRUE if it was successful.
(no version information, might be only in CVS)
hw_api->info -- Returns information about server configuration
See also hwapi_dcstat(), hwapi_dbstat(), hwapi_ftstat(), hwapi_hwstat().
Insert a new object. The object type can be user, group, document or anchor. Depending on the type other object attributes has to be set. The parameter array contains the required elements 'object' and 'content' (if the object is a document) and the optional parameters 'parameters', 'mode' and 'attributeSelector'. The 'object' must contain all attributes of the object. 'parameters' is an object as well holding further attributes like the destination (attribute key is 'Parent'). 'content' is the content of the document. 'mode' can be a combination of the following flags:
The object in inserted into the server.
See also hwapi_replace().
(no version information, might be only in CVS)
hw_api->insertanchor -- Inserts a new object of type anchorThis function is a shortcut for hwapi_insert(). It inserts an object of type anchor and sets some of the attributes required for an anchor. The parameter array contains the required elements 'object' and 'documentIdentifier' and the optional elements 'destinationIdentifier', 'parameter', 'hint' and 'attributeSelector'. The 'documentIdentifier' specifies the document where the anchor shall be inserted. The target of the anchor is set in 'destinationIdentifier' if it already exists. If the target does not exists the element 'hint' has to be set to the name of object which is supposed to be inserted later. Once it is inserted the anchor target is resolved automatically.
See also hwapi_insertdocument(), hwapi_insertcollection(), hwapi_insert().
(no version information, might be only in CVS)
hw_api->insertcollection -- Inserts a new object of type collectionThis function is a shortcut for hwapi_insert(). It inserts an object of type collection and sets some of the attributes required for a collection. The parameter array contains the required elements 'object' and 'parentIdentifier' and the optional elements 'parameter' and 'attributeSelector'. See hwapi_insert() for the meaning of each element.
See also hwapi_insertdocument(), hwapi_insertanchor(), hwapi_insert().
(no version information, might be only in CVS)
hw_api->insertdocument -- Inserts a new object of type documentThis function is a shortcut for hwapi_insert(). It inserts an object with content and sets some of the attributes required for a document. The parameter array contains the required elements 'object', 'parentIdentifier' and 'content' and the optional elements 'mode', 'parameter' and 'attributeSelector'. See hwapi_insert() for the meaning of each element.
See also hwapi_insert() hwapi_insertanchor(), hwapi_insertcollection().
Creates a link to an object. Accessing this link is like accessing the object to links points to. The parameter array contains the required elements 'objectIdentifier' and 'destinationParentIdentifier'. 'destinationParentIdentifier' is the target collection.
The function returns TRUE on success or an error object.
See also hwapi_copy().
Locks an object for exclusive editing by the user calling this function. The object can be only unlocked by this user or the system user. The parameter array contains the required element 'objectIdentifier' and the optional parameters 'mode' and 'objectquery'. 'mode' determines how an object is locked. HW_API_LOCK_NORMAL means, an object is locked until it is unlocked. HW_API_LOCK_RECURSIVE is only valid for collection and locks all objects within the collection and possible subcollections. HW_API_LOCK_SESSION means, an object is locked only as long as the session is valid.
See also hwapi_unlock().
(no version information, might be only in CVS)
hw_api_content -- Create new instance of class hw_api_contentCreates a new content object from the string content. The mimetype is set to mimetype.
(no version information, might be only in CVS)
hw_api_object->attreditable -- Checks whether an attribute is editableAdds an attribute to the object. Returns TRUE on success and otherwise FALSE.
See also hwapi_object_remove().
(no version information, might be only in CVS)
hw_api_object -- Creates a new instance of class hw_api_objectRemoves the attribute with the given name. Returns TRUE on success and otherwise FALSE.
See also hwapi_object_insert().
Returns the value of the attribute with the given name or FALSE if an error occurred.
This function retrieves the attribute information of an object of any version. It will not return the document content. The parameter array contains the required elements 'objectIdentifier' and the optional elements 'attributeSelector' and 'version'.
The returned object is an instance of class HW_API_Object on success or HW_API_Error if an error occurred.
This simple example retrieves an object and checks for errors.
ÐáñÜäåéãìá 1. Retrieve an object
|
See also hwapi_content().
(no version information, might be only in CVS)
hw_api->objectbyanchor -- Returns the object an anchor belongs toThis function retrieves an object the specified anchor belongs to. The parameter array contains the required element 'objectIdentifier' and the optional element 'attributeSelector'.
See also hwapi_dstofsrcanchor(), hwapi_srcanchors(), hwapi_dstanchors().
Retrieves the parents of an object. The parents can be further filtered by specifying an object query. The parameter array contains the required elements 'objectidentifier' and the optional elements 'attributeselector' and 'objectquery'.
The return value is an array of objects of type HW_API_Object or HW_API_Error.
See also hwapi_children().
(no version information, might be only in CVS)
hw_api_reason->description -- Returns description of reasonRemoves an object from the specified parent. Collections will be removed recursively. You can pass an optional object query to remove only those objects which match the query. An object will be deleted physically if it is the last instance. The parameter array contains the required elements 'objectidentifier' and 'parentidentifier'. If you want to remove a user or group 'parentidentifier' can be skipped. The optional parameter 'mode' determines how the deletion is performed. In normal mode the object will not be removed physically until all instances are removed. In physical mode all instances of the object will be deleted immediately. In removelinks mode all references to and from the objects will be deleted as well. In nonrecursive the deletion is not performed recursive. Removing a collection which is not empty will cause an error.
See also hwapi_move().
Replaces the attributes and the content of an object The parameter array contains the required elements 'objectIdentifier' and 'object' and the optional parameters 'content', 'parameters', 'mode' and 'attributeSelector'. 'objectIdentifier' contains the object to be replaced. 'object' contains the new object. 'content' contains the new content. 'parameters' contain extra information for HTML documents. HTML_Language is the letter abbreviation of the language of the title. HTML_Base sets the base attribute of the HTML document. 'mode' can be a combination of the following flags:
The object on the server is replace with the object passed.
See also hwapi_insert().
(no version information, might be only in CVS)
hw_api->setcommitedversion -- Commits version other than last versionCommits a version of a document. The committed version is the one which is visible to users with read access. By default the last version is the committed version.
See also hwapi_checkin(), hwapi_checkout(), hwapi_revert().
(no version information, might be only in CVS)
hw_api->srcanchors -- Returns a list of all source anchorsRetrieves all source anchors of an object. The parameter array contains the required element 'objectIdentifier' and the optional elements 'attributeSelector' and 'objectQuery'.
See also hwapi_dstanchors().
(no version information, might be only in CVS)
hw_api->srcsofdst -- Returns source of a destination objectRetrieves all the source anchors pointing to the specified destination. The destination object can either be a destination anchor or a whole document. The parameters array contains the required element 'objectIdentifier' and the optional element 'attributeSelector' and 'objectQuery'. The function returns an array of objects or an error.
See also hwapi_dstofsrcanchor().
Unlocks a locked object. Only the user who has locked the object and the system user may unlock an object. The parameter array contains the required element 'objectIdentifier' and the optional parameters 'mode' and 'objectquery'. The meaning of 'mode' is the same as in function hwapi_lock().
Returns TRUE on success or an object of class HW_API_Error.
See also hwapi_lock().
This module contains an interface to iconv character set conversion facility. With this module, you can turn a string represented by a local character set into the one represented by another character set, which may be the Unicode charcter set. Supported character sets depend on the iconv implementation of your system. Note that the iconv function on some systems may not work as you expect. In such case, it'd be a good idea to install the GNU libiconv library. It will most likely end up with more consistent results.
Since PHP 5.0.0, this extension comes with various utility functions that help you to write multilingual scripts. Let's have a look at the following sections to explore the new features.
You will need nothing if the system you are using is one of the recent POSIX-compliant systems because standard C libraries that are supplied in them must provide iconv facility. Otherwise, you have to get the libiconv library installed in your system.
To use functions provided by this module, the PHP binary must be built with the following configure line: --with-iconv[=DIR].
Note to Windows® Users: In order to enable this module on a Windows® environment, you need to put a DLL file named iconv.dll or iconv-1.3.dll (prior to 4.2.1) which is bundled with the PHP/Win32 binary package into a directory specified by the PATH environment variable or one of the system directories of your Windows® installation.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Iconv configuration options
Name | Default | Changeable |
---|---|---|
iconv.input_encoding | ICONV_INPUT_ENCODING | PHP_INI_ALL |
iconv.output_encoding | ICONV_OUTPUT_ENCODING | PHP_INI_ALL |
iconv.internal_encoding | ICONV_INTERNAL_ENCODING | PHP_INI_ALL |
Since PHP 4.3.0 it is possible to identify at runtime which iconv implementation is adopted by this extension.
Ðßíáêáò 2. iconv constants
Name | Type | Description |
---|---|---|
ICONV_IMPL | string | The implementation name |
ICONV_VERSION | string | The implementation version |
Óçìåßùóç: Writing implementation-dependent scripts with these constants is strongly discouraged.
Since PHP 5.0.0, the following constants are also available:
Ðßíáêáò 3. iconv constants available since PHP 5.0.0
Name | Type | Description |
---|---|---|
ICONV_MIME_DECODE_STRICT | integer | A bitmask used for iconv_mime_decode() |
ICONV_MIME_DECODE_CONTINUE_ON_ERROR | integer | A bitmask used for iconv_mime_decode() |
(PHP 4 >= 4.0.5, PHP 5)
iconv_get_encoding -- Retrieve internal configuration variables of iconv extensioniconv_get_encoding() returns the current value of the internal configuration variable if successful, or FALSE on failure.
The value of the optional type can be:
all |
input_encoding |
output_encoding |
internal_encoding |
If type is omitted or set to "all", iconv_get_encoding() returns an array that stores all these variables.
ÐáñÜäåéãìá 1. iconv_get_encoding() example
The printout of the above program will be:
|
See also iconv_set_encoding() and ob_iconv_handler().
Returns an associative array that holds a whole set of MIME header fields specified by encoded_headers on success, or FALSE if an error occurs during the decoding.
Each key of the return value represents an individual field name and the corresponding element represents a field value. If more than one field of the same name are present, iconv_mime_decode_headers() automatically incorporates them into a numerically indexed array in the order of occurrence.
mode determines the behaviour in the event iconv_mime_decode_headers() encounters a malformed MIME header field. You can specify any combination of the following bitmasks.
Ðßíáêáò 1. Bitmasks acceptable to iconv_mime_decode_headers()
Value | Constant | Description |
---|---|---|
1 | ICONV_MIME_DECODE_STRICT | If set, the given header is decoded in full conformance with the standards defined in RFC2047. This option is disabled by default because there are a lot of broken mail user agents that don't follow the specification and don't produce correct MIME headers. |
2 | ICONV_MIME_DECODE_CONTINUE_ON_ERROR | If set, iconv_mime_decode_headers() attempts to ignore any grammatical errors and continue to process a given header. |
The optional charset parameter specifies the character set to represent the result by. If omitted, iconv.internal_charset will be used.
ÐáñÜäåéãìá 1. iconv_mime_decode_headers() example
The output of this script should look like:
|
See also iconv_mime_decode(), mb_decode_mimeheader(), imap_mime_header_decode(), imap_base64() and imap_qprint().
Returns a decoded MIME field on success, or FALSE if an error occurs during the decoding.
mode determines the behaviour in the event iconv_mime_decode() encounters a malformed MIME header field. You can specify any combination of the following bitmasks.
Ðßíáêáò 1. Bitmasks acceptable to iconv_mime_decode()
Value | Constant | Description |
---|---|---|
1 | ICONV_MIME_DECODE_STRICT | If set, the given header is decoded in full conformance with the standards defined in RFC2047. This option is disabled by default because there are a lot of broken mail user agents that don't follow the specification and don't produce correct MIME headers. |
2 | ICONV_MIME_DECODE_CONTINUE_ON_ERROR | If set, iconv_mime_decode() attempts to continue to process the given header even though an error occurs. |
The optional charset parameter specifies the character set to represent the result by. If omitted, iconv.internal_charset will be used.
See also iconv_mime_decode_headers(), mb_decode_mimeheader(), imap_mime_header_decode(), imap_base64() and imap_qprint().
Composes and returns a string that represents a valid MIME header field, which looks like the following:
Subject: =?ISO-8859-1?Q?Pr=FCfung_f=FCr?= Entwerfen von einer MIME kopfzeile |
You can control the behaviour of iconv_mime_encode() by specifying an associative array that contains configuration items to the optional third parameter preferences. The items supported by iconv_mime_encode() are listed below. Note that item names are treated case-sensitive.
Ðßíáêáò 1. Configuration items supported by iconv_mime_encode()
Item | Type | Description | Default value | Example |
---|---|---|---|---|
scheme | boolean | Specifies the method to encode a field value by. The value of this item may be either "B" or "Q", where "B" stands for base64 encoding scheme and "Q" stands for quoted-printable encoding scheme. | B | B |
input-charset | string | Specifies the character set in which the first parameter field_name and the second parameter field_value are presented. If not given, iconv_mime_encode() assumes those parameters are presented to it in the iconv.internal_charset ini setting. | iconv.internal_charset | ISO-8859-1 |
output-charset | string | Specifies the character set to use to compose the MIME header. If not given, the same value as input-charset will be used. | the same value as input-charset | UTF-8 |
line-length | integer | Specifies the maximum length of the header lines. The resulting header is "folded" to a set of multiple lines in case the resulting header field would be longer than the value of this parameter, according to RFC2822 - Internet Message Format. If not given, the length will be limited to 76 characters. | 76 | 996 |
line-break-chars | string | Specifies the sequence of characters to append to each line as an end-of-line sign when "folding" is performed on a long header field. If not given, this defaults to "\r\n" (CR LF). Note that this parameter is always treated as an ASCII string regardless of the value of input-charset. | \r\n | \n |
ÐáñÜäåéãìá 1. iconv_mime_encode() example:
|
See also imap_binary(), mb_encode_mimeheader() and imap_8bit().
iconv_set_encoding() changes the value of the internal configuration variable specified by type to charset. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The value of type can be any one of those:
input_encoding |
output_encoding |
internal_encoding |
See also iconv_get_encoding() and ob_iconv_handler().
Returns the character count of str.
In contrast to strlen(), iconv_strlen() counts the occurrences of characters in the given byte sequence str on the basis of the specified character set, the result of which is not necessarily identical to the length of the string in byte.
If charset parameter is omitted, str is assumed to be encoded in iconv.internal_charset.
See also strlen() and mb_strlen().
Returns the numeric position of the first occurrence of needle in haystack.
The optional offset parameter specifies the position from which the search should be performed.
If needle is not found, iconv_strpos() will return FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
If haystack or needle is not a string, it is converted to a string and applied as the ordinal value of a character.
In contrast to strpos(), the return value of iconv_strpos() is the number of characters that appear before the needle, rather than the offset in bytes to the position where the needle has been found. The characters are counted on the basis of the specified character set charset.
If charset parameter is omitted, string are assumed to be encoded in iconv.internal_charset.
See also strpos(), iconv_strrpos() and mb_strpos().
(PHP 5)
iconv_strrpos -- Finds the last occurrence of a needle within the specified range of haystack.Returns the numeric position of the last occurrence of needle in haystack.
If needle is not found, iconv_strrpos() will return FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
If haystack or needle is not a string, it is converted to a string and applied as the ordinal value of a character.
In contrast to strpos(), the return value of iconv_strrpos() is the number of characters that appear before the needle, rather than the offset in bytes to the position where the needle has been found. The characters are counted on the basis of the specified character set charset.
See also strrpos(), iconv_strpos() and mb_strrpos().
Returns the portion of str specified by the start and length parameters.
If start is non-negative, iconv_substr() cuts the portion out of str beginning at start'th character, counting from zero.
If start is negative, iconv_substr() cuts out the portion beginning at the position, start characters away from the end of str.
If length is given and is positive, the return value will contain at most length characters of the portion that begins at start (depending on the length of string). If str is shorter than start characters long, FALSE will be returned.
If negative length is passed, iconv_substr() cuts the portion out of str from the start'th character up to the character that is length characters away from the end of the string. In case start is also negative, the start position is calculated beforehand according to the rule explained above.
Note that offset and length parameters are always deemed to represent offsets that are calculated on the basis of the character set determined by charset, whilst the counterpart substr() always takes these for byte offsets. If charset is not given, the character set is determined by the iconv.internal_charset ini setting.
See also substr(), mb_substr() and mb_strcut().
Performs a character set conversion on the string str from in_charset to out_charset. Returns the converted string or FALSE on failure.
It converts the string encoded in internal_encoding to output_encoding.
internal_encoding and output_encoding should be defined by iconv_set_encoding() or in the configuration file php.ini.
See also iconv_get_encoding(), iconv_set_encoding() and output-control functions.
H PHP äåí ðåñéïñßæåôáé ìüíï óôç äçìéïõñãßá åíüò HTML output. Ìðïñåß åðßóçò íá ÷ñçóéìïðïéçèåß ãéá ôç äçìéïõñãßá êáé äéá÷åßñçóç áñ÷åßùí åéêüíáò ðïéêßëùí ôýðùí, óõìðåñéëáìâáíïìÝíùí ôùí gif, png, jpg, wbmp, êáé xpm. Áêüìá ðéï âïëéêü åßíáé ôï ãåãïíüò üôé ç PHP ìðïñåß íá óôåßëåé stream åéêüíùí êáôåõèåßáí óå Ýíáí browser. Èá ðñÝðåé íá êÜíåôå compile ôçí PHP ìå ôç âéâëéïèÞêç GD, ôùí óõíáñôÞóåùí åéêüíáò, ãéá íá ëåéôïõñãÞóåé ìå áõôüí ôùí ôñüðï. Ïé GD êáé PHP ìðïñåß íá ÷ñåéáóôïýí êáé Üëëåò âéâëéïèÞêåò, ðñÜãìá ðïõ åîáñôÜôáé áðü ôï ðïéïõò ôýðïõò åéêüíáò Ý÷åôáé åðéëÝîåé íá áó÷ïëçèåßôå.
Ìðïñåßôå íá ÷ñçóéìïðïéåßóåôå áõôÝò ôéò óõíáñôÞóåéò, óôçí PHP, ãéá íá ðÜñåôå ôï ìÝãåèïò ôùí JPEG, GIF, PNG, SWF, TIFF êáé JPEG2000 åéêüíùí.
Óçìåßùóç: ÄéáâÜóôå ôï ôìÞìá ðïõ áíáöÝñåôáé óôéò áðáéôÞóåéò, ãéá ðëçñïöïñßåò ó÷åôéêÜ ìå ôï ðþò ìðïñåßôå íá áõîÞóåôáé ôç äõíáôüôçôá áíÜãíùóçò, ãñáöÞò êáé ôñïðïðïßçóçò åéêüíùí, êáèþò åðßóçò êáé ôçò áíÜãíùóçò ôùí meta data ôùí åéêüíùí ðïõ ëáìâÜíïíôáé áðü øçöéáêÝò cameras.
ÅÜí Ý÷åôå ôç âéâëéïèÞêç GD (äéáèÝóéìç óôï http://www.boutell.com/gd/) èá åßóôå, åðßóçò, óå èÝóç íá äçìéïõñãåßóåôå êáé íá äéá÷åéñéóôåßôå åéêüíåò.
Ï ôýðïò ôùí åéêüíùí ðïõ ìðïñåßôå íá äéá÷åéñéóôåßôå, åîáñôÜôáé áðü ôçí Ýêäïóç ôçò GD ðïõ åßíáé åãêáôåóôçìÝíç, êáé áðü ïðïéáäÞðïôå Üëëç âéâëéïèÞêç ìðïñåß íá ÷ñåéóôåß ç GD ãéá íá ðñïóðåëÜóåé ôïí áðáéôïýìåíï ôýðï. Ïé ðáëéüôåñåò ôçò gd-1.6 åêäüóåéò ôçò GD, õðïóôçñßæïõí åéêüíåò ôýðïõ GIF, åíþ äåí õðïóôçñßæïõí ôéò PNG, åíþ ïé åêäüóåéò ìåôÜ ôçí gd-1.6 õðïóôçñßæïõí ôïí PNG ôýðï, áëëÜ ü÷é ôïí GIF.
Óçìåßùóç: Áðü ôçí Ýêäïóç 4.3 ôçò PHP õðÜñ÷åé ìáæß ìå ôï ðáêÝôï ìßá Ýêäïóç ôçò âéâëéïèÞêçò GD. ÁõôÞ Ý÷åé êÜðïéá åðéðëÝïí ÷áñáêôçñéóôéêÜ, üðùò ôï alpha blending êáé èá ðñÝðåé íá ÷ñçóéìïðïéåßôáé áõôÞ, êáôÜ ðñïôßìçóç, ìéáò êáé ç codebase ôçò åßíáé êáëýôåñá äéáôçñçìÝíç êáé ðéï óôáèåñÞ.
Ìðïñåß íá åðéèõìåßôå ôçí GD íá äéá÷åéñßæåôáé ðåñéóóüôåñïõò ôýðïõò åéêüíùí.
Ðßíáêáò 1. Õðïóôçñéæüìåíïé ôýðïé åéêüíùí
Ôýðïò åéêüíáò | ÂéâëéïèÞêç ðïõ ðñÝðåé íá êÜíåôå download | Óçìåéþóåéò |
---|---|---|
gif | Õðïóôçñßæåôáé óå åêäüóåéò ìåãáëýôåñåò ôçò gd-1.6. Read-only GIF õðïóôÞñéîç åßíáé äéáèÝóéìç óôçí Ýêäïóç 4.3.0 ôçò PHP 4.3.0 êáé ôç óõíçììÝíç GD âéâëéïèÞêç. | |
jpeg-6b | ftp://ftp.uu.net/graphics/jpeg/ | |
png | http://www.libpng.org/pub/png/libpng.html | Õðïóôçñßæåôáé óå åêäüóåéò ôçò GD ðïõ åßíáé ìåãáëýôåñåò ôçò gd-1.6. |
xpm | ftp://metalab.unc.edu/pub/Linux/libs/X/!INDEX.html | Åßíáé ðéèáíüí íá Ý÷åôå Þäç åãêáôåóôçìÝíç áõôÞ ôç âéâëéïèÞêç åÜí Ý÷åôå Ýíá X-Environment. |
Ìðïñåß íá åðéèõìåßôå ôçí GD íá ÷åéñßæåôáé äéÜöïñåò ãñáììáôïóåéñÝò. Áêïëïõèïýí ïé õðïóôçñéæüìåíåò âéâëéïèÞêåò ãñáììáôïóåéñþí:
Ðßíáêáò 2. Õðïóôçñéæüìåíåò âéâëéïèÞêåò ãñáììáôïóåéñþí
ÂéâëéïèÞêç ãñáììáôïóåéñþí | Download | Óçìåéþóåéò |
---|---|---|
FreeType 1.x | http://www.freetype.org/ | |
FreeType 2 | http://www.freetype.org/ | |
T1lib | ftp://sunsite.unc.edu/pub/Linux/libs/graphics/) | ÕðïóôÞñéêç ãéá Type 1 fonts. |
ÅÜí Ý÷åôáé êÜíåé compile ôçí PHP ìå --enable-exif åßóôå óå èÝóç íá åñãáóôåßôå ìå ôéò ðëçñïöïñßåò ðïõ âñßóêïíôáé óôá headers ôùí JPEG êáé TIFF åéêüíùí. Ìå áõôüí ôïí ôñüðï ìðïñåß íá ãßíåé áíÜãíùóç ôùí meta data, ðïõ üðùò áíáöÝñèçêå êáé ðïçãïõìÝíùò ðáñÜãïíôáé áðü ôéò øçöéáêÝò cameras. ÁõôÝò ïé óõíáñôÞóåéò äåí áðáéôïýí ôç âéâëéïèÞêç GD.
Óçìåßùóç: Ç PHP äåí áðáéôåß êÜðïéá åðéðëÝïí âéâëéïèÞêç ãéá ôï exif module.
Ãéá íá Ý÷åôå GD õðïóôÞñéîç, ðñÝðåé íá êÜíåôå configure ôçí PHP ìå ôçí åðéëïãÞ --with-gd[=DIR], üðïõ DIR åßíáé ôï üíïìá ôïõ êáôáëüãïõ åãêáôÜóôáóçò ôçò. Ãéá íá ÷ñçóéìïðïåßóåôå ôçí ðñïôéíüìåíç, óõíçììÝíç, Ýêäïóç ôçò GD âéâëéïèÞêçò (ðïõ ðñùôïâãÞêå ìå ôçí PHP 4.3.0), ÷ñçóéìïðïéåßóôå ôçí åðéëïãÞ --with-gd. Óôá Windows, èá ðñÝðåé íá óõìðåñéëÜâåôå ôï GD2 DLL php_gd2.dll ùò extension óôï php.ini. Ôï GD1 DLL php_gd.dll áöáéñÝèçêå óôçí Ýêäïóç 4.3.2 ôçò PHP. Åðßóçò ðñüóåîôå üôé ïé ðñïôéìüìåíåò truecolor image óõíáñôÞóåéò, üðùò åßíáé ç imagecreatetruecolor(), áðáéôïýí GD2.
Ãéá íá êÜíåôå disable ôçí GD õðïóôÞñéîç óôçí PHP 3, ðñïóèÝóôå ôçí åðéëïãÞ --without-gd óôï configure line óáò.
Ìðïñåßôå íá áõîÞóåôå ôéò äõíáôüôçôåò ôçò GD, þóôå íá ÷åéñßæåôáé ðåñéóóüôåñïõò ôýðïõò åéêüíùí, ìå ôï íá êáèïñßóåôå ôïí configure switch --with-XXXX, óôï PHP configure line óáò.
Ðßíáêáò 3. Õðïóôçñéæüìåíïé ôýðïé åéêüíáò
Ôýðïò åéêüíáò | Configure Switch |
---|---|
jpeg-6b | Ãéá íá áðïêôÞóåôå õðïóôÞñéîç ãéá ôïí jpeg-6b, ðñïóèÝóôå ôçí --with-jpeg-dir=DIR. |
png | Ãéá íá áðïêôÞóåôå õðïóôÞñéîç ãéá ôïí png, ðñïóèÝóôå ôçí --with-png-dir=DIR. ÐñïóÝîôå üôé ç libpng áðáéôåß ôçí zlib library, ãéá áõôü ôï ëüãï ðñïóèÝóôå ôçí åðéëïãÞ --with-zlib-dir[=DIR] óôï configure line óáò. |
xpm | Ãéá íá áðïêôÞóåôå õðïóôÞñéîç ãéá ôïí xpm, ðñïóèÝóôå ôçí --with-xpm-dir=DIR. ÅÜí ç äéá÷åßñéóç äåí ìðïñåß íá åíôïðßóåé ôéò áðáéôïýìåíåò âéâëéïèÞêåò, ìðïñåßôå íá ðñïóèÝóåôå ôï path ãéá ôéò X11 âéâëéïèÞêåò óáò. |
Ãéá íá åðåêôåßíåôå ôéò äõíáôüôçôåò ôçò GD, þóôå íá ÷åéñßæåôáé äéÜöïñåò ãñáììáôïóåéñÝò, ðñïóäéïñßóôå ôïí configure switch --with-XXXX, óôï PHP onfigure line óáò.
Ðßíáêáò 4. Õðïóôçñéæüìåíåò âéâëéïèÞêåò ãñáììáôïóåéñþí
ÂéâëéïèÞêç ãñáììáôïóåéñþí | Configure Switch |
---|---|
FreeType 1.x | Ãéá íá áðïêôåßóåôå õðïóôÞñéîç ãéá ôç FreeType 1.x, ðñïóèÝóôå ôçí --with-ttf[=DIR]. |
FreeType 2 | Ãéá íá áðïêôåßóåôå õðïóôÞñéîç ãéá ôç FreeType 2, ðñïóèÝóôå ôçí --with-freetype-dir=DIR. |
T1lib | Ãéá íá áðïêôåßóåôå õðïóôÞñéîç ãéá ôç T1lib (Type 1 fonts), ðñïóèÝóôå ôçí --with-t1lib[=DIR]. |
Native TrueType string óõíÜñôçóç | Ãéá íá áðïêôåßóåôå õðïóôÞñéîç ãéá ôç native TrueType string óõíÜñôçóç, ðñïóèÝóôå ôçí --enable-gd-native-ttf. |
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
H exif õðïóôçñßæåé ôçí áõôüìáôç ìåôáôñïðÞ ãéá Unicode êáé JIS êùäéêïðïéÞóåéò ÷áñáêôÞñùí ôùí ó÷ïëßùí ôïõ ÷ñÞóôç, üôáí ôï module mbstring åßíáé äéáèÝóéìï. Áõôü ãßíåôáé ìå ôçí áðïêùäéêïðïßçóç, óå ðñþôç öÜóç, ôïõ ó÷ïëßïõ ÷ñçóéìïðïéþíôáò ôï êáèïñéóìÝíï óýíïëï ÷áñáêôÞñùí. ÌåôÜ áðü áõôü, ôï áðïôÝëåóìá êùäéêïðïéåßôáé ìå Ýíá Üëëï óýíïëï ÷áñáêôÞñùí ôï ïðïßï ôáéñéÜæåé ìå ôï HTTP output.
Ðßíáêáò 5. ÅðéëïãÝò äéá÷åßñéóçò ôïõ exif
¼íïìá | ÐñïêáèïñéìÝíç ôéìÞ | Õðïêåßìåíç óå áëëáãÞ |
---|---|---|
exif.encode_unicode | "ISO-8859-15" | PHP_INI_ALL |
exif.decode_unicode_motorola | "UCS-2BE" | PHP_INI_ALL |
exif.decode_unicode_intel | "UCS-2LE" | PHP_INI_ALL |
exif.encode_jis | "" | PHP_INI_ALL |
exif.decode_jis_motorola | "JIS" | PHP_INI_ALL |
exif.decode_jis_intel | "JIS" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Ç exif.encode_unicode êáèïñßæåé ôï óýíïëï ÷áñáêôÞñùí ìå ôï ïðïßï èá äéá÷åéñéóôïýí ôá UNICODE ó÷üëéá ôïõ ÷ñÞóôç. Áõôü áíôéóôïé÷åß óôï ISO-8859-15, ðïõ ëåéôïõñãåß êáíïíéêÜ ãéá ôéò ðåñéóóüôåñåò ìç-áóéáôéêÝò ÷þñåò. Ç ñýèìéóç ìðïñåß íá åßíáé êåíÞ Þ íá ðåñéÝ÷åé ìßá êùäéêïðïßçóç ðïõ íá õðïóôçñßæåôáé áðü ôï mbstring. ÅÜí åßíáé êåíÞ, ÷ñçóéìïðïéåßôáé ç ôñÝ÷ïõóá åóùôåñéêÞ êùäéêïðïßçóç ôïõ mbstring.
Ç exif.decode_unicode_motorola êáèïñßæåé ôï åóùôåñéêü óýíïëï ÷áñáêôÞñùí åéêüíáò, ãéá ó÷üëéá ÷ñÞóôç ìå Unicode êùäéêïðïßçóç, üôáí ç åéêüíá åßíáé óå motorola byte order (big-endian). ÁõôÞ ç ñýèìéóç äåí ìðïñåß íá åßíáé êåíÞ, áëëÜ ìðïñåßôå íá êáèïñßóåôå ìßá ëßóôá áðü êùäéêïðïéÞóåéò ðïõ èá õðïóôçñßæïíôáé áðü ôï mbstring. Ç ðñïêáèïñéóìÝíç åßíáé ç UCS-2BE.
Ç exif.decode_unicode_intel êáèïñßæåé ôï åóùôåñéêü óýíïëï ÷áñáêôÞñùí åéêüíáò, ãéá ó÷üëéá ÷ñÞóôç ìå Unicode êùäéêïðïßçóç, üôáí ç åéêüíá åßíáé óå intel byte order (little-endian). ÁõôÞ ç ñýèìéóç äåí ìðïñåß íá åßíáé êåíÞ, áëëÜ ìðïñåßôå íá êáèïñßóåôå ìßá ëßóôá áðü êùäéêïðïéÞóåéò ðïõ èá õðïóôçñßæïíôáé áðü ôï mbstring. Ç ðñïêáèïñéóìÝíç åßíáé ç UCS-2BE.
Ç exif.encode_jis êáèïñßæåé ôï óýíïëï ÷áñáêôÞñùí âÜóåé ôïõ ïðïßïõ äéá÷åéñßæïíáôé ôá JIS ó÷üëéá ÷ñÞóôç. ÁõôÞ êáèïñßæåôáé íá Ý÷åé ìßá êåíÞ ôéìÞ, ç ïðïßá áíáãêÜæåé ôéò óõíáñôÞóåéò íá ÷ñçóéìïðïéïýí ôçí ôñÝ÷ïõóá åóùôåñéêÞ êùäéêïðïßçóç ôïõ mbstring.
Ç exif.decode_jis_motorola êáèïñßæåé ôï åóùôåñéêü óýíïëï ÷áñáêôÞñùí åéêüíáò ãéá ó÷üëéá ÷ñÞóôç ìå JIS êùäéêïðïßçóç, üôáí ç åéêüíá åßíáé óå motorola byte order (big-endian). ÁõôÞ ç ñýèìéóç äåí ìðïñåß íá åßíáé êåíÞ, áëëÜ ìðïñåßôå íá êáèïñßóåôå ìßá ëßóôá áðü êùäéêïðïéÞóåéò ðïõ èá õðïóôçñßæïíôáé áðü ôï mbstring H ðñïêáèïñéóìÝíç åßíáé ç JIS.
Ç exif.decode_jis_intel êáèïñßæåé ôï åóùôåñéêü óýíïëï ÷áñáêôÞñùí åéêüíáò ãéá ó÷üëéá ÷ñÞóôç ìå Unicode êùäéêïðïßçóç, üôáí ç åéêüíá åßíáé óå intel byte order (little-endian). ÁõôÞ ç ñýèìéóç äåí ìðïñåß íá åßíáé êåíÞ, áëëÜ ìðïñåßôå íá êáèïñßóåôå ìßá ëßóôá áðü êùäéêïðïéÞóåéò ðïõ èá õðïóôçñßæïíôáé áðü ôï mbstring. H ðñïêáèïñéóìÝíç åßíáé ç JIS.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
ÐáñÜäåéãìá 1. Äçìéïõñãßá PNG ìå ôçí PHP
|
Ç exif_imagetype() äéáâÜæåé ôá ðñþôá bytes ìßáò åéêüíáò êáé åëÝã÷åé ôç signature ôçò. ¼ôáí âñåèåß ìßá óùóôÞ signature, åðéóôñÝöåôáé ìßá óôáèåñÜ, áëëéþò ç ôéìÞ FALSE. Ç åðéóôñåöüìåíç ôéìÞ åßíáé ç ßäéá ìå áõôÞí ðïõ ç getimagesize() åðéóôñÝöåé ãéá äåßêôç ßóï ìå 2, ìüíï ðïõ áõôÞ ç óõíÜñôçóç åßíáé êáôÜ ðïëý ãñçãïñüôåñç.
Êáèïñßæïíôáé ïé áêüëïõèåò óôáèåñÝò: 1 = IMAGETYPE_GIF, 2 = IMAGETYPE_JPEG, 3 = IMAGETYPE_PNG, 4 = IMAGETYPE_SWF, 5 = IMAGETYPE_PSD, 6 = IMAGETYPE_BMP, 7 = IMAGETYPE_TIFF_II (intel byte order), 8 = IMAGETYPE_TIFF_MM (motorola byte order), 9 = IMAGETYPE_JPC, 10 = IMAGETYPE_JP2, 11 = IMAGETYPE_JPX, êáé 12 = IMAGETYPE_SWC.
Ç óõíÜñôçóç áõôÞ ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá áðïöåõ÷èïýí êëÞóåéò óå Üëëåò exif óõíáñôÞóåéò ìå ìç õðïóôçñéæüìåíïõò ôýðïõò áñ÷åßùí Þ ìå ôçí $_SERVER['HTTP_ACCEPT'], ãéá íá åëÝã÷åôáé åÜí ï ÷ñÞóôçò ìðïñåß íá äåé ìßá óõãêåêñéìÝíç åéêüíá óôïí browser ôïõ.
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ åßíáé äéáèÝóéìç ìüíï óôçí Ýêäïóç 4 ôçò PHP êáé üôáí áõôÞ ãßíåôáé compile ÷ñçóéìïðïéþíôáò ôçí --enable-exif.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí áðáéôåß ôç âéâëéïèÞêç åéêüíùí GD.
ÁíáôñÝîåôå åðßóçò óôçí getimagesize().
(PHP 4 >= 4.2.0, PHP 5)
exif_read_data -- ÄéáâÜóôå ôá EXIF headers áðü JPEG Þ TIFF ôýðïõò åéêüíùí. Ìå áõôüí ôïí ôñüðï ìðïñåßôå íá äéáâÜóåôå ôá meta data ðïõ ðáñÜãïíôáé áðü øçöéáêÝò êÜìåñåò.Ç óõíÜñôçóç exif_read_data() äéáâÜæåé ôá EXIF headers áðü JPEG Þ TIFF áñ÷åßá åéêüíùí. ÅðéóôñÝöåé Ýíá array üðïõ ïé äåßêôåò åßíáé ôá ïíüìáôá ôùí headers êáé ïé ôéìÝò åßíáé ó÷åôéêÝò ìå áõôÜ ôá headers. ÅÜí äåí ìðïñïýí íá åðéóôñáöïýí äåäïìÝíá ôï áðïôÝëåóìá åßíáé FALSE.
Ç ðáñÜìåôñïò filename áíôéðñïóùðåýåé ôï üíïìá ôïõ ðñïò áíÜãíùóç áñ÷åßïõ êáé äåí ìðïñåß íá åßíáé Ýíá url.
Ç ðáñÜìåôñïò sections åßíáé ìßá ëßóôá sections, ïé ïðïßïé ÷ùñßæïíôáé ìå êüììá êáé ðñÝðåé íá õðÜñ÷åé óå Ýíá áñ÷åßï ãéá íá ðáñÜîåé áðïôÝëåóìá array.
FILE | FileName, FileSize, FileDateTime, SectionsFound |
COMPUTED | html, Width, Height, IsColor êáé Üëëá áí åßíáé äéáèÝóéìá. |
ANY_TAG | ÏðïéáäÞðïôå ðëçñïöïñßá Ý÷åé Ýíá Tag ð.÷. IFD0, EXIF, ... |
IFD0 | ¼ëá ôá ðñïóáñôçìÝíá äåäïìÝíá ôïõ IFD0. Óôá óõíçèéóìÝíá áñ÷åßá åéêüíùí áõôü ðåñéëáìâÜíåé ôï ìÝãåèïò ôçò åéêüíáò êáé Üëëá ó÷åôéêÜ. |
THUMBNAIL | ¸íá áñ÷åßï ðñÝðåé íá ðåñéÝ÷åé Ýíá thumbnail åÜí Ý÷åé Ýíá äåýôåñï IFD. ¼ëåò ïé ðñïóáñôçìÝíåò ðëçñïöïñßåò, ó÷åôéêÜ ìå ôï thumbnail, öõëÜóóïíôáé óå áõôü ôï section. |
COMMENT | Headers ìå ó÷üëéá ôùí åéêüíùí JPEG. |
EXIF | Ôï EXIF section åßíáé Ýíá õðü-section ôïõ IFD0. ÐåñéÝ÷åé ðåñéóóüôåñï ëåðôïìåñåßò ðëçñïöïñßåò ó÷åôéêÜ ìå ìßá åéêüíá. Ôá ðåñéóóüôåñá áðü áõôÜ ôá óôïé÷åßá ó÷åôßæïíôáé ìå øçöéáêÝò êÜìåñåò. |
Ç ðáñÜìåôñïò arrays êáèïñßæåé ôï áí êÜèå section ãßíåôáé Ýíá array. Ôá sections FILE, COMPUTED êáé THUMBNAIL ãßíïíôáé ðÜíôá arrays êáèþò ìðïñåß íá ðåñéÝ÷ïõí ôéìÝò, ôá ïíüìáôá ôùí ïðïßùí ðñïêáëïýí conflicts ìå Üëëá sections.
Ç ðáñÜìåôñïò thumbnail êáèïñßæåé ôï áí èá äéáâáóôåß ìüíï ôï thumbnail, ÷ùñßò ôçí áíÜãíùóç ôùí ðñïóáñôçìÝíùí äåäïìÝíùí ôïõ.
Óçìåßùóç: Ôá exif headers âñßóêïíôáé, óõíÞèùò, óå åéêüíåò JPEG/TIFF, ðïõ ðáñÜãïíôáé áðü øçöéáêÝò êÜìåñåò. Äõóôõ÷þò, üìùò, êÜèå êáôáóêåõáóôÞò Ý÷åé ìßá äéáöïñåôéêÞ éäÝá ãéá ôï ðþò íá êÜíåé tag ôéò åéêüíåò ôïõ ìå áðïôÝëåóìá íá ìçí ìðïñåßôå íá âáóßæåóôå ðÜíôá óôï ðáñüí Exif header.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ôçò exif_read_data()
Ç ðñþôç êëÞóç áðïôõã÷Üíåé ãéáôß ç åéêüíá äåí Ý÷åé ðëçñïöïñßåò header.
|
Óçìåßùóç: ÅÜí ç åéêüíá ðåñéÝ÷åé äåäïìÝíá IFD0 ôüôå ôï COMPUTED ðåñéÝ÷åé ôï ByteOrderMotorola, ðïõ åßíáé 0 ãéá little-endian (intel) êáé 1 ãéá big-endian (motorola) byte order. Áõôü ðñïóôÝèçêå óôçí Ýêäïóç 4.3 ôçò PHP.
¼ôáí Ýíá exif header ðåñéÝ÷åé ìßá óçìåßùóç Copyright ôüôå ìðïñåß íá ðåñéÝ÷åé äýï ôéìÝò. ÅÜí ç ëýóç åßíáé áêáôÜëëçëç, ôï COMPUTED section ôïõ Exif 2.10 standard èá åðßóôñÝøåé êáé ôéò äýï êáôá÷ùñÞóåéò, Copyright.Photographer êáé Copyright.Editor, åíþ ôá IFD0 sections èá ðåñéÝ÷ïõí ôï byte array ìå ôï NULL ÷áñáêôÞñá, ðïõ îå÷ùñßæåé ôéò äýï êáôá÷ùñÞóåéò. Áëëéþò ôçí ðñþôç êáôá÷þñçóç, åÜí ï ôýðïò äåäïìÝíùí Þôáí ëÜèïò (óõíÞèçò óõìðåñéöïñÜ ôïõ Exif). Ôï COMPUTED èá ðåñéÝ÷åé åðßóçò ôçí êáôá÷þñçóç Copyright, ðïõ åßíáé åßôå ôï áõèåíôéêü copyright string åßôå ìßá ëßóôá, áðü ÷ùñéæüìåíá ìå êüììá, photo êáé editor copyright.
Óçìåßùóç: Ôï tag UserComment Ý÷åé ôï ßäéï ðñüâëçìá ìå ôï Copyright. Ìðïñåß íá áðïèçêåýåé äýï ôéìÝò: ðñþôç ôç ÷ñçóéìïðïéçèåßóá êùäéêïðïßçóç êáé äåýôåñç ôçí ßäéá ôçí ôéìÞ. ÅÜí åßíáé Ýôóé ôï IFD section ðåñéÝ÷åé ìüíï ôçí êùäéêïðïßçóç Þ Ýíá byte array. Ôï COMPUTED section èá áðïèçêåýóåé ôéò êáôá÷ùñÞóåéò UserCommentEncoding êáé UserComment. Ç UserComment åßíáé äéáèÝóéìç êáé óôéò äýï ðåñéðôþóåéò êé Ýôóé èá Ýðñåðå íá ðñïôéìÜôáé áðü ôçí ôéìÞ ôïõ IFD0 section.
ÅÜí ôï ó÷üëéï ôïõ ÷ñÞóôç ÷ñçóéìïðïéåß êùäéêïðïßçóç Unicode Þ JIS êáé ôï module mbstring åßíáé äéáèÝóéìï ôüôå ç êùäéêïðïßçóç èá áëëá÷èåß áõôüìáôá, óýìöùíá ìå ôéò ñõèìßóåéò ôïõ exif ini. Áõôü ðñïóôÝèçêå óôçí Ýêäïóç 4.3 ôçò PHP.
Óçìåßùóç: Ïé Height êáé Width õðïëïãßæïíôáé üðùò èá ôï Ýêáíå êáé ç óõíÜñôçóç getimagesize() êé Ýôóé ç ôéìÝò ôïõò äåí ðñÝðåé íá óõìðåñéëáìâÜíïíôáé óå êÜðïéï åðéóôñåöüìåíï header. Åðßóçò ôï html åßíáé height/width text string ðïõ ðñüêåéôáé íá ÷ñçóéìïðïéçèåß óå óõíçèéóìÝíï HTML êþäéêá.
Óçìåßùóç: Îåêéíþíôáò áðü ôçí Ýêäïóç 4.3 ôçò PHP, ç óõíÜñôçóç ìðïñåß íá "äéáâÜóåé" üëá ôá óõíçììÝíá IFD äåäïìÝíá ðïõ ðåñéÝ÷ïõí arrays. Åðßóçò ôï ìÝãåèïò åíüò óõíçììÝíïõ thumbnail åðéóôñÝöåôáé óôï subarray THUMBNAIL êáé ç óõíÜñôçóç exif_read_data() ìðïñåß íá åðéóôñÝöåé thumbnails óå ìïñöÞTIFF. Ôåëåõôáßá êáé óçìáíôéêÞ ðáñáôÞñçóç, äåí õðÜñ÷åé ðëÝïí Ýíá ìÝãéóôï ìÞêïò ãéá åðéóôñåöüìåíåò ôéìÝò (ü÷é ìÝ÷ñé öôáóôåß ôï üñéï ôçò ìíÞìçò).
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ õðÜñ÷åé ìüíï óôçí PHP 4, êáé üôáí áõôÞ Ýãéíå compiled ÷ñçóéìïðïéþíôáò ôçí --enable-exif. Ç ëåéôïõñãéêüôçôá êáé ç óõìðïñéöüñá ôçò Ý÷ïõí áëëÜîåé óôçí PHP 4.2. Ç ðáëáéüôåñåò åêäüóåéò åßíáé áñêåôÜ áóôáèåßò.
Áðü ôçí Ýêäïóç 4.3 ôçò PHP ôï ó÷üëéï ÷ñÞóôç ìðïñåß íá áëëÜîåé áõôüìáôá êùäéêïðïßçóç åÜí ç PHP 4 Ý÷åé ãßíåé compiled ÷ñçóéìïðïéþíôáò ôçí --enable-mbstring.
Ç óõíÜñôçóç áõôÞ äå ÷ñåéÜæåôáé ôçí GD image library.
ÁíáôñÝîôå åðßóçò óôéò: exif_thumbnail() êáé getimagesize().
Ç exif_thumbnail() äéáâÜæåé ôï óõíçììÝíï thumbnail ìßáò åéêüíáò TIFF Þ JPEG. ÅÜí ç åéêüíá äåí ðåñéÝ÷åé thumbnail ôüôå åðéóôñÝöåôáé ç ôéìÞ FALSE.
Ïé ðáñÜìåôñïé width, height êáé imagetype åßíáé äéáèÝóéìåò áðü ôçí PHP 4.3 êáé åðéóôñÝöïõí ôï ìÝãåèïò ôïõ thumbnail êáèþò åðßóçò êáé ôïí ôýðï ôïõ. Åßíáé äõíáôüí ç exif_thumbnail() íá ìçí ìðïñåß íá äçìéïõñãÞóåé ìßá åéêüíá áëëÜ íá ìðïñåß íá ðñïóäéïñßóåé ô ìÝãåèüò áõôÞò. Óôçí ôåëåõôáßá ðåñßðôùóç, ç åðéóôñåöüìåíç ôéìÞ åßíáé FALSE, áëëÜ ôßèåíôáé ïé width êáé height.
ÅÜí ìðïñåßôå íá áíáêôÜôå thumbnails ìÝóù áõôÞò ôçò óõíÜñôçóçò èá ðñÝðåé íá óôÝëíåôå ôçí ðëçñïöïñßá mimetype ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç header(). Ôï áêüëïõèï ðáñÜäåéãìá äåß÷íåé ôï ðñïáíáöåñèÝí.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ôçò exif_thumbnail()
|
Áðü ôçí Ýêäïóç 4.3 ôçò PHP, ç óõíÜñôçóç exif_thumbnail() ìðïñåß íá åðéóôñÝöåé thumbnails ôýðïõ TIFF.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé äéáèÝóéìç ìüíï óôçí PHP 4 êáé üôáí áõôÞ Ý÷åé ãßíåé compiled ÷ñçóéìïðïéþíôáò ôçí --enable-exif. Ç ëåéôïõñãéêüôçôá êáé ç óõìðåñéöïñÜ ôçò Ý÷ïõí áëëÜîåé óôçí PHP 4.2
Ç óõíÜñôçóç áõôÞ äå ÷ñåéÜæåôáé ôçí GD image library.
ÁíáôñÝîôå åðßóçò óôéò: exif_read_data() êáé image_type_to_mime_type().
ÅðéóôñÝöåé Ýíá associative array, ðïõ ðåñéãñÜöåé ôçí Ýêäïóç êáé ôéò äõíáôüôçôåò ôçò åãêáôåóôçìÝíçò GD âéâëéïèÞêçò.
Ðßíáêáò 1. Óôïé÷åßá ôïõ array ðïõ åðéóôñÝöåôáé áðü ôçí gd_info()
Éäéüôçôá | Óçìáóßá |
---|---|
GD Version | ÔéìÞ ôýðïõ string, ðïõ ðåñéãñÜöåé ôçí åãêáôåóôçìÝíç Ýêäïóç ôçò libgd. |
Freetype Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE åÜí Ý÷åé åãêáôáóôáèåß ç Freetype õðïóôÞñéîç. |
Freetype Linkage | ÔéìÞ ôýðïõ string, ðïõ ðåñéãñÜöåé ôïí ôñüðï ìå ôïí ïðïßï Ýãéíå linked ç Freetype. Áíáìåíüìåíåò ôéìÝò åßíáé ïé: 'with freetype', 'with TTF library', êáé 'with unknown library'. Ôï óôïé÷åßï áõôü èá ðñïóäéïñéóôåß ìüíï åÜí ç Freetype Support âñÝèçêå TRUE. |
T1Lib Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE åÜí ç õðïóôÞñéîç ôçò T1Lib Ý÷åé óõìðåñéëçöèåß. |
GIF Read Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE åÜí ç õðïóôÞñéîç ãéá reading ôùí GIF åéêüíùí Ý÷åé óõìðåñéëçöèåß. |
GIF Create Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE åÜí ç õðïóôÞñéîç ãéá creating GIF åéêüíåò Ý÷åé óõìðåñéëçöèåß. |
JPG Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE åÜí ç õðïóôÞñéîç ãéá ôïí ôýðï JPG Ý÷åé óõìðåñéëçöèåß. |
PNG Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE åÜí ç õðïóôÞñéîåé ãéá ôïí ôýðï PNG Ý÷åé óõìðåñéëçöèåß. |
WBMP Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE Ýáí ç õðïóôÞñéîç ãéá ôïí ôýðï WBMP Ý÷åé óõìðåñéëçöèåß. |
XBM Support | ÔéìÞ ôýðïõ boolean. Åßíáé TRUE åÜí ç õðïóôÞñéîç ãéá ôïí ôýðï XBM Ý÷åé óõìðåñéëçöèåß. |
ÐáñÜäåéãìá 1. ×ñÞóç ôçò gd_info()
|
ÁíáôñÝîôå åðßóçò óôéò: imagepng(), imagejpeg(), imagegif(), imagewbmp(), êáé imagetypes().
Ç óõíÜñôçóç getimagesize() õðïëïãßæåé ôï ìÝãåèïò ïðïéïõäÞðïôå áñ÷åßïõ åéêüíáò ôýðïõ GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP Þ IFF êáé åðéóôñÝöåé ôéò äéáóôÜóåéò ôïõ, ìáæß ìå ôïí ôýðï áñ÷åßïõ êáé Ýíá height/width text string, ðïõ èá ÷ñçóéìïðïéçèåß óå Ýíá óõíçèéóìÝíï HTML IMG tag.
ÅðéóôñÝöåé Ýíá array 4 óôïé÷åßùí. Ï äåßêôçò 0 ðåñéÝ÷åé ôï ðëÜôïò ôçò åéêüíáò óå pixels, åíþ ï äåßêôçò 1 ôï ýøïò. Ï äåßêôçò 2 åßíáé Ýíá flag ðïõ äåß÷íåé ôïí ôýðï ôçò åéêüíáò: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF. ÁõôÝò ïé ôéìÝò áíôáðïêñßíïíôáé óôéò óôáèåñÝò IMAGETYPE ðïõ ðñïóôÝèçêáí óôçí Ýêäïóç 4.3 ôçò PHP. Ï äåßêôçò 3 åßíáé Ýíá text string ìå ôï êáôÜëëçëï height="yyy" width="xxx" string, ôï ïðïßï ìðïñåß íá ÷ñçóéìïðïéçèåß áð' åõèåßáò óå Ýíá IMG tag.
¼ôáí Ý÷ïõìå JPG åéêüíåò, åðéóôñÝöïíôáé äýï åðéðëÝïí äåßêôåò: Ïé channels êáé bits. Ï channels ôßèåôáé 3 ãéá RGB åéêüíåò êáé 4 ãéá CMYK åéêüíåò. Ï bits åßíáé ï áñéèìüò ôùí bits ãéá êÜèå ÷ñþìá.
Áðü ôçí PHP 4.3, ïé bits êáé channels õðÜñ÷ïõí êáé ãéá Üëëïõò ôýðïõò åéêüíáò. Ðáñ' üëá áõôÜ, ç ðáñïõóßá áõôþí ôùí ôéìþí ìðïñåß íá ðñïêáëÝóåé óýã÷õóç. Ùò ðáñÜäåéãìá áíáöÝñåôáé ôï áêüëïõèï: ï ôýðïò GIF ÷ñçóéìïðïéåß ðÜíôá 3 channels áíÜ pixel, áëëÜ ï áñéèìüò ôùí bits áíÜ pixel äåí ìðïñåß íá õðïëïãéóôåß ãéá Ýíá animated GIF ìå Ýíá global color table.
Ìåñéêïß ôýðïé ìðïñåß íá ìçí ðåñéÝ÷ïõí åéêüíåò Þ áêüìá íá ðåñéÝ÷ïõí ðïëëáðëÝò åéêüíåò. Óå áõôÝò ôéò ðåñéðôþóåéò, ç getimagesize() ìðïñåß íá ìçí åßíáé óå èÝóç íá õðïëïãßóåé óùóôÜ ôï ìÝãåèïò ôçò åéêüíáò. ¸ôóé ç getimagesize() èá åðéóôñÝøåé ìçäÝí ãéá ôï ðëÜôïò êáé ôï ýøïò.
Beginning with PHP 4.3, getimagesize() also returns an additional parameter, mime, that corresponds with the MIME type of the image. This information can be used to deliver images with correct HTTP Content-type headers:
ÅÜí ç ðñïóðÝëáóç ôçò åéêüíáò filename åßíáé áäýíáôç, Þ åÜí ç åéêüíá äåí åßíáé Ýãêõñç, ç getimagesize() èá åðéóôñÝøåé ôçí ôéìÞ FALSE êáé èá ðáñÜîåé Ýíá ìÞíõìá ëÜèïõò.
Ç ðñïáéñåôéêÞ ðáñÜìåôñïò imageinfo óáò åðéôñÝðåé íá áðïóðÜôå êÜðïéåò åðéðëÝïí ðëçñïöïñßåò áðü ôï áñ÷åßï åéêüíáò. Ðñïò ôï ðáñüí, áõôÞ åðéóôñÝöåé ôïõò äéÜöïñïõò JPG APP markers ùò Ýíá associative array. ÌåñéêÜ ðñïãñÜììáôá ÷ñçóéìïðïéïýí ôïõò APP markers óå óõíçììÝíåò text ðëçñïöïñßåò óå åéêüíåò. Åßíáé ðïëý óõíçèéóìÝíç, åðßóçò, ç ÷ñÞóç óå óõíçììÝíåò IPTC http://www.iptc.org/ ðëçñïöïñßåò óå APP13 marker. Ìðïñåßôå íá ÷ñçóéìïðïéåßóåôå ôç óõíÜñôçóç iptcparse() ãéá íá êÜíåôå parse ôï binary APP13 marker óå êÜðïéá áíáãíþóéìç ìïñöÞ.
Óçìåßùóç: Ç õðïóôÞñéîç ãéá TIFF ðñïóôÝèçêå óôçí PHP 4.2.
Ç óõíÜñôçóç áõôÞ äåí ÷ñåéÜæåôáé ôçí GD image library.
ÁíáôñÝîôå åðßóçò óôéò: image_type_to_mime_type(), exif_imagetype(), exif_read_data() êáé exif_thumbnail().
Ç õðïóôÞñéîç ãéá URL ðñïóôÝèçêå óôçí Ýêäïóç 4.0.5 ôçò PHP.
(no version information, might be only in CVS)
image_type_to_extension -- Get file extension for image typeÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
image_type_to_mime_type -- Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetypeThe image_type_to_mime_type() function will determine the Mime-Type for an IMAGETYPE constant.
The returned values are as follows
Ðßíáêáò 1. Returned values Constants
imagetype | Returned value |
---|---|
IMAGETYPE_GIF | image/gif |
IMAGETYPE_JPEG | image/jpeg |
IMAGETYPE_PNG | image/png |
IMAGETYPE_SWF | application/x-shockwave-flash |
IMAGETYPE_PSD | image/psd |
IMAGETYPE_BMP | image/bmp |
IMAGETYPE_TIFF_II (intel byte order) | image/tiff |
IMAGETYPE_TIFF_MM (motorola byte order) | image/tiff |
IMAGETYPE_JPC | application/octet-stream |
IMAGETYPE_JP2 | image/jp2 |
IMAGETYPE_JPX | application/octet-stream |
IMAGETYPE_JB2 | application/octet-stream |
IMAGETYPE_SWC | application/x-shockwave-flash |
IMAGETYPE_IFF | image/iff |
IMAGETYPE_WBMP | image/vnd.wap.wbmp |
IMAGETYPE_XBM | image/xbm |
Óçìåßùóç: This function does not require the GD image library.
See also getimagesize(), exif_imagetype(), exif_read_data() and exif_thumbnail().
Ç óõíÜñôçóç image2wbmp() äçìéïõñãåß ôï WBMP áñ÷åßï, ìå üíïìá filename, áðü ôï image. Ç ðáñÜìåôñïò image åßíáé ç åðéóôñåöüìåíç ôéìÞ ôçò óõíÜñôçóçò imagecreate().
Ç filename åßíáé ðñïáéñåôéêÞ, êáé áí ðáñáëåéöèåß ôüôå ôï raw image stream èá ãßíåé áð' åõèåßáò output. ÓôÝëíïíôáò Ýíáí image/vnd.wap.wbmp content-type, ìå ÷ñÞóç ôçò óõíÜñôçóçò header(), ìðïñåßôå íá äçìéïõñãåßóåôå Ýíá PHP script ðïõ êÜíåé áìÝóùò output ôá WBMP images.
Óçìåßùóç: Ç õðïóôÞñéîç ôïõ WBMP åßíáé äéáèÝóéìç ìüíï åÜí ç PHP ãßíåé compile ãéá GD-1.8 Þ íåþôåñç.
ÁíáôñÝîôå åðßóçò óôçí imagewbmp().
Ç óõíÜñôçóç imagealphablending() åðéôñÝðåé ôçí ýðáñîç äýï äéáöïñåôéêþí mode ó÷åäßáóçò óå truecolor åéêüíåò. Óôï blending mode, ç alpha channel óõíéóôþóá ôïõ ðáñå÷üìåíïõ, óå üëåò ôéò óõíáñôÞóåéò ó÷åäßáóçò (üðùò ç imagesetpixel()), ÷ñþìáôïò, õðïëïãßæåé ôçí ðïóüôçôá ôïõ underlying ÷ñþìáôïò ðïõ åðéôñÝðåôáé íá äéáêñßíåôáé. Áõôü óõíôåëåß óôï íá áíáìåéãíýåé, ç gd, ôï ìÝ÷ñé åêåßíç ôç óôéãìÞ ÷ñþìá ìå áõôü ôçò ó÷åäßáóçò, êáé íá áðïèçêåýåé ôï áðïôÝëåóìá óôçí åéêüíá. To pixel ðïõ Ý÷ïõìå ùò áðïôÝëåóìá åßíáé áäéáöáíÝò. Óôï non-blending mode, ôï ÷ñþìá ó÷åäßáóçò áíôéãñÜöåôáé, åðáêñéâþò, ìáæß ôéò ðëçñïöïñßåò ôïõ alpha channel, áíôéêáèéóôüíôáò ôï pixel ðñïïñéóìïý. Ôï blending mode äåí åßíáé äéáèÝóéìï êáôÜ ôç ó÷åäßáóç óå palette åéêüíåò. ÅÜí ç ðáñÜìåôñïò blendmode åßíáé TRUE, ôüôå ôï blending mode åßíáé enabled, áëëéþò ôßèåôáé disabled.
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP êáé áðáéôåß ôçí GD 2.0.1.
(PHP 4 >= 4.3.2, PHP 5)
imageantialias -- ¸ëåã÷ïò ãéá ôï áí ðñÝðåé íá ÷ñçóéìïðïéçèïýí antialias óõíáñôÞóåéòÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÁíáôñÝîôå åðßóçò óôçí imagecreatetruecolor().
Ç imagearc() ó÷åäéÜæåé ìßá ìåñéêÞ Ýëëåéøç ìå êÝíôñï ôï óçìåßï cx, cy (ðÜíù áñéóôåñÜ âñßóêåôáé ôï 0, 0) ôçò åéêüíáò image. Ïé ðáñÜìåôñïé W êáé h êáèïñßæïõí ôï ðëÜôïò êáé ôï ýøïò ôçò Ýëëåéøçò, áíôßóôïé÷á, åíþ ôá óçìåßá áñ÷Þò êáé ôÝëïõò ïñßæïíôáé óå ìïßñåò ìÝóù ôùí ðáñáìÝôñùí s êáé e. Ïé 0° ìïßñåò âñßóêïíôáé óôç èÝóç "3 þñá", êáé ç ó÷åäßáóç ãßíåôáé ìå öïñÜ áíôßèåôç áõôÞò ôùí äåéêôþí ôïõ ñïëïãéïý.
ÁíáôñÝîôå åðßóçò óôéò: imageellipse(), imagefilledellipse(), êáé imagefilledarc().
Ç imagechar() ó÷åäéÜæåé ôïí ðñþôï ÷áñáêôÞñá ôçò c óôçí åéêüíá id ìå ôï ðÜíù áñéóôåñü óçìåßï ôïõ íá åßíáé óôç èÝóç x,y (ç ðÜíù áñéóôåñÞ ãùíßá ôçò åéêüíáò åßíáé ôï 0, 0) ìå ÷ñþìá color. ÅÜí ç font åßíáé 1, 2, 3, 4 Þ 5, ÷ñçóéìïðïéåßôáé ìßá åíóùìáôùìÝíç ãñáììáôïóåéñÜ (ìå ìåãáëýôåñá íïýìåñá íá áíôéóôïé÷ïýí óå ìåãáëýôåñïõò ÷áñáêôÞñåò).
ÁíáôñÝîôå åðßóçò óôçí imageloadfont().
Ç imagecharup() ó÷åäéÜæåé ôï ÷áñáêôÞñá c êÜèåôá óôçí åéêüíá image óôç èÝóç ìå óõíôåôáãìÝíåò x, y (ç ðÜíù áñéóôåñÞ ãùíßá ôçò åéêüíáò Ý÷åé óõíôåôáãìÝíåò 0, 0) ìå ôï ÷ñþìá color. ÅÜí ç font åßíáé 1, 2, 3, 4 Þ 5, ÷ñçéóìïðïåßôáé ìßá åíóùìáôùìÝíç ãñáììáôïóåéñÜ.
ÁíáôñôÝîôå åðßóçò óôçí imageloadfont().
Ç imagecolorallocate() åðéóôñÝöåé Ýíáí color identifier, ðïõ áíáðáñéóôÜ to óõíôéèÝìåíï, áðü ôéò äïèåßóåò RGB óõíéóôþóåò, ÷ñþìá. Ç ðáñÜìåôñïò im åßíáé ç åðéóôñåöüìåíç ôéìÞ ôçò óõíÜñôçóçò imagecreate(). Ïé ðáñÜìåôñïé red, green êáé blue åßíáé ïé ôéìÝò ôéò êüêêéíçò, ðñÜóéíçò êáé ìðëå óõíéóôþóáò ôïõ æçôïýìåíïõ ÷ñþìáôïò, áíôßóïé÷á. Ðáßñíïõí áêÝñáéåò ôéìÝò áðü ôï 0 Ýùò ôï 255. Ç imagecolorallocate() ðñÝðåé íá êëçèåß ãéá íá äçìéïõñãÞóåé ôï êÜèå ÷ñþìá ðïõ ðñüêåéôáé íá ÷ñçóéìïðïéçèåß óôçí åéêüíá image.
ÅðéóôñÝöåé -1 åÜí áðïôý÷åé ç äéÜèåóç.
Ç imagecolorallocatealpha() óõìðåñéöÝñåôáé áêñéâþò üðùò ç imagecolorallocate(), ìå ìüíç äéáöïñÜ ôçí åðéðëÝïí ðáñÜìåôñï ãéá ôç äéáöÜíåéá alpha, ç ïðïßá ìðïñåß íá Ý÷åé ôéìÞ áðü ôï 0 Ýùò ôï 127. Ôï 0 äçëþíåé ðëÞñç áäéáöÜíåéá, åíþ ôï 127 äçëþíåé ðëÞñç äéáöÜíåéá.
ÅðéóôñÝöåé FALSE åÜí áðïôý÷åé ç äéÜèåóç.
ÅðéóôñÝöåé ôï äåßêôç ôïõ ÷ñþìáôïò ôïõ pixel, poy br;isketai óôçí êáèïñéóìÝíç èÝóç ôçò åéêüíáò image.
ÅÜí ç PHP ãßíåé compiled ìå ôçí Ýêäïóç 2.0, Þ êáé ìåãáëýôåñç, ôçò GD library, êáé ç åéêüíá åßíáé truecolor, ôüôå ç óõíÜñôçóç åðéóôñÝöåé ôçí ôéìÞ RGB ôïõ pixel ìå ôç ìïñöÞ áêåñáßïõ áñéèìïý. ×ñçóéìïðïéåßóôå bitshifting êáé masking ãéá íá ðñïóðåëÜóåôå îå÷ùñéóôÜ ôéò ôéìÝò êüêêéíïõ, ðñÜóéíïõ êáé ìðëå ôçò óõíéóôþóáò:
ÁíáôñÝîôå åðßóçò óôéò: imagecolorset() êáé imagecolorsforindex().
(PHP 3, PHP 4 , PHP 5)
imagecolorclosest -- Áíáêôåßóôå ôï äåßêôç ôïõ ðéï êïíôéíïý, óôï ðñïóäéïñéóìÝíï, ÷ñþìáôïòÅðéóôñÝöåé ôï äåßêôç ôïõ ÷ñþìáôïò ôçò ðáëÝôôáò ôçò åéêüíáò, ðïõ åßíáé ôï ðéï "êïíôéíü" óôçí ðñïóäéïñéóìÝíç RGB ôéìÞ.
Ç "áðüóôáóç" ìåôáîý ôïõ åðéèõìçôïý ÷ñþìáôïò êáé êÜèå ÷ñþìáôïò óôçí ðáëÝôôá õðïëïãßæåôáé óáí ïé RGB ôéìÝò íá áíôéðñïóþðåõáí óçìåßá ôñéóäéÜóôáôïõ ÷þñïõ.
ÁíáôñÝîôå åðßóçò óôçí imagecolorexact().
(PHP 4 >= 4.0.6, PHP 5)
imagecolorclosestalpha -- Áíáêôåßóôå ôï äåßêôç ôïõ ðéï êïíôéíïý, óôï ðñïóäéïñéóìÝíï, ÷ñþìáôïò + alphaÅðéóôñÝöåé ôï äåßêôç ôïõ ÷ñþìáôïò ôçò ðáëÝôôáò ôçò åéêüíáò, ðïõ åßíáé ðéï "êïíôÜ" óôçí ðñïóäéïñéóìÝíç RGB ôéìÞ êáé alpha åðßðåäï.
ÁíáôñÝîôå åðßóçò óôçí imagecolorexactalpha().
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç ðñïóôÝèçêå óôç Ýêäïóç 4.0.6õ ôçò PHP êáé áðáéôåß GD 2.0.1
(PHP 4 >= 4.0.1, PHP 5)
imagecolorclosesthwb -- Áíáêôåßóôå ôï äåßêôç ôïõ ÷ñþìáôïò ðïõ Ý÷åé ôçí ðëçóéÝóôåñç, óôï äïèÝí ÷ñþìá, áðü÷ñùóç, ëåõêüôçôá, áðü÷ñùóç êáé óêïôåéíüôçôá
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ç óõíÜñôçóç imagecolordeallocate() áðïäåõóìåýåé Ýíá ÷ñþìá ðïõ äåóìåýôçêå ðñïçãïõìÝíùò ìå ôç óõíÜñôçóç imagecolorallocate().
ÁíáêôÜ ôï äåßêôç ôïõ ðñïóäéïñéóìÝíïõ, óôçí ðáëÝôôá ôçò åéêüíáò, ÷ñþìáôïò.
ÅÜí ôï ÷ñþìá äåí õðÜñ÷åé óôçí ðáëÝôôá ôçò åéêüíáò, åðéóôñÝöåôáé ç ôéìÞ -1.
ÁíáôñÝîôå åðßóçò óôçí imagecolorclosest().
ÅðéóôñÝöåé ôï äåßêôç ôïõ ðñïóäéïñéóìÝíïõ ÷ñþìáôïò + alpha ôçò ðáëÝôôáò ôçò åéêüíáò.
ÅÜí äåí õðÜñ÷åé ôï ÷ñþìá óôçí ðáëÝôôá ôçò åéêüíáò, åðéóôñÝöåôáé ç ôéìÞ -1.
ÁíáôñÝîôå åðßóçò óôçí imagecolorclosestalpha().
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP êáé ÷ñåéÜæåôáé ôçí Ýêäïóç 2.0.1 (Þ íåüôåñç) ôçò GD 2.0.1
(PHP 4 >= 4.3.0, PHP 5)
imagecolormatch -- ÊÜíåé ôá ÷ñþìáôá ôçò ðáëÝôôáò ìßáò åéêüíáò íá ðëçóéÜæïõí ôçí true color ÝêäïóçÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ç ðáñÜìåôñïò image1 ðñÝðåé íá åßíáé Truecolor, ç image2 íá åßíáé ç Palette, åíþ êáé ïé äýï ðñÝðåé íá åßíáé ôïõ ßäïõ ìåãÝèïõò must be the same size.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÁíáôñÝîôå åðßóçò óôçí imagecreatetruecolor().
(PHP 3>= 3.0.2, PHP 4 , PHP 5)
imagecolorresolve -- Áíáêôåßóôå ôï äåßêôç åíüò ÷ñþìáôïò Þ ôïí ðéï êïíôéíü óå áõôü, ùò åíáëëëáêôéêÞ åðéëïãÞÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé, åããõçìÝíá, ôï äåßêôç ÷ñþìáôïò ôïõ ÷ñþìáôïò ðïõ æçôÞèçêå, åßôå áõôü åßíáé ôï áêñéâÝò ÷ñþìá åßôå ôï ðéï êïíôéíü óå áõôü.
ÁíáôñÝîôå åðßóçò óôçí imagecolorclosest().
(PHP 4 >= 4.0.6, PHP 5)
imagecolorresolvealpha -- Áíáêôåßóôå ôï äåßêôç åíüò ÷ñþìáôïò + alpha Þ ôçí ðéï êïíôéíÞ åíáëëáêôéêÞ ôïõ åðéëïãÞÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé, åããõçìÝíá, ôï äåßêôç ôïõ ÷ñþìáôïò ðïõ æçôÞèçêå, åßôå áõôü åßíáé ôï áêñéâÝò ÷ñþìá åßôå ôï ðéï êïíôéíü óå áõôü.
ÁíáôñÝîå åðßóçò óôçí imagecolorclosestalpha().
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP 4.0.6 êáé áðáéôåß ôçí GD 2.0.1
ÁõôÞ ç óõíÜñôçóç áíôéóôïé÷åß Ýíá äåßêôç ôçò ðáëÝôôáò óå Ýíá ÷ñþìá. ÁõôÞ ç ëåéôïõñãßá åßíáé ÷ñÞóéìç ãéá ôç äçìéïõñãßá flood-fill-like effects óå paletted images ÷ùñßò íá ÷ñåéÜæåôáé ç ðñáãìáôéêÞ åêôÝëåóç ôïõ flood-fill.
ÁíáôñÝîôå åðßóçò óôçí imagecolorat().
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé Ýíá array ìå ôá red, green, êáé blue keys ðïõ ðåñéÝ÷ïõí ôéò êáôÜëëçëåò ôéìÝò ãéá ôï óõãêåêñéìÝíï äåßêôç ÷ñþìáôïò.
ÁíáôñÝîôå åðßóçò óôéò: imagecolorat() êáé imagecolorexact().
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé ôï ðëÞèïò ôùí ÷ñùìÜôùí ôçò ðáëÝôôáò ôçò ðñïóäéïñéóìÝíçò åéêüíáò.
ÁíáôñÝîôå åðßóçò óôéò: imagecolorat() êáé imagecolorsforindex().
Ç óõíÜñôçóç imagecolortransparent() èÝôåé ôï äéáöáíÝò ÷ñþìá óôçí åéêüíá image ùò color. Ç image åßíáé ï image identifier ðïõ åðéóôñÝöåôáé áðü ôç óõíÜñôçóç imagecreate() êáé ç color åßíáé Ýíáò color identifier ðïõ åðéóôñÝöåôáé áðü ôçí imagecolorallocate().
Óçìåßùóç: Ôï äéáöáíÝò ÷ñþìá åßíáé ìßá éäéüôçôá ôçò åéêüíáò, êé ü÷é ìßá éäéüôçôá ôïõ ÷ñþìáôïò. Áðü ôç óôéãìÞ ðïõ ïñßóåôáé Ýíá ÷ñþìá ãéá íá åßíáé ôï äéáöáíÝò, ïðïéåóäÞðïôå ðåñéï÷Ýò ôçò åéêüíáò åß÷áí ÷ñùìáôéóôåß ìå áõôü ôï ÷ñþìá èá ãßíïõí äéáöáíÞò.
Ï identifier ôïõ íÝïõ (Þ ôïõ ôñÝ÷ïíôïò, åÜí äåí Ý÷åé ðñïóäéïñéóôåß êáíÝíá) äéáöáíïýò ÷ñþìáôïò åðéóôñÝöåôáé.
ÁíôéãñÜøôå Ýíá ìÝñïò ôçò src_im óôçí dst_im îåêéíþíôáò áðü ôï óçìåßï x,y ìå óõíôåôáãìÝíåò src_x, src_y ìå ðëÜôïò src_w êáé ýøïò src_h. Ôï ôìÞìá ðïõ ðñïóäéïñßóôçêå èá áíôéãñáöåß óôï óçìåßï x,y ìå óõíôåôáãìÝíåò, dst_x êáé dst_y.
ÁíôéãñÜøôå Ýíá ìÝñïò ôçò src_im óôçí dst_im îåêéíþíôáò áðü ôï óçìåßï x,y ìå óõíôåôáãìÝíåò src_x, src_y , ðëÜôïò src_w êáé ýøïò src_h. Ôï ôìÞìá ðïõ ðñïóäéïñßóôçêå èá áíôéãñáöåß óôï óçìåßï x,y ìå óõíôåôáãìÝíåò dst_x êáé dst_y. Ç äýï åéêüíåò èá óõã÷ùíåõôïýí óýìöùíá ìå ôçí pct ðïõ ìðïñåß íá ðïéêßëåé áðü 0 Ýùò 100. ¼ôáí pct = 0, äåí ãßíåôáé êáìßá åíÝñãåéá, åíþ üôáí éóïýôáé ìå 100 ç óõíÜñôçóç óõìðåñéöÝñåôáé áêñéâþò üðùò ç imagecopy().
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP 4.0.6
(PHP 4 >= 4.0.6, PHP 5)
imagecopymergegray -- ÁíôéãñÜøôå êáé óõã÷ùíåýóôå Ýíá ìÝñïò ìßáò åéêüíáò óå gray scaleÇ óõíÜñôçóç imagecopymergegray() áíôéãñÜöåé Ýíá ìÝñïò ôçò src_im óôçí dst_im îåêéíþíôáò áðü ôï óçìåßï x,y ìå óõíôåôáãìÝíåò src_x, src_y , ðëÜôïò src_w êáé ýøïò src_h. Ôï ôìÞìá ðïõ ðñïóäéïñßóôçêå èá áíôéãñáöåß óôï óçìåßï x,y ìå óõíôåôáãìÝíåò dst_x êáé dst_y. Ç äýï åéêüíåò èá óõã÷ùíåõôïýí óýìöùíá ìå ôçí pct ðïõ ìðïñåß íá ðïéêßëåé áðü 0 Ýùò 100. ¼ôáí pct = 0, äåí ãßíåôáé êáìßá åíÝñãåéá, åíþ üôáí éóïýôáé ìå 100 ç óõíÜñôçóç óõìðåñéöÝñåôáé áêñéâþò üðùò ç imagecopy().
ÁõôÞ ç óõíÜñôçóç åßíáé áêñéâþò ßäéá ìå ôçí imagecopymerge() åêôüò ôïõ üôé üôáí óõã÷ùíåýåé äéáôçñåß ôçí áðü÷ñùóç ôçò source ìåôáôñÝðïíôáò ôá pixels ðñïïñéóìïý óå gray scale ðñéí ôçí áíôéãñáöÞ.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP
(PHP 4 >= 4.0.6, PHP 5)
imagecopyresampled -- ÁíôéãñÜøôå êáé êÜíåôå resize ìÝñïò ìßáò åéêüíáò ìå resamplingÇ óõíÜñôçóç imagecopyresampled() áíôéãñÜöåé Ýíá ôìÞìá ôñéãùíéêïý ó÷Þìáôïò ôçò åéêüíáò óå ìßá Üëëç åéêüíáò, ðáñáðïéþíôáò ïìáëÜ ôçò ôéìÝò ôùí pixel Ýôóé þóôå, åéäéêÜ, üôáí ìåéþíåôáé ôï ìÝãåèïò ìßáò åéêüíáò íá äéáôçñåß êáôÜ ìåãÜëï ðïóïóôü ôçí êáèáñüôçôÜ ôçò. Ç Dst_im åßíáé ç åéêüíá ðñïïñéóìüò, åíþ ç src_im åßíáé ï source image identifier. ÅÜí ïé óõíôåôáãìÝíåò, ðëÜôïò êáé ýøïò ðçãÞò êáé ðñïïñéóìïý äéáöÝñïõí, èá õðÜñîåé êáôÜëëçëç ìåãÝèõíóç Þ óìßêñõíóç ôïõ ôìÞìáôïò ôçò åéêüíáò. Ïé óõíôåôáãìÝíåò áíáöÝñïíôáé óôçí ðÜíù áñéóôåñÞ ãùíßáò. ÁõôÞ ç óõíÜñôçóç ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá áíôéãñÜöåé ðåñéï÷Ýò óôçí ßäéá åéêüíá (åÜí ç dst_im åßíáé ç ßäéá ìå ôçí src_im), áëëÜ åÜí ïé ðåñéï÷Ýò áëëçëïêáëýðôïíôáé ôï áðïôÝëåóìá åßíáé áðñüâëåðôï.
Óçìåßùóç: ÕðÜñ÷åé Ýíá ðñüâëçìá ëüãù ôùí ðåñéïñéóìþí ôçò ðáëÝôôáò ôçò åéêüíáò (255+1 ÷ñþìáôá). Ôï íá êÜíåéò resampling Þ filtering ìßá åéêüíá óõíÞèùò ÷ñåéÜæåôáé ðåñéóóüôåñá áðü 255, Ýíá åéäüò ðñïóÝããéóçò ÷ñçóéìïðïéåßôáé ãéá ôïí õðïëïãéóìü ôïõ íÝïõ resampled pixel êáé ôïõ ÷ñþìáôüò ôïõ. Ìå ìßá ðáëÝôôá ìßáò åéêüíáò ðñïóðáèïýìå íá äåóìåýóïõìå Ýíá íÝï ÷ñþìá, åÜí áõôü áðïôý÷åé, åðéëÝãïõìå ôï ÷ñþìá ðïõ Ý÷åé õðïëïãéóôåß ùò ôï ðéï êïíôéíü (èåùñçôéêÜ). Áõôü äåí åßíáé ðÜíôá ôï ðéï êïíôéíü ïðôéêÜ ÷ñþìá. Áõôü ìðïñåß íá ðñïêáëÝóåé Ýíá ðåñßåñãï áðïôÝëåóìá, üðùò êåíÝò (Þ ïðôéêÜ êåíÝò) åéêüíåò. Ãéá íá îåðåñÜóåôå áõôü ôï ðñüâëçìá, ðáñáêåëåßóôå íá ÷ñçóéìïðïéåßôå ìßá truecolor åéêüíá, üðùò áõôÞ ðïõ äçìéïõñãåßôáé áðü ôç óõíÜñôçóç imagecreatetruecolor(), ùò åéêüíá ðñïïñéóìïý.
Óçìåßùóç: Ç imagecopyresampled() áðáéôåß ôçí GD Ýêäïóçò 2.0.l Þ ìåãáëýôåñçò.
ÁíáôñÝîôå áðßóçò óôçí imagecopyresized().
Ç óõíÜñôçóç imagecopyresized() áíôéãñÜöåé ìßá ðåñéï÷Þ, ó÷Þìáôïò ôåôñáãþíïõ, ìßáò åéêüíáò óå ìßá Üëëç. Ç ðáñÜìåôñïò dst_im åßíáé ç åéêüíá ðñïïñéóìüò, åíþ ç src_im åêöñÜæåé ôïí source image identifier. ÅÜí ïé óõíôåôáãìÝíåò ðëÜôïò êáé ýøïò ðñïïñéóìïý êáé ðçãÞò äéáöÝñïõí, èá õðÜñîåé ç áðáñáßôçôç ìåãÝèõíóç Þ óìßêñõíóç ôïõ ìÝñïõò ôçò åéêüíáò. Ïé óõíôåôáãìÝíåò áíáöÝñïíôáé óôçí ðÜíù áñéóôåñÞ åéêüíá. ÁõôÞ ç óõíÜñôçóç ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá áíôéãñáöïýí ðåñéï÷Ýò ôçò ßäéáò åéêüíáò ìÝóá óå áõôÞí (åÜí ç dst_im åßíáé ç ßäéá ìå ôçí src_im), áëëÜ åÜí ïé ðåñéï÷Ýò áëëçëïêáëýðôïíôáé ôï áðïôÝëåóìá åßíáé áðñüâëåðôï.
Óçìåßùóç: ÕðÜñ÷åé Ýíá ðñüâëçìá ëüãù ôùí ðåñéïñéóìþí ôçò ðáëÝôôáò ôçò åéêüíáò (255+1 ÷ñþìáôá). Ôï íá êÜíåéò resampling Þ filtering ìßá åéêüíá óõíÞèùò ÷ñåéÜæåôáé ðåñéóóüôåñá áðü 255, Ýíá åéäüò ðñïóÝããéóçò ÷ñçóéìïðïéåßôáé ãéá ôïí õðïëïãéóìü ôïõ íÝïõ resampled pixel êáé ôïõ ÷ñþìáôüò ôïõ. Ìå ìßá ðáëÝôôá ìßáò åéêüíáò ðñïóðáèïýìå íá äåóìåýóïõìå Ýíá íÝï ÷ñþìá, åÜí áõôü áðïôý÷åé, åðéëÝãïõìå ôï ÷ñþìá ðïõ Ý÷åé õðïëïãéóôåß ùò ôï ðéï êïíôéíü (èåùñçôéêÜ). Áõôü äåí åßíáé ðÜíôá ôï ðéï êïíôéíü ïðôéêÜ ÷ñþìá. Áõôü ìðïñåß íá ðñïêáëÝóåé Ýíá ðåñßåñãï áðïôÝëåóìá, üðùò êåíÝò (Þ ïðôéêÜ êåíÝò) åéêüíåò. Ãéá íá îåðåñÜóåôå áõôü ôï ðñüâëçìá, ðáñáêåëåßóôå íá ÷ñçóéìïðïéåßôå ìßá truecolor åéêüíá, üðùò áõôÞ ðïõ äçìéïõñãåßôáé áðü ôç óõíÜñôçóç imagecreatetruecolor(), ùò åéêüíá ðñïïñéóìïý.
ÁíáôñÝîôå åðßóçò óôçí imagecopyresampled().
Ç óõíÜñôçóç imagecreate() åðéóôñÝöåé Ýíáí image identifier ðïõ áíáðáñéóôÜ ìßá êåíÞ åéêüíá ìåãÝèïõò x_size êáé y_size.
Óõíéóôïýìå ôç ÷ñÞóç ôçò imagecreatetruecolor().
ÐáñÜäåéãìá 1. Äçìéïõñãßá ìßáò íÝáò GD åéêüíáò êáé ôï output áõôÞò.
|
ÁíáôñÝîôå åðßóçò óôçí imagecreatetruecolor().
(PHP 4 >= 4.1.0, PHP 5)
imagecreatefromgd2 -- Äçìéïõñãåßóôå ìßá íÝá åéêüíá áðü Ýíá GD2 áñ÷åßï Þ Ýíá URL
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
(PHP 4 >= 4.1.0, PHP 5)
imagecreatefromgd2part -- Äçìéïõñãåßóôå ìßá íÝá åéêüíá áðü Ýíá äïóìÝíï ìÝñïò åíüò GD2 áñ÷åßïõ Þ åíüò URL
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
(PHP 4 >= 4.1.0, PHP 5)
imagecreatefromgd -- Äçìéïõñãåßóôå ìßá íÝá åéêüíá áðü Ýíá GD áñ÷åßï Þ Ýíá URL
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
Ç óõíÜñôçóç imagecreatefromgif() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ôçí åéêüíá ðïõ áðïêôÜôáé áðü ôï äïóìÝíï filename (áñ÷åßï).
Óå ðåñßðôùóç áðïôõ÷ßáò ç imagecreatefromgif() åðéóôñÝöåé Ýíá Üäåéï string. Åðßóçò äßíåé ùò Ýîïäï Ýíá ìÞíõìá ëÜèïõò, ôï ïðïßï äõóôõ÷þò åìöáíßæåôáé óáí Ýíá broken link óå Ýíáí browser. Ãéá ôç äéåõêüëõíóç ôïõ debugging ôï áêüëïõèï ðáñÜäåéãìá èá ðáñÜîåé Ýíá ëÜèïò GIF:
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ãéá ôç äéá÷åßñéóç åíüò ëÜèïõò êáôÜ ôç äéÜñêåéá äçìéïýñãéáò (ìå ôçí Üäåéá ôïõ vic@zymsys.com)
|
Óçìåßùóç: Áðü ôç óôéãìÞ ðïõ áöáéñÝèçêå ç õðïóôÞñéîç GIF áðü ôç GD âéâëéïèÞêç (Ýêäïóç 1.6), ç óõíÜñôçóç áõôÞ äåí åßíáé äéáèÝóéìç åÜí ÷ñçóéìïðïéåßôå áõôÞ ôçí Ýêäïóç ôçò âéâëéïèÞêçò.
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
(PHP 3>= 3.0.16, PHP 4 , PHP 5)
imagecreatefromjpeg -- Äçìéïõñãåßóôå ìßá íÝá åéêüíá áðü Ýíá áñ÷åßï Þ Ýíá URLÇ óõíÜñôçóç imagecreatefromjpeg() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ôçí åéêüíá ðïõ áðïêôÜôáé áðü ôï äïóìÝíï filename.
Óå ðåñßðôùóç áðïôõ÷ßáò ç imagecreatefromjpeg() åðéóôñÝöåé Ýíá Üäåéï string. Åðßóçò äßíåé ùò Ýîïäï Ýíá ìÞíõìá ëÜèïõò, ôï ïðïßï äõóôõ÷þò åìöáíßæåôáé ùò Ýíá broken link óå Ýíáí browser. Ãéá ôç äéåõêüëõíóç ôïõ debugging ôï áêüëïõèï ðáñÜäåéãìá èá ðáñÜîåé Ýíá ëÜèïò JPEG:
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ãéá ôç äéá÷åßñéóç åíüò ëÜèïõò êáôÜ ôç äéÜñêåéá ôçò äçìéïõñãßáò (ìå ôçí Üäåéá ôïõ vic@zymsys.com )
|
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
(PHP 3>= 3.0.13, PHP 4 , PHP 5)
imagecreatefrompng -- Äçìéïõñãåßóôå ìßá íÝá åéêüíá áðü Ýíá áñ÷åßï Þ Ýíá URLÇ óõíÜñôçóç imagecreatefrompng() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ôçí åéêüíá ðïõ áðïêôÜôáé áðü ôï äïóìÝíï filename.
Óå ðåñßðôùóç áðïôõ÷ßáò ç imagecreatefrompng() returns an empty string on failure. åðéóôñÝöåé Ýíá Üäåéï string. Åðßóçò äßíåé ùò Ýîïäï Ýíá ìÞíõìá ëÜèïõò, ôï ïðïßï äõóôõ÷þò åìöáíßæåôáé óáí Ýíá broken link óå Ýíáí browser. Ãéá ôç äéåõêüëõíóç ôïõ debugging ôï áêüëïõèï ðáñÜäåéãìá èá ðáñÜîåé Ýíá ëÜèïò PNG:
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ãéá ôç äéá÷åßñéóç åíüò ëÜèïõò êáôÜ ôç äéÜñêåé äçìéïõñãßáò (ìå ôçí Üäåéá ôïõ vic@zymsys.com)
|
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
(PHP 4 >= 4.0.4, PHP 5)
imagecreatefromstring -- Äçìéïõñãåßóôå ìßá íÝá åéêüíá áðü ôï image stream ôçò stringÇ óõíÜñôçóç imagecreatefromstring() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ôçí åéêüíá ðïõ áðïêôÜôáé áðü ôï äïóìÝíï string.
Ç óõíÜñôçóç imagecreatefromwbmp() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ôçí åéêüíá ðïõ áðïêôÜôáé áðü ôï äïóìÝíï filename.
Óå ðåñßðôùóç áðïôõ÷ßáò ç imagecreatefromwbmp() åðéóôñÝöåé Ýíá Üäåéï string. Åðßóçò äßíåé ùò Ýîïäï Ýíá ìÞíõìá ëÜèïõò, ôï ïðïßï äõóôõ÷þò åìöáíßæåôáé óáí Ýíá broken link óå Ýíáí browser. Ãéá ôç äéåõêüëõíóç ôïõ debugging ôï áêüëïõèï ðáñÜäåéãìá èá ðáñÜîåé Ýíá ëÜèïò WBMP:
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ãéá ôç äéá÷åßñéóç åíüò ëÜèïõò êáôÜ ôç äéÜñêåéá äçìéïýñãéáò (ìå ôçí Üäåéá ôïõ vic@zymsys.com)
|
Óçìåßùóç: Ç õðïóôÞñéîç ãéá ôïí WBMP ôýðï åßíáé äéáèÝóéìç ìüíï óôçí ðåñßðôùóç ðïõ ç PHP Ý÷åé ãßíåé compiled ìå ôçí GD-1.8 Þ íåüôåñç Ýêäïóç áõôÞò.
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
Ç óõíÜñôçóç imagecreatefromxbm() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ôçí åéêüíá ðïõ áðïêôÜôáé áðü ôï äïóìÝíï filename.
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
Ç óõíÜñôçóç imagecreatefromxpm() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ôçí åéêüíá ðïõ áðïêôÜôáé áðü ôï äïóìÝíï filename.
Õðüäåéîç: Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå Ýíá URL óáí Ýíá üíïìá áñ÷åßïõ ìå áõôÞ ôç óõíÜñôçóç áí ôá fopen wrappers Ý÷ïõí åíåñãïðïéçèåß. Äåßôå ôçí fopen() ãéá ðéï ðïëëÝò ëåðôïìÝñåéåò óôï ðþò íá ïñßóåôå ôï üíïìá ôïõ áñ÷åßïõ êáé ãéá Ýíá ÐáñÜñôçìá J êáôÜëïãï ôùí õðïóôçñéæüìåíùí URL ðñïôïêüëëùí.
Ðñïåéäïðïßçóç |
Ïé åêäüóåéò ôçò PHP ãéá Windows ðñéí ôçí 4.3.0 äåí Ý÷ïõí õðïóôÞñéîç ãéá ðñüóâáóç áðïìáêñõóìÝíùí (remote) áñ÷åßùí ìÝóù áõôÞò ôçò óõíÜñôçóçò, áêüìç êáé áí ôï allow_url_fopen åßíáé åíåñãïðïéçìÝíï. |
Ç óõíÜñôçóç imagecreatetruecolor() åðéóôñÝöåé Ýíáí image identifier ðïõ áíôéðñïóùðåýåé ìßá ìáýñç åéêüíá ìåãÝèïõò x_size êáé y_size.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP êáé áðáéôåß ôçí GD Ýêäïóçò 2.0.1 Þ ìåãáëýôåñçò
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äå ëåéôïõñãåß ãéá áñ÷åßá ôýðïõ GIF.
Äå óõíßóôáôáé ç ÷ñÞóç áõôÞò ôçò óõíÜñôçóçò. Áíôß áõôÞò ÷ñçóéìïðïåßóôå Ýíá óõíäéáóìü ôùí óõíáñôÞóåùí imagesetstyle() êáé imageline().
Ç óõíÜñôçóç imagedestroy() åëåõèåñþíåé êÜèå ìÝñïò ôçò ìíÞìçò ðïõ ó÷åôßæåôáé ìå ôçí åéêüíá image. Ç ðáñÜìåôñïò image åßíáé ï image identifier ðïõ åðéóôñÝöåôáé áðü ôç óõíÜñôçóç imagecreate().
Ç óõíÜñôçóç imageellipse() ó÷åäéÜæåé ìßá Ýëëåéøç ìå êÝíôñï ôï óçìåßï cx, cy (ç ðÜíù áñéóôåñÞ ãùíßá Ý÷åé óõíôåôáãìÝíåò 0, 0) ôçò åéêüíáò image. Ïé ðáñÜìåôñïé W êáé h êáèïñßæïõí ôï ðëÜôïò êáé ôï ýøïò ôçò Ýëëåéøçò, áíôßóôïé÷á. Ôï ÷ñþìá ôçò Ýëëåéøçò êáèïñßæåôáé ìå ôçí ðáñÜìåôñï color.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP êáé áðáéôåß GD Ýêäïóçò 2.0.2 Þ ìåãáëýôåñçò, ðïõ ìðïñåß íá áðïêôçèåß áðü ôçí éóôïóåëßäá http://www.boutell.com/gd/
ÁíáôñÝîôå åðßóçò óôçí imagearc().
Ç óõíÜñôçóç imagefill() åêôåëåß Ýíá flood fill îåêéíþíôáò áðü ôï óçìåßï x, y (ç ðÜíù áñéóôåñÞ ãùíßá Ý÷åé óõíôåôáãìÝíåò 0, 0) ìå ÷ñþìá color óôçí åéêüíá image.
Ç óõíÜñôçóç imagefilledarc() ó÷åäéÜæåé ìßá ìåñéêÞ Ýëëåéøç ìå êÝíôñï áõôÞò ôï óçìåßï cx, cy (ç ðÜíù áñéóôåñÞ ãùíßá Ý÷åé óõíôåôáãìÝíåò 0, 0) óôçí åéêüíá image. Ïé ðáñÜìåôñïé W êáé h êáèïñßæïõí ôï ðëÜôïò êáé ôï ýøïò ôçò Ýëëåéøçò, áíôßóôïé÷á, åíþ ôá óçìåßá áñ÷Þò êáé ôÝëïõò ðñïóäéïñßæïíôáé óå ìïßñåò ìå ôéò ðáñáìÝôñïõò s êáé e. Ç ðáñÜìåôñïò style åßíáé Ýíá bitwise OR ìå ôéò áêüëïõèåò ðéèáíÝò ôéìÝò:
IMG_ARC_PIE
IMG_ARC_CHORD
IMG_ARC_NOFILL
IMG_ARC_EDGED
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP êáé ÷ñåéÜæåôáé ôçí GD Ýêäïóçò 2.0.1
Ç óõíÜñôçóç imagefilledellipse() ó÷åäéÜæåé ìßá ìåñéêÞ Ýëëåéøç ìå êÝíôñï áõôÞò ôï óçìåßï cx, cy (ç ðÜíù áñéóôåñÞ ãùíßá Ý÷åé óõíôåôáãìÝíåò 0, 0) óôçí åéêüíá image. Ïé ðáñÜìåôñïé W êáé h êáèïñßæïõí ôï ðëÜôïò êáé ôï ýøïò ôçò Ýëëåéøçò, áíôßóôïé÷á. Ç Ýëëåéøç ãåìßæåé ìå ôï ÷ñþìá color.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP êáé áðáéôåß GD Ýêäïóçò 2.0.1 Þ ìåãáëýôåñçò
ÁíáôñÝîôå åðßóçò óôçí imagefilledarc().
Ç óõíÜñôçóç imagefilledpolygon() äçìéïõñãåß Ýíá ãåìéóìÝíï ðïëýãùíï óôçí åéêüíá image. Ç ðáñÜìåôñïò points åßíáé Ýíá PHP array ðïõ ðåñéÝ÷åé ôçò êïñõöÝò ôïõ ðïëõãþíïõ, ð.÷. points[0] = x0, points[1] = y0, points[2] = x1, points[3] = y1, êëð. Ç ðáñÜìåôñïò num_points åßíáé ï óõíïëéêüò áñéèìüò êïñõöþí.
Ç óõíÜñôçóç imagefilledrectangle() äçìéïõñãåß Ýíá ãåìéóìÝíï ïñèïãþíéï ÷ñþìáôïò color óôçí åéêüíá image îåêéíþíôáò áðü ôéò ðÜíù áñéóôåñÜ óõíôåôáãìÝíåò x1, y1 êáé ôåëåéþíïíôáò óôéò êÜôù áñéóôåñÜ x2, y2. Ôï óçìåßï 0, 0 åßíáé ç ðÜíù áñéóôåñÞ ãùíßá ôçò åéêüíáò.
Ç óõíÜñôçóç imagefilltoborder() åêôåëåß Ýíá performs a flood fill, ôï border ôïõ ïðïßïõ ïñßæåôáé áðü ôçí border. Ôï óçìåßï åêêßíçóçò ôïõ ãåìßóìáôïò åßíáé ôï x, y (ç ðÜíù áñéóôåñá ãùíßá Ý÷åé óõíôåôáãìÝíåò 0, 0) êáé ç ðåñéï÷Þ ãåìßæåé ìå ôï ÷ñþìá color.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This function is only available if PHP is compiled with the bundled version of the GD library.
ÅðéóôñÝöåé ôï ýøïò åíüò ÷áñáêôÞñá, ôçò ðñïóäéïñéóìÝíçò ãñáììáôïóåéñÜò, óå pixels.
ÁíáôñÝîôå åðßóçò óôéò: imagefontwidth() êáé imageloadfont().
ÅðéóôñÝöåé ôï ðëÜôïò åíüò ÷áñáêôÞñá ôçò ãñáììáôïóåéñÜò, óå pixels.
ÁíáôñÝîôå åðßóçò óôéò: imagefontheight() êáé imageloadfont().
(PHP 4 >= 4.1.0, PHP 5)
imageftbbox -- Äþóôå ôï bounding box åíüò êåéìÝíïõ ÷ñçóéìïðïéþíôáò ãñáììáôïóåéñÝò ìÝóù ôïõ freetype2
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
imagefttext -- ÃñÜøôå êåßìåíï óôçí åéêüíá ÷ñçóéìïðïéþíôáò ãñáììáôïóåéñÜ ìÝóù ôïõ FreeType 2
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ç óõíÜñôçóç imagegammacorrect() åöáñìüæåé ìßá gamma äéüñèùóç óå Ýíá gd image stream (image) äïèåßóçò ìßáò input gamma ôéìÞò, ìÝóù ôçò ðáñáìÝôñïõ inputgamma êáé ìßáò Üëëçò output gamma, ìÝóù ôçò outputgamma.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ç óõíÜñôçóç imagegd2() óôÝëíåé ìßá GD2 åéêüíá óôïí browser Þ óå Ýíá áñ÷åßï.
Ç ðñïáéñåôéêÞ ðáñÜìåôñïò type Ý÷åé åßôå ôçí ôéìÞ IMG_GD2_RAW åßôå ôçí IMG_GD2_COMPRESSED. Ç ðñïêáèïñéóìÝíç ôéìÞ åßíáé IMG_GD2_RAW.
Óçìåßùóç: Ïé ðñïáéñåôéêÝò ðáñÜìåôñïé chunk_size êáé type Ýãéíáí äéáèÝóéìåò áðü ôçí Ýêäïóç 4.3.2 ôçò PHP.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ç óõíÜñôçóç imagegif() äçìéïõñãåß Ýíá áñ÷åßï GIF ìå üíïìá áõôü ôçò image. Ç ðáñÜìåôñïò image åßíáé ç åðéóôñåöüìåíç ôéìÞ ôçò óõíÜñôçóçò imagecreate().
Ôï format ôçò åéêüíáò èá åßíáé GIF87a, åêôüò áðü ôçí ðåñßðôùóç ðïõ ç åéêüíá Ýãéíå äéáöáíÞò ìå ôçí imagecolortransparent(), üðïõ ôï format ôçò åéêüíáò èá åßíáé GIF89a.
Ç ðáñÜìåôñïò filename åßíáé ðñïáéñåôéêÞ, êáé áí ðáñáëåßðåôáé, ôï raw image stream èá óôáëåß áìÝóùò óôçí Ýîïäï. ÓôÝëíïíôáò Ýíáí image/gif content-type ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç header(), ìðïñåßôå íá äçìéïõñãåßóåôå Ýíá PHP script ðïõ óôÝëíåé áìÝóùò óôç Ýîïäï åéêüíåò ôýðïõ GIF.
Óçìåßùóç: Áðü ôüôå ðïõ áöáéñÝèçêå áðü ôçí GD âéâëéïèÞêç (Ýêäïóç 1.6) ç õðïóôÞñéîç ãéá ôïí ôýðï GIF, ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç áí ÷ñçóéìïðïåßôå ôç óõãêåêñéìÝíç Ýêäïóç ôçò âéâëéïèÞêçò.
Ôï áêüëïõèï snippet óáò åðéôñÝðåé íá ãñÜøåôå ðåñéóóüôåñï portable PHP åöáñìïãÝò ìå ôïí áõôüìáôï åíôïðéóìü ôïõ ôýðïõ ôçò GD õðïóôÞñéîçò ðïõ åßíáé äéáèÝóéìïò. Áíôéêáôáóôåßóôå ôï header ("Content-type: image/gif"); imagegif ($im); ìå ôï ðéï åõÝëéêôï:
<?php if (function_exists("imagegif")) { header ("Content-type: image/gif"); imagegif ($im); } elseif (function_exists("imagejpeg")) { header ("Content-type: image/jpeg"); imagejpeg ($im, "", 0.5); } elseif (function_exists("imagepng")) { header ("Content-type: image/png"); imagepng ($im); } elseif (function_exists("imagewbmp")) { header ("Content-type: image/vnd.wap.wbmp"); imagewbmp ($im); } else die("No image support in this PHP server"); ?>
Óçìåßùóç: Óôçí Ýêäïóç 4.0.2 ìðïñåßôå íá ÷ñçóéìïðïåßóåôå ôç óõíÜñôçóç imagetypes() óôç èÝóç ôçò function_exists(), ðïõ ÷ñçóéìïðïéåßôáé óôçí 3.0.18, ðñïêåéìÝíïõ íá åëÝã÷åôå ôïõò õðïóôçñéæüìåíïõò ôýðïõò åéêüíáò:
ÁíáôñÝîôå åðßóçò óôéò: imagepng(), imagewbmp(), imagejpeg() êáé imagetypes().
Ç óõíÜñôçóç imageinterlace() èÝôåé ôï interlace bit 1 Þ 0. ÅÜí ôï interlace åßíáé 1 ç åéêüíá èá ãßíåé interlaced, áëëéþò ü÷é.
ÅÜí Ý÷åé ôåèåß ôï interlace êáé ç åéêüíá ÷ñçóéìïðïéåßôáé ùò JPEG, ôüôå ç åéêüíá èá äçìéïõñãçèåß ùò ìßá progressive JPEG.
ÁõôÞ ç óõíÜñôçóç äåß÷íåé åÜí Ý÷åé ôåèåß ôï interlace bit ãéá ôç óõãêåêñéìÝíç åéêüíá.
(no version information, might be only in CVS)
imageistruecolorcreate -- ÅëÝã÷åé åÜí ìßá åéêüíá åßíáé truecolor.Ç óõíÜñôçóç imageistruecolor() åëÝã÷åé åÜí ìßá åéêüíá åßíáé truecolor.
ÁíáôñÝîôå åðßóçò óôçí imagecreatetruecolor().
Ç óõíÜñôçóç imagejpeg() äçìéïõñãåß Ýíá áñ÷åßï JPEG ìå üíïìá áõôü ôçò image. Ç ðáñÜìåôñïò image åßíáé ç åðéóôñåöüìåíç ôéìÞ ôçò óõíÜñôçóçò imagecreate().
Ç ðáñÜìåôñïò filename åßíáé ðñïáéñåôéêÞ, êáé åÜí ðáñáëåßðåôáé, ôï raw image stream èá óôáëåß áìÝóùò óôçí Ýîïäï. Ãéá íá ðáñáâëÝøåôå ôç filename ðñïêåéìÝíïõ íá ðñïóäéïñßóåôå ôçí quality, áðëÜ ÷ñçóéìïðïéåßóôå Ýíá êåíü string (''). ÓôÝëíïíôáò Ýíáí image/jpeg content-type ÷ñçóéìïðïéþíôáò ôç óõíÜñôçóç header(), ìðïñåßôå íá äçìéïõñãåßóåôå Ýíá PHP script, ðïõ íá óôÝëíåé áìÝóùò óôçí Ýîïäï åéêüíåò ôýðïõ JPEG.
Óçìåßùóç: Ç JPEG support åßíáé äéáèÝóéìç ìüíï óôçí ðåñßðôùóç ðïõ ç PHP ãßíåé compiled ìå ôçí GD-1.8 Þ íåþôåñç Ýêäïóç áõôÞò.
Ç ðáñÜìåôñïò quality åßíáé ðñïáéñåôéêÞ, êáé ðïéêßëëåé áðü ôï 0 (÷åéñüôåñç ðïéüôçôá, ìéêñüôåñï áñ÷åßï) Ýùò ôï 100 (êáëýôåñç ðïéüôçôá, ìåãáëýôåñï áñ÷åßï). Ç ðñïêáèïñéóìÝíç åßíáé ç IJG ôéìÞ ðïéüôçôáò (ðåñßðïõ 75).
ÅÜí èÝëåôå íá ðáñÜîåôå Progressive JPEGs, ðñÝðåé íá èÝóåôå ôï interlacing ìå ôç óõíÜñôçóç imageinterlace().
ÁíáôñÝîôå åðßóçò óôéò: imagepng(), imagegif(), imagewbmp(), imageinterlace() êáé imagetypes().
(PHP 4 >= 4.3.0, PHP 5)
imagelayereffect -- Set the alpha blending flag to use the bundled libgd layering effectsÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This function is only available if PHP is compiled with the bundled version of the GD library.
Ç óõíÜñôçóç imageline() ó÷åäéÜæåé ìßá ãñáììÞ áðü ôï óçìåßï x1, y1 Ýùò ôï x2, y2 (ðÜíù áñéóôåñÜ âñßóêåôáé ôï óçìåßï 0, 0) óôçí åéêüíá im ÷ñþìáôïò color.
ÁíáôñÝîôå åðßóçò óôéò: imagecreate() êáé imagecolorallocate().
Ç óõíÜñôçóç imageloadfont() öïñôþíåé ìßá, êáèïñéóìÝíç áðü ôï ÷ñÞóôç, bitmap ãñáììáôïóåéñÜ êáé åðéóôñÝöåé Ýíáí identifier ãéá áõôÞí (ðïõ åßíáé ðÜíôá ìåãáëýôåñïò áðü ôï 5, Ýôóé þóôå íá ìçí õðÜñ÷åé conflict ìå ôéò built-in ãñáììáôïóåéñÝò).
Ï ôýðïò ôïõ áñ÷åßïõ ãñáììáôïóåéñÜò åßíáé äõáäéêüò êáé åîáñôÜôáé áðü ôçí áñ÷éôåêôïíéêÞ. Áõôü óçìáßíåé üôé ðñÝðåé íá ðáñÜîåôå ôá áñ÷åßá ãñáììáôïóåéñþí óå ßäéï ôýðï CPU ìå áõôüí ôïõ ìç÷áíÞìáôïò óôï ïðïßï ôñÝ÷åôå ôçí PHP.
Ðßíáêáò 1. Ôýðïò áñ÷åßùí ãñáììáôïóåéñþí
ÈÝóç byte | Ôýðïò äåäïìÝíùí C | ÐåñéãñáöÞ |
---|---|---|
byte 0-3 | int | ÐëÞèïò ÷áñáêôÞñùí ôçò ãñáììáôïóåéñÜò |
byte 4-7 | int | Ç ôéìÞ ôïõ ðñþôïõ ÷áñáêôÞñá ôçò ãñáììáôïóåéñÜò (óõíÞèùò ôï 32 åßíáé ôï êåíü äéÜóôçìá) |
byte 8-11 | int | Ôï ðëÜôïò óå pixel êÜèå ÷áñáêôÞñá |
byte 12-15 | int | Ôï ýøïò óå pixel êÜèå ÷áñáêôÞñá |
byte 16- | char | ¸íá array ìå äåäïìÝíá ÷áñáêôÞñåò, Ýíá byte áíÜ pixel ãéá êÜèå ÷áñáêôÞñá, êáé Ýíá óýíïëï áðü (nchars*width*height) bytes. |
ÁíáôñÝîôå åðßóçò óôéò: imagefontwidth() êáé imagefontheight().
Ç óõíÜñôçóç imagepalettecopy() áíôéãñÜöåé ôçí ðáëÝôôá ôçò åéêüíáò source óôçí åéêüíá destination.
(PHP 3>= 3.0.13, PHP 4 , PHP 5)
imagepng -- ÓôÝëíåé ìßá PNG åéêüíá åßôå óôïí browser åßôå óå Ýíá áñ÷åßïÇ óõíÜñôçóç imagepng() óôÝëíåé Ýíá GD image stream (image) óå PNG format óôï standard output (óõíÞèùò óôïí browser) Þ, åÜí ïñßæåôáé ôï üíïìá ôïõ áñ÷åßïõ áðü ôçí filename óôÝëíåé ôçí åéêüíá óå áõôü.
ÁíáôñÝîôå åðßóçò óôéò: imagegif(), imagewbmp(), imagejpeg() êáé imagetypes().
Ç óõíÜñôçóç imagepolygon() ó÷åäéÜæåé Ýíá ðïëýãùíï óôçí åéêüíá. Ç ðáñÜìåôñïò points åßíáé Ýíá PHP array, ðïõ ðåñéÝ÷åé ôéò êïñõöÝò ôïõ ðïëõãþíïõ, ð.÷. points[0] = x0, points[1] = y0, points[2] = x1, points[3] = y1, êëð. Ç num_points áíôéðñïóùðåýåé ôï óõíïëéêü áñéèìü ôùí óçìåßùí (êïñõöþí).
ÁíáôñÝîôå åðßóçò óôéò: imagecreate() êáé imagecreatetruecolor().
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
imagepsbbox -- Äþóôå ôï bounding box åíüò êåéìÝíïõ ÷ñçóéìïðïéþíôáò PostScript Type1 ãñáììáôïóåéñÝòÇ ðáñÜìåôñïò size åêöñÜæåôáé óå pixels.
Ç ðáñÜìåôñïò space óáò åðéôñÝðåé íá áëëÜîåôå ôçí ðñïêáèïñéóìÝíç ôéìÞ ôïõ äéáóôÞìáôïò ìßáò ãñáììáôïóåéñÜò. ÁõôÞ ç ðïóüôçôçôá ðñïóôßèåôáé óôçí êáíïíéêÞ êáé ìðïñåß íá åßíáé áñíçôéêÞ.
Ç ðáñÜìåôñïò tightness óáò åðéôñÝðåé íá åëÝã÷åôáé ôï ðëÞèïò ôùí êåíþí ìåôáîý ÷áñáêôÞñùí. ÁõôÞ ç ôéìÞ ðñïóôßèåôáé óôçí êáíïíéêÞ êáé ìðïñåß íá åßíáé áñíçôéêÞ.
Ç ðáñÜìåôñïò angle åêöñÜæåôáé óå ìïßñåò.
Ïé ðáñÜìåôñïé space êáé tightness åêöñÜæïíôáé óå ìïíÜäåò ÷áñáêôÞñùí êåíïý, üðïõ 1 ìïíÜäá åßíáé ôï 1/1000óôï åíüò ôåôñáãùíéäßïõ.
Ïé ðáñÜìåôñïé space, tightness, êáé angle åßíáé ðñïáéñåôéêÝò.
Ôï bounding box õðïëïãßæåôáé ÷ñçóéìïðïéþíôáò ðëçñïöïñßåò ðïõ åßíáé äéáèÝóéìåò áðü character metrics, êáé, äõóôõ÷þò, õðÜñ÷åé ìéêñÞ äéáöïñÜ ìåôáîý ôùí áðïôåëåóìÜôùí ðïõ ëáìâÜíïíôáé áðü ôï rasterizing ôïõ êåéìÝíïõ. ÅÜí ç ãùíßá åßíáé 0 ìïéñþí, ìðïñåßôå íá õðïëïãßóåôå üôé ôï êåßìåíï ÷ñåéÜæåôáé 1 pixel, åðéðëÝïí, ðïñïò êÜèå êáôåýèõíóç.
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé Ýíá array, ðïõ ðåñéÝ÷åé ôá áêüëïõèá óôïé÷åßá:
0 | ÊÜôù áñéóôåñÞ x-óõíôåôáãìÝíç |
1 | ÊÜôù áñéóôåñÞ y-óõíôåôáãìÝíç |
2 | ÐÜíù äåîéÜ x-óõíôåôáãìÝíç |
3 | ÐÜíù äåîéÜ y-óõíôåôáãìÝíç |
ÁíáôñÝîåôå åðßóçò óôçí imagepstext().
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
imagepscopyfont -- Äçìéïõñãåßóôå Ýíá áíôßãñáöï ìßáò, Þäç, åãêáôåóôçìÝíçò ãñáììáôïóåéñÜò, ãéá ðåñáéôÝñù åðåîåñãáóßá×ñçóéìïðïéåßóôå áõôÞí ôç óõíÜñôçóç åÜí èÝëåôå íá ôñïðïðïéåßóåôå ìéá ãñáììáôïóåéñÜ, ãéá ðáñÜäåéãìá íá ôçí åðåêôåßíåôå, íá ôçí ìéêñýíåôáé Þ íá áëëÜîåôå ôçí êùäéêïðïßçóç ôùí ÷áñáêôÞñùí ôçò, áëëÜ ðñÝðåé íá êñáôÞóåôå êáé ôï ðñïôüôõðï áõôÞò. ÐñïóÝîôå üôé ç ãñáììáôïóåéñÜ ðïõ èÝëåôå íá áíôéãñÜøåôå ðñÝðåé íá Ý÷åé áðïêôçèåß áðü ôç ÷ñÞóç ôçò óõíÜñôçóçò imagepsloadfont(), êé ü÷é áðëÜ Ýíá Ýíá ïðïéïäÞðïôå áíôßãñáöï ãñáììáôïóåéñÜò. Ìðïñåßôå ùóôüóï íá êÜíåôå áëëáãÝò óå áõôÞ ðñéí ôçí áíôéãñáöÞ ôçò.
Áöïý ÷ñçóéìïðïéåßóåôå áõôÞ ôç óõíÜñôçóç, ðñÝðåé, áðü ìüíïé óáò, íá åëåõèåñþóåôå ôéò ãñáììáôïóåéñÝò ðïõ áðïêôÞèçêáí ìå áõôüí ôïí ôñüðï êáé áíôßóôñïöá. Áëëéþò ôï script óáò èá êñåìÜóåé.
ÅÜí üëá ðÞãáí êáëÜ, èá åðéóôñáöåß Ýíáò Ýãêõñïò font index, ï ïðïßïò ìðïñåß íá ÷ñçóéìïðïéçèåß êáé ãéá Üëëïõò óêïðïýò. Óå áíôßèåôç ðåñßðôùóç èá åðéóôñáöåß ç ôéìÞ FALSE êáé èá ôõðùèåß Ýíá ìÞíõìá ðïõ ðåñéãñáöåß ôï ôß ðÞãå ëÜèïò.
ÁíáôñÝîôå åðßóçò óôçí imagepsloadfont().
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
imagepsencodefont -- ÁëëÜîôå ôï äéÜíõóìá êùäéêïðïßçóçò ÷áñáêôÞñùí ìßáò ãñáììáôïóåéñÜòÖïñôþíåé Ýíá äéÜíõóìá êùäéêïðïßçóçò ÷ñáêôÞñùí áðü Ýíá áñ÷åßï êáé ìåôáâÜëëåé ôï áíôßóôïé÷ï ôçò ãñáììáôïóåéñÜò ðñïò áõôü. Êáèþò ôá äéáíýóìáôá PostScript ãñáììáôïóåéñþí äåí ðåñéÝ÷ïõí üëïõò ôïõò ÷áñáêôÞñåò Üíù ôïõ 127, èá åðéèõìåßôå ïðùóäÞðïôå íá áëëÜîåôå áõôÞí ôçí êáôÜóôáóç åÜí ÷ñçóéìïðïéåßôå ìßá ãëþóóá åêôüò ôçò áããëéêÞò. Ï áêñéâÞò ôýðïò ôïõ áñ÷åßïõ ðåñéãñÜöåôáé óôçí ôåêìçñßùóç ôùí T1libs. Ç T1lib óõíïäåýåôáé áðü äýï Ýôïéìá ãéá ÷ñÞóç áñ÷åßá, ôï IsoLatin1.enc êáé ôï IsoLatin2.enc.
ÅÜí ÷ñçóéìïðïéåßôáé óõ÷íÜ áõôÞ ôç óõíÜñôçóç, Ýíáò ðïëý êáëýôåñïò ôñüðïò íá êáèïñßóåôáé ôçí êùäéêïðïßçóç åßíáé íá áëëÜîåôå ôï ps.default_encoding ôïõ configuration file þóôå íá äåß÷íåé óôï óùóôü áñ÷åßï êùäéêïðïßçóçò. ¸ôóé üëåò ïé ãñáììáôïóåéñÝò ðïõ ÷ñçóéìïðïåßôáé èá Ý÷ïõí áõôïìÜôùò ôç óùóôÞ êùäéêïðïßóç.
Åðåêôåßíåôáé Þ óõññéêíþóôå ìßá ãñáììáôïóåéñÜ (font_index), åÜí ç ôéìÞ ôçò ðáñáìÝôñïõ extend åßíáé ìéêñüôåñç ôçò ìïíÜäáò ôüôå ôç óõññéêíþíåôå.
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
imagepsfreefont -- Åëåõèåñþóôå ìíÞìç ðïõ ÷ñçóéìïðéåßôáé áðü ìßá PostScript Type 1 ãñáììáôïóåéñÜÇ imagepsfreefont() åëåõèåñþíåé ìíÞìç ðïõ ÷ñçóéìïðïéåßôáé áðü ìßá PostScript Type 1 ãñáììáôïóåéñÜ.
ÁíáôñÝîôå åðßóçò óôçí imagepsloadfont().
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
imagepsloadfont -- Öïñôþíåé ìßá PostScript Type 1 ãñáììáôïóåéñÜ áðü Ýíá áñ÷åßïÓå ðåñßðôùóç ðïõ ç äéáäéêáóßá Þôáí óùóôÞ, èá åðéóôñáöåß ï äåßêôçò ìßáò Ýãêõñçò ãñáììáôïóåéñÜò, ï ïðïßïò ìðïñåß íá ÷ñçóéìïðïéçèåß ðåñáéôÝñù. Óå Üëëç ðåñßðôùóç ç óõíÜñôçóç åðéóôñÝöåé ôçí ôéìÞ FALSE êáé åìöáíßæåé Ýíá ìÞíõìá ðïõ ðåñéãñÜöåé ôé ðÞãå ëÜèïò, ôï ïðïßï äåí ìðïñåßôå íá äéáâÜóåôå áð' åõèåßáò, áöïý åßíáé óå ìïñöÞ åéêüíáò.
<?php header ("Content-type: image/jpeg"); $im = imagecreate (350, 45); $black = imagecolorallocate ($im, 0, 0, 0); $white = imagecolorallocate ($im, 255, 255, 255); $font = imagepsloadfont ("bchbi.pfb"); // or locate your .pfb files on your machine imagepstext ($im, "Testing... It worked!", $font, 32, $white, $black, 32, 32); imagepsfreefont ($font); imagejpeg ($im, "", 100); //for best quality...your mileage may vary imagedestroy ($im); ?> |
ÁíáôñÝîôå åðßóçò óôçí imagepsfreefont().
Äþóôå êëßóç óôá óôïé÷åßá ìßáò ãñáììáôïóåéñÜò, ç ïðïßá áíôéðñïóùðåýåôáé áðü ôçí ðáñÜìåôñï font_index. Ç êëßóç áõôÞ ðñïóäéïñßæåôáé áðü ôçí slant.
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
imagepstext -- Ó÷åäéÜóôå Ýíá text string ðÜíù óå ìßá åéêüíá ìå ÷ñÞóç PostScript Type1 ãñáììáôïóåéñÜòÇ ðáñÜìåôñïò foreground áíáöÝñåôáé óôï ÷ñþìá ôïõ êåéìÝíïõ. Ç ðáñÜìåôñïò Background åêöñÜæåé ôï ÷ñþìá óôï ïðïßï ôï êåßìåíï èá ðñïóðáèÞóåé íá áëëÜîåé ìå antialiasing. Óôçí ðñáãìáôéêüôçôá äå ÷ñùìáôßæïíôáé pixels ìå ôï ÷ñþìá background, Ýôóé ç background åéêüíá äåí åßíáé áðáñáßôçôï íá åßíáé óõìðáãïýò ÷ñþìáôïò.
Ïé óõíôåôáãìÝíåò ðïõ äßíïíôáé áðü ôéò ðáñáìÝôñïõò x, y ðñïóäéïñßæïõí ôçí áñ÷Þ (Þ ôç ó÷åôéêÞ èÝóç) ôïõ ðñþôïõ ÷áñáêôÞñá (êáôÜ ðñïóÝããéóç ôçí êÜôù áñéóôåñÞ ãùíßá ôïõ ÷áñáêôÞñá). ÁõôÝò ïé ðáñÜìåôñïé äéáöÝñïõí áðü áõôÝò ôçò óõíÜñôçóçò imagestring(), üðïõ ïé x, y ðñïóäéïñßæïõí ôçí ðÜíù áñéóôåñÞ ãùßá ôïõ ðñþôïõ ÷áñáêôÞñá. ÁíáôñÝîôå óôçí ôåêìçñßùóç ôïõ PostScipt ó÷åôéêÜ ìå ãñáììáôïóåéñÝò êáé óõóôÞìáôá ìÝôñçóçò, Ýáí Ý÷åôå äõóêïëßåò íá êáôáíïÞóåôå ôïí ôñüðï ëåéôïõñãßáò.
Ç ðáñÜìåôñïò space óáò åðéôñÝðåé íá áëëÜîåôå ôçí ðñïêáèïñéóìÝíç ôéìÞ ôïõ êåíïý óå ìßá ãñáììáôïóåéñÜ. ÁõôÞ ç ôéìÞ ðñïóôßèåôáé óôçí êáíïíéêÞ êáé ìðïñåß íá åßíáé áêüìá êáé áñíçôéêÞ.
Ç ðáñÜìåôñïò tightness óáò åðéôÝðåé íá åëÝãîåôå ôçí ôéìÞ ôïõ êåíïý ìåôáîý ôùí ÷áñáêôÞñùí. Ç ôéìÞ áõôÞ ðñüóôßèåôáé óôçí êáíïíéêü ðëÜôïò ôùí ÷áñáêôÞñùí êáé ìðïñåß íá åßíáé áñíçôéêÞ.
Ç ðáñÜìåôñïò angle äßíåôáé óå ìïßñåò.
Ç ðáñÜìåôñïò size åêöñÜæåôáé óå pixels.
Ç ðáñÜìåôñïò antialias_steps óáò åðéôñÝðåé íá åëÝã÷åôå ôï ðëÞèïò ôùí ÷ñùìÜôùí ðïõ ÷ñçóéìïðïéïýíôáé ãéá ôï antialiasing ôïõ êåéìÝíïõ. Ïé åðéôñåðüìåíåò ôéìÝò åßíáé ïé 4 êáé 16. Ãéá ìÝãåèïò êåéìÝíïõ ìéêñüôåñïõ ôïõ 20 ðñïôåßíåôáé ç õøçëüôåñç ôéìÞ, üðïõ ôï áðïôÝëåóìá óôçí ðïéüôçôá ôïõ êåéìÝíïõ åßíáé áñêåôÜ åìöáíÝò. Ìå ìåãáëýôåñá ìåãÝèç ÷ñçóéìïðïéåßôáé ôï 4. Åßíáé ëéãüôåñï âáñý õðïëïãéóôéêÜ.
Ïé ðáñÜìåôñïé space êáé tightness åêöñÜæïíôáé óå ìïíÜäåò êåíþí ÷áñáêôÞñùí, üðïõ ìßá ìïíÜäá éóïäõíáìåß ìå ôï 1/1000óôï åíüò em-square.
Ïé ðáñÜìåôñïé space, tightness, angle êáé antialias åßíáé ðñïáéñåôéêïß.
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá array, ðïõ ðåñéÝ÷åé ôá áêüëïõèá óôïé÷åßá:
0 | êÜôù áñéóôåñÞ x-óõíôåôòáãìÝíç |
1 | êÜôù áñéóôåñÞ y-óõíôåôáãìÝíç |
2 | ðÜíù äåîéÜ x-óõíôåôáãìÝíç |
3 | ðÜíù áñéóôåñÜ y-óõíôåôáãìÝíç |
ÁíáôñÝîôå åðßóçò óôçí imagepsbbox().
Ç óõíÜñôçóç imagerectangle() äçìéïõñãåß Ýíá ôåôñÜãùíï ÷ñþìáôïò col óôçí åéêüíá image îåêéíþíôáò áðü ôçí ðÜíù áñéóôåñü óçìåßï x1, y1 êáé ôåëåéþíïíôáò êÜôù äåîéÜ óôï óçìåßï x2, y2. Ôï óçìåßï 0, 0 åßíáé ç ðÜíù áñéóôåñÞ ãùíßá ôçò åéêüíáò.
ÐåñéóôñÝöåé ôçí åéêüíá src_im ÷ñçóéìïðïéþíôáò ôç äïèåßóá óå ìïßñåò angle. Ç ðáñÜìåôñïò bgd_color êáèïñßæåé ôï ÷ñþìá ôçò ìç êáëõðôüìåíçò ìåôÜ ôçí ðåñéóôñïöÞ ðåñéï÷Þò.
(PHP 4 >= 4.3.2, PHP 5)
imagesavealpha -- ÈÝóôå ôï flag ãéá íá áðïèçêåýóåôå üëåò ôéò alpha channel ðëçñïöïñßåò (êáèþò áíôéôßèåíôáé óå ìïíï÷ñùìáôéêÞ äéáöÜíåéá) üôáí óþæåôå PNG åéêüíåò.Ç óõíÜñôçóç imagesavealpha() ôï flag ãéá íá áðïèçêåýóåôå üëåò ôéò alpha channel ðëçñïöïñßåò (êáèþò áíôéôßèåíôáé óå ìïíï÷ñùìáôéêÞ äéáöÜíåéá) üôáí óþæåôå PNG åéêüíåò.
ÐñÝðåé íá áðåíåñãïðïßóåôå ôï alphablending (imagealphaplending($im,FALSE)), ãéá íá ôç ÷ñçóéìïðïßóåôå.
Ôï alpha channel äåí õðïóôçñßæåôáé áðü üëïõò ôïõò browsers. ÅÜí Ý÷åôå ðñüâëçìá ìå ôïí browser óáò, ðñïóðáèÞóôå íá öïñôþóåôå ôï script óå Ýíáí óõìâáôü ìå alpha channel browser, üðùò åßíáé ï ôåëåõôáßïò Mozilla.
ÁíáôñÝîôå åðßóçò óôçí imagealphablending().
Ç óõíÜñôçóç imagesetbrush() èÝôåé ôçí brush åéêüíá íá ÷ñçóéìïðïåßôå áðü üëåò ôéò óõíáñôÞóåéò ó÷åäßáóçò (üðùò åßíáé ïé imageline() êáé imagepolygon()) üôáí ó÷åäéÜæåôå ìå ôá åéäéêÜ ÷ñþìáôá IMG_COLOR_BRUSHED, IMG_COLOR_STYLEDBRUSHED.
Óçìåßùóç: Äå ÷ñåéÜæåôáé íá êÜíåôå êÜðïéá óõãêåêñéìÝíç åíÝñãåéá üôáí ôåëåéþóåôå ìå ôç ÷ñÞóç ôçò brush, áëëÜ åÜí êáôáôóôñÝæåôå ìßá brush åéêüíá, äåí ðñÝðåé íá ÷ñçóéìïðïåßôå ôá IMG_COLOR_BRUSHED, IMG_COLOR_STYLEDBRUSHED ÷ñþìáôá ìÝ÷ñéò üôïõ èÝóåôå íÝá colors until you have set a new åéêüíá!
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ ðñïóôÝèçêå óôçí PHP 4.0.6
Ç óõíÜñôçóç imagesetpixel() ó÷åäéÜæåé Ýíá pixel óôï óçìåßï x, y (ðÜíù áñéóôåñÜ åßíáé ôï 0, 0) óôçí åéêïíá image ÷ñþìáôïò color.
ÁíáôñÝîôå åðßóçò óôéò imagecreate() êáé imagecolorallocate().
Ç óõíÜñôçóç imagesetstyle() èÝôåé ôï óôõë ðïõ ðñüêåéôáé íá ÷ñçóéìïðïéçèåß áðü üëåò ôéò óõíáñôÞóåéò ó÷åäßáóçò ãñáììþí (üðùò åßíáé ïé imageline(), imagepolygon()) üôáí ó÷åäéÜæåôå ìå ôï åéäéêü ÷ñþìá IMG_COLOR_STYLED Þ ãñáììÝò åéêüíùò ìå ôï ÷ñþìá IMG_COLOR_STYLEDBRUSHED.
Ç ðáñÜìåôñïò style åßíáé Ýíá array áðü pixels. Ôï áêüëïõèï ðáñÜäåéãìá script ó÷åäéÜæåé ìßá äéáêåêïììÝíç ãñáììÞ áðü ôçí ðÜíù áñéóôåñÞ Ýùò ôçí êÜôù äåîéÜ ãùíßá ôïõ êáìâÜ:
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò imagesetstyle()
|
ÁíáôñÝîôå åðßóçò óôéò imagesetbrush(), imageline().
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ ðñïóôÝèçêå óôçí Ýêäïóç 4.0.6 ôçò PHP
Ç óõíÜñôçóç imagesetthickness() èÝôåé ôï ðÜ÷ïò ôùí ãñáììþí, üôáí ó÷åäéÜæåôå ôåôñÜãùíá, ðïëýãùíá, åëëåßøåéò êôë., óå thickness pixels.
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ ðñüóôåèçêå óôçí PHP 4.0.6 êáé áðáéôåß GD 2.0.1 ç íåþôåñï
Ç óõíÜñôçóç imagesettile() êáèïñßæåé ôçí tile åéêüíá ðïõ ðñüêåéôáé íá ÷ñçóéìïðïéçèåß áðü üëåò ôéò óõíáñôÞóåéò ãåìßóìáôïò ðåñéï÷þí (üðùò åßíáé ïé imagefill(), imagefilledpolygon()) üôáí ãåìßæåôå ìå ôï åéäéêü ÷ñþìá IMG_COLOR_TILED.
Tile åßíáé ìßá åéêüíá ðïõ ÷ñçóéìïðïåßôáé ãéá íá êáëýøåé ìßá ðåñéï÷Þ ìå Ýíá åðåíáëáìâáíüìåíï ó÷Ýäéï. ÏðïéáäÞðïôå GD åéêüíá ìðïñåß íá ÷ñçóéìïðïéçèåß óáí tile, êáé ìå ôï íá ðñïóäéïñßóåôå ôï äåßêôç äéáöáíïýò ÷ñþìáôïò ôçò tile åéêüíáò, ìå ôç óõíÜñôçóç imagecolortransparent(), ôï tile åðéôñÝðåé ôç äçìéïõñãßá êÜðïéùí ðåñéï÷þí ôïõ õðïóôñþìáôïò ðïõ íá ëÜìðïõí.
Óçìåßùóç: Äå ÷ñåéÜæåôáé íá êÜíåôå êÜðïéá åéäéêÞ åíÝñãåéá üôáí Ý÷åôå ôåëåéþóç ìå ôç ÷ñÞóç åíüò tile, áëëÜ åÜí êáôáóôñÝøåôå ôçí tile åéêüíá, äåí ðñÝðåé íá ÷ñçóéìïðïéåßôáé ôï IMG_COLOR_TILED ÷ñþìá Ýùò üôïõ ïñßóåôå ìßá íÝá tile åéêüíá!
Ç óõíÜñôçóç imagestring() ó÷åäéÜæåé Ýíá string s óôçí åéêüíá image óôï óçìåßï x, y (ðÜíù áñéóôåñÜ åßíáé ôï óçìåßï 0, 0) ÷ñþìáôïò col. ÅÜí ïé ãñáììáôïóåéñÜ åßíáé 1, 2, 3, 4 Þ 5, ÷ñçóéìïðïéåßôáé ìßá åóùôåñéêÞ.
ÁíáôñÝîôå åðßóçò óôçí imageloadfont().
Ç óõíÜñôçóç imagestringup() ó÷åäéÜæåé ôï string s êáèÝôùò óôçí åéêüíá image óôï óçìåßï x, y (êÜôù áñéóôåñÜ åßíáé ôï óçìåßï 0, 0) ìå ÷ñþìá col. ÅÜí ç ãñáììáôïóåéñÜ åßíáé 1, 2, 3, 4 or 5, ÷ñçóéìïðïéåßôáé ìßá åóùôåñéêÞ.
ÁíáôñÝîôå åðßóçò óôçí imageloadfont().
Ç óõíÜñôçóç imagesx() åðéóôñÝöåé ôï ðëÜôïò ôçò åéêüíáò image.
ÁíáôñÝîôå åðßóçò óôéò: imagecreate(), getimagesize() êáé imagesy().
Ç óõíÜñôçóç imagesy() åðéóôñÝöåé ôï ýøïò ôçò åéêüíáò image.
ÁíáôñÝîôå åðßóçò óôéò: imagecreate(), getimagesize() êáé imagesx().
(PHP 4 >= 4.0.6, PHP 5)
imagetruecolortopalette -- ÌåôáôñÝøôå ìßá true color åéêüíá óå ìßá palette åéêüíáÇ óõíÜñôçóç imagetruecolortopalette() ìåôñÝðåé ìßá truecolor åéêüíá óå ìßá ðáëÝôôá. Ï êþäéêáò áõôÞò ôçò óõíÜñôçóçò åß÷å áñ÷éêÜ ó÷åäéáóôåß áðü ôï Independent JPEG Group library code, êáé åßíáé Üñéóôïò. Ï êþäéêáò ôñïðïðïéÞèçêå ãéá íá äéáôçñÞóåé üóï ôï äéíáôüí ðåñéóóüôåñç alpha channel ðëçñïöïñßá ãßíåôáé, óôçí ðñïêýðôïõóá palette, êáé åðéðëÝïí ãéá íá äéáôçñÞóåé üóï ôï äõíáôüí êáëýôåñá ôá ÷ñþìáôá. Äå ëåéôïõñãåß üìùò ôüóï êáëÜ üóï õðïëïãéæüôáí. ÓõíÞèùò åßíáé ðñïôéìüôåñç ç ðáñáãùãÞ ìßáò truecolor åéêüíáò, ç ïðïßáò åîáóöáëßæåé ôçí õøçëüôåñç ðïéüôçôá åîüäïõ.
Ç ðáñÜìåôñïò dither äåß÷íåé åÜí ç åéêüíá ðñÝðåé íá ãßíåé dithered - åÜí åßíáé TRUE èá ÷ñçóéìïðïéçèåß dithering ôï ïðïßï èá Ý÷åé ùò áðïôÝëåóìá ìßá åéêüíá ìå ðåñéóóüôåñá óôßãìáôá áëëÜ ìå êáëýôåñç ðñïóÝããéóç ÷ñùìÜôùí.
Ç ðáñÜìåôñïò ncolors êáèïñßæåé ôï ìÝãéóôï áñéèìü ÷ñùìÜôùí ðïõ èá ðñÝðåé íá äéáôçñçèïýí óôçí ðáëÝôôá.
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ ðñïóôÝèçêå óôçí PHP 4.0.6 êáé áðáéôåß ôçí GD 2.0.1 Þ íåþôåñç
(PHP 3>= 3.0.1, PHP 4 , PHP 5)
imagettfbbox -- Äþóôå ôï bounding box åíüò êåéìÝíïõ ÷ñçóéìïðïéþíôáò TrueType ãñáììáôïóåéñÜÇ óõíÜñôçóç áõôÞ õðüëïãßæåé êáé åðéóôñÝöåé ôï bounding box óå pixels äïèÝíôïò åíüò TrueType êåéìÝíïõ.
Ôï string ôïõ ïðïßïõ èá ðáñèïýí ôá ìÝôñá.
Ôï ìÝãåèïò ôçò ãñáììáôïóåéñÜò óå pixels.
Ôï üíïìá ôïõ áñ÷åßïõ ôçò TrueType ãñáììáôïóéåñÜò. (Ìðïñåß íá åßíáé êáé Ýíá URL.) ÅîáñôÜôáé áðü ôç Ýêäïóç ôçò GD âéâëéïèÞêçò ðïõ ÷ñçóéìïðïéåß ç PHP, ôï áí èá ðñïóðáèÞóåé íá øÜîåé ãéá áñ÷åßá ðïõ äåí îåêéíïýí ìå '/' ìå ôï íá ôïðïèåôÞóåé ôï '.ttf' óôï üíïìá ôïõ áñ÷åßïõ êáé íá øÜîåé óå Ýíá ðñïóäéïñéóìÝíï áðü ôç âéâëéïèÞêç font path.
Ç ãùíßá óôçí ïðïßá èá ìåôñçèåß ôï text, óå âáèìïýò.
0 | êÜôù áñéóôåñÞ ãùíßá, X èÝóç |
1 | êÜôù áñéóôåñÞ ãùíßá, Y èÝóç |
2 | êÜôù äåîéÜ ãùíßá, X èÝóç |
3 | êÜôù äåîéÜ ãùíßá, Y èÝóç |
4 | ðÜíù äåîéÜ ãùíßá, X èÝóç |
5 | ðÜíù äåîéÜ ãùíßá, Y èÝóç |
6 | ðÜíù áñéóôåñÞ ãùíßá, X èÝóç |
7 | ðÜíù áñéóôåñÞ ãùíßá, Y èÝóç |
Ç óõíÜñôçóç áõôÞ ÷ñåéÜæåôáé ôçí GD âéâëéïèÞêç êáèþò åðßóçò êáé ôçí FreeType.
ÁíáôñÝîôå åðßóçò óôçí imagettftext().
(PHP 3, PHP 4 , PHP 5)
imagettftext -- ÃñÜøôå êåßìåíï óôçí åéêüíá ÷ñçóéìïðïéþôáò TrueType ãñáììáôïóåéñÜÇ óõíÜñôçóç imagettftext() ó÷åäéÜæåé ôï string text óôçí åéêüíá image, îåêéíþíôáò áðü ôï óçìåßï ìå óõíôåôáãìÝíåò x, y (ðÜíù áñéóôåñÜ åßíáé ôï óçìåßï 0, 0), ìå ãùíßá angle, ÷ñçóéìïðïéþíôáò ôï ÷ñþìá color, êáé ôçí TrueType ãñáììáôïóåéñÜ fontfile. ÅîáñôÜôáé áðü ôçí Ýêäïóç ôçò GD âéâëéïèÞêçò ðïõ ÷ñçóéìïðïéåß ç PHP, ôï üôé áí ç ðáñÜìåôñïò fontfile äåí îåêéíÜåé ìå ìßá '/', ôï '.ttf' èá ðñïóôåèåß óôï üíïìá ôïõ áñ÷åßïõ êáé ç âéâëéïèÞêç èá ðñïóðáèÞóåé íá íá øÜîåé áõôü ôï áñ÷åßï óå Ýíá êáèïñéóìÝíï áðü ôç âéâëéïèÞêç font path.
Ïé óõíôåôáãìÝíåò ðïõ äßíïíôáé áðü ôéò x, y ðñïóäéïñßæåé ôï áñ÷éêü óçìåßï ôïõ ðñþôïõ ÷áñáêôÞñá (ðñïóåããéóôéêÜ ç êÜôù áñéóôåñÞ ãùíßá ôïõ ÷áñáêôÞñá). Ïé ðáñÜìåôñïé áõôïß äéáöÝñïõí áðü áõôÝò ôçò óõíÜñôçóçò imagestring(), üðïõ ïé x, y ðñïóäéïñßæïõí ôçí ðÜíå äåîéÜ ãùíßá ôïõ ðñþôïõ ÷áñáêôÞñá.
Ç ðáñÜìåôñïò angle äßíåôáé óå ìïßñåò, ìå ôéò 0 íá áíáðáñéóôïýí ôï äéÜâáóìá áðü áñéóôåñÜ ðñïò ôá äåîéÜ (3 o'clock êáôåýèõíóç), êáé ôéò õøçëüôåñåò ôéìÝò íá áíáðáñéóôïýí ôçí áíôßèåôç ìå ôçí áñéóôåñüóôñïöç ðåñéóôñïöÞ. (ð.÷., ìßá ôéìÞ 90 ìïéñþí èá åß÷å ùò áðïôåëÝóìá ôï áðü êÜôù ðñïò ôá ðÜíù äéÜâáóìá ôïõ êåéìÝíïõ).
Ç ðáñÜìåôñïò fontfile åßíáé ôï path ôçò TrueType ãñáììáôïóåéñÜò ðïõ åðéèõìåßôå íá ÷ñçóéìïðïéåßóåôå.
Ç ðáñÜìåôñïò text åßíáé ôï text string ðïõ ìðïñåß íá ðåñéëáìâÜíåé UTF-8 áêïëïõèßåò ÷áñáêôÞñùí (ôïõ ôýðïõ: {) ãéá íá ðñïóðåëÜóåôå ÷áñáêôÞñåò ìßáò ãñáììáôïóåéñÜò ìåôÜ ôïõò ðñþôïõò 255.
Ç ðáñÜìåôñïò color åßíáé ï äåßêôçò ÷ñþìáôïò. Ç ÷ñÞóç ôïõ áñíçôéêïý äåßêôç åíüò ÷ñþìáôïò Ý÷åé ùò áðïôÝëåóìá íá áðåíåñãïðïéåßôáé ôï antialiasing.
Ç ðáñÜìåôñïò imagettftext() åðéóôñÝöåé Ýíá array ìå 8 óôïé÷åßá, ðïõ áíáðáñéóôïýí ôá ôÝóóåñá óçìåßá ðïõ õëïðïéïýí ôï bounding box ôïõ êåéÝíïõ. Ç óåéñÜ ôùí óçìåßùí åßíáé: êÜôù áñéóôåñÜ, êÜôù äåîéÜ, ðÜíù äåîéÜ, êÜôù áñéóôåñÜ. Ôá óçìåßá åßíáé ó÷åôéêÜ ìå ôï êåßìåíï êáé Üó÷åôá ìå ôçí angle, Ýôóé ôï "ðÜíù áñéóôåñÜ" óçìáßíåé ôçí ðÜíù áñéóôåñÞ ãùíßá üðùò âëÝðåôå ôï êåßìåíï ïñéæüíôéá.
Ôï áêüëïõèï script èá ðáñÜîåé Ýíá ìáýñïõ ÷ñþìáôïò GIF 400x30 pixels, ìå ôï êåßìåíï "Testing..." óå Üóðñï ÷ñþìá êáé ìå ãñáììáôïóåéñÜ Arial.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò imagettftext()
|
Ç óõíÜñôçóç áõôÞ ÷ñåéÜæåôáé ôçí GD êáé ôçí FreeType âéâëéïèÞêç.
ÁíáôñÝîôå åðßóçò óôçí imagettfbbox().
(PHP 3 CVS only, PHP 4 >= 4.0.2, PHP 5)
imagetypes -- ÅðéóôñÝöåé ôïõò ôýðïõò åéêüíáò ðïõ õðïóôçñßæïíôáé áðü ôçí åãêáôåóôçìÝíç PHPÇ óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá bit-field ðïõ åðéóôñÝöåé ôïõò ôýðïõò åéêüíáòðïõ õðïóôçñßæïíôáé áðü ôçí Ýêäïóç ôçò GD ðïõ åßíáé linked ìå ôçí PHP. ÅðéóôñÝöïíôáé ôá áêüëïõèá bits, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP. Ãéá íá åëÝãîåôå, ãéá ðáñÜäåéãìá, ôçí õðïóôÞñéîç ãéá PNG êÜíåôå ôï áêüëïõèï:
Ç óõíÜñôçóç imagewbmp() äçìéïõñãåß Ýíá WBMP ìå üíïìá image. Ôï üñéóìá image åßíáé ç åðéóôñåöüìåíç áðü ôç óõíÜñôçóç imagecreate() ôéìÞ.
Ôï filename üñéóìá åßíáé ðñïáéñåôéêü, êáé áí ðáñáëåéöèåß, ôï raw image stream èá óôáëåß áìÝóùò. ÓôÝëíïíôáò Ýíáí image/vnd.wap.wbmp content-type ìå ôç ÷ñÞóç ôçò óõíÜñôçóçò header(), ìðïñåßôå íá äçìéïõñãÞóåôå Ýíá PHP script ìðïõ íá êÜíåé output ôéò WBMP åéêüíåò áð' åõèåßáò.
Óçìåßùóç: Ç õðïóôÞñéîç WBMP åßíáé äéáèÝóéìç ìüíï áí ç PHP Ýãéíå compiled ìå ôçí GD-1.8 Þ íåþôåñç.
×ñçóéìïðïéþíôáò ôçí ðñïáéñåôéêÞ ðáñÜìåôñï foreground, ìðïñåßôå íá êáèïñßóåôå ôï foreground ÷ñþìá. ×ñçóéìïðïéåßóôå Ýíáí Use an identifier, ðïõ áðïêôÜôáé áðü ôç óõíÜñôçóç imagecolorallocate(). Ôï ðñïêáèïñéóìÝíï foreground ÷ñþìá åßíáé ôï ìáýñï.
ÁíáôñÝîôå åðßóçò óôéò óõíáñôÞóåéò image2wbmp(), imagepng(), imagegif(), imagejpeg(), imagetypes().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This function is only available if PHP is compiled with the bundled version of the GD library.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
iptcparse -- ÊÜíåôå parse Ýíá binary IPTC http://www.iptc.org/ block êáôÜ single tags.ÁõôÞ ç óõíÜñôçóç êáíåé parse Ýíá binary IPTC block êáôÜ ôá single tags ôïõ. ÅðéóôñÝöåé Ýíá array ÷ñçóéìïðïéþíôáò ôïí tagmarker ùò äåßêôç êáé ôçí value ùò ôéìÞ. ÅðéóôñÝöåé FALSE óå ðåñßðôùóç ëÜèïõò Þ áí äå âñÝèçêáí IPTC äåäïìÝíá. Áíáôñåßîôå óôç óõíÜñôçóç getimagesize() ãéá Ýíá ðáñÜäåéãìá.
ÌåôáôñÝðåé ôï jpegname JPEG áñ÷åßï óå WBMP ôýðï, êáé ôï áðïèçêåýåé ùò wbmpname. Ìå ôéò ðáñáìÝôñïõò d_height êáé d_width êáèïñßæåôå ôï ýøïò êáé ôï ðëÜôïò ôçò ôåëéêÞò åéêüíáò.
Óçìåßùóç: Ç õðïóôÞñéîç ãéá WBMP åßíáé äéáèÝóéìç ìüíï åÜí ç PHP Ýãéíå compiled íå ôçí GD-1.8 Þ íåþôåñç.
ÁíáôñÝîôå åðßóçò óôçí png2wbmp().
ÌåôáôñÝðåé ôï pngname PNG áñ÷åßï óå WBMP ôýðï, êáé ôï óþæåé ùò wbmpname. Ìå ôéò ðáñáìÝôñïõò d_height êáé d_width êáèïñßæåôå ôï ýøïò êáé ðëÜôïò ôçò ôåëéêÞò åéêüíáò.
Óçìåßùóç: Ç õðïóôÞñéîç ãéá WBMP åßíáé äéáèÝóéìç ìüíï åÜí ç PHP Ýãéíå compiled ìå ôçí GD-1.8 Þ íåþôåñç.
ÁíáôñÝîôå åðßóçò óôçí jpeg2wbmp().
These functions are not limited to the IMAP protocol, despite their name. The underlying c-client library also supports NNTP, POP3 and local mailbox access methods.
This extension requires the c-client library to be installed. Grab the latest version from ftp://ftp.cac.washington.edu/imap/ and compile it.
It's important that you do not copy the IMAP source files directly into the system include directory as there may be conflicts. Instead, create a new directory inside the system include directory, such as /usr/local/imap-2000b/ (location and name depend on your setup and IMAP version), and inside this new directory create additional directories named lib/ and include/. From the c-client directory from your IMAP source tree, copy all the *.h files into include/ and all the *.c files into lib/. Additionally when you compiled IMAP, a file named c-client.a was created. Also put this in the lib/ directory but rename it as libc-client.a.
Óçìåßùóç: To build the c-client library with SSL or/and Kerberos support read the docs supplied with the package.
To get these functions to work, you have to compile PHP with --with-imap[=DIR], where DIR is the c-client install prefix. From our example above, you would use --with-imap=/usr/local/imap-2000b. This location depends on where you created this directory according to the description above. Windows users may include the php_imap.dll DLL in php.ini
Óçìåßùóç: Depending how the c-client was configured, you might also need to add --with-imap-ssl=/path/to/openssl/ and/or --with-kerberos=/path/to/kerberos into the PHP configure line.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Open mailbox read-only
Don't use or update a .newsrc for news (NNTP only)
For IMAP and NNTP names, open a connection but don't open a mailbox.
silently expunge the mailbox before closing when calling imap_close()
The parameter is a UID
Do not set the \Seen flag if not already set
The return string is in internal format, will not canonicalize to CRLF.
The sequence argument contains UIDs instead of sequence numbers
the sequence numbers contain UIDS
Delete the messages from the current mailbox after copying with imap_mail_copy()
Return UIDs instead of sequence numbers
Don't prefetch searched messages
This mailbox has no "children" (there are no mailboxes below this one).
This is only a container, not a mailbox - you cannot open it.
This mailbox is marked. Only used by UW-IMAPD.
This mailbox is not marked. Only used by UW-IMAPD.
Sort criteria for imap_sort(): message Date
Sort criteria for imap_sort(): arrival date
Sort criteria for imap_sort(): mailbox in first From address
Sort criteria for imap_sort(): message subject
Sort criteria for imap_sort(): mailbox in first To address
Sort criteria for imap_sort(): mailbox in first cc address
Sort criteria for imap_sort(): size of message in octets
This document can't go into detail on all the topics touched by the provided functions. Further information is provided by the documentation of the c-client library source (docs/internal.txt). and the following RFC documents:
RFC2821: Simple Mail Transfer Protocol (SMTP).
RFC2822: Standard for ARPA internet text messages.
RFC2060: Internet Message Access Protocol (IMAP) Version 4rev1.
RFC1939: Post Office Protocol Version 3 (POP3).
RFC977: Network News Transfer Protocol (NNTP).
RFC2076: Common Internet Message Headers.
RFC2045 , RFC2046 , RFC2047 , RFC2048 & RFC2049: Multipurpose Internet Mail Extensions (MIME).
Convert an 8bit string to a quoted-printable string (according to RFC2045, section 6.7).
Returns a quoted-printable string.
See also imap_qprint().
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
imap_alerts -- This function returns all IMAP alert messages (if any) that have occurred during this page request or since the alert stack was resetThis function returns an array of all of the IMAP alert messages generated since the last imap_alerts() call, or the beginning of the page. When imap_alerts() is called, the alert stack is subsequently cleared. The IMAP specification requires that these messages be passed to the user.
imap_append() appends a string message to the specified mailbox mbox. If the optional options is specified, writes the options to that mailbox also.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
When talking to the Cyrus IMAP server, you must use "\r\n" as your end-of-line terminator instead of "\n" or the operation will fail.
ÐáñÜäåéãìá 1. imap_append() example
|
imap_base64() function decodes BASE-64 encoded text (see RFC2045, Section 6.8). The decoded message is returned as a string.
See also imap_binary(), base64_encode() and base64_decode().
Convert an 8bit string to a base64 string (according to RFC2045, Section 6.8).
Returns a base64 string.
See also imap_base64().
imap_body() returns the body of the message, numbered msg_number in the current mailbox.
The optional options are a bit mask with one or more of the following:
FT_UID - The msg_number is a UID
FT_PEEK - Do not set the \Seen flag if not already set
FT_INTERNAL - The return string is in internal format, will not canonicalize to CRLF.
imap_body() will only return a verbatim copy of the message body. To extract single parts of a multipart MIME-encoded message you have to use imap_fetchstructure() to analyze its structure and imap_fetchbody() to extract a copy of a single body component.
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
imap_bodystruct -- Read the structure of a specified body section of a specific message
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns information about the current mailbox. Returns FALSE on failure.
The imap_check() function checks the current mailbox status on the server and returns the information in an object with following properties:
Date - current system time formatted according to RFC822
Driver - protocol used to access this mailbox: POP3, IMAP, NNTP
Mailbox - the mailbox name
Nmsgs - number of messages in the mailbox
Recent - number of recent messages in the mailbox
ÐáñÜäåéãìá 1. imap_check() example
this will output :
|
This function causes a store to delete the specified flag to the flags set for the messages in the specified sequence. The flags which you can unset are "\\Seen", "\\Answered", "\\Flagged", "\\Deleted", and "\\Draft" (as defined by RFC2060). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá..
options are a bit mask and may contain the single option:
ST_UID - The sequence argument contains UIDs instead of sequence numbers
See also: imap_setflag_full().
Closes the imap stream. Takes an optional flag CL_EXPUNGE, which will silently expunge the mailbox before closing, removing all messages marked for deletion.
See also: imap_open().
imap_createmailbox() creates a new mailbox specified by mbox. Names containing international characters should be encoded by imap_utf7_encode()
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá..
ÐáñÜäåéãìá 1. imap_createmailbox() example
|
See also imap_renamemailbox(), imap_deletemailbox() and imap_open() for the format of mbox names.
Returns TRUE.
imap_delete() marks messages listed in msg_number for deletion. The optional flags parameter only has a single option, FT_UID, which tells the function to treat the msg_number argument as a UID. Messages marked for deletion will stay in the mailbox until either imap_expunge() is called or imap_close() is called with the optional parameter CL_EXPUNGE.
Óçìåßùóç: POP3 mailboxes do not have their message flags saved between connections, so imap_expunge() must be called during the same connection in order for messages marked for deletion to actually be purged.
ÐáñÜäåéãìá 1. imap_delete() example
|
See also: imap_undelete(), imap_expunge(), and imap_close().
imap_deletemailbox() deletes the specified mailbox (see imap_open() for the format of mbox names).
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá..
See also imap_createmailbox(), imap_renamemailbox(), and imap_open() for the format of mbox.
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
imap_errors -- This function returns all of the IMAP errors (if any) that have occurred during this page request or since the error stack was reset.This function returns an array of all of the IMAP error messages generated since the last imap_errors() call, or the beginning of the page. When imap_errors() is called, the error stack is subsequently cleared.
See also: imap_last_error().
imap_expunge() deletes all the messages marked for deletion by imap_delete(), imap_mail_move(), or imap_setflag_full().
Returns TRUE.
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
imap_fetch_overview -- Read an overview of the information in the headers of the given messageThis function fetches mail headers for the given sequence and returns an overview of their contents. sequence will contain a sequence of message indices or UIDs, if flags contains FT_UID. The returned value is an array of objects describing one message header each:
subject - the messages subject
from - who sent it
date - when was it sent
message_id - Message-ID
references - is a reference to this message id
size - size in bytes
uid - UID the message has in the mailbox
msgno - message sequence number in the maibox
recent - this message is flagged as recent
flagged - this message is flagged
answered - this message is flagged as answered
deleted - this message is flagged for deletion
seen - this message is flagged as already read
draft - this message is flagged as being a draft
ÐáñÜäåéãìá 1. imap_fetch_overview() example
|
This function causes a fetch of a particular section of the body of the specified messages as a text string and returns that text string. The section specification is a string of integers delimited by period which index into a body part list as per the IMAP4 specification. Body parts are not decoded by this function.
The options for imap_fetchbody() is a bitmask with one or more of the following:
FT_UID - The msg_number is a UID
FT_PEEK - Do not set the \Seen flag if not already set
FT_INTERNAL - The return string is in internal format, will not canonicalize to CRLF.
See also: imap_fetchstructure().
This function causes a fetch of the complete, unfiltered RFC2822 format header of the specified message as a text string and returns that text string.
The options are:
FT_UID - The msgno argument is a UID
FT_INTERNAL - The return string is in "internal" format, without any attempt to canonicalize to CRLF newlines
FT_PREFETCHTEXT - The RFC822.TEXT should be pre-fetched at the same time. This avoids an extra RTT on an IMAP connection if a full message text is desired (e.g. in a "save to local file" operation)
This function fetches all the structured information for a given message. The optional options parameter only has a single option, FT_UID, which tells the function to treat the msg_number argument as a UID. The returned object includes the envelope, internal date, size, flags and body structure along with a similar object for each mime attachment. The structure of the returned objects is as follows:
Ðßíáêáò 1. Returned Objects for imap_fetchstructure()
type | Primary body type |
encoding | Body transfer encoding |
ifsubtype | TRUE if there is a subtype string |
subtype | MIME subtype |
ifdescription | TRUE if there is a description string |
description | Content description string |
ifid | TRUE if there is an identification string |
id | Identification string |
lines | Number of lines |
bytes | Number of bytes |
ifdisposition | TRUE if there is a disposition string |
disposition | Disposition string |
ifdparameters | TRUE if the dparameters array exists |
dparameters | An array of objects where each object has an "attribute" and a "value" property corresponding to the parameters on the Content-disposition MIMEheader. |
ifparameters | TRUE if the parameters array exists |
parameters | An array of objects where each object has an "attribute" and a "value" property. |
parts | An array of objects identical in structure to the top-level object, each of which corresponds to a MIME body part. |
See also: imap_fetchbody().
(PHP 4 >= 4.0.5, PHP 5)
imap_get_quota -- Retrieve the quota level settings, and usage statics per mailboxReturns an array with integer values limit and usage for the given mailbox. The value of limit represents the total amount of space allowed for this mailbox. The usage value represents the mailboxes current level of capacity. Will return FALSE in the case of failure.
This function is currently only available to users of the c-client2000 or greater library.
NOTE: For this function to work, the mail stream is required to be opened as the mail-admin user. For a non-admin user version of this function, please see the imap_get_quotaroot() function of PHP.
imap_stream should be the value returned from an imap_open() call. NOTE: This stream is required to be opened as the mail admin user for the get_quota function to work. quota_root should normally be in the form of user.name where name is the mailbox you wish to retrieve information about.
ÐáñÜäåéãìá 1. imap_get_quota() example
|
As of PHP 4.3, the function more properly reflects the functionality as dictated by the RFC 2087. The array return value has changed to support an unlimited number of returned resources (i.e. messages, or sub-folders) with each named resource receiving an individual array key. Each key value then contains an another array with the usage and limit values within it. The example below shows the updated returned output.
For backwards compatibility reasons, the originial access methods are still available for use, although it is suggested to update.
ÐáñÜäåéãìá 2. imap_get_quota() 4.3 or greater example
|
See also imap_open(), imap_set_quota() and imap_get_quotaroot().
Returns an array of integer values pertaining to the specified user mailbox. All values contain a key based upon the resource name, and a corresponding array with the usage and limit values within.
The limit value represents the total amount of space allowed for this user's total mailbox usage. The usage value represents the user's current total mailbox capacity. This function will return FALSE in the case of call failure, and an array of information about the connection upon an un-parsable response from the server.
This function is currently only available to users of the c-client2000 or greater library.
imap_stream should be the value returned from an imap_open() call. This stream should be opened as the user whose mailbox you wish to check. quota_root should normally be in the form of which mailbox (i.e. INBOX).
ÐáñÜäåéãìá 1. imap_get_quotaroot() example
|
See also imap_open(), imap_set_quota() and imap_get_quota().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also: imap_setacl().
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
imap_getmailboxes -- Read the list of mailboxes, returning detailed information on each oneReturns an array of objects containing mailbox information. Each object has the attributes name, specifying the full name of the mailbox; delimiter, which is the hierarchy delimiter for the part of the hierarchy this mailbox is in; and attributes. Attributes is a bitmask that can be tested against:
LATT_NOINFERIORS - This mailbox has no "children" (there are no mailboxes below this one).
LATT_NOSELECT - This is only a container, not a mailbox - you cannot open it.
LATT_MARKED - This mailbox is marked. Only used by UW-IMAPD.
LATT_UNMARKED - This mailbox is not marked. Only used by UW-IMAPD.
Mailbox names containing international Characters outside the printable ASCII range will be encoded and may be decoded by imap_utf7_decode().
ref should normally be just the server specification as described in imap_open(), and pattern specifies where in the mailbox hierarchy to start searching. If you want all mailboxes, pass '*' for pattern.
There are two special characters you can pass as part of the pattern: '*' and '%'. '*' means to return all mailboxes. If you pass pattern as '*', you will get a list of the entire mailbox hierarchy. '%' means to return the current level only. '%' as the pattern parameter will return only the top level mailboxes; '~/mail/%' on UW_IMAPD will return every mailbox in the ~/mail directory, but none in subfolders of that directory.
ÐáñÜäåéãìá 1. imap_getmailboxes() example
|
See also imap_getsubscribed().
This function is identical to imap_getmailboxes(), except that it only returns mailboxes that the user is subscribed to.
This function returns an object of various header elements.
remail, date, Date, subject, Subject, in_reply_to, message_id,
newsgroups, followup_to, references
message flags:
Recent - 'R' if recent and seen,
'N' if recent and not seen,
' ' if not recent
Unseen - 'U' if not seen AND not recent,
' ' if seen OR not seen and recent
Answered -'A' if answered,
' ' if unanswered
Deleted - 'D' if deleted,
' ' if not deleted
Draft - 'X' if draft,
' ' if not draft
Flagged - 'F' if flagged,
' ' if not flagged
NOTE that the Recent/Unseen behavior is a little odd. If you want to
know if a message is Unseen, you must check for
Unseen == 'U' || Recent == 'N'
toaddress (full to: line, up to 1024 characters)
to[] (returns an array of objects from the To line, containing):
personal
adl
mailbox
host
fromaddress (full from: line, up to 1024 characters)
from[] (returns an array of objects from the From line, containing):
personal
adl
mailbox
host
ccaddress (full cc: line, up to 1024 characters)
cc[] (returns an array of objects from the Cc line, containing):
personal
adl
mailbox
host
bccaddress (full bcc line, up to 1024 characters)
bcc[] (returns an array of objects from the Bcc line, containing):
personal
adl
mailbox
host
reply_toaddress (full reply_to: line, up to 1024 characters)
reply_to[] (returns an array of objects from the Reply_to line,
containing):
personal
adl
mailbox
host
senderaddress (full sender: line, up to 1024 characters)
sender[] (returns an array of objects from the sender line, containing):
personal
adl
mailbox
host
return_path (full return-path: line, up to 1024 characters)
return_path[] (returns an array of objects from the return_path line,
containing):
personal
adl
mailbox
host
udate (mail message date in unix time)
fetchfrom (from line formatted to fit fromlength
characters)
fetchsubject (subject line formatted to fit subjectlength characters)
Returns an array of string formatted with header info. One element per mail message.
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
imap_last_error -- This function returns the last IMAP error (if any) that occurred during this page requestThis function returns the full text of the last IMAP error message that occurred on the current page. The error stack is untouched; calling imap_last_error() subsequently, with no intervening errors, will return the same error.
See also: imap_errors().
Returns an array containing the names of the mailboxes. See imap_getmailboxes() for a description of ref and pattern.
ÐáñÜäåéãìá 1. imap_list() example
|
See also: imap_getmailboxes().
(no version information, might be only in CVS)
imap_listscan -- Read the list of mailboxes, takes a string to search for in the text of the mailboxReturns an array containing the names of the mailboxes that have content in the text of the mailbox.
This function is similar to imap_listmailbox(), but it will additionally check for the presence of the string content inside the mailbox data.
See imap_getmailboxes() for a description of ref and pattern.
Returns an array of all the mailboxes that you have subscribed.
(PHP 3>= 3.0.5, PHP 4 , PHP 5)
imap_mail_compose -- Create a MIME message based on given envelope and body sections
ÐáñÜäåéãìá 1. imap_mail_compose() example
|
Copies mail messages specified by msglist to specified mailbox. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá..
msglist is a range not just message numbers (as described in RFC2060).
options is a bitmask of one or more of
CP_UID - the sequence numbers contain UIDS
CP_MOVE - Delete the messages from the current mailbox after copying
See also imap_mail_move().
Moves mail messages specified by msglist to specified mailbox mbox. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá..
msglist is a range not just message numbers (as described in RFC2060).
options is a bitmask and may contain the single option:
CP_UID - the sequence numbers contain UIDS
See also imap_mail_copy().
This function allows sending of emails with correct handling of Cc and Bcc receivers. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá..
The parameters to, cc and bcc are all strings and are all parsed as rfc822 address lists.
The receivers specified in bcc will get the mail, but are excluded from the headers.
Use the rpath parameter to specify return path. This is useful when using PHP as a mail client for multiple users.
Returns information about the current mailbox. Returns FALSE on failure.
The imap_mailboxmsginfo() function checks the current mailbox status on the server. It is similar to imap_status(), but will additionally sum up the size of all messages in the mailbox, which will take some additional time to execute. It returns the information in an object with following properties.
Ðßíáêáò 1. Mailbox properties
Date | date of last change |
Driver | driver |
Mailbox | name of the mailbox |
Nmsgs | number of messages |
Recent | number of recent messages |
Unread | number of unread messages |
Deleted | number of deleted messages |
Size | mailbox size |
ÐáñÜäåéãìá 1. imap_mailboxmsginfo() example
|
imap_mime_header_decode() function decodes MIME message header extensions that are non ASCII text (see RFC2047) The decoded elements are returned in an array of objects, where each object has two properties, "charset" and "text". If the element hasn't been encoded, and in other words is in plain US-ASCII,the "charset" property of that element is set to "default".
In the above example we would have two elements, whereas the first element had previously been encoded with ISO-8859-1, and the second element would be plain US-ASCII.
(PHP 3>= 3.0.3, PHP 4 , PHP 5)
imap_msgno -- This function returns the message sequence number for the given UIDThis function returns the message sequence number for the given uid. It is the inverse of imap_uid().
See also imap_uid().
Return the number of messages in the current mailbox.
See also: imap_num_recent() and imap_status().
Returns the number of recent messages in the current mailbox.
See also: imap_num_msg() and imap_status().
Returns an IMAP stream on success and FALSE on error. This function can also be used to open streams to POP3 and NNTP servers, but some functions and features are only available on IMAP servers.
A mailbox name consists of a server part and a mailbox path on this server. The special name INBOX stands for the current users personal mailbox. The server part, which is enclosed in '{' and '}', consists of the servers name or ip address, an optional port (prefixed by ':'), and an optional protocol specification (prefixed by '/'). The server part is mandatory in all mailbox parameters. Mailbox names that contain international characters besides those in the printable ASCII space have to be encoded with imap_utf7_encode().
The options are a bit mask with one or more of the following:
OP_READONLY - Open mailbox read-only
OP_ANONYMOUS - Don't use or update a .newsrc for news (NNTP only)
OP_HALFOPEN - For IMAP and NNTP names, open a connection but don't open a mailbox.
CL_EXPUNGE - Expunge mailbox automatically upon mailbox close (see also imap_delete() and imap_expunge())
To connect to an IMAP server running on port 143 on the local machine, do the following:
To connect to a POP3 server on port 110 on the local server, use: To connect to an SSL IMAP or POP3 server, add /ssl after the protocol specification: To connect to an SSL IMAP or POP3 server with a self-signed certificate, add /ssl/novalidate-cert after the protocol specification: To connect to an NNTP server on port 119 on the local server, use: To connect to a remote server replace "localhost" with the name or the IP address of the server you want to connect to.
ÐáñÜäåéãìá 1. imap_open() example
|
Returns TRUE if the stream is still alive, FALSE otherwise.
imap_ping() function pings the stream to see it is still active. It may discover new mail; this is the preferred method for a periodic "new mail check" as well as a "keep alive" for servers which have inactivity timeout. (As PHP scripts do not tend to run that long, I can hardly imagine that this function will be useful to anyone.)
Convert a quoted-printable string to an 8 bit string (according to RFC2045, section 6.7).
See also imap_8bit().
This function renames on old mailbox to new mailbox (see imap_open() for the format of mbox names).
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also imap_createmailbox(), imap_deletemailbox(), and imap_open() for the format of mbox.
This function reopens the specified stream to a new mailbox on an IMAP or NNTP server.
The options are a bit mask with one or more of the following:
OP_READONLY - Open mailbox read-only
OP_ANONYMOUS - Don't use or update a .newsrc for news (NNTP only)
OP_HALFOPEN - For IMAP and NNTP names, open a connection but don't open a mailbox.
CL_EXPUNGE - Expunge mailbox automatically upon mailbox close (see also imap_delete() and imap_expunge())
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function parses the address string as defined in RFC2822 and for each address, returns an array of objects. The objects properties are:
mailbox - the mailbox name (username)
host - the host name
personal - the personal name
adl - at domain source route
ÐáñÜäåéãìá 1. imap_rfc822_parse_adrlist() example
|
This function returns an object of various header elements, similar to imap_header(), except without the flags and other elements that come from the IMAP server.
(PHP 3>= 3.0.2, PHP 4 , PHP 5)
imap_rfc822_write_address -- Returns a properly formatted email address given the mailbox, host, and personal info.Returns a properly formatted email address as defined in RFC2822 given the mailbox, host, and personal info.
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
imap_search -- This function returns an array of messages matching the given search criteriaThis function performs a search on the mailbox currently opened in the given imap stream. criteria is a string, delimited by spaces, in which the following keywords are allowed. Any multi-word arguments (e.g. FROM "joey smith") must be quoted.
ALL - return all messages matching the rest of the criteria
ANSWERED - match messages with the \\ANSWERED flag set
BCC "string" - match messages with "string" in the Bcc: field
BEFORE "date" - match messages with Date: before "date"
BODY "string" - match messages with "string" in the body of the message
CC "string" - match messages with "string" in the Cc: field
DELETED - match deleted messages
FLAGGED - match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
FROM "string" - match messages with "string" in the From: field
KEYWORD "string" - match messages with "string" as a keyword
NEW - match new messages
OLD - match old messages
ON "date" - match messages with Date: matching "date"
RECENT - match messages with the \\RECENT flag set
SEEN - match messages that have been read (the \\SEEN flag is set)
SINCE "date" - match messages with Date: after "date"
SUBJECT "string" - match messages with "string" in the Subject:
TEXT "string" - match messages with text "string"
TO "string" - match messages with "string" in the To:
UNANSWERED - match messages that have not been answered
UNDELETED - match messages that are not deleted
UNFLAGGED - match messages that are not flagged
UNKEYWORD "string" - match messages that do not have the keyword "string"
UNSEEN - match messages which have not been read yet
For example, to match all unanswered messages sent by Mom, you'd use: "UNANSWERED FROM mom". Searches appear to be case insensitive. This list of criteria is from a reading of the UW c-client source code and may be incomplete or inaccurate (see also RFC2060, section 6.4.4).
Valid values for flags are SE_UID, which causes the returned array to contain UIDs instead of messages sequence numbers.
Sets an upper limit quota on a per mailbox basis. This function requires the imap_stream to have been opened as the mail administrator account. It will not work if opened as any other user.
This function is currently only available to users of the c-client2000 or greater library.
imap_stream is the stream pointer returned from a imap_open() call. This stream must be opened as the mail administrator, other wise this function will fail. quota_root is the mailbox to have a quota set. This should follow the IMAP standard format for a mailbox, 'user.name'. quota_limit is the maximum size (in KB) for the quota_root.
Returns TRUE on success and FALSE on error.
See also imap_open() and imap_set_quota().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also: imap_getacl().
This function causes a store to add the specified flag to the flags set for the messages in the specified sequence.
The flags which you can set are "\\Seen", "\\Answered", "\\Flagged", "\\Deleted", and "\\Draft" (as defined by RFC2060).
options are a bit mask and may contain the single option:
ST_UID - The sequence argument contains UIDs instead of sequence numbers
See also: imap_clearflag_full().
Returns an array of message numbers sorted by the given parameters.
Reverse is 1 for reverse-sorting.
Criteria can be one (and only one) of the following:
SORTDATE - message Date
SORTARRIVAL - arrival date
SORTFROM - mailbox in first From address
SORTSUBJECT - message subject
SORTTO - mailbox in first To address
SORTCC - mailbox in first cc address
SORTSIZE - size of message in octets
The flags are a bitmask of one or more of the following:
SE_UID - Return UIDs instead of sequence numbers
SE_NOPREFETCH - Don't prefetch searched messages
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
imap_status -- This function returns status information on a mailbox other than the current oneThis function returns an object containing status information. Valid flags are:
SA_MESSAGES - set status->messages to the number of messages in the mailbox
SA_RECENT - set status->recent to the number of recent messages in the mailbox
SA_UNSEEN - set status->unseen to the number of unseen (new) messages in the mailbox
SA_UIDNEXT - set status->uidnext to the next uid to be used in the mailbox
SA_UIDVALIDITY - set status->uidvalidity to a constant that changes when uids for the mailbox may no longer be valid
SA_ALL - set all of the above
status->flags is also set, which contains a bitmask which can be checked against any of the above constants.
ÐáñÜäåéãìá 1. imap_status() example
|
Subscribe to a new mailbox.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also: imap_unsubscribe().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 3>= 3.0.3, PHP 4 , PHP 5)
imap_uid -- This function returns the UID for the given message sequence numberThis function returns the UID for the given message sequence number. An UID is an unique identifier that will not change over time while a message sequence number may change whenever the content of the mailbox changes. This function is the inverse of imap_msgno().
Óçìåßùóç: This is not supported by POP3 mailboxes.
See also: imap_msgno().
This function removes the deletion flag for a specified message, which is set by imap_delete() or imap_mail_move().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also: imap_delete(), and imap_mail_move().
Unsubscribe from a specified mailbox.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also: imap_subscribe().
Decodes modified UTF-7 text into ISO-8859-1 string.
Returns a string that is encoded in ISO-8859-1 and consists of the same sequence of characters in text, or FALSE if text contains invalid modified UTF-7 sequence or text contains a character that is not part of ISO-8859-1 character set.
This function is needed to decode mailbox names that contain certain characters which are not in range of printable ASCII characters.
The modified UTF-7 encoding is defined in RFC 2060, section 5.1.3 (original UTF-7 was defined in RFC1642).
See also: imap_utf7_encode().
(PHP 3>= 3.0.15, PHP 4 , PHP 5)
imap_utf7_encode -- Converts ISO-8859-1 string to modified UTF-7 text.Converts data to modified UTF-7 text. Note that data is expected to be encoded in ISO-8859-1.
This is needed to encode mailbox names that contain certain characters which are not in range of printable ASCII characters.
The modified UTF-7 encoding is defined in RFC 2060, section 5.1.3 (original UTF-7 was defined in RFC1642).
See also: imap_utf7_decode().
The Informix driver for Informix (IDS) 7.x, SE 7.x, Universal Server (IUS) 9.x and IDS 2000 is implemented in "ifx.ec" and "php3_ifx.h" in the informix extension directory. IDS 7.x support is fairly complete, with full support for BYTE and TEXT columns. IUS 9.x support is partly finished: the new data types are there, but SLOB and CLOB support is still under construction.
Configuration notes: You need a version of ESQL/C to compile the PHP Informix driver. ESQL/C versions from 7.2x on should be OK. ESQL/C is now part of the Informix Client SDK.
Make sure that the "INFORMIXDIR" variable has been set, and that $INFORMIXDIR/bin is in your PATH before you run the "configure" script.
To be able to use the functions defined in this module you must compile your PHP interpreter using the configure line --with_informix[=DIR], where DIR is the Informix base install directory, defaults to nothing.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Óçìåßùóç: Make sure that the Informix environment variables INFORMIXDIR and INFORMIXSERVER are available to the PHP ifx driver, and that the INFORMIX bin directory is in the PATH. Check this by running a script that contains a call to phpinfo() before you start testing. The phpinfo() output should list these environment variables. This is TRUE for both CGI php and Apache mod_php. You may have to set these environment variables in your Apache startup script.
The Informix shared libraries should also be available to the loader (check LD_LIBRARY_PATH or ld.so.conf/ldconfig).
Some notes on the use of BLOBs (TEXT and BYTE columns): BLOBs are normally addressed by BLOB identifiers. Select queries return a "blob id" for every BYTE and TEXT column. You can get at the contents with "string_var = ifx_get_blob($blob_id);" if you choose to get the BLOBs in memory (with: "ifx_blobinfile(0);"). If you prefer to receive the content of BLOB columns in a file, use "ifx_blobinfile(1);", and "ifx_get_blob($blob_id);" will get you the filename. Use normal file I/O to get at the blob contents.
For insert/update queries you must create these "blob id's" yourself with "ifx_create_blob();". You then plug the blob id's into an array, and replace the blob columns with a question mark (?) in the query string. For updates/inserts, you are responsible for setting the blob contents with ifx_update_blob().
The behaviour of BLOB columns can be altered by configuration variables that also can be set at runtime:
configuration variable: ifx.textasvarchar
configuration variable: ifx.byteasvarchar
runtime functions:
ifx_textasvarchar(0): use blob id's for select queries with TEXT columns
ifx_byteasvarchar(0): use blob id's for select queries with BYTE columns
ifx_textasvarchar(1): return TEXT columns as if they were VARCHAR columns, so that you don't need to use blob id's for select queries.
ifx_byteasvarchar(1): return BYTE columns as if they were VARCHAR columns, so that you don't need to use blob id's for select queries.
configuration variable: ifx.blobinfile
runtime function:
ifx_blobinfile_mode(0): return BYTE columns in memory, the blob id lets you get at the contents.
ifx_blobinfile_mode(1): return BYTE columns in a file, the blob id lets you get at the file name.
If you set ifx_text/byteasvarchar to 1, you can use TEXT and BYTE columns in select queries just like normal (but rather long) VARCHAR fields. Since all strings are "counted" in PHP, this remains "binary safe". It is up to you to handle this correctly. The returned data can contain anything, you are responsible for the contents.
If you set ifx_blobinfile to 1, use the file name returned by ifx_get_blob(..) to get at the blob contents. Note that in this case YOU ARE RESPONSIBLE FOR DELETING THE TEMPORARY FILES CREATED BY INFORMIX when fetching the row. Every new row fetched will create new temporary files for every BYTE column.
The location of the temporary files can be influenced by the environment variable "blobdir", default is "." (the current directory). Something like: putenv(blobdir=tmpblob"); will ease the cleaning up of temp files accidentally left behind (their names all start with "blb").
Automatically trimming "char" (SQLCHAR and SQLNCHAR) data: This can be set with the configuration variable
ifx.charasvarchar: if set to 1 trailing spaces will be automatically trimmed, to save you some "chopping".
NULL values: The configuration variable ifx.nullformat (and the runtime function ifx_nullformat()) when set to TRUE will return NULL columns as the string "NULL", when set to FALSE they return the empty string. This allows you to discriminate between NULL columns and empty columns.
Ðßíáêáò 1. Informix configuration options
Name | Default | Changeable |
---|---|---|
ifx.allow_persistent | "1" | PHP_INI_SYSTEM |
ifx.max_persistent | "-1" | PHP_INI_SYSTEM |
ifx.max_links | "-1" | PHP_INI_SYSTEM |
ifx.default_host | NULL | PHP_INI_SYSTEM |
ifx.default_user | NULL | PHP_INI_SYSTEM |
ifx.default_password | NULL | PHP_INI_SYSTEM |
ifx.blobinfile | "1" | PHP_INI_ALL |
ifx.textasvarchar | "0" | PHP_INI_ALL |
ifx.byteasvarchar | "0" | PHP_INI_ALL |
ifx.charasvarchar | "0" | PHP_INI_ALL |
ifx.nullformat | "0" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to allow persistent Informix connections.
The maximum number of persistent Informix connections per process.
The maximum number of Informix connections per process, including persistent connections.
The default host to connect to when no host is specified in ifx_connect() or ifx_pconnect(). Doesn't apply in safe mode.
The default user id to use when none is specified in ifx_connect() or ifx_pconnect(). Doesn't apply in safe mode.
The default password to use when none is specified in ifx_connect() or ifx_pconnect(). Doesn't apply in safe mode.
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().
Set to TRUE if you want to return TEXT columns as normal strings in select statements, FALSE if you want to use blob id parameters. You can override the setting at runtime with ifx_textasvarchar().
Set to TRUE if you want to return BYTE columns as normal strings in select queries, FALSE if you want to use blob id parameters. You can override the setting at runtime with ifx_textasvarchar().
Set to TRUE if you want to trim trailing spaces from CHAR columns when fetching them.
Set to TRUE if you want to return NULL columns as the literal string "NULL", FALSE if you want them returned as the empty string "". You can override this setting at runtime with ifx_nullformat().
result_id is a valid result id returned by ifx_query() or ifx_prepare().
Returns the number of rows affected by a query associated with result_id.
For inserts, updates and deletes the number is the real number (sqlerrd[2]) of affected rows. For selects it is an estimate (sqlerrd[0]). Don't rely on it. The database server can never return the actual number of rows that will be returned by a SELECT because it has not even begun fetching them at this stage (just after the "PREPARE" when the optimizer has determined the query plan).
Useful after ifx_prepare() to limit queries to reasonable result sets.
ÐáñÜäåéãìá 1. Informix affected rows
|
See also ifx_num_rows().
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
ifx_blobinfile_mode -- Set the default blob mode for all select queriesSet the default blob mode for all select queries. Mode "0" means save Byte-Blobs in memory, and mode "1" means save Byte-Blobs in a file.
Sets the default byte mode for all select-queries. Mode "0" will return a blob id, and mode "1" will return a varchar with text content.
Returns: always TRUE.
ifx_close() closes the link to an Informix database that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed.
Note that this isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.
ifx_close() will not close persistent links generated by ifx_pconnect().
See also ifx_connect() and ifx_pconnect().
Returns a connection identifier on success, or FALSE on error.
ifx_connect() establishes a connection to an Informix server. All of the arguments are optional, and if they're missing, defaults are taken from values supplied in configuration file (ifx.default_host for the host (Informix libraries will use INFORMIXSERVER environment value if not defined), ifx.default_user for user, ifx.default_password for the password (none if not defined).
In case a second call is made to ifx_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.
The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling ifx_close().
See also ifx_pconnect() and ifx_close().
Duplicates the given blob object. bid is the ID of the blob object.
Returns FALSE on error otherwise the new blob object-id.
Creates an blob object.
type: 1 = TEXT, 0 = BYTE
mode: 0 = blob-object holds the content in memory, 1 = blob-object holds the content in file.
param: if mode = 0: pointer to the content, if mode = 1: pointer to the filestring.
Return FALSE on error, otherwise the new blob object-id.
Creates an char object. param should be the char content.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Executes a previously prepared query or opens a cursor for it.
Does NOT free result_id on error.
Also sets the real number of ifx_affected_rows() for non-select statements for retrieval by ifx_affected_rows()
See also: ifx_prepare().
The Informix error codes (SQLSTATE & SQLCODE) formatted as follows :
x [SQLSTATE = aa bbb SQLCODE=cccc]
where x = space : no error
E : error
N : no more data
W : warning
? : undefined
If the "x" character is anything other than space, SQLSTATE and SQLCODE describe the error in more detail.
See the Informix manual for the description of SQLSTATE and SQLCODE
Returns in a string one character describing the general results of a statement and both SQLSTATE and SQLCODE associated with the most recent SQL statement executed. The format of the string is "(char) [SQLSTATE=(two digits) (three digits) SQLCODE=(one digit)]". The first character can be ' ' (space) (success), 'W' (the statement caused some warning), 'E' (an error happened when executing the statement) or 'N' (the statement didn't return any data).
See also: ifx_errormsg()
Returns the Informix error message associated with the most recent Informix error, or, when the optional "errorcode" parameter is present, the error message corresponding to "errorcode".
See also ifx_error().
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows.
Blob columns are returned as integer blob id values for use in ifx_get_blob() unless you have used ifx_textasvarchar(1) or ifx_byteasvarchar(1), in which case blobs are returned as string values. Returns FALSE on error
result_id is a valid resultid returned by ifx_query() or ifx_prepare() (select type queries only!).
position is an optional parameter for a "fetch" operation on "scroll" cursors: "NEXT", "PREVIOUS", "CURRENT", "FIRST", "LAST" or a number. If you specify a number, an "absolute" row fetch is executed. This parameter is optional, and only valid for SCROLL cursors.
ifx_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0, with the column name as key.
Subsequent calls to ifx_fetch_row() would return the next row in the result set, or FALSE if there are no more rows.
ÐáñÜäåéãìá 1. Informix fetch rows
|
Returns an associative array with fieldnames as key and the SQL fieldproperties as data for a query with result_id. Returns FALSE on error.
Returns the Informix SQL fieldproperties of every field in the query as an associative array. Properties are encoded as: "SQLTYPE;length;precision;scale;ISNULLABLE" where SQLTYPE = the Informix type like "SQLVCHAR" etc. and ISNULLABLE = "Y" or "N".
ÐáñÜäåéãìá 1. Informix SQL fieldproperties
|
Returns an associative array with fieldnames as key and the SQL fieldtypes as data for query with result_id. Returns FALSE on error.
Deletes the blobobject for the given blob object-id bid. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Deletes the charobject for the given char object-id bid. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Releases resources for the query associated with result_id. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Returns the content of the blob object for the given blob object-id bid.
Returns the content of the char object for the given char object-id bid.
result_id is a valid result id returned by ifx_query() or ifx_prepare().
Returns a pseudo-row (associative array) with sqlca.sqlerrd[0] ... sqlca.sqlerrd[5] after the query associated with result_id.
For inserts, updates and deletes the values returned are those as set by the server after executing the query. This gives access to the number of affected rows and the serial insert value. For SELECTs the values are those saved after the PREPARE statement. This gives access to the *estimated* number of affected rows. The use of this function saves the overhead of executing a "select dbinfo('sqlca.sqlerrdx')" query, as it retrieves the values that were saved by the ifx driver at the appropriate moment.
ÐáñÜäåéãìá 1. Retrieve Informix sqlca.sqlerrd[x] values
|
Returns the number of rows fetched or FALSE on error.
Formats all rows of the result_id query into a HTML table. The optional second argument is a string of <table> tag options
ÐáñÜäåéãìá 1. Informix results as HTML table
|
Sets the default return value of a NULL-value on a fetch row. Mode "0" returns "", and mode "1" returns "NULL".
Returns the number of columns in query for result_id or FALSE on error
After preparing or executing a query, this call gives you the number of columns in the query.
Gives the number of rows fetched so far for a query with result_id after a ifx_query() or ifx_do() query.
Returns: A positive Informix persistent link identifier on success, or FALSE on error
ifx_pconnect() acts very much like ifx_connect() with two major differences.
This function behaves exactly like ifx_connect() when PHP is not running as an Apache module. First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (ifx_close() will not close links established by ifx_pconnect()).
This type of links is therefore called 'persistent'.
See also: ifx_connect().
Returns an integer result_id for use by ifx_do(). Sets affected_rows for retrieval by the ifx_affected_rows() function.
Prepares query on connection conn_id. For "select-type" queries a cursor is declared and opened. The optional cursor_type parameter allows you to make this a "scroll" and/or "hold" cursor. It's a bitmask and can be either IFX_SCROLL, IFX_HOLD, or both or'ed together.
For either query type the estimated number of affected rows is saved for retrieval by ifx_affected_rows().
If you have BLOB (BYTE or TEXT) columns in the query, you can add a blobidarray parameter containing the corresponding "blob ids", and you should replace those columns with a "?" in the query text.
If the contents of the TEXT (or BYTE) column allow it, you can also use "ifx_textasvarchar(1)" and "ifx_byteasvarchar(1)". This allows you to treat TEXT (or BYTE) columns just as if they were ordinary (but long) VARCHAR columns for select queries, and you don't need to bother with blob id's.
With ifx_textasvarchar(0) or ifx_byteasvarchar(0) (the default situation), select queries will return BLOB columns as blob id's (integer value). You can get the value of the blob as a string or file with the blob functions (see below).
See also: ifx_do().
Returns a positive Informix result identifier on success, or FALSE on error.
A "result_id" resource used by other functions to retrieve the query results. Sets "affected_rows" for retrieval by the ifx_affected_rows() function.
ifx_query() sends a query to the currently active database on the server that's associated with the specified link identifier.
Executes query on connection conn_id. For "select-type" queries a cursor is declared and opened. The optional cursor_type parameter allows you to make this a "scroll" and/or "hold" cursor. It's a bitmask and can be either IFX_SCROLL, IFX_HOLD, or both or'ed together. Non-select queries are "execute immediate". IFX_SCROLL and IFX_HOLD are symbolic constants and as such shouldn't be between quotes. I you omit this parameter the cursor is a normal sequential cursor.
For either query type the number of (estimated or real) affected rows is saved for retrieval by ifx_affected_rows().
If you have BLOB (BYTE or TEXT) columns in an update query, you can add a blobidarray parameter containing the corresponding "blob ids", and you should replace those columns with a "?" in the query text.
If the contents of the TEXT (or BYTE) column allow it, you can also use "ifx_textasvarchar(1)" and "ifx_byteasvarchar(1)". This allows you to treat TEXT (or BYTE) columns just as if they were ordinary (but long) VARCHAR columns for select queries, and you don't need to bother with blob id's.
With ifx_textasvarchar(0) or ifx_byteasvarchar(0) (the default situation), select queries will return BLOB columns as blob id's (integer value). You can get the value of the blob as a string or file with the blob functions (see below).
ÐáñÜäåéãìá 1. Show all rows of the "orders" table as a HTML table
|
ÐáñÜäåéãìá 2. Insert some values into the "catalog" table
|
See also ifx_connect().
Sets the default text mode for all select-queries. Mode "0" will return a blob id, and mode "1" will return a varchar with text content.
Updates the content of the blob object for the given blob object bid. content is a string with new data. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Updates the content of the char object for the given char object bid. content is a string with new data. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Deletes the slob object on the given slob object-id bid. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Creates an slob object and opens it. Modes: 1 = LO_RDONLY, 2 = LO_WRONLY, 4 = LO_APPEND, 8 = LO_RDWR, 16 = LO_BUFFER, 32 = LO_NOBUFFER -> or-mask. You can also use constants named IFX_LO_RDONLY, IFX_LO_WRONLY etc. Return FALSE on error otherwise the new slob object-id.
Deletes the slob object. bid is the Id of the slob object. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Opens an slob object. bid should be an existing slob id. Modes: 1 = LO_RDONLY, 2 = LO_WRONLY, 4 = LO_APPEND, 8 = LO_RDWR, 16 = LO_BUFFER, 32 = LO_NOBUFFER -> or-mask. Returns FALSE on error otherwise the new slob object-id.
Reads nbytes of the slob object. bid is a existing slob id and nbytes is the number of bytes read. Return FALSE on error otherwise the string.
Sets the current file or seek position of an open slob object. bid should be an existing slob id. Modes: 0 = LO_SEEK_SET, 1 = LO_SEEK_CUR, 2 = LO_SEEK_END and offset is an byte offset. Return FALSE on error otherwise the seek position.
Returns the current file or seek position of an open slob object bid should be an existing slob id. Return FALSE on error otherwise the seek position.
InterBase is a popular database put out by Borland/Inprise. More information about InterBase is available at http://www.interbase.com/. Oh, by the way, InterBase just joined the open source movement!
To enable InterBase support configure PHP --with-interbase[=DIR], where DIR is the InterBase base install directory, which defaults to /usr/interbase.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy gds32.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32). In case you installed the InterBase database server on the same machine PHP is running on, you will have this DLL already. Therefore you don't need to copy gds32.dll from the DLL folder.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. InterBase configuration options
Name | Default | Changeable |
---|---|---|
ibase.allow_persistent | "1" | PHP_INI_SYSTEM |
ibase.max_persistent | "-1" | PHP_INI_SYSTEM |
ibase.max_links | "-1" | PHP_INI_SYSTEM |
ibase.default_user | NULL | PHP_INI_ALL |
ibase.default_password | NULL | PHP_INI_ALL |
ibase.timestampformat | "%m/%d/%Y%H:%M:%S" | PHP_INI_ALL |
ibase.dateformat | "%m/%d/%Y" | PHP_INI_ALL |
ibase.timeformat | "%H:%M:%S" | PHP_INI_ALL |
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Access mode
Access mode
Isolation level
Isolation level
Isolation level (default)
Lock resolution
Lock resolution (default)
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also ibase_modify_user() and ibase_delete_user().
This function returns the number of rows that were affected by the previous query that was executed from within the transaction context specified by link_identifier. If link_identifier is a connection resource, its default transaction is used.
See also ibase_query() and ibase_execute().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ibase_blob_add() adds data into a blob created with ibase_blob_create(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ibase_blob_cancel(), ibase_blob_close(), ibase_blob_create() and ibase_blob_import().
This function will discard a BLOB created by ibase_create_blob() if it has not yet been closed by ibase_blob_close(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ibase_blob_close(), ibase_blob_create() and ibase_blob_import().
This function closes a BLOB that has either been opened for reading by ibase_open_blob() or has been opened for writing by ibase_create_blob(). If the BLOB was being read, this function returns TRUE on success, if the BLOB was being written to, this function returns a string containing the BLOB id that has been assigned to it by the database. On failure, this function returns FALSE.
See also ibase_blob_cancel() and ibase_blob_open().
ibase_blob_create() creates a new BLOB for filling with data. It returns a BLOB handle for later use with ibase_blob_add() or FALSE on failure.
See also ibase_blob_add(), ibase_blob_cancel(), ibase_blob_close() and ibase_blob_import().
This function opens a BLOB for reading and sends its contents directly to standard output (the browser, in most cases). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ibase_blob_open(), ibase_blob_close() and ibase_blob_get().
This function returns at most len bytes from a BLOB that has been opened for reading by ibase_blob_open(). Returns FALSE on failure.
<?php $sql = "SELECT blob_value FROM table"; $result = ibase_query($sql); $data = ibase_fetch_object($result); $blob_data = ibase_blob_info($data->BLOB_VALUE); $blob_hndl = ibase_blob_open($data->BLOB_VALUE); echo ibase_blob_get($blob_hndl, $blob_data[0]); ?> |
Óçìåßùóç: It is not possible to read from a BLOB that has been opened for writing by ibase_blob_create().
See also ibase_blob_open(), ibase_blob_close() and ibase_blob_echo().
This function creates a BLOB, reads an entire file into it, closes it and returns the assigned BLOB id. The file handle is a handle returned by fopen(). Returns FALSE on failure.
See also ibase_blob_add(), ibase_blob_cancel(), ibase_blob_close() and ibase_blob_create().
Returns an array containing information about a BLOB. The information returned consists of the length of the BLOB, the number of segments it contains, the size of the largest segment, and whether it is a stream BLOB or a segmented BLOB.
ibase_blob_open() opens an existing BLOB for reading. It returns a BLOB handle for later use with ibase_blob_get() or FALSE on failure.
See also ibase_blob_close(), ibase_blob_echo() and ibase_blob_get().
Closes the link to an InterBase database that's associated with a connection id returned from ibase_connect(). If the connection id is omitted, the last opened link is assumed. Default transaction on link is committed, other transactions are rolled back. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ibase_connect() and ibase_pconnect().
If called without an argument, this function commits the default transaction of the default link. If the argument is a connection identifier, the default transaction of the corresponding connection will be committed. If the argument is a transaction identifier, the corresponding transaction will be committed. The transaction context will be retained, so statements executed from within this transaction will not be invalidated. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
If called without an argument, this function commits the default transaction of the default link. If the argument is a connection identifier, the default transaction of the corresponding connection will be committed. If the argument is a transaction identifier, the corresponding transaction will be committed. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Establishes a connection to an InterBase server. The database argument has to be a valid path to database file on the server it resides on. If the server is not local, it must be prefixed with either 'hostname:' (TCP/IP), '//hostname/' (NetBEUI) or 'hostname@' (IPX/SPX), depending on the connection protocol used. username and password can also be specified with PHP configuration directives ibase.default_user and ibase.default_password. charset is the default character set for a database. buffers is the number of database buffers to allocate for the server-side cache. If 0 or omitted, server chooses its own default. dialect selects the default SQL dialect for any statement executed within a connection, and it defaults to the highest one supported by client libraries.
In case a second call is made to ibase_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling ibase_close().
ÐáñÜäåéãìá 1. ibase_connect() example
|
Óçìåßùóç: The optional buffers parameter was added in PHP 4.0.0.
Óçìåßùóç: The optional dialect parameter was added in PHP 4.0.0 and is functional only with InterBase 6 and up.
Óçìåßùóç: The optional role parameter was added in PHP 4.0.0 and is functional only with InterBase 5 and up.
Óçìåßùóç: If you get some error like "arithmetic exception, numeric overflow, or string truncation. Cannot transliterate character between character sets" (this occurs when you try use some character with accents) when using this and after ibase_query() you must set the character set (i.e. ISO8859_1 or your current character set).
See also ibase_pconnect() and ibase_close().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ibase_delete_user -- Delete a user from a security database (only for IB6 or later)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also ibase_add_user() and ibase_modify_user().
This functions drops a database that was opened by either ibase_connect() or ibase_pconnect(). The database is closed and deleted from the server. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ibase_connect() and ibase_pconnect().
Returns the error code that resulted from the most recent InterBase function call. Returns FALSE if no error occurred.
See also ibase_errmsg().
Returns the error message that resulted from the most recent InterBase function call. Returns FALSE if no error occurred.
See also ibase_errcode().
Execute a query prepared by ibase_prepare(). If the query raises an error, returns FALSE. If it is successful and there is a (possibly empty) result set (such as with a SELECT query), returns a result identifier. If the query was successful and there were no results, returns TRUE.
This is a lot more effective than using ibase_query() if you are repeating a same kind of query several times with only some parameters changing.
ÐáñÜäåéãìá 1. ibase_execute() example
|
Óçìåßùóç: In PHP 5.0.0 and up, this function returns the number of rows affected by the query (if > 0 and applicable to the statement type). A query that succeeded, but did not affect any rows (e.g. an UPDATE of a non-existent record) will return TRUE.
See also ibase_query().
ibase_fetch_assoc() returns an associative array that corresponds to the fetched row. Subsequent calls will return the next row in the result set, or FALSE if there are no more rows.
ibase_fetch_assoc() fetches one row of data from the result. If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indices by using ibase_fetch_row() or use alias names in your query.
fetch_flag is a combination of the constants IBASE_TEXT and IBASE_UNIXTIME ORed together. Passing IBASE_TEXT will cause this function to return BLOB contents instead of BLOB ids. Passing IBASE_UNIXTIME will cause this function to return date/time values as Unix timestamps instead of as formatted strings.
See also ibase_fetch_row() and ibase_fetch_object().
Fetches a row as a pseudo-object from a result_id obtained either by ibase_query() or ibase_execute().
<?php $dbh = ibase_connect($host, $username, $password); $stmt = 'SELECT * FROM tblname'; $sth = ibase_query($dbh, $stmt); while ($row = ibase_fetch_object($sth)) { echo $row->email . "\n"; } ibase_close($dbh); ?> |
Subsequent calls to ibase_fetch_object() return the next row in the result set, or FALSE if there are no more rows.
fetch_flag is a combination of the constants IBASE_TEXT and IBASE_UNIXTIME ORed together. Passing IBASE_TEXT will cause this function to return BLOB contents instead of BLOB ids. Passing IBASE_UNIXTIME will cause this function to return date/time values as Unix timestamps instead of as formatted strings.
See also ibase_fetch_row() and ibase_fetch_assoc().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
ibase_fetch_row() fetches one row of data from the result associated with the specified result_identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
Subsequent calls to ibase_fetch_row() return the next row in the result set, or FALSE if there are no more rows.
fetch_flag is a combination of the constants IBASE_TEXT and IBASE_UNIXTIME ORed together. Passing IBASE_TEXT will cause this function to return BLOB contents instead of BLOB ids. Passing IBASE_UNIXTIME will cause this function to return date/time values as Unix timestamps instead of as formatted strings.
See also ibase_fetch_assoc() and ibase_fetch_object().
Returns an array with information about a field after a select query has been run. The array is in the form of name, alias, relation, length, type.
<?php $rs = ibase_query("SELECT * FROM tablename"); $coln = ibase_num_fields($rs); for ($i = 0; $i < $coln; $i++) { $col_info = ibase_field_info($rs, $i); echo "name: ". $col_info['name']. "\n"; echo "alias: ". $col_info['alias']. "\n"; echo "relation: ". $col_info['relation']. "\n"; echo "length: ". $col_info['length']. "\n"; echo "type: ". $col_info['type']. "\n"; } ?> |
See also: ibase_num_fields().
This function causes the registered event handler specified by event to be cancelled. The callback function will no longer be called for the events it was registered to handle. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ibase_set_event_handler().
Free a query prepared by ibase_prepare(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Frees a result set that has been created by ibase_query() or ibase_execute(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ibase_modify_user -- Modify a user to a security database (only for IB6 or later)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also ibase_add_user() and ibase_delete_user().
This function assigns a name to a result set. This name can be used later in UPDATE|DELETE ... WHERE CURRENT OF name statements. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
<?php $result = ibase_query("SELECT field1,field2 FROM table FOR UPDATE"); ibase_name_result($result, "my_cursor"); $updateqry = ibase_prepare("UPDATE table SET field2 = ? WHERE CURRENT OF my_cursor"); for ($i = 0; ibase_fetch_row($result); ++$i) { ibase_execute($updateqry, $i); } ?> |
See also ibase_prepare() and ibase_execute().
Returns an integer containing the number of fields in a result set.
<?php $rs = ibase_query("SELECT * FROM tablename"); $coln = ibase_num_fields($rs); for ($i = 0; $i < $coln; $i++) { $col_info = ibase_field_info($rs, $i); echo "name: " . $col_info['name'] . "\n"; echo "alias: " . $col_info['alias'] . "\n"; echo "relation: " . $col_info['relation'] . "\n"; echo "length: " . $col_info['length'] . "\n"; echo "type: " . $col_info['type'] . "\n"; } ?> |
See also: ibase_field_info().
This function returns the number of parameters in the prepared query specified by query. This is the number of binding arguments that must be present when calling ibase_execute().
See also ibase_prepare() and ibase_param_info().
Returns an array with information about a parameter after a query has been prepared. The array is in the form of name, alias, relation, length, type.
See also ibase_field_info() and ibase_num_params().
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
ibase_pconnect -- Open a persistent connection to an InterBase databaseibase_pconnect() acts very much like ibase_connect() with two major differences. First, when connecting, the function will first try to find a (persistent) link that's already opened with the same parameters. If one is found, an identifier for it will be returned instead of opening a new connection. Second, the connection to the InterBase server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (ibase_close() will not close links established by ibase_pconnect()). This type of link is therefore called 'persistent'.
Óçìåßùóç: buffers was added in PHP4-RC2.
Óçìåßùóç: dialect was added in PHP4-RC2. It is functional only with InterBase 6 and versions higher than that.
Óçìåßùóç: role was added in PHP4-RC2. It is functional only with InterBase 5 and versions higher than that.
See also ibase_close() and ibase_connect() for the meaning of parameters passed to this function. They are exactly the same.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
ibase_prepare -- Prepare a query for later binding of parameter placeholders and executionPrepare a query for later binding of parameter placeholders and execution (via ibase_execute()).
Performs a query on an InterBase database. If the query raises an error, returns FALSE. If it is successful and there is a (possibly empty) result set (such as with a SELECT query), returns a result identifier. If the query was successful and there were no results, returns TRUE.
Óçìåßùóç: In PHP 5.0.0 and up, this function will return the number of rows affected by the query for INSERT, UPDATE and DELETE statements. In order to retain backward compatibility, it will return TRUE for these statements if the query succeeded without affecting any rows.
Óçìåßùóç: If you get some error like "arithmetic exception, numeric overflow, or string truncation. Cannot transliterate character between character sets" (this occurs when you try use some character with accents) when using this and after ibase_query() you must set the character set (i.e. ISO8859_1 or your current character set).
See also ibase_errmsg(), ibase_fetch_row(), ibase_fetch_object(), and ibase_free_result().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
If called without an argument, this function rolls back the default transaction of the default link. If the argument is a connection identifier, the default transaction of the corresponding connection will be rolled back. If the argument is a transaction identifier, the corresponding transaction will be rolled back. The transaction context will be retained, so statements executed from within this transaction will not be invalidated. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
If called without an argument, this function rolls back the default transaction of the default link. If the argument is a connection identifier, the default transaction of the corresponding connection will be rolled back. If the argument is a transaction identifier, the corresponding transaction will be rolled back. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
This function registers a PHP user function as event handler for the specified events. The callback is called with the event name and the link resource as arguments whenever one of the specified events is posted by the database. The callback must return FALSE if the event handler should be canceled. Any other return value is ignored.
<?php function event_handler($event_name, $link) { if ($event_name=="NEW ORDER") { // process new order ibase_query($link, "UPDATE orders SET status='handled'"); } else if ($event_name=="DB_SHUTDOWN") { // free event handler return false; } } ibase_set_event_handler($link, "event_handler", "NEW_ORDER", "DB_SHUTDOWN"); ?> |
The return value is an event resource. This resource can be used to free the event handler using ibase_free_event_handler().
See also ibase_free_event_handler() and ibase_wait_event().
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
ibase_timefmt -- Sets the format of timestamp, date and time type columns returned from queriesSets the format of timestamp, date or time type columns returned from queries. Internally, the columns are formatted by c-function strftime(), so refer to its documentation regarding to the format of the string. columntype is one of the constants IBASE_TIMESTAMP, IBASE_DATE and IBASE_TIME. If omitted, defaults to IBASE_TIMESTAMP for backwards compatibility.
<?php /* InterBase 6 TIME-type columns will be returned in * the form '05 hours 37 minutes'. */ ibase_timefmt("%H hours %M minutes", IBASE_TIME); ?> |
You can also set defaults for these formats with PHP configuration directives ibase.timestampformat, ibase.dateformat and ibase.timeformat.
Óçìåßùóç: columntype was added in PHP 4.0. It has any meaning only with InterBase version 6 and higher.
Óçìåßùóç: A backwards incompatible change happened in PHP 4.0 when PHP configuration directive ibase.timeformat was renamed to ibase.timestampformat and directives ibase.dateformat and ibase.timeformat were added, so that the names would match better their functionality.
Begins a transaction.
trans_args can be a combination of IBASE_READ, IBASE_WRITE, IBASE_COMMITTED, IBASE_CONSISTENCY, IBASE_CONCURRENCY, IBASE_REC_VERSION, IBASE_REC_NO_VERSION, IBASE_WAIT and IBASE_NOWAIT.
Óçìåßùóç: The behaviour of this function has been changed in PHP 5.0.0. The first call to ibase_trans() will not return the default transaction of a connection. All transactions started by ibase_trans() will be rolled back at the end of the script if they were not committed or rolled back by either ibase_commit() or ibase_rollback().
Óçìåßùóç: In PHP 5.0.0. and up, this function will accept multiple trans_args and link_identifier arguments. This allows transactions over multiple database connections, which are committed using a 2-phase commit algorithm. This means you can rely on the updates to either succeed in every database, or fail in every database. It does NOT mean you can use tables from different databases in the same query!
If you use transactions over multiple databases, you will have to specify both the link_id and transaction_id in calls to ibase_query() and ibase_prepare().
This function suspends execution of the script until one of the specified events is posted by the database. The name of the event that was posted is returned. This function accepts up to 15 event arguments.
See also ibase_set_event_handler() and ibase_free_event_handler().
These functions allow you to access Ingres II database servers.
Óçìåßùóç: If you already used PHP extensions to access other database servers, note that Ingres doesn't allow concurrent queries and/or transaction over one connection, thus you won't find any result or transaction handle in this extension. The result of a query must be treated before sending another query, and a transaction must be committed or rolled back before opening another transaction (which is automatically done when sending the first query).
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
To compile PHP with Ingres support, you need the Open API library and header files included with Ingres II.
In order to have these functions available, you must compile PHP with Ingres support by using the --with-ingres[=DIR] option, where DIR is the Ingres base directory, which defaults to /II/ingres. If the II_SYSTEM environment variable isn't correctly set you may have to use --with-ingres=DIR to specify your Ingres installation directory.
When using this extension with Apache, if Apache does not start and complains with "PHP Fatal error: Unable to start ingres_ii module in Unknown on line 0" then make sure the environment variable II_SYSTEM is correctly set. Adding "export II_SYSTEM="/home/ingres/II" in the script that starts Apache, just before launching httpd, should be fine.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Ingres II configuration options
Name | Default | Changeable |
---|---|---|
ingres.allow_persistent | "1" | PHP_INI_SYSTEM |
ingres.max_persistent | "-1" | PHP_INI_SYSTEM |
ingres.max_links | "-1" | PHP_INI_SYSTEM |
ingres.default_database | NULL | PHP_INI_ALL |
ingres.default_user | NULL | PHP_INI_ALL |
ingres.default_password | NULL | PHP_INI_ALL |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_autocommit() is called before opening a transaction (before the first call to ingres_query() or just after a call to ingres_rollback() or ingres_commit()) to switch the "autocommit" mode of the server on or off (when the script begins the autocommit mode is off).
When the autocommit mode is on, every query is automatically committed by the server, as if ingres_commit() was called after every call to ingres_query().
See also ingres_query(), ingres_rollback(), and ingres_commit().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Returns TRUE on success, or FALSE on failure.
ingres_close() closes the connection to the Ingres server that's associated with the specified link. If the link parameter isn't specified, the last opened link is used.
ingres_close() isn't usually necessary, as it won't close persistent connections and all non-persistent connections are automatically closed at the end of the script.
See also ingres_connect() and ingres_pconnect().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_commit() commits the currently open transaction, making all changes made to the database permanent.
This closes the transaction. A new one can be open by sending a query with ingres_query().
You can also have the server commit automatically after every query by calling ingres_autocommit() before opening the transaction.
See also ingres_query(), ingres_rollback(), and ingres_autocommit().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Returns a Ingres II link resource on success, or FALSE on failure.
ingres_connect() opens a connection with the Ingres database designated by database, which follows the syntax [node_id::]dbname[/svr_class].
If some parameters are missing, ingres_connect() uses the values in php.ini for ingres.default_database, ingres.default_user, and ingres.default_password.
The connection is closed when the script ends or when ingres_close() is called on this link.
All the other ingres functions use the last opened link as a default, so you need to store the returned value only if you use more than one link at a time.
See also ingres_pconnect() and ingres_close().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_fetch_array() Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
This function is an extended version of ingres_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must use the numeric index of the column or make an alias for the column.
<?php ingres_query("select t1.f1 as foo t2.f1 as bar from t1, t2"); $result = ingres_fetch_array(); $foo = $result["foo"]; $bar = $result["bar"]; ?> |
result_type can be INGRES_NUM for enumerated array, INGRES_ASSOC for associative array, or INGRES_BOTH (default).
Speed-wise, the function is identical to ingres_fetch_object(), and almost as quick as ingres_fetch_row() (the difference is insignificant).
See also ingres_query(), ingres_num_fields(), ingres_field_name(), ingres_fetch_object(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_fetch_object() Returns an object that corresponds to the fetched row, or FALSE if there are no more rows.
This function is similar to ingres_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
The optional argument result_type is a constant and can take the following values: INGRES_ASSOC, INGRES_NUM, and INGRES_BOTH.
Speed-wise, the function is identical to ingres_fetch_array(), and almost as quick as ingres_fetch_row() (the difference is insignificant).
See also ingres_query(), ingres_num_fields(), ingres_field_name(), ingres_fetch_array(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_fetch_row() returns an array that corresponds to the fetched row, or FALSE if there are no more rows. Each result column is stored in an array offset, starting at offset 1.
Subsequent call to ingres_fetch_row() would return the next row in the result set, or FALSE if there are no more rows.
See also ingres_num_fields(), ingres_query(), ingres_fetch_array(), and ingres_fetch_object().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_field_length() returns the length of a field. This is the number of bytes used by the server to store the field. For detailed information, see the Ingres/OpenAPI User Guide - Appendix C.
index is the number of the field and must be between 1 and the value given by ingres_num_fields().
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_field_name() returns the name of a field in a query result, or FALSE on failure.
index is the number of the field and must be between 1 and the value given by ingres_num_fields().
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object() and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_field_nullable() returns TRUE if the field can be set to the NULL value and FALSE if it can't.
index is the number of the field and must be between 1 and the value given by ingres_num_fields().
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_field_precision() returns the precision of a field. This value is used only for decimal, float and money SQL data types. For detailed information, see the Ingres/OpenAPI User Guide - Appendix C.
index is the number of the field and must be between 1 and the value given by ingres_num_fields().
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_field_scale() returns the scale of a field. This value is used only for the decimal SQL data type. For detailed information, see the Ingres/OpenAPI User Guide - Appendix C.
index is the number of the field and must be between 1 and the value given by ingres_num_fields().
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_field_type() returns the type of a field in a query result, or FALSE on failure. Examples of types returned are "IIAPI_BYTE_TYPE", "IIAPI_CHA_TYPE", "IIAPI_DTE_TYPE", "IIAPI_FLT_TYPE", "IIAPI_INT_TYPE", "IIAPI_VCH_TYPE". Some of these types can map to more than one SQL type depending on the length of the field (see ingres_field_length()). For example "IIAPI_FLT_TYPE" can be a float4 or a float8. For detailed information, see the Ingres/OpenAPI User Guide - Appendix C.
index is the number of the field and must be between 1 and the value given by ingres_num_fields().
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_num_fields() returns the number of fields in the results returned by the Ingres server after a call to ingres_query()
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object(), and ingres_fetch_row().
(PHP 4 >= 4.0.2, PHP 5)
ingres_num_rows -- Get the number of rows affected or returned by the last queryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
For delete, insert or update queries, ingres_num_rows() returns the number of rows affected by the query. For other queries, ingres_num_rows() returns the number of rows in the query's result.
Óçìåßùóç: This function is mainly meant to get the number of rows modified in the database. If this function is called before using ingres_fetch_array(), ingres_fetch_object() or ingres_fetch_row() the server will delete the result's data and the script won't be able to get them.
You should instead retrieve the result's data using one of these fetch functions in a loop until it returns FALSE, indicating that no more results are available.
See also ingres_query(), ingres_fetch_array(), ingres_fetch_object(), and ingres_fetch_row().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Returns a Ingres II link resource on success, or FALSE on failure.
See ingres_connect() for parameters details and examples. There are only 2 differences between ingres_pconnect() and ingres_connect() : First, when connecting, the function will first try to find a (persistent) link that's already opened with the same parameters. If one is found, an identifier for it will be returned instead of opening a new connection. Second, the connection to the Ingres server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (ingres_close() will not close links established by ingres_pconnect()). This type of link is therefore called 'persistent'.
See also ingres_connect() and ingres_close().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Returns TRUE on success, or FALSE on failure.
ingres_query() sends the given query to the Ingres server. This query must be a valid SQL query (see the Ingres SQL reference guide)
The query becomes part of the currently open transaction. If there is no open transaction, ingres_query() opens a new transaction. To close the transaction, you can either call ingres_commit() to commit the changes made to the database or ingres_rollback() to cancel these changes. When the script ends, any open transaction is rolled back (by calling ingres_rollback()). You can also use ingres_autocommit() before opening a new transaction to have every SQL query immediately committed.
Some types of SQL queries can't be sent with this function:
close (see ingres_close())
commit (see ingres_commit())
connect (see ingres_connect())
disconnect (see ingres_close())
get dbevent
prepare to commit
rollback (see ingres_rollback())
savepoint
set autocommit (see ingres_autocommit())
all cursor related queries are unsupported
See also ingres_fetch_array(), ingres_fetch_object(), ingres_fetch_row(), ingres_commit(), ingres_rollback(), and ingres_autocommit().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ingres_rollback() rolls back the currently open transaction, actually canceling all changes made to the database during the transaction.
This closes the transaction. A new one can be open by sending a query with ingres_query().
See also ingres_query(), ingres_commit(), and ingres_autocommit().
With IRCG you can rapidly stream XML data to thousands of concurrently connected users. This can be used to build powerful, extensible interactive platforms such as online games and webchats. IRCG also features support for a non-streaming mode where a helper application reformats incoming data and supplies static file snippets in special formats such as cHTML (i-mode) or WML (WAP). These static files are then delivered by the high-performance web server.
Up to v4, IRCG runs under these platforms:
AIX
FreeBSD
HP-UX
Irix
Linux
Solaris
Tru64
Windows
Detailed installation instructions can be found at http://www.schumann.cx/ircg/. We urge you to use the provided installation script.
It is not recommended, but you can try enable IRCG support yourself. Provide the path to the ircg-config script, --with-ircg-config=path/to/irc-config and in addition add --with-ircg to your configure line.
Set channel mode flags for channel on server connected to by connection. Mode flags are passed in mode_spec and are applied to the user specified by nick.
Mode flags are set or cleared by specifying a mode character and prepending it with a plus or minus character, respectively. E.g. operator mode is granted by '+o' and revoked by '-o', as passed as mode_spec.
ircg_disconnect() will close a connection to a server previously established with ircg_pconnect().
See also: ircg_pconnect().
ircg_fetch_error_msg() returns the error from a failed connection.
Óçìåßùóç: Error code is stored in first array element, error text in second. The error code is equivalent to IRC reply codes as defined by RFC 2812.
Function ircg_get_username() returns the username for the specified connection connection. Returns FALSE if connection died or is not valid.
Encodes a HTML string html_string for output. This exposes the interface which the IRCG extension uses internally to reformat data coming from an IRC link. The function causes IRC color/font codes to be encoded in HTML and escapes certain entities.
This function adds user nick to the ignore list of connection connection. Afterwards, IRCG will suppress all messages from this user through the associated connection.
See also: ircg_ignore_del().
This function removes user nick from the IRCG ignore list associated with connection.
See also: ircg_ignore_add().
ircg_invite() will send an invitation to the user nickname, prompting him to join channel. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ircg_is_conn_alive() returns TRUE if connection is still alive and working or FALSE, if the connection has died for some reason.
Join the channel channel on the server connected to by connection. IRCG will optionally pass the room key key.
Kick user nick from channel on server connected to by connection. reason should give a short message describing why this action was performed.
ircg_list() will request a list of users in the channel. The answer is sent to the output defined by ircg_set_file() or ircg_set_current(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. ircg_list() example
This example will output something similar to:
|
See also: ircg_set_file(), ircg_set_current(), and ircg_who().
(PHP 4 >= 4.0.5, PHP 5)
ircg_lookup_format_messages -- Check for the existence of a format message setCheck for the existence of the format message set name. Sets may be registered with ircg_register_format_messages(), a default set named ircg is always available. Returns TRUE, if the set exists and FALSE otherwise.
See also: ircg_register_format_messages()
ircg_lusers() will request a statistical breakdown of users on the network connected to on connection. The answer is sent to the output defined by ircg_set_file() or ircg_set_current(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also: ircg_set_file(), and ircg_set_current().
ircg_msg() will send the message to a channel or user on the server connected to by connection. A recipient starting with # or & will send the message to a channel, anything else will be interpreted as a username.
Setting the optional parameter suppress to a TRUE value will suppress output of your message to your own connection. This so-called loopback is necessary, because the IRC server does not echo PRIVMSG commands back to us.
Change your nickname on the given connection to the one given in nick, if possible.
Will return TRUE on success and FALSE on failure.
(PHP 4 >= 4.0.6, PHP 5)
ircg_nickname_escape -- Encode special characters in nickname to be IRC-compliantFunction ircg_nickname_escape() returns an encoded nickname specified by nick which is IRC-compliant.
See also: ircg_nickname_unescape()
Function ircg_nickname_unescape() returns a decoded nickname, which is specified in nick.
See also: ircg_nickname_escape()
This function will send the message text to the user nick on the server connected to by connection. IRC servers and other software will not automatically generate replies to NOTICEs in contrast to other message types.
ircg_oper() will authenticate the logged in user on connection as an IRC operator. name and password must match a registered IRC operator account. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Leave the channel channel on the server connected to by connection.
ircg_pconnect() will try to establish a connection to an IRC server and return a connection resource handle for further use.
The only mandatory parameter is username, this will set your initial nickname on the server. server_ip and server_port are optional and default to 127.0.0.1 and 6667.
Óçìåßùóç: For now parameter server_ip will not do any hostname lookups and will only accept IP addresses in numerical form. DNS lookups are expensive and should be done in the context of IRCG.
You can customize the output of IRC messages and events by selecting a format message set previously created with ircg_register_format_messages() by specifying the set's name in msg_format.
If you want to handle CTCP messages such as ACTION (/me), you need to define a mapping from CTCP type (e.g. ACTION) to a custom format string. Do this by passing an associative array as ctcp_messages. The keys of the array are the CTCP type and the respective value is the format message.
You can define "ident", "password", and "realname" tokens which are sent to the IRC server by setting these in an associative array. Pass that array as user_settings.
See also: ircg_disconnect(), ircg_is_conn_alive(), ircg_register_format_messages().
With ircg_register_format_messages() you can customize the way your IRC output looks like or which script functions are invoked on the client side.
Plain channel message
Private message received
Private message sent
Some user leaves channel
Some user enters channel
Some user was kicked from the channel
Topic has been changed
Error
Fatal error
Join list end(?)
Self part(?)
Some user changes his nick
Some user quits his connection
Mass join begin
Mass join element
Mass join end
Whois user
Whois server
Whois idle
Whois channel
Whois end
Voice status change on user
Operator status change on user
Banlist
Banlist end
%f - from
%t - to
%c - channel
%r - plain message
%m - encoded message
%j - js encoded message
1 - mod encode
2 - nickname decode
See also: ircg_lookup_format_messages().
Select the current HTTP connection for output in this execution context. Every output sent from the server connected to by connection will be copied to standard output while using default formatting or a format message set specified by ircg_register_format_messages().
See also: ircg_register_format_messages().
Function ircg_set_file() specifies a logfile path in which all output from connection connection will be logged. Returns TRUE on success, otherwise FALSE.
In case of the termination of connection connection IRCG will connect to host at port (Note: host must be an IPv4 address, IRCG does not resolve host-names due to blocking issues), send data to the new host connection and will wait until the remote part closes connection. This can be used to trigger a PHP script for example.
This feature requires IRCG 3.
Change the topic for channel channel on the server connected to by connection to new_topic.
ircg_who() will request a list of users whose nickname is matching mask on connected network connection. The optional parameter ops_only will shrink the list to server operators only.
The answer is sent to the output defined by ircg_set_file() or ircg_set_current(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also: ircg_set_file(), and ircg_set_current().
There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.
The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
To include Java support in your PHP build you must add the option --with-java[=DIR] where DIR points to the base install directory of your JDK. This extension can only be built as a shared dl. More build instructions for this extension can be found in php-src/ext/java/README.
Note to Win32 Users: In order to enable this module on a Windows environment with PHP <= 4.0.6, you must copy jvm.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32). For PHP > 4.0.6 you do not need any additional dll file.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Java configuration options
Name | Default | Changeable |
---|---|---|
java.class.path | NULL | PHP_INI_ALL |
java.home | NULL | PHP_INI_ALL |
java.library.path | NULL | PHP_INI_ALL |
java.library | JAVALIB | PHP_INI_ALL |
ÐáñÜäåéãìá 1. Java Example
|
ÐáñÜäåéãìá 2. AWT Example
|
new Java() will create an instance of a class if a suitable constructor is available. If no parameters are passed and the default constructor is useful as it provides access to classes like java.lang.System which expose most of their functionallity through static methods.
Accessing a member of an instance will first look for bean properties then public fields. In other words, print $date.time will first attempt to be resolved as $date.getTime(), then as $date.time.
Both static and instance members can be accessed on an object with the same syntax. Furthermore, if the java object is of type java.lang.Class, then static members of the class (fields and methods) can be accessed.
Exceptions raised result in PHP warnings, and NULL results. The warnings may be eliminated by prefixing the method call with an "@" sign. The following APIs may be used to retrieve and reset the last error:
Overload resolution is in general a hard problem given the differences in types between the two languages. The PHP Java extension employs a simple, but fairly effective, metric for determining which overload is the best match.
Additionally, method names in PHP are not case sensitive, potentially increasing the number of overloads to select from.
Once a method is selected, the parameters are coerced if necessary, possibly with a loss of data (example: double precision floating point numbers will be converted to boolean).
In the tradition of PHP, arrays and hashtables may pretty much be used interchangably. Note that hashtables in PHP may only be indexed by integers or strings; and that arrays of primitive types in Java can not be sparse. Also note that these constructs are passed by value, so may be expensive in terms of memory and time.
The Java Servlet SAPI builds upon the mechanism defined by the Java extension to enable the entire PHP processor to be run as a servlet. The primary advanatage of this from a PHP perspective is that web servers which support servlets typically take great care in pooling and reusing JVMs. Build instructions for the Servlet SAPI module can be found in php4/sapi/README. Notes:
While this code is intended to be able to run on any servlet engine, it has only been tested on Apache's Jakarta/tomcat to date. Bug reports, success stories and/or patches required to get this code to run on other engines would be appreciated.
PHP has a habit of changing the working directory. sapi/servlet will eventually change it back, but while PHP is running the servlet engine may not be able to load any classes from the CLASSPATH which are specified using a relative directory syntax, or find the work directory used for administration and JSP compilation tasks.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See java_last_exception_get() for an example.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The following example demonstrates the usage of Java's exception handler from within PHP:
ÐáñÜäåéãìá 1. Java exception handler
|
LDAP is the Lightweight Directory Access Protocol, and is a protocol used to access "Directory Servers". The Directory is a special kind of database that holds information in a tree structure.
The concept is similar to your hard disk directory structure, except that in this context, the root directory is "The world" and the first level subdirectories are "countries". Lower levels of the directory structure contain entries for companies, organisations or places, while yet lower still we find directory entries for people, and perhaps equipment or documents.
To refer to a file in a subdirectory on your hard disk, you might use something like:
/usr/local/myapp/docs
The forwards slash marks each division in the reference, and the sequence is read from left to right.
The equivalent to the fully qualified file reference in LDAP is the "distinguished name", referred to simply as "dn". An example dn might be:
cn=John Smith,ou=Accounts,o=My Company,c=US
The comma marks each division in the reference, and the sequence is read from right to left. You would read this dn as:
country = US
organization = My Company
organizationalUnit = Accounts
commonName = John Smith
In the same way as there are no hard rules about how you organise the directory structure of a hard disk, a directory server manager can set up any structure that is meaningful for the purpose. However, there are some conventions that are used. The message is that you can not write code to access a directory server unless you know something about its structure, any more than you can use a database without some knowledge of what is available.
Lots of information about LDAP can be found at
The Netscape SDK contains a helpful Programmer's Guide in HTML format.
You will need to get and compile LDAP client libraries from either the University of Michigan ldap-3.3 package, Netscape Directory SDK 3.0 or OpenLDAP to compile PHP with LDAP support.
LDAP support in PHP is not enabled by default. You will need to use the --with-ldap[=DIR] configuration option when compiling PHP to enable LDAP support. DIR is the LDAP base install directory.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy several files from the DLL folder of the PHP/Win32 binary package to the SYSTEM folder of your windows machine. (Ex: C:\WINNT\SYSTEM32, or C:\WINDOWS\SYSTEM). For PHP <= 4.2.0 copy libsasl.dll, for PHP >= 4.3.0 copy libeay32.dll and ssleay32.dll to your SYSTEM folder.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
For further details and definition of the PHP_INI_* constants see ini_set().
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Retrieve information for all entries where the surname starts with "S" from a directory server, displaying an extract with name and email address.
ÐáñÜäåéãìá 1. LDAP search example
|
Before you can use the LDAP calls you will need to know ..
The name or address of the directory server you will use
The "base dn" of the server (the part of the world directory that is held on this server, which could be "o=My Company,c=US")
Whether you need a password to access the server (many servers will provide read access for an "anonymous bind" but require a password for anything else)
The typical sequence of LDAP calls you will make in an application will follow this pattern:
ldap_connect() // establish connection to server
|
ldap_bind() // anonymous or authenticated "login"
|
do something like search or update the directory
and display the results
|
ldap_close() // "logout"
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The ldap_add() function is used to add entries in the LDAP directory. The DN of the entry to be added is specified by dn. Array entry specifies the information about the entry. The values in the entries are indexed by individual attributes. In case of multiple values for an attribute, they are indexed using integers starting with 0.
ÐáñÜäåéãìá 1. Complete example with authenticated bind
|
Binds to the LDAP directory with specified RDN and password. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ldap_bind() does a bind operation on the directory. bind_rdn and bind_password are optional. If not specified, anonymous bind is attempted.
ÐáñÜäåéãìá 1. Using LDAP Bind
|
ÐáñÜäåéãìá 2. Using LDAP Bind Anonymously
|
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ldap_close() closes the link to the LDAP server that's associated with the specified link_identifier.
This call is internally identical to ldap_unbind(). The LDAP API uses the call ldap_unbind(), so perhaps you should use this in preference to ldap_close().
Óçìåßùóç: This function is an alias of ldap_unbind().
Returns TRUE if value matches otherwise returns FALSE. Returns -1 on error.
ldap_compare() is used to compare value of attribute to value of same attribute in LDAP directory entry specified with dn.
The following example demonstrates how to check whether or not given password matches the one defined in DN specified entry.
ÐáñÜäåéãìá 1. Complete example of password check
|
Ðñïåéäïðïßçóç |
ldap_compare() can NOT be used to compare BINARY values! |
Óçìåßùóç: This function was added in 4.0.2.
Returns a positive LDAP link identifier on success, or FALSE on error.
ldap_connect() establishes a connection to a LDAP server on a specified hostname and port. Both the arguments are optional. If no arguments are specified then the link identifier of the already opened link will be returned. If only hostname is specified, then the port defaults to 389.
If you are using OpenLDAP 2.x.x you can specify a URL instead of the hostname. To use LDAP with SSL, compile OpenLDAP 2.x.x with SSL support, configure PHP with SSL, and use ldaps://hostname/ as host parameter. The port parameter is not used when using URLs.
Óçìåßùóç: URL and SSL support were added in 4.0.4.
Returns number of entries in the result or FALSE on error.
ldap_count_entries() returns the number of entries stored in the result of previous search operations. result_identifier identifies the internal ldap result.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ldap_delete() function delete a particular entry in LDAP directory specified by dn.
ldap_dn2ufn() function is used to turn a DN, specified by dn, into a more user-friendly form, stripping off type names.
Returns string error message.
This function returns the string error message explaining the error number errno. While LDAP errno numbers are standardized, different libraries return different or even localized textual error messages. Never check for a specific error message text, but always use an error number to check.
See also ldap_errno() and ldap_error().
Return the LDAP error number of the last LDAP command for this link.
This function returns the standardized error number returned by the last LDAP command for the given link_identifier. This number can be converted into a textual error message using ldap_err2str().
Unless you lower your warning level in your php.ini sufficiently or prefix your LDAP commands with @ (at) characters to suppress warning output, the errors generated will also show up in your HTML output.
ÐáñÜäåéãìá 1. Generating and catching an error
|
See also ldap_err2str() and ldap_error().
Returns string error message.
This function returns the string error message explaining the error generated by the last LDAP command for the given link_identifier While LDAP errno numbers are standardized, different libraries return different or even localized textual error messages. Never check for a specific error message text, but always use an error number to check.
Unless you lower your warning level in your php.ini sufficiently or prefix your LDAP commands with @ (at) characters to suppress warning output, the errors generated will also show up in your HTML output.
See also ldap_err2str() and ldap_errno().
ldap_explode_dn() function is used to split the DN returned by ldap_get_dn() and breaks it up into its component parts. Each part is known as Relative Distinguished Name, or RDN. ldap_explode_dn() returns an array of all those components. with_attrib is used to request if the RDNs are returned with only values or their attributes as well. To get RDNs with the attributes (i.e. in attribute=value format) set with_attrib to 0 and to get only values set it to 1.
Returns the first attribute in the entry on success and FALSE on error.
Similar to reading entries, attributes are also read one by one from a particular entry. ldap_first_attribute() returns the first attribute in the entry pointed by the result_entry_identifier. Remaining attributes are retrieved by calling ldap_next_attribute() successively. ber_identifier is the identifier to internal memory location pointer. It is passed by reference. The same ber_identifier is passed to the ldap_next_attribute() function, which modifies that pointer.
See also ldap_get_attributes()
Returns the result entry identifier for the first entry on success and FALSE on error.
Entries in the LDAP result are read sequentially using the ldap_first_entry() and ldap_next_entry() functions. ldap_first_entry() returns the entry identifier for first entry in the result. This entry identifier is then supplied to ldap_next_entry() routine to get successive entries from the result.
See also ldap_get_entries().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ldap_free_result() frees up the memory allocated internally to store the result and pointed by the result_identifier. All result memory will be automatically freed when the script terminates.
Typically all the memory allocated for the ldap result gets freed at the end of the script. In case the script is making successive searches which return large result sets, ldap_free_result() could be called to keep the runtime memory usage by the script low.
Returns a complete entry information in a multi-dimensional array on success and FALSE on error.
ldap_get_attributes() function is used to simplify reading the attributes and values from an entry in the search result. The return value is a multi-dimensional array of attributes and values.
Having located a specific entry in the directory, you can find out what information is held for that entry by using this call. You would use this call for an application which "browses" directory entries and/or where you do not know the structure of the directory entries. In many applications you will be searching for a specific attribute such as an email address or a surname, and won't care what other data is held.
return_value["count"] = number of attributes in the entry
return_value[0] = first attribute
return_value[n] = nth attribute
return_value["attribute"]["count"] = number of values for attribute
return_value["attribute"][0] = first value of the attribute
return_value["attribute"][i] = (i+1)th value of the attribute
ÐáñÜäåéãìá 1. Show the list of attributes held for a particular directory entry
|
See also ldap_first_attribute() and ldap_next_attribute().
Returns the DN of the result entry and FALSE on error.
ldap_get_dn() function is used to find out the DN of an entry in the result.
Returns a complete result information in a multi-dimensional array on success and FALSE on error.
ldap_get_entries() function is used to simplify reading multiple entries from the result, specified with result_identifier, and then reading the attributes and multiple values. The entire information is returned by one function call in a multi-dimensional array. The structure of the array is as follows.
The attribute index is converted to lowercase. (Attributes are case-insensitive for directory servers, but not when used as array indices.)
return_value["count"] = number of entries in the result
return_value[0] : refers to the details of first entry
return_value[i]["dn"] = DN of the ith entry in the result
return_value[i]["count"] = number of attributes in ith entry
return_value[i][j] = jth attribute in the ith entry in the result
return_value[i]["attribute"]["count"] = number of values for
attribute in ith entry
return_value[i]["attribute"][j] = jth value of attribute in ith entry
See also ldap_first_entry() and ldap_next_entry()
Sets retval to the value of the specified option. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The parameter option can be one of: LDAP_OPT_DEREF, LDAP_OPT_SIZELIMIT, LDAP_OPT_TIMELIMIT, LDAP_OPT_PROTOCOL_VERSION, LDAP_OPT_ERROR_NUMBER, LDAP_OPT_REFERRALS, LDAP_OPT_RESTART, LDAP_OPT_HOST_NAME, LDAP_OPT_ERROR_STRING, LDAP_OPT_MATCHED_DN. These are described in draft-ietf-ldapext-ldap-c-api-xx.txt
Óçìåßùóç: This function is only available when using OpenLDAP 2.x.x OR Netscape Directory SDK x.x, and was added in PHP 4.0.4
See also ldap_set_option().
Returns an array of values for the attribute on success and FALSE on error.
ldap_get_values_len() function is used to read all the values of the attribute in the entry in the result. entry is specified by the result_entry_identifier. The number of values can be found by indexing "count" in the resultant array. Individual values are accessed by integer index in the array. The first index is 0.
This function is used exactly like ldap_get_values() except that it handles binary data and not string data.
Óçìåßùóç: This function was added in 4.0.
Returns an array of values for the attribute on success and FALSE on error.
ldap_get_values() function is used to read all the values of the attribute in the entry in the result. entry is specified by the result_entry_identifier. The number of values can be found by indexing "count" in the resultant array. Individual values are accessed by integer index in the array. The first index is 0.
This call needs a result_entry_identifier, so needs to be preceded by one of the ldap search calls and one of the calls to get an individual entry.
You application will either be hard coded to look for certain attributes (such as "surname" or "mail") or you will have to use the ldap_get_attributes() call to work out what attributes exist for a given entry.
LDAP allows more than one entry for an attribute, so it can, for example, store a number of email addresses for one person's directory entry all labeled with the attribute "mail"
return_value["count"] = number of values for attribute
return_value[0] = first value of attribute
return_value[i] = ith value of attribute
ÐáñÜäåéãìá 1. List all values of the "mail" attribute for a directory entry
|
Returns a search result identifier or FALSE on error.
ldap_list() performs the search for a specified filter on the directory with the scope LDAP_SCOPE_ONELEVEL.
LDAP_SCOPE_ONELEVEL means that the search should only return information that is at the level immediately below the base_dn given in the call. (Equivalent to typing "ls" and getting a list of files and folders in the current working directory.)
This call takes 5 optional parameters. See ldap_search() notes.
Óçìåßùóç: These optional parameters were added in 4.0.2: attrsonly, sizelimit, timelimit, deref.
ÐáñÜäåéãìá 1. Produce a list of all organizational units of an organization
|
Óçìåßùóç: From 4.0.5 on it's also possible to do parallel searches. See ldap_search() for details.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function adds attribute(s) to the specified dn. It performs the modification at the attribute level as opposed to the object level. Object-level additions are done by the ldap_add() function.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function removes attribute(s) from the specified dn. It performs the modification at the attribute level as opposed to the object level. Object-level deletions are done by the ldap_delete() function.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function replaces attribute(s) from the specified dn. It performs the modification at the attribute level as opposed to the object level. Object-level modifications are done by the ldap_modify() function.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ldap_modify() function is used to modify the existing entries in the LDAP directory. The structure of the entry is same as in ldap_add().
Returns the next attribute in an entry on success and FALSE on error.
ldap_next_attribute() is called to retrieve the attributes in an entry. The internal state of the pointer is maintained by the ber_identifier. It is passed by reference to the function. The first call to ldap_next_attribute() is made with the result_entry_identifier returned from ldap_first_attribute().
See also ldap_get_attributes()
Returns entry identifier for the next entry in the result whose entries are being read starting with ldap_first_entry(). If there are no more entries in the result then it returns FALSE.
ldap_next_entry() function is used to retrieve the entries stored in the result. Successive calls to the ldap_next_entry() return entries one by one till there are no more entries. The first call to ldap_next_entry() is made after the call to ldap_first_entry() with the result_entry_identifier as returned from the ldap_first_entry().
See also ldap_get_entries()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns a search result identifier or FALSE on error.
ldap_read() performs the search for a specified filter on the directory with the scope LDAP_SCOPE_BASE. So it is equivalent to reading an entry from the directory.
An empty filter is not allowed. If you want to retrieve absolutely all information for this entry, use a filter of "objectClass=*". If you know which entry types are used on the directory server, you might use an appropriate filter such as "objectClass=inetOrgPerson".
This call takes 5 optional parameters. See ldap_search() notes.
Óçìåßùóç: These optional parameters were added in 4.0.2: attrsonly, sizelimit, timelimit, deref.
From 4.0.5 on it's also possible to do parallel searches. See ldap_search() for details.
The entry specified by dn is renamed/moved. The new RDN is specified by newrdn and the new parent/superior entry is specified by newparent. If the parameter deleteoldrdn is TRUE the old RDN value(s) is removed, else the old RDN value(s) is retained as non-distinguished values of the entry. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function currently only works with LDAPv3. You may have to use ldap_set_option() prior to binding to use LDAPv3. This function is only available when using OpenLDAP 2.x.x OR Netscape Directory SDK x.x, and was added in PHP 4.0.5.
Returns a search result identifier or FALSE on error.
ldap_search() performs the search for a specified filter on the directory with the scope of LDAP_SCOPE_SUBTREE. This is equivalent to searching the entire directory. base_dn specifies the base DN for the directory.
There is an optional fourth parameter, that can be added to restrict the attributes and values returned by the server to just those required. This is much more efficient than the default action (which is to return all attributes and their associated values). The use of the fourth parameter should therefore be considered good practice.
The fourth parameter is a standard PHP string array of the required attributes, e.g. array("mail", "sn", "cn") Note that the "dn" is always returned irrespective of which attributes types are requested.
Note too that some directory server hosts will be configured to return no more than a preset number of entries. If this occurs, the server will indicate that it has only returned a partial results set. This occurs also if the sixth parameter sizelimit has been used to limit the count of fetched entries.
The fifth parameter attrsonly should be set to 1 if only attribute types are wanted. If set to 0 both attributes types and attribute values are fetched which is the default behaviour.
With the sixth parameter sizelimit it is possible to limit the count of entries fetched. Setting this to 0 means no limit. NOTE: This parameter can NOT override server-side preset sizelimit. You can set it lower though.
The seventh parameter timelimit sets the number of seconds how long is spend on the search. Setting this to 0 means no limit. NOTE: This parameter can NOT override server-side preset timelimit. You can set it lower though.
The eighth parameter deref specifies how aliases should be handled during the search. It can be one of the following:
LDAP_DEREF_NEVER - (default) aliases are never dereferenced.
LDAP_DEREF_SEARCHING - aliases should be dereferenced during the search but not when locating the base object of the search.
LDAP_DEREF_FINDING - aliases should be dereferenced when locating the base object but not during the search.
LDAP_DEREF_ALWAYS - aliases should be dereferenced always.
Óçìåßùóç: These optional parameters were added in 4.0.2: attrsonly, sizelimit, timelimit, deref.
The search filter can be simple or advanced, using boolean operators in the format described in the LDAP documentation (see the Netscape Directory SDK for full information on filters).
The example below retrieves the organizational unit, surname, given name and email address for all people in "My Company" where the surname or given name contains the substring $person. This example uses a boolean filter to tell the server to look for information in more than one attribute.
ÐáñÜäåéãìá 1. LDAP search
|
From 4.0.5 on it's also possible to do parallel searches. To do this you use an array of link identifiers, rather than a single identifier, as the first argument. If you don't want the same base DN and the same filter for all the searches, you can also use an array of base DNs and/or an array of filters. Those arrays must be of the same size as the link identifier array since the first entries of the arrays are used for one search, the second entries are used for another, and so on. When doing parallel searches an array of search result identifiers is returned, except in case of error, then the entry corresponding to the search will be FALSE. This is very much like the value normally returned, except that a result identifier is always returned when a search was made. There are some rare cases where the normal search returns FALSE while the parallel search returns an identifier.
Sets the value of the specified option to be newval. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. on error.
The parameter option can be one of: LDAP_OPT_DEREF, LDAP_OPT_SIZELIMIT, LDAP_OPT_TIMELIMIT, LDAP_OPT_PROTOCOL_VERSION, LDAP_OPT_ERROR_NUMBER, LDAP_OPT_REFERRALS, LDAP_OPT_RESTART, LDAP_OPT_HOST_NAME, LDAP_OPT_ERROR_STRING, LDAP_OPT_MATCHED_DN, LDAP_OPT_SERVER_CONTROLS, LDAP_OPT_CLIENT_CONTROLS. Here's a brief description, see draft-ietf-ldapext-ldap-c-api-xx.txt for details.
The options LDAP_OPT_DEREF, LDAP_OPT_SIZELIMIT, LDAP_OPT_TIMELIMIT, LDAP_OPT_PROTOCOL_VERSION and LDAP_OPT_ERROR_NUMBER have integer value, LDAP_OPT_REFERRALS and LDAP_OPT_RESTART have boolean value, and the options LDAP_OPT_HOST_NAME, LDAP_OPT_ERROR_STRING and LDAP_OPT_MATCHED_DN have string value. The first example illustrates their use. The options LDAP_OPT_SERVER_CONTROLS and LDAP_OPT_CLIENT_CONTROLS require a list of controls, this means that the value must be an array of controls. A control consists of an oid identifying the control, an optional value, and an optional flag for criticality. In PHP a control is given by an array containing an element with the key oid and string value, and two optional elements. The optional elements are key value with string value and key iscritical with boolean value. iscritical defaults to FALSE if not supplied. See also the second example below.
Óçìåßùóç: This function is only available when using OpenLDAP 2.x.x OR Netscape Directory SDK x.x, and was added in PHP 4.0.4.
ÐáñÜäåéãìá 2. Set server controls
|
See also ldap_get_option().
(PHP 4 >= 4.2.0, PHP 5)
ldap_set_rebind_proc -- Set a callback function to do re-binds on referral chasing.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
LZF is a very fast compression algorithm, ideal for saving space with only slight speed cost. It can be optimized for speed or space at the time of compilation.
LZF is currently available through PECL http://pecl.php.net/package/lzf.
If PEAR is available on your *nix-like system you can use the pear installer to install the LZF extension, by the following command: pear -v install lzf.
You can always download the tar.gz package and install LZF by hand:
You can pass --enable-lzf-better-compression to optimize LZF for space rather then speed.
Windows users can download the extension dll php_lzf.dll from http://snaps.php.net/win32/PECL_STABLE/.
lzf_compress() compresses data in arg parameter.
Returns compressed data or FALSE if an error occured.
See also lzf_decompress().
lzf_decompress() decompresses data from parameter arg.
Returns decompressed data or FALSE if an error occured.
See also lzf_compress().
Ç óõíÜñôçóç mail() åðéôñÝðåé ôçí áðïóôïëÞ e-mail.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. ÅðéëïãÝò ñõèìßóåùí ôïõ Mail
Name | Default | Changeable |
---|---|---|
SMTP | "localhost" | PHP_INI_ALL |
smtp_port | "25" | PHP_INI_ALL |
sendmail_from | NULL | PHP_INI_ALL |
sendmail_path | DEFAULT_SENDMAIL_PATH | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
×ñçóéìïðïéåßôáé óå Windows ìüíï: Ôï DNS name Þ ç IP address ôïõ SMTP server ðïõ èá ðñÝðåé íá ÷ñçóéìïðïéåß ç PHP ãéá mail ðïõ óôÝëíïíôáé ìå ôçí mail() óõíÜñôçóç.
×ñçóéìïðïéåßôáé óå Windows ìüíï: Ï áñéèìüò ôçò port ãéá óýíäåóç óôï server êáèïñßæåôáé áðü ôçí ñýèìéóç SMTP üôáí ãßíåôáé áðïóôïëÞ mail ìå mail(); ìå default ôï 25. Åßíáé äéáèÝóéìï ìüíï áðü ôçí PHP 4.3.0 êáé ìåôÜ.
Ç ïðïßá "From:" äéåýèõíóç mail ðñÝðåé íá ÷ñçóéìïðïéåßôáé óôçí áðïóôïëÞ mail áðü ôçí PHP óå Windows.
Åêåß ðïõ ôï sendmail ðñüãñáììá ìðïñåß íá âñåèåß, óõíÞèùò óôï /usr/sbin/sendmail Þ /usr/lib/sendmail. Ç configure êÜíåé ìéá óïâáñÞ ðñïóðÜèåéá íá ôï åíôïðßóåé áðü ìüíç ôçò êáé íá èÝóåé Ýíá default, áëëÜ Ýáí áðïôý÷åé, ìðïñåßôå åóåßò íá ôï ïñßóåôå.
Ôá óõóôÞìáôá ðïõ äåí ÷ñçóéìïðïéïýí ôï sendmail èá ðñÝðåé íá ïñßóïõí áõôÞ ôçí ïäçãßá óôïí áíôéêáôáóôÜôç ôïõ sendmail ðïõ ðñïóöÝñåé ôï óýóôçìá mail ôïõò, åÜí õðÜñ÷åé. Ãéá ðáñÜäåéãìá, Qmail ïé ÷ñÞóôåò ìðïñïýí öõóéïëïãéêÜ íá ôï ñõèìßóïõí óå /var/qmail/bin/sendmail Þ /var/qmail/bin/qmail-inject.
Ç qmail-inject äåí áðáéôåß êáìßá åðéëïãÞ ãéá íá åðåîåñãáóôåß mail óùóôÜ.
(PHP 3>= 3.0.17, PHP 4 >= 4.0.2, PHP 5)
ezmlm_hash -- Õðïëïãßæåé ôçí ôéìÞ hash ðïõ áðáéôåßôáé áðü ôï EZMLMÇ ezmlm_hash() õðïëïãßæåé ôçí ôéìÞ hash ðïõ áðáéôåßôáé êáôÜ ôçí äéáôÞñçóç EZMLM mailing lists óå ìéá MySQL database.
Ç mail() áõôïìÜôá óôÝëíåé ìå mail ôï ìÞíõìá üðùò ïñßæåôáé óôï message óôïí ðáñáëÞðôç üðùò ïñßæåôáé óôï to. Ðïëëáðëïß ðáñáëÞðôåò ìðïñïýí íá ïñéóôïýí ìå ôçí ðñïóèÞêç åíüò êüììáôïò áíÜìåóá óå êÜèå äéåýèõíóç óôï to. Email ìå óõííçìÝíá áñ÷åßá êáé åéäéêïýò ôýðïõò ðåñéå÷ïìÝíïõ ìðïñïýí íá áðïóôáëïýí ìå ôçí ÷ñÞóç áõôÞò ôçò óõíÜñôçóçò. Áõôü ðñáãìáôïðïéåßôáé ìÝóù MIME-êùäéêïðïßçóçò - ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äåßôå áõôü: ôï Üñèñï Zend Þ ôéò PEAR Mime Classes.
Ôá ðáñáêÜôù RFC's ìðïñïýí åðéóÞò íá âïçèÞóïõí: RFC 1896, RFC 2045, RFC 2046, RFC 2047, RFC 2048, and RFC 2049.
Ç mail() åðéóôñÝöåé TRUE åÜí ôï mail ðáñáäüèçêå åðéôõ÷þò, FALSE óå áíôßèåôç ðåñßðôùóç.
Ðñïåéäïðïßçóç |
Ç åãêáôÜóôáóç óôá Windows ôçò mail() äéáöÝñåé ðïéêéëïôñüðùò áðü ôçí áíôßóôïé÷ç óôï UNIX. Êáôáñ÷Þí, äåí ÷ñçóéìïðïéåß Ýíá ôïðéêü binary áñ÷åßï ãéá íá óõíèÝôåé ìçíýìáôá áëëÜ ìüíï åíåñãåß óå direct sockets ðïõ óçìáßíåé üôé Ýíá MTA áðáéôåßôáé ðïõ èá "áêïýåé" óå Ýíá network socket (ôï ïðïßï ìðïñåß íá åßíáé åßôå óôï localhost -ôïðéêÜ- åßôå óôï áðïìáêñõóìÝíï ìç÷Üíçìá). ¸ðåéôá, ôá custom headers üðùò From:, Cc:, Bcc: êáé Date: äåí åñìçíåýïíôáé áðü ôï MTA óôçí áñ÷Þ, áëëÜ áíáëýïíôáé áðü ôçí PHP. Ç PHP < 4.3 õðïóôÞñéæå ìüíï ôï óôïé÷åßï header Cc: (êáé Þôáí case-sensitive). Ç PHP >= 4.3 õðïóôçñßæåé üëá ôá ðñïáíáöåñèÝíôá óôïé÷åßá header êáé äåí åßíáé ðëÝïí case-sensitive. |
ÅÜí ðåñáóôåß Ýíá fourth string argument, áõôü ôï string åéóÜãåôáé óôï ôÝëïò ôïõ header. Áõôü ÷ñçóéìïðïéåßôáé êõñßùò ãéá íá ðñïóôåèïýí åðéðëÝïí headers. Ðïëëáðëïß åðéðëÝïí headers ÷ùñßæïíôáé ìå Ýíá return (enter) êáé ìéá íÝá ãñáììÞ.
Óçìåßùóç: ÐñÝðåé íá ÷ñçóéìïðïéåßôå ôï \r\n ãéá íá ÷ùñßæåôå ôá headers, áí êáé êÜðïéïé Unix mail transfer agents åíäÝ÷åôáé íá äïõëåýïõí ìüíï ìå ìéÜ íÝá ãñáììÞ (\n).
Ç ðáñÜìåôñïò additional_parameters ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá ðåñáóôåß ìéá åðéðñüóèåôç ðáñÜìåôñïò óôï ðñüãñáììá, ôï ïðïßï Ý÷åé ñõèìéóôåß íá ÷ñçóéìïðïéåß üôáí óôÝëíåôáé mail ìå ÷ñÞóç ôçò sendmail_path ñýèìéóçò. Ãéá ðáñÜäåéãìá, áõôü ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá ïñßóåé ôçí äéåýèõíóç ôïõ áðïóôïëÝá üôáí ãßíåôáé ÷ñÞóç ôïõ sendmail ìå ôçí åðéëïãÞ -f. ºóùò ÷ñåéáóôåß íá ðñïóèÝóåôå ôïí ÷ñÞóôç, ðïõ ï web server óáò ÷ñçóéìïðïéåß óýìöùíá ìå ôéò ñõèìßóåéò ôïõ sendmail, ãéá íá áðïôñÝøåôå íá ðñïóôåèåß óôï ìÞíõìá Ýíá 'X-Warning' header üôáí ïñßæåôå ôïí áðïóôïëÝá ìå áõôÞ ôç ìÝèïäï.
Óçìåßùóç: ÁõôÞ ç ðÝìðôç ðáñÜìåôñïò ðñïóôÝèçêå óôçí PHP 4.0.5. Áðü ôçí PHP 4.2.3 áõôÞ ç ðáñÜìåôñïò åßíáé áðåíåñãïðïéçìÝíç óôï safe_mode êáé ç óõíÜñôçóç mail() èá åìöáíßóåé Ýíá ìÞíõìá ðñïçäïðïéÞóçò êáé èá åðéóôñÝøåé FALSE åÜí ðñïóðáèåßôå íá ôçí ÷ñçóéìïðïéÞóåôå.
Ìðïñåßôå åðßóçò íá ÷ñçóéìïðïéÞóåôå áðëÝò ôå÷íéêÝò string building ãéá íá äçìéïõñãÞóåôå ðïëýðëïêá ìçíýìáôá email.
ÐáñÜäåéãìá 4. ÓôÝëíïíôáò ðïëýðëïêá email.
|
Óçìåßùóç: Öñïíôßóôå íá ìçí Ý÷åôå ôßðïôá newline ÷áñáêôÞñåò óôï to Þ subject, äéáöïñåôéêÜ ôï mail ßóùò íá ìçí óôáëåß óùóôÜ.
Óçìåßùóç: Ç to ðáñÜìåôñïò äåí ìðïñåß íá åßíáé ìéá äéåýèõíóç ôçò ìïñöÞò "Something <someone@example.com>". Ç åíôïëÞ mail äåí èá ôï áíáëýóåé óùóôÜ êáôÜ ôçí åðéêïéíùíßá ìå ôï MTA.
Äåßôå åðßóçò imap_mail().
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
This extension has been moved from PHP as of PHP 4.2.0 and now mailparse lives in PECL.
(4.1.0 - 4.1.2 only)
mailparse_determine_best_xfer_encoding -- Figures out the best way of encoding the content read from the file pointer fp, which must be seek-ableÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.1.0 - 4.1.2 only)
mailparse_msg_extract_part_file -- Extracts/decodes a message section, decoding the transfer encodingÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.1.0 - 4.1.2 only)
mailparse_msg_extract_part -- Extracts/decodes a message section. If callbackfunc is not specified, the contents will be sent to "stdout"Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.1.0 - 4.1.2 only)
mailparse_msg_get_part_data -- Returns an associative array of info about the messageÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.1.0 - 4.1.2 only)
mailparse_msg_get_structure -- Returns an array of mime section names in the supplied messageÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.1.0 - 4.1.2 only)
mailparse_msg_parse_file -- Parse file and return a resource representing the structureÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.1.0 - 4.1.2 only)
mailparse_rfc822_parse_addresses -- Parse addresses and returns a hash containing that dataÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.1.0 - 4.1.2 only)
mailparse_stream_encode -- Streams data from source file pointer, apply encoding and write to destfpÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
mailparse_uudecode_all -- Scans the data from fp and extract each embedded uuencoded file. Returns an array listing filename informationÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ïé óõíáñôÞóåéò ìáèçìáôéêþí ÷åéñßæïíôáé ôéìÝò ìüíï ìÝóá óôá üñéá ôùí integer êáé float ôýðùí ôïõ õðïëïãéóôÞ óáò. (áõôü áíôéóôïé÷åß óôïõò ôýðïõò long êáé double, áíôßóôïé÷á, ôçò C) Ãéá ôï ðþò ìðïñåßôå íá ÷åéñéóôåßôå ìåãáëýôåñïõ ìåãÝèïõò áñéèìïýò, êïéôÜîôå óôéò arbitrary precision math functions.
Ïé ðáñáêÜôù óôáèåñÝò åßíáé ðÜíôá äéáèÝóéìåò ùò ìÝñïò ôïõ ðõñÞíá ôçò PHP.
Ðßíáêáò 1. ÌáèçìáôéêÝò ÓôáèåñÝò
ÓôáèåñÜ | ÔéìÞ | ÐåñéãñáöÞ |
---|---|---|
M_PI | 3.14159265358979323846 | Pi |
M_E | 2.7182818284590452354 | e |
M_LOG2E | 1.4426950408889634074 | log_2 e |
M_LOG10E | 0.43429448190325182765 | log_10 e |
M_LN2 | 0.69314718055994530942 | log_e 2 |
M_LN10 | 2.30258509299404568402 | log_e 10 |
M_PI_2 | 1.57079632679489661923 | pi/2 |
M_PI_4 | 0.78539816339744830962 | pi/4 |
M_1_PI | 0.31830988618379067154 | 1/pi |
M_2_PI | 0.63661977236758134308 | 2/pi |
M_SQRTPI | 1.77245385090551602729 | sqrt(pi) [4.0.2] |
M_2_SQRTPI | 1.12837916709551257390 | 2/sqrt(pi) |
M_SQRT2 | 1.41421356237309504880 | sqrt(2) |
M_SQRT3 | 1.73205080756887729352 | sqrt(3) [4.0.2] |
M_SQRT1_2 | 0.70710678118654752440 | 1/sqrt(2) |
M_LNPI | 1.14472988584940017414 | log_e(pi) [4.0.2] |
M_EULER | 0.57721566490153286061 | Euler constant [4.0.2] |
ÅðéóôñÝöåé ôçí áðüëõôç ôéìÞ ôïõ number. ÅÜí ï number åßíáé float, ï åðéóôñåöüìåíïò ôýðïò åßíáé float, áëëéþò åßíáé integer (ùò float Ý÷åé óõíÞèùò ìåãáëýôåñï åýñïò ôéìþí áðü Ýíáí integer).
ÅðéóôñÝöåé ôï áíôßóôñïöï óõíçìßôïíï ôçò arg óå rad. Ç acos() åßíáé óõìðëçñùìáôéêÞ ôçò áõíÜñôçóçò cos(), ôï ïðïßï óçìáßíåé üôé a==cos(acos(a)) ãéá êÜèå ôéìÞ ôïõ a ðïõ åßíáé åíôüò ôïõ ðåäßïõ ôçò acos().
ÅðéóôñÝöåé ôï áíôßóôñïöï õðåñâïëéêü óõíçìßôïíï ôçò arg, ð.÷. ôçí ôéìÞ ôçò ïðïßáò ôï õðåñâïëéêü óõíçìßôïíï åßíáé arg.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
ÅðéóôñÝöåé ôï áíôßóôñïöï çìßôïíï ôçò arg óå rad. Ç asin() åßíáé ç óõìðëçñùìáôéêÞ ôçò óõíÜñôçóçò sin(), ôï ïðïßï óçìáßíåé a==sin(asin(a)) ãéá êÜèå ôéìÞ ôïõ a ðïõ åßíáé åíôüò ôïõ ðåäßïõ ôçò asin().
ÅðéóôñÝöåé ôï áíôßóôñïöï õðåñâïëéêü çìßôïíï ôçò arg, ð.÷. ôçí ôéìÞ ôçò ïðïßáò ôï õðåñâïëéêü çìßôïíï åßíáé arg.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
ÁõôÞ ç óõíÜñôçóç õðïëïãßæåé ôçí áíôßóôñïöç åöáðôïìÝíç ôùí äýï ìåôáâëçôþí x êáé y. Åßíáé üìïéï ìå ôïí õðïëïãéóìü ôçò áíôßóôñïöçò åöáðôïìÝíçò ôïõ y / x, åêôüò ôïõ üôé ôá ðñüóçìá êáé ôùí äýï ðáñáìÝôñùí ÷ñçóéìïðïéïýíôáé ãéá ôïí õðïëïãéóìü ôïõ ôåôáñôçìïñßïõ óôï ïðïßï áíÞêåé ôï áðïôÝëåóìá.
Ç óõíÜñôçóç åðéóôñÝöåé ôï áðïôÝëåóìá, ôï ïðïßï âñßóêåôáé ìåôáîý ôïõ -PI êáé ôïõ PI (óõìðåñéëáìâáíïìÝíùí ôùí Üêñùí), óå rad.
ÅðéóôñÝöåé ôçí áíôßóôñïöç åöáðôïìÝíç ôçò arg óå rad. Ç atan() åßíáé ç óõìðëçñùìáôéêÞ ôçò óõíÜñôçóçò tan(), ôï ïðïßï óçìáßíåé üôé a==tan(atan(a)) ãéá êÜèå ôéìÞ ôïõ a ðïõ åßíáé åíôüò ôïõ ðåäßïõ ôçò atan().
ÅðéóôñÝöåé ôçí áíôßóôñïöç õðåñâïëéêÞ åöáðôïìÝíç ôçò arg, ð.÷. ôçí ôéìÞ ôçò ïðïßáò ç õðåñâïëéêÞ åöáðôïìÝíç åßíáé arg.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
base_convert -- ÌåôáôñÝðåé Ýíáí áñéèìü áðü ìßá äïóìÝíç âÜóç óå êÜðïéá ÜëëçÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôï number óå áíáðáñÜóôáóç óôç âÜóç tobase. Ç âÜóç óôçí ïðïßá ï number åßíáé äïóìÝíïò ïñßæåôáé óôç frombase. Ïé frombase êáé tobase ðñÝðåé íá åßíáé ìåôáîý 2 êáé 36, óõìðåñéëáìâáíïìÝíùí ôùí Üêñùí. Øçößá áñéèìþí ìå âÜóç ìåãáëýôåñç ôïõ 10 áíáðáñßóôáíôáé ìå ôá ãñÜììáôá a-z, ìå ôï a íá óçìáßíåé 10, ôï b 11 êáé ôï z 35.
ÅðéóôñÝöåé ôï äåêáäéêü éóïäýíáìï ôïõ äõáäéêïý áñéèìïý ðïõ áíáðáñéóôÜ ï binary_string.
Ç bindec() ìåôáôñÝðåé Ýíá äõáäéêü áñéèìü óå integer. Ï ìåãáëýôåñïò áñéèìüò ðïõ ìðïñåß íá ìåôáôñáðåß åßíáé 31 bits áðü 1 Þ ï 2147483647 óôï äåêáäéêü.
ÁíáôñÝîôå åðßóçò óôç óõíÜñôçóç decbin().
ÅðéóôñÝöåé ôçí áìÝóùò ìåãáëýôåñç áêÝñáéá ôéìÞ óôñïããõëïðïéþíôáò ðñïò ôá Üíù ôçí value åÜí åßíáé áðáñáßôçôï. Ç åðéóôñåöüìåíç ôéìÞ ôçò ceil() ðáñáìÝíåé float êáèþò ôï åýñïò ôéìþí ôùí float åßíáé óõíÞèùò ìåãáëýôåñï áðü áõôü ôùí integer.
ÅðéóôñÝöåé ôï õðåñâïëéêü óõíçìßôïíï ôçò arg, ðïõ õðïëïãßæåôáé áðü ôçí ðáñÜóôáóç (exp(arg) + exp(-arg))/2.
ÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôç äõáäéêÞ áíáðáñÜóôáóç ôïõ number. Ï ìåãáëýôåñïò áñéèìüò ðïõ ìðïñåß íá ìåôáôñáðåß åßíáé ï 4294967295, óôï äåêáäéêü, ï ïðïßïò äßíåé ùò áðïôÝëåóìá Ýíá string áðü 32 Üóóïõò.
ÁíáôñÝîôå åðßóçò óôç óõíÜñôçóç bindec().
ÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôç äåêáåîáäéêÞ áíáðáñÜóôáóç ôïõ number. Ï ìåãáëýôåñïò áñéèìüò ðïõ ìðïñåß íá ìåôáôñáðåß åßíáé ï 2147483647, óôï äåêáäéêü, ï ïðïßïò äßíåé ôïí "7fffffff".
ÁíáôñÝîôå åðßóçò óôç hexdec().
ÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôçí ïêôáäéêÞ áíáðáñÜóôáóç ôïõ number. Ï ìåãáëýôåñïò áñéèìüò ðïõ ìðïñåß íá ìåôáôñáðåß åéíáé ï 2147483647, óôï äåêáäéêü, ï ïðïßïò äßíåé ôïí "17777777777".
ÁíáôñÝîôå åðßóçò óôçí octdec().
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
deg2rad -- ÌåôáôñÝðåé Ýíáí áñéèìü ðïõ åßíáé óå ìïßñåò óôïí éóïäýíáìü ôïõ óå rad.ÁõôÞ ç óõíÜñôçóç ìåôáôñÝðåé ôï number áðü ìïßñåò óôïí éóïäýíáìü ôïõ óå rad.
ÁíáôñÝîôå åðßóçò óôç rad2deg().
(PHP 3, PHP 4 , PHP 5)
exp -- Õðïëïãßæåé ìßá äýíáìç ôïõ e (ç âÜóç ôïõ Íåðåñéáíïý Þ Öõóéêïý ëïãáñßèìïõ)(PHP 4 >= 4.1.0, PHP 5)
expm1 -- ÅðéóôñÝöåé ôïí áñéèìü exp(number) - 1, õðïëïãéóìÝíï ìå ôÝôïéï ôñüðï þóôå íá åßíáé áêñéâÞò áêüìç êáé üôáí ç ôéìÞ ôïõ number ôåßíåé óôï ìçäÝí.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé ôçí áìÝóùò ðñïçãïýìåíç áêÝñáéá ôéìÞ óôñïããõëïðïéþíôáò ðñïò ôá êÜôù ôç value, åÜí åßíáé áðáñáßôçôï. Ç åðéóôñåöüìåíç ôéìÞ ôçò floor() ðáñáìÝíåé float åðåéäÞ ôï åýñïò ôéìþí ôùí float åßíáé óõíÞèùò ìåãáëýôåñï áðü áõôü ôùí int.
(PHP 4 >= 4.2.0, PHP 5)
fmod -- ÅðéóôñÝöåé ôï äåêáäéêü õðüëïéðï (modulo) ôçò äéáßñåóçò ôùí ðáñáìÝôñùíÅðéóôñÝöåé ôï modulo äéáéñþíôáò ôï äéáéñåôÝï (x) ìå ôï äéáéñÝôç (y). Ôï õðüëïéðï (r) ïñßæåôáé ùò: x = i * y + r, ãéá êÜðïéïí integer i. ÅÜí ï y åßíáé ìç ìçäåíéêüò, ôï r Ý÷åé ôï ßäéï ðñüóçìï ìå ôï x êáé ìÝãåèïò ìéêñüôåñï áðü áõôü ôïõ y.
ÅðéóôñÝöåé ôç ìÝãéóôç ôéìÞ ðïõ ìðïñåß íá åðéóôñáöåß êáëþíôáò ôçí rand().
ÁíáôñÝîôå åðßóçò óôéò: rand(), srand(), êáé mt_getrandmax().
ÅðéóôñÝöåé ôï äåêáäéêü éóïäýíáìï ôïõ äåêáåîáäéêïý áñéèìïý ðïõ áíôéðñïóùðåýåé ï hex_string. Ç hexdec() ìåôáôñÝðåé Ýíá äåêáåîáäéêü string óå Ýíá äåêáäéêü áñéèìü. Ï ìåãáëýôåñïò áñéèìüò ðïõ ìðïñåß íá ìåôáôñáðåß åßíáé ï 7fffffff Þ ï äåêáäéêüò 2147483647.
Ç hexdec() èá áíôéêáôáóôÞóåé ôï êÜèå ìç-äåêáåîáäéêü ÷áñáêôÞñá ðïõ óõíáíôÜ ìå ôï 0. ¸ôóé, üëá ôá ìçäåíéêÜ ðïõ âñßóêïíôáé áñéóôåñÜ áãíïïýíôáé, åíþ áõôÜ ðïõ âñßóêïíôáé äåîéÜ ëáìâÜíïíôáé õð' üøéí óôç ìåôáôñïðÞ.
ÁíáôñÝîôå åðßóçò óôçí dechex().
(PHP 4 >= 4.1.0, PHP 5)
hypot -- ÅðéóôñÝöåé ôï áðïôÝëåóìá ôçò ðáñÜóôáóçò sqrt( num1*num1 + num2*num2)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé TRUE åÜí ç ôéìÞ ôçò val åßíáé ðåðåñáóìÝíïò áñéèìüò ìÝóá óôá üñéá åíüò float ôçò PHP óôç óõãêåêñéìÝíç platform.
ÅðéóôñÝöåé TRUE åÜí ç ôéìÞ ôçò val åßíáé ôï Üðåéñï (èåôéêü Þ áñíçôéêü), üðùò ôï áðïôÝëåóìá ôïõ log(0) Þ ïðïéáäÞðïôå ôéìÞ ðïëý ìåãÜëç ãéá íá áðïèçêåõèåß ùò float óôç óõãêåêñéìÝíç platform.
ÅðéóôñÝöåé TRUE åÜí ç ôéìÞ ôçò val åßíáé NAN, üðùò ôï áðïôÝëåóìá ôïõ acos(1.01).
Ç lcg_value() åðéóôñÝöåé Ýíá øåõäï-ôõ÷áßï áñéèìü ìÝóá óôï äéÜóôçìá (0, 1). Ç óõíÜñôçóç óõíäõÜæåé äýï CGs ìå ðåñéüäïõò ôïõ 2^31 - 85 êáé 2^31 - 249. Ç ðåñßïäïò ôçò óõíÜñôçóçò åßíáé ßóç ìå ôï ãéíüìåíï êáé ôùí äýï primes.
(PHP 4 >= 4.1.0, PHP 5)
log1p -- ÅðéóôñÝöåé ôï áðïôÝëåóìá ôçò log(1 + number), õðïëïãéóìÝíï Ýôóé þóôå íá åßíáé áêñéâÝò áêüìá êé üôáí ï number ôåßíåé óôï ìçäÝí.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅÜí ç ðñïáéñåôéêÞ ðáñÜìåôñïò base åßíáé ïñéóìÝíç, ç log() åðéóôñÝöåé ôï áðïôÝëåóìá ôïõ logbase arg, áëëéþò ç log() åðéóôñÝöåé ôï öõóéêü ëïãÜñéèìï ôçò arg.
Óçìåßùóç: Ç base åßíáé äéáèÝóéìç ìå ôçí Ýêäïóç 4.3.0 ôçò PHP.
Ç max() åðéóôñÝöåé ôçí áñéèìçôéêÜ ìåãáëýôåñç áðü ôéò ôéìÝò ôùí ðáñáìÝôñùí.
ÅÜí ç ðñþôç ðáñÜìåôñïò åßíáé Ýíá array, ç max() åðéóôñÝöåé ôç ìÝãéóôç ôéìÞ ôïõ array. ÅÜí ç ðñþôç ðáñÜìåôñïò åßíáé integer, string Þ float, ÷ñåéÜæåóôå ôïõëÜ÷éóôïí äýï ðáñáìÝôñïõò êáé ç max() åðéóôñÝöåé ôç ìåãáëýôåñç áðü áõôÝò ôéò ôéìÝò. Ìðïñåßôå íá óõãêñßíåôå áðåñéüñéóôï ðëÞèïò ôéìþí.
ÅÜí ìßá Þ ðåñéóóüôåñåò ôéìÝò åßíáé float, üëåò ïé ôéìÝò èá áíôéìåôùðéóèïýí ùò float, êáé ìßá ôéìÞ ôÝôïéïõ ôýðïõ èá åðéóôñáöåß. ÅÜí äåí õðÜñ÷åé ôéìÞ ðïõ íá åßíáé float, üëåò èá áíôéìåôùðéóèïýí ùò integers, êáé èá åðéóôñáöåß Ýíáò integer.
Ç min() åðéóôñÝöåé ôçí áñéèìçôéêÜ ìéêñüôåñç áðü ôçò ôéìÝò ôùí ðáñáìÝôñùí.
Óôçí ðñþôç ðåñßðôùóç, ÷ñåéÜæåóôå ôïõëÜ÷éóôïí äýï ðáñáìÝôñïõò êáé ç min() åðéóôñÝöåé ôç ìéêñüôåñç ôùí ôéìþí. Ìðïñåßôå íá óõãêñßíåôå áðåñéüñéóôï ðëÞèïò ôéìþí. ÅÜí ìßá áðü ôéò ìåôáâëçôÝò äåí åßíáé ïñéóìÝíç, ç min() èá áðïôý÷åé.
Óôç äåýôåñç ðåñßðôùóç, ç min() åðéóôñÝöåé ôçí ìéêñüôåñç ôéìÞ óôï numbers.
ÅÜí ìßá Þ ðåñéóóüôåñåò ôéìÝò åßíáé float, üëåò ïé ôéìÝò èá áíôéìåôùðéóèïýí ùò floats, êáé èá åðéóôñáöåß Ýíáò float. ÅÜí äåí õðÜñ÷åé ôéìÞ ðïõ íá åßíáé float, üëåò áíôéìåôùðßæïíôáé ùò integers, êáé èá åðéóôñáöåß Ýíáò integer. Óå ðåñßðôùóç áðïôõ÷ßáò, ç min() åðéóôñÝöåé NULL êáé Ýíá error of level E_WARNING èá ðáñá÷èåß.
<?php $a = 4; $b = 9; $c = 3; $arr = array(99, 34, 11); // You may want to implement your own error checking in // case of failure (a variable may not be set) if (!$min_value = @min($a, $b, $c)) { echo "Could not get min value, please try again."; } else { echo "min value is $min_value"; } print min($arr); // 11 ?> |
ÁáôñÝîôå åðßóçò óôç max().
Äßíåé ôç ìåãáëýôåñç ôéìÞ ðïõ ìðïñåß íá åðéóôñáöåß áðü Ýíá êÜëåóìá ôçò mt_rand().
ÁíáôñÝîôå åðßóçò óôéò: mt_rand(), mt_srand() êáé getrandmax().
ÐïëëÝò ãåííÞôñéåò ôõ÷áßùí áñéèìþí ðáëéüôåñùí libcs Ý÷ïõí Üãíùóôá ÷áñáêôçñéóôéêÜ êáé åßíáé áñãÝò. Ç ÷ñÞóç ôçò ãåííÞôñéáò ôõ÷áßùí áñéèìþí libc ìå ôç óõíÜñôçóç rand() áðïôåëåß ôçí default åðéëïãÞ ôçò PHP. H óõíÜñôçóç mt_rand() åßíáé ìßá drop-in áíôéêáôÜóôáóç ôïõ ðñïçãïýìåíïõ. ×ñçóéìïðïåß ìßá ãåííÞôñéá ôõ÷áßùí áñéèìþí ìå ãíùóôÜ ÷áñáêôçñéóôéêÜ, ôç Mersenne Twister, ç ïðïßá ðáñÜãåé ôõ÷áßïõò áñéèìïýò êáôÜëëçëïõò ãéá ôçí áíÜðôõîç åíüò åßäïò êñõðôïãñáößáò (áíáôñÝîôå óôéò home pages ãéá ëåðôïìÝñéåò) êáé åßíáé ôÝóóåñéò öïñÝò ãñçãïñüôåñç áðü ìßá ìÝóç libc. Ç Homepage ôçò Mersenne Twister åßíáé ç http://www.math.keio.ac.jp/~matumoto/emt.html êáé ìßá âåëôéóôïðïéçìÝíç Ýêäïóç ôïõ MT êþäéêá åßíáé äéáèÝóéìç óôï ??? .
ÅÜí êáëåóôåß ÷ùñßò ôéò ðñïáéñåôéêÝò ðáñáìÝôñïõò min, max, ç mt_rand() åðéóôñÝöåé ìßá øåõäï-ôõ÷áßá ôéìÞ ìåôáîý 0 êáé RAND_MAX. ÅÜí èÝëåôå Ýíáí ôõ÷áßï áñéèìü ìåôáîý 5 êáé 15 (óõìðåñéëáìâáíïìÝíùí ôùí Üêñùí), ãéá ðáñÜäåéãìá, ÷ñçóéìïðïéåßóôå mt_rand (5, 15).
Óå ðáëéüôåñåò åêäüóåéò ôçò PHP, Ýðñåðå íá ôñïöïäïôÞóåôå ôç ãåííÞôñéá ôõ÷áßùí áñéèìþí ðñéí ôç ÷ñçóéìïðïéÞóåôå ìå ôç mt_srand(). Áðü ôçí Ýêäïóç 4.2.0 áõôü äåí åßíáé ðëÝïí áðáñáßôçôï.
Óçìåßùóç: Óôéò åêäüóåéò ðñéí ôçí 3.0.7 ç óçìáóßá ôçò max Þôáí range. Ãéá íá Ý÷åôå ôá ßäéá áðïôåëÝóìáôá óå áõôÝò ôéò åêäüóåéò, ôï ðñïçãïýìåíï ðáñÜäåéãìá ãßíåôáé mt_rand (5, 11).
ÁíáôñÝîôå åðßóçò óôéò: mt_srand(), mt_getrandmax() êáé rand().
Ôñïöïäïôåß ôçí êáëýôåñç ãåííÞôñéá ôõ÷áßùí áñéèìþí ìå ôç seed.
// seed with microseconds function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } mt_srand(make_seed()); $randval = mt_rand(); |
Óçìåßùóç: Áðü ôçí PHP 4.2.0 äåí åßíáé áðáñáßôçôï íá ôñïöïäïôÞóåôå ôç ãåííÞôñéá ôõ÷áßùí áñéèìþí ðñéí ôç ÷ñçóéìïðïéÞóåôå.
ÁíáôñÝîôå åðßóçò óôéò: mt_rand(), mt_getrandmax() êáé srand().
ÅðéóôñÝöåé ôï äåêáäéêü éóïäýíáìï ôïõ ïêôáäéêïý áñéèìïý octal_string. Ï ìåãáëýôåñïò áñéèìüò ðïõ ìðïñåß íá ìåôáôñáðåß åßíáé ï 17777777777 Þ ï äåêáäéêüò 2147483647.
ÁíáôñÝîôå åðßóçò óôçí decoct().
ÅðéóôñÝöåé ìßá ðñïóÝããéóç ôïõ pi. Ï åðéóôñåöüìåíïò float áñéèìüò Ý÷åé áêñßâåéá ðïõ åîáñôÜôáé áðü ôçí precision directive óôï php.ini, ç ïðïßá Ý÷åé ôåèåß åê ôùí ðñïôÝñùí óôï 14. Åðßóçò, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôç óôáèåñÜ M_PI ç ïðïßá Ý÷åé áêñéâþò ôï ßäéï áðïôÝëåóìá ìå ôçí pi().
ÅðéóôñÝöåé ôçí base õøùìÝíåé óôï exp. ÅÜí åßíáé äõíáôü, ç óõíÜñôçóç èá åðéóôñÝøåé Ýíáí integer.
ÅÜí äåí ìðïñåß íá õðïëïãéóôåß ç äýíáìç, èá åìöáíéóôåß Ýíá warning, êáé ç pow() èá åðéóôñÝøåé FALSE.
Ðñïåéäïðïßçóç |
Óôçí PHP 4.0.6 êáé ðéï ðñßí ç pow() ðÜíôá åðÝóôñåöå Ýíá float, êáé äåí åìöÜíéæå warnings. |
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
rad2deg -- ÌåôáôñÝðåé Ýíáí áñéèìü äïóìÝíï óå rad óôïí éóïäýíáìï ôïõ óå ìïßñåòÁõôÞ ç óõíÜñôçóç ìåôáôñÝðåé ôï number áðü rad óå ìïßñåò.
ÁíáôñÝîôå åðßóçò óôçí deg2rad().
ÅÜí êáëåóôåß ÷ùñßò ôéò ðñïáéñåôéêÝò ðáñáìÝôñïõò min, max ç rand() åðéóôñÝöåé ìßá øåõäï-ôõ÷áßá ôéìÞ ìåôáîý ôïõ 0 êáé ôïõ RAND_MAX. ÅÜí èÝëåôå Ýíáí ôõ÷áßï áñéèìü ìåôáîý ôïõ 5 êáé 15 (óõìðåñéëáìâáíïìÝíùí ôùí Üêñùí), ãéá ðáñÜäåéãìá, ÷ñçóéìïðïåßóôå ôï rand (5,15).
Óå ðáëéüôåñåò åêäüóåéò ôçò PHP, Ýðñåðå íá ôñïöïäïôÞóåôå ôç ãåííÞôñéá ôõ÷áßùí áñéèìþí ðñéí ôç ÷ñçóéìïðïéÞóåôå ìå ôçí srand(). Áðü ôçí Ýêäïóç 4.2.0 áõôü äåí åßíáé ðëÝïí áðáñáßôçôï.
Óçìåßùóç: Óôéò åêäüóåéò ðñéí ôçí 3.0.7 ç óçìáóßá ôïõ max Þôáí range. Óå áõôÝò, ãéá íá ðÜñåôå ôï ßäéï áðïôÝëåóìá ìå áõôü ôïõ ðáñáäåßãìáôïò, èá ðñÝðåé íá ÷ñçóéìïðïéåßóåôå ôï rand (5, 11).
ÁíáôñÝîôå åðßóçò óôéò: srand(), getrandmax(), êáé mt_rand().
ÅðéóôñÝöåé ôç óôïããõëïðïéçìÝíç ôéìÞ ôçò val ìå ìßá óõãêåêñéìÝíç precision (ðëÞèïò äåêáäéêþí øçößùí ìåôÜ ôçí ôåëåßá). Ç precision ìðïñåß íá åßíáé, åðßóçò, áñíçôéêÞ Þ êáé ìçäÝí (default).
Ðñïóï÷Þ |
Ç PHP äåí ÷åéñßæåôáé óùóôÜ strings ôïõ ôýðïõ "12,300.2". ÁíáôñÝîôå óôï converting from strings. |
echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 |
Óçìåßùóç: Ç ðáñÜìåôñïò precision åßíáé äéáèÝóéìç ìüíï óôçí Ýêäïóç 4 ôçò PHP.
Ç sin() åðéóôñÝöåé ôï çìßôïíï ôçò arg. Ç arg åßíáé óå rad.
ÅðéóôñÝöåé ôï õðåñâïëéêü çìßôïíï ôçò arg, ðïõ ïñßæåôáé ùò (exp(arg) - exp(-arg))/2.
ÅðéóôñÝöåé ôçí ôåôñáãùíéêÞ ñßæá ôçò arg.
<?php // Precision depends on your precision directive echo sqrt(9); // 3 echo sqrt(10); // 3.16227766 ... ?> |
ÁíáôñÝîôå åðßóçò óôçí pow().
Ôñïöïäïôåß ôç ãåííÞôñéá ôõ÷áßùí áñéèìþí ìå ôçí seed.
// seed with microseconds function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } srand(make_seed()); $randval = rand(); |
Óçìåßùóç: Áðü ôçí Ýêäïóç 4.2.0 ôçò PHP äåí åßíáé ðëÝïí áðáñáßôçôï íá ôñïöïäïôåßôå ôç ãåííÞôñéá ôõ÷áßùí áñéèìþí ðñéí íá ôç ÷ñçóéìïðïéÞóåôå.
ÁíáôñÝîôå åðßóçò óôéò: rand(), getrandmax() êáé mt_srand().
While there are many languages in which every necessary character can be represented by a one-to-one mapping to a 8-bit value, there are also several languages which require so many characters for written communication that cannot be contained within the range a mere byte can code. Multibyte character encoding schemes were developed to express that many (more than 256) characters in the regular bytewise coding system.
When you manipulate (trim, split, splice, etc.) strings encoded in a multibyte encoding, you need to use special functions since two or more consecutive bytes may represent a single character in such encoding schemes. Otherwise, if you apply a non-multibyte-aware string function to the string, it probably fails to detect the beginning or ending of the multibyte character and ends up with a corrupted garbage string that most likely loses its original meaning.
mbstring provides these multibyte specific string functions that help you deal with multibyte encodings in PHP, which is basically supposed to be used with single byte encodings. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs.
mbstring is also designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience (listed below), whereas mbstring was originally developed for use in Japanese web pages.
Encodings of the following types are safely used with PHP.
A singlebyte encoding,
which has ASCII-compatible (ISO646 compatible) mappings for the characters in range of 00h to 7fh.
A multibyte encoding,
which has ASCII-compatible mappings for the characters in range of 00h to 7fh.
which don't use ISO2022 escape sequences.
which don't use a value from 00h to 7fh in any of the compounded bytes that represents a single character.
These are examples of character encodings that are unlikely to work with PHP.
Although PHP scripts written in any of those encodings might not work, especially in the case where encoded strings appear as identifiers or literals in the script, you can almost avoid using these encodings by setting up the mbstring's transparent encoding filter function for incoming HTTP queries.
Óçìåßùóç: It's highly discouraged to use SJIS, BIG5, CP936, CP949 and GB18030 for the internal encoding unless you are familiar with the parser, the scanner and the character encoding.
Óçìåßùóç: If you have some database connected with PHP, it is recommended that you use the same character encoding for both database and the internal encoding for ease of use and better performance.
If you are using PostgreSQL, the character encoding used in the database and the one used in the PHP may differ as it supports automatic character set conversion between the backend and the frontend.
mbstring is a non-default extension. This means it is not enabled by default. You must explicitly enable the module with the configure option. See the Install section for details.
The following configure options are related to the mbstring module.
--enable-mbstring=LANG: Enable mbstring functions. This option is required to use mbstring functions.
As of PHP 4.3.0, mbstring extension provides enhanced support for Simplified Chinese, Traditional Chinese, Korean, and Russian in addition to Japanese. To enable that feature, you will have to supply either one of the following options to the LANG parameter; --enable-mbstring=cn for Simplified Chinese support, --enable-mbstring=tw for Traditional Chinese support, --enable-mbstring=kr for Korean support, --enable-mbstring=ru for Russian support, and --enable-mbstring=ja for Japanese support.
Also --enable-mbstring=all is convenient for you to enable all the supported languages listed above.
Óçìåßùóç: Japanese language support is also enabled by --enable-mbstring without any options for the sake of backwards compatibility.
--enable-mbstr-enc-trans : Enable HTTP input character encoding conversion using mbstring conversion engine. If this feature is enabled, HTTP input character encoding may be converted to mbstring.internal_encoding automatically.
Óçìåßùóç: As of PHP 4.3.0, the option --enable-mbstr-enc-trans was eliminated and replaced with the runtime setting mbstring.encoding_translation. HTTP input character encoding conversion is enabled when this is set to On (the default is Off).
--enable-mbregex: Enable regular expression functions with multibyte character support.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. mbstring configuration options
Name | Default | Changeable |
---|---|---|
mbstring.language | "neutral" | PHP_INI_SYSTEM | PHP_INI_PERDIR |
mbstring.detect_order | NULL | PHP_INI_ALL |
mbstring.http_input | "pass" | PHP_INI_ALL |
mbstring.http_output | "pass" | PHP_INI_ALL |
mbstring.internal_encoding | NULL | PHP_INI_ALL |
mbstring.script_encoding | NULL | PHP_INI_ALL |
mbstring.substitute_character | NULL | PHP_INI_ALL |
mbstring.func_overload | "0" | PHP_INI_SYSTEM | PHP_INI_PERDIR |
mbstring.encoding_translation | "0" | PHP_INI_SYSTEM | PHP_INI_PERDIR |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
mbstring.language is the default national language setting (NLS) used in mbstring. Note that this option automagically defines mbstring.internal_encoding and mbstring.internal_encoding should be placed after mbstring.language in php.ini
mbstring.encoding_translation enables the transparent character encoding filter for the incoming HTTP queries, which performs detection and conversion of the input encoding to the internal character encoding.
mbstring.internal_encoding defines the default internal character encoding.
mbstring.http_input defines the default HTTP input character encoding.
mbstring.http_output defines the default HTTP output character encoding.
mbstring.detect_order defines default character code detection order. See also mb_detect_order().
mbstring.substitute_character defines character to substitute for invalid character encoding.
mbstring.func_overload overloads a set of single byte functions by the mbstring counterparts. See Funtion overloading for more information.
According to the HTML 4.01 specification, Web browsers are allowed to encode a form being submitted with a character encoding different from the one used for the page. See mb_http_input() to detect character encoding used by browsers.
Although popular browsers are capable of giving a reasonably accurate guess to the character encoding of a given HTML document, it would be better to set the charset parameter in the Content-Type HTTP header to the appropriate value by header() or default_charset ini setting.
ÐáñÜäåéãìá 1. php.ini setting examples
|
ÐáñÜäåéãìá 2. php.ini setting for EUC-JP users
|
ÐáñÜäåéãìá 3. php.ini setting for SJIS users
|
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
HTTP input/output character encoding conversion may convert binary data also. Users are supposed to control character encoding conversion if binary data is used for HTTP input/output.
Óçìåßùóç: In PHP 4.3.2 or earlier versions, there was a limitation in this functionality that mbstring does not perform character encoding conversion in POST data if the enctype attribute in the form element is set to multipart/form-data. So you have to convert the incoming data by yourself in this case if necessary.
Beginning with PHP 4.3.3, if enctype for HTML form is set to multipart/form-data and mbstring.encoding_translation is set to On in php.ini the POST'ed variables and the names of uploaded files will be converted to the internal character encoding as well. However, the conversion isn't applied to the query keys.
HTTP Input
There is no way to control HTTP input character conversion from PHP script. To disable HTTP input character conversion, it has to be done in php.ini.
When using PHP as an Apache module, it is possible to override those settings in each Virtual Host directive in httpd.conf or per directory with .htaccess. Refer to the Configuration section and Apache Manual for details.
HTTP Output
There are several ways to enable output character encoding conversion. One is using php.ini, another is using ob_start() with mb_output_handler() as ob_start callback function.
Óçìåßùóç: PHP3-i18n users should note that mbstring's output conversion differs from PHP3-i18n. Character encoding is converted using output buffer.
Currently the following character encodings are supported by the mbstring module. Any of those Character encodings can be specified in the encoding parameter of mbstring functions.
The following character encoding is supported in this PHP extension:
UCS-4
UCS-4BE
UCS-4LE
UCS-2
UCS-2BE
UCS-2LE
UTF-32
UTF-32BE
UTF-32LE
UTF-16
UTF-16BE
UTF-16LE
UTF-7
UTF7-IMAP
UTF-8
ASCII
EUC-JP
SJIS
eucJP-win
SJIS-win
ISO-2022-JP
JIS
ISO-8859-1
ISO-8859-2
ISO-8859-3
ISO-8859-4
ISO-8859-5
ISO-8859-6
ISO-8859-7
ISO-8859-8
ISO-8859-9
ISO-8859-10
ISO-8859-13
ISO-8859-14
ISO-8859-15
byte2be
byte2le
byte4be
byte4le
BASE64
HTML-ENTITIES
7bit
8bit
EUC-CN
CP936
HZ
EUC-TW
CP950
BIG-5
EUC-KR
UHC (CP949)
ISO-2022-KR
Windows-1251 (CP1251)
Windows-1252 (CP1252)
CP866 (IBM866)
KOI8-R
php.ini entry, which accepts encoding name, accepts "auto" and "pass" also. mbstring functions, which accepts encoding name, and accepts "auto".
If "pass" is set, no character encoding conversion is performed.
If "auto" is set, it is expanded to the list of encodings defined per the NLS. For instance, if the NLS is set to Japanese, the value is assumed to be "ASCII,JIS,UTF-8,EUC-JP,SJIS".
See also mb_detect_order()
You might often find it difficult to get an existing PHP application work in a given multibyte environment. That's mostly because lots of PHP applications out there are written with the standard string functions such as substr(), which are known to not properly handle multibyte-encoded strings.
mbstring supports 'function overloading' feature which enables you to add multibyte awareness to such an application without code modification by overloading multibyte counterparts on the standard string functions. For example, mb_substr() is called instead of substr() if function overloading is enabled. This feature makes it easy to port applications that only support single-byte encodings to a multibyte environment in many cases.
To use the function overloading, set mbstring.func_overload in php.ini to a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions. For example, if is set for 7, mail, strings and regular expression functions should be overloaded. The list of overloaded functions are shown below.
Ðßíáêáò 2. Functions to be overloaded
value of mbstring.func_overload | original function | overloaded function |
---|---|---|
1 | mail() | mb_send_mail() |
2 | strlen() | mb_strlen() |
2 | strpos() | mb_strpos() |
2 | strrpos() | mb_strrpos() |
2 | substr() | mb_substr() |
2 | strtolower() | mb_strtolower() |
2 | strtoupper() | mb_strtoupper() |
2 | substr_count() | mb_substr_count() |
4 | ereg() | mb_ereg() |
4 | eregi() | mb_eregi() |
4 | ereg_replace() | mb_ereg_replace() |
4 | eregi_replace() | mb_eregi_replace() |
4 | split() | mb_split() |
Óçìåßùóç: It is not recommended to use the function overloading option in the per-directory context, because it's not confirmed yet to be stable enough in a production environment and may lead to undefined behaviour.
It is often said quite hard to figure out how Japanese texts are handled in the computer. This is not only because Japanese characters can only be represented by multibyte encodings, but because different encoding standards are adopted for different purposes / platforms. Moreover, not a few character set standards are used there, which are slightly different from one another. Those facts have often led developers to inevitable mess-up.
To create a working web application that would be put in the Japanese environment, it is important to use the proper character encoding and character set for the task in hand.
Storage for a character can be up to six bytes
Most of multibyte characters often appear twice as wide as a single-byte character on display. Those characters are called "zen-kaku" in Japanese which means "full width", and the other (narrower) characters are called "han-kaku" - means half width. However the graphical properties of the characters depend on the glyphs of the type faces used to display them or print them out.
Some character encodings use shift(escape) sequences defined in ISO2022 to switch the code map of the specific code area (00h to 7fh).
ISO-2022-JP should be used in SMTP/NNTP, and headers and entities should be reencoded as per RFC requirements. Although those are not requisites, it's still a good idea because several popular user agents cannot recognize any other encoding methods.
Webpages created for mobile phone services such as i-mode, Vodafone live!, or EZweb are supposed to use Shift_JIS.
Multibyte character encoding schemes and the related issues are very complicated. There should be too few space to cover in sufficient details. Please refer to the following URLs and other resources for further readings.
Unicode materials
Japanese/Korean/Chinese character information
Summaries of supported encodings
Name in the IANA character set registry: ISO-10646-UCS-4
Underlying character set: ISO 10646
Description: The Universal Character Set with 31-bit code space, standardized as UCS-4 by ISO/IEC 10646. It is kept synchronized with the latest version of the Unicode code map.
Additional note: If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented.
Name in the IANA character set registry: ISO-10646-UCS-4
Underlying character set: UCS-4
Description: See above.
Additional note: In contrast to UCS-4, strings are always assumed to be in big endian form.
Name in the IANA character set registry: ISO-10646-UCS-4
Underlying character set: UCS-4
Description: See above.
Additional note: In contrast to UCS-4, strings are always assumed to be in little endian form.
Name in the IANA character set registry: ISO-10646-UCS-2
Underlying character set: UCS-2
Description: The Universal Character Set with 16-bit code space, standardized as UCS-2 by ISO/IEC 10646. It is kept synchronized with the latest version of the unicode code map.
Additional note: If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented.
Name in the IANA character set registry: ISO-10646-UCS-2
Underlying character set: UCS-2
Description: See above.
Additional note: In contrast to UCS-2, strings are always assumed to be in big endian form.
Name in the IANA character set registry: ISO-10646-UCS-2
Underlying character set: UCS-2
Description: See above.
Additional note: In contrast to UCS-2, strings are always assumed to be in little endian form.
Name in the IANA character set registry: UTF-32
Underlying character set: Unicode
Description: Unicode Transformation Format of 32-bit unit width, whose encoding space refers to the Unicode's codeset standard. This encoding scheme wasn't identical to UCS-4 because the code space of Unicode were limited to a 21-bit value.
Additional note: If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented.
Name in the IANA character set registry: UTF-32BE
Underlying character set: Unicode
Description: See above
Additional note: In contrast to UTF-32, strings are always assumed to be in big endian form.
Name in the IANA character set registry: UTF-32LE
Underlying character set: Unicode
Description: See above
Additional note: In contrast to UTF-32, strings are always assumed to be in little endian form.
Name in the IANA character set registry: UTF-16
Underlying character set: Unicode
Description: Unicode Transformation Format of 16-bit unit width. It's worth a note that UTF-16 is no longer the same specification as UCS-2 because the surrogate mechanism has been introduced since Unicode 2.0 and UTF-16 now refers to a 21-bit code space.
Additional note: If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented.
Name in the IANA character set registry: UTF-16BE
Underlying character set: Unicode
Description: See above.
Additional note: In contrast to UTF-16, strings are always assumed to be in big endian form.
Name in the IANA character set registry: UTF-16BE
Underlying character set: Unicode
Description: See above.
Additional note: In contrast to UTF-16, strings are always assumed to be in big endian form.
Name in the IANA character set registry: UTF-8
Underlying character set: Unicode / UCS
Description: Unicode Transformation Format of 8-bit unit width.
Additional note: none
Name in the IANA character set registry: UTF-7
Underlying character set: Unicode
Description: A mail-safe transformation format of Unicode, specified in RFC2152.
Additional note: none
Name in the IANA character set registry: (none)
Underlying character set: Unicode
Description: A variant of UTF-7 which is specialized for use in the IMAP protocol.
Additional note: none
Name in the IANA character set registry: US-ASCII (preferred MIME name) / iso-ir-6 / ANSI_X3.4-1986 / ISO_646.irv:1991 / ASCII / ISO646-US / us / IBM367 / CP367 / csASCII
Underlying character set: ASCII / ISO 646
Description: American Standard Code for Information Interchange is a commonly-used 7-bit encoding. Also standardized as an international standard, ISO 646.
Additional note: (none)
Name in the IANA character set registry: EUC-JP (preferred MIME name) / Extended_UNIX_Code_Packed_Format_for_Japanese / csEUCPkdFmtJapanese
Underlying character set: Compound of US-ASCII / JIS X0201:1997 (hankaku kana part) / JIS X0208:1990 / JIS X0212:1990
Description: As you see the name is derived from an abbreviation of Extended UNIX Code Packed Format for Japanese, this encoding is mostly used on UNIX or alike platforms. The original encoding scheme, Extended UNIX Code, is designed on the basis of ISO 2022.
Additional note: The character set referred to by EUC-JP is different to IBM932 / CP932, which are used by OS/2® and Microsoft® Windows®. For information interchange with those platforms, use EUCJP-WIN instead.
Name in the IANA character set registry: Shift_JIS (preferred MIME name) / MS_Kanji / csShift_JIS
Underlying character set: Compound of JIS X0201:1997 / JIS X0208:1997
Description: Shift_JIS was developed in early 80's, at the time personal Japanese word processors were brought into the market, in order to maintain compatiblities with the legacy encoding scheme JIS X 0201:1976. According to the IANA definition the codeset of Shift_JIS is slightly different to IBM932 / CP932. However, the names "SJIS" / "Shift_JIS" are often wrongly used to refer to these codesets.
Additional note: For the CP932 codemap, use SJIS-WIN instead.
Name in the IANA character set registry: (none)
Underlying character set: Compound of JIS X0201:1997 / JIS X0208:1997 / IBM extensions / NEC extensions
Description: While this "encoding" uses the same encoding scheme as EUC-JP, the underlying character set is different. That is, some code points map to different characters than EUC-JP.
Additional note: none
Name in the IANA character set registry: Windows-31J / csWindows31J
Underlying character set: Compound of JIS X0201:1997 / JIS X0208:1997 / IBM extensions / NEC extensions
Description: While this "encoding" uses the same encoding scheme as Shift_JIS, the underlying character set is different. That means some code points map to different characters than Shift_JIS.
Additional note: (none)
Name in the IANA character set registry: ISO-2022-JP (preferred MIME name) / csISO2022JP
Underlying character set: US-ASCII / JIS X0201:1976 / JIS X0208:1978 / JIS X0208:1983
Description: RFC1468
Additional note: (none)
Name in the IANA character set registry: JIS
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-1
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-2
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-3
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-4
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-5
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-6
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-7
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-8
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-9
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-10
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-13
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-14
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-8859-15
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: byte2be
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: byte2le
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: byte4be
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: byte4le
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: BASE64
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: HTML-ENTITIES
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: 7bit
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: 8bit
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: EUC-CN
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: CP936
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: HZ
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: EUC-TW
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: CP950
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: BIG-5
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: EUC-KR
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: UHC (CP949)
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: ISO-2022-KR
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: Windows-1251 (CP1251)
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: Windows-1252 (CP1252)
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: CP866 (IBM866)
Underlying character set:
Description:
Additional note:
Name in the IANA character set registry: KOI8-R
Underlying character set:
Description:
Additional note:
mb_convert_case() returns case folded version of string converted in the way specified by mode.
mode can be one of MB_CASE_UPPER, MB_CASE_LOWER or MB_CASE_TITLE.
encoding specifies the encoding of str; if omitted, the internal character encoding value will be used.
The return value is str with the appropriate case folding applied.
By contrast to the standard case folding functions such as strtolower() and strtoupper(), case folding is performed on the basis of the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).
For more information about the Unicode properties, please see http://www.unicode.org/unicode/reports/tr21/.
ÐáñÜäåéãìá 1. mb_convert_case() example
|
See also mb_strtolower(), mb_strtoupper(), strtolower() and strtoupper().
mb_convert_encoding() converts character encoding of string str from from-encoding to to-encoding.
str : String to be converted.
from-encoding is specified by character code name before conversion. it can be array or string - comma separated enumerated list. If it is not specified, the internal encoding will be used.
ÐáñÜäåéãìá 1. mb_convert_encoding() example
|
See also mb_detect_order().
(PHP 4 >= 4.0.6, PHP 5)
mb_convert_kana -- Convert "kana" one from another ("zen-kaku", "han-kaku" and more)mb_convert_kana() performs "han-kaku" - "zen-kaku" conversion for string str. It returns converted string. This function is only useful for Japanese.
option is conversion option. Default value is "KV".
encoding is character encoding. If it is omitted, internal character encoding is used.
Specify with combination of following options. Default value is KV.
Ðßíáêáò 1. Applicable Conversion Options
Option | Meaning |
---|---|
r | Convert "zen-kaku" alphabets to "han-kaku" |
R | Convert "han-kaku" alphabets to "zen-kaku" |
n | Convert "zen-kaku" numbers to "han-kaku" |
N | Convert "han-kaku" numbers to "zen-kaku" |
a | Convert "zen-kaku" alphabets and numbers to "han-kaku" |
A | Convert "han-kaku" alphabets and numbers to "zen-kaku" (Characters included in "a", "A" options are U+0021 - U+007E excluding U+0022, U+0027, U+005C, U+007E) |
s | Convert "zen-kaku" space to "han-kaku" (U+3000 -> U+0020) |
S | Convert "han-kaku" space to "zen-kaku" (U+0020 -> U+3000) |
k | Convert "zen-kaku kata-kana" to "han-kaku kata-kana" |
K | Convert "han-kaku kata-kana" to "zen-kaku kata-kana" |
h | Convert "zen-kaku hira-gana" to "han-kaku kata-kana" |
H | Convert "han-kaku kata-kana" to "zen-kaku hira-gana" |
c | Convert "zen-kaku kata-kana" to "zen-kaku hira-gana" |
C | Convert "zen-kaku hira-gana" to "zen-kaku kata-kana" |
V | Collapse voiced sound notation and convert them into a character. Use with "K","H" |
mb_convert_variables() convert character encoding of variables vars in encoding from-encoding to encoding to-encoding. It returns character encoding before conversion for success, FALSE for failure.
mb_convert_variables() join strings in Array or Object to detect encoding, since encoding detection tends to fail for short strings. Therefore, it is impossible to mix encoding in single array or object.
It from-encoding is specified by array or comma separated string, it tries to detect encoding from from-coding. When encoding is omitted, detect_order is used.
vars (3rd and larger) is reference to variable to be converted. String, Array and Object are accepted. mb_convert_variables() assumes all parameters have the same encoding.
mb_decode_mimeheader() decodes encoded-word string str in MIME header.
It returns decoded string in internal character encoding.
See also mb_encode_mimeheader().
Convert numeric string reference of string str in specified block to character. It returns converted string.
convmap is array to specifies code area to convert.
encoding is character encoding. If it is omitted, internal character encoding is used.
ÐáñÜäåéãìá 1. convmap example
|
See also mb_encode_numericentity().
mb_detect_encoding() detects character encoding in string str. It returns detected character encoding.
encoding-list is list of character encoding. Encoding order may be specified by array or comma separated list string.
If encoding_list is omitted, detect_order is used.
ÐáñÜäåéãìá 1. mb_detect_encoding() example
|
See also mb_detect_order().
mb_detect_order() sets automatic character encoding detection order to encoding-list. It returns TRUE for success, FALSE for failure.
encoding-list is array or comma separated list of character encoding. ("auto" is expanded to "ASCII, JIS, UTF-8, EUC-JP, SJIS")
If encoding-list is omitted, it returns current character encoding detection order as array.
This setting affects mb_detect_encoding() and mb_send_mail().
Óçìåßùóç: mbstring currently implements following encoding detection filters. If there is an invalid byte sequence for following encoding, encoding detection will fail.
Óçìåßùóç: UTF-8, UTF-7, ASCII, EUC-JP,SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP
For ISO-8859-*, mbstring always detects as ISO-8859-*.
For UTF-16, UTF-32, UCS2 and UCS4, encoding detection will fail always.
ÐáñÜäåéãìá 2. mb_detect_order() examples
|
See also mb_internal_encoding(), mb_http_input(), mb_http_output() and mb_send_mail().
mb_encode_mimeheader() encodes a given string str by the MIME header encoding scheme. Returns a converted version of the string represented in ASCII.
charset specifies the name of the character set in which str is represented in. The default value is determined by the current NLS setting (mbstring.language).
transfer-encoding specifies the scheme of MIME encoding. It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
linefeed specifies the EOL (end-of-line) marker with which mb_encode_mime_header() performs line-folding (a RFC term, the act of breaking a line longer than a certain length into multiple lines. The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
Óçìåßùóç: This function isn't designed to break lines at higher-level contextual break points (word boundaries, etc.). This behaviour may clutter up the original string with unexpected spaces.
See also mb_decode_mimeheader().
mb_encode_numericentity() converts specified character codes in string str from HTML numeric character reference to character code. It returns converted string.
convmap is array specifies code area to convert.
encoding is character encoding.
ÐáñÜäåéãìá 1. convmap example
|
ÐáñÜäåéãìá 2. mb_encode_numericentity() example
|
See also mb_decode_numericentity().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_match() returns TRUE if string matches regular expression pattern, FALSE if not.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_replace() scans string for matches to pattern, then replaces the matched text with replacement and returns the result string or FALSE on error. Multibyte character can be used in pattern.
Matching condition can be set by option parameter. If i is specified for this parameter, the case will be ignored. If x is specified, white space will be ignored. If m is specified, match will be executed in multiline mode and line break will be included in '.'. If p is specified, match will be executed in POSIX mode, line break will be considered as normal character. If e is specified, replacement string will be evaluated as PHP expression.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_eregi_replace().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_search_getpos() returns the point to start regular expression match for mb_ereg_search(), mb_ereg_search_pos(), mb_ereg_search_regs(). The position is represented by bytes from the head of string.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_search_setpos().
(PHP 4 >= 4.2.0)
mb_ereg_search_getregs -- Retrieve the result from the last multibyte regular expression matchÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_search_getregs() returns an array including the sub-string of matched part by last mb_ereg_search(), mb_ereg_search_pos(), mb_ereg_search_regs(). If there are some maches, the first element will have the matched sub-string, the second element will have the first part grouped with brackets, the third element will have the second part grouped with brackets, and so on. It returns FALSE on error;
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_search_init().
(PHP 4 >= 4.2.0)
mb_ereg_search_init -- Setup string and regular expression for multibyte regular expression matchÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_search_init() sets string and pattern for multibyte regular expression. These values are used for mb_ereg_search(), mb_ereg_search_pos(), mb_ereg_search_regs(). It returns TRUE for success, FALSE for error.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_search_regs().
(PHP 4 >= 4.2.0)
mb_ereg_search_pos -- Return position and length of matched part of multibyte regular expression for predefined multibyte stringÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_search_pos() returns an array including position of matched part for multibyte regular expression. The first element of the array will be the beginning of matched part, the second element will be length (bytes) of matched part. It returns FALSE on error.
The string for match is specified by mb_ereg_search_init(). It it is not specified, the previous one will be used.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_search_init().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_search_regs() executes the multibyte regular expression match, and if there are some matched part, it returns an array including substring of matched part as first element, the first grouped part with brackets as second element, the second grouped part as third element, and so on. It returns FALSE on error.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_search_init().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_search_setpos() sets the starting point of match for mb_ereg_search().
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_search_init().
(PHP 4 >= 4.2.0)
mb_ereg_search -- Multibyte regular expression match for predefined multibyte stringÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_search() returns TRUE if the multibyte string matches with the regular expression, FALSE for otherwise. The string for matching is set by mb_ereg_search_init(). If pattern is not specified, the previous one is used.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_search_init().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg() executes the regular expression match with multibyte support, and returns 1 if matches are found. If the optional third parameter was specified, the function returns the byte length of matched part, and the array regs will contain the substring of matched string. The functions returns 1 if it matches with the empty string. If no matches found or error happend, FALSE will be returned.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_eregi()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_ereg_replace() scans string for matches to pattern, then replaces the matched text with replacement and returns the result string or FALSE on error. Multibyte character can be used in pattern. The case will be ignored.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg_replace().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_eregi() executes the regular expression match with multibyte support, and returns 1 if matches are found. This function ignore case. If the optional third parameter was specified, the function returns the byte length of matched part, and the array regs will contain the substring of matched string. The functions returns 1 if it matches with the empty string. If no matches found or error happend, FALSE will be returned.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_get_info() returns internal setting parameter of mbstring.
If type isn't specified or is specified to "all", an array having the elements "internal_encoding", "http_output", "http_input", "func_overload" will be returned.
If type is specified for "http_output", "http_input", "internal_encoding", "func_overload", the specified setting parameter will be returned.
See also mb_internal_encoding(), mb_http_output().
mb_http_input() returns result of HTTP input character encoding detection.
type: Input string specifies input type. "G" for GET, "P" for POST, "C" for COOKIE. If type is omitted, it returns last input type processed.
Return Value: Character encoding name. If mb_http_input() does not process specified HTTP input, it returns FALSE.
See also mb_internal_encoding(), mb_http_output(), mb_detect_order().
If encoding is set, mb_http_output() sets HTTP output character encoding to encoding. Output after this function is converted to encoding. mb_http_output() returns TRUE for success and FALSE for failure.
If encoding is omitted, mb_http_output() returns current HTTP output character encoding.
See also mb_internal_encoding(), mb_http_input(), mb_detect_order().
mb_internal_encoding() sets internal character encoding to encoding If parameter is omitted, it returns current internal encoding.
encoding is used for HTTP input character encoding conversion, HTTP output character encoding conversion and default character encoding for string functions defined by mbstring module.
encoding: Character encoding name
Return Value: If encoding is set,mb_internal_encoding() returns TRUE for success, otherwise returns FALSE. If encoding is omitted, it returns current character encoding name.
See also mb_http_input(), mb_http_output() and mb_detect_order().
mb_language() sets language. If language is omitted, it returns current language as string.
language setting is used for encoding e-mail messages. Valid languages are "Japanese", "ja","English","en" and "uni" (UTF-8). mb_send_mail() uses this setting to encode e-mail.
Language and its setting is ISO-2022-JP/Base64 for Japanese, UTF-8/Base64 for uni, ISO-8859-1/quoted printable for English.
Return Value: If language is set and language is valid, it returns TRUE. Otherwise, it returns FALSE. When language is omitted, it returns language name as string. If no language is set previously, it returns FALSE.
See also mb_send_mail().
(PHP 4 >= 4.0.6, PHP 5)
mb_output_handler -- Callback function converts character encoding in output buffermb_output_handler() is ob_start() callback function. mb_output_handler() converts characters in output buffer from internal character encoding to HTTP output character encoding.
4.1.0 or later version, this handler adds charset HTTP header when following conditions are met:
Does not set Content-Type by header()
Default MIME type begins with text/
http_output setting is other than pass
contents : Output buffer contents
status : Output buffer status
Return Value: String converted
Óçìåßùóç: If you want to output some binary data such as image from PHP script with PHP 4.3.0 or later, Content-Type: header must be send using header() before any binary data was send to client (e.g. header("Content-Type: image/png")). If Content-Type: header was send, output character encoding conversion will not be performed.
Note that if 'Content-Type: text/*' was send using header(), the sending data is regarded as text, encoding conversion will be performed using character encoding settings.
If you want to output some binary data such as image from PHP script with PHP 4.2.x or earlier, you must set output encoding to "pass" using mb_http_output().
See also ob_start().
mb_parse_str() parses GET/POST/COOKIE data and sets global variables. Since PHP does not provide raw POST/COOKIE data, it can only used for GET data for now. It preses URL encoded data, detects encoding, converts coding to internal encoding and set values to result array or global variables.
encoded_string: URL encoded data.
result: Array contains decoded and character encoding converted values.
Return Value: It returns TRUE for success or FALSE for failure.
See also mb_detect_order(), mb_internal_encoding().
mb_preferred_mime_name() returns MIME charset string for character encoding encoding. It returns charset string.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_regex_encoding() returns the character encoding used by multibyte regex functions.
If the optional parameter encoding is specified, it is set to the character encoding for multibyte regex. The default value is the internal character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_internal_encoding(), mb_ereg()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_regex_set_options() sets the default options described by options for multibyte regex functions.
Returns the previous options. If options is omitted, it returns the string that describes the current options.
Óçìåßùóç: This function is supported in PHP 4.3.0 or higher.
See also mb_split(), mb_ereg() and mb_eregi()
mb_send_mail() sends email. Headers and message are converted and encoded according to mb_language() setting. mb_send_mail() is wrapper function of mail(). See mail() for details.
to is mail addresses send to. Multiple recipients can be specified by putting a comma between each address in to. This parameter is not automatically encoded.
subject is subject of mail.
message is mail message.
additional_headers is inserted at the end of the header. This is typically used to add extra headers. Multiple extra headers are separated with a newline ("\n").
additional_parameter is a MTA command line parameter. It is useful when setting the correct Return-Path header when using sendmail.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also mail(), mb_encode_mimeheader(), and mb_language().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
mb_split() split multibyte string using regular expression pattern and returns the result as an array.
If optional parameter limit is specified, it will be split in limit elements as maximum.
The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.
Óçìåßùóç: This function is supported in PHP 4.2.0 or higher.
See also: mb_regex_encoding(), mb_ereg().
mb_strcut() returns the portion of str specified by the start and length parameters.
mb_strcut() performs equivalent operation as mb_substr() with different method. If start position is multi-byte character's second byte or larger, it starts from first byte of multi-byte character.
It subtracts string from str that is shorter than length AND character that is not part of multi-byte string or not being middle of shift sequence.
encoding is character encoding. If it is not set, internal character encoding is used.
See also mb_substr(), mb_internal_encoding().
mb_strimwidth() truncates string str to specified width. It returns truncated string.
If trimmarker is set, trimmarker is appended to return value.
start is start position offset. Number of characters from the beginning of string. (First character is 0)
trimmarker is string that is added to the end of string when string is truncated.
encoding is character encoding. If it is omitted, internal encoding is used.
See also mb_strwidth() and mb_internal_encoding().
mb_strlen() returns number of characters in string str having character encoding encoding. A multi-byte character is counted as 1.
encoding is character encoding for str. If encoding is omitted, internal character encoding is used.
See also mb_internal_encoding(), strlen().
mb_strpos() returns the numeric position of the first occurrence of needle in the haystack string. If needle is not found, it returns FALSE.
mb_strpos() performs multi-byte safe strpos() operation based on number of characters. needle position is counted from the beginning of the haystack. First character's position is 0. Second character position is 1, and so on.
If encoding is omitted, internal character encoding is used. mb_strrpos() accepts string for needle where strrpos() accepts only character.
offset is search offset. If it is not specified, 0 is used.
encoding is character encoding name. If it is omitted, internal character encoding is used.
See also mb_strpos(), mb_internal_encoding(), strpos()
mb_strrpos() returns the numeric position of the last occurrence of needle in the haystack string. If needle is not found, it returns FALSE.
mb_strrpos() performs multi-byte safe strrpos() operation based on number of characters. needle position is counted from the beginning of haystack. First character's position is 0. Second character position is 1.
If encoding is omitted, internal encoding is assumed. mb_strrpos() accepts string for needle where strrpos() accepts only character.
encoding is character encoding. If it is not specified, internal character encoding is used.
See also mb_strpos(), mb_internal_encoding(), strrpos().
mb_strtolower() returns str with all alphabetic characters converted to lowercase.
encoding specifies the encoding of str; if omitted, the internal character encoding value will be used.
For more information about the Unicode properties, please see http://www.unicode.org/unicode/reports/tr21/.
By contrast to strtolower(), 'alphabetic' is determined by the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).
See also strtolower(), mb_strtoupper() and mb_convert_case().
mb_strtoupper() returns str with all alphabetic characters converted to uppercase.
encoding specifies the encoding of str; if omitted, the internal character encoding value will be used.
By contrast to strtoupper(), 'alphabetic' is determined by the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as a-umlaut (ä).
For more information about the Unicode properties, please see http://www.unicode.org/unicode/reports/tr21/.
See also strtoupper(), mb_strtolower() and mb_convert_case().
mb_strwidth() returns width of string str.
Multi-byte character usually twice of width compare to single byte character.
Ðßíáêáò 1. Characters width
Chars | Width |
---|---|
U+0000 - U+0019 | 0 |
U+0020 - U+1FFF | 1 |
U+2000 - U+FF60 | 2 |
U+FF61 - U+FF9F | 1 |
U+FFA0 - | 2 |
encoding is character encoding. If it is omitted, internal encoding is used.
See also: mb_strimwidth(), mb_internal_encoding().
mb_substitute_character() specifies substitution character when input character encoding is invalid or character code is not exist in output character encoding. Invalid characters may be substituted NULL(no output), string or integer value (Unicode character code value).
This setting affects mb_convert_encoding(), mb_convert_variables(), mb_output_handler(), and mb_send_mail().
substchar : Specify Unicode value as integer or specify as string as follows
"none" : no output
"long" : Output character code value (Example: U+3000,JIS+7E7E)
Return Value: If substchar is set, it returns TRUE for success, otherwise returns FALSE. If substchar is not set, it returns Unicode value or "none"/"long".
mb_substr_count() returns the number of times the needle substring occurs in the haystack string.
encoding specifies the encoding for needle and haystack. If omitted, internal character encoding is used.
See also substr_count(), mb_strpos(), mb_substr().
mb_substr() returns the portion of str specified by the start and length parameters.
mb_substr() performs multi-byte safe substr() operation based on number of characters. Position is counted from the beginning of str. First character's position is 0. Second character position is 1, and so on.
If encoding is omitted, internal encoding is assumed.
encoding is character encoding. If it is omitted, internal character encoding is used.
See also mb_strcut(), mb_internal_encoding().
MCAL stands for Modular Calendar Access Library.
Libmcal is a C library for accessing calendars. It's written to be very modular, with pluggable drivers. MCAL is the calendar equivalent of the IMAP module for mailboxes.
With mcal support, a calendar stream can be opened much like the mailbox stream with the IMAP support. Calendars can be local file stores, remote ICAP servers, or other formats that are supported by the mcal library.
Calendar events can be pulled up, queried, and stored. There is also support for calendar triggers (alarms) and recurring events.
With libmcal, central calendar servers can be accessed, removing the need for any specific database or local file programming.
Most of the functions use an internal event structure that is unique for each stream. This alleviates the need to pass around large objects between functions. There are convenience functions for setting, initializing, and retrieving the event structure values.
Óçìåßùóç: This extension has been removed as of PHP 5 and moved to the PECL repository.
Óçìåßùóç: PHP had an ICAP extension previously, but the original library and the PHP extension is not supported anymore. The suggested replacement is MCAL.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
This extension requires the mcal library to be installed. Grab the latest version from http://mcal.chek.com/ and compile and install it.
After you installed the mcal library, to get these functions to work, you have to compile PHP -with-mcal[=DIR].
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
mcal_append_event() stores the global event into an MCAL calendar for the stream mcal_stream.
Returns the id of the newly inserted event.
Creates a new calendar named calendar.
mcal_date_compare() Compares the two given dates, returns <0, 0, >0 if a<b, a==b, a>b respectively.
(PHP 3>= 3.0.13, PHP 4 )
mcal_date_valid -- Returns TRUE if the given year, month, day is a valid datemcal_date_valid() Returns TRUE if the given year, month and day is a valid date, FALSE if not.
mcal_day_of_week() returns the day of the week of the given date. Possible return values range from 0 for Sunday through 6 for Saturday.
mcal_day_of_year() returns the day of the year of the given date.
mcal_days_in_month() returns the number of days in the month month, taking into account if the considered year is a leap year or not.
Deletes the calendar named calendar.
mcal_delete_event() deletes the calendar event specified by the event_id.
Returns TRUE.
(PHP 3>= 3.0.15, PHP 4 )
mcal_event_add_attribute -- Adds an attribute and a value to the streams global event structuremcal_event_add_attribute() adds an attribute to the stream's global event structure with the value given by "value".
mcal_event_init() initializes a streams global event structure. this effectively sets all elements of the structure to 0, or the default settings.
Returns TRUE.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_alarm -- Sets the alarm of the streams global event structuremcal_event_set_alarm() sets the streams global event structure's alarm to the given minutes before the event.
Returns TRUE.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_category -- Sets the category of the streams global event structuremcal_event_set_category() sets the streams global event structure's category to the given string.
Returns TRUE.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_class -- Sets the class of the streams global event structuremcal_event_set_class() sets the streams global event structure's class to the given value. The class is either 1 for public, or 0 for private.
Returns TRUE.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_description -- Sets the description of the streams global event structuremcal_event_set_description() sets the streams global event structure's description to the given string.
Returns TRUE.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_end -- Sets the end date and time of the streams global event structuremcal_event_set_end() sets the streams global event structure's end date and time to the given values.
Returns TRUE.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_recur_daily -- Sets the recurrence of the streams global event structuremcal_event_set_recur_daily() sets the streams global event structure's recurrence to the given value to be reoccurring on a daily basis, ending at the given date.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_recur_monthly_mday -- Sets the recurrence of the streams global event structuremcal_event_set_recur_monthly_mday() sets the streams global event structure's recurrence to the given value to be reoccurring on a monthly by month day basis, ending at the given date.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_recur_monthly_wday -- Sets the recurrence of the streams global event structuremcal_event_set_recur_monthly_wday() sets the streams global event structure's recurrence to the given value to be reoccurring on a monthly by week basis, ending at the given date.
(PHP 3>= 3.0.15, PHP 4 )
mcal_event_set_recur_none -- Sets the recurrence of the streams global event structuremcal_event_set_recur_none() sets the streams global event structure to not recur (event->recur_type is set to MCAL_RECUR_NONE).
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_recur_weekly -- Sets the recurrence of the streams global event structuremcal_event_set_recur_weekly() sets the streams global event structure's recurrence to the given value to be reoccurring on a weekly basis, ending at the given date.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_recur_yearly -- Sets the recurrence of the streams global event structuremcal_event_set_recur_yearly() sets the streams global event structure's recurrence to the given value to be reoccurring on a yearly basis,ending at the given date.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_start -- Sets the start date and time of the streams global event structuremcal_event_set_start() sets the streams global event structure's start date and time to the given values.
Returns TRUE.
(PHP 3>= 3.0.13, PHP 4 )
mcal_event_set_title -- Sets the title of the streams global event structuremcal_event_set_title() sets the streams global event structure's title to the given string.
Returns TRUE.
(no version information, might be only in CVS)
mcal_expunge -- Deletes all events marked for being expunged.mcal_expunge() deletes all events which have been previously marked for deletion.
(PHP 3>= 3.0.13, PHP 4 )
mcal_fetch_current_stream_event -- Returns an object containing the current streams event structuremcal_fetch_current_stream_event() returns the current stream's event structure as an object containing:
int id - ID of that event.
int public - TRUE if the event if public, FALSE if it is private.
string category - Category string of the event.
string title - Title string of the event.
string description - Description string of the event.
int alarm - number of minutes before the event to send an alarm/reminder.
object start - Object containing a datetime entry.
object end - Object containing a datetime entry.
int recur_type - recurrence type
int recur_interval - recurrence interval
datetime recur_enddate - recurrence end date
int recur_data - recurrence data
int year - year
int month - month
int mday - day of month
int hour - hour
int min - minutes
int sec - seconds
int alarm - minutes before event to send an alarm
mcal_fetch_event() fetches an event from the calendar stream specified by id.
Returns an event object consisting of:
int id - ID of that event.
int public - TRUE if the event if public, FALSE if it is private.
string category - Category string of the event.
string title - Title string of the event.
string description - Description string of the event.
int alarm - number of minutes before the event to send an alarm/reminder.
object start - Object containing a datetime entry.
object end - Object containing a datetime entry.
int recur_type - recurrence type
int recur_interval - recurrence interval
datetime recur_enddate - recurrence end date
int recur_data - recurrence data
int year - year
int month - month
int mday - day of month
int hour - hour
int min - minutes
int sec - seconds
int alarm - minutes before event to send an alarm
0 - Indicates that this event does not recur
1 - This event recurs daily
2 - This event recurs on a weekly basis
3 - This event recurs monthly on a specific day of the month (e.g. the 10th of the month)
4 - This event recurs monthly on a sequenced day of the week (e.g. the 3rd Saturday)
5 - This event recurs on an annual basis
mcal_is_leap_year() returns 1 if the given year is a leap year, 0 if not.
(PHP 3>= 3.0.13, PHP 4 )
mcal_list_alarms -- Return a list of events that has an alarm triggered at the given datetimeReturns an array of event ID's that has an alarm going off between the start and end dates, or if just a stream is given, uses the start and end dates in the global event structure.
mcal_list_events() function takes in an optional beginning date and an end date for a calendar stream. An array of event id's that are between the given dates or the internal event dates are returned.
Returns an array of ID's that are between the start and end dates, or if just a stream is given, uses the start and end dates in the global event structure.
mcal_list_events() takes in an beginning date and an optional end date for a calendar stream. An array of event id's that are between the given dates or the internal event dates are returned.
mcal_next_recurrence() returns an object filled with the next date the event occurs, on or after the supplied date. Returns empty date field if event does not occur or something is invalid. Uses weekstart to determine what day is considered the beginning of the week.
Returns an MCAL stream on success, FALSE on error.
mcal_open() opens up an MCAL connection to the specified calendar store. If the optional options is specified, passes the options to that mailbox also. The streams internal event structure is also initialized upon connection.
Returns an MCAL stream on success, FALSE on error.
mcal_popen() opens up an MCAL connection to the specified calendar store. If the optional options is specified, passes the options to that mailbox also. The streams internal event structure is also initialized upon connection.
Renames the calendar old_name to new_name.
Reopens an MCAL stream to a new calendar.
mcal_reopen() reopens an MCAL connection to the specified calendar store. If the optional options is specified, passes the options to that mailbox also.
mcal_snooze() turns off an alarm for a calendar event specified by the stream_id and event_id.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
mcal_store_event() stores the modifications to the current global event for the given stream.
Returns the event id of the modified event on success and FALSE on error.
(PHP 3>= 3.0.13, PHP 4 )
mcal_time_valid -- Returns TRUE if the given hour, minutes and seconds is a valid timemcal_time_valid() Returns TRUE if the given hour, minutes and seconds is a valid time, FALSE if not.
This is an interface to the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes. Additionally, it supports RC6 and IDEA which are considered "non-free".
These functions work using mcrypt. To use it, download libmcrypt-x.x.tar.gz from http://mcrypt.sourceforge.net/ and follow the included installation instructions. Windows users will find all the needed compiled mcrypt binaries at http://ftp.emini.dk/pub/php/win32/mcrypt/.
If you linked against libmcrypt 2.4.x or higher, the following additional block algorithms are supported: CAST, LOKI97, RIJNDAEL, SAFERPLUS, SERPENT and the following stream ciphers: ENIGMA (crypt), PANAMA, RC4 and WAKE. With libmcrypt 2.4.x or higher another cipher mode is also available; nOFB.
You need to compile PHP with the --with-mcrypt[=DIR] parameter to enable this extension. DIR is the mcrypt install directory. Make sure you compile libmcrypt with the option --disable-posix-threads.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Mcrypt configuration options
Name | Default | Changeable |
---|---|---|
mcrypt.algorithms_dir | NULL | PHP_INI_ALL |
mcrypt.modes_dir | NULL | PHP_INI_ALL |
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Mcrypt can operate in four block cipher modes (CBC, OFB, CFB, and ECB). If linked against libmcrypt-2.4.x or higher the functions can also operate in the block cipher mode nOFB and in STREAM mode. Below you find a list with all supported encryption modes together with the constants that are defines for the encryption mode. For a more complete reference and discussion see Applied Cryptography by Schneier (ISBN 0-471-11709-9).
MCRYPT_MODE_ECB (electronic codebook) is suitable for random data, such as encrypting other keys. Since data there is short and random, the disadvantages of ECB have a favorable negative effect.
MCRYPT_MODE_CBC (cipher block chaining) is especially suitable for encrypting files where the security is increased over ECB significantly.
MCRYPT_MODE_CFB (cipher feedback) is the best mode for encrypting byte streams where single bytes must be encrypted.
MCRYPT_MODE_OFB (output feedback, in 8bit) is comparable to CFB, but can be used in applications where error propagation cannot be tolerated. It's insecure (because it operates in 8bit mode) so it is not recommended to use it.
MCRYPT_MODE_NOFB (output feedback, in nbit) is comparable to OFB, but more secure because it operates on the block size of the algorithm.
MCRYPT_MODE_STREAM is an extra mode to include some stream algorithms like WAKE or RC4.
Some other mode and random device constants:
Here is a list of ciphers which are currently supported by the mcrypt extension. For a complete list of supported ciphers, see the defines at the end of mcrypt.h. The general rule with the mcrypt-2.2.x API is that you can access the cipher from PHP with MCRYPT_ciphername. With the libmcrypt-2.4.x and libmcrypt-2.5.x API these constants also work, but it is possible to specify the name of the cipher as a string with a call to mcrypt_module_open().
MCRYPT_3DES
MCRYPT_ARCFOUR_IV (libmcrypt > 2.4.x only)
MCRYPT_ARCFOUR (libmcrypt > 2.4.x only)
MCRYPT_BLOWFISH
MCRYPT_CAST_128
MCRYPT_CAST_256
MCRYPT_CRYPT
MCRYPT_DES
MCRYPT_DES_COMPAT (libmcrypt 2.2.x only)
MCRYPT_ENIGMA (libmcrypt > 2.4.x only, alias for MCRYPT_CRYPT)
MCRYPT_GOST
MCRYPT_IDEA (non-free)
MCRYPT_LOKI97 (libmcrypt > 2.4.x only)
MCRYPT_MARS (libmcrypt > 2.4.x only, non-free)
MCRYPT_PANAMA (libmcrypt > 2.4.x only)
MCRYPT_RIJNDAEL_128 (libmcrypt > 2.4.x only)
MCRYPT_RIJNDAEL_192 (libmcrypt > 2.4.x only)
MCRYPT_RIJNDAEL_256 (libmcrypt > 2.4.x only)
MCRYPT_RC2
MCRYPT_RC4 (libmcrypt 2.2.x only)
MCRYPT_RC6 (libmcrypt > 2.4.x only)
MCRYPT_RC6_128 (libmcrypt 2.2.x only)
MCRYPT_RC6_192 (libmcrypt 2.2.x only)
MCRYPT_RC6_256 (libmcrypt 2.2.x only)
MCRYPT_SAFER64
MCRYPT_SAFER128
MCRYPT_SAFERPLUS (libmcrypt > 2.4.x only)
MCRYPT_SERPENT(libmcrypt > 2.4.x only)
MCRYPT_SERPENT_128 (libmcrypt 2.2.x only)
MCRYPT_SERPENT_192 (libmcrypt 2.2.x only)
MCRYPT_SERPENT_256 (libmcrypt 2.2.x only)
MCRYPT_SKIPJACK (libmcrypt > 2.4.x only)
MCRYPT_TEAN (libmcrypt 2.2.x only)
MCRYPT_THREEWAY
MCRYPT_TRIPLEDES (libmcrypt > 2.4.x only)
MCRYPT_TWOFISH (for older mcrypt 2.x versions, or mcrypt > 2.4.x )
MCRYPT_TWOFISH128 (TWOFISHxxx are available in newer 2.x versions, but not in the 2.4.x versions)
MCRYPT_TWOFISH192
MCRYPT_TWOFISH256
MCRYPT_WAKE (libmcrypt > 2.4.x only)
MCRYPT_XTEA (libmcrypt > 2.4.x only)
You must (in CFB and OFB mode) or can (in CBC mode) supply an initialization vector (IV) to the respective cipher function. The IV must be unique and must be the same when decrypting/encrypting. With data which is stored encrypted, you can take the output of a function of the index under which the data is stored (e.g. the MD5 key of the filename). Alternatively, you can transmit the IV together with the encrypted data (see chapter 9.3 of Applied Cryptography by Schneier (ISBN 0-471-11709-9) for a discussion of this topic).
Mcrypt can be used to encrypt and decrypt using the above mentioned ciphers. If you linked against libmcrypt-2.2.x, the four important mcrypt commands (mcrypt_cfb(), mcrypt_cbc(), mcrypt_ecb(), and mcrypt_ofb()) can operate in both modes which are named MCRYPT_ENCRYPT and MCRYPT_DECRYPT, respectively.
If you linked against libmcrypt 2.4.x or 2.5.x, these functions are still available, but it is recommended that you use the advanced functions.
ÐáñÜäåéãìá 2. Encrypt an input value with TripleDES under 2.4.x and higher in ECB mode
|
The first prototype is when linked against libmcrypt 2.2.x, the second when linked against libmcrypt 2.4.x or higher. The mode should be either MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
This function should not be used anymore, see mcrypt_generic() and mdecrypt_generic() for replacements.
The first prototype is when linked against libmcrypt 2.2.x, the second when linked against libmcrypt 2.4.x or higher. The mode should be either MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
This function should not be used anymore, see mcrypt_generic() and mdecrypt_generic() for replacements.
(PHP 3>= 3.0.8, PHP 4 , PHP 5)
mcrypt_create_iv -- Create an initialization vector (IV) from a random sourcemcrypt_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. MCRYPT_RAND is the only one supported on Windows because Windows (of course) doesn't have /dev/random or /dev/urandom.
The IV is only meant to give an alternative seed to the encryption routines. This IV does not need to be secret at all, though it can be desirable. You even can send it along with your ciphertext without loosing security.
More information can be found at http://www.ciphersbyritter.com/GLOSSARY.HTM#IV, http://fn2.freenet.edmonton.ab.ca/~jsavard/crypto/co0409.htm and in chapter 9.3 of Applied Cryptography by Schneier (ISBN 0-471-11709-9) for a discussion of this topic.
mcrypt_decrypt() decrypts the data and returns the unencrypted data.
Cipher is one of the MCRYPT_ciphername constants of the name of the algorithm as string.
Key is the key with which the data is encrypted. If it's smaller that the required keysize, it is padded with '\0'.
Data is the data that will be decrypted with the given cipher and mode. If the size of the data is not n * blocksize, the data will be padded with '\0'.
Mode is one of the MCRYPT_MODE_modename constants of one of "ecb", "cbc", "cfb", "ofb", "nofb" or "stream".
The IV parameter is used for the initialisation in CBC, CFB, OFB modes, and in some algorithms in STREAM mode. If you do not supply an IV, while it is needed for an algorithm, the function issues a warning and uses an IV with all bytes set to '\0'.
The first prototype is when linked against libmcrypt 2.2.x, the second when linked against libmcrypt 2.4.x or higher. The mode should be either MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
This function is deprecated and should not be used anymore, see mcrypt_generic() and mdecrypt_generic() for replacements.
This function returns the name of the algorithm.
ÐáñÜäåéãìá 1. mcrypt_enc_get_algorithms_name() example
|
This function returns the block size of the algorithm specified by the encryption descriptor td in bytes.
This function returns the size of the iv of the algorithm specified by the encryption descriptor in bytes. If it returns '0' then the IV is ignored in the algorithm. An IV is used in cbc, cfb and ofb modes, and in some algorithms in stream mode.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_enc_get_key_size -- Returns the maximum supported keysize of the opened modeThis function returns the maximum supported key size of the algorithm specified by the encryption descriptor td in bytes.
This function returns the name of the mode.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_enc_get_supported_key_sizes -- Returns an array with the supported keysizes of the opened algorithmReturns an array with the key sizes supported by the algorithm specified by the encryption descriptor. If it returns an empty array then all key sizes between 1 and mcrypt_enc_get_key_size() are supported by the algorithm.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_enc_is_block_algorithm_mode -- Checks whether the encryption of the opened mode works on blocksThis function returns TRUE if the mode is for use with block algorithms, otherwise it returns FALSE. (e.g. FALSE for stream, and TRUE for cbc, cfb, ofb).
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_enc_is_block_algorithm -- Checks whether the algorithm of the opened mode is a block algorithmThis function returns TRUE if the algorithm is a block algorithm, or FALSE if it is a stream algorithm.
This function returns TRUE if the mode outputs blocks of bytes or FALSE if it outputs bytes. (e.g. TRUE for cbc and ecb, and FALSE for cfb and stream).
This function runs the self test on the algorithm specified by the descriptor td. If the self test succeeds it returns FALSE. In case of an error, it returns TRUE.
mcrypt_encrypt() encrypts the data and returns the encrypted data.
Cipher is one of the MCRYPT_ciphername constants of the name of the algorithm as string.
Key is the key with which the data will be encrypted. If it's smaller that the required keysize, it is padded with '\0'. It is better not to use ASCII strings for keys. It is recommended to use the mhash functions to create a key from a string.
Data is the data that will be encrypted with the given cipher and mode. If the size of the data is not n * blocksize, the data will be padded with '\0'. The returned crypttext can be larger that the size of the data that is given by data.
Mode is one of the MCRYPT_MODE_modename constants of one of "ecb", "cbc", "cfb", "ofb", "nofb" or "stream".
The IV parameter is used for the initialisation in CBC, CFB, OFB modes, and in some algorithms in STREAM mode. If you do not supply an IV, while it is needed for an algorithm, the function issues a warning and uses an IV with all bytes set to '\0'.
ÐáñÜäåéãìá 1. mcrypt_encrypt() Example
The above example will print out:
|
See also mcrypt_module_open() for a more advanced API and an example.
This function terminates encryption specified by the encryption descriptor (td). It clears all buffers, but does not close the module. You need to call mcrypt_module_close() yourself. (But PHP does this for you at the end of the script.) Returns FALSE on error, or TRUE on success.
See for an example mcrypt_module_open() and the entry on mcrypt_generic_init().
Ðñïåéäïðïßçóç |
This function is deprecated, use mcrypt_generic_deinit() instead. It can cause crashes when used with mcrypt_module_close() due to multiple buffer frees. |
This function terminates encryption specified by the encryption descriptor (td). Actually it clears all buffers, and closes all the modules used. Returns FALSE on error, or TRUE on success.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_generic_init -- This function initializes all buffers needed for encryptionThe maximum length of the key should be the one obtained by calling mcrypt_enc_get_key_size() and every value smaller than this is legal. The IV should normally have the size of the algorithms block size, but you must obtain the size by calling mcrypt_enc_get_iv_size(). IV is ignored in ECB. IV MUST exist in CFB, CBC, STREAM, nOFB and OFB modes. It needs to be random and unique (but not secret). The same IV must be used for encryption/decryption. If you do not want to use it you should set it to zeros, but this is not recommended.
The function returns a negative value on error, -3 when the key length was incorrect, -4 when there was a memory allocation problem and any other return value is an unknown error. If an error occurs a warning will be displayed accordingly.
You need to call this function before every call to mcrypt_generic() or mdecrypt_generic().
See for an example mcrypt_module_open().
This function encrypts data. The data is padded with "\0" to make sure the length of the data is n * blocksize. This function returns the encrypted data. Note that the length of the returned string can in fact be longer then the input, due to the padding of the data.
If you want to store the encrypted data in a database make sure to store the entire string as returned by mcrypt_generic, or the string will not entirely decrypt properly. If your original string is 10 characters long and the block size is 8 (use mcrypt_enc_get_block_size() to determine the blocksize), you would need at least 16 characters in your database field. Note the string returned by mdecrypt_generic() will be 16 characters as well...use rtrim()($str, "\0") to remove the padding.
If you are for example storing the data in a MySQL database remember that varchar fields automatically have trailing spaces removed during insertion. As encrypted data can end in a space (ASCII 32), the data will be damaged by this removal. Store data in a tinyblob/tinytext (or larger) field instead.
The encryption handle should always be initialized with mcrypt_generic_init() with a key and an IV before calling this function. Where the encryption is done, you should free the encryption buffers by calling mcrypt_generic_deinit(). See mcrypt_module_open() for an example.
See also mdecrypt_generic(), mcrypt_generic_init(), and mcrypt_generic_deinit().
The first prototype is when linked against libmcrypt 2.2.x, the second when linked against libmcrypt 2.4.x or 2.5.x.
mcrypt_get_block_size() is used to get the size of a block of the specified cipher (in combination with an encryption mode).
It is more useful to use the mcrypt_enc_get_block_size() function as this uses the resource returned by mcrypt_module_open().
This example shows how to use this function when linked against libmcrypt 2.4.x and 2.5.x.
See also: mcrypt_get_key_size(), mcrypt_enc_get_block_size() and mcrypt_encrypt().
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 (libmcrypt 2.2.x) or takes the cipher name as an argument (libmcrypt 2.4.x or higher) and returns the name of the cipher or FALSE, if the cipher does not exist.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_get_iv_size -- Returns the size of the IV belonging to a specific cipher/mode combinationmcrypt_get_iv_size() returns the size of the Initialisation Vector (IV) in bytes. On error the function returns FALSE. If the IV is ignored in the specified cipher/mode combination zero is returned.
cipher is one of the MCRYPT_ciphername constants of the name of the algorithm as string.
mode is one of the MCRYPT_MODE_modename constants or one of "ecb", "cbc", "cfb", "ofb", "nofb" or "stream". The IV is ignored in ECB mode as this mode does not require it. You will need to have the same IV (think: starting point) both at encryption and decryption stages, otherwise your encryption will fail.
It is more useful to use the mcrypt_enc_get_iv_size() function as this uses the resource returned by mcrypt_module_open().
See also mcrypt_get_block_size(), mcrypt_enc_get_iv_size() and mcrypt_create_iv().
The first prototype is when linked against libmcrypt 2.2.x, the second when linked against libmcrypt 2.4.x or 2.5.x.
mcrypt_get_key_size() is used to get the size of a key of the specified cipher (in combination with an encryption mode).
This example shows how to use this function when linked against libmcrypt 2.4.x and 2.5.x. It is more useful to use the mcrypt_enc_get_key_size() function as this uses the resource returned by mcrypt_module_open().
ÐáñÜäåéãìá 1. mcrypt_get_block_size() example
|
See also: mcrypt_get_block_size(), mcrypt_end_get_key_size() and mcrypt_encrypt().
mcrypt_list_algorithms() is used to get an array of all supported algorithms in the lib_dir parameter.
mcrypt_list_algorithms() takes an optional lib_dir parameter which specifies the directory where all algorithms are located. If not specifies, the value of the mcrypt.algorithms_dir php.ini directive is used.
mcrypt_list_modes() is used to get an array of all supported modes in the lib_dir.
mcrypt_list_modes() takes as optional parameter a directory which specifies the directory where all modes are located. If not specifies, the value of the mcrypt.modes_dir php.ini directive is used.
ÐáñÜäåéãìá 1. mcrypt_list_modes() Example
The above example will produce a list with all supported algorithms in the default mode directory. If it is not set with the ini directive mcrypt.modes_dir, the default directory of mcrypt is used (which is /usr/local/lib/libmcrypt). |
This function closes the specified encryption handle.
See mcrypt_module_open() for an example.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_get_algo_block_size -- Returns the blocksize of the specified algorithmThis function returns the block size of the algorithm specified in bytes. The optional lib_dir parameter can contain the location where the mode module is on the system.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_get_algo_key_size -- Returns the maximum supported keysize of the opened modeThis function returns the maximum supported key size of the algorithm specified in bytes. The optional lib_dir parameter can contain the location where the mode module is on the system.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_get_supported_key_sizes -- Returns an array with the supported keysizes of the opened algorithmReturns an array with the key sizes supported by the specified algorithm. If it returns an empty array then all key sizes between 1 and mcrypt_module_get_algo_key_size() are supported by the algorithm. The optional lib_dir parameter can contain the location where the mode module is on the system.
See also mcrypt_enc_get_supported_key_sizes() which is used on open encryption modules.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_is_block_algorithm_mode -- returns if the specified module is a block algorithm or notThis function returns TRUE if the mode is for use with block algorithms, otherwise it returns FALSE. (e.g. FALSE for stream, and TRUE for cbc, cfb, ofb). The optional lib_dir parameter can contain the location where the mode module is on the system.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_is_block_algorithm -- This function checks whether the specified algorithm is a block algorithmThis function returns TRUE if the specified algorithm is a block algorithm, or FALSE is it is a stream algorithm. The optional lib_dir parameter can contain the location where the algorithm module is on the system.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_is_block_mode -- Returns if the specified mode outputs blocks or notThis function returns TRUE if the mode outputs blocks of bytes or FALSE if it outputs just bytes. (e.g. TRUE for cbc and ecb, and FALSE for cfb and stream). The optional lib_dir parameter can contain the location where the mode module is on the system.
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_open -- Opens the module of the algorithm and the mode to be usedThis function opens the module of the algorithm and the mode to be used. The name of the algorithm is specified in algorithm, e.g. "twofish" or is one of the MCRYPT_ciphername constants. The module is closed by calling mcrypt_module_close(). Normally it returns an encryption descriptor, or FALSE on error.
The algorithm_directory and mode_directory are used to locate the encryption modules. When you supply a directory name, it is used. When you set one of these to the empty string (""), the value set by the mcrypt.algorithms_dir or mcrypt.modes_dir ini-directive is used. When these are not set, the default directories that are used are the ones that were compiled in into libmcrypt (usually /usr/local/lib/libmcrypt).
The first line in the example above will try to open the DES cipher from the default directory and the EBC mode from the directory /usr/lib/mcrypt-modes. The second example uses strings as name for the cipher and mode, this only works when the extension is linked against libmcrypt 2.4.x or 2.5.x.
ÐáñÜäåéãìá 2. Using mcrypt_module_open() in encryption
|
The first line in the example above will try to open the DES cipher from the default directory and the EBC mode from the directory /usr/lib/mcrypt-modes. The second example uses strings as name for the cipher and mode, this only works when the extension is linked against libmcrypt 2.4.x or 2.5.x.
See also mcrypt_module_close(), mcrypt_generic(), mdecrypt_generic(), mcrypt_generic_init(), and mcrypt_generic_deinit().
(PHP 4 >= 4.0.2, PHP 5)
mcrypt_module_self_test -- This function runs a self test on the specified moduleThis function runs the self test on the algorithm specified. The optional lib_dir parameter can contain the location of where the algorithm module is on the system.
The function returns TRUE if the self test succeeds, or FALSE when if fails.
The first prototype is when linked against libmcrypt 2.2.x, the second when linked against libmcrypt 2.4.x or higher. The mode should be either MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
This function should not be used anymore, see mcrypt_generic() and mdecrypt_generic() for replacements.
This function decrypts data. Note that the length of the returned string can in fact be longer then the unencrypted string, due to the padding of the data.
ÐáñÜäåéãìá 1. mdecrypt_generic() example
|
The above example shows how to check if the data before the encryption is the same as the data after the decryption. It is very important to reinitialize the encryption buffer with mcrypt_generic_init() before you try to decrypt the data.
The decryption handle should always be initialized with mcrypt_generic_init() with a key and an IV before calling this function. Where the encryption is done, you should free the encryption buffers by calling mcrypt_generic_deinit(). See mcrypt_module_open() for an example.
See also mcrypt_generic(), mcrypt_generic_init(), and mcrypt_generic_deinit().
These functions interface the MCVE API (libmcve), allowing you to work directly with MCVE from your PHP scripts. MCVE is Main Street Softworks' solution to direct credit card processing for Linux / Unix ( http://www.mainstreetsoftworks.com/ ). It lets you directly address the credit card clearing houses via your *nix box, modem and/or internet connection (bypassing the need for an additional service such as Authorize.Net or Pay Flow Pro). Using the MCVE module for PHP, you can process credit cards directly through MCVE via your PHP scripts. The following references will outline the process.
Óçìåßùóç: MCVE is the replacement for RedHat's CCVS. They contracted with RedHat in late 2001 to migrate all existing clientele to the MCVE platform.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
To enable MCVE Support in PHP, first verify your LibMCVE installation directory. You will then need to configure PHP with the --with-mcve option. If you use this option without specifying the path to your MCVE installation, PHP will attempt to look in the default LibMCVE Install location (/usr/local). If MCVE is in a non-standard location, run configure with: --with-mcve=$mcve_path, where $mcve_path is the path to your MCVE installation. Please note that MCVE support requires that $mcve_path/lib and $mcve_path/include exist, and include mcve.h under the include directory and libmcve.so and/or libmcve.a under the lib directory.
Since MCVE has true server/client separation, there are no additional requirements for running PHP with MCVE support. To test your MCVE extension in PHP, you may connect to testbox.mcve.com on port 8333 for IP, or port 8444 for SSL using the MCVE PHP API. Use 'vitale' for your username, and 'test' for your password. Additional information about test facilities are available at http://www.mainstreetsoftworks.com/.
Additional documentation about MCVE's PHP API can be found at http://www.mainstreetsoftworks.com/docs/phpapi.pdf. Main Street's documentation is complete and should be the primary reference for functions.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_completeauthorizations -- Number of complete authorizations in queue, returning an array of their identifiers
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
mcve_connectionerror -- Get a textual representation of why a connection failed
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_getcell -- Get a specific cell from a comma delimited response by column name
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_getcellbynum -- Get a specific cell from a comma delimited response by column number
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_getcommadelimited -- Get the RAW comma delimited data returned from MCVE
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
mcve_maxconntimeout -- The maximum amount of time the API will attempt a connection to MCVE
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_monitor -- Perform communication with MCVE (send/receive data) Non-blocking
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_parsecommadelimited -- Parse the comma delimited response so mcve_getcell, etc will work
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_preauthcompletion -- Complete a PREAUTHORIZATION... Ready it for settlement
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.3, PHP 5)
mcve_setssl_files -- Set certificate key files and certificates if server requires client certificate verification
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_transactionauth -- Get the authorization number returned for the transaction (alpha-numeric)
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_transactionbatch -- Get the batch number associated with the transaction
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_transactionitem -- Get the ITEM number in the associated batch for this transaction
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
mcve_transactiontext -- Get verbiage (text) return from MCVE or processing institution
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
mcve_verifyconnection -- Set whether or not to PING upon connect to verify connection
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
mcve_verifysslcert -- Set whether or not to verify the server ssl certificate
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
These functions are intended to work with mhash. Mhash can be used to create checksums, message digests, message authentication codes, and more.
This is an interface to the mhash library. mhash supports a wide variety of hash algorithms such as MD5, SHA1, GOST, and many others. For a complete list of supported hashes, refer to the documentation of mhash. The general rule is that you can access the hash algorithm from PHP with MHASH_HASHNAME. For example, to access TIGER you use the PHP constant MHASH_TIGER.
To use it, download the mhash distribution from its web site and follow the included installation instructions.
You need to compile PHP with the --with-mhash[=DIR] parameter to enable this extension. DIR is the mhash install directory.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Here is a list of hashes which are currently supported by mhash. If a hash is not listed here, but is listed by mhash as supported, you can safely assume that this documentation is outdated.
MHASH_MD5
MHASH_SHA1
MHASH_HAVAL256
MHASH_HAVAL192
MHASH_HAVAL160
MHASH_HAVAL128
MHASH_RIPEMD160
MHASH_GOST
MHASH_TIGER
MHASH_CRC32
MHASH_CRC32B
ÐáñÜäåéãìá 1. Compute the MD5 digest and hmac and print it out as hex
This will produce:
|
mhash_count() returns the highest available hash id. Hashes are numbered from 0 to this hash id.
mhash_get_block_size() is used to get the size of a block of the specified hash.
mhash_get_block_size() takes one argument, the hash and returns the size in bytes or FALSE, if the hash does not exist.
mhash_get_hash_name() is used to get the name of the specified hash.
mhash_get_hash_name() takes the hash id as an argument and returns the name of the hash or FALSE, if the hash does not exist.
mhash_keygen_s2k() generates a key that is bytes long, from a user given password. This is the Salted S2K algorithm as specified in the OpenPGP document (RFC 2440). That algorithm will use the specified hash algorithm to create the key. The salt must be different and random enough for every key you generate in order to create different keys. That salt must be known when you check the keys, thus it is a good idea to append the key to it. Salt has a fixed length of 8 bytes and will be padded with zeros if you supply less bytes.
Keep in mind that user supplied passwords are not really suitable to be used as keys in cryptographic algorithms, since users normally choose keys they can write on keyboard. These passwords use only 6 to 7 bits per character (or less). It is highly recommended to use some kind of transformation (like this function) to the user supplied key.
mhash() applies a hash function specified by hash to the data and returns the resulting hash (also called digest). If the key is specified it will return the resulting HMAC. HMAC is keyed hashing for message authentication, or simply a message digest that depends on the specified key. Not all algorithms supported in mhash can be used in HMAC mode. In case of an error returns FALSE.
Ðñïåéäïðïßçóç |
This extension has been deprecated as the PECL extension fileinfo provides the same functionality (and more) in a much cleaner way. |
The functions in this module try to guess the content type and encoding of a file by looking for certain magic byte sequences at specific positions within the file. While this is not a bullet proof approach the heuristics used do a very good job.
This extension is derived from Apache mod_mime_magic, which is itself based on the file command maintained by Ian F. Darwin. See the source code for further historic and copyright information.
You must compile PHP with the configure switch --with-mime-magic to get support for mime-type functions. The extension needs a copy of the simplified magic file that is distributed with the Apache httpd.
Óçìåßùóç: The configure option has been changed from --enable-mime-magic to --with-mime-magic since PHP 4.3.2
Óçìåßùóç: This extension is not capable of handling the fully decorated magic file that generally comes with standard Linux distro's and is supposed to be used with recent versions of file command.
Note to Win32 Users: In order to use this module on a Windows environment, you must set the path to the bundled magic.mime file in your php.ini.
Remember to substitute the $PHP_INSTALL_DIR for your actual path to PHP in the above example. e.g. c:\php
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Mimetype configuration options
Name | Default | Changeable |
---|---|---|
mime_magic.magicfile | "/usr/share/misc/magic.mime" | PHP_INI_SYSTEM |
Requirements for Win32 platforms.
The extension requires the MS SQL Client Tools to be installed on the system where PHP is installed. The Client Tools can be installed from the MS SQL Server CD or by copying ntwdblib.dll from \winnt\system32 on the server to \winnt\system32 on the PHP box. Copying ntwdblib.dll will only provide access. Configuration of the client will require installation of all the tools.
Requirements for Unix/Linux platforms.
To use the MSSQL extension on Unix/Linux, you first need to build and install the FreeTDS library. Source code and installation instructions are available at the FreeTDS home page: http://www.freetds.org/
Óçìåßùóç: In Windows, the DBLIB from Microsoft is used. Functions that return a column name are based on the dbcolname() function in DBLIB. DBLIB was developed for SQL Server 6.x where the max identifier length is 30. For this reason, the maximum column length is 30 characters. On platforms where FreeTDS is used (Linux), this is not a problem.
The MSSQL extension is enabled by adding extension=php_mssql.dll to php.ini.
To get these functions to work, you have to compile PHP with --with-mssql[=DIR], where DIR is the FreeTDS install prefix. And FreeTDS should be compiled using --enable-msdblib.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. MS SQL Server configuration options
Name | Default | Changeable |
---|---|---|
mssql.allow_persistent | "1" | PHP_INI_SYSTEM |
mssql.max_persistent | "-1" | PHP_INI_SYSTEM |
mssql.max_links | "-1" | PHP_INI_SYSTEM |
mssql.min_error_severity | "10" | PHP_INI_ALL |
mssql.min_message_severity | "10" | PHP_INI_ALL |
mssql.compatability_mode | "0" | PHP_INI_ALL |
mssql.connect_timeout | "5" | PHP_INI_ALL |
mssql.timeout | "60" | PHP_INI_ALL |
mssql.textsize | "-1" | PHP_INI_ALL |
mssql.textlimit | "-1" | PHP_INI_ALL |
mssql.batchsize | "0" | PHP_INI_ALL |
mssql.datetimeconvert | "1" | PHP_INI_ALL |
mssql.secure_connection | "0" | PHP_INI_SYSTEM |
mssql.max_procs | "25" | PHP_INI_ALL |
(PHP 4 >= 4.1.0, PHP 5)
mssql_bind -- Adds a parameter to a stored procedure or a remote stored procedureÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also mssql_execute(), mssql_free_statement(), and mssql_init().
mssql_close() closes the link to a MS SQL Server database that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Note that this isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.
mssql_close() will not close persistent links generated by mssql_pconnect().
See also mssql_connect(), and mssql_pconnect().
Returns: A positive MS SQL link identifier on success, or FALSE on error.
mssql_connect() establishes a connection to a MS SQL server. The servername argument has to be a valid servername that is defined in the 'interfaces' file.
In case a second call is made to mssql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.
The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mssql_close().
See also mssql_pconnect(), mssql_close().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
mssql_data_seek() moves the internal row pointer of the MS SQL result associated with the specified result identifier to point to the specified row number, first row being number 0. The next call to mssql_fetch_row() would return that row.
See also mssql_data_seek().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: If the stored procedure returns parameters or a return value these will be available after the call to mssql_execute() unless the stored procedure returns more than one result set. In that case use mssql_next_result() to shift through the results. When the last result has been processed the output parameters and return values will be available.
See also mssql_bind(), mssql_free_statement(), and mssql_init().
(PHP 3, PHP 4 , PHP 5)
mssql_fetch_array -- Fetch a result row as an associative array, a numeric array, or bothReturns: An array that corresponds to the fetched row, or FALSE if there are no more rows.
mssql_fetch_array() is an extended version of mssql_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.
An important thing to note is that using mssql_fetch_array() is NOT significantly slower than using mssql_fetch_row(), while it provides a significant added value.
Óçìåßùóç: Field names returned by this function are case-sensitive.
For further details, also see mssql_fetch_row().
(PHP 4 >= 4.2.0, PHP 5)
mssql_fetch_assoc -- Returns an associative array of the current row in the result set specified by result_idÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns an object containing field information.
mssql_fetch_field() can be used in order to obtain information about fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by mssql_fetch_field() is retrieved.
The properties of the object are:
name - column name. if the column is a result of a function, this property is set to computed#N, where #N is a serial number.
column_source - the table from which the column was taken
max_length - maximum length of the column
numeric - 1 if the column is numeric
type - the column type.
See also mssql_field_seek().
Returns: An object with properties that correspond to the fetched row, or FALSE if there are no more rows.
mssql_fetch_object() is similar to mssql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
Óçìåßùóç: Field names returned by this function are case-sensitive.
Speed-wise, the function is identical to mssql_fetch_array(), and almost as quick as mssql_fetch_row() (the difference is insignificant).
See also mssql_fetch_array(), and mssql_fetch_row().
Returns: An array that corresponds to the fetched row, or FALSE if there are no more rows.
mssql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
Subsequent call to mssql_fetch_row() would return the next row in the result set, or FALSE if there are no more rows.
See also mssql_fetch_array(), mssql_fetch_object(), mssql_data_seek(), mssql_fetch_lengths(), and mssql_result().
This function returns the length of field no. offset in result result. If offset is omitted, the current field is used.
Note to Win32 Users: Due to a limitation in the underlying API used by PHP (MS DbLib C API), the length of VARCHAR fields is limited to 255. If you need to store more data, use a TEXT field instead.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Seeks to the specified field offset. If the next call to mssql_fetch_field() won't include a field offset, this field would be returned.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also mssql_fetch_field().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
mssql_free_result() only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script ends. You may call mssql_free_result() with the result identifier as an argument and the associated result memory will be freed.
mssql_free_statement() only needs to be called if you are worried about using too much memory while your script is running. All statement memory will automatically be freed when the script ends. You may call mssql_free_statement() with the statement identifier as an argument and the associated statement memory will be freed.
See also mssql_bind(), mssql_execute(), and mssql_init()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
See also mssql_bind(), mssql_execute(), and mssql_free_statement()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
When sending more than one SQL statement to the server or executing a stored procedure with multiple results, it will cause the server to return multiple result sets. This function will test for additional results available form the server. If an additional result set exists it will free the existing result set and prepare to fetch the rows from the new result set. The function will return TRUE if an additional result set was available or FALSE otherwise.
ÐáñÜäåéãìá 1. mssql_next_result() example
|
mssql_num_fields() returns the number of fields in a result set.
See also mssql_query(), mssql_fetch_field(), and mssql_num_rows().
mssql_num_rows() returns the number of rows in a result set.
See also mssql_query() and mssql_fetch_row().
Returns: A positive MS SQL persistent link identifier on success, or FALSE on error.
mssql_pconnect() acts very much like mssql_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mssql_close() will not close links established by mssql_pconnect()).
This type of links is therefore called 'persistent'.
Returns: A positive MS SQL result identifier on success, or FALSE on error.
mssql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if mssql_connect() was called, and use it.
See also mssql_select_db() and mssql_connect().
mssql_result() returns the contents of one cell from a MS SQL result set. The field argument can be the field's offset, the field's name or the field's table dot field's name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), it uses the alias instead of the column name.
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mssql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
Recommended high-performance alternatives: mssql_fetch_row(), mssql_fetch_array(), and mssql_fetch_object().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
mssql_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if mssql_connect() was called, and use it.
Every subsequent call to mssql_query() will be made on the active database.
In order to select a database containing a space or a hyphen ("-") you need to enclose the database name in brackets, like is shown in the example below:
See also: mssql_connect(), mssql_pconnect(), and mssql_query()
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
First of all: Ming is not an acronym. Ming is an open-source (LGPL) library which allows you to create SWF ("Flash") format movies. Ming supports almost all of Flash 4's features, including: shapes, gradients, bitmaps (pngs and jpegs), morphs ("shape tweens"), text, buttons, actions, sprites ("movie clips"), streaming mp3, and color transforms --the only thing that's missing is sound events.
Note that all values specifying length, distance, size, etc. are in "twips", twenty units per pixel. That's pretty much arbitrary, though, since the player scales the movie to whatever pixel size is specified in the embed/object tag, or the entire frame if not embedded.
Ming offers a number of advantages over the existing PHP/libswf module. You can use Ming anywhere you can compile the code, whereas libswf is closed-source and only available for a few platforms, Windows not one of them. Ming provides some insulation from the mundane details of the SWF file format, wrapping the movie elements in PHP objects. Also, Ming is still being maintained; if there's a feature that you want to see, just let us know ming@opaque.net.
Ming was added in PHP 4.0.5.
To use Ming with PHP, you first need to build and install the Ming library. Source code and installation instructions are available at the Ming home page: http://ming.sourceforge.net/ along with examples, a small tutorial, and the latest news.
Download the ming archive. Unpack the archive. Go in the Ming directory. make. make install.
This will build libming.so and install it into /usr/lib/, and copy ming.h into /usr/include/. Edit the PREFIX= line in the Makefile to change the installation directory.
Now either just add extension=php_ming.so to your php.ini file, or put dl('php_ming.so'); at the head of all of your Ming scripts.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ïé ðáñáêÜôù êëÜóåéò ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ming introduces 13 new objects in PHP, all with matching methods and attributes. To use them, you need to know about objects.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfaction() creates a new Action, and compiles the given script into an SWFAction object.
The script syntax is based on the C language, but with a lot taken out- the SWF bytecode machine is just too simpleminded to do a lot of things we might like. For instance, we can't implement function calls without a tremendous amount of hackery because the jump bytecode has a hardcoded offset value. No pushing your calling address to the stack and returning- every function would have to know exactly where to return to.
So what's left? The compiler recognises the following tokens:
break
for
continue
if
else
do
while
There is no typed data; all values in the SWF action machine are stored as strings. The following functions can be used in expressions:
Returns the number of milliseconds (?) elapsed since the movie started.
Returns a pseudo-random number in the range 0-seed.
Returns the length of the given expression.
Returns the given number rounded down to the nearest integer.
Returns the concatenation of the given expressions.
Returns the ASCII code for the given character
Returns the character for the given ASCII code
Returns the substring of length length at location location of the given string string.
Additionally, the following commands may be used:
Duplicate the named movie clip (aka sprite). The new movie clip has name name and is at depth depth.
Removes the named movie clip.
Write the given expression to the trace log. Doubtful that the browser plugin does anything with this.
Start dragging the movie clip target. The lock argument indicates whether to lock the mouse (?)- use 0 (FALSE) or 1 (TRUE). Optional parameters define a bounding area for the dragging.
Stop dragging my heart around. And this movie clip, too.
Call the named frame as a function.
Load the given URL into the named target. The target argument corresponds to HTML document targets (such as "_top" or "_blank"). The optional method argument can be POST or GET if you want to submit variables back to the server.
Load the given URL into the named target. The target argument can be a frame name (I think), or one of the magical values "_level0" (replaces current movie) or "_level1" (loads new movie on top of current movie).
Go to the next frame.
Go to the last (or, rather, previous) frame.
Start playing the movie.
Stop playing the movie.
Toggle between high and low quality.
Stop playing all sounds.
Go to frame number num. Frame numbers start at 0.
Go to the frame named name. Which does a lot of good, since I haven't added frame labels yet.
Sets the context for action. Or so they say- I really have no idea what this does.
Movie clips (all together now- aka sprites) have properties. You can read all of them (or can you?), you can set some of them, and here they are:
x
y
xScale
yScale
currentFrame - (read-only)
totalFrames - (read-only)
alpha - transparency level
visible - 1=on, 0=off (?)
width - (read-only)
height - (read-only)
rotation
target - (read-only) (???)
framesLoaded - (read-only)
name
dropTarget - (read-only) (???)
url - (read-only) (???)
highQuality - 1=high, 0=low (?)
focusRect - (???)
soundBufTime - (???)
This simple example will move the red square across the window.
ÐáñÜäåéãìá 1. swfaction() example
|
This simple example tracks down your mouse on the screen.
ÐáñÜäåéãìá 2. swfaction() example
|
Same as above, but with nice colored balls...
ÐáñÜäåéãìá 3. swfaction() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbitmap->getheight() returns the bitmap's height in pixels.
See also swfbitmap->getwidth().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbitmap->getwidth() returns the bitmap's width in pixels.
See also swfbitmap->getheight().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbitmap() creates a new SWFBitmap object from the Jpeg or DBL file named filename. alphafilename indicates a MSK file to be used as an alpha mask for a Jpeg image.
Óçìåßùóç: We can only deal with baseline (frame 0) jpegs, no baseline optimized or progressive scan jpegs!
SWFBitmap has the following methods : swfbitmap->getwidth() and swfbitmap->getheight().
You can't import png images directly, though- have to use the png2dbl utility to make a dbl ("define bits lossless") file from the png. The reason for this is that I don't want a dependency on the png library in ming- autoconf should solve this, but that's not set up yet.
ÐáñÜäåéãìá 1. Import PNG files
|
And you can put an alpha mask on a jpeg fill.
ÐáñÜäåéãìá 2. swfbitmap() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton->addaction() adds the action action to this button for the given conditions. The following flags are valid: SWFBUTTON_MOUSEOVER, SWFBUTTON_MOUSEOUT, SWFBUTTON_MOUSEUP, SWFBUTTON_MOUSEUPOUTSIDE, SWFBUTTON_MOUSEDOWN, SWFBUTTON_DRAGOUT and SWFBUTTON_DRAGOVER.
See also swfbutton->addshape() and swfaction().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton->addshape() adds the shape shape to this button. The following flags' values are valid: SWFBUTTON_UP, SWFBUTTON_OVER, SWFBUTTON_DOWN or SWFBUTTON_HIT. SWFBUTTON_HIT isn't ever displayed, it defines the hit region for the button. That is, everywhere the hit shape would be drawn is considered a "touchable" part of the button.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton->setaction() sets the action to be performed when the button is clicked. Alias for addAction(shape, SWFBUTTON_MOUSEUP). action is a swfaction().
See also swfbutton->addshape() and swfaction().
(no version information, might be only in CVS)
SWFbutton->setdown -- Alias for addShape(shape, SWFBUTTON_DOWN)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton->setdown() alias for addShape(shape, SWFBUTTON_DOWN).
See also swfbutton->addshape() and swfaction().
(no version information, might be only in CVS)
SWFbutton->setHit -- Alias for addShape(shape, SWFBUTTON_HIT)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton->sethit() alias for addShape(shape, SWFBUTTON_HIT).
See also swfbutton->addshape() and swfaction().
(no version information, might be only in CVS)
SWFbutton->setOver -- Alias for addShape(shape, SWFBUTTON_OVER)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton->setover() alias for addShape(shape, SWFBUTTON_OVER).
See also swfbutton->addshape() and swfaction().
(no version information, might be only in CVS)
SWFbutton->setUp -- Alias for addShape(shape, SWFBUTTON_UP)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton->setup() alias for addShape(shape, SWFBUTTON_UP).
See also swfbutton->addshape() and swfaction().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfbutton() creates a new Button. Roll over it, click it, see it call action code. Swank.
SWFButton has the following methods : swfbutton->addshape(), swfbutton->setup(), swfbutton->setover() swfbutton->setdown(), swfbutton->sethit() swfbutton->setaction() and swfbutton->addaction().
This simple example will show your usual interactions with buttons : rollover, rollon, mouseup, mousedown, noaction.
ÐáñÜäåéãìá 1. swfbutton() example
|
This simple example will enables you to drag draw a big red button on the windows. No drag-and-drop, just moving around.
ÐáñÜäåéãìá 2. swfbutton->addaction() example
|
(no version information, might be only in CVS)
SWFDisplayItem->addColor -- Adds the given color to this item's color transform.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->addcolor() adds the color to this item's color transform. The color is given in its RGB form.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
(no version information, might be only in CVS)
SWFDisplayItem->move -- Moves object in relative coordinates.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->move() moves the current object by (dx,dy) from its current position.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->moveto().
(no version information, might be only in CVS)
SWFDisplayItem->moveTo -- Moves object in global coordinates.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->moveto() moves the current object to (x,y) in global coordinates.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->move().
(no version information, might be only in CVS)
SWFDisplayItem->multColor -- Multiplies the item's color transform.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->multcolor() multiplies the item's color transform by the given values.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
This simple example will modify your picture's atmospher to Halloween (use a landscape or bright picture).
ÐáñÜäåéãìá 1. swfdisplayitem->multcolor() example
|
(no version information, might be only in CVS)
SWFDisplayItem->remove -- Removes the object from the movieÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->remove() removes this object from the movie's display list.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfmovie->add().
(no version information, might be only in CVS)
SWFDisplayItem->Rotate -- Rotates in relative coordinates.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->rotate() rotates the current object by ddegrees degrees from its current rotation.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->rotateto().
(no version information, might be only in CVS)
SWFDisplayItem->rotateTo -- Rotates the object in global coordinates.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->rotateto() set the current object rotation to degrees degrees in global coordinates.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
This example bring three rotating string from the background to the foreground. Pretty nice.
ÐáñÜäåéãìá 1. swfdisplayitem->rotateto() example
|
See also swfdisplayitem->rotate().
(no version information, might be only in CVS)
SWFDisplayItem->scale -- Scales the object in relative coordinates.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->scale() scales the current object by (dx,dy) from its current size.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->scaleto().
(no version information, might be only in CVS)
SWFDisplayItem->scaleTo -- Scales the object in global coordinates.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->scaleto() scales the current object to (x,y) in global coordinates.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->scale().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->rotate() sets the object's z-order to depth. Depth defaults to the order in which instances are created (by adding a shape/text to a movie)- newer ones are on top of older ones. If two objects are given the same depth, only the later-defined one can be moved.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->setname() sets the object's name to name, for targetting with action script. Only useful on sprites.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->setratio() sets the object's ratio to ratio. Obviously only useful for morphs.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
This simple example will morph nicely three concentric circles.
ÐáñÜäåéãìá 1. swfdisplayitem->setname() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->skewx() adds ddegrees to current x-skew.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->skewx(), swfdisplayitem->skewy() and swfdisplayitem->skewyto().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->skewxto() sets the x-skew to degrees. For degrees is 1.0, it means a 45-degree forward slant. More is more forward, less is more backward.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->skewx(), swfdisplayitem->skewy() and swfdisplayitem->skewyto().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->skewy() adds ddegrees to current y-skew.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->skewyto(), swfdisplayitem->skewx() and swfdisplayitem->skewxto().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem->skewyto() sets the y-skew to degrees. For degrees is 1.0, it means a 45-degree forward slant. More is more upward, less is more downward.
The object may be a swfshape(), a swfbutton(), a swftext() or a swfsprite() object. It must have been added using the swfmovie->add().
See also swfdisplayitem->skewy(), swfdisplayitem->skewx() and swfdisplayitem->skewxto().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfdisplayitem() creates a new swfdisplayitem object.
Here's where all the animation takes place. After you define a shape, a text object, a sprite, or a button, you add it to the movie, then use the returned handle to move, rotate, scale, or skew the thing.
SWFDisplayItem has the following methods : swfdisplayitem->move(), swfdisplayitem->moveto(), swfdisplayitem->scaleto(), swfdisplayitem->scale(), swfdisplayitem->rotate(), swfdisplayitem->rotateto(), swfdisplayitem->skewxto(), swfdisplayitem->skewx(), swfdisplayitem->skewyto() swfdisplayitem->skewyto(), swfdisplayitem->setdepth() swfdisplayitem->remove(), swfdisplayitem->setname() swfdisplayitem->setratio(), swfdisplayitem->addcolor() and swfdisplayitem->multcolor().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swffill->moveto() moves fill's origin to (x,y) in global coordinates.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swffill->rotateto() sets fill's rotation to degrees degrees.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swffill->scaleto() sets fill's scale to x in the x-direction, y in the y-direction.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swffill->skewxto() sets fill x-skew to x. For x is 1.0, it is a 45-degree forward slant. More is more forward, less is more backward.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swffill->skewyto() sets fill y-skew to y. For y is 1.0, it is a 45-degree upward slant. More is more upward, less is more downward.
The swffill() object allows you to transform (scale, skew, rotate) bitmap and gradient fills. swffill() objects are created by the swfshape->addfill() methods.
SWFFill has the following methods : swffill->moveto() and swffill->scaleto(), swffill->rotateto(), swffill->skewxto() and swffill->skewyto().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swffont->getwidth() returns the string string's width, using font's default scaling. You'll probably want to use the swftext() version of this method which uses the text object's scale.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
If filename is the name of an FDB file (i.e., it ends in ".fdb"), load the font definition found in said file. Otherwise, create a browser-defined font reference.
FDB ("font definition block") is a very simple wrapper for the SWF DefineFont2 block which contains a full description of a font. One may create FDB files from SWT Generator template files with the included makefdb utility- look in the util directory off the main ming distribution directory.
Browser-defined fonts don't contain any information about the font other than its name. It is assumed that the font definition will be provided by the movie player. The fonts _serif, _sans, and _typewriter should always be available. For example:
<?php $f = newSWFFont("_sans"); ?> |
swffont() returns a reference to the font definition, for use in the swftext->setfont() and the swftextfield->setfont() methods.
SWFFont has the following methods : swffont->getwidth().
(no version information, might be only in CVS)
SWFGradient->addEntry -- Adds an entry to the gradient list.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfgradient->addentry() adds an entry to the gradient list. ratio is a number between 0 and 1 indicating where in the gradient this color appears. Thou shalt add entries in order of increasing ratio.
red, green, blue is a color (RGB mode). Last parameter a is optional.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfgradient() creates a new SWFGradient object.
After you've added the entries to your gradient, you can use the gradient in a shape fill with the swfshape->addfill() method.
SWFGradient has the following methods : swfgradient->addentry().
This simple example will draw a big black-to-white gradient as background, and a reddish disc in its center.
ÐáñÜäåéãìá 1. swfgradient() example
|
(no version information, might be only in CVS)
SWFMorph->getshape1 -- Gets a handle to the starting shapeÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmorph->getshape1() gets a handle to the morph's starting shape. swfmorph->getshape1() returns an swfshape() object.
(no version information, might be only in CVS)
SWFMorph->getshape2 -- Gets a handle to the ending shapeÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmorph->getshape2() gets a handle to the morph's ending shape. swfmorph->getshape2() returns an swfshape() object.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmorph() creates a new SWFMorph object.
Also called a "shape tween". This thing lets you make those tacky twisting things that make your computer choke. Oh, joy!
The methods here are sort of weird. It would make more sense to just have newSWFMorph(shape1, shape2);, but as things are now, shape2 needs to know that it's the second part of a morph. (This, because it starts writing its output as soon as it gets drawing commands- if it kept its own description of its shapes and wrote on completion this and some other things would be much easier.)
SWFMorph has the following methods : swfmorph->getshape1() and swfmorph->getshape1().
This simple example will morph a big red square into a smaller blue black-bordered square.
ÐáñÜäåéãìá 1. swfmorph() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->add() adds instance to the current movie. instance is any type of data : Shapes, text, fonts, etc. must all be added to the movie to make this work.
For displayable types (shape, text, button, sprite), this returns an swfdisplayitem(), a handle to the object in a display list. Thus, you can add the same shape to a movie multiple times and get separate handles back for each separate instance.
See also all other objects (adding this later), and swfmovie->remove()
See examples in : swfdisplayitem->rotateto() and swfshape->addfill().
(no version information, might be only in CVS)
SWFMovie->nextframe -- Moves to the next frame of the animation.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->nextframe() moves to the next frame of the animation.
(no version information, might be only in CVS)
SWFMovie->output -- Dumps your lovingly prepared movie out.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->output() dumps your lovingly prepared movie out. In PHP, preceding this with the command
<?php header('Content-type: application/x-shockwave-flash'); ?> |
See also swfmovie->save().
See examples in : swfmovie->streammp3(), swfdisplayitem->rotateto(), swfaction()... Any example will use this method.
(no version information, might be only in CVS)
swfmovie->remove -- Removes the object instance from the display list.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->remove() removes the object instance instance from the display list.
See also swfmovie->add().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->save() saves your movie to the file named filename.
See also swfmovie->output().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->setbackground() sets the background color. Why is there no rgba version? Think about it. (Actually, that's not such a dumb question after all- you might want to let the HTML background show through. There's a way to do that, but it only works on IE4. Search the http://www.macromedia.com/ site for details.)
(no version information, might be only in CVS)
SWFMovie->setdimension -- Sets the movie's width and height.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->setdimension() sets the movie's width to width and height to height.
(no version information, might be only in CVS)
SWFMovie->setframes -- Sets the total number of frames in the animation.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->setframes() sets the total number of frames in the animation to numberofframes.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->setrate() sets the frame rate to rate, in frame per seconds. Animation will slow down if the player can't render frames fast enough- unless there's a streaming sound, in which case display frames are sacrificed to keep sound from skipping.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie->streammp3() streams the mp3 file mp3FileName. Not very robust in dealing with oddities (can skip over an initial ID3 tag, but that's about it). Like swfshape->addjpegfill(), this isn't a stable function- we'll probably need to make a separate SWFSound object to contain sound types.
Note that the movie isn't smart enough to put enough frames in to contain the entire mp3 stream- you'll have to add (length of song * frames per second) frames to get the entire stream in.
Yes, now you can use ming to put that rock and roll devil worship music into your SWF files. Just don't tell the RIAA.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfmovie() creates a new movie object, representing an SWF version 4 movie.
SWFMovie has the following methods : swfmovie->output(),swfmovie->save(), swfmovie->add(), swfmovie->remove(), swfmovie->nextframe(), swfmovie->setbackground(), swfmovie->setrate(), swfmovie->setdimension(), swfmovie->setframes() and swfmovie->streammp3().
See examples in : swfdisplayitem->rotateto(), swfshape->setline(), swfshape->addfill()... Any example will use this object.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->addfill() adds a solid fill to the shape's list of fill styles. swfshape->addfill() accepts three different types of arguments.
red, green, blue is a color (RGB mode). Last parameter a is optional.
The bitmap argument is an swfbitmap() object. The flags argument can be one of the following values : SWFFILL_CLIPPED_BITMAP or SWFFILL_TILED_BITMAP. Default is SWFFILL_TILED_BITMAP. I think.
The gradient argument is an swfgradient() object. The flags argument can be one of the following values : SWFFILL_RADIAL_GRADIENT or SWFFILL_LINEAR_GRADIENT. Default is SWFFILL_LINEAR_GRADIENT. I'm sure about this one. Really.
swfshape->addfill() returns an swffill() object for use with the swfshape->setleftfill() and swfshape->setrightfill() functions described below.
See also swfshape->setleftfill() and swfshape->setrightfill().
This simple example will draw a frame on a bitmap. Ah, here's another buglet in the flash player- it doesn't seem to care about the second shape's bitmap's transformation in a morph. According to spec, the bitmap should stretch along with the shape in this example..
ÐáñÜäåéãìá 1. swfshape->addfill() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->drawcurve() draws a quadratic curve (using the current line style,set by swfshape->setline()) from the current pen position to the relative position (anchorx,anchory) using relative control point (controlx,controly). That is, head towards the control point, then smoothly turn to the anchor point.
See also swfshape->drawlineto(), swfshape->drawline(), swfshape->movepento() and swfshape->movepen().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->drawcurveto() draws a quadratic curve (using the current line style, set by swfshape->setline()) from the current pen position to (anchorx,anchory) using (controlx,controly) as a control point. That is, head towards the control point, then smoothly turn to the anchor point.
See also swfshape->drawlineto(), swfshape->drawline(), swfshape->movepento() and swfshape->movepen().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->drawline() draws a line (using the current line style set by swfshape->setline()) from the current pen position to displacement (dx,dy).
See also swfshape->movepento(), swfshape->drawcurveto(), swfshape->movepen() and swfshape->drawlineto().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->setrightfill() draws a line (using the current line style, set by swfshape->setline()) from the current pen position to point (x,y) in the shape's coordinate space.
See also swfshape->movepento(), swfshape->drawcurveto(), swfshape->movepen() and swfshape->drawline().
(no version information, might be only in CVS)
SWFShape->movePen -- Moves the shape's pen (relative).Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->setrightfill() move the shape's pen from coordinates (current x,current y) to (current x + dx, current y + dy) in the shape's coordinate space.
See also swfshape->movepento(), swfshape->drawcurveto(), swfshape->drawlineto() and swfshape->drawline().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->setrightfill() move the shape's pen to (x,y) in the shape's coordinate space.
See also swfshape->movepen(), swfshape->drawcurveto(), swfshape->drawlineto() and swfshape->drawline().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
What this nonsense is about is, every edge segment borders at most two fills. When rasterizing the object, it's pretty handy to know what those fills are ahead of time, so the swf format requires these to be specified.
swfshape->setleftfill() sets the fill on the left side of the edge- that is, on the interior if you're defining the outline of the shape in a counter-clockwise fashion. The fill object is an SWFFill object returned from one of the addFill functions above.
This seems to be reversed when you're defining a shape in a morph, though. If your browser crashes, just try setting the fill on the other side.
Shortcut for swfshape->setleftfill($s->addfill($r, $g, $b [, $a]));.
See also swfshape->setrightfill().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape->setline() sets the shape's line style. width is the line's width. If width is 0, the line's style is removed (then, all other arguments are ignored). If width > 0, then line's color is set to red, green, blue. Last parameter a is optional.
swfshape->setline() accepts 1, 4 or 5 arguments (not 3 or 2).
You must declare all line styles before you use them (see example).
This simple example will draw a big "!#%*@", in funny colors and gracious style.
ÐáñÜäåéãìá 1. swfshape->setline() example
|
(no version information, might be only in CVS)
SWFShape->setRightFill -- Sets right rasterizing color.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also swfshape->setleftfill().
Shortcut for swfshape->setrightfill($s->addfill($r, $g, $b [, $a]));.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfshape() creates a new shape object.
SWFShape has the following methods : swfshape->setline(), swfshape->addfill(), swfshape->setleftfill(), swfshape->setrightfill(), swfshape->movepento(), swfshape->movepen(), swfshape->drawlineto(), swfshape->drawline(), swfshape->drawcurveto() and swfshape->drawcurve().
This simple example will draw a big red elliptic quadrant.
ÐáñÜäåéãìá 1. swfshape() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfsprite->add() adds a swfshape(), a swfbutton(), a swftext(), a swfaction() or a swfsprite() object.
For displayable types (swfshape(), swfbutton(), swftext(), swfaction() or swfsprite()), this returns a handle to the object in a display list.
(no version information, might be only in CVS)
SWFSprite->nextframe -- Moves to the next frame of the animation.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfsprite->setframes() moves to the next frame of the animation.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfsprite->remove() remove a swfshape(), a swfbutton(), a swftext(), a swfaction() or a swfsprite() object from the sprite.
(no version information, might be only in CVS)
SWFSprite->setframes -- Sets the total number of frames in the animation.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfsprite->setframes() sets the total number of frames in the animation to numberofframes.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swfsprite() are also known as a "movie clip", this allows one to create objects which are animated in their own timelines. Hence, the sprite has most of the same methods as the movie.
swfsprite() has the following methods : swfsprite->add(), swfsprite->remove(), swfsprite->nextframe() and swfsprite->setframes().
This simple example will spin gracefully a big red square.
ÐáñÜäåéãìá 1. swfsprite() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext->addstring() draws the string string at the current pen (cursor) location. Pen is at the baseline of the text; i.e., ascending text is in the -y direction.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext->addstring() returns the rendered width of the string string at the text object's current font, scale, and spacing settings.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext->moveto() moves the pen (or cursor, if that makes more sense) to (x,y) in text object's coordinate space. If either is zero, though, value in that dimension stays the same. Annoying, should be fixed.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext->setspacing() changes the current text color. Default is black. I think. Color is represented using the RGB system.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext->setfont() sets the current font to font.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext->setheight() sets the current font height to height. Default is 240.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext->setspacing() sets the current font spacing to spacingspacing. Default is 1.0. 0 is all of the letters written at the same point. This doesn't really work that well because it inflates the advance across the letter, doesn't add the same amount of spacing between the letters. I should try and explain that better, prolly. Or just fix the damn thing to do constant spacing. This was really just a way to figure out how letter advances work, anyway.. So nyah.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftext() creates a new SWFText object, fresh for manipulating.
SWFText has the following methods : swftext->setfont(), swftext->setheight(), swftext->setspacing(), swftext->setcolor(), swftext->moveto(), swftext->addstring() and swftext->getwidth().
This simple example will draw a big yellow "PHP generates Flash with Ming" text, on white background.
ÐáñÜäåéãìá 1. swftext() example
|
(no version information, might be only in CVS)
SWFTextField->addstring -- Concatenates the given string to the text fieldÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setname() concatenates the string string to the text field.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->align() sets the text field alignment to alignement. Valid values for alignement are : SWFTEXTFIELD_ALIGN_LEFT, SWFTEXTFIELD_ALIGN_RIGHT, SWFTEXTFIELD_ALIGN_CENTER and SWFTEXTFIELD_ALIGN_JUSTIFY.
(no version information, might be only in CVS)
SWFTextField->setbounds -- Sets the text field width and heightÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setbounds() sets the text field width to width and height to height. If you don't set the bounds yourself, Ming makes a poor guess at what the bounds are.
(no version information, might be only in CVS)
SWFTextField->setcolor -- Sets the color of the text field.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setcolor() sets the color of the text field. Default is fully opaque black. Color is represented using RGB system.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setfont() sets the text field font to the [browser-defined?] font font.
(no version information, might be only in CVS)
SWFTextField->setHeight -- Sets the font height of this text field font.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setheight() sets the font height of this text field font to the given height height. Default is 240.
(no version information, might be only in CVS)
SWFTextField->setindentation -- Sets the indentation of the first line.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setindentation() sets the indentation of the first line in the text field, to width.
(no version information, might be only in CVS)
SWFTextField->setLeftMargin -- Sets the left margin width of the text field.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setleftmargin() sets the left margin width of the text field to width. Default is 0.
(no version information, might be only in CVS)
SWFTextField->setLineSpacing -- Sets the line spacing of the text field.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setlinespacing() sets the line spacing of the text field to the height of height. Default is 40.
(no version information, might be only in CVS)
SWFTextField->setMargins -- Sets the margins width of the text field.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setmargins() set both margins at once, for the man on the go.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setname() sets the variable name of this text field to name, for form posting and action scripting purposes.
(no version information, might be only in CVS)
SWFTextField->setrightMargin -- Sets the right margin width of the text field.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield->setrightmargin() sets the right margin width of the text field to width. Default is 0.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
swftextfield() creates a new text field object. Text Fields are less flexible than swftext() objects- they can't be rotated, scaled non-proportionally, or skewed, but they can be used as form entries, and they can use browser-defined fonts.
The optional flags change the text field's behavior. It has the following possibles values :
SWFTEXTFIELD_DRAWBOX draws the outline of the textfield
SWFTEXTFIELD_HASLENGTH
SWFTEXTFIELD_HTML allows text markup using HTML-tags
SWFTEXTFIELD_MULTILINE allows multiple lines
SWFTEXTFIELD_NOEDIT indicates that the field shouldn't be user-editable
SWFTEXTFIELD_NOSELECT makes the field non-selectable
SWFTEXTFIELD_PASSWORD obscures the data entry
SWFTEXTFIELD_WORDWRAP allows text to wrap
<?php $t = newSWFTextField(SWFTEXTFIELD_PASSWORD | SWFTEXTFIELD_NOEDIT); ?> |
SWFTextField has the following methods : swftextfield->setfont(), swftextfield->setbounds(), swftextfield->align(), swftextfield->setheight(), swftextfield->setleftmargin(), swftextfield->setrightmargin(), swftextfield->setmargins(), swftextfield->setindentation(), swftextfield->setlinespacing(), swftextfield->setcolor(), swftextfield->setname() and swftextfield->addstring().
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Misc. Configuration Options
Name | Default | Changeable |
---|---|---|
ignore_user_abort | "0" | PHP_INI_ALL |
highlight.string | #DD0000 | PHP_INI_ALL |
highlight.comment | #FF9900 | PHP_INI_ALL |
highlight.keyword | #007700 | PHP_INI_ALL |
highlight.bg | #FFFFFF | PHP_INI_ALL |
highlight.default | #0000BB | PHP_INI_ALL |
highlight.html | #000000 | PHP_INI_ALL |
browscap | NULL | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
TRUE by default. If changed to FALSE scripts will be terminated as soon as they try to output something after a client has aborted their connection.
See also ignore_user_abort().
Colors for Syntax Highlighting mode. Anything that's acceptable in <font color="??????"> would work.
Name (e.g.: browscap.ini) and location of browser capabilities file. See also get_browser().
Returns TRUE if client disconnected. See the Connection Handling description in the Features chapter for a complete explanation.
See also connection_status(), and ignore_user_abort().
Returns the connection status bitfield. See the Connection Handling description in the Features chapter for a complete explanation.
See also connection_aborted(), and ignore_user_abort().
Returns TRUE if script timed out.
Deprecated |
This function is deprecated, and doesn't even exist anymore as of 4.0.5. |
See the Connection Handling description in the Features chapter for a complete explanation.
constant() will return the value of the constant indicated by name.
constant() is useful if you need to retrieve the value of a constant, but do not know its name. i.e. It is stored in a variable or returned by a function.
Defines a named constant. See the section on constants for more details.
The name of the constant is given by name; the value is given by value.
The optional third parameter case_insensitive is also available. If the value TRUE is given, then the constant will be defined case-insensitive. The default behaviour is case-sensitive; i.e. CONSTANT and Constant represent different values.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also defined(), constant() and the section on Constants.
Returns TRUE if the named constant given by name has been defined, FALSE otherwise.
Óçìåßùóç: If you want to see if a variable exists, use isset() as defined() only applies to constants. If you want to see if a function exists, use function_exists().
See also define(), constant(), get_defined_constants(), function_exists(), and the section on Constants.
eval() evaluates the string given in code_str as PHP code. Among other things, this can be useful for storing code in a database text field for later execution.
There are some factors to keep in mind when using eval(). Remember that the string passed must be valid PHP code, including things like terminating statements with a semicolon so the parser doesn't die on the line after the eval(), and properly escaping things in code_str.
Also remember that variables given values under eval() will retain these values in the main script afterwards.
A return statement will terminate the evaluation of the string immediately. In PHP 4, eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. In PHP 3, eval() does not return a value.
ÐáñÜäåéãìá 1. eval() example - simple text merge
The above example will show:
|
Õðüäåéîç: ¼ðùò ìå ïôéäÞðïôå ðáñÜãåé ôá áðïôåëÝóìáô ôïõ êáôåõèåßáí óôïí browser, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôéò óõíáñôÞóåéò åëÝã÷ïõ åîüäïõ ãéá íá ðÜñåôå ôçí Ýîïäï áõôÞò ôçò óõíÜñôçóçò êáé íá ôçí áðïèçêåýóåôå óå Ýíá string (ãéá ðáñÜäåéãìá).
Óçìåßùóç: This is not a real function, but a language construct.
Óçìåßùóç: PHP >= 4.2.0 does NOT print the status if it is an integer.
The exit() function terminates execution of the script. It prints status just before exiting.
If status is an integer, that value will also be used as the exit status. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.
Óçìåßùóç: The die() function is an alias for exit().
See also: register_shutdown_function().
get_browser() attempts to determine the capabilities of the user's browser. This is done by looking up the browser's information in the browscap.ini file. By default, the value of $_SERVER["HTTP_USER_AGENT"] is used; however, you can alter this (i.e., look up another browser's info) by passing the optional user_agent parameter to get_browser().
The information is returned in an object, which will contain various data elements representing, for instance, the browser's major and minor version numbers and ID string; TRUE/FALSE values for features such as frames, JavaScript, and cookies; and so forth.
While browscap.ini contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.
The following example shows how one might list all available information retrieved about the user's browser.
ÐáñÜäåéãìá 1. get_browser() example
The output of the above script would look something like this:
|
In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system. browscap.ini is not bundled with PHP but you may find an up-to-date browscap.ini file here. By default, the browscap directive is commented out.
The cookies value simply means that the browser itself is capable of accepting cookies and does not mean the user has enabled the browser to accept cookies or not. The only way to test if cookies are accepted is to set one with setcookie(), reload, and check for the value.
Óçìåßùóç: On versions older than PHP 4.0.6, you will have to pass the user agent in via the optional user_agent parameter if the PHP directive register_globals is off. In this case, you will pass in $HTTP_SERVER_VARS['HTTP_USER_AGENT'].
The highlight_file() function prints out a syntax highlighted version of the code contained in filename using the colors defined in the built-in syntax highlighter for PHP.
If the second parameter return is set to TRUE then highlight_file() will return the highlighted code as a string instead of printing it out. If the second parameter is not set to TRUE then highlight_file() will return TRUE on success, FALSE on failure.
Óçìåßùóç: The return parameter became available in PHP 4.2.0. Before this time it behaved like the default, which is FALSE
Ðñïóï÷Þ |
Care should be taken when using the show_source() and highlight_file() functions to make sure that you do not inadvertently reveal sensitive information such as passwords or any other type of information that might create a potential security risk. |
Óçìåßùóç: Since PHP 4.2.1 this function is also affected by safe_mode and open_basedir.
To setup a URL that can code hightlight any script that you pass to it, we will make use of the "ForceType" directive in Apache to generate a nice URL pattern, and use the function highlight_file() to show a nice looking code list.
In your httpd.conf you can add the following:
ÐáñÜäåéãìá 1. Creating a source highlighting URL
And then make a file named source and put it in your web root directory.
Then you can use a URL like the one below to display a colorized version of a script located in "/path/to/script.php" in your web site.
|
See also highlight_string().
The highlight_string() function outputs a syntax highlighted version of str using the colors defined in the built-in syntax highlighter for PHP.
If the second parameter return is set to TRUE then highlight_string() will return the highlighted code as a string instead of printing it out. If the second parameter is not set to TRUE then highlight_string() will return TRUE on success, FALSE on failure.
ÐáñÜäåéãìá 1. highlight_string() example
The above example will output (in PHP 4):
The above example will output (in PHP 5):
|
Óçìåßùóç: The return parameter became available in PHP 4.2.0. Before this time it behaved like the default, which is FALSE
See also highlight_file().
(PHP 3>= 3.0.7, PHP 4 , PHP 5)
ignore_user_abort -- Set whether a client disconnect should abort script executionThis function sets whether a client disconnect should cause a script to be aborted. It will return the previous setting and can be called without an argument to not change the current setting and only return the current setting. See the Connection Handling section in the Features chapter for a complete description of connection handling in PHP.
See also connection_aborted(), and connection_status().
Pack given arguments into binary string according to format. Returns binary string containing data.
The idea to this function was taken from Perl and all formatting codes work the same as there, however, there are some formatting codes that are missing such as Perl's "u" format code. The format string consists of format codes followed by an optional repeater argument. The repeater argument can be either an integer value or * for repeating to the end of the input data. For a, A, h, H the repeat count specifies how many characters of one data argument are taken, for @ it is the absolute position where to put the next data, for everything else the repeat count specifies how many data arguments are consumed and packed into the resulting binary string. Currently implemented are
Ðßíáêáò 1. pack() format characters
Code | Description |
---|---|
a | NUL-padded string |
A | SPACE-padded string |
h | Hex string, low nibble first |
H | Hex string, high nibble first |
c | signed char |
C | unsigned char |
s | signed short (always 16 bit, machine byte order) |
S | unsigned short (always 16 bit, machine byte order) |
n | unsigned short (always 16 bit, big endian byte order) |
v | unsigned short (always 16 bit, little endian byte order) |
i | signed integer (machine dependent size and byte order) |
I | unsigned integer (machine dependent size and byte order) |
l | signed long (always 32 bit, machine byte order) |
L | unsigned long (always 32 bit, machine byte order) |
N | unsigned long (always 32 bit, big endian byte order) |
V | unsigned long (always 32 bit, little endian byte order) |
f | float (machine dependent size and representation) |
d | double (machine dependent size and representation) |
x | NUL byte |
X | Back up one byte |
@ | NUL-fill to absolute position |
Note that the distinction between signed and unsigned values only affects the function unpack(), where as function pack() gives the same result for signed and unsigned format codes.
Also note that PHP internally stores integer values as signed values of a machine dependent size. If you give it an unsigned integer value too large to be stored that way it is converted to a float which often yields an undesired result.
See also unpack().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The sleep() function delays program execution for the given number of seconds.
See also usleep() and set_time_limit()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
uniqid() returns a prefixed unique identifier based on the current time in microseconds. The prefix can be useful for instance if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond. Prefix can be up to 114 characters long.
If the optional lcg parameter is TRUE, uniqid() will add additional "combined LCG" entropy at the end of the return value, which should make the results more unique.
With an empty prefix, the returned string will be 13 characters long. If lcg is TRUE, it will be 23 characters.
Óçìåßùóç: The lcg parameter is only available in PHP 4 and PHP 3.0.13 and later.
If you need a unique identifier or token and you intend to give out that token to the user via the network (i.e. session cookies), it is recommended that you use something along these lines:
<?php // no prefix $token = md5(uniqid("")); // better, difficult to guess $better_token = md5(uniqid(rand(), true)); ?> |
This will create a 32 character identifier (a 128 bit hex number) that is extremely difficult to predict.
unpack() from binary string into array according to format. Returns array containing unpacked elements of binary string.
unpack() works slightly different from Perl as the unpacked data is stored in an associative array. To accomplish this you have to name the different format codes and separate them by a slash /.
Ðñïóï÷Þ |
Note that PHP internally stores integral values as signed. If you unpack a large unsigned long and it is of the same size as PHP internally stored values the result will be a negative number even though unsigned unpacking was specified. |
See also pack() for an explanation of the format codes.
The usleep() function delays program execution for the given number of micro_seconds. A microsecond is one millionth of a second.
Óçìåßùóç: This function did not work on Windows systems until PHP 5.0.0
See also sleep() and set_time_limit().
These functions allow you to access the mnoGoSearch (former UdmSearch) free search engine. mnoGoSearch is a full-featured search engine software for intranet and internet servers, distributed under the GNU license. mnoGoSearch has a number of unique features, which makes it appropriate for a wide range of applications from search within your site to a specialized search system such as cooking recipes or newspaper search, FTP archive search, news articles search, etc. It offers full-text indexing and searching for HTML, PDF, and text documents. mnoGoSearch consists of two parts. The first is an indexing mechanism (indexer). The purpose of the indexer is to walk through HTTP, FTP, NEWS servers or local files, recursively grabbing all the documents and storing meta-data about that documents in a SQL database in a smart and effective manner. After every document is referenced by its corresponding URL, meta-data is collected by the indexer for later use in a search process. The search is performed via Web interface. C, CGI, PHP and Perl search front ends are included.
More information about mnoGoSearch can be found at http://www.mnogosearch.ru/.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
Download mnoGosearch from http://www.mnogosearch.ru/ and install it on your system. You need at least version 3.1.10 of mnoGoSearch installed to use these functions.
In order to have these functions available, you must compile PHP with mnoGosearch support by using the --with-mnogosearchoption. If you use this option without specifying the path to mnoGosearch, PHP will look for mnoGosearch under /usr/local/mnogosearch path by default. If you installed mnoGosearch at a different location you should specify it: --with-mnogosearch=DIR.
Óçìåßùóç: PHP contains built-in MySQL access library, which can be used to access MySQL. It is known that mnoGoSearch is not compatible with this built-in library and can work only with generic MySQL libraries. Thus, if you use mnoGoSearch with MySQL, during PHP configuration you have to indicate the directory of your MySQL installation, that was used during mnoGoSearch configuration, i.e. for example: --with-mnogosearch --with-mysql=/usr.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
udm_add_search_limit() adds search restrictions. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
agent - a link to Agent, received after call to udm_alloc_agent().
var - defines parameter, indicating limit.
val - defines the value of the current parameter.
Possible var values:
UDM_LIMIT_URL - defines document URL limitations to limit the search through subsection of the database. It supports SQL % and _ LIKE wildcards, where % matches any number of characters, even zero characters, and _ matches exactly one character. E.g. http://www.example.___/catalog may stand for http://www.example.com/catalog and http://www.example.net/catalog.
UDM_LIMIT_TAG - defines site TAG limitations. In indexer-conf you can assign specific TAGs to various sites and parts of a site. Tags in mnoGoSearch 3.1.x are lines, that may contain metasymbols % and _. Metasymbols allow searching among groups of tags. E.g. there are links with tags ABCD and ABCE, and search restriction is by ABC_ - the search will be made among both of the tags.
UDM_LIMIT_LANG - defines document language limitations.
UDM_LIMIT_CAT - defines document category limitations. Categories are similar to tag feature, but nested. So you can have one category inside another and so on. You have to use two characters for each level. Use a hex number going from 0-F or a 36 base number going from 0-Z. Therefore a top-level category like 'Auto' would be 01. If it has a subcategory like 'Ford', then it would be 01 (the parent category) and then 'Ford' which we will give 01. Put those together and you get 0101. If 'Auto' had another subcategory named 'VW', then it's id would be 01 because it belongs to the 'Ford' category and then 02 because it's the next category. So it's id would be 0102. If VW had a sub category called 'Engine' then it's id would start at 01 again and it would get the 'VW' id 02 and 'Auto' id of 01, making it 010201. If you want to search for sites under that category then you pass it cat=010201 in the URL.
UDM_LIMIT_DATE - defines limitation by date the document was modified.
Format of parameter value: a string with first character < or >, then with no space - date in unixtime format, for example:
If > character is used, then the search will be restricted to those documents having a modification date greater than entered, if <, then smaller.
udm_alloc_agent_array() will create an agent with multiple database connections. The array databases must contain one database URL per element, analog to the first parameter of udm_alloc_agent().
See also: udm_alloc_agent().
Returns a mnogosearch agent identifier on success, FALSE on failure. This function creates a session with database parameters.
dbaddr - URL-style database description, with options (type, host, database name, port, user and password) to connect to SQL database. Do not matter for built-in text files support. Format for dbaddr: DBType:[//[DBUser[:DBPass]@]DBHost[:DBPort]]/DBName/. Currently supported DBType values are: mysql, pgsql, msql, solid, mssql, oracle, and ibase. Actually, it does not matter for native libraries support, but ODBC users should specify one of the supported values. If your database type is not supported, you may use unknown instead.
dbmode - You may select the SQL database mode of words storage. Possible values of dbmode are: single, multi, crc, or crc-multi. When single is specified, all words are stored in the same table. If multi is selected, words will be located in different tables depending of their lengths. "multi" mode is usually faster, but requires more tables in the database. If "crc" mode is selected, mnoGoSearch will store 32 bit integer word IDs calculated by CRC32 algorithm instead of words. This mode requires less disk space and it is faster comparing with "single" and "multi" modes. crc-multi uses the same storage structure with the "crc" mode, but also stores words in different tables depending on words lengths like in "multi" mode.
Óçìåßùóç: dbaddr and dbmode must match those used during indexing.
Óçìåßùóç: In fact this function does not open a connection to the database and thus does not check the entered login and password. Establishing a connection to the database and login/password verification is done by udm_find().
udm_api_version() returns the mnoGoSearch API version number. E.g. if mnoGoSearch 3.1.10 API is used, this function will return 30110.
This function allows the user to identify which API functions are available, e.g. udm_get_doc_count() function is only available in mnoGoSearch 3.1.11 or later.
(PHP 4 >= 4.0.6, PHP 5)
udm_cat_list -- Get all the categories on the same level with the current one.Returns an array listing all categories of the same level as the current category in the categories tree. agent is the agent identifier returned by a previous call to >udm_alloc_agent().
The function can be useful for developing categories tree browser.
The returned array consists of pairs. Elements with even index numbers contain the category paths, odd elements contain the corresponding category names.
$array[0] will contain '020300' $array[1] will contain 'Audi' $array[2] will contain '020301' $array[3] will contain 'BMW' $array[4] will contain '020302' $array[5] will contain 'Opel' ... etc. |
Following is an example of displaying links of the current level in format:
Audi BMW Opel ... |
See also udm_cat_path().
Returns an array describing the path in the categories tree from the tree root to the current one, specified by category. agent is the agent identifier returned by a previous call to >udm_alloc_agent().
The returned array consists of pairs. Elements with even index numbers contain the category paths, odd elements contain the corresponding category names.
For example, the call $array=udm_cat_path($agent, '02031D'); may return the following array:
$array[0] will contain '' $array[1] will contain 'Root' $array[2] will contain '02' $array[3] will contain 'Sport' $array[4] will contain '0203' $array[5] will contain 'Auto' $array[4] will contain '02031D' $array[5] will contain 'Ferrari' |
ÐáñÜäåéãìá 1. Specifying path to the current category in the following format: '> Root > Sport > Auto > Ferrari'
|
See also udm_cat_list().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
udm_clear_search_limits() resets defined search limitations and returns TRUE.
See also udm_add_search_limit().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
udm_errno() returns mnoGoSearch error number, zero if no error.
agent - link to agent identifier, received after call to udm_alloc_agent().
Receiving numeric agent error code.
udm_error() returns mnoGoSearch error message, empty string if no error.
agent - link to agent identifier, received after call to udm_alloc_agent().
Receiving agent error message.
Returns a result link identifier on success, or FALSE on failure.
The search itself. The first argument - session, the next one - query itself. To find something just type words you want to find and press SUBMIT button. For example, "mysql odbc". You should not use quotes " in query, they are written here only to divide a query from other text. mnoGoSearch will find all documents that contain word "mysql" and/or word "odbc". Best documents having bigger weights will be displayed first. If you use search mode ALL, search will return documents that contain both (or more) words you entered. In case you use mode ANY, the search will return list of documents that contain any of the words you entered. If you want more advanced results you may use query language. You should select "bool" match mode in the search from.
mnoGoSearch understands the following boolean operators:
& - logical AND. For example, "mysql & odbc". mnoGoSearch will find any URLs that contain both "mysql" and "odbc".
| - logical OR. For example "mysql|odbc". mnoGoSearch will find any URLs, that contain word "mysql" or word "odbc".
~ - logical NOT. For example "mysql & ~odbc". mnoGoSearch will find URLs that contain word "mysql" and do not contain word "odbc" at the same time. Note that ~ just excludes given word from results. Query "~odbc" will find nothing!
() - group command to compose more complex queries. For example "(mysql | msql) & ~postgres". Query language is simple and powerful at the same time. Just consider query as usual boolean expression.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
agent - link to agent identifier, received ` after call to udm_alloc_agent().
Freeing up memory allocated for agent session.
udm_free_ispell_data() always returns TRUE.
agent - agent link identifier, received after call to udm_alloc_agent().
Óçìåßùóç: This function is supported beginning from version 3.1.12 of mnoGoSearch and it does not do anything in previous versions.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
res - a link to result identifier, received after call to udm_find().
Freeing up memory allocated for results.
udm_get_doc_count() returns the number of documents in the database.
agent - link to agent identifier, received after call to udm_alloc_agent().
Óçìåßùóç: This function is supported only in mnoGoSearch 3.1.11 or later.
udm_get_res_field() returns result field value on success, FALSE on error.
res - a link to result identifier, received after call to udm_find().
row - the number of the link on the current page. May have values from 0 to UDM_PARAM_NUM_ROWS-1.
field - field identifier, may have the following values:
UDM_FIELD_URL - document URL field
UDM_FIELD_CONTENT - document Content-type field (for example, text/html).
UDM_FIELD_CATEGORY - document category field. Use udm_cat_path() to get full path to current category from the categories tree root. (This parameter is available only in PHP 4.0.6 or later).
UDM_FIELD_TITLE - document title field.
UDM_FIELD_KEYWORDS - document keywords field (from META KEYWORDS tag).
UDM_FIELD_DESC - document description field (from META DESCRIPTION tag).
UDM_FIELD_TEXT - document body text (the first couple of lines to give an idea of what the document is about).
UDM_FIELD_SIZE - document size.
UDM_FIELD_URLID - unique URL ID of the link.
UDM_FIELD_RATING - page rating (as calculated by mnoGoSearch).
UDM_FIELD_MODIFIED - last-modified field in unixtime format.
UDM_FIELD_ORDER - the number of the current document in set of found documents.
UDM_FIELD_CRC - document CRC.
udm_get_res_param() returns result parameter value on success, FALSE on error.
res - a link to result identifier, received after call to udm_find().
param - parameter identifier, may have the following values:
UDM_PARAM_NUM_ROWS - number of received found links on the current page. It is equal to UDM_PARAM_PAGE_SIZE for all search pages, on the last page - the rest of links.
UDM_PARAM_FOUND - total number of results matching the query.
UDM_PARAM_WORDINFO - information on the words found. E.g. search for "a good book" will return "a: stopword, good:5637, book: 120"
UDM_PARAM_SEARCHTIME - search time in seconds.
UDM_PARAM_FIRST_DOC - the number of the first document displayed on current page.
UDM_PARAM_LAST_DOC - the number of the last document displayed on current page.
udm_hash32() will take a string str and return a quite unique 32-bit hash number from it. Requires an allocated agent.
See also: udm_alloc_agent().
udm_load_ispell_data() loads ispell data. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
agent - agent link identifier, received after call to udm_alloc_agent().
var - parameter, indicating the source for ispell data. May have the following values:
After using this function to free memory allocated for ispell data, please use udm_free_ispell_data(), even if you use UDM_ISPELL_TYPE_SERVER mode.
The fastest mode is UDM_ISPELL_TYPE_SERVER. UDM_ISPELL_TYPE_TEXT is slower and UDM_ISPELL_TYPE_DB is the slowest. The above pattern is TRUE for mnoGoSearch 3.1.10 - 3.1.11. It is planned to speed up DB mode in future versions and it is going to be faster than TEXT mode.
UDM_ISPELL_TYPE_DB - indicates that ispell data should be loaded from SQL. In this case, parameters val1 and val2 are ignored and should be left blank. flag should be equal to 1.
Óçìåßùóç: flag indicates that after loading ispell data from defined source it should be sorted (it is necessary for correct functioning of ispell). In case of loading ispell data from files there may be several calls to udm_load_ispell_data(), and there is no sense to sort data after every call, but only after the last one. Since in db mode all the data is loaded by one call, this parameter should have the value 1. In this mode in case of error, e.g. if ispell tables are absent, the function will return FALSE and code and error message will be accessible through udm_error() and udm_errno().
UDM_ISPELL_TYPE_AFFIX - indicates that ispell data should be loaded from file and initiates loading affixes file. In this case val1 defines double letter language code for which affixes are loaded, and val2 - file path. Please note, that if a relative path entered, the module looks for the file not in UDM_CONF_DIR, but in relation to current path, i.e. to the path where the script is executed. In case of error in this mode, e.g. if file is absent, the function will return FALSE, and an error message will be displayed. Error message text cannot be accessed through udm_error() and udm_errno(), since those functions can only return messages associated with SQL. Please, see flag parameter description in UDM_ISPELL_TYPE_DB.
ÐáñÜäåéãìá 2. udm_load_ispell_data() example
|
Óçìåßùóç: flag is equal to 1 only in the last call.
UDM_ISPELL_TYPE_SPELL - indicates that ispell data should be loaded from file and initiates loading of ispell dictionary file. In this case val1 defines double letter language code for which affixes are loaded, and val2 - file path. Please note, that if a relative path entered, the module looks for the file not in UDM_CONF_DIR, but in relation to current path, i.e. to the path where the script is executed. In case of error in this mode, e.g. if file is absent, the function will return FALSE, and an error message will be displayed. Error message text cannot be accessed through udm_error() and udm_errno(), since those functions can only return messages associated with SQL. Please, see flag parameter description in UDM_ISPELL_TYPE_DB.
<?php if ((! Udm_Load_Ispell_Data($udm, UDM_ISPELL_TYPE_AFFIX, 'en', '/opt/ispell/en.aff', 0)) || (! Udm_Load_Ispell_Data($udm, UDM_ISPELL_TYPE_AFFIX, 'ru', '/opt/ispell/ru.aff', 0)) || (! Udm_Load_Ispell_Data($udm, UDM_ISPELL_TYPE_SPELL, 'en', '/opt/ispell/en.dict', 0)) || (! Udm_Load_Ispell_Data($udm, UDM_ISPELL_TYPE_SPELL, 'ru', '/opt/ispell/ru.dict', 1))) { exit; } ?> |
Óçìåßùóç: flag is equal to 1 only in the last call.
UDM_ISPELL_TYPE_SERVER - enables spell server support. val1 parameter indicates address of the host running spell server. val2 ` is not used yet, but in future releases it is going to indicate number of port used by spell server. flag parameter in this case is not needed since ispell data is stored on spellserver already sorted.
Spelld server reads spell-data from a separate configuration file (/usr/local/mnogosearch/etc/spelld.conf by default), sorts it and stores in memory. With clients server communicates in two ways: to indexer all the data is transferred (so that indexer starts faster), from search.cgi server receives word to normalize and then passes over to client (search.cgi) list of normalized word forms. This allows fastest, compared to db and text modes processing of search queries (by omitting loading and sorting all the spell data).
udm_load_ispell_data() function in UDM_ISPELL_TYPE_SERVER mode does not actually load ispell data, but only defines server address. In fact, server is automatically used by udm_find() function when performing search. In case of errors, e.g. if spellserver is not running or invalid host indicated, there are no messages returned and ispell conversion does not work.
Óçìåßùóç: This function is available in mnoGoSearch 3.1.12 or later.
Example:
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Defines mnoGoSearch session parameters.
The following parameters and their values are available:
UDM_PARAM_PAGE_NUM - used to choose search results page number (results are returned by pages beginning from 0, with UDM_PARAM_PAGE_SIZE results per page).
UDM_PARAM_PAGE_SIZE - number of search results displayed on one page.
UDM_PARAM_SEARCH_MODE - search mode. The following values available: UDM_MODE_ALL - search for all words; UDM_MODE_ANY - search for any word; UDM_MODE_PHRASE - phrase search; UDM_MODE_BOOL - boolean search. See udm_find() for details on boolean search.
UDM_PARAM_CACHE_MODE - turns on or off search result cache mode. When enabled, the search engine will store search results to disk. In case a similar search is performed later, the engine will take results from the cache for faster performance. Available values: UDM_CACHE_ENABLED, UDM_CACHE_DISABLED.
UDM_PARAM_TRACK_MODE - turns on or off trackquery mode. Since version 3.1.2 mnoGoSearch has a query tracking support. Note that tracking is implemented in SQL version only and not available in built-in database. To use tracking, you have to create tables for tracking support. For MySQL, use create/mysql/track.txt. When doing a search, front-end uses those tables to store query words, a number of found documents and current Unix timestamp in seconds. Available values: UDM_TRACK_ENABLED, UDM_TRACK_DISABLED.
UDM_PARAM_PHRASE_MODE - defines whether index database using phrases ("phrase" parameter in indexer.conf). Possible values: UDM_PHRASE_ENABLED and UDM_PHRASE_DISABLED. Please note, that if phrase search is enabled (UDM_PHRASE_ENABLED), it is still possible to do search in any mode (ANY, ALL, BOOL or PHRASE). In 3.1.10 version of mnoGoSearch phrase search is supported only in sql and built-in database modes, while beginning with 3.1.11 phrases are supported in cachemode as well.
Examples of phrase search:
"Arizona desert" - This query returns all indexed documents that contain "Arizona desert" as a phrase. Notice that you need to put double quotes around the phrase
UDM_PARAM_CHARSET - defines local charset. Available values: set of charsets supported by mnoGoSearch, e.g. koi8-r, cp1251, ...
UDM_PARAM_STOPFILE - Defines name and path to stopwords file. (There is a small difference with mnoGoSearch - while in mnoGoSearch if relative path or no path entered, it looks for this file in relation to UDM_CONF_DIR, the module looks for the file in relation to current path, i.e. to the path where the PHP script is executed.)
UDM_PARAM_STOPTABLE - Load stop words from the given SQL table. You may use several StopwordTable commands. This command has no effect when compiled without SQL database support.
UDM_PARAM_WEIGHT_FACTOR - represents weight factors for specific document parts. Currently body, title, keywords, description, url are supported. To activate this feature please use degrees of 2 in *Weight commands of the indexer.conf. Let's imagine that we have these weights:
URLWeight 1
BodyWeight 2
TitleWeight 4
KeywordWeight 8
DescWeight 16
As far as indexer uses bit OR operation for word weights when some word presents several time in the same document, it is possible at search time to detect word appearance in different document parts. Word which appears only in the body will have 00000010 aggregate weight (in binary notation). Word used in all document parts will have 00011111 aggregate weight.
This parameter's value is a string of hex digits ABCDE. Each digit is a factor for corresponding bit in word weight. For the given above weights configuration:
E is a factor for weight 1 (URL Weight bit)
D is a factor for weight 2 (BodyWeight bit)
C is a factor for weight 4 (TitleWeight bit)
B is a factor for weight 8 (KeywordWeight bit)
A is a factor for weight 16 (DescWeight bit)
Examples:
UDM_PARAM_WEIGHT_FACTOR=00001 will search through URLs only.
UDM_PARAM_WEIGHT_FACTOR=00100 will search through Titles only.
UDM_PARAM_WEIGHT_FACTOR=11100 will search through Title,Keywords,Description but not through URL and Body.
UDM_PARAM_WEIGHT_FACTOR=F9421 will search through:
Description with factor 15 (F hex)
Keywords with factor 9
Title with factor 4
Body with factor 2
URL with factor 1
If UDM_PARAM_WEIGHT_FACTOR variable is omitted, original weight value is taken to sort results. For a given above weight configuration it means that document description has a most big weight 16.
UDM_PARAM_WORD_MATCH - word match. You may use this parameter to choose word match type. This feature works only in "single" and "multi" modes using SQL based and built-in database. It does not work in cachemode and other modes since they use word CRC and do not support substring search. Available values:
UDM_MATCH_BEGIN - word beginning match;
UDM_MATCH_END - word ending match;
UDM_MATCH_WORD - whole word match;
UDM_MATCH_SUBSTR - word substring match.
UDM_PARAM_MIN_WORD_LEN - defines minimal word length. Any word shorter this limit is considered to be a stopword. Please note that this parameter value is inclusive, i.e. if UDM_PARAM_MIN_WORD_LEN=3, a word 3 characters long will not be considered a stopword, while a word 2 characters long will be. Default value is 1.
UDM_PARAM_ISPELL_PREFIXES - Possible values: UDM_PREFIXES_ENABLED and UDM_PREFIXES_DISABLED, that respectively enable or disable using prefixes. E.g. if a word "tested" is in search query, also words like "test", "testing", etc. Only suffixes are supported by default. Prefixes usually change word meanings, for example if somebody is searching for the word "tested" one hardly wants "untested" to be found. Prefixes support may also be found useful for site's spelling checking purposes. In order to enable ispell, you have to load ispell data with udm_load_ispell_data().
UDM_PARAM_CROSS_WORDS - enables or disables crosswords support. Possible values: UDM_CROSS_WORDS_ENABLED and UDM_CROSS_WORDS_DISABLED.
The crosswords feature allows to assign words between <a href="xxx"> and </a> also to a document this link leads to. It works in SQL database mode and is not supported in built-in database and Cachemode.
Óçìåßùóç: Crosswords are supported only in mnoGoSearch 3.1.11 or later.
UDM_PARAM_VARDIR - specifies a custom path to directory where indexer stores data when using built-in database and in cache mode. By default /var directory of mnoGoSearch installation is used. Can have only string values. The parameter is available in PHP 4.1.0 or later.
These functions allow you to access mSQL database servers. More information about mSQL can be found at http://www.hughes.com.au/.
In order to have these functions available, you must compile PHP with msql support by using the --with-msql[=DIR] option. DIR is the mSQL base install directory, defaults to /usr/local/msql3.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy msql.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32)
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. mSQL configuration options
Name | Default | Changeable |
---|---|---|
msql.allow_persistent | "On" | PHP_INI_SYSTEM |
msql.max_persistent | "-1" | PHP_INI_SYSTEM |
msql.max_links | "-1" | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
There are two resource types used in the mSQL module. The first one is the link identifier for a database connection, the second a resource which holds the result of a query.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
This simple example shows how to connect, execute a query, print resulting rows and disconnect from a mSQL database.
ÐáñÜäåéãìá 1. mSQL usage example
|
Returns number of affected ("touched") rows by a specific query (i.e. the number of rows returned by a SELECT, the number of rows modified by an update, or the number of rows removed by a delete).
See also: msql_query().
msql_close() closes the link to a mSQL database that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Note that this isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.
msql_close() will not close persistent links generated by msql_pconnect().
See also: msql_connect() and msql_pconnect().
msql_connect() establishes a connection to a mSQL server. The hostname parameter can also include a port number. e.g. "hostname:port". It defaults to 'localhost'.
Returns a positive mSQL link identifier on success, or FALSE on error.
In case a second call is made to msql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.
The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling msql_close().
See also msql_pconnect() and msql_close().
msql_create_db() attempts to create a new database on the server associated with the specified link_identifier.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also msql_drop_db().
msql_data_seek() moves the internal row pointer of the mSQL result associated with the specified query identifier to point to the specified row number. The next call to msql_fetch_row() would return that row.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also msql_fetch_row().
Returns a positive mSQL query identifier to the query result, or FALSE on error.
msql_db_query() selects a database and executes a query on it. If the optional link_identifier is not specified, the function will try to find an open link to the mSQL server; if no such link is found it will try to create one as if msql_connect() was called with no arguments.
See also msql_connect().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
msql_drop_db() attempts to drop (remove) an entire database from the server associated with the specified link identifier.
See also: msql_create_db().
msql_error() returns the last issued error by the mSQL server or an empty string if no error was issued. If no link is explicitly passed, the last successful open link will be used to retrieve the error message. Note that only the last error message is accessible with msql_error().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
msql_fetch_array() is an extended version of msql_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.
The second optional argument result_type in msql_fetch_array() is a constant and can take the following values: MSQL_ASSOC, MSQL_NUM, and MSQL_BOTH with MSQL_BOTH being the default.
Be careful if you are retrieving results from a query that may return a record that contains only one field that has a value of 0 (or an empty string, or NULL).
An important thing to note is that using msql_fetch_array() is NOT significantly slower than using msql_fetch_row(), while it provides a significant added value.
See also msql_fetch_row() and msql_fetch_object().
Returns an object containing field information
msql_fetch_field() can be used in order to obtain information about fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by msql_fetch_field() is retrieved.
The properties of the object are:
name - column name
table - name of the table the column belongs to
not_null - 1 if the column cannot be NULL
primary_key - 1 if the column is a primary key
unique - 1 if the column is a unique key
type - the type of the column
See also msql_field_seek().
Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.
msql_fetch_object() is similar to msql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
Speed-wise, the function is identical to msql_fetch_array(), and almost as quick as msql_fetch_row() (the difference is insignificant).
See also: msql_fetch_array() and msql_fetch_row().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
msql_fetch_row() fetches one row of data from the result associated with the specified query identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
Subsequent call to msql_fetch_row() would return the next row in the result set, or FALSE if there are no more rows.
See also: msql_fetch_array(), msql_fetch_object(), msql_data_seek(), and msql_result().
msql_field_flags() returns the field flags of the specified field. Currently this is either, "not NULL", "primary key", a combination of the two or "" (an empty string).
msql_field_len() returns the length of the specified field or FALSE on error.
msql_field_name() returns the name of the specified field from the result resource query_identifier. msql_field_name($result, 2); will return the name of the second field in the result set associated with the result identifier.
Seeks to the specified field offset. If the next call to msql_fetch_field() won't include a field offset, this field would be returned.
This function returns FALSE on failure.
See also: msql_fetch_field().
Returns the name of the table field was fetched from.
This function returns FALSE on failure.
msql_field_type() is similar to the msql_field_name() function. The arguments are identical, but the field type is returned. This will be one of "int", "char" or "real".
This function returns FALSE on failure.
msql_free_result() frees the memory associated with query_identifier. When PHP completes a request, this memory is freed automatically, so you only need to call this function when you want to make sure you don't use too much memory while the script is running.
For downward compatibility, the alias named msql_freeresult() may be used. This, however, is deprecated and not recommended.
msql_list_dbs() will return a result pointer containing the databases available from the current msql daemon. Use the msql_result() function to traverse this result pointer.
For downward compatibility, the alias named msql_listtables() may be used. This, however, is deprecated and not recommended.
msql_list_fields() retrieves information about the given tablename. The returned result set can be traversed with any function that fetches result sets, such as msql_fetch_array().
This function returns FALSE on failure.
For downward compatibility, the alias named msql_listfields() may be used. This, however, is deprecated and not recommended.
msql_list_tables() lists the tables on the specified database. It returns a result set which may be traversed with any function that fetches result sets, such as msql_fetch_array().
This function returns FALSE on failure.
For downward compatibility, the alias named msql_listtables() may be used. This, however, is deprecated and not recommended.
msql_num_fields() returns the number of fields in a result set.
For downwards compatability, the alias named msql_numfields() may be used. This, however, is deprecated and not recommended.
See also: msql_query(), msql_fetch_field(), and msql_num_rows().
msql_num_rows() returns the number of rows in a result set.
For downwards compatability, the alias named msql_numrows() may be used. This, however is deprecated and not recommended.
See also: msql_db_query() and msql_query().
msql_pconnect() acts very much like msql_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link that's already open with the same host. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (msql_close() will not close links established by msql_pconnect()).
Returns a positive mSQL persistent link identifier on success, or FALSE on error.
msql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if msql_connect() was called, and use it.
Returns a positive mSQL query identifier on success, or FALSE on error.
ÐáñÜäåéãìá 1. msql_query() example
|
See also msql_db_query(), msql_select_db(), and msql_connect().
Returns the contents of the cell at the row and offset in the specified mSQL result set.
msql_result() returns the contents of one cell from a mSQL result set. The field argument can be the field's offset, or the field's name, or the field's table dot field's name (fieldname.tablename). If the column name has been aliased ('select foo as bar from ...'), use the alias instead of the column name.
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they are often much quicker than msql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
Recommended high-performance alternatives: msql_fetch_row(), msql_fetch_array(), and msql_fetch_object().
For downward compatibility, the aliases named msql(), msql_tablename(), and msql_dbname() may be used. This, however, is deprecated and not recommended.
msql_select_db() sets the current active database on the server that's associated with the specified link_identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if msql_connect() was called, and use it.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Subsequent calls to msql_query() will be made on the active database.
For downward compatibility, the alias named msql_selectdb() may be used. This, however, is deprecated and not recommended.
See also msql_connect(), msql_pconnect(), and msql_query().
These functions allow you to access MySQL database servers. More information about MySQL can be found at http://www.mysql.com/.
Documentation for MySQL can be found at http://dev.mysql.com/doc/.
By using the --with-mysql[=DIR] configuration option you enable PHP to access MySQL databases.
In PHP 4, the option --with-mysql is enabled by default. To disable this default behavior, you may use the --without-mysql configure option. Also in PHP 4, if you enable MySQL without specifying the path to the MySQL install DIR, PHP will use the bundled MySQL client libraries. In Windows, there is no DLL, it's simply built into PHP 4. Users who run other applications that use MySQL (for example, auth-mysql) should not use the bundled library, but rather specify the path to MySQL's install directory, like so: --with-mysql=/path/to/mysql. This will force PHP to use the client libraries installed by MySQL, thus avoiding any conflicts.
In PHP 5, MySQL is no longer enabled by default, nor is the MySQL library bundled with PHP. Read this FAQ for details on why.
This MySQL extension doesn't support full functionality of MySQL versions greater than 4.1.0. For that, use MySQLi.
If you would like to install the mysql extension along with the mysqli extension you have to use the same client library to avoid any conflicts.
Ðñïåéäïðïßçóç |
Crashes and startup problems of PHP may be encountered when loading this extension in conjunction with the recode extension. See the recode extension for more information. |
Óçìåßùóç: If you need charsets other than latin (default), you have to install external (not bundled) libmysql with compiled charset support.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. MySQL Configuration Options
Name | Default | Changeable |
---|---|---|
mysql.allow_persistent | "On" | PHP_INI_SYSTEM |
mysql.max_persistent | "-1" | PHP_INI_SYSTEM |
mysql.max_links | "-1" | PHP_INI_SYSTEM |
mysql.default_port | NULL | PHP_INI_ALL |
mysql.default_socket | NULL | PHP_INI_ALL |
mysql.default_host | NULL | PHP_INI_ALL |
mysql.default_user | NULL | PHP_INI_ALL |
mysql.default_password | NULL | PHP_INI_ALL |
mysql.connect_timeout | "0" | PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to allow persistent connections to MySQL.
The maximum number of persistent MySQL connections per process.
The maximum number of MySQL connections per process, including persistent connections.
The default TCP port number to use when connecting to the database server if no other port is specified. If no default is specified, the port will be obtained from the MYSQL_TCP_PORT environment variable, the mysql-tcp entry in /etc/services or the compile-time MYSQL_PORT constant, in that order. Win32 will only use the MYSQL_PORT constant.
The default socket name to use when connecting to a local database server if no other socket name is specified.
The default server host to use when connecting to the database server if no other host is specified. Doesn't apply in safe mode.
The default user name to use when connecting to the database server if no other name is specified. Doesn't apply in safe mode.
The default password to use when connecting to the database server if no other password is specified. Doesn't apply in safe mode.
Connect timeout in seconds. On Linux this timeout is also used for waiting for the first answer from the server.
There are two resource types used in the MySQL module. The first one is the link identifier for a database connection, the second a resource which holds the result of a query.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Since PHP 4.3.0 it is possible to specify additional client flags for the mysql_connect() and mysql_pconnect() functions. The following constants are defined:
Ðßíáêáò 2. MySQL client constants
Constant | Description |
---|---|
MYSQL_CLIENT_COMPRESS | Use compression protocol |
MYSQL_CLIENT_IGNORE_SPACE | Allow space after function names |
MYSQL_CLIENT_INTERACTIVE | Allow interactive_timeout seconds (instead of wait_timeout) of inactivity before closing the connection. |
The function mysql_fetch_array() uses a constant for the different types of result arrays. The following constants are defined:
Ðßíáêáò 3. MySQL fetch constants
Constant | Description |
---|---|
MYSQL_ASSOC | Columns are returned into the array having the fieldname as the array index. |
MYSQL_BOTH | Columns are returned into the array having both a numerical index and the fieldname as the array index. |
MYSQL_NUM | Columns are returned into the array having a numerical index to the fields. This index starts with 0, the first field in the result. |
This simple example shows how to connect, execute a query, print resulting rows and disconnect from a MySQL database.
ÐáñÜäåéãìá 1. MySQL extension overview example
|
(PHP 3, PHP 4 , PHP 5)
mysql_affected_rows -- Get number of affected rows in previous MySQL operationmysql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query associated with link_identifier. If the link identifier isn't specified, the last link opened by mysql_connect() is assumed.
Óçìåßùóç: If you are using transactions, you need to call mysql_affected_rows() after your INSERT, UPDATE, or DELETE query, not after the commit.
If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero.
Óçìåßùóç: When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.
mysql_affected_rows() does not work with SELECT statements; only on statements which modify records. To retrieve the number of rows returned by a SELECT, use mysql_num_rows().
If the last query failed, this function will return -1.
ÐáñÜäåéãìá 1. Delete-Query
The above example would produce the following output:
|
ÐáñÜäåéãìá 2. Update-Query
The above example would produce the following output:
|
See also mysql_num_rows(), and mysql_info().
mysql_change_user() changes the logged in user of the current active connection, or the connection given by the optional link_identifier parameter. If a database is specified, this will be the current database after the user has been changed. If the new user and password authorization fails, the current connected user stays active. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function was introduced in PHP 3.0.13 and requires MySQL 3.23.3 or higher. It is not available in PHP 4.
mysql_client_encoding() returns the default character set name for the current connection.
See also mysql_real_escape_string()
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
mysql_close() closes the connection to the MySQL server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.
Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.
Óçìåßùóç: mysql_close() will not close persistent links created by mysql_pconnect().
See also mysql_connect() and mysql_pconnect().
Returns a MySQL link identifier on success, or FALSE on failure.
mysql_connect() establishes a connection to a MySQL server. The following defaults are assumed for missing optional parameters: server = 'localhost:3306', username = name of the user that owns the server process and password = empty password.
The server parameter can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost.
Óçìåßùóç: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as mysql.default_host in your PHP configuration and leave the server field blank.
Support for ":port" was added in PHP 3.0B4.
Support for ":/path/to/socket" was added in PHP 3.0.10.
You can suppress the error message on failure by prepending a @ to the function name.
If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. The client_flags parameter can be a combination of the constants MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE or MYSQL_CLIENT_INTERACTIVE.
Óçìåßùóç: The new_link parameter became available in PHP 4.2.0
The client_flags parameter became available in PHP 4.3.0
The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().
See also mysql_pconnect() and mysql_close().
mysql_create_db() attempts to create a new database on the server associated with the specified link identifier.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. MySQL create database example
|
For downwards compatibility mysql_createdb() can also be used. This is deprecated, however.
Óçìåßùóç: The function mysql_create_db() is deprecated. It is preferable to use mysql_query() to issue a SQL CREATE DATABASE Statement instead.
Ðñïåéäïðïßçóç |
This function will not be available if the MySQL extension was built against a MySQL 4.x client library. |
See also mysql_query().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
mysql_data_seek() moves the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number. The next call to mysql_fetch_row() would return that row.
Row_number starts at 0. The row_number should be a value in the range from 0 to mysql_num_rows - 1. However if the result set is empty (mysql_num_rows == 0), a seek to 0 will fail with a E_WARNING and mysql_data_seek() will return FALSE.
Óçìåßùóç: The function mysql_data_seek() can be used in conjunction only with mysql_query(), not with mysql_unbuffered_query().
ÐáñÜäåéãìá 1. mysql_data_seek() example
|
See also mysql_query() and mysql_num_rows().
mysql_db_name() takes as its first parameter the result pointer from a call to mysql_list_dbs(). The row parameter is an index into the result set.
If an error occurs, FALSE is returned. Use mysql_errno() and mysql_error() to determine the nature of the error.
For backward compatibility, mysql_dbname() is also accepted. This is deprecated, however.
Returns a positive MySQL result resource to the query result, or FALSE on error. The function also returns TRUE/FALSE for INSERT/UPDATE/DELETE queries to indicate success/failure.
mysql_db_query() selects a database and executes a query on it. If the optional link identifier isn't specified, the function will try to find an open link to the MySQL server and if no such link is found it'll try to create one as if mysql_connect() was called with no arguments.
Be aware that this function does NOT switch back to the database you were connected before. In other words, you can't use this function to temporarily run a sql query on another database, you would have to manually switch back. Users are strongly encouraged to use the database.table syntax in their sql queries instead of this function.
See also mysql_connect() and mysql_query().
Óçìåßùóç: This function has been deprecated since PHP 4.0.6. Do not use this function. Use mysql_select_db() and mysql_query() instead.
mysql_drop_db() attempts to drop (remove) an entire database from the server associated with the specified link identifier.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
For downward compatibility mysql_dropdb() can also be used. This is deprecated, however.
Óçìåßùóç: The function mysql_drop_db() is deprecated. It is preferable to use mysql_query() to issue a SQL DROP DATABASE statement instead.
Ðñïåéäïðïßçóç |
This function will not be available if the MySQL extension was built against a MySQL 4.x client library |
See also mysql_query().
(PHP 3, PHP 4 , PHP 5)
mysql_errno -- Returns the numerical value of the error message from previous MySQL operationReturns the error number from the last MySQL function, or 0 (zero) if no error occurred.
Errors coming back from the MySQL database backend no longer issue warnings. Instead, use mysql_errno() to retrieve the error code. Note that this function only returns the error code from the most recently executed MySQL function (not including mysql_error() and mysql_errno()), so if you want to use it, make sure you check the value before calling another MySQL function.
ÐáñÜäåéãìá 1. mysql_errno() example
The above example would produce the following output:
|
Óçìåßùóç: If the optional argument is specified the given link is used to retrieve the error code. If not, the last opened link is used.
See also mysql_error() and MySQL error codes.
(PHP 3, PHP 4 , PHP 5)
mysql_error -- Returns the text of the error message from previous MySQL operationReturns the error text from the last MySQL function, or '' (the empty string) if no error occurred. If no link is explicitly passed to the function, the last successful open link will be used to retrieve the error message from the MySQL server.
Errors coming back from the MySQL database backend no longer issue warnings. Instead, use mysql_error() to retrieve the error text. Note that this function only returns the error text from the most recently executed MySQL function (not including mysql_error() and mysql_errno()), so if you want to use it, make sure you check the value before calling another MySQL function.
ÐáñÜäåéãìá 1. mysql_error() example
The above example would produce the following output:
|
See also mysql_errno() and MySQL error messages.
This function will escape the unescaped_string, so that it is safe to place it in a mysql_query().
Óçìåßùóç: mysql_escape_string() does not escape % and _.
This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting.
See also mysql_real_escape_string(), addslashes() and the magic_quotes_gpc directive.
(PHP 3, PHP 4 , PHP 5)
mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both.Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
mysql_fetch_array() is an extended version of mysql_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must use the numeric index of the column or make an alias for the column. For aliased columns, you cannot access the contents with the original column name (by using 'field' in this example).
An important thing to note is that using mysql_fetch_array() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.
The optional second argument result_type in mysql_fetch_array() is a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH. This feature was added in PHP 3.0.7. MYSQL_BOTH is the default for this argument.
By using MYSQL_BOTH, you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
Óçìåßùóç: Field names returned by this function are case-sensitive.
ÐáñÜäåéãìá 2. mysql_fetch_array() with MYSQL_NUM
|
ÐáñÜäåéãìá 3. mysql_fetch_array() with MYSQL_ASSOC
|
ÐáñÜäåéãìá 4. mysql_fetch_array() with MYSQL_BOTH
|
See also mysql_fetch_row() and mysql_fetch_assoc().
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows.
mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC for the optional second parameter. It only returns an associative array. This is the way mysql_fetch_array() originally worked. If you need the numeric indices as well as the associative, use mysql_fetch_array().
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indices by using mysql_fetch_row() or add alias names. See the example at the mysql_fetch_array() description about aliases.
An important thing to note is that using mysql_fetch_assoc() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.
Óçìåßùóç: Field names returned by this function are case-sensitive.
ÐáñÜäåéãìá 1. An expanded mysql_fetch_assoc() example
|
See also mysql_fetch_row(), mysql_fetch_array(), mysql_query() and mysql_error().
(PHP 3, PHP 4 , PHP 5)
mysql_fetch_field -- Get column information from a result and return as an objectReturns an object containing field information.
mysql_fetch_field() can be used in order to obtain information about fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by mysql_fetch_field() is retrieved.
The properties of the object are:
name - column name
table - name of the table the column belongs to
max_length - maximum length of the column
not_null - 1 if the column cannot be NULL
primary_key - 1 if the column is a primary key
unique_key - 1 if the column is a unique key
multiple_key - 1 if the column is a non-unique key
numeric - 1 if the column is numeric
blob - 1 if the column is a BLOB
type - the type of the column
unsigned - 1 if the column is unsigned
zerofill - 1 if the column is zero-filled
Óçìåßùóç: Field names returned by this function are case-sensitive.
ÐáñÜäåéãìá 1. mysql_fetch_field() example
|
See also mysql_field_seek().
Returns an array that corresponds to the lengths of each field in the last row fetched by mysql_fetch_row(), or FALSE on error.
mysql_fetch_lengths() stores the lengths of each result column in the last row returned by mysql_fetch_row(), mysql_fetch_array(), and mysql_fetch_object() in an array, starting at offset 0.
See also mysql_fetch_row().
Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.
mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
Óçìåßùóç: Field names returned by this function are case-sensitive.
<?php /* this is valid */ echo $row->field; /* this is invalid */ echo $row->0; ?> |
Speed-wise, the function is identical to mysql_fetch_array(), and almost as quick as mysql_fetch_row() (the difference is insignificant).
See also mysql_fetch_array(), mysql_fetch_assoc() and mysql_fetch_row().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
Subsequent call to mysql_fetch_row() would return the next row in the result set, or FALSE if there are no more rows.
See also mysql_fetch_array(), mysql_fetch_assoc(), mysql_fetch_object(), mysql_data_seek(), mysql_fetch_lengths() and mysql_result().
(PHP 3, PHP 4 , PHP 5)
mysql_field_flags -- Get the flags associated with the specified field in a resultmysql_field_flags() returns the field flags of the specified field. The flags are reported as a single word per flag separated by a single space, so that you can split the returned value using explode().
The following flags are reported, if your version of MySQL is current enough to support them: "not_null", "primary_key", "unique_key", "multiple_key", "blob", "unsigned", "zerofill", "binary", "enum", "auto_increment", "timestamp".
For downward compatibility mysql_fieldflags() can also be used. This is deprecated, however.
mysql_field_len() returns the length of the specified field.
For downward compatibility mysql_fieldlen() can also be used. This is deprecated, however.
mysql_field_name() returns the name of the specified field index. result must be a valid result identifier and field_index is the numerical offset of the field.
Óçìåßùóç: field_index starts at 0.
e.g. The index of the third field would actually be 2, the index of the fourth field would be 3 and so on.
Óçìåßùóç: Field names returned by this function are case-sensitive.
ÐáñÜäåéãìá 1. mysql_field_name() example
The above example would produce the following output:
|
For downwards compatibility mysql_fieldname() can also be used. This is deprecated, however.
Seeks to the specified field offset. If the next call to mysql_fetch_field() doesn't include a field offset, the field offset specified in mysql_field_seek() will be returned.
See also mysql_fetch_field().
Returns the name of the table that the specified field is in.
For downward compatibility mysql_fieldtable() can also be used. This is deprecated, however.
mysql_field_type() is similar to the mysql_field_name() function. The arguments are identical, but the field type is returned instead. The field type will be one of "int", "real", "string", "blob", and others as detailed in the MySQL documentation.
ÐáñÜäåéãìá 1. mysql_field_type() example
The above example would produce the following output:
|
For downward compatibility mysql_fieldtype() can also be used. This is deprecated, however.
mysql_free_result() will free all memory associated with the result identifier result.
mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
For downward compatibility mysql_freeresult() can also be used. This is deprecated, however.
mysql_get_client_info() returns a string that represents the client library version.
See also mysql_get_host_info(), mysql_get_proto_info() and mysql_get_server_info().
mysql_get_host_info() returns a string describing the type of connection in use for the connection link_identifier, including the server host name. If link_identifier is omitted, the last opened connection will be used.
ÐáñÜäåéãìá 1. mysql_get_host_info() example
The above example would produce the following output:
|
See also mysql_get_client_info(), mysql_get_proto_info() and mysql_get_server_info().
mysql_get_proto_info() returns the protocol version used by connection link_identifier. If link_identifier is omitted, the last opened connection will be used.
ÐáñÜäåéãìá 1. mysql_get_proto_info() example
The above example would produce the following output:
|
See also mysql_get_client_info(), mysql_get_host_info() and mysql_get_server_info().
mysql_get_server_info() returns the server version used by connection link_identifier. If link_identifier is omitted, the last opened connection will be used.
ÐáñÜäåéãìá 1. mysql_get_server_info() example
The above example would produce the following output:
|
See also mysql_get_client_info(), mysql_get_host_info() and mysql_get_proto_info().
mysql_info() returns detailed information about the last query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.
mysql_info() returns a string for all statements listed below. For everything else, it returns FALSE. The string format depends on the given statement.
ÐáñÜäåéãìá 1. Relevant MySQL Statements
|
Óçìåßùóç: mysql_info() returns a non-FALSE value for the INSERT ... VALUES statement only if multiple value lists are specified in the statement.
See also mysql_affected_rows().
mysql_insert_id() returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.
mysql_insert_id() returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call mysql_insert_id() immediately after the query that generates the value.
Óçìåßùóç: The value of the MySQL SQL function LAST_INSERT_ID() always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries.
Ðñïåéäïðïßçóç |
mysql_insert_id() converts the return type of the native MySQL C API function mysql_insert_id() to a type of long (named int in PHP). If your AUTO_INCREMENT column has a column type of BIGINT, the value returned by mysql_insert_id() will be incorrect. Instead, use the internal MySQL SQL function LAST_INSERT_ID() in an SQL query. |
ÐáñÜäåéãìá 1. mysql_insert_id() example
|
See also mysql_query().
mysql_list_dbs() will return a result pointer containing the databases available from the current mysql daemon. Use the mysql_tablename() function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array().
ÐáñÜäåéãìá 1. mysql_list_dbs() example
The above example would produce the following output:
|
Óçìåßùóç: The above code would just as easily work with mysql_fetch_row() or other similar functions.
For downward compatibility mysql_listdbs() can also be used. This is deprecated however.
See also mysql_db_name().
mysql_list_fields() retrieves information about the given table name. Arguments are the database and the table name. A result pointer is returned which can be used with mysql_field_flags(), mysql_field_len(), mysql_field_name(), and mysql_field_type().
ÐáñÜäåéãìá 1. mysql_list_fields() example
The above example would produce the following output:
|
For downward compatibility mysql_listfields() can also be used. This is deprecated however.
Óçìåßùóç: The function mysql_list_fields() is deprecated. It is preferable to use mysql_query() to issue a SQL SHOW COLUMNS FROM table [LIKE 'name'] Statement instead.
mysql_list_processes() returns a result pointer describing the current server threads.
ÐáñÜäåéãìá 1. mysql_list_processes() example
The above example would produce the following output:
|
See also mysql_thread_id().
mysql_list_tables() takes a database name and returns a result pointer much like the mysql_query() function. Use the mysql_tablename() function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array().
The database parameter is the name of the database to retrieve the list of tables from. Upon failure, mysql_list_tables() returns FALSE.
For downward compatibility, the function alias named mysql_listtables() can be used. This is deprecated however and is not recommended.
Óçìåßùóç: The function mysql_list_tables() is deprecated. It is preferable to use mysql_query() to issue a SQL SHOW TABLES [FROM db_name] [LIKE 'pattern'] statement instead.
ÐáñÜäåéãìá 1. mysql_list_tables() example
|
See also mysql_list_dbs() and mysql_tablename().
mysql_num_fields() returns the number of fields in the result set result.
See also mysql_select_db(), mysql_query(), mysql_fetch_field() and mysql_num_rows().
For downward compatibility mysql_numfields() can also be used. This is deprecated however.
mysql_num_rows() returns the number of rows in a result set. This command is only valid for SELECT statements. To retrieve the number of rows affected by a INSERT, UPDATE or DELETE query, use mysql_affected_rows().
Óçìåßùóç: If you use mysql_unbuffered_query(), mysql_num_rows() will not return the correct value until all the rows in the result set have been retrieved.
See also mysql_affected_rows(), mysql_connect(), mysql_data_seek(), mysql_select_db() and mysql_query().
For downward compatibility mysql_numrows() can also be used. This is deprecated however.
Returns a positive MySQL persistent link identifier on success, or FALSE on error.
mysql_pconnect() establishes a connection to a MySQL server. The following defaults are assumed for missing optional parameters: server = 'localhost:3306', username = name of the user that owns the server process and password = empty password. The client_flags parameter can be a combination of the constants MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE or MYSQL_CLIENT_INTERACTIVE.
The server parameter can also include a port number. e.g. "hostname:port" or a path to a socket e.g. ":/path/to/socket" for the localhost.
Óçìåßùóç: Support for ":port" was added in 3.0B4.
Support for the ":/path/to/socket" was added in 3.0.10.
mysql_pconnect() acts very much like mysql_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).
The optional client_flags parameter became available in PHP 4.3.0.
This type of link is therefore called 'persistent'.
Óçìåßùóç: Note, that these kind of links only work if you are using a module version of PHP. See the Persistent Database Connections section for more information.
Ðñïåéäïðïßçóç |
Using persistent connections can require a bit of tuning of your Apache and MySQL configurations to ensure that you do not exceed the number of connections allowed by MySQL. |
(PHP 4 >= 4.3.0, PHP 5)
mysql_ping -- Ping a server connection or reconnect if there is no connectionmysql_ping() checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted. This function can be used by scripts that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary. mysql_ping() returns TRUE if the connection to the server is working, otherwise FALSE.
See also mysql_thread_id() and mysql_list_processes().
mysql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if mysql_connect() was called with no arguments, and use it. The result of the query is buffered.
Óçìåßùóç: The query string should not end with a semicolon.
Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier or FALSE if the query was not executed correctly. For other type of SQL statements, mysql_query() returns TRUE on success and FALSE on error. A non-FALSE return value means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly possible for a query to succeed but affect no rows or return no rows.
The following query is syntactically invalid, so mysql_query() fails and returns FALSE:
The following query is semantically invalid if my_col is not a column in the table my_tbl, so mysql_query() fails and returns FALSE:
mysql_query() will also fail and return FALSE if you don't have permission to access the table(s) referenced by the query.
Assuming the query succeeds, you can call mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.
Only for SELECT,SHOW,DESCRIBE or EXPLAIN statements, mysql_query() returns a new result identifier that you can pass to mysql_fetch_array() and other functions dealing with result tables. When you are done with the result set, you can free the resources associated with it by calling mysql_free_result(). Although, the memory will automatically be freed at the end of the script's execution.
See also mysql_num_rows(), mysql_affected_rows(), mysql_unbuffered_query(), mysql_free_result(), mysql_fetch_array(), mysql_fetch_row(), mysql_fetch_assoc(), mysql_result(), mysql_select_db() and mysql_connect().
(PHP 4 >= 4.3.0, PHP 5)
mysql_real_escape_string -- Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection.This function will escape special characters in the unescaped_string, taking into account the current charset of the connection so that it is safe to place it in a mysql_query().
Óçìåßùóç: mysql_real_escape_string() does not escape % and _.
ÐáñÜäåéãìá 1. mysql_real_escape_string() example
The above example would produce the following output:
|
See also mysql_escape_string() and mysql_client_encoding().
mysql_result() returns the contents of one cell from a MySQL result set. The field argument can be the field's offset, or the field's name, or the field's table dot field name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name.
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
Calls to mysql_result() should not be mixed with calls to other functions that deal with the result set.
ÐáñÜäåéãìá 1. mysql_result() example
|
Recommended high-performance alternatives : mysql_fetch_row(), mysql_fetch_array(), mysql_fetch_assoc() and mysql_fetch_object().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
mysql_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if mysql_connect() was called without arguments, and use it.
Every subsequent call to mysql_query() will be made on the active database.
ÐáñÜäåéãìá 1. mysql_select_db() example
|
See also mysql_connect(), mysql_pconnect() and mysql_query().
For downward compatibility mysql_selectdb() can also be used. This is deprecated however.
mysql_stat() returns the current server status.
Óçìåßùóç: mysql_stat() currently only returns status for uptime, threads, queries, open tables, flush tables and queries per second. For a complete list of other status variables you have to use the SHOW STATUS SQL command.
ÐáñÜäåéãìá 1. mysql_stat() example
The above example would produce the following output:
|
mysql_tablename() takes a result pointer returned by the mysql_list_tables() function as well as an integer index and returns the name of a table. The mysql_num_rows() function may be used to determine the number of tables in the result pointer. Use the mysql_tablename() function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array().
See also mysql_list_tables().
mysql_thread_id() returns the current thread ID. If the connection is lost and you reconnect with mysql_ping(), the thread ID will change. This means you should not get the thread ID and store it for later. You should get it when you need it.
See also mysql_ping() and mysql_list_processes().
(PHP 4 >= 4.0.6, PHP 5)
mysql_unbuffered_query -- Send an SQL query to MySQL, without fetching and buffering the result rowsmysql_unbuffered_query() sends a SQL query query to MySQL, without fetching and buffering the result rows automatically, as mysql_query() does. On the one hand, this saves a considerable amount of memory with SQL queries that produce large result sets. On the other hand, you can start working on the result set immediately after the first row has been retrieved: you don't have to wait until the complete SQL query has been performed. When using multiple DB-connects, you have to specify the optional parameter link_identifier.
Óçìåßùóç: The benefits of mysql_unbuffered_query() come at a cost: You cannot use mysql_num_rows() and mysql_data_seek() on a result set returned from mysql_unbuffered_query(). You also have to fetch all result rows from an unbuffered SQL query, before you can send a new SQL query to MySQL.
See also mysql_query().
The mysqli extension allows you to access the functionality provided by MySQL 4.1 and above. More information about the MySQL Database server can be found at http://www.mysql.com/
Documentation for MySQL can be found at http://dev.mysql.com/doc/.
Parts of this documentation included from MySQL manual with permissions of MySQL AB.
In order to have these functions available, you must compile PHP with support for the mysqli extension.
Óçìåßùóç: The mysqli extension is designed to work with the version 4.1.2 or above of MySQL. For previous versions, please see the MySQL extension documentation.
To install the mysqli extension for PHP, use the --with-mysqli=mysql_config_path/mysql_config configuration option where mysql_config_path represents the location of the mysql_config program that comes with MySQL versions greater than 4.1.
If you would like to install the mysql extension along with the mysqli extension you have to use the same client library to avoid any conflicts.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. MySQLi Configuration Options
Name | Default | Changeable |
---|---|---|
mysqli.max_links | "-1" | PHP_INI_SYSTEM |
mysqli.default_port | NULL | PHP_INI_ALL |
mysqli.default_socket | NULL | PHP_INI_ALL |
mysqli.default_host | NULL | PHP_INI_ALL |
mysqli.default_user | NULL | PHP_INI_ALL |
mysqli.default_pw | NULL | PHP_INI_ALL |
For further details and definitions of the above PHP_INI_* constants, see the chapter on configuration changes.
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
The maximum number of MySQL connections per process.
The default TCP port number to use when connecting to the database server if no other port is specified. If no default is specified, the port will be obtained from the MYSQL_TCP_PORT environment variable, the mysql-tcp entry in /etc/services or the compile-time MYSQL_PORT constant, in that order. Win32 will only use the MYSQL_PORT constant.
The default socket name to use when connecting to a local database server if no other socket name is specified.
The default server host to use when connecting to the database server if no other host is specified. Doesn't apply in safe mode.
The default user name to use when connecting to the database server if no other name is specified. Doesn't apply in safe mode.
The default password to use when connecting to the database server if no other password is specified. Doesn't apply in safe mode.
Represents a connection between PHP and a MySQL database.
autocommit() - turns on or off auto-commiting database modifications
change_user() - changes the user of the specified database connection
character_set_name - returns the default character set for the database connection
close - closes a previously opened connection
commit - commits the current transaction
connect - opens a new connection to MySQL database server
debug - performs debugging operations
dump_debug_info - dumps debug information
get_client_info - returns client version
get_host_info - returns type of connection used
get_server_info - returns version of the MySQL server
get_server_version - returns version of the MySQL server
init - initializes mysqli object
info - retrieves information about the most recently executed query
kill - asks the server to kill a mysql thread
multi_query - performs multiple queries
more_results - check if more results exists from currently executed multi-query
next_result - reads next result from currently executed multi-query
options - set options
ping - pings a server connection or reconnects if there is no connection
prepare - prepares a SQL query
query - performs a query
real_connect - attempts to open a connection to MySQL database server
escape_string - Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection
rollback - rolls back the current transaction
select_db - selects the default database
ssl_set - sets ssl parameters
stat - gets the current system status
stmt_initInitializes a statement for use with mysqli_stmt_prepare
store_result - transfers a resultset from last query
use_result - transfers an unbuffered resultset from last query
thread-safe - returns whether thread safety is given or not
affected_rows - gets the number of affected rows in a previous MySQL operation
errno - returns the error code for the most recent function call
error - returns the error string for the most recent function call
field_count - returns the number of columns for the most recent query
host_info - returns a string representing the type of connection used
info - retrieves information about the most recently executed query
insert-id - returns the auto generated id used in the last query
protocol_version - returns the version of the MySQL protocol used
sqlstate - returns a string containing the SQLSTATE error code for the last error
thread_id - returns the thread ID for the current connection
warning-count - returns the number of warnings generated during execution of the previous SQL statement
Represents a prepared statement.
bind_param - Binds variables to a prepared statement
bind_result - Binds variables to a prepared statement for result storage
close - Closes a prepared statement
data-seek - Seeks to an arbitrary row in a statement result set
execute - Executes a prepared statement
fetch - Fetches result from a prepared statement into bound variables
free_result - Frees stored result memory for the given statement handle
result_metadata - Retrieves a resultset from a prepared statement for metadata information
prepare - prepares a SQL query
send_long_data - Sends data in chunks
store_result - Buffers complete resultset from a prepared statement
affected_rows - Returns affected rows from last statement execution
errno - Returns errorcode for last statement function
errno - Returns errormessage for last statement function
param_count - Returns number of parameter for a given prepare statement
sqlstate - returns a string containing the SQLSTATE error code for the last statement function
Represents the result set obtained from a query against the database.
close - closes resultset
data_seek - moves internal result pointer
fetch_field - gets column information from a resultset
fetch_fields - gets information for all columns from a resulset
fetch_field_direct - gets column information for specified column
fetch_array - fetches a result row as an associative array, a numeric array, or both.
fetch_assoc - fetches a result row as an associative array
fetch_object - fetches a result row as an object
fetch_row - gets a result row as an enumerated array
close - frees result memory
field_seek - set result pointer to a specified field offset
current_field - returns offset of current fieldpointer
field_count - returns number of fields in resultset
lengths - returns an array of columnlengths
num_rows - returns number of rows in resultset
Ðßíáêáò 2. MySQLi Constants
Name | Description |
---|---|
MYSQLI_READ_DEFAULT_GROUP (integer) | Read options from the named group from `my.cnf' or the file specified with MYSQLI_READ_DEFAULT_FILE |
MYSQLI_READ_DEFAULT_FILE (integer) | Read options from the named option file instead of from my.cnf |
MYSQLI_OPT_CONNECT_TIMEOUT (integer) | Connect timeout in seconds |
MYSQLI_OPT_LOCAL_INFILE (integer) | Enables command LOAD LOCAL INFILE |
MYSQLI_INIT_COMMAND (integer) | Command to execute when connecting to MySQL server. Will automatically be re-executed when reconnecting. |
MYSQLI_CLIENT_SSL (integer) | Use SSL (encrypted protocol). This option should not be set by application programs; it is set internally in the MySQL client library |
MYSQLI_CLIENT_COMPRESS (integer) | Use compression protocol |
MYSQLI_CLIENT_INTERACTIVE (integer) | Allow interactive_timeout seconds (instead of wait_timeout seconds) of inactivity before closing the connection. The client's session wait_timeout variable will be set to the value of the session interactive_timeout variable. |
MYSQLI_CLIENT_IGNORE_SPACE (integer) | Allow spaces after function names. Makes all functions names reserved words. |
MYSQLI_CLIENT_NO_SCHEMA (integer) | Don't allow the db_name.tbl_name.col_name syntax. |
MYSQLI_CLIENT_MULTI_QUERIES (integer) | |
MYSQLI_STORE_RESULT (integer) | For using buffered resultsets |
MYSQLI_USE_RESULT (integer) | For using unbuffered resultsets |
MYSQLI_ASSOC (integer) | Columns are returned into the array having the fieldname as the array index. |
MYSQLI_NUM (integer) | Columns are returned into the array having an enumerated index. |
MYSQLI_BOTH (integer) | Columns are returned into the array having both a numerical index and the fieldname as the associative index. |
MYSQLI_NOT_NULL_FLAG (integer) | Indicates that a field is defined as NOT NULL |
MYSQLI_PRI_KEY_FLAG (integer) | Field is part of a primary index |
MYSQLI_UNIQUE_KEY_FLAG (integer) | Field is part of an unique index. |
MYSQLI_MULTIPLE_KEY_FLAG (integer) | Field is part of an index. |
MYSQLI_BLOB_FLAG (integer) | Field is defined as BLOB |
MYSQLI_UNSIGNED_FLAG (integer) | Field is defined as UNSIGNED |
MYSQLI_ZEROFILL_FLAG (integer) | Field is defined as ZEROFILL |
MYSQLI_AUTO_INCREMENT_FLAG (integer) | Field is defined as AUTO_INCREMENT |
MYSQLI_TIMESTAMP_FLAG (integer) | Field is defined as TIMESTAMP |
MYSQLI_SET_FLAG (integer) | Field is defined as SET |
MYSQLI_NUM_FLAG (integer) | Field is defined as NUMERIC |
MYSQLI_PART_KEY_FLAG (integer) | Field is part of an multi-index |
MYSQLI_GROUP_FLAG (integer) | Field is part of GROUP BY |
MYSQLI_TYPE_DECIMAL (integer) | Field is defined as DECIMAL |
MYSQLI_TYPE_TINY (integer) | Field is defined as TINYINT |
MYSQLI_TYPE_SHORT (integer) | Field is defined as INT |
MYSQLI_TYPE_LONG (integer) | Field is defined as INT |
MYSQLI_TYPE_FLOAT (integer) | Field is defined as FLOAT |
MYSQLI_TYPE_DOUBLE (integer) | Field is defined as DOUBLE |
MYSQLI_TYPE_NULL (integer) | Field is defined as DEFAULT NULL |
MYSQLI_TYPE_TIMESTAMP (integer) | Field is defined as TIMESTAMP |
MYSQLI_TYPE_LONGLONG (integer) | Field is defined as BIGINT |
MYSQLI_TYPE_INT24 (integer) | Field is defined as MEDIUMINT |
MYSQLI_TYPE_DATE (integer) | Field is defined as DATE |
MYSQLI_TYPE_TIME (integer) | Field is defined as TIME |
MYSQLI_TYPE_DATETIME (integer) | Field is defined as DATETIME |
MYSQLI_TYPE_YEAR (integer) | Field is defined as YEAR |
MYSQLI_TYPE_NEWDATE (integer) | Field is defined as DATE |
MYSQLI_TYPE_ENUM (integer) | Field is defined as ENUM |
MYSQLI_TYPE_SET (integer) | Field is defined as SET |
MYSQLI_TYPE_TINY_BLOB (integer) | Field is defined as TINYBLOB |
MYSQLI_TYPE_MEDIUM_BLOB (integer) | Field is defined as MEDIUMBLOB |
MYSQLI_TYPE_LONG_BLOB (integer) | Field is defined as LONGBLOB |
MYSQLI_TYPE_BLOB (integer) | Field is defined as BLOB |
MYSQLI_TYPE_STRING (integer) | Field is defined as VARCHAR |
MYSQLI_TYPE_CHAR (integer) | Field is defined as CHAR |
MYSQLI_TYPE_GEOMETRY (integer) | Field is defined as GEOMETRY |
MYSQLI_NEED_DATA (integer) | More data available for bind variable |
MYSQLI_NO_DATA (integer) | No more data available for bind variable |
All Examples in the MySQLI documentation use the world database from MySQL AB. The world database can be found at http://www.mysql.com/get/Downloads/Manual/world.sql.gz/from/pick
(PHP 5)
mysqli_affected_rows(no version information, might be only in CVS)
mysqli->affected_rows -- Gets the number of affected rows in a previous MySQL operationProcedural style:
mixed mysqli_affected_rows ( object link)Object oriented style (property):
class mysqli {mysqli_affected_rows() returns the number of rows affected by the last INSERT, UPDATE, or DELETE query associated with the provided link parameter. If the last query was invalid, this function will return -1.
Óçìåßùóç: For SELECT statements mysqli_affected_rows() works like mysqli_num_rows().
The mysqli_affected_rows() function only works with queries which modify a table. In order to return the number of rows from a SELECT query, use the mysqli_num_rows() function instead.
An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records where updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error.
Óçìåßùóç: If the number of affected rows is greater than maximal int value, the number of affected rows will be returned as a string.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Affected rows (INSERT): 984 Affected rows (UPDATE): 168 Affected rows (DELETE): 815 Affected rows (SELECT): 169 |
(PHP 5)
mysqli_autocommit(no version information, might be only in CVS)
mysqli->auto_commit -- Turns on or off auto-commiting database modificationsProcedural style:
bool mysqli_autocommit ( object link, bool mode)Object oriented style (method)
class mysqli {mysqli_autocommit() is used to turn on or off auto-commit mode on queries for the database connection represented by the link object.
Óçìåßùóç: mysqli_autocommit() doesn't work with non transactional table types (like MyISAM or ISAM).
To determine the current state of autocommit use the SQL command 'SELECT @@autocommit'.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Autocommit is 1 |
This function is an alias of mysqli_stmt_bind_param(). For a detailled descripton see description of mysqli_stmt_bind_param().
Óçìåßùóç: mysqli_bind_param() is deprecated and will be removed.
This function is an alias of mysqli_stmt_bind_result(). For a detailled descripton see description of mysqli_stmt_bind_result().
Óçìåßùóç: mysqli_bind_result() is deprecated and will be removed.
(PHP 5)
mysqli_change_user(no version information, might be only in CVS)
mysqli->change_user -- Changes the user of the specified database connectionProcedural style:
bool mysqli_change_user ( object link, string user, string password, string database)Object oriented style (method):
class mysqli {mysqli_change_user() is used to change the user of the specified database connection as given by the link parameter and to set the current database to that specified by the database parameter.
If desired, the NULL value may be passed in place of the database parameter resulting in only changing the user and not selecting a database. To select a database in this case use the mysqli_select_db() function.
In order to successfully change users a valid username and password parameters must be provided and that user must have sufficient permissions to access the desired database. If for any reason authorization fails, the current user authentication will remain.
Óçìåßùóç: Using this command will always cause the current database connection to behave as if was a completely new database connection, regardless of if the operation was completed successfully. This reset includes performing a rollback on any active transactions, closing all temporary tables, and unlocking all locked tables.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Default database: world Value of variable a is NULL |
(PHP 5)
mysqli_character_set_name(no version information, might be only in CVS)
mysqli->character_set_name -- Returns the default character set for the database connectionProcedural style:
string mysqli_character_set_name ( object link)Object oriented style (method):
class mysqli {Returns the current character set for the database connection specified by the link parameter.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would be produce the following output:
Current character set is latin1_swedish_ci |
This function is an alias of mysqli_character_set_name(). For a detailled descripton see description of mysqli_character_set_name().
(PHP 5)
mysqli_close(no version information, might be only in CVS)
mysqli->close -- Closes a previously opened database connectionProcedural style:
bool mysqli_close ( object link)Object oriented style (method):
class mysqli {The mysqli_close() function closes a previously opened database connection specified by the link parameter.
(PHP 5)
mysqli_commit(no version information, might be only in CVS)
mysqli->commit -- Commits the current transactionProcedural style:
bool mysqli_commit ( object link)Object oriented style (method)
class mysqli {Commits the current transaction for the database connection specified by the link parameter.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The mysqli_connect_errno() function will return the last error code number for last call to mysqli_connect(). If no errors have occured, this function will return zero.
Óçìåßùóç: Client error message numbers are listed in the MySQL errmsg.h header file, server error message numbers are listed in mysqld_error.h. In the MySQL source distribution you can find a complete list of error messages and error numbers in the file Docs/mysqld_error.txt.
An error code value for the last call to mysqli_connect(), if it failed. zero means no error occurred.
mysqli_connect(), mysqli_connect_error(), mysqli_errno(), mysqli_error(), mysqli_sqlstate()
The mysqli_connect_error() function is identical to the corresponding mysqli_connect_errno() function in every way, except instead of returning an integer error code the mysqli_connect_error() function will return a string representation of the last error to occur for the last mysqli_connect() call. If no error has occured, this function will return an empty string.
mysqli_connect(), mysqli_connect_errno(), mysqli_errno(), mysqli_error(), mysqli_sqlstate()
(PHP 5)
mysqli_connect(no version information, might be only in CVS)
mysqli() -- Open a new connection to the MySQL serverProcedural style
object mysqli_connect ( [string host [, string username [, string passwd [, string dbname [, int port [, string socket]]]]]])Object oriented style (constructor):
class mysqli {The mysqli_connect() function attempts to open a connection to the MySQL Server running on host which can be either a host name or an IP address. Passing the NULL value or the string "localhost" to this parameter, the local host is assumed. When possible, pipes will be used instead of the TCP/IP protocol. If successful, the mysqli_connect() will return an object representing the connection to the database, or FALSE on failure.
The username and password parameters specify the username and password under which to connect to the MySQL server. If the password is not provided (the NULL value is passed), the MySQL server will attempt to authenticate the user against those user records which have no password only. This allows one username to be used with different permissions (depending on if a password as provided or not).
The dbname parameter if provided will specify the default database to be used when performing queries.
The port and socket parameters are used in conjunction with the host parameter to further control how to connect to the database server. The port parameter specifies the port number to attempt to connect to the MySQL server on, while the socket parameter specifies the socket or named pipe that should be used.
Óçìåßùóç: Specifying the socket parameter will not explicitly determine the type of connection to be used when connecting to the MySQL server. How the connection is made to the MySQL database is determined by the host parameter.
Returns a object which represents the connection to a MySQL Server or FALSE if the connection failed.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Host information: Localhost via UNIX socket |
(PHP 5)
mysqli_data_seek(no version information, might be only in CVS)
result->data_seek -- Adjusts the result pointer to an arbitary row in the resultProcedural style:
bool mysqli_data_seek ( object result, int offset)Object oriented style (method):
class result {The mysqli_data_seek() function seeks to an arbitrary result pointer specified by the offset in the result set represented by result. The offset parameter must be between zero and the total number of rows minus one (0..mysqli_num_rows() - 1).
Óçìåßùóç: This function can only be used with unbuffered results attained from the use of the mysqli_store_result() or mysqli_query() functions.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
City: Benin City Countrycode: NGA |
The mysqli_debug() function is used to perform debugging operations using the Fred Fish debugging library. The debug parameter is a string representing the debugging operation to perform.
Óçìåßùóç: To use the mysqli_debug() function you must complile the MySQL client library to support debugging.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
(PHP 5)
mysqli_dump_debug_info(no version information, might be only in CVS)
mysqli->dump_debug_info -- Dump debugging information into the logThis function is designed to be executed by an user with the SUPER privlege and is used to dump debugging information into the log for the MySQL Server relating to the connection specified by the link parameter.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
(PHP 5)
mysqli_errno(no version information, might be only in CVS)
mysqli->errno -- Returns the error code for the most recent function callProcedural style:
int mysqli_errno ( object link)Object oriented style (property):
class mysqli {The mysqli_errno() function will return the last error code for the most recent MySQLi function call that can succeed or fail with respect to the database link defined by the link parameter. If no errors have occured, this function will return zero.
Óçìåßùóç: Client error message numbers are listed in the MySQL errmsg.h header file, server error message numbers are listed in mysqld_error.h. In the MySQL source distribution you can find a complete list of error messages and error numbers in the file Docs/mysqld_error.txt.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Errorcode: 1193 |
Procedural style:
string mysqli_error ( object link)Object oriented style (property)
class mysqli {The mysqli_error() function is identical to the corresponding mysqli_errno() function in every way, except instead of returning an integer error code the mysqli_error() function will return a string representation of the last error to occur for the database connection represented by the link parameter. If no error has occured, this function will return an empty string.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Errormessage: Unknown system variable 'a' |
This function is an alias of mysqli_stmt_execute(). For a detailled descripton see description of mysqli_stmt_execute().
Óçìåßùóç: mysqli_execute() is deprecated and will be removed.
(PHP 5)
mysqli_fetch_array(no version information, might be only in CVS)
result->fetch_array -- Fetch a result row as an associative, a numeric array, or both.Procedural style:
mixed mysqli_fetch_array ( object result [, int resulttype])Object oriend style (method):
class result {Returns an array that corresponds to the fetched row or NULL if there are no more rows for the resultset represented by the result parameter.
mysqli_fetch_array() is an extended version of the mysqli_fetch_row() function. In addition to storing the data in the numeric indices of the result array, the mysqli_fetch_array() function can also store the data in associative indices, using the field names of the result set as keys.
Óçìåßùóç: Field names returned by this function are case-sensitive.
If two or more columns of the result have the same field names, the last column will take precedence and overwrite the earlier data. In order to access multiple columns with the same name, the numerically indexed version of the row must be used.
The optional second argument resulttype is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH. By default the mysqli_fetch_array() function will assume MYSQLI_BOTH for this parameter.
By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function. The final option MYSQLI_BOTH will create a single array with the attributes of both.
Returns an array that corresponds to the fetched row or NULL if there are no more rows in resultset.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Kabul (AFG) Qandahar (AFG) Herat (AFG) |
(PHP 5)
mysqli_fetch_assoc(no version information, might be only in CVS)
mysqli->fetch_assoc -- Fetch a result row as an associative arrayProcedural style:
array mysqli_fetch_assoc ( object result)Object oriend style (method):
class result {Returns an associative array that corresponds to the fetched row or NULL if there are no more rows.
The mysqli_fetch_assoc() function is used to return an associative array representing the next row in the result set for the result represented by the result parameter, where each key in the array represents the name of one of the result set's columns.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indices by using mysqli_fetch_row() or add alias names.
Óçìåßùóç: Field names returned by this function are case-sensitive.
Returns an array that corresponds to the fetched row or NULL if there are no more rows in resultset.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Pueblo (USA) Arvada (USA) Cape Coral (USA) Green Bay (USA) Santa Clara (USA) |
(PHP 5)
mysqli_fetch_field_direct(no version information, might be only in CVS)
result->fetch_field_direct -- Fetch meta-data for a single fieldProcedural style:
mixed mysqli_fetch_field_direct ( object result, int fieldnr)Object oriented style (method):
class result {mysqli_fetch_field_direct() returns an object which contains field definition informations from specified resultset. The value of fieldnr must be in the range from 0 to number of fields - 1.
Returns an object which contains field definition informations or FALSE if no field information for specified fieldnr is available.
Ðßíáêáò 1. Object attributes
Attribute | Description |
---|---|
name | The name of the column |
orgname | Original column name if an alias was specified |
table | The name of the table this field belongs to (if not calculated) |
orgtable | Original table name if an alias was specified |
def | The default value for this field, represented as a string |
max_length | The maximum width of the field for the result set. |
flags | An integer representing the bit-flags for the field. |
type | The data type used for this field |
decimals | The number of decimals used (for integer fields) |
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4 |
(PHP 5)
mysqli_fetch_field(no version information, might be only in CVS)
result->fetch_field -- Returns the next field in the result setProcedural style:
mixed mysqli_fetch_field ( object result)Object oriented style (method):
class result {The mysqli_fetch_field() returns the definition of one column of a result set as an object. Call this function repeatedly to retrieve information about all columns in the result set. mysqli_fetch_field() returns FALSE when no more fields are left.
Returns an object which contains field definition informations or FALSE if no field information is available.
Ðßíáêáò 1. Object properties
Property | Description |
---|---|
name | The name of the column |
orgname | Original column name if an alias was specified |
table | The name of the table this field belongs to (if not calculated) |
orgtable | Original table name if an alias was specified |
def | The default value for this field, represented as a string |
max_length | The maximum width of the field for the result set. |
flags | An integer representing the bit-flags for the field. |
type | The data type used for this field |
decimals | The number of decimals used (for integer fields) |
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Name: Name Table: Country max. Len: 11 Flags: 1 Type: 254 Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4 |
(PHP 5)
mysqli_fetch_fields(no version information, might be only in CVS)
result->fetch_fields -- Returns an array of objects representing the fields in a result setProcedural Style:
mixed mysqli_fetch_fields ( object result)Object oriented style (method):
class result {This function serves an identical purpose to the mysqli_fetch_field() function with the single difference that, instead of returning one object at a time for each field, the columns are returned as an array of objects.
Returns an array of objects which contains field definition informations or FALSE if no field information is available.
Ðßíáêáò 1. Object properties
Property | Description |
---|---|
name | The name of the column |
orgname | Original column name if an alias was specified |
table | The name of the table this field belongs to (if not calculated) |
orgtable | Original table name if an alias was specified |
def | The default value for this field, represented as a string |
max_length | The maximum width of the field for the result set. |
flags | An integer representing the bit-flags for the field. |
type | The data type used for this field |
decimals | The number of decimals used (for integer fields) |
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Name: Name Table: Country max. Len: 11 Flags: 1 Type: 254 Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4 |
(PHP 5)
mysqli_fetch_lengths(no version information, might be only in CVS)
result->lengths -- Returns the lengths of the columns of the current row in the result setProcedural style:
mixed mysqli_fetch_lengths ( object result)Object oriented style (property):
class result {The mysqli_fetch_lengths() function returns an array containing the lengths of every column of the current row within the result set represented by the result parameter. If successful, a numerically indexed array representing the lengths of each column is returned or FALSE on failure.
An array of integers representing the size of each column (not including any terminating null characters). FALSE if an error occurred.
mysql_fetch_lengths() is valid only for the current row of the result set. It returns FALSE if you call it before calling mysql_fetch_row/array/object or after retrieving all rows in the result.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Field 1 has Length 3 Field 2 has Length 5 Field 3 has Length 13 Field 4 has Length 9 Field 5 has Length 6 Field 6 has Length 1 Field 7 has Length 6 Field 8 has Length 4 Field 9 has Length 6 Field 10 has Length 6 Field 11 has Length 5 Field 12 has Length 44 Field 13 has Length 7 Field 14 has Length 3 Field 15 has Length 2 |
(PHP 5)
mysqli_fetch_object(no version information, might be only in CVS)
result->fetch_object -- Returns the current row of a result set as an objectProcedural style:
mixed mysqli_fetch_object ( object result)Object oriented style (method):
class result {The mysqli_fetch_object() will return the current row result set as an object where the attributes of the object represent the names of the fields found within the result set. If no more rows exist in the current result set, NULL is returned.
Returns an object that corresponds to the fetched row or NULL if there are no more rows in resultset.
Óçìåßùóç: Field names returned by this function are case-sensitive.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Pueblo (USA) Arvada (USA) Cape Coral (USA) Green Bay (USA) Santa Clara (USA) |
(PHP 5)
mysqli_fetch_row(no version information, might be only in CVS)
result->fetch_row -- Get a result row as an enumerated arrayProcedural style:
mixed mysqli_fetch_row ( object result)Object oriented style (method):
class result {Returns an array that corresponds to the fetched row, or NULL if there are no more rows.
mysqli_fetch_row() fetches one row of data from the result set represented by result and returns it as an enumerated array, where each column is stored in an array offset starting from 0 (zero). Each subsequent call to the mysqli_fetch_row() function will return the next row within the result set, or FALSE if there are no more rows.
mysqli_fetch_row() returns an array that corresponds to the fetched row or NULL if there are no more rows in result set.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Pueblo (USA) Arvada (USA) Cape Coral (USA) Green Bay (USA) Santa Clara (USA) |
This function is an alias of mysqli_stmt_fetch(). For a detailled descripton see description of mysqli_stmt_fetch().
Óçìåßùóç: mysqli_fetch() is deprecated and will be removed.
(PHP 5)
mysqli_field_count(no version information, might be only in CVS)
mysqli->field_count -- Returns the number of columns for the most recent queryProcedural style:
int mysqli_field_count ( object link)Object oriented style (method):
class mysql {Returns the number of columns for the most recent query on the connection represented by the link parameter. This function can be useful when using the mysqli_store_result() function to determine if the query should have produced a non-empty result set or not without knowing the nature of the query.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
(PHP 5)
mysqli_field_seek(no version information, might be only in CVS)
result->field_seek -- Set result pointer to a specified field offsetProcedural style:
int mysqli_field_seek ( object result, int fieldnr)Object oriented style (method):
class result {Sets the field cursor to the given offset. The next call to mysqli_fetch_field() will retrieve the field definition of the column associated with that offset.
Óçìåßùóç: To seek to the beginning of a row, pass an offset value of zero.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4 |
(PHP 5)
mysqli_field_tell(no version information, might be only in CVS)
result->current_field -- Get current field offset of a result pointerProcedural style:
int mysqli_field_tell ( object result)Object oriented style (property):
class result {Returns the position of the field cursor used for the last mysqli_fetch_field() call. This value can be used as an argument to mysqli_field_seek().
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Column 1: Name: Name Table: Country max. Len: 11 Flags: 1 Type: 254 Column 2: Name: SurfaceArea Table: Country max. Len: 10 Flags: 32769 Type: 4 |
(PHP 5)
mysqli_free_result(no version information, might be only in CVS)
result->free -- Frees the memory associated with a resultProcedural style:
void mysqli_free_result ( object result)Object oriented style (method):
class result {The mysqli_free_result() function frees the memory associated with the result represented by the result parameter, which was allocated by mysqli_query(), mysqli_store_result() or mysqli_use_result().
Óçìåßùóç: You should always free your result with mysqli_free_result(), when your result object is not needed anymore.
mysqli_query(), mysqli_stmt_store_result(), mysqli_store_result(), mysqli_use_result().
The mysqli_get_client_info() function is used to return a string representing the client version being used in the MySQLi extension.
A number that represents the MySQL client library version in format: main_version*10000 + minor_version *100 + sub_version. For example, 4.1.0 is returned as 40100.
This is useful to quickly determine the version of the client library to know if some capability exits.
(PHP 5)
mysqli_get_host_info(no version information, might be only in CVS)
mysqli->get_host_info -- Returns a string representing the type of connection usedProcdural style:
string mysqli_get_host_info ( object link)Object oriented style (property):
class mysqli {The mysqli_get_host_info() function returns a string describing the connection represented by the link parameter is using (including the server host name).
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Host info: Localhost via UNIX socket |
This function is an alias of mysqli_stmt_result_metadata(). For a detailled descripton see description of mysqli_stmt_result_metadata().
Óçìåßùóç: mysqli_get_metadata() is deprecated and will be removed.
(PHP 5)
mysqli_get_proto_info(no version information, might be only in CVS)
mysqli->protocol_version -- Returns the version of the MySQL protocol usedProcedural style:
int mysqli_get_proto_info ( object link)Object oriented style (property):
class mysqli {Returns an integer representing the MySQL protocol version used by the connection represented by the link parameter.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Protocol version: 10 |
(PHP 5)
mysqli_get_server_info(no version information, might be only in CVS)
mysqli->server_info -- Returns the version of the MySQL serverProcedural style:
string mysqli_get_server_info ( object link)Object oriented style (property):
class mysqli {Returns a string representing the version of the MySQL server that the MySQLi extension is connected to (represented by the link parameter).
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Server version: 4.1.2-alpha-debug |
Procedural style:
int mysqli_get_server_version ( object link)Object oriented style (property):
class mysqli {The mysqli_get_server_version() function returns the version of the server connected to (represented by the link parameter) as an integer.
The form of this version number is main_version * 10000 + minor_version * 100 + sub_version (i.e. version 4.1.0 is 40100).
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Server version: 40102 |
(PHP 5)
mysqli_info(no version information, might be only in CVS)
mysqli->info -- Retrieves information about the most recently executed queryProcedural style:
string mysqli_info ( object link)Object oriented style (property)
class mysqli {The mysqli_info() function returns a string providing information about the last query executed. The nature of this string is provided below:
Ðßíáêáò 1. Possible mysqli_info return values
Query type | Example result string |
---|---|
INSERT INTO...SELECT... | Records: 100 Duplicates: 0 Warnings: 0 |
INSERT INTO...VALUES (...),(...),(...) | Records: 3 Duplicates: 0 Warnings: 0 |
LOAD DATA INFILE ... | Records: 1 Deleted: 0 Skipped: 0 Warnings: 0 |
ALTER TABLE ... | Records: 3 Duplicates: 0 Warnings: 0 |
UPDATE ... | Rows matched: 40 Changed: 40 Warnings: 0 |
Óçìåßùóç: Queries which do not fall into one of the above formats are not supported. In these situations, mysqli_info() will return an empty string.
A character string representing additional information about the most recently executed query.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Records: 150 Duplicates: 0 Warnings: 0 |
Allocates or initializes a MYSQL object suitable for mysqli_options() and mysqli_real_connect().
Óçìåßùóç: Any subsequent calls to any mysqli function (except mysqli_options()) will fail until mysqli_real_connect() was called.
(PHP 5)
mysqli_insert_id(no version information, might be only in CVS)
mysqli->insert_id -- Returns the auto generated id used in the last queryProcedural style:
mixed mysqli_insert_id ( object link)Object oriented style (property):
class mysqli {The mysqli_insert_id() function returns the ID generated by a query on a table with a column having the AUTO_INCREMENT attribute. If the last query wasn't an INSERT or UPDATE statement or if the modified table does not have a column with the AUTO_INCREMENT attribute, this function will return zero.
Óçìåßùóç: Performing an INSERT or UPDATE statement using the LAST_INSERT_ID() function will also modify the value returned by the mysqli_insert_id() function.
The value of the AUTO_INCREMENT field that was updated by the previous query. Returns zero if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value.
Óçìåßùóç: If the number is greater than maximal int value, mysqli_insert_id() will return a string.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
New Record has id 1. |
(PHP 5)
mysqli_kill(no version information, might be only in CVS)
mysqli->kill -- Asks the server to kill a MySQL threadProcedural style:
bool mysqli_kill ( object link, int processid)Object oriented style (method)
class mysqli {This function is used to ask the server to kill a MySQL thread specified by the processid parameter. This value must be retrieved by calling the mysqli_thread_id() function.
Óçìåßùóç: To stop a running query you should use the SQL command KILL QUERY processid.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Error: MySQL server has gone away |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
(PHP 5)
mysqli_more_results(no version information, might be only in CVS)
mysqli->more_results -- Check if there any more query results from a multi query.mysqli_more_results() indicates if one or more result sets are available from a previous call to mysqli_multi_query().
(PHP 5)
mysqli_multi_query(no version information, might be only in CVS)
mysqli->multi_query -- Performs a query on the databaseProcedural style:
bool mysqli_multi_query ( object link, string query)Object oriented style (method):
class mysqli {The mysqli_multi_query() executes one or multiple queries which are concatenated by a semicolon.
To retrieve the resultset from the first query you can use mysqli_use_result() or mysqli_store_result(). All subsequent query results can be processed using mysqli_more_results() and mysqli_next_result().
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
my_user@localhost ----------------- Amersfoort Maastricht Dordrecht Leiden Haarlemmermeer |
(PHP 5)
mysqli_next_result(no version information, might be only in CVS)
mysqli->next_result -- prepare next result from multi_query.mysqli_next_result() prepares next result set from a previous call to mysqli_multi_query() which can be retrieved by mysqli_store_result() or mysqli_use_result().
(PHP 5)
mysqli_num_fields(no version information, might be only in CVS)
result->field_count -- Get the number of fields in a resultProcedural style:
int mysqli_num_fields ( object result)Object oriented style (property):
class result {mysqli_num_fields() returns the number of fields from specified result set.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Result set has 5 fields. |
Procedural style:
mixed mysqli_num_rows ( object result)Object oriented style (property):
class mysqli {Returns the number of rows in the result set.
The use of mysqli_num_rows() depends on whether you use buffered or unbuffered result sets. In case you use unbuffered resultsets mysqli_num_rows() will not correct the correct number of rows until all the rows in the result have been retrieved.
Returns number of rows in the result set.
Óçìåßùóç: If the number of rows is greater than maximal int value, the number will be returned as a string.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Result set has 239 rows. |
Procedural style:
bool mysqli_options ( object link, int option, mixed value)Object oriented style (method)
class mysqli {mysqli_options() can be used to set extra connect options and affect behavior for a connection.
This function may be called multiple times to set several options.
mysqli_options() should be called after mysqli_init() and before mysqli_real_connect().
The parameter option is the option that you want to set, the value is the value for the option. The parameter option can be one of the following values:
Ðßíáêáò 1. Valid options
Name | Description |
---|---|
MYSQLI_OPT_CONNECT_TIMEOUT | connection timeout in seconds |
MYSQLI_OPT_COMPRESS | use compression protocol |
MYSQLI_OPT_LOCAL_INFILE | enable/disable use of LOAD LOCAL INFILE |
MYSQLI_INIT_CMD | command to execute after when connecting to MySQL server |
MYSQLI_READ_DEFAULT_FILE | Read options from named option file instead of my.cnf |
MYSQLI_READ_DEFAULT_GROUP | Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE. |
This function is an alias of mysqli_stmt_param_count(). For a detailled descripton see description of mysqli_stmt_param_count().
Óçìåßùóç: mysqli_param_count() is deprecated and will be removed.
(PHP 5)
mysqli_ping(no version information, might be only in CVS)
mysqli->ping -- Pings a server connection, or tries to reconnect if the connection has gone down.Procedural style:
bool mysqli_ping ( object link)Object oriented style (method):
class mysqli {Checks whether the connection to the server is working. If it has gone down, and global option mysqli.reconnect is enabled an automatic reconnection is attempted.
This function can be used by clients that remain idle for a long while, to check whether the server has closed the connection and reconnect if necessary.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Our connection is ok! |
(PHP 5)
mysqli_prepare(no version information, might be only in CVS)
mysqli->prepare -- Prepare a SQL statement for executionProcedure style:
mixed mysqli_prepare ( object link, string query)Object oriented style (method)
class stmt {mysqli_prepare() prepares the SQL query pointed to by the null-terminated string query, and returns a statement handle to be used for further operations on the statement. The query must consist of a single SQL statement.
Óçìåßùóç: You should not add a terminating semicolon or \g to the statement.
The parameter query can include one or more parameter markers in the SQL statement by embedding question mark (?) characters at the appropriate positions.
Óçìåßùóç: The markers are legal only in certain places in SQL statements. For example, they are allowed in the VALUES() list of an INSERT statement (to specify column values for a row), or in a comparison with a column in a WHERE clause to specify a comparison value.
However, they are not allowed for identifiers (such as table or column names), in the select list that names the columns to be returned by a SELECT statement), or to specify both operands of a binary operator such as the = equal sign. The latter restriction is necessary because it would be impossible to determine the parameter type. In general, parameters are legal only in Data Manipulation Languange (DML) statements, and not in Data Defination Language (DDL) statements.
The parameter markers must be bound to application variables using mysqli_stmt_bind_param() and/or mysqli_stmt_bind_result() before executing the statement or fetching rows.
mysqli_stmt_execute(), mysqli_stmt_fetch(), mysqli_stmt_bind_param(), mysqli_stmt_bind_result(), mysqli_stmt_close()
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Amersfoort is in district Utrecht |
(PHP 5)
mysqli_query(no version information, might be only in CVS)
mysqli->query -- Performs a query on the databaseProcedural style:
mixed mysqli_query ( object link, string query [, int resultmode])Object oriented style (method):
class mysqli {The mysqli_query() function is used to simplify the act of performing a query against the database represented by the link parameter.
Functionally, using this function is identical to calling mysqli_real_query() followed either by mysqli_use_result() or mysqli_store_result() where query is the query string itself and resultmode is either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, if the resultmode is not provided MYSQLI_STORE_RESULT is used.
If you execute mysqli_query() with resultmode MYSQLI_USE_RESULT all subsequent calls will return error Commands out of sync unless you call mysqli_free_result().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. For SELECT, SHOW, DESCRIBE or EXPLAIN mysqli_query() will return a result object.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Table myCity successfully created. Select returned 10 rows. Error: Commands out of sync; You can't run this command now |
(PHP 5)
mysqli_real_connect(no version information, might be only in CVS)
mysqli->real_connect -- Opens a connection to a mysql serverProcedural style
bool mysqli_real_connect ( object link [, string hostname [, string username [, string passwd [, string dbname [, int port [, string socket [, int flags]]]]]]])Object oriented style (method)
class mysqli {mysql_real_connect() attempts to establish a connection to a MySQL database engine running on host.
This function differs from mysqli_connect():
mysqli_real_connect() needs a valid object which has to be created by function mysqli_init()
With function mysqli_options() you can set various options for connection.
With the parameter flags you can set different connection options:
Ðßíáêáò 1. Supported flags
Name | Description |
---|---|
MYSQLI_CLIENT_COMPRESS | Use compression protocol |
MYSQLI_CLIENT_FOUND_ROWS | return number of matched rows, not the number of affected rows |
MYSQLI_CLIENT_IGNORE_SPACE | Allow spaces after function names. Makes all function names reserved words. |
MYSQLI_CLIENT_INTERACTIVE | Allow interactive_timeout seconds (instead of wait_timeout seconds) of inactivity before closing the connection |
MYSQLI_CLIENT_SSL | Use SSL (encryption) |
Óçìåßùóç: For security reasons the MULTI_STATEMENT flag is not supported in PHP. If you want to execute multiple queries use the mysqli_multi_query() function.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Connection: Localhost via UNIX socket |
(PHP 5)
mysqli_real_escape_string(no version information, might be only in CVS)
mysqli->real_escape_string -- Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connectionProcedural style:
string mysqli_real_escape_string ( object link, string escapestr)Object oriented style (method):
class mysqli {This function is used to create a legal SQL string that you can use in a SQL statement. The string escapestr is encoded to an escaped SQL string, taking into account the current character set of the connection.
Characters encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Error: 42000 1 Row inserted. |
(PHP 5)
mysqli_real_query(no version information, might be only in CVS)
mysqli->real_query -- Execute an SQL queryProcedural style
bool mysqli_real_query ( object link, string query)Object oriented style (method):
class mysqli {The mysqli_real_query() function is used to execute only a query against the database represented by the link whose result can then be retrieved or stored using the mysqli_store_result() or mysqli_use_result() functions.
Óçìåßùóç: In order to determine if a given query should return a result set or not, see mysqli_field_count().
mysqli_report() is a powerful function to improve your queries and code during development and testing phase. Depending on the flags it reports errors from mysqli function calls or queries which don't use an index (or use a bad index).
ÐáñÜäåéãìá 1. Object oriented style
|
(PHP 5)
mysqli_rollback(no version information, might be only in CVS)
mysqli->rollback -- Rolls back current transactionRollbacks the current transaction for the database specified by the link parameter.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
0 rows in table myCity. 50 rows in table myCity (after rollback). |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
(PHP 5)
mysqli_select_db(no version information, might be only in CVS)
mysqli->select_db -- Selects the default database for database queriesThe mysqli_select_db() function selects the default database (specified by the dbname parameter) to be used when performing queries against the database connection represented by the link parameter.
Óçìåßùóç: This function should only be used to change the default database for the connection. You can select the default database with 4th parameter in mysqli_connect().
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Default database is test. Default database is world. |
This function is an alias of mysqli_stmt_send_long_data(). For a detailled descripton see description of mysqli_stmt_send_long_data().
Óçìåßùóç: mysqli_send_long_data() is deprecated and will be removed.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
(PHP 5)
mysqli_sqlstate(no version information, might be only in CVS)
mysqli->sqlstate -- Returns the SQLSTATE error from previous MySQL operation.Procedural style:
string mysqli_sqlstate ( object link)Object oriented style (property):
class mysqli {Returns a string containing the SQLSTATE error code for the last error. The error code consists of five characters. '00000' means no error. The values are specified by ANSI SQL and ODBC. For a list of possible values, see http://dev.mysql.com/doc/mysql/en/Error-returns.html.
Óçìåßùóç: Note that not all MySQL errors are yet mapped to SQLSTATE's. The value HY000 (general error) is used for unmapped errors.
Returns a string containing the SQLSTATE error code for the last error. The error code consists of five characters. '00000' means no error.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Error - SQLSTATE 42S01. |
(PHP 5)
mysqli_ssl_set(no version information, might be only in CVS)
mysqli->ssl_set -- Used for establishing secure connections using SSL.Procedural style:
bool mysqli_ssl_set ( object link [, string key [, string cert [, string ca [, string capath [, string cipher]]]]])Object oriented style (method):
class mysqli {The function mysqli_ssl_set() is used for establishing secure connections using SSL. It must be called before mysqli_real_connect(). This function does nothing unless OpenSSL support is enabled.
key is the pathname to the key file. cert is the pathname to the certificate file. ca is the pathname to the certificate authority file. capath is the pathname to a directory that contains trusted SSL CA certificates in pem format. cipher is a list of allowable ciphers to use for SSL encryption. Any unused SSL parameters may be given as NULL
This function always returns TRUE value. If SSL setup is incorrect mysqli_real_connect() will return an error when you attempt to connect.
(PHP 5)
mysqli_stat(no version information, might be only in CVS)
mysqli->stat -- Gets the current system statusProcedural style:
mixed mysqli_stat ( object link)Object oriented style (method):
class mysqli {mysqli_stat() returns a string containing information similar to that provided by the 'mysqladmin status' command. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables.
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
System status: Uptime: 272 Threads: 1 Questions: 5340 Slow queries: 0 Opens: 13 Flush tables: 1 Open tables: 0 Queries per second avg: 19.632 Memory in use: 8496K Max memory used: 8560K |
(PHP 5)
mysqli_stmt_affected_rows(no version information, might be only in CVS)
mysqli_stmt->affected_rows -- Returns the total number of rows changed, deleted, or inserted by the last executed statementProcedural style :
mixed mysqli_stmt_affected_rows ( object stmt)Object oriented style (property):
class stmt {mysqli_stmt_affected_rows() returns the number of rows affected by INSERT, UPDATE, or DELETE query. If the last query was invalid, this function will return -1.
The mysqli_stmt_affected_rows() function only works with queries which update a table. In order to return the number of rows from a SELECT query, use the mysqli_stmt_num_rows() function instead.
An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records where updated for an UPDATE/DELETE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query has returned an error.
Óçìåßùóç: If the number of affected rows is greater than maximal PHP int value, the number of affected rows will be returned as a string value.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
rows inserted: 17 |
(PHP 5)
mysqli_stmt_bind_param(no version information, might be only in CVS)
stmt->bind_param -- Binds variables to a prepared statement as parametersProcedural style:
bool mysqli_stmt_bind_param ( object stmt, string types, mixed var1 [, mixed var2, ...])Object oriented style (method):
class stmt {mysqli_stmt_bind_param() is used to bind variables for the parameter markers in the SQL statement that was passed to mysql_prepare(). The string types contains one or more characters which specify the types for the corresponding bind variables
Ðßíáêáò 1. Type specification chars
Character | Description |
---|---|
i | corresponding variable has type integer |
d | corresponding variable has type double |
s | corresponding variable has type string |
b | corresponding variable is a blob and will be send in packages |
Óçìåßùóç: If data size of a variable exceeds max. allowed package size (max_allowed_package), you have to specify b in types and use mysqli_stmt_send_long_data() to send the data in packages.
The number of variables and length of string types must match the parameters in the statement.
mysqli_stmt_bind_result(), mysqli_stmt_execute(), mysqli_stmt_fetch(), mysqli_prepare(), mysqli_stmt_send_long_data(), mysqli_stmt_errno(), mysqli_stmt_error()
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
1 Row inserted. 1 Row deleted. |
(PHP 5)
mysqli_stmt_bind_result(no version information, might be only in CVS)
stmt->bind_result -- Binds variables to a prepared statement for result storageProcedural style:
bool mysqli_stnt_bind_result ( object stmt, mixed var1 [, mixed var2, ...])Object oriented style (method):
class stmt {mysqli_stmt_bind_result() is used to associate (bind) columns in the result set to variables. When mysqli_stmt_fetch() is called to fetch data, the MySQL client/server protocol places the data for the bound columns into the specified variables var1, ....
Óçìåßùóç: Note that all columns must be bound prior to calling mysqli_stmt_fetch(). Depending on column types bound variables can silently change to the corresponding PHP type.
A column can be bound or rebound at any time, even after a result set has been partially retrieved. The new binding takes effect the next time mysqli_stmt_fetch() is called.
mysqli_stmt_bind_param(), mysqli_stmt_execute(), mysqli_stmt_fetch(), mysqli_prepare(), mysqli_stmt_prepare(), mysqli_stmt_init(), mysqli_stmt_errno(), mysqli_stmt_error()
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
AFG Afghanistan ALB Albania DZA Algeria ASM American Samoa AND Andorra |
(PHP 5)
mysqli_stmt_close(no version information, might be only in CVS)
mysqli_stmt->close -- Closes a prepared statementProcedural style:
bool mysqli_stmt_close ( object stmt)Object oriented style (method):
class mysqli_stmt {Closes a prepared statement. mysql_stmt_close() also deallocates the statement handle pointed to by stmt. If the current statement has pending or unread results, this function cancels them so that the next query can be executed.
(PHP 5)
mysqli_stmt_data_seek(no version information, might be only in CVS)
stmt->data_seek -- Seeks to an arbitray row in statement result setProcedural style:
bool mysqli_stmt_data_seek ( object statement, int offset)Object oriented style (method):
class stmt {The mysqli_stmt_data_seek() function seeks to an arbitrary result pointer specified by the offset in the statement result set represented by statement. The offset parameter must be between zero and the total number of rows minus one (0..mysqli_stmt_num_rows() - 1).
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
City: Benin City Countrycode: NGA |
(PHP 5)
mysqli_stmt_errno(no version information, might be only in CVS)
mysqli_stmt->errno -- Returns the error code for the most recent statement callProcedural style :
int mysqli_stmt_errno ( object stmt)Object oriented style (property):
class stmt {For the statement specified by stmt, mysqli_stmt_errno() returns the error code for the most recently invoked statement function that can succeed or fail.
Óçìåßùóç: Client error message numbers are listed in the MySQL errmsg.h header file, server error message numbers are listed in mysqld_error.h. In the MySQL source distribution you can find a complete list of error messages and error numbers in the file Docs/mysqld_error.txt.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Error: 1146. |
(PHP 5)
mysqli_stmt_error(no version information, might be only in CVS)
mysqli_stmt->error -- Returns a string description for last statement errorProcedural style:
string mysqli_stmt_error ( object stmt)Object oriented style (property):
class stmt {For the statement specified by stmt, mysql_stmt_error() returns a containing the error message for the most recently invoked statement function that can succeed or fail.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Error: Table 'world.myCountry' doesn't exist. |
(PHP 5)
mysqli_stmt_execute(no version information, might be only in CVS)
stmt->execute -- Executes a prepared QueryProcedural style:
bool mysqli_stmt_execute ( object stmt)Object oriented style (method):
class mysql {The mysqli_stmt_execute() function executes a query that has been previously prepared using the mysqli_prepare() function represented by the stmt object. When executed any parameter markers which exist will automatically be replaced with the appropiate data.
If the statement is UPDATE, DELETE, or INSERT, the total number of affected rows can be determined by using the mysqli_stmt_affected_rows() function. Likewise, if the query yields a result set the mysqli_fetch() function is used.
Óçìåßùóç: When using mysqli_stmt_execute(), the mysqli_fetch() function must be used to fetch the data prior to preforming any additional queries.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Stuttgart (DEU,Baden-Wuerttemberg) Bordeaux (FRA,Aquitaine) |
(PHP 5)
mysqli_stmt_fetch(no version information, might be only in CVS)
stmt->fetch -- Fetch results from a prepared statement into the bound variablesProcedural style:
mixed mysqli_stmt_fetch ( object stmt)Object oriented style (method):
class stmt {mysqli_stmt_fetch() returns row data using the variables bound by mysqli_stmt_bind_result().
Óçìåßùóç: Note that all columns must be bound by the application before calling mysqli_stmt_fetch().
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Rockford (USA) Tallahassee (USA) Salinas (USA) Santa Clarita (USA) Springfield (USA) |
(PHP 5)
mysqli_stmt_free_result(no version information, might be only in CVS)
stmt->free_result -- Frees stored result memory for the given statement handleProcedural style:
void mysqli_stmt_free_result ( object stmt)Object oriented style (method):
class stmt {The mysqli_stmt_free_result() function frees the result memory associated with the statement represented by the stmt parameter, which was allocated by mysqli_stmt_store_result().
(PHP 5)
mysqli_stmt-init(no version information, might be only in CVS)
mysqli->stmt->init -- Initializes a statement and returns an object for use with mysqli_stmt_prepareProcedural style :
object mysqli_stmt_init ( object link)Object oriented style (property):
class mysqli {Allocates and initializes a statement object suitable for mysqli_stmt_prepare().
Óçìåßùóç: Any subsequent calls to any mysqli_stmt function will fail until mysqli_stmt_prepare() was called.
(PHP 5)
mysqli_stmt_num_rows(no version information, might be only in CVS)
stmt->num_rows -- Return the number of rows in statements result set.Returns the number of rows in the result set. The use of mysqli_stmt_num_rows() depends on whether or not you used mysqli_stmt_store_result() to buffer the entire result set in the statement handle.
If you use mysqli_stmt_store_result(), mysqli_stmt_num_rows() may be called immediately.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Number of rows: 20. |
(PHP 5)
mysqli_stmt_param_count(no version information, might be only in CVS)
stmt->param_count -- Returns the number of parameter for the given statementProcedural style:
int mysqli_stmt_param_count ( object stmt)Object oriented style (property):
class stmt {mysqli_stmt_param_count() returns the number of parameter markers present in the prepared statement.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Statement has 2 markers. |
(PHP 5)
mysqli_stmt_prepare(no version information, might be only in CVS)
stmt->prepare -- Prepare a SQL statement for executionProcedure style:
bool mysqli_stmt_prepare ( object stmt, string query)Object oriented style (method)
class stmt {mysqli_stmt_prepare() prepares the SQL query pointed to by the null-terminated string query. The statement object has to be allocated by mysqli_stmt_init(). The query must consist of a single SQL statement.
Óçìåßùóç: You should not add a terminating semicolon or \g to the statement.
The parameter query can include one or more parameter markers in the SQL statement by embedding question mark (?) characters at the appropriate positions.
Óçìåßùóç: The markers are legal only in certain places in SQL statements. For example, they are allowed in the VALUES() list of an INSERT statement (to specify column values for a row), or in a comparison with a column in a WHERE clause to specify a comparison value.
However, they are not allowed for identifiers (such as table or column names), in the select list that names the columns to be returned by a SELECT statement), or to specify both operands of a binary operator such as the = equal sign. The latter restriction is necessary because it would be impossible to determine the parameter type. In general, parameters are legal only in Data Manipulation Languange (DML) statements, and not in Data Defination Language (DDL) statements.
The parameter markers must be bound to application variables using mysqli_stmt_bind_param() and/or mysqli_stmt_bind_result() before executing the statement or fetching rows.
mysqli_stmt_init(), mysqli_stmt_execute(), mysqli_stmt_fetch(), mysqli_stmt_bind_param(), mysqli_stmt_bind_result(), mysqli_stmt_close()
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Amersfoort is in district Utrecht |
Procedural style:
mixed mysqli_stmt_result_metadata ( object stmt)Object oriented style (method):
class stmt {If a statement passed to mysqli_prepare() is one that produces a result set, mysqli_stmt_result_metadata() returns the result object that can be used to process the meta information such as total number of fields and individual field information.
Óçìåßùóç: This result set pointer can be passed as an argument to any of the field-based functions that process result set metadata, such as:
The result set structure should be freed when you are done with it, which you can do by passing it to mysqli_free_result()
Óçìåßùóç: The result set returned by mysqli_stmt_result_metadata() contains only metadata. It does not contain any row results. The rows are obtained by using the statement handle with mysqli_fetch().
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
(PHP 5)
mysqli_stmt_send_long_data(no version information, might be only in CVS)
stmt->send_long_data -- Send data in blocksProcedural style:
bool mysqli_stmt_send_long_data ( object stmt, int param_nr, string data)Object oriented style (method)
class stmt {Allows to send parameter data to the server in pieces (or chunks), e.g. if the size of a blob exceeds the size of max_allowed_packet. This function can be called multiple times to send the parts of a character or binary data value for a column, which must be one of the TEXT or BLOB datatypes.
param_nr indicates which parameter to associate the data with. Parameters are numbered beginning with 0. data is a string containing data to be sent.
Returns a string containing the SQLSTATE error code for the most recently invoked prepared statement function that can succeed or fail. The error code consists of five characters. '00000' means no error. The values are specified by ANSI SQL and ODBC. For a list of possible values, see http://dev.mysql.com/doc/mysql/en/Error-returns.html.
Óçìåßùóç: Note that not all MySQL errors are yet mapped to SQLSTATE's. The value HY000 (general error) is used for unmapped errors.
Returns a string containing the SQLSTATE error code for the last error. The error code consists of five characters. '00000' means no error.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Error: 42S02. |
(PHP 5)
mysqli_stmt_store_result(no version information, might be only in CVS)
mysqli_stmt->store_result -- Transfers a result set from a prepared statementProcedural style:
bool mysqli_stmt_store_result ( object stmt)Object oriented style (method):
class mysqli_stmt {You must call mysql_stmt_store_result() for every query that successfully produces a result set (SELECT, SHOW, DESCRIBE, EXPLAIN), and only if you want to buffer the complete result set by the client, so that the subsequent mysql_fetch() call returns buffered data.
Óçìåßùóç: It is unnecessary to call mysql_stmt_store_result() for other queries, but if you do, it will not harm or cause any notable performance in all cases. You can detect whether the query produced a result set by checking if mysql_stmt_result_metadata() returns NULL.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Number of rows: 20. |
(PHP 5)
mysqli_store_result(no version information, might be only in CVS)
mysqli->store_result -- Transfers a result set from the last queryProcedural style:
object mysqli_store_result ( object link)Object oriented style (method):
class mysqli {Transfers the result set from the last query on the database connection represented by the link parameter to be used with the mysqli_data_seek() function.
Óçìåßùóç: Although it is always good practice to free the memory used by the result of a query using the mysqli_free_result() function, when transfering large result sets using the mysqli_store_result() this becomes particularly important.
Óçìåßùóç: mysqli_store_result() returns FALSE in case the query didn't return a result set (if the query was, for example an INSERT statement). This function also returns FALSE if the reading of the result set failed. You can check if you have got an error by checking if mysqli_error() doesn't return an empty string, if mysqli_errno() returns a non zero value, or if mysqli_field_count() returns a non zero value. Also possible reason for this function returning FALSE after successfull call to mysqli_query() can be too large result set (memory for it cannot be allocated). If mysqli_field_count() returns a non-zero value, the statement should have produced a non-empty result set.
(PHP 5)
mysqli_thread_id(no version information, might be only in CVS)
mysqli->thread_id -- Returns the thread ID for the current connectionProcedural style:
int mysqli_thread_id ( object link)Object oriented style (property):
class mysqli {The mysqli_thread_id() function returns the thread ID for the current connection which can then be killed using the mysqli_kill() function. If the connection is lost and you reconnect with mysqli_ping(), the thread ID will be other. Therefore you should get the thread ID only when you need it.
Óçìåßùóç: The thread ID is assigned on a connection-by-connection basis. Hence, if the connection is broken and then re-established a new thread ID will be assigned.
To kill a running query you can use the SQL command KILL QUERY processid.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Error: MySQL server has gone away |
Procedural style:
bool mysqli_thread_safe ( void )mysqli_thread_safe() indicates whether the client library is compiled as thread-safe.
(PHP 5)
mysqli_use_result(no version information, might be only in CVS)
mysqli->use_result -- Initiate a result set retrievalProcedural style:
mixed mysqli_use_result ( object link)Object oriented style (method):
class mysqli {mysqli_use_result() is used to initiate the retrieval of a result set from the last query executed using the mysqli_real_query() function on the database connection specified by the link parameter. Either this or the mysqli_store_result() function must be called before the results of a query can be retrieved, and one or the other must be called to prevent the next query on that database connection from failing.
Óçìåßùóç: The mysqli_use_result() function does not transfer the entire result set from the database and hence cannot be used functions such as mysqli_data_seek() to move to a particular row within the set. To use this functionality, the result set must be stored using mysqli_store_result(). One should not use mysqli_use_result() if a lot of processing on the client side is performed, since this will tie up the server and prevent other threads from updating any tables from which the data is being fetched.
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
my_user@localhost ----------------- Amersfoort Maastricht Dordrecht Leiden Haarlemmermeer |
(PHP 5)
mysqli_warning_count(no version information, might be only in CVS)
mysqli->warning_count -- Returns the number of warnings from the last query for the given linkProcedural style:
int mysqli_warning_count ( object link)Object oriented style (property):
class mysqli {mysqli_warning_count() returns the number of warnings from the last query in the connection represented by the link parameter.
Óçìåßùóç: For retrieving warning messages you can use the SQL command SHOW WARNINGS [limit row_count].
ÐáñÜäåéãìá 1. Object oriented style
|
ÐáñÜäåéãìá 2. Procedural style
|
The above examples would produce the following output:
Warning (1264): Data truncated for column 'Name' at row 1 |
msession is an interface to a high speed session daemon which can run either locally or remotely. It is designed to provide consistent session management for a PHP web farm. More Information about msession and the session server software itself can be found at http://devel.mohawksoft.com/msession.html.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns an associative array of value/session for all sessions with a variable named name.
Used for searching sessions with common attributes.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
msession_plugin -- Call an escape function within the msession personality pluginÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
(4.0.5 - 4.2.3 only)
muscat_close -- Shuts down the muscat session and releases any memory back to PHP.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
[Not back to the system, note!]
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
muscat_setup_net() creates a new muscat session and returns the handle.
muscat_host is the hostname to connect to. port is the port number to connect to.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
size is the amount of memory in bytes to allocate for muscat. muscat_dir is the muscat installation dir e.g. "/usr/local/empower", it defaults to the compile time muscat directory.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
For further details and definition of the PHP_INI_* constants see ini_set().
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether or not to define the various syslog variables (e.g. $LOG_PID, $LOG_CRON, etc.). Turning it off is a good idea performance-wise. At runtime, you can define these variables by calling define_syslog_variables().
Ïé ðáñáêÜôù óôáèåñÝò åßíáé ðÜíôá äéáèÝóéìåò ùò ìÝñïò ôïõ ðõñÞíá ôçò PHP.
Ðßíáêáò 2. openlog() Options
Constant | Description |
---|---|
LOG_CONS | if there is an error while sending data to the system logger, write directly to the system console |
LOG_NDELAY | open the connection to the logger immediately |
LOG_ODELAY | (default) delay opening the connection until the first message is logged |
LOG_NOWAIT | |
LOG_PERROR | print log message also to standard error |
LOG_PID | include PID with each message |
Ðßíáêáò 3. openlog() Facilities
Constant | Description |
---|---|
LOG_AUTH | security/authorization messages (use LOG_AUTHPRIV instead in systems where that constant is defined) |
LOG_AUTHPRIV | security/authorization messages (private) |
LOG_CRON | clock daemon (cron and at) |
LOG_DAEMON | other system daemons |
LOG_KERN | kernel messages |
LOG_LOCAL0 ... LOG_LOCAL7 | reserved for local use, these are not available in Windows |
LOG_LPR | line printer subsystem |
LOG_MAIL | mail subsystem |
LOG_NEWS | USENET news subsystem |
LOG_SYSLOG | messages generated internally by syslogd |
LOG_USER | generic user-level messages |
LOG_UUCP | UUCP subsystem |
Ðßíáêáò 4. syslog() Priorities (in descending order)
Constant | Description |
---|---|
LOG_EMERG | system is unusable |
LOG_ALERT | action must be taken immediately |
LOG_CRIT | critical conditions |
LOG_ERR | error conditions |
LOG_WARNING | warning conditions |
LOG_NOTICE | normal, but significant, condition |
LOG_INFO | informational message |
LOG_DEBUG | debug-level message |
Ðßíáêáò 5. dns_get_record() Options
Constant | Description |
---|---|
DNS_A | IPv4 Address Resource |
DNS_MX | Mail Exchanger Resource |
DNS_CNAME | Alias (Canonical Name) Resource |
DNS_NS | Authoritative Name Server Resource |
DNS_PTR | Pointer Resource |
DNS_HINFO | Host Info Resource (See IANA's Operating System Names for the meaning of these values) |
DNS_SOA | Start of Authority Resource |
DNS_TXT | Text Resource |
DNS_ANY | Any Resource Record. On most systems this returns all resource records, however it should not be counted upon for critical uses. Try DNS_ALL instead. |
DNS_AAAA | IPv6 Address Resource |
DNS_ALL | Iteratively query the name server for each available record type. |
(PHP 3, PHP 4 , PHP 5)
checkdnsrr -- Check DNS records corresponding to a given Internet host name or IP addressSearches DNS for records of type type corresponding to host. Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred.
type may be any one of: A, MX, NS, SOA, PTR, CNAME, AAAA, or ANY. The default is MX.
Host may either be the IP address in dotted-quad notation or the host name.
Óçìåßùóç: AAAA type added with PHP 5.0.0
See also getmxrr(), gethostbyaddr(), gethostbyname(), gethostbynamel(), and the named(8) manual page.
closelog() closes the descriptor being used to write to the system logger. The use of closelog() is optional.
See also define_syslog_variables(), syslog() and openlog().
Disables the internal PHP debugger. This function is only available in PHP 3.
For more information see the appendix on Debugging PHP.
Enables the internal PHP debugger, connecting it to address. This function is only available in PHP 3.
For more information see the appendix on Debugging PHP.
Initializes all constants used in the syslog functions.
See also openlog(), syslog() and closelog().
Check DNS records corresponding to a given Internet host name or IP address
Get MX records corresponding to a given Internet host name.
This function returns an array of associative arrays. Each associative array contains at minimum the following keys:
Ðßíáêáò 1. Basic DNS attributes
Attribute | Meaning |
---|---|
host | The record in the DNS namespace to which the rest of the associated data refers. |
class | dns_get_record() only returns Internet class records and as such this parameter will always return IN. |
type | String containing the record type. Additional attributes will also be contained in the resulting array dependant on the value of type. See table below. |
ttl | Time To Live remaining for this record. This will not equal the record's original ttl, but will rather equal the original ttl minus whatever length of time has passed since the authoritative name server was queried. |
hostname should be a valid DNS hostname such as "www.example.com". Reverse lookups can be generated using in-addr.arpa notation, but gethostbyaddr() is more suitable for the majority of reverse lookups.
By default, dns_get_record() will search for any resource records associated with hostname. To limit the query, specify the optional type parameter. type may be any one of the following: DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_ALL or DNS_ANY. The default is DNS_ANY.
Óçìåßùóç: Because of eccentricities in the performance of libresolv between platforms, DNS_ANY will not always return every record, the slower DNS_ALL will collect all records more reliably.
The optional third and fourth arguments to this function, authns and addtl are passed by reference and, if given, will be populated with Resource Records for the Authoritative Name Servers, and any Additional Records respectively. See the example below.
Ðßíáêáò 2. Other keys in associative arrays dependant on 'type'
Type | Extra Columns |
---|---|
A | ip: An IPv4 addresses in dotted decimal notation. |
MX | pri: Priority of mail exchanger. Lower numbers indicate greater priority. target: FQDN of the mail exchanger. See also dns_get_mx(). |
CNAME | target: FQDN of location in DNS namespace to which the record is aliased. |
NS | target: FQDN of the name server which is authoritative for this hostname. |
PTR | target: Location within the DNS namespace to which this record points. |
TXT | txt: Arbitrary string data associated with this record. |
HINFO | cpu: IANA number designating the CPU of the machine referenced by this record. os: IANA number designating the Operating System on the machine referenced by this record. See IANA's Operating System Names for the meaning of these values. |
SOA | mname: FQDN of the machine from which the resource records originated. rname: Email address of the administrative contain for this domain. serial: Serial # of this revision of the requested domain. refresh: Refresh interval (seconds) secondary name servers should use when updating remote copies of this domain. retry: Length of time (seconds) to wait after a failed refresh before making a second attempt. expire: Maximum length of time (seconds) a secondary DNS server should retain remote copies of the zone data without a successful refresh before discarding. minimum-ttl: Minimum length of time (seconds) a client can continue to use a DNS resolution before it should request a new resolution from the server. Can be overridden by individual resource records. |
AAAA | ipv6: IPv6 address |
SRV | pri: (Priority) lowest priorities should be used first. weight: Ranking to weight which of commonly prioritized targets should be chosen at random. target and port: hostname and port where the requested service can be found. For additional information see: RFC 2782 |
NAPTR | order and pref: Equivalent to pri and weight above. flags, services, regex, and replacement: Parameters as defined by RFC 2915. |
Óçìåßùóç: Per DNS standards, email addresses are given in user.host format (for example: hostmaster.example.com as opposed to hostmaster@example.com), be sure to check this value and modify if necessary before using it with a functions such as mail().
ÐáñÜäåéãìá 1. Using dns_get_record()
Produces output similar to the following:
|
Since it's very common to want the IP address of a mail server once the MX record has been resolved, dns_get_record() also returns an array in addtl which contains associate records. authns is returned as well containing a list of authoritative name servers.
ÐáñÜäåéãìá 2. Using dns_get_record() and DNS_ANY
Produces output similar to the following:
|
See also dns_get_mx(), and dns_check_record()
Initiates a socket connection to the resource specified by target. PHP supports targets in the Internet and Unix domains as described in ÐáñÜñôçìá L. A list of supported transports can also be retrieved using stream_get_transports().
Óçìåßùóç: If you need to set a timeout for reading/writing data over the socket, use stream_set_timeout(), as the timeout parameter to fsockopen() only applies while connecting the socket.
As of PHP 4.3.0, if you have compiled in OpenSSL support, you may prefix the hostname with either 'ssl://' or 'tls://' to use an SSL or TLS client connection over TCP/IP to connect to the remote host.
fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()).
If the call fails, it will return FALSE and if the optional errno and errstr arguments are present they will be set to indicate the actual system level error that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments will always be passed by reference.
Depending on the environment, the Unix domain or the optional connect timeout may not be available.
The socket will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking().
ÐáñÜäåéãìá 1. fsockopen() Example
|
Ðñïåéäïðïßçóç |
UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data. |
Óçìåßùóç: ¼ôáí êáèïñßæåôå ìéá áñéèìçôéêÞ äéåýèõíóç IPv6 (ð.÷. fe80::1) ðñÝðåé íá åóùêëåßåôå ôçí IP óå áãêýëåò. Ãéá ðáñÜäåéãìá, tcp://[fe80::1]:80.
Óçìåßùóç: The timeout parameter was introduced in PHP 3.0.9 and UDP support was added in PHP 4.
(PHP 3, PHP 4 , PHP 5)
gethostbyaddr -- Get the Internet host name corresponding to a given IP addressReturns the host name of the Internet host specified by ip_address or a string containing the unmodified ip_address on failure.
See also gethostbyname().
(PHP 3, PHP 4 , PHP 5)
gethostbyname -- Get the IP address corresponding to a given Internet host nameReturns the IP address of the Internet host specified by hostname or a string containing the unmodified hostname on failure.
See also gethostbyaddr().
(PHP 3, PHP 4 , PHP 5)
gethostbynamel -- Get a list of IP addresses corresponding to a given Internet host nameReturns a list of IP addresses to which the Internet host specified by hostname resolves.
See also gethostbyname(), gethostbyaddr(), checkdnsrr(), getmxrr(), and the named(8) manual page.
Searches DNS for MX records corresponding to hostname. Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred.
A list of the MX records found is placed into the array mxhosts. If the weight array is given, it will be filled with the weight information gathered.
Óçìåßùóç: This function should not be used for the purposes of address verification. Only the mailexchangers found in DNS are returned, however, according to RFC 2821 when no mail exchangers are listed, hostname itself should be used as the only mail exchanger with a priority of 0.
See also checkdnsrr(), gethostbyname(), gethostbynamel(), gethostbyaddr(), and the named(8) manual page.
getprotobyname() returns the protocol number associated with the protocol name as per /etc/protocols.
See also: getprotobynumber().
getprotobynumber() returns the protocol name associated with protocol number as per /etc/protocols.
See also: getprotobyname().
getservbyname() returns the Internet port which corresponds to service for the specified protocol as per /etc/services. protocol is either "tcp" or "udp" (in lowercase).
For complete list of port numbers see: http://www.iana.org/assignments/port-numbers.
See also: getservbyport().
getservbyport() returns the Internet service associated with port for the specified protocol as per /etc/services. protocol is either "tcp" or "udp" (in lowercase).
See also: getservbyname().
(PHP 4 , PHP 5)
ip2long -- Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address.The function ip2long() generates an IPv4 Internet network address from its Internet standard format (dotted string) representation. If ip_address is invalid then -1 is returned. Note that -1 does not evaluate as FALSE in PHP.
Óçìåßùóç: Because PHP's integer type is signed, and many IP addresses will result in negative integers, you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned IP address.
ip2long() will also work with non-complete ip adresses. Read http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/libs/commtrf2/inet_addr.htm for more info.
Óçìåßùóç: ip2long() will return -1 for the ip 255.255.255.255
(PHP 4 , PHP 5)
long2ip -- Converts an (IPv4) Internet network address into a string in Internet standard dotted formatThe function long2ip() generates an Internet address in dotted format (i.e.: aaa.bbb.ccc.ddd) from the proper address representation.
See also: ip2long()
openlog() opens a connection to the system logger for a program. The string ident is added to each message. Values for option and facility are given below. The option argument is used to indicate what logging options will be used when generating a log message. The facility argument is used to specify what type of program is logging the message. This allows you to specify (in your machine's syslog configuration) how messages coming from different facilities will be handled. The use of openlog() is optional. It will automatically be called by syslog() if necessary, in which case ident will default to FALSE.
Ðßíáêáò 1. openlog() Options
Constant | Description |
---|---|
LOG_CONS | if there is an error while sending data to the system logger, write directly to the system console |
LOG_NDELAY | open the connection to the logger immediately |
LOG_ODELAY | (default) delay opening the connection until the first message is logged |
LOG_PERROR | print log message also to standard error |
LOG_PID | include PID with each message |
Ðßíáêáò 2. openlog() Facilities
Constant | Description |
---|---|
LOG_AUTH | security/authorization messages (use LOG_AUTHPRIV instead in systems where that constant is defined) |
LOG_AUTHPRIV | security/authorization messages (private) |
LOG_CRON | clock daemon (cron and at) |
LOG_DAEMON | other system daemons |
LOG_KERN | kernel messages |
LOG_LOCAL0 ... LOG_LOCAL7 | reserved for local use, these are not available in Windows |
LOG_LPR | line printer subsystem |
LOG_MAIL | mail subsystem |
LOG_NEWS | USENET news subsystem |
LOG_SYSLOG | messages generated internally by syslogd |
LOG_USER | generic user-level messages |
LOG_UUCP | UUCP subsystem |
Óçìåßùóç: LOG_USER is the only valid log type under Windows operating systems
See also define_syslog_variables(), syslog() and closelog().
(PHP 3>= 3.0.7, PHP 4 , PHP 5)
pfsockopen -- Open persistent Internet or Unix domain socket connectionThis function behaves exactly as fsockopen() with the difference that the connection is not closed after the script finishes. It is the persistent version of fsockopen().
syslog() generates a log message that will be distributed by the system logger. priority is a combination of the facility and the level, values for which are given in the next section. The remaining argument is the message to send, except that the two characters %m will be replaced by the error message string (strerror) corresponding to the present value of errno.
Ðßíáêáò 1. syslog() Priorities (in descending order)
Constant | Description |
---|---|
LOG_EMERG | system is unusable |
LOG_ALERT | action must be taken immediately |
LOG_CRIT | critical conditions |
LOG_ERR | error conditions |
LOG_WARNING | warning conditions |
LOG_NOTICE | normal, but significant, condition |
LOG_INFO | informational message |
LOG_DEBUG | debug-level message |
ÐáñÜäåéãìá 1. Using syslog()
|
On Windows NT, the syslog service is emulated using the Event Log.
Óçìåßùóç: Use of LOG_LOCAL0 through LOG_LOCAL7 for the facility parameter of openlog() is not available in Windows.
See also define_syslog_variables(), openlog() and closelog().
ncurses (new curses) is a free software emulation of curses in System V Rel 4.0 (and above). It uses terminfo format, supports pads, colors, multiple highlights, form characters and function key mapping. Because of the interactive nature of this library, it will be of little use for writing Web applications, but may be useful when writing scripts meant using PHP from the command line.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
Ncurses is available for the following platforms:
AIX
BeOS
Cygwin
Digital Unix (aka OSF1)
FreeBSD
GNU/Linux
HPUX
IRIX
OS/2
SCO OpenServer
Solaris
SunOS
You need the ncurses libraries and headerfiles. Download the latest version from the ftp://ftp.gnu.org/pub/gnu/ncurses/ or from an other GNU-Mirror.
To get these functions to work, you have to compile the CGI or CLI version of PHP with --with-ncurses[=DIR].
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Ncurses configuration options
Name | Default | Changeable |
---|---|---|
ncurses.value | "42" | PHP_INI_ALL |
ncurses.string | "foobar" | PHP_INI_ALL |
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðßíáêáò 2. ncurses color constants
constant | meaning |
---|---|
NCURSES_COLOR_BLACK | no color (black) |
NCURSES_COLOR_WHITE | white |
NCURSES_COLOR_RED | red - supported when terminal is in color mode |
NCURSES_COLOR_GREEN | green - supported when terminal is in color mod |
NCURSES_COLOR_YELLOW | yellow - supported when terminal is in color mod |
NCURSES_COLOR_BLUE | blue - supported when terminal is in color mod |
NCURSES_COLOR_CYAN | cyan - supported when terminal is in color mod |
NCURSES_COLOR_MAGENTA | magenta - supported when terminal is in color mod |
Ðßíáêáò 3. ncurses key constants
constant | meaning |
---|---|
NCURSES_KEY_F0 - NCURSES_KEY_F64 | function keys F1 - F64 |
NCURSES_KEY_DOWN | down arrow |
NCURSES_KEY_UP | up arrow |
NCURSES_KEY_LEFT | left arrow |
NCURSES_KEY_RIGHT | right arrow |
NCURSES_KEY_HOME | home key (upward+left arrow) |
NCURSES_KEY_BACKSPACE | backspace |
NCURSES_KEY_DL | delete line |
NCURSES_KEY_IL | insert line |
NCURSES_KEY_DC | delete character |
NCURSES_KEY_IC | insert char or enter insert mode |
NCURSES_KEY_EIC | exit insert char mode |
NCURSES_KEY_CLEAR | clear screen |
NCURSES_KEY_EOS | clear to end of screen |
NCURSES_KEY_EOL | clear to end of line |
NCURSES_KEY_SF | scroll one line forward |
NCURSES_KEY_SR | scroll one line backward |
NCURSES_KEY_NPAGE | next page |
NCURSES_KEY_PPAGE | previous page |
NCURSES_KEY_STAB | set tab |
NCURSES_KEY_CTAB | clear tab |
NCURSES_KEY_CATAB | clear all tabs |
NCURSES_KEY_SRESET | soft (partial) reset |
NCURSES_KEY_RESET | reset or hard reset |
NCURSES_KEY_PRINT | |
NCURSES_KEY_LL | lower left |
NCURSES_KEY_A1 | upper left of keypad |
NCURSES_KEY_A3 | upper right of keypad |
NCURSES_KEY_B2 | center of keypad |
NCURSES_KEY_C1 | lower left of keypad |
NCURSES_KEY_C3 | lower right of keypad |
NCURSES_KEY_BTAB | back tab |
NCURSES_KEY_BEG | beginning |
NCURSES_KEY_CANCEL | cancel |
NCURSES_KEY_CLOSE | close |
NCURSES_KEY_COMMAND | cmd (command) |
NCURSES_KEY_COPY | copy |
NCURSES_KEY_CREATE | create |
NCURSES_KEY_END | end |
NCURSES_KEY_EXIT | exit |
NCURSES_KEY_FIND | find |
NCURSES_KEY_HELP | help |
NCURSES_KEY_MARK | mark |
NCURSES_KEY_MESSAGE | message |
NCURSES_KEY_MOVE | move |
NCURSES_KEY_NEXT | next |
NCURSES_KEY_OPEN | open |
NCURSES_KEY_OPTIONS | options |
NCURSES_KEY_PREVIOUS | previous |
NCURSES_KEY_REDO | redo |
NCURSES_KEY_REFERENCE | ref (reference) |
NCURSES_KEY_REFRESH | refresh |
NCURSES_KEY_REPLACE | replace |
NCURSES_KEY_RESTART | restart |
NCURSES_KEY_RESUME | resume |
NCURSES_KEY_SAVE | save |
NCURSES_KEY_SBEG | shiftet beg (beginning) |
NCURSES_KEY_SCANCEL | shifted cancel |
NCURSES_KEY_SCOMMAND | shifted command |
NCURSES_KEY_SCOPY | shifted copy |
NCURSES_KEY_SCREATE | shifted create |
NCURSES_KEY_SDC | shifted delete char |
NCURSES_KEY_SDL | shifted delete line |
NCURSES_KEY_SELECT | select |
NCURSES_KEY_SEND | shifted end |
NCURSES_KEY_SEOL | shifted end of line |
NCURSES_KEY_SEXIT | shifted exit |
NCURSES_KEY_SFIND | shifted find |
NCURSES_KEY_SHELP | shifted help |
NCURSES_KEY_SHOME | shifted home |
NCURSES_KEY_SIC | shifted input |
NCURSES_KEY_SLEFT | shifted left arrow |
NCURSES_KEY_SMESSAGE | shifted message |
NCURSES_KEY_SMOVE | shifted move |
NCURSES_KEY_SNEXT | shifted next |
NCURSES_KEY_SOPTIONS | shifted options |
NCURSES_KEY_SPREVIOUS | shifted previous |
NCURSES_KEY_SPRINT | shifted print |
NCURSES_KEY_SREDO | shifted redo |
NCURSES_KEY_SREPLACE | shifted replace |
NCURSES_KEY_SRIGHT | shifted right arrow |
NCURSES_KEY_SRSUME | shifted resume |
NCURSES_KEY_SSAVE | shifted save |
NCURSES_KEY_SSUSPEND | shifted suspend |
NCURSES_KEY_UNDO | undo |
NCURSES_KEY_MOUSE | mouse event has occurred |
NCURSES_KEY_MAX | maximum key value |
Ðßíáêáò 4. mouse constants
Constant | meaning |
---|---|
NCURSES_BUTTON1_RELEASED - NCURSES_BUTTON4_RELEASED | button (1-4) released |
NCURSES_BUTTON1_PRESSED - NCURSES_BUTTON4_PRESSED | button (1-4) pressed |
NCURSES_BUTTON1_CLICKED - NCURSES_BUTTON4_CLICKED | button (1-4) clicked |
NCURSES_BUTTON1_DOUBLE_CLICKED - NCURSES_BUTTON4_DOUBLE_CLICKED | button (1-4) double clicked |
NCURSES_BUTTON1_TRIPLE_CLICKED - NCURSES_BUTTON4_TRIPLE_CLICKED | button (1-4) triple clicked |
NCURSES_BUTTON_CTRL | ctrl pressed during click |
NCURSES_BUTTON_SHIFT | shift pressed during click |
NCURSES_BUTTON_ALT | alt pressed during click |
NCURSES_ALL_MOUSE_EVENTS | report all mouse events |
NCURSES_REPORT_MOUSE_POSITION | report mouse position |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ncurses_addchnstr -- Add attributed string with specified length at current positionÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_beep() sends an audible alert (bell) and if its not possible flashes the screen. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ncurses_flash()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ncurses_border -- Draw a border around the screen using attributed charactersÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_border() draws the specified lines and corners around the main window. Each parameter expects 0 to draw a line and 1 to skip it. The corners are top left, top right, bottom left and bottom right.
Use ncurses_wborder() for borders around subwindows!
See also ncurses_wborder().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function ncurses_can_change_color() returns TRUE or FALSE, depending on whether the terminal has color capabilities and whether the programmer can change the colors.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_cbreak() disables line buffering and character processing (interrupt and flow control characters are unaffected), making characters typed by the user immediately available to the program.
ncurses_cbreak() returns TRUE or NCURSES_ERR if any error occurred.
See also: ncurses_nocbreak()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_clear() clears the screen completely without setting blanks. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Note: ncurses_clear() clears the screen without setting blanks, which have the current background rendition. To clear screen with blanks, use ncurses_erase().
See also ncurses_erase().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_clrtobot() erases all lines from cursor to end of screen and creates blanks. Blanks created by ncurses_clrtobot() have the current background rendition. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ncurses_clear(), and ncurses_clrtoeol()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_clrtoeol() erases the current line from cursor position to the end. Blanks created by ncurses_clrtoeol() have the current background rendition. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ncurses_clear(), and ncurses_clrtobot()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_def_prog_mode() saves the current terminal modes for program (in curses) for use by ncurses_reset_prog_mode(). Returns FALSE on success, otherwise TRUE.
See also: ncurses_reset_prog_mode()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_def_shell_mode() saves the current terminal modes for shell (not in curses) for use by ncurses_reset_shell_mode(). Returns FALSE on success, otherwise TRUE.
See also: ncurses_reset_shell_mode()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
ncurses_del_panel -- Remove panel from the stack and delete it (but not the associated window)
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
ncurses_delch -- Delete character at current position, move rest of line leftÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_delch() deletes the character under the cursor. All characters to the right of the cursor on the same line are moved to the left one position and the last character on the line is filled with a blank. The cursor position does not change. Returns FALSE on success, otherwise TRUE.
See also: ncurses_deleteln()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_deleteln() deletes the current line under cursorposition. All lines below the current line are moved up one line. The bottom line of window is cleared. Cursor position does not change. Returns FALSE on success, otherwise TRUE.
See also: ncurses_delch()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_doupdate()() compares the virtual screen to the physical screen and updates the physical screen. This way is more effective than using multiple refresh calls. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_echo() enables echo mode. All characters typed by user are echoed by ncurses_getch(). Returns FALSE on success, TRUE if any error occurred.
To disable echo mode use ncurses_noecho().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_erase() fills the terminal screen with blanks. Created blanks have the current background rendition, set by ncurses_bkgd(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ncurses_bkgd(), and ncurses_clear()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_erasechar() returns the current erase char character.
See also: ncurses_killchar()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_flash() flashes the screen, and if its not possible, sends an audible alert (bell). Returns FALSE on success, otherwise TRUE.
See also: ncurses_beep()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The ncurses_flushinp() throws away any typeahead that has been typed and has not yet been read by your program. Returns FALSE on success, otherwise TRUE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_getmaxyx() puts the horizontal and vertical size of the window window into the given variables &y and &x. Variables must be passed as reference, so they are updated when the user changes terminal size.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_getmouse() reads mouse event out of queue. Function ncurses_getmouse() will return ;FALSE if a mouse event is actually visible in the given window, otherwise it will return TRUE. Event options will be delivered in parameter mevent, which has to be an array, passed by reference (see example below). On success an associative array with following keys will be delivered:
"id" : Id to distinguish multiple devices
"x" : screen relative x-position in character cells
"y" : screen relative y-position in character cells
"z" : currently not supported
"mmask" : Mouse action
See also ncurses_ungetmouse()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_has_colors() returns TRUE or FALSE depending on whether the terminal has color capacities.
See also: ncurses_can_change_color()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_has_ic() checks terminals insert- and delete capabilities. It returns TRUE when terminal has insert/delete-capabilities, otherwise FALSE.
See also: ncurses_has_il()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_has_il() checks terminals insert- and delete-line-capabilities. It returns TRUE when terminal has insert/delete-line capabilities, otherwise FALSE
See also: ncurses_has_ic()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ncurses_hline -- Draw a horizontal line at current position using an attributed character and max. n characters longÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_inch() returns the character from the current position.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_init() initializes the ncurses interface and must be used before any other ncurses function.
(PHP 4 >= 4.1.0, PHP 5)
ncurses_insch -- Insert character moving rest of line including character at current positionÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
ncurses_insdelln -- Insert lines before current line scrolling down (negative numbers delete and scroll up)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_insertln() inserts a new line above the current line. The bottom line will be lost.
(PHP 4 >= 4.2.0, PHP 5)
ncurses_insstr -- Insert string at current position, moving rest of line rightÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_instr() returns the number of characters read from the current character position until end of line. buffer contains the characters. Attributes are stripped from the characters.
(PHP 4 >= 4.1.0, PHP 5)
ncurses_isendwin -- Ncurses is in endwin mode, normal screen output may be performedÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_isendwin() returns TRUE, if ncurses_endwin() has been called without any subsequent calls to ncurses_wrefresh(), otherwise FALSE.
See also ncurses_endwin() and ncurses_wrefresh().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_killchar() returns the current line kill character.
See also: ncurses_erasechar()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_longname() returns a verbose description of the terminal. The description is truncated to 128 characters. On Error ncurses_longname() returns NULL.
See also: ncurses_termname()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Function ncurses_mousemask() will set mouse events to be reported. By default no mouse events will be reported. The function ncurses_mousemask() will return a mask to indicated which of the in parameter newmask specified mouse events can be reported. On complete failure, it returns 0. In parameter oldmask, which is passed by reference ncurses_mousemask() returns the previous value of mouse event mask. Mouse events are represented by NCURSES_KEY_MOUSE in the ncurses_wgetch() input stream. To read the event data and pop the event of of queue, call ncurses_getmouse().
As a side effect, setting a zero mousemask in newmask turns off the mouse pointer. Setting a non zero value turns mouse pointer on.
mouse mask options can be set with the following predefined constants:
NCURSES_BUTTON1_PRESSED
NCURSES_BUTTON1_RELEASED
NCURSES_BUTTON1_CLICKED
NCURSES_BUTTON1_DOUBLE_CLICKED
NCURSES_BUTTON1_TRIPLE_CLICKED
NCURSES_BUTTON2_PRESSED
NCURSES_BUTTON2_RELEASED
NCURSES_BUTTON2_CLICKED
NCURSES_BUTTON2_DOUBLE_CLICKED
NCURSES_BUTTON2_TRIPLE_CLICKED
NCURSES_BUTTON3_PRESSED
NCURSES_BUTTON3_RELEASED
NCURSES_BUTTON3_CLICKED
NCURSES_BUTTON3_DOUBLE_CLICKED
NCURSES_BUTTON3_TRIPLE_CLICKED
NCURSES_BUTTON4_PRESSED
NCURSES_BUTTON4_RELEASED
NCURSES_BUTTON4_CLICKED
NCURSES_BUTTON4_DOUBLE_CLICKED
NCURSES_BUTTON4_TRIPLE_CLICKED
NCURSES_BUTTON_SHIFT>
NCURSES_BUTTON_CTRL
NCURSES_BUTTON_ALT
NCURSES_ALL_MOUSE_EVENTS
NCURSES_REPORT_MOUSE_POSITION
See also ncurses_getmouse(), ncurses_ungetmouse() and ncurese_getch().
(PHP 4 >= 4.3.0, PHP 5)
ncurses_move_panel -- Moves a panel so that its upper-left corner is at [startx, starty]
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ncurses_mvaddchnstr -- Move position and add attributed string with specified lengthÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ncurses_mvdelch -- Move position and delete character, shift rest of line leftÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ncurses_mvhline -- Set new position and draw a horizontal line using an attributed character and max. n characters longÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ncurses_mvvline -- Set new position and draw a vertical line using an attributed character and max. n characters longÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_newwin() creates a new window to draw elements in. Windows can be positioned using x, y, rows and cols. When creating additional windows, remember to use ncurses_getmaxyx() to check for available space, as terminal size is individual and may vary. The return value is a resource ID used to differ between multiple windows.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_nocbreak() routine returns terminal to normal (cooked) mode. Initially the terminal may or may not in cbreak mode as the mode is inherited. Therefore a program should call ncurses_cbreak() and ncurses_nocbreak() explicitly. Returns TRUE if any error occurred, otherwise FALSE.
See also: ncurses_cbreak()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_noecho() prevents echoing of user typed characters. Returns TRUE if any error occurred, otherwise FALSE.
See also: ncurses_echo(), ncurses_getch()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_noraw() switches the terminal out of raw mode. Raw mode is similar to cbreak mode, in that characters typed are immediately passed through to the user program. The differences that are that in raw mode, the interrupt, quit, suspend and flow control characters are all passed through uninterpreted, instead of generating a signal. Returns TRUE if any error occurred, otherwise FALSE.
See also: ncurses_raw(), ncurses_cbreak(), ncurses_nocbreak()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
ncurses_panel_above -- Returns the panel above panel. If panel is null, returns the bottom panel in the stack
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
ncurses_panel_below -- Returns the panel below panel. If panel is null, returns the top panel in the stack
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_raw() places the terminal in raw mode. Raw mode is similar to cbreak mode, in that characters typed are immediately passed through to the user program. The differences that are that in raw mode, the interrupt, quit, suspend and flow control characters are all passed through uninterpreted, instead of generating a signal. Returns TRUE if any error occurred, otherwise FALSE.
See also: ncurses_noraw(), ncurses_cbreak(), ncurses_nocbreak()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Function ncurses_resetty() restores the terminal state, which was previously saved by calling ncurses_savetty(). This function always returns FALSE.
See also: ncurses_savetty()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Function ncurses_savetty() saves the current terminal state. The saved terminal state can be restored with function ncurses_resetty(). ncurses_savetty() always returns FALSE.
See also: ncurses_resetty()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
ncurses_scrl -- Scroll window content up or down without changing current positionÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
ncurses_show_panel -- Places an invisible panel on top of the stack, making it visible
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_slk_attr() returns the current soft label key attribute. On error returns TRUE, otherwise FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function ncurses_slk_clear() clears soft label keys from screen. Returns TRUE on error, otherwise FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Function ncurses_slk_init() must be called before ncurses_initscr() or ncurses_newterm() is called. If ncurses_initscr() eventually uses a line from stdscr to emulate the soft labels, then format determines how the labels are arranged of the screen. Setting format to 0 indicates a 3-2-3 arrangement of the labels, 1 indicates a 4-4 arrangement and 2 indicates the PC like 4-4-4 mode, but in addition an index line will be created.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_slk_refresh() copies soft label keys from virtual screen to physical screen. Returns TRUE on error, otherwise FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function ncurses_slk_restore() restores the soft label keys after ncurses_slk_clear() has been performed.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The ncurses_slk_touch() function forces all the soft labels to be output the next time a ncurses_slk_noutrefresh() is performed.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
ncurses_termattrs -- Returns a logical OR of all attribute flags supported by terminalÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_termname() returns terminals shortname. The shortname is truncated to 14 characters. On error ncurses_termname() returns NULL.
See also: ncurses_longname()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_getmouse() pushes a KEY_MOUSE event onto the unput queue and associates with this event the given state sata and screen-relative character cell coordinates, specified in mevent. Event options will be specified in associative array mevent:
"id" : Id to distinguish multiple devices
"x" : screen relative x-position in character cells
"y" : screen relative y-position in character cells
"z" : currently not supported
"mmask" : Mouse action
ncurses_ungetmouse() returns FALSE on success, otherwise TRUE.
See also: ncurses_getmouse()
(PHP 4 >= 4.3.0, PHP 5)
ncurses_update_panels -- Refreshes the virtual screen to reflect the relations between panels in the stack.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
ncurses_use_env -- Control use of environment information about terminal sizeÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
ncurses_use_extended_names -- Control use of extended names in terminfo descriptionsÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
ncurses_vline -- Draw a vertical line at current position using an attributed character and max. n characters longÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
ncurses_waddch -- Adds character at current position in a window and advance cursor
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
ncurses_wborder -- Draws a border around the window using attributed charactersÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ncurses_wborder() draws the specified lines and corners around the passed window window. Each parameter expects 0 to draw a line and 1 to skip it. The corners are top left, top right, bottom left and bottom right.
Use ncurses_border() for borders around the main window.
See also ncurses_border().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
ncurses_whline -- Draws a horizontal line in a window at current position using an attributed character and max. n characters long
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
Óçìåßùóç: This extension has been removed as of PHP 5 and moved to the PECL repository.
(PHP 4 >= 4.0.5)
notes_body -- Open the message msg_number in the specified mailbox on the specified server (leave servÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.0.5)
notes_find_note -- Returns a note id found in database_name. Specify the name of the note. Leaving type blaÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.0.5)
notes_header_info -- Open the message msg_number in the specified mailbox on the specified server (leave servÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
These functions are only available when running PHP as a NSAPI module in Netscape/iPlanet/SunONE webservers.
For PHP installation on Netscape/iPlanet/SunONE webservers see the NSAPI section in the installation chapter.
The behaviour of the NSAPI PHP module is affected by settings in php.ini. Configuration settings from php.ini may be overridden by additional parameters to the php4_execute call in obj.conf
NSAPI implements a subset of the functions from the Apache module for maximum compatibility.
Ðßíáêáò 2. Apache functions implemented by NSAPI
Apache function (only as alias) | NSAPI function | Description |
---|---|---|
apache_request_headers() | nsapi_request_headers() | Fetch all HTTP request headers |
apache_response_headers() | nsapi_response_headers() | Fetch all HTTP response headers |
getallheaders() | nsapi_request_headers() | Fetch all HTTP request headers |
virtual() | nsapi_virtual() | Make NSAPI sub-request |
nsapi_request_headers() returns an associative array of all the HTTP headers in the current request. This is only supported when PHP runs as a NSAPI module.
Óçìåßùóç: Prior to PHP 4.3.3, getallheaders() was only available for the Apache servers. After PHP 4.3.3, getallheaders() is an alias for nsapi_request_headers() if you use the NSAPI module.
Óçìåßùóç: You can also get at the value of the common CGI variables by reading them from the $_SERVER superglobal, which works whether or not you are using PHP as a NSAPI module.
Returns an array of all NSAPI response headers. This functionality is only available in PHP 4.3.3 and greater.
See also nsapi_request_headers() and headers_sent().
nsapi_virtual() is an NSAPI-specific function which is equivalent to <!--#include virtual...--> in SSI (.shtml files). It does an NSAPI sub-request. It is useful for including CGI scripts or .shtml files, or anything else that you'd parse through webserver.
To run the sub-request, all buffers are terminated and flushed to the browser, pending headers are sent too.
You cannot make recursive requests with this function to other PHP scripts. If you want to include PHP scripts, use include() or require().
Óçìåßùóç: This function depends on a undocumented feature of the Netscape/iPlanet/SunONE webservers. Use phpinfo() to determine if it is available. In the Unix environment it should always work, in windows it depends on the name of a ns-httpdXX.dll file. Read the note about subrequests in the install section if you experience this problem.
In addition to normal ODBC support, the Unified ODBC functions in PHP allow you to access several databases that have borrowed the semantics of the ODBC API to implement their own API. Instead of maintaining multiple database drivers that were all nearly identical, these drivers have been unified into a single set of ODBC functions.
The following databases are supported by the Unified ODBC functions: Adabas D, IBM DB2, iODBC, Solid, and Sybase SQL Anywhere.
Óçìåßùóç: There is no ODBC involved when connecting to the above databases. The functions that you use to speak natively to them just happen to share the same names and syntax as the ODBC functions. The exception to this is iODBC. Building PHP with iODBC support enables you to use any ODBC-compliant drivers with your PHP applications. iODBC is maintained by OpenLink Software. More information on iODBC, as well as a HOWTO, is available at www.iodbc.org.
To access any of the supported databases you need to have the required libraries installed.
Include Adabas D support. DIR is the Adabas base install directory, defaults to /usr/local.
Include SAP DB support. DIR is SAP DB base install directory, defaults to /usr/local.
Include Solid support. DIR is the Solid base install directory, defaults to /usr/local/solid.
Include IBM DB2 support. DIR is the DB2 base install directory, defaults to /home/db2inst1/sqllib.
Include Empress support. DIR is the Empress base install directory, defaults to $EMPRESSPATH. From PHP 4, this option only supports Empress Version 8.60 and above.
Include Empress Local Access support. DIR is the Empress base install directory, defaults to $EMPRESSPATH. From PHP 4, this option only supports Empress Version 8.60 and above.
Include Birdstep support. DIR is the Birdstep base install directory, defaults to /usr/local/birdstep.
Include a user defined ODBC support. The DIR is ODBC install base directory, which defaults to /usr/local. Make sure to define CUSTOM_ODBC_LIBS and have some odbc.h in your include dirs. E.g., you should define following for Sybase SQL Anywhere 5.5.00 on QNX, prior to run configure script: CPPFLAGS="-DODBC_QNX -DSQLANY_BUG" LDFLAGS=-lunix CUSTOM_ODBC_LIBS="-ldblib -lodbc".
Include iODBC support. DIR is the iODBC base install directory, defaults to /usr/local.
Include Easysoft OOB support. DIR is the OOB base install directory, defaults to /usr/local/easysoft/oob/client.
Include unixODBC support. DIR is the unixODBC base install directory, defaults to /usr/local.
Include OpenLink ODBC support. DIR is the OpenLink base install directory, defaults to /usr/local. This is the same as iODBC.
Include DBMaker support. DIR is the DBMaker base install directory, defaults to where the latest version of DBMaker is installed (such as /home/dbmaker/3.6).
To disable unified ODBC support in PHP 3 add --disable-unified-odbc to your configure line. Only applicable if iODBC, Adabas, Solid, Velocis or a custom ODBC interface is enabled.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Unified ODBC Configuration Options
Name | Default | Changeable |
---|---|---|
odbc.default_db * | NULL | PHP_INI_ALL |
odbc.default_user * | NULL | PHP_INI_ALL |
odbc.default_pw * | NULL | PHP_INI_ALL |
odbc.allow_persistent | "1" | PHP_INI_SYSTEM |
odbc.check_persistent | "1" | PHP_INI_SYSTEM |
odbc.max_persistent | "-1" | PHP_INI_SYSTEM |
odbc.max_links | "-1" | PHP_INI_SYSTEM |
odbc.defaultlrl | "4096" | PHP_INI_ALL |
odbc.defaultbinmode | "1" | PHP_INI_ALL |
Óçìåßùóç: Entries marked with * are not implemented yet.
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
ODBC data source to use if none is specified in odbc_connect() or odbc_pconnect().
User name to use if none is specified in odbc_connect() or odbc_pconnect().
Password to use if none is specified in odbc_connect() or odbc_pconnect().
Whether to allow persistent ODBC connections.
Check that a connection is still valid before reuse.
The maximum number of persistent ODBC connections per process.
The maximum number of ODBC connections per process, including persistent connections.
Handling of LONG fields. Specifies the number of bytes returned to variables.
Handling of binary data.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Without the OnOff parameter, this function returns auto-commit status for connection_id. TRUE is returned if auto-commit is on, FALSE if it is off or an error occurs.
If OnOff is TRUE, auto-commit is enabled, if it is FALSE auto-commit is disabled. Returns TRUE on success, FALSE on failure.
By default, auto-commit is on for a connection. Disabling auto-commit is equivalent with starting a transaction.
See also odbc_commit() and odbc_rollback().
(ODBC SQL types affected: BINARY, VARBINARY, LONGVARBINARY)
ODBC_BINMODE_PASSTHRU: Passthru BINARY data
ODBC_BINMODE_RETURN: Return as is
ODBC_BINMODE_CONVERT: Convert to char and return
When binary SQL data is converted to character C data, each byte (8 bits) of source data is represented as two ASCII characters. These characters are the ASCII character representation of the number in its hexadecimal form. For example, a binary 00000001 is converted to "01" and a binary 11111111 is converted to "FF".
Ðßíáêáò 1. LONGVARBINARY handling
binmode | longreadlen | result |
---|---|---|
ODBC_BINMODE_PASSTHRU | 0 | passthru |
ODBC_BINMODE_RETURN | 0 | passthru |
ODBC_BINMODE_CONVERT | 0 | passthru |
ODBC_BINMODE_PASSTHRU | 0 | passthru |
ODBC_BINMODE_PASSTHRU | >0 | passthru |
ODBC_BINMODE_RETURN | >0 | return as is |
ODBC_BINMODE_CONVERT | >0 | return as char |
If odbc_fetch_into() is used, passthru means that an empty string is returned for these columns.
If result_id is 0, the settings apply as default for new results.
Óçìåßùóç: Default for longreadlen is 4096 and binmode defaults to ODBC_BINMODE_RETURN. Handling of binary long columns is also affected by odbc_longreadlen()
odbc_close_all() will close down all connections to database server(s).
Óçìåßùóç: This function will fail if there are open transactions on a connection. This connection will remain open in this case.
odbc_close() will close down the connection to the database server associated with the given connection identifier.
Óçìåßùóç: This function will fail if there are open transactions on this connection. The connection will remain open in this case.
(PHP 4 , PHP 5)
odbc_columnprivileges -- Returns a result identifier that can be used to fetch a list of columns and associated privilegesLists columns and associated privileges for the given table. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
TABLE_QUALIFIER
TABLE_OWNER
TABLE_NAME
GRANTOR
GRANTEE
PRIVILEGE
IS_GRANTABLE
The result set is ordered by TABLE_QUALIFIER, TABLE_OWNER and TABLE_NAME.
The column_name argument accepts search patterns ('%' to match zero or more characters and '_' to match a single character).
(PHP 4 , PHP 5)
odbc_columns -- Lists the column names in specified tables. Returns a result identifier containing the information.Lists all columns in the requested range. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
TABLE_QUALIFIER
TABLE_SCHEM
TABLE_NAME
COLUMN_NAME
DATA_TYPE
TYPE_NAME
PRECISION
LENGTH
SCALE
RADIX
NULLABLE
REMARKS
The result set is ordered by TABLE_QUALIFIER, TABLE_SCHEM and TABLE_NAME.
The schema, table_name and column_name arguments accept search patterns ('%' to match zero or more characters and '_' to match a single character).
See also odbc_columnprivileges() to retrieve associated privileges.
odbc_commit() commits all pending transactions on the connection_id connection. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Returns an ODBC connection id or 0 (FALSE) on error.
The connection id returned by this functions is needed by other ODBC functions. You can have multiple connections open at once as long as they either use different db or different credentials. The optional fourth parameter sets the type of cursor to be used for this connection. This parameter is not normally needed, but can be useful for working around problems with some ODBC drivers.
With some ODBC drivers, executing a complex stored procedure may fail with an error similar to: "Cannot open a cursor on a stored procedure that has anything other than a single select statement in it". Using SQL_CUR_USE_ODBC may avoid that error. Also, some drivers don't support the optional row_number parameter in odbc_fetch_row(). SQL_CUR_USE_ODBC might help in that case, too.
The following constants are defined for cursortype:
SQL_CUR_USE_IF_NEEDED
SQL_CUR_USE_ODBC
SQL_CUR_USE_DRIVER
SQL_CUR_DEFAULT
For persistent connections see odbc_pconnect().
odbc_cursor will return a cursorname for the given result_id.
Returns FALSE on error, and an array upon success.
This function will return information about the active connection following the information from within the DSN. The connection_id is required to be a valid ODBC connection. The fetch_type can be one of two constant types: SQL_FETCH_FIRST, SQL_FETCH_NEXT. Use SQL_FETCH_FIRST the first time this function is called, thereafter use the SQL_FETCH_NEXT.
odbc_do() will execute a query on the given connection.
Returns a six-digit ODBC state, or an empty string if there has been no errors. If connection_id is specified, the last state of that connection is returned, else the last state of any connection is returned.
See also: odbc_errormsg() and odbc_exec().
Returns a string containing the last ODBC error message, or an empty string if there has been no errors. If connection_id is specified, the last state of that connection is returned, else the last state of any connection is returned.
See also: odbc_error() and odbc_exec().
Returns FALSE on error. Returns an ODBC result identifier if the SQL command was executed successfully.
odbc_exec() will send an SQL statement to the database server specified by connection_id. This parameter must be a valid identifier returned by odbc_connect() or odbc_pconnect().
See also: odbc_prepare() and odbc_execute() for multiple execution of SQL statements.
Executes a statement prepared with odbc_prepare().ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. The array parameters_array only needs to be given if you really have parameters in your statement.
Parameters in parameter_array will be substituted for placeholders in the prepared statement in order.
Any parameters in parameter_array which start and end with single quotes will be taken as the name of a file to read and send to the database server as the data for the appropriate placeholder.
Óçìåßùóç: As of PHP 4.1.1, this file reading functionality has the following restrictions:
File reading is not subject to any safe mode or open-basedir restrictions. This is fixed in PHP 4.2.0.
Remote files are not supported.
If you wish to store a string which actually begins and ends with single quotes, you must escape them or add a space or other non-single-quote character to the beginning or end of the parameter, which will prevent the parameter's being taken as a file name. If this is not an option, then you must use another mechanism to store the string, such as executing the query directly with odbc_exec()).
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns the number of columns in the result; FALSE on error. result_array must be passed by reference, but it can be of any type since it will be converted to type array. The array will contain the column values starting at array index 0.
As of PHP 4.0.5 the result_array does not need to be passed by reference any longer.
As of PHP 4.0.6 the rownumber cannot be passed as a constant, but rather as a variable.
As of PHP 4.2.0 the result_array and rownumber have been swapped. This allows the rownumber to be a constant again. This change will also be the last one to this function.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
If odbc_fetch_row() was successful (there was a row), TRUE is returned. If there are no more rows, FALSE is returned.
odbc_fetch_row() fetches a row of the data that was returned by odbc_do() / odbc_exec(). After odbc_fetch_row() is called, the fields of that row can be accessed with odbc_result().
If row_number is not specified, odbc_fetch_row() will try to fetch the next row in the result set. Calls to odbc_fetch_row() with and without row_number can be mixed.
To step through the result more than once, you can call odbc_fetch_row() with row_number 1, and then continue doing odbc_fetch_row() without row_number to review the result. If a driver doesn't support fetching rows by number, the row_number parameter is ignored.
odbc_field_len() will return the length of the field referenced by number in the given ODBC result identifier. Field numbering starts at 1.
See also: odbc_field_scale() to get the scale of a floating point number.
odbc_field_name() will return the name of the field occupying the given column number in the given ODBC result identifier. Field numbering starts at 1. FALSE is returned on error.
odbc_field_num() will return the number of the column slot that corresponds to the named field in the given ODBC result identifier. Field numbering starts at 1. FALSE is returned on error.
odbc_field_precision() will return the precision of the field referenced by number in the given ODBC result identifier.
See also: odbc_field_scale() to get the scale of a floating point number.
odbc_field_precision() will return the scale of the field referenced by number in the given ODBC result identifier.
odbc_field_type() will return the SQL type of the field referenced by number in the given ODBC result identifier. Field numbering starts at 1.
(PHP 4 , PHP 5)
odbc_foreignkeys -- Returns a list of foreign keys in the specified table or a list of foreign keys in other tables that refer to the primary key in the specified tableodbc_foreignkeys() retrieves information about foreign keys. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
PKTABLE_QUALIFIER
PKTABLE_OWNER
PKTABLE_NAME
PKCOLUMN_NAME
FKTABLE_QUALIFIER
FKTABLE_OWNER
FKTABLE_NAME
FKCOLUMN_NAME
KEY_SEQ
UPDATE_RULE
DELETE_RULE
FK_NAME
PK_NAME
If pk_table contains a table name, odbc_foreignkeys() returns a result set containing the primary key of the specified table and all of the foreign keys that refer to it.
If fk_table contains a table name, odbc_foreignkeys() returns a result set containing all of the foreign keys in the specified table and the primary keys (in other tables) to which they refer.
If both pk_table and fk_table contain table names, odbc_foreignkeys() returns the foreign keys in the table specified in fk_table that refer to the primary key of the table specified in pk_table. This should be one key at most.
Always returns TRUE.
odbc_free_result() only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script is finished. But, if you are sure you are not going to need the result data anymore in a script, you may call odbc_free_result(), and the memory associated with result_id will be freed.
Óçìåßùóç: If auto-commit is disabled (see odbc_autocommit()) and you call odbc_free_result() before committing, all pending transactions are rolled back.
(PHP 4 , PHP 5)
odbc_gettypeinfo -- Returns a result identifier containing information about data types supported by the data source.Retrieves information about data types supported by the data source. Returns an ODBC result identifier or FALSE on failure. The optional argument data_type can be used to restrict the information to a single data type.
The result set has the following columns:
TYPE_NAME
DATA_TYPE
PRECISION
LITERAL_PREFIX
LITERAL_SUFFIX
CREATE_PARAMS
NULLABLE
CASE_SENSITIVE
SEARCHABLE
UNSIGNED_ATTRIBUTE
MONEY
AUTO_INCREMENT
LOCAL_TYPE_NAME
MINIMUM_SCALE
MAXIMUM_SCALE
The result set is ordered by DATA_TYPE and TYPE_NAME.
(ODBC SQL types affected: LONG, LONGVARBINARY) The number of bytes returned to PHP is controlled by the parameter length. If it is set to 0, Long column data is passed through to the client.
Óçìåßùóç: Handling of LONGVARBINARY columns is also affected by odbc_binmode().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
odbc_num_fields() will return the number of fields (columns) in an ODBC result. This function will return -1 on error. The argument is a valid result identifier returned by odbc_exec().
odbc_num_rows() will return the number of rows in an ODBC result. This function will return -1 on error. For INSERT, UPDATE and DELETE statements odbc_num_rows() returns the number of rows affected. For a SELECT clause this can be the number of rows available.
Note: Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers.
Returns an ODBC connection id or 0 (FALSE) on error. This function is much like odbc_connect(), except that the connection is not really closed when the script has finished. Future requests for a connection with the same dsn, user, password combination (via odbc_connect() and odbc_pconnect()) can reuse the persistent connection.
Óçìåßùóç: Persistent connections have no effect if PHP is used as a CGI program.
For information about the optional cursor_type parameter see the odbc_connect() function. For more information on persistent connections, refer to the PHP FAQ.
Returns FALSE on error.
Returns an ODBC result identifier if the SQL command was prepared successfully. The result identifier can be used later to execute the statement with odbc_execute().
(PHP 4 , PHP 5)
odbc_primarykeys -- Returns a result identifier that can be used to fetch the column names that comprise the primary key for a tableReturns the column names that comprise the primary key for a table. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
TABLE_QUALIFIER
TABLE_OWNER
TABLE_NAME
COLUMN_NAME
KEY_SEQ
PK_NAME
Returns the list of input and output parameters, as well as the columns that make up the result set for the specified procedures. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
PROCEDURE_QUALIFIER
PROCEDURE_OWNER
PROCEDURE_NAME
COLUMN_NAME
COLUMN_TYPE
DATA_TYPE
TYPE_NAME
PRECISION
LENGTH
SCALE
RADIX
NULLABLE
REMARKS
The result set is ordered by PROCEDURE_QUALIFIER, PROCEDURE_OWNER, PROCEDURE_NAME and COLUMN_TYPE.
The owner, proc and column arguments accept search patterns ('%' to match zero or more characters and '_' to match a single character).
(PHP 4 , PHP 5)
odbc_procedures -- Get the list of procedures stored in a specific data source. Returns a result identifier containing the information.Lists all procedures in the requested range. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
PROCEDURE_QUALIFIER
PROCEDURE_OWNER
PROCEDURE_NAME
NUM_INPUT_PARAMS
NUM_OUTPUT_PARAMS
NUM_RESULT_SETS
REMARKS
PROCEDURE_TYPE
The owner and name arguments accept search patterns ('%' to match zero or more characters and '_' to match a single character).
Returns the number of rows in the result or FALSE on error.
odbc_result_all() will print all rows from a result identifier produced by odbc_exec(). The result is printed in HTML table format. With the optional string argument format, additional overall table formatting can be done.
Returns the contents of the field.
field can either be an integer containing the column number of the field you want; or it can be a string containing the name of the field. For example:
The first call to odbc_result() returns the value of the third field in the current record of the query result. The second function call to odbc_result() returns the value of the field whose field name is "val" in the current record of the query result. An error occurs if a column number parameter for a field is less than one or exceeds the number of columns (or fields) in the current record. Similarly, an error occurs if a field with a name that is not one of the fieldnames of the table(s) that is(are) being queried.
Field indices start from 1. Regarding the way binary or long column data is returned refer to odbc_binmode() and odbc_longreadlen().
Rolls back all pending statements on connection_id. Returns TRUE on success, FALSE on failure.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
odbc_setoption -- Adjust ODBC settings. Returns FALSE if an error occurs, otherwise TRUE.This function allows fiddling with the ODBC options for a particular connection or query result. It was written to help find work around to problems in quirky ODBC drivers. You should probably only use this function if you are an ODBC programmer and understand the effects the various options will have. You will certainly need a good ODBC reference to explain all the different options and values that can be used. Different driver versions support different options.
Because the effects may vary depending on the ODBC driver, use of this function in scripts to be made publicly available is strongly discouraged. Also, some ODBC options are not available to this function because they must be set before the connection is established or the query is prepared. However, if on a particular job it can make PHP work so your boss doesn't tell you to use a commercial product, that's all that really matters.
id is a connection id or result id on which to change the settings.For SQLSetConnectOption(), this is a connection id. For SQLSetStmtOption(), this is a result id.
Function is the ODBC function to use. The value should be 1 for SQLSetConnectOption() and 2 for SQLSetStmtOption().
Parameter option is the option to set.
Parameter param is the value for the given option.
ÐáñÜäåéãìá 1. ODBC Setoption Examples
|
(PHP 4 , PHP 5)
odbc_specialcolumns -- Returns either the optimal set of columns that uniquely identifies a row in the table or columns that are automatically updated when any value in the row is updated by a transactionWhen the type argument is SQL_BEST_ROWID, odbc_specialcolumns() returns the column or columns that uniquely identify each row in the table.
When the type argument is SQL_ROWVER, odbc_specialcolumns() returns the optimal column or set of columns that, by retrieving values from the column or columns, allows any row in the specified table to be uniquely identified.
Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
SCOPE
COLUMN_NAME
DATA_TYPE
TYPE_NAME
PRECISION
LENGTH
SCALE
PSEUDO_COLUMN
The result set is ordered by SCOPE.
Get statistics about a table and its indexes. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
TABLE_QUALIFIER
TABLE_OWNER
TABLE_NAME
NON_UNIQUE
INDEX_QUALIFIER
INDEX_NAME
TYPE
SEQ_IN_INDEX
COLUMN_NAME
COLLATION
CARDINALITY
PAGES
FILTER_CONDITION
The result set is ordered by NON_UNIQUE, TYPE, INDEX_QUALIFIER, INDEX_NAME and SEQ_IN_INDEX.
Lists tables in the requested range and the privileges associated with each table. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
TABLE_QUALIFIER
TABLE_OWNER
TABLE_NAME
GRANTOR
GRANTEE
PRIVILEGE
IS_GRANTABLE
The result set is ordered by TABLE_QUALIFIER, TABLE_OWNER and TABLE_NAME.
The owner and name arguments accept search patterns ('%' to match zero or more characters and '_' to match a single character).
(PHP 3>= 3.0.17, PHP 4 , PHP 5)
odbc_tables -- Get the list of table names stored in a specific data source. Returns a result identifier containing the information.Lists all tables in the requested range. Returns an ODBC result identifier or FALSE on failure.
The result set has the following columns:
TABLE_QUALIFIER
TABLE_OWNER
TABLE_NAME
TABLE_TYPE
REMARKS
The result set is ordered by TABLE_TYPE, TABLE_QUALIFIER, TABLE_OWNER and TABLE_NAME.
The owner and name arguments accept search patterns ('%' to match zero or more characters and '_' to match a single character).
To support enumeration of qualifiers, owners, and table types, the following special semantics for the qualifier, owner, name, and table_type are available:
If qualifier is a single percent character (%) and owner and name are empty strings, then the result set contains a list of valid qualifiers for the data source. (All columns except the TABLE_QUALIFIER column contain NULLs.)
If owner is a single percent character (%) and qualifier and name are empty strings, then the result set contains a list of valid owners for the data source. (All columns except the TABLE_OWNER column contain NULLs.)
If table_type is a single percent character (%) and qualifier, owner and name are empty strings, then the result set contains a list of valid table types for the data source. (All columns except the TABLE_TYPE column contain NULLs.)
If table_type is not an empty string, it must contain a list of comma-separated values for the types of interest; each value may be enclosed in single quotes (') or unquoted. For example, "'TABLE','VIEW'" or "TABLE, VIEW". If the data source does not support a specified table type, odbc_tables() does not return any results for that type.
See also odbc_tableprivileges() to retrieve associated privileges.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
In Object Oriented Programming, it is common to see the composition of simple classes (and/or instances) into a more complex one. This is a flexible strategy for building complicated objects and object hierarchies and can function as a dynamic alternative to multiple inheritance. There are two ways to perform class (and/or object) composition depending on the relationship between the composed elements: Association and Aggregation.
An Association is a composition of independently constructed and externally visible parts. When we associate classes or objects, each one keeps a reference to the ones it is associated with. When we associate classes statically, one class will contain a reference to an instance of the other class. For example:
ÐáñÜäåéãìá 1. Class association
|
ÐáñÜäåéãìá 2. Object association
|
Aggregation, on the other hand, implies encapsulation (hidding) of the parts of the composition. We can aggregate classes by using a (static) inner class (PHP does not yet support inner classes), in this case the aggregated class definition is not accessible, except through the class that contains it. The aggregation of instances (object aggregation) involves the dynamic creation of subobjects inside an object, in the process, expanding the properties and methods of that object.
Object aggregation is a natural way of representing a whole-part relationship, (for example, molecules are aggregates of atoms), or can be used to obtain an effect equivalent to multiple inheritance, without having to permanently bind a subclass to two or more parent classes and their interfaces. In fact object aggregation can be more flexible, in which we can select what methods or properties to "inherit" in the aggregated object.
We define 3 classes, each implementing a different storage method:
ÐáñÜäåéãìá 3. storage_classes.inc
|
We then instantiate a couple of objects from the defined classes, and perform some aggregations and deaggregations, printing some object information along the way:
ÐáñÜäåéãìá 4. test_aggregation.php
|
We will now consider the output to understand some of the side-effects and limitation of object aggregation in PHP. First, the newly created $fs and $ws objects give the expected output (according to their respective class declaration). Note that for the purposes of object aggregation, private elements of a class/object begin with an underscore character ("_"), even though there is not real distinction between public and private class/object elements in PHP.
$fs object Class: filestorage property: data (array) 0 => 3.1415926535898 1 => kludge != cruft method: filestorage method: write $ws object Class: wddxstorage property: data (array) 0 => 3.1415926535898 1 => kludge != cruft property: version = 1.0 property: _id = ID::9bb2b640764d4370eb04808af8b076a5 method: wddxstorage method: store method: _genid |
We then aggregate $fs with the WDDXStorage class, and print out the object information. We can see now that even though nominally the $fs object is still of FileStorage, it now has the property $version, and the method store(), both defined in WDDXStorage. One important thing to note is that it has not aggregated the private elements defined in the class, which are present in the $ws object. Also absent is the constructor from WDDXStorage, which will not be logical to aggegate.
Let's aggregate $fs to the WDDXStorage class $fs object Class: filestorage property: data (array) 0 => 3.1415926535898 1 => kludge != cruft property: version = 1.0 method: filestorage method: write method: store |
The proccess of aggregation is cummulative, so when we aggregate $fs with the class DBStorage, generating an object that can use the storage methods of all the defined classes.
Now let us aggregate it to the DBStorage class $fs object Class: filestorage property: data (array) 0 => 3.1415926535898 1 => kludge != cruft property: version = 1.0 property: dbtype = mysql method: filestorage method: write method: store method: save |
Finally, the same way we aggregated properties and methods dynamically, we can also deaggregate them from the object. So, if we deaggregate the class WDDXStorage from $fs, we will obtain:
And deaggregate the WDDXStorage methods and properties $fs object Class: filestorage property: data (array) 0 => 3.1415926535898 1 => kludge != cruft property: dbtype = mysql method: filestorage method: write method: save |
One point that we have not mentioned above, is that the process of aggregation will not override existing properties or methods in the objects. For example, the class FileStorage defines a $data property, and the class WDDXStorage also defines a similar property which will not override the one in the object acquired during instantiation from the class FileStorage.
(no version information, might be only in CVS)
aggregate_info -- Returns an associative array of the methods and properties from each class that has been aggregated to the object.Will return the aggregation information for a particular object as an associative array of arrays of methods and properties. The key for the main array is the name of the aggregated class.
For example the code below
ÐáñÜäåéãìá 1. Using aggregate_info()
Will produce the output
|
See also aggregate(), aggregate_methods(), aggregate_methods_by_list(), aggregate_methods_by_regexp(), aggregate_properties(), aggregate_properties_by_list(), aggregate_properties_by_regexp(), deaggregate()
(PHP 4 >= 4.2.0)
aggregate_methods_by_list -- Selective dynamic class methods aggregation to an objectAggregates methods from a class to an existing object using a list of method names. The optional paramater exclude is used to decide whether the list contains the names of methods to include in the aggregation (i.e. exclude is FALSE, which is the default value), or to exclude from the aggregation (exclude is TRUE).
The class constructor or methods whose names start with an underscore character (_), which are considered private to the aggregated class, are always excluded.
See also aggregate(), aggregate_info(), aggregate_methods(), aggregate_methods_by_regexp(), aggregate_properties(), aggregate_properties_by_list(), aggregate_properties_by_regexp(), deaggregate()
(PHP 4 >= 4.2.0)
aggregate_methods_by_regexp -- Selective class methods aggregation to an object using a regular expressionAggregates methods from a class to an existing object using a regular expresion to match method names. The optional paramater exclude is used to decide whether the regular expression will select the names of methods to include in the aggregation (i.e. exclude is FALSE, which is the default value), or to exclude from the aggregation (exclude is TRUE).
The class constructor or methods whose names start with an underscore character (_), which are considered private to the aggregated class, are always excluded.
See also aggregate(), aggregate_info(), aggregate_methods(), aggregate_methods_by_list(), aggregate_properties(), aggregate_properties_by_list(), aggregate_properties_by_regexp(), deaggregate()
Aggregates all methods defined in a class to an existing object, except for the class constructor, or methods whose names start with an underscore character (_) which are considered private to the aggregated class.
See also aggregate(), aggregate_info(), aggregate_methods_by_list(), aggregate_methods_by_regexp(), aggregate_properties(), aggregate_properties_by_list(), aggregate_properties_by_regexp(), deaggregate()
(PHP 4 >= 4.2.0)
aggregate_properties_by_list -- Selective dynamic class properties aggregation to an objectAggregates properties from a class to an existing object using a list of property names. The optional paramater exclude is used to decide whether the list contains the names of class properties to include in the aggregation (i.e. exclude is FALSE, which is the default value), or to exclude from the aggregation (exclude is TRUE).
The properties whose names start with an underscore character (_), which are considered private to the aggregated class, are always excluded.
See also aggregate(), aggregate_methods(), aggregate_methods_by_list(), aggregate_methods_by_regexp(), aggregate_properties(), aggregate_properties_by_regexp(), aggregate_info(), deaggregate()
(PHP 4 >= 4.2.0)
aggregate_properties_by_regexp -- Selective class properties aggregation to an object using a regular expressionAggregates properties from a class to an existing object using a regular expresion to match their names. The optional paramater exclude is used to decide whether the regular expression will select the names of class properties to include in the aggregation (i.e. exclude is FALSE, which is the default value), or to exclude from the aggregation (exclude is TRUE).
The properties whose names start with an underscore character (_), which are considered private to the aggregated class, are always excluded.
See also aggregate(), aggregate_methods(), aggregate_methods_by_list(), aggregate_methods_by_regexp(), aggregate_properties(), aggregate_properties_by_list(), aggregate_info(), deaggregate()
Aggregates all properties defined in a class to an existing object, except for properties whose names start with an underscore character (_) which are considered private to the aggregated class.
See also aggregate(), aggregate_methods(), aggregate_methods_by_list(), aggregate_methods_by_regexp(), aggregate_properties_by_list(), aggregate_properties_by_regexp(), aggregate_info(), deaggregate()
Aggregates methods and properties defined in a class to an existing object. Methods and properties with names starting with an underscore character (_) are considered private to the aggregated class and are not used, constructors are also excluded from the aggregation procedure.
See also aggregate_info(), aggregate_methods(), aggregate_methods_by_list(), aggregate_methods_by_regexp(), aggregate_properties(), aggregate_properties_by_list(), aggregate_properties_by_regexp(), deaggregate()
Removes the methods and properties from classes that were aggregated to an object. If the optional class_name parameters is passed, only those methods and properties defined in that class are removed, otherwise all aggregated methods and properties are eliminated.
See also aggregate(), aggregate_methods(), aggregate_methods_by_list(), aggregate_methods_by_regexp(), aggregate_properties(), aggregate_properties_by_list(), aggregate_properties_by_regexp(), aggregate_info()
These functions allow you to access Oracle9, Oracle8 and Oracle7 databases. It uses the Oracle Call Interface (OCI).
This extension is more flexible than the old Oracle extension. It supports binding of global and local PHP variables to Oracle placeholders, has full LOB, FILE and ROWID support and allows you to use user-supplied define variables. You are recommended to use this extension instead of old Oracle extension where possible.
You will need the Oracle client libraries to use this extension. Windows users will need at least Oracle version 8.1 to use the php_oci8.dll dll.
Before using this extension, make sure that you have set up your Oracle environment variables properly for the Oracle user, as well as your web daemon user. The variables you might need to set are as follows:
ORACLE_HOME
ORACLE_SID
LD_PRELOAD
LD_LIBRARY_PATH
NLS_LANG
ORA_NLS33
After setting up the environment variables for your webserver user, be sure to also add the webserver user (nobody, www) to the oracle group.
If your webserver doesn't start or crashes at startup: Check that Apache is linked with the pthread library:
# ldd /www/apache/bin/httpd libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000) libm.so.6 => /lib/libm.so.6 (0x4002f000) libcrypt.so.1 => /lib/libcrypt.so.1 (0x4004c000) libdl.so.2 => /lib/libdl.so.2 (0x4007a000) libc.so.6 => /lib/libc.so.6 (0x4007e000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)If the libpthread is not listed you have to reinstall Apache:
Please note that on some systems like UnixWare it is libthread instead of libpthread. PHP and Apache have to be configured with EXTRA_LIBS=-lthread.
You have to compile PHP with the option --with-oci8[=DIR], where DIR defaults to your environment variable ORACLE_HOME.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Statement execution mode. Statement is not committed automatically when using this mode.
Statement execution mode. Use this mode if you don't want to really execute query, but only get select-list description.
Statement execution mode. Statement is automatically commited after oci_execute() call.
Statement fetch mode. Used when the application knows in advance exactly how many rows it will be fetching. This mode turns prefetching off for Oracle release 8 or later mode. Cursor is cancelled after the desired rows are fetched and may result in reduced server-side resource usage.
Used with oci_bind_by_name() when binding BFILEs.
Used with oci_bind_by_name() when binding CFILEs.
Used with oci_bind_by_name() when binding CLOBs.
Used with oci_bind_by_name() when binding BLOBs.
Used with oci_bind_by_name() when binding ROWIDs.
Used with oci_bind_by_name() when binding cursors, previously allocated with oci_new_descriptor().
Used with oci_bind_by_name() when binding named data types.
The same as OCI_B_BFILE.
The same as OCI_B_CFILEE.
The same as OCI_B_CLOB.
The same as OCI_B_BLOB.
The same as OCI_B_ROWID.
The same as OCI_B_NTY.
Default mode of oci_fetch_all().
Alternative mode of oci_fetch_all().
Used with oci_fetch_all() and oci_fetch_array() to get an associative array as a result.
Used with oci_fetch_all() and oci_fetch_array() to get an enumerated array as a result.
Used with oci_fetch_all() and oci_fetch_array() to get an array with both associative and number indices.
Used with oci_fetch_array() to get empty array elements if field's value is NULL.
Used with oci_fetch_array() to get value of LOB instead of the descriptor.
This flag tells oci_new_descriptor() to initialize new FILE descriptor.
This flag tells oci_new_descriptor() to initialize new LOB descriptor.
This flag tells oci_new_descriptor() to initialize new ROWID descriptor.
The same as OCI_DTYPE_FILE.
The same as OCI_DTYPE_LOB.
The same as OCI_DTYPE_ROWID.
ÐáñÜäåéãìá 1. OCI Hints
|
You can easily access stored procedures in the same way as you would from the commands line.
ÐáñÜäåéãìá 2. Using Stored Procedures
|
oci_bind_by_name() binds the PHP variable variable to the Oracle placeholder ph_name. Whether it will be used for input or output will be determined at run-time and the necessary storage space will be allocated. The length parameter sets the maximum length for the bind. If you set length to -1 oci_bind_by_name() will use the current length of variable to set the maximum length.
If you need to bind an abstract datatype (LOB/ROWID/BFILE) you need to allocate it first using the oci_new_descriptor() function. The length is not used for abstract datatypes and should be set to -1. The type parameter tells Oracle which descriptor is used. Possible values are:
OCI_B_FILE - for BFILEs;
OCI_B_CFILE - for CFILEs;
OCI_B_CLOB - for CLOBs;
OCI_B_BLOB - for BLOBs;
OCI_B_ROWID - for ROWIDs;
OCI_B_NTY - for named datatypes;
OCI_B_CURSOR - for cursors, that were created before with oci_new_cursor().
ÐáñÜäåéãìá 1. oci_bind_by_name()example
|
Remember, that this function strips trailing whitespace. See the following example:
ÐáñÜäåéãìá 2. oci_bind_by_name() example
|
ÐáñÜäåéãìá 3. oci_bind_by_name() example
|
Ðñïåéäïðïßçóç |
Do not use magic_quotes_gpc or addslashes() and oci_bind_by_name() simultaneously as no quoting is needed and any magically applied quotes will be written into your database as oci_bind_by_name() is not able to distinguish magically added quotings from those added intentionally. |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocibindbyname() instead. This name still can be used, it was left as alias of oci_bind_by_name() for downwards compatability. This, however, is deprecated and not recommended.
oci_cancel() invalidates a cursor, freeing all associated resources and cancels the ability to read from it.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
In PHP versions before 5.0.0 you must use ocicancel() instead. This name still can be used, it was left as alias of oci_cancel() for downwards compatability. This, however, is deprecated and not recommended.
oci_close() closes the Oracle connection connection.
Óçìåßùóç: As non-persistent links are closed automatically at the end of script execution, calling this function is not required. Because of this and the method the extension uses to handle connection resources, oci_close() currently provides no actual functionality.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociclose() instead. This name still can be used, it was left as alias of oci_close() for downwards compatability. This, however, is deprecated and not recommended.
(no version information, might be only in CVS)
collection->append -- Appends an object to the collectionAppends an object to the end of the collection. Parameter value can be a string or a number.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(no version information, might be only in CVS)
collection->assign -- Assigns a value to the collection from another existing collectionAssigns a value to the collection from another, previously created collection. Both collections must be created with oci_new_collection() prior to using them.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(no version information, might be only in CVS)
collection->assignElem -- Assigns a value to the element of the collectionAssigns a value to the element with index index. Parameter value can be a string or a number.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Method collection->getElem() returns value of the element with index index (1-based).
collection->getElem() will return FALSE if such element doesn't exist; NULL if element is NULL; string if element is column of a string datatype or number if element is numeric field.
collection->getElem() will return FALSE in case of error.
(no version information, might be only in CVS)
collection->max -- Gets the maximum number of elements in the collectionReturns the maximum number of elements in the collection. If the returned value is 0, then the number of elements is not limited. collection->max() returns FALSE in case of error.
See also oci_collection_size().
Returns the number of elements in the collection.
See also oci_collection_max().
(no version information, might be only in CVS)
collection->trim -- Trims elements from the end of the collectionTrims num of elements from the end of the collection.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also oci_collection_size().
oci_commit() commits all outstanding statements for the active transaction on the Oracle connection connection.
ÐáñÜäåéãìá 1. oci_commit() example
|
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicommit() instead. This name still can be used, it was left as alias of oci_commit() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_rollback() and oci_execute().
oci_connect() returns a connection identifier needed for most other OCI calls. The optional third parameter can either contain the name of the local Oracle instance or the name of the entry in tnsnames.ora to which you want to connect. If the optional third parameter is not specified, PHP uses the environment variables ORACLE_SID (Oracle instance) or TWO_TASK (tnsnames.ora) to determine which database to connect to.
Óçìåßùóç: oci_connect() does not reestablish the connection, if a connection with such parameters was established before. In this case, oci_connect() will return identifier of previously opened connection. This means, that you cannot use this function to separate transactions. To establish a distinctly new connection, use oci_new_connect().
ÐáñÜäåéãìá 1. oci_connect() example
|
oci_connect() returns FALSE if an error occured.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocilogon() instead. This name still can be used, it was left as alias of oci_connect() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_pconnect() and oci_new_connect().
oci_define_by_name() defines PHP variables for fetches of SQL-Columns. Be careful that Oracle uses ALL-UPPERCASE column names, whereby in your select you can also write lowercase. oci_define_by_name() expects the column_name to be in uppercase. If you define a variable that doesn't exists in your select statement, no error will issued.
If you need to define an abstract datatype (LOB/ROWID/BFILE) you must allocate it first using oci_new_descriptor(). See also the oci_bind_by_name() function.
ÐáñÜäåéãìá 1. oci_define_by_name() example
|
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocidefinebyname() instead. This name still can be used, it was left as alias of oci_define_by_name() for downwards compatability. This, however, is deprecated and not recommended.
oci_error() returns the last error found. If the optional source is not provided, the last error encountered is returned. You can use connection or statement resources as value of parameter source. If no error is found, oci_error() returns FALSE. oci_error() returns the error as an associative array. In this array, code consists the oracle error code and message the oracle error string.
As of PHP 4.3: offset and sqltext will also be included in the return array to indicate the location of the error and the original SQL text which caused it.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocierror() instead. This name still can be used, it was left as alias of oci_error() for downwards compatability. This, however, is deprecated and not recommended.
oci_execute() executes a previously parsed statement (see oci_parse()). The optional mode allows you to specify the execution mode (default is OCI_COMMIT_ON_SUCCESS). If you don't want statements to be committed automatically, you should specify OCI_DEFAULT as your mode.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociexecute() instead. This name still can be used, it was left as alias of oci_execute() for downwards compatability. This, however, is deprecated and not recommended.
oci_fetch_all() fetches all the rows from a result into a user-defined array. oci_fetch_all() returns the number of rows fetched or FALSE in case of error. skip is the number of initial rows to ignore when fetching the result (default value of 0, to start at the first line). maxrows is the number of rows to read, starting at the skipth row (default to -1, meaning all the rows).
Parameter flags can be any combination of the following:
OCI_FETCHSTATEMENT_BY_ROW |
OCI_FETCHSTATEMENT_BY_COLUMN (default value) |
OCI_NUM |
OCI_ASSOC |
ÐáñÜäåéãìá 1. oci_fetch_all() example
|
oci_fetch_all() returns FALSE in case of error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocifetchstatement() instead. This name still can be used, it was left as alias of oci_fetch_all() for downwards compatability. This, however, is deprecated and not recommended.
(PHP 5)
oci_fetch_array -- Returns the next row from the result data as an associative or numeric array, or bothReturns an array, which corresponds to the next result row or FALSE in case of error or there is no more rows in the result.
oci_fetch_array() returns an array with both associative and numeric indices.
Optional second paramater can be any combination of the following constants:
OCI_BOTH - return an array with both associative and numeric indices (the same as OCI_ASSOC + OCI_NUM). This is the default behavior. |
OCI_ASSOC - return an associative array (as oci_fetch_assoc() works). |
OCI_NUM - return a numeric array, (as oci_fetch_row() works). |
OCI_RETURN_NULLS - create empty elements for the NULL fields. |
OCI_RETURN_LOBS - return the value of a LOB of the descriptor. |
It should be mentioned here, that oci_fetch_array() is insignificantly slower, than oci_fetch_row(), but much more handy.
Óçìåßùóç: Don't forget, that Oracle returns all field names in uppercase and associative indices in the result array will be uppercased too.
ÐáñÜäåéãìá 1. oci_fetch_array() with OCI_BOTH example
|
ÐáñÜäåéãìá 2. oci_fetch_array() with OCI_NUM example
|
ÐáñÜäåéãìá 3. oci_fetch_array() with OCI_ASSOC example
|
ÐáñÜäåéãìá 4. oci_fetch_array() with OCI_RETURN_LOBS example
|
See also oci_fetch_assoc(), oci_fetch_object(), oci_fetch_row() and oci_fetch_all().
oci_fetch_assoc() returns the next row from the result data as an associative array (identical to oci_fetch_array() call with OCI_ASSOC flag).
Subsequent call to oci_fetch_assoc() will return next row or FALSE if there is no more rows.
Óçìåßùóç: Don't forget, that Oracle returns all field names in uppercase and associative indices in the result array will be uppercased too.
See also oci_fetch_array(), oci_fetch_object(), oci_fetch_row() and oci_fetch_all().
oci_fetch_object() returns the next row from the result data as an object, which attributes correspond to fields in statement.
Subsequent calls to oci_fetch_object() will return the next row from the result or FALSE if there is no more rows.
Óçìåßùóç: Don't forget, that Oracle returns all field names in uppercase and attributes' names in the result object will be in uppercase as well.
See also oci_fetch_array(), oci_fetch_assoc(), oci_fetch_row() and oci_fetch_all().
Calling oci_fetch_row() is identical to oci_fetch_array() with OCI_NUM flag and returns the next row from the result data as a numeric array.
Subsequent calls to oci_fetch_row() will return the next row from the result data or FALSE if there is no more rows.
See also oci_fetch_array(), oci_fetch_object(), oci_fetch_assoc() and oci_fetch_all().
oci_fetch() fetches the next row (for SELECT statements) into the internal result-buffer.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocifetch() instead. This name still can be used, it was left as alias of oci_fetch() for downwards compatability. This, however, is deprecated and not recommended.
oci_field_is_null() returns TRUE if field field from the statement is NULL. Parameter field could be a field's index or a field's name (uppercased).
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicolumnisnull() instead. This name still can be used, it was left as alias of oci_field_is_null() for downwards compatability. This, however, is deprecated and not recommended.
oci_field_name() returns the name of the field corresponding to the field number (1-based).
ÐáñÜäåéãìá 1. oci_field_name() example
|
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicolumnname() instead. This name still can be used, it was left as alias of oci_field_name() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_num_fields(), oci_field_type(), and oci_field_size().
Returns precision of the field with field index (1-based).
For FLOAT columns, precision is nonzero and scale is -127. If precision is 0, then column is NUMBER. Else it's NUMBER(precision, scale).
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicolumnprecision() instead. This name still can be used, it was left as alias of oci_field_precision() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_field_scale() and oci_field_type().
Returns scale of the column with field index (1-based) or FALSE if there is no such field.
For FLOAT columns, precision is nonzero and scale is -127. If precision is 0, then column is NUMBER. Else it's NUMBER(precision, scale).
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicolumnscale() instead. This name still can be used, it was left as alias of oci_field_scale() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_field_precision() and oci_field_type().
oci_field_size() returns the size of a field in bytes. Value of field parameter can be the field's index (1-based) or it's name.
ÐáñÜäåéãìá 1. oci_field_size()example
|
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicolumnsize() instead. This name still can be used, it was left as alias of oci_field_size() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_num_fields() and oci_field_name().
oci_field_type_raw() returns Oracle's raw data type of the field.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicolumntyperaw() instead. This name still can be used, it was left as alias of oci_field_type_raw() for downwards compatability. This, however, is deprecated and not recommended.
However, if you want to get field's type, then oci_field_type() will suit you better. See oci_field_type() for additional information.
oci_field_type() returns a field's data type. Parameter field is an index of the field in the statement (1-based).
ÐáñÜäåéãìá 1. oci_field_type() example
|
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicolumntype() instead. This name still can be used, it was left as alias of oci_field_type() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_num_fields(), oci_field_name(), and oci_field_size().
(no version information, might be only in CVS)
collection->free -- Frees resources associated with collection objectFrees resources associated with collection object.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(no version information, might be only in CVS)
descriptor->free -- Frees resources associated with descriptordescriptor->free() frees resources associated with descriptor, previously allocated with oci_new_descriptor().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
oci_free_statement() frees resources associated with Oracle's cursor or statement, which was received from as a result of oci_parse() or obtained from Oracle.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
oci_internal_debug() enables or disables internal debug output. Set onoff to 0 to turn debug output off or 1 to turn it on.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociinternaldebug() instead. This name still can be used, it was left as alias of oci_internal_debug() for downwards compatability. This, however, is deprecated and not recommended.
(no version information, might be only in CVS)
lob->append -- Appends data from the large object to another large objectAppends data from the large object to the end of another large object.
Writing to the large object with lob->append() will fail if buffering was previously enabled. You must disable buffering before appending. You may need to flush buffers with oci_lob_flush() before disabling buffering.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also oci_lob_flush(), ocisetbufferinglob() and ocigetbufferinglob().
lob->close() closes descriptor of LOB or FILE. This function should be used only with lob->writeTemporary().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocicloselob() instead. This name still can be used, it was left as alias of oci_lob_close() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_lob_write_temporary().
Copies large object or a part of large object to another large object. Parameter length indicates the length of data to be copied. Old data of LOB-recipient will be overwritten.
If you need to copy a particular part of LOB to a particular position of LOB, you can use oci_lob_seek() to move internal pointers of LOBs.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(no version information, might be only in CVS)
lob->eof -- Tests for end-of-file on a large object's descriptorReturns TRUE if internal pointer of large object is at the end of LOB. Otherwise returns FALSE.
See also oci_lob_size().
(no version information, might be only in CVS)
lob->erase -- Erases a specified portion of the internal LOB dataErases a specified portion of the internal LOB data starting at a specified offset. Parameters length and offset are optional. lob->erase() erases all LOB data by default.
For BLOBs, erasing means that the existing LOB value is overwritten with zero-bytes. For CLOBs, the existing LOB value is overwritten with spaces.
lob->erase() returns the actual number of characters/bytes erased or FALSE in case of error.
Exports LOB's contents to a file, which name is given in parameter filename. Optional parameter start indicates from what position to start export and parameter length - length of data to be exported.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(no version information, might be only in CVS)
lob->flush -- Flushes/writes buffer of the LOB to the serverlob->flush() actually writes data to the server. By default, resources are not freed, but using flag OCI_LOB_BUFFER_FREE you can do it explicitly. Be sure you know what you're doing - next read/write operation to the same part of LOB will involve a round-trip to the server and initialize new buffer resources. Tt is recommended to use OCI_LOB_BUFFER_FREE flag only when you are not going to work with the LOB anymore.
lob->flush() returns FALSE if buffering was not enabled or an error occurred.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Writes data from filename in to the current position of large object.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocisavelobfile() instead. This name still can be used, it was left as alias of oci_lob_import() for downwards compatability. This, however, is deprecated and not recommended.
Compares two LOB/FILE locators. Returns TRUE if these objects are equal and FALSE otherwise.
Returns large object's contents. As script execution is terminated when the memory_limit is reached, ensure that the LOB does not exceed this limit. In most cases it's recommended to use oci_lob_read() instead. In case of error lob->load() returns FALSE.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociloadlob() instead. This name still can be used, it was left as alias of oci_lob_load() for downwards compatability. This, however, is deprecated and not recommended.
Reads length bytes from the current position of LOB's internal pointer. Reading stops when length bytes have been read or end of large object is reached. Internal pointer of large object will be shifted on the amount of bytes read.
Returns FALSE in case of error.
See also oci_lob_eof(), oci_lob_seek(), oci_lob_tell() and oci_lob_write().
(no version information, might be only in CVS)
lob->rewind -- Moves the internal pointer to the beginning of the large objectSets the internal pointer to the beginning of the large object.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also oci_lob_seek() and oci_lob_tell().
Saves data to the large object. Parameter offset can be used to indicate offset from the beginning of the large object.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocisavelob() instead. This name still can be used, it was left as alias of oci_lob_save() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_lob_write() and oci_lob_import().
(no version information, might be only in CVS)
lob->seek -- Sets the internal pointer of the large objectSets the internal pointer of the large object. Parameter offset indicates the amount of bytes, on which internal pointer should be moved from the position, pointed by whence:
OCI_SEEK_SET - sets the position equal to offset |
OCI_SEEK_CUR - adds offset bytes to the current position |
OCI_SEEK_END - adds offset bytes to the end of large object (use negative value to move to a position before the end of large object) |
See also oci_lob_rewind() and oci_lob_tell().
Returns length of large object value or FALSE in case of error. Empty objects have zero length.
(no version information, might be only in CVS)
lob->tell -- Returns current position of internal pointer of large objectReturns current position of a LOB's internal pointer or FALSE if an error occured.
See also oci_lob_size() and oci_lob_eof().
If parameter length is given, lob->truncate() truncates large object to length bytes. Otherwise, lob->truncate() will purge the LOB completely.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also oci_lob_erase().
Creates a temporary large object and writes data to it.
Parameter lob_type can be one of the following:
OCI_TEMP_BLOB is used to create temporary BLOBs |
OCI_TEMP_CLOB is used to create temporary CLOBs |
lob->writeTemporary() creates a CLOB by default.
You should use oci_lob_close() when the work with the object is over.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociwritetemporarylob() instead. This name still can be used, it was left as alias of oci_lob_write_temporary() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_lob_close().
Writes data from the parameter data into the current position of LOB's internal pointer. If the parameter length is given, writing will stop after length bytes have been written or the end of data is reached, whichever comes first.
lob->write() returns the number of bytes written or FALSE in case of error.
See also oci_lob_read().
Allocates new collection object. Parameter tdo should be a valid named type (uppercased). Third, optional parameter schema should point to the scheme, where the named type was created. oci_new_collection() uses name of the current user as default value of schema.
oci_new_collection() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocinewcollection() instead. This name still can be used, it was left as alias of oci_new_collection() for downwards compatability. This, however, is deprecated and not recommended.
oci_new_connect() creates a new connection to an Oracle server and logs on. The optional third parameter can either contain the name of the local Oracle instance or the name of the entry in tnsnames.ora. If the third parameter is not specified, PHP uses environment variables ORACLE_SID and TWO_TASK to determine the name of local Oracle instance and location of tnsnames.ora accordingly.
oci_new_connect() forces the creation of a new connection. This should be used if you need to isolate a set of transactions. By default, connections are shared and subsequent calls to oci_connect() will return the same connection identifier.
The following demonstrates how you can separate connections.
ÐáñÜäåéãìá 1. oci_new_connect() example
|
oci_new_connect() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocinlogon() instead. This name still can be used, it was left as alias of oci_new_connect() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_connect() and oci_pconnect().
oci_new_cursor() allocates a new statement handle on the specified connection.
ÐáñÜäåéãìá 1. Using REF CURSOR in an Oracle's stored procedure
|
ÐáñÜäåéãìá 2. Using REF CURSOR in an Oracle's select statement
|
oci_new_cursor() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocinewcursor() instead. This name still can be used, it was left as alias of oci_new_cursor() for downwards compatability. This, however, is deprecated and not recommended.
oci_new_descriptor() allocates resources to hold descriptor or LOB locator. Valid values for type are: OCI_D_FILE, OCI_D_LOB and OCI_D_ROWID.
ÐáñÜäåéãìá 1. oci_new_descriptor() example
|
ÐáñÜäåéãìá 2. oci_new_descriptor() example
|
oci_new_descriptor() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocinewdescriptor() instead. This name still can be used, it was left as alias of oci_new_descriptor() for downwards compatability. This, however, is deprecated and not recommended.
oci_num_fields() returns the number of columns in the statement.
ÐáñÜäåéãìá 1. oci_num_fields() example
|
oci_num_fields() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocinumcols() instead. This name still can be used, it was left as alias of oci_num_fields() for downwards compatability. This, however, is deprecated and not recommended.
oci_num_rows() returns number of rows affected during statement execution.
Óçìåßùóç: This function does not return number of rows selected! For SELECT statements this function will return the number of rows, that were fetched to the buffer with oci_fetch*() functions.
ÐáñÜäåéãìá 1. oci_num_rows() example
|
oci_num_rows() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocirowcount() instead. This name still can be used, it was left as alias of oci_num_rows() for downwards compatability. This, however, is deprecated and not recommended.
oci_parse() prepares the query using connection and returns the statement identifier, which can be used with oci_bind_by_name(), oci_execute() and other functions.
Óçìåßùóç: This function does not validate query. The only way to find out if query is valid SQL or PL/SQL statement - is to execute it.
oci_parse() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociparse() instead. This name still can be used, it was left as alias of oci_parse() for downwards compatability. This, however, is deprecated and not recommended.
Changes password for user with username. Parameters old_password and new_password should indicate old and new passwords respectively.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocipasswordchange() instead. This name still can be used, it was left as alias of oci_password_change() for downwards compatability. This, however, is deprecated and not recommended.
oci_pconnect() creates a new persistent connection to an Oracle server and logs on. The optional third parameter can either contain the name of the local Oracle instance or the name of the entry in tnsnames.ora. If the third parameter is not specified, PHP uses environment variables ORACLE_SID and TWO_TASK to determine the name of local Oracle instance and location of tnsnames.ora accordingly.
oci_pconnect() returns connection identifier or FALSE on error.
Óçìåßùóç: Note, that these kind of links only work if you are using a module version of PHP. See the Persistent Database Connections section for more information.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociplogon() instead. This name still can be used, it was left as alias of oci_pconnect() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_connect() and oci_new_connect().
oci_result() returns the data from the field field in the current row, fetched by oci_fetch(). oci_result() returns everything as strings except for abstract types (ROWIDs, LOBs and FILEs). oci_result() returns FALSE on error.
You can either use the column number (1-based) or the column name (in uppercase) for the field() parameter.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociresult() instead. This name still can be used, it was left as alias of oci_result() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_fetch_array(), oci_fetch_assoc(), oci_fetch_object(), oci_fetch_row() and oci_fetch_all().
oci_rollback() rolls back all outstanding statements for Oracle connection connection.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocirollback() instead. This name still can be used, it was left as alias of oci_rollback() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_commit().
Returns a string with version information of the Oracle server, which uses connection connection or returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ociserverversion() instead. This name still can be used, it was left as alias of oci_server_version() for downwards compatability. This, however, is deprecated and not recommended.
Sets the number of rows to be prefetched after successful call to oci_execute(). The default value for rows is 1.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocisetprefetch() instead. This name still can be used, it was left as alias of oci_set_prefetch() for downwards compatability. This, however, is deprecated and not recommended.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
oci_statement_type() returns the query type of statement statement as one of the following values:
SELECT
UPDATE
DELETE
INSERT
CREATE
DROP
ALTER
BEGIN
DECLARE
UNKNOWN
Parameter statement is a valid OCI statement identifier, returned from oci_parse().
oci_statement_type() returns FALSE on error.
Óçìåßùóç: In PHP versions before 5.0.0 you must use ocistatementtype() instead. This name still can be used, it was left as alias of oci_statement_type() for downwards compatability. This, however, is deprecated and not recommended.
ocibindbyname() binds the PHP variable variable to the Oracle placeholder ph_name. Whether it will be used for input or output will be determined run-time, and the necessary storage space will be allocated. The length parameter sets the maximum length for the bind. If you set length to -1 ocibindbyname() will use the current length of variable to set the maximum length.
If you need to bind an abstract Datatype (LOB/ROWID/BFILE) you need to allocate it first using ocinewdescriptor() function. The length is not used for abstract Datatypes and should be set to -1. The type variable tells oracle, what kind of descriptor we want to use. Possible values are: OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File), OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID).
ÐáñÜäåéãìá 1. ocibindbyname() example
|
Óçìåßùóç: This function was renamed to oci_bind_by_name() after PHP >= 5.0.0. For downward compatibility ocibindbyname() can also be used. This is deprecated, however.
Ðñïåéäïðïßçóç |
It is a bad idea to use magic quotes and ocibindbyname() simultaneously as no quoting is needed on quoted variables and any quotes magically applied will be written into your database as ocibindbyname() is not able to distinguish magically added quotings from those added by intention. |
If you do not want read more data from a cursor, then call ocicancel().
Óçìåßùóç: This function was renamed to oci_cancel() after PHP >= 5.0.0. For downward compatibility ocicancel() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_lob_close() after PHP >= 5.0.0. For downward compatibility ocicloselob() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_collection_append() after PHP >= 5.0.0. For downward compatibility ocicollappend() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_collection_assign() after PHP >= 5.0.0. For downward compatibility ocicollassign() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_collection_element_assign() after PHP >= 5.0.0. For downward compatibility ocicollassignelem() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_collection_element_get() after PHP >= 5.0.0. For downward compatibility ocicollgetelem() can also be used. This is deprecated, however.
(PHP 4 >= 4.0.6, PHP 5)
ocicollmax -- Return the max value of a collection. For a varray this is the maximum length of the arrayÓçìåßùóç: This function was renamed to oci_collection_max() after PHP >= 5.0.0. For downward compatibility ocicollmax() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_collection_size() after PHP >= 5.0.0. For downward compatibility ocicollsize() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_collection_trim() after PHP >= 5.0.0. For downward compatibility ocicolltrim() can also be used. This is deprecated, however.
ocicolumnisnull() returns TRUE if the returned column column in the result from the statement stmt is NULL. You can either use the column-number (1-Based) or the column-name, in uppercase, for the col parameter.
Óçìåßùóç: This function was renamed to oci_field_is_null() after PHP >= 5.0.0. For downward compatibility ocicolumnisnull() can also be used. This is deprecated, however.
ocicolumnname() returns the name of the column corresponding to the column number (1-based) that is passed in.
ÐáñÜäåéãìá 1. ocicolumnname() example
|
Óçìåßùóç: This function was renamed to oci_field_name() after PHP >= 5.0.0. For downward compatibility ocicolumnname() can also be used. This is deprecated, however.
Returns precision of the field with col index (1-based).
For FLOAT columns precision is nonzero and scale is -127. If precision is 0, then columnt is NUMBER. Else it's NUMBER(precision, scale).
Óçìåßùóç: This function was renamed to oci_field_precision() after PHP >= 5.0.0. For downward compatibility ocicolumnprecision() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_field_scale() after PHP >= 5.0.0. For downward compatibility ocicolumnscale() can also be used. This is deprecated, however.
ocicolumnsize() returns the size of the column as given by Oracle. You can either use the column-number (1-Based) or the column-name for the column parameter.
ÐáñÜäåéãìá 1. ocicolumnsize() example
|
Óçìåßùóç: This function was renamed to oci_field_size() after PHP >= 5.0.0. For downward compatibility ocicolumnsize() can also be used. This is deprecated, however.
ocicolumntype() returns the data type of the column corresponding to the column number (1-based) that is passed in.
ÐáñÜäåéãìá 1. ocicolumntype() example
|
Óçìåßùóç: This function was renamed to oci_field_type() after PHP >= 5.0.0. For downward compatibility ocicolumntype() can also be used. This is deprecated, however.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This function was renamed to oci_field_type_raw() after PHP >= 5.0.0. For downward compatibility ocicolumntyperaw() can also be used. This is deprecated, however.
ocicommit() commits all outstanding statements for the active transaction on Oracle connection connection. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This example demonstrates how ocicommit() is used.
ÐáñÜäåéãìá 1. ocicommit() example
|
Óçìåßùóç: This function was renamed to oci_commit() after PHP >= 5.0.0. For downward compatibility ocicommit() can also be used. This is deprecated, however.
See also ocirollback().
(PHP 3>= 3.0.7, PHP 4 , PHP 5)
ocidefinebyname -- Use a PHP variable for the define-step during a SELECTocidefinebyname() binds PHP variables for fetches of SQL-Columns. Be careful that Oracle uses ALL-UPPERCASE column-names, whereby in your select you can also write lowercase. ocidefinebyname() expects the column_name to be in uppercase. If you define a variable that doesn't exists in your select statement, no error will be given!
If you need to define an abstract datatype (LOB/ROWID/BFILE) you need to allocate it first using ocinewdescriptor(). See also the ocibindbyname() function.
ÐáñÜäåéãìá 1. ocidefinebyname() example
|
Óçìåßùóç: This function was renamed to oci_define_by_name() after PHP >= 5.0.0. For downward compatibility ocidefinebyname() can also be used. This is deprecated, however.
ocierror() returns the last error found. If the optional stmt|conn|global is not provided, the last error encountered is returned. If no error is found, ocierror() returns FALSE. ocierror() returns the error as an associative array. In this array, code consists the oracle error code and message the oracle errorstring.
As of PHP 4.3: offset and sqltext will also be included in the return array to indicate the location of the error and the original SQL text which caused it.
Óçìåßùóç: This function was renamed to oci_error() after PHP >= 5.0.0. For downward compatibility ocierror() can also be used. This is deprecated, however.
ociexecute() executes a previously parsed statement. (see ociparse()). The optional mode allows you to specify the execution-mode (default is OCI_COMMIT_ON_SUCCESS). If you don't want statements to be committed automatically specify OCI_DEFAULT as your mode.
Óçìåßùóç: This function was renamed to oci_execute() after PHP >= 5.0.0. For downward compatibility ociexecute() can also be used. This is deprecated, however.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ocifetch() fetches the next row (for SELECT statements) into the internal result-buffer. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function was renamed to oci_fetch() after PHP >= 5.0.0. For downward compatibility ocifetch() can also be used. This is deprecated, however.
Óçìåßùóç: This function is deprecated. Recommended alternatives: oci_fetch_array(), oci_fetch_object(), oci_fetch_assoc() and oci_fetch_row().
ocifetchinto() fetches the next row of SELECT statement into the result array. ocifetchinto() overwrites previous content of result. By default result will contain a zero-based array of all columns that are not NULL.
The mode parameter allows you to change the default behaviour. You can specify more the one flag by simply adding them up (e.g. OCI_ASSOC+OCI_RETURN_NULLS). Valid values are:
OCI_ASSOC - return an associative array. |
OCI_NUM - return a numeric array starting with zero (default behaviour). |
OCI_RETURN_NULLS - return the empty values for column, which values is NULL. |
OCI_RETURN_LOBS - return the value of a LOB instead of the descriptor. |
See also oci_fetch_array(), oci_fetch_object(), oci_fetch_assoc(), oci_fetch_row(), oci_fetch() and oci_execute().
Óçìåßùóç: In PHP 5.0.0 this function became an alias for oci_fetch_all(). This name still can be used, it was left as alias of oci_fetch_all() for downwards compatability. This, however, is deprecated and not recommended.
See also oci_fetch_array(), oci_fetch_assoc(), oci_fetch_object(), oci_fetch_row().
Óçìåßùóç: This function was renamed to oci_free_collection() after PHP >= 5.0.0. For downward compatibility ocifreecollection() can also be used. This is deprecated, however.
ocifreecursor() frees all resources associated with the cursor stmt. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function was renamed to oci_free_cursor() after PHP >= 5.0.0. For downward compatibility ocifreecursor() can also be used. This is deprecated, however.
ocifreedesc() deletes a large object descriptor. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function was renamed to oci_free_descriptor() after PHP >= 5.0.0. For downward compatibility ocifreedesc() can also be used. This is deprecated, however.
ocifreestatement() free all resources associated with the statement stmt. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function was renamed to oci_free_statement() after PHP >= 5.0.0. For downward compatibility ocifreestatement() can also be used. This is deprecated, however.
(no version information, might be only in CVS)
lob->getBuffering -- Returns current state of buffering for large objectReturns FALSE if buffering for the large object is off and TRUE if buffering is used.
See also ocisetbufferinglob().
ociinternaldebug() enables internal debug output. Set onoff to 0 to turn debug output off, 1 to turn it on.
Óçìåßùóç: This function was renamed to oci_internal_debug() after PHP >= 5.0.0. For downward compatibility ociinternaldebug() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_lob_load() after PHP >= 5.0.0. For downward compatibility ociloadlob() can also be used. This is deprecated, however.
ocilogoff() closes the Oracle connection connection.
Using ocilogoff() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.
Óçìåßùóç: This function was renamed to oci_close() after PHP >= 5.0.0. For downward compatibility ocilogoff() can also be used. This is deprecated, however.
ocilogon() returns an connection identifier needed for most other OCI calls. The optional third parameter can either contain the name of the local Oracle instance or the name of the entry in tnsnames.ora to which you want to connect. If the optional third parameter is not specified, PHP uses the environment variables ORACLE_SID (Oracle instance) or TWO_TASK (tnsnames.ora) to determine which database to connect to.
Connections are shared at the page level when using ocilogon(). This means that commits and rollbacks apply to all open transactions in the page, even if you have created multiple connections.
This example demonstrates how the connections are shared.
ÐáñÜäåéãìá 1. ocilogon() example
|
Óçìåßùóç: This function was renamed to oci_connect() after PHP >= 5.0.0. For downward compatibility ocilogon() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_new_collection() after PHP >= 5.0.0. For downward compatibility ocinewcollection() can also be used. This is deprecated, however.
ocinewcursor() allocates a new statement handle on the specified connection.
ÐáñÜäåéãìá 1. Using a REF CURSOR from a stored procedure in Oracle
|
ÐáñÜäåéãìá 2. Using a REF CURSOR in a select statement in Oracle
|
Óçìåßùóç: This function was renamed to oci_new_cursor() after PHP >= 5.0.0. For downward compatibility ocinewcursor() can also be used. This is deprecated, however.
ocinewdescriptor() allocates storage to hold descriptors or LOB locators. Valid values for type are OCI_D_FILE, OCI_D_LOB and OCI_D_ROWID. For LOB descriptors, the methods load, save, and savefile are associated with the descriptor, for BFILE only the load method exists. See the second example usage hints.
ÐáñÜäåéãìá 1. ocinewdescriptor() example
|
ÐáñÜäåéãìá 2. ocinewdescriptor() second example
|
Óçìåßùóç: This function was renamed to oci_new_descriptor() after PHP >= 5.0.0. For downward compatibility ocinewdescriptor() can also be used. This is deprecated, however.
ocinlogon() creates a new connection to an Oracle 8 database and logs on. The optional third parameter can either contain the name of the local Oracle instance or the name of the entry in tnsnames.ora to which you want to connect. If the optional third parameter is not specified, PHP uses the environment variables ORACLE_SID (Oracle instance) or TWO_TASK (tnsnames.ora) to determine which database to connect to.
ocinlogon() forces a new connection. This should be used if you need to isolate a set of transactions. By default, connections are shared at the page level if using ocilogon() or at the web server process level if using ociplogon(). If you have multiple connections open using ocinlogon(), all commits and rollbacks apply to the specified connection only.
This example demonstrates how the connections are separated.
ÐáñÜäåéãìá 1. ocinlogon() example
|
Óçìåßùóç: This function was renamed to oci_new_connect() after PHP >= 5.0.0. For downward compatibility ocinlogon() can also be used. This is deprecated, however.
ocinumcols() returns the number of columns in the statement stmt.
ÐáñÜäåéãìá 1. ocinumcols() example
|
Óçìåßùóç: This function was renamed to oci_num_fields() after PHP >= 5.0.0. For downward compatibility ocinumcols() can also be used. This is deprecated, however.
ociparse() parses the query using conn. It returns the statement identity if the query is valid, FALSE if not. The query can be any valid SQL statement or PL/SQL block.
Óçìåßùóç: This function was renamed to oci_parse() after PHP >= 5.0.0. For downward compatibility ociparse() can also be used. This is deprecated, however.
(PHP 3>= 3.0.8, PHP 4 , PHP 5)
ociplogon -- Connect to an Oracle database using a persistent connectionociplogon() creates a persistent connection to an Oracle 8 database and logs on. The optional third parameter can either contain the name of the local Oracle instance or the name of the entry in tnsnames.ora to which you want to connect. If the optional third parameter is not specified, PHP uses the environment variables ORACLE_SID (Oracle instance) or TWO_TASK (tnsnames.ora) to determine which database to connect to.
Óçìåßùóç: This function was renamed to oci_pconnect() after PHP >= 5.0.0. For downward compatibility ociplogon() can also be used. This is deprecated, however.
ociresult() returns the data for column column in the current row (see ocifetch()). ociresult() will return everything as strings except for abstract types (ROWIDs, LOBs and FILEs).
You can either use the column-number (1-Based) or the column-name, in uppercase, for the col parameter.
Óçìåßùóç: This function was renamed to oci_result() after PHP >= 5.0.0. For downward compatibility ociresult() can also be used. This is deprecated, however.
ocirollback() rolls back all outstanding statements for Oracle connection connection. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function was renamed to oci_rollback() after PHP >= 5.0.0. For downward compatibility ocirollback() can also be used. This is deprecated, however.
ocirowcount() returns the number of rows affected for e.g. update-statements. This function will not tell you the number of rows that a select will return!
ÐáñÜäåéãìá 1. ocirowcount() example
|
Óçìåßùóç: This function was renamed to oci_num_rows() after PHP >= 5.0.0. For downward compatibility ocirowcount() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_lob_save() after PHP >= 5.0.0. For downward compatibility ocisavelob() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_lob_import() after PHP >= 5.0.0. For downward compatibility ocisavelobfile() can also be used. This is deprecated, however.
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
ociserverversion -- Return a string containing server version information
Óçìåßùóç: This function was renamed to oci_server_version() after PHP >= 5.0.0. For downward compatibility ociserverversion() can also be used. This is deprecated, however.
(no version information, might be only in CVS)
lob->setBuffering -- Changes current state of buffering for large objectlob->setBuffering() sets the buffering for the large object, depending on the value of the on_off parameter. Repeated calls to lob->setBuffering() with the same flag will return TRUE. The values for on_off are: TRUE for on and FALSE for off.
Use of this function may provide perfomance improvements by buffering small reads and writes of LOBs by reducing the number of network round-trips and LOB versions. oci_lob_flush() should be used to flush buffers, when you have finished working with the large object.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ocigetbufferinglob().
Sets the number of top level rows to be prefetched to rows. The default value for rows is 1 row.
Óçìåßùóç: This function was renamed to oci_set_prefetch() after PHP >= 5.0.0. For downward compatibility ocisetprefetch() can also be used. This is deprecated, however.
ocistatementtype() returns one of the following values:
SELECT
UPDATE
DELETE
INSERT
CREATE
DROP
ALTER
BEGIN
DECLARE
UNKNOWN
Óçìåßùóç: This function was renamed to oci_statement_type() after PHP >= 5.0.0. For downward compatibility ocistatementtype() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_lob_export() after PHP >= 5.0.0. For downward compatibility ociwritelobtofile() can also be used. This is deprecated, however.
Óçìåßùóç: This function was renamed to oci_lob_write_temporary() after PHP >= 5.0.0. For downward compatibility ociwritetemporarylob() can also be used. This is deprecated, however.
This module uses the functions of OpenSSL for generation and verification of signatures and for sealing (encrypting) and opening (decrypting) data. OpenSSL offers many features that this module currently doesn't support. Some of these may be added in the future.
In order to use the OpenSSL functions you need to install the OpenSSL package. PHP-4.0.4pl1 requires OpenSSL >= 0.9.6, but PHP-4.0.5 and greater will also work with OpenSSL >= 0.9.5.
To use PHP's OpenSSL support you must also compile PHP --with-openssl[=DIR].
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy libeay32.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32)
Additionally, if you are planning to use the key generation and certificate signing functions, you will need to install a valid openssl.cnf on your system. As of PHP 4.3.0, we include a sample configuration file in the openssl folder of our win32 binary distribution. If you are using PHP 4.2.0 or later and are missing the file, you can obtain it from the OpenSSL home page or by downloading the PHP 4.3.0 release and using the configuration file from there.
Note to Win32 Users: PHP will search for the openssl.cnf using the following logic:
the OPENSSL_CONF environmental variable, if set, will be used as the path (including filename) of the configuration file.
the SSLEAY_CONF environmental variable, if set, will be used as the path (including filename) of the configuration file.
The file openssl.cnf will be assumed to be found in the default certificate area, as configured at the time that the openssl DLL was compiled. This is usually means that the default filename is c:\usr\local\ssl\openssl.cnf.
In your installation, you need to decide whether to install the configuration file at c:\usr\local\ssl\openssl.cnf or whether to install it someplace else and use environmental variables (possibly on a per-virtual-host basis) to locate the configuration file. Note that it is possible to override the default path from the script using the configargs of the functions that require a configuration file.
Quite a few of the openssl functions require a key or a certificate parameter. PHP 4.0.5 and earlier have to use a key or certificate resource returned by one of the openssl_get_xxx functions. Later versions may use one of the following methods:
Certificates
An X.509 resource returned from openssl_x509_read()
A string having the format file://path/to/cert.pem; the named file must contain a PEM encoded certificate
A string containing the content of a certificate, PEM encoded
Public/Private Keys
A key resource returned from openssl_get_publickey() or openssl_get_privatekey()
For public keys only: an X.509 resource
A string having the format file://path/to/file.pem - the named file must contain a PEM encoded certificate/private key (it may contain both)
A string containing the content of a certificate/key, PEM encoded
For private keys, you may also use the syntax array($key, $passphrase) where $key represents a key specified using the file:// or textual content notation above, and $passphrase represents a string containing the passphrase for that private key
When calling a function that will verify a signature/certificate, the cainfo parameter is an array containing file and directory names that specify the locations of trusted CA files. If a directory is specified, then it must be a correctly formed hashed directory as the openssl command would use.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
The S/MIME functions make use of flags which are specified using a bitfield which can include one or more of the following values:
Ðßíáêáò 1. PKCS7 CONSTANTS
Constant | Description |
---|---|
PKCS7_TEXT | Adds text/plain content type headers to encrypted/signed message. If decrypting or verifying, it strips those headers from the output - if the decrypted or verified message is not of MIME type text/plain then an error will occur. |
PKCS7_BINARY | Normally the input message is converted to "canonical" format which is effectively using CR and LF as end of line: as required by the S/MIME specification. When this options is present, no translation occurs. This is useful when handling binary data which may not be in MIME format. |
PKCS7_NOINTERN | When verifying a message, certificates (if any) included in the message are normally searched for the signing certificate. With this option only the certificates specified in the extracerts parameter of openssl_pkcs7_verify() are used. The supplied certificates can still be used as untrusted CAs however. |
PKCS7_NOVERIFY | Do not verify the signers certificate of a signed message. |
PKCS7_NOCHAIN | Do not chain verification of signers certificates: that is don't use the certificates in the signed message as untrusted CAs. |
PKCS7_NOCERTS | When signing a message the signer's certificate is normally included - with this option it is excluded. This will reduce the size of the signed message but the verifier must have a copy of the signers certificate available locally (passed using the extracerts to openssl_pkcs7_verify() for example). |
PKCS7_NOATTR | Normally when a message is signed, a set of attributes are included which include the signing time and the supported symmetric algorithms. With this option they are not included. |
PKCS7_DETACHED | When signing a message, use cleartext signing with the MIME type multipart/signed. This is the default if you do not specify any flags to openssl_pkcs7_sign(). If you turn this option off, the message will be signed using opaque signing, which is more resistant to translation by mail relays but cannot be read by mail agents that do not support S/MIME. |
PKCS7_NOSIGS | Don't try and verify the signatures on a message |
Óçìåßùóç: These constants were added in 4.0.6.
openssl_csr_export_to_file() takes the Certificate Signing Request represented by csr and saves it as ascii-armoured text into the file named by outfilename.
The optional parameter notext affects the verbosity of the output; if it is FALSE then additional human-readable information is included in the output. The default value of notext is TRUE.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also openssl_csr_export(), openssl_csr_new() and openssl_csr_sign().
openssl_csr_export() takes the Certificate Signing Request represented by csr and stores it as ascii-armoured text into out, which is passed by reference.
The optional parameter notext affects the verbosity of the output; if it is FALSE then additional human-readable information is included in the output. The default value of notext is TRUE.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also openssl_csr_export_to_file(), openssl_csr_new() and openssl_csr_sign().
openssl_csr_new() generates a new CSR (Certificate Signing Request) based on the information provided by dn, which represents the Distinguished Name to be used in the certificate.
privkey should be set to a private key that was previously generated by openssl_pkey_new() (or otherwise obtained from the other openssl_pkey family of functions). The corresponding public portion of the key will be used to sign the CSR.
extraattribs is used to specify additional configuration options for the CSR. Both dn and extraattribs are associative arrays whose keys are converted to OIDs and applied to the relevant part of the request.
Óçìåßùóç: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.
By default, the information in your system openssl.conf is used to initialize the request; you can specify a configuration file section by setting the config_section_section key of configargs. You can also specify an alternative openssl configuration file by setting the value of the config key to the path of the file you want to use. The following keys, if present in configargs behave as their equivalents in the openssl.conf, as listed in the table below.
Ðßíáêáò 1. Configuration overrides
configargs key | type | openssl.conf equivalent | description |
---|---|---|---|
digest_alg | string | default_md | Selects which digest method to use |
x509_extensions | string | x509_extensions | Selects which extensions should be used when creating an x509 certificate |
req_extensions | string | req_extensions | Selects which extensions should be used when creating a CSR |
private_key_bits | string | default_bits | Specifies how many bits should be used to generate a private key |
private_key_type | integer | none | Specifies the type of private key to create. This can be one of OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH or OPENSSL_KEYTYPE_RSA. The default value is OPENSSL_KEYTYPE_RSA which is currently the only supported key type. |
encrypt_key | boolean | encrypt_key | Should an exported key (with passphrase) be encrypted? |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. openssl_csr_new() example - creating a self-signed-certificate
|
(PHP 4 >= 4.2.0, PHP 5)
openssl_csr_sign -- Sign a CSR with another certificate (or itself) and generate a certificateopenssl_csr_sign() generates an x509 certificate resource from the csr previously generated by openssl_csr_new(), but it can also be the path to a PEM encoded CSR when specified as file://path/to/csr or an exported string generated by openssl_csr_export(). The generated certificate will be signed by cacert. If cacert is NULL, the generated certificate will be a self-signed certificate. priv_key is the private key that corresponds to cacert. days specifies the length of time for which the generated certificate will be valid, in days. You can finetune the CSR signing by configargs. See openssl_csr_new() for more information about configargs. Since PHP 4.3.3 you can specify the serial number of issued certificate by serial. In earlier versions, it was always 0.
Returns an x509 certificate resource on success, FALSE on failure.
Óçìåßùóç: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.
ÐáñÜäåéãìá 1. openssl_csr_sign() example - signing a CSR (how to implement your own CA)
|
Returns an error message string, or FALSE if there are no more error messages to return.
openssl_error_string() returns the last error from the openSSL library. Error messages are stacked, so this function should be called multiple times to collect all of the information.
openssl_free_key() frees the key associated with the specified key_identifier from memory.
This is an alias for openssl_pkey_get_private().
(PHP 4 >= 4.0.4, PHP 5)
openssl_get_publickey -- Extract public key from certificate and prepare it for useThis is an alias for openssl_pkey_get_public().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. If successful the opened data is returned in open_data.
openssl_open() opens (decrypts) sealed_data using the private key associated with the key identifier priv_key_id and the envelope key env_key, and fills open_data with the decrypted data. The envelope key is generated when the data are sealed and can only be used by one specific private key. See openssl_seal() for more information.
ÐáñÜäåéãìá 1. openssl_open() example
|
See also openssl_seal().
Decrypts the S/MIME encrypted message contained in the file specified by infilename using the certificate and its associated private key specified by recipcert and recipkey.
The decrypted message is output to the file specified by outfilename
ÐáñÜäåéãìá 1. openssl_pkcs7_decrypt() example
|
openssl_pkcs7_encrypt() takes the contents of the file named infile and encrypts them using an RC2 40-bit cipher so that they can only be read by the intended recipients specified by recipcerts, which is either a lone X.509 certificate, or an array of X.509 certificates. headers is an array of headers that will be prepended to the data after it has been encrypted. flags can be used to specify options that affect the encoding process - see PKCS7 constants. headers can be either an associative array keyed by header name, or an indexed array, where each element contains a single header line.
ÐáñÜäåéãìá 1. openssl_pkcs7_encrypt() example
|
openssl_pkcs7_sign() takes the contents of the file named infilename and signs them using the certificate and its matching private key specified by signcert and privkey parameters.
headers is an array of headers that will be prepended to the data after it has been signed (see openssl_pkcs7_encrypt() for more information about the format of this parameter.
flags can be used to alter the output - see PKCS7 constants - if not specified, it defaults to PKCS7_DETACHED.
extracerts specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.
ÐáñÜäåéãìá 1. openssl_pkcs7_sign() example
|
openssl_pkcs7_verify() reads the S/MIME message contained in the filename specified by filename and examines the digital signature. It returns TRUE if the signature is verified, FALSE if it is not correct (the message has been tampered with, or the signing certificate is invalid), or -1 on error.
flags can be used to affect how the signature is verified - see PKCS7 constants for more information.
If the outfilename is specified, it should be a string holding the name of a file into which the certificates of the persons that signed the messages will be stored in PEM format.
If the cainfo is specified, it should hold information about the trusted CA certificates to use in the verification process - see certificate verification for more information about this parameter.
If the extracerts is specified, it is the filename of a file containing a bunch of certificates to use as untrusted CAs.
(PHP 4 >= 4.2.0, PHP 5)
openssl_pkey_export_to_file -- Gets an exportable representation of a key into a fileopenssl_pkey_export_to_file() saves an ascii-armoured (PEM encoded) rendition of key into the file named by outfilename. The key can be optionally protected by a passphrase. configargs can be used to fine-tune the export process by specifying and/or overriding options for the openssl configuration file. See openssl_csr_new() for more information about configargs. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.
(PHP 4 >= 4.2.0, PHP 5)
openssl_pkey_export -- Gets an exportable representation of a key into a stringopenssl_pkey_export() exports key as a PEM encoded string and stores it into out (which is passed by reference). The key is optionally protected by passphrase. configargs can be used to fine-tune the export process by specifying and/or overriding options for the openssl configuration file. See openssl_csr_new() for more information about configargs. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.
Returns a positive key resource identifier on success, or FALSE on error.
openssl_get_privatekey() parses key and prepares it for use by other functions. key can be one of the following:
a string having the format file://path/to/file.pem. The named file must contain a PEM encoded certificate/private key (it may contain both).
A PEM formatted private key.
The optional parameter passphrase must be used if the specified key is encrypted (protected by a passphrase).
(PHP 4 >= 4.2.0, PHP 5)
openssl_pkey_get_public -- Extract public key from certificate and prepare it for useReturns a positive key resource identifier on success, or FALSE on error.
openssl_get_publickey() extracts the public key from certificate and prepares it for use by other functions. certificate can be one of the following:
an X.509 certificate resource
a string having the format file://path/to/file.pem. The named file must contain a PEM encoded certificate/private key (it may contain both).
A PEM formatted private key.
openssl_pkey_new() generates a new private and public key pair. The public component of the key can be obtained using openssl_pkey_get_public(). You can finetune the key generation (such as specifying the number of bits) using configargs. See openssl_csr_new() for more information about configargs.
Óçìåßùóç: You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
openssl_private_decrypt() decrypts data that was previous encrypted via openssl_public_encrypt() and stores the result into decrypted. key must be the private key corresponding that was used to encrypt the data. padding defaults to OPENSSL_PKCS1_PADDING, but can also be one of OPENSSL_SSLV23_PADDING, OPENSSL_PKCS1_OAEP_PADDING, OPENSSL_NO_PADDING.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
You can use this function e.g. to decrypt data which were supposed only to you.
See also openssl_public_encrypt() and openssl_public_decrypt().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
openssl_private_encrypt() encrypts data with private key and stores the result into crypted. Encrypted data can be decrypted via openssl_public_decrypt. padding defaults to OPENSSL_PKCS1_PADDING, but can also be OPENSSL_NO_PADDING.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function can be used e.g. to sign data (or its hash) to prove that it is not written by someone else.
See also openssl_public_decrypt() and openssl_public_encrypt().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
openssl_public_decrypt() decrypts data that was previous encrypted via openssl_private_encrypt() and stores the result into decrypted. key must be the public key corresponding that was used to encrypt the data. padding defaults to OPENSSL_PKCS1_PADDING, but can also be OPENSSL_NO_PADDING.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
You can use this function e.g. to check if the message was written by the owner of the private key.
See also openssl_private_encrypt() and openssl_private_decrypt().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
openssl_public_encrypt() encrypts data with public key and stores the result into crypted. Encrypted data can be decrypted via openssl_private_decrypt. padding defaults to OPENSSL_PKCS1_PADDING, but can also be one of OPENSSL_SSLV23_PADDING, OPENSSL_PKCS1_OAEP_PADDING, OPENSSL_NO_PADDING.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function can be used e.g. to encrypt message which can be then read only by owner of the private key. It can be also used to store secure data in database.
See also openssl_private_decrypt() and openssl_private_encrypt().
Returns the length of the sealed data on success, or FALSE on error. If successful the sealed data is returned in sealed_data, and the envelope keys in env_keys.
openssl_seal() seals (encrypts) data by using RC4 with a randomly generated secret key. The key is encrypted with each of the public keys associated with the identifiers in pub_key_ids and each encrypted key is returned in env_keys. This means that one can send sealed data to multiple recipients (provided one has obtained their public keys). Each recipient must receive both the sealed data and the envelope key that was encrypted with the recipient's public key.
ÐáñÜäåéãìá 1. openssl_seal() example
|
See also openssl_open().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. If successful the signature is returned in signature.
openssl_sign() computes a signature for the specified data by using SHA1 for hashing followed by encryption using the private key associated with priv_key_id. Note that the data itself is not encrypted.
ÐáñÜäåéãìá 1. openssl_sign() example
|
See also openssl_verify().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Returns 1 if the signature is correct, 0 if it is incorrect, and -1 on error.
openssl_verify() verifies that the signature is correct for the specified data using the public key associated with pub_key_id. This must be the public key corresponding to the private key used for signing.
ÐáñÜäåéãìá 1. openssl_verify() example
|
See also openssl_sign().
(PHP 4 >= 4.2.0, PHP 5)
openssl_x509_check_private_key -- Checks if a private key corresponds to a certificateopenssl_x509_check_private_key() returns TRUE if key is the private key that corresponds to cert, or FALSE otherwise.
(PHP 4 >= 4.0.6, PHP 5)
openssl_x509_checkpurpose -- Verifies if a certificate can be used for a particular purposeReturns TRUE if the certificate can be used for the intended purpose, FALSE if it cannot, or -1 on error.
openssl_x509_checkpurpose() examines the certificate specified by x509cert to see if it can be used for the purpose specified by purpose.
cainfo should be an array of trusted CA files/dirs as described in Certificate Verification.
untrustedfile, if specified, is the name of a PEM encoded file holding certificates that can be used to help verify the certificate, although no trust in placed in the certificates that come from that file.
Ðßíáêáò 1. openssl_x509_checkpurpose() purposes
Constant | Description |
---|---|
X509_PURPOSE_SSL_CLIENT | Can the certificate be used for the client side of an SSL connection? |
X509_PURPOSE_SSL_SERVER | Can the certificate be used for the server side of an SSL connection? |
X509_PURPOSE_NS_SSL_SERVER | Can the cert be used for Netscape SSL server? |
X509_PURPOSE_SMIME_SIGN | Can the cert be used to sign S/MIME email? |
X509_PURPOSE_SMIME_ENCRYPT | Can the cert be used to encrypt S/MIME email? |
X509_PURPOSE_CRL_SIGN | Can the cert be used to sign a certificate revocation list (CRL)? |
X509_PURPOSE_ANY | Can the cert be used for Any/All purposes? |
openssl_x509_export_to_file() stores x509 into a file named by outfilename in a PEM encoded format.
The optional parameter notext affects the verbosity of the output; if it is FALSE then additional human-readable information is included in the output. The default value of notext is TRUE.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
openssl_x509_export() stores x509 into a string named by output in a PEM encoded format.
The optional parameter notext affects the verbosity of the output; if it is FALSE then additional human-readable information is included in the output. The default value of notext is TRUE.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
openssl_x509_free() frees the certificate associated with the specified x509cert resource from memory.
(PHP 4 >= 4.0.6, PHP 5)
openssl_x509_parse -- Parse an X509 certificate and return the information as an arrayÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
openssl_x509_parse() returns information about the supplied x509cert, including fields such as subject name, issuer name, purposes, valid from and valid to dates etc. shortnames controls how the data is indexed in the array - if shortnames is TRUE (the default) then fields will be indexed with the short name form, otherwise, the long name form will be used - e.g.: CN is the shortname form of commonName.
The structure of the returned data is (deliberately) not yet documented, as it is still subject to change.
This extension adds support for Oracle database server access. See also the OCI8 extension.
You have to compile PHP with the option --with-oracle[=DIR], where DIR defaults to your environment variable ORACLE_HOME.
This function binds the named PHP variable with a SQL parameter. The SQL parameter must be in the form ":name". With the optional type parameter, you can define whether the SQL parameter is an in/out (0, default), in (1) or out (2) parameter. As of PHP 3.0.1, you can use the constants ORA_BIND_INOUT, ORA_BIND_IN and ORA_BIND_OUT instead of the numbers.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
ora_bind() must be called after ora_parse() and before ora_exec(). Input values can be given by assignment to the bound PHP variables, after calling ora_exec() the bound PHP variables contain the output values if available.
ÐáñÜäåéãìá 1. ora_bind() example
|
This function closes a data cursor opened with ora_open().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
Returns the name of the field/column column on the cursor cursor. The returned name is in all uppercase letters. Column 0 is the first column.
Returns the size of the Oracle column column on the cursor cursor. Column 0 is the first column.
Returns the Oracle data type name of the field/column column on the cursor cursor. Column 0 is the first column. The returned type will be one of the following:
"VARCHAR2" |
"VARCHAR" |
"CHAR" |
"NUMBER" |
"LONG" |
"LONG RAW" |
"ROWID" |
"DATE" |
"CURSOR" |
This function commits an Oracle transaction. A transaction is defined as all the changes on a given connection since the last commit/rollback, autocommit was turned off or when the connection was established.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
See also ora_commiton() and ora_commitoff().
This function turns off automatic commit after each ora_exec() on the given connection.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
See also ora_commiton() and ora_commit().
This function turns on automatic commit after each ora_exec() on the given connection.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
See also ora_commitoff() and ora_commit().
ora_do() is quick combination of ora_parse(), ora_exec() and ora_fetch(). It will parse and execute a statement, then fetch the first result row.
This function returns a cursor index or FALSE on failure. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
See also ora_parse(),ora_exec(), and ora_fetch().
Returns an error message of the form XXX-NNNNN where XXX is where the error comes from and NNNNN identifies the error message.
Óçìåßùóç: Support for connection ids was added in 3.0.4.
On Unix versions of Oracle, you can find details about an error message like this: $ oerr ora 00001 00001, 00000, "unique constraint (%s.%s) violated" // *Cause: An update or insert statement attempted to insert a duplicate key // For Trusted ORACLE configured in DBMS MAC mode, you may see // this message if a duplicate entry exists at a different level. // *Action: Either remove the unique restriction or do not insert the key
Returns the numeric error code of the last executed statement on the specified cursor or connection.
Óçìåßùóç: Support for connection ids was added in 3.0.4.
ora_exec() execute the parsed statement cursor, already parsed by ora_parse().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
See also ora_parse(), ora_fetch(), and ora_do().
Fetches a row of data into an array. The flags has two flag values: if the ORA_FETCHINTO_NULLS flag is set, columns with NULL values are set in the array; and if the ORA_FETCHINTO_ASSOC flag is set, an associative array is created.
Returns the number of columns fetched.
See also ora_parse(),ora_exec(), ora_fetch(), and ora_do().
Retrieves a row of data from the specified cursor.
Returns TRUE (a row was fetched) or FALSE (no more rows, or an error occurred). If an error occurred, details can be retrieved using the ora_error() and ora_errorcode() functions. If there was no error, ora_errorcode() will return 0.
See also ora_parse(),ora_exec(), and ora_do().
Fetches the data for a column or function result.
Returns the column data. If an error occurs, FALSE is returned and ora_errorcode() will return a non-zero value. Note, however, that a test for FALSE on the results from this function may be TRUE in cases where there is not error as well (NULL result, empty string, the number 0, the string "0").
Logs out the user and disconnects from the server.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
See also ora_logon().
Establishes a connection between PHP and an Oracle database with the given username user and password password.
Connections can be made using SQL*Net by supplying the TNS name to user like this:
If you have character data with non-ASCII characters, you should make sure that NLS_LANG is set in your environment. For server modules, you should set it in the server's environment before starting the server.
Returns a connection index on success, or FALSE on failure. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
ora_numcols() returns the number of columns in a result. Only returns meaningful values after an parse/exec/fetch sequence.
See also ora_parse(),ora_exec(), ora_fetch(), and ora_do().
Opens an Oracle cursor associated with connection.
Returns a cursor index or FALSE on failure. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
This function parses an SQL statement or a PL/SQL block and associates it with the given cursor.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also ora_exec(), ora_fetch(), and ora_do().
Establishes a persistent connection between PHP and an Oracle database with the username user and password password.
See also ora_logon().
This function undoes an Oracle transaction. (See ora_commit() for the definition of a transaction.)
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.
Ovrimos SQL Server, is a client/server, transactional RDBMS combined with Web capabilities and fast transactions.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
You'll need to install the sqlcli library available in the Ovrimos SQL Server distribution.
To enable Ovrimos support in PHP just compile PHP with the --with-ovrimos[=DIR] parameter to your configure line. DIR is the Ovrimos' libsqlcli install directory.
ÐáñÜäåéãìá 1. Connect to Ovrimos SQL Server and select from a system table
|
ovrimos_close() is used to close the specified connection to Ovrimos. This has the effect of rolling back uncommitted transactions.
ovrimos_commit() is used to commit the transaction. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ovrimos_connect() is used to connect to the specified database.
ovrimos_connect() returns a connection id (greater than 0) or 0 for failure. The meaning of host and db are those used everywhere in Ovrimos APIs. host is a host name or IP address and db is either a database name, or a string containing the port number.
ÐáñÜäåéãìá 1. ovrimos_connect() Example
|
ovrimos_cursor() returns the name of the cursor. Useful when wishing to perform positioned updates or deletes.
ovrimos_exec() executes an SQL statement (query or update) and returns a result_id or FALSE. Evidently, the SQL statement should not contain parameters.
ovrimos_execute() executes a prepared statement. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. If the prepared statement contained parameters (question marks in the statement), the correct number of parameters should be passed in an array. Notice that I don't follow the PHP convention of placing just the name of the optional parameter inside square brackets. I couldn't bring myself on liking it.
ovrimos_fetch_into() fetches a row from the result set into result_array, which should be passed by reference. Which row is fetched is determined by the two last parameters. how is one of Next (default), Prev, First, Last, Absolute, corresponding to forward direction from current position, backward direction from current position, forward direction from the start, backward direction from the end and absolute position from the start (essentially equivalent to 'first' but needs 'rownumber'). Case is not significant. rownumber is optional except for absolute positioning. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. A fetch into example
|
ovrimos_fetch_row() fetches a row from the result set. Column values should be retrieved with other calls. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. A fetch row example
|
ovrimos_field_len() is used to get the length of the output column with number field_number (1-based), in result result_id.
ovrimos_field_name() returns the output column name at the (1-based) index specified.
ovrimos_field_num() returns the (1-based) index of the output column specified by field_name, or FALSE.
ovrimos_field_type() returns the (numeric) type of the output column at the (1-based) index specified by field_number.
ovrimos_free_result() frees the specified result_id. Returns TRUE.
(PHP 4 >= 4.0.3, PHP 5)
ovrimos_longreadlen -- Specifies how many bytes are to be retrieved from long datatypesovrimos_longreadlen() specifies how many bytes are to be retrieved from long datatypes (long varchar and long varbinary). Default is zero. It currently sets this parameter the specified result set. Returns TRUE.
ovrimos_num_fields() returns the number of columns in a result_id resulting from a query.
ovrimos_num_rows() returns the number of rows affected by update operations.
ovrimos_prepare() prepares an SQL statement and returns a result_id (or FALSE on failure).
ÐáñÜäåéãìá 1. Connect to Ovrimos SQL Server and prepare a statement
|
ovrimos_result_all() prints the whole result set as an HTML table. Returns the number of rows in the generated table.
ÐáñÜäåéãìá 1. Prepare a statement, execute, and view the result
|
ÐáñÜäåéãìá 2. ovrimos_result_all() with meta-information
|
ÐáñÜäåéãìá 3. ovrimos_result_all() example
|
ovrimos_result() retrieves the output column specified by field, either as a string or as an 1-based index. Returns FALSE on failure.
The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo() and data between blocks of PHP code.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Output Control configuration options
Name | Default | Changeable |
---|---|---|
output_buffering | "0" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
output_handler | NULL | PHP_INI_PERDIR|PHP_INI_SYSTEM |
implicit_flush | "0" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
You can enable output buffering for all files by setting this directive to 'On'. If you wish to limit the size of the buffer to a certain size - you can use a maximum number of bytes instead of 'On', as a value for this directive (e.g., output_buffering=4096).
You can redirect all of the output of your scripts to a function. For example, if you set output_handler to mb_output_handler(), character encoding will be transparently converted to the specified encoding. Setting any output handler automatically turns on output buffering.
Óçìåßùóç: You cannot use both mb_output_handler() with ob_inconv_handler() and you cannot use both ob_gzhandler() and zlib.output_compression.
FALSE by default. Changing this to TRUE tells PHP to tell the output layer to flush itself automatically after every output block. This is equivalent to calling the PHP function flush() after each and every call to print() or echo() and each and every HTML block.
When using PHP within an web environment, turning this option on has serious performance implications and is generally recommended for debugging purposes only. This value defaults to TRUE when operating under the CLI SAPI.
See also ob_implicit_flush().
In the above example, the output from echo() would be stored in the output buffer until ob_end_flush() was called. In the mean time, the call to setcookie() successfully stored a cookie without causing an error. (You can not normally send headers to the browser after data has already been sent.)
Óçìåßùóç: When upgrading from PHP 4.1 (and 4.2) to 4.3 that due to a bug in earlier versions you must ensure that implict_flush is OFF in your php.ini, otherwise any output with ob_start() will not be hidden from output.
Flushes the output buffers of PHP and whatever backend PHP is using (CGI, a web server, etc). This effectively tries to push all the output so far to the user's browser.
flush() has no effect on the buffering scheme of your webserver or the browser on the client side.
Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.
Server modules for Apache like mod_gzip may do buffering of their own that will cause flush() to not result in data being sent immediately to the client.
Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the </table> tag of the outermost table is seen.
Some versions of Microsoft Internet Explorer will only start to display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page.
This function discards the contents of the output buffer.
This function does not destroy the output buffer like ob_end_clean() does.
See also ob_flush(), ob_end_flush() and ob_end_clean().
This function discards the contents of the topmost output buffer and turns off this output buffering. If you want to further process the buffer's contents you have to call ob_get_contents() before ob_end_clean() as the buffer contents are discarded when ob_end_flush() is called. The function returns TRUE when it successfully discarded one buffer and FALSE otherwise. Reasons for failure are first that you called the function without an active buffer or that for some reason a buffer could not be deleted (possible for special buffer).
The following example shows an easy way to get rid of all output buffers:
Óçìåßùóç: If the function fails it generates an E_NOTICE.
The boolean return value was added in PHP 4.2.0.
See also ob_start(), ob_get_contents(), and ob_flush().
This function will send the contents of the topmost output buffer (if any) and turn this output buffer off. If you want to further process the buffer's contents you have to call ob_get_contents() before ob_end_flush() as the buffer contents are discarded after ob_end_flush() is called. The function returns TRUE when it successfully discarded one buffer and FALSE otherwise. Reasons for failure are first that you called the function without an active buffer or that for some reason a buffer could not be deleted (possible for special buffer).
Óçìåßùóç: This function is similar to ob_get_flush(), except that ob_get_flush() returns the buffer as a string.
The following example shows an easy way to flush and end all output buffers:
Óçìåßùóç: If the function fails it generates an E_NOTICE.
The boolean return value was added in PHP 4.2.0.
See also ob_start(), ob_get_contents(), ob_get_flush(), ob_flush() and ob_end_clean().
This function will send the contents of the output buffer (if any). If you want to further process the buffer's contents you have to call ob_get_contents() before ob_flush() as the buffer contents are discarded after ob_flush() is called.
This function does not destroy the output buffer like ob_end_flush() does.
See also ob_get_contents(), ob_clean(), ob_end_flush() and ob_end_clean().
This will return the contents of the output buffer and end output buffering. If output buffering isn't active then FALSE is returned. ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().
See also ob_start() and ob_get_contents().
This will return the contents of the output buffer or FALSE, if output buffering isn't active.
See also ob_start() and ob_get_length().
(PHP 4 >= 4.3.0, PHP 5)
ob_get_flush -- Flush the output buffer, return it as a string and turn off output bufferingob_get_flush() flushs the output buffer, return it as a string and turns off output buffering. ob_get_flush() returns FALSE if no buffering is active.
Óçìåßùóç: This function is similar to ob_end_flush(), except that this function returns the buffer as a string.
ÐáñÜäåéãìá 1. ob_get_flush() example
The above example will output:
|
See also ob_end_clean(), ob_end_flush() and ob_list_handlers().
This will return the length of the contents in the output buffer or FALSE, if output buffering isn't active.
See also ob_start() and ob_get_contents().
This will return the level of nested output buffering handlers or zero if output buffering is not activated.
See also ob_start() and ob_get_contents().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This will return the current status of output buffers. It returns array contains buffer status or FALSE for error.
See also ob_get_level().
Óçìåßùóç: mode was added in PHP 4.0.5.
ob_gzhandler() is intended to be used as a callback function for ob_start() to help facilitate sending gz-encoded data to web browsers that support compressed web pages. Before ob_gzhandler() actually sends compressed data, it determines what type of content encoding the browser will accept ("gzip", "deflate" or none at all) and will return its output accordingly. All browsers are supported since it's up to the browser to send the correct header saying that it accepts compressed web pages.
See also ob_start() and ob_end_flush().
Óçìåßùóç: You cannot use both ob_gzhandler() and ini.zlib.output_compression. Also note that using ini.zlib.output_compression is preferred over ob_gzhandler().
ob_implicit_flush() will turn implicit flushing on or off (if no flag is given, it defaults to on). Implicit flushing will result in a flush operation after every output call, so that explicit calls to flush() will no longer be needed.
Turning implicit flushing on will disable output buffering, the output buffers current output will be sent as if ob_end_flush() had been called.
See also flush(), ob_start(), and ob_end_flush().
This will return an array with the output handlers in use (if any). If output_buffering is enabled, ob_list_handlers() will return "default output handler".
See also ob_end_clean(), ob_end_flush(), ob_get_flush(), and ob_start().
This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.
The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.
An optional output_callback function may be specified. This function takes a string as a parameter and should return a string. The function will be called when ob_end_flush() is called, or when the output buffer is flushed to the browser at the end of the request. When output_callback is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser. If the output_callback is not a callable function, this function will return FALSE.
Óçìåßùóç: In PHP 4.0.4, ob_gzhandler() was introduced to facilitate sending gz-encoded data to web browsers that support compressed web pages. ob_gzhandler() determines what type of content encoding the browser will accept and will return its output accordingly.
Óçìåßùóç: Before PHP 4.3.2 this function did not return FALSE in case the passed output_callback can not be executed.
Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.
ob_end_clean(), ob_end_flush(), ob_clean(), ob_flush() and ob_start() may not be called from a callback function. If you call them from callback function, the behavior is undefined. If you would like to delete the contents of a buffer, return "" (a null string) from callback function.
ÐáñÜäåéãìá 1. User defined callback function example
Would produce:
|
See also ob_get_contents(), ob_end_flush(), ob_end_clean(), ob_implicit_flush() and ob_gzhandler().
This function rewrite the URLs and forms with the given variable.
Óçìåßùóç: This function buffers the output.
ÐáñÜäåéãìá 1. output_add_rewrite_var() example
The above example will output:
|
See also output_reset_rewrite_vars(), ob_flush() and ob_list_handlers().
This function resets the URL rewriter and undo the changes made by output_add_rewrite_var() and/or by session_start() that are still in the buffer.
ÐáñÜäåéãìá 1. output_reset_rewrite_vars() example
The above example will output:
|
See also output_add_rewrite_var(), ob_flush(), ob_list_handlers() and session_start().
The purpose of this extension is to allow overloading of object property access and method calls. Only one function is defined in this extension, overload() which takes the name of the class that should have this functionality enabled. The class named has to define appropriate methods if it wants to have this functionality: __get(), __set() and __call() respectively for getting/setting a property, or calling a method. This way overloading can be selective. Inside these handler functions the overloading is disabled so you can access object properties normally.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
In order to use these functions, you must compile PHP with the --enable-overload option. Starting with PHP 4.3.0 this extension is enabled by default. You can disable overload support with --disable--overload.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Óçìåßùóç: Builtin support for overload is available with PHP 4.3.0.
Some simple examples on using the overload() function:
ÐáñÜäåéãìá 1. Overloading a PHP class
|
Ðñïåéäïðïßçóç |
As this is an experimental extension, not all things work. There is no __call() support currently, you can only overload the get and set operations for properties. You cannot invoke the original overloading handlers of the class, and __set() only works to one level of property access. |
The overload() function will enable property and method call overloading for a class identified by class_name. See an example in the introductory section of this part.
The PDF functions in PHP can create PDF files using the PDFlib library created by Thomas Merz.
The documentation in this section is only meant to be an overview of the available functions in the PDFlib library and should not be considered an exhaustive reference. Please consult the documentation included in the source distribution of PDFlib for the full and detailed explanation of each function here. It provides a very good overview of what PDFlib is capable of doing and contains the most up-to-date documentation of all functions.
All of the functions in PDFlib and the PHP module have identical function names and parameters. You will need to understand some of the basic concepts of PDF and PostScript to efficiently use this extension. All lengths and coordinates are measured in PostScript points. There are generally 72 PostScript points to an inch, but this depends on the output resolution. Please see the PDFlib documentation included with the source distribution of PDFlib for a more thorough explanation of the coordinate system used.
Please note that most of the PDF functions require a pdfdoc as its first parameter. Please see the examples below for more information.
Óçìåßùóç: If you're interested in alternative free PDF generators that do not utilize external PDF libraries, see this related FAQ.
PDFlib is available for download at http://www.pdflib.com/products/pdflib/index.html, but requires that you purchase a license for commercial use. The JPEG and TIFF libraries are required to compile this extension.
To get these functions to work, you have to compile PHP with --with-pdflib[=DIR]. DIR is the PDFlib base install directory, defaults to /usr/local. In addition you can specify the jpeg, tiff, and pnglibrary for PDFlib to use, which is optional for PDFlib 4.x. To do so add to your configure line the options --with-jpeg-dir[=DIR] --with-png-dir[=DIR] --with-tiff-dir[=DIR].
When using version 3.x of PDFlib, you should configure PDFlib with the option --enable-shared-pdflib.
Starting with PHP 4.0.5, the PHP extension for PDFlib is officially supported by PDFlib GmbH. This means that all the functions described in the PDFlib manual (V3.00 or greater) are supported by PHP 4 with exactly the same meaning and the same parameters. Only the return values may differ from the PDFlib manual, because the PHP convention of returning FALSE was adopted. For compatibility reasons, this binding for PDFlib still supports the old functions, but they should be replaced by their new versions. PDFlib GmbH will not support any problems arising from the use of these deprecated functions.
Ðßíáêáò 1. Deprecated functions and their replacements
Old function | Replacement |
---|---|
pdf_put_image() | Not needed anymore. |
pdf_execute_image() | Not needed anymore. |
pdf_get_annotation() | pdf_get_bookmark() using the same parameters. |
pdf_get_font() | pdf_get_value() passing "font" as the second parameter. |
pdf_get_fontsize() | pdf_get_value() passing "fontsize" as the second parameter. |
pdf_get_fontname() | pdf_get_parameter() passing "fontname" as the second parameter. |
pdf_set_info_creator() | pdf_set_info() passing "Creator" as the second parameter. |
pdf_set_info_title() | pdf_set_info() passing "Title" as the second parameter. |
pdf_set_info_subject() | pdf_set_info() passing "Subject" as the second parameter. |
pdf_set_info_author() | pdf_set_info() passing "Author" as the second parameter. |
pdf_set_info_keywords() | pdf_set_info() passing "Keywords" as the second parameter. |
pdf_set_leading() | pdf_set_value() passing "leading" as the second parameter. |
pdf_set_text_rendering() | pdf_set_value() passing "textrendering" as the second parameter. |
pdf_set_text_rise() | pdf_set_value() passing "textrise" as the second parameter. |
pdf_set_horiz_scaling() | pdf_set_value() passing "horizscaling" as the second parameter. |
pdf_set_text_matrix() | Not available anymore |
pdf_set_char_spacing() | pdf_set_value() passing "charspacing" as the second parameter. |
pdf_set_word_spacing() | pdf_set_value() passing "wordspacing" as the second parameter. |
pdf_set_transition() | pdf_set_parameter() passing "transition" as the second parameter. |
pdf_open() | pdf_new() plus an subsequent call of pdf_open_file() |
pdf_set_font() | pdf_findfont() plus an subsequent call of pdf_setfont() |
pdf_set_duration() | pdf_set_value() passing "duration" as the second parameter. |
pdf_open_gif() | pdf_open_image_file() passing "gif" as the second parameter. |
pdf_open_jpeg() | pdf_open_image_file() passing "jpeg" as the second parameter. |
pdf_open_tiff() | pdf_open_image_file() passing "tiff" as the second parameter. |
pdf_open_png() | pdf_open_image_file() passing "png" as the second parameter. |
pdf_get_image_width() | pdf_get_value() passing "imagewidth" as the second parameter and the image as the third parameter. |
pdf_get_image_height() | pdf_get_value() passing "imageheight" as the second parameter and the image as the third parameter. |
Most of the functions are fairly easy to use. The most difficult part is probably creating your first PDF document. The following example should help to get you started. It creates test.pdf with one page. The page contains the text "Times Roman outlined" in an outlined, 30pt font. The text is also underlined.
ÐáñÜäåéãìá 1. Creating a PDF document with PDFlib
|
The PDFlib distribution contains a more complex example which creates a page with an analog clock. Here we use the in-memory creation feature of PDFlib to alleviate the need to use temporary files. The example was converted to PHP from the PDFlib example. (The same example is available in the CLibPDF documentation.)
ÐáñÜäåéãìá 3. pdfclock example from PDFlib distribution
|
Add a nested bookmark under parent, or a new top-level bookmark if parent = 0. Returns a bookmark descriptor which may be used as parent for subsequent nested bookmarks. If open = 1, child bookmarks will be folded out, and invisible if open = 0.
ÐáñÜäåéãìá 1. pdf_add_bookmark() example
|
Adds a link to a web resource specified by filename. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_add_locallink().
Add a link annotation to a target within the current PDF file. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
dest is the zoom setting on the destination page, it can be one of retain, fitpage, fitwidth, fitheight or fitbbox.
See also pdf_add_launchlink().
Sets an annotation for the current page. icon is one of comment, insert, note, paragraph, newparagraph, key, or help. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Add a file link annotation (to a PDF target). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_add_locallink() and pdf_add_weblink().
Adds an existing image as thumbnail for the current page. Thumbnail images must not be wider or higher than 106 pixels. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_open_image(), pdf_open_image_file() and pdf_open_memory_image().
Add a weblink annotation to a target url on the Web. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Add a counterclockwise circular arc from alpha to beta degrees with center (x; y) and radius r. Actual drawing of the circle is performed by the next stroke or fill operation.
ÐáñÜäåéãìá 1. pdf_arcn() example
|
See also: pdf_arcn(), pdf_circle(), pdf_stroke(), pdf_fill() and pdf_fill_stroke().
Add a clockwise circular arc from alpha to beta degrees with center (x; y) and radius r. Actual drawing of the circle is performed by the next stroke or fill operation.
ÐáñÜäåéãìá 1. pdf_arcn() example
|
See also: pdf_arc(), pdf_circle(), pdf_stroke(), pdf_fill() and pdf_fillstroke().
Add a file attachment annotation. icon is one of graph, paperclip, pushpin, or tag. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: Only the 'Full' Acrobat software will be able to display these file attachments. All other PDF viewers will either show nothing or display a question mark.
Add a new page to the document. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. The width and height are specified in points, which are 1/72 of an inch.
Ðßíáêáò 1. Common Page Sizes in Points
name | size |
---|---|
A0 | 2380✗3368 |
A1 | 1684✗2380 |
A2 | 1190✗1684 |
A3 | 842✗1190 |
A4 | 595✗842 |
A5 | 421✗595 |
A6 | 297✗421 |
B5 | 501✗709 |
letter (8.5"✗11") | 612✗792 |
legal (8.5"✗14") | 612✗1008 |
ledger (17"✗11") | 1224✗792 |
11"✗17" | 792✗1224 |
See also pdf_end_page().
Starts a new pattern definition and returns a pattern handle. width, and height define the bounding box for the pattern. xstep and ystep give the repeated pattern offsets. painttype=1 means that the pattern has its own colour settings whereas a value of 2 indicates that the current colour is used when the pattern is applied.
See also pdf_end_pattern().
Start a new template definition.
Add a circle with center (x, y) and radius r to the current page. Actual drawing of the circle is performed by the next stroke or fill operation.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
ÐáñÜäåéãìá 1. pdf_circle() example
|
See also: pdf_arc(), pdf_arcn(), pdf_curveto(), pdf_stroke(), pdf_fill() and pdf_fill_stroke().
Use the current path as clipping path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Close an image retrieved with the pdf_open_image() function.
Close the page handle, and free all page-related resources. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Close all open page handles, and close the input PDF document. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_open_pdi().
Close the generated PDF file, and free all document-related resources. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_new().
Close the path, fill, and stroke it. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_closepath() and pdf_closepath_stroke().
Close the path, and stroke it. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_closepath() and pdf_closepath_fil_stroke().
Close the current path. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_closepath_stroke() and pdf_closepath_fil_stroke().
Concatenate a matrix to the CTM. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Print text at the next line. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Draw a Bezier curve from the current point, using 3 more control points. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Delete the PDF resource, and free all internal resources. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_new().
Finish the page. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_begin_page().
Finish the pattern definition. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_begin_pattern().
Finish the template definition. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function is deprecated, use one of the pdf_stroke(), pdf_clip() or pdf_closepath_fill_stroke() functions instead.
Fill and stroke the path with the current fill and stroke color. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_setcolor().
Fill the interior of the path with the current fill color. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_setcolor().
Prepare a font for later use with pdf_setfont(). The metrics will be loaded, and if embed is nonzero, the font file will be checked, but not yet used. encoding is one of builtin, macroman, winansi, host, a user-defined encoding name or the name of a CMap.
pdf_findfont() returns a font handle or FALSE on error.
Get the contents of the PDF output buffer. The result must be used by the client before calling any other PDFlib function.
Returns the major version number of the PDFlib.
See also pdf_get_minorversion().
Returns the minor version number of the PDFlib.
See also pdf_get_majorversion().
Get the contents of some PDFlib parameter with string type.
Get the contents of some PDI document parameter with string type.
Get the contents of some PDI document parameter with numerical type.
Get the contents of some PDFlib parameter with float type.
Reset all implicit color and graphics state parameters to their defaults. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Draw a line from the current point to (x, y). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Make a named spot color from the current color. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_setcolor().
Set the current point to (x, y. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The current point for graphics and the current text output position are maintained separately. See pdf_set_text_pos() to set the text output position.
Create a new PDF resource, using default error handling and memory management.
See also pdf_close().
Open a raw CCITT image.
Create a new PDF file using the supplied file name. If filename is empty the PDF document will be generated in memory instead of on file. The result must be fetched by the client with the pdf_get_buffer() function. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The following example shows how to create a pdf document in memory and how to output it correctly.
ÐáñÜäåéãìá 1. Creating a PDF document in memory
|
Open an image file. Supported types are jpeg, tiff, gif, and png. stringparam is either , mask, masked, or page. intparamis either 0, the image id of the applied mask, or the page.
Use image data from a variety of data sources. Supported types are jpeg, ccitt, raw. Supported sources are memory, fileref, url. len is only used when type is raw, params is only used when type is ccitt.
(PHP 3>= 3.0.10, PHP 4 , PHP 5)
pdf_open_memory_image -- Opens an image created with PHP's image functionsThe pdf_open_memory_image() function takes an image created with the PHP's image functions and makes it available for the pdf resource. The function returns a pdf image identifier.
See also pdf_close_image() and pdf_place_image().
Prepare a page for later use with pdf_place_image()
Opens an existing PDF document and prepares it for later use.
See also pdf_close_pdi().
Place an image with the lower left corner at (x, y), and scale it. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Place a PDI page with the lower left corner at (x, y), and scale it. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Draw a (width * height) rectangle at lower left (x, y). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Restore the most recently saved graphics state. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Rotate the coordinate system by phi degrees. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Save the current graphics state. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Scale the coordinate system. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
pdf_set_border_color -- Sets color of border around links and annotationsSet the border color for all kinds of annotations. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(PHP 4 >= 4.0.1, PHP 5)
pdf_set_border_dash -- Sets dash style of border around links and annotationsSets the border dash style for all kinds of annotations. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_setdash().
(PHP 3>= 3.0.12, PHP 4 , PHP 5)
pdf_set_border_style -- Sets style of border around links and annotationsSets the border style for all kinds of annotations. style is solid or dashed. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Fill document information field key with value. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. key is one of Subject, Title, Creator, Author, Keywords, or a user-defined key.
Sets some PDFlib parameters with string type. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_set_value().
Set the text output position specified by x and y. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Set the value of some PDFlib parameter with float type. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_set_parameter().
Set the current color space and color. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. The parameter type can be fill, stroke or both to specify that the color is set for filling, stroking or both filling and stroking. The parameter colorspace can be gray, rgb, cmyk, spot or pattern. The parameters c1, c2, c3 and c4 represent the color components for the color space specified by colorspace. Except as otherwise noted, the color components are floating-point values that range from 0 to 1.
For gray only c1 is used.
For rgb parameters c1, c2, and c3 specify the red, green and blue values respectively.
For cmyk, parameters c1, c2, c3, and c4 are the cyan, magenta, yellow and black values, respectively.
For spot, c1 should be a spot color handles returned by pdf_makespotcolor() and c2 is a tint value between 0 and 1.
For pattern, c1 should be a pattern handle returned by pdf_begin_pattern().
Set the current dash pattern to b black and w white units. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Sets the flatness to a value between 0 and 100 inclusive. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Set the current font in the given size, using a font handle returned by pdf_findfont(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pdf_findfont().
Set the current fill color to a gray value between 0 and 1 inclusive. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: PDFlib V4.0: Deprecated, use pdf_setcolor() instead.
Set the current stroke color to a gray value between 0 and 1 inclusive. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: PDFlib V4.0: Deprecated, use pdf_setcolor() instead.
Set the current fill and stroke color. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: PDFlib V4.0: Deprecated, use pdf_setcolor() instead.
Set the linecap parameter to a value between 0 and 2 inclusive.
Sets the line join parameter to a value between 0 and 2 inclusive. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Sets the current linewidth to width. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Explicitly set the current transformation matrix. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Set the miter limit to a value greater than or equal to 1. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Set the current fill color to the supplied RGB values. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: PDFlib V4.0: Deprecated, use pdf_setcolor() instead.
Set the current stroke color to the supplied RGB values. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: PDFlib V4.0: Deprecated, use pdf_setcolor() instead.
Set the current fill and stroke color to the supplied RGB values. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: PDFlib V4.0: Deprecated, use pdf_setcolor() instead.
Format text in the current font and size into the supplied text box according to the requested formatting mode, which must be one of left, right, center, justify or fulljustify. If width and height are 0, only a single line is placed at the point (left, top) in the requested mode.
Returns the number of characters that did not fit in the specified box. Returns 0 if all characters fit or the width and height parameters were set to 0 for single-line formatting.
Print text in the current font at ( x, y). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Print text in the current font and size at the current position. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Skew the coordinate system in x and y direction by alpha and beta degrees. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Returns the width of text using the last font set by pdf_setfont(). If the optional parameters font and size are specified, the width will be calculated using that font and size instead. Please note that font is a font handle returned by pdf_findfont().
Óçìåßùóç: Both the font and size parameters must be used together.
See also pdf_setfont() and pdf_findfont().
Stroke the path with the current color and line width, and clear it. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This extension allows you to process credit cards and other financial transactions using Verisign Payment Services, formerly known as Signio (http://www.verisign.com/products/payflow/pro/index.html).
When using these functions, you may omit calls to pfpro_init() and pfpro_cleanup() as this extension will do so automatically if required. However the functions are still available in case you are processing a number of transactions and require fine control over the library. You may perform any number of transactions using pfpro_process() between the two.
These functions were added in PHP 4.0.2.
Óçìåßùóç: These functions only provide a link to Verisign Payment Services. Be sure to read the Payflow Pro Developers Guide for full details of the required parameters.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
You will require the appropriate SDK for your platform, which may be downloaded from within the manager interface once you have registered. If you are going to use this extension in an SSL-enabled webserver or with other SSL components (such as the CURL+SSL extension) you MUST get the beta SDK.
Once you have downloaded the SDK you should copy the files from the lib directory of the distribution. Copy the header file pfpro.h to /usr/local/include and the library file libpfpro.so to /usr/local/lib.
These functions are only available if PHP has been compiled with the --with-pfpro[=DIR] option.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Verisign Payflow Pro configuration options
Name | Default | Changeable |
---|---|---|
pfpro.defaulthost/PFPRO_VERSION < 3 | "test.signio.com" | PHP_INI_ALL |
pfpro.defaulthost | "test-payflow.verisign.com" | PHP_INI_ALL |
pfpro.defaultport | "443" | PHP_INI_ALL |
pfpro.defaulttimeout | "30" | PHP_INI_ALL |
pfpro.proxyaddress | "" | PHP_INI_ALL |
pfpro.proxyport | "" | PHP_INI_ALL |
pfpro.proxylogon | "" | PHP_INI_ALL |
pfpro.proxypassword | "" | PHP_INI_ALL |
pfpro_cleanup() is used to shutdown the Payflow Pro library cleanly. It should be called after you have processed any transactions and before the end of your script. However you may omit this call, in which case this extension will automatically call pfpro_cleanup() after your script terminates.
See also pfpro_init().
pfpro_init() is used to initialise the Payflow Pro library. You may omit this call, in which case this extension will automatically call pfpro_init() before the first transaction.
See also pfpro_cleanup().
Returns: A string containing the response.
pfpro_process_raw() processes a raw transaction string with Payflow Pro. You should really use pfpro_process() instead, as the encoding rules of these transactions are non-standard.
The first parameter in this case is a string containing the raw transaction request. All other parameters are the same as with pfpro_process(). The return value is a string containing the raw response.
Óçìåßùóç: Be sure to read the Payflow Pro Developers Guide for full details of the required parameters and encoding rules. You would be well advised to use pfpro_process() instead.
ÐáñÜäåéãìá 1. Payflow Pro raw example
|
See also pfpro_process().
Returns: An associative array containing the response
pfpro_process() processes a transaction with Payflow Pro. The first parameter is an associative array containing keys and values that will be encoded and passed to the processor.
The second parameter is optional and specifies the host to connect to. By default this is "test.signio.com", so you will certainly want to change this to "connect.signio.com" in order to process live transactions.
The third parameter specifies the port to connect on. It defaults to 443, the standard SSL port.
The fourth parameter specifies the timeout to be used, in seconds. This defaults to 30 seconds. Note that this timeout appears to only begin once a link to the processor has been established and so your script could potentially continue for a very long time in the event of DNS or network problems.
The fifth parameter, if required, specifies the hostname of your SSL proxy. The sixth parameter specifies the port to use.
The seventh and eighth parameters specify the logon identity and password to use on the proxy.
The function returns an associative array of the keys and values in the response.
Óçìåßùóç: Be sure to read the Payflow Pro Developers Guide for full details of the required parameters.
ÐáñÜäåéãìá 1. Payflow Pro example
|
This functions enable you to get a lot of information about PHP itself, e.g. runtime configuration, loaded extensions, version and much more. You'll also find functions to set options for your running PHP. The probably best known function of PHP - phpinfo() - can be found here.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. PHP Options/Inf Configuration Options
Name | Default | Changeable |
---|---|---|
assert.active | "1" | PHP_INI_ALL |
assert.bail | "0" | PHP_INI_ALL |
assert.warning | "1" | PHP_INI_ALL |
assert.callback | NULL | PHP_INI_ALL |
assert.quiet_eval | "0" | PHP_INI_ALL |
enable_dl | "1" | PHP_INI_SYSTEM |
max_execution_time | "30" | PHP_INI_ALL |
max_input_time | "60" | PHP_INI_ALL |
magic_quotes_gpc | "1" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
magic_quotes_runtime | "0" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Enable assert() evaluation.
Terminate script execution on failed assertions.
Issue a PHP warning for each failed assertion.
user function to call on failed assertions
Use the current setting of error_reporting() during assertion expression evaluation. If enabled, no errors are shown (implicit error_reporting(0)) while evaluation. If disabled, errors are shown according to the settings of error_reporting()
This directive is really only useful in the Apache module version of PHP. You can turn dynamic loading of PHP extensions with dl() on and off per virtual server or per directory.
The main reason for turning dynamic loading off is security. With dynamic loading, it's possible to ignore all open_basedir restrictions. The default is to allow dynamic loading, except when using safe mode. In safe mode, it's always impossible to use dl().
This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30.
The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.
You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.
This sets the maximum time in seconds a script is allowed to receive input data, like POST, GET and file uploads. The default setting is 60.
Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically.
Óçìåßùóç: If the magic_quotes_sybase directive is also ON it will completely override magic_quotes_gpc. Having both directives enabled means only single quotes are escaped as ''. Double quotes, backslashes and NUL's will remain untouched and unescaped.
See also get_magic_quotes_gpc()
If magic_quotes_runtime is enabled, most functions that return data from any sort of external source including databases and text files will have quotes escaped with a backslash. If magic_quotes_sybase is also on, a single-quote is escaped with a single-quote instead of a backslash.
Ïé ðáñáêÜôù óôáèåñÝò åßíáé ðÜíôá äéáèÝóéìåò ùò ìÝñïò ôïõ ðõñÞíá ôçò PHP.
Ðßíáêáò 2. Pre-defined phpcredits() constants
Constant | Value | Description |
---|---|---|
CREDITS_GROUP | 1 | A list of the core developers |
CREDITS_GENERAL | 2 | General credits: Language design and concept, PHP 4.0 authors and SAPI module. |
CREDITS_SAPI | 4 | A list of the server API modules for PHP, and their authors. |
CREDITS_MODULES | 8 | A list of the extension modules for PHP, and their authors. |
CREDITS_DOCS | 16 | The credits for the documentation team. |
CREDITS_FULLPAGE | 32 | Usually used in combination with the other flags. Indicates that the a complete stand-alone HTML page needs to be printed including the information indicated by the other flags. |
CREDITS_QA | 64 | The credits for the quality assurance team. |
CREDITS_ALL | -1 | All the credits, equivalent to using: CREDITS_DOCS + CREDITS_GENERAL + CREDITS_GROUP + CREDITS_MODULES + CREDITS_QA CREDITS_FULLPAGE. It generates a complete stand-alone HTML page with the appropriate tags. This is the default value. |
Ðßíáêáò 3. phpinfo() constants
Constant | Value | Description |
---|---|---|
INFO_GENERAL | 1 | The configuration line, php.ini location, build date, Web Server, System and more. |
INFO_CREDITS | 2 | PHP 4 Credits. See also phpcredits(). |
INFO_CONFIGURATION | 4 | Current Local and Master values for PHP directives. See also ini_get(). |
INFO_MODULES | 8 | Loaded modules and their respective settings. |
INFO_ENVIRONMENT | 16 | Environment Variable information that's also available in $_ENV. |
INFO_VARIABLES | 32 | Shows all predefined variables from EGPCS (Environment, GET, POST, Cookie, Server). |
INFO_LICENSE | 64 | PHP License information. See also the license faq. |
INFO_ALL | -1 | Shows all of the above. This is the default value. |
Using assert_options() you may set the various assert() control options or just query their current settings.
Ðßíáêáò 1. Assert Options
option | ini-parameter | default | description |
---|---|---|---|
ASSERT_ACTIVE | assert.active | 1 | enable assert() evaluation |
ASSERT_WARNING | assert.warning | 1 | issue a PHP warning for each failed assertion |
ASSERT_BAIL | assert.bail | 0 | terminate execution on failed assertions |
ASSERT_QUIET_EVAL | assert.quiet_eval | 0 | disable error_reporting during assertion expression evaluation |
ASSERT_CALLBACK | assert.callback | (NULL) | user function to call on failed assertions |
assert_options() will return the original setting of any option or FALSE on errors.
assert() will check the given assertion and take appropriate action if its result is FALSE.
If the assertion is given as a string it will be evaluated as PHP code by assert(). The advantages of a string assertion are less overhead when assertion checking is off and messages containing the assertion expression when an assertion fails. This means that if you pass a boolean condition as assertion this condition will not show up as parameter to the assertion function which you may have defined with the assert_options() function, the condition is converted to a string before calling that handler function, and the boolean FALSE is converted as the empty string.
Assertions should be used as a debugging feature only. You may use them for sanity-checks that test for conditions that should always be TRUE and that indicate some programming errors if not or to check for the presence of certain features like extension functions or certain system limits and features.
Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be able to work correctly if assertion checking is not activated.
The behavior of assert() may be configured by assert_options() or by .ini-settings described in that functions manual page.
The assert_options() function and/or ASSERT_CALLBACK configuration directive allow a callback function to be set to handle failed assertions.
assert() callbacks are particularly useful for building automated test suites because they allow you to easily capture the code passed to the assertion, along with information on where the assertion was made. While this information can be captured via other methods, using assertions makes it much faster and easier!
The callback function should accept three arguments. The first argument will contain the file the assertion failed in. The second argument will contain the line the assertion failed on and the third argument will contain the expression that failed (if any - literal values such as 1 or "two" will not be passed via this argument)
ÐáñÜäåéãìá 1. Handle a failed assertion with a custom handler
|
Loads the PHP extension given by the parameter library. The library parameter is only the filename of the extension to load which also depends on your platform. For example, the sockets extension (if compiled as a shared module, not the default!) would be called sockets.so on Unix platforms whereas it is called php_sockets.dll on the Windows platform.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. If the functionality of loading modules is not available (see Note) or has been disabled (either by turning it off enable_dl or by enabling safe mode in php.ini) an E_ERROR is emitted and execution is stopped. If dl() fails because the specified library couldn't be loaded, in addition to FALSE an E_WARNING message is emitted.
Use extension_loaded() to test whether a given extension is already available or not. This works on both built-in extensions and dynamically loaded ones (either through php.ini or dl()).
ÐáñÜäåéãìá 1. dl() examples
|
The directory where the extension is loaded from depends on your platform:
Windows - If not explicitly set in the php.ini, the extension is loaded from c:\php4\extensions\ by default.
Unix - If not explicitly set in the php.ini, the default extension directory depends on
whether PHP has been built with --enable-debug or not
whether PHP has been built with (experimental) ZTS (Zend Thread Safety) support or not
the current internal ZEND_MODULE_API_NO (Zend internal module API number, which is basically the date on which a major module API change happened, e.g. 20010901)
Óçìåßùóç: dl() is not supported in multithreaded Web servers. Use the extensions statement in your php.ini when operating under such an environment. However, the CGI and CLI build are not affected !
Óçìåßùóç: dl() is case sensitive on Unix platforms.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé áðåíåñãïðïéçìÝíç óôï safe mode.
See also Extension Loading Directives and extension_loaded().
Returns TRUE if the extension identified by name is loaded, FALSE otherwise.
You can see the names of various extensions by using phpinfo() or if you're using the CGI or CLI version of PHP you can use the -m switch to list all available extensions:
$ php -m [PHP Modules] xml tokenizer standard sockets session posix pcre overload mysql mbstring ctype [Zend Modules] |
Óçìåßùóç: extension_loaded() uses the internal extension name to test whether a certain extension is available or not. Most internal extension names are written in lower case but there may be extension available which also use uppercase letters. Be warned that this function compares case sensitive !
See also get_loaded_extensions(), get_extension_funcs(), phpinfo(), and dl().
Returns the current value of the PHP configuration variable specified by varname, or FALSE if an error occurs.
It will not return configuration information set when the PHP was compiled, or read from an Apache configuration file (using the php3_configuration_option directives).
To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. If this is available, a configuration file is being used.
See also ini_get().
Returns the name of the owner of the current PHP script.
See also getmyuid(), getmygid(), getmypid(), getmyinode(), and getlastmod().
(PHP 4 >= 4.1.0, PHP 5)
get_defined_constants -- Returns an associative array with the names of all the constants and their valuesThis function returns the names and values of all the constants currently defined. This includes those created by extensions as well as those created with the define() function.
For example the line below:
<?php print_r(get_defined_constants()); ?> |
will print a list like:
Array ( [E_ERROR] => 1 [E_WARNING] => 2 [E_PARSE] => 4 [E_NOTICE] => 8 [E_CORE_ERROR] => 16 [E_CORE_WARNING] => 32 [E_COMPILE_ERROR] => 64 [E_COMPILE_WARNING] => 128 [E_USER_ERROR] => 256 [E_USER_WARNING] => 512 [E_USER_NOTICE] => 1024 [E_ALL] => 2047 [TRUE] => 1 ) |
See also get_loaded_extensions(), get_defined_functions(), and get_defined_vars().
This function returns the names of all the functions defined in the module indicated by module_name.
For example the lines below
<?php print_r(get_extension_funcs("xml")); print_r(get_extension_funcs("gd")); ?> |
will print a list of the functions in the modules xml and gd respectively.
See also: get_loaded_extensions()
Gets the current include_path configuration option value.
See also ini_get(), restore_include_path(), set_include_path(), and include().
Returns an array of the names of all files that have been included using include(), include_once(), require() or require_once().
The script originally called is considered an "included file," so it will be listed together with the files referenced by include() and family.
Files that are included or required multiple times only show up once in the returned array.
Óçìåßùóç: Files included using the auto_prepend_file configuration directive are not included in the returned array.
ÐáñÜäåéãìá 1. get_included_files() example (abc.php)
will generate the following output:
|
Óçìåßùóç: In PHP 4.0.1pl2 and previous versions get_included_files() assumed that the required files ended in the extension .php; other extensions would not be returned. The array returned by get_included_files() was an associative array and only listed files included by include() and include_once().
See also include(), include_once(), require(), require_once(), and get_required_files().
(PHP 4 , PHP 5)
get_loaded_extensions -- Returns an array with the names of all modules compiled and loadedThis function returns the names of all the modules compiled and loaded in the PHP interpreter.
For example the line below
<?php print_r(get_loaded_extensions()); ?> |
will print a list like:
Array ( [0] => xml [1] => wddx [2] => standard [3] => session [4] => posix [5] => pgsql [6] => pcre [7] => gd [8] => ftp [9] => db [10] => calendar [11] => bcmath ) |
See also get_extension_funcs(), extension_loaded(), dl(), and phpinfo().
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
get_magic_quotes_gpc -- Gets the current active configuration setting of magic quotes gpcReturns the current active configuration setting of magic_quotes_gpc (0 for off, 1 for on).
Óçìåßùóç: If the directive magic_quotes_sybase is ON it will completely override magic_quotes_gpc. So even when get_magic_quotes() returns TRUE neither double quotes, backslashes or NUL's will be escaped. Only single quotes will be escaped. In this case they'll look like: ''
Keep in mind that magic_quotes_gpc can not be set at runtime.
ÐáñÜäåéãìá 1. get_magic_quotes_gpc() example
|
See also addslashes(), stripslashes(), get_magic_quotes_runtime(), and ini_get().
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
get_magic_quotes_runtime -- Gets the current active configuration setting of magic_quotes_runtimeReturns the current active configuration setting of magic_quotes_runtime (0 for off, 1 for on).
See also get_magic_quotes_gpc() and set_magic_quotes_runtime().
Returns the value of the environment variable varname, or FALSE on an error.
You can see a list of all the environmental variables by using phpinfo(). You can find out what many of them mean by taking a look at the CGI specification, specifically the page on environmental variables.
Óçìåßùóç: This function does not work in ISAPI mode.
See also putenv().
Returns the time of the last modification of the current page. The value returned is a Unix timestamp, suitable for feeding to date(). Returns FALSE on error.
Óçìåßùóç: If you're interested in getting the last modification time of a different file, consider using filemtime().
See also date(), getmyuid(), getmygid(), get_current_user(), getmyinode(), getmypid(), and filemtime().
Returns the group ID of the current script, or FALSE on error.
See also getmyuid(), getmypid(), get_current_user(), getmyinode(), and getlastmod().
Returns the current script's inode, or FALSE on error.
See also getmygid(), getmyuid(), get_current_user(), getmypid(), and getlastmod().
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
Returns the current PHP process ID, or FALSE on error.
Ðñïåéäïðïßçóç |
Process IDs are not unique, thus they are a weak entropy source. We recommend against relying on pids in security-dependent contexts. |
See also getmygid(), getmyuid(), get_current_user(), getmyinode(), and getlastmod().
Returns the user ID of the current script, or FALSE on error.
See also getmygid(), getmypid(), get_current_user(), getmyinode(), and getlastmod().
Returns an associative array of option / argument pairs based on the options format specified in options, or FALSE on an error.
The options parameter may contain the following elements: individual characters, and characters followed by a colon to indicate an option argument is to follow. For example, an option string x recognizes an option -x, and an option string x: recognizes an option and argument -x argument. It does not matter if an argument has leading white space.
This function will return an array of option / argument pairs. If an option does not have an argument, the value will be set to FALSE.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
This is an interface to getrusage(2). It returns an associative array containing the data returned from the system call. If who is 1, getrusage will be called with RUSAGE_CHILDREN.
All entries are accessible by using their documented field names.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí Ý÷åé õëïðïéçèåß óå Windows óõóôÞìáôá.
Returns all the registered configuration options as an associative array. If the optional extension parameter is set, returns only options specific for that extension.
The returned array uses the directive name as the array key, with elements of that array being global_value (set in php.ini), local_value (perhaps set with ini_set() or .htaccess), and access (the access level). See the manual section on configuration changes for information on what access levels mean.
Óçìåßùóç: It's possible for a directive to have multiple access levels, which is why access shows the appropriate bitmask values.
ÐáñÜäåéãìá 1. A ini_get_all() example
Partial output may look like:
|
See also: ini_get(), ini_restore(), ini_set(), get_loaded_extensions(), and phpinfo().
Returns the value of the configuration option on success. Failure, such as querying for a non-existant value, will return an empty string.
When querying boolean values: A boolean ini value of off will be returned as an empty string while a boolean ini value of on will be returned as "1".
When querying memory size values: Many ini memory size values, such as upload_max_filesize are stored in the php.ini file in shorthand notation. ini_get() will return the exact string stored in the php.ini file, NOT its integer equivalent. Attempting normal arithmetic functions on these values will not have otherwise expected results.
<?php /* Our php.ini contains the following settings: display_errors = On register_globals = Off post_max_size = 8M */ echo 'display_errors = ' . ini_get('display_errors') . "\n"; echo 'register_globals = ' . ini_get('register_globals') . "\n"; echo 'post_max_size = ' . ini_get('post_max_size') . "\n"; echo 'post_max_size+1 = ' . (ini_get('post_max_size')+1) . "\n"; ?>This script will produce:
display_errors = 1 register_globals = 0 post_max_size = 8M post_max_size+1 = 9
See also get_cfg_var(), ini_get_all(), ini_restore(), and ini_set().
Restores a given configuration option to its original value.
See also ini_get(), ini_get_all(), and ini_set().
Sets the value of the given configuration option. Returns the old value on success, FALSE on failure. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
Not all the available options can be changed using ini_set(). Below is a table with a list of all PHP options (as of PHP 4.2.0), indicating which ones can be changed/set and at what level.
Ðßíáêáò 1. Configuration options
Name | Default | Changeable |
---|---|---|
com.allow_dcom | "0" | PHP_INI_SYSTEM |
com.autoregister_typelib | "0" | PHP_INI_SYSTEM |
com.autoregister_verbose | "0" | PHP_INI_SYSTEM |
com.autoregister_casesensitive | "1" | PHP_INI_SYSTEM |
com.typelib_file | "" | PHP_INI_SYSTEM |
crack.default_dictionary | NULL | PHP_INI_SYSTEM |
exif.encode_unicode | "ISO-8859-15" | PHP_INI_ALL |
exif.decode_unicode_motorola | "UCS-2BE" | PHP_INI_ALL |
exif.decode_unicode_intel | "UCS-2LE" | PHP_INI_ALL |
exif.encode_jis | "" | PHP_INI_ALL |
exif.decode_jis_motorola | "JIS" | PHP_INI_ALL |
exif.decode_jis_intel | "JIS" | PHP_INI_ALL |
fbsql.allow_persistent | "1" | PHP_INI_SYSTEM |
fbsql.generate_warnings | "0" | PHP_INI_SYSTEM |
fbsql.autocommit | "1" | PHP_INI_SYSTEM |
fbsql.max_persistent | "-1" | PHP_INI_SYSTEM |
fbsql.max_links | "128" | PHP_INI_SYSTEM |
fbsql.max_connections | "128" | PHP_INI_SYSTEM |
fbsql.max_results | "128" | PHP_INI_SYSTEM |
fbsql.batchSize | "1000" | PHP_INI_SYSTEM |
fbsql.default_host | NULL | PHP_INI_SYSTEM |
fbsql.default_user | "_SYSTEM" | PHP_INI_SYSTEM |
fbsql.default_password | "" | PHP_INI_SYSTEM |
fbsql.default_database | "" | PHP_INI_SYSTEM |
fbsql.default_database_password | "" | PHP_INI_SYSTEM |
hwapi.allow_persistent | "0" | PHP_INI_SYSTEM |
hyperwave.allow_persistent | "0" | PHP_INI_SYSTEM |
hyperwave.default_port | "418" | PHP_INI_ALL |
iconv.input_encoding | ICONV_INPUT_ENCODING | PHP_INI_ALL |
iconv.output_encoding | ICONV_OUTPUT_ENCODING | PHP_INI_ALL |
iconv.internal_encoding | ICONV_INTERNAL_ENCODING | PHP_INI_ALL |
ifx.allow_persistent | "1" | PHP_INI_SYSTEM |
ifx.max_persistent | "-1" | PHP_INI_SYSTEM |
ifx.max_links | "-1" | PHP_INI_SYSTEM |
ifx.default_host | NULL | PHP_INI_SYSTEM |
ifx.default_user | NULL | PHP_INI_SYSTEM |
ifx.default_password | NULL | PHP_INI_SYSTEM |
ifx.blobinfile | "1" | PHP_INI_ALL |
ifx.textasvarchar | "0" | PHP_INI_ALL |
ifx.byteasvarchar | "0" | PHP_INI_ALL |
ifx.charasvarchar | "0" | PHP_INI_ALL |
ifx.nullformat | "0" | PHP_INI_ALL |
ingres.allow_persistent | "1" | PHP_INI_SYSTEM |
ingres.max_persistent | "-1" | PHP_INI_SYSTEM |
ingres.max_links | "-1" | PHP_INI_SYSTEM |
ingres.default_database | NULL | PHP_INI_ALL |
ingres.default_user | NULL | PHP_INI_ALL |
ingres.default_password | NULL | PHP_INI_ALL |
ibase.allow_persistent | "1" | PHP_INI_SYSTEM |
ibase.max_persistent | "-1" | PHP_INI_SYSTEM |
ibase.max_links | "-1" | PHP_INI_SYSTEM |
ibase.default_user | NULL | PHP_INI_ALL |
ibase.default_password | NULL | PHP_INI_ALL |
ibase.timestampformat | "%m/%d/%Y%H:%M:%S" | PHP_INI_ALL |
ibase.dateformat | "%m/%d/%Y" | PHP_INI_ALL |
ibase.timeformat | "%H:%M:%S" | PHP_INI_ALL |
java.class.path | NULL | PHP_INI_ALL |
java.home | NULL | PHP_INI_ALL |
java.library.path | NULL | PHP_INI_ALL |
java.library | JAVALIB | PHP_INI_ALL |
java.library | NULL | PHP_INI_ALL |
ldap.max_links | "-1" | PHP_INI_SYSTEM |
mbstring.detect_order | NULL | PHP_INI_ALL |
mbstring.http_input | NULL | PHP_INI_ALL |
mbstring.http_output | NULL | PHP_INI_ALL |
mbstring.internal_encoding | NULL | PHP_INI_ALL |
mbstring.substitute_character | NULL | PHP_INI_ALL |
mbstring.func_overload | "0" | PHP_INI_SYSTEM |
mcrypt.algorithms_dir | NULL | PHP_INI_ALL |
mcrypt.modes_dir | NULL | PHP_INI_ALL |
mime_magic.magicfile | "/usr/share/misc/magic.mime" | PHP_INI_SYSTEM |
mssql.allow_persistent | "1" | PHP_INI_SYSTEM |
mssql.max_persistent | "-1" | PHP_INI_SYSTEM |
mssql.max_links | "-1" | PHP_INI_SYSTEM |
mssql.max_procs | "25" | PHP_INI_ALL |
mssql.min_error_severity | "10" | PHP_INI_ALL |
mssql.min_message_severity | "10" | PHP_INI_ALL |
mssql.compatability_mode | "0" | PHP_INI_ALL |
mssql.connect_timeout | "5" | PHP_INI_ALL |
mssql.timeout | "60" | PHP_INI_ALL |
mssql.textsize | "-1" | PHP_INI_ALL |
mssql.textlimit | "-1" | PHP_INI_ALL |
mssql.batchsize | "0" | PHP_INI_ALL |
mssql.datetimeconvert | "1" | PHP_INI_ALL |
mssql.secure_connection | "0" | PHP_INI_SYSTEM |
mysql.allow_persistent | "1" | PHP_INI_SYSTEM |
mysql.max_persistent | "-1" | PHP_INI_SYSTEM |
mysql.max_links | "-1" | PHP_INI_SYSTEM |
mysql.default_host | NULL | PHP_INI_ALL |
mysql.default_user | NULL | PHP_INI_ALL |
mysql.default_password | NULL | PHP_INI_ALL |
mysql.default_port | NULL | PHP_INI_ALL |
mysql.default_socket | NULL | PHP_INI_ALL |
ncurses.value | "42" | PHP_INI_ALL |
ncurses.string | "foobar" | PHP_INI_ALL |
odbc.allow_persistent | "1" | PHP_INI_SYSTEM |
odbc.max_persistent | "-1" | PHP_INI_SYSTEM |
odbc.max_links | "-1" | PHP_INI_SYSTEM |
odbc.default_db | NULL | PHP_INI_ALL |
odbc.default_user | NULL | PHP_INI_ALL |
odbc.default_pw | NULL | PHP_INI_ALL |
odbc.defaultlrl | "4096" | PHP_INI_ALL |
odbc.defaultbinmode | "1" | PHP_INI_ALL |
odbc.check_persistent | "1" | PHP_INI_SYSTEM |
pfpro.defaulthost | "test.signio.com" | |
pfpro.defaulthost | "test-payflow.verisign.com" | |
pfpro.defaultport | "443" | PHP_INI_ALL |
pfpro.defaulttimeout | "30" | PHP_INI_ALL |
pfpro.proxyaddress | "" | PHP_INI_ALL |
pfpro.proxyport | "" | PHP_INI_ALL |
pfpro.proxylogon | "" | PHP_INI_ALL |
pfpro.proxypassword | "" | PHP_INI_ALL |
pgsql.allow_persistent | "1" | PHP_INI_SYSTEM |
pgsql.max_persistent | "-1" | PHP_INI_SYSTEM |
pgsql.max_links | "-1" | PHP_INI_SYSTEM |
pgsql.auto_reset_persistent | "0" | PHP_INI_SYSTEM |
pgsql.ignore_notice | "0" | PHP_INI_ALL |
pgsql.log_notice | "0" | PHP_INI_ALL |
session.save_path | "/tmp" | PHP_INI_ALL |
session.name | "PHPSESSID" | PHP_INI_ALL |
session.save_handler | "files" | PHP_INI_ALL |
session.auto_start | "0" | PHP_INI_ALL |
session.gc_probability | "1" | PHP_INI_ALL |
session.gc_divisor | "100" | PHP_INI_ALL |
session.gc_maxlifetime | "1440" | PHP_INI_ALL |
session.serialize_handler | "php" | PHP_INI_ALL |
session.cookie_lifetime | "0" | PHP_INI_ALL |
session.cookie_path | "/" | PHP_INI_ALL |
session.cookie_domain | "" | PHP_INI_ALL |
session.cookie_secure | "" | PHP_INI_ALL |
session.use_cookies | "1" | PHP_INI_ALL |
session.use_only_cookies | "0" | PHP_INI_ALL |
session.referer_check | "" | PHP_INI_ALL |
session.entropy_file | "" | PHP_INI_ALL |
session.entropy_length | "0" | PHP_INI_ALL |
session.cache_limiter | "nocache" | PHP_INI_ALL |
session.cache_expire | "180" | PHP_INI_ALL |
session.use_trans_sid | "0" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
session.encode_sources | "globals,track" | PHP_INI_ALL |
assert.active | "1" | PHP_INI_ALL |
assert.bail | "0" | PHP_INI_ALL |
assert.warning | "1" | PHP_INI_ALL |
assert.callback | NULL | PHP_INI_ALL |
assert.quiet_eval | "0" | PHP_INI_ALL |
safe_mode_protected_env_vars | SAFE_MODE_PROTECTED_ENV_VARS | PHP_INI_SYSTEM |
safe_mode_allowed_env_vars | SAFE_MODE_ALLOWED_ENV_VARS | PHP_INI_SYSTEM |
url_rewriter.tags | "a=href,area=href,frame=src,form=fakeentry" | PHP_INI_ALL |
sybct.allow_persistent | "1" | PHP_INI_SYSTEM |
sybct.max_persistent | "-1" | PHP_INI_SYSTEM |
sybct.max_links | "-1" | PHP_INI_SYSTEM |
sybct.min_server_severity | "10" | PHP_INI_ALL |
sybct.min_client_severity | "10" | PHP_INI_ALL |
sybct.hostname | NULL | PHP_INI_ALL |
vpopmail.directory | "" | PHP_INI_ALL |
zlib.output_compression | "0" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
zlib.output_compression_level | "-1" | PHP_INI_ALL |
define_syslog_variables | "0" | PHP_INI_ALL |
highlight.bg | HL_BG_COLOR | PHP_INI_ALL |
highlight.comment | HL_COMMENT_COLOR | PHP_INI_ALL |
highlight.default | HL_DEFAULT_COLOR | PHP_INI_ALL |
highlight.html | HL_HTML_COLOR | PHP_INI_ALL |
highlight.keyword | HL_KEYWORD_COLOR | PHP_INI_ALL |
highlight.string | HL_STRING_COLOR | PHP_INI_ALL |
allow_call_time_pass_reference | "1" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
asp_tags | "0" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
display_errors | "1" | PHP_INI_ALL |
display_startup_errors | "0" | PHP_INI_ALL |
enable_dl | "1" | PHP_INI_SYSTEM |
expose_php | "1" | PHP_INI_SYSTEM |
html_errors | "1" | PHP_INI_ALL |
xmlrpc_errors | "0" | PHP_INI_SYSTEM |
xmlrpc_error_number | "0" | PHP_INI_ALL |
ignore_user_abort | "0" | PHP_INI_ALL |
implicit_flush | "0" | PHP_INI_ALL |
log_errors | "0" | PHP_INI_ALL |
log_errors_max_len | "1024" | PHP_INI_ALL |
ignore_repeated_errors | "0" | PHP_INI_ALL |
ignore_repeated_source | "0" | PHP_INI_ALL |
magic_quotes_gpc | "1" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
magic_quotes_runtime | "0" | PHP_INI_ALL |
magic_quotes_sybase | "0" | PHP_INI_ALL |
output_buffering | "0" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
output_handler | NULL | PHP_INI_PERDIR|PHP_INI_SYSTEM |
register_argc_argv | "1" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
register_globals | "0" | PHP_INI_PERDIR|PHP_INI_SYSTEM |
safe_mode | "1" | PHP_INI_SYSTEM |
safe_mode | "0" | PHP_INI_SYSTEM |
safe_mode_include_dir | NULL | PHP_INI_SYSTEM |
safe_mode_gid | "0" | PHP_INI_SYSTEM |
short_open_tag | DEFAULT_SHORT_OPEN_TAG | PHP_INI_SYSTEM|PHP_INI_PERDIR |
sql.safe_mode | "0" | PHP_INI_SYSTEM |
track_errors | "0" | PHP_INI_ALL |
y2k_compliance | "0" | PHP_INI_ALL |
unserialize_callback_func | NULL | PHP_INI_ALL |
arg_separator.output | "&" | PHP_INI_ALL |
arg_separator.input | "&" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
auto_append_file | NULL | PHP_INI_SYSTEM|PHP_INI_PERDIR |
auto_prepend_file | NULL | PHP_INI_SYSTEM|PHP_INI_PERDIR |
doc_root | NULL | PHP_INI_SYSTEM |
default_charset | SAPI_DEFAULT_CHARSET | PHP_INI_ALL |
default_mimetype | SAPI_DEFAULT_MIMETYPE | PHP_INI_ALL |
error_log | NULL | PHP_INI_ALL |
extension_dir | PHP_EXTENSION_DIR | PHP_INI_SYSTEM |
gpc_order | "GPC" | PHP_INI_ALL |
include_path | PHP_INCLUDE_PATH | PHP_INI_ALL |
max_execution_time | "30" | PHP_INI_ALL |
open_basedir | NULL | PHP_INI_SYSTEM |
safe_mode_exec_dir | "1" | PHP_INI_SYSTEM |
upload_max_filesize | "2M" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
file_uploads | "1" | PHP_INI_SYSTEM |
post_max_size | "8M" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
upload_tmp_dir | NULL | PHP_INI_SYSTEM |
user_dir | NULL | PHP_INI_SYSTEM |
variables_order | NULL | PHP_INI_ALL |
error_append_string | NULL | PHP_INI_ALL |
error_prepend_string | NULL | PHP_INI_ALL |
SMTP | "localhost" | PHP_INI_ALL |
smtp_port | 25 | PHP_INI_ALL |
browscap | NULL | PHP_INI_SYSTEM |
error_reporting | NULL | PHP_INI_ALL |
memory_limit | "8M" | PHP_INI_ALL |
precision | "14" | PHP_INI_ALL |
sendmail_from | NULL | PHP_INI_ALL |
sendmail_path | DEFAULT_SENDMAIL_PATH | PHP_INI_SYSTEM |
disable_classes | "" | php.ini only |
disable_functions | "" | php.ini only |
allow_url_fopen | "1" | PHP_INI_SYSTEM |
always_populate_raw_post_data | "0" | PHP_INI_SYSTEM|PHP_INI_PERDIR |
xbithack | "0" | PHP_INI_ALL |
engine | "1" | PHP_INI_ALL |
last_modified | "0" | PHP_INI_ALL |
child_terminate | "0" | PHP_INI_ALL |
async_send | "0" | PHP_INI_ALL |
Ðßíáêáò 2. Definition of PHP_INI_* constants
Constant | Value | Meaning |
---|---|---|
PHP_INI_USER | 1 | Entry can be set in user scripts |
PHP_INI_PERDIR | 2 | Entry can be set in php.ini, .htaccess or httpd.conf |
PHP_INI_SYSTEM | 4 | Entry can be set in php.ini or httpd.conf |
PHP_INI_ALL | 7 | Entry can be set anywhere |
See also: get_cfg_var(), ini_get(), ini_get_all(), and ini_restore()
There is no function named main() except in the PHP source. In PHP 4.3.0, a new type of error handling in the PHP source (php_error_docref) was introduced. One feature is to provide links to a manual page in PHP error messages when the PHP directives html_errors (on by default) and docref_root (on by default until PHP 4.3.2) are set.
Sometimes error messages refer to a manual page for the function main() which is why this page exists. Please add a user comment below that mentions what PHP function caused the error that linked to main() and it will be fixed and properly documented.
Ðßíáêáò 1. Known errors that point to main()
Function name | No longer points here as of |
---|---|
include() | 4.3.2 |
include_once() | 4.3.2 |
require() | 4.3.2 |
require_once() | 4.3.2 |
See also html_errors and display_errors.
Returns the amount of memory, in bytes, that's currently being allocated to your PHP script.
memory_get_usage() will only be defined if your PHP is compiled with the --enable-memory-limit configuration option.
ÐáñÜäåéãìá 1. A memory_get_usage() example
|
See also memory_limit.
(PHP 4 >= 4.3.0, PHP 5)
php_ini_scanned_files -- Return a list of .ini files parsed from the additional ini dirphp_ini_scanned_files() returns a comma-separated list of configuration files parsed after php.ini. These files are found in a directory defined by the --with-config-file-scan-dir. option which is set during compilation.
Returns a comma-separated string of .ini files on success. If the directive --with-config-files-scan-dir wasn't set, FALSE is returned. If it was set and the directory was empty, an empty string is returned. If a file is unrecognizable, the file will still make it into the returned string but a PHP error will also result. This PHP error will be seen both at compile time and while using php_ini_scanned_files().
The returned configuration files also include the path as declared in the --with-config-file-scan-dir directive. Also, each comma is followed by a newline.
This function returns the ID which can be used to display the PHP logo using the built-in image.
See also phpinfo(), phpversion(), phpcredits() and zend_logo_guid().
php_sapi_name() returns a lowercase string which describes the type of interface between web server and PHP (Server API, SAPI). In CGI PHP, this string is "cgi", in mod_php for Apache, this string is "apache" and so on.
php_uname() returns a string with a description of the operating system PHP is built on. If you're just wanting the name of the operating system, consider using the PHP_OS constant.
ÐáñÜäåéãìá 1. Some php_uname() examples
|
There are also some related Predefined PHP constants that may come in handy, for example:
See also phpversion(), php_sapi_name(), and phpinfo().
This function prints out the credits listing the PHP developers, modules, etc. It generates the appropriate HTML codes to insert the information in a page. flag is optional, and it defaults to CREDITS_ALL. To generate a custom credits page, you may want to use the flag parameter. For example to print the general credits, you will use somewhere in your code:
And if you want to print the core developers and the documentation group, in a page of its own, you will use:
And if you feel like embedding all the credits in your page, then code like the one below will do it:
<html> <head> <title>My credits page</title> </head> <body> <?php // some code of your own phpcredits(CREDITS_ALL - CREDITS_FULLPAGE); // some more code ?> </body> </html> |
Ðßíáêáò 1. Pre-defined phpcredits() flags
name | description |
---|---|
CREDITS_ALL | All the credits, equivalent to using: CREDITS_DOCS + CREDITS_GENERAL + CREDITS_GROUP + CREDITS_MODULES + CREDITS_FULLPAGE. It generates a complete stand-alone HTML page with the appropriate tags. |
CREDITS_DOCS | The credits for the documentation team |
CREDITS_FULLPAGE | Usually used in combination with the other flags. Indicates that the a complete stand-alone HTML page needs to be printed including the information indicated by the other flags. |
CREDITS_GENERAL | General credits: Language design and concept, PHP 4.0 authors and SAPI module. |
CREDITS_GROUP | A list of the core developers |
CREDITS_MODULES | A list of the extension modules for PHP, and their authors |
CREDITS_SAPI | A list of the server API modules for PHP, and their authors |
See also phpinfo(), phpversion() and php_logo_guid().
Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.
Because every system is setup differently, phpinfo() is commonly used to check configuration settings and for available predefined variables on a given system. Also, phpinfo() is a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data.
The output may be customized by passing one or more of the following constants bitwise values summed together in the optional what parameter. One can also combine the respective constants or bitwise values together with the or operator.
Ðßíáêáò 1. phpinfo() options
Name (constant) | Value | Description |
---|---|---|
INFO_GENERAL | 1 | The configuration line, php.ini location, build date, Web Server, System and more. |
INFO_CREDITS | 2 | PHP 4 Credits. See also phpcredits(). |
INFO_CONFIGURATION | 4 | Current Local and Master values for PHP directives. See also ini_get(). |
INFO_MODULES | 8 | Loaded modules and their respective settings. See also get_loaded_modules(). |
INFO_ENVIRONMENT | 16 | Environment Variable information that's also available in $_ENV. |
INFO_VARIABLES | 32 | Shows all predefined variables from EGPCS (Environment, GET, POST, Cookie, Server). |
INFO_LICENSE | 64 | PHP License information. See also the license faq. |
INFO_ALL | -1 | Shows all of the above. This is the default value. |
Óçìåßùóç: Parts of the information displayed are disabled when the expose_php configuration setting is set to off. This includes the PHP and Zend logos, and the credits.
Óçìåßùóç: Since PHP 4.3.0, if html_errors is off, phpinfo() outputs plain text instead of HTML.
See also phpversion(), phpcredits(), php_logo_guid(), ini_get(), ini_set(), get_loaded_modules(), and the section on Predefined Variables.
Returns a string containing the version of the currently running PHP parser.
Óçìåßùóç: This information is also available in the predefined constant PHP_VERSION.
See also version_compare(), phpinfo(), phpcredits(), php_logo_guid(), and zend_version().
Adds setting to the server environment. The environment variable will only exist for the duration of the current request. At the end of the request the environment is restored to its original state.
Setting certain environment variables may be a potential security breach. The safe_mode_allowed_env_vars directive contains a comma-delimited list of prefixes. In Safe Mode, the user may only alter environment variables whose names begin with the prefixes supplied by this directive. By default, users will only be able to set environment variables that begin with PHP_ (e.g. PHP_FOO=BAR). Note: if this directive is empty, PHP will let the user modify ANY environment variable!
The safe_mode_protected_env_vars directive contains a comma-delimited list of environment variables, that the end user won't be able to change using putenv(). These variables will be protected even if safe_mode_allowed_env_vars is set to allow to change them.
Ðñïåéäïðïßçóç |
These directives have only effect when safe-mode itself is enabled! |
See also getenv().
(PHP 4 >= 4.3.0, PHP 5)
restore_include_path -- Restores the value of the include_path configuration optionRestores the include_path configuration option back to its original master value as set in php.ini
ÐáñÜäåéãìá 1. restore_include_path() example
|
See also ini_restore(), set_include_path(), get_include_path(), and include().
Sets the include_path configuration option for the duration of the script. Returns the old include_path on success or FALSE on failure.
See also ini_set(), get_include_path(), restore_include_path(), and include().
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
set_magic_quotes_runtime -- Sets the current active configuration setting of magic_quotes_runtimeSet the current active configuration setting of magic_quotes_runtime (0 for off, 1 for on).
See also: get_magic_quotes_gpc() and get_magic_quotes_runtime().
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
Ðñïåéäïðïßçóç |
set_time_limit() has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini. |
Óçìåßùóç: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.
See also: max_execution_time and max_input_time ini directives.
version_compare() compares two "PHP-standardized" version number strings. This is useful if you would like to write programs working only on some versions of PHP.
version_compare() returns -1 if the first version is lower than the second, 0 if they are equal, and +1 if the second is lower.
The function first replaces _, - and + with a dot . in the version strings and also inserts dots . before and after any non number so that for example '4.3.2RC1' becomes '4.3.2.RC.1'. Then it splits the results like if you were using explode('.', $ver). Then it compares the parts starting from left to right. If a part contains special version strings these are handled in the following order: dev < alpha = a < beta = b < RC < pl. This way not only versions with different levels like '4.1' and '4.1.2' can be compared but also any PHP specific version containing development state.
If you specify the third optional operator argument, you can test for a particular relationship. The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively. Using this argument, the function will return 1 if the relationship is the one specified by the operator, 0 otherwise.
This function returns the ID which can be used to display the Zend logo using the built-in image.
See also php_logo_guid().
Returns a string containing the version of the currently running Zend Engine.
See also phpinfo(), phpcredits(), php_logo_guid(), and phpversion().
This module contains an interface to those functions defined in the IEEE 1003.1 (POSIX.1) standards document which are not accessible through other means. POSIX.1 for example defined the open(), read(), write() and close() functions, too, which traditionally have been part of PHP 3 for a long time. Some more system specific functions have not been available before, though, and this module tries to remedy this by providing easy access to these functions.
Ðñïåéäïðïßçóç |
Sensitive data can be retrieved with the POSIX functions, e.g. posix_getpwnam() and friends. None of the POSIX function perform any kind of access checking when safe mode is enabled. It's therefore strongly advised to disable the POSIX extension at all (use --disable-posix in your configure line) if you're operating in such an environment. |
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.2.0, PHP 5)
posix_get_last_error -- Retrieve the error number set by the last posix function that failed.Returns the errno (error number) set by the last posix function that failed. If no errors exist, 0 is returned. If you're wanting the system error message associated with the errno, use posix_strerror().
See also posix_strerror().
posix_getcwd() returns the absolute pathname of the script's current working directory. posix_getcwd() returns FALSE on error.
(PHP 3>= 3.0.10, PHP 4 , PHP 5)
posix_getegid -- Return the effective group ID of the current processReturn the numeric effective group ID of the current process. See also posix_getgrgid() for information on how to convert this into a useable group name.
Return the numeric effective user ID of the current process. See also posix_getpwuid() for information on how to convert this into a useable username.
Return the numeric real group ID of the current process. See also posix_getgrgid() for information on how to convert this into a useable group name.
Returns an array of information about a group and FALSE on failure. If gid isn't a number then NULL is returned and an E_WARNING level error is generated.
Óçìåßùóç: As of PHP 4.2.0, members is returned as an array of member usernames in the group. Before this time it was simply an integer (the number of members in the group) and the member names were returned with numerical indices.
See also posix_getegid(), filegroup(), stat(), and safe_mode_gid.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns an array of integers containing the numeric group ids of the group set of the current process. See also posix_getgrgid() for information on how to convert this into useable group names.
Returns the login name of the user owning the current process. See posix_getpwnam() for information how to get more information about this user.
Returns the process group identifier of the process pid.
This is not a POSIX function, but is common on BSD and System V systems. If your system does not support this function at system level, this PHP function will always return FALSE.
Return the process group identifier of the current process. See POSIX.1 and the getpgrp(2) manual page on your POSIX system for more information on process groups.
Return the process identifier of the parent process of the current process.
Returns an associative array containing information about a user referenced by an alphanumeric username, passed in the username parameter.
The array elements returned are:
Ðßíáêáò 1. The user information array
Element | Description |
---|---|
name | The name element contains the username of the user. This is a short, usually less than 16 character "handle" of the user, not her real, full name. This should be the same as the username parameter used when calling the function, and hence redundant. |
passwd | The passwd element contains the user's password in an encrypted format. Often, for example on a system employing "shadow" passwords, an asterisk is returned instead. |
uid | User ID of the user in numeric form. |
gid | The group ID of the user. Use the function posix_getgrgid() to resolve the group name and a list of its members. |
gecos | GECOS is an obsolete term that refers to the finger information field on a Honeywell batch processing system. The field, however, lives on, and its contents have been formalized by POSIX. The field contains a comma separated list containing the user's full name, office phone, office number, and home phone number. On most systems, only the user's full name is available. |
dir | This element contains the absolute path to the home directory of the user. |
shell | The shell element contains the absolute path to the executable of the user's default shell. |
Returns an associative array containing information about a user referenced by a numeric user ID, passed in the uid parameter.
The array elements returned are:
Ðßíáêáò 1. The user information array
Element | Description |
---|---|
name | The name element contains the username of the user. This is a short, usually less than 16 character "handle" of the user, not her real, full name. |
passwd | The passwd element contains the user's password in an encrypted format. Often, for example on a system employing "shadow" passwords, an asterisk is returned instead. |
uid | User ID, should be the same as the uid parameter used when calling the function, and hence redundant. |
gid | The group ID of the user. Use the function posix_getgrgid() to resolve the group name and a list of its members. |
gecos | GECOS is an obsolete term that refers to the finger information field on a Honeywell batch processing system. The field, however, lives on, and its contents have been formalized by POSIX. The field contains a comma separated list containing the user's full name, office phone, office number, and home phone number. On most systems, only the user's full name is available. |
dir | This element contains the absolute path to the home directory of the user. |
shell | The shell element contains the absolute path to the executable of the user's default shell. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Return the sid of the process pid. If pid is 0, the sid of the current process is returned.
This is not a POSIX function, but is common on System V systems. If your system does not support this function at system level, this PHP function will always return FALSE.
Return the numeric real user ID of the current process. See also posix_getpwuid() for information on how to convert this into a useable username.
(PHP 3>= 3.0.13, PHP 4 , PHP 5)
posix_isatty -- Determine if a file descriptor is an interactive terminal
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Send the signal sig to the process with the process identifier pid. Returns FALSE, if unable to send the signal, TRUE otherwise.
See also the kill(2) manual page of your POSIX system, which contains additional information about negative process identifiers, the special pid 0, the special pid -1, and the signal number 0.
posix_mkfifo() creates a special FIFO file which exists in the file system and acts as a bidirectional communication endpoint for processes.
The second parameter mode has to be given in octal notation (e.g. 0644). The permission of the newly created FIFO also depends on the setting of the current umask(). The permissions of the created file are (mode & ~umask).
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ï êáôÜëïãïò óôïí ïðïßï ðñüêåéôáé íá åíåñãÞóåôå Ý÷åé ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
Set the effective group ID of the current process. This is a privileged function and you need appropriate privileges (usually root) on your system to be able to perform this function.
Returns TRUE on success, FALSE otherwise.
Set the real user ID of the current process. This is a privileged function and you need appropriate privileges (usually root) on your system to be able to perform this function.
Returns TRUE on success, FALSE otherwise. See also posix_setgid().
Set the real group ID of the current process. This is a privileged function and you need appropriate privileges (usually root) on your system to be able to perform this function. The appropriate order of function calls is posix_setgid() first, posix_setuid() last.
Returns TRUE on success, FALSE otherwise.
Let the process pid join the process group pgid. See POSIX.1 and the setsid(2) manual page on your POSIX system for more informations on process groups and job control. Returns TRUE on success, FALSE otherwise.
Make the current process a session leader. See POSIX.1 and the setsid(2) manual page on your POSIX system for more informations on process groups and job control. Returns the session id.
Set the real user ID of the current process. This is a privileged function and you need appropriate privileges (usually root) on your system to be able to perform this function.
Returns TRUE on success, FALSE otherwise. See also posix_setgid().
(PHP 4 >= 4.2.0, PHP 5)
posix_strerror -- Retrieve the system error message associated with the given errno.Returns the POSIX system error message associated with the given errno. If errno is 0, then the string "Success" is returned. The function posix_get_last_error() is used for retrieving the last POSIX errno.
See also posix_get_last_error().
Returns a hash of strings with information about the current process CPU usage. The indices of the hash are
ticks - the number of clock ticks that have elapsed since reboot.
utime - user time used by the current process.
stime - system time used by the current process.
cutime - user time used by current process and children.
cstime - system time used by current process and children.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns a hash of strings with information about the system. The indices of the hash are
sysname - operating system name (e.g. Linux)
nodename - system name (e.g. valiant)
release - operating system release (e.g. 2.2.10)
version - operating system version (e.g. #4 Tue Jul 20 17:01:36 MEST 1999)
machine - system architecture (e.g. i586)
domainname - DNS domainname (e.g. php.net)
domainname is a GNU extension and not part of POSIX.1, so this field is only available on GNU systems or when using the GNU libc.
Posix requires that you must not make any assumptions about the format of the values, e.g. you cannot rely on three digit version numbers or anything else returned by this function.
PostgreSQL database is Open Source product and available without cost. Postgres, developed originally in the UC Berkeley Computer Science Department, pioneered many of the object-relational concepts now becoming available in some commercial databases. It provides SQL92/SQL99 language support, transactions, referential integrity, stored procedures and type extensibility. PostgreSQL is an open source descendant of this original Berkeley code.
To use PostgreSQL support, you need PostgreSQL 6.5 or later, PostgreSQL 7.0 or later to enable all PostgreSQL module features. PostgreSQL supports many character encoding including multibyte character encoding. The current version and more information about PostgreSQL is available at http://www.postgresql.org/ and http://techdocs.postgresql.org/.
In order to enable PostgreSQL support, --with-pgsql[=DIR] is required when you compile PHP. DIR is the PostgreSQL base install directory, defaults to /usr/local/pgsql. If shared object module is available, PostgreSQL module may be loaded using extension directive in php.ini or dl() function.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. PostgreSQL configuration options
Name | Default | Changeable |
---|---|---|
pgsql.allow_persistent | "1" | PHP_INI_SYSTEM |
pgsql.max_persistent | "-1" | PHP_INI_SYSTEM |
pgsql.max_links | "-1" | PHP_INI_SYSTEM |
pgsql.auto_reset_persistent | "0" | PHP_INI_SYSTEM |
pgsql.ignore_notice | "0" | PHP_INI_ALL |
pgsql.log_notice | "0" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to allow persistent Postgres connections.
The maximum number of persistent Postgres connections per process.
The maximum number of Postgres connections per process, including persistent connections.
Detect broken persistent links with pg_pconnect(). Needs a little overhead.
Whether or not to ignore PostgreSQL backend notices.
Whether or not to log PostgreSQL backends notice messages. The PHP directive pgsql.ignore_notice must be off in order to log notice messages.
Ðñïåéäïðïßçóç |
Using the PostgreSQL module with PHP 4.0.6 is not recommended due to a bug in the notice message handling code. Use 4.1.0 or later. |
Ðñïåéäïðïßçóç | ||||||||||||||||||||||||||||||||||||||||||||||
PostgreSQL function names will be changed in 4.2.0 release to confirm to current coding standards. Most of new names will have additional underscores, e.g. pg_lo_open(). Some functions are renamed to different name for consistency. e.g. pg_exec() to pg_query(). Older names can be used in 4.2.0 and a few releases from 4.2.0, but they may be deleted in the future. Ðßíáêáò 2. Function names changed
The old pg_connect()/pg_pconnect() syntax will be deprecated to support asynchronous connections in the future. Please use a connection string for pg_connect() and pg_pconnect(). |
Not all functions are supported by all builds. It depends on your libpq (The PostgreSQL C Client interface) version and how libpq is compiled. If there is missing function, libpq does not support the feature required for the function.
It is also important that you do not use an older libpq than the PostgreSQL Server to which you will be connecting. If you use libpq older than PostgreSQL Server expects, you may have problems.
Since version 6.3 (03/02/1998) PostgreSQL uses unix domain sockets by default. TCP port will NOT be opened by default. A table is shown below describing these new connection possibilities. This socket will be found in /tmp/.s.PGSQL.5432. This option can be enabled with the '-i' flag to postmaster and its meaning is: "listen on TCP/IP sockets as well as Unix domain sockets".
Ðßíáêáò 3. Postmaster and PHP
Postmaster | PHP | Status |
---|---|---|
postmaster & | pg_connect("dbname=MyDbName"); | OK |
postmaster -i & | pg_connect("dbname=MyDbName"); | OK |
postmaster & | pg_connect("host=localhost dbname=MyDbName"); | Unable to connect to PostgreSQL server: connectDB() failed: Is the postmaster running and accepting TCP/IP (with -i) connection at 'localhost' on port '5432'? in /path/to/file.php on line 20. |
postmaster -i & | pg_connect("host=localhost dbname=MyDbName"); | OK |
A connection to PostgreSQL server can be established with the following value pairs set in the command string: $conn = pg_connect("host=myHost port=myPort tty=myTTY options=myOptions dbname=myDB user=myUser password=myPassword ");
The previous syntax of: $conn = pg_connect ("host", "port", "options", "tty", "dbname") has been deprecated.
Environmental variables affect PostgreSQL server/client behavior. For example, PostgreSQL module will lookup PGHOST environment variable when the hostname is omitted in the connection string. Supported environment variables are different from version to version. Refer to PostgreSQL Programmer's Manual (libpq - Environment Variables) for details.
Make sure you set environment variables for appropriate user. Use $_ENV or getenv() to check which environment variables are available to the current process.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Starting with PostgreSQL 7.1.0, you can store up to 1GB into a field of type text. In older versions, this was limited to the block size (default was 8KB, maximum was 32KB, defined at compile time)
To use the large object (lo) interface, it is required to enclose large object functions within a transaction block. A transaction block starts with a SQL statement BEGIN and if the transaction was valid ends with COMMIT or END. If the transaction fails the transaction should be closed with ROLLBACK or ABORT.
ÐáñÜäåéãìá 2. Using Large Objects
|
pg_affected_rows() returns the number of tuples (instances/records/rows) affected by INSERT, UPDATE, and DELETE queries executed by pg_query(). If no tuple is affected by this function, it will return 0.
Óçìåßùóç: This function used to be called pg_cmdtuples().
See also pg_query() and pg_num_rows().
pg_cancel_query() cancel asynchronous query sent by pg_send_query(). You cannot cancel query executed by pg_query().
See also pg_send_query() and pg_connection_busy().
pg_client_encoding() returns the client encoding as the string. The returned string should be either : SQL_ASCII, EUC_JP, EUC_CN, EUC_KR, EUC_TW, UNICODE, MULE_INTERNAL, LATINX (X=1...9), KOI8, WIN, ALT, SJIS, BIG5, WIN1250.
Óçìåßùóç: This function requires PHP-4.0.3 or higher and PostgreSQL-7.0 or higher. If libpq is compiled without multibyte encoding support, pg_set_client_encoding() always return "SQL_ASCII". Supported encoding depends on PostgreSQL version. Refer to PostgreSQL manual for details to enable multibyte support and encoding supported.
The function used to be called pg_clientencoding().
See also pg_set_client_encoding().
pg_close() closes the non-persistent connection to a PostgreSQL database associated with the given connection resource. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: Using pg_close() is not usually necessary, as non-persistent open connections are automatically closed at the end of the script.
If there is open large object resource on the connection, do not close the connection before closing all large object resources.
pg_connect() returns a connection resource that is needed by other PostgreSQL functions.
pg_connect() opens a connection to a PostgreSQL database specified by the connection_string. It returns a connection resource on success. It returns FALSE if the connection could not be made. connection_string should be a quoted string.
ÐáñÜäåéãìá 1. Using pg_connect()
|
If a second call is made to pg_connect() with the same connection_string, no new connection will be established, but instead, the connection resource of the already opened connection will be returned. You can have multiple connections to the same database if you use different connection strings.
The old syntax with multiple parameters $conn = pg_connect("host", "port", "options", "tty", "dbname") has been deprecated.
See also pg_pconnect(), pg_close(), pg_host(), pg_port(), pg_tty(), pg_options() and pg_dbname().
pg_connection_busy() returns TRUE if the connection is busy. If it is busy, a previous query is still executing. If pg_get_result() is called, it will be blocked.
See also pg_connection_status() and pg_get_result().
pg_connection_reset() resets the connection. It is useful for error recovery. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pg_connect(), pg_pconnect() and pg_connection_status().
pg_connection_status() returns a connection status. Possible statuses are PGSQL_CONNECTION_OK and PGSQL_CONNECTION_BAD. The return value 0 as integer indicates a valid connection.
See also pg_connection_busy().
(PHP 4 >= 4.3.0, PHP 5)
pg_convert -- Convert associative array value into suitable for SQL statement.pg_convert() checks and converts the values in assoc_array into suitable values for use in a SQL statement. Precondition for pg_convert() is the existence of a table table_name which has at least as many columns as assoc_array has elements. The fieldnames as well as the fieldvalues in table_name must match the indices and values of assoc_array. Returns an array with the converted values on success, FALSE otherwise.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also pg_meta_data().
pg_copy_from() insert records into a table from rows. It issues COPY FROM SQL command internally to insert records. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also pg_copy_to().
pg_copy_to() copies a table to an array. It issues COPY TO SQL command internally to retrieve records. The resulting array is returned. It returns FALSE on failure.
See also pg_copy_from().
pg_dbname() returns the name of the database that the given PostgreSQL connection resource. It returns FALSE, if connection is not a valid PostgreSQL connection resource.
pg_delete() deletes record condition specified by assoc_array which has field=>value. If option is specified, pg_convert() is applied to assoc_array with specified option.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also pg_convert().
pg_end_copy() syncs the PostgreSQL frontend (usually a web server process) with the PostgreSQL server after doing a copy operation performed by pg_put_line(). pg_end_copy() must be issued, otherwise the PostgreSQL server may get out of sync with the frontend and will report an error. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
For further details and an example, see also pg_put_line().
pg_escape_bytea() escapes string for bytea datatype. It returns escaped string.
Óçìåßùóç: When you SELECT bytea type, PostgreSQL returns octal byte value prefixed by \ (e.g. \032). Users are supposed to convert back to binary format by yourself.
This function requires PostgreSQL 7.2 or later. With PostgreSQL 7.2.0 and 7.2.1, bytea type must be casted when you enable multi-byte support. i.e. INSERT INTO test_table (image) VALUES ('$image_escaped'::bytea); PostgreSQL 7.2.2 or later does not need cast. Exception is when client and backend character encoding does not match, there may be multi-byte stream error. User must cast to bytea to avoid this error.
See also pg_unescape_bytea() and pg_escape_string().
pg_escape_string() escapes string for text/char datatype. It returns escaped string for PostgreSQL. Use of this function is recommended instead of addslashes().
Óçìåßùóç: This function requires PostgreSQL 7.2 or later.
See also pg_escape_bytea()
pg_fetch_all() returns an array that contains all rows (tuples/records) in result resource. It returns FALSE, if there are no rows.
See also pg_fetch_row(), pg_fetch_array(), pg_fetch_object() and pg_fetch_result().
pg_fetch_array() returns an array that corresponds to the fetched row (tuples/records). It returns FALSE, if there are no more rows.
pg_fetch_array() is an extended version of pg_fetch_row(). In addition to storing the data in the numeric indices (field index) to the result array, it also stores the data in associative indices (field name) by default.
row is row (record) number to be retrieved. First row is 0.
result_type is an optional parameter that controls how the return value is initialized. result_type is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. pg_fetch_array() returns associative array that has field name as key for PGSQL_ASSOC, field index as key with PGSQL_NUM and both field name/index as key with PGSQL_BOTH. Default is PGSQL_BOTH.
Óçìåßùóç: result_type was added in PHP 4.0.
pg_fetch_array() is NOT significantly slower than using pg_fetch_row(), while it provides a significant ease of use.
ÐáñÜäåéãìá 1. pg_fetch_array() example
|
Óçìåßùóç: From 4.1.0, row became optional. Calling pg_fetch_array() will increment internal row counter by 1.
See also pg_fetch_row(), pg_fetch_object() and pg_fetch_result().
pg_fetch_assoc() returns an associative array that corresponds to the fetched row (tuples/records). It returns FALSE, if there are no more rows.
pg_fetch_assoc() is equivalent to calling pg_fetch_array() with PGSQL_ASSOC for the optional third parameter. It only returns an associative array. If you need the numeric indices, use pg_fetch_row().
row is row (record) number to be retrieved. First row is 0.
pg_fetch_assoc() is NOT significantly slower than using pg_fetch_row(), while it provides a significant ease of use.
ÐáñÜäåéãìá 1. pg_fetch_assoc() example
|
See also pg_fetch_row(), pg_fetch_array(), pg_fetch_object() and pg_fetch_result().
pg_fetch_object() returns an object with properties that correspond to the fetched row. It returns FALSE if there are no more rows or error.
pg_fetch_object() is similar to pg_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
row is row (record) number to be retrieved. First row is 0.
Speed-wise, the function is identical to pg_fetch_array(), and almost as quick as pg_fetch_row() (the difference is insignificant).
Óçìåßùóç: From 4.1.0, row is optional.
From 4.3.0, result_type is default to PGSQL_ASSOC while older versions' default was PGSQL_BOTH. There is no use for numeric property, since numeric property name is invalid in PHP.
result_type may be deleted in future versions.
ÐáñÜäåéãìá 1. pg_fetch_object() example
|
Óçìåßùóç: From 4.1.0, row became optional. Calling pg_fetch_object() will increment internal row counter counter by 1.
See also pg_query(), pg_fetch_array(), pg_fetch_assoc(), pg_fetch_row() and pg_fetch_result().
pg_fetch_result() returns values from a result resource returned by pg_query(). row is integer. field is field name (string) or field index (integer). The row and field specify what cell in the table of results to return. Row numbering starts from 0. Instead of naming the field, you may use the field index as an unquoted number. Field indices start from 0.
PostgreSQL has many built in types and only the basic ones are directly supported here. All forms of integer types are returned as integer values. All forms of float, and real types are returned as float values. Boolean is returned as "t" or "f". All other types, including arrays are returned as strings formatted in the same default PostgreSQL manner that you would see in the psql program.
pg_fetch_row() fetches one row of data from the result associated with the specified result resource. The row (record) is returned as an array. Each result column is stored in an array offset, starting at offset 0.
It returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
ÐáñÜäåéãìá 1. pg_fetch_row() example
|
Óçìåßùóç: From 4.1.0, row became optional. Calling pg_fetch_row() will increment internal row counter by 1.
See also pg_query(), pg_fetch_array(), pg_fetch_object() and pg_fetch_result().
pg_field_is_null() tests if a field is NULL or not. It returns 1 if the field in the given row is NULL. It returns 0 if the field in the given row is NOT NULL. Field can be specified as column index (number) or fieldname (string). Row numbering starts at 0.
ÐáñÜäåéãìá 1. pg_field_is_null() example
|
Óçìåßùóç: This function used to be called pg_fieldisnull().
pg_field_name() returns the name of the field occupying the given field_number in the given PostgreSQL result resource. Field numbering starts from 0.
ÐáñÜäåéãìá 1. Getting informations about fields
The above example would produce the following output:
|
Óçìåßùóç: This function used to be called pg_fieldname().
See also pg_field_num().
pg_field_num() will return the number of the column (field) slot that corresponds to the field_name in the given PostgreSQL result resource. Field numbering starts at 0. This function will return -1 on error.
See the example given at the pg_field_name() page.
Óçìåßùóç: This function used to be called pg_fieldnum().
See also pg_field_name().
pg_field_prtlen() returns the actual printed length (number of characters) of a specific value in a PostgreSQL result. Row numbering starts at 0. This function will return -1 on an error.
See the example given at the pg_field_name() page.
Óçìåßùóç: This function used to be called pg_fieldprtlen().
See also pg_field_size().
pg_field_size() returns the internal storage size (in bytes) of the field number in the given PostgreSQL result. Field numbering starts at 0. A field size of -1 indicates a variable length field. This function will return FALSE on error.
See the example given at the pg_field_name() page.
Óçìåßùóç: This function used to be called pg_fieldsize().
See also pg_field_prtlen() and pg_field_type().
pg_field_type() returns a string containing the type name of the given field_number in the given PostgreSQL result resource. Field numbering starts at 0.
See the example given at the pg_field_name() page.
Óçìåßùóç: This function used to be called pg_fieldtype().
See also pg_field_prtlen() and pg_field_name().
pg_free_result() only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script is finished. But, if you are sure you are not going to need the result data anymore in a script, you may call pg_free_result() with the result resource as an argument and the associated result memory will be freed. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: This function used to be called pg_freeresult().
See also pg_query().
pg_get_notify() gets notify message sent by NOTIFY SQL command. To receive notify messages, LISTEN SQL command must be issued. If there is notify message on the connection, array contains message name and backend PID is returned. If there is no message, FALSE is returned.
See also pg_get_pid()
ÐáñÜäåéãìá 1. PostgreSQL NOTIFY message
|
pg_get_pid() gets backend (database server process) PID. PID is useful to check if NOTIFY message is sent from other process or not.
See also pg_get_notify().
pg_get_result() get result resource from async query executed by pg_send_query(). pg_send_query() can send multiple queries to PostgreSQL server and pg_get_result() is used to get query result one by one. It returns result resource. If there is no more results, it returns FALSE.
pg_host() returns the host name of the given PostgreSQL connection resource is connected to.
See also pg_connect() and pg_pconnect().
pg_insert() inserts the values of assoc_array into the table specified by table_name. table_name must at least have as many columns as assoc_array has elements. The fieldnames as well as the fieldvalues in table_name must match the indices and values of assoc_array. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. If options is specified, pg_insert() is applied to assoc_array with specified option.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also pg_convert().
pg_last_error() returns the last error message for given connection.
Error messages may be overwritten by internal PostgreSQL(libpq) function calls. It may not return appropriate error message, if multiple errors are occurred inside a PostgreSQL module function.
Use pg_result_error(), pg_result_status() and pg_connection_status() for better error handling.
Óçìåßùóç: This function used to be called pg_errormessage().
See also pg_result_error().
pg_last_notice() returns the last notice message from the PostgreSQL server specified by connection. The PostgreSQL server sends notice messages in several cases, e.g. if the transactions can't be continued. With pg_last_notice(), you can avoid issuing useless queries, by checking whether the notice is related to the transaction or not.
Ðñïåéäïðïßçóç |
This function is EXPERIMENTAL and it is not fully implemented yet. pg_last_notice() was added in PHP 4.0.6. However, PHP 4.0.6 has problem with notice message handling. Use of the PostgreSQL module with PHP 4.0.6 is not recommended even if you are not using pg_last_notice(). This function is fully implemented in PHP 4.3.0. PHP earlier than PHP 4.3.0 ignores database connection parameter. |
Notice message tracking can be set to optional by setting 1 for pgsql.ignore_notice in php.ini from PHP 4.3.0.
Notice message logging can be set to optional by setting 0 for pgsql.log_notice in php.ini from PHP 4.3.0. Unless pgsql.ignore_notice is set to 0, notice message cannot be logged.
See also pg_query() and pg_last_error().
pg_last_oid() is used to retrieve the oid assigned to an inserted tuple (record) if the result resource is used from the last command sent via pg_query() and was an SQL INSERT. Returns a positive integer if there was a valid oid. It returns FALSE if an error occurs or the last command sent via pg_query() was not an INSERT or INSERT is failed.
OID field became an optional field from PostgreSQL 7.2. When OID field is not defined in a table, programmer must use pg_result_status() to check if record is is inserted successfully or not.
Óçìåßùóç: This function used to be called pg_getlastoid().
See also pg_query() and pg_result_status()
pg_lo_close() closes a Large Object. large_object is a resource for the large object from pg_lo_open().
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_loclose().
See also pg_lo_open(), pg_lo_create() and pg_lo_import().
pg_lo_create() creates a Large Object and returns the oid of the large object. connection specifies a valid database connection opened by pg_connect() or pg_pconnect(). PostgreSQL access modes INV_READ, INV_WRITE, and INV_ARCHIVE are not supported, the object is created always with both read and write access. INV_ARCHIVE has been removed from PostgreSQL itself (version 6.3 and above). It returns large object oid, otherwise it returns FALSE if an error occurred.
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_locreate().
The oid argument specifies oid of the large object to export and the pathname argument specifies the pathname of the file. It returns FALSE if an error occurred, TRUE otherwise.
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_loexport().
See also pg_lo_import().
In versions before PHP 4.2.0 the syntax of this function was different, see the following definition:
int pg_lo_import ( string pathname [, resource connection])The pathname argument specifies the pathname of the file to be imported as a large object. It returns FALSE if an error occurred, oid of the just created large object otherwise.
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: ¼ôáí ôï safe mode åßíáé åíåñãïðïéçìÝíï, ç PHP åëÝã÷åé ôá áñ÷åßá Þ ïé êáôÜëïãïé óôïõò ïðïßïõò ðñüêåéôáé íá åíåñãÞóåôå Ý÷ïõí ôï ßäéï UID (éäéïêôÞôç) üðùò ôï script ôï ïðïßï åêôåëåßôáé.
Óçìåßùóç: This function used to be called pg_loimport().
See also pg_lo_export() and pg_lo_open().
pg_lo_open() opens a Large Object and returns large object resource. The resource encapsulates information about the connection. oid specifies a valid large object oid and mode can be either "r", "w", or "rw". It returns FALSE if there is an error.
Ðñïåéäïðïßçóç |
Do not close the database connection before closing the large object resource. |
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_loopen().
See also pg_lo_close() and pg_lo_create().
pg_lo_read_all() reads a large object and passes it straight through to the browser after sending all pending headers. Mainly intended for sending binary data like images or sound. It returns number of bytes read. It returns FALSE, if an error occurred.
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_loreadall().
See also pg_lo_read().
pg_lo_read() reads at most len bytes from a large object and returns it as a string. large_object specifies a valid large object resource andlen specifies the maximum allowable size of the large object segment. It returns FALSE if there is an error.
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_loread().
See also pg_lo_read_all().
pg_lo_seek() seeks position of large object resource. whence is PGSQL_SEEK_SET, PGSQL_SEEK_CUR or PGSQL_SEEK_END.
See also pg_lo_tell().
pg_lo_tell() returns current position (offset from the beginning of large object).
See also pg_lo_seek().
pg_lo_unlink() deletes a large object with the oid. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_lo_unlink().
See also pg_lo_create() and pg_lo_import().
pg_lo_write() writes at most to a large object from a variable data and returns the number of bytes actually written, or FALSE in the case of an error. large_object is a large object resource from pg_lo_open().
To use the large object (lo) interface, it is necessary to enclose it within a transaction block.
Óçìåßùóç: This function used to be called pg_lowrite().
See also pg_lo_create() and pg_lo_open().
pg_meta_data() returns table definition for table_name as an array. If there is error, it returns FALSE
ÐáñÜäåéãìá 1. Getting table metadata
The above example would produce the following output:
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also pg_convert().
pg_num_fields() returns the number of fields (columns) in a PostgreSQL result. The argument is a result resource returned by pg_query(). This function will return -1 on error.
Óçìåßùóç: This function used to be called pg_numfields().
See also pg_num_rows() and pg_affected_rows().
pg_num_rows() will return the number of rows in a PostgreSQL result resource. result is a query result resource returned by pg_query(). This function will return -1 on error.
Óçìåßùóç: Use pg_affected_rows() to get number of rows affected by INSERT, UPDATE and DELETE query.
Óçìåßùóç: This function used to be called pg_numrows().
See also pg_num_fields() and pg_affected_rows().
pg_options() will return a string containing the options specified on the given PostgreSQL connection resource.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
pg_pconnect() opens a connection to a PostgreSQL database. It returns a connection resource that is needed by other PostgreSQL functions.
For a description of the connection_string parameter, see pg_connect().
To enable persistent connection, the pgsql.allow_persistent php.ini directive must be set to "On" (which is the default). The maximum number of persistent connection can be defined with the pgsql.max_persistent php.ini directive (defaults to -1 for no limit). The total number of connections can be set with the pgsql.max_links php.ini directive.
pg_close() will not close persistent links generated by pg_pconnect().
See also pg_connect(), and the section Persistent Database Connections for more information.
pg_ping() ping database connection, try to reconnect if it is broken. It returns TRUE if connection is alive, otherwise FALSE.
See also pg_connection_status() and pg_connection_reset().
pg_port() returns the port number that the given PostgreSQL connection resource is connected to.
pg_put_line() sends a NULL-terminated string to the PostgreSQL backend server. This is useful for example for very high-speed inserting of data into a table, initiated by starting a PostgreSQL copy-operation. That final NULL-character is added automatically. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The application must explicitly send the two characters "\." on the last line to indicate to the backend that it has finished sending its data.
ÐáñÜäåéãìá 1. High-speed insertion of data into a table
|
See also pg_end_copy().
pg_query() returns a query result resource if query could be executed. It returns FALSE on failure or if connection is not a valid connection. Details about the error can be retrieved using the pg_last_error() function if connection is valid. pg_query() sends an SQL statement to the PostgreSQL database specified by the connection resource. The connection must be a valid connection that was returned by pg_connect() or pg_pconnect(). The return value of this function is an query result resource to be used to access the results from other PostgreSQL functions such as pg_fetch_array().
Óçìåßùóç: connection is an optional parameter for pg_query(). If connection is not set, default connection is used. Default connection is the last connection made by pg_connect() or pg_pconnect().
Although connection can be omitted, it is not recommended, since it could be a cause of hard to find bug in script.
Óçìåßùóç: This function used to be called pg_exec(). pg_exec() is still available for compatibility reasons but users are encouraged to use the newer name.
See also pg_connect(), pg_pconnect(), pg_fetch_array(), pg_fetch_object(), pg_num_rows() and pg_affected_rows().
pg_result_error() returns error message associated with result resource. Therefore, user has better chance to get better error message than pg_last_error().
See also pg_query(), pg_send_query(), pg_get_result(), pg_last_error() and pg_last_notice()
pg_result_seek() set internal row offset in result resource. It returns FALSE, if there is error.
See also pg_fetch_row(), pg_fetch_assoc(), pg_fetch_array(), pg_fetch_object() and pg_fetch_result().
pg_result_status() returns status of result resource. Possible return values are PGSQL_EMPTY_QUERY, PGSQL_COMMAND_OK, PGSQL_TUPLES_OK, PGSQL_COPY_TO, PGSQL_COPY_FROM, PGSQL_BAD_RESPONSE, PGSQL_NONFATAL_ERROR and PGSQL_FATAL_ERROR.
See also pg_connection_status().
pg_select() selects records specified by assoc_array which has field=>value. For successful query, it returns array contains all records and fields that match the condition specified by assoc_array. If options is specified, pg_convert() is applied to assoc_array with specified option.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also pg_convert()
pg_send_query() send asynchronous query to the connection. Unlike pg_query(), it can send multiple query to PostgreSQL and get the result one by one using pg_get_result(). Script execution is not blocked while query is executing. Use pg_connection_busy() to check connection is busy (i.e. query is executing). Query may be cancelled by calling pg_cancel_query().
Although user can send multiple query at once, user cannot send multiple query over busy connection. If query is sent while connection is busy, it waits until last query is finished and discards all result.
ÐáñÜäåéãìá 1. Asynchronous Queries
The above example would produce the following output:
|
See also pg_query(), pg_cancel_query(), pg_get_result() and pg_connection_busy().
pg_set_client_encoding() sets the client encoding and returns 0 if success or -1 if error.
encoding is the client encoding and can be either : SQL_ASCII, EUC_JP, EUC_CN, EUC_KR, EUC_TW, UNICODE, MULE_INTERNAL, LATINX (X=1...9), KOI8, WIN, ALT, SJIS, BIG5, WIN1250. Available encoding depends on your PostgreSQL and libpq version. Refer to PostgreSQL manual for supported encodings for your PostgreSQL.
Óçìåßùóç: This function requires PHP-4.0.3 or higher and PostgreSQL-7.0 or higher. Supported encoding depends on PostgreSQL version. Refer to PostgreSQL manual for details.
The function used to be called pg_setclientencoding().
See also pg_client_encoding().
pg_trace() enables tracing of the PostgreSQL frontend/backend communication to a debugging file specified as pathname. To fully understand the results, one needs to be familiar with the internals of PostgreSQL communication protocol. For those who are not, it can still be useful for tracing errors in queries sent to the server, you could do for example grep '^To backend' trace.log and see what query actually were sent to the PostgreSQL server. For more information, refer to PostgreSQL manual.
pathname and mode are the same as in fopen() (mode defaults to 'w'), connection specifies the connection to trace and defaults to the last one opened.
pg_trace() returns TRUE if pathname could be opened for logging, FALSE otherwise.
See also fopen() and pg_untrace().
pg_tty() returns the tty name that server side debugging output is sent to on the given PostgreSQL connection resource.
pg_unescape_bytea() unescapes string from bytea datatype. It returns unescaped string (binary).
Óçìåßùóç: When you SELECT bytea type, PostgreSQL returns octal byte value prefixed by \ (e.g. \032). Users are supposed to convert back to binary format by yourself.
This function requires PostgreSQL 7.2 or later. With PostgreSQL 7.2.0 and 7.2.1, bytea type must be casted when you enable multi-byte support. i.e. INSERT INTO test_table (image) VALUES ('$image_escaped'::bytea); PostgreSQL 7.2.2 or later does not need cast. Exception is when client and backend character encoding does not match, there may be multi-byte stream error. User must cast to bytea to avoid this error.
See also pg_escape_bytea() and pg_escape_string()
Stop tracing started by pg_trace(). connection specifies the connection that was traced and defaults to the last one opened.
Returns always TRUE.
See also pg_trace().
pg_update() updates records that matches condition with data. If options is specified, pg_convert() is applied to data with specified options.
ÐáñÜäåéãìá 1. pg_update() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
See also pg_convert().
Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a webserver environment and unexpected results may happen if any Process Control functions are used within a webserver environment.
This documentation is intended to explain the general usage of each of the Process Control functions. For detailed information about Unix process control you are encouraged to consult your systems documentation including fork(2), waitpid(2) and signal(2) or a comprehensive reference such as Advanced Programming in the UNIX Environment by W. Richard Stevens (Addison-Wesley).
PCNTL now uses ticks as the signal handle callback mechanism, which is much faster than the previous mechanism. This change follows the same semantics as using "user ticks". You use the declare() statement to specify the locations in your program where callbacks are allowed to occur. This allows you to minimize the overhead of handling asynchronous events. In the past, compiling PHP with pcntl enabled would always incur this overhead, whether or not your script actually used pcntl.
There is one adjustment that all pcntl scripts prior to PHP 4.3.0 must make for them to work which is to either to use declare() on a section where you wish to allow callbacks or to just enable it across the entire script using the new global syntax of declare().
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
Process Control support in PHP is not enabled by default. You have to compile the CGI or CLI version of PHP with --enable-pcntl configuration option when compiling PHP to enable Process Control support.
Óçìåßùóç: Currently, this module will not function on non-Unix platforms (Windows).
The following list of signals are supported by the Process Control functions. Please see your systems signal(7) man page for details of the default behavior of these signals.
This example forks off a daemon process with a signal handler.
ÐáñÜäåéãìá 1. Process Control Example
|
The pcntl_alarm() function creates a timer that will send a SIGALRM signal to the process after seconds seconds. If seconds is zero, no new alarm is created. Any call to pcntl_alarm() will cancel any previously set alarm.
pcntl_alarm() will return the time in seconds that any previously scheduled alarm had remaining before it was to be delivered, or 0 if there was no previously scheduled alarm.
pcntl_exec() executes the program path with arguments args. path must be the path to a binary executable or a script with a valid path pointing to an executable in the shebang ( #!/usr/local/bin/perl for example) as the first line. See your system's man execve(2) page for additional information.
args is an array of argument strings passed to the program.
envs is an array of strings which are passed as environment to the program. The array is in the format of name => value, the key being the name of the environmental variable and the value being the value of that variable.
pcntl_exec() returns FALSE on error and does not return on success.
The pcntl_fork() function creates a child process that differs from the parent process only in its PID and PPID. Please see your system's fork(2) man page for specific details as to how fork works on your system.
On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and a PHP error is raised.
See also pcntl_waitpid() and pcntl_signal().
pcntl_getpriority() gets the priority of pid. If pid is not specified, the pid of the current process is used. Because priority levels can differ between system types and kernel versions, please see your system's getpriority(2) man page for specific details.
pcntl_getpriority() returns the priority of the process or FALSE on error. A lower numerical value causes more favorable scheduling.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
pcntl_setpriority() sets the priority of pid to priority. If pid is not specified, the pid of the current process is used.
priority is generally a value in the range -20 to 20. The default priority is 0 while a lower numerical value causes more favorable scheduling. Because priority levels can differ between system types and kernel versions, please see your system's setpriority(2) man page for specific details.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The pcntl_signal() function installs a new signal handler for the signal indicated by signo. The signal handler is set to handler which may be the name of a user created function, or either of the two global constants SIG_IGN or SIG_DFL. The optional restart_syscalls specifies whether system call restarting should be used when this signal arrives and defaults to TRUE.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The optional restart_syscalls parameter became available in PHP 4.3.0.
Óçìåßùóç: The ability to use an object method as a callback became available in PHP 4.3.0. Note that when you set a handler to an object method, that object's reference count is increased which makes it persist until you either change the handler to something else, or your script ends.
ÐáñÜäåéãìá 1. pcntl_signal() example
|
Óçìåßùóç: As of PHP 4.3.0 PCNTL uses ticks as the signal handle callback mechanism, which is much faster than the previous mechanism. This change follows the same semantics as using "user ticks". You must use the declare() statement to specify the locations in your program where callbacks are allowed to occur for the signal handler to function properly (as used in the above example).
See also pcntl_fork() and pcntl_waitpid().
The wait function suspends execution of the current process until a child has exited, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function. If a child has already exited by the time of the call (a so-called "zombie" process), the function returns immediately. Any system resources used by the child are freed. Please see your system's wait(2) man page for specific details as to how wait works on your system.
pcntl_wait() returns the process ID of the child which exited, -1 on error or zero if WNOHANG was provided as an option (on wait3-available systems) and no child was available.
If wait3 is available on your system (mostly BSD-style systems), you can provide the optional options parameter. If this parameter is not provided, wait will be used for the system call. If wait3 is not available, providing a value for options will have no effect. The value of options is the value of zero or more of the following two constants OR'ed together:
Ðßíáêáò 1. Possible values for options if wait3 is available
WNOHANG | Return immediately if no child has exited. |
WUNTRACED | Return for children which are stopped, and whose status has not been reported. |
pcntl_wait() will store status information in the status parameter which can be evaluated using the following functions: pcntl_wifexited(), pcntl_wifstopped(), pcntl_wifsignaled(), pcntl_wexitstatus(), pcntl_wtermsig() and pcntl_wstopsig().
Óçìåßùóç: This function is equivalent to calling pcntl_waitpid() with a -1 pid and no options.
See also pcntl_fork(), pcntl_signal(), pcntl_wifexited(), pcntl_wifstopped(), pcntl_wifsignaled(), pcntl_wexitstatus(), pcntl_wtermsig(), pcntl_wstopsig() and pcntl_waitpid().
The pcntl_waitpid() function suspends execution of the current process until a child as specified by the pid argument has exited, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function. If a child as requested by pid has already exited by the time of the call (a so-called "zombie" process), the function returns immediately. Any system resources used by the child are freed. Please see your system's waitpid(2) man page for specific details as to how waitpid works on your system.
pcntl_waitpid() returns the process ID of the child which exited, -1 on error or zero if WNOHANG was used and no child was available
The value of pid can be one of the following:
Ðßíáêáò 1. possible values for pid
< -1 | wait for any child process whose process group ID is equal to the absolute value of pid. |
-1 | wait for any child process; this is the same behaviour that the wait function exhibits. |
0 | wait for any child process whose process group ID is equal to that of the calling process. |
> 0 | wait for the child whose process ID is equal to the value of pid. |
Óçìåßùóç: Specifying -1 as the pid is equivalent to the functionality pcntl_wait() provides (minus options).
pcntl_waitpid() will store status information in the status parameter which can be evaluated using the following functions: pcntl_wifexited(), pcntl_wifstopped(), pcntl_wifsignaled(), pcntl_wexitstatus(), pcntl_wtermsig() and pcntl_wstopsig().
The value of options is the value of zero or more of the following two global constants OR'ed together:
Ðßíáêáò 2. possible values for options
WNOHANG | return immediately if no child has exited. |
WUNTRACED | return for children which are stopped, and whose status has not been reported. |
See also pcntl_fork(), pcntl_signal(), pcntl_wifexited(), pcntl_wifstopped(), pcntl_wifsignaled(), pcntl_wexitstatus(), pcntl_wtermsig() and pcntl_wstopsig().
Returns the return code of a terminated child. This function is only useful if pcntl_wifexited() returned TRUE.
The parameter status is the status parameter supplied to a successfull call to pcntl_waitpid().
See also pcntl_waitpid() and pcntl_wifexited().
Returns TRUE if the child status code represents a successful exit.
The parameter status is the status parameter supplied to a successfull call to pcntl_waitpid().
See also pcntl_waitpid() and pcntl_wexitstatus().
(PHP 4 >= 4.1.0, PHP 5)
pcntl_wifsignaled -- Returns TRUE if status code represents a termination due to a signalReturns TRUE if the child process exited because of a signal which was not caught.
The parameter status is the status parameter supplied to a successfull call to pcntl_waitpid().
See also pcntl_waitpid() and pcntl_signal().
Returns TRUE if the child process which caused the return is currently stopped; this is only possible if the call to pcntl_waitpid() was done using the option WUNTRACED.
The parameter status is the status parameter supplied to a successfull call to pcntl_waitpid().
See also pcntl_waitpid().
Returns the number of the signal which caused the child to stop. This function is only useful if pcntl_wifstopped() returned TRUE.
The parameter status is the status parameter supplied to a successfull call to pcntl_waitpid().
See also pcntl_waitpid() and pcntl_wifstopped().
Returns the number of the signal that caused the child process to terminate. This function is only useful if pcntl_wifsignaled() returned TRUE.
The parameter status is the status parameter supplied to a successfull call to pcntl_waitpid().
See also pcntl_waitpid(), pcntl_signal() and pcntl_wifsignaled().
Those functions provides means to executes commands on the system itself, and means secure such commands.
These functions are also closely related to the backtick operator. Also, while in safe mode you must consider the safe_mode_exec_dir directive.
escapeshellarg() adds single quotes around a string and quotes/escapes any existing single quotes allowing you to pass a string directly to a shell function and having it be treated as a single safe argument. This function should be used to escape individual arguments to shell functions coming from user input. The shell functions include exec(), system() and the backtick operator. A standard use would be:
See also escapeshellcmd(), exec(), popen(), system(), and the backtick operator.
escapeshellcmd() escapes any characters in a string that might be used to trick a shell command into executing arbitrary commands. This function should be used to make sure that any data coming from user input is escaped before this data is passed to the exec() or system() functions, or to the backtick operator. A standard use would be:
<?php $e = escapeshellcmd($userinput); // here we don't care if $e has spaces system("echo $e"); $f = escapeshellcmd($filename); // and here we do, so we use quotes system("touch \"/tmp/$f\"; ls -l \"/tmp/$f\""); ?> |
See also escapeshellarg(), exec(), popen(), system(), and the backtick operator.
exec() executes the given command, however it does not output anything. It simply returns the last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
If the output argument is present, then the specified array will be filled with every line of output from the command. Line endings, such as \n, are not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().
If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.
Ðñïåéäïðïßçóç |
If you are going to allow data coming from user input to be passed to this function, then you should be using escapeshellarg() or escapeshellcmd() to make sure that users cannot trick the system into executing arbitrary commands. |
Óçìåßùóç: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.
Óçìåßùóç: When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir. For practical reasons it is currently not allowed to have .. components in the path to the executable.
Ðñïåéäïðïßçóç |
With safe mode enabled, all words following the initial command string are treated as a single argument. Thus, echo y | echo x becomes echo "y | echo x". |
See also system(), passthru(), popen(), escapeshellcmd() pcntl_exec(), and the backtick operator.
The passthru() function is similar to the exec() function in that it executes a command. If the return_var argument is present, the return status of the Unix command will be placed here. This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser. A common use for this is to execute something like the pbmplus utilities that can output an image stream directly. By setting the Content-type to image/gif and then calling a pbmplus program to output a gif, you can create PHP scripts that output images directly.
Ðñïåéäïðïßçóç |
If you are going to allow data coming from user input to be passed to this function, then you should be using escapeshellarg() or escapeshellcmd() to make sure that users cannot trick the system into executing arbitrary commands. |
Óçìåßùóç: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.
Óçìåßùóç: When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir. For practical reasons it is currently not allowed to have .. components in the path to the executable.
Ðñïåéäïðïßçóç |
With safe mode enabled, all words following the initial command string are treated as a single argument. Thus, echo y | echo x becomes echo "y | echo x". |
See also exec(), system(), popen(), escapeshellcmd(), and the backtick operator.
(PHP 4 >= 4.3.0, PHP 5)
proc_close -- Close a process opened by proc_open() and return the exit code of that process.proc_close() is similar to pclose() except that it only works on processes opened by proc_open(). proc_close() waits for the process to terminate, and returns its exit code. If you have open pipes to that process, you should fclose() them prior to calling this function in order to avoid a deadlock - the child process may not be able to exit while the pipes are open.
proc_get_status() fetches data about a process opened using proc_open(). The collected information is returned in an array containing the following elements:
element | type | description |
---|---|---|
command | string | The command string that was passed to proc_open() |
pid | int | process id |
running | bool | TRUE if the process is still running, FALSE if it has terminated |
signaled | bool | TRUE if the child process has been terminated by an uncaught signal. Always set to FALSE on Windows. |
stopped | bool | TRUE if the child process has been stopped by a signal. Always set to FALSE on Windows. |
exitcode | int | the exit code returned by the process (which is only meaningful if running is FALSE) |
termsig | int | the number of the signal that caused the child process to terminate its execution (only meaningful if signaled is TRUE) |
stopsig | int | the number of the signal that caused the child process to stop its execution (only meaningful if stopped is TRUE) |
See also proc_open().
proc_nice() changes the priority of the current process. If an error occurs, like the user lacks permission to change the priority, an error of level E_WARNING is generated and FALSE is returned. Otherwise, TRUE is returned.
Óçìåßùóç: proc_nice() will only exist if your system has 'nice' capabilities. 'nice' conforms to: SVr4, SVID EXT, AT&T, X/OPEN, BSD 4.3. This means that proc_nice() is not available on Windows.
proc_nice() is not related to proc_open() and its associated functions in any way.
proc_open() is similar to popen() but provides a much greater degree of control over the program execution. cmd is the command to be executed by the shell. descriptorspec is an indexed array where the key represents the descriptor number and the value represents how PHP will pass that descriptor to the child process. pipes will be set to an indexed array of file pointers that correspond to PHP's end of any pipes that are created. The return value is a resource representing the process; you should free it using proc_close() when you are finished with it.
<?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to ); $process = proc_open("php", $descriptorspec, $pipes); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0], "<?php echo \"Hello World!\"; ?>"); fclose($pipes[0]); while (!feof($pipes[1])) { echo fgets($pipes[1], 1024); } fclose($pipes[1]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); echo "command returned $return_value\n"; } ?> |
PHP 5RC2 introduces pty support for systems with Unix98 ptys. This allows your script to interact with applications that expect to be talking to a terminal. A pty works like a pipe, but is bi-directional, so there is no need to specify a read/write mode. The example below shows how to use a pty; note that you don't have to have all descriptors talking to a pty. Also note that only one pty is created, even though pty is specified 3 times. In a future version of PHP, it might be possible to do more than just read and write to the pty.
<?php // Create a pseudo terminal for the child process $descriptorspec = array( 0 => array("pty"), 1 => array("pty"), 2 => array("pty") ); $process = proc_open("cvs -d:pserver:cvsread@cvs.php.net:/repository login", $descriptorspec, $pipes); if (is_resource($process)) { // work with it here } ?> |
The file descriptor numbers in descriptorspec are not limited to 0, 1 and 2 - you may specify any valid file descriptor number and it will be passed to the child process. This allows your script to interoperate with other scripts that run as "co-processes". In particular, this is useful for passing passphrases to programs like PGP, GPG and openssl in a more secure manner. It is also useful for reading status information provided by those programs on auxiliary file descriptors.
Óçìåßùóç: Windows compatibility: Descriptors beyond 2 (stderr) are made available to the child process as inheritable handles, but since the Windows architecture does not associate file descriptor numbers with low-level handles, the child process does not (yet) have a means of accessing those handles. Stdin, stdout and stderr work as expected.
Óçìåßùóç: If you only need a uni-directional (one-way) process pipe, use popen() instead, as it is much easier to use.
See also stream_select(), exec(), system(), passthru(), popen(), escapeshellcmd(), and the backtick operator.
Signals a process (created using proc_open()) that it should terminate. proc_terminate() returns immediately and does not wait for the process to terminate.
The optional signal is only useful on POSIX operating systems; you may specify a signal to send to the process using the kill(2) system call. The default is SIGTERM.
proc_terminate() allows you terminate the process and continue with other tasks. You may poll the process (to see if it has stopped yet) by using the proc_get_status() function.
See also proc_open(), proc_close(), and proc_get_status().
This function is identical to the backtick operator.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé áðåíåñãïðïéçìÝíç óôï safe mode.
system() is just like the C version of the function in that it executes the given command and outputs the result. If a variable is provided as the second argument, then the return status code of the executed command will be written to this variable.
Ðñïåéäïðïßçóç |
If you are going to allow data coming from user input to be passed to this function, then you should be using escapeshellarg() or escapeshellcmd() to make sure that users cannot trick the system into executing arbitrary commands. |
Óçìåßùóç: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.
The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.
Returns the last line of the command output on success, and FALSE on failure.
If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
ÐáñÜäåéãìá 1. system() example
|
Óçìåßùóç: When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir. For practical reasons it is currently not allowed to have .. components in the path to the executable.
Ðñïåéäïðïßçóç |
With safe mode enabled, all words following the initial command string are treated as a single argument. Thus, echo y | echo x becomes echo "y | echo x". |
See also exec(), passthru(), popen(), escapeshellcmd(), pcntl_exec(), and the backtick operator.
These functions are only available under Windows 9.x, ME, NT4 and 2000. They have been added in PHP 4.0.4.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
For further details and definition of the PHP_INI_* constants see ini_set().
This function deletes the printers spool file.
handle must be a valid handle to a printer.
This function closes the printer connection. printer_close() also closes the active device context.
handle must be a valid handle to a printer.
The function creates a new brush and returns a handle to it. A brush is used to fill shapes. For an example see printer_select_brush(). color must be a color in RGB hex format, i.e. "000000" for black, style must be one of the following constants:
PRINTER_BRUSH_SOLID: creates a brush with a solid color.
PRINTER_BRUSH_DIAGONAL: creates a brush with a 45-degree upward left-to-right hatch ( / ).
PRINTER_BRUSH_CROSS: creates a brush with a cross hatch ( + ).
PRINTER_BRUSH_DIAGCROSS: creates a brush with a 45 cross hatch ( x ).
PRINTER_BRUSH_FDIAGONAL: creates a brush with a 45-degree downward left-to-right hatch ( \ ).
PRINTER_BRUSH_HORIZONTAL: creates a brush with a horizontal hatch ( - ).
PRINTER_BRUSH_VERTICAL: creates a brush with a vertical hatch ( | ).
PRINTER_BRUSH_CUSTOM: creates a custom brush from an BMP file. The second parameter is used to specify the BMP instead of the RGB color code.
The function creates a new device context. A device context is used to customize the graphic objects of the document. handle must be a valid handle to a printer.
ÐáñÜäåéãìá 1. printer_create_dc() example
|
The function creates a new font and returns a handle to it. A font is used to draw text. For an example see printer_select_font(). face must be a string specifying the font face. height specifies the font height, and width the font width. The font_weight specifies the font weight (400 is normal), and can be one of the following predefined constants.
PRINTER_FW_THIN: sets the font weight to thin (100).
PRINTER_FW_ULTRALIGHT: sets the font weight to ultra light (200).
PRINTER_FW_LIGHT: sets the font weight to light (300).
PRINTER_FW_NORMAL: sets the font weight to normal (400).
PRINTER_FW_MEDIUM: sets the font weight to medium (500).
PRINTER_FW_BOLD: sets the font weight to bold (700).
PRINTER_FW_ULTRABOLD: sets the font weight to ultra bold (800).
PRINTER_FW_HEAVY: sets the font weight to heavy (900).
italic can be TRUE or FALSE, and sets whether the font should be italic.
underline can be TRUE or FALSE, and sets whether the font should be underlined.
strikeout can be TRUE or FALSE, and sets whether the font should be stroked out.
orientation specifies a rotation. For an example see printer_select_font().
The function creates a new pen and returns a handle to it. A pen is used to draw lines and curves. For an example see printer_select_pen(). color must be a color in RGB hex format, i.e. "000000" for black, width specifies the width of the pen whereas style must be one of the following constants:
PRINTER_PEN_SOLID: creates a solid pen.
PRINTER_PEN_DASH: creates a dashed pen.
PRINTER_PEN_DOT: creates a dotted pen.
PRINTER_PEN_DASHDOT: creates a pen with dashes and dots.
PRINTER_PEN_DASHDOTDOT: creates a pen with dashes and double dots.
PRINTER_PEN_INVISIBLE: creates an invisible pen.
The function deletes the selected brush. For an example see printer_select_brush(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. handle must be a valid handle to a brush.
The function deletes the device context. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. For an example see printer_create_dc(). handle must be a valid handle to a printer.
The function deletes the selected font. For an example see printer_select_font(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. handle must be a valid handle to a font.
The function deletes the selected pen. For an example see printer_select_pen(). ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. handle must be a valid handle to a pen.
The function simply draws an bmp the bitmap filename at position x, y. handle must be a valid handle to a printer.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The function simply draws an chord. handle must be a valid handle to a printer.
rec_x is the upper left x coordinate of the bounding rectangle.
rec_y is the upper left y coordinate of the bounding rectangle.
rec_x1 is the lower right x coordinate of the bounding rectangle.
rec_y1 is the lower right y coordinate of the bounding rectangle.
rad_x is x coordinate of the radial defining the beginning of the chord.
rad_y is y coordinate of the radial defining the beginning of the chord.
rad_x1 is x coordinate of the radial defining the end of the chord.
rad_y1 is y coordinate of the radial defining the end of the chord.
ÐáñÜäåéãìá 1. printer_draw_chord() example
|
The function simply draws an ellipse. handle must be a valid handle to a printer.
ul_x is the upper left x coordinate of the ellipse.
ul_y is the upper left y coordinate of the ellipse.
lr_x is the lower right x coordinate of the ellipse.
lr_y is the lower right y coordinate of the ellipse.
ÐáñÜäåéãìá 1. printer_draw_elipse() example
|
The function simply draws a line from position from_x, from_y to position to_x, to_y using the selected pen. printer_handle must be a valid handle to a printer.
ÐáñÜäåéãìá 1. printer_draw_line() example
|
The function simply draws an pie. handle must be a valid handle to a printer.
rec_x is the upper left x coordinate of the bounding rectangle.
rec_y is the upper left y coordinate of the bounding rectangle.
rec_x1 is the lower right x coordinate of the bounding rectangle.
rec_y1 is the lower right y coordinate of the bounding rectangle.
rad1_x is x coordinate of the first radial's ending.
rad1_y is y coordinate of the first radial's ending.
rad2_x is x coordinate of the second radial's ending.
rad2_y is y coordinate of the second radial's ending.
ÐáñÜäåéãìá 1. printer_draw_pie() example
|
The function simply draws a rectangle.
handle must be a valid handle to a printer.
ul_x is the upper left x coordinate of the rectangle.
ul_y is the upper left y coordinate of the rectangle.
lr_x is the lower right x coordinate of the rectangle.
lr_y is the lower right y coordinate of the rectangle.
ÐáñÜäåéãìá 1. printer_draw_rectangle() example
|
(no version information, might be only in CVS)
printer_draw_roundrect -- Draw a rectangle with rounded cornersThe function simply draws a rectangle with rounded corners.
handle must be a valid handle to a printer.
ul_x is the upper left x coordinate of the rectangle.
ul_y is the upper left y coordinate of the rectangle.
lr_x is the lower right x coordinate of the rectangle.
lr_y is the lower right y coordinate of the rectangle.
width is the width of the ellipse.
height is the height of the ellipse.
ÐáñÜäåéãìá 1. printer_draw_roundrect() example
|
The function simply draws text at position x, y using the selected font. printer_handle must be a valid handle to a printer.
ÐáñÜäåéãìá 1. printer_draw_text() example
|
Closes a new document in the printer spooler. The document is now ready for printing. For an example see printer_start_doc(). handle must be a valid handle to a printer.
The function closes the active page in the active document. For an example see printer_start_doc(). handle must be a valid handle to a printer.
(no version information, might be only in CVS)
printer_get_option -- Retrieve printer configuration dataThe function retrieves the configuration setting of option. handle must be a valid handle to a printer. Take a look at printer_set_option() for the settings that can be retrieved, additionally the following settings can be retrieved:
PRINTER_DEVICENAME returns the devicename of the printer.
PRINTER_DRIVERVERSION returns the printer driver version.
(no version information, might be only in CVS)
printer_list -- Return an array of printers attached to the serverThe function enumerates available printers and their capabilities. level sets the level of information request. Can be 1,2,4 or 5. enumtype must be one of the following predefined constants:
PRINTER_ENUM_LOCAL: enumerates the locally installed printers.
PRINTER_ENUM_NAME: enumerates the printer of name, can be a server, domain or print provider.
PRINTER_ENUM_SHARED: this parameter can't be used alone, it has to be OR'ed with other parameters, i.e. PRINTER_ENUM_LOCAL to detect the locally shared printers.
PRINTER_ENUM_DEFAULT: (Win9.x only) enumerates the default printer.
PRINTER_ENUM_CONNECTIONS: (WinNT/2000 only) enumerates the printers to which the user has made connections.
PRINTER_ENUM_NETWORK: (WinNT/2000 only) enumerates network printers in the computer's domain. Only valid if level is 1.
PRINTER_ENUM_REMOTE: (WinNT/2000 only) enumerates network printers and print servers in the computer's domain. Only valid if level is 1.
The function calculates the logical font height of height. handle must be a valid handle to a printer.
This function tries to open a connection to the printer devicename, and returns a handle on success or FALSE on failure.
If no parameter was given it tries to open a connection to the default printer (if not specified in php.ini as printer.default_printer, PHP tries to detect it).
printer_open() also starts a device context.
The function selects a brush as the active drawing object of the actual device context. A brush is used to fill shapes. If you draw an rectangle the brush is used to draw the shapes, while the pen is used to draw the border. If you haven't selected a brush before drawing shapes, the shape won't be filled. printer_handle must be a valid handle to a printer. brush_handle must be a valid handle to a brush.
ÐáñÜäåéãìá 1. printer_select_brush() example
|
The function selects a font to draw text. printer_handle must be a valid handle to a printer. font_handle must be a valid handle to a font.
ÐáñÜäåéãìá 1. printer_select_font() example
|
The function selects a pen as the active drawing object of the actual device context. A pen is used to draw lines and curves. I.e. if you draw a single line the pen is used. If you draw an rectangle the pen is used to draw the borders, while the brush is used to fill the shape. If you haven't selected a pen before drawing shapes, the shape won't be outlined. printer_handle must be a valid handle to a printer. pen_handle must be a valid handle to a pen.
ÐáñÜäåéãìá 1. printer_select_pen() example
|
(no version information, might be only in CVS)
printer_set_option -- Configure the printer connectionThe function sets the following options for the current connection. handle must be a valid handle to a printer. For option can be one of the following constants:
PRINTER_COPIES: sets how many copies should be printed, value must be an integer.
PRINTER_MODE: specifies the type of data (text, raw or emf), value must be a string.
PRINTER_TITLE: specifies the name of the document, value must be a string.
PRINTER_ORIENTATION: specifies the orientation of the paper, value can be either PRINTER_ORIENTATION_PORTRAIT or PRINTER_ORIENTATION_LANDSCAPE
PRINTER_RESOLUTION_Y: specifies the y-resolution in DPI, value must be an integer.
PRINTER_RESOLUTION_X: specifies the x-resolution in DPI, value must be an integer.
PRINTER_PAPER_FORMAT: specifies the a predefined paper format, set value to PRINTER_FORMAT_CUSTOM if you want to specify a custom format with PRINTER_PAPER_WIDTH and PRINTER_PAPER_LENGTH. value can be one of the following constants.
PRINTER_FORMAT_CUSTOM: let's you specify a custom paper format.
PRINTER_FORMAT_LETTER: specifies standard letter format (8 1/2- by 11-inches).
PRINTER_FORMAT_LETTER: specifies standard legal format (8 1/2- by 14-inches).
PRINTER_FORMAT_A3: specifies standard A3 format (297- by 420-millimeters).
PRINTER_FORMAT_A4: specifies standard A4 format (210- by 297-millimeters).
PRINTER_FORMAT_A5: specifies standard A5 format (148- by 210-millimeters).
PRINTER_FORMAT_B4: specifies standard B4 format (250- by 354-millimeters).
PRINTER_FORMAT_B5: specifies standard B5 format (182- by 257-millimeter).
PRINTER_FORMAT_FOLIO: specifies standard FOLIO format (8 1/2- by 13-inch).
PRINTER_PAPER_LENGTH: if PRINTER_PAPER_FORMAT is set to PRINTER_FORMAT_CUSTOM, PRINTER_PAPER_LENGTH specifies a custom paper length in mm, value must be an integer.
PRINTER_PAPER_WIDTH: if PRINTER_PAPER_FORMAT is set to PRINTER_FORMAT_CUSTOM, PRINTER_PAPER_WIDTH specifies a custom paper width in mm, value must be an integer.
PRINTER_SCALE: specifies the factor by which the printed output is to be scaled. the page size is scaled from the physical page size by a factor of scale/100. for example if you set the scale to 50, the output would be half of its original size. value must be an integer.
PRINTER_BACKGROUND_COLOR: specifies the background color for the actual device context, value must be a string containing the rgb information in hex format i.e. "005533".
PRINTER_TEXT_COLOR: specifies the text color for the actual device context, value must be a string containing the rgb information in hex format i.e. "005533".
PRINTER_TEXT_ALIGN: specifies the text alignment for the actual device context, value can be combined through OR'ing the following constants:
PRINTER_TA_BASELINE: text will be aligned at the base line.
PRINTER_TA_BOTTOM: text will be aligned at the bottom.
PRINTER_TA_TOP: text will be aligned at the top.
PRINTER_TA_CENTER: text will be aligned at the center.
PRINTER_TA_LEFT: text will be aligned at the left.
PRINTER_TA_RIGHT: text will be aligned at the right.
The function creates a new document in the printer spooler. A document can contain multiple pages, it's used to schedule the print job in the spooler. handle must be a valid handle to a printer. The optional parameter document can be used to set an alternative document name.
The function creates a new page in the active document. For an example see printer_start_doc(). handle must be a valid handle to a printer.
To compile PHP with pspell support, you need the aspell library, available from http://aspell.sourceforge.net/.
If you have the libraries needed add the --with-pspell[=dir] option when compiling PHP.
Note to Win32 Users: win32 support is available only in PHP 4.3.3 and later versions. Also, you must have aspell 0.50 or newer installed. In order to enable this module under Windows, you must copy aspell-15.dll from the bin folder of your aspell installation to a folder where PHP will be able to find it. C:\PHP or the SYSTEM32 folder of your windows machine (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32) are good choices.
pspell_add_to_personal() adds a word to the personal wordlist. If you used pspell_new_config() with pspell_config_personal() to open the dictionary, you can save the wordlist later with pspell_save_wordlist(). Please, note that this function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_add_to_session() adds a word to the wordlist associated with the current session. It is very similar to pspell_add_to_personal()
pspell_check() checks the spelling of a word and returns TRUE if the spelling is correct, FALSE if not.
pspell_clear_session() clears the current session. The current wordlist becomes blank, and, for example, if you try to save it with pspell_save_wordlist(), nothing happens.
ÐáñÜäåéãìá 1. pspell_add_to_personal()
|
pspell_config_create() has a very similar syntax to pspell_new(). In fact, using pspell_config_create() immediately followed by pspell_new_config() will produce the exact same result. However, after creating a new config, you can also use pspell_config_*() functions before calling pspell_new_config() to take advantage of some advanced functionality.
The language parameter is the language code which consists of the two letter ISO 639 language code and an optional two letter ISO 3166 country code after a dash or underscore.
The spelling parameter is the requested spelling for languages with more than one spelling such as English. Known values are 'american', 'british', and 'canadian'.
The jargon parameter contains extra information to distinguish two different words lists that have the same language and spelling parameters.
The encoding parameter is the encoding that words are expected to be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned 32'. This parameter is largely untested, so be careful when using.
The mode parameter is the mode in which spellchecker will work. There are several modes available:
PSPELL_FAST - Fast mode (least number of suggestions)
PSPELL_NORMAL - Normal mode (more suggestions)
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
For more information and examples, check out inline manual pspell website:http://aspell.net/.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
pspell_config_ignore() should be used on a config before calling pspell_new_config(). This function allows short words to be skipped by the spellchecker. Words less then n characters will be skipped.
pspell_config_mode() should be used on a config before calling pspell_new_config(). This function determines how many suggestions will be returned by pspell_suggest().
The mode parameter is the mode in which spellchecker will work. There are several modes available:
PSPELL_FAST - Fast mode (least number of suggestions)
PSPELL_NORMAL - Normal mode (more suggestions)
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
pspell_config_personal() should be used on a config before calling pspell_new_config(). The personal wordlist will be loaded and used in addition to the standard one after you call pspell_new_config(). If the file does not exist, it will be created. The file is also the file where pspell_save_wordlist() will save personal wordlist to. The file should be writable by whoever PHP runs as (e.g. nobody). Please, note that this function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_config_repl() should be used on a config before calling pspell_new_config(). The replacement pairs improve the quality of the spellchecker. When a word is misspelled, and a proper suggestion was not found in the list, pspell_store_replacement() can be used to store a replacement pair and then pspell_save_wordlist() to save the wordlist along with the replacement pairs. The file should be writable by whoever PHP runs as (e.g. nobody). Please, note that this function will not work unless you have pspell .11.2 and aspell .32.5 or later.
ÐáñÜäåéãìá 1. pspell_config_repl()
|
pspell_config_runtogether() should be used on a config before calling pspell_new_config(). This function determines whether run-together words will be treated as legal compounds. That is, "thecat" will be a legal compound, although there should be a space between the two words. Changing this setting only affects the results returned by pspell_check(); pspell_suggest() will still return suggestions.
(PHP 4 >= 4.0.2, PHP 5)
pspell_config_save_repl -- Determine whether to save a replacement pairs list along with the wordlistpspell_config_save_repl() should be used on a config before calling pspell_new_config(). It determines whether pspell_save_wordlist() will save the replacement pairs along with the wordlist. Usually there is no need to use this function because if pspell_config_repl() is used, the replacement pairs will be saved by pspell_save_wordlist() anyway, and if it is not, the replacement pairs will not be saved. Please, note that this function will not work unless you have pspell .11.2 and aspell .32.5 or later.
(PHP 4 >= 4.0.2, PHP 5)
pspell_new_config -- Load a new dictionary with settings based on a given configpspell_new_config() opens up a new dictionary with settings specified in a config, created with with pspell_config_create() and modified with pspell_config_*() functions. This method provides you with the most flexibility and has all the functionality provided by pspell_new() and pspell_new_personal().
The config parameter is the one returned by pspell_config_create() when the config was created.
pspell_new_personal() opens up a new dictionary with a personal wordlist and returns the dictionary link identifier for use in other pspell functions. The wordlist can be modified and saved with pspell_save_wordlist(), if desired. However, the replacement pairs are not saved. In order to save replacement pairs, you should create a config using pspell_config_create(), set the personal wordlist file with pspell_config_personal(), set the file for replacement pairs with pspell_config_repl(), and open a new dictionary with pspell_new_config().
The personal parameter specifies the file where words added to the personal list will be stored. It should be an absolute filename beginning with '/' because otherwise it will be relative to $HOME, which is "/root" for most systems, and is probably not what you want.
The language parameter is the language code which consists of the two letter ISO 639 language code and an optional two letter ISO 3166 country code after a dash or underscore.
The spelling parameter is the requested spelling for languages with more than one spelling such as English. Known values are 'american', 'british', and 'canadian'.
The jargon parameter contains extra information to distinguish two different words lists that have the same language and spelling parameters.
The encoding parameter is the encoding that words are expected to be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned 32'. This parameter is largely untested, so be careful when using.
The mode parameter is the mode in which spellchecker will work. There are several modes available:
PSPELL_FAST - Fast mode (least number of suggestions)
PSPELL_NORMAL - Normal mode (more suggestions)
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
PSPELL_RUN_TOGETHER - Consider run-together words as legal compounds. That is, "thecat" will be a legal compound, although there should be a space between the two words. Changing this setting only affects the results returned by pspell_check(); pspell_suggest() will still return suggestions.
For more information and examples, check out inline manual pspell website:http://aspell.net/.
pspell_new() opens up a new dictionary and returns the dictionary link identifier for use in other pspell functions.
The language parameter is the language code which consists of the two letter ISO 639 language code and an optional two letter ISO 3166 country code after a dash or underscore.
The spelling parameter is the requested spelling for languages with more than one spelling such as English. Known values are 'american', 'british', and 'canadian'.
The jargon parameter contains extra information to distinguish two different words lists that have the same language and spelling parameters.
The encoding parameter is the encoding that words are expected to be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned 32'. This parameter is largely untested, so be careful when using.
The mode parameter is the mode in which spellchecker will work. There are several modes available:
PSPELL_FAST - Fast mode (least number of suggestions)
PSPELL_NORMAL - Normal mode (more suggestions)
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
PSPELL_RUN_TOGETHER - Consider run-together words as legal compounds. That is, "thecat" will be a legal compound, although there should be a space between the two words. Changing this setting only affects the results returned by pspell_check(); pspell_suggest() will still return suggestions.
For more information and examples, check out inline manual pspell website:http://aspell.net/.
pspell_save_wordlist() saves the personal wordlist from the current session. The dictionary has to be open with pspell_new_personal(), and the location of files to be saved specified with pspell_config_personal() and (optionally) pspell_config_repl(). Please, note that this function will not work unless you have pspell .11.2 and aspell .32.5 or later.
ÐáñÜäåéãìá 1. pspell_add_to_personal()
|
pspell_store_replacement() stores a replacement pair for a word, so that replacement can be returned by pspell_suggest() later. In order to be able to take advantage of this function, you have to use pspell_new_personal() to open the dictionary. In order to permanently save the replacement pair, you have to use pspell_config_personal() and pspell_config_repl() to set the path where to save your custom wordlists, and then use pspell_save_wordlist() for the changes to be written to disk. Please, note that this function will not work unless you have pspell .11.2 and aspell .32.5 or later.
ÐáñÜäåéãìá 1. pspell_store_replacement()
|
The readline() functions implement an interface to the GNU Readline library. These are functions that provide editable command lines. An example being the way Bash allows you to use the arrow keys to insert characters or scroll through command history. Because of the interactive nature of this library, it will be of little use for writing Web applications, but may be useful when writing scripts meant using PHP from the command line.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
To use the readline functions, you need to install libreadline. You can find libreadline on the home page of the GNU Readline project, at http://cnswww.cns.cwru.edu/~chet/readline/rltop.html. It's maintained by Chet Ramey, who's also the author of Bash.
You can also use this functions with the libedit library, a non-GPL replacement for the readline library. The libedit library is BSD licensed and available for download from http://sourceforge.net/projects/libedit/.
This function adds a line to the command line history.
This function clears the entire command line history.
This function registers a completion function. You must supply the name of an existing function which accepts a partial command line and returns an array of possible matches. This is the same kind of functionality you'd get if you hit your tab key while using Bash.
If called with no parameters, this function returns an array of values for all the setting readline uses. The elements will be indexed by the following values: done, end, erase_empty_line, library_version, line_buffer, mark, pending_input, point, prompt, readline_name, and terminal_name.
If called with one parameter, the value of that setting is returned. If called with two parameters, the setting will be changed to the given value.
This function returns an array of the entire command line history. The elements are indexed by integers starting at zero.
This function reads a command history from a file.
This function writes the command history to a file.
This function returns a single string from the user. You may specify a string with which to prompt the user. The line returned has the ending newline removed. You must add this line to the history yourself using readline_add_history().
This module contains an interface to the GNU Recode library. The GNU Recode library converts files between various coded character sets and surface encodings. When this cannot be achieved exactly, it may get rid of the offending characters or fall back on approximations. The library recognises or produces nearly 150 different character sets and is able to convert files between almost any pair. Most RFC 1345 character sets are supported.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
You must have GNU Recode 3.5 or higher installed on your system. You can download the package from http://www.gnu.org/directory/All_GNU_Packages/recode.html.
To be able to use the functions defined in this module you must compile your PHP interpreter using the --with-recode[=DIR] option.
Ðñïåéäïðïßçóç |
Crashes and startup problems of PHP may be encountered when loading the recode as extension after loading any extension of mysql or imap. Loading the recode before those extension has proved to fix the problem. This is due a technical problem that both the c-client library used by imap and recode have their own hash_lookup() function and both mysql and recode have their own hash_insert function. |
Recode the file referenced by file handle input into the file referenced by file handle output according to the recode request. Returns FALSE, if unable to comply, TRUE otherwise.
This function does not currently process filehandles referencing remote files (URLs). Both filehandles must refer to local files.
Recode the string string according to the recode request request. Returns the recoded string or FALSE, if unable to perform the recode request.
A simple recode request may be "lat1..iso646-de". See also the GNU Recode documentation of your installation for detailed instructions about recode requests.
The syntax for patterns used in these functions closely resembles Perl. The expression should be enclosed in the delimiters, a forward slash (/), for example. Any character can be used for delimiter as long as it's not alphanumeric or backslash (\). If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash. Since PHP 4.0.4, you can also use Perl-style (), {}, [], and <> matching delimiters. See Pattern Syntax for detailed explanation.
The ending delimiter may be followed by various modifiers that affect the matching. See Pattern Modifiers.
PHP also supports regular expressions using a POSIX-extended syntax using the POSIX-extended regex functions.
Ðñïåéäïðïßçóç |
You should be aware of some limitations of PCRE. Read http://www.pcre.org/pcre.txt for more info. |
Regular expression support is provided by the PCRE library package, which is open source software, written by Philip Hazel, and copyright by the University of Cambridge, England. It is available at ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/.
Beginning with PHP 4.2.0 these functions are enabled by default. You can disable the pcre functions with --without-pcre-regex. Use --with-pcre-regex=DIR to specify DIR where PCRE's include and library files are located, if not using bundled library. For older versions you have to configure and compile PHP with --with-pcre-regex[=DIR] in order to use these functions.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðßíáêáò 1. PREG constants
constant | description |
---|---|
PREG_PATTERN_ORDER | Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on. This flag is only used with preg_match_all(). |
PREG_SET_ORDER | Orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches, and so on. This flag is only used with preg_match_all(). |
PREG_OFFSET_CAPTURE | See the description of PREG_SPLIT_OFFSET_CAPTURE. This flag is available since PHP 4.3.0. |
PREG_SPLIT_NO_EMPTY | This flag tells preg_split() to return only non-empty pieces. |
PREG_SPLIT_DELIM_CAPTURE | This flag tells preg_split() to capture parenthesized expression in the delimiter pattern as well. This flag is available since PHP 4.0.5. |
PREG_SPLIT_OFFSET_CAPTURE | If this flag is set, for every occurring match the appendant string offset will also be returned. Note that this changes the return values in an array where every element is an array consisting of the matched string at offset 0 and its string offset within subject at offset 1. This flag is available since PHP 4.3.0 and is only used for preg_split(). |
The current possible PCRE modifiers are listed below. The names in parentheses refer to internal PCRE names for these modifiers.
- i (PCRE_CASELESS)
If this modifier is set, letters in the pattern match both upper and lower case letters.
- m (PCRE_MULTILINE)
By default, PCRE treats the subject string as consisting of a single "line" of characters (even if it actually contains several newlines). The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless D modifier is set). This is the same as Perl.
When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively, as well as at the very start and end. This is equivalent to Perl's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, setting this modifier has no effect.
- s (PCRE_DOTALL)
If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.
- x (PCRE_EXTENDED)
If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl's /x modifier, and makes it possible to include comments inside complicated patterns. Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern.
- e
If this modifier is set, preg_replace() does normal substitution of backreferences in the replacement string, evaluates it as PHP code, and uses the result for replacing the search string.
Only preg_replace() uses this modifier; it is ignored by other PCRE functions.
Óçìåßùóç: This modifier was not available in PHP 3.
- A (PCRE_ANCHORED)
If this modifier is set, the pattern is forced to be "anchored", that is, it is constrained to match only at the start of the string which is being searched (the "subject string"). This effect can also be achieved by appropriate constructs in the pattern itself, which is the only way to do it in Perl.
- D (PCRE_DOLLAR_ENDONLY)
If this modifier is set, a dollar metacharacter in the pattern matches only at the end of the subject string. Without this modifier, a dollar also matches immediately before the final character if it is a newline (but not before any other newlines). This modifier is ignored if m modifier is set. There is no equivalent to this modifier in Perl.
- S
When a pattern is going to be used several times, it is worth spending more time analyzing it in order to speed up the time taken for matching. If this modifier is set, then this extra analysis is performed. At present, studying a pattern is useful only for non-anchored patterns that do not have a single fixed starting character.
- U (PCRE_UNGREEDY)
This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern.
- X (PCRE_EXTRA)
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Any backslash in a pattern that is followed by a letter that has no special meaning causes an error, thus reserving these combinations for future expansion. By default, as in Perl, a backslash followed by a letter with no special meaning is treated as a literal. There are at present no other features controlled by this modifier.
- u (PCRE_UTF8)
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32.
The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5, with just a few differences (see below). The current implementation corresponds to Perl 5.005.
The differences described here are with respect to Perl 5.005.
By default, a whitespace character is any character that the C library function isspace() recognizes, though it is possible to compile PCRE with alternative character type tables. Normally isspace() matches space, formfeed, newline, carriage return, horizontal tab, and vertical tab. Perl 5 no longer includes vertical tab in its set of whitespace characters. The \v escape that was in the Perl documentation for a long time was never in fact recognized. However, the character itself was treated as whitespace at least up to 5.002. In 5.004 and 5.005 it does not match \s.
PCRE does not allow repeat quantifiers on lookahead assertions. Perl permits them, but they do not mean what you might think. For example, (?!a){3} does not assert that the next three characters are not "a". It just asserts that the next character is not "a" three times.
Capturing subpatterns that occur inside negative lookahead assertions are counted, but their entries in the offsets vector are never set. Perl sets its numerical variables from any such patterns that are matched before the assertion fails to match something (thereby succeeding), but only if the negative lookahead assertion contains just one branch.
Though binary zero characters are supported in the subject string, they are not allowed in a pattern string because it is passed as a normal C string, terminated by zero. The escape sequence "\\x00" can be used in the pattern to represent a binary zero.
The following Perl escape sequences are not supported: \l, \u, \L, \U, \E, \Q. In fact these are implemented by Perl's general string-handling and are not part of its pattern matching engine.
The Perl \G assertion is not supported as it is not relevant to single pattern matches.
Fairly obviously, PCRE does not support the (?{code}) construction.
There are at the time of writing some oddities in Perl 5.005_02 concerned with the settings of captured strings when part of a pattern is repeated. For example, matching "aba" against the pattern /^(a(b)?)+$/ sets $2 to the value "b", but matching "aabbaa" against /^(aa(bb)?)+$/ leaves $2 unset. However, if the pattern is changed to /^(aa(b(b))?)+$/ then $2 (and $3) get set. In Perl 5.004 $2 is set in both cases, and that is also TRUE of PCRE. If in the future Perl changes to a consistent state that is different, PCRE may change to follow.
Another as yet unresolved discrepancy is that in Perl 5.005_02 the pattern /^(a)?(?(1)a|b)+$/ matches the string "a", whereas in PCRE it does not. However, in both Perl and PCRE /^(a)?a/ matched against "a" leaves $1 unset.
PCRE provides some extensions to the Perl regular expression facilities:
Although lookbehind assertions must match fixed length strings, each alternative branch of a lookbehind assertion can match a different length of string. Perl 5.005 requires them all to have the same length.
If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $ meta-character matches only at the very end of the string.
If PCRE_EXTRA is set, a backslash followed by a letter with no special meaning is faulted.
If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is inverted, that is, by default they are not greedy, but if followed by a question mark they are.
The syntax and semantics of the regular expressions supported by PCRE are described below. Regular expressions are also described in the Perl documentation and in a number of other books, some of which have copious examples. Jeffrey Friedl's "Mastering Regular Expressions", published by O'Reilly (ISBN 1-56592-257-3), covers them in great detail. The description here is intended as reference documentation.
A regular expression is a pattern that is matched against a subject string from left to right. Most characters stand for themselves in a pattern, and match the corresponding characters in the subject. As a trivial example, the pattern The quick brown fox matches a portion of a subject string that is identical to itself.
The power of regular expressions comes from the ability to include alternatives and repetitions in the pattern. These are encoded in the pattern by the use of meta-characters, which do not stand for themselves but instead are interpreted in some special way.
There are two different sets of meta-characters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized in square brackets. Outside square brackets, the meta-characters are as follows:
general escape character with several uses
assert start of subject (or line, in multiline mode)
assert end of subject (or line, in multiline mode)
match any character except newline (by default)
start character class definition
end character class definition
start of alternative branch
start subpattern
end subpattern
extends the meaning of (, also 0 or 1 quantifier, also quantifier minimizer
0 or more quantifier
1 or more quantifier
start min/max quantifier
end min/max quantifier
general escape character
negate the class, but only if the first character
indicates character range
terminates the character class
The backslash character has several uses. Firstly, if it is followed by a non-alphanumeric character, it takes away any special meaning that character may have. This use of backslash as an escape character applies both inside and outside character classes.
For example, if you want to match a "*" character, you write "\*" in the pattern. This applies whether or not the following character would otherwise be interpreted as a meta-character, so it is always safe to precede a non-alphanumeric with "\" to specify that it stands for itself. In particular, if you want to match a backslash, you write "\\".
If a pattern is compiled with the PCRE_EXTENDED option, whitespace in the pattern (other than in a character class) and characters between a "#" outside a character class and the next newline character are ignored. An escaping backslash can be used to include a whitespace or "#" character as part of the pattern.
A second use of backslash provides a way of encoding non-printing characters in patterns in a visible manner. There is no restriction on the appearance of non-printing characters, apart from the binary zero that terminates a pattern, but when a pattern is being prepared by text editing, it is usually easier to use one of the following escape sequences than the binary character it represents:
alarm, that is, the BEL character (hex 07)
"control-x", where x is any character
escape (hex 1B)
formfeed (hex 0C)
newline (hex 0A)
carriage return (hex 0D)
tab (hex 09)
character with hex code hh
character with octal code ddd, or backreference
The precise effect of "\cx" is as follows: if "x" is a lower case letter, it is converted to upper case. Then bit 6 of the character (hex 40) is inverted. Thus "\cz" becomes hex 1A, but "\c{" becomes hex 3B, while "\c;" becomes hex 7B.
After "\x", up to two hexadecimal digits are read (letters can be in upper or lower case).
After "\0" up to two further octal digits are read. In both cases, if there are fewer than two digits, just those that are present are used. Thus the sequence "\0\x\07" specifies two binary zeros followed by a BEL character. Make sure you supply two digits after the initial zero if the character that follows is itself an octal digit.
The handling of a backslash followed by a digit other than 0 is complicated. Outside a character class, PCRE reads it and any following digits as a decimal number. If the number is less than 10, or if there have been at least that many previous capturing left parentheses in the expression, the entire sequence is taken as a back reference. A description of how this works is given later, following the discussion of parenthesized subpatterns.
Inside a character class, or if the decimal number is greater than 9 and there have not been that many capturing subpatterns, PCRE re-reads up to three octal digits following the backslash, and generates a single byte from the least significant 8 bits of the value. Any subsequent digits stand for themselves. For example:
is another way of writing a space
is the same, provided there are fewer than 40 previous capturing subpatterns
is always a back reference
might be a back reference, or another way of writing a tab
is always a tab
is a tab followed by the character "3"
is the character with octal code 113 (since there can be no more than 99 back references)
is a byte consisting entirely of 1 bits
is either a back reference, or a binary zero followed by the two characters "8" and "1"
Note that octal values of 100 or greater must not be introduced by a leading zero, because no more than three octal digits are ever read.
All the sequences that define a single byte value can be used both inside and outside character classes. In addition, inside a character class, the sequence "\b" is interpreted as the backspace character (hex 08). Outside a character class it has a different meaning (see below).
The third use of backslash is for specifying generic character types:
any decimal digit
any character that is not a decimal digit
any whitespace character
any character that is not a whitespace character
any "word" character
any "non-word" character
Each pair of escape sequences partitions the complete set of characters into two disjoint sets. Any given character matches one, and only one, of each pair.
A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word". The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place (see "Locale support" above). For example, in the "fr" (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w.
These character type sequences can appear both inside and outside character classes. They each match one character of the appropriate type. If the current matching point is at the end of the subject string, all of them fail, since there is no character to match.
The fourth use of backslash is for certain simple assertions. An assertion specifies a condition that has to be met at a particular point in a match, without consuming any characters from the subject string. The use of subpatterns for more complicated assertions is described below. The backslashed assertions are
word boundary
not a word boundary
start of subject (independent of multiline mode)
end of subject or newline at end (independent of multiline mode)
end of subject(independent of multiline mode)
These assertions may not appear in character classes (but note that "\b" has a different meaning, namely the backspace character, inside a character class).
A word boundary is a position in the subject string where the current character and the previous character do not both match \w or \W (i.e. one matches \w and the other matches \W), or the start or end of the string if the first or last character matches \w, respectively.
The \A, \Z, and \z assertions differ from the traditional circumflex and dollar (described below) in that they only ever match at the very start and end of the subject string, whatever options are set. They are not affected by the PCRE_MULTILINE or PCRE_DOLLAR_ENDONLY options. The difference between \Z and \z is that \Z matches before a newline that is the last character of the string as well as at the end of the string, whereas \z matches only at the end.
Outside a character class, in the default matching mode, the circumflex character is an assertion which is true only if the current matching point is at the start of the subject string. Inside a character class, circumflex has an entirely different meaning (see below).
Circumflex need not be the first character of the pattern if a number of alternatives are involved, but it should be the first thing in each alternative in which it appears if the pattern is ever to match that branch. If all possible alternatives start with a circumflex, that is, if the pattern is constrained to match only at the start of the subject, it is said to be an "anchored" pattern. (There are also other constructs that can cause a pattern to be anchored.)
A dollar character is an assertion which is TRUE only if the current matching point is at the end of the subject string, or immediately before a newline character that is the last character in the string (by default). Dollar need not be the last character of the pattern if a number of alternatives are involved, but it should be the last item in any branch in which it appears. Dollar has no special meaning in a character class.
The meaning of dollar can be changed so that it matches only at the very end of the string, by setting the PCRE_DOLLAR_ENDONLY option at compile or matching time. This does not affect the \Z assertion.
The meanings of the circumflex and dollar characters are changed if the PCRE_MULTILINE option is set. When this is the case, they match immediately after and immediately before an internal "\n" character, respectively, in addition to matching at the start and end of the subject string. For example, the pattern /^abc$/ matches the subject string "def\nabc" in multiline mode, but not otherwise. Consequently, patterns that are anchored in single line mode because all branches start with "^" are not anchored in multiline mode. The PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is set.
Note that the sequences \A, \Z, and \z can be used to match the start and end of the subject in both modes, and if all branches of a pattern start with \A is it always anchored, whether PCRE_MULTILINE is set or not.
Outside a character class, a dot in the pattern matches any one character in the subject, including a non-printing character, but not (by default) newline. If the PCRE_DOTALL option is set, then dots match newlines as well. The handling of dot is entirely independent of the handling of circumflex and dollar, the only relationship being that they both involve newline characters. Dot has no special meaning in a character class.
An opening square bracket introduces a character class, terminated by a closing square bracket. A closing square bracket on its own is not special. If a closing square bracket is required as a member of the class, it should be the first data character in the class (after an initial circumflex, if present) or escaped with a backslash.
A character class matches a single character in the subject; the character must be in the set of characters defined by the class, unless the first character in the class is a circumflex, in which case the subject character must not be in the set defined by the class. If a circumflex is actually required as a member of the class, ensure it is not the first character, or escape it with a backslash.
For example, the character class [aeiou] matches any lower case vowel, while [^aeiou] matches any character that is not a lower case vowel. Note that a circumflex is just a convenient notation for specifying the characters which are in the class by enumerating those that are not. It is not an assertion: it still consumes a character from the subject string, and fails if the current pointer is at the end of the string.
When caseless matching is set, any letters in a class represent both their upper case and lower case versions, so for example, a caseless [aeiou] matches "A" as well as "a", and a caseless [^aeiou] does not match "A", whereas a caseful version would.
The newline character is never treated in any special way in character classes, whatever the setting of the PCRE_DOTALL or PCRE_MULTILINE options is. A class such as [^a] will always match a newline.
The minus (hyphen) character can be used to specify a range of characters in a character class. For example, [d-m] matches any letter between d and m, inclusive. If a minus character is required in a class, it must be escaped with a backslash or appear in a position where it cannot be interpreted as indicating a range, typically as the first or last character in the class.
It is not possible to have the literal character "]" as the end character of a range. A pattern such as [W-]46] is interpreted as a class of two characters ("W" and "-") followed by a literal string "46]", so it would match "W46]" or "-46]". However, if the "]" is escaped with a backslash it is interpreted as the end of range, so [W-\]46] is interpreted as a single class containing a range followed by two separate characters. The octal or hexadecimal representation of "]" can also be used to end a range.
Ranges operate in ASCII collating sequence. They can also be used for characters specified numerically, for example [\000-\037]. If a range that includes letters is used when caseless matching is set, it matches the letters in either case. For example, [W-c] is equivalent to [][\^_`wxyzabc], matched caselessly, and if character tables for the "fr" locale are in use, [\xc8-\xcb] matches accented E characters in both cases.
The character types \d, \D, \s, \S, \w, and \W may also appear in a character class, and add the characters that they match to the class. For example, [\dABCDEF] matches any hexadecimal digit. A circumflex can conveniently be used with the upper case character types to specify a more restricted set of characters than the matching lower case type. For example, the class [^\W_] matches any letter or digit, but not underscore.
All non-alphanumeric characters other than \, -, ^ (at the start) and the terminating ] are non-special in character classes, but it does no harm if they are escaped.
Vertical bar characters are used to separate alternative patterns. For example, the pattern gilbert|sullivan matches either "gilbert" or "sullivan". Any number of alternatives may appear, and an empty alternative is permitted (matching the empty string). The matching process tries each alternative in turn, from left to right, and the first one that succeeds is used. If the alternatives are within a subpattern (defined below), "succeeds" means matching the rest of the main pattern as well as the alternative in the subpattern.
The settings of PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and PCRE_EXTENDED can be changed from within the pattern by a sequence of Perl option letters enclosed between "(?" and ")". The option letters are
Ðßíáêáò 1. Internal option letters
i | for PCRE_CASELESS |
m | for PCRE_MULTILINE |
s | for PCRE_DOTALL |
x | for PCRE_EXTENDED |
For example, (?im) sets caseless, multiline matching. It is also possible to unset these options by preceding the letter with a hyphen, and a combined setting and unsetting such as (?im-sx), which sets PCRE_CASELESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED, is also permitted. If a letter appears both before and after the hyphen, the option is unset.
The scope of these option changes depends on where in the pattern the setting occurs. For settings that are outside any subpattern (defined below), the effect is the same as if the options were set or unset at the start of matching. The following patterns all behave in exactly the same way:
(?i)abc
a(?i)bc
ab(?i)c
abc(?i)
which in turn is the same as compiling the pattern abc with PCRE_CASELESS set. In other words, such "top level" settings apply to the whole pattern (unless there are other changes inside subpatterns). If there is more than one setting of the same option at top level, the rightmost setting is used.
If an option change occurs inside a subpattern, the effect is different. This is a change of behaviour in Perl 5.005. An option change inside a subpattern affects only that part of the subpattern that follows it, so (a(?i)b)c matches abc and aBc and no other strings (assuming PCRE_CASELESS is not used). By this means, options can be made to have different settings in different parts of the pattern. Any changes made in one alternative do carry on into subsequent branches within the same subpattern. For example, (a(?i)b|c) matches "ab", "aB", "c", and "C", even though when matching "C" the first branch is abandoned before the option setting. This is because the effects of option settings happen at compile time. There would be some very weird behaviour otherwise.
The PCRE-specific options PCRE_UNGREEDY and PCRE_EXTRA can be changed in the same way as the Perl-compatible options by using the characters U and X respectively. The (?X) flag setting is special in that it must always occur earlier in the pattern than any of the additional features it turns on, even when it is at top level. It is best put at the start.
Subpatterns are delimited by parentheses (round brackets), which can be nested. Marking part of a pattern as a subpattern does two things:
1. It localizes a set of alternatives. For example, the pattern cat(aract|erpillar|) matches one of the words "cat", "cataract", or "caterpillar". Without the parentheses, it would match "cataract", "erpillar" or the empty string.
2. It sets up the subpattern as a capturing subpattern (as defined above). When the whole pattern matches, that portion of the subject string that matched the subpattern is passed back to the caller via the ovector argument of pcre_exec(). Opening parentheses are counted from left to right (starting from 1) to obtain the numbers of the capturing subpatterns.
For example, if the string "the red king" is matched against the pattern the ((red|white) (king|queen)) the captured substrings are "red king", "red", and "king", and are numbered 1, 2, and 3.
The fact that plain parentheses fulfil two functions is not always helpful. There are often times when a grouping subpattern is required without a capturing requirement. If an opening parenthesis is followed by "?:", the subpattern does not do any capturing, and is not counted when computing the number of any subsequent capturing subpatterns. For example, if the string "the white queen" is matched against the pattern the ((?:red|white) (king|queen)) the captured substrings are "white queen" and "queen", and are numbered 1 and 2. The maximum number of captured substrings is 99, and the maximum number of all subpatterns, both capturing and non-capturing, is 200.
As a convenient shorthand, if any option settings are required at the start of a non-capturing subpattern, the option letters may appear between the "?" and the ":". Thus the two patterns
(?i:saturday|sunday)
(?:(?i)saturday|sunday)
match exactly the same set of strings. Because alternative branches are tried from left to right, and options are not reset until the end of the subpattern is reached, an option setting in one branch does affect subsequent branches, so the above patterns match "SUNDAY" as well as "Saturday".
Repetition is specified by quantifiers, which can follow any of the following items:
a single character, possibly escaped
the . metacharacter
a character class
a back reference (see next section)
a parenthesized subpattern (unless it is an assertion - see below)
The general repetition quantifier specifies a minimum and maximum number of permitted matches, by giving the two numbers in curly brackets (braces), separated by a comma. The numbers must be less than 65536, and the first must be less than or equal to the second. For example: z{2,4} matches "zz", "zzz", or "zzzz". A closing brace on its own is not a special character. If the second number is omitted, but the comma is present, there is no upper limit; if the second number and the comma are both omitted, the quantifier specifies an exact number of required matches. Thus [aeiou]{3,} matches at least 3 successive vowels, but may match many more, while \d{8} matches exactly 8 digits. An opening curly bracket that appears in a position where a quantifier is not allowed, or one that does not match the syntax of a quantifier, is taken as a literal character. For example, {,6} is not a quantifier, but a literal string of four characters.
The quantifier {0} is permitted, causing the expression to behave as if the previous item and the quantifier were not present.
For convenience (and historical compatibility) the three most common quantifiers have single-character abbreviations:
It is possible to construct infinite loops by following a subpattern that can match no characters with a quantifier that has no upper limit, for example: (a?)*
Earlier versions of Perl and PCRE used to give an error at compile time for such patterns. However, because there are cases where this can be useful, such patterns are now accepted, but if any repetition of the subpattern does in fact match no characters, the loop is forcibly broken.
By default, the quantifiers are "greedy", that is, they match as much as possible (up to the maximum number of permitted times), without causing the rest of the pattern to fail. The classic example of where this gives problems is in trying to match comments in C programs. These appear between the sequences /* and */ and within the sequence, individual * and / characters may appear. An attempt to match C comments by applying the pattern /\*.*\*/ to the string /* first command */ not comment /* second comment */ fails, because it matches the entire string due to the greediness of the .* item.
However, if a quantifier is followed by a question mark, then it ceases to be greedy, and instead matches the minimum number of times possible, so the pattern /\*.*?\*/ does the right thing with the C comments. The meaning of the various quantifiers is not otherwise changed, just the preferred number of matches. Do not confuse this use of question mark with its use as a quantifier in its own right. Because it has two uses, it can sometimes appear doubled, as in \d??\d which matches one digit by preference, but can match two if that is the only way the rest of the pattern matches.
If the PCRE_UNGREEDY option is set (an option which is not available in Perl) then the quantifiers are not greedy by default, but individual ones can be made greedy by following them with a question mark. In other words, it inverts the default behaviour.
When a parenthesized subpattern is quantified with a minimum repeat count that is greater than 1 or with a limited maximum, more store is required for the compiled pattern, in proportion to the size of the minimum or maximum.
If a pattern starts with .* or .{0,} and the PCRE_DOTALL option (equivalent to Perl's /s) is set, thus allowing the . to match newlines, then the pattern is implicitly anchored, because whatever follows will be tried against every character position in the subject string, so there is no point in retrying the overall match at any position after the first. PCRE treats such a pattern as though it were preceded by \A. In cases where it is known that the subject string contains no newlines, it is worth setting PCRE_DOTALL when the pattern begins with .* in order to obtain this optimization, or alternatively using ^ to indicate anchoring explicitly.
When a capturing subpattern is repeated, the value captured is the substring that matched the final iteration. For example, after (tweedle[dume]{3}\s*)+ has matched "tweedledum tweedledee" the value of the captured substring is "tweedledee". However, if there are nested capturing subpatterns, the corresponding captured values may have been set in previous iterations. For example, after /(a|(b))+/ matches "aba" the value of the second captured substring is "b".
Outside a character class, a backslash followed by a digit greater than 0 (and possibly further digits) is a back reference to a capturing subpattern earlier (i.e. to its left) in the pattern, provided there have been that many previous capturing left parentheses.
However, if the decimal number following the backslash is less than 10, it is always taken as a back reference, and causes an error only if there are not that many capturing left parentheses in the entire pattern. In other words, the parentheses that are referenced need not be to the left of the reference for numbers less than 10. See the section entitled "Backslash" above for further details of the handling of digits following a backslash.
A back reference matches whatever actually matched the capturing subpattern in the current subject string, rather than anything matching the subpattern itself. So the pattern (sens|respons)e and \1ibility matches "sense and sensibility" and "response and responsibility", but not "sense and responsibility". If caseful matching is in force at the time of the back reference, then the case of letters is relevant. For example, ((?i)rah)\s+\1 matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capturing subpattern is matched caselessly.
There may be more than one back reference to the same subpattern. If a subpattern has not actually been used in a particular match, then any back references to it always fail. For example, the pattern (a|(bc))\2 always fails if it starts to match "a" rather than "bc". Because there may be up to 99 back references, all digits following the backslash are taken as part of a potential back reference number. If the pattern continues with a digit character, then some delimiter must be used to terminate the back reference. If the PCRE_EXTENDED option is set, this can be whitespace. Otherwise an empty comment can be used.
A back reference that occurs inside the parentheses to which it refers fails when the subpattern is first used, so, for example, (a\1) never matches. However, such references can be useful inside repeated subpatterns. For example, the pattern (a|b\1)+ matches any number of "a"s and also "aba", "ababaa" etc. At each iteration of the subpattern, the back reference matches the character string corresponding to the previous iteration. In order for this to work, the pattern must be such that the first iteration does not need to match the back reference. This can be done using alternation, as in the example above, or by a quantifier with a minimum of zero.
An assertion is a test on the characters following or preceding the current matching point that does not actually consume any characters. The simple assertions coded as \b, \B, \A, \Z, \z, ^ and $ are described above. More complicated assertions are coded as subpatterns. There are two kinds: those that look ahead of the current position in the subject string, and those that look behind it.
An assertion subpattern is matched in the normal way, except that it does not cause the current matching position to be changed. Lookahead assertions start with (?= for positive assertions and (?! for negative assertions. For example, \w+(?=;) matches a word followed by a semicolon, but does not include the semicolon in the match, and foo(?!bar) matches any occurrence of "foo" that is not followed by "bar". Note that the apparently similar pattern (?!foo)bar does not find an occurrence of "bar" that is preceded by something other than "foo"; it finds any occurrence of "bar" whatsoever, because the assertion (?!foo) is always TRUE when the next three characters are "bar". A lookbehind assertion is needed to achieve this effect.
Lookbehind assertions start with (?<= for positive assertions and (?<! for negative assertions. For example, (?<!foo)bar does find an occurrence of "bar" that is not preceded by "foo". The contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length. However, if there are several alternatives, they do not all have to have the same fixed length. Thus (?<=bullock|donkey) is permitted, but (?<!dogs?|cats?) causes an error at compile time. Branches that match different length strings are permitted only at the top level of a lookbehind assertion. This is an extension compared with Perl 5.005, which requires all branches to match the same length of string. An assertion such as (?<=ab(c|de)) is not permitted, because its single top-level branch can match two different lengths, but it is acceptable if rewritten to use two top-level branches: (?<=abc|abde) The implementation of lookbehind assertions is, for each alternative, to temporarily move the current position back by the fixed width and then try to match. If there are insufficient characters before the current position, the match is deemed to fail. Lookbehinds in conjunction with once-only subpatterns can be particularly useful for matching at the ends of strings; an example is given at the end of the section on once-only subpatterns.
Several assertions (of any sort) may occur in succession. For example, (?<=\d{3})(?<!999)foo matches "foo" preceded by three digits that are not "999". Notice that each of the assertions is applied independently at the same point in the subject string. First there is a check that the previous three characters are all digits, then there is a check that the same three characters are not "999". This pattern does not match "foo" preceded by six characters, the first of which are digits and the last three of which are not "999". For example, it doesn't match "123abcfoo". A pattern to do that is (?<=\d{3}...)(?<!999)foo
This time the first assertion looks at the preceding six characters, checking that the first three are digits, and then the second assertion checks that the preceding three characters are not "999".
Assertions can be nested in any combination. For example, (?<=(?<!foo)bar)baz matches an occurrence of "baz" that is preceded by "bar" which in turn is not preceded by "foo", while (?<=\d{3}(?!999)...)foo is another pattern which matches "foo" preceded by three digits and any three characters that are not "999".
Assertion subpatterns are not capturing subpatterns, and may not be repeated, because it makes no sense to assert the same thing several times. If any kind of assertion contains capturing subpatterns within it, these are counted for the purposes of numbering the capturing subpatterns in the whole pattern. However, substring capturing is carried out only for positive assertions, because it does not make sense for negative assertions.
Assertions count towards the maximum of 200 parenthesized subpatterns.
With both maximizing and minimizing repetition, failure of what follows normally causes the repeated item to be re-evaluated to see if a different number of repeats allows the rest of the pattern to match. Sometimes it is useful to prevent this, either to change the nature of the match, or to cause it fail earlier than it otherwise might, when the author of the pattern knows there is no point in carrying on.
Consider, for example, the pattern \d+foo when applied to the subject line 123456bar
After matching all 6 digits and then failing to match "foo", the normal action of the matcher is to try again with only 5 digits matching the \d+ item, and then with 4, and so on, before ultimately failing. Once-only subpatterns provide the means for specifying that once a portion of the pattern has matched, it is not to be re-evaluated in this way, so the matcher would give up immediately on failing to match "foo" the first time. The notation is another kind of special parenthesis, starting with (?> as in this example: (?>\d+)bar
This kind of parenthesis "locks up" the part of the pattern it contains once it has matched, and a failure further into the pattern is prevented from backtracking into it. Backtracking past it to previous items, however, works as normal.
An alternative description is that a subpattern of this type matches the string of characters that an identical standalone pattern would match, if anchored at the current point in the subject string.
Once-only subpatterns are not capturing subpatterns. Simple cases such as the above example can be thought of as a maximizing repeat that must swallow everything it can. So, while both \d+ and \d+? are prepared to adjust the number of digits they match in order to make the rest of the pattern match, (?>\d+) can only match an entire sequence of digits.
This construction can of course contain arbitrarily complicated subpatterns, and it can be nested.
Once-only subpatterns can be used in conjunction with look-behind assertions to specify efficient matching at the end of the subject string. Consider a simple pattern such as abcd$ when applied to a long string which does not match. Because matching proceeds from left to right, PCRE will look for each "a" in the subject and then see if what follows matches the rest of the pattern. If the pattern is specified as ^.*abcd$ then the initial .* matches the entire string at first, but when this fails (because there is no following "a"), it backtracks to match all but the last character, then all but the last two characters, and so on. Once again the search for "a" covers the entire string, from right to left, so we are no better off. However, if the pattern is written as ^(?>.*)(?<=abcd) then there can be no backtracking for the .* item; it can match only the entire string. The subsequent lookbehind assertion does a single test on the last four characters. If it fails, the match fails immediately. For long strings, this approach makes a significant difference to the processing time.
When a pattern contains an unlimited repeat inside a subpattern that can itself be repeated an unlimited number of times, the use of a once-only subpattern is the only way to avoid some failing matches taking a very long time indeed. The pattern (\D+|<\d+>)*[!?] matches an unlimited number of substrings that either consist of non-digits, or digits enclosed in <>, followed by either ! or ?. When it matches, it runs quickly. However, if it is applied to aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa it takes a long time before reporting failure. This is because the string can be divided between the two repeats in a large number of ways, and all have to be tried. (The example used [!?] rather than a single character at the end, because both PCRE and Perl have an optimization that allows for fast failure when a single character is used. They remember the last single character that is required for a match, and fail early if it is not present in the string.) If the pattern is changed to ((?>\D+)|<\d+>)*[!?] sequences of non-digits cannot be broken, and failure happens quickly.
It is possible to cause the matching process to obey a subpattern conditionally or to choose between two alternative subpatterns, depending on the result of an assertion, or whether a previous capturing subpattern matched or not. The two possible forms of conditional subpattern are
(?(condition)yes-pattern)
(?(condition)yes-pattern|no-pattern)
If the condition is satisfied, the yes-pattern is used; otherwise the no-pattern (if present) is used. If there are more than two alternatives in the subpattern, a compile-time error occurs.
There are two kinds of condition. If the text between the parentheses consists of a sequence of digits, then the condition is satisfied if the capturing subpattern of that number has previously matched. Consider the following pattern, which contains non-significant white space to make it more readable (assume the PCRE_EXTENDED option) and to divide it into three parts for ease of discussion: ( \( )? [^()]+ (?(1) \) )
The first part matches an optional opening parenthesis, and if that character is present, sets it as the first captured substring. The second part matches one or more characters that are not parentheses. The third part is a conditional subpattern that tests whether the first set of parentheses matched or not. If they did, that is, if subject started with an opening parenthesis, the condition is TRUE, and so the yes-pattern is executed and a closing parenthesis is required. Otherwise, since no-pattern is not present, the subpattern matches nothing. In other words, this pattern matches a sequence of non-parentheses, optionally enclosed in parentheses.
If the condition is not a sequence of digits, it must be an assertion. This may be a positive or negative lookahead or lookbehind assertion. Consider this pattern, again containing non-significant white space, and with the two alternatives on the second line:
(?(?=[^a-z]*[a-z])
\d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} )
The condition is a positive lookahead assertion that matches an optional sequence of non-letters followed by a letter. In other words, it tests for the presence of at least one letter in the subject. If a letter is found, the subject is matched against the first alternative; otherwise it is matched against the second. This pattern matches strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are letters and dd are digits.
The sequence (?# marks the start of a comment which continues up to the next closing parenthesis. Nested parentheses are not permitted. The characters that make up a comment play no part in the pattern matching at all.
If the PCRE_EXTENDED option is set, an unescaped # character outside a character class introduces a comment that continues up to the next newline character in the pattern.
Consider the problem of matching a string in parentheses, allowing for unlimited nested parentheses. Without the use of recursion, the best that can be done is to use a pattern that matches up to some fixed depth of nesting. It is not possible to handle an arbitrary nesting depth. Perl 5.6 has provided an experimental facility that allows regular expressions to recurse (among other things). The special item (?R) is provided for the specific case of recursion. This PCRE pattern solves the parentheses problem (assume the PCRE_EXTENDED option is set so that white space is ignored): \( ( (?>[^()]+) | (?R) )* \)
First it matches an opening parenthesis. Then it matches any number of substrings which can either be a sequence of non-parentheses, or a recursive match of the pattern itself (i.e. a correctly parenthesized substring). Finally there is a closing parenthesis.
This particular example pattern contains nested unlimited repeats, and so the use of a once-only subpattern for matching strings of non-parentheses is important when applying the pattern to strings that do not match. For example, when it is applied to (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() it yields "no match" quickly. However, if a once-only subpattern is not used, the match runs for a very long time indeed because there are so many different ways the + and * repeats can carve up the subject, and all have to be tested before failure can be reported.
The values set for any capturing subpatterns are those from the outermost level of the recursion at which the subpattern value is set. If the pattern above is matched against (ab(cd)ef) the value for the capturing parentheses is "ef", which is the last value taken on at the top level. If additional parentheses are added, giving \( ( ( (?>[^()]+) | (?R) )* ) \) then the string they capture is "ab(cd)ef", the contents of the top level parentheses. If there are more than 15 capturing parentheses in a pattern, PCRE has to obtain extra memory to store data during a recursion, which it does by using pcre_malloc, freeing it via pcre_free afterwards. If no memory can be obtained, it saves data for the first 15 capturing parentheses only, as there is no way to give an out-of-memory error from within a recursion.
Certain items that may appear in patterns are more efficient than others. It is more efficient to use a character class like [aeiou] than a set of alternatives such as (a|e|i|o|u). In general, the simplest construction that provides the required behaviour is usually the most efficient. Jeffrey Friedl's book contains a lot of discussion about optimizing regular expressions for efficient performance.
When a pattern begins with .* and the PCRE_DOTALL option is set, the pattern is implicitly anchored by PCRE, since it can match only at the start of a subject string. However, if PCRE_DOTALL is not set, PCRE cannot make this optimization, because the . metacharacter does not then match a newline, and if the subject string contains newlines, the pattern may match from the character immediately following one of them instead of from the very start. For example, the pattern (.*) second matches the subject "first\nand second" (where \n stands for a newline character) with the first captured substring being "and". In order to do this, PCRE has to retry the match starting after every newline in the subject.
If you are using such a pattern with subject strings that do not contain newlines, the best performance is obtained by setting PCRE_DOTALL, or starting the pattern with ^.* to indicate explicit anchoring. That saves PCRE from having to scan along the subject looking for a newline to restart at.
Beware of patterns that contain nested indefinite repeats. These can take a long time to run when applied to a string that does not match. Consider the pattern fragment (a+)*
This can match "aaaa" in 33 different ways, and this number increases very rapidly as the string gets longer. (The * repeat can match 0, 1, 2, 3, or 4 times, and for each of those cases other than 0, the + repeats can match different numbers of times.) When the remainder of the pattern is such that the entire match is going to fail, PCRE has in principle to try every possible variation, and this can take an extremely long time.
An optimization catches some of the more simple cases such as (a+)*b where a literal character follows. Before embarking on the standard matching procedure, PCRE checks that there is a "b" later in the subject string, and if there is not, it fails the match immediately. However, when there is no following literal this optimization cannot be used. You can see the difference by comparing the behaviour of (a+)*\d with the pattern above. The former gives a failure almost instantly when applied to a whole line of "a" characters, whereas the latter takes an appreciable time with strings longer than about 20 characters.
preg_grep() returns the array consisting of the elements of the input array that match the given pattern.
flags can be the following flag:
If this flag is passed, preg_grep() returns the elements of the input array that do not match the given pattern. This flag is available since PHP 4.2.0.
Since PHP 4.0.4, the results returned by preg_grep() are indexed using the keys from the input array. If this behavior is undesirable, use array_values() on the array returned by preg_grep() to reindex the values.
Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags.
After the first match is found, the subsequent searches are continued on from end of the last match.
flags can be a combination of the following flags (note that it doesn't make sense to use PREG_PATTERN_ORDER together with PREG_SET_ORDER):
Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on.
<?php preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<b>example: </b><div align=left>this is a test</div>", $out, PREG_PATTERN_ORDER); echo $out[0][0] . ", " . $out[0][1] . "\n"; echo $out[1][0] . ", " . $out[1][1] . "\n"; ?> |
This example will produce:
<b>example: </b>, <div align=left>this is a test</div> example: , this is a test |
So, $out[0] contains array of strings that matched full pattern, and $out[1] contains array of strings enclosed by tags.
Orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches, and so on.
<?php preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<b>example: </b><div align=\"left\">this is a test</div>", $out, PREG_SET_ORDER); echo $out[0][0] . ", " . $out[0][1] . "\n"; echo $out[1][0] . ", " . $out[1][1] . "\n"; ?> |
This example will produce:
<b>example: </b>, example: <div align="left">this is a test</div>, this is a test |
In this case, $matches[0] is the first set of matches, and $matches[0][0] has text matched by full pattern, $matches[0][1] has text matched by first subpattern and so on. Similarly, $matches[1] is the second set of matches, etc.
If this flag is passed, for every occurring match the appendant string offset will also be returned. Note that this changes the return value in an array where every element is an array consisting of the matched string at offset 0 and its string offset into subject at offset 1. This flag is available since PHP 4.3.0 .
If no order flag is given, PREG_PATTERN_ORDER is assumed.
Normally, the search starts from the beginning of the subject string. The optional parameter offset can be used to specify the alternate place from which to start the search. It is equivalent to passing substr()($subject, $offset) to preg_match() in place of the subject string. The offset parameter is available since PHP 4.3.3.
Returns the number of full pattern matches (which might be zero), or FALSE if an error occurred.
ÐáñÜäåéãìá 2. Find matching HTML tags (greedy)
This example will produce:
|
See also preg_match(), preg_replace(), and preg_split().
Searches subject for a match to the regular expression given in pattern.
If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
flags can be the following flag:
If this flag is passed, for every occurring match the appendant string offset will also be returned. Note that this changes the return value in an array where every element is an array consisting of the matched string at offset 0 and its string offset into subject at offset 1. This flag is available since PHP 4.3.0 .
Normally, the search starts from the beginning of the subject string. The optional parameter offset can be used to specify the alternate place from which to start the search. It is equivalent to passing substr()($subject, $offset) to preg_match() in place of the subject string. The offset parameter is available since PHP 4.3.3.
preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject. preg_match() returns FALSE if an error occurred.
Õðüäåéîç: Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.
ÐáñÜäåéãìá 2. Find the word "web"
|
ÐáñÜäåéãìá 3. Getting the domain name out of a URL
This example will produce:
|
See also preg_match_all(), preg_replace(), and preg_split().
preg_quote() takes str and puts a backslash in front of every character that is part of the regular expression syntax. This is useful if you have a run-time string that you need to match in some text and the string may contain special regex characters.
If the optional delimiter is specified, it will also be escaped. This is useful for escaping the delimiter that is required by the PCRE functions. The / is the most commonly used delimiter.
The special regular expression characters are: . \\ + * ? [ ^ ] $ ( ) { } = ! < > | :
ÐáñÜäåéãìá 2. Italicizing a word within some text
|
(PHP 4 >= 4.0.5, PHP 5)
preg_replace_callback -- Perform a regular expression search and replace using a callbackThe behavior of this function is almost identical to preg_replace(), except for the fact that instead of replacement parameter, one should specify a callback that will be called and passed an array of matched elements in the subject string. The callback should return the replacement string.
ÐáñÜäåéãìá 1. preg_replace_callback() example
|
You'll often need the callback function for a preg_replace_callback() in just one place. In this case you can use create_function() to declare an anonymous function as callback within the call to preg_replace_callback(). By doing it this way you have all information for the call in one place and do not clutter the function namespace with a callback functions name not used anywhere else.
ÐáñÜäåéãìá 2. preg_replace_callback() and create_function()
|
See also preg_replace() and create_function().
Searches subject for matches to pattern and replaces them with replacement. If limit is specified, then only limit matches will be replaced; if limit is omitted or is -1, then all matches are replaced.
Replacement may contain references of the form \\n or (since PHP 4.0.4) $n, with the latter form being the preferred one. Every such reference will be replaced by the text captured by the n'th parenthesized pattern. n can be from 0 to 99, and \\0 or $0 refers to the text matched by the whole pattern. Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern.
When working with a replacement pattern where a backreference is immediately followed by another number (i.e.: placing a literal number immediately after a matched pattern), you cannot use the familiar \\1 notation for your backreference. \\11, for example, would confuse preg_replace() since it does not know whether you want the \\1 backreference followed by a literal 1, or the \\11 backreference followed by nothing. In this case the solution is to use \${1}1. This creates an isolated $1 backreference, leaving the 1 as a literal.
If matches are found, the new subject will be returned, otherwise subject will be returned unchanged.
Every parameter to preg_replace() (except limit) can be an unidimensional array. When using arrays with pattern and replacement, the keys are processed in the order they appear in the array. This is not necessarily the same as the numerical index order. If you use indexes to identify which pattern should be replaced by which replacement, you should perform a ksort() on each array prior to calling preg_replace().
ÐáñÜäåéãìá 2. Using indexed arrays with preg_replace()
Output:
By ksorting patterns and replacements, we should get what we wanted.
Output :
|
If subject is an array, then the search and replace is performed on every entry of subject, and the return value is an array as well.
If pattern and replacement are arrays, then preg_replace() takes a value from each array and uses them to do search and replace on subject. If replacement has fewer values than pattern, then empty string is used for the rest of replacement values. If pattern is an array and replacement is a string, then this replacement string is used for every value of pattern. The converse would not make sense, though.
/e modifier makes preg_replace() treat the replacement parameter as PHP code after the appropriate references substitution is done. Tip: make sure that replacement constitutes a valid PHP code string, otherwise PHP will complain about a parse error at the line containing preg_replace().
ÐáñÜäåéãìá 5. Convert HTML to text
|
Óçìåßùóç: Parameter limit was added after PHP 4.0.1pl2.
See also preg_match(), preg_match_all(), and preg_split().
Returns an array containing substrings of subject split along boundaries matched by pattern.
If limit is specified, then only substrings up to limit are returned, and if limit is -1, it actually means "no limit", which is useful for specifying the flags.
flags can be any combination of the following flags (combined with bitwise | operator):
If this flag is set, only non-empty pieces will be returned by preg_split().
If this flag is set, parenthesized expression in the delimiter pattern will be captured and returned as well. This flag was added for 4.0.5.
If this flag is set, for every occurring match the appendant string offset will also be returned. Note that this changes the return value in an array where every element is an array consisting of the matched string at offset 0 and its string offset into subject at offset 1. This flag is available since PHP 4.3.0 .
ÐáñÜäåéãìá 3. Splitting a string into matches and their offsets
will yield:
|
Óçìåßùóç: Parameter flags was added in PHP 4 Beta 3.
See also spliti(), split(), implode(), preg_match(), preg_match_all(), and preg_replace().
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
Óçìåßùóç: This extension has been removed as of PHP 5 and moved to the PECL repository.
(PHP 4 >= 4.0.5)
qdom_error -- Returns the error string from the last QDOM operation or FALSE if no errors occurredÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: Ôï PHP õðïóôçñßæåé åðßóçò êáé regular expressions ìå óõíôáêôéêü óõìâáôü ìå ôçí Perl ÷ñçóéìïðïéþíôáò ôéò óõíáñôÞóåéò PCRE. ÁõôÝò ïé óõíáñôÞóåéò õðïóôçñßæïõí non-greedy matching, assertions, conditional subpatterns, êáé ðïëëÜ Üëëá ÷áñáêôçñéóôéêÜ ðïõ äåí õðïóôçñßæïíôáé áðü ôï åêôåôáìÝíï POSIX óõíôáêôéêü ôùí regular expressions.
Ðñïåéäïðïßçóç |
ÁõôÝò ïé óõíáñôÞóåéò regular expression äåí åßíáé binary-safe. Ïé PCRE óõíáñôÞóåéò åßíáé. |
Ïé regular expressions ÷ñçóéìïðïéïýíôáé ãéá ðïëýðëïêç åðåîåñãáóßá ôùí string óôï PHP. Ïé óõíáñôÞóåéò õðïóôÞñéîçò ôùí regular expressions åßíáé ïé ðáñáêÜôù:
ÁõôÝò ïé óõíáñôÞóåéò äÝ÷ïíôáé Ýíá regular expression string óáí ôï ðñþôï ôïõò üñéóìá. Ôï PHP õëïðïéåß ôï åêôåôáìÝíï POSIX óõíôáêôéêü ôùí regular expressions üðùò ïñßæåôáé áðü ôï POSIX 1003.2. Ãéá ìéá ðëÞñç ðåñéãñáöÞ ôùí POSIX regular expressions äåßôå ôéò man pages regex ðïõ ðåñéëáìâÜíïíôáé óôïí õðïêáôÜëïãï regex ôçò äéáíïìÞò ôïõ PHP. Åßíáé áñ÷åßá óå ìïñöÞ manpage, ïðüôå èá ðñÝðåé íá êÜíåôå êÜôé óáí man /usr/local/src/regex/regex.7 ãéá íá ôá äéáâÜóåôå.Ãéá íá åíåñãïðïéÞóåôå ôçí õðïóôÞñéîç regexp êáôÜ ôçí åãêáôÜóôáóç ôïõ PHP ÷ñçóéìïðïéÞóôå ôçí åðéëïãÞ --with-regex[=ÔÕÐÏÓ]. Ï ÔÕÐÏÓ ìðïñåß íá åßíáé åßôå system, åßôå apache, åßôå php. Ï ðñïêáèïñéóìÝíïò ôýðïò åßíáé php.
Óçìåßùóç: Ìçí áëëÜæåôå ôïí ÔÕÐÏ åêôüò êé áí îÝñåôå êáëÜ ôé êÜíåôå.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá Regular Expression
|
Ãéá regular expressions ìå óõíôáêôéêü óõìâáôü ìå Perl äåßôå ôéò óõíáñôÞóåéò PCRE. Áí ðÜëé èÝëåôå ðéï áðëü pattern matching óôï óôõë ôïõ shell õðÜñ÷åé ç óõíÜñôçóç fnmatch().
Óçìåßùóç: Ç óõíÜñôçóç preg_replace(), ç ïðïßá êáôáëáâáßíåé óõíôáêôéêü regular expression óõìâáôü ìå Perl, ÷ñçóéìïðïéåßôáé óõ÷íÜ óáí ìéá ðéï ãñÞãïñç åíáëëáêôéêÞ óõíÜñôçóç áíôß ãéá ôçí ereg_replace().
ÁõôÞ ç óõíÜñôçóç øÜ÷íåé óôï string ãéá åìöáíßóåéò ôïõ pattern, êáé áíôéêáèéóôÜ ôï êåßìåíï êÜèå åìöÜíéóçò ìå ôï replacement.
ÅðéóôñÝöåé ôï ôñïðïðïéçìÝíï string. (Ðïõ ìðïñåß íá åßíáé êáé ôï ßäéï ìå ôï áñ÷éêü string áí äåí õðÜñ÷ïõí åìöáíßóåéò ðïõ èá áíôéêáôáóôáèïýí.)
Áí ôï pattern ðåñéÝ÷åé substrings ìÝóá óå ðáñåíèÝóåéò, ôï replacement ìðïñåß íá ðåñéÝ÷åé substrings ôçò ìïñöÞò \\÷ (üðïõ ôï ÷ åßíáé Ýíá íïýìåñï 0-9), ôá ïðïßá èá áíôéêáôáóôáèïýí áðü ôï êåßìåíï ðïõ ôáßñéáîå ìå ôï substring ÷. Óôï replacement ç Ýêöñáóç \\0 ðáñÜãåé ïëüêëçñï ôï áñ÷éêü string. ÌÝ÷ñé 9 substrings ìðïñïýí íá ÷ñçóéìïðïéçèïýí. ÆåõãÜñéá ðáñåíèÝóåùí ìðïñïýí íá ðåñéÝ÷ïõí Üëëá æåõãÜñéá. Óå áõôÞ ôçí ðåñßðôùóç ôá íïýìåñá êáèïñßæïíôáé áðü ôçí ðáñÝíèåóç ðïõ áíïßãåé ôï æåõãÜñé.
Áí äåí âñåèïýí åìöáíßóåéò óôï string, ôüôå åðéóôñÝöåôáé ç ðáñÜìåôñïò string ÷ùñßò áëëáãÝò.
Ãéá ðáñÜäåéãìá ôï ðáñáêÜôù êïììÜôé êþäéêá ôõðþíåé "Áõôü Þôáí Ýíá test" ôñåßò öïñÝò:
ÊÜôé ðïõ áîßæåé íá óçìåéùèåß åßíáé üôé üôáí ÷ñçóéìïðïéåßôå ìéá áêÝñáéá ôéìÞ óôçç èÝóç ôçò ðáñáìÝôñïõ replacement, ìðïñåß íá ìç ðÜñåôå ôá áðïôåëÝóìáôá ðïõ ßóùò ðåñéìÝíáôå. Áõôü óõìâáßíåé ãéáôß ç óõíÜñôçóç ereg_replace() ðñïóðáèåß íá åñìçíåýóåé ôïí áñéèìü óáí ôçí ôéìÞ ASCII åíüò ÷áñáêôÞñá êáé ãñÜöåé áõôüí ôïí ÷áñáêôÞñá. Ãéá ðáñÜäåéãìá:
ÐáñÜäåéãìá 2. ÐáñÜäåéãìá óõíÜñôçóçò ereg_replace()
|
Äåßôå åðßóçò ôéò ereg(), eregi(), eregi_replace(), str_replace(), êáé preg_match().
Óçìåßùóç: Ç óõíÜñôçóç preg_match(), ç ïðïßá êáôáëáâáßíåé óõíôáêôéêü regular expression óõìâáôü ìå Perl, ÷ñçóéìïðïéåßôáé óõ÷íÜ óáí ìéá ðéï ãñÞãïñç åíáëëáêôéêÞ óõíÜñôçóç áíôß ãéá ôçí ereg().
ÁíáæçôÜ åìöáíßóåéò åíüò regular expression pattern óå Ýíá string.
Áí âñåèïýí åìöáíßóåéò ãéá êÜðïéï ôìÞìá ôïõ pattern ðïõ åßíáé ìÝóá óå ðáñåíèÝóåéò êáé ç óõíÜñôçóç Ý÷åé êëçèåß ìå ôñßá ïñßóìáôá, ïé åìöáíßóåéò ôïõ pattern èá áðïèçêåõèïýí óôá óôïé÷åßá ôïõ ðßíáêá regs. Ôï óôïé÷åßï $regs[1] èá ðåñéÝ÷åé ôï ðñþôï string ðïõ îåêéíÜ ìå ôçí ðñþôç áñéóôåñÞ ðáñÝíèåóç. Ôï óôïé÷åßï $regs[2] èá ðåñéÝ÷åé ôï string ðïõ îåêéíÜ ìå ôç äåýôåñç, êé ïýôù êáèåîÞò. Ôï óôïé÷åßï $regs[0] èá ðåñéÝ÷åé Ýíá áíôßãñáöï áðü üëï ôï string ðïõ ôáßñéáîå.
Óçìåßùóç: ÌÝ÷ñé êáé ôçí Ýêäïóç 4.1.0 ôïõ PHP (óõìðåñéëáìâáíïìÝíçò êáé ôçò 4.1.0), ï ðßíáêáò $regs ãåìßæåé ðÜíôá ìå áêñéâþò 10 óôïé÷åßá, ðáñüëï ðïõ ìðïñåß íá õðÜñ÷ïõí ëéãüôåñåò áðü äÝêá åêöñÜóåéò ìÝóá óå ðáñåíèÝóåéò ðïõ ìðïñåß íá ôáéñéÜîïõí. Áõôü äåí åðçñåÜæåé ôçí äõíáôüôçôá ôçò ereg() íá âñåé ðåñéóóüôåñåò åìöáíßóåéò. Áí äåí âñåèåß êáìßá åìöÜíéóç, ôüôå ï ðßíáêáò $regs äåí ôñïðïðïéåßôáé áðü ôçí óõíÜñôçóç ereg().
Ç áíáæÞôçóç ëáìâÜíåé õðüøç ôçò ôç äéáöïñÜ ìéêñþí-êåöáëáßùí ãñáììÜôùí.
ÅðéóôñÝöåôáé TRUE áí õðÜñ÷åé ôïõëÜ÷éóôïí ìéá åìöÜíéóç ôïõ pattern óôï string. FALSE åðéóôñÝöåôáé áí äåí õðÜñ÷åé êáìßá åìöÜíéóç Þ ðñïêëÞèçêå êÜðïéï ëÜèïò.
Ôï ðáñáêÜôù ðáñÜäåéãìá êþäéêá ðáßñíåé ìéá çìåñïìçíßá óôç ìïñöÞ ISO (××××-ÌÌ-ÇÇ) êáé ôçí ôõðþíåé óôç ìïñöÞ ÇÇ.ÌÌ.××××:
Äåßôå åðßóçò ôéò eregi(), ereg_replace(), eregi_replace(), preg_match(), strpos(), êáé strstr().
(PHP 3, PHP 4 , PHP 5)
eregi_replace -- áíôéêáôÜóôáóç regular expression ÷ùñßò Ýëåã÷ï êåöáëáßùí-ìéêñþíÁõôÞ ç óõíÜñôçóç åßíáé ßäéá óå óõìðåñéöïñÜ êáé ëåéôïõñãßá ìå ôçí ereg_replace() áëëÜ äåí îå÷ùñßæåé ôá êåöáëáßá áðü ôá ìéêñÜ ãñÜììáôá.
Äåßôå åðßóçò ôéò óõíáñôÞóåéò ereg(), eregi(), êáé ereg_replace().
ÁõôÞ ç óõíÜñôçóç åßíáé ßäéá óå óõìðåñéöïñÜ êáé ëåéôïõñãßá ìå ôçí ereg() áëëÜ äåí îå÷ùñßæåé ôá êåöáëáßá áðü ôá ìéêñÜ ãñÜììáôá.
Äåßôå åðßóçò ôéò óõíáñôÞóåéò ereg(), ereg_replace(), eregi_replace(), stripos(), êáé stristr().
Óçìåßùóç: Ç óõíÜñôçóç preg_split(), ðïõ ÷ñçóéìïðïéåß óõíôáêôéêü regular expression óõìâáôü ìå Perl, ÷ñçóéìïðïéåßôáé óõ÷íÜ óáí ìéá åíáëëáêôéêÞ óõíÜñôçóç áíôß ãéá ôçí split().
ÅðéóôñÝöåé Ýíá ðßíáêá áðü string, êÜèå óôïé÷åßï ôïõ ïðïßïõ åßíáé Ýíá êïììÜôé ôçò ðáñáìÝôñïõ string, ÷ùñßæïíôáò ôï string óå üñéá ðïõ êáèïñßæïíôáé áðü ôéò åìöáíßóåéò ôïõ regular expression pattern. Áí ç ðáñÜìåôñïò limit Ý÷åé äïèåß, ï ðßíáêáò ðïõ åðéóôñÝöåôáé ðåñéÝ÷åé ôï ðïëý limit óôïé÷åßá ìå ôï ôåëåõôáßï óôïé÷åßï íá ðåñéÝ÷åé ôï õðüëïéðï ôçò ðáñáìÝôñïõ string. Áí ðñïêëçèåß êÜðïéï ëÜèïò, ç óõíÜñôçóç split() åðéóôñÝöåéå FALSE.
Ãéá íá ÷ùñßóåôå ôá ôÝóóåñá ðñþôá ðåäßá ìéáò ãñáììÞò áðü ôï áñ÷åßï /etc/passwd:
Óçìåßùóç: Áí õðÜñ÷ïõí ÷ åìöáíßóåéò ôïõ pattern, ï ðßíáêáò ðïõ åðéóôñÝöåôáé èá ðåñéÝ÷åé ÷+1 óôïé÷åßá. Ãéá ðáñÜäåéãìá, áí äåí õðÜñ÷åé êáìßá åìöÜíéóç ôïõ pattern, Ýíáò ðßíáêáò ìå ìüíï Ýíá óôïé÷åßï åðéóôñÝöåôáé. ÖõóéêÜ, ôï ßäéï ãßíåôáé êé üôáí ç ðáñÜìåôñïò string åßíáé êåíÞ.
Ãéá íá îå÷ùñßóåôå ôá ìÝñç ìéáò çìåñïìçíßáò üôáí áõôÜ ÷ùñßæïíôáé ìå slashes, ôåëåßåò Þ ðáýëåò:
Ç äéáöïñÜ êåöáëáßùí-ìéêñþí ÷áñáêôÞñùí óôçí ðáñÜìåôñï pattern ëáìâÜíåôáé õðüøç.
Áí äåí ÷ñåéÜæåóôå áðáñáéôÞôùò ôçí åõåëéîßá ôùí regular expression åßíáé ðéï ãñÞãïñç ç óõíÜñôçóç explode() ðïõ äåí ÷ñçóéìïðïéåß ôïí ìç÷áíéóìü ôùí regular expression.
For users looking for a way to emulate Perl's @chars = split('', $str) behaviour, please see the examples for preg_split().
Ç ðáñÜìåôñïò pattern åßíáé Ýíá regular expression. Áí èÝëåôå íá ÷ùñßóåôå ôï string ìå âÜóç êÜðïéï áðü ôïõò ÷áñáêôÞñåò ðïõ Ý÷ïõí åéäéêÞ óçìáóßá óôá regular expression èá ðñÝðåé íá ôïõò êÜíåôå escape ðñþôá. Áí êÜðïéá óôéãìÞ íïìßóåôå üôé ç split() (Þ êÜðïéá Üëëç óõíÜñôçóç ðïõ ÷ñçóéìïðïéåß regular expression) êÜíåé êÜôé ðåñßåñãï, äéáâÜóôå ôï áñ÷åßï regex.7, ðïõ ðåñéÝ÷åôáé óôïí êáôÜëïãï regex/ ôçò äéáíïìÞò ôïõ PHP. Åßíáé óå ìïñöÞ manpage, ïðüôå èá ðñÝðåé íá êÜíåôå êÜôé óáí man /usr/local/src/regex/regex.7 ãéá íá ôï äéáâÜóåôå.
Äåßôå åðßóçò ôéò óõíáñôÞóåéò: preg_split(), spliti(), explode(), implode(), chunk_split(), êáé wordwrap().
(PHP 4 >= 4.0.1, PHP 5)
spliti -- ÷ùñéóìüò åíüò string óå array ìå âÜóç Ýíá regular expression ÷ùñßò Ýëåã÷ï êåöáëáßùí-ìéêñþíÁõôÞ ç óõíÜñôçóç åßíáé ðáíïìïéüôõðç ìå ôçí split() áëëÜ äåí ëáìâÜíåé õðüøç ôçò ôç äéáöïñÜ êåöáëáßùí-ìéêñþí ÷áñáêôÞñùí.
Äåßôå åðßóçò ôéò óõíáñôÞóåéò preg_spliti(), split(), explode(), êáé implode().
(PHP 3, PHP 4 , PHP 5)
sql_regcase -- äçìéïõñãßá åíüò regular expression ãéá ôáßñéáóìá ÷ùñßò Ýëåã÷ï êåöáëáßùí-ìéêñþíÅðéóôñÝöåé Ýíá regular expression êáôÜëëçëï ãéá ôáßñéáóìá ôçò ðáñáìÝôñïõ string ÷ùñßò Ýëåã÷ï êåöáëáßùí-ìéêñþí. Áõôü ôï regular expression åßíáé ôï ßäéï ôï string üðïõ êÜèå ÷áñáêôÞñáò Ý÷åé ìåôáôñáðåß óå ìéá Ýêöñáóç ìå áãêýëåò. Ç Ýêöñáóç ìÝóá óôéò áãêýëåò ðåñéÝ÷åé ôüóï ôïí ìéêñü üóï êáé ôïí êåöáëáßï ÷áñáêôÞñá, üðïõ áõôü Ý÷åé íüçìá, áëëéþò ðåñéÝ÷åé ôïí áñ÷éêü ÷áñáêôÞñá äõï öïñÝò. Ôï ðáñáêÜôù êïììÜôé êþäéêá
[Ff][Oo][Oo] [Bb][Aa][Rr] |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá õëïðïéçèåß ôáßñéáóìá regular expression óå ðñïúüíôá ðïõ õðïóôçñßæïõí ìüíï regular expression ìå Ýëåã÷ï êåöáëáßùí-ìéêñþí.
This module provides wrappers for the System V IPC family of functions. It includes semaphores, shared memory and inter-process messaging (IPC).
Semaphores may be used to provide exclusive access to resources on the current machine, or to limit the number of processes that may simultaneously use a resource.
This module provides also shared memory functions using System V shared memory. Shared memory may be used to provide access to global variables. Different httpd-daemons and even other programs (such as Perl, C, ...) are able to access this data to provide a global data-exchange. Remember, that shared memory is NOT safe against simultaneous access. Use semaphores for synchronization.
Ðßíáêáò 1. Limits of Shared Memory by the Unix OS
SHMMAX | max size of shared memory, normally 131072 bytes |
SHMMIN | minimum size of shared memory, normally 1 byte |
SHMMNI | max amount of shared memory segments on a system, normally 100 |
SHMSEG | max amount of shared memory segments per process, normally 6 |
The messaging functions may be used to send and receive messages to/from other processes. They provide a simple and effective means of exchanging data between processes, without the need for setting up an alternative using Unix domain sockets.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
Support for this functions are not enabled by default. To enable System V semaphore support compile PHP with the option --enable-sysvsem. To enable the System V shared memory support compile PHP with the option --enable-sysvshm. To enable the System V messages support compile PHP with the option --enable-sysvmsg.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 2. Semaphore Configuration Options
Name | Default | Changeable |
---|---|---|
sysvmsg.value | "42" | PHP_INI_ALL |
sysvmsg.string | "foobar" | PHP_INI_ALL |
The function converts the pathname of an existing accessible file and a project identifier (proj) into a integer for use with for example shmop_open() and other System V IPC keys. The proj parameter should be a one character string.
On success the return value will be the created key value, otherwise -1 is returned.
See also shmop_open() and sem_get().
msg_get_queue() returns an id that can be used to access the System V message queue with the given key. The first call creates the message queue with the optional perms (default: 0666). A second call to msg_get_queue() for the same key will return a different message queue identifier, but both identifiers access the same underlying message queue. If the message queue already exists, the perms will be ignored.
See also msg_remove_queue(), msg_receive(), msg_send(), msg_stat_queue() and msg_set_queue().
msg_receive() will receive the first message from the specified queue of the type specified by desiredmsgtype. The type of the message that was received will be stored in msgtype. The maximum size of message to be accepted is specified by the maxsize; if the message in the queue is larger than this size the function will fail (unless you set flags as described below). The received message will be stored in message, unless there were errors receiving the message, in which case the optional errorcode will be set to the value of the system errno variable to help you identify the cause.
If desiredmsgtype is 0, the message from the front of the queue is returned. If desiredmsgtype is greater than 0, then the first message of that type is returned. If desiredmsgtype is less than 0, the first message on the queue with the lowest type less than or equal to the absolute value of desiredmsgtype will be read. If no messages match the criteria, your script will wait until a suitable message arrives on the queue. You can prevent the script from blocking by specifying MSG_IPC_NOWAIT in the flags parameter.
unserialize defaults to TRUE; if it is set to TRUE, the message is treated as though it was serialized using the same mechanism as the session module. The message will be unserialized and then returned to your script. This allows you to easily receive arrays or complex object structures from other PHP scripts, or if you are using the WDDX serializer, from any WDDX compatible source. If unserialize is FALSE, the message will be returned as a binary-safe string.
The optional flags allows you to pass flags to the low-level msgrcv system call. It defaults to 0, but you may specify one or more of the following values (by adding or ORing them together).
Ðßíáêáò 1. Flag values for msg_receive
MSG_IPC_NOWAIT | If there are no messages of the desiredmsgtype, return immediately and do not wait. The function will fail and return an integer value corresponding to ENOMSG. |
MSG_IPC_NOWAIT | Using this flag in combination with a desiredmsgtype greater than 0 will cause the function to receive the first message that is not equal to desiredmsgtype. |
MSG_IPC_NOWAIT | If the message is longer than maxsize, setting this flag will truncate the message to maxsize and will not signal an error. |
Upon successful completion the message queue data structure is updated as follows: msg_lrpid is set to the process-ID of the calling process, msg_qnum is decremented by 1 and msg_rtime is set to the current time.
msg_receive() returns TRUE on success or FALSE on failure. If the function fails, the optional errorcode will be set to the value of the system errno variable.
See also msg_remove_queue(), msg_send(), msg_stat_queue() and msg_set_queue().
msg_remove_queue() destroys the message queue specified by the queue. Only use this function when all processes have finished working with the message queue and you need to release the system resources held by it.
See also msg_remove_queue(), msg_receive(), msg_stat_queue() and msg_set_queue().
msg_send() sends a message of type msgtype (which MUST be greater than 0) to a the message queue specified by queue.
If the message is too large to fit in the queue, your script will wait until another process reads messages from the queue and frees enough space for your message to be sent. This is called blocking; you can prevent blocking by setting the optional blocking parameter to FALSE, in which case msg_send() will immediately return FALSE if the message is too big for the queue, and set the optional errorcode to EAGAIN, indicating that you should try to send your message again a little later on.
The optional serialize controls how the message is sent. serialize defaults to TRUE which means that the message is serialized using the same mechanism as the session module before being sent to the queue. This allows complex arrays and objects to be sent to other PHP scripts, or if you are using the WDDX serializer, to any WDDX compatible client.
Upon successful completion the message queue data structure is updated as follows: msg_lspid is set to the process-ID of the calling process, msg_qnum is incremented by 1 and msg_stime is set to the current time.
See also msg_remove_queue(), msg_receive(), msg_stat_queue() and msg_set_queue().
msg_set_queue() allows you to change the values of the msg_perm.uid, msg_perm.gid, msg_perm.mode and msg_qbytes fields of the underlying message queue data structure. You specify the values you require by setting the value of the keys that you require in the data array.
Changing the data structure will require that PHP be running as the same user that created the queue, owns the queue (as determined by the existing msg_perm.xxx fields), or be running with root privileges. root privileges are required to raise the msg_qbytes values above the system defined limit.
See also msg_remove_queue(), msg_receive(), msg_stat_queue() and msg_set_queue().
msg_stat_queue() returns the message queue meta data for the message queue specified by the queue. This is useful, for example, to determine which process sent the message that was just received.
The return value is an array whose keys and values have the following meanings:
Ðßíáêáò 1. Array structure for msg_stat_queue
msg_perm.uid | The uid of the owner of the queue. |
msg_perm.gid | The gid of the owner of the queue. |
msg_perm.mode | The file access mode of the queue. |
msg_stime | The time that the last message was sent to the queue. |
msg_rtime | The time that the last message was received from the queue. |
msg_ctime | The time that the queue was last changed. |
msg_qnum | The number of messages waiting to be read from the queue. |
msg_qbytes | The number of bytes of space currently available in the queue to hold sent messages until they are received. |
msg_lspid | The pid of the process that sent the last message to the queue. |
msg_lrpid | The pid of the process that received the last message from the queue. |
See also msg_remove_queue(), msg_receive(), msg_stat_queue() and msg_set_queue().
sem_acquire() blocks (if necessary) until the semaphore can be acquired. A process attempting to acquire a semaphore which it has already acquired will block forever if acquiring the semaphore would cause its maximum number of semaphore to be exceeded. sem_identifier is a semaphore ressource, obtained from sem_get().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
After processing a request, any semaphores acquired by the process but not explicitly released will be released automatically and a warning will be generated.
See also sem_get(), and sem_release().
sem_get() returns an id that can be used to access the System V semaphore with the given key. The semaphore is created if necessary using the permission bits specified in perm (defaults to 0666). The number of processes that can acquire the semaphore simultaneously is set to max_acquire (defaults to 1). Actually this value is set only if the process finds it is the only process currently attached to the semaphore.
Returns: A positive semaphore identifier on success, or FALSE on error.
A second call to sem_get() for the same key will return a different semaphore identifier, but both identifiers access the same underlying semaphore.
See also sem_acquire(), sem_release(), and ftok().
sem_release() releases the semaphore if it is currently acquired by the calling process, otherwise a warning is generated.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
After releasing the semaphore, sem_acquire() may be called to re-acquire it.
See also sem_get() and sem_acquire().
sem_remove() removes the semaphore sem_identifier if it has been created by sem_get(), otherwise generates a warning.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
After removing the semaphore, it is no more accessible.
See also sem_get(), sem_release() and sem_acquire().
shm_attach() returns an id that that can be used to access the System V shared memory with the given key, the first call creates the shared memory segment with memsize (default: sysvshm.init_mem in the php.ini, otherwise 10000 bytes) and the optional perm-bits perm (default: 0666).
A second call to shm_attach() for the same key will return a different shared memory identifier, but both identifiers access the same underlying shared memory. Memsize and perm will be ignored.
See also ftok(), and shm_detach().
shm_detach() disconnects from the shared memory given by the shm_identifier created by shm_attach(). Remember, that shared memory still exist in the Unix system and the data is still present.
shm_detach() always returns TRUE.
See also shm_attach(), shm_remove(), and shm_remove_var().
shm_get_var() returns the variable with a given variable_key, in the shared memory segment identified by shm_identifier. shm_identifier was obtained from shm_attach(). The variable is still present in the shared memory.
shm_put_var() inserts or updates the variable with the given variable_key. All variable-types are supported.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Warnings (E_WARNING level) will be issued if shm_identifier is not a valid SysV shared memory index or if there was not enough shared memory remaining to complete your request.
Removes a variable with a given variable_key and frees the occupied memory.
See also shm_remove().
shm_remove() removes the shared memory shm_identifier. All data will be destroyed.
See also shm_remove_var().
SESAM/SQL-Server is a mainframe database system, developed by Fujitsu Siemens Computers, Germany. It runs on high-end mainframe servers using the operating system BS2000/OSD.
In numerous productive BS2000 installations, SESAM/SQL-Server has proven
the ease of use of Java-, Web- and client/server connectivity,
the capability to work with an availability of more than 99.99%,
the ability to manage tens and even hundreds of thousands of users.
There is a PHP3 SESAM interface available which allows database operations via PHP-scripts.
Óçìåßùóç: Access to SESAM is only available with the latest CVS-Version of PHP3. PHP 4 does not support the SESAM database.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Name of BS2000 PLAM library containing the loadable SESAM driver modules. Required for using SESAM functions. The BS2000 PLAM library must be set ACCESS=READ,SHARE=YES because it must be readable by the apache server's user id.
Name of SESAM application configuration file. Required for using SESAM functions. The BS2000 file must be readable by the apache server's user id.
The application configuration file will usually contain a configuration like (see SESAM reference manual):
Name of SESAM message catalog file. In most cases, this directive is not necessary. Only if the SESAM message file is not installed in the system's BS2000 message file table, it can be set with this directive.
The message catalog must be set ACCESS=READ,SHARE=YES because it must be readable by the apache server's user id.
There is no standalone support for the PHP SESAM interface, it works only as an integrated Apache module. In the Apache PHP module, this SESAM interface is configured using Apache directives.
Ðßíáêáò 1. SESAM Configuration directives
Directive | Meaning |
---|---|
php3_sesam_oml |
Name of BS2000 PLAM library containing the loadable SESAM
driver modules. Required for using SESAM functions.
Example: |
php3_sesam_configfile |
Name of SESAM application configuration file. Required for
using SESAM functions.
Example: It will usually contain a configuration like (see SESAM reference manual): |
php3_sesam_messagecatalog |
Name of SESAM message catalog file. In most cases, this
directive is not necessary. Only if the SESAM message file
is not installed in the system's BS2000 message file table,
it can be set with this directive.
Example: |
In addition to the configuration of the PHP/SESAM interface, you have to configure the SESAM-Database server itself on your mainframe as usual. That means:
starting the SESAM database handler (DBH), and
connecting the databases with the SESAM database handler
To get a connection between a PHP script and the database handler, the CNF and NAM parameters of the selected SESAM configuration file must match the id of the started database handler.
In case of distributed databases you have to start a SESAM/SQL-DCN agent with the distribution table including the host and database names.
The communication between PHP (running in the POSIX subsystem) and the database handler (running outside the POSIX subsystem) is realized by a special driver module called SQLSCI and SESAM connection modules using common memory. Because of the common memory access, and because PHP is a static part of the web server, database accesses are very fast, as they do not require remote accesses via ODBC, JDBC or UTM.
Only a small stub loader (SESMOD) is linked with PHP, and the SESAM connection modules are pulled in from SESAM's OML PLAM library. In the configuration, you must tell PHP the name of this PLAM library, and the file link to use for the SESAM configuration file (As of SESAM V3.0, SQLSCI is available in the SESAM Tool Library, which is part of the standard distribution).
Because the SQL command quoting for single quotes uses duplicated single quotes (as opposed to a single quote preceded by a backslash, used in some other databases), it is advisable to set the PHP configuration directives php3_magic_quotes_gpc and php3_magic_quotes_sybase to On for all PHP scripts using the SESAM interface.
Because of limitations of the BS2000 process model, the driver can be loaded only after the Apache server has forked off its server child processes. This will slightly slow down the initial SESAM request of each child, but subsequent accesses will respond at full speed.
When explicitly defining a Message Catalog for SESAM, that catalog will be loaded each time the driver is loaded (i.e., at the initial SESAM request). The BS2000 operating system prints a message after successful load of the message catalog, which will be sent to Apache's error_log file. BS2000 currently does not allow suppression of this message, it will slowly fill up the log.
Make sure that the SESAM OML PLAM library and SESAM configuration file are readable by the user id running the web server. Otherwise, the server will be unable to load the driver, and will not allow to call any SESAM functions. Also, access to the database must be granted to the user id under which the Apache server is running. Otherwise, connections to the SESAM database handler will fail.
The result cursors which are allocated for SQL "select type" queries can be either "sequential" or "scrollable". Because of the larger memory overhead needed by "scrollable" cursors, the default is "sequential".
When using "scrollable" cursors, the cursor can be freely positioned on the result set. For each "scrollable" query, there are global default values for the scrolling type (initialized to: SESAM_SEEK_NEXT) and the scrolling offset which can either be set once by sesam_seek_row() or each time when fetching a row using sesam_fetch_row(). When fetching a row using a "scrollable" cursor, the following post-processing is done for the global default values for the scrolling type and scrolling offset:
Ðßíáêáò 2. Scrolled Cursor Post-Processing
Scroll Type | Action |
---|---|
SESAM_SEEK_NEXT | none |
SESAM_SEEK_PRIOR | none |
SESAM_SEEK_FIRST | set scroll type to SESAM_SEEK_NEXT |
SESAM_SEEK_LAST | set scroll type to SESAM_SEEK_PRIOR |
SESAM_SEEK_ABSOLUTE | Auto-Increment internal offset value |
SESAM_SEEK_RELATIVE | none. (maintain global default offset value, which allows for, e.g., fetching each 10th row backwards) |
Because in the PHP world it is natural to start indexes at zero (rather than 1), some adaptions have been made to the SESAM interface: whenever an indexed array is starting with index 1 in the native SESAM interface, the PHP interface uses index 0 as a starting point. E.g., when retrieving columns with sesam_fetch_row(), the first column has the index 0, and the subsequent columns have indexes up to (but not including) the column count ($array["count"]). When porting SESAM applications from other high level languages to PHP, be aware of this changed interface. Where appropriate, the description of the respective PHP sesam functions include a note that the index is zero based.
When allowing access to the SESAM databases, the web server user should only have as little privileges as possible. For most databases, only read access privilege should be granted. Depending on your usage scenario, add more access rights as you see fit. Never allow full control to any database for any user from the 'net! Restrict access to PHP scripts which must administer the database by using password control and/or SSL security.
No two SQL dialects are ever 100% compatible. When porting SQL applications from other database interfaces to SESAM, some adaption may be required. The following typical differences should be noted:
Vendor specific data types
Some vendor specific data types may have to be replaced by standard SQL data types (e.g., TEXT could be replaced by VARCHAR(max. size)).
Keywords as SQL identifiers
In SESAM (as in standard SQL), such identifiers must be enclosed in double quotes (or renamed).
Display length in data types
SESAM data types have a precision, not a display length. Instead of int(4) (intended use: integers up to '9999'), SESAM requires simply int for an implied size of 31 bits. Also, the only datetime data types available in SESAM are: DATE, TIME(3) and TIMESTAMP(3).
SQL types with vendor-specific unsigned, zerofill, or auto_increment attributes
Unsigned and zerofill are not supported. Auto_increment is automatic (use "INSERT ... VALUES(*, ...)" instead of "... VALUES(0, ...)" to take advantage of SESAM-implied auto-increment.
int ... DEFAULT '0000'
Numeric variables must not be initialized with string constants. Use DEFAULT 0 instead. To initialize variables of the datetime SQL data types, the initialization string must be prefixed with the respective type keyword, as in: CREATE TABLE exmpl ( xtime timestamp(3) DEFAULT TIMESTAMP '1970-01-01 00:00:00.000' NOT NULL );
$count = xxxx_num_rows();
Some databases promise to guess/estimate the number of the rows in a query result, even though the returned value is grossly incorrect. SESAM does not know the number of rows in a query result before actually fetching them. If you REALLY need the count, try SELECT COUNT(...) WHERE ..., it will tell you the number of hits. A second query will (hopefully) return the results.
DROP TABLE thename;
In SESAM, in the DROP TABLE command, the table name must be either followed by the keyword RESTRICT or CASCADE. When specifying RESTRICT, an error is returned if there are dependent objects (e.g., VIEWs), while with CASCADE, dependent objects will be deleted along with the specified table.
SESAM does not currently support the BLOB type. A future version of SESAM will have support for BLOB.
At the PHP interface, the following type conversions are automatically applied when retrieving SQL fields:
Ðßíáêáò 3. SQL to PHP Type Conversions
SQL Type | PHP Type |
---|---|
SMALLINT, INTEGER | integer |
NUMERIC, DECIMAL, FLOAT, REAL, DOUBLE | float |
DATE, TIME, TIMESTAMP | string |
VARCHAR, CHARACTER | string |
The special "multiple fields" feature of SESAM allows a column to consist of an array of fields. Such a "multiple field" column can be created like this:
When retrieving a result row, "multiple columns" are accessed like "inlined" additional columns. In the example above, "pkey" will have the index 0, and the three "multi(1..3)" columns will be accessible as indices 1 through 3.
For specific SESAM details, please refer to the SESAM/SQL-Server documentation (english) or the SESAM/SQL-Server documentation (german), both available online, or use the respective manuals.
result_id is a valid result id returned by sesam_query().
Returns the number of rows affected by a query associated with result_id.
The sesam_affected_rows() function can only return useful values when used in combination with "immediate" SQL statements (updating operations like INSERT, UPDATE and DELETE) because SESAM does not deliver any "affected rows" information for "select type" queries. The number returned is the number of affected rows.
See also sesam_query() and sesam_execimm().
Returns: TRUE on success, FALSE on errors
sesam_commit() commits any pending updates to the database.
Note that there is no "auto-commit" feature as in other databases, as it could lead to accidental data loss. Uncommitted data at the end of the current script (or when calling sesam_disconnect()) will be discarded by an implied sesam_rollback() call.
See also: sesam_rollback().
Returns TRUE if a connection to the SESAM database was made, or FALSE on error.
sesam_connect() establishes a connection to an SESAM database handler task. The connection is always "persistent" in the sense that only the very first invocation will actually load the driver from the configured SESAM OML PLAM library. Subsequent calls will reuse the driver and will immediately use the given catalog, schema, and user.
When creating a database, the "catalog" name is specified in the SESAM configuration directive //ADD-SQL-DATABASE-CATALOG-LIST ENTRY-1 = *CATALOG(CATALOG-NAME = catalogname,...)
The "schema" references the desired database schema (see SESAM handbook).
The "user" argument references one of the users which are allowed to access this "catalog" / "schema" combination. Note that "user" is completely independent from both the system's user id's and from HTTP user/password protection. It appears in the SESAM configuration only.
See also sesam_disconnect().
Returns an associative array of status and return codes for the last SQL query/statement/command. Elements of the array are:
Ðßíáêáò 1. Status information returned by sesam_diagnostic()
Element | Contents |
---|---|
$array["sqlstate"] | 5 digit SQL return code (see the SESAM manual for the description of the possible values of SQLSTATE) |
$array["rowcount"] | number of affected rows in last update/insert/delete (set after "immediate" statements only) |
$array["errmsg"] | "human readable" error message string (set after errors only) |
$array["errcol"] | error column number of previous error (0-based; or -1 if undefined. Set after errors only) |
$array["errlin"] | error line number of previous error (0-based; or -1 if undefined. Set after errors only) |
In the following example, a syntax error (E SEW42AE ILLEGAL CHARACTER) is displayed by including the offending SQL statement and pointing to the error location:
ÐáñÜäåéãìá 1. Displaying SESAM error messages with error position
|
See also: sesam_errormsg() for simple access to the error string only
Returns: always TRUE.
sesam_disconnect() closes the logical link to a SESAM database (without actually disconnecting and unloading the driver).
Note that this isn't usually necessary, as the open connection is automatically closed at the end of the script's execution. Uncommitted data will be discarded, because an implicit sesam_rollback() is executed.
sesam_disconnect() will not close the persistent link, it will only invalidate the currently defined "catalog", "schema" and "user" triple, so that any sesam function called after sesam_disconnect() will fail.
See also sesam_connect().
Returns the SESAM error message associated with the most recent SESAM error.
See also sesam_diagnostic() for the full set of SESAM SQL status information.
Returns: A SESAM "result identifier" on success, or FALSE on error.
sesam_execimm() executes an "immediate" statement (i.e., a statement like UPDATE, INSERT or DELETE which returns no result, and has no INPUT or OUTPUT variables). "select type" queries can not be used with sesam_execimm(). Sets the affected_rows value for retrieval by the sesam_affected_rows() function.
Note that sesam_query() can handle both "immediate" and "select-type" queries. Use sesam_execimm() only if you know beforehand what type of statement will be executed. An attempt to use SELECT type queries with sesam_execimm() will return $err["sqlstate"] == "42SBW".
The returned "result identifier" can not be used for retrieving anything but the sesam_affected_rows(); it is only returned for symmetry with the sesam_query() function.
<?php $stmt = "INSERT INTO mytable VALUES ('one', 'two')"; $result = sesam_execimm($stmt); $err = sesam_diagnostic(); echo "sqlstate = " . $err["sqlstate"] . "\n". "Affected rows = " . $err["rowcount"] . " == " . sesam_affected_rows($result) . "\n"; ?> |
See also sesam_query() and sesam_affected_rows().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
sesam_fetch_array() is an alternative version of sesam_fetch_row(). Instead of storing the data in the numeric indices of the result array, it stores the data in associative indices, using the field names as keys.
result_id is a valid result id returned by sesam_query() (select type queries only!).
For the valid values of the optional whenceand offset parameters, see the sesam_fetch_row() function for details.
sesam_fetch_array() fetches one row of data from the result associated with the specified result identifier. The row is returned as an associative array. Each result column is stored with an associative index equal to its column (aka. field) name. The column names are converted to lower case.
Columns without a field name (e.g., results of arithmetic operations) and empty fields are not stored in the array. Also, if two or more columns of the result have the same column names, the later column will take precedence. In this situation, either call sesam_fetch_row() or make an alias for the column.
A special handling allows fetching "multiple field" columns (which would otherwise all have the same column names). For each column of a "multiple field", the index name is constructed by appending the string "(n)" where n is the sub-index of the multiple field column, ranging from 1 to its declared repetition factor. The indices are NOT zero based, in order to match the nomenclature used in the respective query syntax. For a column declared as:
the associative indices used for the individual "multiple field" columns would be "multi(1)", "multi(2)", and "multi(3)" respectively.Subsequent calls to sesam_fetch_array() would return the next (or prior, or n'th next/prior, depending on the scroll attributes) row in the result set, or FALSE if there are no more rows.
ÐáñÜäåéãìá 1. SESAM fetch array
|
See also: sesam_fetch_row() which returns an indexed array.
Returns a mixed array with the query result entries, optionally limited to a maximum of max_rows rows. Note that both row and column indexes are zero-based.
Ðßíáêáò 1. Mixed result set returned by sesam_fetch_result()
Array Element | Contents |
---|---|
int $arr["count"] | number of columns in result set (or zero if this was an "immediate" query) |
int $arr["rows"] | number of rows in result set (between zero and max_rows) |
bool $arr["truncated"] | TRUE if the number of rows was at least max_rows, FALSE otherwise. Note that even when this is TRUE, the next sesam_fetch_result() call may return zero rows because there are no more result entries. |
mixed $arr[col][row] | result data for all the fields at row(row) and column(col), (where the integer index row is between 0 and $arr["rows"]-1, and col is between 0 and $arr["count"]-1). Fields may be empty, so you must check for the existence of a field by using the php isset() function. The type of the returned fields depend on the respective SQL type declared for its column (see SESAM overview for the conversions applied). SESAM "multiple fields" are "inlined" and treated like a sequence of columns. |
See also: sesam_fetch_row(), and sesam_field_array() to check for "multiple fields". See the description of the sesam_query() function for a complete example using sesam_fetch_result().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
The number of columns in the result set is returned in an associative array element $array["count"]. Because some of the result columns may be empty, the count() function can not be used on the result row returned by sesam_fetch_row().
result_id is a valid result id returned by sesam_query() (select type queries only!).
whence is an optional parameter for a fetch operation on "scrollable" cursors, which can be set to the following predefined constants:
Ðßíáêáò 1. Valid values for "whence" parameter
Value | Constant | Meaning |
---|---|---|
0 | SESAM_SEEK_NEXT | read sequentially (after fetch, the internal default is set to SESAM_SEEK_NEXT) |
1 | SESAM_SEEK_PRIOR | read sequentially backwards (after fetch, the internal default is set to SESAM_SEEK_PRIOR) |
2 | SESAM_SEEK_FIRST | rewind to first row (after fetch, the default is set to SESAM_SEEK_NEXT) |
3 | SESAM_SEEK_LAST | seek to last row (after fetch, the default is set to SESAM_SEEK_PRIOR) |
4 | SESAM_SEEK_ABSOLUTE | seek to absolute row number given as offset (Zero-based. After fetch, the internal default is set to SESAM_SEEK_ABSOLUTE, and the internal offset value is auto-incremented) |
5 | SESAM_SEEK_RELATIVE | seek relative to current scroll position, where offset can be a positive or negative offset value. |
When using "scrollable" cursors, the cursor can be freely positioned on the result set. If the whence parameter is omitted, the global default values for the scrolling type (initialized to: SESAM_SEEK_NEXT, and settable by sesam_seek_row()) are used. If whence is supplied, its value replaces the global default.
offset is an optional parameter which is only evaluated (and required) if whence is either SESAM_SEEK_RELATIVE or SESAM_SEEK_ABSOLUTE. This parameter is only valid for "scrollable" cursors.
sesam_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array (indexed by values between 0 and $array["count"]-1). Fields may be empty, so you must check for the existence of a field by using the isset() function. The type of the returned fields depend on the respective SQL type declared for its column (see SESAM overview for the conversions applied). SESAM "multiple fields" are "inlined" and treated like a sequence of columns.
Subsequent calls to sesam_fetch_row() would return the next (or prior, or n'th next/prior, depending on the scroll attributes) row in the result set, or FALSE if there are no more rows.
ÐáñÜäåéãìá 1. SESAM fetch rows
|
See also: sesam_fetch_array() which returns an associative array, and sesam_fetch_result() which returns many rows per invocation.
result_id is a valid result id returned by sesam_query().
Returns a mixed associative/indexed array with meta information (column name, type, precision, ...) about individual columns of the result after the query associated with result_id.
Ðßíáêáò 1. Mixed result set returned by sesam_field_array()
Array Element | Contents |
---|---|
int $arr["count"] | Total number of columns in result set (or zero if this was an "immediate" query). SESAM "multiple fields" are "inlined" and treated like the respective number of columns. |
string $arr[col]["name"] | column name for column(col), where col is between 0 and $arr["count"]-1. The returned value can be the empty string (for dynamically computed columns). SESAM "multiple fields" are "inlined" and treated like the respective number of columns, each with the same column name. |
string $arr[col]["count"] | The "count" attribute describes the repetition factor when the column has been declared as a "multiple field". Usually, the "count" attribute is 1. The first column of a "multiple field" column however contains the number of repetitions (the second and following column of the "multiple field" contain a "count" attribute of 1). This can be used to detect "multiple fields" in the result set. See the example shown in the sesam_query() description for a sample use of the "count" attribute. |
string $arr[col]["type"] | PHP variable type of the data for column(col), where col is between 0 and $arr["count"]-1. The returned value can be one of depending on the SQL type of the result. SESAM "multiple fields" are "inlined" and treated like the respective number of columns, each with the same PHP type. |
string $arr[col]["sqltype"] |
SQL variable type of the column data for
column(col), where col
is between 0 and $arr["count"]-1. The
returned value can be one of
|
string $arr[col]["length"] | The SQL "length" attribute of the SQL variable in column(col), where col is between 0 and $arr["count"]-1. The "length" attribute is used with "CHARACTER" and "VARCHAR" SQL types to specify the (maximum) length of the string variable. SESAM "multiple fields" are "inlined" and treated like the respective number of columns, each with the same length attribute. |
string $arr[col]["precision"] | The "precision" attribute of the SQL variable in column(col), where col is between 0 and $arr["count"]-1. The "precision" attribute is used with numeric and time data types. SESAM "multiple fields" are "inlined" and treated like the respective number of columns, each with the same precision attribute. |
string $arr[col]["scale"] | The "scale" attribute of the SQL variable in column(col), where col is between 0 and $arr["count"]-1. The "scale" attribute is used with numeric data types. SESAM "multiple fields" are "inlined" and treated like the respective number of columns, each with the same scale attribute. |
See also sesam_query() for an example of the sesam_field_array() use.
Returns the name of a field (i.e., the column name) in the result set, or FALSE on error.
For "immediate" queries, or for dynamic columns, an empty string is returned.
Óçìåßùóç: The column index is zero-based, not one-based as in SESAM.
See also: sesam_field_array(). It provides an easier interface to access the column names and types, and allows for detection of "multiple fields".
Releases resources for the query associated with result_id. Returns FALSE on error.
After calling sesam_query() with a "select type" query, this function gives you the number of columns in the result. Returns an integer describing the total number of columns (aka. fields) in the current result_id result set or FALSE on error.
For "immediate" statements, the value zero is returned. The SESAM "multiple field" columns count as their respective dimension, i.e., a three-column "multiple field" counts as three columns.
See also: sesam_query() and sesam_field_array() for a way to distinguish between "multiple field" columns and regular columns.
Returns: A SESAM "result identifier" on success, or FALSE on error.
A "result_id" resource is used by other functions to retrieve the query results.
sesam_query() sends a query to the currently active database on the server. It can execute both "immediate" SQL statements and "select type" queries. If an "immediate" statement is executed, then no cursor is allocated, and any subsequent sesam_fetch_row() or sesam_fetch_result() call will return an empty result (zero columns, indicating end-of-result). For "select type" statements, a result descriptor and a (scrollable or sequential, depending on the optional boolean scrollable parameter) cursor will be allocated. If scrollable is omitted, the cursor will be sequential.
When using "scrollable" cursors, the cursor can be freely positioned on the result set. For each "scrollable" query, there are global default values for the scrolling type (initialized to: SESAM_SEEK_NEXT) and the scrolling offset which can either be set once by sesam_seek_row() or each time when fetching a row using sesam_fetch_row().
For "immediate" statements, the number of affected rows is saved for retrieval by the sesam_affected_rows() function.
See also: sesam_fetch_row() and sesam_fetch_result().
ÐáñÜäåéãìá 1. Show all rows of the "phone" table as a HTML table
|
Returns: TRUE on success, FALSE on errors
sesam_rollback() discards any pending updates to the database. Also affected are result cursors and result descriptors.
At the end of each script, and as part of the sesam_disconnect() function, an implied sesam_rollback() is executed, discarding any pending changes to the database.
See also: sesam_commit().
ÐáñÜäåéãìá 1. Discarding an update to the SESAM database
|
result_id is a valid result id (select type queries only, and only if a "scrollable" cursor was requested when calling sesam_query()).
whence sets the global default value for the scrolling type, it specifies the scroll type to use in subsequent fetch operations on "scrollable" cursors, which can be set to the following predefined constants:
Ðßíáêáò 1. Valid values for "whence" parameter
Value | Constant | Meaning |
---|---|---|
0 | SESAM_SEEK_NEXT | read sequentially |
1 | SESAM_SEEK_PRIOR | read sequentially backwards |
2 | SESAM_SEEK_FIRST | fetch first row (after fetch, the default is set to SESAM_SEEK_NEXT) |
3 | SESAM_SEEK_LAST | fetch last row (after fetch, the default is set to SESAM_SEEK_PRIOR) |
4 | SESAM_SEEK_ABSOLUTE | fetch absolute row number given as offset (Zero-based. After fetch, the default is set to SESAM_SEEK_ABSOLUTE, and the offset value is auto-incremented) |
5 | SESAM_SEEK_RELATIVE | fetch relative to current scroll position, where offset can be a positive or negative offset value (this also sets the default "offset" value for subsequent fetches). |
offset is an optional parameter which is only evaluated (and required) if whence is either SESAM_SEEK_RELATIVE or SESAM_SEEK_ABSOLUTE.
Returns: TRUE if the values are valid, and the settransaction() operation was successful, FALSE otherwise.
sesam_settransaction() overrides the default values for the "isolation level" and "read-only" transaction parameters (which are set in the SESAM configuration file), in order to optimize subsequent queries and guarantee database consistency. The overridden values are used for the next transaction only.
sesam_settransaction() can only be called before starting a transaction, not after the transaction has been started already.
To simplify the use in PHP scripts, the following constants have been predefined in PHP (see SESAM handbook for detailed explanation of the semantics):
Ðßíáêáò 1. Valid values for "Isolation_Level" parameter
Value | Constant | Meaning |
---|---|---|
1 | SESAM_TXISOL_READ_UNCOMMITTED | Read Uncommitted |
2 | SESAM_TXISOL_READ_COMMITTED | Read Committed |
3 | SESAM_TXISOL_REPEATABLE_READ | Repeatable Read |
4 | SESAM_TXISOL_SERIALIZABLE | Serializable |
Ðßíáêáò 2. Valid values for "Read_Only" parameter
Value | Constant | Meaning |
---|---|---|
0 | SESAM_TXREAD_READWRITE | Read/Write |
1 | SESAM_TXREAD_READONLY | Read-Only |
The values set by sesam_settransaction() will override the default setting specified in the SESAM configuration file.
Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.
A visitor accessing your web site is assigned an unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.
The session support allows you to register arbitrary numbers of variables to be preserved across requests. When a visitor accesses your site, PHP will check automatically (if session.auto_start is set to 1) or on your request (explicitly through session_start() or implicitly through session_register()) whether a specific session id has been sent with the request. If this is the case, the prior saved environment is recreated.
Ðñïóï÷Þ |
If you do turn on session.auto_start then you cannot put objects into your sessions since the class definition has to be loaded before starting the session in order to recreate the objects in your session. |
All registered variables are serialized after the request finishes. Registered variables which are undefined are marked as being not defined. On subsequent accesses, these are not defined by the session module unless the user defines them later.
Óçìåßùóç: Session handling was added in PHP 4.0.
Óçìåßùóç: Please note when working with sessions that a record of a session is not created until a variable has been registered using the session_register() function or by adding a new key to the $_SESSION superglobal array. This holds true regardless of if a session has been started using the session_start() function.
External links: Session fixation
The session module cannot guarantee that the information you store in a session is only viewed by the user who created the session. You need to take additional measures to actively protect the integrity of the session, depending on the value associated with it.
Assess the importance of the data carried by your sessions and deploy additional protections -- this usually comes at a price, reduced convenience for the user. For example, if you want to protect users from simple social engineering tactics, you need to enable session.use_only_cookies. In that case, cookies must be enabled unconditionally on the user side, or sessions will not work.
There are several ways to leak an existing session id to third parties. A leaked session id enables the third party to access all resources which are associated with a specific id. First, URLs carrying session ids. If you link to an external site, the URL including the session id might be stored in the external site's referrer logs. Second, a more active attacker might listen to your network traffic. If it is not encrypted, session ids will flow in plain text over the network. The solution here is to implement SSL on your server and make it mandatory for users.
Äåí ÷ñåéÜæïíôáé åîùôåñéêÝò âéâëéïèÞêåò ãéá íá ãßíåé build áõôÞ ç åðÝêôáóç.
Óçìåßùóç: Optionally you can use shared memory allocation (mm), developed by Ralf S. Engelschall, for session storage. You have to download mm and install it. This option is not available for Windows platforms. Note that the session storage module for mm does not guarantee that concurrent accesses to the same session are properly locked. It might be more appropriate to use a shared memory based filesystem (such as tmpfs on Solaris/Linux, or /dev/md on BSD) to store sessions in files, because they are properly locked.
Session support is enabled in PHP by default. If you would not like to build your PHP with session support, you should specify the --disable-session option to configure. To use shared memory allocation (mm) for session storage configure PHP --with-mm[=DIR] .
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Óçìåßùóç: By default, all data related to a particular session will be stored in a file in the directory specified by the session.save_path INI option. A file for each session (regardless of if any data is associated with that session) will be created. This is due to the fact that a session is opened (a file is created) but no data is even written to that file. Note that this behavior is a side-effect of the limitations of working with the file system and it is possible that a custom session handler (such as one which uses a database) does not keep track of sessions which store no data.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Session configuration options
Name | Default | Changeable |
---|---|---|
session.save_path | "/tmp" | PHP_INI_ALL |
session.name | "PHPSESSID" | PHP_INI_ALL |
session.save_handler | "files" | PHP_INI_ALL |
session.auto_start | "0" | PHP_INI_ALL |
session.gc_probability | "1" | PHP_INI_ALL |
session.gc_divisor | "100" | PHP_INI_ALL |
session.gc_maxlifetime | "1440" | PHP_INI_ALL |
session.serialize_handler | "php" | PHP_INI_ALL |
session.cookie_lifetime | "0" | PHP_INI_ALL |
session.cookie_path | "/" | PHP_INI_ALL |
session.cookie_domain | "" | PHP_INI_ALL |
session.cookie_secure | "" | PHP_INI_ALL |
session.use_cookies | "1" | PHP_INI_ALL |
session.use_only_cookies | "0" | PHP_INI_ALL |
session.referer_check | "" | PHP_INI_ALL |
session.entropy_file | "" | PHP_INI_ALL |
session.entropy_length | "0" | PHP_INI_ALL |
session.cache_limiter | "nocache" | PHP_INI_ALL |
session.cache_expire | "180" | PHP_INI_ALL |
session.use_trans_sid | "0" | PHP_INI_SYSTEM | PHP_INI_PERDIR |
session.bug_compat_42 | "1" | PHP_INI_ALL |
session.bug_compat_warn | "1" | PHP_INI_ALL |
session.hash_function | "0" | PHP_INI_ALL |
session.hash_bits_per_character | "4" | PHP_INI_ALL |
url_rewriter.tags | "a=href,area=href,frame=src,input=src,form=fakeentry" | PHP_INI_ALL |
The session management system supports a number of configuration options which you can place in your php.ini file. We will give a short overview.
session.save_handler defines the name of the handler which is used for storing and retrieving data associated with a session. Defaults to files. See also session_set_save_handler().
session.save_path defines the argument which is passed to the save handler. If you choose the default files handler, this is the path where the files are created. Defaults to /tmp. See also session_save_path().
There is an optional N argument to this directive that determines the number of directory levels your session files will be spread around in. For example, setting to '5;/tmp' may end up creating a session file and location like /tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If . In order to use N you must create all of these directories before use. A small shell script exists in ext/session to do this, it's called mod_files.sh. Also note that if N is used and greater than 0 then automatic garbage collection will not be performed, see a copy of php.ini for further information. Also, if you use N, be sure to surround session.save_path in "quotes" because the separator (;) is also used for comments in php.ini.
Ðñïåéäïðïßçóç |
If you leave this set to a world-readable directory, such as /tmp (the default), other users on the server may be able to hijack sessions by getting the list of files in that directory. |
Óçìåßùóç: Windows users have to change this variable in order to use PHP's session functions. Make sure to specify a valid path, e.g.: c:/temp.
session.name specifies the name of the session which is used as cookie name. It should only contain alphanumeric characters. Defaults to PHPSESSID. See also session_name().
session.auto_start specifies whether the session module starts a session automatically on request startup. Defaults to 0 (disabled).
session.serialize_handler defines the name of the handler which is used to serialize/deserialize data. Currently, a PHP internal format (name php) and WDDX is supported (name wddx). WDDX is only available, if PHP is compiled with WDDX support. Defaults to php.
session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. Defaults to 1. See session.gc_divisor for details.
session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. session.gc_divisor defaults to 100.
session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up.
Óçìåßùóç: If you are using the default file-based session handler, your filesystem must keep track of access times (atime). Windows FAT does not so you will have to come up with another way to handle garbage collecting your session if you are stuck with a FAT filesystem or any other fs where atime tracking is not available. Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you won't have problems with filesystems where atime tracking is not available.
session.referer_check contains the substring you want to check each HTTP Referer for. If the Referer was sent by the client and the substring was not found, the embedded session id will be marked as invalid. Defaults to the empty string.
session.entropy_file gives a path to an external resource (file) which will be used as an additional entropy source in the session id creation process. Examples are /dev/random or /dev/urandom which are available on many Unix systems.
session.entropy_length specifies the number of bytes which will be read from the file specified above. Defaults to 0 (disabled).
session.use_cookies specifies whether the module will use cookies to store the session id on the client side. Defaults to 1 (enabled).
session.use_only_cookies specifies whether the module will only use cookies to store the session id on the client side. Defaults to 0 (disabled, for backward compatibility). Enabling this setting prevents attacks involved passing session ids in URLs. This setting was added in PHP 4.3.0.
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0.See also session_get_cookie_params() and session_set_cookie_params().
session.cookie_path specifies path to set in session_cookie. Defaults to /.See also session_get_cookie_params() and session_set_cookie_params().
session.cookie_domain specifies the domain to set in session_cookie. Default is none at all. See also session_get_cookie_params() and session_set_cookie_params().
session.cookie_secure specifies whether cookies should only be sent over secure connections. Defaults to off. This setting was added in PHP 4.0.4. See also session_get_cookie_params() and session_set_cookie_params().
session.cache_limiter specifies cache control method to use for session pages (none/nocache/private/private_no_expire/public). Defaults to nocache. See also session_cache_limiter().
session.cache_expire specifies time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180. See also session_cache_expire().
session.use_trans_sid whether transparent sid support is enabled or not. Defaults to 0 (disabled).
Óçìåßùóç: For PHP 4.1.2 or less, it is enabled by compiling with --enable-trans-sid. From PHP 4.2.0, trans-sid feature is always compiled.
URL based session management has additional security risks compared to cookie based session management. Users may send a URL that contains an active session ID to their friends by email or users may save a URL that contains a session ID to their bookmarks and access your site with the same session ID always, for example.
PHP versions 4.2.0 and lower have an undocumented feature/bug that allows you to to initialize a session variable in the global scope, albeit register_globals is disabled. PHP 4.3.0 and later will warn you, if this feature is used, and if session.bug_compat_warn is also enabled.
PHP versions 4.2.0 and lower have an undocumented feature/bug that allows you to to initialize a session variable in the global scope, albeit register_globals is disabled. PHP 4.3.0 and later will warn you, if this feature is used by enabling both session.bug_compat_42 and session.bug_compat_warn.
session.hash_function allows you to specify the hash algorithm used to generate the session IDs. '0' means MD5 (128 bits) and '1' means SHA-1 (160 bits).
Óçìåßùóç: This was introduced in PHP 5.
session.hash_bits_per_character allows you to define how many bits are stored in each character when converting the binary hash data to something readable. The possible values are '4' (0-9, a-f), '5' (0-9, a-v), and '6' (0-9, a-z, A-Z, "-", ",").
Óçìåßùóç: This was introduced in PHP 5.
url_rewriter.tags specifies which HTML tags are rewritten to include session id if transparent sid support is enabled. Defaults to a=href,area=href,frame=src,input=src,form=fakeentry,fieldset=
Óçìåßùóç: If you want XHTML conformity, remove the form entry and use the <fieldset> tags around your form fields.
The track_vars and register_globals configuration settings influence how the session variables get stored and restored.
Óçìåßùóç: As of PHP 4.0.3, track_vars is always turned on.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Constant containing either the session name and session ID in the form of "name=ID" or empty string if session ID was set in an appropriate session cookie.
Óçìåßùóç: As of PHP 4.1.0, $_SESSION is available as a global variable just like $_POST, $_GET, $_REQUEST and so on. Unlike $HTTP_SESSION_VARS, $_SESSION is always global. Therefore, you do not need to use the global keyword for $_SESSION. Please note that this documentation has been changed to use $_SESSION everywhere. You can substitute $HTTP_SESSION_VARS for $_SESSION, if you prefer the former. Also note that you must start your session using session_start() before use of $_SESSION becomes available.
The keys in the $_SESSION associative array are subject to the same limitations as regular variable names in PHP, i.e. they cannot start with a number and must start with a letter or underscore. For more details see the section on variables in this manual.
If register_globals is disabled, only members of the global associative array $_SESSION can be registered as session variables. The restored session variables will only be available in the array $_SESSION.
Use of $_SESSION (or $HTTP_SESSION_VARS with PHP 4.0.6 or less) is recommended for improved security and code readability. With $_SESSION, there is no need to use the session_register(), session_unregister(), session_is_registered() functions. Session variables are accessible like any other variables.
ÐáñÜäåéãìá 2. Unregistering a variable with $_SESSION and register_globals disabled.
|
Ðñïóï÷Þ |
Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal. |
ÐáñÜäåéãìá 3. Unregistering a variable with register_globals enabled, after registering it using $_SESSION.
|
If register_globals is enabled, then each global variable can be registered as session variable. Upon a restart of a session, these variables will be restored to corresponding global variables. Since PHP must know which global variables are registered as session variables, users need to register variables with session_register() function. You can avoid this by simply setting entries in $_SESSION.
Ðñïóï÷Þ |
If you are using $_SESSION and disable register_globals, do not use session_register(), session_is_registered() and session_unregister(), if your scripts shall work in PHP 4.2 and earlier. You can use these functions in 4.3 and later. If you enable register_globals, session_unregister() should be used since session variables are registered as global variables when session data is deserialized. Disabling register_globals is recommended for both security and performance reasons. |
ÐáñÜäåéãìá 4. Registering a variable with register_globals enabled
|
If register_globals is enabled, then the global variables and the $_SESSION entries will automatically reference the same values which were registered in the prior session instance.
There is a defect in PHP 4.2.3 and earlier. If you register a new session variable by using session_register(), the entry in the global scope and the $_SESSION entry will not reference the same value until the next session_start(). I.e. a modification to the newly registered global variable will not be reflected by the $_SESSION entry. This has been corrected in PHP 4.3.
There are two methods to propagate a session id:
Cookies
URL parameter
The session module supports both methods. Cookies are optimal, but because they are not always available, we also provide an alternative way. The second method embeds the session id directly into URLs.
PHP is capable of transforming links transparently. Unless you are using PHP 4.2 or later, you need to enable it manually when building PHP. Under Unix, pass --enable-trans-sid to configure. If this build option and the run-time option session.use_trans_sid are enabled, relative URIs will be changed to contain the session id automatically.
Óçìåßùóç: The arg_separator.output php.ini directive allows to customize the argument seperator. For full XHTML conformance, specify & there.
Alternatively, you can use the constant SID which is always defined. If the client did not send an appropriate session cookie, it has the form session_name=session_id. Otherwise, it expands to an empty string. Thus, you can embed it unconditionally into URLs.
The following example demonstrates how to register a variable, and how to link correctly to another page using SID.
ÐáñÜäåéãìá 5. Counting the number of hits of a single user
|
The strip_tags() is used when printing the SID in order to prevent XSS related attacks.
Printing the SID, like shown above, is not necessary if --enable-trans-sid was used to compile PHP.
Óçìåßùóç: Non-relative URLs are assumed to point to external sites and hence don't append the SID, as it would be a security risk to leak the SID to a different server.
To implement database storage, or any other storage method, you will need to use session_set_save_handler() to create a set of user-level storage functions.
session_cache_expire() returns the current setting of session.cache_expire. The value returned should be read in minutes, defaults to 180. If new_cache_expire is given, the current cache expire is replaced with new_cache_expire.
The cache expire is reset to the default value of 180 stored in session.cache_limiter at request startup time. Thus, you need to call session_cache_expire() for every request (and before session_start() is called).
ÐáñÜäåéãìá 1. session_cache_expire() example
|
Óçìåßùóç: Setting new_cache_expire is of value only, if session.cache_limiter is set to a value different from nocache.
See also the configuration settings session.cache_expire, session.cache_limiter and session_cache_limiter().
session_cache_limiter() returns the name of the current cache limiter. If cache_limiter is specified, the name of the current cache limiter is changed to the new value.
The cache limiter defines which cache control HTTP headers are sent to the client. These headers determine the rules by which the page content may be cached by the client and intermediate proxies. Setting the cache limiter to nocache disallows any client/proxy caching. A value of public permits caching by proxies and the client, whereas private disallows caching by proxies and permits the client to cache the contents.
In private mode, the Expire header sent to the client may cause confusion for some browsers, including Mozilla. You can avoid this problem by using private_no_expire mode. The expire header is never sent to the client in this mode.
Óçìåßùóç: private_no_expire was added in PHP 4.2.0.
The cache limiter is reset to the default value stored in session.cache_limiter at request startup time. Thus, you need to call session_cache_limiter() for every request (and before session_start() is called).
Also see the session.cache_limiter configuration directive.
session_decode() decodes the session data in data, setting variables stored in the session.
See also session_encode().
session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.
This function returns TRUE on success and FALSE on failure to destroy the session data.
session_encode() returns a string with the contents of the current session encoded within.
See also session_decode()
The session_get_cookie_params() function returns an array with the current session cookie information, the array contains the following items:
"lifetime" - The lifetime of the cookie in seconds.
"path" - The path where information is stored.
"domain" - The domain of the cookie.
"secure" - The cookie should only be sent over secure connections. (This item was added in PHP 4.0.4.)
See also the configuration directives session.cookie_lifetime, session.cookie_path, session.cookie_domain, session.cookie_secure, and session_set_cookie_params().
session_id() returns the session id for the current session.
If id is specified, it will replace the current session id. session_id() needs to be called before session_start() for that purpose. Depending on the session handler, not all characters are allowed within the session id. For example, the file session handler only allows characters in the range a-z, A-Z and 0-9!
Óçìåßùóç: When using session cookies, specifying an id for session_id() will always send a new cookie when session_start() is called, regardless if the current session id is identical to the one being set.
The constant SID can also be used to retrieve the current name and session id as a string suitable for adding to URLs. Note that SID is only defined if the client didn't send the right cookie. See also Session handling.
See also session_start(), session_set_save_handler(), and session.save_handler.
(PHP 4 , PHP 5)
session_is_registered -- Find out whether a global variable is registered in a sessionsession_is_registered() returns TRUE if there is a global variable with the name name registered in the current session.
Óçìåßùóç: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use isset() to check a variable is registered in $_SESSION.
Ðñïóï÷Þ |
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). |
session_module_name() returns the name of the current session module. If module is specified, that module will be used instead.
session_name() returns the name of the current session. If name is specified, the name of the current session is changed to its value.
The session name references the session id in cookies and URLs. It should contain only alphanumeric characters; it should be short and descriptive (i.e. for users with enabled cookie warnings). The session name is reset to the default value stored in session.name at request startup time. Thus, you need to call session_name() for every request (and before session_start() or session_register() are called).
See also the session.name configuration directive.
(PHP 4 >= 4.3.2, PHP 5)
session_regenerate_id -- Update the current session id with a newly generated onesession_regenerate_id() will replace the current session id with a new one, and keep the current session information.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: As of PHP 4.3.3, if session cookies are enabled, use of session_regenerate_id() will also submit a new session cookie with the new session id.
See also session_id(), session_start(), and session_name().
session_register() accepts a variable number of arguments, any of which can be either a string holding the name of a variable or an array consisting of variable names or other arrays. For each name, session_register() registers the global variable with that name in the current session.
Ðñïóï÷Þ |
If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled. |
register_globals: óçìáíôéêÞ óçìåßùóç: Áðü ôçí PHP 4.2.0, ç ðñïåðéëåãìÝíç ôéìÞ ãéá ôï PHP directive register_globals åßíáé off. Ç êïéíüôçôá ôçò PHP åíèáññýíåé üëïõò íá ìçí âáóßæïíôáé óå áõôü ôï directive (åíôïëÞ, ïäçãßá) áëëÜ óôç èÝóç ôïõ óå Üëëá ìÝóá, üðùò ôï superglobals.
Ðñïóï÷Þ |
This registers a global variable. If you want to register a session variable from within a function, you need to make sure to make it global using the global keyword or the $GLOBALS[] array, or use the special session arrays as noted below. |
Ðñïóï÷Þ |
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister(). |
This function returns TRUE when all of the variables are successfully registered with the session.
If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made. $_SESSION does not mimic this behavior and requires session_start() before use.
You can also create a session variable by simply setting the appropriate member of the $_SESSION or $HTTP_SESSION_VARS (PHP < 4.1.0) array.
<?php // Use of session_register() is deprecated $barney = "A big purple dinosaur."; session_register("barney"); // Use of $_SESSION is preferred, as of PHP 4.1.0 $_SESSION["zim"] = "An invader from another planet."; // The old way was to use $HTTP_SESSION_VARS $HTTP_SESSION_VARS["spongebob"] = "He's got square pants."; ?> |
Óçìåßùóç: It is currently impossible to register resource variables in a session. For example, you cannot create a connection to a database and store the connection id as a session variable and expect the connection to still be valid the next time the session is restored. PHP functions that return a resource are identified by having a return type of resource in their function definition. A list of functions that return resources are available in the resource types appendix.
If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, assign values to $_SESSION. For example: $_SESSION['var'] = 'ABC';
See also session_is_registered(), session_unregister(), and $_SESSION.
session_save_path() returns the path of the current directory used to save session data. If path is specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose.
Óçìåßùóç: On some operating systems, you may want to specify a path on a filesystem that handles lots of small files efficiently. For example, on Linux, reiserfs may provide better performance than ext2fs.
See also the session.save_path configuration directive.
Set cookie parameters defined in the php.ini file. The effect of this function only lasts for the duration of the script. Thus, you need to call session_set_cookie_params() for every request and before session_start() is called.
Óçìåßùóç: The secure parameter was added in PHP 4.0.4.
See also the configuration directives session.cookie_lifetime, session.cookie_path, session.cookie_domain, session.cookie_secure, and session_get_cookie_params().
session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The "write" handler is not executed until after the output stream is closed. Thus, output from debugging statements in the "write" handler will never be seen in the browser. If debugging output is necessary, it is suggested that the debug output be written to a file instead.
Óçìåßùóç: The write handler is not executed if the session contains no data; this applies even if empty session variables are registered. This differs to the default file-based session save handler, which creates empty session files.
The following example provides file based session storage similar to the PHP sessions default save handler files. This example could easily be extended to cover database storage using your favorite PHP supported database engine.
Read function must return string value always to make save handler work as expected. Return empty string if there is no data to read. Return values from other handlers are converted to boolean expression. TRUE for success, FALSE for failure.
ÐáñÜäåéãìá 1. session_set_save_handler() example
|
See also the session.save_handler configuration directive.
session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.
This function always returns TRUE.
Óçìåßùóç: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.
ÐáñÜäåéãìá 1. A session example: page1.php
|
After viewing page1.php, the second page page2.php will magically contain the session data. Read the session reference for information on propagating session ids as it, for example, explains what the constant SID is all about.
ÐáñÜäåéãìá 2. A session example: page2.php
|
If you want to use a named session, you must call session_name() before calling session_start().
session_start() will register internal output handler for URL rewriting when trans-sid is enabled. If a user uses ob_gzhandler or like with ob_start(), the order of output handler is important for proper output. For example, user must register ob_gzhandler before session start.
Óçìåßùóç: Use of zlib.output_compression is recommended rather than ob_gzhandler()
Óçìåßùóç: As of PHP 4.3.3, calling session_start() while the session has already been started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored.
See also $_SESSION, session.auto_start, and session_id().
session_unregister() unregisters the global variable named name from the current session.
This function returns TRUE when the variable is successfully unregistered from the session.
Óçìåßùóç: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable. Do not unset() $_SESSION itself as this will disable the special function of the $_SESSION superglobal.
Ðñïóï÷Þ |
This function does not unset the corresponding global variable for name, it only prevents the variable from being saved as part of the session. You must call unset() to remove the corresponding global variable. |
Ðñïóï÷Þ |
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). |
The session_unset() function frees all session variables currently registered.
Óçìåßùóç: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable, i.e. unset ($_SESSION['varname']);.
Ðñïóï÷Þ |
Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal. |
End the current session and store session data.
Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.
Shmop is an easy to use set of functions that allows PHP to read, write, create and delete Unix shared memory segments.
Óçìåßùóç: Versions of Windows previous to Windows 2000 do not support shared memory. Under Windows, Shmop will only work when PHP is running as a web server module, such as Apache or IIS (CLI and CGI will not work).
Óçìåßùóç: In PHP 4.0.3, these functions were prefixed by shm rather than shmop.
To use shmop you will need to compile PHP with the --enable-shmop parameter in your configure line.
ÐáñÜäåéãìá 1. Shared Memory Operations Overview
|
shmop_close() is used to close a shared memory block.
shmop_close() takes the shmid, which is the shared memory block identifier created by shmop_open().
This example will close shared memory block identified by $shm_id.
shmop_delete() is used to delete a shared memory block.
shmop_delete() takes the shmid, which is the shared memory block identifier created by shmop_open(). On success 1 is returned, on failure 0 is returned.
This example will delete shared memory block identified by $shm_id.
shmop_open() can create or open a shared memory block.
shmop_open() takes 4 parameters: key, which is the system's id for the shared memory block, this parameter can be passed as a decimal or hex. The second parameter are the flags that you can use:
"a" for access (sets SHM_RDONLY for shmat) use this flag when you need to open an existing shared memory segment for read only
"c" for create (sets IPC_CREATE) use this flag when you need to create a new shared memory segment or if a segment with the same key exists, try to open it for read and write
"w" for read & write access use this flag when you need to read and write to a shared memory segment, use this flag in most cases.
"n" create a new memory segment (sets IPC_CREATE|IPC_EXCL) use this flag when you want to create a new shared memory segment but if one already exists with the same flag, fail. This is useful for security purposes, using this you can prevent race condition exploits.
Óçìåßùóç: Note: the 3rd and 4th should be entered as 0 if you are opening an existing memory segment. On success shmop_open() will return an id that you can use to access the shared memory segment you've created.
This example opened a shared memory block with a system id returned by ftok().
shmop_read() will read a string from shared memory block.
shmop_read() takes 3 parameters: shmid, which is the shared memory block identifier created by shmop_open(), offset from which to start reading and count on the number of bytes to read.
This example will read 50 bytes from shared memory block and place the data inside $shm_data.
shmop_size() is used to get the size, in bytes of the shared memory block.
shmop_size() takes the shmid, which is the shared memory block identifier created by shmop_open(), the function will return and int, which represents the number of bytes the shared memory block occupies.
This example will put the size of shared memory block identified by $shm_id into $shm_size.
shmop_write() will write a string into shared memory block.
shmop_write() takes 3 parameters: shmid, which is the shared memory block identifier created by shmop_open(), data, a string that you want to write into shared memory block and offset, which specifies where to start writing data inside the shared memory segment.
This example will write data inside $my_string into shared memory block, $shm_bytes_written will contain the number of bytes written.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.
This extension is only available if PHP was configured with --enable-simplexml. The PHP configuration script does this by default.
Many examples in this reference require an XML string. Instead of repeating this string in every example, we put it into a file which we include in each example. This included file is shown in the following example section. Alternatively, you could create an XML document and read it with simplexml_load_file().
ÐáñÜäåéãìá 1. Include file example.php with XML string
|
The simplicity of SimpleXML appears most clearly when one extracts a string or number from a basic XML document.
ÐáñÜäåéãìá 3. Accessing non-unique elements in SimpleXML When multiple instances of an element exist as children of a single parent element, normal iteration techniques apply.
|
ÐáñÜäåéãìá 4. Using attributes So far, we have only covered the work of reading element names and their values. SimpleXML can also access element attributes. Access attributes of an element just as you would elements of an array.
|
ÐáñÜäåéãìá 5. Comparing Elements and Attributes with Text To compare an element or attribute with a string or pass it into a function that requires a string, you must cast it to a string using (string). Otherwise, PHP treats the element as an object.
|
ÐáñÜäåéãìá 6. Using Xpath SimpleXML includes builtin Xpath support. To find all <character> elements:
'//' serves as a wildcard. To specify absolute paths, omit one of the slashes. |
ÐáñÜäåéãìá 7. Setting values Data in SimpleXML doesn't have to be constant. The object allows for manipulation of all of its elements.
The above code will output a new XML document, just like the original, except that the new XML will define Ms. Coder's age as 21. |
ÐáñÜäåéãìá 8. DOM Interoperability PHP has a mechanism to convert XML nodes between SimpleXML and DOM formats. This example shows how one might change a DOM element to SimpleXML.
|
(no version information, might be only in CVS)
simplexml_element->asXML -- Return a well-formed XML string based on SimpleXML element.The asXML method formats the parent object's data in XML version 1.0.
asXML also works on Xpath results:
ÐáñÜäåéãìá 2. Using asXML() on Xpath results
|
(no version information, might be only in CVS)
simplexml_element->attributes -- Identifies an element's attributes.This function provides the attributes and values defined within an xml tag.
Óçìåßùóç: SimpleXML has made a rule of adding iterative properties to most methods. They cannot be viewed using var_dump() or anything else which can examine objects.
(no version information, might be only in CVS)
simplexml_element->children -- Finds children of given node.This method finds the children of the element of which it is a member. The result follows normal iteration rules.
Óçìåßùóç: SimpleXML has made a rule of adding iterative properties to most methods. They cannot be viewed using var_dump() or anything else which can examine objects.
ÐáñÜäåéãìá 1. Traversing a children() pseudo-array
This script will output:
|
(no version information, might be only in CVS)
simplexml_element->xpath -- Runs Xpath query on XML data.The xpath method searches the SimpleXML node for children matching the Xpath path. It always returns an array of simplexml_element objects.
ÐáñÜäåéãìá 1. Xpath
This script will display:
Notice that the two results are equal. |
This function takes a node of a DOM document and makes it into a SimpleXML node. This new object can then be used as a native SimpleXML element. If any errors occur, it returns FALSE.
This function will convert the well-formed XML document in the file specified by filename to an object of class simplexml_element. If any errors occur during file access or interpretation, the function returns FALSE.
ÐáñÜäåéãìá 1. Interpret an XML document
This script will display, on success:
At this point, you can go about using $xml->title and any other elements. |
See also: simplexml_load_string()
This function will take the well-formed xml string data and return an object with properties containing the data held within the xml document. If any errors occur, it returns FALSE.
ÐáñÜäåéãìá 1. Interpret an XML string
This script will display:
At this point, you can go about using $xml->body and such. |
See also: simplexml_load_file().
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
The SOAP extension can be used to write SOAP Servers and Clients. It supports subsets of SOAP 1.1, SOAP 1.2 and WSDL 1.1 specifications.
This extension makes use of the GNOME xml library. Download and install this library. You will need at least libxml-2.5.4.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. SOAP Configuration Options
Name | Default | Changeable |
---|---|---|
soap.wsdl_cache_enabled | "1" | PHP_INI_ALL |
soap.wsdl_cache_dir | "/tmp" | PHP_INI_ALL |
soap.wsdl_cache_ttl | 86400 | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
This constructor allows creating SoapClient objects in WSDL or non-WSDL mode. The first case requires the URI of WSDL file as the first parameter and an optional options array. The second case requires NULL as the first parameter and the options array with location and uri options set, where location is a URL to request and uri is a target namespace of the SOAP service.
The style and use options only work in non-WSDL mode. In WSDL mode, they comes from the WSDL file.
The soap_version option specifies whether to use SOAP 1.1, or SOAP 1.2 client.
For HTTP authentication, you may use the login and password options. For making a HTTP connection through a proxy server, use the options proxy_host, proxy_port, proxy_login and proxy_password.
ÐáñÜäåéãìá 1. SoapClient examples
|
This is a low level API function to make a SOAP call. Usually in WSDL mode you can simply call SOAP functions as SoapClient methods. It is useful for non-WSDL mode when soapaction is unknown, uri differs from the default or when you like to send and/or receive SOAP Headers. On error, a call to a SOAP function can cause PHP exceptions or return a SoapFault object if exceptions was disabled. To check if the function call failed catch the SoapFault exceptions or check the result with the is_soap_fault() function.
SOAP functions may return one or several values. In the first case it will return just the value of output parameter, in the second it will return the associative array with named output parameters.
ÐáñÜäåéãìá 1. SoapClient::__call() examples
|
See also SoapClient::SoapClient(), SoapParam::SoapParam(), SoapVar::SoapVar(), SoapHeader::SoapHeader(), SoapFault::SoapFault(), and is_soap_fault().
(no version information, might be only in CVS)
SoapClient::__getFunctions -- Returns list of SOAP functionsThis function works only in WSDL mode.
See also SoapClient::SoapClient().
(no version information, might be only in CVS)
SoapClient::__getLastRequest -- Returns last SOAP requestThis function works only with SoapClient which was created with the trace option.
See also SoapClient::SoapClient().
(no version information, might be only in CVS)
SoapClient::__getLastResponse -- Returns last SOAP responseThis function works only with SoapClient which was created with the trace option.
See also SoapClient::SoapClient().
This function works only in WSDL mode.
See also SoapClient::SoapClient().
This class is useful when you would like to send SOAP fault responses from the PHP handler. faultcode, faultstring, faultactor and details are standard elements of SOAP Fault; faultname is an optional parameter that can be used to select proper fault encoding from WSDL; headerfault is an optional parameter that can be used during SOAP header handling to report an error in the response header.
It is possible to use PHP exception mechanism to throw SOAP Fault.
See also SoapClient::SoapClient(), SoapClient::__call(), SoapParam::SoapParam(), SoapVar::SoapVar(), and is_soap_fault().
SoapHeader is a special low-level class for passing or returning SOAP headers. It is just a data holder and it does not have any special methods except a constructor. It can be used in the SoapClient::__call() method to pass a SOAP header or in a SOAP header handler to return the header in a SOAP response. namespace and name are namespace and name of the SOAP header element. data is a SOAP header's content. It can be a PHP value or SoapVar object. mustUnderstand and actor are values for mustUnderstand and actor attributes of this SOAP Header element.
See also SoapClient::__call(), SoapParam::SoapParam(), and SoapVar::SoapVar().
SoapParam is a special low-level class for naming parameters and return ing values in non-WSDL mode. It is just a data holder and it does not have any special methods except the constructor. The constructor takes data to pass or return and name. It is possible to pass parameters directly as PHP values, but in this case it will be named as paramN and the SOAP Service may not understand them.
See also SoapClient::__call(), and SoapVar::SoapVar().
This constuctor allows the creatiion of SoapServer objects in WSDL or non-WSDL mode. In the first case, wsdl must be set to the URI of a WSDL file. In the second case, wsdl must be set to NULL and the uri option must be set. Additional options allow setting a default SOAP version (soap_version) and actor URI (actor).
ÐáñÜäåéãìá 1. Some examples
|
(no version information, might be only in CVS)
SoapServer::addFunction -- Adds one or several functions those will handle SOAP requestsExports one or more functions for remote clients.
To export one function, pass the function name into the functions parameter as a string. To export several functions pass an array of function names, and to export all functions pass a special constant SOAP_FUNCTIONS_ALL.
functions must receive all input arguments in the same order as defined in the WSDL file (They should not receive any output parameters as arguments) and return one or more values. To return several values they must return an array with named output parameters.
ÐáñÜäåéãìá 1. Some examples
|
See also SoapServer::SoapServer(), and SoapServer::SetClass().
(no version information, might be only in CVS)
SoapServer::getFunctions -- Returns list of defined functionsThis functions returns the list of all functions which was added by SoapServer::addFunction() or SoapServer::setCalss().
ÐáñÜäåéãìá 1. Some examples
|
See also SoapServer::SoapServer(), SoapServer::addFunction(), and SoapServer::SetClass().
Processes a SOAP request, calls necessary functions, and sends a response back. It assumes a request in input parameter soap_request or in the global $HTTP_RAW_POST_DATA PHP variable if the argument is omitted.
See also SoapServer::SoapServer().
(no version information, might be only in CVS)
SoapServer::setClass -- Sets class which will handle SOAP requestsExports all methods from specified class. Additional parameters args will be passed to the default class constructor during object creation. The object can be made persistent across request for a given PHP session with the SoapServer::setPersistence() method.
See also SoapServer::SoapServer(), SoapServer::addFunction(), and SoapServer::setPersistence().
(no version information, might be only in CVS)
SoapServer::setPersistence -- Sets persistence mode of SoapServerThis function allows saving data between requests in a PHP session. It works only with a server that exports functions from a class with SoapServer::setClass().
See also SoapServer::SoapServer(), and SoapServer::SetClass().
SoapVar is a special low-level class for encoding parameters and returning values in non-WSDL mode. It is just a data holder and does not have any special methods except the constructor. It is useful when you would like to set the type property in SOAP request or response. The constructor takes data to pass or return, encoding ID to encode it (see XSD_... constants) and as option type name and namespace and XML node name and namespace.
ÐáñÜäåéãìá 1. Some examples
|
See also SoapClient::__call() and SoapParam::SoapParam().
This function is useful when you like to check if the SOAP call failed, but don't like to use exceptions. To use it you must create a SoapClient object with exceptions option set to zero or FALSE. In this case, the SOAP method will return a special SoapFault object which encapsulates the fault details (faultcode, faultstring, faultactor and faultdetails).
If exceptions is not set then SOAP call will throw an exception on error. is_soap_fault() checks if the given parameter is a SoapFault object.
See also SoapClient::SoapClient(), and SoapFault::SoapFault().
This is an extension for the SQLite Embeddable SQL Database Engine. SQLite is a C library that implements an embeddable SQL database engine. Programs that link with the SQLite library can have SQL database access without running a separate RDBMS process.
SQLite is not a client library used to connect to a big database server. SQLite is the server. The SQLite library reads and writes directly to and from the database files on disk.
Óçìåßùóç: For further information see the SQLite Website (http://sqlite.org/).
Read the INSTALL file, which comes with the package. Or just use the PEAR installer with "pear install sqlite". SQLite itself is already included, You do not need to install any additional software.
Windows users may download the DLL version of the SQLite extension here: (php_sqlite.dll).
In PHP 5, the SQLite extension and the engine itself are bundled and compilled by default.
In order to have these functions available, you must compile PHP with SQLite support, or load the SQLite extension dynamically from your php.ini.
There are two resources used in the SQLite Interface. The first one is the database connection, the second one the result set.
The functions sqlite_fetch_array() and sqlite_current() use a constant for the different types of result arrays. The following constants are defined:
Ðßíáêáò 1. SQLite fetch constants
constant | meaning |
---|---|
SQLITE_ASSOC | Columns are returned into the array having the fieldname as the array index. |
SQLITE_BOTH | Columns are returned into the array having both a numerical index and the fieldname as the array index. |
SQLITE_NUM | Columns are returned into the array having a numerical index to the fields. This index starts with 0, the first field in the result. |
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
For further details and definition of the PHP_INI_* constants see ini_set().
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to use mixed case (0), upper case (1) or lower case (2) hash indexes.
This option is primarily useful when you need compatibility with other database systems, where the names of the columns are always returned as uppercase or lowercase, regardless of the case of the actual field names in the database schema.
The SQLite library returns the column names in their natural case (that matches the case you used in your schema). When sqlite.assoc_case is set to 0 the natural case will be preserved. When it is set to 1 or 2, PHP will apply case folding on the hash keys to upper- or lower-case the keys, respectively.
Use of this option incurs a slight performance penalty, but is MUCH faster than performing the case folding yourself using PHP script.
sqlite_array_query() is similar to calling sqlite_query() and then sqlite_fetch_array() for each row of the result set and storing it into an array, as shown in the example below. Calling sqlite_array_query() is significantly faster than using such a script.
Õðüäåéîç: sqlite_array_query() is best suited to queries returning 45 rows or less. If you have more data than that, it is recommended that you write your scripts to use sqlite_unbuffered_query() instead for more optimal performance.
See also sqlite_query(), sqlite_fetch_array(), and sqlite_fetch_string().
Set the maximum time that sqlite will wait for a dbhandle to become ready for use to milliseconds. If milliseconds is 0, busy handlers will be disabled and sqlite will return immediately with a SQLITE_BUSY status code if another process/thread has the database locked for an update.
PHP sets the default busy timeout to be 60 seconds when the database is opened.
Óçìåßùóç: There are one thousand (1000) milliseconds in one second.
See also sqlite_open().
(PHP 5)
sqlite_changes -- Returns the number of rows that were changed by the most recent SQL statement.Returns the numbers of rows that were changed by the most recent SQL statement executed against the dbhandle database handle.
See also sqlite_num_rows().
Closes the given database handle. If the database was persistent, it will be closed and removed from the persistent list.
See also sqlite_open() and sqlite_popen().
Fetches the value of a column named index_or_name (if it is a string), or of the ordinal column numbered index_or_name (if it is an integer) from the current row of the query result handle result. The decode binary flag operates in the same way as described under sqlite_fetch_array().
Use this function when you are iterating a large result set with many columns, or with columns that contain large amounts of data.
See also sqlite_fetch_string().
sqlite_create_aggregate() is similar to sqlite_create_function() except that it registers functions that can be used to calculate a result aggregated across all the rows of a query.
The key difference between this function and sqlite_create_function() is that two functions are required to manage the aggregate; step_func is called for each row of the result set. Your PHP function should accumulate the result and store it into the aggregation context. Once all the rows have been processed, finalize_func will be called and it should then take the data from the aggregation context and return the result.
ÐáñÜäåéãìá 1. max_length aggregation function example
|
In this example, we are creating an aggregating function that will calculate the length of the longest string in one of the columns of the table. For each row, the max_len_step function is called and passed a context parameter. The context parameter is just like any other PHP variable and be set to hold an array or even an object value. In this example, we are simply using it to hold the maximum length we have seen so far; if the string has a length longer than the current maximum, we update the context to hold this new maximum length.
After all of the rows have been processed, SQLite calls the max_len_finalize function to determine the aggregate result. Here, we could perform some kind of calculation based on the data found in the context. In our simple example though, we have been calculating the result as the query progressed, so we simply need to return the context value.
Óçìåßùóç: The example above will not work correctly if the column contains binary data. Take a look at the manual page for sqlite_udf_decode_binary() for an explanation of why this is so, and an example of how to make it respect the binary encoding.
Õðüäåéîç: It is NOT recommended for you to store a copy of the values in the context and then process them at the end, as you would cause SQLite to use a lot of memory to process the query - just think of how much memory you would need if a million rows were stored in memory, each containing a string 32 bytes in length.
Õðüäåéîç: You can use sqlite_create_function() and sqlite_create_aggregate() to override SQLite native SQL functions.
See also sqlite_create_function(), sqlite_udf_encode_binary() and sqlite_udf_decode_binary().
(PHP 5)
sqlite_create_function -- Registers a "regular" User Defined Function for use in SQL statements.sqlite_create_function() allows you to register a PHP function with SQLite as an UDF (User Defined Function), so that it can be called from within your SQL statements.
dbhandle specifies the database handle that you wish to extend, function_name specifies the name of the function that you will use in your SQL statements, callback is any valid PHP callback to specify a PHP function that should be called to handle the SQL function. The optional parameter num_args is used as a hint by the SQLite expression parser/evaluator. It is recommended that you specify a value if your function will only ever accept a fixed number of parameters.
The UDF can be used in any SQL statement that can call functions, such as SELECT and UPDATE statements and also in triggers.
ÐáñÜäåéãìá 1. sqlite_create_function() example
|
In this example, we have a function that calculates the md5 sum of a string, and then reverses it. When the SQL statement executes, it returns the value of the filename transformed by our function. The data returned in $rows contains the processed result.
The beauty of this technique is that you do not need to process the result using a foreach() loop after you have queried for the data.
PHP registers a special function named php when the database is first opened. The php function can be used to call any PHP function without having to register it first.
ÐáñÜäåéãìá 2. Example of using the PHP function
This example will call the md5() on each filename column in the database and return the result into $rows |
Óçìåßùóç: For performance reasons, PHP will not automatically encode/decode binary data passed to and from your UDF's. You need to manually encode/decode the parameters and return values if you need to process binary data in this way. Take a look at sqlite_udf_encode_binary() and sqlite_udf_decode_binary() for more details.
Õðüäåéîç: It is not recommended to use UDF's to handle processing of binary data, unless high performance is not a key requirement of your application.
Õðüäåéîç: You can use sqlite_create_function() and sqlite_create_aggregate() to override SQLite native SQL functions.
See also sqlite_create_aggregate().
sqlite_current() is identical to sqlite_fetch_array() except that it does not advance to the next row prior to returning the data; it returns the data from the current position only.
If the current position is beyond the final row, this function returns FALSE
Óçìåßùóç: This function will not work on unbuffered result handles.
See also sqlite_seek(), sqlite_next(), and sqlite_fetch_array().
Returns a human readable description of the error_code returned from sqlite_last_error().
See also sqlite_last_error().
sqlite_escape_string() will correctly quote the string specified by item for use in an SQLite SQL statement. This includes doubling up single-quote characters (') and checking for binary-unsafe characters in the query string.
If the item contains a NUL character, or if it begins with a character whose ordinal value is 0x01, PHP will apply a binary encoding scheme so that you can safely store and retrieve binary data.
Although the encoding makes it safe to insert the data, it will render simple text comparisons and LIKE clauses in your queries unusable for the columns that contain the binary data. In practice, this shouldn't be a problem, as your schema should be such that you don't use such things on binary columns (in fact, it might be better to store binary data using other means, such as in files).
Ðñïåéäïðïßçóç |
addslashes() should NOT be used to quote your strings for SQLite queries; it will lead to strange results when retrieving your data. |
Óçìåßùóç: Do not use this function to encode the return values from UDF's created using sqlite_create_function() or sqlite_create_aggregate() - use sqlite_udf_encode_binary() instead.
See also sqlite_udf_encode_binary().
(no version information, might be only in CVS)
sqlite_exec -- Executes a result-less query against a given database.Executes an SQL statement given by the query against a given database handle (specified by the dbhandle parameter).
This function will return a boolean result; TRUE for success or FALSE for failure. If you need to run a query that returns rows, see sqlite_query().
Óçìåßùóç: Two alternative syntaxes are supported for compatibility with other database extensions (such as MySQL). The preferred form is the first one, where the db parameter is the first parameter to the function.
Ðñïåéäïðïßçóç |
SQLite will execute multiple queries separated by semicolons, so you can use it to execute a batch of SQL that you have loaded from a file or have embedded in a script. |
See also sqlite_query(), sqlite_unbuffered_query() and sqlite_array_query().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Fetches the next row from the given result handle. If there are no more rows, returns FALSE, otherwise returns an associative array representing the row data.
result_type can be used to specify how you want the results to be returned. The default value is SQLITE_BOTH which returns columns indexed by their ordinal column number and by column name. SQLITE_ASSOC causes the array to be indexed only by column names, and SQLITE_NUM to be indexed only by ordinal column numbers.
The column names returned by SQLITE_ASSOC and SQLITE_BOTH will be case-folded according to the value of the sqlite.assoc_case configuration option.
When decode_binary is set to TRUE (the default), PHP will decode the binary encoding it applied to the data if it was encoded using the sqlite_escape_string(). You will usually always leave this value at its default, unless you are interoperating with databases created by other sqlite capable applications.
See also sqlite_array_query() and sqlite_fetch_string().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
sqlite_fetch_single() is identical to sqlite_fetch_array() except that it returns the value of the first column of the rowset.
This is the most optimal way to retrieve data when you are only interested in the values from a single column of data.
ÐáñÜäåéãìá 1. A sqlite_fetch_single() example
|
See also sqlite_fetch_array().
Given the ordinal column number, field_index, returns the name of that field in the result handle result.
sqlite_has_more() returns TRUE if there are more rows available from the result handle, or FALSE otherwise.
See also sqlite_num_rows() and sqlite_changes().
Returns the error code from the last operation performed on dbhandle, the database handle. A human readable description of the error code can be retrieved using sqlite_error_string().
See also sqlite_error_string().
Returns the rowid of the row that was most recently inserted into the database dbhandle, if it was created as an auto-increment field.
Õðüäåéîç: You can create auto-increment fields in SQLite by declaring them as INTEGER PRIMARY KEY in your table schema.
The SQLite library may be compiled in either ISO-8859-1 or UTF-8 compatible modes. This function allows you to determine which encoding scheme is used by your version of the library.
Ðñïåéäïðïßçóç |
The default PHP distribution builds libsqlite in ISO-8859-1 encoding mode. However, this is a misnomer; rather than handling ISO-8859-1, it operates according to your current locale settings for string comparisons and sort ordering. So, rather than ISO-8859-1, you should think of it as being '8-bit' instead. |
When compiled with UTF-8 support, sqlite handles encoding and decoding of UTF-8 multi-byte character sequences, but does not yet do a complete job when working with the data (no normalization is performed for example), and some comparison operations may still not be carried out correctly.
Ðñïåéäïðïßçóç |
It is not recommended that you use PHP in a web-server configuration with a version of the SQLite library compiled with UTF-8 support, since libsqlite will abort the process if it detects a problem with the UTF-8 encoding. |
See also sqlite_libversion().
Returns the version of the linked SQLite library as a string.
See also sqlite_libencoding().
sqlite_next() advances the result handle result to the next row. Returns FALSE if there are no more rows, TRUE otherwise.
Óçìåßùóç: This function cannot be used with unbuffered result handles.
See also sqlite_seek(), sqlite_current() and sqlite_rewind().
Returns the number of fields in the result set.
See also sqlite_column() and sqlite_num_rows().
Returns the number of rows in the buffered result set.
Óçìåßùóç: This function cannot be used with unbuffered result sets.
See also sqlite_changes() and sqlite_query().
Returns a resource (database handle) on success, FALSE on error.
The filename parameter is the name of the database. It can be a relative or absolute path to the file that sqlite will use to store your data. If the file does not exist, sqlite will attempt to create it. You MUST have write permissions to the file if you want to insert data or modify the database schema.
The mode parameter specifies the mode of the file and is intended to be used to open the database in read-only mode. Presently, this parameter is ignored by the sqlite library. The default value for mode is the octal value 0666 and this is the recommended value to use if you need access to the errmessage parameter.
errmessage is passed by reference and is set to hold a descriptive error message explaining why the database could not be opened if there was an error.
ÐáñÜäåéãìá 1. sqlite_open() example
|
Õðüäåéîç: On Unix platforms, SQLite is sensitive to scripts that use the fork() system call. If you do have such a script, it is recommended that you close the handle prior to forking and then re-open it in the child and/or parent. For more information on this issue, see The C language interface to the SQLite library in the section entitled Multi-Threading And SQLite.
Õðüäåéîç: It is not recommended to work with SQLite databases mounted on NFS partitions. Since NFS is notoriously bad when it comes to locking you may find that you cannot even open the database at all, and if it succeeds, the locking behaviour may be undefined.
Óçìåßùóç: Starting with SQLite library version 2.8.2, you can specify :memory: as the filename to create a database that lives only in the memory of the computer. This is useful mostly for temporary processing, as the in-memory database will be destroyed when the process ends. It can also be useful when coupled with the ATTACH DATABASE SQL statement to load other databases and move and query data between them.
Óçìåßùóç: SQLite is safe mode and open_basedir aware.
See also sqlite_popen(), sqlite_close() and sqlite_query().
(PHP 5)
sqlite_popen -- Opens a persistent handle to an SQLite database. Will create the database if it does not exist.This function behaves identically to sqlite_open() except that is uses the persistent resource mechanism of PHP. For information about the meaning of the parameters, read the sqlite_open() manual page.
sqlite_popen() will first check to see if a persistent handle has already been opened for the given filename. If it finds one, it returns that handle to your script, otherwise it opens a fresh handle to the database.
The benefit of this approach is that you don't incur the performance cost of re-reading the database and index schema on each page hit served by persistent web server SAPI's (any SAPI except for regular CGI or CLI).
Óçìåßùóç: If you use persistent handles and have the database updated by a background process (perhaps via a crontab), and that process re-creates the database by overwriting it (either by unlinking and rebuilding, or moving the updated version to replace the current version), you may experience undefined behaviour when a persistent handle on the old version of the database is recycled.
To avoid this situation, have your background processes open the same database file and perform their updates in a transaction.
See also sqlite_open(), sqlite_close() and sqlite_query().
Executes an SQL statement given by the query against a given database handle (specified by the dbhandle parameter).
For queries that return rows, this function will return a result handle which can then be used with functions such as sqlite_fetch_array() and sqlite_seek().
For other kinds of queries, this function will return a boolean result; TRUE for success or FALSE for failure.
Regardless of the query type, this function will return FALSE if the query failed.
sqlite_query() returns a buffered, seekable result handle. This is useful for reasonably small queries where you need to be able to randomly access the rows. Buffered result handles will allocate memory to hold the entire result and will not return until it has been fetched. If you only need sequential access to the data, it is recommended that you use the much higher performance sqlite_unbuffered_query() instead.
Óçìåßùóç: Two alternative syntaxes are supported for compatibility with other database extensions (such as MySQL). The preferred form is the first one, where the db parameter is the first parameter to the function.
Ðñïåéäïðïßçóç |
SQLite will execute multiple queries separated by semicolons, so you can use it to execute a batch of SQL that you have loaded from a file or have embedded in a script. However, this works only when the result of the function is not used - if it is used, only the first SQL statement would be executed. Function sqlite_exec() will always execute multiple SQL statements. When executing multiple queries, the return value of this function will be FALSE if the was an error, but undefined otherwise (it might be TRUE for success or it might return a result handle). |
See also sqlite_unbuffered_query() and sqlite_array_query().
sqlite_rewind() seeks back to the first row in the result set. Returns FALSE if there are no rows in the result set, TRUE otherwise.
Óçìåßùóç: This function cannot be used with unbuffered result sets.
See also sqlite_next(), sqlite_current(), and sqlite_seek().
sqlite_seek() seeks to the row given by the parameter rownum. The row number is zero-based (0 is the first row). Returns FALSE if the row does not exist, TRUE otherwise.
Óçìåßùóç: This function cannot be used with unbuffered result handles.
See also sqlite_next(), sqlite_current() and sqlite_rewind().
(PHP 5)
sqlite_single_query -- Executes a query and returns either an array for one single column or the value of the first rowÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
sqlite_udf_decode_binary() decodes the binary encoding that was applied to the parameter by either sqlite_udf_encode_binary() or sqlite_escape_string().
You must call this function on parameters passed to your UDF if you need them to handle binary data, as the binary encoding employed by PHP will obscure the content and of the parameter in its natural, non-coded form.
PHP does not perform this encode/decode operation automatically as it would severely impact performance if it did.
ÐáñÜäåéãìá 1. binary-safe max_length aggregation function example
|
See also sqlite_udf_encode_binary(), sqlite_create_function() and sqlite_create_aggregate().
sqlite_udf_encode_binary() applies a binary encoding to the data so that it can be safely returned from queries (since the underlying libsqlite API is not binary safe).
If there is a chance that your data might be binary unsafe (e.g.: it contains a NUL byte in the middle rather than at the end, or if it has and 0x01 byte as the first character) then you must call this function to encode the return value from your UDF.
PHP does not perform this encode/decode operation automatically as it would severely impact performance if it did.
Óçìåßùóç: Do not use sqlite_escape_string() to quote strings returned from UDF's as it will lead to double-quoting of the data. Use sqlite_udf_encode_binary() instead!
See also sqlite_udf_decode_binary(), sqlite_escape_string(), sqlite_create_function() and sqlite_create_aggregate().
sqlite_unbuffered_query() is identical to sqlite_query() except that the result that is returned is a sequential forward-only result set that can only be used to read each row, one after the other.
This function is ideal for generating things such as HTML tables where you only need to process one row at a time and don't need to randomly access the row data.
Óçìåßùóç: Functions such as sqlite_seek(), sqlite_rewind(), sqlite_next(), sqlite_current(), and sqlite_num_rows() do not work on result handles returned from sqlite_unbuffered_query().
See also sqlite_query().
PHP offers the ability to create Shockwave Flash files via Paul Haeberli's libswf module.
Óçìåßùóç: SWF support was added in PHP 4 RC2.
The libswf does not have support for Windows. The development of that library has been stopped, and the source is not available to port it to another systems.
For up to date SWF support take a look at the MING functions.
You need the libswf library to compile PHP with support for this extension. You can download libswf at ftp://ftp.sgi.com/sgi/graphics/grafica/flash/.
Once you have libswf all you need to do is to configure --with-swf[=DIR] where DIR is a location containing the directories include and lib. The include directory has to contain the swf.h file and the lib directory has to contain the libswf.a file. If you unpack the libswf distribution the two files will be in one directory. Consequently you will have to copy the files to the proper location manually.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Once you've successfully installed PHP with Shockwave Flash support you can then go about creating Shockwave files from PHP. You would be surprised at what you can do, take the following code:
ÐáñÜäåéãìá 1. SWF example
|
The swf_actiongeturl() function gets the URL specified by the parameter url with the target target.
The swf_actiongotoframe() function will go to the frame specified by framenumber, play it, and then stop.
The swf_actiongotolabel() function displays the frame with the label given by the label parameter and then stops.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
The swf_actionsettarget() function sets the context for all actions. You can use this to control other flash movies that are currently playing.
Toggle the flash movie between high and low quality.
The swf_actionwaitforframe() function will check to see if the frame, specified by the framenumber parameter has been loaded, if not it will skip the number of actions specified by the skipcount parameter. This can be useful for "Loading..." type animations.
The swf_addbuttonrecord() function allows you to define the specifics of using a button. The first parameter, states, defines what states the button can have, these can be any or all of the following constants: BSHitTest, BSDown, BSOver or BSUp. The second parameter, the shapeid is the look of the button, this is usually the object id of the shape of the button. The depth parameter is the placement of the button in the current frame.
ÐáñÜäåéãìá 1. swf_addbuttonrecord() example
|
The swf_addcolor() function sets the global add color to the rgba color specified. This color is then used (implicitly) by the swf_placeobject(), swf_modifyobject() and the swf_addbuttonrecord() functions. The color of the object will be add by the rgba values when the object is written to the screen.
Óçìåßùóç: The rgba values can be either positive or negative.
Close a file that was opened by the swf_openfile() function. If the return_file parameter is set then the contents of the SWF file are returned from the function.
ÐáñÜäåéãìá 1. Creating a simple flash file based on user input and outputting it and saving it in a database
|
The swf_definebitmap() function defines a bitmap given a GIF, JPEG, RGB or FI image. The image will be converted into a Flash JPEG or Flash color map format.
The swf_definefont() function defines a font given by the fontname parameter and gives it the id specified by the fontid parameter. It then sets the font given by fontname to the current font.
The swf_defineline() defines a line starting from the x coordinate given by x1 and the y coordinate given by y1 parameter. Up to the x coordinate given by the x2 parameter and the y coordinate given by the y2 parameter. It will have a width defined by the width parameter.
The swf_definepoly() function defines a polygon given an array of x, y coordinates (the coordinates are defined in the parameter coords). The parameter npoints is the number of overall points that are contained in the array given by coords. The width is the width of the polygon's border, if set to 0.0 the polygon is filled.
The swf_definerect() defines a rectangle with an upper left hand coordinate given by the x, x1, and the y, y1. And a lower right hand coordinate given by the x coordinate, x2, and the y coordinate, y2 . Width of the rectangles border is given by the width parameter, if the width is 0.0 then the rectangle is filled.
Define a text string (the str parameter) using the current font and font size. The docenter is where the word is centered, if docenter is 1, then the word is centered in x.
The swf_endbutton() function ends the definition of the current button.
Ends the current action started by the swf_startdoaction() function.
The swf_endshape() completes the definition of the current shape.
The swf_endsymbol() function ends the definition of a symbol that was started by the swf_startsymbol() function.
The swf_fontsize() function changes the font size to the value given by the size parameter.
Set the current font slant to the angle indicated by the slant parameter. Positive values create a forward slant, negative values create a negative slant.
Set the font tracking to the value specified by the tracking parameter. This function is used to increase the spacing between letters and text, positive values increase the space and negative values decrease the space between letters.
The swf_getbitmapinfo() function returns an array of information about a bitmap given by the bitmapid parameter. The returned array has the following elements:
"size" - The size in bytes of the bitmap.
"width" - The width in pixels of the bitmap.
"height" - The height in pixels of the bitmap.
The swf_getfontinfo() function returns an associative array with the following parameters:
Aheight - The height in pixels of a capital A.
xheight - The height in pixels of a lowercase x.
The swf_getframe() function gets the number of the current frame.
Label the current frame with the name given by the name parameter.
The swf_lookat() function defines a viewing transformation by giving the viewing position (the parameters view_x, view_y, and view_z) and the coordinates of a reference point in the scene, the reference point is defined by the reference_x, reference_y , and reference_z parameters. The twist controls the rotation along with viewer's z axis.
Updates the position and/or color of the object at the specified depth, depth. The parameter how determines what is updated. how can either be the constant MOD_MATRIX or MOD_COLOR or it can be a combination of both (MOD_MATRIX|MOD_COLOR).
MOD_COLOR uses the current mulcolor (specified by the function swf_mulcolor()) and addcolor (specified by the function swf_addcolor()) to color the object. MOD_MATRIX uses the current matrix to position the object.
The swf_mulcolor() function sets the global multiply color to the rgba color specified. This color is then used (implicitly) by the swf_placeobject(), swf_modifyobject() and the swf_addbuttonrecord() functions. The color of the object will be multiplied by the rgba values when the object is written to the screen.
Óçìåßùóç: The rgba values can be either positive or negative.
The swf_oncondition() function describes a transition that will trigger an action list. There are several types of possible transitions, the following are for buttons defined as TYPE_MENUBUTTON:
IdletoOverUp
OverUptoIdle
OverUptoOverDown
OverDowntoOverUp
IdletoOverDown
OutDowntoIdle
MenuEnter (IdletoOverUp|IdletoOverDown)
MenuExit (OverUptoIdle|OverDowntoIdle)
IdletoOverUp
OverUptoIdle
OverUptoOverDown
OverDowntoOverUp
OverDowntoOutDown
OutDowntoOverDown
OutDowntoIdle
ButtonEnter (IdletoOverUp|OutDowntoOverDown)
ButtonExit (OverUptoIdle|OverDowntoOutDown)
The swf_openfile() function opens a new file named filename with a width of width and a height of height a frame rate of framerate and background with a red color of r a green color of g and a blue color of b.
The swf_openfile() must be the first function you call, otherwise your script will cause a segfault. If you want to send your output to the screen make the filename: "php://stdout" (support for this is in 4.0.1 and up).
The swf_ortho2() function defines a two dimensional orthographic mapping of user coordinates onto the current viewport, this defaults to one to one mapping of the area of the Flash movie. If a perspective transformation is desired, the swf_perspective () function can be used.
(PHP 4 >= 4.0.1)
swf_ortho -- Defines an orthographic mapping of user coordinates onto the current viewportThe swf_ortho() function defines an orthographic mapping of user coordinates onto the current viewport.
The swf_perspective() function defines a perspective projection transformation. The fovy parameter is field-of-view angle in the y direction. The aspect parameter should be set to the aspect ratio of the viewport that is being drawn onto. The near parameter is the near clipping plane and the far parameter is the far clipping plane.
Óçìåßùóç: Various distortion artifacts may appear when performing a perspective projection, this is because Flash players only have a two dimensional matrix. Some are not to pretty.
Places the object specified by objid in the current frame at a depth of depth. The objid parameter and the depth must be between 1 and 65535.
This uses the current mulcolor (specified by swf_mulcolor()) and the current addcolor (specified by swf_addcolor()) to color the object and it uses the current matrix to position the object.
Óçìåßùóç: Full RGBA colors are supported.
The swf_polarview() function defines the viewer's position in polar coordinates. The dist parameter gives the distance between the viewpoint to the world space origin. The azimuth parameter defines the azimuthal angle in the x,y coordinate plane, measured in distance from the y axis. The incidence parameter defines the angle of incidence in the y,z plane, measured in distance from the z axis. The incidence angle is defined as the angle of the viewport relative to the z axis. Finally the twist specifies the amount that the viewpoint is to be rotated about the line of sight using the right hand rule.
The swf_popmatrix() function pushes the current transformation matrix back onto the stack.
(PHP 4 )
swf_posround -- Enables or Disables the rounding of the translation when objects are placed or movedThe swf_posround() function enables or disables the rounding of the translation when objects are placed or moved, there are times when text becomes more readable because rounding has been enabled. The round is whether to enable rounding or not, if set to the value of 1, then rounding is enabled, if set to 0 then rounding is disabled.
The swf_pushmatrix() function pushes the current transformation matrix back onto the stack.
The swf_rotate() rotates the current transformation by the angle given by the angle parameter around the axis given by the axis parameter. Valid values for the axis are 'x' (the x axis), 'y' (the y axis) or 'z' (the z axis).
The swf_scale() scales the x coordinate of the curve by the value of the x parameter, the y coordinate of the curve by the value of the y parameter, and the z coordinate of the curve by the value of the z parameter.
The swf_setfont() sets the current font to the value given by the fontid parameter.
The swf_setframe() changes the active frame to the frame specified by framenumber.
The swf_shapearc() function draws a circular arc from angle A given by the ang1 parameter to angle B given by the ang2 parameter. The center of the circle has an x coordinate given by the x parameter and a y coordinate given by the y, the radius of the circle is given by the r parameter.
Draw a cubic bezier curve using the x,y coordinate pairs x1, y1 and x2,y2 as off curve control points and the x,y coordinate x3, y3 as an endpoint. The current position is then set to the x,y coordinate pair given by x3,y3.
The swf_shapecurveto() function draws a quadratic bezier curve from the current location, though the x coordinate given by x1 and the y coordinate given by y1 to the x coordinate given by x2 and the y coordinate given by y2. The current position is then set to the x,y coordinates given by the x2 and y2 parameters
Sets the fill to bitmap clipped, empty spaces will be filled by the bitmap given by the bitmapid parameter.
Sets the fill to bitmap tile, empty spaces will be filled by the bitmap given by the bitmapid parameter (tiled).
The swf_shapefilloff() function turns off filling for the current shape.
The swf_shapefillsolid() function sets the current fill style to solid, and then sets the fill color to the values of the rgba parameters.
The swf_shapelinesolid() function sets the current line style to the color of the rgba parameters and width to the width parameter. If 0.0 is given as a width then no lines are drawn.
The swf_shapelineto() draws a line to the x,y coordinates given by the x parameter & the y parameter. The current position is then set to the x,y parameters.
The swf_shapemoveto() function moves the current position to the x coordinate given by the x parameter and the y position given by the y parameter.
The swf_startbutton() function starts off the definition of a button. The type parameter can either be TYPE_MENUBUTTON or TYPE_PUSHBUTTON. The TYPE_MENUBUTTON constant allows the focus to travel from the button when the mouse is down, TYPE_PUSHBUTTON does not allow the focus to travel when the mouse is down.
The swf_startdoaction() function starts the description of an action list for the current frame. This must be called before actions are defined for the current frame.
The swf_startshape() function starts a complex shape, with an object id given by the objid parameter.
Define an object id as a symbol. Symbols are tiny flash movies that can be played simultaneously. The objid parameter is the object id you want to define as a symbol.
The swf_textwidth() function gives the width of the string, str, in pixels, using the current font and font size.
The swf_translate() function translates the current transformation by the x, y, and z values given.
In order to use the SNMP functions on Unix you need to install the NET-SNMP package. On Windows these functions are only available on NT and not on Win95/98.
Important: In order to use the UCD SNMP package, you need to define NO_ZEROLENGTH_COMMUNITY to 1 before compiling it. After configuring UCD SNMP, edit config.h and search for NO_ZEROLENGTH_COMMUNITY. Uncomment the #define line. It should look like this afterwards:
#define NO_ZEROLENGTH_COMMUNITY 1 |
If you see strange segmentation faults in combination with SNMP commands, you did not follow the above instructions. If you do not want to recompile UCD SNMP, you can compile PHP with the --enable-ucd-snmp-hack switch which will work around the misfeature.
The Windows distribution contains support files for SNMP in the mibs directory. This directory should be moved to DRIVE:\usr\mibs, where DRIVE must be replaced with the driveletter where PHP is installed on, e.g.: c:\usr\mibs.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
(PHP 3>= 3.0.8, PHP 4 , PHP 5)
snmp_get_quick_print -- Fetches the current value of the UCD library's quick_print settingReturns the current value stored in the UCD Library for quick_print. quick_print is off by default.
Above function call would return FALSE if quick_print is off, and TRUE if quick_print is on.
snmp_get_quick_print() is only available when using the UCD SNMP library. This function is not available when using the Windows SNMP library.
See also snmp_set_quick_print() for a full description of what quick_print does.
(PHP 4 >= 4.3.3, PHP 5)
snmp_get_valueretrieval -- Return the method how the SNMP values will be returnedÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
snmp_set_enum_print -- Return all values that are enums with their enum value instead of the raw integerÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.3.0, PHP 5)
snmp_set_oid_numeric_print -- Return all objects including their respective object id within the specified oneÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 3>= 3.0.8, PHP 4 , PHP 5)
snmp_set_quick_print -- Set the value of quick_print within the UCD SNMP librarySets the value of quick_print within the UCD SNMP library. When this is set (1), the SNMP library will return 'quick printed' values. This means that just the value will be printed. When quick_print is not enabled (default) the UCD SNMP library prints extra information including the type of the value (i.e. IpAddress or OID). Additionally, if quick_print is not enabled, the library prints additional hex values for all strings of three characters or less.
Setting quick_print is often used when using the information returned rather then displaying it.
<?php snmp_set_quick_print(0); $a = snmpget("127.0.0.1", "public", ".1.3.6.1.2.1.2.2.1.9.1"); echo "$a< br />\n"; snmp_set_quick_print(1); $a = snmpget("127.0.0.1", "public", ".1.3.6.1.2.1.2.2.1.9.1"); echo "$a<br />\n"; ?> |
The first value printed might be: 'Timeticks: (0) 0:00:00.00', whereas with quick_print enabled, just '0:00:00.00' would be printed.
By default the UCD SNMP library returns verbose values, quick_print is used to return only the value.
Currently strings are still returned with extra quotes, this will be corrected in a later release.
snmp_set_quick_print() is only available when using the UCD SNMP library. This function is not available when using the Windows SNMP library.
(PHP 4 >= 4.3.3, PHP 5)
snmp_set_valueretrieval -- Specify the method how the SNMP values will be returnedÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns SNMP object value on success and FALSE on error.
The snmpget() function is used to read the value of an SNMP object specified by the object_id. SNMP agent is specified by the hostname and the read community is specified by the community parameter.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 3>= 3.0.8, PHP 4 , PHP 5)
snmprealwalk -- Return all objects including their respective object ID within the specified one
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Sets the specified SNMP object value, returning TRUE on success and FALSE on error.
The snmpset() function is used to set the value of an SNMP object specified by the object_id. SNMP agent is specified by the hostname and the read community is specified by the community parameter.
Returns an array of SNMP object values starting from the object_id as root and FALSE on error.
snmpwalk() function is used to read all the values from an SNMP agent specified by the hostname. Community specifies the read community for that agent. A NULL object_id is taken as the root of the SNMP objects tree and all objects under that tree are returned as an array. If object_id is specified, all the SNMP objects below that object_id are returned.
Above function call would return all the SNMP objects from the SNMP agent running on localhost. One can step through the values with a loop
Returns an associative array with object ids and their respective object value starting from the object_id as root and FALSE on error.
snmpwalkoid() function is used to read all object ids and their respective values from an SNMP agent specified by the hostname. Community specifies the read community for that agent. A NULL object_id is taken as the root of the SNMP objects tree and all objects under that tree are returned as an array. If object_id is specified, all the SNMP objects below that object_id are returned.
The existence of snmpwalkoid() and snmpwalk() has historical reasons. Both functions are provided for backward compatibility.
Above function call would return all the SNMP objects from the SNMP agent running on localhost. One can step through the values with a loop
The socket extension implements a low-level interface to the socket communication functions based on the popular BSD sockets, providing the possibility to act as a socket server as well as a client.
For a more generic client-side socket interface, see stream_socket_client(), stream_socket_server(), fsockopen(), and pfsockopen().
When using these functions, it is important to remember that while many of them have identical names to their C counterparts, they often have different declarations. Please be sure to read the descriptions to avoid confusion.
Those unfamiliar with socket programming can find a lot of useful material in the appropriate Unix man pages, and there is a great deal of tutorial information on socket programming in C on the web, much of which can be applied, with slight modifications, to socket programming in PHP. The Unix Socket FAQ might be a good start.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
The socket functions described here are part of an extension to PHP which must be enabled at compile time by giving the --enable-sockets option to configure.
Óçìåßùóç: Ç õðïóôÞñéîç ãéá IPv6 ðñïóôÝèçêå ìå ôçí PHP 5.0.0 .
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
The socket extension was written to provide a useable interface to the powerful BSD sockets. Care has been taken that the functions work equally well on Win32 and Unix implementations. Almost all of the sockets functions may fail under certain conditions and therefore emit an E_WARNING message describing the error. Sometimes this doesn't happen to the desire of the developer. For example the function socket_read() may suddenly emit an E_WARNING message because the connection broke unexpectedly. It's common to suppress the warning with the @-operator and catch the error code within the application with the socket_last_error() function. You may call the socket_strerror() function with this error code to retrieve a string describing the error. See their description for more information.
Óçìåßùóç: The E_WARNING messages generated by the socket extension are in English though the retrieved error message will appear depending on the current locale (LC_MESSAGES):
Warning - socket_bind() unable to bind address [98]: Die Adresse wird bereits verwendet
ÐáñÜäåéãìá 1. Socket example: Simple TCP/IP server This example shows a simple talkback server. Change the address and port variables to suit your setup and execute. You may then connect to the server with a command similar to: telnet 192.168.1.53 10000 (where the address and port match your setup). Anything you type will then be output on the server side, and echoed back to you. To disconnect, enter 'quit'.
|
ÐáñÜäåéãìá 2. Socket example: Simple TCP/IP client This example shows a simple, one-shot HTTP client. It simply connects to a page, submits a HEAD request, echoes the reply, and exits.
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
After the socket socket has been created using socket_create(), bound to a name with socket_bind(), and told to listen for connections with socket_listen(), this function will accept incoming connections on that socket. Once a successful connection is made, a new socket resource is returned, which may be used for communication. If there are multiple connections queued on the socket, the first will be used. If there are no pending connections, socket_accept() will block until a connection becomes present. If socket has been made non-blocking using socket_set_blocking() or socket_set_nonblock(), FALSE will be returned.
The socket resource returned by socket_accept() may not be used to accept new connections. The original listening socket socket, however, remains open and may be reused.
Returns a new socket resource on success, or FALSE on error. The actual error code can be retrieved by calling socket_last_error(). This error code may be passed to socket_strerror() to get a textual explanation of the error.
See also socket_bind(), socket_connect(), socket_listen(), socket_create(), and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
socket_bind() binds the name given in address to the socket described by socket, which must be a valid socket resource created with socket_create().
The address parameter is either an IP address in dotted-quad notation (e.g. 127.0.0.1), if the socket is of the AF_INET family; or the pathname of a Unix-domain socket, if the socket family is AF_UNIX.
The port parameter is only used when connecting to an AF_INET socket, and designates the port on the remote host to which a connection should be made.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error. Note that socket_last_error() is reported to return an invalid error code in case you are trying to bind the socket to a wrong address that does not belong to your Windows 9x/ME machine.
See also socket_connect(), socket_listen(), socket_create(), socket_last_error() and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function clears the error code on the given socket or the global last socket error.
This function allows explicitly resetting the error code value either of a socket or of the extension global last error code. This may be useful to detect within a part of the application if an error occurred or not.
See also socket_last_error() and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
socket_close() closes the socket resource given by socket.
Óçìåßùóç: socket_close() can't be used on PHP file resources created with fopen(), popen(), fsockopen(), or pfsockopen(); it is meant for sockets created with socket_create() or socket_accept().
See also socket_bind(), socket_listen(), socket_create() and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Initiates a connection using the socket resource socket, which must be a valid socket resource created with socket_create().
The address parameter is either an IP address in dotted-quad notation (e.g. 127.0.0.1), if the socket is of the AF_INET family; or the pathname of a Unix domain socket, if the socket family is AF_UNIX.
The port parameter is only used when connecting to an AF_INET socket, and designates the port on the remote host to which a connection should be made.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error.
See also socket_bind(), socket_listen(), socket_create(), socket_last_error() and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function is meant to ease the task of creating a new socket which only listens to accept new connections.
socket_create_listen() creates a new socket resource of type AF_INET listening on all local interfaces on the given port waiting for new connections.
The backlog parameter defines the maximum length the queue of pending connections may grow to. SOMAXCONN may be passed as backlog parameter, see socket_listen() for more information.
socket_create_listen() returns a new socket resource on success or FALSE on error. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error.
Óçìåßùóç: If you want to create a socket which only listens on a certain interface you need to use socket_create(), socket_bind() and socket_listen().
See also socket_create(), socket_bind(), socket_listen(), socket_last_error() and socket_strerror().
(PHP 4 >= 4.1.0, PHP 5)
socket_create_pair -- Creates a pair of indistinguishable sockets and stores them in an array.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
socket_create_pair() creates two connected and indistinguishable sockets, and stores them in &fd. This function is commonly used in IPC (InterProcess Communication).
The domain parameter specifies the protocol family to be used by the socket.
Ðßíáêáò 1. Available address/protocol families
Domain | Description |
---|---|
AF_INET | IPv4 Internet based protocols. TCP and UDP are common protocols of this protocol family. Supported only in windows. |
AF_INET6 | IPv6 Internet based protocols. TCP and UDP are common protocols of this protocol family. Support added in PHP 5.0.0. Supported only in windows. |
AF_UNIX | Local communication protocol family. High efficiency and low overhead make it a great form of IPC (Interprocess Communication). |
The type parameter selects the type of communication to be used by the socket.
Ðßíáêáò 2. Available socket types
Type | Description |
---|---|
SOCK_STREAM | Provides sequenced, reliable, full-duplex, connection-based byte streams. An out-of-band data transmission mechanism may be supported. The TCP protocol is based on this socket type. |
SOCK_DGRAM | Supports datagrams (connectionless, unreliable messages of a fixed maximum length). The UDP protocol is based on this socket type. |
SOCK_SEQPACKET | Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each read call. |
SOCK_RAW | Provides raw network protocol access. This special type of socket can be used to manually construct any type of protocol. A common use for this socket type is to perform ICMP requests (like ping, traceroute, etc). |
SOCK_RDM | Provides a reliable datagram layer that does not guarantee ordering. This is most likely not implemented on your operating system. |
The protocol parameter sets the specific protocol within the specified domain to be used when communicating on the returned socket. The proper value can be retrieved by name by using getprotobyname(). If the desired protocol is TCP, or UDP the corresponding constants SOL_TCP, and SOL_UDP can also be used.
Ðßíáêáò 3. Common protocols
Name | Description |
---|---|
icmp | The Internet Control Message Protocol is used primarily by gateways and hosts to report errors in datagram communication. The "ping" command (present in most modern operating systems) is an example application of ICMP. |
udp | The User Datagram Protocol is a connectionless, unreliable, protocol with fixed record lengths. Due to these aspects, UDP requires a minimum amount of protocol overhead. |
tcp | The Transmission Control Protocol is a reliable, connection based, stream oriented, full duplex protocol. TCP guarantees that all data packets will be received in the order in which they were sent. If any packet is somehow lost during communication, TCP will automatically retransmit the packet until the destination host acknowledges that packet. For reliability and performance reasons, the TCP implementation itself decides the appropriate octet boundaries of the underlying datagram communication layer. Therefore, TCP applications must allow for the possibility of partial record transmission. |
ÐáñÜäåéãìá 1. socket_create_pair() example
|
ÐáñÜäåéãìá 2. socket_create_pair() IPC example
|
Creates and returns a socket resource, also referred to as an endpoint of communication. A typical network connection is made up of 2 sockets, one performing the role of the client, and another performing the role of the server.
The domain parameter specifies the protocol family to be used by the socket.
Ðßíáêáò 1. Available address/protocol families
Domain | Description |
---|---|
AF_INET | IPv4 Internet based protocols. TCP and UDP are common protocols of this protocol family. |
AF_INET6 | IPv6 Internet based protocols. TCP and UDP are common protocols of this protocol family. Support added in PHP 5.0.0. |
AF_UNIX | Local communication protocol family. High efficiency and low overhead make it a great form of IPC (Interprocess Communication). |
The type parameter selects the type of communication to be used by the socket.
Ðßíáêáò 2. Available socket types
Type | Description |
---|---|
SOCK_STREAM | Provides sequenced, reliable, full-duplex, connection-based byte streams. An out-of-band data transmission mechanism may be supported. The TCP protocol is based on this socket type. |
SOCK_DGRAM | Supports datagrams (connectionless, unreliable messages of a fixed maximum length). The UDP protocol is based on this socket type. |
SOCK_SEQPACKET | Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each read call. |
SOCK_RAW | Provides raw network protocol access. This special type of socket can be used to manually construct any type of protocol. A common use for this socket type is to perform ICMP requests (like ping, traceroute, etc). |
SOCK_RDM | Provides a reliable datagram layer that does not guarantee ordering. This is most likely not implemented on your operating system. |
The protocol parameter sets the specific protocol within the specified domain to be used when communicating on the returned socket. The proper value can be retrieved by name by using getprotobyname(). If the desired protocol is TCP, or UDP the corresponding constants SOL_TCP, and SOL_UDP can also be used.
Ðßíáêáò 3. Common protocols
Name | Description |
---|---|
icmp | The Internet Control Message Protocol is used primarily by gateways and hosts to report errors in datagram communication. The "ping" command (present in most modern operating systems) is an example application of ICMP. |
udp | The User Datagram Protocol is a connectionless, unreliable, protocol with fixed record lengths. Due to these aspects, UDP requires a minimum amount of protocol overhead. |
tcp | The Transmission Control Protocol is a reliable, connection based, stream oriented, full duplex protocol. TCP guarantees that all data packets will be received in the order in which they were sent. If any packet is somehow lost during communication, TCP will automatically retransmit the packet until the destination host acknowledges that packet. For reliability and performance reasons, the TCP implementation itself decides the appropriate octet boundaries of the underlying datagram communication layer. Therefore, TCP applications must allow for the possibility of partial record transmission. |
socket_create() Returns a socket resource on success, or FALSE on error. The actual error code can be retrieved by calling socket_last_error(). This error code may be passed to socket_strerror() to get a textual explanation of the error.
Óçìåßùóç: If an invalid domain or type is given, socket_create() defaults to AF_INET and SOCK_STREAM respectively and additionally emits an E_WARNING message.
See also socket_accept(), socket_bind(), socket_connect(), socket_listen(), socket_last_error(), and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The socket_get_option() function retrieves the value for the option specified by the optname parameter for the socket specified by the socket parameter. socket_get_option() will return FALSE on failure.
The level parameter specifies the protocol level at which the option resides. For example, to retrieve options at the socket level, a level parameter of SOL_SOCKET would be used. Other levels, such as TCP, can be used by specifying the protocol number of that level. Protocol numbers can be found by using the getprotobyname() function.
Ðßíáêáò 1. Available Socket Options
Option | Description |
---|---|
SO_DEBUG | Reports whether debugging information is being recorded. |
SO_ACCEPTCONN | Reports whether socket listening is enabled. |
SO_BROADCAST | Reports whether transmission of broadcast messages is supported. |
SO_REUSEADDR | Reports whether local addresses can be reused. |
SO_KEEPALIVE | Reports whether connections are kept active with periodic transmission of messages. If the connected socket fails to respond to these messages, the connection is broken and processes writing to that socket are notified with a SIGPIPE signal. |
SO_LINGER | Reports whether the socket lingers on socket_close() if data is present. |
SO_OOBINLINE | Reports whether the socket leaves out-of-band data inline. |
SO_SNDBUF | Reports send buffer size information. |
SO_RCVBUF | Reports recieve buffer size information. |
SO_ERROR | Reports information about error status and clears it. |
SO_TYPE | Reports the socket type. |
SO_DONTROUTE | Reports whether outgoing messages bypass the standard routing facilities. |
SO_RCVLOWAT | Reports the minimum number of bytes to process for socket input operations. ( Defaults to 1 ) |
SO_RCVTIMEO | Reports the timeout value for input operations. |
SO_SNDLOWAT | Reports the minimum number of bytes to process for socket output operations. |
SO_SNDTIMEO | Reports the timeout value specifying the amount of time that an output function blocks because flow control prevents data from being sent. |
Óçìåßùóç: This function used to be called socket_getopt() prior to PHP 4.3.0
(PHP 4 >= 4.1.0, PHP 5)
socket_getpeername -- Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
If the given socket is of type AF_INET or AF_INET6, socket_getpeername() will return the peers (remote) IP address in appropriate notation (e.g. 127.0.0.1 or fe80::1) in the address parameter and, if the optional port parameter is present, also the associated port.
If the given socket is of type AF_UNIX, socket_getpeername() will return the Unix filesystem path (e.g. /var/run/daemon.sock) in the address parameter.
Óçìåßùóç: socket_getpeername() should not be used with AF_UNIX sockets created with socket_accept(). Only sockets created with socket_connect() or a primary server socket following a call to socket_bind() will return meaningful values.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. socket_getpeername() may also return FALSE if the socket type is not any of AF_INET, AF_INET6, or AF_UNIX, in which case the last socket error code is not updated.
See also socket_getsockname(), socket_last_error() and socket_strerror().
(PHP 4 >= 4.1.0, PHP 5)
socket_getsockname -- Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
If the given socket is of type AF_INET or AF_INET6, socket_getsockname() will return the local IP address in appropriate notation (e.g. 127.0.0.1 or fe80::1) in the address parameter and, if the optional port parameter is present, also the associated port.
If the given socket is of type AF_UNIX, socket_getsockname() will return the Unix filesystem path (e.g. /var/run/daemon.sock) in the address parameter.
Óçìåßùóç: socket_getsockname() should not be used with AF_UNIX sockets created with socket_connect(). Only sockets created with socket_accept() or a primary server socket following a call to socket_bind() will return meaningful values.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. socket_getsockname() may also return FALSE if the socket type is not any of AF_INET, AF_INET6, or AF_UNIX, in which case the last socket error code is not updated.
See also socket_getpeername(), socket_last_error() and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0)
socket_iovec_alloc -- Builds a 'struct iovec' for use with sendmsg, recvmsg, writev, and readvÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0)
socket_iovec_fetch -- Returns the data held in the iovec specified by iovec_id[iovec_position]Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function returns a socket error code.
If a socket resource is passed to this function, the last error which occurred on this particular socket is returned. If the socket resource is omitted, the error code of the last failed socket function is returned. The latter is in particular helpful for functions like socket_create() which don't return a socket on failure and socket_select() which can fail for reasons not directly tied to a particular socket. The error code is suitable to be fed to socket_strerror() which returns a string describing the given error code.
<?php if (false == ($socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) { die("Couldn't create socket, error code is: " . socket_last_error() . ",error message is: " . socket_strerror(socket_last_error())); } ?> |
Óçìåßùóç: socket_last_error() does not clear the error code, use socket_clear_error() for this purpose.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
After the socket socket has been created using socket_create() and bound to a name with socket_bind(), it may be told to listen for incoming connections on socket.
A maximum of backlog incoming connections will be queued for processing. If a connection request arrives with the queue full the client may receive an error with an indication of ECONNREFUSED, or, if the underlying protocol supports retransmission, the request may be ignored so that retries may succeed.
Óçìåßùóç: The maximum number passed to the backlog parameter highly depends on the underlying platform. On Linux, it is silently truncated to SOMAXCONN. On win32, if passed SOMAXCONN, the underlying service provider responsible for the socket will set the backlog to a maximum reasonable value. There is no standard provision to find out the actual backlog value on this platform.
socket_listen() is applicable only to sockets of type SOCK_STREAM or SOCK_SEQPACKET.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error.
See also socket_accept(), socket_bind(), socket_connect(), socket_create() and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function socket_read() reads from the socket resource socket created by the socket_create() or socket_accept() functions. The maximum number of bytes read is specified by the length parameter. Otherwise you can use \r, \n, or \0 to end reading (depending on the type parameter, see below).
socket_read() returns the data as a string on success, or FALSE on error. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual representation of the error.
Óçìåßùóç: socket_read() may return a zero length string ("") indicating the end of communication (i.e. the remote end point has closed the connection).
Optional type parameter is a named constant:
PHP_BINARY_READ - use the system read() function. Safe for reading binary data. (Default in PHP >= 4.1.0)
PHP_NORMAL_READ - reading stops at \n or \r. (Default in PHP <= 4.0.6)
See also socket_accept(), socket_bind(), socket_connect(), socket_listen(), socket_last_error(), socket_strerror() and socket_write().
(PHP 4 >= 4.1.0)
socket_readv -- Reads from an fd, using the scatter-gather array defined by iovec_idÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0)
socket_recvmsg -- Used to receive messages on a socket, whether connection-oriented or notÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
socket_select -- Runs the select() system call on the given arrays of sockets with a specified timeoutÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
socket_select() accepts arrays of sockets and waits for them to change status. Those coming with BSD sockets background will recognize that those socket resource arrays are in fact the so-called file descriptor sets. Three independent arrays of socket resources are watched.
The sockets listed in the read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a socket resource is also ready on end-of-file, in which case a socket_read() will return a zero length string).
The sockets listed in the write array will be watched to see if a write will not block.
The sockets listed in the except array will be watched for exceptions.
Ðñïåéäïðïßçóç |
On exit, the arrays are modified to indicate which socket resource actually changed status. |
You do not need to pass every array to socket_select(). You can leave it out and use an empty array or NULL instead. Also do not forget that those arrays are passed by reference and will be modified after socket_select() returns.
ÐáñÜäåéãìá 1. socket_select() example
|
Óçìåßùóç: Due a limitation in the current Zend Engine it is not possible to pass a constant modifier like NULL directly as a parameter to a function which expects this parameter to be passed by reference. Instead use a temporary variable or an expression with the leftmost member being a temporary variable:
The tv_sec and tv_usec together form the timeout parameter. The timeout is an upper bound on the amount of time elapsed before socket_select() return. tv_sec may be zero , causing socket_select() to return immediately. This is useful for polling. If tv_sec is NULL (no timeout), socket_select() can block indefinitely.
On success socket_select() returns the number of socket resources contained in the modified arrays, which may be zero if the timeout expires before anything interesting happens. On error FALSE is returned. The error code can be retrieved with socket_last_error().
Óçìåßùóç: Be sure to use the === operator when checking for an error. Since the socket_select() may return 0 the comparison with == would evaluate to TRUE:
Óçìåßùóç: Be aware that some socket implementations need to be handled very carefully. A few basic rules:
You should always try to use socket_select() without timeout. Your program should have nothing to do if there is no data available. Code that depends on timeouts is not usually portable and difficult to debug.
No socket resource must be added to any set if you do not intend to check its result after the socket_select() call, and respond appropriately. After socket_select() returns, all socket resources in all arrays must be checked. Any socket resource that is available for writing must be written to, and any socket resource available for reading must be read from.
If you read/write to a socket returns in the arrays be aware that they do not necessarily read/write the full amount of data you have requested. Be prepared to even only be able to read/write a single byte.
It's common to most socket implementations that the only exception caught with the except array is out-of-bound data received on a socket.
See also socket_read(), socket_write(), socket_last_error() and socket_strerror().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function socket_send() sends len bytes to the socket socket from buf
The value of flags can be any ORed combination of the following:
Ðßíáêáò 1. possible values for flags
0x1 | Process OOB (out-of-band) data |
0x2 | Peek at incoming message |
0x4 | Bypass routing, use direct interface |
0x8 | Data completes record |
0x100 | Data completes transaction |
See also socket_sendmsg() and socket_sendto().
(PHP 4 >= 4.1.0)
socket_sendmsg -- Sends a message to a socket, regardless of whether it is connection-oriented or notÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function socket_sendto() sends len bytes from buf through the socket socket to the port at the address addr
The value of flags can be one of the following:
Ðßíáêáò 1. possible values for flags
0x1 | Process OOB (out-of-band) data. |
0x2 | Peek at incoming message. |
0x4 | Bypass routing, use direct interface. |
0x8 | Data completes record. |
0x100 | Data completes transaction. |
ÐáñÜäåéãìá 1. socket_sendto() Example
|
See also socket_send() and socket_sendmsg().
The socket_set_block() function removes the O_NONBLOCK flag on the socket specified by the socket parameter.
ÐáñÜäåéãìá 1. socket_set_block() example
|
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also socket_set_nonblock() and socket_set_option()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The socket_set_nonblock() function sets the O_NONBLOCK flag on the socket specified by the socket parameter.
ÐáñÜäåéãìá 1. socket_set_nonblock() example
|
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also socket_set_block() and socket_set_option()
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The socket_set_option() function sets the option specified by the optname parameter, at the protocol level specified by the level parameter, to the value pointed to by the optval parameter for the socket specified by the socket parameter. socket_set_option() will return FALSE on failure.
The level parameter specifies the protocol level at which the option resides. For example, to retrieve options at the socket level, a level parameter of SOL_SOCKET would be used. Other levels, such as TCP, can be used by specifying the protocol number of that level. Protocol numbers can be found by using the getprotobyname() function.
The available socket options are the same as those for the socket_get_option() function.
Óçìåßùóç: This function used to be called socket_setopt() prior to PHP 4.3.0
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The socket_shutdown() function allows you to stop incoming, outgoing or all data (the default) from being sent through the socket
The value of how can be one of the following:
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
socket_strerror() takes as its errno parameter a socket error code as returned by socket_last_error() and returns the corresponding explanatory text. This makes it a bit more pleasant to figure out why something didn't work; for instance, instead of having to track down a system include file to find out what '-111' means, you just pass it to socket_strerror(), and it tells you what happened.
ÐáñÜäåéãìá 1. socket_strerror() example
The expected output from the above example (assuming the script is not run with root privileges):
|
See also socket_accept(), socket_bind(), socket_connect(), socket_listen(), and socket_create().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
The function socket_write() writes to the socket socket from buffer.
The optional parameter length can specify an alternate length of bytes written to the socket. If this length is greater then the buffer length, it is silently truncated to the length of the buffer.
Returns the number of bytes successfully written to the socket or FALSE one error. The error code can be retrieved with socket_last_error(). This code may be passed to socket_strerror() to get a textual explanation of the error.
Óçìåßùóç: socket_write() does not necessarily write all bytes from the given buffer. It's valid that, depending on the network buffers etc., only a certain amount of data, even one byte, is written though your buffer is greater. You have to watch out so you don't unintentionally forget to transmit the rest of your data.
Óçìåßùóç: It is perfectly valid for socket_write() to return zero which means no bytes have been written. Be sure to use the === operator to check for FALSE in case of an error.
See also socket_accept(), socket_bind(), socket_connect(), socket_listen(), socket_read() and socket_strerror().
(PHP 4 >= 4.1.0)
socket_writev -- Writes to a file descriptor, fd, using the scatter-gather array defined by iovec_idÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
This function returns the current array entry
ÐáñÜäåéãìá 1. ArrayIterator::current() example
The above example will output:
|
This function moves the iterator to the next entry.
ÐáñÜäåéãìá 1. ArrayIterator::next() example
The above example will output:
|
(no version information, might be only in CVS)
ArrayIterator::rewind -- Rewind array back to the startThis function rewinds the iterator to the begining.
ÐáñÜäåéãìá 1. ArrayIterator::rewind() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ArrayIterator::valid -- Check whether array contains more entriesThis function checks if the array contains any more entries.
ÐáñÜäåéãìá 1. ArrayIterator::valid() example
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ArrayObject::__construct -- Construct a new array objectThis constructs a new array object. The input parameter accepts an array or another ArrayObject.
ÐáñÜäåéãìá 1. ArrayObject::__construct() example
The above example will output:
|
(no version information, might be only in CVS)
ArrayObject::count -- Return the number of elements in the IteratorÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ArrayObject::getIterator -- Create a new iterator from an ArrayObject instanceThis function will return an iterator from an ArrayObject.
ÐáñÜäåéãìá 1. ArrayObject::getIterator() example
The above example will output:
|
(no version information, might be only in CVS)
ArrayObject::offsetExists -- Returns whether the requested $index existsÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ArrayObject::offsetGet -- Returns the value at the specified $indexÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ArrayObject::offsetSet -- Sets the value at the specified $index to $newvalÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ArrayObject::offsetUnset -- Unsets the value at the specified $indexÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
CachingIterator::hasNext -- Cehck whether the inner iterator has a valid next elementÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
CachingIterator::__toString -- Retrun the string representation of the current elementÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
CachingIterator::valid -- Check whether the current element is validÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
CachingRecursiveIterator::getChildren -- Return the inenr iteraor's children as a CachingRecursiveIteratorÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
CachingRecursiveIterator::hasChildren -- Check whether the current element of the inner iterator has childrenÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::__construct -- Constructs a new dir iterator from a path.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::current -- Return this (needed for Iterator interface)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::fileATime -- Get last access time of fileÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::fileCTime -- Get inode modification time of fileÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::fileMTime -- Get last modification time of fileÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::getChildren -- Returns an iterator for the current entry if it is a directoryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::getFilename -- Return filename of current dir entryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::getPathname -- Return path and filename of current dir entryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::isDir -- Returns true if file is directoryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::isDot -- Returns true if current entry is '.' or '..'Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::isExecutable -- Returns true if file is executableÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::isFile -- Returns true if file is a regular fileÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::isLink -- Returns true if file is symbolic linkÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::isReadable -- Returns true if file can be readÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::isWritable -- Returns true if file can be writtenÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::rewind -- Rewind dir back to the startÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
DirectoryIterator::valid -- Check whether dir contains more entriesÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
FilterIterator::current -- Get the current element valueÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
FilterIterator::getInnerIterator -- Get the inner iteratorÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
FilterIterator::valid -- Check whether the current element is validÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
LimitIterator::getPosition -- Return the current positionÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
LimitIterator::rewind -- Rewind the iterator to the specified starting offsetÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
LimitIterator::valid -- Check whether the current element is validÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ParentIterator::getChildren -- Return the inner iterator's children contained in a ParentIteratorÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
ParentIterator::hasChildren -- Check whether the inner iterator's current element has childrenÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveDirectoryIterator::getChildren -- Returns an iterator for the current entry if it is a directoryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveDirectoryIterator::hasChildren -- Returns whether current entry is a directory and not '.' or '..'Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveDirectoryIterator::key -- Return path and filename of current dir entryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveDirectoryIterator::next -- Move to next entryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveDirectoryIterator::rewind -- Rewind dir back to the startÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveIteratorIterator::current -- Access the current element valueÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveIteratorIterator::getDepth -- Get the current depth of the recursive iterationÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveIteratorIterator::getSubIterator -- The current active sub iteratorÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveIteratorIterator::key -- Access the current keyÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveIteratorIterator::next -- Move forward to the next elementÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveIteratorIterator::rewind -- Rewind the iterator to the first element of the top level inner iterator.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
RecursiveIteratorIterator::valid -- Check whether the current position is validÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
SimpleXMLIterator::current -- Return current SimpleXML entryÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
SimpleXMLIterator::getChildren -- Returns an iterator for the current entry if it is a SimpleXML objectÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
SimpleXMLIterator::hasChildren -- Returns whether current entry is a SimpleXML objectÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
SimpleXMLIterator::key -- Return current SimpleXML keyÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
SimpleXMLIterator::rewind -- Rewind SimpleXML back to the startÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Streams were introduced with PHP 4.3.0 as a way of generalizing file, network, data compression, and other operations which share a common set of functions and uses. In its simplest definition, a stream is a resource object which exhibits streamable behavior. That is, it can be read from or written to in a linear fashion, and may be able to fseek() to an arbitrary locations within the stream.
A wrapper is additional code which tells the stream how to handle specific protocols/encodings. For example, the http wrapper knows how to translate a URL into an HTTP/1.0 request for a file on a remote server. There are many wrappers built into PHP by default (See ÐáñÜñôçìá J), and additional, custom wrappers may be added either within a PHP script using stream_wrapper_register(), or directly from an extension using the API Reference in ÊåöÜëáéï 43. Because any variety of wrapper may be added to PHP, there is no set limit on what can be done with them. To access the list of currently registered wrappers, use stream_get_wrappers().
A stream is referenced as: scheme://target
scheme(string) - The name of the wrapper to be used. Examples include: file, http, https, ftp, ftps, compress.zlib, compress.bz2, and php. See ÐáñÜñôçìá J for a list of PHP builtin wrappers. If no wrapper is specified, the function default is used (typically file://).
target - Depends on the wrapper used. For filesystem related streams this is typically a path and filename of the desired file. For network related streams this is typically a hostname, often with a path appended. Again, see ÐáñÜñôçìá J for a description of targets for builtin streams.
A filter is a final piece of code which may perform operations on data as it is being read from or written to a stream. Any number of filters may be stacked onto a stream. Custom filters can be defined in a PHP script using stream_filter_register() or in an extension using the API Reference in ÊåöÜëáéï 43. To access the list of currently registered filters, use stream_get_filters().
A context is a set of parameters and wrapper specific options which modify or enhance the behavior of a stream. Contexts are created using stream_context_create() and can be passed to most filesystem related stream creation functions (i.e. fopen(), file(), file_get_contents(), etc...).
Options can be specified when calling stream_context_create(), or later using stream_context_set_option(). A list of wrapper specific options can be found with the list of built-in wrappers (See ÐáñÜñôçìá J).
In addition, parameters may be set on a context using stream_context_set_params(). Currently the only context parameter supported by PHP is notification. The value of this parameter must be the name of a function to be called when an event occurs on a stream. The notification function called during an event should accept the following six parameters:
void my_notifier ( int notification_code, int severity, string message, int message_code, int bytes_transferred, int bytes_max)notification_code and severity are numerical values which correspond to the STREAM_NOTIFY_* constants listed below. If a descriptive message is available from the stream, message and message_code will be populated with the appropriate values. The meaning of these values is dependent on the specific wrapper in use. bytes_transferred and bytes_max will be populated when applicable.
Streams are an integral part of PHP as of version 4.3.0. No steps are required to enable them.
User designed wrappers can be registered via stream_wrapper_register(), using the class definition shown on that manual page.
class php_user_filter is predefined and is an abstract baseclass for use with user defined filters. See the manual page for stream_filter_register() for details on implementing user defined filters.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Constant | Description |
---|---|
STREAM_FILTER_READ | Used with stream_filter_append() and stream_filter_prepend() to indicate that the specified filter should only be applied when reading |
STREAM_FILTER_WRITE | Used with stream_filter_append() and stream_filter_prepend() to indicate that the specified filter should only be applied when writing |
STREAM_FILTER_ALL | This constant is equivalent to STREAM_FILTER_READ | STREAM_FILTER_WRITE |
PSFS_PASS_ON | Return Code indicating that the userspace filter returned buckets in $out. |
PSFS_FEED_ME | Return Code indicating that the userspace filter did not return buckets in $out (i.e. No data available). |
PSFS_ERR_FATAL | Return Code indicating that the userspace filter encountered an unrecoverable error (i.e. Invalid data received). |
STREAM_USE_PATH | Flag indicating if the stream used the include path. |
STREAM_REPORT_ERRORS | Flag indicating if the wrapper is responsible for raising errors using trigger_error() during opening of the stream. If this flag is not set, you should not raise any errors. |
STREAM_CLIENT_ASYNC_CONNECT | Open client socket asynchronously. Used with stream_socket_client(). |
STREAM_CLIENT_PERSISTENT | Client socket opened with stream_socket_client() should remain persistent between page loads. |
STREAM_SERVER_BIND | Tells a stream created with stream_socket_server() to bind to the specified target. Server sockets should always include this flag. |
STREAM_SERVER_LISTEN | Tells a stream created with stream_socket_server() and bound using the STREAM_SERVER_BIND flag to start listening on the socket. Server sockets should always include this flag. |
STREAM_NOTIFY_RESOLVE | A remote address required for this stream has been resolved, or the resolution failed. See severity for an indication of which happened. |
STREAM_NOTIFY_CONNECT | A connection with an external resource has been established. |
STREAM_NOTIFY_AUTH_REQUIRED | Additional authorization is required to access the specified resource. Typical issued with severity level of STREAM_NOTIFY_SEVERITY_ERR. |
STREAM_NOTIFY_MIME_TYPE_IS | The mime-type of resource has been identified, refer to message for a description of the discovered type. |
STREAM_NOTIFY_FILE_SIZE_IS | The size of the resource has been discovered. |
STREAM_NOTIFY_REDIRECTED | The external resource has redirected the stream to an alternate location. Refer to message. |
STREAM_NOTIFY_PROGRESS | Indicates current progress of the stream transfer in bytes_transferred and possibly bytes_max as well. |
STREAM_NOTIFY_COMPLETED | There is no more data available on the stream. |
STREAM_NOTIFY_FAILURE | A generic error occurred on the stream, consult message and message_code for details. |
STREAM_NOTIFY_AUTH_RESULT | Authorization has been completed (with or without success). |
STREAM_NOTIFY_SEVERITY_INFO | Normal, non-error related, notification. |
STREAM_NOTIFY_SEVERITY_WARN | Non critical error condition. Processing may continue. |
STREAM_NOTIFY_SEVERITY_ERR | A critical error occurred. Processing cannot continue. |
As with any file or socket related function, an operation on a stream may fail for a variety of normal reasons (i.e.: Unable to connect to remote host, file not found, etc...). A stream related call may also fail because the desired stream is not registered on the running system. See the array returned by stream_get_wrappers() for a list of streams supported by your installation of PHP. As with most PHP internal functions if a failure occurs an E_WARNING message will be generated describing the nature of the error.
ÐáñÜäåéãìá 1. Using file_get_contents() to retrieve data from multiple sources
|
ÐáñÜäåéãìá 2. Making a POST request to an https server
|
ÐáñÜäåéãìá 3. Writing data to a compressed file
|
Creates and returns a stream context with any options supplied in options preset.
options must be an associative array of associative arrays in the format $arr['wrapper']['option'] = $value.
ÐáñÜäåéãìá 1. Using stream_context_create()
|
See Also: stream_context_set_option(), and Listing of supported wrappers with context options (ÐáñÜñôçìá J)
Returns an array of options on the specified stream or context.
Sets an option on the specified context. value is set to option for wrapper
params should be an associative array of the structure: $params['paramname'] = "paramvalue";.
Makes a copy of up to maxlength bytes of data from the current position in source to dest. If maxlength is not specified, all remaining content in source will be copied. Returns the total count of bytes copied.
ÐáñÜäåéãìá 1. stream_copy_to_stream() example
|
See also copy().
Adds filtername to the list of filters attached to stream. This filter will be added with the specified params to the end of the list and will therefore be called last during stream operations. To add a filter to the beginning of the list, use stream_filter_prepend().
By default, stream_filter_append() will attach the filter to the read filter chain if the file was opened for reading (i.e. File Mode: r, and/or +). The filter will also be attached to the write filter chain if the file was opened for writing (i.e. File Mode: w, a, and/or +). STREAM_FILTER_READ, STREAM_FILTER_WRITE, and/or STREAM_FILTER_ALL can also be passed to the read_write parameter to override this behavior.
ÐáñÜäåéãìá 1. Controlling where filters are applied
|
When using custom (user) filters: stream_filter_register() must be called first in order to register the desired user filter to filtername.
Óçìåßùóç: Stream data is read from resources (both local and remote) in chunks, with any unconsumed data kept in internal buffers. When a new filter is appended to a stream, data in the internal buffers is processed through the new filter at that time. This differs from the behavior of stream_filter_prepend().
See also stream_filter_register(), and stream_filter_prepend()
Adds filtername to the list of filters attached to stream. This filter will be added with the specified params to the beginning of the list and will therefore be called first during stream operations. To add a filter to the end of the list, use stream_filter_append().
By default, stream_filter_prepend() will attach the filter to the read filter chain if the file was opened for reading (i.e. File Mode: r, and/or +). The filter will also be attached to the write filter chain if the file was opened for writing (i.e. File Mode: w, a, and/or +). STREAM_FILTER_READ, STREAM_FILTER_WRITE, and/or STREAM_FILTER_ALL can also be passed to the read_write parameter to override this behavior. See stream_filter_append() for an example of using this parameter.
When using custom (user) filters: stream_filter_register() must be called first in order to register the desired user filter to filtername.
Óçìåßùóç: Stream data is read from resources (both local and remote) in chunks, with any unconsumed data kept in internal buffers. When a new filter is prepended to a stream, data in the internal buffers, which has already been processed through other filters will not be reprocessed through the new filter at that time. This differs from the behavior of stream_filter_append().
See also stream_filter_register(), and stream_filter_append()
(PHP 5)
stream_filter_register -- Register a stream filter implemented as a PHP class derived from php_user_filterstream_filter_register() allows you to implement your own filter on any registered stream used with all the other filesystem functions (such as fopen(), fread() etc.).
To implement a filter, you need to define a class as an extension of php_user_filter with a number of member functions as defined below. When performing read/write operations on the stream to which your filter is attached, PHP will pass the data through your filter (and any other filters attached to that stream) so that the data may be modified as desired. You must implement the methods exactly as described below - doing otherwise will lead to undefined behaviour.
stream_filter_register() will return FALSE if the filtername is already defined.
int filter ( resource in, resource out, int &consumed, bool closing)This method is called whenever data is read from or written to the attached stream (such as with fread() or fwrite()). in is a resource pointing to a bucket brigade which contains one or more bucket objects containing data to be filtered. out is a resource pointing to a second bucket brigade into which your modified buckets should be placed. consumed, which must always be declared by reference, should be incremented by the length of the data which your filter reads in and alters. In most cases this means you will increment consumed by $bucket->datalen for each $bucket. If the stream is in the process of closing (and therefore this is the last pass through the filterchain), the closing parameter will be set to TRUE The filter method must return one of three values upon completion.
Return Value | Meaning |
---|---|
PSFS_PASS_ON | Filter processed successfully with data available in the out bucket brigade. |
PSFS_FEED_ME | Filter processed successfully, however no data was available to return. More data is required from the stream or prior filter. |
PSFS_ERR_FATAL (default) | The filter experienced an unrecoverable error and cannot continue. |
This method is called during instantiation of the filter class object. If your filter allocates or initializes any other resources (such as a buffer), this is the place to do it. Your implementation of this method should return FALSE on failure, or TRUE on success.
When your filter is first instantiated, and yourfilter->onCreate() is called, a number of properties will be available as shown in the table below.
Property | Contents |
---|---|
FilterClass->filtername | A string containing the name the filter was instantiated with. Filters may be registered under multiple names or under wildcards. Use this property to determine which name was used. |
FilterClass->params | The contents of the params parameter passed to stream_filter_append() or stream_filter_prepend(). |
This method is called upon filter shutdown (typically, this is also during stream shutdown), and is executed after the flush method is called. If any resources were allocated or initialzed during onCreate this would be the time to destroy or dispose of them.
The example below implements a filter named strtoupper on the foo-bar.txt stream which will capitalize all letter characters written to/read from that stream.
ÐáñÜäåéãìá 1. Filter for capitalizing characters on foo-bar.txt stream
Output
|
ÐáñÜäåéãìá 2. Registering a generic filter class to match multiple filter names.
|
See Also: stream_wrapper_register(), stream_filter_prepend(), and stream_filter_append()
Identical to file_get_contents(), except that stream_get_contents() operates on an already open file resource and returns the remaining contents, up to maxlength bytes, in a string.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé binary-safe.
See also: fgets(), fread(), and fpassthru().
Returns an indexed array containing the name of all stream filters available on the running system.
ÐáñÜäåéãìá 1. Using stream_get_filters()
Output will be similar to the following Note: there may be more or fewer filters in your version of PHP.
|
See also stream_filter_register(), and stream_get_wrappers()
Returns a string of up to length bytes read from the file pointed to by handle. Reading ends when length bytes have been read, when the string specified by ending is found (which is not included in the return value), or on EOF (whichever comes first).
If an error occurs, returns FALSE.
This function is nearly identical to fgets() except in that it allows end of line delimiters other than the standard \n, \r, and \r\n, and does not return the delimiter itself.
(PHP 4 >= 4.3.0, PHP 5)
stream_get_meta_data -- Retrieves header/meta data from streams/file pointersReturns information about an existing stream. The stream can be any stream created by fopen(), fsockopen() and pfsockopen(). The result array contains the following items:
timed_out (bool) - TRUE if the stream timed out while waiting for data on the last call to fread() or fgets().
blocked (bool) - TRUE if the stream is in blocking IO mode. See stream_set_blocking().
eof (bool) - TRUE if the stream has reached end-of-file. Note that for socket streams this member can be TRUE even when unread_bytes is non-zero. To determine if there is more data to be read, use feof() instead of reading this item.
unread_bytes (int) - the number of bytes currently contained in the read buffer.
The following items were added in PHP 4.3:
stream_type (string) - a label describing the underlying implementation of the stream.
wrapper_type (string) - a label describing the protocol wrapper implementation layered over the stream. See ÐáñÜñôçìá J for more information about wrappers.
wrapper_data (mixed) - wrapper specific data attached to this stream. See ÐáñÜñôçìá J for more information about wrappers and their wrapper data.
filters (array) - and array containing the names of any filters that have been stacked onto this stream. Filters are currently undocumented.
Óçìåßùóç: This function was introduced in PHP 4.3, but prior to this version, socket_get_status() could be used to retrieve the first four items, for socket based streams only.
In PHP 4.3 and later, socket_get_status() is an alias for this function.
Óçìåßùóç: This function does NOT work on sockets created by the Socket extension.
The following items were added in PHP 5.0:
mode (string) - the mode (or permissions) of the URI associated with this stream.
seakable (bool) - whether the current stream can be seeked in.
uri (string) - the URI/filename associated with this stream.
Returns an indexed array containing the name of all socket transports available on the running system.
See also stream_get_filters(), and stream_get_wrappers()
Returns an indexed array containing the name of all stream wrappers available on the running system.
See also stream_wrapper_register()
This function is an alias of stream_wrapper_register(). This function is included for compatability with PHP 4.3.0 and PHP 4.3.1 only. stream_wrapper_register() should be used instead.
(PHP 4 >= 4.3.0, PHP 5)
stream_select -- Runs the equivalent of the select() system call on the given arrays of streams with a timeout specified by tv_sec and tv_usecThe stream_select() function accepts arrays of streams and waits for them to change status. Its operation is equivalent to that of the socket_select() function except in that it acts on streams.
The streams listed in the read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a stream resource is also ready on end-of-file, in which case an fread() will return a zero length string).
The streams listed in the write array will be watched to see if a write will not block.
The streams listed in the except array will be watched for high priority exceptional ("out-of-band") data arriving.
Óçìåßùóç: When stream_select() returns, the arrays read, write and except are modified to indicate which stream resource(s) actually changed status.
The tv_sec and tv_usec together form the timeout parameter, tv_sec specifies the number of seconds while tv_usec the number of microseconds. The timeout is an upper bound on the amount of time that stream_select() will wait before it returns. If tv_sec and tv_usec are both set to 0, stream_select() will not wait for data - instead it will return immediately, indicating the current status of the streams. If tv_sec is NULL stream_select() can block indefinitely, returning only when an event on one of the watched streams occurs (or if a signal interrupts the system call).
On success stream_select() returns the number of stream resources contained in the modified arrays, which may be zero if the timeout expires before anything interesting happens. On error FALSE is returned and a warning raised (this can happen if the system call is interrupted by an incoming signal).
Ðñïåéäïðïßçóç |
Using a timeout value of 0 allows you to instantaneously poll the status of the streams, however, it is NOT a good idea to use a 0 timeout value in a loop as it will cause your script to consume too much CPU time. It is much better to specify a timeout value of a few seconds, although if you need to be checking and running other code concurrently, using a timeout value of at least 200000 microseconds will help reduce the CPU usage of your script. Remember that the timeout value is the maximum time that will elapse; stream_select() will return as soon as the requested streams are ready for use. |
You do not need to pass every array to stream_select(). You can leave it out and use an empty array or NULL instead. Also do not forget that those arrays are passed by reference and will be modified after stream_select() returns.
This example checks to see if data has arrived for reading on either $stream1 or $stream2. Since the timeout value is 0 it will return immediately:
<?php /* Prepare the read array */ $read = array($stream1, $stream2); if (false === ($num_changed_streams = stream_select($read, $write = NULL, $except = NULL, 0))) { /* Error handling */ } elseif ($num_changed_streams > 0) { /* At least on one of the streams something interesting happened */ } ?> |
Óçìåßùóç: Due to a limitation in the current Zend Engine it is not possible to pass a constant modifier like NULL directly as a parameter to a function which expects this parameter to be passed by reference. Instead use a temporary variable or an expression with the leftmost member being a temporary variable:
<?php stream_select($r, $w, $e = NULL, 0); ?>
Óçìåßùóç: Be sure to use the === operator when checking for an error. Since the stream_select() may return 0 the comparison with == would evaluate to TRUE:
<?php if (false === stream_select($r, $w, $e = NULL, 0)) { echo "stream_select() failed\n"; } ?>
Óçìåßùóç: If you read/write to a stream returned in the arrays be aware that they do not necessarily read/write the full amount of data you have requested. Be prepared to even only be able to read/write a single byte.
Windows 98 Note: stream_select() used on a pipe returned from proc_open() may cause data loss under Windows 98.
See also stream_set_blocking()
If mode is FALSE, the given stream will be switched to non-blocking mode, and if TRUE, it will be switched to blocking mode. This affects calls like fgets() and fread() that read from the stream. In non-blocking mode an fgets() call will always return right away while in blocking mode it will wait for data to become available on the stream.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function was previously called as set_socket_blocking() and later socket_set_blocking() but this usage is deprecated.
Óçìåßùóç: Prior to PHP 4.3, this function only worked on socket based streams. Since PHP 4.3, this function works for any stream that supports non-blocking mode (currently, regular files and socket streams).
See also stream_select().
Sets the timeout value on stream, expressed in the sum of seconds and microseconds. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: As of PHP 4.3, this function can (potentially) work on any kind of stream. In PHP 4.3, socket based streams are still the only kind supported in the PHP core, although streams from other extensions may support this function.
This function was previously called as set_socket_timeout() and later socket_set_timeout() but this usage is deprecated.
See also: fsockopen() and fopen().
Output using fwrite() is normally buffered at 8K. This means that if there are two processes wanting to write to the same output stream (a file), each is paused after 8K of data to allow the other to write. stream_set_write_buffer() sets the buffering for write operations on the given filepointer stream to buffer bytes. If buffer is 0 then write operations are unbuffered. This ensures that all writes with fwrite() are completed before other processes are allowed to write to that output stream.
The function returns 0 on success, or EOF if the request cannot be honored.
The following example demonstrates how to use stream_set_write_buffer() to create an unbuffered stream.
Accept a connection on a socket previously created by stream_socket_server(). If timeout is specified, the default socket accept timeout will be overridden with the time specified in seconds. The name (address) of the client which connected will be passed back in peername if included and available from the selected transport.
peername can also be determined later using stream_socket_get_name().
If the call fails, it will return FALSE.
See also stream_socket_server(), stream_socket_get_name(), stream_set_blocking(), stream_set_timeout(), fgets(), fgetss(), fwrite(), fclose(), feof(), and the Curl extension.
Initiates a stream or datagram connection to the destination specified by remote_socket. The type of socket created is determined by the transport specified using standard URL formatting: transport://target. For Internet Domain sockets (AF_INET) such as TCP and UDP, the target portion of the remote_socket parameter should consist of a hostname or IP address followed by a colon and a port number. For Unix domain sockets, the target portion should point to the socket file on the filesystem. The optional timeout can be used to set a timeout in seconds for the connect system call. flags is a bitmask field which may be set to any combination of connection flags. Currently the selection of connection flags is limited to STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT.
Óçìåßùóç: If you need to set a timeout for reading/writing data over the socket, use stream_set_timeout(), as the timeout parameter to stream_socket_client() only applies while connecting the socket.
stream_socket_client() returns a stream resource which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()).
If the call fails, it will return FALSE and if the optional errno and errstr arguments are present they will be set to indicate the actual system level error that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments will always be passed by reference.
Depending on the environment, the Unix domain or the optional connect timeout may not be available. A list of available transports can be retrieved using stream_get_transports(). See ÐáñÜñôçìá L for a list of built in transports.
The stream will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking().
ÐáñÜäåéãìá 1. stream_socket_client() Example
|
Ðñïåéäïðïßçóç |
UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data. |
Óçìåßùóç: ¼ôáí êáèïñßæåôå ìéá áñéèìçôéêÞ äéåýèõíóç IPv6 (ð.÷. fe80::1) ðñÝðåé íá åóùêëåßåôå ôçí IP óå áãêýëåò. Ãéá ðáñÜäåéãìá, tcp://[fe80::1]:80.
Returns the local or remote name of a given socket connection. If want_peer is set to TRUE the remote socket name will be returned, if it is set to FALSE the local socket name will be returned.
See also stream_socket_accept()
The function stream_socket_recvfrom() accepts data from a remote socket up to length bytes. If address is provided it will be populated with the address of the remote socket.
The value of flags can be any combination of the following:
Ðßíáêáò 1. possible values for flags
STREAM_OOB | Process OOB (out-of-band) data. |
STREAM_PEEK | Retrieve data from the socket, but do not consume the buffer. Subsequent calls to fread() or stream_socket_recvfrom() will see the same data. |
ÐáñÜäåéãìá 1. stream_socket_recvfrom() Example
|
See also stream_socket_sendto(), stream_socket_client(), and stream_socket_server().
The function stream_socket_sendto() sends the data specified by data through the socket specified by socket. The address specified when the socket stream was created will be used unless an alternate address is specified in address.
The value of flags can be any combination of the following:
ÐáñÜäåéãìá 1. stream_socket_sendto() Example
|
See also stream_socket_recvfrom(), stream_socket_client(), and stream_socket_server().
Creates a stream or datagram socket on the specified local_socket. The type of socket created is determined by the transport specified using standard URL formatting: transport://target. For Internet Domain sockets (AF_INET) such as TCP and UDP, the target portion of the remote_socket parameter should consist of a hostname or IP address followed by a colon and a port number. For Unix domain sockets, the target portion should point to the socket file on the filesystem. flags is a bitmask field which may be set to any combination of socket creation flags. The default value of flags is STREAM_SERVER_BIND | STREAM_SERVER_LISTEN.
This function only creates a socket, to begin accepting connections use stream_socket_accept().
If the call fails, it will return FALSE and if the optional errno and errstr arguments are present they will be set to indicate the actual system level error that occurred in the system-level socket(), bind(), and listen() calls. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the bind() call. This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments will always be passed by reference.
Depending on the environment, Unix domain sockets may not be available. A list of available transports can be retrieved using stream_get_transports(). See ÐáñÜñôçìá L for a list of bulitin transports.
ÐáñÜäåéãìá 1. stream_socket_server() Example
|
The example below shows how to act as a time server which can respond to time queries as shown in an example on stream_socket_client().
Óçìåßùóç: Most systems require root access to create a server socket on a port below 1024.
ÐáñÜäåéãìá 2. Using UDP server sockets
|
Óçìåßùóç: ¼ôáí êáèïñßæåôå ìéá áñéèìçôéêÞ äéåýèõíóç IPv6 (ð.÷. fe80::1) ðñÝðåé íá åóùêëåßåôå ôçí IP óå áãêýëåò. Ãéá ðáñÜäåéãìá, tcp://[fe80::1]:80.
See also stream_socket_client(), stream_set_blocking(), stream_set_timeout(), fgets(), fgetss(), fwrite(), fclose(), feof(), and the Curl extension.
stream_wrapper_register() allows you to implement your own protocol handlers and streams for use with all the other filesystem functions (such as fopen(), fread() etc.).
To implement a wrapper, you need to define a class with a number of member functions, as defined below. When someone fopens your stream, PHP will create an instance of classname and then call methods on that instance. You must implement the methods exactly as described below - doing otherwise will lead to undefined behaviour.
Óçìåßùóç: As of PHP 5.0.0 the instance of classname will be populated with a context property referencing a Context Resource which may be accessed with stream_context_get_options(). If no context was passed to the stream creation function, context will be set to NULL.
stream_wrapper_register() will return FALSE if the protocol already has a handler.
bool stream_open ( string path, string mode, int options, string opened_path)This method is called immediately after your stream object is created. path specifies the URL that was passed to fopen() and that this object is expected to retrieve. You can use parse_url() to break it apart.
mode is the mode used to open the file, as detailed for fopen(). You are responsible for checking that mode is valid for the path requested.
options holds additional flags set by the streams API. It can hold one or more of the following values OR'd together.
Flag | Description |
---|---|
STREAM_USE_PATH | If path is relative, search for the resource using the include_path. |
STREAM_REPORT_ERRORS | If this flag is set, you are responsible for raising errors using trigger_error() during opening of the stream. If this flag is not set, you should not raise any errors. |
If the path is opened successfully, and STREAM_USE_PATH is set in options, you should set opened_path to the full path of the file/resource that was actually opened.
If the requested resource was opened successfully, you should return TRUE, otherwise you should return FALSE
void stream_close ( void )This method is called when the stream is closed, using fclose(). You must release any resources that were locked or allocated by the stream.
string stream_read ( int count)This method is called in response to fread() and fgets() calls on the stream. You must return up-to count bytes of data from the current read/write position as a string. If there are less than count bytes available, return as many as are available. If no more data is available, return either FALSE or an empty string. You must also update the read/write position of the stream by the number of bytes that were successfully read.
int stream_write ( string data)This method is called in response to fwrite() calls on the stream. You should store data into the underlying storage used by your stream. If there is not enough room, try to store as many bytes as possible. You should return the number of bytes that were successfully stored in the stream, or 0 if none could be stored. You must also update the read/write position of the stream by the number of bytes that were successfully written.
bool stream_eof ( void )This method is called in response to feof() calls on the stream. You should return TRUE if the read/write position is at the end of the stream and if no more data is available to be read, or FALSE otherwise.
int stream_tell ( void )This method is called in response to ftell() calls on the stream. You should return the current read/write position of the stream.
bool stream_seek ( int offset, int whence)This method is called in response to fseek() calls on the stream. You should update the read/write position of the stream according to offset and whence. See fseek() for more information about these parameters. Return TRUE if the position was updated, FALSE otherwise.
bool stream_flush ( void )This method is called in response to fflush() calls on the stream. If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now. Return TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
array stream_stat ( void )This method is called in response to fstat() calls on the stream and should return an array containing the same values as appropriate for the stream.
bool unlink ( string path)This method is called in response to unlink() calls on URL paths associated with the wrapper and should attempt to delete the item specified by path. It should return TRUE on success or FALSE on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support unlinking.
Óçìåßùóç: Userspace wrapper unlink method is not supported prior to PHP 5.0.0.
This method is called in response to rename() calls on URL paths associated with the wrapper and should attempt to rename the item specified by path_from to the specification given by path_to. It should return TRUE on success or FALSE on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support renaming.
Óçìåßùóç: Userspace wrapper rename method is not supported prior to PHP 5.0.0.
This method is called in response to mkdir() calls on URL paths associated with the wrapper and should attempt to create the directory specified by path. It should return TRUE on success or FALSE on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support creating directories. Posible values for options include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE.
Óçìåßùóç: Userspace wrapper mkdir method is not supported prior to PHP 5.0.0.
This method is called in response to rmdir() calls on URL paths associated with the wrapper and should attempt to remove the directory specified by path. It should return TRUE on success or FALSE on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support removing directories. Possible values for options include STREAM_REPORT_ERRORS.
Óçìåßùóç: Userspace wrapper rmdir method is not supported prior to PHP 5.0.0.
This method is called immediately when your stream object is created for examining directory contents with opendir(). path specifies the URL that was passed to opendir() and that this object is expected to explore. You can use parse_url() to break it apart.
array url_stat ( string path, int flags)This method is called in response to stat() calls on the URL paths associated with the wrapper and should return as many elements in common with the system function as possible. Unknown or unavailable values should be set to a rational value (usually 0).
flags holds additional flags set by the streams API. It can hold one or more of the following values OR'd together.
Flag | Description |
---|---|
STREAM_URL_STAT_LINK | For resources with the ability to link to other resource (such as an HTTP Location: forward, or a filesystem symlink). This flag specified that only information about the link itself should be returned, not the resource pointed to by the link. This flag is set in response to calls to lstat(), is_link(), or filetype(). |
STREAM_URL_STAT_QUIET | If this flag is set, your wrapper should not raise any errors. If this flag is not set, you are responsible for reporting errors using the trigger_error() function during stating of the path. |
This method is called in response to readdir() and should return a string representing the next filename in the location opened by dir_opendir().
bool dir_rewinddir ( void )This method is called in response to rewinddir() and should reset the output generated by dir_readdir(). i.e.: The next call to dir_readdir() should return the first entry in the location returned by dir_opendir().
bool dir_closedir ( void )This method is called in response to closedir(). You should release any resources which were locked or allocated during the opening and use of the directory stream.
The example below implements a var:// protocol handler that allows read/write access to a named global variable using standard filesystem stream functions such as fread(). The var:// protocol implemented below, given the URL "var://foo" will read/write data to/from $GLOBALS["foo"].
ÐáñÜäåéãìá 1. A Stream for reading/writing global variables
|
Ïé óõíáñôÞóåéò áõôÝò äéá÷åéñßæïíôáé strings ìå ðïéêßëïõò ôñüðïõò. ÊÜðïéá ðéï åîåéäéêåõìÝíá ôìÞìáôá ãéá áíÜãíùóç ìðïñïýí íá âñåèïýí óôéò ó÷åôéêÝò ìå regular expression êáé URL handling åíüôçôåò.
Ãéá ðëçñïöïñßåò ó÷åôéêÝò ìå ôç óõìðåñéöïñÜ ôùí strings, êõñßùò ùò ðñïò ôç ÷ñÞóç áðëþí êáé äéðëþí åéóáãùãéêþí, êáèþò êáé escape sequences, áíáôñÝîôå óôï ÷ùñßï strings ôçò åíüôçôáò ôýðïé äåäïìÝíùí ôïõ åã÷åéñéäßïõ.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ãéá áêüìá ðéï éêáíÝò óõíáñôÞóåéò äéá÷åßñçóçò êáé åðåîåñãáóßáò strings áíáôñÝîôå óôéò POSIX regular expression óõíáñôÞóåéò êáé óôéò Perl compatible regular expression óõíáñôÞóåéò.
ÅðéóôñÝöåé Ýíá string ìå backslashes ðñéí ôïõò ÷áñáêôÞñåò ðïõ áíáöÝñïíôáé óôçí ðáñÜìåôñï charlist. ÊÜíåé escape ôïõò \n, \r êëð., óå Ýíá üìïéï ìå ôç C óôõë, ÷áñáêôÞñåò ìå êþäéêá ASCII ìéêñüôåñï ôïõ 32 êáé ìåãáëýôåñï ôïõ 126 ìåôáôñÝðïíôáé óå ïêôáäéêÞ áíáðáñÜóôáóç.
Íá åßóôå ðñïóåêôéêïß åÜí èÝëåôå íá êÜíåôå escape ôïõò ÷áñáêôÞñåò 0, a, b, f, n, r, t êáé v. Èá ìåôáôñáðïýí óôïõò \0, \a, \b, \f, \n, \r, \t êáé \v. Óôçí PHP ïé \0 (NULL), \r (carriage return), \n (íÝá ãñáììÞ) êáé \t (tab) åßíáé ðñïêáèïñéóìÝíåò escape sequences, åíþ óôç C êáé ïé õðüëïéðïé åßíáé ðñïêáèïñéóìÝíåò escape sequences.
ÅÜí ç ðáñÜìåôñïò charlist åßíáé "\0..\37", ôüôå èá ãßíïõí escaped üëïé ïé ÷áñáêôÞñåò ðïõ Ý÷ïõí êþäéêá ASCII áðü 0 Ýùò 31.
Ðñéí êáèïñßóåôå ìßá áêïëïõèßá áðü ÷áñáêôÞñåò óôï üñéóìá charlist, âåâáéùèåßôå üôé îÝñåôå ôïõò ÷áñáêôÞñåò ðïõ õðÜñ÷ïõí ìåôáîý áõôþí ðïõ Ý÷åôå ïñßóåé ùò áñ÷Þ êáé ôÝëïò ôïõ ðåäßïõ.
<?php echo addcslashes('foo[ ]', 'A..z'); // output: \f\o\o\[ \] // All upper and lower-case letters will be escaped // ... but so will the [\]^_` and any tabs, line // feeds, carriage returns, etc. ?> |
ÁíáôñÝîôå åðßóçò óôéò: stripcslashes(), stripslashes(), htmlspecialchars(), êáé quotemeta().
ÅðéóôñÝöåé Ýíá string ìå backslashes ðñéí ôïõò ÷áñáêôÞñåò ðïõ ðñÝðåé íá ÷ñçóéìïðïéçèïýí óå database queries êëð. Áõôïß åßíáé: ôá áðëÜ åéóáãùãéêÜ ('), ôÜ äéðëÜ åéóáãùãéêÜ ("), ôï backslash (\) êáé ôï NUL (ôï NULL byte).
Ìßá åíäåéêôéêÞ ÷ñÞóç ôçò addslashes() åßíáé ç åéóáãùãÞ äåäïìÝíùí óå ìßá âÜóç äåäïìÝíùí. Ãéá ðáñÜäåéãìá, ãéá íá åéóáãÜãåôå ôï üíïìá O'reilly óôç âÜóç äåäïìÝíùí, ðñÝðåé íá ôï êÜíåôå escape. Ïé ðåñéóóüôåñåò âÜóåéò õëïðïéïýí ôçí ðñïçãïýìåíç ëåéôïõñãßá ìå ìßá \, ôï ïðïßï óçìáßíåé üôé ôï ðñïçãïýìåíï üíïìá ãßíåôáé O\'reilly. Áõôü ÷ñåéÜæåôáé ìüíï ãéá ôçí åßóïäï ôùí äåäïìÝíùí óôç âÜóç äåäïìÝíùí, ç åðéðëÝïí \ äåí åéóáãÜãåôáé. ¸÷ïíôáò åíåñãïðïéçìÝíç ôçí PHP directive magic_quotes_sybase, ï ÷áñáêôÞñáò ' ãßíåôáé escaped ìå Ýíá Üëëï '.
Ç PHP directive magic_quotes_gpc åßíáé åê ôùí ðñïôÝñùí åíåñãïðïéçìÝíç, êáé óôçí ïõóßá åêôåëåß ôç óõíÜñôçóç addslashes() ãéá üëá ôá GET, POST, êáé COOKIE äåäïìÝíá. Äåí ðñÝðåé íá ÷ñçóéìïðïéåßôáé ôçí addslashes() óå strings, ðïõ Ý÷ïõí Þäç ãßíåé escaped ìå ôçí magic_quotes_gpc, êáèþò ôüôå èá Ý÷åôå êÜíåé äéðëü escape. Ç óõíÜñôçóç get_magic_quotes_gpc() ìðïñåß íá öáíåß ÷ñÞóéìç ãéá ôïí Ýëåã÷ï ôïõ ðñïáíáöåñèÝíôïò.
ÁíáôñÝîôå åðßóçò óôéò: stripslashes(), htmlspecialchars(), quotemeta(), êáé get_magic_quotes_gpc().
(PHP 3>= 3.0.9, PHP 4 , PHP 5)
bin2hex -- ÌåôáôñÝøôå äõáäéêÜ äåäïìÝíá óôç äåêáåîáäéêÞ ôïõò áíáðáñÜóôáóçÅðéóôñÝöåé Ýíá ASCII string ðïõ ðåñéÝ÷åé ôç äåêáåîáäéêÞ áíáðáñÜóôáóç ôçò ðáñáìÝôñïõ str. Ç ìåôáôñïðÞ ãßíåôáé byte-wise ìå ðñþôç ôç high-nibble.
Ç ëåéôïõñãßá ôçò óõíÜñôçóçò áõôÞò åßíáé áêñéâþò ç ßäéá ìå áõôÞí ôçò rtrim().
Óçìåßùóç: Ç óõíÜñôçóç chop() äéáöÝñåé áðü ôçí chop() ôçò Perl, ç ïðïßá áöáéñåß ôïí ôåëåõôáßï ÷áñáêôÞñá ôïõ string.
ÅðéóôñÝöåé Ýíá string ìåãÝèïõò åíüò ÷áñáêôÞñá, ôï ïðïßï ðåñéÝ÷åé ôï ÷áñáêôÞñá ðïõ ðñïóäéïñßæåôáé áðü ôçí ðáñÜìåôñï ascii.
Ôïí ðßíáêá ASCII ìðïñåßôå íá ôïí âñåßôå óôç äéåýèõíóç: http://www.asciitable.com.
Ç óõíÜóôçóç áõôÞ óõìðëçñþíåé ôçí ord() óôç ëåéôïõñãßá. ÁíáôñÝîåôå åðßóçò óôçí sprintf() ãéá string ôýðïõ %c.
Ìðïñåß íá ÷ñçóéìïðïéçèåß ãéá íá ÷ùñßóåé Ýíá string óå ìéêñüôåñá ìÝñç, ôï ïðïßï, ðáñáäåßãìáôïò ÷Üñç, ìðïñåß íá åßíáé ÷ñÞóéìï ãéá ôç ìåôáôñïðÞ ôïõ base64_encode þóôå íá ôáéñéÜæåé óôá RFC 2045 semantics. Ôïðïèåôåß ôçí ðáñÜìåôñï end (ç ïðïßá åßíáé åê ôùí ðñïôÝñùí åßíáé "\r\n") áíÜ chunklen ðëÞèïò ÷áñáêôÞñùí (ç ïðïßá åßíáé åê ôùí ðñïôÝñùí åßíáé 76). ÔÝëïò, åðéóôñÝöåé Ýíá íÝï string áöÞíïíôáò ôï áñ÷éêü ÷ùñßò áëëáãÝò.
ÁíáôñÝîôå åðßóçò óôéò: explode(), split(), wordwrap() êáé óôç äéåýèõíóç RFC 2045.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
convert_cyr_string -- ÌåôáôñïðÞ áðü ôï êõñéëëéêü óýíïëï ÷áñáêôÞñùí óå êÜðïéï ÜëëïÇ óõíÜñôçóç áõôÞ åðéóôñÝöåé ôï äïèÝí string Ý÷ïíôáò ìåôáôñÝøåé ôï êõñéëëéêü óýíïëï ÷áñáêôÞñùí, ðïõ áñ÷éêÜ åß÷å, óå êÜðïéï Üëëï. Ôá ïñßóìáôá from êáé to åßíáé áðëïß ÷áñáêôÞñåò ðïõ áíáðáñéóôïýí ôá êõñéëëéêÜ óýíïëá ÷áñáêôÞñùí ðçãÞò êáé óôü÷ïõ. Ïé õðïóôçñéæüìåíïé ôýðïé åßíáé ïé áêüëïõèïé:
k - koi8-r
w - windows-1251
i - iso8859-5
a - x-cp866
d - x-cp866
m - x-mac-cyrillic
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 , PHP 5)
count_chars -- ÅðéóôñïöÞ ðëçñïöïñéþí ó÷åôéêþí ìå ôïõò ÷áñáêôÞñåò ðïõ ðåñéÝ÷ïíôáé óå Ýíá stringÌåôñÜ ôï ðëÞèïò ôùí åìöáíßóåùí êÜèå byte-value (0..255) óôï string êáé ôï åðéóôñÝöåé ìå ðïéêßëïõò ôñüðïõò. Ç ðñïáéñåôéêÞ ðáñÜìåôñïò mode ôßèåôáé åê ôùí ðñïôÝñùí óôï 0. ÁíÜëïãá ìå ôçí ôéìÞ ôçò mode ç óõíÜñôçóç count_chars() åðéóôñÝöåé Ýíá áðü ôá áêüëïõèá:
0 - Ýíáí ðßíáêá ìå ôçí byte-value ùò êëåéäß êáé ôç óõ÷íüôçôá ôïõ êÜèå byte ùò ôéìÞ.
1 - ôï ßäéï ìå ôï ðñïçãïýìåíï, ìüíï ðïõ åìöáíßæïíôáé ìüíï ïé byte-values ìå óõ÷íüôçôá ìåãáëýôåñç ôïõ ìçäåíüò.
2 - ôï ßäéï ìå ôï 0, ìüíï ðïõ åìöáíßæïíôáé ìüíï ïé byte-values ìå óõ÷íüôçôá ßóç ìå ìçäÝí.
3 - åðéóôñÝöåôáé Ýíá string, ðïõ ðåñéÝ÷åé üëåò ôéò ÷ñçóéìïðïéïýìåíåò byte-values.
4 - åðéóôñÝöåôáé Ýíá string, ðïõ ðåñéÝ÷åé üëåò ôéò á÷ñçóéìïðïßçôåò byte-values.
ÁíáôñÝîôå åðßóçò óôéò: strpos() êáé substr_count().
ÐáñÜãåé ôï cyclic redundancy checksum ðïëõþíõìï, ìÞêïõò 32-bit, ôçò ðáñáìÝôñïõstr. ÁõôÞ ç ëåéôïõñãßá ÷ñçóéìïðïéåßôáé óõíÞèùò ãéá ôïí Ýëåã÷ï ôçò áêåñáéüôçôáò ôùí äåäïìÝíùí ðïõ ìåôáäßäïíôáé.
ÅðåéäÞ ï ôýðïò äïäìÝíùí integer ôçò PHP åßíáé ðñïóçìáóìÝíïò, êáé ðïëëÜ crc32 checksums Ý÷ïõí ùò áðïôÝëåóìá áñíçôéêÜ ðñïóçìáóìÝíïõò integers, åßíáé áðáñáßôçôï íá ÷ñçóéìïðïéåßôå ôçí ðñïäéáãñáöÞ ìïñöïðïßçóçò "%u" ôçò óõíÜñôçóçò sprintf() Þ ôçò printf() ãéá íá ðáßñíåôå ôçí áíáðáñÜóôáóç óå string ôïõ ìç ðñïóçìáóìÝíïõ crc32 checksum.
Ôï áêüëïõèï ðáñÜäåéãìá äåß÷íåé ðþò ìðïñåßôå íá åìöáíßæåôå ôï ìåôáôñåììÝíï checksum ìå ôç óõíÜñôçóç printf():
Ç óõíÜñôçóç crypt() êñõðôïãñáöåß Ýíá string ìå ôç ÷ñÞóç ôïõ óõíçèéóìÝíïõ Unix DES-based áëãïñßèìïõ êñõðôïãñÜöçóçò Þ Üëëùí áëãïñßèìùí ðïõ ìðïñåß íá åßíáé äéáèÝóéìïé óôï óýóôçìá. Ôá ïñßóìáôá åßíáé ôï ðñïò êñõðôïãñÜöçóç string êáé Ýíá ðñïáéñåôéêü salt string ðÜíù óôï ïðïßï âáóßæåôáé ç êñõðôïãñÜöçóç. Ãéá ðëçñïöïñßåò ó÷åôéêÜ ìå ôç óõíÜñôçóç crypt, áíáôñÝîôå óôçí êáôÜëëçëç man óåëßäá ôïõ UNIX.
ÅÜí ôï üñéóìá salt äå äßíåôáé, èá ðáñá÷èåß Ýíá ôõ÷áßï áðü ôçí PHP.
ÊÜðïéá ëåéôïõñãéêÜ óõóôÞìáôá õðïóôçñßæïõí ðåñéóóüôåñïõò ôïõ åíüò ôýðïõò êñõðôïãñÜöçóçò. Óôçí ðñáãìáôéêüôçôá, ìåñéêÝò öïñÝò ç óõíçèéóìÝíç DES-based êñõðôïãñÜöçóç áíôéêáèßóôáôáé áðü Ýíáí MD5-based áëãüñéèìï êñõðôïãñÜöçóçò. Ï ôýðïò ôçò êñõðôïãñÜöçóçò åîáñôÜôáé áðü ôï üñéóìá salt. ÊáôÜ ôç äéÜñêåéá ôçò åãêáôÜóôáóçò, ç PHP ðñïóäéïñßæåé ôéò äõíáôüôçôåò ôçò óõíÜñôçóçò crypt êáé èá äå÷èåß salts êáé ãéá Üëëïõò ôýðïõò êñõðôïãñÜöçóçò. ÅÜí äå äïèåß salt, ç PHP èá ðáñÜîåé áõôüìáôá Ýíá óõíçèéóìÝíï salt, äýï ÷áñáêôÞñùí êáôÜ ðñïôßìçóç, åêôüò åÜí ï ðñïêáèïñéóìÝíïò ôýðïò êñõðôïãñÜöçóçò ôïõ óõóôÞìáôïò åßíáé ï MD5, ïðüôå êáé èá ðáñá÷èåß Ýíá ôõ÷áßï, óõìâáôü ìå ôï MD5 salt. Ç PHP äçìéïõñãåß ìßá óôáèåñÜ ìå ôï üíïìá CRYPT_SALT_LENGTH, ç ïðïßá ïñßæåé åÜí èá åöáñìïóèåß óôï óýóôçìÜ óáò Ýíá óõíçèéóìÝíï salt äýï ÷áñáêôÞñùí Þ Ýíá ìáêñýôåñï äþäåêá ÷áñáêôÞñùí.
ÅÜí êÜíåôå ÷ñÞóç ôïõ ðáñå÷üìåíïõ salt, èá ðñÝðåé íá Ý÷åôå êáôÜ íïõ üôé áõôü ðáñÜãåôáé ìßá ìüíï öïñÜ. Ç áíáäñïìéêÞ êëÞóç ôçò óõíÜñôçóçò ìðïñåß íá Ý÷åé åðéäñÜóåéò ôüóï óôçí åìöÜíéóç üóï êáé óôçí áóöÜëåéá.
Ç óõíçèéóìÝíç DES-based êñõðôïãñÜöçóç ìå ôç óõíÜñôçóç crypt() åðéóôñÝöåé ôï salt ùò ôïõò äýï ðñþôïõò ÷áñáêôÞñåò ôçò åîüäïõ. Åðßóçò ÷ñçóéìïðïéåß ìüíï ôïõò ï÷ôþ ðñþôïõò ÷áñáêôÞñåò ôçò ðáñáìÝôñïõ str, Ýôóé þóôå ìåãáëýôåñá strings ðïõ îåêéíïýí áðü ôïõò ßäéïõò ï÷ôþ ÷áñáêôÞñåò íá ðáñÜãïõí ôï ßäéï áðïôÝëåóìá (üôáí ÷ñçóéìïðïéåßôáé ôï ßäéï salt).
Óå óõóôÞìáôá üðïõ ç óõíÜñôçóç crypt() õðïóôçñßæåé ðïëëáðëïýò ôýðïõò êñõðôïãñÜöçóçò, ïé áêüëïõèåò óôáèåñÝò ôßèåíôáé óôï 0 Þ óôï 1 áíÜëïãá ìå ôï áí ï äïèÝí ôýðïò åßíáé äéáèÝóéìïò:
CRYPT_STD_DES - ÓõíçèéóìÝíç DES-based êñõðôïãñÜöçóç ìå salt äýï ÷áñáêôÞñùí
CRYPT_EXT_DES - ÅêôåôáìÝíç DES-based êñõðôïãñÜöçóç ìå salt åííÝá ÷áñáêôÞñùí
CRYPT_MD5 - MD5 êñõðôïãñÜöçóç ìå salt äþäåêá ÷áñáêôÞñùí îåêéíþíôáò ìå $1$
CRYPT_BLOWFISH - Blowfish êñõðôïãñÜöçóç ìå salt äåêáÝîé ÷áñáêôÞñùí îåêéíþíôáò ìå $2$
Óçìåßùóç: Äåí õðÜñ÷åé óõíÜñôçóç áðïêñõðôïãñÜöçóçò, áöïý ç crypt() ÷ñçóéìïðïéåß áëãüñéèìï ìßáò êáôåýèõíóçò.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò crypt()
|
ÁíáôñÝîôå åðßóçò óôç óõíÜñôçóç md5() êáé óôçí åíüôçôá ç Mcrypt åðÝêôáóç.
Åìöáíßæåé üëåò ôéò ðáñáìÝôñïõò.
Ç echo() äåí åßíáé óôçí ðñáãìáôéêüôçôá ìßá óõíÜñôçóç (åßíáé Ýíá ãëùóóéêü êáôáóêåýáóìá) êé Ýôóé äåí åßóôå áíáãêáóìÝíïé íá ÷ñçóéìïðïéåßôáé ðáñåíèÝóåéò ìå áõôÞí. Óôçí ðñáãìáôéêüôçôá, åÜí èÝëåôå íá ðåñÜóåôå ðÜíù áðü Ýíá üñéóìá óôçí echo, äåí ðñÝðåé íá ðåñéêëåßóåôå ôéò ðáñáìÝôñïõò óå ðáñåíèÝóåéò.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò echo()
|
Ç óõíÜñôçóç echo() Ý÷åé ìßá ðéï óýíôïìç óýíôáîç, üðïõ ôï tag áíïßãìáôïò ìðïñåß íá áêïëïõèåßôáé, áìÝóùò, áðü Ýíá ßóïí. Ç óýíôáîç áõôÞ ëåéôïõñãåß ìüíï åÜí ç ñýèìéóç short_open_tag ôïõ configuration Ý÷åé ôåèåß óå ëåéôïõñãßá.
Ãéá ðåñéóóüôåñï ðñïâëçìáôéóìü áíáöïñéêÜ ìå ôéò äéáöïñÝò ìåôáîý ôùí óõíáñôÞóåùí print() êáé echo(), äéáâÜóôå áõôü ôï FAQTs Knowledge Base Article: http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
Óçìåßùóç: ÅðåéäÞ áõôü åßíáé ìéá äïìÞ ôçò ãëþóóáò êáé ü÷é ìéá óõíÜñôçóç, äåí ìðïñåß íá êáëåóôåß ÷ñçóéìïðïéþíôáò óõíáñôÞóåéò ìåôáâëçôþí
ÅðéóôñÝöåé Ýíáí ðßíáêá áðü strings, êÜèå Ýíá áðü ôá ïðïßá åßíáé Ýíá õðü-string ôçò ðáñáìÝôñïõ string, êáé ó÷çìáôßæåôáé áðü ôç äéáßñåóç ôïõ áñ÷éêïý óå üñéá êáèïñéóìÝíá áðü ôçí ðáñÜìåôñï separator. ÅÜí ç ðáñÜìåôñïò limit Ý÷åé ôåèåß, ï ðñïò åðéóôñïöÞ ðßíáêáò èá ðåñéÝ÷åé Ýíá ìÝãéóôï ðëÞèïò áðü limit óôïé÷åßá ìå ôï ôåëåõôáßï áðü áõôÜ íá ðåñéÝ÷åé ôï õðüëïéðï ôïõ string.
ÅÜí ç ðáñÜìåôñïò separator åßíáé ôï êåíü string (""), ç óõíÜñôçóç explode() èá åðéóôñÝøåé ôçí ôéìÞ FALSE. ÅÜí ç separator ðåñéÝ÷åé ìßá ôéìÞ ðïõ äåí ðåñéÝ÷åôáé óôï üñéóìá string, ôüôå ç explode() èá åðéóôñÝøåé Ýíáí ðßíáêá ðïõ èá ðåñéÝ÷åé ôï áñ÷éêü string.
Áí êáé ç implode() ìðïñåß, ãéá éóôïñéêïýò ëüãïõò, íá äå÷èåß ôçò ðáñáìÝôïõò ôçò ìå ïðïéáäÞðïôå óåéñÜ, ç explode() äåí ìðïñåß. ÐñÝðåé íá âåâáéùèåßôå ôï üñéóìá separator ðñïçãåßôáé ôïõ string.
Óçìåßùóç: Ç ðáñÜìåôñïò limit ðñïóôÝèçêå óôçí Ýêäïóç 4.0.1 ôçò PHP.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò explode()
|
ÁíáôñÝîôå åðßóçò óôéò: preg_split(), spliti(), split(), êáé implode().
Åìöáíßóôå Ýíá string óýìöùíá ìå ôï string öïñìáñßóìáôïò format óôç stream resource ðïõ êáèïñßæåôáé áðü ôçí ðáñÜìåôñï handle..
Ôï string format áðïôåëåßôáé áðü êáìßá Þ ðåñéóóüôåñåò directives: óõíçèéóìÝíïé ÷áñáêôÞñåò (åêôüò ôïõ %) ðïõ áíôéãñÜöïíôáé áð' åõèåßáò óôï áðïôÝëåóìá, êáé ðñïäéáãñáöÝò ìåôáôñïðÞò, êÜèå ìßá åê ôùí ïðïßùí ÷ñçóéìïðïéåß ôç äéêÞ ôçò ðáñÜìåôñï. Ôá ðñïçãïýìåíá ÷ñçóéìïðïéïýíôáé óôéò óõíáñôÞóåéò: fprintf(), sprintf(), êáé printf().
ÊÜèå ðñïäéáãñáöÞ ìåôáôñïðÞò áðüôåëåßôáé áðü ôï åðß ôïéò åêáôü óýìâïëï (%), áêïëïõèïýìåíï áðü Ýíá Þ ðåñéóóüôåñá áðü ôá áêüëïõèá óôïé÷åßá, ìå ôçí áêüëïõèç óåéñÜ:
¸íáí ðñïáéñåôéêü ðñïóäéïñéóôÞ ãåìßóìáôïò, ï ïðïßïò ïñßæåé ôï ÷áñáêôÞñá ðïõ èá ÷ñçóéìïðïéçèåß ãéá ôï ãÝìéóìá ôùí string, áðü ôç äåîéÜ ôïõò ðëåõñÜ. Áõôüò ìðïñåß íá åßíáé Ýíá êåíü Þ ôï 0 (ï ÷áñáêôÞñáò ìçäÝí). Ç ðñïåðéëåãìÝíï åßíáé ôï ãÝìéóìá ìå êåíÜ. ¸íáò Üëëïò ÷áñáêôÞñáò ãåìßóìáôïò ìðïñåß íá êáèïñéóôåß ìå ôï íá ôïðïèåôÞóåôå ìðñïóôÜ ôïõ Ýíá áðëü åéóáãùãéêü ('). ÁíáôñÝîôå óôï ó÷åôéêü ðáñÜäåéãìá.
Åíáí ðñïáéñåôéêü ðñïóäéïñéóôÞ óôïß÷éóçò, ï ïðïßïò ïñßæåé åÜí ôï áðïôÝëóìá èá åßíáé áñéóôåñÞò Þ äåîéÜò óôïß÷êóçò. Ç ðñïêáèïñéóìÝíç åðéëïãÞ åßíáé ç äåîéÜ óôïß÷éóç. ÅÜí ðñïóôåèåß ï ÷áñáêôÞñáò - ôüôå èá ðñïêýøåé áñéóôåñÞ óôïß÷éóç.
¸íáí ðñïáéñåôéêü áñéèìü, Ýíáí ðñïóäéïñéóôÞ ðëÜôïõò ðïõ ïñßæåé ðüóïé ÷áñáêôÞñåò (åëÜ÷éóôï ðëÞèïò) èá ðñÝðåé íá åðéóôñÝøåé ç ìåôáôñïðÞ.
¸íáí ðñïáéñåôéêü ðñïóäéïñéóôÞ áêñßâåéáò, ðïõ ïñßæåé ðüóá äåêáäéêÜ øçößá èá ðñÝðåé íá åìöáíßæïíôáé óôïõò áñéèìïýò êéíçôÞò õðïäéáóôïëÞò. Ç åðéëïãÞ áõôÞ äåí åðéäñÜ óå êÜðïéïí Üëëï ôýðï åêôüò áðü ôïí float. (Ìßá Üëëç ÷ñÞóéìç óõíÜñôçóç ãéá ó÷çìáôéóìü áñéèìþí åßíáé ç number_format().)
¸íáí ðñïóäéïñéóôÞ ôýðïõ ðïõ ïñßæåé ùò ðñïò ðïéï ôýðï èá äéá÷åéñéóôïýí ôá äåäïìÝíá ôùí ïñéóìÜôùí. Ðéèáíïß ôýðïé:
% - ¸íáò åðß ôïéò åêáôï ÷áñáêôÞñáò. Äå ÷ñåéÜæïíôáé ïñßóìáôá. |
b - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé ùò äõáäéêüò áñéèìüò. |
c - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé ùò ÷áñáêôÞñáò ìå ôç óõãêåêñéìÝíç ôéìÞ ùò ôéìÞ ASCII. |
d - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé óáí (ðñïóçìáóìÝíïò) äåêáäéêüò áñéèìüò. |
u - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé óá ìç ðñïóçìáóìÝíïò äåêáäéêüò áñéèìüò. |
f - ôï üñéóìá ìåôá÷åéñßæåôáé óá float, êáé åìöáíßæåôáé óáí áñéèìüò êéíçôÞò õðïäéáóôïëÞò. |
o - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé óáí Ýíáò ïêôáäéêüò áñéèìüò. |
s - ôï üñéóìá ìåôá÷åéñßæåôáé êáé åìöáíßæåôáé óáí Ýíá string. |
x - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer êáé ðáñïõóéÜæåôáé óáí Ýíáò äåêáåîáäéêüò áñéèìüò (ìå ìéêñÜ ãñÜììáôá). |
X - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer êáé ðáñïõóéÜæåôáé óáí Ýíáò äåêáåîáäéêüò áñéèìüò (ìå êåöáëáßá ãñÜììáôá). |
ÁíáôñÝîôå åðßóçò óôéò: printf(), sprintf(), sscanf(), fscanf(), vsprintf(), êáé number_format().
ÐáñÜäåéãìá 1. sprintf(): Integers ðïõ ãåìßæïíôáé ìå ìçäånéêÜ
|
ÐáñÜäåéãìá 2. sprintf(): Ó÷çìáôßæïíôáò íïìéóìáôéêÞ ôéìÞ
|
(PHP 4 , PHP 5)
get_html_translation_table -- ÅðéóôñÝöåé ôïí ðßíáêá ìåôÜöñáóçò ðïõ ÷ñçóéìïðïéåßôáé áðü ôéò óõíáñôÞóåéò htmlspecialchars() êáé htmlentities()Ç óõíÜñôçóç get_html_translation_table() åðéóôñÝöåé ôïí ðßíáêá ìåôÜöñáóçò ðïõ ÷ñçóéìïðïåßôáé åóùôåñéêÜ áðü ôéò óõíáñôÞóåéò htmlspecialchars() êáé htmlentities().
ÕðÜñ÷ïõí äýï íÝåò óôáèåñÝò (HTML_ENTITIES, HTML_SPECIALCHARS) ðïõ óáò åðéôñÝðïõí íá êáèïñßóåôå ôïí ðßíáêá ðïõ åðéèõìåßôå. ¼ðùò óõìâáßíåé êáé óôéò óõíáñôÞóåéò htmlspecialchars() êáé htmlentities() ìðïñåßôå íá ïñßóåôå ðñïáéñåôéêÜ ôçí ðáñÜìåôñï quote_style ìå ôçí ïðïßá êáé äïõëåýåôå. Ç ðñïêáèïñéóìÝíç åßíáé ç ENT_COMPAT ëåéôïõñãßá. ÁíáôñÝîôå óôçí ðåñéãñáöÞ ôùí ëåéôïõñãéþí áõôþí, óôç óõíÜñôçóç htmlspecialchars().
Ìßá Üëëç åíäéáöÝñïõóá ÷ñÞóç ôçò óõíÜñôçóçò åßíáé, ìå ôç âïÞèåéá ôçò array_flip(), ç áëëáãÞ ôçò êáôåýèõíóçò ìåôÜöñáóçò.
Ôï ðåñéÝ÷ïìåíï ôçò ìåôáâëçôÞò $original èá åßíáé: "Hallo & <Frau> & Krämer".ÁíáôñÝîôå åðßóçò óôéò: htmlspecialchars(), htmlentities(), strtr(), êáé array_flip().
Ç ðñïáéñåôéêÞ ðáñÜìåôñïò max_chars_per_line åêöñÜæåé ôï ìÝãéóôï ðëÞèïò ôùí ÷áñáêôÞñùí áíÜ ãñáììÞ ðïõ èá óôáëïýí óôçí Ýîïäï. Ç óõíÜñôçóç ðñïóðáèåß íá áðïöýãåé ôç äéáßñåóç ôùí ëÝîåùí.
ÁíáôñÝîôå åðßóçò óôçí hebrevc()
(PHP 3, PHP 4 , PHP 5)
hebrevc -- ÌåáôñÝøôå logical åâñáúêü êåßìåíï óå visual êåßìåíï ðñïóèÝôïíôáò êáé ôçí áëëáãÞ íÝáò ãñáììÞòÇ óõíÜñôçóç áõôÞ åßíáé üìïéá ìå ôçí hebrev() ìå ôç ìüíç äéáöïñÜ üôé ìåôáôñÝðåé ôéò íÝåò ãñáììÝò (\n) óå "<br>\n". Ç ðñïáéñåôéêÞ ðáñÜìåôñïò max_chars_per_line åêöñÜæåé ôï ìÝ÷éóôï ðëÞèïò ôùí ÷áñáêôÞñùí áíÜ ãñáììÞ ðïõ èá óôáëïýí óôçí Ýîïäï. Ç óõíÜñôçóç ðñïóðáèåß íá áðïöýãåé ôç äéáßñåóç ôùí ëÝîåùí.
ÁíáôñÝîôå åðßóçò óôçí hebrev()
(PHP 4 >= 4.3.0, PHP 5)
html_entity_decode -- ÌåôáôñÝøôå üëåò ôéò HTML ïíôüôçôåò óôïõò êáôÜëëçëïõò ÷áñáêôÞñåòÇ óõíÜñôçóç html_entity_decode() åßíáé åêôåëåß ôçí áíôßóôñïöç ëåéôïõñãßá áðü ôçí htmlentities() ãéáôé ìåôáôñÝðåé üëåò ôéò HTML ïíôüôçôåò ôïõ string óôïõò êáôÜëëçëïõò ÷áñáêôÞñåò.
Ç ðñïáéñåôéêÞ äåýôåñç ðáñÜìåôñïò quote_style óáò åðéôñÝðåé íá ïñßóåôå ôï ôé èá ãßíåé ìå ôá 'áðëÜ' êáé ôá "äéðëÜ" åéóáãùãéêÜ. Ðáßñíåé ìßá áðü ôéò áêüëïõèåò ôñåéò óôáèåñÝò ìå ôçí ðñïåðéëåãìÝíç íá åßíáé ç ENT_COMPAT:
Ðßíáêáò 1. ÄéáèÝóéìåò quote_style óôáèåñÝò
¼íïìá óôáèåñÜò | ÐåñéãñáöÞ |
---|---|
ENT_COMPAT | Èá ìåôáôñÝøåé ôá äéðëÜ åéóáãùãéêÜ êáé èá áöÞóåé ôá áðëÜ áíÝããé÷ôá. |
ENT_QUOTES | Èá ìåôáôñÝøåé ôá äéðëÜ êáé ôá áðëÜ åéóáãùãéêÜ. |
ENT_NOQUOTES | Äå èá ìåôáôñÝøåé ôá äéðëÜ êáé ôá áðëÜ åéóáãùãéêÜ. |
Ç ðñïêáèïñéóìÝíç åðéëïãÞ ãéá ôçí ðáñÜìåôñï charset åßíáé ôï óýíïëï ÷áñáêôÞñùí ISO-8859-1. ÁõôÞ ïñßæåé ôï óýíïëï ÷áñáêôÞñùí ðïõ èá ÷ñçóéìïðïéçèåß êáôÜ ôç ìåôáôñïðÞ. Ç õðïóôÞñéîç ãéá ôçí ôñßôç áõôÞ ðáñÜìåôñï ðñïóôÝèçêå óôçí 4.1.0.
Ç Ýêäïóç PHP 4.3.0 êáé ïé íåþôåñåò áõôÞò õðïóôçñßæïõí ôá áêüëïõèá óýíïëá ÷áñáêôÞñùí:
Ðßíáêáò 2. Õðïóôçñéæüìåíá óýíïëá ÷áñáêôÞñùí
Óýíïëï ÷áñáêôÞñùí | Äåýôåñç ïíïìáóßá | ÐåñéãñáöÞ |
---|---|---|
ISO-8859-1 | ISO8859-1 | Western European, Latin-1 |
ISO-8859-15 | ISO8859-15 | Western European, Latin-9. ÐåñéÝ÷åé åðéðëÝïí ôï óýìâïëï ôïõ Åõñþ, êáèþò åðßóçò ãáëëéêÜ êáé öéíëáíäéêÜ ãñÜììáôá, ðïõ äåí ðåñéëáìâÜíïíôáé óôï Latin-1(ISO-8859-1). |
UTF-8 | Óõìâáôü ìå ASCII, multi-byte 8-bit Unicode. | |
cp866 | ibm866, 866 | Óýíïëï ÷áñáêôÞñùí ôïõ DOS ãéá ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
cp1251 | Windows-1251, win-1251, 1251 | Óýíïëï ÷áñáêôÞñùí ôùí Windows ãéá ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
cp1252 | Windows-1252, 1252 | Óýíïëï ÷áñáêôÞñùí ôùí Windows ãéá Western European. |
KOI8-R | koi8-ru, koi8r | Ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
BIG5 | 950 | ÐáñáäïóéáêÜ êéíÝæéêá, êõñßùò áõôÜ ðïõ ÷ñçóéìïðïéïýíôáé óôçí ÔáúâÜí. |
GB2312 | 936 | ÁðëïðïéçìÝíá êéíÝæéêá, ôï åèíéêÜ ÷ñçóéìïðïéïýìåíï óýíïëï ÷áñáêôÞñùí. |
BIG5-HKSCS | Big5 ìå åðåêôÜóåéò ãéá ôï Hong Kong, ðáñáäïóéêÜ êéíÝæéêá. | |
Shift_JIS | SJIS, 932 | Japanese |
EUC-JP | EUCJP | ÃéáðùíÝæéêá |
Óçìåßùóç: Óôç èÝóç ïðïéïõäÞðïôå óõíüëïõ ÷áñáêôÞñùí ðïõ äåí áíáãíùñßæåôáé èá ÷ñçóéìïðïéçèåß ôï ISO-8859-1.
ÐáñÜäåéãìá 1. Áðïêùäéêïðïéþíôáò html ïíôüôçôåò
|
Óçìåßùóç: Ìðïñåß íá áðïñåßôå ãéáôß ç trim(html_entity_decode(' ')); äåí ìåéþíåé ôï ìÞêïò ôïõ string þóôå íá ðñïêýøåé ôï êåíü, ï ëüãïò åßíáé üôé ç ïíôüôçôá ' ' äåí åßíáé ï êþäéêáò ASCII 32 (ðïõ ãßíåôáé êåíüò ÷áñáêôÞñáò áðü ôç óõíÜñôçóç trim()) áëëÜ ï êþäéêáò ASCII code 160 (0xa0) óôï ðñïêáèïñéóìÝíï óýíïëï ÷áñáêôÞñùí ISO8859-1.
ÁíáôñÝîôå åðßóçò óôéò: htmlentities(), htmlspecialchars(), get_html_translation_table(), htmlspecialchars() êáé urldecode().
Ç óõíÜñôçóç åßíáé üìïéá, áðü êÜèå Üðïøç, ìå ôçí htmlspecialchars(), åêôüò ôïõ üôé ìå ôçí htmlentities(), êÜèå ÷áñáêôÞñáò ðïõ Ý÷åé ìßá áíôßóôïé÷ç HTML ïíôüôçôá ìåôáöñÜæåôáé óå áõôÞ.
¼ðùò êáé óôç óõíÜñôçóç htmlspecialchars(), ç ðñïáéñåôéêÞ äåýôåñç ðáñÜìåôñïò quote_style óáò åðéôñÝðåé íá ïñßóåôå ôé èá ãßíåé ìå ôá 'áðëÜ' êáé "äéðëÜ" åéóáãùãéêÜ. ÄÝ÷åôáé ìßá áðü ôéò ôñåéò óôáèåñÝò ìå ðñïêáèïñéóìÝíç ôçí ENT_COMPAT:
Ðßíáêáò 1. ÄéáèÝóéìåò quote_style óôáèåñÝò
¼íïìá óôáèåñÜò | ÐåñéãñáöÞ |
---|---|
ENT_COMPAT | Èá ìåôáôñÝøåé ôá äéðëÜ åéóáãùãéêÜ êáé èá áöÞóåé ôá áðëÜ áíÝããé÷ôá. |
ENT_QUOTES | Èá ìåôáôñÝøåé ôá äéðëÜ êáé ôá áðëÜ åéóáãùãéêÜ. |
ENT_NOQUOTES | Äå èá ìåôáôñÝøåé ôá äéðëÜ êáé ôá áðëÜ åéóáãùãéêÜ. |
Ç õðïóôÞñéîç ãéá ôçí ðñïáéñåôéêÞ ðáñÜìåôñï quote ðñïóôÝèçêå óôçí Ýêäïóç 4.0.4 ôçò PHP.
¼ðùò ç óõíÜñôçóç htmlspecialchars(), Ýôóé êáé áõôÞ ÷ñåéÜæåôáé Ýíá ðñïáéñåôéêü ôñßôï üñéóìá charset, ôï ïðïßï ïñßæåé ôï óýíïëï ÷áñáêôÞñùí ðïõ èá ÷ñçóéìïðïéçèåß óôçí ìåôñïðÞ. Ç õðïóôÞñéîç áõôÞò ôçò ðáñáìÝôñïõ ðñïóôÝèçêå óôçí Ýêäïóç 4.1.0 ôçò PHP. Ðñïò ôï ðáñüí, ôï ðñïêáèïñéóìÝíï óýíïëï ÷áñáêôÞñùí ISO-8859-1.
Ç Ýêäïóç PHP 4.3.0 êáé ïé íåþôåñåò áõôÞò õðïóôçñßæïõí ôá áêüëïõèá óýíïëá ÷áñáêôÞñùí:
Ðßíáêáò 2. Õðïóôçñéæüìåíá óýíïëá ÷áñáêôÞñùí
Óýíïëï ÷áñáêôÞñùí | Äåýôåñç ïíïìáóßá | ÐåñéãñáöÞ |
---|---|---|
ISO-8859-1 | ISO8859-1 | Western European, Latin-1 |
ISO-8859-15 | ISO8859-15 | Western European, Latin-9. ÐåñéÝ÷åé åðéðëÝïí ôï óýìâïëï ôïõ Åõñþ, êáèþò åðßóçò ãáëëéêÜ êáé öéíëáíäéêÜ ãñÜììáôá, ðïõ äåí ðåñéëáìâÜíïíôáé óôï Latin-1(ISO-8859-1). |
UTF-8 | Óõìâáôü ìå ASCII, multi-byte 8-bit Unicode. | |
cp866 | ibm866, 866 | Óýíïëï ÷áñáêôÞñùí ôïõ DOS ãéá ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
cp1251 | Windows-1251, win-1251, 1251 | Óýíïëï ÷áñáêôÞñùí ôùí Windows ãéá ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
cp1252 | Windows-1252, 1252 | Óýíïëï ÷áñáêôÞñùí ôùí Windows ãéá Western European. |
KOI8-R | koi8-ru, koi8r | Ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
BIG5 | 950 | ÐáñáäïóéáêÜ êéíÝæéêá, êõñßùò áõôÜ ðïõ ÷ñçóéìïðïéïýíôáé óôçí ÔáúâÜí. |
GB2312 | 936 | ÁðëïðïéçìÝíá êéíÝæéêá, ôï åèíéêÜ ÷ñçóéìïðïéïýìåíï óýíïëï ÷áñáêôÞñùí. |
BIG5-HKSCS | Big5 ìå åðåêôÜóåéò ãéá ôï Hong Kong, ðáñáäïóéêÜ êéíÝæéêá. | |
Shift_JIS | SJIS, 932 | Japanese |
EUC-JP | EUCJP | ÃéáðùíÝæéêá |
Óçìåßùóç: Óôç èÝóç ïðïéïõäÞðïôå óõíüëïõ ÷áñáêôÞñùí ðïõ äåí áíáãíùñßæåôáé èá ÷ñçóéìïðïéçèåß ôï ISO-8859-1.
ÅÜí èÝëåôå áðïêùäéêïðïßçóç (áíôßóôñïöï ëåéôïõñãßá) ìðïñåßôå íá ÷ñçóéìïðïéåßóåôå ôç óõíÜñôçóç html_entity_decode().
ÁíáôñÝîôå åðßóçò óôéò: html_entity_decode(), get_html_translation_table(), htmlspecialchars(), nl2br(), êáé urlencode().
ÊÜðïéïé ÷áñáêôÞñåò Ý÷ïõí ìßá éäéáßôåñç óçìáóßá óôçí HTML, êáé èá Ýðñåðå íá áíáðáñßóôáíôáé áðü áíôéêåßìåíá ôçò HTML ðñïêåéìÝíïõ íá äéáôçñÞóïõí ôç óçìáóßá áõôÞ. Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá string, ôï ïðïßï Ý÷åé êÜðïéåò áðü ôéò ìåôáôñïðÝò õëïðïéçìÝíåò. ÁõôÝò ïé ìåôáöñÜóåéò åßíáé ïé ðéï ÷ñÞóéìåò ðïõ ãßíïííôáé êÜèå ìÝñá óôï web programming. ÅÜí åðéèõìåßôå íá ìåôáöñáóôïýí üëá ôá áíôéêåßìåíá HTML ôüôå ÷ñçóéìïðïéåßóôå ôç óõíÜñôçóç htmlentities().
Ç óõíÜñôçóç áõôÞ ÷ñçóéìåýåé óôç ìç ýðáñîç HTML markup óå öüñìåò êåéìÝíïõ, üðùò óõìâáßíåé óôéò åöáñìïãÝò ôïõ ðéíÜêá ìçíõìÜôùí êáé ôïõ âéâëßïõ åðéóêåðôþí. Ôï ðñïáéñåôéêü äåýôåñï üñéóìá, quote_style, ïñßæåé ôï ôé èá êÜíåé ç óõíÜñôçóç ìå ôïõò ÷áñáêôÞñåò ôùí áðëþí êáé äéðëþí åéóáãùãéêþí. Ç ðñïêáèïñéóìÝíç ëåéôïõñãßá, ENT_COMPAT, åßíáé ìßá ðñïò ôá ðßóù óõìâáôÞ ëåéôïõñãßá, ç ïðïßá ìåôáöñÜæåé ìüíï ôï ÷áñáêôÞñá äéðëþí åéóáãùãéêþí, áöÞíïíôáò ôá áðëÜ åéóáãùãéêÜ áìåôÜöñáóôá. ÅÜí åðéëåãåß ç ENT_QUOTES, êáé ôá äýï åßäç åéóáãùãéêþí èá ìåôáöñáóôïýí, åíþ óôçí ðåñßðôùóç ôçò ENT_NOQUOTES äåí ðñüêåéôáé íá ìåôáöñáóôåß êáíÝíá åßäïò åéóáãùãéêïý.
Ïé ìåôáöñÜóåéò ðïõ õëïðïéïýíôáé åßíáé ïé áêüëïõèåò:
'&' ("êáé" êáëëéãñáöéêü) ãßíåôáé '&'
'"' (äéðëÜ åéóáãùãéêÜ) ãßíåôáé '"' üôáí äåí Ý÷åé ôåèåß ç ENT_NOQUOTES.
''' (áðëÜ åéóáãùãéêÜ) ãßíåôáé ''' ìüíï üôáí Ý÷åé ôåèåß ç ENT_QUOTES.
'<' (ìéêñüôåñï áðü) ãßíåôáé '<'
'>' (ìåãáëýôåñï áðü) ãßíåôáé '>'
Ðáñáôçñåßóôå üôé áõôÞ ç óõíÜñôçóç äå ìåôáöñÜæåé êÜôé Üëëï åêôüò áõôþí ðïõ ðñïáíáöÝñèçêáí. Ãéá ðëÞñç ìåôÜöñáóç ïíôïôÞôùí áíáôñÝîôå óôç óõíÜñôçóç htmlentities(). Ç õðïóôÞñçîç ôçò ðñïáéñåôéêÞò äåýôåñçò ðáñáìÝôñïõ ðñïóôÝèçêå óôçí PHP 3.0.17 êáé ôçí PHP 4.0.3.
Ôï ôñßôï üñéóìá charset ïñßæåé ôï óýíïëï ÷áñáêôÞñùí ðïõ èá ÷ñçóéìïðïéçèïýí êáôÜ ôç ìåôáôñïðÞ. Ôï ðñïêáèïñéóìÝíï óýíïëï åßíáé ôï ISO-8859-1. Ç õðïóôÞñéîç ôçò ôñßôçò ðáñáìÝôñïõ ðñïóôÝèçêå óôçí PHP 4.1.0.
Ç Ýêäïóç PHP 4.3.0 êáé ïé íåþôåñåò áõôÞò õðïóôçñßæïõí ôá áêüëïõèá óýíïëá ÷áñáêôÞñùí:
Ðßíáêáò 1. Õðïóôçñéæüìåíá óýíïëá ÷áñáêôÞñùí
Óýíïëï ÷áñáêôÞñùí | Äåýôåñç ïíïìáóßá | ÐåñéãñáöÞ |
---|---|---|
ISO-8859-1 | ISO8859-1 | Western European, Latin-1 |
ISO-8859-15 | ISO8859-15 | Western European, Latin-9. ÐåñéÝ÷åé åðéðëÝïí ôï óýìâïëï ôïõ Åõñþ, êáèþò åðßóçò ãáëëéêÜ êáé öéíëáíäéêÜ ãñÜììáôá, ðïõ äåí ðåñéëáìâÜíïíôáé óôï Latin-1(ISO-8859-1). |
UTF-8 | Óõìâáôü ìå ASCII, multi-byte 8-bit Unicode. | |
cp866 | ibm866, 866 | Óýíïëï ÷áñáêôÞñùí ôïõ DOS ãéá ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
cp1251 | Windows-1251, win-1251, 1251 | Óýíïëï ÷áñáêôÞñùí ôùí Windows ãéá ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
cp1252 | Windows-1252, 1252 | Óýíïëï ÷áñáêôÞñùí ôùí Windows ãéá Western European. |
KOI8-R | koi8-ru, koi8r | Ñþóéêá. Áõôü ôï óýíïëï ÷áñáêôÞñùí õðïóôçñßæåôáé áðü ôçí Ýêäïóç 4.3.2 êáé ìåôÜ. |
BIG5 | 950 | ÐáñáäïóéáêÜ êéíÝæéêá, êõñßùò áõôÜ ðïõ ÷ñçóéìïðïéïýíôáé óôçí ÔáúâÜí. |
GB2312 | 936 | ÁðëïðïéçìÝíá êéíÝæéêá, ôï åèíéêÜ ÷ñçóéìïðïéïýìåíï óýíïëï ÷áñáêôÞñùí. |
BIG5-HKSCS | Big5 ìå åðåêôÜóåéò ãéá ôï Hong Kong, ðáñáäïóéêÜ êéíÝæéêá. | |
Shift_JIS | SJIS, 932 | Japanese |
EUC-JP | EUCJP | ÃéáðùíÝæéêá |
Óçìåßùóç: Óôç èÝóç ïðïéïõäÞðïôå óõíüëïõ ÷áñáêôÞñùí ðïõ äåí áíáãíùñßæåôáé èá ÷ñçóéìïðïéçèåß ôï ISO-8859-1.
ÁíáôñÝîôå åðßóçò óôéò: get_html_translation_table(), htmlentities(), êáé nl2br().
ÅðéóôñÝöåé Ýíá string ðïõ ðåñéÝ÷åé ôçí áíáðáñÜóôáóç óå string üëùí ôùí óôïé÷åßùí ôïõ ðßíáêá ìå ôçí ßäéá ðÜíôá óåéñÜ êáé ìå ôï glue string ìåôáîý áõôþí.
Óçìåßùóç: Ç óõíÜñôçóç implode() ìðïñåß, ãéá éóôïñéêïýò ëüãïõò, íá äå÷èåß ôéò ðáñáìÝôñïõò ôçò ìå ïðïðïéáäÞðïôå óåéñÜ. Ãéá óõíï÷Þ, üìùò, ìå ôçí explode(), åßíáé êáëýôåñï íá ÷ñçóéìïðïéåßôáé ôç óåéñÜ ïñéóìÜôùí ðïõ Ý÷åé äïèåß.
Óçìåßùóç: Áðü ôçí PHP 4.3.0, ç ðáñÜìåôñïò glue ôçò implode() åßíáé ðñïáéñåôéêÞ êáé ç ðñïêáèïñéóìÝíç ôéìÞ ôçò åßíáé ôï êåíü string(''). ÁõôÞ äåí åßíáé ç ðñïôéìüìåíç ÷ñÞóç ôçò implode(). Ðñïôåßíïõìå íá ÷ñçóéìïðïéåßôå ðÜíôá üëåò ôéò ðáñáìÝôñïõò ãéá óõìâáôüôçôá ìå ôçò ðáëáéüôåñåò åêäüóåéò.
(PHP 3>= 3.0.17, PHP 4 >= 4.0.1, PHP 5)
levenshtein -- Õðïëïãßóôå ôçí áðüóôáóç Levenshtein ìåôáîý äýï stringsÇ óõíÜñôçóç áõôÞ åðéóôñÝöåé ôçí áðüóôáóç Levenshtein ìåôáîý äýï strings ïñéóìÜôùí Þ ôçí ôéìÞ -1, åÜí êÜðïéï áðü ôá string ïñßóìáôá åßíáé ìåãáëýôåñï áðü ôï üñéï ôùí 255 ÷áñáêôÞñùí (ïé 255 ÷áñáêôÞñåò åßíáé ðåñéóóüôåñï áðü áñêåôïß ãéá ïíüìáôá Þ óõãêñßóåéò óå ëåîéêÜ, êáé åðéðëÝïí êáíåßò äåí ðñüêåéôáé íá êÜíåé ãåííåôéêÞ áíÜëõóç ìå ôçí PHP).
Ç áðüóôáóç Levenshtein ïñßæåôáé ùò ï åëÜ÷éóôïò áñéèìüò ÷áñÜêôçñùí ðïõ ðñÝðåé íá áíôéêáôáóôáèïýí, íá åéóá÷èïýí Þ íá äéáãñáöïýí ãéá íá ìåôáôñáðåß ôï string str1 óôï str2. Ç ðïëõðëïêüôçôá ôïõ áëãïñßèìïõ åßíáé O(m*n), üðïõ ïé ðáñÜìåôñïé n êáé m åßíáé ôá ìÞêç ôïõ str1 êáé ôïõ str2 áíôßóôïé÷á. Ç ðïëõðëïêüôçôá áõôÞ åßíáé áñêåôÜ êáëÞ óõãêñéíüìåíç ìå áõôÞí ôçò óõíÜñôçóçò similar_text(), ç ïðïßá åßíáé O(max(n,m)**3), ðáñáìÝíåé, üìùò, ìåãÜëç.
Óôçí ðéï áðëÞ ôçò ìïñöÞ ç óõíÜñôçóç èá ðÜñåé óáí ðáñáìÝôñïõò ìüíï ôá äýï strings êáé èá õðïëïãßóåé ìïíÜ÷á ôï ðëÞèïò ôùí åéóáãùãþí, äéáãñáöþí êáé áíôéêáôáóôÜóåùí ðïõ ÷ñåéÜæïíôáé ãéá ôç ìåôáôñïðÞ ôïõ str1 óå str2.
Ìßá äåýôåñç ðáñáëëáãÞ ðáßñíåé ôñåéò åðéðëÝïí ðáñáìÝôñïõò ðïõ ïñßæïõí ôá êüóôç ôùí åéóáãùãþí, áíôéêáôáóôÜóåùí êáé ôùí äéáãñáöþí áíôßóôïé÷á. ÁõôÞ åßíáé ðéï ãåíéêÞ êáé åõÝëéêôç áðü ôçí ðñþôç ðáñáëëáãÞ áëëÜ ü÷é êáé ôï ßäéï áðïôåëåóìáôéêÞ.
Ç ôñßôç ðáñáëëáãÞ (ðïõ äåí Ý÷åé åöáñìïóôåß áêüìá) èá åßíáé áêüìá ðéï ãåíéêÞ êáé åõÝëéêôç, áëëÜ ôáõôï÷ñüíùò êáé ç ðéï áñãÞ. Èá êáëåß ìßá ðáñå÷üìåíç áðü ôï ÷ñÞóôç óõíÜñôçóç, ç ïðïßá èá õðïëïãßæåé ôï êüóôïò êÜèå ëåéôïõñãßáò.
Ç ðáñå÷üìåíç áðü ôï ÷ñÞóôç óõíÜñôçóç èá êáëåßôáé ìå ôá áêüëïõèá ïñßóìáôá:
ëåéôïõñãßá ðïõ èá åêôåëåóôåß: 'I', 'R' Þ 'D'
ðñáãìáôéêüò ÷áñáêôÞñáò óôï string 1
ðñáãìáôéêüò ÷áñáêôÞñáò óôï string 2
èÝóç óôï string 1
èÝóç óôï string 2
õðïëïéðüìåíïé ÷áñáêôÞñåò óôï string 1
õðïëïéðüìåíç ÷áñáêôÞñåò óôï string 2
Ç ðáñå÷üìåíç áðü ôï ÷ñÞóôç óõíÜñôçóç ðñïóöÝñåé ôç äõíáôüôçôá íá ëçöèåß õð' üøéí ç ó÷Ýóç êáé/Þ ç äéáöïñÜ ìåôáîý êÜðïéùí óõìâüëùí (÷áñáêôÞñùí) Þ áêüìá êáé ôï ãåíéêü ðëáßóéï óôï ïðïßï åìöáíßæïíôáé ôá óýìâïëá áõôÜ, ðñïêåéìÝíïõ íá õðïëïãéóôåß ôï êüóôïò åéóáãùãÞò, áíôéêáôÜóôáóçò êáé äéáãñáöÞò, áëëÜ üëá áõôÜ åéò âÜñïò ôùí âåëôéóôïðïéÞóåùí ðïõ Ýãéíáí óôç ÷ñÞóç ôùí êáôá÷ùñçôþí ôçò cpu êáé ôùí áóôï÷éþí ôçò cache êáôÜ ôéò ðñïçãïýìåíåò ðáñáëëáãÝò.
ÁíáôñÝîôå åðßóçò óôéò: soundex(), similar_text(), êáé metaphone().
ÅðéóôñÝöåé Ýíáí associative ðßíáêá, ðïõ ðåñéÝ÷åé ôïðéêÝò ðëçñïöïñßåò ãéá ôï ó÷çìáôéóìü áñéèìþí êáé íïìéóìáôéêþí ðïóïôÞôùí.
Ç óõíÜñôçóç localeconv() åðéóôñÝöåé äåäïìÝíá ðïõ âáóßæïíôáé óôï ôñÝ÷ùí locale üðùò áõôÜ ïñßæïíôáé áðü ôç óõíÜñôçóç setlocale(). Ï ðßíáêáò, ðïõ åðéóôñÝöåôáé, ðåñéÝ÷åé ôá áêüëïõèá ðåäßá:
Óôïé÷åßï ðßíáêá | ÐåñéãñáöÞ | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
decimal_point | ×áñáêôÞñáò äåêáäéêïý óçìåßïõ | ||||||||||
thousands_sep | ×áñáêôÞñáò äéÜêñéóçò ôùí ÷éëéÜäùí | ||||||||||
grouping | Ðßíáêáò ðïõ ðåñéÝ÷åé ôá áñéèìçôéêÜ groupings | ||||||||||
int_curr_symbol | ÄéåèíÝò óýìâïëï íïìßóìáôïò (ð.÷. USD) | ||||||||||
currency_symbol | Ôïðéêü óýìâïëï íïìßóìáôïò (ð.÷. $) | ||||||||||
mon_decimal_point | ×áñáêôÞñáò äåêáäéêïý óçìåßïõ ãéá íïìßóìáôá | ||||||||||
mon_thousands_sep | ×áñáêôÞñáò äéÜêñéóçò ÷éëéÜäùí ãéá íïìßóìáôá | ||||||||||
mon_grouping | Ðßíáêáò ðïõ ðåñéÝ÷åé ôá íïìéóìáôéêÜ groupings | ||||||||||
positive_sign | Óýìâïëï ãéá èåôéêÝò ôéìÝò | ||||||||||
negative_sign | Óýìâïëï ãéá áñíçôéêÝò ôéìÝò | ||||||||||
int_frac_digits | ÄéåèíÞ êëáóìáôéêÜ øçößá | ||||||||||
frac_digits | ÔïðéêÜ êëáóìáôéêÜ øçößá | ||||||||||
p_cs_precedes | Åßíáé TRUE åÜí ôï currency_symbol ðñïçãåßôáé ìßáò èåôéêÞò ôéìÞò, åíþ åßíáé FALSE åÜí Ýðåôáé ìéáò. | ||||||||||
p_sep_by_space | Åßíáé TRUE åÜí Ýíá êåíü ÷ùñßæåé ôï currency_symbol áðü ìßá èåôéêÞ ôéìÞ, áëëéþò åßíáé FALSE | ||||||||||
n_cs_precedes | Åßíáé TRUE åÜí ôï currency_symbol ðñïçãåßôáé ìßáò áñíçôéêÞò ôéìÞò, åíþ åßíáé FALSE åÜí Ýðåôáé ìéáò. | ||||||||||
n_sep_by_space | Åßíáé TRUE åÜí Ýíá êåíü ÷ùñßæåé ôï currency_symbol áðü ìßá áñíçôéêÞ ôéìÞ, áëëéþò åßíáé FALSE | ||||||||||
p_sign_posn |
| ||||||||||
n_sign_posn |
|
Ôá ðåäßá grouping ðåñéÝ÷ïõí ðßíáêåò ðïõ ïñßæïõí ôïí ôñüðï ìå ôïí ïðïßï èá ðñÝðåé íá ïìáäïðïéïýíôáé ïé áñéèìïß. Ãéá ðáñÜäåéãìá, ôï ðåäßï grouping ãéá ôï en_US locale, ðñÝðåé íá ðåñéÝ÷åé Ýíáí ðßíáêá äýï óôïé÷åßùí 2 item ìå ôéò ôéìÝò 3 êáé 3. ¼óï ìåãáëýôåñïò åßíáé ï äåßêôçò óå Ýíáí ðßíáêá ôüóï ìåãáëýôåñç åßíáé ç ïìáäïðïßçóç óôá áñéóôåñÜ áõôïý. ÅÜí Ýíá óôïé÷åßï ðßíáêá åßíáé ßóï ìå CHAR_MAX, äåí åðéôñÝðåôáé Üëëç ïìáäïðïßçóç. ÅÜí Ýíá óôïé÷åßï ðßíáêá åßíáé ßóï ìå 0, èá ðñÝðåé íá ÷ñçóéìïðïéçèåß ôï ðñïçãïýìåíï áðü áõôü óôïé÷åßï.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò localeconv()
|
Ç óôáèåñÜ CHAR_MAX ÷ñçóéìïðïéåßôáé êáé ãéá ôçí ðñïáíáöåñèåßóá ÷ñÞóç.
ÁíáôñÝîôå åðßóçò óôç setlocale().
Óçìåßùóç: Ç äåýôåñç ðáñÜìåôñïò ðñïóôÝèçêå óôçí PHP 4.1.0.
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá string ìå ôá êåíÜ íá Ý÷ïõí áöáéñåèåß áðü ôçí áñ÷Þ ôïõ str. ×ùñßò ôç äåýôåñç ðáñÜìåôñï, ltrim() èá áöáéñÝóåé ôïõò áêüëïõèïõò ÷áñáêôÞñåò:
" " (ASCII 32 (0x20)), Ýíá êáíïíéêü êåíü.
"\t" (ASCII 9 (0x09)), Ýíá tab.
"\n" (ASCII 10 (0x0A)), ìßá íÝá ãñáììÞ (line feed).
"\r" (ASCII 13 (0x0D)), Ýíá carriage return.
"\0" (ASCII 0 (0x00)), ôï NUL-byte.
"\x0B" (ASCII 11 (0x0B)), Ýíá êÜèåôï tab.
Ìðïñåßôå åðßóçò íá êáèïñßóåôå ôïõò ÷áñáêôÞñåò ðïõ åðéèõìåßôå íá áöáéñåèïýí ìå ôç ÷ñÞóç ôçò ðáñáìÝôñïõ charlist. ÁðëÜ ãñÜøôå üëïõò ôïõò ÷áñáêôÞñåò ðïõ åðéèõìåßôå íá áöáéñåèïýí. Ìå ôç ÷ñÞóç äýï ôåëåéþí (..) ìðïñåßôå íá ïñßóåôå Ýíá ðåäßï ÷áñáêôÞñùí.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò ltrim()
|
Õðïëïãßæåé ôïí MD5 hash áñéèìü ôïõ filename ìå ôç ÷ñÞóç ôïõ RSA Data Security, Inc. MD5 Message-Digest Algorithm, êáé ôïí åðéóôñÝöåé. Ï hash áñéèìüò åßíáé äåêáåîáäéêüò êáé Ý÷åé ìÞêïò 32 ÷áñáêôÞñùí. ÅÜí ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ôåèåß TRUE, ôüôå åðéóôñÝöåôáé ìßá ðåñßëçøç ôïõ md5 óå ìßá raw binary ìïñöÞ ìå ìÞêïò 16 ÷áñáêôÞñùí.
Óçìåßùóç: Ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ðñïóôÝèçêå óôçí PHP 5.0.0 êáé ç ðñïêáèïñéóìÝíç ôçò ôéìÞ åßíáé FALSE
Ç óõíÜñôçóç áõôÞ Ý÷åé ôçí ßäéá command line ÷ñçóéìüôçôá ìå ôçí md5sum.
ÁíáôñÝîôå åðßóçò óôéò: md5(), crc32(), êáé sha1_file().
Õðïëïãßæåé ôïí MD5 hash áñéèìü ôïõ str ÷ñçóéìïðïéþíôáò ôïí RSA Data Security, Inc. MD5 Message-Digest Algorithm, êáé ôïí åðéóôñÝöåé. Ï hash åßíáé Ýíáò äåêáåîáäéêüò áñéèìüò 32 ÷áñáêôÞñùí. ÅÜí ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ôåèåß óáí TRUE, ôüôå åðéóôñÝöåôáé ìßá ðåñßëçøç ôïõ md5 óå ìßá raw binary ìïñöÞ ìå ìÞêïò 16 ÷áñáêôÞñùí.
Óçìåßùóç: Ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ðñïóôÝèçêå óôçí PHP 5.0.0 êáé ç ðñïêáèïñéóìÝíç ôçò ôéìÞ åßíáé FALSE
ÁíáôñÝîôå åðßóçò óôéò: crc32(), md5_file(), êáé sha1().
Õðïëïãßæåé ôï metaphone êëåéäß ôïõ str.
¼ìïéá ìå ôï metaphone ôçò óõíÜñôçóçò soundex() äçìéïõñãåß ôï ßäéï êëåéäß ãéá üìïéåò ç÷çôéêÜ ëÝîåéò. Åßíáé ðéï áêñéâÞò áðü ôç óõíÜñôçóç soundex() êáèþò ãíùñßæåé ôïõò âáóéêïýò êáíüíåò ôçò áããëéêÞò ðñïöïñÜò. Ôá äçìéïõñãçìÝíá áðü ôï metaphone êëåéäéÜ åßíáé ìåôáâëçôïý ìÞêïõò.
Ôï metaphone áíáðôý÷èçêå áðü ôïí Lawrence Philips <lphilips@verity.com>. ÐåñéãñÜöåôáé óôï ["Practical Algorithms for Programmers", Binstock & Rex, Addison Wesley, 1995].
Ç óõíÜñôçóç money_format() åðéóôñÝöåé ôç ìïñöïðïéçìÝíç Ýêäïóç ôïõ number. Ç óõíÜñôçóç áõôÞ åßíáé ßäéá ìå ôçí strfmon() ôçò âéâëéïèÞêçò ôçò C ìå ôç ìüíç äéáöïñÜ üôé óå êÜèå åöáñìïãÞ ôçò ìåôáôñÝðåôáé Ýíáò áñéèìüò ôç öïñÜ.
Óçìåßùóç: Ç óõíÜñôçóç money_format() ïñßæåôáé ìüíï åÜí ôï óýóôçìá õðïóôçñßæåé ôçí strfmon. Ãéá ðáñÜäåéãìá, ôá Windows äåí ôçí õðïóôçñßæïõí, Ýôóé ç money_format() äåí ïñßæåôáé óôá Windows.
Ç ðñïäéáãñáöÞ ìïñöïðïßçóçò áðüôåëåéôáé áðü ôá áêüëïõèá êáôÜ óåéñÜ óôïé÷åßá:
Ýíáí % ÷áñáêôÞñá
ðñïáéñåôéêÜ flags
ðñïáéñåôêü ðëÜôïò ðåäßïõ
ðñïáéñåôéêÞ áñéóôåñÞ áêñßâåéá
ðñïáéñåôéêÞ äåîéÜ áêñßâåéá
Ýíáí õðï÷ñåùôéêü ÷áñáêôÞñá ìåôáôñïðÞò
Flags. Ìðïñïýí íá ÷ñçóéìïðïéçèïýí Ýíá Þ ðåñéóóüôåñá áðü ôá áêüëïõèá ðñïáéñåôéêÜ:
Ï ÷áñáêôÞñáò = áêïëïõèïýìåíïò áðü Ýíá ÷áñáôêÞñá f (åíüò byte) ãéá íá ÷ñçóéìïðïéçèåß ùò ÷ñáêôÞñáò áñéèìçôéêïý ãåìßóìáôïò. Ï ðñïêáèïñéóìÝíïò ÷áñáêôÞñáò ãåìßóìáôïò åßíáé ôï êåíü.
Áðåíåñãïðïéåßóôå ôç ÷ñÞóç ôùí ÷áñáêôÞñùí ïìáäïðïßçóçò (üðùò áõôïß ïñßæïíôáé áðü ôï ôñÝ÷ùí locale).
Êáèïñßóôå ôï óôõë ìïñöïðïßçóçò ãéá èåôéêïýò êáé áñíçôéêïýò áñéèìïýò. ÅÜí ÷ñçóéìïðïéåßôáé ôï +, èá ÷ñçóéìïðïéçèïýí ôá éóïäýíáìá ôùí +, - ôïõ locale. ÅÜí ÷ñçóéìïðïéçèåß ôï (, ïé áñíçôéêÝò ðïóüôçôåò ðåñéêëåßïíôáé áðü ðáñåíèÝóåéò. ÅÜí äåí õðÜñîåé ðñïóäéïñéóìüò, ôüôå ÷ñçóéìïðïéåßôáé ôï +.
ÁöáéñÝóôå ôï óýìâïëï íïìßóìáôïò áðü ôï string ôçò åîüäïõ.
ÅÜí äßíåôáé, êÜíåé üëá ôá ðåäßá íá óôïé÷ßæïíôáé áñéóôåñÜ (ãÝìéóìá ðñïò ôá äåîéÜ), áíôßèåôá ìå ôçí ðñïêáèïñéóìÝíç óôïß÷éóç ãéá ôá ðåäßá, ðïõ åßíáé ç äåîéÜ (ãÝìéóìá ðñïò ô' áñéóôåñÜ).
ÌÞêïò ðåäßïõ.
¸íá string åíüò äåêáäéêïý øçößïõ, ðïõ êáèïñßæåé Ýíá åëÜ÷éóôï ðëÜôïò ðåäßïõ. Ôï ðåäßï èá óôïé÷çèåß äåîéÜ åêôüò åÜí ÷ñçóéìïðïéçèåß ôï flag -. Ç ðñïêáèïñéóìÝíç ôéìÞ åßíáé ôï 0 (ìçäÝí).
ÁñéóôåñÞ áêñßâåéá.
Ôï ìÝãéóôï ðëÞèïò øçößùí (n) ðïõ áíáìÝíïíôáé óôá áñéóôåñÜ ôïõ äåêáäéêïý ÷áñáêôÞñá (ð.÷. ôï äåêáäéêü óçìåßï). ×ñçóéìïðïéåßôáé óõíÞèùò ãéá íá äéáôçñåßôáé ç Ýîïäïò óôïé÷éóìëåíç óôéò ßäéåò óôÞëåò, ìå ôç ÷ñÞóç ôïõ ÷áñáêôÞñá ãåìßóìáôïò åÜí ôï ðëÞèïò ôùí øçößùí åßíáé ìéêñüôåñï ôïõ n. ÅÜí ôï ðëÞèïò ôùí ðñáãìáôéêþí øçößùí åßíáé ìåãáëýôåñï ôïõ n, ôüôå ç ðñïäéáãñáöÞ ðáñáâëÝðåôáé.
ÅÜí ç ïìáäïðïßçóç äåí Ý÷åé ðáñáëçöèåß ìå ôç ÷ñÞóç ôïõ ^ flag, ïé äéá÷ùñéóôÝò ïìáäïðïéÞóçò èá ðñïóôåèïýí ìðñïóôÜ áðü ôïõò ÷áñáêôÞñåò ïìáäïðïßçóçò (åÜí õðÜñ÷ïõí). Ïé äéá÷ùñéóôÝò ïìáäïðïßçóçò äå èá åöáñìïóôïýí óôïõò ÷áñáêôÞñåò ãåìßóìáôïò, áêüìá êáé áí ï ôåëåõôáßïò åßíáé Ýíá øçößï.
Ãéá ôçí åîáóöÜëéóç ôçò óôïß÷éóçò, ïðïéïéäÞðïôå ÷áñáêôÞñåò åìöáíßæïíôáé ðñßí Þ ìåôÜ ôïí áñéèìü ðïõ äßíåôáé ùò åîüäïò, üðùò åßíáé ôá óýìâïëá íïìßóìáôïò êáé ðñïóÞìïõ, ãåìßæïíôáé üóï ÷ñåéÜæåôáé ìå ÷áñáêôÞñåò êåíïý, ãéá íá ãßíïõí ïé áñíçôéêÝò êáé èåôéêÝò ôïõò ìïñöÝò ßóåò óå ìÞêïò.
ÄåîéÜ áêñßâåéá .
Ìßá ôåëåßá ðïõ áêïëïõèåßôáé áðü ôï ðëÞèïò ôùí øçößùí (p) ìåôÜ ôï äåêáäéêü ÷áñáêôÞñá. ÅÜí ç ôéìÞ ôïõ p åßíáé 0 (ìçäÝí), ï äåêáäéêüò ÷áñáêôÞñáò êáé ôá øçößá óôá äåîéÜ ôïõ èá ðáñáëçöèïýí. ÅÜí äåí õðÜñ÷åé äåîéÜ áêñßâåéá, ôüôå ç ðñïêáèïñéìÝíç èá åßíáé áõôÞ ðïõ èá ïñéóôåß áðü ôçí ôïðéêÜ ÷ñçóéìïðïéïýìåíç. Ôï ìÝãåèïò ðïõ ìïñöïðïéåßôáé óôñïããõëïðïéåßôáé óôïí êáèïñéóìÝíï ðñéí ôç ìïñöïðïßçóç áñéèìü øçößùí.
×áñáêôÞñåò ìåôáôñïðÞò .
Ï áñéèìüò ìïñöïðïéåßôáé óýìöùíá ìå ôç äéåèíÞ íïìéóìáôéêÞ ìïñöÞ, üðùò áõôÞ ïñßæåôáé óôï locale (ð.÷. ãéá ôï USA locale: USD 1,234.56).
Ï áñéèìüò ìïñöïðïéåßôáé óýìöùíá ìå ôçí åèíéêÞ íïìéóìáôéêÞ ìïñöÞ, üðùò áõôÞ ïñßæåôáé óôï locale (ð.÷. ãéá ôï de_DE locale: DM1.234,56).
ÅðéóôñÝöåé Ýíáí % ÷áñáêôÞñá.
Óçìåßùóç: Ç êáôçãïñßá LC_MONETARY ôùí ñõèìßóåùí ôïõ locale, åðçñåÜæåé ôç óõìðåñéöïñÜ ôçò óõíÜñôçóçò. ×ñçóéìïðïéåßóôå ôç óõíÜñôçóç setlocale() ãéá íá êáèïñßóåôå ôï êáôÜëëçëï locale ðñéí ôç ÷ñÞóç áõôÞò ôçò óõíÜñôçóçò.
×áñáêôÞñåò ðñéí êáé ìåôÜ ôï õðü ìïñöïðïßçóç string èá ðáñáìåßíïõí ùò Ý÷ïõí.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ôçò money_format() Èá ÷ñçóéìïðïéÞóïõìå äéáöïñåôéêÜ locales êáé ðñïäéáãñáöÝò ìïñöïðïßçóçò ãéá íá äåßîïõìå ôç ÷ñÞóç ôçò óõíÜñôçóçò.
|
ÁíáôñÝîôå åðßóçò óôéò: setlocale(), number_format(),sprintf(), printf() êáé sscanf().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
ÅðéóôñÝöåé ôï string ìå '<br />' ðñéí áðü êÜèå íÝá ãñáììÞ.
Óçìåßùóç: Îåêéíþíôáò áðü ôçí PHP 4.0.5, ç óõíÜñôçóç nl2br() åßíáé ôþñá ðëÝïí óõìâáôÞ ìå XHTML. ¼ëåò ïé åêäüóåéò ðñéí ôçí 4.0.5 èá åðéóôñÝøïõí ôï string ìå '<br>' ðñéí áðü êÜèå ãñáììÞ áíôß ãéá '<br />'.
ÁíáôñÝîôå åðßóçò óôéò: htmlspecialchars(), htmlentities(), wordwrap() êáé str_replace().
Ç óõíÜñôçóç number_format() åðéóôñÝöåé ôïí number ìå äéáöïñåôéêÞ ìïñöÞ. ÄÝ÷åôáé ìßá, äýï Þ ôÝóóåñéò ðáñáìÝôñïõò (ü÷é ôñåéò):
ÅÜí äïèåß ìßá ìüíï ìßá ðáñÜìåôñïò, ï number èá ìïñöïðïéçèåß ÷ùñßò äåêáäéêÜ øçößá, áëëÜ ìå Ýíá êüììá (",") ìåôáîý êÜèå ïìÜäáò.
ÅÜí äïèïýí äýï ðáñÜìåôñïé, ï number èá ìïñöïðïéçèåß ìå decimals ðëÞèïò äåêáäéêþí ìå ìßá ôåëåßá (".") ìðñïóôÜ ôïõò, êáé ìå Ýíá êüììá ìåôáîý êÜèå ïìÜäùí.
ÅÜí Ý÷ïõí äïèåß êáé ïé ôÝóóåñéò ðáñÜìåôñïé, ï number èá ìïñöïðïéçèåß ìå decimals ðëÞèïò äåêáäéêþí øçößùí, ìå dec_point áíôß ãéá ôåëåßá (".") ðñéí áðü áõôÜ êáé ìå thousands_sep áíôß ãéá êüììá (",") ìåôáîý êÜèå ïìÜäáò.
Èá ÷ñçóéìïðïéçèåß ìüíï ï ðñþôïò ÷áñáêôÞñáò ôçò ðáñáìÝôñïõ thousands_sep. Ãéá ðáñÜäåéãìá, åÜí ÷ñçóéìïðïéÞóåôå ôï foo óáí thousands_sep ãéá ôïí áñéèìü 1000, ôüôå ç óõíÜñôçóç number_format() èá åðéóôñÝøåé 1f000.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò number_format() Ãéá ðáñÜäåéãìá, ç ãáëëéêÞ óçìåéïãñáößá ÷ñçóéìïðïéåß äýï äåêáäéêÜ øçößá, êüììá (',') ùò äéá÷ùñéóôÞ ôùí äåêáäéêþí, êáé êåíü (' ') ìåôáîý ôùí ïìÜäùí ôùí ÷éëéÜäùí. Áõôü åðéôõã÷Üíåôáé ìå ôçí áêüëïõèç ãñáììÞ:
|
ÅðéóôñÝöåé ôçí ôéìÞ ASCII ôïõ ðñþôïõ ÷áñáêôÞñá ôçò ðáñáìÝôñïõ string. Ç óõíÜñôçóç áõôÞ óõìðëçñþíåé óôç ëåéôïõñãßá ôçí chr().
Ìðïñåßôå íá âñåßôå ôïí ðßíáêá ASCII óôç äéåýèõíóç: http://www.asciitable.com.
ÁíáôñÝîôå åðßóçò óôçí chr().
ÊÜíåé parse ôçí ðáñÜìåôñï str óá íá Þôáí ôï query string ðïõ ðåñíéÝôáé ìÝóù åíüò URL êáé èÝôåé ôéò ìåôáâëçôÝò óôï ôñÝ÷ùí ðëáßóéï. ÅÜí ç äåýôåñç ðáñÜìåôñïò arr Ý÷åé ïñéóôåß, ôüôå ïé ìåôáâëçôÝò öõëÜóóïíôáé óá óôïé÷åßá ðßíáêá.
Óçìåßùóç: Ç õðïóôÞñéîç ôçò ðñïáéñåôéêÞò äåýôåñçò ðáñáìÝôñïõ ðñïóôÝèçêå óôçí PHP 4.0.3.
Óçìåßùóç: Ãéá íá ëÜâåôå ôï ôñÝ÷ùí QUERY_STRING, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôç ìåôáâëçôÞ $_SERVER['QUERY_STRING']. Åðßóçò, ìðïñåßôå íá äéáâÜóåôå ôï ëÞììá ìåôáâëçôÝò åîù áðü ôçí PHP.
ÐáñÜäåéãìá 1. ×ñçóéìïðïéþíôáò ôçí parse_str()
|
ÁíáôñÝîôå åðßóçò óôéò: parse_url(), pathinfo(), set_magic_quotes_runtime(), êáé urldecode().
Åìöáíßæåé ôçí ðáñÜìåôñï arg. ÅðéóôñÝöåé ðÜíôá 1.
Ç print() äåí åßíáé ìßá ðñáãìáôéêÞ óõíÜñôçóç (åßíáé Ýíá ãëùóóéêü êáôáóêåýáóìá) Ýôóé äåí åßíáé áðáñáßôçôç ç ÷ñÞóç ðáñÝíèåóåùí ìå ôç ëßóôá ïñéóìÜôùí ôçò.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò print()
|
Ãéá ðåñéóóüôåñï ðñïâëçìáôéóìü áíáöïñéêÜ ìå ôéò äéáöïñÝò ìåôáîý ôùí óõíáñôÞóåùí print() êáé echo(), äéáâÜóôå áõôü ôï FAQTs Knowledge Base Article: http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
Óçìåßùóç: ÅðåéäÞ áõôü åßíáé ìéá äïìÞ ôçò ãëþóóáò êáé ü÷é ìéá óõíÜñôçóç, äåí ìðïñåß íá êáëåóôåß ÷ñçóéìïðïéþíôáò óõíáñôÞóåéò ìåôáâëçôþí
ÐáñÜãåé ìßá Ýîïäï áíÜëïãá ìå ôçí ðáñÜìåôñï format, ç ïðïßá ðåñéãñÜöåôáé óôçí ôåêìçñßùóç ôçò óõíÜñôçóçò sprintf().
ÁíáôñÝîôå åðßóçò óôéò: print(), sprintf(), sscanf(), fscanf(), êáé flush().
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
quoted_printable_decode -- ÌåôáôñÝøôå ôï äïèÝí åêôõðþóéìï string óå Ýíá string ôùí 8 bitÇ óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá 8-bit binary string ðïõ áíôéóôïé÷åß óôï äïèÝí áðïêùäéêïðïéçìÝíï êáé åêôõðþóéìï string. Åßíáé üìïéá ìå ôç óõíÜñôçóç imap_qprint(), åêôüò ôïõ üôé äåí áðáéôåß ôï IMAP module ãéá íá ëåéôïõñãÞóåé.
ÅðéóôñÝöåé ìßá Ýêäïóç ôçò str ìå Ýíáí ÷áñáêôÞñá backslash (\) ðñéí áðü êÜèå ÷áñáêôÞñá, ðïõ åßíáé êÜðïéïò áðü ôïõò:
. \\ + * ? [ ^ ] ( $ ) |
ÁíáôñÝîôå åðßóçò óôéò: addslashes(), htmlentities(), htmlspecialchars(), nl2br(), êáé stripslashes().
Óçìåßùóç: Ç äåýôåñç ðáñÜìåôïò ðñïóôÝèçêå óôçí PHP 4.1.0
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá string ìå ôá êåíÜ íá Ý÷ïõí áöáéñåèåß áðü ôï ôÝëïò ôïõ str. ×ùñßò ôç äåýôåñç ðáñÜìåôñï, ç rtrim() èá áöáéñÝóç ôïõò áêüëïõèïõò ÷áñáêôÞñåò:
" " (ASCII 32 (0x20)), Ýíá êáíïíéêü êåíü.
"\t" (ASCII 9 (0x09)), Ýíá tab.
"\n" (ASCII 10 (0x0A)), ìßá íÝá ãñáììÞ (line feed).
"\r" (ASCII 13 (0x0D)), Ýíá carriage return.
"\0" (ASCII 0 (0x00)), ôï NUL-byte.
"\x0B" (ASCII 11 (0x0B)), Ýíá êÜèåôï tab.
Ìðïñåßôå åðßóçò íá êáèïñßóåôå ôïõò ÷áñáêôÞñåò ðïõ åðéèõìåßôå íá áöáéñåèïýí ìå ôç ÷ñÞóç ôçò ðáñáìÝôñïõ charlist. ÁðëÜ ãñÜøôå üëïõò ôïõò ÷áñáêôÞñåò ðïõ åðéèõìåßôå íá áöáéñåèïýí. Ìå ôç ÷ñÞóç äýï ôåëåéþí (..) ìðïñåßôå íá ïñßóåôå Ýíá ðåäßï ÷áñáêôÞñùí.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò rtrim()
|
Ç ðáñÜìåôñïò category åßíáé ìßá óôáèåñÜ (Þ string) ðïõ ïñßæåé ôçí êáôçãïñßá ôùí óõíáñôÞóåùí, ïé ïðïßåò åðçñåÜæïíôáé áðü ôç ñýèìéóç ôïõ locale:
LC_ALL ãéá üëåò ôéò ðáñáêÜôù
LC_COLLATE ãéá óýãêñéóç strings, áíáôñÝîôå óôç óõíÜñôçóç strcoll()
LC_CTYPE ãéá êáôÜôáîç ÷áñáêôÞñùí êáé ìåôáôñïðÞ, ãéá ðáñÜäåéãìá ç óõíÜñôçóç strtoupper()
LC_MONETARY ãéá ôç óõíÜñôçóç localeconv()
LC_NUMERIC ãéá ôï äéá÷ùñéóôÞ äåêáäéêïý ìÝñïõò (áíáôñÝîôå åðßóçò óôç óõíÜñôçóç localeconv())
LC_TIME ãéá ìïñöïðïßçóç çìåñïìçíßáò êáé þñáò ìå ôç óõíÜñôçóç strftime()
ÅÜí ç ðáñÜìåôñïò locale åßíáé Ýíá êåíü string "", ôá ïíüìáôá ôçò èá ôåèïýí áðü ôéò ôéìÝò ôùí ìåôáâëçôþí ðåñéâÜëëïíôïò ðïõ Ý÷ïõí ôá ßäéá ïíüìáôá ìå ôéò ðáñáðÜíù êáôçãïñßåò, Þ áðü ôï "LANG".
ÅÜí ç ðáñÜìåôñïò locale åßíáé NULL Þ "0", ç ñýèìéóç ôïõ locale äåí åðçñåÜæåôáé, ìüíï ç ôñÝ÷ïõóá ñýèìéóç åðéóôñÝöåôáé.
ÅÜí ç ðáñÜìåôñïò locale åßíáé Ýíáò ðßíáêáò Þ áêïëïõèåßôáé áðü åðéðëÝïí ðáñáìÝôñïõò ôüôå ãßíåôáé ðñïóðÜèåéá, ìÝ÷ñé íá åðéôåõ÷èåß, þóôå êÜèå óôïé÷åßï ôïõ ðßíáêá Þ ðáñÜìåôñïò íá ôåèåß ùò íÝï locale. Ç ëåéôïõñãßá áõôÞ åßíáé ÷ñÞóéìç åÜí Ýíá locale åßíáé ãíùóôü ìå äéÜöïñá ïíüìáôá óå äéáöïñåôéêÜ óõóôÞìáôá Þ ãéá íá ðáñÜó÷åé ëýóç óôçí ðåñßðôùóç ðïõ äåí åßíáé äéáèÝóéìï.
Óçìåßùóç: Ôï ðÝñáóìá äéáöïñåôéêþí locales äåí Þôáí äéáèÝóéìï ðñéí ôçí PHP 4.3.0
Ç óõíÜñôçóç setlocale åðéóôñÝöåé ôï íÝï éó÷ýïí locale, Þ ôçí ôéìÞ FALSE åÜí äåí Ý÷åé åãêáôáóôáèåß ëåéôïõñãßá locale óôçí ðëáôöüñìá óáò Þ ôï óõãêåêñéìÝíï locale äåí õðÜñ÷åé Þ áêüìá êá áí ôï üíïìá ôçò êáôçãïñßáò åßíáé ëÜèïò. ¸íá üíïìá ëÜèïò êáôçãïñßáò ìðïñåß íá ðñïêáëÝóåé ôçí åìöÜíéóç ìçíýìáôïò ëÜèïõò. Ïíüìáôá êáôçãïñéþí/locale ìðïñïýí íá âñåèïýí óôéò åíüôçôåò RFC 1766 and ISO 639.
Óçìåßùóç: Ç åðéóôñåöüìåíç ôéìÞ ôçò óõíÜñôçóçò setlocale() åîáñôÜôáé áðü ôï óýóôçìá óôï ïðïßï ôñÝ÷åé ç PHP. ÅðéóôñÝöåé áêñéâþò ü,ôé êáé ç setlocale ôïõ óõóôÞìáôïò.
Õðüäåéîç: Ç ÷ñÞóôåò ôùí Windows èá âñïõí ÷ñÞóéìåò ðëçñïöïñßåò ãéá ôá locale strings óôï MSDN website ôçò Microsoft. Ôá õðïóóôçñéæüìåíá strings ãëþóóáò ìðïñïýí íá âñåèïýí åäþ êáé ôá õðïóôçñéæüìåíá strings ÷þñáò/ðåñéï÷Þò åäþ. Ôá óõóôÞìáôá Windows õðïóôçñßæïõí ôïõò êþäéêåò ôñéþí ãñáììÜôùí ãéá ôéò ÷þñåò/ðåñéï÷Ýò üðùò áõôïß ïñßæïíôáé áðü ôï ISO 3166-Alpha-3, ôï ïðïßï ìðïñåß íá âñåèåß óôï website ôçò Unicode.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò setlocale()
|
ÐáñÜäåéãìá 2. ÐáñÜäåéãìá ÷ñÞóçò ôçò setlocale() óôá Windows
|
Õðïëïãßæåé ôïí áñéèìü sha1 hash ôïõ áñ÷åßïõ filename ÷ñçóéìïðïéþíôáò ôïí US Secure Hash Algorithm 1, êáé ôïí åðéóôñÝöåé. Ï hash åßíáé Ýíáò äåêáåîáäéêüò áñéèìüò 40 ÷áñáêôÞñùí. Óå ðåñßðôùóç áðïôõ÷ßáò åðéóôñÝöåôáé ç ôéìÞ FALSE. ÅÜí ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ðÜñåé ôçí ôéìÞ TRUE, ôüôå åðéóôñÝöåôáé ìßá ðåñßëçøç ôïõ sha1 óå ìïñöÞ raw binary êáé ìå ìÞêïò 20 ÷áñáêôÞñùí.
Óçìåßùóç: Ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ðñïóôÝèçêå óôçí PHP 5.0.0 êáé ç ðñïêáèïñéóìÝíç ôéìÞ ôçò åßíáé FALSE
ÁíáôñÝîôå åðßóçò óôéò: sha1(), crc32(), êáé md5_file()
Õðïëïãßæåé ôïí áñéèìü sha1 hash ôïõ str ìå ôç ÷ñÞóç ôïõ US Secure Hash Algorithm 1, êáé ôïí åðéóôñÝöåé. Ï hash åßíáé Ýíáò äåêáåîáäéêüò áñéèìüò 40 ÷áñáêôÞñùí. ÅÜí ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ðÜñåé ôçí ôéìÞ TRUE, ôüôå åðéóôñÝöåôáé ìßá ðåñßëçøç ôïõ sha1 óå ìïñöÞ raw binary êáé ìå ìÞêïò 20 ÷áñáêôÞñùí.
Óçìåßùóç: Ç ðñïáéñåôéêÞ ðáñÜìåôñïò raw_output ðñïóôÝèçêå óôçí PHP 5.0.0 êáé ç ðñïêáèïñéóìÝíç ôéìÞ ôçò åßíáé FALSE
ÁíáôñÝîôå åðßóçò óôéò: sha1_file(), crc32(), êáé md5()
ÁõôÞ ç óõíÜñôçóç õðïëïãßæåé ôéò ïìïéüôçôåò ìåôáîý äýï strings, üðùò áõôÝò ðåñéãñÜöïíôáé óôïí øåõäï-êþäéêá Oliver [1993]. Ðáñáôçñåßóôå üôé ç åöáñìïãÞ äå ÷ñçóéìïðïéåß stack üðùò ï ðñïáíáöåñèÝíôáò êþäéêáò, áëëÜ áíáäñïìéêÝò êëÞóåéò, ïé ïðïßåò ìðïñåß Þ ü÷é íá åðéôá÷ýíïõí ôçí üëç äéáäéêáóßá. Ðáñáôçñåßóôå åðßóçò üôé ç ðïëõðëïêüôçôá ôïõ áëãïñßèìïõ åßíáé O(N**3), ìå ôï N åêöñÜæåé ôï ìÞêïò ôïõ ìåãáëýôåñïõ óå ìÞêïò string.
Ðåñíþíôáò ìßá áíáöïñÜ ùò ôñßôï üñéóìá, ç similar_text() èá õðïëïãßóåé ôçí ïìïéüôçôá óå ðïóïóôü åðß ôïéò åêáôü. ÅðéóôñÝöåé ôïí áñéèìü ôùí êïéíþí ÷áñáêôÞñùí, ðïõ âñßóêåôáé óôá äýï strings.
Õðïëïãßæåé ôï soundex key ôçò ðáñáìÝôñïõ str.
Ôá soundex keys Ý÷ïõí ôçí éäéüôçôá üôé üìïéá ðñïöåñüìåíåò ëÝîåéò ðáñÜãïõí ôï ßäéï soundex key, êáé ãéá áõôü ôï ëüãï ìðïñïýí ÷ñçóéìïðïéçèïýí ãéá Ýñåõíåò óå âÜóåéò äåäïìÝíùí, óôéò ïðïßåò åßíáé ãíùóôÞ ç ðñïöïñÜ áëëÜ ü÷é ç ïñèïãñáößá ìßáò ëÝîçò. ÁõôÞ ç óõíÜñôçóç ðáñÜãåé Ýíá string ìÞêïõò 4 ÷áñáêôÞñùí, ôï ïðïßï îåêéíÜåé ìå ãñÜììá.
Ç óõãêåêñéìÝíç soundex óõíÜñôçóç, ðåñéãñÜöåôáé áðü ôïí Donald Knuth óôï âéâëßï ôïõ "The Art Of Computer Programming, vol. 3: Sorting And Searching", Addison-Wesley (1973), pp. 391-392.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò soundex
|
ÁíáôñÝîôå åðßóçò óôéò: levenshtein(), metaphone(), êáé similar_text().
ÅðéóôñÝöåé Ýíá string, ðïõ ðáñÜãåôáé óýìöùíá ìå ôï string format.
Ôï string format óõíôßèåôáé áðü êáìßá Þ ðåñéóóüôåñåò directives: êáíïíéêïß ÷áñáêôÞñåò (åêôüò ôïõ %) ðïõ áíôéãñÜöïíôáé áðåõèåßáò óôï áðïôÝëåóìá, êáé ðñïäéáãñáöÝò ìåôáôñïðÞò, êÜèå ìßá åê ôùí ïðïßùí ÷ñçóéìïðïéåß ôç äéêÞ ôçò ðáñÜìåôñï. Ôá ðñïçãïýìåíá éó÷ýïõí êáé ãéá ôéò óõíáñôÞóåéò sprintf() êáé printf().
ÊÜèå ðñïäéáãñáöÞ ìåôáôñïðÞò áðïôåëåßôáé áðü ôï åðé ôïéò åêáôü óýìâïëï (%), áêïëïõèïýìåíï áðü Ýíá Þ ðåñéóóüôåñá áðü ôá ðáñáêÜôù óôïé÷åßá, ìå ôçí áêüëïõèç óåéñÜ:
¸íáí ðñïáéñåôéêü ðñïóäéïñéóôÞ ãåìßóìáôïò, ï ïðïßïò ïñßæåé ôï ÷áñáêôÞñá ðïõ èá ÷ñçóéìïðïéçèåß ãéá ôï ãÝìéóìá ôùí string, áðü ôç äåîéÜ ôïõò ðëåõñÜ. Áõôüò ìðïñåß íá åßíáé Ýíá êåíü Þ ôï 0 (ï ÷áñáêôÞñáò ìçäÝí). Ç ðñïåðéëåãìÝíï åßíáé ôï ãÝìéóìá ìå êåíÜ. ¸íáò Üëëïò ÷áñáêôÞñáò ãåìßóìáôïò ìðïñåß íá êáèïñéóôåß ìå ôï íá ôïðïèåôÞóåôå ìðñïóôÜ ôïõ Ýíá áðëü åéóáãùãéêü ('). ÁíáôñÝîôå óôï ó÷åôéêü ðáñÜäåéãìá.
Åíáí ðñïáéñåôéêü ðñïóäéïñéóôÞ óôïß÷éóçò, ï ïðïßïò ïñßæåé åÜí ôï áðïôÝëóìá èá åßíáé áñéóôåñÞò Þ äåîéÜò óôïß÷êóçò. Ç ðñïêáèïñéóìÝíç åðéëïãÞ åßíáé ç äåîéÜ óôïß÷éóç. ÅÜí ðñïóôåèåß ï ÷áñáêôÞñáò - ôüôå èá ðñïêýøåé áñéóôåñÞ óôïß÷éóç.
¸íáí ðñïáéñåôéêü áñéèìü, Ýíáí ðñïóäéïñéóôÞ ðëÜôïõò ðïõ ïñßæåé ðüóïé ÷áñáêôÞñåò (åëÜ÷éóôï ðëÞèïò) èá ðñÝðåé íá åðéóôñÝøåé ç ìåôáôñïðÞ.
¸íáí ðñïáéñåôéêü ðñïóäéïñéóôÞ áêñßâåéáò, ðïõ ïñßæåé ðüóá äåêáäéêÜ øçößá èá ðñÝðåé íá åìöáíßæïíôáé óôïõò áñéèìïýò êéíçôÞò õðïäéáóôïëÞò. Ç åðéëïãÞ áõôÞ äåí åðéäñÜ óå êÜðïéïí Üëëï ôýðï åêôüò áðü ôïí float. (Ìßá Üëëç ÷ñÞóéìç óõíÜñôçóç ãéá ó÷çìáôéóìü áñéèìþí åßíáé ç number_format().)
¸íáí ðñïóäéïñéóôÞ ôýðïõ ðïõ ïñßæåé ùò ðñïò ðïéï ôýðï èá äéá÷åéñéóôïýí ôá äåäïìÝíá ôùí ïñéóìÜôùí. Ðéèáíïß ôýðïé:
% - ¸íáò åðß ôïéò åêáôï ÷áñáêôÞñáò. Äå ÷ñåéÜæïíôáé ïñßóìáôá. |
b - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé ùò äõáäéêüò áñéèìüò. |
c - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé ùò ÷áñáêôÞñáò ìå ôç óõãêåêñéìÝíç ôéìÞ ùò ôéìÞ ASCII. |
d - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé óáí (ðñïóçìáóìÝíïò) äåêáäéêüò áñéèìüò. |
u - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé óá ìç ðñïóçìáóìÝíïò äåêáäéêüò áñéèìüò. |
f - ôï üñéóìá ìåôá÷åéñßæåôáé óá float, êáé åìöáíßæåôáé óáí áñéèìüò êéíçôÞò õðïäéáóôïëÞò. |
o - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer, êáé åìöáíßæåôáé óáí Ýíáò ïêôáäéêüò áñéèìüò. |
s - ôï üñéóìá ìåôá÷åéñßæåôáé êáé åìöáíßæåôáé óáí Ýíá string. |
x - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer êáé ðáñïõóéÜæåôáé óáí Ýíáò äåêáåîáäéêüò áñéèìüò (ìå ìéêñÜ ãñÜììáôá). |
X - ôï üñéóìá ìåôá÷åéñßæåôáé óáí integer êáé ðáñïõóéÜæåôáé óáí Ýíáò äåêáåîáäéêüò áñéèìüò (ìå êåöáëáßá ãñÜììáôá). |
Áðü ôçí Ýêäïóç 4.0.6 ôçò PHP ôï string format õðïóôçñßæåé ôçí áñßèìçóç êáé áíôáëëáãÞ ôùí ïñéóìÜôùí. Áêïëïõèåß Ýíá ðáñÜäåéãìá:
ÁíáôñÝîôå åðßóçò óôéò: printf(), sscanf(), fscanf(), vsprintf(), êáé number_format().
Ç óõíÜñôçóç sscanf() åßíáé áíÜëïãç ôçò printf(), áëëÜ ãéá åßóïäï. Ç sscanf() êÜíåé áíÜãíùóç áðü ôï string str êáé ôï ìåôáöñÜæåé óýìöùíá ìå ôï êáèïñéóìÝíï format. ÅÜí ðåñáóôïýí ìüíï äýï ðáñÜìåôñïé óôç óõíÜñôçóç, ôüôå ïé ôéìÝò ðïõ ãßíïíôáé parsed åðéóôñÝöïíôáé ùò Ýíáò ðßíáêáò.
ÏðïéïäÞðïôå êåíü óôï format string ôáéñéÜæåé ìå ôï êÜèå êåíü óôï string åéóüäïõ. Áõôü óçìáßíåé üôé áêüìá êáé Ýíá tab \t ôïõ format string ìðïñåß íá ôáéñéÜîåé ìå Ýíá ÷áñáêôÞñá êåíïý óôï string åéóüäïõ.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò sscanf()
|
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá string Þ Ýíáí ðßíáêá, óôïí ïðïßï ç êÜèå åìöÜíéóç ôçò ðáñáìÝôñïõ search óôï string subject (ignoring case) Ý÷åé áíôéêáôáóôáèåß áðü ôçí ôéìÞ replace. ÅÜí äå èÝëåôå ðåñßðëïêïõò êáíüíåò áíôéêáôÜóôáóçò, èá ðñÝðåé íá ÷ñçóéìïðïéåßôáé áõôÞ ôç óõíÜñôçóç áíôß ôçò eregi_replace() Þ ôçò preg_replace() ìå ôïí modifier i.
ÅÜí ç ðáñÜìåôñïò subject åßíáé Ýíáò ðßíáêáò, ôüôå ç Ýñåõíá êáé ç áíôéêáôÜóôáóç õëïðïéïýíôáé ìå êÜèå óôïé÷åßï ôïõ subject, êáé ç åðéóôñåöüìåíç ôéìÞ åßíáé Ýíáò ðßíáêáò.
ÅÜí ïé ðáñÜìåôñïé search êáé replace åßíáé ðßíáêåò, ôüôå ç óõíÜñôçóç str_ireplace() ðÝñíåé ìßá ôéìÞ áðü êÜèå ðßíáêá êáé ôç ÷ñçóéìïðïéåß ãéá Ýñåõíá êáé áíôéêáôÜóôáóç åðß ôïõ subject. ÅÜí ï ðßíáêáò replace Ý÷åé ëéãüôåñåò ôéìÝò áðü ôïí search, ôüôå ÷ñçóéìïðïéåßôáé Ýíá êåíü string ãéá ôéò õðüëïéðåò ôéìÝò áíôéêáôÜóôáóçò. ÅÜí ç search åßíáé Ýíáò ðßíáêáò êáé ç replace Ýíá string, ôüôå áõôü ôï string áíôéêáôÜóôáóçò ÷ñçóéìïðïéåßôáé ãéá êÜèå ôéìÞ ôïõ search.
Ç óõíÜñôçóç áõôÞ åßíáé binary safe.
Óçìåßùóç: Áðü ôçí PHP 5.0.0 ï áñéèìüò ôùí ôáéñéáóìÝíùí êáé áíôéêáôåóôçìÝíùí needles èá åðéóôñÝöåôáé ìå ôçí ðáñÜìåôñï count, ç ïðïßá èá ðåñíÜôáé ìå áíáöïñÜ. Óôéò åêäüóåéò ðñéí ôçí PHP 5.0.0 ç ðáñÜìåôñïò áõôÞ äåí åßíáé äéáèÝóéìç.
ÁíáôñÝîôå åðßóçò óôéò: str_replace(), ereg_replace(), preg_replace(), êáé strtr().
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé ôï input string áõîçìÝíï áðü ôçí áñéóôåñÞ, ôç äåîéÜ, Þ êáé ôéò äýï ðëåõñÝò êáôÜ ôï ðñïóäéïñéóìÝíï ìÞêïò. ÅÜí ôï ðñïáéñåôéêü üñéóìá pad_string äåí ïñßæåôáé, ôï input ãåìßæåôáé ìå êåíÜ, áëëéþò ãåìßæåôáé ìå ÷áñáêôÞñåò áðü ôï pad_string ìÝ÷ñé ôï üñéï ðïõ ðñïóäéïñßóôçêå.
Ç ðñïáéñåôéêÞ ðáñÜìåôñïò pad_type ìðïñåß íá åßíáé STR_PAD_RIGHT, STR_PAD_LEFT, Þ STR_PAD_BOTH. ÅÜí ç pad_type äåí ïñßæåôáé ëáìâÜíåôáé ùò STR_PAD_RIGHT.
ÅÜí ç ôéìÞ ôçò pad_length åßíáé áñíçôéêÞ Þ ìéêñüôåñç ôïõ ìÞêïõò ôïõ input string, äåí ðñüêåéôáé íá ãßíåé áýîçóç.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò str_pad()
|
Óçìåßùóç: Ôï pad_string ìðïñåß óìéêñõíèåß åÜí ï áðáéôïýìåíïò áñéèìüò ôùí ÷áñáêôÞñùí ãåìßóìáôïò äåí ìðïñåß íá äéáéñÝóåé áêñéâþò ôï ìÞêïò ôïõ pad_string.
ÅðéóôñÝöåé Ýíá string, ðïõ ðåñéÝ÷åé ôçí input_str multiplier öïñÝò. Ç ðáñÜìåôñïò multiplier ðñÝðåé íá åßíáé ìåãáëýôåñç Þ ßóç ìå ôï 0. ÅÜí ç multiplier ôåèåß ßóç ìå ôï 0, ç óõíÜñôçóç èá åðéóôñÝøåé Ýíá êåíü string.
This will output "-=-=-=-=-=-=-=-=-=-=".
ÁíáôñÝîôå åðßóçò óôéò: for, str_pad(), êáé substr_count().
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
str_replace -- ÁíôéêáôÜóôáóç üëùí ôùí åìöáíßóåùí ôïõ search string áðü ôï replace stringÇ óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá string Þ Ýíáí ðßíáêá, üðïõ üëåò ïé åìöáíßóåéò ôïõ search string óôï subject string Ý÷ïõí áíôéêáôáóôáèåß áðü ôç äïóìÝíç ôéìÞ replace. ÅÜí äåí åðéèõìåßôå ðåñßðëïêïõò êáíüíåò áíôéêáôÜóôáóçò, èá ðñÝðåé íá ÷ñçóéìïðïéåßôå áõôÞ ôç óõíÜñôçóç áíôß ôçò ereg_replace() Þ ôçò preg_replace().
Áðü ôçí PHP 4.0.5, êÜèå ðáñÜìåôñïò ôçò óõíÜñôçóçò str_replace() ìðïñåß íá åßíáé ðßíáêáò.
Ðñïåéäïðïßçóç |
Óôéò åêäüóåéò ôçò PHP ðñéí ôçí 4.3.3 õðÞñ÷å Ýíá bug üôáí ãéíüôáí ÷ñÞóç ðéíÜêùí ãéá ôéò ðáñáìÝôñïõò search êáé replace, ëüãù ôïõ ïðïßïõ ïé êåíïß äåßêôåò ôïõ search ðñïóðåñíéüíôïõóáí ÷ùñßò íá õðÜñ÷åé áíôßóôïé÷ç áýîçóç óôïí åóùôåñéêü äåßêôç ôïõ ðßíáêá replace. Áõôü äéïñèþèçêå óôçí PHP 4.3.3, ïðïéáäÞðïôå scripts âáóßæïíôáí óå áõôü ôï bug èá ðñÝðåé íá áöáéñïýí ôéò êåíÝò ôéìÝò search ðñéí ôçí êëÞóç áõôÞò ôçò óõíÜñôçóçò ðñïêåéìÝíïõ íá õðÜñ÷åé ðñïóïìïßùóç ôçò êáíïíéêÞò óõìðåñéöïñÜò. |
ÅÜí ç ðáñÜìåôñïò subject åßíáé Ýíáò ðßíáêáò, ôüôå ç Ýñåõíá êáé ç áíôéêáôÜóôáóç åêôåëåßôáé ãéá êÜèå óôïé÷åßï ôïõ subject, êáé ç åðéóôñåöüìåíç ôéìÞ åßíáé åðßóçò ðßíáêáò.
ÅÜí ç ðáñÜìåôñïé search êáé replace åßíáé ðßíáêåò, ôüôå ç óõíÜñôçóç str_replace() ðáßñíåé ìßá ôéìÞ áðü êÜèå ðßíáêá êáé ôéò ÷ñçóéìïðïéåß ãéá Ýñåõíá êáé áíôéêáôÜóôáóç óôïí ðßíáêá subject. ÅÜí ç replace Ý÷åé ëéãüôåñåò ôéìÝò áðü ôçí search, ôüôå ÷ñçóéìïðïéåßôáé Ýíá êåíü string ãéá ôéò õðüëïéðåò ôéìÝò áíôéêáôÜóôáóçò. ÅÜí ç search åßíáé Ýíáò ðßíáêáò êáé ç replace Ýíá string, ôüôå ÷ñçóéìïðïéåßôáé áõôü ôï string ãéá êÜèå ôéìÞ ôïõ search.
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò str_replace()
|
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç åßíáé binary-safe.
Óçìåßùóç: Áðü ôçí PHP 5.0.0 ï áñéèìüò ôùí ôáéñéáóìÝíùí êáé áíôéêáôåóôçìÝíùí needles èá äßíåôáé áðü ôçí ðáñÜìåôñï count ç áðïßá ðåñíÜôáé êáô' áíáöïñÜ. Ðñéí ôçí PHP 5.0.0 áõôÞ ç ðáñÜìåôñïò äåí åßíáé äéáèÝóéìç.
ÁíáôñÝîôå åðßóçò óôéò: str_ireplace(), substr_replace(), ereg_replace(), preg_replace(), êáé strtr().
Ç óõíÜñôçóç áõôÞ åöáñìüæåé ôçí êùäéêïðïßçóç ROT13 óôï üñéóìá str êáé åðéóôñÝöåé ôï string ôïõ áðïôåëÝóìáôïò. Ç êùäéêïðïßçóç ROT13 áðëÜ êÜíåé shift êÜèå ãñÜììá êáôÜ 13 èÝóåéò ôïõ áëöáâÞôïõ áöÞíïíôáò áðåßñá÷ôïõò üëïõò ôïõò ìç áëöáâçôéêïýò ÷áñáêôÞñåò. Ç êùäéêïðïßçóç êáé ç áðïêùäéêïðïßçóç ãßíïíôáé ìå ôçí ßäéá óõíÜñôçóç, ôï ðÝñáóìá Ýíïò êùäéêïðïéçìÝíïõ string ùò üñéóìá Ý÷åé ùò áðïôÝëåóìá ôçí åðéóôñïöÞ ôçò ìïñöÞò ðïõ åß÷å ðñéí ôçí êùäéêïðïßçóç.
Ç óõíÜñôçóç str_shuffle() áíáêáôåýåé Ýíá string. Ùò Ýîïäïò äßíåôáé ìßá áðü üëåò ôéò äõíáôÝò ìåôáèÝóåéò.
ÌåôáôñÝðåé Ýíá string óå ðßíáêá. ÅÜí ç ðñïáéñåôéêÞ ðáñÜìåôñïò split_length Ý÷åé ïñéóôåß, ï åðéóôñåöüìåíïò ðßíáêáò èá óðáóôåß óå ôìÞìáôá ìå ôï êÜèå Ýíá íá åßíáé ìÞêïõò split_length. Óå äéáöïñåôéêÞ ðåñßðôùóç ôï êÜèå êïììÜôé èá Ý÷åé ìÞêïò åíüò ÷áñáêôÞñá.
ÅÜí ç ðáñÜìåôñïò split_length åßíáé ìéêñüôåñç ôïõ 1, åðéóôñÝöåôáé ç ôéìÞ FALSE. ÅÜí ôï ìÞêïò split_length îåðåñíÜ ôï Þêïò ôïõ string, ôüôå ùò ðñþôï (êáé ìïíáäéêü) óôïé÷åßï ôïõ ðßíáêá ôßèåôáé ôï string.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò str_split()
|
ÁíáôñÝîôå åðßóçò óôéò: preg_split(), split(), count_chars(), str_word_count(), êáé for.
(PHP 4 >= 4.3.0, PHP 5)
str_word_count -- ÅðéóôñÝöåé ðëçñïöïñßåò ó÷åôéêÜ ìå ôéò ëÝîåéò ðïõ ÷ñçóéìïðïéïýíôáé óå Ýíá stringÌåôñÜåé ôï ðëÞèïò ôùí ëÝîåùí ðïõ âñßóêïíôáé óôï string. ÅÜí ç ðñïáéñåôéêÞ ðáñÜìåôñïò format äåí Ý÷åé ïñéóôåß, ôüôå ç åðéóôñåöüìåíç ôéìÞ èá åßíáé Ýíáò integer, ï ïðïßïò èá áíáðáñéóôÜ ôï ðëÞèïò ôùí ëÝîåùí ðïõ âñÝèçêáí. Óå ðåñßðôùóç ðïõ ç format Ý÷åé ïñéóôåß, ç åðéóôñåöüìåíç ôéìÞ èá åßíáé Ýíáò ðßíáêáò, ôï ðåñéå÷üìåíï ôïõ ïðïßïõ åîáñôÜôáé áðü ôçí format. Ïé ðéèáíÝò ôéìÝò ãéá ôçí ðáñÜìåôñï format êáé ôá áðïôåëÝóìáôá êÜèå ìéáò áíáöÝñïíôáé áêïëïýèùò.
1 - åðéóôñÝöåé Ýíáí ðßíáêá, ðïõ ðåñéÝ÷åé üëåò ôéò ëÝîåéò ðïõ âñÝèçêáí óôï string.
2 - ÅðéóôñÝöåé Ýíáí associative ðßíáêá, üðïõ ï äåßêôçò åßíáé ï áñéèìüò ôçò èÝóçò ôçò ëÝîçò åíôüò ôïõ string êáé ç ôéìÞ ôïõ óôïé÷åßïõ åßíáé ç ßäéá ç ëÝîç.
Ãéá ôïõò óêïðïýò áõôÞò ôçò óõíÜñôçóçò, ç 'ëÝîç' ïñßæåôáé ùò Ýíá åîáñôüìåíï áðü ôï locale string, ôï ïðïßï ðåñéÝ÷åé áëöáâçôéêïýò ÷áñáêôÞñåò, êáé ðïõ ìðïñåß åðßóçò íá ðåñéÝ÷åé, áëëÜ ü÷é êáé íá îåêéíÜåé, ôïõò ÷áñáêôÞñåò "'" êáé "-".
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò str_word_count()
|
ÁíáôñÝîôå åðßóçò óôéò óõíáñôÞóåéò: explode(), preg_split(), split(), count_chars(), êáé substr_count().
ÅðéóôñÝöåé < 0 åÜí ç ðáñÜìåôñïò str1 åßíáé ìéêñüôåñç ôçò str2, > 0 åÜí ç str1 åßíáé ìåãáëýôåñç ôçò str2, êáé 0 åÜí ïé äýï ðáñÜìåôñïé åßíáé ßóåò.
ÁíáôñÝîôå åðßóçò óôéò: ereg(), strcmp(), substr(), stristr(), strncasecmp(), êáé strstr().
ÅðéóôñÝöåé < 0 åÜí ç ðáñÜìåôñïò str1 åßíáé ìéêñüôåñç ôçò str2, > 0 åÜí ç str1 åßíáé ìåãáëýôåñç ôçò str2, êáé 0 åÜí ïé äýï ðáñÜìåôñïé åßíáé ßóåò.
ÐñïóÝîôå üôé ç óýãêñéóç åßíáé case sensitive.
ÁíáôñÝîôå åðßóçò óôéò: ereg(), strcasecmp(), substr(), stristr(), strncasecmp(), strncmp(), êáé strstr().
ÅðéóôñÝöåé < 0 åÜí ç ðáñÜìåôñïò str1 åßíáé ìéêñüôåñç ôçò str2, > 0 åÜí ç str1 åßíáé ìåãáëýôåñç ôçò str2, êáé 0 åÜí ïé äýï ðáñÜìåôñïé åßíáé ßóåò. Ç óõíÜñôçóç strcoll() ÷ñçóéìïðïéåß ôï ôñÝ÷ïí locale ãéá ôçí õëïðïßçóç ôùí óõãêñßóåùí. ÅÜí áõôü åßíáé C Þ POSIX, ç óõíÜñôçóç Ý÷åé ôçí ßäéá ëåéôïõñãßá ìå ôçí strcmp().
ÐñïóÝîôå üôé ç óýãêñéóç åßíáé case sensitive, êáé üôé äéáöÝñåé áðü ôçí strcmp() óôï üôé äåí åßíáé binary safe.
Óçìåßùóç: Ç óõíÜñôçóç strcoll() ðñïóôÝèçêå óôçí PHP 4.0.5, áëëÜ äåí Þôáí äéáèÝóéìç ãéá win32 ìÝ÷ñé ôçí Ýêäïóç 4.2.3.
ÁíáôñÝîôå åðßóçò óôéò: ereg(), strcmp(), strcasecmp(), substr(), stristr(), strncasecmp(), strncmp(), strstr(), êáé setlocale().
(PHP 3>= 3.0.3, PHP 4 , PHP 5)
strcspn -- Õðïëïãéóìüò ôïõ ìÞêïõò ôïõ áñ÷éêïý ôìÞìáôïò ðïõ äåí ôáéñéÜæåé óôç ìÜóêáÅðéóôñÝöåé ôï ìÞêïò ôïõ áñ÷éêïý ôìÞìáôïò ôçò ðáñáìÝôñïõ str1, ôï ïðïßï äåí ðåñéÝ÷åé ÷áñáêôÞñåò ôçò str2.
ÁíáôñÝîôå åðßóçò óôçí strspn().
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá string áðü ôï ïðïßï ëåßðïõí üëá ôá HTML êáé PHP tags ôïõ äïóìÝíïõ str string. Åìöáíßæåé ìÞíõìá ðñïåéäïðïßçóçò óôçí ðåñßðôùóç ìç óõìâáôþí Þ øåýôéêùí tags. ×ñçóéìïðïéåß ôçí ßäéá ìç÷áíÞ êáôáóôÜóåùí ãéá ôçí áöáßñåóç tag ìå ôç óõíÜñôçóç fgetss().
Ìðïñåßôå íá ÷ñçóéìïðïéåßóåôå ôçí ðñïáéñåôéêÞ äåýôåñç ðáñÜìåôñï ãéá íá ðñïóäéïñßóåôå tags ðïõ äåí åðéèõìåßôå íá áöáéñåèïýí.
Óçìåßùóç: Ç ðáñÜìåôñïò allowable_tags ðñïóôÝèçêå óôçí PHP 3.0.13 êáé PHP 4.0b3.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç äåí áëëÜæåé êÜðïéá éäéüôçôá ôùí tags ôùí ïðïßùí åðéôñÝðåôå ôç ÷ñÞóç ìå ôçí ðáñÜìåôñï allowable_tags, óõìðåñéëáìâáíïìÝíùí êáé ôùí style êáé onmouseover, ôùí ïðïßùí ôç ÷ñÞóç ìðïñåß íá åêìåôáëëåõôåß êÜðïéïò êáêüâïõëïò ÷ñÞóôçò üôáí áðïóôÝëåé êåßìåíï ôï ïðïßï èá åìöáíéóôåß óå Üëëïõò ÷ñÞóôåò. |
(PHP 4 , PHP 5)
stripcslashes -- ÊÜíåôå un-quote Ýíá string ðïõ Ý÷åé ãßíåé quoted ìå ôç óõíÜñôçóç addcslashes()ÅðéóôñÝöåé Ýíá string ÷ùñßò ôéò backslashes. Áíáãíùñßæåé ôéò C-like \n, \r ..., ïêôáäéêÝò êáé äåêáåîáäéêÝò áíáðáñáóôÜóåéò.
ÁíáôñÝîôå åðßóçò óôçí addcslashes().
ÅðéóôñÝöåé ôïí áñéèìü ôçò èÝóçò ôçò ðñþôçò åìöÜíéóçò ôïõ string needle óôï haystack string. Áíôßèåôá ìå ôç óõíÜñôçóç strpos(), ç stripos() åßíáé case-insensitive. Åðßóçò, óå áíôßèåóç ìå ôçí strrpos(), ç óõíÜñôçóç áõôÞ ìðïñåß íá ðÜñåé Ýíá ïëüêëçñï string óôç èÝóç ôçò ðáñáìÝôñïõ needle êáé íá ôï ÷ñçóéìïðïéÞóåé ïëüêëçñï.
ÅÜí äå âñåèåß ç ðáñÜìåôñïòneedle, ç óõíÜñôçóç strpos() èá åðéóôñÝøåé ôçí boolean ôéìÞ FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò stripos()
|
ÅÜí ç ðáñÜìåôñïò needle äåí åßíáé string, ìåôáôñÝðåôáé óå Ýíáí integer êáé ÷ñçóéìïðïéåßôáé ùò ç êáíïíéêÞ ôéìÞ åíüò ÷áñáêôÞñá.
Ç ðñïáéñåôéêÞ ðáñÜìåôñïò offset óáò åðéôñÝðåé íá êáèïñßóåôáé ôï ÷áñáêôÞñá ôçò haystack áðü ôïí ïðïßï èá áñ÷ßóåé ôï øÜîéìï. Ç èÝóç ðïõ èá åðéóôñáöåß ðáñáìÝíåé ó÷åôéêÞ ìå ôçí áñ÷Þ ôçò haystack.
ÁíáôñÝîôå åðßóçò óôéò: strpos(), strrpos(), strrchr(), substr(), stristr(), strstr() êáé stri_replace().
(PHP 3, PHP 4 , PHP 5)
stripslashes -- ÊÜíôå un-quote Ýíá string ðïõ Ý÷åé ãßíåé quoted ìå ôç óõíÜñôçóç addslashes()ÅðéóôñÝöåé Ýíá string ÷ùñßò ôéò backslashes. (Ç \' ãßíåôáé ' êáé ðÜåé ëÝãïíôáò). Ïé äéðëÝò backslashes (\\) ìåôáôñÝðïíôáé óå ìïíÞ backslash (\).
¸íá ðáñÜäåéãìá ÷ñÞóçò ôçò stripslashes() åßíáé üôáí ç PHP directive magic_quotes_gpc Ý÷åé ôåèåß on (ç ðñïêáèïñéóìÝíç ôéìÞ ôçò åßíáé on), êáé äåí åéóáãÜãåôå äåäïìÝíá êÜðïõ (ãéá ðáñÜäåéãìá ìßá âÜóç äåäïìÝíùí) ðïõ ÷ñåéÜæåôáé escaping. Ãéá ðáñÜäåéãìá, åÜí áðëÜ ðáßñíåôå äåäïìÝíá êáôáõèåßáí áðü Ýíá HTML form.
ÁíáôñÝîôå åðßóçò óôéò: addslashes() êáé get_magic_quotes_gpc().
ÅðéóôñÝöåé ôï ìÝñïò ôïõ haystack ðïõ îåêéíÜ áðü ôçí ðñþôç åìöÜíéóç ôïõ string needle êáé öôÜíåé ìÝ÷ñé ôï ôÝëïò ôïõ haystack. Ïé ðáñÜìåôñïé needle êáé haystack åîåôÜæïíôáé ìå case-insensitive ôñüðï.
ÅÜí ç needle äå âñåèåß, åðéóôñÝöåôáé ç ôéìÞ FALSE.
ÅÜí ç needle äåí åßíáé string, ìåôáôñÝðåôáé óå Ýíáí integer êáé ÷ñçóéìïðïéåßôáé ùò ç êáíïíéêÞ ôéìÞ åíüò ÷áñáêôÞñá.
ÁíáôñÝîôå åðßóçò óôéò: strchr(), strrchr(), substr(), êáé ereg().
(PHP 4 , PHP 5)
strnatcasecmp -- Case insensitive óõãêñßóåéò string ìå ôç ÷ñÞóç åíüò áëãïñßèìïõ "öõóéêÞò äéÜôáîçò"Ç óõíÜñôçóç áõôÞ ÷ñçóéìïðïéåß Ýíáí áëãüñéèìï óýãêñéóçò, ï ïðïßïò äéáôÜóóåé ôá áëöáñéèìçôéêÜ strings ìå ôïí ßäéï ôñüðï ìå ôïí ïðïßï èá ôï Ýêáíå êÜðïéïò Üíèñùðïò. Ç óõìðåñéöïñÜ ôçò óõíÜñôçóçò åßíáé üìïéá ìå áõôÞí ôçò strnatcmp(), åêôüò ôïõ üôé ç óýãêñéóç äåí åßíáé case sensitive. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò áíáôñÝîôå óôç óåëßäá ôïõ Martin Pool: Natural Order String Comparison.
¼ìïéá ìå ôéò õðüëïéðåò óõíáñôÞóåéò óýãêñéóçò string, Ýôóé êáé áõôÞ åðéóôñÝöåé < 0 åÜí ç ðáñÜìåôñïò str1 åßíáé ìéêñüôåñç ôçò str2, > 0 åÜí ç str1 åßíáé ìåãáëýôåñç ôçò str2, êáé 0 åÜí ïé äýï ðáñÜìåôñïé åßíáé ßóåò.
ÁíáôñÝîôå åðßóçò óôéò: ereg(), strcasecmp(), substr(), stristr(), strcmp(), strncmp(), strncasecmp(), strnatcmp(), êáé strstr().
Ç óõíÜñôçóç áõôÞ ÷ñçóéìïðïéåß Ýíáí áëãüñéèìï óýãêñéóçò, ï ïðïßïò äéáôÜóóåé ôá áëöáñéèìçôéêÜ strings ìå ôïí ßäéï ôñüðï ðïõ èá ôï Ýêáíå êáé Ýíáò Üèñùðïò. ¸íá ðáñÜäåéãìá ôçò äéáöïñÜò ìåôáîý áõôïý ôïõ áëãïñßèìïõ êáé áõôþí ðïõ ÷ñçóéìïðïéïýíôáé óõíÞèùò áðü ôïõò õðïëïãéóôÝò ãéá ôçí ôáîéíüìçóç ôùí string (÷ñçóéìïðïéïýíôáé êáé óôçí strcmp()) ìðïñåß íá èåùñçèåß ôï áêüëïõèï:
<?php $arr1 = $arr2 = array("img12.png","img10.png","img2.png","img1.png"); echo "Standard string comparison\n"; usort($arr1,"strcmp"); print_r($arr1); echo "\nNatural order string comparison\n"; usort($arr2,"strnatcmp"); print_r($arr2); ?> |
Standard string comparison Array ( [0] => img1.png [1] => img10.png [2] => img12.png [3] => img2.png ) Natural order string comparison Array ( [0] => img1.png [1] => img2.png [2] => img10.png [3] => img12.png ) |
¼ìïéá ìå ôéò õðüëïéðåò óõíáñôÞóåéò óýãêñéóçò, êáé áõôÞ åðéóôñÝöåé < 0 åÜí ç ðáñÜìåôñïò str1 åßíáé ìéêñüôåñç ôçò str2, > 0 åÜí ç str1 åßíáé ìåãáëýôåñç ôçò str2, êáé 0 åÜí ïé äýï ðáñÜìåôñïé åßíáé ßóåò.
ÐñïóÝîôå üôé áõôÞ ç óýãêñéóç åßíáé case sensitive.
ÁíáôñÝîôå åðßóçò óôéò: ereg(), strcasecmp(), substr(), stristr(), strcmp(), strncmp(), strncasecmp(), strnatcasecmp(), strstr(), natsort() êáé natcasesort().
(PHP 4 >= 4.0.2, PHP 5)
strncasecmp -- Binary safe case-insensitive óýãêñéóç ôùí ðñþôùí n ÷áñáêôÞñùí äýï stringÇ óõíÜñôçóç áõôÞ åßíáé üìïéá ìå ôç óõíÜñôçóç strcasecmp(), ìå ôç ìüíç äéáöïñÜ üôé ìðïñåßôå íá ïñßóåôå ôï (ðÜíù üñéï ôïõ) ðëÞèïò ôùí ÷áñáêôÞñùí (len) ðïõ èá ÷ñçóéìïðïéçèïýí áðü êÜèå string ãéá ôç óýãêñéóç. ÅÜí êÜðïéï áðü ôá strings åßíáé ìéêñüôåñï ôïõ len, ôüôå ãéá ôç óýãêñéóç èá ÷ñçóéìïðïéçèåß ôï ìÞêïò áõôïý ôïõ string.
ÅðéóôñÝöåé < 0 åÜí ç ðáñÜìåôñïò str1 åßíáé ìéêñüôåñç ôçò str2, > 0 åÜí ç str1 åßíáé ìåãáëýôåñç ôçò str2, êáé 0 åÜí ïé äýï ðáñÜìåôñïé åßíáé ßóåò.
ÁíáôñÝîôå åðßóçò óôéò: ereg(), strcasecmp(), strcmp(), substr(), stristr(), êáé strstr().
Ç óõíÜñôçóç áõôÞ åßíáé üìïéá ìå ôç óõíÜñôçóç strcmp(), ìå ôç ìüíç äéáöïñÜ üôé ìðïñåßôå íá êïèïñßóåôå ôï (ðÜíù üñéï ôïõ) ðëÞèïò ôùí ÷áñáêôÞñùí (len) ðïõ èá ÷ñçóéìïðïéçèïýí áðü êÜèå string ãéá ôç óýãêñéóç. ÅÜí êÜðïéï áðü ôá strings åßíáé ìéêñüôåñï áðü ôï len, ôüôå ãéá ôç óýãêñéóç èá ÷ñçóéìïðïéçèåß ôï ìÞêïò áõôïý ôïõ string.
ÅðéóôñÝöåé < 0 åÜí ç ðáñÜìåôñïò str1 åßíáé ìéêñüôåñç ôçò str2, > 0 åÜí ç str1 åßíáé ìåãáëýôåñç ôçò str2, êáé 0 åÜí ïé äýï ðáñÜìåôñïé åßíáé ßóåò.
ÐñïóÝîôå üôé ç óýãêñéóç áõôÞ åßíáé case sensitive.
ÁíáôñÝîåôå åðßóçò óôéò: ereg(), strncasecmp(), strcasecmp(), substr(), stristr(), strcmp(), êáé strstr().
ÅðéóôñÝöåé ôïí áñéèìü ôçò èÝóçò ðñþôçò åìöÜíéóçò ôïõ needle óôï string haystack. Áíôßèåôá ðñïò ôç óõíÜñôçóç strrpos(), áõôÞ ðáßñíåé üëï ôï string ùò ðáñÜìåôñï needle êáé ôï ÷ñçóéìïðïéåß êáé ïëüêëçñï.
ÅÜí äå âñåèåß ç needle, ç óõíÜñôçóç strpos() èá åðéóôñÝøåé ôçí boolean ôéìÞ FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
ÐáñÜäåéãìá 1. Ðáñáäåßãìáôá ÷ñÞóçò ôçò strpos()
|
ÅÜí ç needle äåí åßíáé Ýíá string, ìåôáôñÝðåôáé óå Ýíáí integer êáé ÷ñçóéìïðïéåßôáé ùò ç êáíïíéêÞ ôéìÞ åíüò ÷áñáêôÞñá.
Ç ðïáéñåôéêÞ ðáñÜìåôñïò offset óáò åðéôñÝðåé íá ïñßóåôå ôï ÷áñáêôÞñá ôïõ haystack string áðü ôïí ïðïßï èá îåêéíëçóåé ôï øÜîéìï. Ç èÝóç ðïõ åðéóôñÝöåôáé ðáñáìÝíåé ó÷åôéêÞ ìå ôçí áñ÷Þ ôïõ haystack.
ÁíáôñÝîôå åðßóçò óôéò: strrpos(), stripos(), strripos(), strrchr(), substr(), stristr(), êáé strstr().
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé ôï ìÝñïò ôïõ haystack ôï ïðïßï îåêéíÜåé áðü ôç èÝóç ôåëåõôáßáò åìöÜíéóçò ôïõ needle êáé óõíå÷ßæåé ìÝ÷ñé ôï ôÝëïò ôïõ haystack.
ÅðéóôñÝöåé ôçí ôéìÞ FALSE åÜí äå âñåèåß ç ðáñÜìåôñïò needle.
ÅÜí ç needle ðåñéÝ÷åé ðáñáðÜíù áðü Ýíá ÷áñáêôÞñá, ôüôå ÷ñçóéìïðïéåßôáé ï ðñþôïò.
ÅÜí ç needle äåí åßíáé string, ìåôáôñÝðåôáé óå Ýíáí integer êáé ÷ñçóéìïðïéåßôáé ùò ç êáíïíéêÞ ôéìÞ åíüò ÷áñáêôÞñá.
ÁíáôñÝîôå åðßóçò óôéò: strchr(), substr(), stristr(), êáé strstr().
(PHP 5)
strripos -- Âñåßôå ôç èÝóç ôçò ôåëåõôáßáò åìöÜíéóçò åíüò string óå Ýíá Üëëï ìå case-insensitive ôñüðïÅðéóôñÝöåé ôïí áñéèìü ôçò èÝóçò ôåëåõôáßáò åìöÜíéóçò ôïõ needle óôï string haystack. Óå áíôßèåóç ìå ôç óõíÜñôçóç strrpos(), ç strripos() åßíáé case-insensitive. Åðßóçò ðñïóÝîôå üôé ç èÝóåéò ôùí string îåêéíïýí óôï 0, êé ü÷é óôï 1.
ÅÜí ðáñáëåßðåôáé ôï needle, ôüôå åðéóôñÝöåôáé ç ôéìÞ FALSE.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç ìðïñåß íá åðéóôñÝøåé Boolean FALSE, áëëÜ ìðïñåß åðßóçò íá åðéóôñÝøåé êáé ìéá non-Boolean ôéìÞ ç ïðïßá áðïôéìåßôáé óå FALSE, üðùò ôï 0 Þ ôï "". Ðáñáêáëïýìå äéáâÜóôå ôçí åíüôçôá ãéá ôá Boolean ãéá ðåñéóóüôåñåò ðëçñïöïñßñåò. ×ñçóéìïðïéåßóôå ôïí ôåëåóôÞ === ãéá íá åëÝãîåôå ôçí ôéìÞ ðïõ åðéóôñÝöåé áõôÞ ç óõíÜñôçóç. |
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò strripos()
|
ÁíáôñÝîôå åðßóçò óôéò: strrpos(), strrchr(), substr(), êáé stristr().
(PHP 3, PHP 4 , PHP 5)
strrpos -- Âñåßôå ôç èÝóç ôçò ôåëåõôáßáò åìöÜíéóçò åíüò ÷áñáêôÞñá ìÝóá óå Ýíá stringÅðéóôñÝöåé ôï íïýìåñï ôçò èÝóçò ôåëåõôáßáò åìöÜíéóçò ôçò ðáñáìÝôñïõ needle óôï string haystack. Ðáñáôçñåßóôå üôé óå áõôÞí ôçí ðåñßðôùóç ç needle ìðïñåß íá åßíáé ìüíï Ýíáò ÷áñáêôÞñáò. ÅÜí ðåñáóôåß Ýíá string ùò needle, ôüôå èá ëçöèåß õð' üøéí ìüíï ï ðñþôïò ÷áñáêôÞñáò áõôïý ôïõ string.
ÅÜí ç ðáñÜìåôñïò needle äå äßíåôáé, åðéóôñÝöåôáé ç ôéìÞ FALSE.
Åßíáé åýêïëï íá ìðåñäÝøåôå ôéò åðéóôñåöüìåíåò ôéìÝò ãéá ôéò ðåñéðôþóåéò "ï ÷áñáêôÞñáò âñÝèçêå óôç èÝóç 0" êáé "ï ÷áñáêôÞñáò äå âñÝèçêå". Áêïëïõèåß ìßá ìÝèïäïò ãéá ôï ðþò íá åíôïðßæåôáé ôç äéáöïñÜ:
<?php // in PHP 4.0b3 and newer: $pos = strrpos($mystring, "b"); if ($pos === false) { // note: three equal signs // not found... } // in versions older than 4.0b3: $pos = strrpos($mystring, "b"); if (is_string($pos) && !$pos) { // not found... } ?> |
ÅÜí ç ðáñÜìåôñïò needle äåí åßíáé string, ìåôáôñÝðåôáé óå Ýíáí integer êáé ÷ñçóéìïðïéåßôáé ùò ç êáíïíéêÞ ôéìÞ åíüò ÷áñáêôÞñá.
ÁíáôñÝîôå åðßóçò óôéò: strpos(), strripos(), strrchr(), substr(), stristr(), êáé strstr().
(PHP 3>= 3.0.3, PHP 4 , PHP 5)
strspn -- Âñåßôå ôï ìÞêïò ôïõ áñ÷éêïý êïììáôéïý ðïõ ôáéñéÜæåé óôç ìÜóêáÅðéóôñÝöåé ôï ìÞêïò ôïõ áñ÷éêïý ôìÞìáôïò ôçò ðáñáìÝôñïõ str1 ðïõ áðïôåëåßôáé óôï óýíïëü ôïõ áðü ÷áñáêôÞñåò ôïõ string str2.
Ç áêüëïõèç ãñáììÞ êþäéêá:
èá èÝóåé ôï 2 ùò ôéìÞ ôçò $var, åðåéäÞ ôï string "42" èá åßíáé ôï ìåãáëýôåñï ôìÞìá ðïõ ðåñéÝ÷åé ÷áñáêôÞñåò áðü ôï "1234567890".ÁíáôñÝîôå åðßóçò óôçí strcspn().
ÅðéóôñÝöåé ôï ìÝñïò ôïõ string haystack ðïõ îåêéíÜ áðü ôç èÝóç ðñþôçò åìöÜíéóçò ôïõ needle êáé ôåëåéþíåé óôï ôÝëïò ôïõ haystack.
ÅÜí äå äßíåôáé ç needle åðéóôñÝöåôáé ç ôéìÞ FALSE.
ÅÜí ç needle äåí åßíáé string, ìåôáôñÝðåôáé óå Ýíáí integer, ðïõ ÷ñçóéìïðïéåßôáé ùò ç êáíïíéêÞ ôéìÞ åíüò ÷áñáêôÞñá.
Óçìåßùóç: Ç óõíÜñôçóç áõôÞ åßíáé case-sensitive. Ãéá case-insensitive ùáîßìáôá, ÷ñçóéìïðïéåßóôå ôç óõíÜñôçóç stristr().
Óçìåßùóç: ÅÜí èÝëåôå ìüíï íá äéáðéóôþóåôå åÜí ðåñéÝ÷åôáé ç needle óôï haystack, ìðïñåßôå íá ÷ñçóéìïðïéåßóåôå ôç ãñçãïñüôåñç êáé ëéãüôåñï óðÜôáëç óå ìíÞìç óõíÜñôçóç strpos().
ÁíáôñÝîôå åðßóçò óôéò: ereg(), preg_match(), strchr(), stristr(), strpos(), strrchr(), êáé substr().
Ç óõíÜñôçóç strtok() ÷ùñßæåé Ýíá string (arg1) óå ìéêñüôåñá (tokens), ìå ôï êÜèå Ýíá íá ïñéïèåôåßôáé áðü ôïõò ÷áñáêôÞñåò ôçò ðáñáìÝôñïõ arg2. ¸ôóé, åÜí Ý÷åôå ôï string "This is an example string" ìðïñåßôå íá ôï ÷ùñßóåôå óå tokens, ðïõ ôï êÜèå Ýíá íá áíôéóôïé÷åß óå ìßá ëÝîç ìå ôï íá ÷ñçóéìïðïéÞóåôå ùò token Ýíá êåíü.
Ðáñáôçñåßóôå üôé ìüíï ç ðñþôç êëÞóç ôçò strtok ÷ñçóéìïðïéåß ôï üñéóìá string. ÊÜèå åðüìåíç êëÞóç ôçò óõíÜñôçóçò ÷ñåéÜæåôáé ìüíï ôï token ðïõ èá ÷ñçóéìïðïéÞóåé, áöïý åíôïðßæåé ôç èÝóç ôïõ óôï ôñÝ÷ùí string. Ãéá íá îáíáîåêéíÞóåôå, Þ ãéá íá êÜíåôå tokenize Ýíá íÝï string ìðïñåßôå áðëÜ íá êáëÝóåôå ôç strtok êáé ðÜëé ìå ôï üñéóìá string ãéá íá îåêéíÞóåôå. Ìðïñåßôå, åðßóçò, íá ÷ñçóéìïðïéåßóåôå ðïëëáðëÜ tokens óôçí ðáñÜìåôñï token. Ôï string èá ÷ùñßæåôáé óå tokens êÜèå öïñÜ ðïõ óõíáíôÜôáé êÜðïéïò áðü áõôïýò ôïõò ÷áñáêôÞñåò.
Ç óõìðåñéöïñÜ ôçò óõíÜñôçóçò óôçí åýñåóç åíüò êåíïý ôìÞìáôïò Üëëáîå ìå ôçí PHP 4.1.0. Óå ðáëéüôåñåò åêäüóåéò èá õðÞñ÷å ùò Ýîïäïò Ýíá êåíü string, åíþ ç íÝá óùóôÞ óõìðåñéöïñÜ ðñïóðåñíÜåé áðëÜ áõôü ôï ìÝñïò ôïõ string:
ÐñïóÝ÷åôå, åðßóçò, íá ìçí åßíáé ôá tokens óáò ßóá ìå ôï "0". Ç ðåñßðôùóç áõôÞ ìåôáöñÜæåôáé óå ôéìÞ FALSE.
ÅðéóôñÝöåé ôï string ìå üëïõò ôïõò áëöáâçôéêïýò ÷áñáêôÞñåò áëëáãìÝíïõò óå ìéêñïýò.
ÐñïóÝîôå üôé ï üñïò 'áëöáâçôéêüò' åîáñôÜôáé áðü ôï ôñÝ÷ùí locale. Ãéá ðáñÜäåéãìá, óôï ðñïêáèïñéóìÝíï "C" locale, ÷áñáêôÞñåò üðùò ï umlaut-A (Ä) äåí ìåôáôñÝðïíôáé.
ÁíáôñÝîôå åðßóçò óôéò: strtoupper(), ucfirst(), êáé ucwords().
ÅðéóôñÝöåé ôï string ìå üëïõò ôïõò áëöáâçôéêïýò ÷áñáêôÞñïõò ôïõ êåöáëáßïõò.
ÐñïóÝîôå üôé ï üñïò 'áëöáâçôéêüò' åîáñôÜôáé áðü ôï ôñÝ÷ùí locale. Ãéá ðáñÜäåéãìá, óôï ðñïêáèïñéóìÝíï "C" locale ÷áñáêôÞñåò üðùò ï umlaut-a (ä) äå ìåôáôñÝðïíôáé.
ÁíáôñÝîôå åðßóçò óôéò: strtolower(), ucfirst(), êáé ucwords().
Ç óõíÜñôçóç áõôÞ åðéóôñÝöåé Ýíá áíôßãñáöï ôïõ str, óôï ïðïßï åßíáé ìåôáöñáóìÝíç ç êÜèå åìöáíßóç ôùí ÷áñáêôÞñùí ôçò from óôïí áíôßóôïé÷ü ôïõò ôçò to.
ÅÜí ïé ðáñÜìåôñïé from êáé to Ý÷ïõí äéáöïñåôéêÜ ìÞêç, ïé åðéðëÝïí ÷áñáêôÞñåò ôïõ ìåãáëýôåñïõ áðü ôá äýï strings èá ðáñáëçöèïýí.
Ç óõíÜñôçóç strtr() ìðïñåß íá êëçèåß ìå äýï ìüíï ïñßóìáôá. ÅÜí êëçèåß ìå áõôüí ôïí ôñüðï óõìðåñéöÝñåôå ìå Ýíá íÝï: Ç ðáñÜìåôñïò from ðñÝðåé íá åßíáé Ýíáò ðßíáêáò ðïõ íá ðåñéÝ÷åé æåõãÜñéá string -> string ôá ïðïßá èá áíôéêáôáóôáèïýí óôï áñ÷éêü string. Ç strtr() èá øÜ÷íåé ðÜíôá íá õëïðïéÞóåé ðñþôï ôï ìåãáëýôåñï äõíáôü ôáßñéáóìá êáé *ÄÅ* èá ðñïóðáèÞóåé íá áíôéêáôáóôÞóåé êÜôé ìå ôï ïðïßï Ý÷åé Þäç áó÷ïëçèåß.
Óçìåßùóç: Ïé ðñïáéñåôéêÝò ðáñÜìåôñïé to êáé from ðñïóôÝèçêáí óôçí PHP 4.0.0
ÁíáôñÝîôå åðßóçò óôçí ereg_replace().
(PHP 5)
substr_compare -- Binary safe optionally case insensitive comparison of 2 strings from an offset, up to length characterssubstr_compare() compares main_str from position offset with str up to length characters.
Returns < 0 if main_str from position offset is less than str, > 0 if it is greater than str, and 0 if they are equal. If length is equal or greater than length of main_str and length is set, substr_compare() prints warning and returns FALSE.
If case_sensitivity is TRUE, comparison is case sensitive.
ÐáñÜäåéãìá 1. A substr_compare() example
|
Ç óõíÜñôçóç substr_count() åðéóôñÝöåé ôï ðëÞèïò ôùí öïñþí ðïõ ôï needle substring åìöáíßæåôáé óôï haystack string.
ÁíáôñÝîôå åðßóçò óôéò: count_chars(), strpos(), substr(), êáé strstr().
substr_replace() replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. The result is returned.
ÅÜí ç ðáñÜìåôñïò start åßíáé èåôéêÞ, ç áíôéêáôÜóôáóç èá îåêéíÞóåé áðü ôç èÝóç ìå áñéèìü start ôïõ string.
ÅÜí ç start åßíáé áñíçôéêÞ, ç áíôéêáôÜóôçóç èá îåêéíÞóåé áðü ôï ÷áñáêôÞñá ðïõ âñßóêåôáé ðïõ âñßóêåôáé óôç èÝóç start áðü ôï ôÝëïò ôïõ string.
ÅÜí ç ðáñÜìåôñïò length Ý÷åé ïñéóôåß êáé åßíáé èåôéêÞ, áíáðáñéóôÜ ôï ìÞêïò ôïõ ôìÞìáôïò ôïõ string ðïõ èá áíôéêáôáóôáèåß. ÅÜí åßíáé áñíçôéêÞ, áíáðáñéóôÜ ôï ðëÞèïò ôùí ÷áñáêôÞñùí áðü ôï ôÝëïò ôïõ string óôïõò ïðïßïõò èá óôáìáôÞóåé ç áíôéêáôÜóôáóç. ÅÜí äå äßíåôáé, ôüôå ç ðñïêáèïñéóìÝíç ôéìÞ ôçò åßíáé strlen( string );, ðïõ óçìáßíåé üôé ç áíôéêáôÜóôáóç ôåëåéþíåé óôï ôÝëïò ôïõ string.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò substr_replace()
|
ÁíáôñÝîôå åðßóçò óôéò: str_replace() êáé substr().
Ç óõíÜñôçóç substr() åðéóôñÝöåé Ýíá ôìÞìá ôïõ string, ðïõ ïñßæåôáé áðü ôéò ðáñáìÝôñïõò start êáé length.
ÅÜí ç start åßíáé ìç áñíçôéêÞ, ôï åðéóôñåöüìåíï string èá îåêéíÞóåé áðü ôçí startç (ð.÷. ðñþôç, äÝêáôç, äÝêáôç-Ýêôç êôë.) èÝóç ôïõ string, îåêéíþíôáò ôçí áñßèìçóç áðü ôï 0. Ãéá ðáñÜäåéãìá, óôï string 'abcdef', ï ÷áñáêôÞñáò óôç èÝóç 0 åßíáé ï 'a', ï ÷áñáêôÞñáò óôç èÝóç 2 åßíáé ï 'c', êáé ðÜåé ëÝãïíôáò.
ÐáñÜäåéãìá 1. ÂáóéêÞ ÷ñÞóç ôçò substr()
|
ÅÜí ç start åßíáé áñíçôéêÞ, ôï åðéóôñåöüìåíï string èá îåêéíÜåé áðü ôïí startï ÷áñáêôÞñá áðü ôï ôÝëïò ôïõ string.
ÅÜí ç ðáñÜìåôñïò length ïñßæåôáé êáé åßíáé èåôéêÞ, ôï string, ðïõ èá åðéóôñáöåß, èá ðåñéÝ÷åé ôï ðïëý length ÷áñáêôÞñåò îåêéíþíôáò áðü ôçí start (ðÜíôá ëáìâÜíïíôáò õð' üøéí ôï ìÞêïò ôïõ string). ÅÜí ôï string åßíáé ìéêñüôåñï áðü start ÷áñáêôÞñåò, ôüôå èá åðéóôñáöåß ç ôéìÞ FALSE.
ÅÜí ç length åßíáé áñíçôéêÞ, ôüôå åêöñÜæåé ôï ðëÞèïò ôùí ÷áñáêôÞñùí ðïõ èá ðáñáëçöèïýí áðü ôï ôÝëïò ôïõ string (ìåôÜ ôïí õðïëïãéóìü ôçò èÝóçò åêêßíçóçò üôáí ç start åßíáé áñíçôéêÞ). ÅÜí ç start óå óõíäõáóìü ìå ôçí áñíçôéêÞ length äåß÷íïõí óå ìßá èÝóç ðÝñáí ôïí ïñßùí ôïõ string, èá åðéóôñáöåß Ýíá êåíü string.
ÁíáôñÝîôå åðßóçò óôéò: strrchr(), substr_replace(), ereg(), êáé trim().
Óçìåßùóç: Ç ðñïáéñåôéêÞ ðáñÜìåôñïò charlist ðñïóôÝèçêå óôçí PHP 4.1.0
Ç óõíÜñôçóç åðéóôñÝöåé Ýíá string ÷ùñßò êåíÜ óôçí áñ÷Þ êáé óôï ôÝëïò ôçò ðáñáìÝôñïõ str. ×ùñßò ôç äåýôåñç ðáñÜìåôñï, ç óõíÜñôçóç trim() èá áöáéñÝóåé ôïõò áêüëïõèïõò ÷áñáêôÞñåò:
" " (ASCII 32 (0x20)), ôï óõíçèéóìÝíï êåíü.
"\t" (ASCII 9 (0x09)), Ýíá tab.
"\n" (ASCII 10 (0x0A)), ìßá íÝá ãñáììÞ (line feed).
"\r" (ASCII 13 (0x0D)), Ýíá carriage return.
"\0" (ASCII 0 (0x00)), ôï NUL-byte.
"\x0B" (ASCII 11 (0x0B)), Ýíá êÜèåôï tab.
Ìðïñåßôå íá êáèïñßóåôå åóåßò ôïõò ÷áñáêôÞñåò ðïõ èÝëåôå íá áöáéñÝóåôå ÷ñçóéìïðïéþíôáò ôçí ðáñÜìåôñï charlist. ÁðëÜ ãñÜøôå üëïõò ôïõò ÷áñáêôÞñåò ðïõ èÝëåôå íá áöáéñåèïýí. Ìå ôéò .. ìðïñåßôå íá ïñßóåôå Ýíá ðåäßï ÷áñáêôÞñùí.
ÐáñÜäåéãìá 1. ÐáñÜäåéãìá ÷ñÞóçò ôçò trim()
|
ÅðéóôñÝöåé Ýíá string ìå êåöáëáßï ôïí ðñþôï ÷áñáêôÞñá ôïõ str, åÜí áõôüò åßíáé áëöáâçôéêüò.
ÐñïóÝîôå üôé ï üñïò 'áëöáâçôéêüò' åîáñôÜôáé áðü ôï ôñÝ÷ùí locale. Ãéá ðáñÜäåéãìá, óôï ðñïêáèïñéóìÝíï "C" locale ÷áñáêôÞñåò üðùò ï umlaut-a (ä) äåí ìåôáôñÝðïíôáé.
ÁíáôñÝîôå åðßóçò óôéò: strtolower(), strtoupper(), êáé ucwords().
(PHP 3>= 3.0.3, PHP 4 , PHP 5)
ucwords -- ÌåôáôñÝøôå óå êåöáëáßï ôïí ðñþôï ÷áñáêôÞñá êÜèå ëÝîçò ôïõ stringÅðéóôñÝöåé Ýíá string ìå êåöáëáßï ôïí ðñþôï ÷áñáêôÞñá êÜèå ëÝîçò ôïõ str, åÜí áõôüò åßíáé áëöáâçôéêüò.
Ùò ëÝîç ïñßæåôáé êÜèå string ÷áñáêôÞñùí ðïõ áêïëïõèåß Ýíá êåíü (ùò êåíÜ ïñßæïíôáé ôá áêüëïõèá: space, form-feed, íÝá ãñáììÞ, carriage return, ïñéæüíôéï tab, êáé êÜèåôï tab).
ÁíáôñÝîôå åðßóçò óôéò: strtoupper(), strtolower() êáé ucfirst().
Åìöáíßæåé ôéò ôéìÝò åíüò ðßíáêá ùò Ýíá ìïñöïðïéçìÝíï string óýìöùíá ìå ôçí ðáñÜìåôñï format (ç ïðïßá ðåñéãñÜöåôáé óôçí ôåêìçñßùóç ôçò óõíÜñôçóçò sprintf()).
Ëåéôïõñãåß üðùò ç printf() áëëÜ äÝ÷åôáé Ýíáí ðßíáêá ïñéóìÜôùí, êé ü÷é Ýíá óýíïëï áðü ïñßóìáôá ìåôáâëçôÝò.
ÁíáôñÝîôå åðßóçò óôéò: printf(), sprintf(), vsprintf()
ÅðéóôñÝöåé ôéò ôéìÝò åíüò ðßíáêÜ óáò, ìå ôç ìïñöÞ åíüò ìïñöïðïéçìÝíïõ string, óýìöùíá ìå ôçí ðáñÜìåôñï format (ç ïðïßá ðåñéãñÜöåôáé óôçí ôåêìçñßùóç ôçò óõíÜñôçóçò sprintf()).
Ëåéôïõñãåß üðùò ç óõíÜñôçóç sprintf() áëëÜ äÝ÷åôáé Ýíáí ðßíáêá ïñéóìÜôùí, êé ü÷é Ýíá óýíïëï áðü ïñßóìáôá ìåôáâëçôÝò.
(PHP 4 >= 4.0.2, PHP 5)
wordwrap -- Áíáäéðëþíåé Ýíá string ìåôÜ áðü Ýíá óõãêåêñéìÝíï ðëÞèïò ÷áñáêôÞñùí ìå ôç ÷ñÞóç åíüò break string.ÅðéóôñÝöåé Ýíá ìå ôï string str áíáäéðëùìÝíï óôç óôÞëç ðïõ Ý÷åé ïñéóôåß áðü ôçí ðñïáéñåôéêÞ ðáñÜìåôñï width. Ç ãñáììÞ óðÜåé ìå ôç ÷ñÞóç ôçò (ðñïáéñåôéêÞò) ðáñáìÝôñïõ break.
ÅÜí äåí ðáñÝ÷ïíôáé ïé ðáñÜìåôñïé width êáé break, ç óõíÜñôçóç wordwrap() èá êÜíåé áõôüìáôç áíáäßðëùóç óôç óôÞëç 75 êáé èá ÷ñçóéìïðïéÞóåé ãéá ôï óðÜóéìï ôï ÷áñáêôÞñá íÝáò ãñáììÞò '\n'.
ÅÜí ç ðáñÜìåôñïò cut ôåèåß ßóç ìå 1, ôï string èá áíáäéðëþíåôáé ìåôÜ áðü êÜèå äéÜóôçìá ßóï ìå ôï äïóìÝíï ìÞêïò. ¸ôóé åÜí Ý÷åôå ìßá ëÝîç ìåãáëýôåñç áðü ôï äïìóÝíï ìÞêïò, ôüôå áõôÞ èá óðÜóåé óå ìéêñüôåñá ôìÞìáôá. (ÁíáôñÝîôå óôï äåýôåñï ðáñÜäåéãìá).
Óçìåßùóç: Ç ðñïáéñåôéêÞ ðáñÜìåôñïò cut ðñïóôÝèçêå óôçí PHP 4.0.3
ÁíáôñÝîôå åðßóçò óôçí nl2br().
To enable Sybase-DB support configure PHP --with-sybase[=DIR]. DIR is the Sybase home directory, defaults to /home/sybase. To enable Sybase-CT support configure PHP --with-sybase-ct[=DIR]. DIR is the Sybase home directory, defaults to /home/sybase.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Sybase configuration options
Name | Default | Changeable |
---|---|---|
sybase.allow_persistent | "On" | PHP_INI_SYSTEM |
sybase.max_persistent | "-1" | PHP_INI_SYSTEM |
sybase.max_links | "-1" | PHP_INI_SYSTEM |
sybase.interface_file | "/usr/sybase/interfaces" | PHP_INI_SYSTEM |
sybase.min_error_severity | "10" | PHP_INI_ALL |
sybase.min_message_severity | "10" | PHP_INI_ALL |
sybase.compatability_mode | "Off" | PHP_INI_SYSTEM |
magic_quotes_sybase | "Off" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to allow persistent Sybase connections.
The maximum number of persistent Sybase connections per process. -1 means no limit.
The maximum number of Sybase connections per process, including persistent connections. -1 means no limit.
Minimum error severity to display.
Minimum message severity to display.
Compatability mode with old versions of PHP 3.0. If on, this will cause PHP to automatically assign types to results according to their Sybase type, instead of treating them all as strings. This compatability mode will probably not stay around forever, so try applying whatever necessary changes to your code, and turn it off.
If magic_quotes_sybase is on, a single-quote is escaped with a single-quote instead of a backslash if magic_quotes_gpc or magic_quotes_runtime are enabled.
Óçìåßùóç: Note that when magic_quotes_sybase is ON it completely overrides magic_quotes_gpc . In this case even when magic_quotes_gpc is enabled neither double quotes, backslashes or NUL's will be escaped.
Ðßíáêáò 2. Sybase-CT configuration options
Name | Default | Changeable |
---|---|---|
sybct.allow_persistent | "On" | PHP_INI_SYSTEM |
sybct.max_persistent | "-1" | PHP_INI_SYSTEM |
sybct.max_links | "-1" | PHP_INI_SYSTEM |
sybct.min_server_severity | "10" | PHP_INI_ALL |
sybct.min_client_severity | "10" | PHP_INI_ALL |
sybct.hostname | NULL | PHP_INI_ALL |
sybct.deadlock_retry_count | "-1" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to allow persistent Sybase-CT connections. The default is on.
The maximum number of persistent Sybase-CT connections per process. The default is -1 meaning unlimited.
The maximum number of Sybase-CT connections per process, including persistent connections. The default is -1 meaning unlimited.
Server messages with severity greater than or equal to sybct.min_server_severity will be reported as warnings. This value can also be set from a script by calling sybase_min_server_severity(). The default is 10 which reports errors of information severity or greater.
Client library messages with severity greater than or equal to sybct.min_client_severity will be reported as warnings. This value can also be set from a script by calling sybase_min_client_severity(). The default is 10 which effectively disables reporting.
The name of the host you claim to be connecting from, for display by sp_who. The default is none.
Allows you to to define how often deadlocks are to be retried. The default is -1, or "forever".
For further details and definition of the PHP_INI_* constants see ini_set().
sybase_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query on the server associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed.
ÐáñÜäåéãìá 1. Delete-Query
The above example would produce the following output:
|
This command is not effective for SELECT statements, only on statements which modify records. To retrieve the number of rows returned from a SELECT, use sybase_num_rows().
Óçìåßùóç: This function is only available using the CT library interface to Sybase, and not the DB library.
See also sybase_num_rows().
sybase_close() closes the link to a Sybase database that's associated with the specified link link_identifier. If the link identifier isn't specified, the last opened link is assumed.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Note that this isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.
sybase_close() will not close persistent links generated by sybase_pconnect().
See also sybase_connect() and sybase_pconnect().
Returns a positive Sybase link identifier on success, or FALSE on failure.
sybase_connect() establishes a connection to a Sybase server. The servername argument has to be a valid servername that is defined in the 'interfaces' file.
In case a second call is made to sybase_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.
The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling sybase_close().
See also sybase_pconnect() and sybase_close().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
sybase_data_seek() moves the internal row pointer of the Sybase result associated with the specified result identifier to pointer to the specified row number. The next call to sybase_fetch_row() would return that row.
See also sybase_fetch_row().
Using sybase_deadlock_retry_count(), the number of retries can be defined in cases of deadlocks. By default, every deadlock is retried an infinite number of times or until the process is killed by Sybase, the executing script is killed (for instance, by set_time_limit()) or the query succeeds.
Óçìåßùóç: This function is only available using the CT library interface to Sybase, and not the DB library.
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
sybase_fetch_array() is an extended version of sybase_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.
An important thing to note is that using sybase_fetch_array() is NOT significantly slower than using sybase_fetch_row(), while it provides a significant added value.
Óçìåßùóç: When selecting fields with identical names (for instance, in a join), the associative indices will have a sequential number prepended. See the example for details.
ÐáñÜäåéãìá 1. Identical fieldnames
The above example would produce the following output (assuming the two tables only have each one column called "person_id"):
|
See also sybase_fetch_row(), sybase_fetch_assoc() and sybase_fetch_object().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
sybase_fetch_assoc() is a version of sybase_fetch_row() that uses column names instead of integers for indices in the result array. Columns from different tables with the same names are returned as name, name1, name2, ..., nameN.
An important thing to note is that using sybase_fetch_assoc() is NOT significantly slower than using sybase_fetch_row(), while it provides a significant added value.
See also sybase_fetch_array(), sybase_fetch_object() and sybase_fetch_row().
Returns an object containing field information.
sybase_fetch_field() can be used in order to obtain information about fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by sybase_fetch_field() is retrieved.
The properties of the object are:
name - column name. if the column is a result of a function, this property is set to computed#N, where #N is a serial number.
column_source - the table from which the column was taken
max_length - maximum length of the column
numeric - 1 if the column is numeric
type - datatype of the column
See also sybase_field_seek().
Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.
sybase_fetch_object() is similar to sybase_fetch_assoc(), with one difference - an object is returned, instead of an array.
Use the second object to specify the type of object you want to return. If this parameter is omitted, the object will be of type stdClass.
Óçìåßùóç: As of PHP 4.3.0, this function will no longer return numeric object members.
Old behaviour:
New behaviour:
object(stdclass)(3) { [0]=> string(3) "foo" ["foo"]=> string(3) "foo" [1]=> string(3) "bar" ["bar"]=> string(3) "bar" }
object(stdclass)(3) { ["foo"]=> string(3) "foo" ["bar"]=> string(3) "bar" }
Speed-wise, the function is identical to sybase_fetch_array(), and almost as quick as sybase_fetch_row() (the difference is insignificant).
See also sybase_fetch_array() and sybase_fetch_row().
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
sybase_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
Subsequent call to sybase_fetch_row() would return the next row in the result set, or FALSE if there are no more rows.
Ðßíáêáò 1. Data types
PHP | Sybase |
---|---|
string | VARCHAR, TEXT, CHAR, IMAGE, BINARY, VARBINARY, DATETIME |
int | NUMERIC (w/o precision), DECIMAL (w/o precision), INT, BIT, TINYINT, SMALLINT |
float | NUMERIC (w/ precision), DECIMAL (w/ precision), REAL, FLOAT, MONEY |
NULL | NULL |
See also sybase_fetch_array(), sybase_fetch_assoc(), sybase_fetch_object(), sybase_data_seek() and sybase_result().
Seeks to the specified field offset. If the next call to sybase_fetch_field() won't include a field offset, this field would be returned.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also sybase_fetch_field().
sybase_free_result() only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script ends. You may call sybase_free_result() with the result identifier as an argument and the associated result memory will be freed.
sybase_get_last_message() returns the last message reported by the server.
See also sybase_min_message_severity().
sybase_min_client_severity() sets the minimum client severity level.
Óçìåßùóç: This function is only available using the CT library interface to Sybase, and not the DB library.
See also sybase_min_server_severity().
sybase_min_error_severity() sets the minimum error severity level.
See also sybase_min_message_severity().
sybase_min_message_severity() sets the minimum message severity level.
See also sybase_min_error_severity().
sybase_min_server_severity() sets the minimum server severity level.
Óçìåßùóç: This function is only available using the CT library interface to Sybase, and not the DB library.
See also sybase_min_client_severity().
sybase_num_fields() returns the number of fields in a result set.
See also sybase_query(), sybase_fetch_field() and sybase_num_rows().
sybase_num_rows() returns the number of rows in a result set.
See also sybase_num_fields(), sybase_query() and sybase_fetch_row().
Returns a positive Sybase persistent link identifier on success, or FALSE on error.
sybase_pconnect() acts very much like sybase_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (sybase_close() will not close links established by sybase_pconnect()()).
This type of links is therefore called 'persistent'.
See also sybase_connect().
Returns a positive Sybase result identifier on success, or FALSE on error.
sybase_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if sybase_connect() was called, and use it.
See also sybase_select_db() and sybase_connect().
Returns the contents of the cell at the row and offset in the specified Sybase result set.
sybase_result() returns the contents of one cell from a Sybase result set. The field argument can be the field's offset, or the field's name, or the field's table dot field's name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name.
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than sybase_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
Recommended high-performance alternatives: sybase_fetch_row(), sybase_fetch_array() and sybase_fetch_object().
sybase_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if sybase_connect() was called, and use it.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Every subsequent call to sybase_query() will be made on the active database.
See also sybase_connect(), sybase_pconnect() and sybase_query()
(PHP 4 >= 4.3.0, PHP 5)
sybase_set_message_handler -- Sets the handler called when a server message is raisedsybase_set_message_handler() sets a user function to handle messages generated by the server. You may specify the name of a global function, or use an array to specify an object reference and a method name.
The handler expects five arguments in the following order: message number, severity, state, line number and description. The first four are integers. The last is a string. If the function returns FALSE, PHP generates an ordinary error message.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: The connection parameter was added in PHP 4.3.5.
ÐáñÜäåéãìá 3. sybase_set_message_handler() unhandled messages
|
Returns a positive Sybase result identifier on success, or FALSE on error.
sybase_unbuffered_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if sybase_connect() was called, and use it.
Unlike sybase_query(), sybase_unbuffered_query() reads only the first row of the result set. sybase_fetch_array() and similar function read more rows as needed. sybase_data_seek() reads up to the target row. The behavior may produce better performance for large result sets.
sybase_num_rows() will only return the correct number of rows if all result sets have been read. To Sybase, the number of rows is not known and is therefore computed by the client implementation.
Óçìåßùóç: If you don't read all of the resultsets prior to executing the next query, PHP will raise a warning and cancel all of the pending results. To get rid of this, use sybase_free_result() which will cancel pending results of an unbuffered query.
The optional store_result can be FALSE to indicate the resultsets shouldn't be fetched into memory, thus minimizing memory usage which is particularly interesting with very large resultsets.
ÐáñÜäåéãìá 1. sybase_unbuffered_query() example
|
The TCP wrappers provides a classical unix mechanism which has been designed to check if the remote client is able to connect from the given IP address.
Tcpwrap is currently available through PECL http://pecl.php.net/package/tcpwrap.
If PEAR is available on your *nix-like system you can use the pear installer to install the tcpwrap extension, by the following command: pear -v install tcpwrap.
You can always download the tar.gz package and install tcpwrap by hand:
This function consults /etc/hosts.allow and /etc/hosts.deny files to check if access to service daemon should be granted or denied for client with remote address address (and optional username user). address can be either IP address or domain name. user can be NULL.
If address looks like domain name then DNS is used to resolve it to IP address; set nodns to TRUE to avoid this.
For more details please consult hosts_access(3) man page.
This function returns TRUE if access should be granted, FALSE otherwise.
Tidy is a binding for the Tidy HTML clean and repair utility which allows you to not only clean and otherwise manipluate HTML documents, but also traverse the document tree.
To use Tidy, you will need libtidy installed, available on the tidy homepage http://tidy.sourceforge.net/.
Tidy is currently available for PHP 4.3.x and PHP 5 as a PECL extension from http://pecl.php.net/package/tidy.
Óçìåßùóç: Tidy 1.0 is just for PHP 4.3.x, while Tidy 2.0 is just for PHP 5.
If PEAR is available on your *nix-like system you can use the pear installer to install the tidy extension, by the following command: pear -v install tidy.
You can always download the tar.gz package and install tidy by hand:
Windows users can download the extension dll php_tidy.dll from http://snaps.php.net/win32/PECL_STABLE/.
In PHP 5 you need only to compile using the --with-tidy option.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Tidy Configuration Options
Name | Default | Changeable | Function |
---|---|---|---|
tidy.default_config | "" | PHP_INI_SYSTEM | default path for tidy config file |
tidy.clean_output | 0 | PHP_INI_PERDIR | turns on/off the output repairing by Tidy |
Ðñïåéäïðïßçóç |
Do not turn on tidy.clean_output if you are generating non-html content such as dynamic images. |
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
The following constants are defined:
Ðßíáêáò 2. tidy tag constants
constant | description |
---|---|
TIDY_TAG_UNKNOWN | |
TIDY_TAG_A | |
TIDY_TAG_ABBR | |
TIDY_TAG_ACRONYM | |
TIDY_TAG_ALIGN | |
TIDY_TAG_APPLET | |
TIDY_TAG_AREA | |
TIDY_TAG_B | |
TIDY_TAG_BASE | |
TIDY_TAG_BASEFONT | |
TIDY_TAG_BDO | |
TIDY_TAG_BGSOUND | |
TIDY_TAG_BIG | |
TIDY_TAG_BLINK | |
TIDY_TAG_BLOCKQUOTE | |
TIDY_TAG_BODY | |
TIDY_TAG_BR | |
TIDY_TAG_BUTTON | |
TIDY_TAG_CAPTION | |
TIDY_TAG_CENTER | |
TIDY_TAG_CITE | |
TIDY_TAG_CODE | |
TIDY_TAG_COL | |
TIDY_TAG_COLGROUP | |
TIDY_TAG_COMMENT | |
TIDY_TAG_DD | |
TIDY_TAG_DEL | |
TIDY_TAG_DFN | |
TIDY_TAG_DIR | |
TIDY_TAG_DIV | |
TIDY_TAG_DL | |
TIDY_TAG_DT | |
TIDY_TAG_EM | |
TIDY_TAG_EMBED | |
TIDY_TAG_FIELDSET | |
TIDY_TAG_FONT | |
TIDY_TAG_FORM | |
TIDY_TAG_FRAME | |
TIDY_TAG_FRAMESET | |
TIDY_TAG_H1 | |
TIDY_TAG_H2 | |
TIDY_TAG_H3 | |
TIDY_TAG_H4 | |
TIDY_TAG_H5 | |
TIDY_TAG_6 | |
TIDY_TAG_HEAD | |
TIDY_TAG_HR | |
TIDY_TAG_HTML | |
TIDY_TAG_I | |
TIDY_TAG_IFRAME | |
TIDY_TAG_ILAYER | |
TIDY_TAG_IMG | |
TIDY_TAG_INPUT | |
TIDY_TAG_INS | |
TIDY_TAG_ISINDEX | |
TIDY_TAG_KBD | |
TIDY_TAG_KEYGEN | |
TIDY_TAG_LABEL | |
TIDY_TAG_LAYER | |
TIDY_TAG_LEGEND | |
TIDY_TAG_LI | |
TIDY_TAG_LINK | |
TIDY_TAG_LISTING | |
TIDY_TAG_MAP | |
TIDY_TAG_MARQUEE | |
TIDY_TAG_MENU | |
TIDY_TAG_META | |
TIDY_TAG_MULTICOL | |
TIDY_TAG_NOBR | |
TIDY_TAG_NOEMBED | |
TIDY_TAG_NOFRAMES | |
TIDY_TAG_NOLAYER | |
TIDY_TAG_NOSAFE | |
TIDY_TAG_NOSCRIPT | |
TIDY_TAG_OBJECT | |
TIDY_TAG_OL | |
TIDY_TAG_OPTGROUP | |
TIDY_TAG_OPTION | |
TIDY_TAG_P | |
TIDY_TAG_PARAM | |
TIDY_TAG_PLAINTEXT | |
TIDY_TAG_PRE | |
TIDY_TAG_Q | |
TIDY_TAG_RP | |
TIDY_TAG_RT | |
TIDY_TAG_RTC | |
TIDY_TAG_RUBY | |
TIDY_TAG_S | |
TIDY_TAG_SAMP | |
TIDY_TAG_SCRIPT | |
TIDY_TAG_SELECT | |
TIDY_TAG_SERVER | |
TIDY_TAG_SERVLET | |
TIDY_TAG_SMALL | |
TIDY_TAG_SPACER | |
TIDY_TAG_SPAN | |
TIDY_TAG_STRIKE | |
TIDY_TAG_STRONG | |
TIDY_TAG_STYLE | |
TIDY_TAG_SUB | |
TIDY_TAG_TABLE | |
TIDY_TAG_TBODY | |
TIDY_TAG_TD | |
TIDY_TAG_TEXTAREA | |
TIDY_TAG_TFOOT | |
TIDY_TAG_TH | |
TIDY_TAG_THEAD | |
TIDY_TAG_TITLE | |
TIDY_TAG_TR | |
TIDY_TAG_TR | |
TIDY_TAG_TT | |
TIDY_TAG_U | |
TIDY_TAG_UL | |
TIDY_TAG_VAR | |
TIDY_TAG_WBR | |
TIDY_TAG_XMP |
Ðßíáêáò 3. tidy attribute constants
constant | description |
---|---|
TIDY_ATTR_UNKNOWN | |
TIDY_ATTR_ABBR | |
TIDY_ATTR_ACCEPT | |
TIDY_ATTR_ACCEPT_CHARSET | |
TIDY_ATTR_ACCESSKEY | |
TIDY_ATTR_ACTION | |
TIDY_ATTR_ADD_DATE | |
TIDY_ATTR_ALIGN | |
TIDY_ATTR_ALINK | |
TIDY_ATTR_ALT | |
TIDY_ATTR_ARCHIVE | |
TIDY_ATTR_AXIS | |
TIDY_ATTR_BACKGROUND | |
TIDY_ATTR_BGCOLOR | |
TIDY_ATTR_BGPROPERTIES | |
TIDY_ATTR_BORDER | |
TIDY_ATTR_BORDERCOLOR | |
TIDY_ATTR_BOTTOMMARGIN | |
TIDY_ATTR_CELLPADDING | |
TIDY_ATTR_CELLSPACING | |
TIDY_ATTR_CHAR | |
TIDY_ATTR_CHAROFF | |
TIDY_ATTR_CHARSET | |
TIDY_ATTR_CHECKED | |
TIDY_ATTR_CITE | |
TIDY_ATTR_CLASS | |
TIDY_ATTR_CLASSID | |
TIDY_ATTR_CLEAR | |
TIDY_ATTR_CODE | |
TIDY_ATTR_CODEBASE | |
TIDY_ATTR_CODETYPE | |
TIDY_ATTR_COLOR | |
TIDY_ATTR_COLS | |
TIDY_ATTR_COLSPAN | |
TIDY_ATTR_COMPACT | |
TIDY_ATTR_CONTENT | |
TIDY_ATTR_COORDS | |
TIDY_ATTR_DATA | |
TIDY_ATTR_DATAFLD | |
TIDY_ATTR_DATAPAGESIZE | |
TIDY_ATTR_DATASRC | |
TIDY_ATTR_DATETIME | |
TIDY_ATTR_DECLARE | |
TIDY_ATTR_DEFER | |
TIDY_ATTR_DIR | |
TIDY_ATTR_DISABLED | |
TIDY_ATTR_ENCODING | |
TIDY_ATTR_ENCTYPE | |
TIDY_ATTR_FACE | |
TIDY_ATTR_FOR | |
TIDY_ATTR_FRAME | |
TIDY_ATTR_FRAMEBORDER | |
TIDY_ATTR_FRAMESPACING | |
TIDY_ATTR_GRIDX | |
TIDY_ATTR_GRIDY | |
TIDY_ATTR_HEADERS | |
TIDY_ATTR_HEIGHT | |
TIDY_ATTR_HREF | |
TIDY_ATTR_HREFLANG | |
TIDY_ATTR_HSPACE | |
TIDY_ATTR_HTTP_EQUIV | |
TIDY_ATTR_ID | |
TIDY_ATTR_ISMAP | |
TIDY_ATTR_LABEL | |
TIDY_ATTR_LANG | |
TIDY_ATTR_LANGUAGE | |
TIDY_ATTR_LAST_MODIFIED | |
TIDY_ATTR_LAST_VISIT | |
TIDY_ATTR_LEFTMARGIN | |
TIDY_ATTR_LINK | |
TIDY_ATTR_LONGDESC | |
TIDY_ATTR_LOWSRC | |
TIDY_ATTR_MARGINHEIGHT | |
TIDY_ATTR_MARGINWIDTH | |
TIDY_ATTR_MAXLENGTH | |
TIDY_ATTR_MEDIA | |
TIDY_ATTR_METHOD | |
TIDY_ATTR_MULTIPLE | |
TIDY_ATTR_NAME | |
TIDY_ATTR_NOHREF | |
TIDY_ATTR_NORESIZE | |
TIDY_ATTR_NOSHADE | |
TIDY_ATTR_NOWRAP | |
TIDY_ATTR_OBJECT | |
TIDY_ATTR_OnAFTERUPDATE | |
TIDY_ATTR_OnBEFOREUNLOAD | |
TIDY_ATTR_OnBEFOREUPDATE | |
TIDY_ATTR_OnBLUR | |
TIDY_ATTR_OnCHANGE | |
TIDY_ATTR_OnCLICK | |
TIDY_ATTR_OnDATAAVAILABLE | |
TIDY_ATTR_OnDATASETCHANGED | |
TIDY_ATTR_OnDATASETCOMPLETE | |
TIDY_ATTR_OnDBLCLICK | |
TIDY_ATTR_OnERRORUPDATE | |
TIDY_ATTR_OnFOCUS | |
TIDY_ATTR_OnKEYDOWN | |
TIDY_ATTR_OnKEYPRESS | |
TIDY_ATTR_OnKEYUP | |
TIDY_ATTR_OnLOAD | |
TIDY_ATTR_OnMOUSEDOWN | |
TIDY_ATTR_OnMOUSEMOVE | |
TIDY_ATTR_OnMOUSEOUT | |
TIDY_ATTR_OnMOUSEOVER | |
TIDY_ATTR_OnMOUSEUP | |
TIDY_ATTR_OnRESET | |
TIDY_ATTR_OnROWENTER | |
TIDY_ATTR_OnROWEXIT | |
TIDY_ATTR_OnSELECT | |
TIDY_ATTR_OnSUBMIT | |
TIDY_ATTR_OnUNLOAD | |
TIDY_ATTR_PROFILE | |
TIDY_ATTR_PROMPT | |
TIDY_ATTR_RBSPAN | |
TIDY_ATTR_READONLY | |
TIDY_ATTR_REL | |
TIDY_ATTR_REV | |
TIDY_ATTR_RIGHTMARGIN | |
TIDY_ATTR_ROWS | |
TIDY_ATTR_ROWSPAN | |
TIDY_ATTR_RULES | |
TIDY_ATTR_SCHEME | |
TIDY_ATTR_SCOPE | |
TIDY_ATTR_SCROLLING | |
TIDY_ATTR_SELECTED | |
TIDY_ATTR_SHAPE | |
TIDY_ATTR_SHOWGRID | |
TIDY_ATTR_SHOWGRIDX | |
TIDY_ATTR_SHOWGRIDY | |
TIDY_ATTR_SIZE | |
TIDY_ATTR_SPAN | |
TIDY_ATTR_SRC | |
TIDY_ATTR_STANDBY | |
TIDY_ATTR_START | |
TIDY_ATTR_STYLE | |
TIDY_ATTR_SUMMARY | |
TIDY_ATTR_TABINDEX | |
TIDY_ATTR_TARGET | |
TIDY_ATTR_TEXT | |
TIDY_ATTR_TITLE | |
TIDY_ATTR_TOPMARGIN | |
TIDY_ATTR_TYPE | |
TIDY_ATTR_USEMAP | |
TIDY_ATTR_VALIGN | |
TIDY_ATTR_VALUE | |
TIDY_ATTR_VALUETYPE | |
TIDY_ATTR_VERSION | |
TIDY_ATTR_VLINK | |
TIDY_ATTR_VSPACE | |
TIDY_ATTR_WIDTH | |
TIDY_ATTR_WRAP | |
TIDY_ATTR_XML_LANG | |
TIDY_ATTR_XML_SPACE | |
TIDY_ATTR_XMLNS |
Ðßíáêáò 4. tidy nodetype constants
constant | description |
---|---|
TIDY_NODETYPE_ROOT | |
TIDY_NODETYPE_DOCTYPE | |
TIDY_NODETYPE_COMMENT | |
TIDY_NODETYPE_PROCINS | |
TIDY_NODETYPE_TEXT | |
TIDY_NODETYPE_START | |
TIDY_NODETYPE_END | |
TIDY_NODETYPE_STARTEND | |
TIDY_NODETYPE_CDATA | |
TIDY_NODETYPE_SECTION | |
TIDY_NODETYPE_ASP | |
TIDY_NODETYPE_JSTE | |
TIDY_NODETYPE_PHP | |
TIDY_NODETYPE_XMLDECL |
ob_tidyhandler() is intended to be used as a callback function for ob_start() to repair the buffer.
See also ob_start().
(PHP 5)
tidy_access_count -- Returns the Number of Tidy accessibility warnings encountered for specified document.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
This function cleans and repairs the given tidy resource.
See also tidy_repair_file() and tidy_repair_string().
(PHP 5)
tidy_config_count -- Returns the Number of Tidy configuration errors encountered for specified document.tidy_config_count() returns the number of errors encountered in the given configuration.
tidy_diagnose() runs diagnostic tests on the given resource.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
tidy_error_count() returns the number of Tidy errors encountered for the specified document.
ÐáñÜäåéãìá 1. tidy_error_count() example
The above example will output:
|
See also tidy_access_count() and tidy_warning_count().
(PHP 5)
tidy_get_body -- Returns a TidyNode Object starting from the <body> tag of the tidy parse treeThis function returns a TidyNode object starting from the <body> tag of the tidy parse tree.
Óçìåßùóç: This function is only available with Zend Engine 2, this means PHP >= 5.0.0.
See also tidy_get_head() and tidy_get_html().
tidy_get_config() returns an array with the configuration options in use by the given resource.
For a explanation about each option, visit http://tidy.sourceforge.net/docs/quickref.html.
ÐáñÜäåéãìá 1. tidy_get_config() example
The above example will output:
|
See also tidy_reset_config() and tidy_save_config().
(PHP 5)
tidy_get_error_buffer -- Return warnings and errors which occurred parsing the specified documenttidy_get_error_buffer() returns warnings and errors which occurred parsing the specified document.
ÐáñÜäåéãìá 1. tidy_get_error_buffer() example
The above example will output:
|
See also tidy_access_count(), tidy_error_count() and tidy_warning_count().
(PHP 5)
tidy_get_head -- Returns a TidyNode Object starting from the <head> tag of the tidy parse treeThis function returns a TidyNode object starting from the <head> tag of the tidy parse tree.
Óçìåßùóç: This function is only available with Zend Engine 2, this means PHP >= 5.0.0.
See also tidy_get_body() and tidy_get_html().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 5)
tidy_get_html -- Returns a TidyNode Object starting from the <html> tag of the tidy parse treeThis function returns a TidyNode object starting from the <html> tag of the tidy parse tree.
ÐáñÜäåéãìá 1. tidy_get_html() example
The above example will output:
|
Óçìåßùóç: This function is only available with Zend Engine 2, this means PHP >= 5.0.0.
See also tidy_get_body() and tidy_get_head().
tidy_get_output() returns a string with the repaired html.
ÐáñÜäåéãìá 1. tidy_get_output() example
The above example will output:
|
This function returns a string with the release date of the Tidy library.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This function is only available with Zend Engine 2, this means PHP >= 5.0.0.
tidy_get_status() returns the status for the specified tidy resource. It returns 0 if no error/warning was raised, 1 for warnings or accessibility errors, or 2 for errors.
(PHP 5)
tidy_getopt -- Returns the value of the specified configuration option for the tidy document.Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
tidy_load_config -- Load an ASCII Tidy configuration file with the specified encodingÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This function is only avaliable in Tidy 1.0. It became obsolete in Tidy 2.0 and thus has been removed.
(no version information, might be only in CVS)
tidy_node->attributes -- Returns an array of attribute objects for nodeÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
tidy_node->children -- Returns an array of child nodesÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
tidy_node->get_attr -- Return the attribute with the provided attribute idÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
tidy_node->get_nodes -- Return an array of nodes under this node with the specified idÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
tidy_node->hasChildren -- Returns true if this node has childrenÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->has_children() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->hasSiblings -- Returns true if this node has siblingsÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->has_siblings() in PHP 4/Tidy 1.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_asp() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->isComment -- Returns true if this node represents a commentÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_comment() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->isHtml -- Returns true if this node is part of a HTML documentÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_html() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->isJste -- Returns true if this node is JSTEÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_jste() in PHP 4/Tidy 1.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_php() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->isText -- Returns true if this node represents text (no markup)Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_text() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->isXhtml -- Returns true if this node is part of a XHTML documentÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_xhtml() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->isXml -- Returns true if this node is part of a XML documentÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This functions was named tidy_node->is_xml() in PHP 4/Tidy 1.
(no version information, might be only in CVS)
tidy_node->next -- Returns the next sibling to this nodeÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
tidy_node->prev -- Returns the previous sibling to this nodeÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
This function parses the given file.
The config parameter can be passed either as an array or as a string. If you pass it as a string, it means the name of the configuration file, otherwise it is interpreted as the options themselves. Check http://tidy.sourceforge.net/docs/quickref.html for an explanation about each option.
The encoding parameter sets the encoding for input/output documents. The possible values for encoding are: ascii, latin1, raw, utf8, iso2022, mac, win1252, utf16le, utf16be, utf16, big5 and shiftjis.
Óçìåßùóç: The optional parameters config and encoding were added in Tidy 2.0.
See also tidy_parse_string(), tidy_parse_string() and tidy_repair_string().
tidy_parse_string() parses a document stored in a string.
The config parameter can be passed either as an array or as a string. If you pass it as a string, it means the name of the configuration file, otherwise it is interpreted as the options themselves. Check http://tidy.sourceforge.net/docs/quickref.html for an explanation about each option.
The encoding parameter sets the encoding for input/output documents. The possible values for encoding are: ascii, latin1, raw, utf8, iso2022, mac, win1252, utf16le, utf16be, utf16, big5 and shiftjis.
ÐáñÜäåéãìá 1. tidy_parse_string() example
The above example will output:
|
Óçìåßùóç: The optional parameters config and encoding were added in Tidy 2.0.
See also tidy_parse_file(), tidy_repair_file() and tidy_repair_string().
This function repairs the given file and returns it as a string.
The config parameter can be passed either as an array or as a string. If you pass it as a string, it means the name of the configuration file, otherwise it is interpreted as the options themselves. Check http://tidy.sourceforge.net/docs/quickref.html for an explanation about each option.
The encoding parameter sets the encoding for input/output documents. The possible values for encoding are: ascii, latin1, raw, utf8, iso2022, mac, win1252, utf16le, utf16be, utf16, big5 and shiftjis.
Óçìåßùóç: The optional parameters config and encoding were added in Tidy 2.0.
See also tidy_parse_file(), tidy_parse_string() and tidy_repair_string().
This function repairs the given string.
The config parameter can be passed either as an array or as a string. If you pass it as a string, it means the name of the configuration file, otherwise it is interpreted as the options themselves. Check http://tidy.sourceforge.net/docs/quickref.html for an explanation about each option.
The encoding parameter sets the encoding for input/output documents. The possible values for encoding are: ascii, latin1, raw, utf8, iso2022, mac, win1252, utf16le, utf16be, utf16, big5 and shiftjis.
ÐáñÜäåéãìá 1. tidy_repair_string() example
The above example will output:
|
Óçìåßùóç: The optional parameters config and encoding were added in Tidy 2.0.
See also tidy_parse_file(), tidy_parse_string() and tidy_repair_file().
(no version information, might be only in CVS)
tidy_reset_config -- Restore Tidy configuration to default valuesÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: This function is only avaliable in Tidy 1.0. It became obsolete in Tidy 2.0 and thus has been removed.
(no version information, might be only in CVS)
tidy_save_config -- Save current settings to named file. Only non-default values are written.tidy_save_config() saves current settings to the specified file. Only non-default values are written.
See also tidy_get_config(), tidy_getopt(), tidy_reset_config() and tidy_setopt().
Óçìåßùóç: This function is only avaliable in Tidy 1.0. It became obsolete in Tidy 2.0 and thus has been removed.
(no version information, might be only in CVS)
tidy_set_encoding -- Set the input/output character encoding for parsing markup.Sets the encoding for input/output documents. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá. Possible values for encoding are ascii, latin1, raw, utf8, iso2022, mac, win1252, utf16le, utf16be, utf16, big5 and shiftjis.
Óçìåßùóç: This function is only avaliable in Tidy 1.0. It became obsolete in Tidy 2.0 and thus has been removed.
(no version information, might be only in CVS)
tidy_setopt -- Updates the configuration settings for the specified tidy document.tidy_setopt() updates the specified option with a new value.
See also tidy_getopt(), tidy_get_config(), tidy_reset_config() and tidy_save_config().
Óçìåßùóç: This function is only avaliable in Tidy 1.0. It became obsolete in Tidy 2.0 and thus has been removed.
(PHP 5)
tidy_warning_count -- Returns the Number of Tidy warnings encountered for specified document.tidy_warning_count() returns the number of Tidy warnings encountered for the specified document.
See also tidy_access_count() and tidy_error_count().
The tokenizer functions provide an interface to the PHP tokenizer embedded in the Zend Engine. Using these functions you may write your own PHP source analyzing or modification tools without having to deal with the language specification at the lexical level.
See also the appendix about tokens.
Beginning with PHP 4.3.0 these functions are enabled by default. For older versions you have to configure and compile PHP with --enable-tokenizer. You can disable tokenizer support with --disable-tokenizer.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Óçìåßùóç: Builtin support for tokenizer is available with PHP 4.3.0.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Óçìåßùóç: T_ML_COMMENT is not defined in PHP 5. All comments in PHP 5 are of token T_COMMENT.
Óçìåßùóç: T_DOC_COMMENT was introduced in PHP 5.
Here is a simple example PHP scripts using the tokenizer that will read in a PHP file, strip all comments from the source and print the pure code only.
ÐáñÜäåéãìá 1. Strip comments with the tokenizer
|
token_get_all() parses the given source string into PHP language tokens using the Zend engine's lexical scanner. The function returns an array of token identifiers. Each individual token identifier is either a single character (i.e.: ;, ., >, !, etc...), or a two element array containing the token index in element 0, and the string content of the original token in element 1.
For a list of parser tokens, see ÐáñÜñôçìá N, or use token_name() to translate a token value into its string representation.
ÐáñÜäåéãìá 1. token_get_all() examples
|
Ç óõíÜñôçóç base64_decode() áðïêùäéêïðïéåß encoded_data êáé åðéóôñÝöåé ôá áñ÷éêÜ äåäïìÝíá. Ôá åðéóôñåöüìåíá äåäïìÝíá åíäå÷ïìÝíùò íá åßíáé äõáäéêÜ.
Äåßôå åðßóçò: base64_encode(), RFC 2045 ôïìÝáò 6.8.
base64_encode() åðéóôñÝöåé äåäïìÝíá êùäéêïðïéçìÝíá ìå base64. ÁõôÞ ç êùäéêïðïßçóç åßíáé ó÷åäéáóìÝíç íá êÜíåé äõáäéêÜ äåäïìÝíá íá åðéâéþíïõí ôçí ìåôáöïñÜ äéáìÝóïõ layers ìåôáöïñÜò ðïõ äåí åßíáé êáèáñÜ 8-bit, üðùò ìéêñÜ bodies áðü e-mail.
Ôá Base64-êùäéêïðïéÞìåíá äåäïìÝíá êáôáëáìâÜíïõí ðåñßðïõ 33% ðåñéóóüôåñï ÷þñï óå ó÷Ýóç ìå ôá áñ÷éêÜ äåäïìÝíá.
Äåßôå åðßóçò: base64_decode(), chunk_split(), RFC 2045 ôïìÝáò 6.8.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 3>= 3.0.4, PHP 4 , PHP 5)
get_meta_tags -- ÁðïóõìðéÝæåé üëá ôá ÷áñáêôçñéóôéêÜ ôïõ ðåñéå÷ïìÝíïõ ôùí meta tag áðü Ýíá áñ÷åßï êáé åðéóôñÝöåé Ýíá ðßíáêáÁíïßãåé ôï filename êáé ôï áíáëýåé ãñáììÞ-ãñáììÞ ãéá <meta> tags óôï áñ÷åßï. Áõôü ìðïñåß íá åßíáé Ýíá ôïðéêü áñ÷åßï Þ Ýíá URL. Ç áíÜëõóç óôáìáôÜ óôï </head>.
Ïñßæïíôáò ôçí use_include_path óå 1 èá Ý÷åé ùò áðïôÝëåóìá ôï PHP íá ðñïóðáèåß íá áíïßîåé ôï áñ÷åßï êáôÜ ìÞêïò ôïõ äåäïìÝíïõ include path óýìöùíá ìå ôçí include_path ïäçãßá. Áõôü ÷ñçóéìïðïéåßôáé ãéá ôïðéêÜ áñ÷åßá, ü÷é ãéá URLs.
Ç ôéìÞ ôçò éäéüôçôáò name ãßíåôáé ôï êëåéäß, ç ôéìÞ ôçò éäéüôçôáò ôïõ ðåñéå÷ïìÝíïõ ãßíåôáé ç ôéìÞ ôïõ åðéóôñåöüìåíïõ ðßíáêá, þóôå íá ìðïñåßôå íá ÷ñçóéìïðïéåßôå åýêïëá ôõðéêÝò ëåéôïõñãßåò ôïõ ðßíáêá ãéá íá ôïí äéáôñÝîåôå Þ íá áðïêôÞóåôå ðñüóâáóç óå ìåìïíïìÝíåò ôéìÝò. Åéäéêïß ÷áñáêôÞñåò óôçí ôéìÞ ìéáò éäéüôçôáò name áíôéêáèßóôùíôáé ìå '_', ôï õðüëïéðï ìåôáôñÝðåôáé óå lower case. Áí äõï meta tags Ý÷ïõí ôï ßäéï name, ìüíï ç ôåëåõôáßá åðéóôñÝöåôáé.
ÐáñÜäåéãìá 2. ÁõôÜ ðïõ åðéóôñÝöåé ç get_meta_tags()
|
Óçìåßùóç: Áðü ôçí PHP 4.0.5, get_meta_tags() õðïóôçñßæïõí åêôüò åéóáãùãéêþí html éäéüôçôåò.
Äåßôå åðßóçò: htmlentities() êáé urlencode().
Generates a URL-encoded query string from the associative (or indexed) array provided. formdata may be an array or object containing properties. A formdata array may be a simple one-dimensional structure, or an array of arrays (who in turn may contain other arrays). If numeric indices are used in the base array and a numeric_prefix is provided, it will be prepended to the numeric index for elements in the base array only. This is to allow for legal variable names when the data is decoded by PHP or another CGI application later on.
ÐáñÜäåéãìá 2. http_build_query() with numerically index elements.
|
ÐáñÜäåéãìá 3. http_build_query() with complex arrays
this will output : (word wrapped for readability)
|
See also: parse_str(), parse_url(), urlencode(), and array_walk()
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé Ýíá ó÷åôéêü ðßíáêá ï ïðïßïò åðéóôñÝöåé ïðïéïäÞðïôå áðü ôá ðïéêßëá ôìÞìáôá ôïõ URL ðïõ õðÜñ÷ïõí. Áõôü ðåñéëáìâÜíåé ôá
scheme - ð.÷. http
host
port
user
pass
path
query - Ýðåéôá áðü ôï åñùôçìáôéêü ?
fragment - Ýðåéôá áðü ôï hachmark #
ÁõôÞ ç óõíÜñôçóç äåí ðñïïñßæåôáé íá åðéêõñþóåé ôï äùóìÝíï URL, ìüíï ôï óðÜåé óôá ðáñáðÜíù ìÝñç. ÁôåëÞ urls ãßíïíôáé åðßóçò äåêôÜ, parse_url() ðñïóðáèåß üóï ìðïñåß íá ôá áíáëýóåé óùóôÜ.
ÐáñÜäåéãìá 1. ×ñçóéìïðïéþíôáò parse_url()
|
Äåßôå åðßóçò pathinfo(), parse_str(), dirname(), êáé basename().
ÅðéóôñÝöåé Ýíá string óôï ïðïßï ïé áêïëïõèßåò ìå ôï óýìâïëï (%) åðß ôïéò åêáôü áêïëïõèïýìåíåò áðü äõï øçößá hex Ý÷ïõí áíôéêáôáóôáèåß ìå áëöáâçôéêïýò ÷áñáêôÞñåò. Ãéá ðáñÜäåéãìá, ôï string
foo%20bar%40baz |
foo bar@baz |
Óçìåßùóç: rawurldecode() äåí áðïêùäéêïðïéåß ôï óýìâïëï ôçò ðñüóèåóçò ('+') óå êåíÜ. urldecode() ôï êÜíåé.
Äåßôå åðßóçò: rawurlencode(), urldecode(), urlencode().
ÅðéóôñÝöåé Ýíá string óôï ïðïßï üëïé ïé ìç-áëöáñéèìçôéêïß ÷áñáêôÞñåò åêôüò ôïõ
-_. |
¹, áí ìåôáöÝñåôå ðëçñïöïñßåò óå Ýíá PATH_INFO ôìÞìá ôïõ URL:
Äåßôå åðßóçò: rawurldecode(), urldecode(), urlencode() êáé RFC 1738
Áðïêùäéêïðïéåß ïðïéïäÞðïôå%## åíþ êùäéêïðïéåß óôï string ðïõ Ý÷åé äïèåß. Ôï áðïêùäéêïðïéçìÝíï string åðéóôñÝöåôáé.
Äåßôå åðßóçò: urlencode(), rawurlencode(), rawurldecode().
Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the RFC1738 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs. This function is convenient when encoding a string to be used in a query part of an URL, as a convenient way to pass variables to the next page:
Note: Be careful about variables that may match HTML entities. Things like &, © and £ are parsed by the browser and the actual entity is used instead of the desired variable name. This is an obvious hassle that the W3C has been telling people about for years. The reference is here: http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2 PHP supports changing the argument separator to the W3C-suggested semi-colon through the arg_separator .ini directive. Unfortunately most user agents do not send form data in this semi-colon separated format. A more portable way around this is to use & instead of & as the separator. You don't need to change PHP's arg_separator for this. Leave it as &, but simply encode your URLs using htmlentities(urlencode($data)).
ÐáñÜäåéãìá 2. urlencode() and htmlentities() example
|
See also urldecode(), htmlentities(), rawurldecode() and rawurlencode().
For information on how variables behave, see the Variables entry in the Language Reference section of the manual.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. Variables Configuration Options
Name | Default | Changeable |
---|---|---|
unserialize_callback_func | "" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
The unserialize callback function will called (with the undefined class' name as parameter), if the unserializer finds an undefined class which should be instanciated. A warning appears if the specified function is not defined, or if the function doesn't include/implement the missing class. So only set this entry, if you really want to implement such a callback-function.
See also unserialize().
This function is an alias of floatval().
Óçìåßùóç: This alias is a left-over from a function-renaming. In older versions of PHP you'll need to use this alias of the floatval() function, because floatval() wasn't yet available in that version.
empty() returns FALSE if var has a non-empty and non-zero value. In otherwords, "", 0, "0", NULL, FALSE, array(), var $var;, and objects with empty properties, are all considered empty. TRUE is returned if var is empty.
empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. See converting to boolean for more information.
ÐáñÜäåéãìá 1. A simple empty() / isset() comparison.
|
Óçìåßùóç: ÅðåéäÞ áõôü åßíáé ìéá äïìÞ ôçò ãëþóóáò êáé ü÷é ìéá óõíÜñôçóç, äåí ìðïñåß íá êáëåóôåß ÷ñçóéìïðïéþíôáò óõíáñôÞóåéò ìåôáâëçôþí
Óçìåßùóç: empty() only checks variables as anything else will result in a parse error. In otherwords, the following will not work: empty(addslashes($name)).
See also isset(), unset(), array_key_exists(), count(), strlen(), and the type comparison tables.
Returns the float value of var.
Var may be any scalar type. You cannot use floatval() on arrays or objects.
<?php $var = '122.34343The'; $float_value_of_var = floatval($var); echo $float_value_of_var; // prints 122.34343 ?> |
See also intval(), strval(), settype() and Type juggling.
This function returns an multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables.
<?php $b = array(1, 1, 2, 3, 5, 8); $arr = get_defined_vars(); // print $b print_r($arr["b"]); /* print path to the PHP interpreter (if used as a CGI) * e.g. /usr/local/bin/php */ echo $arr["_"]; // print the command-line paramaters if any print_r($arr["argv"]); // print all the server vars print_r($arr["_SERVER"]); // print all the available keys for the arrays of variables print_r(array_keys(get_defined_vars())); ?> |
See also get_defined_functions() and get_defined_constants().
This function returns a string representing the type of the resource passed to it. If the paramater is not a valid resource, it generates an error.
Returns the type of the PHP variable var.
Ðñïåéäïðïßçóç |
Never use gettype() to test for a certain type, since the returned string may be subject to change in a future version. In addition, it is slow too, as it involves string comparison. Instead, use the is_* functions. |
Possibles values for the returned string are:
"boolean" (since PHP 4)
"integer"
"double" (for historical reasons "double" is returned in case of a float, and not simply "float")
"string"
"array"
"object"
"resource" (since PHP 4)
"NULL" (since PHP 4)
"user function" (PHP 3 only, deprecated)
"unknown type"
For PHP 4, you should use function_exists() and method_exists() to replace the prior usage of gettype() on a function.
See also settype(), is_array(), is_bool(), is_float(), is_integer(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar(), and is_string().
(PHP 4 >= 4.1.0, PHP 5)
import_request_variables -- Import GET/POST/Cookie variables into the global scopeImports GET/POST/Cookie variables into the global scope. It is useful if you disabled register_globals, but would like to see some variables in the global scope.
Using the types parameter, you can specify which request variables to import. You can use 'G', 'P' and 'C' characters respectively for GET, POST and Cookie. These characters are not case sensitive, so you can also use any combination of 'g', 'p' and 'c'. POST includes the POST uploaded file information. Note that the order of the letters matters, as when using "gp", the POST variables will overwrite GET variables with the same name. Any other letters than GPC are discarded.
The prefix parameter is used as a variable name prefix, prepended before all variable's name imported into the global scope. So if you have a GET value named "userid", and provide a prefix "pref_", then you'll get a global variable named $pref_userid.
If you're interested in importing other variables into the global scope, such as SERVER, consider using extract().
Óçìåßùóç: Although the prefix parameter is optional, you will get an E_NOTICE level error if you specify no prefix, or specify an empty string as a prefix. This is a possible security hazard. Notice level errors are not displayed using the default error reporting level.
<?php // This will import GET and POST vars // with an "rvar_" prefix import_request_variables("gP", "rvar_"); echo $rvar_foo; ?> |
See also $_REQUEST, register_globals, Predefined Variables, and extract().
Returns the integer value of var, using the specified base for the conversion (the default is base 10).
var may be any scalar type. You cannot use intval() on arrays or objects.
Óçìåßùóç: The base argument for intval() has no effect unless the var argument is a string.
See also floatval(), strval(), settype() and Type juggling.
Returns TRUE if var is an array, FALSE otherwise.
See also is_float(), is_int(), is_integer(), is_string(), and is_object().
Returns TRUE if the var parameter is a boolean.
See also is_array(), is_float(), is_int(), is_integer(), is_string(), and is_object().
(PHP 4 >= 4.0.6, PHP 5)
is_callable -- Verify that the contents of a variable can be called as a functionVerify that the contents of a variable can be called as a function. This can check that a simple variable contains the name of a valid function, or that an array contains a properly encoded object and function name.
The var parameter can be either the name of a function stored in a string variable, or an object and the name of a method within the object, like this:
array($SomeObject, 'MethodName') |
If the syntax_only argument is TRUE the function only verifies that var might be a function or method. It will only reject simple variables that are not strings, or an array that does not have a valid structure to be used as a callback. The valid ones are supposed to have only 2 entries, the first of which is an object or a string, and the second a string.
The callable_name argument receives the "callable name". In the example below it's "someClass:someMethod". Note, however, that despite the implication that someClass::SomeMethod() is a callable static method, this is not the case.
<?php // How to check a variable to see if it can be called // as a function. // // Simple variable containing a function // function someFunction() { } $functionVariable = 'someFunction'; var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true) echo $callable_name, "\n"; // someFunction // // Array containing a method // class someClass { function someMethod() { } } $anObject = new someClass(); $methodVariable = array($anObject, 'someMethod'); var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true) echo $callable_name, "\n"; // someClass:someMethod ?> |
Returns TRUE if var is a float, FALSE otherwise.
Óçìåßùóç: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric().
See also is_bool(), is_int(), is_integer(), is_numeric(), is_string(), is_array(), and is_object(),
Returns TRUE if var is an integer FALSE otherwise.
Óçìåßùóç: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric().
See also is_bool(), is_float(), is_integer(), is_numeric(), is_string(), is_array(), and is_object().
Returns TRUE if var is null, FALSE otherwise.
See the NULL type when a variable is considered to be NULL and when not.
See also NULL, is_bool(), is_numeric(), is_float(), is_int(), is_string(), is_object(), is_array(), is_integer(), and is_real().
Returns TRUE if var is a number or a numeric string, FALSE otherwise.
See also is_bool(), is_float(), is_int(), is_string(), is_object(), is_array(), and is_integer().
Returns TRUE if var is an object, FALSE otherwise.
See also is_bool(), is_int(), is_integer(), is_float(), is_string(), and is_array().
is_resource() returns TRUE if the variable given by the var parameter is a resource, otherwise it returns FALSE.
See the documentation on the resource-type for more information.
is_scalar() returns TRUE if the variable given by the var parameter is a scalar, otherwise it returns FALSE.
Scalar variables are those containing an integer, float, string or boolean. Types array, object and resource are not scalar.
<?php function show_var($var) { if (is_scalar($var)) { echo $var; } else { var_dump($var); } } $pi = 3.1416; $proteins = array("hemoglobin", "cytochrome c oxidase", "ferredoxin"); show_var($pi); // prints: 3.1416 show_var($proteins) // prints: // array(3) { // [0]=> // string(10) "hemoglobin" // [1]=> // string(20) "cytochrome c oxidase" // [2]=> // string(10) "ferredoxin" // } ?> |
Óçìåßùóç: is_scalar() does not consider resource type values to be scalar as resources are abstract datatypes which are currently based on integers. This implementation detail should not be relied upon, as it may change.
See also is_bool(), is_numeric(), is_float(), is_int(), is_real(), is_string(), is_object(), is_array(), and is_integer().
Returns TRUE if var is a string, FALSE otherwise.
See also is_bool(), is_int(), is_integer(), is_float(), is_real(), is_object(), and is_array().
Returns TRUE if var exists; FALSE otherwise.
If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.
Warning: isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.
<?php $var = ''; // This will evaluate to TRUE so the text will be printed. if (isset($var)) { echo "This var is set set so I will print."; } // In the next examples we'll use var_dump to output // the return value of isset(). $a = "test"; $b = "anothertest"; var_dump(isset($a)); // TRUE var_dump(isset($a, $b)); // TRUE unset ($a); var_dump(isset($a)); // FALSE var_dump(isset($a, $b)); // FALSE $foo = NULL; var_dump(isset($foo)); // FALSE ?> |
This also work for elements in arrays:
<?php $a = array ('test' => 1, 'hello' => NULL); var_dump(isset($a['test'])); // TRUE var_dump(isset($a['foo'])); // FALSE var_dump(isset($a['hello'])); // FALSE // The key 'hello' equals NULL so is considered unset // If you want to check for NULL key values then try: var_dump(array_key_exists('hello', $a)); // TRUE ?> |
Óçìåßùóç: ÅðåéäÞ áõôü åßíáé ìéá äïìÞ ôçò ãëþóóáò êáé ü÷é ìéá óõíÜñôçóç, äåí ìðïñåß íá êáëåóôåß ÷ñçóéìïðïéþíôáò óõíáñôÞóåéò ìåôáâëçôþí
See also empty(), unset(), defined(), the type comparison tables, array_key_exists(), and the error control @ operator.
Óçìåßùóç: The return parameter was added in PHP 4.3.0
print_r() displays information about a variable in a way that's readable by humans. If given a string, integer or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects. print_r() and var_export() will also show protected and private properties of objects with PHP 5, on the contrary to var_dump().
Remember that print_r() will move the array pointer to the end. Use reset() to bring it back to beginning.
<pre> <?php $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); print_r ($a); ?> </pre> |
Which will output:
<pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) </pre> |
If you would like to capture the output of print_r(), use the return parameter. If this parameter is set to TRUE, print_r() will return its output, instead of printing it (which it does by default).
Óçìåßùóç: If you need to capture the output of print_r() with a version of PHP prior to 4.3.0, use the output-control functions.
Óçìåßùóç: Prior to PHP 4.0.4, print_r() will continue forever if given an array or object that contains a direct or indirect reference to itself. An example is print_r($GLOBALS) because $GLOBALS is itself a global variable that contains a reference to itself.
See also ob_start(), var_dump() and var_export().
serialize() returns a string containing a byte-stream representation of value that can be stored anywhere.
This is useful for storing or passing PHP values around without losing their type and structure.
To make the serialized string into a PHP value again, use unserialize(). serialize() handles all types, except the resource-type. You can even serialize() arrays that contain references to itself. References inside the array/object you are serialize()ing will also be stored.
When serializing objects, PHP will attempt to call the member function __sleep() prior to serialization. This is to allow the object to do any last minute clean-up, etc. prior to being serialized. Likewise, when the object is restored using unserialize() the __wakeup() member function is called.
Óçìåßùóç: In PHP 3, object properties will be serialized, but methods are lost. PHP 4 removes that limitation and restores both properties and methods. Please see the Serializing Objects section of Classes and Objects for more information.
ÐáñÜäåéãìá 1. serialize() example
|
See Also: unserialize().
Set the type of variable var to type.
Possibles values of type are:
"boolean" (or, since PHP 4.2.0, "bool")
"integer" (or, since PHP 4.2.0, "int")
"float" (only possible since PHP 4.2.0, for older versions use the deprecated variant "double")
"string"
"array"
"object"
"null" (since PHP 4.2.0)
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also gettype(), type-casting and type-juggling.
Returns the string value of var. See the documentation on string for more information on converting to string.
var may be any scalar type. You cannot use strval() on arrays or objects.
See also floatval(), intval(), settype() and Type juggling.
unserialize() takes a single serialized variable (see serialize()) and converts it back into a PHP value. The converted value is returned, and can be an integer, float, string, array or object. In case the passed string is not unserializeable, FALSE is returned.
unserialize_callback_func directive: It's possible to set a callback-function which will be called, if an undefined class should be instantiated during unserializing. (to prevent getting an incomplete object "__PHP_Incomplete_Class".) Use your php.ini, ini_set() or .htaccess to define 'unserialize_callback_func'. Everytime an undefined class should be instantiated, it'll be called. To disable this feature just empty this setting. Also note that the directive unserialize_callback_func directive became available in PHP 4.2.0.
If the variable being unserialized is an object, after successfully reconstructing the object PHP will automatically attempt to call the __wakeup() member function (if it exists).
ÐáñÜäåéãìá 1. unserialize_callback_func example
|
Óçìåßùóç: In PHP 3, methods are not preserved when unserializing a serialized object. PHP 4 removes that limitation and restores both properties and methods. Please see the Serializing Objects section of Classes and Objects or more information.
ÐáñÜäåéãìá 2. unserialize() example
|
See also serialize().
unset() destroys the specified variables. Note that in PHP 3, unset() will always return TRUE (actually, the integer value 1). In PHP 4, however, unset() is no longer a true function: it is now a statement. As such no value is returned, and attempting to take the value of unset() results in a parse error.
The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy.
If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.
<?php function destroy_foo() { global $foo; unset($foo); } $foo = 'bar'; destroy_foo(); echo $foo; ?> |
If a variable that is PASSED BY REFERENCE is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.
<?php function foo(&$bar) { unset($bar); $bar = "blah"; } $bar = 'something'; echo "$bar\n"; foo($bar); echo "$bar\n"; ?> |
If a static variable is unset() inside of a function, unset() destroys the variable and all its references.
The above example would output:If you would like to unset() a global variable inside of a function, you can use the $GLOBALS array to do so:
Óçìåßùóç: ÅðåéäÞ áõôü åßíáé ìéá äïìÞ ôçò ãëþóóáò êáé ü÷é ìéá óõíÜñôçóç, äåí ìðïñåß íá êáëåóôåß ÷ñçóéìïðïéþíôáò óõíáñôÞóåéò ìåôáâëçôþí
See also isset(), empty(), and array_splice().
This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.
In PHP only public properties of objects will be returned in the output. var_export() and print_r() will also return protected and private properties.
Õðüäåéîç: ¼ðùò ìå ïôéäÞðïôå ðáñÜãåé ôá áðïôåëÝóìáô ôïõ êáôåõèåßáí óôïí browser, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôéò óõíáñôÞóåéò åëÝã÷ïõ åîüäïõ ãéá íá ðÜñåôå ôçí Ýîïäï áõôÞò ôçò óõíÜñôçóçò êáé íá ôçí áðïèçêåýóåôå óå Ýíá string (ãéá ðáñÜäåéãìá).
See also var_export() and print_r().
(PHP 4 >= 4.2.0, PHP 5)
var_export -- Outputs or returns a parsable string representation of a variableThis function returns structured information about the variable that is passed to this function. It is similar to var_dump() with two exceptions. The first one is that the returned representation is valid PHP code, the second that it will also return protected and private properties of an object with PHP 5.
You can also return the variable representation by using TRUE as second parameter to this function.
<?php $a = array (1, 2, array ("a", "b", "c")); var_export($a); ?> |
output:
array ( 0 => 1, 1 => 2, 2 => array ( 0 => 'a', 1 => 'b', 2 => 'c', ), ) |
<?php $b = 3.1; $v = var_export($b, true); echo $v; ?> |
output:
3.1 |
See also var_dump() and print_r().
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
This extension has been moved from PHP as of PHP 4.3.0 and now vpopmail lives in PECL.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(4.0.5 - 4.2.3 only)
vpopmail_auth_user -- Attempt to validate a username/domain/password. Returns true/falseÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
This extension is a generic extension API to DLLs. This was originally written to allow access to the Win32 API from PHP, although you can also access other functions exported via other DLLs.
Currently supported types are generic PHP types (strings, booleans, floats, integers and nulls) and types you define with w32api_deftype().
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
This extension defines one resource type, used for user defined types. The name of this resource is "dynaparm".
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
This example gets the amount of time the system has been running and displays it in a message box.
ÐáñÜäåéãìá 1. Get the uptime and display it in a message box
|
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
If you would like to define a type for a w32api call, you need to call w32api_deftype(). This function takes 2n+1 arguments, where n is the number of members the type has. The first argument is the name of the type. After that is the type of the member followed by the members name (in pairs). A member type can be a user defined type. All the type names are case sensitive. Built in type names should be provided in lowercase. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
(4.2.0 - 4.2.3 only)
w32api_init_dtype -- Creates an instance of the data type typename and fills it with the values passedÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function creates an instance of the data type named typename, filling in the values of the data type. The typename parameter is case sensitive. You should give the values in the same order as you defined the data type with w32api_deftype(). The type of the resource returned is dynaparm.
(4.2.0 - 4.2.3 only)
w32api_invoke_function -- Invokes function funcname with the arguments passed after the function nameÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
w32api_invoke_function() tries to find the previously registered function, named funcname, passing the parameters you provided. The return type is the one you set when you registered the function, the value is the one returned by the function itself. Any of the arguments can be of any PHP type or w32api_deftype() defined type, as needed.
(4.2.0 - 4.2.3 only)
w32api_register_function -- Registers function function_name from library with PHPÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function tries to find the function_name function in libary, and tries to import it into PHP. The function will be registered with the given return_type. This type can be a generic PHP type, or a type defined with w32api_deftype(). All type names are case sensitive. Built in type names should be provided in lowercase. ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
This function sets the method call type. The parameter can be one of the constants DC_CALL_CDECL or DC_CALL_STD. The extension default is DC_CALL_STD.
These functions are intended for work with WDDX.
In order to use WDDX, you will need to install the expat library (which comes with Apache 1.3.7 or higher).
After installing expat compile PHP with --enable-wddx.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
All the functions that serialize variables use the first element of an array to determine whether the array is to be serialized into an array or structure. If the first element has string key, then it is serialized into a structure, otherwise, into an array.
ÐáñÜäåéãìá 2. Using incremental packets with WDDX
This example will produce:
|
Óçìåßùóç: If you want to serialize non-ASCII characters you have to set the appropriate locale before doing so (see setlocale()).
wddx_add_vars() is used to serialize passed variables and add the result to the packet specified by the packet_id. The variables to be serialized are specified in exactly the same way as wddx_serialize_vars().
wddx_deserialize() takes a packet string and deserializes it. It returns the result which can be string, number, or array. Note that structures are deserialized into associative arrays.
wddx_packet_end() ends the WDDX packet specified by the packet_id and returns the string with the packet.
(PHP 3>= 3.0.7, PHP 4 , PHP 5)
wddx_packet_start -- Starts a new WDDX packet with structure inside itUse wddx_packet_start() to start a new WDDX packet for incremental addition of variables. It takes an optional comment string and returns a packet ID for use in later functions. It automatically creates a structure definition inside the packet to contain the variables.
wddx_serialize_value() is used to create a WDDX packet from a single given value. It takes the value contained in var, and an optional comment string that appears in the packet header, and returns the WDDX packet.
wddx_serialize_vars() is used to create a WDDX packet with a structure that contains the serialized representation of the passed variables.
wddx_serialize_vars() takes a variable number of arguments, each of which can be either a string naming a variable or an array containing strings naming the variables or another array, etc.
The above example will produce:
<wddxPacket version='1.0'><header/><data><struct><var name='a'><number>1</number></var> <var name='b'><number>5.5</number></var><var name='c'><array length='3'> <string>blue</string><string>orange</string><string>violet</string></array></var> <var name='d'><string>colors</string></var></struct></data></wddxPacket> |
Ç XML (eXtensible Markup Language) åßíáé ìéá ìïñöÞ äåäïìÝíùí ãéá áíôáëëáãÞ äïìçìÝíùí áñ÷åßùí óôï Web. Åßíáé Ýíá standard êáèïñéóìÝíï áðü ôï The World Wide Web consortium (W3C). Ðëçñïöïñßåò ó÷åôéêÜ ìå ôçí XML êáé ôéò óõó÷åôéæüìåíåò ì'áõôÞí ôå÷íïëïãßåò ìðïñåßôå íá âñåßôå óôï http://www.w3.org/XML/.
ÁõôÞ ç åðÝêôáóç ôçò PHP õëïðïéåß õðïóôÞñéîç ãéá ôçí expat ôïõ James Clark óôçí PHP. Áõôü ôï åñãáëåßï óáò åðéôñÝðåôáé íá ìåôáãëùôßóåôå, áëëÜ ü÷é íá åëÝíîåôå ôçí åãêõñüôçôá, ôùí XML áñ÷åßùí. Õðïóôçñßæåé ôñßá ðçãÝò êùäéêïðïßçóçò ÷áñáêôÞñùí ðïõ ðáñÝ÷ïíôáé åðßóçò êáé áðü ôçí by PHP: ôçí US-ASCII, ôçí ISO-8859-1 êáé ôçí UTF-8. Ç UTF-16 äåí õðïóôçñßæåôáé.
ÁõôÞ ç åðÝêôáóç óáò åðéôñÝðåé íá äçìéïõñãÞóåôå XML parsers êáé óôç óõíÝ÷åéá íá ïñßóåôå handlers ãéá äéáöïñåôéêÜ XML events. Ï êÜèå XML parser Ý÷åé åðßóçò êáé ìåñéêÝò ðáñáìÝôñïõò ôéò ïðïßåò ìðïñåßôå íá ñõèìßóåôå.
ÁõôÞ ç åðÝêôáóç ÷ñçóéìïðïéåß ôçí expat, ç ïðïßá ìðïñåß íá âñåèåß óôï http://www.jclark.com/xml/expat.html. Ç Makefile ðïõ óõíïäåýåé ôçí expat äåí äçìéïõñãåß ìéá library åê ôùí ðñáãìÜôùí, ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå áõôü ãéá íá äçìéïõñãÞóåôå Ýíáí êáíüíá ãéá åêåßíï:
libexpat.a: $(OBJS) ar -rc $@ $(OBJS) ranlib $@ |
ÁõôÝò ïé óõíáñôÞóåéò åßíáé åíåñãïðïéçìÝíåò by default, ÷ñçóéìïðïéþíôáò ôçí bundled expat library. Ìðïñåßôå íá áðåíåñãïðïéÞóåôå ôçí õðïóôÞñéîç ôçò XML ìå ôçí --disable-xml. Áí êÜíåôå compile ôçí PHP ùò module ãéá ôïí Apache 1.3.9 êáé ìåôÜ, ç PHP èá ÷ñçóéìïðïéÞóåé áõôüìáôá ôçí bundled expat library áðü ôïí Apache. Óå ðåñßðôùóç ðïõ äå èÝëåôå íá ÷ñçóéìïðïéÞóåôå ôçí bundled expat library ñõèìßóôå ôçí PHP --with-expat-dir=DIR, üðïõ ç DIR èá ðñÝðåé íá äåß÷íåé óôï âáóéêü êáôÜëïãï åãêáôÜóôáóçò ôïõ expat.
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Ç xml resource üðùò åðéóôñÝöåôáé áðü ôçí xml_parser_create() êáé ôçí xml_parser_create_ns() êÜíåé áíáöïñÜ óå Ýíá óôéãìéüôõðï ôïõ xml parser ãéá íá ÷ñçóéìïðïéçèåß ìå ôéò óõíáñôÞóåéò ðïõ ðáñÝ÷ïíôáé áðü áõôÞ ôçí åðÝêôáóç.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ïé event handlers (÷åéñéóôÝò ãåãïíüôùí) ôçò XML ðïõ Ý÷ïõí ïñéóôåß åßíáé:
Ðßíáêáò 1. XML handlers ðïõ õðïóôçñßæïíôáé
ÓõíÜñôçóç ôçò PHP ðïõ ïñßæåé ôïí handler | ÐåñéãñáöÞ Event |
---|---|
xml_set_element_handler() | Ôá events åíüò óôïé÷åßïõ åíåñãïðïéïýíôáé üôáí ï XML parser óõíáíôÜ tags áñ÷Þò Þ ôÝëïõò. ÕðÜñ÷ïõí îå÷ùñéóôïß handlers ãéá tags áñ÷Þò êáé tags ôÝëïõò. |
xml_set_character_data_handler() | Ôá äåäïìÝíá ÷áñáêôÞñùí åßíáé ó÷åäüí üëá ôá ðåñéå÷üìåíá ôùí XML áñ÷åßùí ðïõ äåí åßíáé markup, óõìðåñéëáìâáíïìÝíïõ ôùí êåíþí áíÜìåóá óôá tags. Óçìåéþóôå üôé ï XML parser äåí ðñïóèÝôåé Þ áöáéñåß êÜðïéï êåíü, åîáñôÜôáé áðü ôçí åöáñìïãÞ óáò (áðü åóÜò) íá áðïöáóéóèåß áí ôá êåíÜ åßíáé óçìáíôéêÜ. |
xml_set_processing_instruction_handler() | Ïé ðñïãñáììáôéóôÝò óå PHP Ý÷ïõí ïéêåéüôçôá ìå åíôïëÝò äéáäéêáóéþí (processing instructions - PIs). Ç <?php ?> åßíáé ìéá processing instruction, üðïõ ç php êáëåßôáé "PI target". Ï ÷åéñéóìüò áõôþí êáèïñßæåôáé áðü ôéò åöáñìïãÝò, åêôüò áðü ôï ïôé üëïé ïé PI targets ðïõ áñ÷ßæïõí ìå "XML" åßíáé äåóìåõìÝíïé. |
xml_set_default_handler() | ¼,ôé äåí ðÜåé óå êÜðïéï Üëëï handler ðçãáßíåé óôïí ðñïêáèïñéóìÝíï handler. Èá ðÜñåôå ðñÜãìáôá üðùò ç XML êáé ç äÞëùóç ôýðùí ôïõ áñ÷åßïõ óôï ðñïêáèïñéóìÝíï handler. |
xml_set_unparsed_entity_decl_handler() | Áõôüò ï handler èá êáëåßôáé ãéá äÞëùóç ìéá ïíôüôçôáò (NDATA) óôçí ïðïßá äåí Ý÷åé ãßíåé parse. |
xml_set_notation_decl_handler() | Áõôüò ï handler êáëåßôáé ãéá äÞëùóç ìéá óçìåßùóçò (notation). |
xml_set_external_entity_ref_handler() | Áõôüò ï handler êáëåßôáé üôáí ï XML parser âñßóêåé ìéá áíáöïñÜ óå ìéá åîùôåñéêÜ ìåôáãëùôôéóìÝíç ãåíéêÞ ïíôüôçôá. Áõôü ìðïñåß íá åßíáé íáíáöïñÜ óå Ýíá áñ÷åßï Þ óå Ýíá URL, ãéá ðáñÜäåéãìá. Äåßôå ôï ðáñÜäåéãìá ãéá åîùôåñéêÝò ïíôüôçôåò ãéá ìéá åðßäåéîç. |
Ïé óõíáñôÞóåéò ðïõ ÷åéñßæïíôáé Ýíá óôïé÷åßï ìðïñïýí íá ðÜñïõí ôá element ïíüìáôá ôïõò ùò case-folded. Ôï Case-folding ïñßæåôáé áðü ôï standard ôçò XML ùò "ç äéáäéêáóßá ðïõ åöáñìüæåôáé óå ìéá áêïëïõèßá ÷áñáêôÞñùí, óôçí ïðïßá áõôïß ïé identified ùò ìç-êåöáëáßïé áíôéêáèßóôáíôáé áðü ôïõò áíôßóôïé÷ïõò ôïõò êåöáëáßïõò". Ìå Üëëá ëüãéá, üôáí åñ÷üìáóôå óôçí XML, ôï case-folding óçìáßíåé áðëÜ ìåôáôñïðÞ óå êåöáëáßá.
Åßíáé ðñïêáèïñéóìÝíï üôé üëá ôá ïíüìáôá ôùí óôïé÷åßùí ðïõ ðåñíïýí óå óõíáñôÞóåéò handler åßíáé case-folded. ÁõôÞ ç óõìðåñéöïñÜ ìðïñåß íá åñùôçèåß êáé íá åëåí÷èåß áíÜ XML parser ìå ôéò óõíáñôÞóåéò xml_parser_get_option() êáé xml_parser_set_option() , áíôßóôïé÷á.
Ïé áêüëïõèåò óôáèåñÝò Ý÷ïõí ïñéóôåß ãéá êùäéêïýò ëÜèïõò ôçò XML (üðùò åðéóôñÝöïíôáé áðü ôçí xml_parse()):
XML_ERROR_NONE |
XML_ERROR_NO_MEMORY |
XML_ERROR_SYNTAX |
XML_ERROR_NO_ELEMENTS |
XML_ERROR_INVALID_TOKEN |
XML_ERROR_UNCLOSED_TOKEN |
XML_ERROR_PARTIAL_CHAR |
XML_ERROR_TAG_MISMATCH |
XML_ERROR_DUPLICATE_ATTRIBUTE |
XML_ERROR_JUNK_AFTER_DOC_ELEMENT |
XML_ERROR_PARAM_ENTITY_REF |
XML_ERROR_UNDEFINED_ENTITY |
XML_ERROR_RECURSIVE_ENTITY_REF |
XML_ERROR_ASYNC_ENTITY |
XML_ERROR_BAD_CHAR_REF |
XML_ERROR_BINARY_ENTITY_REF |
XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF |
XML_ERROR_MISPLACED_XML_PI |
XML_ERROR_UNKNOWN_ENCODING |
XML_ERROR_INCORRECT_ENCODING |
XML_ERROR_UNCLOSED_CDATA_SECTION |
XML_ERROR_EXTERNAL_ENTITY_HANDLING |
Ç åðÝêôáóç óå XML ôçò PHP õðïóôçñßæåé ôï óýíïëï ÷áñáêôÞñùí Unicode äéáìÝóïõ äéáöïñåôéêþí êùäéêïðïéÞóåùí ÷áñáêôÞñùí. ÕðÜñ÷ïõí äýï ôýðïé êùäéêïðïßçóçò ÷áñáêôÞñùí, ç source êùäéêïðïßçóç êáé ç target êùäéêïðïßçóç. ç åóùôåñéêÞ áíáðáñÜóôáóç ôçò PHP åíüò áñ÷åßïõ åßíáé ðÜíôá êùäéêïðïéçìÝíç ìå UTF-8.
Ç Source êùäéêïðïßçóç ãßíåôáé üôáí Ýíá XML áñ÷åßï ìåôáãëùôôßæåôáé. ¼ôáí äçìéïõñãåßôáé Ýíáò XML parser, ç source êùäéêïðïßçóç ìðïñåß íá ðñïóäéïñéóôåß (áõôÞ ç êùäéêïðïßçóç äåí ìðïñåß íá áëëÜîåé áñãüôåñá óôï ÷ñüíï æùÞò ôïõ XML parser). Ïé source êùäéêïðïéÞóåéò ðïõ õðïóôçñßæïíôáé åßíáé ç ISO-8859-1, ç US-ASCII êáé ç UTF-8. Ïé äõï ðñþôåò åßíáé single-byte êùäéêïðïéÞóåéò, ôï ïðïßï óçìáßíåé üôé êÜèå ÷áñáêôÞñáò áíáðáñßóôáôáé áðü Ýíá ìüíï byte. Ç UTF-8 ìðïñåß íá êùäéêïðïéÞóåé ÷áñáêôÞñåò ðïõ áðïôåëïýíôáé áðü Ýíáí ìåôáâëçôü áñéèìü áðü bits (ìÝ÷ñé 21) áðü Ýíá ìÝ÷ñé ôÝóóåôá bytes. Ç ðñïêáèïñéóìÝíç source êùäéêïðïßçóç ðïõ ÷ñçóéìïðïéåßôáé óôçí PHP åßíáé ç ISO-8859-1.
Ç Target êùäéêïðïßçóç ãßíåôáé üôáí ç PHP ìåôáöÝñåé äåäïìÝíá óå XML handler óõíáñôÞóåéò. ¼ôáí Ýíáò XML parser äçìéïõñãåßôáé, ç target êùäéêïðïßçóç ïñßæåôáé ßäéá ìå ôçí source êùäéêïðïßçóç, áëëÜ áõôü ìðïñåß íá áëëÜîåé óå ïðïéïäÞðïôå óçìåßï. Ç target êùäéêïðïßçóç èá åðçñåÜóåé ôá äåäïìÝíá ôùí ÷áñáêôÞñùí êáèþò åðßóçò êáé ôá ïíüìáôá ôùí tags êáé ôá processing instruction targets.
Áí ï XML parser óõíáíôÞóåé ÷áñáêôÞñåò åêôüò ðåäßïõ ðïõ ç source êùäéêïðïßçóç ìðïñåß íá áíáðáñáóôÞóåé, èá åðéóôñÝøåé Ýíá ëÜèïò.
Áí ç PHP óõíáôÞóåé ÷áñáêôÞñåò óôï ìåôáãëùôôéóìÝíï XML áñ÷åßï ðïõ äåí ìðïñåß íá áíáðáñáóôÞóåé óôçí åðéëåãìÝíç target êùäéêïðïßçóç, ïé ðñïâëçìáôéêïß ÷áñáêôÞñåò èá "õðïâéâáóôïýí". Ðñïó ôï ðáñüí, áõôü óçìáßíåé üôé ôÝôïéïé ÷áñáêôÞñåò áíôéêáèßóôáíôáé áðü ôï áããëéêü åñùôçìáôéêü.
Åäþ õðÜñ÷ïõí ìåñéêÜ åíäåéêôéêÜ PHP scripts ðïõ êÜíïõí ìåôáãëþôôéóç óå XML áñ÷åßá.
Ôï ðñþôï ðáñÜäåéãìá åìöáíßæåé ôç äïìÞ ôùí áñ÷éêþí elements óå Ýíá áñ÷åßï ìå åóï÷Ýò.
ÐáñÜäåéãìá 1. ÅìöÜíéóç ôçò äïìÞò åíüò XML Element
|
ÐáñÜäåéãìá 2. Áíôéóôïé÷ßá XML óå HTML Áõôü ôï ðáñÜäåéãìá áíôéóôïé÷åß ôá tags óå Ýíá XML áñ÷åßï êáôåõèåßáí óå HTML tags. Ôá Elements ðïõ äåí õðÜñ÷ïõí óôïí "map array" áãíïïýíôáé. ÖõóéêÜ, áõôü ôï ðáñÜäåéãìá èá äïõëÝøåé ìå Ýíá óõãêåêñéìÝíï XML ôýðï áñ÷åßïõ.
|
Áõôü ôï ðáñÜäåéãìá áíôéêáôïðôñßæåé ôïí XML êþäéêá. Äåß÷íåé ðùò íá ÷ñçóéìïðïéÞóåôå Ýíáí external entity reference handler ãéá íá óõìðåñéëÜâåôå êáé íá êÜíåôå parse êáé óå Üëëá áñ÷åßá, êáèþò åðßóçò êáé ðþò ïé PIs ìðïñïýí íá åêôåëåóôïýí, êáé Ýíáí ôñüðï ãéá íá êáèïñéóôïýí ïé "Ýìðéóôïé" PIs ðïõ ðåñéÝ÷ïõí êþäéêá.
Ôá XML áñ÷åßá ðïõ ìðïñïýí íá ÷ñçóéìïðïéçèïýí ó'áõôü ôï ðáñÜäåéãìá âñßóêïíôáé êÜôù áðü ôï ðáñÜäåéãìá (xmltest.xml êáé xmltest2.xml.)
ÐáñÜäåéãìá 3. ÐÜñáäåéãìá ãéá External Entity
|
ÐáñÜäåéãìá 4. xmltest.xml
|
Áõôü ôï áñ÷åßï óõìðåñéëáìâÜíåôáé áðü ôï xmltest.xml:
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
utf8_decode -- ÌåôáôñÝðåé Ýíá string ìå ISO-8859-1 ÷áñáêôÞñåò êùäéêïðïéçìÝíï ìå UTF-8 óå single-byte ISO-8859-1.ÁõôÞ ç óõíÜñôçóç áðïêùäéêïðïéåß ôá data, ðïõ õðïèÝôïõìå üôé åßíáé êùäéêïðïéçìÝíá óå UTF-8, óå ISO-8859-1.
Äåßôå åðßóçò ôï utf8_encode() ãéá åîÞãçóç ôçò UTF-8 êùäéêïðïßçóçò.
ÁõôÞ ç óõíÜñôçóç êùäéêïðïéåß Ýíá string data óå UTF-8, êáé åðéóôñÝöåé ôçí êùäéêïðïéçìÝíç Ýêäïóç. Ôï UTF-8 åßíáé Ýíáò standard ìç÷áíóéìüò ðïõ ÷ñçóéìïðïéåßôáé áðü ôçí Unicode ãéá êùäéêïðïßçóç wide ÷áñáêôÞñùí ôéìþí óå Ýíá byte stream. Ç UTF-8 åßíáé äéáöáíÞò óå áðëïýò ASCII ÷áñáêôÞñåò, åßíáé self-synchronized (ðïõ óçìáßíåé üôé åßíáé äõíáôü ãéá Ýíá ðñüãñáììá íá äéáêñßíåé ðïý áñ÷ßæïõí ïé ÷áñáêôÞñåò óå Ýíá bytestream) êáé ìðïñåß íá ÷ñçóéìïðïéçèåß ìå êáíïíéêÝò óõíáñôÞóåéò óýãêñéóçò strings ãéá ôáîéíüìçóç êáé Üëëá. Ç PHP êùäéêïðïéåß ôïõò UTF-8 ÷áñáêôÞñåò óå ìÝ÷ñé ôÝóóåñá bytes, ùò åîÞò:
ÊÜèå b áíáðáñéóôÜ Ýíá bit ðïõ ìðïñåß íá ÷ñçóéìïðïéåß ãéá íá áðïèçêåýóåé äåäïìÝíá ÷áñáêôÞñùí.
¸íá error code áðü ôçí xml_get_error_code().
ÅðéóôñÝöåé Ýíá string ìå ìéá ðåñéãñáöÞ ôïõ êþäéêá ëÜèïõò code, Þ FALSE áí äåí âñåèåß êÜðïéá ðåñéãñáöÞ.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_get_current_byte_index -- Ðáßñíåé ôï ôñÝ÷ïí byte index ãéá Ýíáí XML parser
Ìéá áíáöïñÜ óôïí XML parser ãéá íá ðÜñåé byte index.
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé FALSE áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser, Þ äéáöïñåôéêÜ åðéóôñÝöåé ôï byte index óôï ïðïßï âñßóêåôáé ï parser óôïí data buffer ôïõ (îåêéíÜ áðü ôï 0).
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_get_current_column_number -- Ðáßñíåé ôïí ôñÝ÷ïí áñéèìü ôçò óôÞëçò ãéá Ýíáí XML parser
Ìéá áíáöïñÜ óôïí XML parser áð'ôï ïðïßï ðáßñíåé ôïí áñéèìü ôçò óôÞëçò.
ÁõôÞ ç óõíÜñôçóç åéóôñÝöåé FALSE áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser, Þ äéáöïñåôéêÜ åðéóôñÝöåé óå ðïéá óôÞëç óôçí ôñÝ÷ïõóá ãñáììÞ (üðùò äßíåôáé áðü ôçí xml_get_current_line_number()) âñßóêåôáé åêåßíç ôç óôéãìÞ ï parser.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_get_current_line_number -- ðáßñíåé óôïí ôñÝ÷ïí áñéèìü ãñáììÞ ãéá Ýíáí XML parser
Ìéá áíáöïñÜ óôïí XML parser áðü ôïí ïðïßï ðáßñíåé ôïí áñéèìü ãñáììÞò.
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé FALSE áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser, Þ äéáöïñåôéêÜ åðéóôñÝöåé ôç ãñáììÞ óôçí ïðïßá âñßóêåôáé ï parser ìÝóá óôï data buffer ôïõ.
Ìéá áíáöïñÜ óôïí XML parser áðü ôïí ïðïßïí ðáßñíåé ôï êùäéêü ëÜèïõò (error code).
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé FALSE áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser, Þ äéáöïñåôéêÜ åðéóôñÝöåé Ýíáí áðü ôïõò êùäéêïýò ëÜèïõò ðïõ áíáöÝñïíôáé óôï ôìÞìá ìå ôá error codes.
(PHP 3>= 3.0.8, PHP 4 , PHP 5)
xml_parse_into_struct -- Ìåôáãëùôßæåé ôá XML äåäïìÝíá óå ìéá äïìÞ ðßíáêáÁõôÞ ç óõíÜñôçóç ìåôáãëùôôßæåé Ýíá XML áñ÷åßï óå 2 ðáñÜëëçëåò äïìÝò ðéíÜêùí, ç ìßá (index) ðåñéÝ÷åé äåßêôåò óôçí ðåñéï÷Þ ôùí êáôÜëëçëùí ôéìþí óôïí ðßíáêá ôùí values . ÁõôÝò ïé ôåëåõôáßåò äõï ðáñÜìåôñïé ðñÝðåé íá ðåñáóôïýí ìå áíáöïñÜ.
ÐáñáêÜôù õðÜñ÷åé Ýíá ðáñÜäåéãìá ðïõ äåß÷íåé ôçí åóùôåñéêÞ äïìÞ ôùí ðéíÜêùí ðïõ ðáñÜãïíôáé áðü ìéá ôÝôïéá óõíÜñôçóç. ×ñçóéìïðïéïýìå Ýíá áðëü note tag ðïõ åìðåñéÝ÷åôå ìÝóá óå Ýíá para tag, êáé óôç óõíÝ÷åéá ìåôáãëùôßæïõìå áõôü êáé åêôõðþíïõìå ôéò äïìÝò ðïõ ðáñÜãïíôáé:
<?php $simple = "<para><note>simple note</note></para>"; $p = xml_parser_create(); xml_parse_into_struct($p,$simple,$vals,$index); xml_parser_free($p); echo "Index array\n"; print_r($index); echo "\nVals array\n"; print_r($vals); ?> |
When we run that code, the output will be:
Index array Array ( [PARA] => Array ( [0] => 0 [1] => 2 ) [NOTE] => Array ( [0] => 1 ) ) Vals array Array ( [0] => Array ( [tag] => PARA [type] => open [level] => 1 ) [1] => Array ( [tag] => NOTE [type] => complete [level] => 2 [value] => simple note ) [2] => Array ( [tag] => PARA [type] => close [level] => 1 ) ) |
Ç ìåôáãëþôôéóç ðïõ åßíáé Event-driven (âáóéóìÝíç óôçí expat library) ìðïñåß íá ãßíåé ðåñßðëïêç üôáí Ý÷åôå Ýíá XML áñ÷åßï ðïõ åßíáé ðåñßðëïêï. ÁõôÞ ç óõíÜñôçóç äåí ðáñÜãåé Ýíá DOM style object, áëëÜ ðáñÜãåé äïìÝò ðïõ ìðïñïýí íá ðñïóðåëáóôïýí üðùò Ýíá äÝíôñï. Óõíåðþò, ìðïñïýìå íá äçìéïõñãÞóïõìå objects åýêïëá ðïõ áíáðáñéóôïýí äåäïìÝíá óôï XML áñ÷åßï. Áò èåùñÞóïõìå ôï áêüëïõèï XML áñ÷åßï ðïõ áíáðáñéóôÜ ìéá ìéêñÞ âÜóç äåïäìÝíùí áðü ðëçñïöïñßåò ãéá áìéíïîÝá:
ÐáñÜäåéãìá 1. moldb.xml - ìéêñÞ âÜóç äåäïìÝíùí ãéá ìïñéáêÝò ðëçñïöïñßåò
|
ÐáñÜäåéãìá 2. parsemoldb.php - ìåôáãëùôôßæåé ôï moldb.xml êáé ôùí ðßíáêá ôùí objects ìå ôá ìüñéá
|
Ìéá áíáöïñÜ óôïí XML parser ãéá íá ôïí ÷ñçóéìïðïéÞóåé.
ÄåäïìÝíá ðñïò ìåôáãëþôôéóç. ¸íá áñ÷åßï ìðïñåß íá ìåôáãëôùôôéóôåß óùóôÜ áíÜ êïììÜôé êáëþíôáò ôçí xml_parse() áñêåôÝò öïñÝò ìå äéÜöïñá äåäïìÝíá, äåäïìÝíïõ üôé ç is_final ðáñÜìåôñïò äåí Ý÷åé ïñéóôåß êáé åßíáé TRUE üôáí êáé ôï ôåëåõôáßï äåäïìÝíï Ý÷åé ìåôáãëùôôéóôåß.
Áí Ý÷åé ïñéóôåß êáé åßíáé TRUE, ç data åßíáé ôï ôåëåõôáßï êïììÜôé äåäïìÝíùí ðïõ óôÝëíåôáé ðñïò ìåôáãëþôôéóç.
¼ôáí ôï XML áñ÷åßï ìåôáëãùôôßæåôáé, ïé handlers ãéá ôá ñõèìéóìÝíá events êáëïýíôáé üóåò öïñÝò ÷ñåéáóôåß, áöïý áõôÞ ç óõíÜñôçóç åðéóôñÝøåé TRUE Þ FALSE.
TRUE åðéóôñÝöåôáé áí ç ìåôáãëþôôéóç Þôáí åðéôõ÷Þò, FALSE áí äåí Þôáí åðéôõ÷Þò, Þ áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser. Ãéá ìç åðéôõ÷åßò ìåôáãëùôôßóåéò, ìðïñïåßôå íá ðÜñåôå ðëçñïöïñßåò ãéá íá ëÜèç ìå ôéò xml_get_error_code(), xml_error_string(), xml_get_current_line_number(), xml_get_current_column_number() êáé xml_get_current_byte_index().
Ç xml_parser_create_ns() äçìéïõñãåß Ýíáí íÝï XML parser ðïõ õðïóôçñßæåé XML namespace êáé åðéóôñÝöåé Ýíá resource handle ðïõ áíáöÝñåôáé ó'áõôü ãéá íá ÷ñçóéìïðïéçèåß êáé áðü Üëëåò XML óõíáñôÞóåéò.
Ìå Ýíáí parser ðïõ ãíùñßæåé áðü namespace ïé ðáñÜìåôñïé ôùí tags ðïõ ðåñíÜí óôéò äéÜöïñåò handler óõíáñôÞóåéò èá áðïôåëïýíôáé áðü namespace êáé ôï üíïìá ôïõ tag èá äéá÷ùñßæåôáé áðü ôï string ðïõ êáèïñßæåôáé áðü ôïí äéá÷ùñéóôåß Þ ôï ':' ðïõ åßíáé êáé ôï ðñïêáèïñéóìÝíï.
Ç ðñïáéñåôéêÞ êùäéêïðïßçóç êáèïñßæåé ôçí êùäéêïðïßçóç ôùí ÷áñáêôÞñùí ôïõ XML ðïõ åéóÜãåôáé ãéá ìåôáãëþôôéóç. Ïé êùäéêïðïéÞóåéò ðïõ õðïóôçñßæïíôáé åßíáé ç "ISO-8859-1", ðïõ åßíáé åðßóçò êáé ç ðñïêáèïñéóìÝíç áí äåí ðñïóäéïñéóôåß êÜðïéá Üëëç êùäéêïðïßçóç, ç "UTF-8" êáé ç "US-ASCII".
Äåßôå åðßóçò ôçí xml_parser_create(), êáé ôçí xml_parser_free().
Ç xml_parser_create() äçìéïõñãåß Ýíáí íÝï XML parser êáé åðéóôñÝöåé a resïurce handle ðïõ áíáöÝñåôáé ó'áõôüí ãéá íá ÷ñçóéìïðïéçèåß áðü Üëëåò XML óõíáñôÞóåéò.
Ç ðñïáéñåôéêÞ êùäéêïðïßçóç (encoding) ðñïóäéïñßæåé ôçí êùäéêïðïßçóç ÷áñáêôÞñùí óôï XML ðïõ åéóÜãåôáé ðñïò ìåôáãëþôôéóç. Ïé êùäéêïðïéÞóåéò ðïõ õðïóôçñßæïíôáé åßíáé ç "ISO-8859-1", ç ïðïßá åßíáé êáé ç ðñïêáèïñéóìÝíç áí äåí ðñïóäéïñéóôåß êÜðïéá Üëëç êùäéêïðïßçóç, ç "UTF-8" êáé ç "US-ASCII".
Äåßôå åðßóçò ôçí xml_parser_create_ns() êáé xml_parser_free().
ÁíáöïñÜ óôï íá åëåõèåñùèåß Ýíáò XML parser.
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé FALSE áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser, Þ äéáöïñåôéêÜ åëåõèåñþíåé ôïí parser êáé åðéóôñÝöåé TRUE.
ÁíáöïñÜ óå Ýíáí XML parser áðü ôïí ïðïßï ðáßñíåé ìéá åðéëïãÞ.
Ðïéá åðéëïãÞ íá öÝñåé. Äåßôå ôï xml_parser_set_option() ãéá ìéá ëßóôá åðéëïãþí.
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé FALSE áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser, Þ áí ç åðéëïãÞ äåí ìðïñåß íá ïñéóôåß. ÄéáöïñåôéêÜ ç ôéìÞ ôçò åðéëïãÞò åðéóôñÝöåôáé.
Äåßôå ôçí xml_parser_set_option() ãéá ìéá ëßóôá åðéëïãþí.
ÁíáöïñÜ óå Ýíáí XML parser óôïí ïðïßï ïñßæåé ìéá åðéëïãÞ (option).
Ðïéá åðéëïãÞ íá ïñßóåé. Äåßôå ðáñáêÜôù.
Ç íÝá ôéìÞ ôçò åðéëïãÞò.
ÁõôÞ ç óõíÜñôçóç åðéóôñÝöåé FALSE áí ï parser äåí áíáöÝñåôáé óå Ýíáí Ýãêõñï parser, Þ áí ç åðéëïãÞ äåí Ý÷åé ïñéóôåß. ÄéáöïñåôéêÜ ç åðéëïãÞ ïñßæåôáé TRUE êáé åðéóôñÝöåôáé.
Ïé áêüëïõèåò åðéëïãÝò åßíáé äéáèÝóéìåò:
Ðßíáêáò 1. XML parser options
Option constant | Ôýðïò äåäïìÝíùí | ÐåñéãñáöÞ |
---|---|---|
XML_OPTION_CASE_FOLDING | integer | ÅëÝã÷åé áí ôï case-folding åßíáé åíåñãïðïéçìÝíï ãé'áõôüí ôïí XML parser. Åßíáé åíåñãïðïéçìÝíï áðü ôéò áñ÷éêÝò ñõèìßóåéò. |
XML_OPTION_TARGET_ENCODING | string | Ïñßæåé ðïéï target encoding èá ÷ñçóéìïðïéçèåß ó'áõôüí ôïí XML parser. Ôï ðñïêáèïñéóìÝíï åßíáé íá ïñéóôåß ôï ßäéï ìå ôçí source êùäéêïðïßçóç ðïõ ÷ñçóéìïðïéåßôáé áðü ôçí xml_parser_create(). Ïé target êùäéêïðïéÞóåéò ðïõ õðïóôçñßæïíôáé åßíáé ç ISO-8859-1, ç US-ASCII êáé ç UTF-8. |
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_set_character_data_handler -- ïñßæåé handler ãéá äåäïìÝíá ÷áñáêôÞñùíÏñßæåé ôç óõíÜñôçóç ãéá handler äåäïìÝíá ÷áñáêôÞñùí ãéá ôïí XML parser parser. Ï handler åßíáé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá ìéáò óõíÜñôçóçò ðïõ ðñÝðåé íá õðÜñ÷åé üôáí ç xml_parse() êáëåßôáé ãéá parser.
ÁõôÞ ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôïí handler ðñÝðåé íá
äÝ÷åôáé äõï ðáñáìÝôñïõò:
handler ( resource parser, string data)
Ç ðñþôç ðáñÜìåôñïò, parser, åßíáé ìéá áíáöïñÜ óôïí XML parser ðïõ êáëåß ôïí handler.
Ç äåýôåñç ðáñÜìåôñïò, data, ðåñéÝ÷åé ôá äåäïìÝíá ÷áñáêôÞñùí ùò string.
Áí ìéá óõíÜñôçóç handler ïñßæåôáé óå Ýíá êåíü string, Þ åßíáé FALSE, ï handler ðïõ áìöéóâçôåßôáé áðåíåñãïðïéåßôáé.
TRUE åðéóôñÝöåôáé áí ï handler ïñéóôåß, êáé FALSE áí ï parser äåí åßíáé parser.
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
Ïñßæåé ôçí ðñïêáèïñéóìÝíç óõíÜñôçóç ôïõ handler ãéá ôïí XML parser parser. Ï handler åßíáé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá ìéáò óõíÜñôçóçò ðïõ ðñÝðåé íá õðÜñ÷åé üôáí ç xml_parse() êáëåßôáé ãéá parser.
ÁõôÞ ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôïí handler ðñÝðåé íá
äÝ÷åôáé äõï ðáñáìÝôñïõò:
handler ( resource parser, string data)
Ç ðñþôç ðáñÜìåôñïò, parser, åßíáé ìéá áíáöïñÜ óôïí XML parser ðïõ êáëåß ôïí handler.
Ç äåýôåñç ðáñÜìåôñïò, data, ðåñéÝ÷åé ôá äåäïìÝíá ÷áñáêôÞñùí. ÁõôÜ ìðïñåß íá åßíáé äÞëùóç ôçò XML, äÞëùóç ôýðïõ áñ÷åßïõ, ïíôüôçôåò Þ Üëëá äåäïìÝíá ãéá ôá ïðïßá äåí õðÜñ÷ïõí Üëëïé handler.
Áí ìéá óõíÜñôçóç handler ïñéóôåß ìå Ýíá êåíü string, Þ FALSE, ï handler ðïõ áìöéóâçôåßôáé áðåíåñãïðïéåßôáé.
TRUE åðóéôñÝöåôáé üôáí ï handler ïñéóôåß, FALSE áí ï parser äåí åßíáé parser.
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_set_element_handler -- ïñßæåé ôá óôïé÷åßá áñ÷Þò êáé ôÝëïõò ôùí handlersÏñßæåé ôéò óõíáñôÞóåéò handler óôïé÷åßùí ãéá ôïí XML parser parser.Ç start_element_handler êáé ç end_element_handler åßíáé strings ðïõ ðåñéÝ÷ïõí ôá ïíüìáôá ôùí óõíáñôÞóåùí ðïõ ðñÝðåé íá õðÜñ÷ïõí üôáí ç xml_parse() êáëåßôáé ãéá parser.
Ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôçí start_element_handler
ðñÝðåé íá äÝ÷åôáé ôñåéò ðáñáìÝôñïõò:
start_element_handler ( resource parser, string name, array attribs)
Ç ðñþôç ðáñÜìåôñïò, parser, åßíáé ìéá áíáöïñÜ óôïí XML parser ðïõ êáëåß ôïí handler.
Ç äåýôåñç ðáñÜìåôñïò, name, ðåñéÝ÷åé ôï üíïìá ôïõ óôïé÷åßïõ ãéá ôï ïðïßï áõôüò ï handler êáëåßôáé. Áí ôï case-folding Ý÷åé åíåñãïðïéçèåß ãé'áõôüí ôïí parser, ôï üíïìá ôïõ óôïé÷åßïõ èá åßíáé óôá êåöáëáßá.
Ç ôñßôç ðáñÜìåôñïò, attribs, ðåñéÝ÷åé Ýíáí associative array ìå ôá ãíùñßóìáôá (attributes) ôùí óôïé÷åßùí (áí õðÜñ÷ïõí). Ôá êëåéäéÜ (keys) áõôïý ôïõ ðßíáêá (array) åßíáé ôá ïíüìáôá ôùí attribute, êáé ïé ôéìÝò åßíáé ïé ôéìÝò ôùí attributes. Ôá ïíüìáôá ôùí attribute names åßíáé case-folded ìå ôá ßäéá êñéôÞñéá üðùò êáé ôá ïíüìáôá ôùí óôïé÷åßùí. Ïé ôéìÝò ôùí attribute values äåí åßíáé case-folded.
Ç áñ÷éêÞ óåéñÜ ôùí attributes ìðïñåßôå íá ôçí ðÜñåôå áí ðñïóðåëÜóåôå ôá attribs ìå ôïí êáíïíéêü ôñüðï, ÷ñçóéìïðïéþíôáò ôçí each(). Ôï ðñþôï key óôïí array èá åßíáé ôï ðñþôï attribute, ê.ï.ê.
Ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôçí end_element_handler
ðñÝðåé íá äÝ÷åôáé äõï ðáñáìÝôñïõò:
end_element_handler ( resource parser, string name)
Ç ðñþôç ðáñÜìåôñïò, parser, åßíáé ìéá áíáöïñÜ óôïí XML parser üôáí êáëåß ôïí handler.
Ç äåýôåñç ðáñÜìåôñïò, name, ðåñéÝ÷åé ôï üíïìá ôïõ óôïé÷åßïõ ãéá ôï ïðïßï ï handler êáëåßôáé. Áí ôï case-folding Ý÷åé åíåñãïðïéçèåß ãé'áõôüí ôïí parser, ôï üíïìá ôïõ óôïé÷åßïõ èá åßíáé óå êåöáëáßá ãñÜììáôá.
Áí ìéá óõíÜñôçóç handler ïñéóôåß óå êåíü string, Þ FALSE, ï handler õðü áìöéóâÞôçóç áðåíåñãïðïéåßôáé.
TRUE åðéóôñÝöåôáé áí ï handler ïñéóôåß, êáé FALSE áí ï parser äåí åßíáé parser.
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
(PHP 4 >= 4.0.5, PHP 5)
xml_set_end_namespace_decl_handler -- Ïñßæåé ôïí handler ãéá äåäïìÝíá ÷áñáêôÞñùí
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_set_external_entity_ref_handler -- ïñßæåé Ýíáí external entity reference handlerÏñßæåé ôç óõíÜñôçóç ãéá ôïí external entity reference handler ãéá ôïí XML parser parser. Ï handler åßíáé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá ìéáò óõíÜñôçóçò ðïõ ðñÝðåé íá õðÜñ÷åé üôáí ç xml_parse() êáëåßôáé ùò parser.
Ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôïí handler ðñÝðåé íá äÝ÷åôáé
ðÝíôå ðáñáìÝôñïõò, êáé ðñÝðåé íá åðéóôñÝöåé ìéá áêÝñáéá ôéìÞ. Áí ç ôéìÞ
ðïõ åðéóôñÝöåôáé áðü ôïí handler åßíáé FALSE (ôï ïðïßï èá åßíáé áí äåí
åðéóôñáöåß êáìßá ôéìÞ), ï XML parser èá óôáìáôÞóåé íá ìåôáãëùôôßæåé êáé ç
xml_get_error_code() èá åðéóôñÝøåé XML_ERROR_EXTERNAL_ENTITY_HANDLING.
handler ( resource parser, string open_entity_names, string base, string system_id, string public_id)
Ç ðñþôç ðáñÜìåôñïò, parser, åßíáé ìéá áíáöïñÜ óôïí XML parser ðïõ êáëåß ôïí handler.
Ç äåýôåñç ðáñÜìåôñïò, open_entity_names, åßíáé ìéá ëßóôá ïíïìÜôùí áðü ïíôüôçôåò ðïõ äéá÷ùñßæåôáé ìå êåíÜ êáé ïé ïðïßåò ïíôüôçôåò åßíáé áíïéêôÝò ãéá ôç ìåôáãëþôôéóç áõôÞò ôçò ïíôüôçôáò (óõìðåñéëáìâÜíåôáé ôï üíïìá ôçò ïíôüôçôáò ðïõ áíáöÝñåôáé).
ÁõôÞ åßíáé ç âÜóç ãéá íá ðÜñïõìå ôïí identifier ôïõ óõóôÞìáôïò (system_id) áðü ìéá åîùôåñéêÞ entity. Ðñïò ôï ðáñüí áõôÞ ç ðáñÜìåôñïò èá ïñßæåôáé ðÜíôá ßóç ìå Ýíá êåíü string.
Ç ôÝôáñôç ðáñÜìåôñïò, system_id, åßíáé ï identifier ôïõ óõóôÞìáôïò üðùò Ý÷åé ïñéóôåß óôç äÞëùóç ôçò entity.
Ç ðÝìðôç ðáñÜìåôñïò, public_id, åßíáé ï public identifier üðùò ïñßæåôáé óôç äÞëùóç ôçò entity, Þ Ýíá êåíü string áí äåí Ý÷åé ðñïóäéïñéóôåß êÜôé Üëëï. Ôá êåíÜ óôïí public identifier èá Ý÷ïõí êáíïíéêïðïéçèåß üðùò áðáéôåß ôï XML spec.
Áí ìéá óõíÜñôçóç handler ïñéóôåß ßóç ìå Ýíá êåíü string, Þ FALSE, ï handler õðü áìöéóâÞôçóç áðåíåñãïðïéåßôáé.
TRUE åðéóôñÝöåôáé áí ï handler Ý÷åé ïñéóôåß, FALSE áí ï parser äåí åßíáé parser.
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_set_notation_decl_handler -- ïñßæåé ôïí notation declaration handlerÏñßæåé ôç óõíÜñôçóç ãéá ôïí notation declaration handler ãéá ôïí XML parser parser. Ï handler åßíáé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá ìéáò óõíÜñôçóçò ðïõ ðñÝðåé íá õðÜñ÷åé üôáí ç xml_parse() êáëåßôáé ùò parser.
Ìéá notation declaration åßíáé ìÝñïò ôïõ áñ÷åßïõ DTD êáé Ý÷åé ôçí áêüëïõèç ìïñöÞ:
<!NOTATION <parameter>name</parameter> { <parameter>systemId</parameter> | <parameter>publicId</parameter>?> |
Ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôçí handler ðñÝðåé íá
äÝ÷åôáé ðÝíôå ðáñáìÝôñïõò:
handler ( resource parser, string notation_name, string base, string system_id, string public_id)
Ç ðñþôç ðáñÜìåôñïò, parser, åßíáé ìéá áíáöïñÜ óôïí XML parser ðïõ êáëåß ôïí handler.
Áõôü åßíáé ôï name (üíïìá) ôïõ notation, üóïí áöïñÜ ôç ìïñöÞ ôïõ notation ðïõ ðåñéãñÜöåôáé ðáñáðÜíù.
ÁõôÞ åßíáé ç âÜóç ãéá íá ðÜñïõìå ôïí identifier ôïõ óõóôÞìáôïò (system_id) ôïõ notation declaration. Ðñïò ôï ðáñüí áõôÞ ç ðáñÜìåôñïò èá ïñßæåôáé ðÜíôá ßóç ìå Ýíá êåíü string.
Åßíáé ï identifier ôïõ óõóôÞìáôïò ôçò åîùôåñéêÞò notation declaration.
Ï Public identifier ôçò åîùôåñéêÞò notation declaration.
Áí ìéá óõíÜñôçóç handler ïñéóôåß íá åßíáé ßóç ìå Ýíá êåíü string, Þ FALSE, ï handler õðü áìöéóâÞôçóç áðåíåñãïðïéåßôáé.
TRUE åðéóôñÝöåôáé áí ï handler Ý÷åé ïñéóôåß, FALSE áí ï parser äåí åßíáé parser.
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
ÁõôÞ ç óõíÜñôçóç åðéôñÝðåé ôç ÷ñÞóç ôïõ parser ìÝóá óå Ýíá object. ¼ëåò ïé callback óõíáñôÞóåéò èá ìðïñïýóáí íá ïñéóôïýí ìå ôçí xml_set_element_handler() êôë êáé íá õðïôåèåß üôé åßíáé ìÝèïäïé ôïõ object.
<?php class xml { var $parser; function xml() { $this->parser = xml_parser_create(); xml_set_object($this->parser, &$this); xml_set_element_handler($this->parser, "tag_open", "tag_close"); xml_set_character_data_handler($this->parser, "cdata"); } function parse($data) { xml_parse($this->parser, $data); } function tag_open($parser, $tag, $attributes) { var_dump($parser, $tag, $attributes); } function cdata($parser, $cdata) { var_dump($parser, $cdata); } function tag_close($parser, $tag) { var_dump($parser, $tag); } } // end of class xml $xml_parser = new xml(); $xml_parser->parse("<A ID='hallo'>PHP</A>"); ?> |
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_set_processing_instruction_handler -- Ïñßæåé ôïí processing instruction (PI) handlerÏñßæåé ôç óõíÜñôçóç ãéá ôïí processing instruction (PI) handler ãéá ôïí XML parser parser. Ï handler åßíáé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá ôçò óõíÜñôçóçò ðïõ ðñÝðåé íá õðÜñ÷åé üôáí ï xml_parse() êáëåßôáé ãéá parser.
Ìéá processing instruction Ý÷åé ôçí áêüëïõèç ìïñöÞ:
Ìðïñåßôå íá âÜëåôå PHP êþäéêá ìÝóá óå Ýíá ôÝôïéï tag, áëëÜ ðñïóÝîôå Ýíáí ðåñéïñéóìü: óå Ýíá XML PI, ôï tag ôÝëïõò ôïõ PI (?>) äåí ìðïñåß íá åßíáé óå åéóáãùãéêÜ, óõíåðþò áõôÞ ç áêïëïõèßá ÷áñáêôÞñùí äåí ðñÝðåé íá åìöáíéóôåß óôïí PHP êþäéêá ôïí ïðïßï åéóÜãåôå ìå PIs óôá XML áñ÷åßá. Áí êÜôé ôÝôïéï óõìâåß, ôï õðüëïéðï ôïõ PHP êþäéêá, êáèþò åðßóçò êáé ôï "ðñáãìáôéêü" tag ôÝëïõò ôïõ PI , èá ÷ñçóéìïðïéåßôáé ùò äåäïìÝíï ÷áñáêôÞñùí.
ÁõôÞ ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôïí handler ðñÝðåé íá
äÝ÷åôáé ôñåéò ðáñáìÝôñïõò:
handler ( resource parser, string target, string data)
Ç ðñþôç ðáñÜìåôñïò, ï parser, åßíáé ìéá áíáöïñÜ óôïí XML parser ðïõ êáëåß ôïí handler.
Ç äåýôåñç ðáñÜìåôñïò, target, ðåñéÝ÷åé ôïí PI target.
Ç ôñßôç ðáñÜìåôñïò, data, ðåñéÝ÷åé ôá PI äåäïìÝíá.
Áí ìéá óõíÜñôçóç handler ïñéóôåß ßóç ìå Ýíá êåíü string, Þ FALSE, ï handler õðü áìöéóâÞôçóç áðåíåñãïðïéåßôáé.
TRUE åðéóôñÝöåôáé áí ï handler ïñéóôåß, FALSE áí ï parser äåí åßíáé parser.
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
(PHP 3>= 3.0.6, PHP 4 , PHP 5)
xml_set_unparsed_entity_decl_handler -- Ïñßæåé Ýíáí áìåôáãëþôôéóôï entity declaration handlerÏñßæåé ôç óõíÜñôçóç ôïõ áìåôáãëþôôéóôïõ entity declaration handler ãéá ôïí XML parser parser. Ï handler åßíáé Ýíá string ðïõ ðåñéÝ÷åé ôï üíïìá ôçò óõíÜñôçóçò ðïõ ðñÝðåé íá õðÜñ÷åé üôáí ç xml_parse() êáëåßôáé ãéá ôïí parser.
Áõôüò ï handler èá êëçèåß áí ï XML parser óõíáôÞóåé ìéá external entity declaration ìå ìéá NDATA äÞëùóç, üðùò ç áêüëïõèç :
<!ENTITY <parameter>name</parameter> {<parameter>publicId</parameter> | <parameter>systemId</parameter>} NDATA <parameter>notationName</parameter> |
Äåßôå ôï ôìÞìá 4.2.2 ôçí XML 1.0 spec ãéá ïñéóìü ôçò óçìåßùóçò ðïõ äçëþíïíôáé external entities.
ÁõôÞ ç óõíÜñôçóç ðïõ ïíïìÜæåôáé áðü ôïí handler ðñÝðåé íá äå÷èåß Ýîé
ðáñáìÝôñïõò:
handler ( resource parser, string entity_name, string base, string system_id, string public_id, string notation_name)
Ç ðñþôç ðáñÜìåôñïò, parser, åßíáé ìéá áíáöïñÜ óôïí XML parser ðïõ êáëåß ôïí handler.
Ôï üíïìá ôçò ïíôüôçôáò ðïõ ðñüêåéôáé íá ïñéóôåß.
Áõôü åßíáé ç âÜóç ãéá åýñåóç ôïõ identifier ôïõ óõóôÞìáôïò (systemId) ìéáò åîùôåñéêÞò ïíôüôçôáò. Ðñïò ôï ðáñüí áõôÞ ç ðáñÜìåôñïò èá åßíáé ðÜíôá ïñéóìÝíç êáé ßóç ìå Ýíá êåíü string.
Åßíáé ï identifier ôïõ óõóôÞìáôïò ãéá ìéá åîùôåñéêÞ ïíôüôçôá.
ï Public identifier ãéá ôçí åîùôåñéêÞ ïíôüôçôá.
Ôï üíïìá ôïõ notation áõôÞò ôçò ïíôüôçôáò (äåßôå ôï xml_set_notation_decl_handler()).
Áí ìéá óõíÜñôçóç ôïõ handler ïñéóôåß ßóç ìå Ýíá êåíü string, Þ FALSE, ï handler õðü áìöéóâÞôçóç áðåíåñãïðïéåßôáé.
TRUE åðéóôñÝöåôáé áí ï handler Ý÷åé ïñéóôåß, FALSE áí ï parser äåí åßíáé parser.
Óçìåßùóç: Áíôß ãéá Ýíá üíïìá óõíÜñôçóçò, Ýíá array ðïõ ðåñéÝ÷åé ìéá áíáöïñÜ óå Ýíá áíôéêåßìåíï êáé Ýíá üíïìá ìåèüäïõ ìðïñåß íá äïèåß.
These functions can be used to write XML-RPC servers and clients. You can find more information about XML-RPC at http://www.xmlrpc.com/, and more documentation on this extension and its functions at http://xmlrpc-epi.sourceforge.net/.
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
XML-RPC support in PHP is not enabled by default. You will need to use the --with-xmlrpc[=DIR] configuration option when compiling PHP to enable XML-RPC support. This extension is bundled into PHP as of 4.1.0.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. XML-RPC configuration options
Name | Default | Changeable |
---|---|---|
xmlrpc_errors | "0" | PHP_INI_SYSTEM |
xmlrpc_error_number | "0" | PHP_INI_ALL |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
xmlrpc_get_type -- Gets xmlrpc type for a PHP value. Especially useful for base64 and datetime stringsÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
xmlrpc_parse_method_descriptions -- Decodes XML into a list of method descriptionsÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
xmlrpc_server_register_introspection_callback -- Register a PHP function to generate documentationÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
xmlrpc_server_register_method -- Register a PHP function to resource method matching method_nameÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(PHP 4 >= 4.1.0, PHP 5)
xmlrpc_set_type -- Sets xmlrpc type, base64 or datetime, for a PHP string valueÐñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
To use xdiff, you will need libxdiff installed, available on the libxdiff homepage http://www.xmailserver.org/xdiff-lib.html.
xdiff is currently available through PECL http://pecl.php.net/package/xdiff.
If PEAR is available on your *nix-like system you can use the pear installer to install the xdiff extension, by the following command: pear -v install xdiff.
You can always download the tar.gz package and install xdiff by hand:
(no version information, might be only in CVS)
xdiff_file_diff_binary -- Make binary diff of two files.xdiff_file_diff_binary() makes binary diff of files file1 and file2 and stores result in file dest.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also xdiff_string_diff_binary().
xdiff_file_diff() makes unified diff of files file1 and file2 and stores result in file dest. context indicated how many lines of context you want to include in diff result. Set minimal to TRUE if you want to minimalize size of diff (can take a long time).
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also xdiff_string_diff().
xdiff_file_merge3() merges files file1, file2 and file3 into one and stores result in file dest.
Returns TRUE if merge was successful, string with rejected chunks if it was not or FALSE if an internal error happened.
See also xdiff_string_merge3().
(no version information, might be only in CVS)
xdiff_file_patch_binary -- Patch a file with a binary diff.xdiff_file_patch_binary() patches file file with binary patch in file patch and stores result in file dest.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
See also xdiff_string_patch_binary().
(no version information, might be only in CVS)
xdiff_file_patch -- Patch a file with an unified diff.xdiff_file_patch() patches file file with unified patch in file patch and stores result in file dest.
flags can be either XDIFF_PATCH_NORMAL (default mode, normal patch) or XDIFF_PATCH_REVERSE (reversed patch).
Returns FALSE if an internal error happened, string with rejected chunks of patch or TRUE if patch has been successfully applied.
See also xdiff_string_patch().
(no version information, might be only in CVS)
xdiff_string_diff_binary -- Make binary diff of two strings.xdiff_string_diff_binary() makes binary diff of strings str1 and str2.
Returns string with result or FALSE if an internal error happened.
See also xdiff_file_diff_binary().
(no version information, might be only in CVS)
xdiff_string_diff -- Make unified diff of two strings.xdiff_string_diff() makes unified diff of strings str1 and str2. context indicated how many lines of context you want to include in diff result. Set minimal to TRUE if you want to minimalize size of diff (can take a long time).
Returns string with result or FALSE if an internal error happened.
See also xdiff_file_diff().
xdiff_string_merge3() merges strings str1, str2 and str3 into one.
If error is passed then rejected parts are stored inside this variable.
Returns merged string or FALSE if an internal error happened.
See also xdiff_file_merge3().
(no version information, might be only in CVS)
xdiff_string_patch_binary -- Patch a string with a binary diff.xdiff_string_patch_binary() patches string str with binary patch in string patch.
Returns a patched string.
See also xdiff_file_patch_binary().
(no version information, might be only in CVS)
xdiff_string_patch -- Patch a string with an unified diff.xdiff_string_patch() patches string str with unified patch in string patch.
flags can be either XDIFF_PATCH_NORMAL (default mode, normal patch) or XDIFF_PATCH_REVERSE (reversed patch).
If error is passed then rejected parts are stored inside this variable.
Returns a patched string.
See also xdiff_file_patch().
Ðñïåéäïðïßçóç |
ÁõôÞ ç åðÝêôáóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò -- óõìðåñéëáìâáíïìÝíïõ êáé ôïõ ïíüìáôïò ôùí óõíáñôÞóåùí ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí åðÝêôáóç -- ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí åðÝêôáóç ìå äéêü óáò ñßóêï. |
The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library.
PHP 5 includes the XSL extension by default and it can be enabled by adding the argument --with-xsl[=DIR] to your configure line. DIR is the libxslt installation directory. libxslt version 1.0.18 or greater is required.
In this small tutorial we will learn how to transform an XML document into HTML.
ÐáñÜäåéãìá 1. A simple XSL tree
|
ÐáñÜäåéãìá 3. Making XML into HTML The following PHP code uses the XML and XSL extensions to transform XML into presentable HTML.
This should produce an HTML fragment similar to the following:
|
Procedural style
bool xsl_xsltprocessor_get_parameter ( string namespace, string name)Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
xsl_xsltprocessor_has_exslt_support -- Determine if PHP has EXSLT supportProcedural style
bool xsl_xsltprocessor_has_exslt_support ( void )Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
xsl_xsltprocessor_has_exslt_support() returns TRUE if PHP was built with the EXSLT library , FALSE otherwise.
Procedural style
bool xsl_xsltprocessor_import_stylesheet ( node index)Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
(no version information, might be only in CVS)
xsl_xsltprocessor_register_php_functions -- Enables the ability to use PHP functions as XSLT functionsProcedural style
void xsl_xsltprocessor_register_php_functions ( void )Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
xsl_xsltprocessor_register_php_functions() enables the ability to use PHP functions as XSLT functions within XSL stylesheets.
Procedural style
bool xsl_xsltprocessor_remove_parameter ( string namespace, string name)Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Procedural style
bool xsl_xsltprocessor_set_parameter ( string namespace, string name, string value)Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Procedural style
bool >xsl_xsltprocessor_transform_to_doc ( node doc [, bool clone])Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Procedural style
bool xsl_xsltprocessor_transform_to_uri ( node doc, string uri [, bool clone])Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Procedural style
bool xsl_xsltprocessor_transform_to_xml ( node doc [, bool clone])Object oriented style (method)
class xsltprocessor {Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åßíáé ÄÏÊÉÌÁÓÔÉÊÇ. Ç óõìðåñéöïñÜ ôçò, ôï üíïìá ôçò êáé ïôéäÞðïôå Üëëï åßíáé ôåêìçñéùìÝíï ó÷åôéêÜ ìå áõôÞ ôçí óõíÜñôçóç ìðïñåß íá áëëÜîåé ÷ùñßò åéäïðïßçóç óå ìåëëïíôéêÝò åêäüóåéò ôçò PHP. ×ñçóéìïðïéÞóôå áõôÞ ôçí óõíÜñôçóç ìå äéêü óáò ñßóêï. |
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
This PHP extension provides a processor independent API to XSLT transformations. Currently this extension only supports the Sablotron library from the Ginger Alliance. Support is planned for other libraries, such as the Xalan library or the libxslt library.
XSLT (Extensible Stylesheet Language (XSL) Transformations) is a language for transforming XML documents into other XML documents. It is a standard defined by The World Wide Web Consortium (W3C). Information about XSLT and related technologies can be found at http://www.w3.org/TR/xslt.
Óçìåßùóç: This extension is different than the sablotron extension distributed with versions of PHP prior to PHP 4.1, currently only the new XSLT extension in PHP 4.1 is supported. If you need support for the old extension, please ask your questions on the PHP mailing lists.
Óçìåßùóç: This extension has been removed as of PHP 5 and moved to the PECL repository.
This extension uses Sablotron and expat, which can both be found at http://www.gingerall.com/. Binaries are provided as well as source.
On Unix, run configure with the --enable-xslt --with-xslt-sablot options. The Sablotron library should be installed somewhere your compiler can find it.
Make sure you have the same libraries linked to the Sablotron library as those, which are linked with PHP. The configuration options: --with-expat-dir=DIR --with-iconv-dir=DIR are there to help you specify them. When asking for support, always mention these directives, and whether there are other versions of those libraries installed on your system somewhere. Naturally, provide all the version numbers.
Ðñïóï÷Þ |
Be sure your Sablot library is linked to -lstdc++ as otherwise your configure will fail, or PHP will fail to run or load. |
JavaScript E-XSLT support: If you compiled Sablotron with JavaScript support, you must specify the option: --with-sablot-js=DIR.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy several files from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32). For PHP <= 4.2.0 copy sablot.dll and expat.dll to your SYSTEM32 folder. For PHP >= 4.2.1 copy sablot.dll, expat.dll and iconv.dll to your SYSTEM32 folder.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Drop all logging and error reporting. This is a generic option for all backends that may be added in the future.
Tell Sablotron to parse public entities. By default this has been turned off.
Do not add the meta tag "Content-Type" for HTML output. The default is set during compilation of Sablotron.
Suppress the whitespace stripping (on data files only).
Consider unresolved documents (the document() function) non-lethal.
Error return code, for scheme handlers.
Create and return a new XSLT processor resource for manipulation by the other XSLT functions.
ÐáñÜäåéãìá 1. xslt_create() example
|
See also xslt_free().
Returns an error code describing the last error that occurred on the passed XSLT processor.
Returns a string describing the last error that occurred on the passed XSLT processor.
ÐáñÜäåéãìá 1. Handling errors using the xslt_error() and xslt_errno() functions.
|
Free the XSLT processor identified by the given handle.
See also xslt_create()
The xslt_process() function is the crux of the new XSLT extension. It allows you to perform an XSLT transformation using almost any type of input source - the containers. This is accomplished through the use of argument buffers -- a concept taken from the Sablotron XSLT processor (currently the only XSLT processor this extension supports). The input containers default to a filename 'containing' the document to be processed. The result container defaults to a filename for the transformed document. If the result container is not specified - i.e. NULL - than the result is returned.
Ðñïåéäïðïßçóç |
This function has changed its arguments, sinceversion 4.0.6. Do NOT provide the actual XML or XSL content as 2nd and 3rd argument, as this will create a segmentation fault, in Sablotron versions up to and including 0.95. |
Containers can also be set via the $arguments array (see below).
The simplest type of transformation with the xslt_process() function is the transformation of an XML file with an XSLT file, placing the result in a third file containing the new XML (or HTML) document. Doing this with sablotron is really quite easy...
ÐáñÜäåéãìá 1. Using the xslt_process() to transform an XML file and a XSL file to a new XML file
|
While this functionality is great, many times, especially in a web environment, you want to be able to print out your results directly. Therefore, if you omit the third argument to the xslt_process() function (or provide a NULL value for the argument), it will automatically return the value of the XSLT transformation, instead of writing it to a file...
ÐáñÜäåéãìá 2. Using the xslt_process() to transform an XML file and a XSL file to a variable containing the resulting XML data
|
The above two cases are the two simplest cases there are when it comes to XSLT transformation and I'd dare say that they are the most common cases, however, sometimes you get your XML and XSLT code from external sources, such as a database or a socket. In these cases you'll have the XML and/or XSLT data in a variable -- and in production applications the overhead of dumping these to file may be too much. This is where XSLT's "argument" syntax, comes to the rescue. Instead of files as the XML and XSLT arguments to the xslt_process() function, you can specify "argument place holders" which are then substituted by values given in the arguments array (5th parameter to the xslt_process() function). The following is an example of processing XML and XSLT into a result variable without the use of files at all.
ÐáñÜäåéãìá 3. Using the xslt_process() to transform a variable containing XML data and a variable containing XSL data into a variable containing the resulting XML data
|
Finally, the last argument to the xslt_process() function represents an array for any top-level parameters that you want to pass to the XSLT document. These parameters can then be accessed within your XSL files using the <xsl:param name="parameter_name"> instruction. The parameters must be UTF-8 encoded and their values will be interpreted as strings by the Sablotron processor. In other words - you cannot pass node-sets as parameters to the XSLT document.
Óçìåßùóç: Please note that file:// is needed in front of path if you use Windows.
Sets the base URI for all XSLT transformations, the base URI is used with Xpath instructions to resolve document() and other commands which access external resources. It is also used to resolve URIs for the <xsl:include> and <xsl:import> elements.
As of 4.3, the default base URI is the directory of the executing script. In effect, it is the directory name value of the __FILE__ constant. Prior to 4.3, the default base URI was less predictable.
Óçìåßùóç: Please note that file:// is needed in front of path if you use Windows.
Set the output encoding for the XSLT transformations. When using the Sablotron backend this option is only available when you compile Sablotron with encoding support.
Set an error handler function for the XSLT processor given by xh, this function will be called whenever an error occurs in the XSLT transformation (this function is also called for notices).
A reference to the XSLT parser.
This parameter is either a boolean value which toggles logging on and off, or a string containing the logfile in which log errors too.
This function allows you to set the file in which you want XSLT log messages to, XSLT log messages are different than error messages, in that log messages are not actually error messages but rather messages related to the state of the XSLT processor. They are useful for debugging XSLT, when something goes wrong.
By default logging is disabled, in order to enable logging you must first call xslt_set_log() with a boolean parameter which enables logging, then if you want to set the log file to debug to, you must then pass it a string containing the filename:
Óçìåßùóç: Please note that file:// is needed in front of path if you use Windows.
Set SAX handlers on the resource handle given by xh. SAX handlers should be a two dimensional array with the format (all top level elements are optional):
array( [document] => array( start document handler, end document handler ), [element] => array( start element handler, end element handler ), [namespace] => array( start namespace handler, end namespace handler ), [comment] => comment handler, [pi] => processing instruction handler, [character] => character data handler ) |
(PHP 4 >= 4.0.6)
xslt_set_sax_handlers -- Set the SAX handlers to be called when the XML document gets processed
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Set Scheme handlers on the resource handle given by xh. Scheme handlers should be an array with the format (all elements are optional):
This extension offers a PHP interface to the YAZ toolkit that implements the Z39.50 Protocol for Information Retrieval. With this extension you can easily implement a Z39.50 origin (client) that searches or scans Z39.50 targets (servers) in parallel.
The module hides most of the complexity of Z39.50 so it should be fairly easy to use. It supports persistent stateless connections very similar to those offered by the various RDB APIs that are available for PHP. This means that sessions are stateless but shared among users, thus saving the connect and initialize phase steps in most cases.
YAZ is available at http://www.indexdata.dk/yaz/. You can find news information, example scripts, etc. for this extension at http://www.indexdata.dk/phpyaz/.
Óçìåßùóç: This extension has been removed as of PHP 5 and moved to the PECL repository.
Compile YAZ (ANSI/NISO Z39.50 support) and install it. Build PHP with your favourite modules and add option --with-yaz[=DIR]. Your task is roughly the following:
If you are using YAZ as a shared extension, add (or uncomment) the following line in php.ini on Unix:
extension=php_yaz.so |
extension=php_yaz.dll |
On Windows, php_yaz.dll depend on yaz.dll. You'll find yaz.dll in sub directory dlls in the Win32 zip archive. Copy yaz.dll to a directory in your PATH environment (c:\winnt\system32 or c:\windows\system32).
Ðñïåéäïðïßçóç |
Ç åðÝêôáóç IMAP äåí ìðïñåß íá ÷ñçóéìïðïéçèåß óå óõíäéáóìü ìå ôéò åðåêôÜóåéò recode Þ YAZ. Áõôü ïöåßëåôáé óôï üôé êáé ïé äýï ìïéñÜæïíôáé ôï ßäéï åóùôåñéêü óýìâïëï. |
Óçìåßùóç: The above problem is solved in version 2.0 of YAZ.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
Ðßíáêáò 1. YAZ configuration options
Name | Default | Changeable |
---|---|---|
yaz.max_links | "100" | PHP_INI_ALL |
yaz.log_file | "" | PHP_INI_ALL |
PHP/YAZ keeps track of connections with targets (Z-Associations). A resource represents a connection to a target.
The script below demonstrates the parallel searching feature of the API. When invoked with no arguments it prints a query form; else (arguments are supplied) it searches the targets as given in array host.
ÐáñÜäåéãìá 2. Parallel searching using Yaz
|
Returns additional error message for server (last request), identified by parameter id. An empty string is returned if the last operation was successful or if no additional information was provided by the server.
See also yaz_error().
This function configures the CCL query parser for a server with definitions of access points (CCL qualifiers) and their mapping to RPN. To map a specific CCL query to RPN afterwards call the yaz_ccl_parse() function. Each index of the array config is the name of a CCL field and the corresponding value holds a string that specifies a mapping to RPN. The mapping is a sequence of attribute-type, attribute-value pairs. Attribute-type and attribute-value is separated by an equal sign (=). Each pair is separated by white space.
ÐáñÜäåéãìá 1. CCL configuration In the example below, the CCL parser is configured to support three CCL fields: ti, au and isbn. Each field is mapped to their BIB-1 equivalent. It is assumed that variable $id is the connection ID.
|
This function invokes a CCL parser. It converts a given CCL FIND query to an RPN query which may be passed to the yaz_search() function to perform a search. To define a set of valid CCL fields call yaz_ccl_conf() prior to this function. If the supplied query was successfully converted to RPN, this function returns TRUE, and the index rpn of the supplied array result holds a valid RPN query. If the query could not be converted (because of invalid syntax, unknown field, etc.) this function returns FALSE and three indexes are set in the resulting array to indicate the cause of failure: errorcode CCL error code (integer), errorstring CCL error string, and errorpos approximate position in query of failure (integer is character position).
ÐáñÜäåéãìá 1. CCL Parsing We will try to search using CCL. In the example below, $ccl is a CCL query.
|
Closes the connection given by parameter id. The id is a connection resource as returned by a previous call to yaz_connect().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function returns a connection resource on success, zero on failure.
yaz_connect() prepares for a connection to a Z39.50 server. The zurl argument takes the form host[:port][/database]. If port is omitted, port 210 is used. If database is omitted Default is used. This function is non-blocking and does not attempt to establish a connection - it merely prepares a connect to be performed later when yaz_wait() is called.
If the second argument, options, is given as a string it is treated as the Z39.50 V2 authentication string (OpenAuth).
If options is given as an array the contents of the array serves as options. Note that array options are only supported for PHP 4.1.0 and later.
yaz_connect() options
Username for authentication.
Group for authentication.
Password for authentication.
Cookie for session (YAZ proxy).
Proxy for connection (YAZ proxy).
A boolean. If TRUE the connection is persistent; If FALSE the connection is not persistent. By default connections are persistent.
A boolean. If TRUE piggyback is enabled for searches; If FALSE piggyback is disabled. By default piggyback is enabled. Enabling piggyback is more efficient and usually saves a network-round-trip for first time fetches of records. However, a few Z39.50 servers do not support piggyback or they ignore element set names. For those, piggyback should be disabled.
A string that specifies character set to be used in Z39.50 language and character set negotiation. Use strings such as: ISO-8859-1, UTF-8, UTF-16.
Most Z39.50 servers do not support this feature (and thus, this is ignored). Many servers use the ISO-8859-1 encoding for queries and messages. MARC21/USMARC records are not affected by this setting.
Óçìåßùóç: The use of a proxy often improves performance. A Z39.50 proxy is part of the free YAZ++ package.
This function specifies one or more databases to be used in search, retrieval, etc. - overriding databases specified in call to yaz_connect(). Multiple databases are separated by a plus sign +.
This function allows you to use different sets of databases within a session.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function sets the element set name for retrieval. Call this function before yaz_search() or yaz_present() to specify the element set name for records to be retrieved. Most servers support F (for full records) and B (for brief records).
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Returns an errornumber for the server (last request) identified by id. The error code is either a Z39.50 diagnostic code (usually a Bib-1 diagnostic) or a client side error code which is generated by PHP/YAZ itself, such as "Connect failed", "Init Rejected", etc.
yaz_errno() should be called after network activity for each server - (after yaz_wait() returns) to determine the success or failure of the last operation (e.g. search). To get a text description of the error, call yaz_error().
Returns an error text message for server (last request), identified by parameter id. An empty string is returned if the last operation was successful.
yaz_error() returns an English text message corresponding to the last error number as returned by yaz_errno().
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
Returns the value of the option specified with name. If an option is not set, an empty string is returned.
See the description of yaz_set_option() for available options.
This function prepares for an Extended Services request using the Profile for the Use of Z39.50 Item Order Extended Service to Transport ILL (Profile/1). See this and the specification. The args parameter must be a hash array with information about the Item Order request to be sent. The key of the hash is the name of the corresponding ASN.1 tag path. For example, the ISBN below the Item-ID has the key item-id,ISBN.
The ILL-Request parameters are:
protocol-version-num
transaction-id,initial-requester-id,person-or-institution-symbol,person
transaction-id,initial-requester-id,person-or-institution-symbol,institution
transaction-id,initial-requester-id,name-of-person-or-institution,name-of-person
transaction-id,initial-requester-id,name-of-person-or-institution,name-of-institution
transaction-id,transaction-group-qualifier
transaction-id,transaction-qualifier
transaction-id,sub-transaction-qualifier
service-date-time,this,date
service-date-time,this,time
service-date-time,original,date
service-date-time,original,time
requester-id,person-or-institution-symbol,person
requester-id,person-or-institution-symbol,institution
requester-id,name-of-person-or-institution,name-of-person
requester-id,name-of-person-or-institution,name-of-institution
responder-id,person-or-institution-symbol,person
responder-id,person-or-institution-symbol,institution
responder-id,name-of-person-or-institution,name-of-person
responder-id,name-of-person-or-institution,name-of-institution
transaction-type
delivery-address,postal-address,name-of-person-or-institution,name-of-person
delivery-address,postal-address,name-of-person-or-institution,name-of-institution
delivery-address,postal-address,extended-postal-delivery-address
delivery-address,postal-address,street-and-number
delivery-address,postal-address,post-office-box
delivery-address,postal-address,city
delivery-address,postal-address,region
delivery-address,postal-address,country
delivery-address,postal-address,postal-code
delivery-address,electronic-address,telecom-service-identifier
delivery-address,electronic-address,telecom-service-addreess
billing-address,postal-address,name-of-person-or-institution,name-of-person
billing-address,postal-address,name-of-person-or-institution,name-of-institution
billing-address,postal-address,extended-postal-delivery-address
billing-address,postal-address,street-and-number
billing-address,postal-address,post-office-box
billing-address,postal-address,city
billing-address,postal-address,region
billing-address,postal-address,country
billing-address,postal-address,postal-code
billing-address,electronic-address,telecom-service-identifier
billing-address,electronic-address,telecom-service-addreess
ill-service-type
requester-optional-messages,can-send-RECEIVED
requester-optional-messages,can-send-RETURNED
requester-optional-messages,requester-SHIPPED
requester-optional-messages,requester-CHECKED-IN
search-type,level-of-service
search-type,need-before-date
search-type,expiry-date
search-type,expiry-flag
place-on-hold
client-id,client-name
client-id,client-status
client-id,client-identifier
item-id,item-type
item-id,call-number
item-id,author
item-id,title
item-id,sub-title
item-id,sponsoring-body
item-id,place-of-publication
item-id,publisher
item-id,series-title-number
item-id,volume-issue
item-id,edition
item-id,publication-date
item-id,publication-date-of-component
item-id,author-of-article
item-id,title-of-article
item-id,pagination
item-id,ISBN
item-id,ISSN
item-id,additional-no-letters
item-id,verification-reference-source
copyright-complicance
retry-flag
forward-flag
requester-note
forward-note
There are also a few parameters that are part of the Extended Services Request package and the ItemOrder package:
package-name
user-id
contact-name
contact-phone
contact-email
itemorder-item
This function prepares for retrieval of records after a successful search. The yaz_range() should be called prior to this function to specify the range of records to be retrieved.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
This function should be called before either yaz_search() or yaz_present() to specify a range of records to be retrieved. The parameter start specifies the position of the first record to be retrieved and parameter number is the number of records. Records in a result set are numbered 1, 2, ... $hits where $hits is the count returned by yaz_hits().
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Returns the record at position pos or an empty string if no record exists at the given position.
The yaz_record() function inspects a record in the current result set at the position specified by parameter pos. If no database record exists at the given position an empty string is returned.
Record positions in a result set are numbered 1, 2, ... $hits where $hits is the count returned by yaz_hits().
The type specifies the form of the returned record.
The record is returned as a string for simple display. In this mode, all MARC records are converted to a line-by-line format since ISO2709 is hardly readable. XML records and SUTRS are returned in their original format. GRS-1 are returned in a (ugly) line-by-line format.
This format is suitable if records are to be displayed in a quick way - for debugging - or because it is not feasible to perform proper display.
The record is returned as an XML string if possible. In this mode, all MARC records are converted to MARCXML. XML records and SUTRS are returned in their original format. GRS-1 is not supported.
This format is similar to string except that MARC records are converted to MARCXML
This format is suitable if records are processed by an XML parser or XSLT processor afterwareds.
The record is returned as a string in its original form. This type is suitable for MARC, XML and SUTRS. It does not work for GRS-1.
MARC records are returned as a ISO2709 string. XML and SUTRS are returned as strings.
The syntax of the record is returned as a string, i.e. USmarc, GRS-1, XML, etc.
The name of database associated with record at the position is returned as a string.
The record is returned as an array that reflects the GRS-1 structure. This type is suitable for MARC and GRS-1. XML, SUTRS are not supported and if the actual record is XML or SUTRS an empty string will be returned.
The array returned consists of a list corresponding to each leaf/internal node of GRS-1. Each list item consists a sub list with first element path and data (if data is available).
The path which is a string holds a list of each tree component (of the structured GRS-1 record) from root to leaf. Each component is a tag type, tag value pair of the form (type, value
String tags normally has a corresponding tag type 3. MARC can also be returned as an array (they are converted to GRS-1 internally).
Óçìåßùóç: It is the application which is responsible for actually ensuring that the records are returned from the Z39.50/SRW server in the proper format. The type given only specifies a conversion to take place on the client side (in PHP/YAZ).
Besides conversion of the transfer record to a string/array, PHP/YAZ it is also possible to perform a character set conversion of the record. Especially for USMARC/MARC21 that is recommended since these are typically returned in the character set MARC-8 that is not supported by browsers, etc. To specify a conversion, add ; charset=from, to where from is the original character set of the record and to is the resulting character set (as seen by PHP).
ÐáñÜäåéãìá 1. Array for GRS-1 record Consider GRS-1 record
If this record is present at position $p, then
|
ÐáñÜäåéãìá 2. Working with MARCXML The following PHP snippet returns a MARC21/USMARC record as MARCXML. The original record is returned in marc-8 (unknown to most XML parsers), so we convert it to UTF-8 (which all XML parsers must support).
The record $rec can be processed with the Sablotron XSLT processor as follows:
For PHP5 the XSL extension can be used instead of Sablotron XSLT. |
yaz_scan_result() returns terms and associated information as received from the server in the last performed yaz_scan(). This function returns an array (0..n-1) where n is the number of terms returned. Each value is a pair where the first item is the term, and the second item is the result-count. If the optional parameter result is given it will be modified to hold additional information taken from the Scan Response: number (number of entries returned), stepsize (Step-size), position (position of term), status (Scan Status).
This function prepares for a Z39.50 Scan Request, where parameter id specifies connection. Starting term point for the scan is given by startterm. The form in which the starting term is specified is given by parameter type. Currently only type rpn is supported. The optional parameter flags specifies additional information to control the behaviour of the scan request. Three indexes are currently read from the flags: number (number of terms requested), position (preferred position of term) and stepSize (preferred step size). To actually transfer the Scan Request to the server and receive the Scan Response, yaz_wait() must be called. Upon completion of yaz_wait() call yaz_error() and yaz_scan_result() to handle the response.
The syntax of startterm is similar to the RPN query as described in yaz_search(). The startterm consists of zero or more @attr-operator specifications, then followed by exactly one token.
ÐáñÜäåéãìá 1. PHP function that scans titles
|
The schema must be specified as an OID (Object Identifier) in a raw dot-notation (like 1.2.840.10003.13.4) or as one of the known registered schemas: GILS-schema, Holdings, Zthes, ... This function should be called before yaz_search() or yaz_present().
yaz_search() prepares for a search on the connection given by parameter id. The parameter type represents the query type - only "rpn" is supported now in which case the third argument specifies a Type-1 query in prefix query notation. Like yaz_connect() this function is non-blocking and only prepares for a search to be executed later when yaz_wait() is called.
The RPN query is a textual representation of the Type-1 query as defined by the Z39.50 standard. However, in the text representation as used by YAZ a prefix notation is used, that is the operater precedes the operands. The query string is a sequence of tokens where white space is ignored unless surrounded by double quotes. Tokens beginning with an at-character (@) are considered operators, otherwise they are treated as search terms.
Ðßíáêáò 1. RPN Operators
Construct | Description |
---|---|
@and query1 query2 | intersection of query1 and query2 |
@or query1 query2 | union of query1 and query2 |
@not query1 query2 | query1 and not query2 |
@set name | result set reference |
@attrset set query | specifies attribute-set for query. This construction is only allowed once - in the beginning of the whole query |
@attr [set] type=value query | applies attribute to query. The type and value are integers specifying the attribute-type and attribute-value respectively. The set, if given, specifies the attribute-set. |
ÐáñÜäåéãìá 1. Query Examples You can search for simple terms, like this
The Query
This query applies two attributes for the same phrase.
This query
Another, more complex, one:
|
You can find information about attributes at the Z39.50 Maintenance Agency site.
Óçìåßùóç: If you would like to use a more friendly notation, use the CCL parser - functions yaz_ccl_conf() and yaz_ccl_parse().
Sets option name to value.
Ðßíáêáò 1. PYP/YAZ Connection Options
Name | Description |
---|---|
implementationName | implementation name of server |
implementationVersion | implementation version of server |
implementationId | implementation ID of server |
schema | schema for retrieval. By default, no schema is used. Setting this option is equivalent to using function yaz_schema() |
preferredRecordSyntax | record syntax for retrieval. By default, no syntax is used. Setting this option is equivalent to using function yaz_syntax() |
start | offset for first record to be retrieved via yaz_search() or yaz_present(). First record is numbered has a start value of 0. Second record has start value 1. Setting this option in combination with option count has the same effect as calling yaz_range() except that records are numbered from 1 in yaz_range() |
count | maximum number of records to be retrieved via yaz_search() or yaz_present(). |
elementSetName | element-set-name for retrieval. Setting this option is equivalent to calling yaz_element(). |
This function sets sorting criteria and enables Z39.50 Sort. Call this function before yaz_search(). Using this function alone does not have any effect. When used in conjunction with yaz_search(), a Z39.50 Sort will be sent after a search response has been received and before any records are retrieved with Z39.50 Present (yaz_present(). The parameter criteria takes the form
field1 flags1 field2 flags2 ...
where field1 specifies the primary attributes for sort, field2 seconds, etc.. The field specifies either a numerical attribute combinations consisting of type=value pairs separated by comma (e.g. 1=4,2=1) ; or the field may specify a plain string criteria (e.g. title. The flags is a sequence of the following characters which may not be separated by any white space.
Sort Flags
Sort ascending
Sort descending
Case insensitive sorting
Case sensitive sorting
The syntax must be specified as an OID (Object Identifier) in a raw dot-notation (like 1.2.840.10003.5.10) or as one of the known registered record syntaxes (sutrs, usmarc, grs1, xml, etc.). This function should be called before yaz_search() or yaz_present().
This function carries out networked (blocked) activity for outstanding requests which have been prepared by the functions yaz_connect(), yaz_search(), yaz_present(), yaz_scan() and yaz_itemorder(). yaz_wait() returns when all servers have either completed all requests or aborted (in case of errors).
If the options array is given that holds options that change the behaviour of yaz_wait().
Sets timeout in seconds. If a server has not responded within the timeout it is considered dead and yaz_wait() returns. The default value for timeout is 15 seconds.
NIS (formerly called Yellow Pages) allows network management of important administrative files (e.g. the password file). For more information refer to the NIS manpage and The Linux NIS(YP)/NYS/NIS+ HOWTO. There is also a book called Managing NFS and NIS by Hal Stern.
Óçìåßùóç: ÁõôÞ ç óõíÜñôçóç äåí åßíáé äéáèÝóéìç óå Windows óõóôÞìáôá.
None besides functions from standard Unix libraries which are always available (either libc or libnsl, configure will detect which one to use).
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
Ðñïåéäïðïßçóç |
ÁõôÞ ç óõíÜñôçóç åðß ôïõ ðáñüíôïò äåí åßíáé ôåêìçñéùìÝíç, ìüíï ï êáôÜëïãïò ôùí argument ôçò åßíáé äéáèÝóéìïò. |
yp_cat() returns all map entries as an array with the maps key values as array indices and the maps entries as array data.
(PHP 4 >= 4.0.6, PHP 5)
yp_err_string -- Returns the error string associated with the given error codeyp_err_string() returns the error message associated with the given error code. Useful to indicate what exactly went wrong.
See also yp_errno().
yp_errno() returns the error code of the previous operation.
Possible errors are:
1 args to function are bad |
2 RPC failure - domain has been unbound |
3 can't bind to server on this domain |
4 no such map in server's domain |
5 no such key in map |
6 internal yp server or client error |
7 resource allocation failure |
8 no more records in map database |
9 can't communicate with portmapper |
10 can't communicate with ypbind |
11 can't communicate with ypserv |
12 local domain name not set |
13 yp database is bad |
14 yp version mismatch |
15 access violation |
16 database busy |
See also yp_err_string().
yp_first() returns the first key-value pair from the named map in the named domain, otherwise FALSE.
See also yp_next() and yp_get_default_domain().
yp_get_default_domain() returns the default domain of the node or FALSE. Can be used as the domain parameter for successive NIS calls.
A NIS domain can be described a group of NIS maps. Every host that needs to look up information binds itself to a certain domain. Refer to the documents mentioned at the beginning for more detailed information.
(PHP 3>= 3.0.7, PHP 4 , PHP 5)
yp_master -- Returns the machine name of the master NIS server for a mapyp_master() returns the machine name of the master NIS server for a map.
See also yp_get_default_domain().
yp_match() returns the value associated with the passed key out of the specified map or FALSE. This key must be exact.
See also yp_get_default_domain().
yp_next() returns the next key-value pair in the named map after the specified key or FALSE.
ÐáñÜäåéãìá 1. Example for NIS next
|
See also yp_first() and yp_get_default_domain().
yp_order() returns the order number for a map or FALSE.
See also yp_get_default_domain().
This module enables you to transparently read ZIP compressed archives and the files inside them.
This module uses the functions of the ZZIPlib library by Guido Draheim. You need ZZIPlib version >= 0.10.6.
Note that ZZIPlib only provides a subset of functions provided in a full implementation of the ZIP compression algorithm and can only read ZIP file archives. A normal ZIP utility is needed to create the ZIP file archives read by this library.
Zip support in PHP is not enabled by default. You will need to use the --with-zip[=DIR] configuration option when compiling PHP to enable zip support.
Óçìåßùóç: Zip support before PHP 4.1.0 is experimental. This section reflects the Zip extension as it exists in PHP 4.1.0 and later.
This example opens a ZIP file archive, reads each file in the archive and prints out its contents. The test2.zip archive used in this example is one of the test archives in the ZZIPlib source distribution.
ÐáñÜäåéãìá 1. Zip Usage Example
|
Closes a zip file archive. The parameter zip must be a zip archive previously opened by zip_open().
This function has no return value.
See also zip_open() and zip_read().
Closes a directory entry specified by zip_entry. The parameter zip_entry must be a valid directory entry opened by zip_entry_open().
This function has no return value.
See also zip_entry_open() and zip_entry_read().
Returns the compressed size of the directory entry specified by zip_entry. The parameter zip_entry is a valid directory entry returned by zip_read().
See also zip_open() and zip_read().
Returns the compression method of the directory entry specified by zip_entry. The parameter zip_entry is a valid directory entry returned by zip_read().
See also zip_open() and zip_read().
Returns the actual size of the directory entry specified by zip_entry. The parameter zip_entry is a valid directory entry returned by zip_read().
See also zip_open() and zip_read().
Returns the name of the directory entry specified by zip_entry. The parameter zip_entry is a valid directory entry returned by zip_read().
See also zip_open() and zip_read().
Opens a directory entry in a zip file for reading. The parameter zip is a valid resource handle returned by zip_open(). The parameter zip_entry is a directory entry resource returned by zip_read(). The optional parameter mode can be any of the modes specified in the documentation for fopen().
Óçìåßùóç: Currently, mode is ignored and is always "rb". This is due to the fact that zip support in PHP is read only access. Please see fopen() for an explanation of various modes, including "rb".
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
Óçìåßùóç: Unlike fopen() and other similar functions, the return value of zip_entry_open() only indicates the result of the operation and is not needed for reading or closing the directory entry.
See also zip_entry_read() and zip_entry_close().
Reads up to length bytes from an open directory entry. If length is not specified, then zip_entry_read() will attempt to read 1024 bytes. The parameter zip_entry is a valid directory entry returned by zip_read().
Óçìåßùóç: The length parameter should be the uncompressed length you wish to read.
Returns the data read, or FALSE if the end of the file is reached.
See also zip_entry_open(), zip_entry_close() and zip_entry_filesize().
Opens a new zip archive for reading. The filename parameter is the filename of the zip archive to open.
Returns a resource handle for later use with zip_read() and zip_close() or returns FALSE if filename does not exist.
See also zip_read() and zip_close().
Reads the next entry in a zip file archive. The parameter zip must be a zip archive previously opened by zip_open().
Returns a directory entry resource for later use with the zip_entry_...() functions or FALSE if there's no more entries to read.
See also zip_open(), zip_close(), zip_entry_open(), and zip_entry_read().
This module enables you to transparently read and write gzip (.gz) compressed files, through versions of most of the filesystem functions which work with gzip-compressed files (and uncompressed files, too, but not with sockets).
Óçìåßùóç: Version 4.0.4 introduced a fopen-wrapper for .gz-files, so that you can use a special 'zlib:' URL to access compressed files transparently using the normal f*() file access functions if you prepend the filename or path with a 'zlib:' prefix when calling fopen().
In version 4.3.0, this special prefix has been changed to 'zlib://' to prevent ambiguities with filenames containing ':'.
This feature requires a C runtime library that provides the fopencookie() function. To my current knowledge the GNU libc is the only library that provides this feature.
This module uses the functions of zlib by Jean-loup Gailly and Mark Adler. You have to use a zlib version >= 1.0.9 with this module.
Zlib support in PHP is not enabled by default. You will need to configure PHP --with-zlib[=DIR]
Ç Ýêäïóç ãéá windows ôçò PHP Ý÷åé åíóùìáôùìÝíç õðïóôÞñéîç ãéá áõôÞ ôçí åðÝêôáóç. Äåí ÷ñåéÜæåôáé íá öïñôþóåôå êÜðïéá ðñüóèåôç åðÝêôáóç ãéá íá ÷ñçóéìïðïéÞóåôå áõôÝò ôéò óõíáñôÞóåéò.
Óçìåßùóç: Builtin support for zlib on Windows is available with PHP 4.3.0.
Ç óõìðåñéöïñÜ áõôþí ôùí óõíáñôÞóåùí åðéñåÜæåôáé áðü ôéò ñõèìßóåéò óôï php.ini.
The zlib extension offers the option to transparently compress your pages on-the-fly, if the requesting browser supports this. Therefore there are three options in the configuration file php.ini.
Ðßíáêáò 1. Zlib Configuration Options
Name | Default | Changeable |
---|---|---|
zlib.output_compression | "Off" | PHP_INI_ALL |
zlib.output_compression_level | "-1" | PHP_INI_ALL |
zlib.output_handler | "" | PHP_INI_ALL |
Áêïëïõèåß ìéá ìéêñÞ åðåîÞãçóç ôùí directive ñõèìßóåùí.
Whether to transparently compress pages. If this option is set to "On" in php.ini or the Apache configuration, pages are compressed if the browser sends an "Accept-Encoding: gzip" or "deflate" header. "Content-Encoding: gzip" (respectively "deflate") and "Vary: Accept-Encoding" headers are added to the output.
You can use ini_set() to disable this in your script if the headers aren't already sent. If you output a "Content-Type: image/" header the compression is disabled, too (in order to circumvent a Netscape bug). You can reenable it, if you add "ini_set('zlib.output_compression', 'On')" after the header call which added the image content-type.
This option also accepts integer values instead of boolean "On"/"Off", using this you can set the output buffer size (default is 4KB).
Óçìåßùóç: output_handler must be empty if this is set 'On' ! Instead you must use zlib.output_handler.
Compression level used for transparent output compression.
You cannot specify additional output handlers if zlib.output_compression is activated here. This setting does the same as output_handler but in a different order.
Ïé óôáèåñÝò ðáñáêÜôù ïñßæïíôáé áðü áõôÞ ôçí åðÝêôáóç, êáé èá åßíáé äéáèÝóéìåò ìüíï áí ç åðÝêôáóç Ý÷åé ãßíåé compile ìÝóá óôçí PHP Þ Ý÷åé öïñôùèåß äõíáìéêÜ êáôÜ ôçí åêôÝëåóç.
This example opens a temporary file and writes a test string to it, then it prints out the content of this file twice.
ÐáñÜäåéãìá 1. Small Zlib Example
|
The gz-file pointed to by zp is closed.
ÅðéóôñÝöåé TRUE óå åðéôõ÷ßá Þ FALSE óå áðïôõ÷ßá.
The gz-file pointer must be valid, and must point to a file successfully opened by gzopen().
See also gzopen().
This function returns a compressed version of the input data using the ZLIB data format, or FALSE if an error is encountered. The optional parameter level can be given as 0 for no compression up to 9 for maximum compression.
For details on the ZLIB compression algorithm see the document "ZLIB Compressed Data Format Specification version 3.3" (RFC 1950).
Óçìåßùóç: This is not the same as gzip compression, which includes some header data. See gzencode() for gzip compression.
See also gzdeflate(), gzinflate(), gzuncompress(), gzencode().
This function returns a compressed version of the input data using the DEFLATE data format, or FALSE if an error is encountered. The optional parameter level can be given as 0 for no compression up to 9 for maximum compression. If level is not given the default compression level will be the default compression level of the zlib library.
For details on the DEFLATE compression algorithm see the document "DEFLATE Compressed Data Format Specification version 1.3" (RFC 1951).
See also gzinflate(), gzcompress(), gzuncompress(), gzencode().
This function returns a compressed version of the input data compatible with the output of the gzip program, or FALSE if an error is encountered. The optional parameter level can be given as 0 for no compression up to 9 for maximum compression, if not given the default compression level will be the default compression level of the zlib library.
You can also give FORCE_GZIP (the default) or FORCE_DEFLATE as optional third parameter encoding_mode. If you use FORCE_DEFLATE, you get a standard zlib deflated string (inclusive zlib headers) after the gzip file header but without the trailing crc32 checksum.
Óçìåßùóç: level was added in PHP 4.2, before PHP 4.2 gzencode() only had the data and (optional) encoding_mode parameters..
The resulting data contains the appropriate headers and data structure to make a standard .gz file, e.g.:
For more information on the GZIP file format, see the document: GZIP file format specification version 4.3 (RFC 1952).
See also gzcompress(). gzuncompress(), gzdeflate(), gzinflate().
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().
Identical to readgzfile(), except that gzfile() returns the file in an array.
You can use the optional second parameter and set it to "1", if you want to search for the file in the include_path, too.
See also readgzfile(), and gzopen().
Returns a string containing a single (uncompressed) character read from the file pointed to by zp. Returns FALSE on EOF (unlike gzeof()).
The gz-file pointer must be valid, and must point to a file successfully opened by gzopen().
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().
Identical to gzgets(), except that gzgetss() attempts to strip any HTML and PHP tags from the text it reads.
You can use the optional third parameter to specify tags which should not be stripped.
Óçìåßùóç: Allowable_tags was added in PHP 3.0.13, PHP 4.0b3.
See also gzgets(), gzopen(), and strip_tags().
This function takes data compressed by gzdeflate() and returns the original uncompressed data or FALSE on error. The function will return an error if the uncompressed data is more than 32768 times the length of the compressed input data or more than the optional parameter length.
See also gzcompress(). gzuncompress(), gzdeflate(), and gzencode().
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.
You can use the optional third parameter and set it to "1", if you want to search for the file in the include_path, too.
See also gzclose().
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().
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.
See also gzwrite(), gzopen(), gzgets(), gzgetss(), gzfile(), and gzpassthru().
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().
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().
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().
This function takes data compressed by gzcompress() and returns the original uncompressed data or FALSE on error. The function will return an error if the uncompressed data is more than 32768 times the length of the compressed input data or more than the optional parameter length.
See also gzdeflate(), gzinflate(), gzcompress(), gzencode().
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.
gzwrite() returns the number of (uncompressed) bytes written to the gz-file stream pointed to by zp.
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.
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.
You can use the optional second parameter and set it to "1", if you want to search for the file in the include_path, too.
See also gzpassthru(), gzfile(), and gzopen().
Returns the coding type used for output compression. Possible return values are gzip, deflate, or FALSE
See also the zlib.output_compression directive.
Sometimes, PHP "as is" simply isn't enough. Although these cases are rare for the average user, professional applications will soon lead PHP to the edge of its capabilities, in terms of either speed or functionality. New functionality cannot always be implemented natively due to language restrictions and inconveniences that arise when having to carry around a huge library of default code appended to every single script, so another method needs to be found for overcoming these eventual lacks in PHP.
As soon as this point is reached, it's time to touch the heart of PHP and take a look at its core, the C code that makes PHP go.
"Extending PHP" is easier said than done. PHP has evolved to a full-fledged tool consisting of a few megabytes of source code, and to hack a system like this quite a few things have to be learned and considered. When structuring this chapter, we finally decided on the "learn by doing" approach. This is not the most scientific and professional approach, but the method that's the most fun and gives the best end results. In the following sections, you'll learn quickly how to get the most basic extensions to work almost instantly. After that, you'll learn about Zend's advanced API functionality. The alternative would have been to try to impart the functionality, design, tips, tricks, etc. as a whole, all at once, thus giving a complete look at the big picture before doing anything practical. Although this is the "better" method, as no dirty hacks have to be made, it can be very frustrating as well as energy- and time-consuming, which is why we've decided on the direct approach.
Note that even though this chapter tries to impart as much knowledge as possible about the inner workings of PHP, it's impossible to really give a complete guide to extending PHP that works 100% of the time in all cases. PHP is such a huge and complex package that its inner workings can only be understood if you make yourself familiar with it by practicing, so we encourage you to work with the source.
The name Zend refers to the language engine, PHP's core. The term PHP refers to the complete system as it appears from the outside. This might sound a bit confusing at first, but it's not that complicated (see Ó÷Þìá 24-1). To implement a Web script interpreter, you need three parts:
The interpreter part analyzes the input code, translates it, and executes it.
The functionality part implements the functionality of the language (its functions, etc.).
The interface part talks to the Web server, etc.
The following sections discuss where PHP can be extended and how it's done.
As shown in Ó÷Þìá 24-1 above, PHP can be extended primarily at three points: external modules, built-in modules, and the Zend engine. The following sections discuss these options.
External modules can be loaded at script runtime using the function dl(). This function loads a shared object from disk and makes its functionality available to the script to which it's being bound. After the script is terminated, the external module is discarded from memory. This method has both advantages and disadvantages, as described in the following table:
Advantages | Disadvantages |
External modules don't require recompiling of PHP. | The shared objects need to be loaded every time a script is being executed (every hit), which is very slow. |
The size of PHP remains small by "outsourcing" certain functionality. | External additional files clutter up the disk. |
Every script that wants to use an external module's functionality has to specifically include a call to dl(), or the extension tag in php.ini needs to be modified (which is not always a suitable solution). |
Third parties might consider using the extension tag in php.ini to create additional external modules to PHP. These external modules are completely detached from the main package, which is a very handy feature in commercial environments. Commercial distributors can simply ship disks or archives containing only their additional modules, without the need to create fixed and solid PHP binaries that don't allow other modules to be bound to them.
Built-in modules are compiled directly into PHP and carried around with every PHP process; their functionality is instantly available to every script that's being run. Like external modules, built-in modules have advantages and disadvantages, as described in the following table:
Built-in modules are best when you have a solid library of functions that remains relatively unchanged, requires better than poor-to-average performance, or is used frequently by many scripts on your site. The need to recompile PHP is quickly compensated by the benefit in speed and ease of use. However, built-in modules are not ideal when rapid development of small additions is required.Of course, extensions can also be implemented directly in the Zend engine. This strategy is good if you need a change in the language behavior or require special functions to be built directly into the language core. In general, however, modifications to the Zend engine should be avoided. Changes here result in incompatibilities with the rest of the world, and hardly anyone will ever adapt to specially patched Zend engines. Modifications can't be detached from the main PHP sources and are overridden with the next update using the "official" source repositories. Therefore, this method is generally considered bad practice and, due to its rarity, is not covered in this book.
Óçìåßùóç: Prior to working through the rest of this chapter, you should retrieve clean, unmodified source trees of your favorite Web server. We're working with Apache (available at http://www.apache.org/) and, of course, with PHP (available at http://www.php.net/ - does it need to be said?).
Make sure that you can compile a working PHP environment by yourself! We won't go into this issue here, however, as you should already have this most basic ability when studying this chapter.
Before we start discussing code issues, you should familiarize yourself with the source tree to be able to quickly navigate through PHP's files. This is a must-have ability to implement and debug extensions.
The following table describes the contents of the major directories.
Directory | Contents |
php4 | Main PHP source files and main header files; here you'll find all of PHP's API definitions, macros, etc. (important). Everything else is below this directory. |
php4/ext | Repository for dynamic and built-in modules; by default, these are the "official" PHP modules that have been integrated into the main source tree. From PHP 4.0, it's possible to compile these standard extensions as dynamic loadable modules (at least, those that support it). |
php4/main | This directory contains the main php macros and definitions. (important) |
php4/pear | Directory for the PHP Extension and Application Repository. This directory contains core PEAR files. |
php4/sapi | Contains the code for the different server abstraction layers. |
php4/TSRM | Location of the "Thread Safe Resource Manager" (TSRM) for Zend and PHP. |
php4/Zend | Location of the Zend Engine files; here you'll find all of Zend's API definitions, macros, etc. (important). |
Discussing all the files included in the PHP package is beyond the scope of this chapter. However, you should take a close look at the following files:
php4/main/php.h, located in the main PHP directory. This file contains most of PHP's macro and API definitions.
php4/Zend/zend.h, located in the main Zend directory. This file contains most of Zend's macros and definitions.
php4/Zend/zend_API.h, also located in the Zend directory, which defines Zend's API.
Zend is built using certain conventions; to avoid breaking its standards, you should follow the rules described in the following sections.
For almost every important task, Zend ships predefined macros that are extremely handy. The tables and figures in the following sections describe most of the basic functions, structures, and macros. The macro definitions can be found mainly in zend.h and zend_API.h. We suggest that you take a close look at these files after having studied this chapter. (Although you can go ahead and read them now, not everything will make sense to you yet.)
Resource management is a crucial issue, especially in server software. One of the most valuable resources is memory, and memory management should be handled with extreme care. Memory management has been partially abstracted in Zend, and you should stick to this abstraction for obvious reasons: Due to the abstraction, Zend gets full control over all memory allocations. Zend is able to determine whether a block is in use, automatically freeing unused blocks and blocks with lost references, and thus prevent memory leaks. The functions to be used are described in the following table:
Function | Description |
emalloc() | Serves as replacement for malloc(). |
efree() | Serves as replacement for free(). |
estrdup() | Serves as replacement for strdup(). |
estrndup() | Serves as replacement for strndup(). Faster than estrdup() and binary-safe. This is the recommended function to use if you know the string length prior to duplicating it. |
ecalloc() | Serves as replacement for calloc(). |
erealloc() | Serves as replacement for realloc(). |
Ðñïåéäïðïßçóç |
To allocate resident memory that survives termination of the current script, you can use malloc() and free(). This should only be done with extreme care, however, and only in conjunction with demands of the Zend API; otherwise, you risk memory leaks. |
The following directory and file functions should be used in Zend modules. They behave exactly like their C counterparts, but provide virtual working directory support on the thread level.
Strings are handled a bit differently by the Zend engine than other values such as integers, Booleans, etc., which don't require additional memory allocation for storing their values. If you want to return a string from a function, introduce a new string variable to the symbol table, or do something similar, you have to make sure that the memory the string will be occupying has previously been allocated, using the aforementioned e*() functions for allocation. (This might not make much sense to you yet; just keep it somewhere in your head for now - we'll get back to it shortly.)
Complex types such as arrays and objects require different treatment. Zend features a single API for these types - they're stored using hash tables.
Óçìåßùóç: To reduce complexity in the following source examples, we're only working with simple types such as integers at first. A discussion about creating more advanced types follows later in this chapter.
PHP 4 features an automatic build system that's very flexible. All modules reside in a subdirectory of the ext directory. In addition to its own sources, each module consists of a config.m4 file, for extension configuration. (for example, see http://www.gnu.org/manual/m4/html_mono/m4.html)
All these stub files are generated automatically, along with .cvsignore, by a little shell script named ext_skel that resides in the ext directory. As argument it takes the name of the module that you want to create. The shell script then creates a directory of the same name, along with the appropriate stub files.
Step by step, the process looks like this:
:~/cvs/php4/ext:> ./ext_skel --extname=my_module Creating directory my_module Creating basic files: config.m4 .cvsignore my_module.c php_my_module.h CREDITS EXPERIMENTAL tests/001.phpt my_module.php [done]. To use your new extension, you will have to execute the following steps: 1. $ cd .. 2. $ vi ext/my_module/config.m4 3. $ ./buildconf 4. $ ./configure --[with|enable]-my_module 5. $ make 6. $ ./php -f ext/my_module/my_module.php 7. $ vi ext/my_module/my_module.c 8. $ make Repeat steps 3-6 until you are satisfied with ext/my_module/config.m4 and step 6 confirms that your module is compiled into PHP. Then, start writing code and repeat the last two steps as often as necessary. |
The default config.m4 shown in ÐáñÜäåéãìá 27-1 is a bit more complex:
ÐáñÜäåéãìá 27-1. The default config.m4.
|
If you're unfamiliar with M4 files (now is certainly a good time to get familiar), this might be a bit confusing at first; but it's actually quite easy.
Note: Everything prefixed with dnl is treated as a comment and is not parsed.
The config.m4 file is responsible for parsing the command-line options passed to configure at configuration time. This means that it has to check for required external files and do similar configuration and setup tasks.
The default file creates two configuration directives in the configure script: --with-my_module and --enable-my_module. Use the first option when referring external files (such as the --with-apache directive that refers to the Apache directory). Use the second option when the user simply has to decide whether to enable your extension. Regardless of which option you use, you should uncomment the other, unnecessary one; that is, if you're using --enable-my_module, you should remove support for --with-my_module, and vice versa.
By default, the config.m4 file created by ext_skel accepts both directives and automatically enables your extension. Enabling the extension is done by using the PHP_EXTENSION macro. To change the default behavior to include your module into the PHP binary when desired by the user (by explicitly specifying --enable-my_module or --with-my_module), change the test for $PHP_MY_MODULE to == "yes":
if test "$PHP_MY_MODULE" == "yes"; then dnl Action.. PHP_EXTENSION(my_module, $ext_shared) fi |
Note: Be sure to run buildconf every time you change config.m4!
We'll go into more details on the M4 macros available to your configuration scripts later in this chapter. For now, we'll simply use the default files.
We'll start with the creation of a very simple extension at first, which basically does nothing more than implement a function that returns the integer it receives as parameter. ÐáñÜäåéãìá 28-1 shows the source.
ÐáñÜäåéãìá 28-1. A simple extension.
|
This code contains a complete PHP module. We'll explain the source code in detail shortly, but first we'd like to discuss the build process. (This will allow the impatient to experiment before we dive into API discussions.)
Óçìåßùóç: The example source makes use of some features introduced with the Zend version used in PHP 4.1.0 and above, it won't compile with older PHP 4.0.x versions.
There are basically two ways to compile modules:
Use the provided "make" mechanism in the ext directory, which also allows building of dynamic loadable modules.
Compile the sources manually.
The second method is good for those who (for some reason) don't have the full PHP source tree available, don't have access to all files, or just like to juggle with their keyboard. These cases should be extremely rare, but for the sake of completeness we'll also describe this method.
Compiling Using Make. To compile the sample sources using the standard mechanism, copy all their subdirectories to the ext directory of your PHP source tree. Then run buildconf, which will create an updated configure script containing appropriate options for the new extension. By default, all the sample sources are disabled, so you don't have to fear breaking your build process.
After you run buildconf, configure --help shows the following additional modules:
--enable-array_experiments BOOK: Enables array experiments --enable-call_userland BOOK: Enables userland module --enable-cross_conversion BOOK: Enables cross-conversion module --enable-first_module BOOK: Enables first module --enable-infoprint BOOK: Enables infoprint module --enable-reference_test BOOK: Enables reference test module --enable-resource_test BOOK: Enables resource test module --enable-variable_creation BOOK: Enables variable-creation module |
The module shown earlier in ÐáñÜäåéãìá 28-1 can be enabled with --enable-first_module or --enable-first_module=yes.
Compiling Manually. To compile your modules manually, you need the following commands:
The command to compile the module simply instructs the compiler to generate position-independent code (-fpic shouldn't be omitted) and additionally defines the constant COMPILE_DL to tell the module code that it's compiled as a dynamically loadable module (the test module above checks for this; we'll discuss it shortly). After these options, it specifies a number of standard include paths that should be used as the minimal set to compile the source files.Note: All include paths in the example are relative to the directory ext. If you're compiling from another directory, change the pathnames accordingly. Required items are the PHP directory, the Zend directory, and (if necessary), the directory in which your module resides.
The link command is also a plain vanilla command instructing linkage as a dynamic module.
You can include optimization options in the compilation command, although these have been omitted in this example (but some are included in the makefile template described in an earlier section).
Note: Compiling and linking manually as a static module into the PHP binary involves very long instructions and thus is not discussed here. (It's not very efficient to type all those commands.)
Depending on the build process you selected, you should either end up with a new PHP binary to be linked into your Web server (or run as CGI), or with an .so (shared object) file. If you compiled the example file first_module.c as a shared object, your result file should be first_module.so. To use it, you first have to copy it to a place from which it's accessible to PHP. For a simple test procedure, you can copy it to your htdocs directory and try it with the source in ÐáñÜäåéãìá 29-1. If you compiled it into the PHP binary, omit the call to dl(), as the module's functionality is instantly available to your scripts.
Ðñïåéäïðïßçóç |
For security reasons, you should not put your dynamic modules into publicly accessible directories. Even though it can be done and it simplifies testing, you should put them into a separate directory in production environments. |
Calling this PHP file in your Web browser should give you the output shown in Ó÷Þìá 29-1.
If required, the dynamic loadable module is loaded by calling the dl() function. This function looks for the specified shared object, loads it, and makes its functions available to PHP. The module exports the function first_module(), which accepts a single parameter, converts it to an integer, and returns the result of the conversion.
If you've gotten this far, congratulations! You just built your first extension to PHP.
Actually, not much troubleshooting can be done when compiling static or dynamic modules. The only problem that could arise is that the compiler will complain about missing definitions or something similar. In this case, make sure that all header files are available and that you specified their path correctly in the compilation command. To be sure that everything is located correctly, extract a clean PHP source tree and use the automatic build in the ext directory with the fresh files; this will guarantee a safe compilation environment. If this fails, try manual compilation.
PHP might also complain about missing functions in your module. (This shouldn't happen with the sample sources if you didn't modify them.) If the names of external functions you're trying to access from your module are misspelled, they'll remain as "unlinked symbols" in the symbol table. During dynamic loading and linkage by PHP, they won't resolve because of the typing errors - there are no corresponding symbols in the main binary. Look for incorrect declarations in your module file or incorrectly written external references. Note that this problem is specific to dynamic loadable modules; it doesn't occur with static modules. Errors in static modules show up at compile time.
Now that you've got a safe build environment and you're able to include the modules into PHP files, it's time to discuss how everything works.
All PHP modules follow a common structure:
Header file inclusions (to include all required macros, API definitions, etc.)
C declaration of exported functions (required to declare the Zend function block)
Declaration of the Zend function block
Declaration of the Zend module block
Implementation of get_module()
Implementation of all exported functions
The only header file you really have to include for your modules is php.h, located in the PHP directory. This file makes all macros and API definitions required to build new modules available to your code.
Tip: It's good practice to create a separate header file for your module that contains module-specific definitions. This header file should contain all the forward definitions for exported functions and include php.h. If you created your module using ext_skel you already have such a header file prepared.
To declare functions that are to be exported (i.e., made available to PHP as new native functions), Zend provides a set of macros. A sample declaration looks like this:
ZEND_FUNCTION ( my_function ); |
ZEND_FUNCTION declares a new C function that complies with Zend's internal API. This means that the function is of type void and accepts INTERNAL_FUNCTION_PARAMETERS (another macro) as parameters. Additionally, it prefixes the function name with zif. The immediately expanded version of the above definitions would look like this:
void zif_my_function ( INTERNAL_FUNCTION_PARAMETERS ); |
void zif_my_function( int ht , zval * return_value , zval * this_ptr , int return_value_used , zend_executor_globals * executor_globals ); |
Since the interpreter and executor core have been separated from the main PHP package, a second API defining macros and function sets has evolved: the Zend API. As the Zend API now handles quite a few of the responsibilities that previously belonged to PHP, a lot of PHP functions have been reduced to macros aliasing to calls into the Zend API. The recommended practice is to use the Zend API wherever possible, as the old API is only preserved for compatibility reasons. For example, the types zval and pval are identical. zval is Zend's definition; pval is PHP's definition (actually, pval is an alias for zval now). As the macro INTERNAL_FUNCTION_PARAMETERS is a Zend macro, the above declaration contains zval. When writing code, you should always use zval to conform to the new Zend API.
The parameter list of this declaration is very important; you should keep these parameters in mind (see Ðßíáêáò 31-1 for descriptions).
Ðßíáêáò 31-1. Zend's Parameters to Functions Called from PHP
Parameter | Description |
ht | The number of arguments passed to the Zend function. You should not touch this directly, but instead use ZEND_NUM_ARGS() to obtain the value. |
return_value | This variable is used to pass any return values of your function back to PHP. Access to this variable is best done using the predefined macros. For a description of these see below. |
this_ptr | Using this variable, you can gain access to the object in which your function is contained, if it's used within an object. Use the function getThis() to obtain this pointer. |
return_value_used | This flag indicates whether an eventual return value from this function will actually be used by the calling script. 0 indicates that the return value is not used; 1 indicates that the caller expects a return value. Evaluation of this flag can be done to verify correct usage of the function as well as speed optimizations in case returning a value requires expensive operations (for an example, see how array.c makes use of this). |
executor_globals | This variable points to global settings of the Zend engine. You'll find this useful when creating new variables, for example (more about this later). The executor globals can also be introduced to your function by using the macro TSRMLS_FETCH(). |
Now that you have declared the functions to be exported, you also have to introduce them to Zend. Introducing the list of functions is done by using an array of zend_function_entry. This array consecutively contains all functions that are to be made available externally, with the function's name as it should appear in PHP and its name as defined in the C source. Internally, zend_function_entry is defined as shown in ÐáñÜäåéãìá 31-1.
ÐáñÜäåéãìá 31-1. Internal declaration of zend_function_entry.
|
zend_function_entry firstmod_functions[] = { ZEND_FE(first_module, NULL) {NULL, NULL, NULL} }; |
Óçìåßùóç: You cannot use the predefined macros for the end marker, as these would try to refer to a function named "NULL"!
The macro ZEND_FE (short for 'Zend Function Entry') simply expands to a structure entry in zend_function_entry. Note that these macros introduce a special naming scheme to your functions - your C functions will be prefixed with zif_, meaning that ZEND_FE(first_module) will refer to a C function zif_first_module(). If you want to mix macro usage with hand-coded entries (not a good practice), keep this in mind.
Tip: Compilation errors that refer to functions named zif_*() relate to functions defined with ZEND_FE.
Ðßíáêáò 31-2 shows a list of all the macros that you can use to define functions.
Ðßíáêáò 31-2. Macros for Defining Functions
Macro Name | Description |
ZEND_FE(name, arg_types) | Defines a function entry of the name name in zend_function_entry. Requires a corresponding C function. arg_types needs to be set to NULL. This function uses automatic C function name generation by prefixing the PHP function name with zif_. For example, ZEND_FE("first_module", NULL) introduces a function first_module() to PHP and links it to the C function zif_first_module(). Use in conjunction with ZEND_FUNCTION. |
ZEND_NAMED_FE(php_name, name, arg_types) | Defines a function that will be available to PHP by the name php_name and links it to the corresponding C function name. arg_types needs to be set to NULL. Use this function if you don't want the automatic name prefixing introduced by ZEND_FE. Use in conjunction with ZEND_NAMED_FUNCTION. |
ZEND_FALIAS(name, alias, arg_types) | Defines an alias named alias for name. arg_types needs to be set to NULL. Doesn't require a corresponding C function; refers to the alias target instead. |
PHP_FE(name, arg_types) | Old PHP API equivalent of ZEND_FE. |
PHP_NAMED_FE(runtime_name, name, arg_types) | Old PHP API equivalent of ZEND_NAMED_FE. |
Note: You can't use ZEND_FE in conjunction with PHP_FUNCTION, or PHP_FE in conjunction with ZEND_FUNCTION. However, it's perfectly legal to mix ZEND_FE and ZEND_FUNCTION with PHP_FE and PHP_FUNCTION when staying with the same macro set for each function to be declared. But mixing is not recommended; instead, you're advised to use the ZEND_* macros only.
This block is stored in the structure zend_module_entry and contains all necessary information to describe the contents of this module to Zend. You can see the internal definition of this module in ÐáñÜäåéãìá 31-2.
ÐáñÜäåéãìá 31-2. Internal declaration of zend_module_entry.
|
In our example, this structure is implemented as follows:
zend_module_entry firstmod_module_entry = { STANDARD_MODULE_HEADER, "First Module", firstmod_functions, NULL, NULL, NULL, NULL, NULL, NO_VERSION_YET, STANDARD_MODULE_PROPERTIES, }; |
For reference purposes, you can find a list of the macros involved in declared startup and shutdown functions in Ðßíáêáò 31-3. These are not used in our basic example yet, but will be demonstrated later on. You should make use of these macros to declare your startup and shutdown functions, as these require special arguments to be passed (INIT_FUNC_ARGS and SHUTDOWN_FUNC_ARGS), which are automatically included into the function declaration when using the predefined macros. If you declare your functions manually and the PHP developers decide that a change in the argument list is necessary, you'll have to change your module sources to remain compatible.
Ðßíáêáò 31-3. Macros to Declare Startup and Shutdown Functions
Macro | Description |
ZEND_MINIT(module) | Declares a function for module startup. The generated name will be zend_minit_<module> (for example, zend_minit_first_module). Use in conjunction with ZEND_MINIT_FUNCTION. |
ZEND_MSHUTDOWN(module) | Declares a function for module shutdown. The generated name will be zend_mshutdown_<module> (for example, zend_mshutdown_first_module). Use in conjunction with ZEND_MSHUTDOWN_FUNCTION. |
ZEND_RINIT(module) | Declares a function for request startup. The generated name will be zend_rinit_<module> (for example, zend_rinit_first_module). Use in conjunction with ZEND_RINIT_FUNCTION. |
ZEND_RSHUTDOWN(module) | Declares a function for request shutdown. The generated name will be zend_rshutdown_<module> (for example, zend_rshutdown_first_module). Use in conjunction with ZEND_RSHUTDOWN_FUNCTION. |
ZEND_MINFO(module) | Declares a function for printing module information, used when phpinfo() is called. The generated name will be zend_info_<module> (for example, zend_info_first_module). Use in conjunction with ZEND_MINFO_FUNCTION. |
This function is special to all dynamic loadable modules. Take a look at the creation via the ZEND_GET_MODULE macro first:
#if COMPILE_DL_FIRSTMOD ZEND_GET_MODULE(firstmod) #endif |
The function implementation is surrounded by a conditional compilation statement. This is needed since the function get_module() is only required if your module is built as a dynamic extension. By specifying a definition of COMPILE_DL_FIRSTMOD in the compiler command (see above for a discussion of the compilation instructions required to build a dynamic extension), you can instruct your module whether you intend to build it as a dynamic extension or as a built-in module. If you want a built-in module, the implementation of get_module() is simply left out.
get_module() is called by Zend at load time of the module. You can think of it as being invoked by the dl() call in your script. Its purpose is to pass the module information block back to Zend in order to inform the engine about the module contents.
If you don't implement a get_module() function in your dynamic loadable module, Zend will compliment you with an error message when trying to access it.
Implementing the exported functions is the final step. The example function in first_module looks like this:
ZEND_FUNCTION(first_module) { long parameter; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", ¶meter) == FAILURE) { return; } RETURN_LONG(parameter); } |
After the declaration, code for checking and retrieving the function's arguments, argument conversion, and return value generation follows (more on this later).
That's it, basically - there's nothing more to implementing PHP modules. Built-in modules are structured similarly to dynamic modules, so, equipped with the information presented in the previous sections, you'll be able to fight the odds when encountering PHP module source files.
Now, in the following sections, read on about how to make use of PHP's internals to build powerful extensions.
One of the most important issues for language extensions is accepting and dealing with data passed via arguments. Most extensions are built to deal with specific input data (or require parameters to perform their specific actions), and function arguments are the only real way to exchange data between the PHP level and the C level. Of course, there's also the possibility of exchanging data using predefined global values (which is also discussed later), but this should be avoided by all means, as it's extremely bad practice.
PHP doesn't make use of any formal function declarations; this is why call syntax is always completely dynamic and never checked for errors. Checking for correct call syntax is left to the user code. For example, it's possible to call a function using only one argument at one time and four arguments the next time - both invocations are syntactically absolutely correct.
Since PHP doesn't have formal function definitions with support for call syntax checking, and since PHP features variable arguments, sometimes you need to find out with how many arguments your function has been called. You can use the ZEND_NUM_ARGS macro in this case. In previous versions of PHP, this macro retrieved the number of arguments with which the function has been called based on the function's hash table entry, ht, which is passed in the INTERNAL_FUNCTION_PARAMETERS list. As ht itself now contains the number of arguments that have been passed to the function, ZEND_NUM_ARGS has been stripped down to a dummy macro (see its definition in zend_API.h). But it's still good practice to use it, to remain compatible with future changes in the call interface. Note: The old PHP equivalent of this macro is ARG_COUNT.
The following code checks for the correct number of arguments:
if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT; |
This macro prints a default error message and then returns to the caller. Its definition can also be found in zend_API.h and looks like this:
ZEND_API void wrong_param_count(void); #define WRONG_PARAM_COUNT { wrong_param_count(); return; } |
New parameter parsing API: This chapter documents the new Zend parameter parsing API introduced by Andrei Zmievski. It was introduced in the development stage between PHP 4.0.6 and 4.1.0 .
Parsing parameters is a very common operation and it may get a bit tedious. It would also be nice to have standardized error checking and error messages. Since PHP 4.1.0, there is a way to do just that by using the new parameter parsing API. It greatly simplifies the process of receiving parameteres, but it has a drawback in that it can't be used for functions that expect variable number of parameters. But since the vast majority of functions do not fall into those categories, this parsing API is recommended as the new standard way.
The prototype for parameter parsing function looks like this:
int zend_parse_parameters(int num_args TSRMLS_DC, char *type_spec, ...); |
zend_parse_parameters() also performs type conversions whenever possible, so that you always receive the data in the format you asked for. Any type of scalar can be converted to another one, but conversions between complex types (arrays, objects, and resources) and scalar types are not allowed.
If the parameters could be obtained successfully and there were no errors during type conversion, the function will return SUCCESS, otherwise it will return FAILURE. The function will output informative error messages, if the number of received parameters does not match the requested number, or if type conversion could not be performed.
Here are some sample error messages:
Warning - ini_get_all() requires at most 1 parameter, 2 given Warning - wddx_deserialize() expects parameter 1 to be string, array given |
Here is the full list of type specifiers:
l - long
d - double
s - string (with possible null bytes) and its length
b - boolean
r - resource, stored in zval*
a - array, stored in zval*
o - object (of any class), stored in zval*
O - object (of class specified by class entry), stored in zval*
z - the actual zval*
| - indicates that the remaining parameters are optional. The storage variables corresponding to these parameters should be initialized to default values by the extension, since they will not be touched by the parsing function if the parameters are not passed.
/ - the parsing function will call SEPARATE_ZVAL_IF_NOT_REF() on the parameter it follows, to provide a copy of the parameter, unless it's a reference.
! - the parameter it follows can be of specified type or NULL (only applies to a, o, O, r, and z). If NULL value is passed by the user, the storage pointer will be set to NULL.
The best way to illustrate the usage of this function is through examples:
/* Gets a long, a string and its length, and a zval. */ long l; char *s; int s_len; zval *param; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsz", &l, &s, &s_len, ¶m) == FAILURE) { return; } /* Gets an object of class specified by my_ce, and an optional double. */ zval *obj; double d = 0.5; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|d", &obj, my_ce, &d) == FAILURE) { return; } /* Gets an object or null, and an array. If null is passed for object, obj will be set to NULL. */ zval *obj; zval *arr; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O!a", &obj, &arr) == FAILURE) { return; } /* Gets a separated array. */ zval *arr; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &arr) == FAILURE) { return; } /* Get only the first three parameters (useful for varargs functions). */ zval *z; zend_bool b; zval *r; if (zend_parse_parameters(3, "zbr!", &z, &b, &r) == FAILURE) { return; } |
Note that in the last example we pass 3 for the number of received parameters, instead of ZEND_NUM_ARGS(). What this lets us do is receive the least number of parameters if our function expects a variable number of them. Of course, if you want to operate on the rest of the parameters, you will have to use zend_get_parameters_array_ex() to obtain them.
The parsing function has an extended version that allows for an additional flags argument that controls its actions.
int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, char *type_spec, ...); |
The only flag you can pass currently is ZEND_PARSE_PARAMS_QUIET, which instructs the function to not output any error messages during its operation. This is useful for functions that expect several sets of completely different arguments, but you will have to output your own error messages.
For example, here is how you would get either a set of three longs or a string:
long l1, l2, l3; char *s; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "lll", &l1, &l2, &l3) == SUCCESS) { /* manipulate longs */ } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s", &s, &s_len) == SUCCESS) { /* manipulate string */ } else { php_error(E_WARNING, "%s() takes either three long values or a string as argument", get_active_function_name(TSRMLS_C)); return; } |
With all the abovementioned ways of receiving function parameters you should have a good handle on this process. For even more example, look through the source code for extensions that are shipped with PHP - they illustrate every conceivable situation.
Deprecated parameter parsing API: This API is deprecated and superseded by the new ZEND parameter parsing API.
After having checked the number of arguments, you need to get access to the arguments themselves. This is done with the help of zend_get_parameters_ex():
zval **parameter; if(zend_get_parameters_ex(1, ¶meter) != SUCCESS) WRONG_PARAM_COUNT; |
zend_get_parameters_ex() accepts at least two arguments. The first argument is the number of arguments to retrieve (which should match the number of arguments with which the function has been called; this is why it's important to check for correct call syntax). The second argument (and all following arguments) are pointers to pointers to pointers to zvals. (Confusing, isn't it?) All these pointers are required because Zend works internally with **zval; to adjust a local **zval in our function,zend_get_parameters_ex() requires a pointer to it.
The return value of zend_get_parameters_ex() can either be SUCCESS or FAILURE, indicating (unsurprisingly) success or failure of the argument processing. A failure is most likely related to an incorrect number of arguments being specified, in which case you should exit with WRONG_PARAM_COUNT.
To retrieve more than one argument, you can use a similar snippet:
zval **param1, **param2, **param3, **param4; if(zend_get_parameters_ex(4, ¶m1, ¶m2, ¶m3, ¶m4) != SUCCESS) WRONG_PARAM_COUNT; |
zend_get_parameters_ex() only checks whether you're trying to retrieve too many parameters. If the function is called with five arguments, but you're only retrieving three of them with zend_get_parameters_ex(), you won't get an error but will get the first three parameters instead. Subsequent calls of zend_get_parameters_ex() won't retrieve the remaining arguments, but will get the same arguments again.
If your function is meant to accept a variable number of arguments, the snippets just described are sometimes suboptimal solutions. You have to create a line calling zend_get_parameters_ex() for every possible number of arguments, which is often unsatisfying.
For this case, you can use the function zend_get_parameters_array_ex(), which accepts the number of parameters to retrieve and an array in which to store them:
zval **parameter_array[4]; /* get the number of arguments */ argument_count = ZEND_NUM_ARGS(); /* see if it satisfies our minimal request (2 arguments) */ /* and our maximal acceptance (4 arguments) */ if(argument_count < 2 || argument_count > 5) WRONG_PARAM_COUNT; /* argument count is correct, now retrieve arguments */ if(zend_get_parameters_array_ex(argument_count, parameter_array) != SUCCESS) WRONG_PARAM_COUNT; |
A very clever implementation of this can be found in the code handling PHP's fsockopen() located in ext/standard/fsock.c, as shown in ÐáñÜäåéãìá 32-1. Don't worry if you don't know all the functions used in this source yet; we'll get to them shortly.
ÐáñÜäåéãìá 32-1. PHP's implementation of variable arguments in fsockopen().
|
fsockopen() accepts two, three, four, or five parameters. After the obligatory variable declarations, the function checks for the correct range of arguments. Then it uses a fall-through mechanism in a switch() statement to deal with all arguments. The switch() statement starts with the maximum number of arguments being passed (five). After that, it automatically processes the case of four arguments being passed, then three, by omitting the otherwise obligatory break keyword in all stages. After having processed the last case, it exits the switch() statement and does the minimal argument processing needed if the function is invoked with only two arguments.
This multiple-stage type of processing, similar to a stairway, allows convenient processing of a variable number of arguments.
To access arguments, it's necessary for each argument to have a clearly defined type. Again, PHP's extremely dynamic nature introduces some quirks. Because PHP never does any kind of type checking, it's possible for a caller to pass any kind of data to your functions, whether you want it or not. If you expect an integer, for example, the caller might pass an array, and vice versa - PHP simply won't notice.
To work around this, you have to use a set of API functions to force a type conversion on every argument that's being passed (see Ðßíáêáò 32-1).
Note: All conversion functions expect a **zval as parameter.
Ðßíáêáò 32-1. Argument Conversion Functions
Function | Description |
convert_to_boolean_ex() | Forces conversion to a Boolean type. Boolean values remain untouched. Longs, doubles, and strings containing 0 as well as NULL values will result in Boolean 0 (FALSE). Arrays and objects are converted based on the number of entries or properties, respectively, that they have. Empty arrays and objects are converted to FALSE; otherwise, to TRUE. All other values result in a Boolean 1 (TRUE). |
convert_to_long_ex() | Forces conversion to a long, the default integer type. NULL values, Booleans, resources, and of course longs remain untouched. Doubles are truncated. Strings containing an integer are converted to their corresponding numeric representation, otherwise resulting in 0. Arrays and objects are converted to 0 if empty, 1 otherwise. |
convert_to_double_ex() | Forces conversion to a double, the default floating-point type. NULL values, Booleans, resources, longs, and of course doubles remain untouched. Strings containing a number are converted to their corresponding numeric representation, otherwise resulting in 0.0. Arrays and objects are converted to 0.0 if empty, 1.0 otherwise. |
convert_to_string_ex() | Forces conversion to a string. Strings remain untouched. NULL values are converted to an empty string. Booleans containing TRUE are converted to "1", otherwise resulting in an empty string. Longs and doubles are converted to their corresponding string representation. Arrays are converted to the string "Array" and objects to the string "Object". |
convert_to_array_ex(value) | Forces conversion to an array. Arrays remain untouched. Objects are converted to an array by assigning all their properties to the array table. All property names are used as keys, property contents as values. NULL values are converted to an empty array. All other values are converted to an array that contains the specific source value in the element with the key 0. |
convert_to_object_ex(value) | Forces conversion to an object. Objects remain untouched. NULL values are converted to an empty object. Arrays are converted to objects by introducing their keys as properties into the objects and their values as corresponding property contents in the object. All other types result in an object with the property scalar , having the corresponding source value as content. |
convert_to_null_ex(value) | Forces the type to become a NULL value, meaning empty. |
Óçìåßùóç: You can find a demonstration of the behavior in cross_conversion.php on the accompanying CD-ROM. Ó÷Þìá 32-2 shows the output.
Using these functions on your arguments will ensure type safety for all data that's passed to you. If the supplied type doesn't match the required type, PHP forces dummy contents on the resulting value (empty strings, arrays, or objects, 0 for numeric values, FALSE for Booleans) to ensure a defined state.
Following is a quote from the sample module discussed previously, which makes use of the conversion functions:
zval **parameter; if((ZEND_NUM_ARGS() != 1) || (zend_get_parameters_ex(1, ¶meter) != SUCCESS)) { WRONG_PARAM_COUNT; } convert_to_long_ex(parameter); RETURN_LONG(Z_LVAL_P(parameter)); |
ÐáñÜäåéãìá 32-2. PHP/Zend zval type definition.
|
Actually, pval (defined in php.h) is only an alias of zval (defined in zend.h), which in turn refers to _zval_struct. This is a most interesting structure. _zval_struct is the "master" structure, containing the value structure, type, and reference information. The substructure zvalue_value is a union that contains the variable's contents. Depending on the variable's type, you'll have to access different members of this union. For a description of both structures, see Ðßíáêáò 32-2, Ðßíáêáò 32-3 and Ðßíáêáò 32-4.
Ðßíáêáò 32-2. Zend zval Structure
Entry | Description |
value | Union containing this variable's contents. See Ðßíáêáò 32-3 for a description. |
type | Contains this variable's type. For a list of available types, see Ðßíáêáò 32-4. |
is_ref | 0 means that this variable is not a reference; 1 means that this variable is a reference to another variable. |
refcount | The number of references that exist for this variable. For every new reference to the value stored in this variable, this counter is increased by 1. For every lost reference, this counter is decreased by 1. When the reference counter reaches 0, no references exist to this value anymore, which causes automatic freeing of the value. |
Ðßíáêáò 32-3. Zend zvalue_value Structure
Entry | Description |
lval | Use this property if the variable is of the type IS_LONG, IS_BOOLEAN, or IS_RESOURCE. |
dval | Use this property if the variable is of the type IS_DOUBLE. |
str | This structure can be used to access variables of the type IS_STRING. The member len contains the string length; the member val points to the string itself. Zend uses C strings; thus, the string length contains a trailing 0x00. |
ht | This entry points to the variable's hash table entry if the variable is an array. |
obj | Use this property if the variable is of the type IS_OBJECT. |
Ðßíáêáò 32-4. Zend Variable Type Constants
Constant | Description |
IS_NULL | Denotes a NULL (empty) value. |
IS_LONG | A long (integer) value. |
IS_DOUBLE | A double (floating point) value. |
IS_STRING | A string. |
IS_ARRAY | Denotes an array. |
IS_OBJECT | An object. |
IS_BOOL | A Boolean value. |
IS_RESOURCE | A resource (for a discussion of resources, see the appropriate section below). |
IS_CONSTANT | A constant (defined) value. |
To access a long you access zval.value.lval, to access a double you use zval.value.dval, and so on. Because all values are stored in a union, trying to access data with incorrect union members results in meaningless output.
Accessing arrays and objects is a bit more complicated and is discussed later.
If your function accepts arguments passed by reference that you intend to modify, you need to take some precautions.
What we didn't say yet is that under the circumstances presented so far, you don't have write access to any zval containers designating function parameters that have been passed to you. Of course, you can change any zval containers that you created within your function, but you mustn't change any zvals that refer to Zend-internal data!
We've only discussed the so-called *_ex() API so far. You may have noticed that the API functions we've used are called zend_get_parameters_ex() instead of zend_get_parameters(), convert_to_long_ex() instead of convert_to_long(), etc. The *_ex() functions form the so-called new "extended" Zend API. They give a minor speed increase over the old API, but as a tradeoff are only meant for providing read-only access.
Because Zend works internally with references, different variables may reference the same value. Write access to a zval container requires this container to contain an isolated value, meaning a value that's not referenced by any other containers. If a zval container were referenced by other containers and you changed the referenced zval, you would automatically change the contents of the other containers referencing this zval (because they'd simply point to the changed value and thus change their own value as well).
zend_get_parameters_ex() doesn't care about this situation, but simply returns a pointer to the desired zval containers, whether they consist of references or not. Its corresponding function in the traditional API, zend_get_parameters(), immediately checks for referenced values. If it finds a reference, it creates a new, isolated zval container; copies the referenced data into this newly allocated space; and then returns a pointer to the new, isolated value.
This action is called zval separation (or pval separation). Because the *_ex() API doesn't perform zval separation, it's considerably faster, while at the same time disabling write access.
To change parameters, however, write access is required. Zend deals with this situation in a special way: Whenever a parameter to a function is passed by reference, it performs automatic zval separation. This means that whenever you're calling a function like this in PHP, Zend will automatically ensure that $parameter is being passed as an isolated value, rendering it to a write-safe state:
my_function(&$parameter); |
But this is not the case with regular parameters! All other parameters that are not passed by reference are in a read-only state.
This requires you to make sure that you're really working with a reference - otherwise you might produce unwanted results. To check for a parameter being passed by reference, you can use the macro PZVAL_IS_REF. This macro accepts a zval* to check if it is a reference or not. Examples are given in in ÐáñÜäåéãìá 32-3.
ÐáñÜäåéãìá 32-3. Testing for referenced parameter passing.
|
You might run into a situation in which you need write access to a parameter that's retrieved with zend_get_parameters_ex() but not passed by reference. For this case, you can use the macro SEPARATE_ZVAL, which does a zval separation on the provided container. The newly generated zval is detached from internal data and has only a local scope, meaning that it can be changed or destroyed without implying global changes in the script context:
zval **parameter; /* retrieve parameter */ zend_get_parameters_ex(1, ¶meter); /* at this stage, <parameter> still is connected */ /* to Zend's internal data buffers */ /* make <parameter> write-safe */ SEPARATE_ZVAL(parameter); /* now we can safely modify <parameter> */ /* without implying global changes */ |
Note: As you can easily work around the lack of write access in the "traditional" API (with zend_get_parameters() and so on), this API seems to be obsolete, and is not discussed further in this chapter.
When exchanging data from your own extensions with PHP scripts, one of the most important issues is the creation of variables. This section shows you how to deal with the variable types that PHP supports.
To create new variables that can be seen "from the outside" by the executing script, you need to allocate a new zval container, fill this container with meaningful values, and then introduce it to Zend's internal symbol table. This basic process is common to all variable creations:
zval *new_variable; /* allocate and initialize new container */ MAKE_STD_ZVAL(new_variable); /* set type and variable contents here, see the following sections */ /* introduce this variable by the name "new_variable_name" into the symbol table */ ZEND_SET_SYMBOL(EG(active_symbol_table), "new_variable_name", new_variable); /* the variable is now accessible to the script by using $new_variable_name */ |
The macro MAKE_STD_ZVAL allocates a new zval container using ALLOC_ZVAL and initializes it using INIT_ZVAL. As implemented in Zend at the time of this writing, initializing means setting the reference count to 1 and clearing the is_ref flag, but this process could be extended later - this is why it's a good idea to keep using MAKE_STD_ZVAL instead of only using ALLOC_ZVAL. If you want to optimize for speed (and you don't have to explicitly initialize the zval container here), you can use ALLOC_ZVAL, but this isn't recommended because it doesn't ensure data integrity.
ZEND_SET_SYMBOL takes care of introducing the new variable to Zend's symbol table. This macro checks whether the value already exists in the symbol table and converts the new symbol to a reference if so (with automatic deallocation of the old zval container). This is the preferred method if speed is not a crucial issue and you'd like to keep memory usage low.
Note that ZEND_SET_SYMBOL makes use of the Zend executor globals via the macro EG. By specifying EG(active_symbol_table), you get access to the currently active symbol table, dealing with the active, local scope. The local scope may differ depending on whether the function was invoked from within a function.
If you need to optimize for speed and don't care about optimal memory usage, you can omit the check for an existing variable with the same value and instead force insertion into the symbol table by using zend_hash_update():
zval *new_variable; /* allocate and initialize new container */ MAKE_STD_ZVAL(new_variable); /* set type and variable contents here, see the following sections */ /* introduce this variable by the name "new_variable_name" into the symbol table */ zend_hash_update( EG(active_symbol_table), "new_variable_name", strlen("new_variable_name") + 1, &new_variable, sizeof(zval *), NULL ); |
The variables generated with the snippet above will always be of local scope, so they reside in the context in which the function has been called. To create new variables in the global scope, use the same method but refer to another symbol table:
zval *new_variable; // allocate and initialize new container MAKE_STD_ZVAL(new_variable); // // set type and variable contents here // // introduce this variable by the name "new_variable_name" into the global symbol table ZEND_SET_SYMBOL(&EG(symbol_table), "new_variable_name", new_variable); |
Note: The active_symbol_table variable is a pointer, but symbol_table is not. This is why you have to use EG(active_symbol_table) and &EG(symbol_table) as parameters to ZEND_SET_SYMBOL - it requires a pointer.
Similarly, to get a more efficient version, you can hardcode the symbol table update:
zval *new_variable; // allocate and initialize new container MAKE_STD_ZVAL(new_variable); // // set type and variable contents here // // introduce this variable by the name "new_variable_name" into the global symbol table zend_hash_update( &EG(symbol_table), "new_variable_name", strlen("new_variable_name") + 1, &new_variable, sizeof(zval *), NULL ); |
Note: You can see that the global variable is actually not accessible from within the function. This is because it's not imported into the local scope using global $global_variable; in the PHP source.
ÐáñÜäåéãìá 33-1. Creating variables with different scopes.
|
Now let's get to the assignment of data to variables, starting with longs. Longs are PHP's integers and are very simple to store. Looking at the zval.value container structure discussed earlier in this chapter, you can see that the long data type is directly contained in the union, namely in the lval field. The corresponding type value for longs is IS_LONG (see ÐáñÜäåéãìá 33-2).
zval *new_long; MAKE_STD_ZVAL(new_long); ZVAL_LONG(new_long, 10); |
Doubles are PHP's floats and are as easy to assign as longs, because their value is also contained directly in the union. The member in the zval.value container is dval; the corresponding type is IS_DOUBLE.
zval *new_double; MAKE_STD_ZVAL(new_double); new_double->type = IS_DOUBLE; new_double->value.dval = 3.45; |
zval *new_double; MAKE_STD_ZVAL(new_double); ZVAL_DOUBLE(new_double, 3.45); |
Strings need slightly more effort. As mentioned earlier, all strings that will be associated with Zend's internal data structures need to be allocated using Zend's own memory-management functions. Referencing of static strings or strings allocated with standard routines is not allowed. To assign strings, you have to access the structure str in the zval.value container. The corresponding type is IS_STRING:
zval *new_string; char *string_contents = "This is a new string variable"; MAKE_STD_ZVAL(new_string); new_string->type = IS_STRING; new_string->value.str.len = strlen(string_contents); new_string->value.str.val = estrdup(string_contents); |
zval *new_string; char *string_contents = "This is a new string variable"; MAKE_STD_ZVAL(new_string); ZVAL_STRING(new_string, string_contents, 1); |
If you want to truncate the string at a certain position or you already know its length, you can use ZVAL_STRINGL(zval, string, length, duplicate), which accepts an explicit string length to be set for the new string. This macro is faster than ZVAL_STRING and also binary-safe.
To create empty strings, set the string length to 0 and use empty_string as contents:
new_string->type = IS_STRING; new_string->value.str.len = 0; new_string->value.str.val = empty_string; |
MAKE_STD_ZVAL(new_string); ZVAL_EMPTY_STRING(new_string); |
Booleans are created just like longs, but have the type IS_BOOL. Allowed values in lval are 0 and 1:
zval *new_bool; MAKE_STD_ZVAL(new_bool); new_bool->type = IS_BOOL; new_bool->value.lval = 1; |
Arrays are stored using Zend's internal hash tables, which can be accessed using the zend_hash_*() API. For every array that you want to create, you need a new hash table handle, which will be stored in the ht member of the zval.value container.
There's a whole API solely for the creation of arrays, which is extremely handy. To start a new array, you call array_init().
zval *new_array; MAKE_STD_ZVAL(new_array); array_init(new_array); |
To add new elements to the array, you can use numerous functions, depending on what you want to do. Ðßíáêáò 33-1, Ðßíáêáò 33-2 and Ðßíáêáò 33-3 describe these functions. All functions return FAILURE on failure and SUCCESS on success.
Ðßíáêáò 33-1. Zend's API for Associative Arrays
Function | Description |
add_assoc_long(zval *array, char *key, long n);() | Adds an element of type long. |
add_assoc_unset(zval *array, char *key);() | Adds an unset element. |
add_assoc_bool(zval *array, char *key, int b);() | Adds a Boolean element. |
add_assoc_resource(zval *array, char *key, int r);() | Adds a resource to the array. |
add_assoc_double(zval *array, char *key, double d);() | Adds a floating-point value. |
add_assoc_string(zval *array, char *key, char *str, int duplicate);() | Adds a string to the array. The flag duplicate specifies whether the string contents have to be copied to Zend internal memory. |
add_assoc_stringl(zval *array, char *key, char *str, uint length, int duplicate); () | Adds a string with the desired length length to the array. Otherwise, behaves like add_assoc_string(). |
add_assoc_zval(zval *array, char *key, zval *value);() | Adds a zval to the array. Useful for adding other arrays, objects, streams, etc... |
Ðßíáêáò 33-2. Zend's API for Indexed Arrays, Part 1
Function | Description |
add_index_long(zval *array, uint idx, long n);() | Adds an element of type long. |
add_index_unset(zval *array, uint idx);() | Adds an unset element. |
add_index_bool(zval *array, uint idx, int b);() | Adds a Boolean element. |
add_index_resource(zval *array, uint idx, int r);() | Adds a resource to the array. |
add_index_double(zval *array, uint idx, double d);() | Adds a floating-point value. |
add_index_string(zval *array, uint idx, char *str, int duplicate);() | Adds a string to the array. The flag duplicate specifies whether the string contents have to be copied to Zend internal memory. |
add_index_stringl(zval *array, uint idx, char *str, uint length, int duplicate);() | Adds a string with the desired length length to the array. This function is faster and binary-safe. Otherwise, behaves like add_index_string()(). |
add_index_zval(zval *array, uint idx, zval *value);() | Adds a zval to the array. Useful for adding other arrays, objects, streams, etc... |
Ðßíáêáò 33-3. Zend's API for Indexed Arrays, Part 2
Function | Description |
add_next_index_long(zval *array, long n);() | Adds an element of type long. |
add_next_index_unset(zval *array);() | Adds an unset element. |
add_next_index_bool(zval *array, int b);() | Adds a Boolean element. |
add_next_index_resource(zval *array, int r);() | Adds a resource to the array. |
add_next_index_double(zval *array, double d);() | Adds a floating-point value. |
add_next_index_string(zval *array, char *str, int duplicate);() | Adds a string to the array. The flag duplicate specifies whether the string contents have to be copied to Zend internal memory. |
add_next_index_stringl(zval *array, char *str, uint length, int duplicate);() | Adds a string with the desired length length to the array. This function is faster and binary-safe. Otherwise, behaves like add_index_string()(). |
add_next_index_zval(zval *array, zval *value);() | Adds a zval to the array. Useful for adding other arrays, objects, streams, etc... |
All these functions provide a handy abstraction to Zend's internal hash API. Of course, you can also use the hash functions directly - for example, if you already have a zval container allocated that you want to insert into an array. This is done using zend_hash_update()() for associative arrays (see ÐáñÜäåéãìá 33-3) and zend_hash_index_update() for indexed arrays (see ÐáñÜäåéãìá 33-4):
ÐáñÜäåéãìá 33-3. Adding an element to an associative array.
|
ÐáñÜäåéãìá 33-4. Adding an element to an indexed array.
|
To emulate the functionality of add_next_index_*(), you can use this:
zend_hash_next_index_insert(ht, zval **new_element, sizeof(zval *), NULL) |
Note: To return arrays from a function, use array_init() and all following actions on the predefined variable return_value (given as argument to your exported function; see the earlier discussion of the call interface). You do not have to use MAKE_STD_ZVAL on this.
Tip: To avoid having to write new_array->value.ht every time, you can use HASH_OF(new_array), which is also recommended for compatibility and style reasons.
Since objects can be converted to arrays (and vice versa), you might have already guessed that they have a lot of similarities to arrays in PHP. Objects are maintained with the same hash functions, but there's a different API for creating them.
To initialize an object, you use the function object_init():
zval *new_object; MAKE_STD_ZVAL(new_object); if(object_init(new_object) != SUCCESS) { // do error handling here } |
Ðßíáêáò 33-4. Zend's API for Object Creation
Function | Description |
add_property_long(zval *object, char *key, long l);() | Adds a long to the object. |
add_property_unset(zval *object, char *key);() | Adds an unset property to the object. |
add_property_bool(zval *object, char *key, int b);() | Adds a Boolean to the object. |
add_property_resource(zval *object, char *key, long r);() | Adds a resource to the object. |
add_property_double(zval *object, char *key, double d);() | Adds a double to the object. |
add_property_string(zval *object, char *key, char *str, int duplicate);() | Adds a string to the object. |
add_property_stringl(zval *object, char *key, char *str, uint length, int duplicate);() | Adds a string of the specified length to the object. This function is faster than add_property_string() and also binary-safe. |
add_property_zval(zval *obect, char *key, zval *container):() | Adds a zval container to the object. This is useful if you have to add properties which aren't simple types like integers or strings but arrays or other objects. |
Resources are a special kind of data type in PHP. The term resources doesn't really refer to any special kind of data, but to an abstraction method for maintaining any kind of information. Resources are kept in a special resource list within Zend. Each entry in the list has a correspondending type definition that denotes the kind of resource to which it refers. Zend then internally manages all references to this resource. Access to a resource is never possible directly - only via a provided API. As soon as all references to a specific resource are lost, a corresponding shutdown function is called.
For example, resources are used to store database links and file descriptors. The de facto standard implementation can be found in the MySQL module, but other modules such as the Oracle module also make use of resources.
Óçìåßùóç: In fact, a resource can be a pointer to anything you need to handle in your functions (e.g. pointer to a structure) and the user only has to pass a single resource variable to your function.
To create a new resource you need to register a resource destruction handler for it. Since you can store any kind of data as a resource, Zend needs to know how to free this resource if its not longer needed. This works by registering your own resource destruction handler to Zend which in turn gets called by Zend whenever your resource can be freed (whether manually or automatically). Registering your resource handler within Zend returns you the resource type handle for that resource. This handle is needed whenever you want to access a resource of this type later and is most of time stored in a global static variable within your extension. There is no need to worry about thread safety here because you only register your resource handler once during module initialization.
The Zend function to register your resource handler is defined as:
ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, char *type_name, int module_number); |
There are two different kinds of resource destruction handlers you can pass to this function: a handler for normal resources and a handler for persistent resources. Persistent resources are for example used for database connection. When registering a resource, either of these handlers must be given. For the other handler just pass NULL.
zend_register_list_destructors_ex() accepts the following parameters:
ld | Normal resource destruction handler callback |
pld | Pesistent resource destruction handler callback |
type_name | A string specifying the name of your resource. It's always a good thing to specify an unique name within PHP for the resource type so when the user for example calls var_dump($resource); he also gets the name of the resource. |
module_number | The module_number is automatically available in your PHP_MINIT_FUNCTION function and therefore you just pass it over. |
The resource destruction handler (either normal or persistent resources) has the following prototype:
void resource_destruction_handler(zend_rsrc_list_entry *rsrc TSRMLS_DC); |
typedef struct _zend_rsrc_list_entry { void *ptr; int type; int refcount; } zend_rsrc_list_entry; |
Now we know how to start things, we define our own resource we want register within Zend. It is only a simple structure with two integer members:
typedef struct { int resource_link; int resource_type; } my_resource; |
void my_destruction_handler(zend_rsrc_list_entry *rsrc TSRMLS_DC) { // You most likely cast the void pointer to your structure type my_resource *my_rsrc = (my_resource *) rsrc->ptr; // Now do whatever needs to be done with you resource. Closing // Files, Sockets, freeing additional memory, etc. // Also, don't forget to actually free the memory for your resource too! do_whatever_needs_to_be_done_with_the_resource(my_rsrc); } |
Óçìåßùóç: One important thing to mention: If your resource is a rather complex structure which also contains pointers to memory you allocated during runtime you have to free them before freeing the resource itself!
Now that we have defined
what our resource is and
our resource destruction handler
create a global variable within the extension holding the resource ID so it can be accessed from every function which needs it
define the resource name
write the resource destruction handler
and finally register the handler
// Somewhere in your extension, define the variable for your registered resources. // If you wondered what 'le' stands for: it simply means 'list entry'. static int le_myresource; // It's nice to define your resource name somewhere #define le_myresource_name "My type of resource" [...] // Now actually define our resource destruction handler void my_destruction_handler(zend_rsrc_list_entry *rsrc TSRMLS_DC) { my_resource *my_rsrc = (my_resource *) rsrc->ptr; do_whatever_needs_to_be_done_with_the_resource(my_rsrc); } [...] PHP_MINIT_FUNCTION(my_extension) { // Note that 'module_number' is already provided through the // PHP_MINIT_FUNCTION() function definition. le_myresource = zend_register_resource_destructors_ex(my_destruction_handler, NULL, le_myresource_name, module_number); // You can register additional resources, initialize // your global vars, constants, whatever. } |
To actually register a new resource you use can either use the zend_register_resource() function or the ZEND_REGISTER_RESOURE() macro, both defined in zend_list.h . Although the arguments for both map 1:1 it's a good idea to always use macros to be upwards compatible:
int ZEND_REGISTER_RESOURCE(zval *rsrc_result, void *rsrc_pointer, int rsrc_type); |
rsrc_result | This is an already initialized zval * container. |
rsrc_pointer | Your resource pointer you want to store. |
rsrc_type | The type which you received when you registered the resource destruction handler. If you followed the naming scheme this would be le_myresource. |
What is really going on when you register a new resource is it gets inserted in an internal list in Zend and the result is just stored in the given zval * container:
rsrc_id = zend_list_insert(rsrc_pointer, rsrc_type); if (rsrc_result) { rsrc_result->value.lval = rsrc_id; rsrc_result->type = IS_RESOURCE; } return rsrc_id; |
RETURN_RESOURCE(rsrc_id) |
Óçìåßùóç: It is common practice that if you want to return the resource immidiately to the user you specify the return_value as the zval * container.
Zend now keeps track of all references to this resource. As soon as all references to the resource are lost, the destructor that you previously registered for this resource is called. The nice thing about this setup is that you don't have to worry about memory leakages introduced by allocations in your module - just register all memory allocations that your calling script will refer to as resources. As soon as the script decides it doesn't need them anymore, Zend will find out and tell you.
Now that the user got his resource, at some point he is passing it back to one of your functions. The value.lval inside the zval * container contains the key to your resource and thus can be used to fetch the resource with the following macro: ZEND_FETCH_RESOURCE:
ZEND_FETCH_RESOURCE(rsrc, rsrc_type, rsrc_id, default_rsrc_id, resource_type_name, resource_type) |
rsrc | This is your pointer which will point to your previously registered resource. |
rsrc_type | This is the typecast argument for your pointer, e.g. myresource *. |
rsrc_id | This is the address of the zval *container the user passed to your function, e.g. &z_resource if zval *z_resource is given. |
default_rsrc_id | This integer specifies the default resource ID if no resource could be fetched or -1. |
resource_type_name | This is the name of the requested resource. It's a string and is used when the resource can't be found or is invalid to form a meaningful error message. |
resource_type | The resource_type you got back when registering the resource destruction handler. In our example this was le_myresource. |
To force removal of a resource from the list, use the function zend_list_delete(). You can also force the reference count to increase if you know that you're creating another reference for a previously allocated value (for example, if you're automatically reusing a default database link). For this case, use the function zend_list_addref(). To search for previously allocated resource entries, use zend_list_find(). The complete API can be found in zend_list.h.
In addition to the macros discussed earlier, a few macros allow easy creation of simple global variables. These are nice to know in case you want to introduce global flags, for example. This is somewhat bad practice, but Table Ðßíáêáò 33-5 describes macros that do exactly this task. They don't need any zval allocation; you simply have to supply a variable name and value.
Ðßíáêáò 33-5. Macros for Global Variable Creation
Macro | Description |
SET_VAR_STRING(name, value) | Creates a new string. |
SET_VAR_STRINGL(name, value, length) | Creates a new string of the specified length. This macro is faster than SET_VAR_STRING and also binary-safe. |
SET_VAR_LONG(name, value) | Creates a new long. |
SET_VAR_DOUBLE(name, value) | Creates a new double. |
Zend supports the creation of true constants (as opposed to regular variables). Constants are accessed without the typical dollar sign ($) prefix and are available in all scopes. Examples include TRUE and FALSE, to name just two.
To create your own constants, you can use the macros in Ðßíáêáò 33-6. All the macros create a constant with the specified name and value.
You can also specify flags for each constant:
CONST_CS - This constant's name is to be treated as case sensitive.
CONST_PERSISTENT - This constant is persistent and won't be "forgotten" when the current process carrying this constant shuts down.
// register a new constant of type "long" REGISTER_LONG_CONSTANT("NEW_MEANINGFUL_CONSTANT", 324, CONST_CS | CONST_PERSISTENT); |
Ðßíáêáò 33-6. Macros for Creating Constants
Macro | Description |
REGISTER_LONG_CONSTANT(name, value, flags) REGISTER_MAIN_LONG_CONSTANT(name, value, flags) | Registers a new constant of type long. |
REGISTER_DOUBLE_CONSTANT(name, value, flags) REGISTER_MAIN_DOUBLE_CONSTANT(name, value, flags) | Registers a new constant of type double. |
REGISTER_STRING_CONSTANT(name, value, flags) REGISTER_MAIN_STRING_CONSTANT(name, value, flags) | Registers a new constant of type string. The specified string must reside in Zend's internal memory. |
REGISTER_STRINGL_CONSTANT(name, value, length, flags) REGISTER_MAIN_STRINGL_CONSTANT(name, value, length, flags) | Registers a new constant of type string. The string length is explicitly set to length. The specified string must reside in Zend's internal memory. |
Sooner or later, you may need to assign the contents of one zval container to another. This is easier said than done, since the zval container doesn't contain only type information, but also references to places in Zend's internal data. For example, depending on their size, arrays and objects may be nested with lots of hash table entries. By assigning one zval to another, you avoid duplicating the hash table entries, using only a reference to them (at most).
To copy this complex kind of data, use the copy constructor. Copy constructors are typically defined in languages that support operator overloading, with the express purpose of copying complex types. If you define an object in such a language, you have the possibility of overloading the "=" operator, which is usually responsible for assigning the contents of the lvalue (result of the evaluation of the left side of the operator) to the rvalue (same for the right side).
Overloading means assigning a different meaning to this operator, and is usually used to assign a function call to an operator. Whenever this operator would be used on such an object in a program, this function would be called with the lvalue and rvalue as parameters. Equipped with that information, it can perform the operation it intends the "=" operator to have (usually an extended form of copying).
This same form of "extended copying" is also necessary for PHP's zval containers. Again, in the case of an array, this extended copying would imply re-creation of all hash table entries relating to this array. For strings, proper memory allocation would have to be assured, and so on.
Zend ships with such a function, called zend_copy_ctor() (the previous PHP equivalent was pval_copy_constructor()).
A most useful demonstration is a function that accepts a complex type as argument, modifies it, and then returns the argument:
zval *parameter; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meter) == FAILURE) return; } // do modifications to the parameter here // now we want to return the modified container: *return_value == *parameter; zval_copy_ctor(return_value); |
The first part of the function is plain-vanilla argument retrieval. After the (left out) modifications, however, it gets interesting: The container of parameter is assigned to the (predefined) return_value container. Now, in order to effectively duplicate its contents, the copy constructor is called. The copy constructor works directly with the supplied argument, and the standard return values are FAILURE on failure and SUCCESS on success.
If you omit the call to the copy constructor in this example, both parameter and return_value would point to the same internal data, meaning that return_value would be an illegal additional reference to the same data structures. Whenever changes occurred in the data that parameter points to, return_value might be affected. Thus, in order to create separate copies, the copy constructor must be used.
The copy constructor's counterpart in the Zend API, the destructor zval_dtor(), does the opposite of the constructor.
Returning values from your functions to PHP was described briefly in an earlier section; this section gives the details. Return values are passed via the return_value variable, which is passed to your functions as argument. The return_value argument consists of a zval container (see the earlier discussion of the call interface) that you can freely modify. The container itself is already allocated, so you don't have to run MAKE_STD_ZVAL on it. Instead, you can access its members directly.
To make returning values from functions easier and to prevent hassles with accessing the internal structures of the zval container, a set of predefined macros is available (as usual). These macros automatically set the correspondent type and value, as described in Ðßíáêáò 35-1 and Ðßíáêáò 35-2.
Óçìåßùóç: The macros in Ðßíáêáò 35-1 automatically return from your function, those in Ðßíáêáò 35-2 only set the return value; they don't return from your function.
Ðßíáêáò 35-1. Predefined Macros for Returning Values from a Function
Macro | Description |
RETURN_RESOURCE(resource) | Returns a resource. |
RETURN_BOOL(bool) | Returns a Boolean. |
RETURN_NULL() | Returns nothing (a NULL value). |
RETURN_LONG(long) | Returns a long. |
RETURN_DOUBLE(double) | Returns a double. |
RETURN_STRING(string, duplicate) | Returns a string. The duplicate flag indicates whether the string should be duplicated using estrdup(). |
RETURN_STRINGL(string, length, duplicate) | Returns a string of the specified length; otherwise, behaves like RETURN_STRING. This macro is faster and binary-safe, however. |
RETURN_EMPTY_STRING() | Returns an empty string. |
RETURN_FALSE | Returns Boolean false. |
RETURN_TRUE | Returns Boolean true. |
Ðßíáêáò 35-2. Predefined Macros for Setting the Return Value of a Function
Macro | Description |
RETVAL_RESOURCE(resource) | Sets the return value to the specified resource. |
RETVAL_BOOL(bool) | Sets the return value to the specified Boolean value. |
RETVAL_NULL | Sets the return value to NULL. |
RETVAL_LONG(long) | Sets the return value to the specified long. |
RETVAL_DOUBLE(double) | Sets the return value to the specified double. |
RETVAL_STRING(string, duplicate) | Sets the return value to the specified string and duplicates it to Zend internal memory if desired (see also RETURN_STRING). |
RETVAL_STRINGL(string, length, duplicate) | Sets the return value to the specified string and forces the length to become length (see also RETVAL_STRING). This macro is faster and binary-safe, and should be used whenever the string length is known. |
RETVAL_EMPTY_STRING | Sets the return value to an empty string. |
RETVAL_FALSE | Sets the return value to Boolean false. |
RETVAL_TRUE | Sets the return value to Boolean true. |
Complex types such as arrays and objects can be returned by using array_init() and object_init(), as well as the corresponding hash functions on return_value. Since these types cannot be constructed of trivial information, there are no predefined macros for them.
Often it's necessary to print messages to the output stream from your module, just as print() would be used within a script. PHP offers functions for most generic tasks, such as printing warning messages, generating output for phpinfo(), and so on. The following sections provide more details. Examples of these functions can be found on the CD-ROM.
zend_printf() works like the standard printf(), except that it prints to Zend's output stream.
zend_error() can be used to generate error messages. This function accepts two arguments; the first is the error type (see zend_errors.h), and the second is the error message.
zend_error(E_WARNING, "This function has been called with empty arguments"); |
Ðßíáêáò 36-1. Zend's Predefined Error Messages.
Error | Description |
E_ERROR | Signals an error and terminates execution of the script immediately . |
E_WARNING | Signals a generic warning. Execution continues. |
E_PARSE | Signals a parser error. Execution continues. |
E_NOTICE | Signals a notice. Execution continues. Note that by default the display of this type of error messages is turned off in php.ini. |
E_CORE_ERROR | Internal error by the core; shouldn't be used by user-written modules. |
E_COMPILE_ERROR | Internal error by the compiler; shouldn't be used by user-written modules. |
E_COMPILE_WARNING | Internal warning by the compiler; shouldn't be used by user-written modules. |
After creating a real module, you'll want to show information about the module in phpinfo() (in addition to the module name, which appears in the module list by default). PHP allows you to create your own section in the phpinfo() output with the ZEND_MINFO() function. This function should be placed in the module descriptor block (discussed earlier) and is always called whenever a script calls phpinfo().
PHP automatically prints a section in phpinfo() for you if you specify the ZEND_MINFO function, including the module name in the heading. Everything else must be formatted and printed by you.
Typically, you can print an HTML table header using php_info_print_table_start() and then use the standard functions php_info_print_table_header() and php_info_print_table_row(). As arguments, both take the number of columns (as integers) and the column contents (as strings). ÐáñÜäåéãìá 36-1 shows a source example and its output. To print the table footer, use php_info_print_table_end().
ÐáñÜäåéãìá 36-1. Source code and screenshot for output in phpinfo().
|
You can also print execution information, such as the current file being executed. The name of the function currently being executed can be retrieved using the function get_active_function_name(). This function returns a pointer to the function name and doesn't accept any arguments. To retrieve the name of the file currently being executed, use zend_get_executed_filename(). This function accesses the executor globals, which are passed to it using the TSRMLS_C macro. The executor globals are automatically available to every function that's called directly by Zend (they're part of the INTERNAL_FUNCTION_PARAMETERS described earlier in this chapter). If you want to access the executor globals in another function that doesn't have them available automatically, call the macro TSRMLS_FETCH() once in that function; this will introduce them to your local scope.
Finally, the line number currently being executed can be retrieved using the function zend_get_executed_lineno(). This function also requires the executor globals as arguments. For examples of these functions, see ÐáñÜäåéãìá 36-2.
ÐáñÜäåéãìá 36-2. Printing execution information.
|
Startup and shutdown functions can be used for one-time initialization and deinitialization of your modules. As discussed earlier in this chapter (see the description of the Zend module descriptor block), there are module, and request startup and shutdown events.
The module startup and shutdown functions are called whenever a module is loaded and needs initialization; the request startup and shutdown functions are called every time a request is processed (meaning that a file is being executed).
For dynamic extensions, module and request startup/shutdown events happen at the same time.
Declaration and implementation of these functions can be done with macros; see the earlier section "Declaration of the Zend Module Block" for details.
You can call user functions from your own modules, which is very handy when implementing callbacks; for example, for array walking, searching, or simply for event-based programs.
User functions can be called with the function call_user_function_ex(). It requires a hash value for the function table you want to access, a pointer to an object (if you want to call a method), the function name, return value, number of arguments, argument array, and a flag indicating whether you want to perform zval separation.
ZEND_API int call_user_function_ex(HashTable *function_table, zval *object, zval *function_name, zval **retval_ptr_ptr, int param_count, zval **params[], int no_separation); |
Note that you don't have to specify both function_table and object; either will do. If you want to call a method, you have to supply the object that contains this method, in which case call_user_function()automatically sets the function table to this object's function table. Otherwise, you only need to specify function_table and can set object to NULL.
Usually, the default function table is the "root" function table containing all function entries. This function table is part of the compiler globals and can be accessed using the macro CG. To introduce the compiler globals to your function, call the macro TSRMLS_FETCH once.
The function name is specified in a zval container. This might be a bit surprising at first, but is quite a logical step, since most of the time you'll accept function names as parameters from calling functions within your script, which in turn are contained in zval containers again. Thus, you only have to pass your arguments through to this function. This zval must be of type IS_STRING.
The next argument consists of a pointer to the return value. You don't have to allocate memory for this container; the function will do so by itself. However, you have to destroy this container (using zval_dtor()) afterward!
Next is the parameter count as integer and an array containing all necessary parameters. The last argument specifies whether the function should perform zval separation - this should always be set to 0. If set to 1, the function consumes less memory but fails if any of the parameters need separation.
ÐáñÜäåéãìá 38-1 shows a small demonstration of calling a user function. The code calls a function that's supplied to it as argument and directly passes this function's return value through as its own return value. Note the use of the constructor and destructor calls at the end - it might not be necessary to do it this way here (since they should be separate values, the assignment might be safe), but this is bulletproof.
ÐáñÜäåéãìá 38-1. Calling user functions.
|
<?php dl("call_userland.so"); function test_function() { print("We are in the test function!<br>"); return("hello"); } $return_value = call_userland("test_function"); print("Return value: \"$return_value\"<br>"); ?> |
PHP 4 features a redesigned initialization file support. It's now possible to specify default initialization entries directly in your code, read and change these values at runtime, and create message handlers for change notifications.
To create an .ini section in your own module, use the macros PHP_INI_BEGIN() to mark the beginning of such a section and PHP_INI_END() to mark its end. In between you can use PHP_INI_ENTRY() to create entries.
PHP_INI_BEGIN() PHP_INI_ENTRY("first_ini_entry", "has_string_value", PHP_INI_ALL, NULL) PHP_INI_ENTRY("second_ini_entry", "2", PHP_INI_SYSTEM, OnChangeSecond) PHP_INI_ENTRY("third_ini_entry", "xyz", PHP_INI_USER, NULL) PHP_INI_END() |
The permissions are grouped into three sections:PHP_INI_SYSTEM allows a change only directly in the php.ini file; PHP_INI_USER allows a change to be overridden by a user at runtime using additional configuration files, such as .htaccess; and PHP_INI_ALL allows changes to be made without restrictions. There's also a fourth level, PHP_INI_PERDIR, for which we couldn't verify its behavior yet.
The fourth parameter consists of a pointer to a change-notification handler. Whenever one of these initialization entries is changed, this handler is called. Such a handler can be declared using the PHP_INI_MH macro:
PHP_INI_MH(OnChangeSecond); // handler for ini-entry "second_ini_entry" // specify ini-entries here PHP_INI_MH(OnChangeSecond) { zend_printf("Message caught, our ini entry has been changed to %s<br>", new_value); return(SUCCESS); } |
#define PHP_INI_MH(name) int name(php_ini_entry *entry, char *new_value, uint new_value_length, void *mh_arg1, void *mh_arg2, void *mh_arg3) |
The change-notification handlers should be used to cache initialization entries locally for faster access or to perform certain tasks that are required if a value changes. For example, if a constant connection to a certain host is required by a module and someone changes the hostname, automatically terminate the old connection and attempt a new one.
Access to initialization entries can also be handled with the macros shown in Ðßíáêáò 39-1.
Ðßíáêáò 39-1. Macros to Access Initialization Entries in PHP
Macro | Description |
INI_INT(name) | Returns the current value of entry name as integer (long). |
INI_FLT(name) | Returns the current value of entry name as float (double). |
INI_STR(name) | Returns the current value of entry name as string. Note: This string is not duplicated, but instead points to internal data. Further access requires duplication to local memory. |
INI_BOOL(name) | Returns the current value of entry name as Boolean (defined as zend_bool, which currently means unsigned char). |
INI_ORIG_INT(name) | Returns the original value of entry name as integer (long). |
INI_ORIG_FLT(name) | Returns the original value of entry name as float (double). |
INI_ORIG_STR(name) | Returns the original value of entry name as string. Note: This string is not duplicated, but instead points to internal data. Further access requires duplication to local memory. |
INI_ORIG_BOOL(name) | Returns the original value of entry name as Boolean (defined as zend_bool, which currently means unsigned char). |
Finally, you have to introduce your initialization entries to PHP. This can be done in the module startup and shutdown functions, using the macros REGISTER_INI_ENTRIES() and UNREGISTER_INI_ENTRIES():
ZEND_MINIT_FUNCTION(mymodule) { REGISTER_INI_ENTRIES(); } ZEND_MSHUTDOWN_FUNCTION(mymodule) { UNREGISTER_INI_ENTRIES(); } |
You've learned a lot about PHP. You now know how to create dynamic loadable modules and statically linked extensions. You've learned how PHP and Zend deal with internal storage of variables and how you can create and access these variables. You know quite a set of tool functions that do a lot of routine tasks such as printing informational texts, automatically introducing variables to the symbol table, and so on.
Even though this chapter often had a mostly "referential" character, we hope that it gave you insight on how to start writing your own extensions. For the sake of space, we had to leave out a lot; we suggest that you take the time to study the header files and some modules (especially the ones in the ext/standard directory and the MySQL module, as these implement commonly known functionality). This will give you an idea of how other people have used the API functions - particularly those that didn't make it into this chapter.
The file config.m4 is processed by buildconf and must contain all the instructions to be executed during configuration. For example, these can include tests for required external files, such as header files, libraries, and so on. PHP defines a set of macros that can be used in this process, the most useful of which are described in Ðßíáêáò 41-1.
Ðßíáêáò 41-1. M4 Macros for config.m4
Macro | Description |
AC_MSG_CHECKING(message) | Prints a "checking <message>" text during configure. |
AC_MSG_RESULT(value) | Gives the result to AC_MSG_CHECKING; should specify either yes or no as value. |
AC_MSG_ERROR(message) | Prints message as error message during configure and aborts the script. |
AC_DEFINE(name,value,description) | Adds #define to php_config.h with the value of value and a comment that says description (this is useful for conditional compilation of your module). |
AC_ADD_INCLUDE(path) | Adds a compiler include path; for example, used if the module needs to add search paths for header files. |
AC_ADD_LIBRARY_WITH_PATH(libraryname,librarypath) | Specifies an additional library to link. |
AC_ARG_WITH(modulename,description,unconditionaltest,conditionaltest) | Quite a powerful macro, adding the module with description to the configure --help output. PHP checks whether the option --with-<modulename> is given to the configure script. If so, it runs the script unconditionaltest (for example, --with-myext=yes), in which case the value of the option is contained in the variable $withval. Otherwise, it executes conditionaltest. |
PHP_EXTENSION(modulename, [shared]) | This macro is a must to call for PHP to configure your extension. You can supply a second argument in addition to your module name, indicating whether you intend compilation as a shared module. This will result in a definition at compile time for your source as COMPILE_DL_<modulename>. |
A set of macros was introduced into Zend's API that simplify access to zval containers (see Ðßíáêáò 42-1).
Ðßíáêáò 42-1. API Macros for Accessing zval Containers
Macro | Refers to |
Z_LVAL(zval) | (zval).value.lval |
Z_DVAL(zval) | (zval).value.dval |
Z_STRVAL(zval) | (zval).value.str.val |
Z_STRLEN(zval) | (zval).value.str.len |
Z_ARRVAL(zval) | (zval).value.ht |
Z_LVAL_P(zval) | (*zval).value.lval |
Z_DVAL_P(zval) | (*zval).value.dval |
Z_STRVAL_P(zval_p) | (*zval).value.str.val |
Z_STRLEN_P(zval_p) | (*zval).value.str.len |
Z_ARRVAL_P(zval_p) | (*zval).value.ht |
Z_LVAL_PP(zval_pp) | (**zval).value.lval |
Z_DVAL_PP(zval_pp) | (**zval).value.dval |
Z_STRVAL_PP(zval_pp) | (**zval).value.str.val |
Z_STRLEN_PP(zval_pp) | (**zval).value.str.len |
Z_ARRVAL_PP(zval_pp) | (**zval).value.ht |
The PHP Streams API introduces a unified approach to the handling of files and sockets in PHP extension. Using a single API with standard functions for common operations, the streams API allows your extension to access files, sockets, URLs, memory and script-defined objects. Streams is a run-time extensible API that allows dynamically loaded modules (and scripts!) to register new streams.
The aim of the Streams API is to make it comfortable for developers to open files, URLs and other streamable data sources with a unified API that is easy to understand. The API is more or less based on the ANSI C stdio family of functions (with identical semantics for most of the main functions), so C programmers will have a feeling of familiarity with streams.
The streams API operates on a couple of different levels: at the base level, the API defines php_stream objects to represent streamable data sources. On a slightly higher level, the API defines php_stream_wrapper objects which "wrap" around the lower level API to provide support for retrieving data and meta-data from URLs. An additional context parameter, accepted by most stream creation functions, is passed to the wrapper's stream_opener method to fine-tune the behavior of the wrapper.
Any stream, once opened, can also have any number of filters applied to it, which process data as it is read from/written to the stream.
Streams can be cast (converted) into other types of file-handles, so that they can be used with third-party libraries without a great deal of trouble. This allows those libraries to access data directly from URL sources. If your system has the fopencookie() or funopen() function, you can even pass any PHP stream to any library that uses ANSI stdio!
Óçìåßùóç: The functions in this chapter are for use in the PHP source code and are not PHP functions. Userland stream functions can be found in the Stream Reference.
Using streams is very much like using ANSI stdio functions. The main difference is in how you obtain the stream handle to begin with. In most cases, you will use php_stream_open_wrapper() to obtain the stream handle. This function works very much like fopen, as can be seen from the example below:
ÐáñÜäåéãìá 43-1. simple stream example that displays the PHP home page
|
The table below shows the Streams equivalents of the more common ANSI stdio functions. Unless noted otherwise, the semantics of the functions are identical.
Ðßíáêáò 43-1. ANSI stdio equivalent functions in the Streams API
ANSI Stdio Function | PHP Streams Function | Notes |
---|---|---|
fopen | php_stream_open_wrapper | Streams includes additional parameters |
fclose | php_stream_close | |
fgets | php_stream_gets | |
fread | php_stream_read | The nmemb parameter is assumed to have a value of 1, so the prototype looks more like read(2) |
fwrite | php_stream_write | The nmemb parameter is assumed to have a value of 1, so the prototype looks more like write(2) |
fseek | php_stream_seek | |
ftell | php_stream_tell | |
rewind | php_stream_rewind | |
feof | php_stream_eof | |
fgetc | php_stream_getc | |
fputc | php_stream_putc | |
fflush | php_stream_flush | |
puts | php_stream_puts | Same semantics as puts, NOT fputs |
fstat | php_stream_stat | Streams has a richer stat structure |
All streams are registered as resources when they are created. This ensures that they will be properly cleaned up even if there is some fatal error. All of the filesystem functions in PHP operate on streams resources - that means that your extensions can accept regular PHP file pointers as parameters to, and return streams from their functions. The streams API makes this process as painless as possible:
ÐáñÜäåéãìá 43-2. How to accept a stream as a parameter
|
ÐáñÜäåéãìá 43-3. How to return a stream from a function
|
Since streams are automatically cleaned up, it's tempting to think that we can get away with being sloppy programmers and not bother to close the streams when we are done with them. Although such an approach might work, it is not a good idea for a number of reasons: streams hold locks on system resources while they are open, so leaving a file open after you have finished with it could prevent other processes from accessing it. If a script deals with a large number of files, the accumulation of the resources used, both in terms of memory and the sheer number of open files, can cause web server requests to fail. Sounds bad, doesn't it? The streams API includes some magic that helps you to keep your code clean - if a stream is not closed by your code when it should be, you will find some helpful debugging information in you web server error log.
Óçìåßùóç: Always use a debug build of PHP when developing an extension (--enable-debug when running configure), as a lot of effort has been made to warn you about memory and stream leaks.
In some cases, it is useful to keep a stream open for the duration of a request, to act as a log or trace file for example. Writing the code to safely clean up such a stream is not difficult, but it's several lines of code that are not strictly needed. To save yourself the trouble of writing the code, you can mark a stream as being OK for auto cleanup. What this means is that the streams API will not emit a warning when it is time to auto-cleanup a stream. To do this, you can use php_stream_auto_cleanup().
(no version information, might be only in CVS)
php_stream_stat_path -- Gets the status for a file or URLphp_stream_stat_path() examines the file or URL specified by path and returns information such as file size, access and creation times and so on. The return value is 0 on success, -1 on error. For more information about the information returned, see php_stream_statbuf.
(no version information, might be only in CVS)
php_stream_stat -- Gets the status for the underlying storage associated with a streamphp_stream_stat() examines the storage to which stream is bound, and returns information such as file size, access and creation times and so on. The return value is 0 on success, -1 on error. For more information about the information returned, see php_stream_statbuf.
(no version information, might be only in CVS)
php_stream_open_wrapper -- Opens a stream on a file or URLphp_stream_open_wrapper() opens a stream on the file, URL or other wrapped resource specified by path. Depending on the value of mode, the stream may be opened for reading, writing, appending or combinations of those. See the table below for the different modes that can be used; in addition to the characters listed below, you may include the character 'b' either as the second or last character in the mode string. The presence of the 'b' character informs the relevant stream implementation to open the stream in a binary safe mode.
The 'b' character is ignored on all POSIX conforming systems which treat binary and text files in the same way. It is a good idea to specify the 'b' character whenever your stream is accessing data where the full 8 bits are important, so that your code will work when compiled on a system where the 'b' flag is important.
Any local files created by the streams API will have their initial permissions set according to the operating system defaults - under Unix based systems this means that the umask of the process will be used. Under Windows, the file will be owned by the creating process. Any remote files will be created according to the URL wrapper that was used to open the file, and the credentials supplied to the remote server.
Open text file for reading. The stream is positioned at the beginning of the file.
Open text file for reading and writing. The stream is positioned at the beginning of the file.
Truncate the file to zero length or create text file for writing. The stream is positioned at the beginning of the file.
Open text file for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file.
Open text file for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file.
options affects how the path/URL of the stream is interpreted, safe mode checks and actions taken if there is an error during opening of the stream. See Stream open options for more information about options.
If opened is not NULL, it will be set to a string containing the name of the actual file/resource that was opened. This is important when the options include USE_PATH, which causes the include_path to be searched for the file. You, the caller, are responsible for calling efree() on the filename returned in this parameter.
Óçìåßùóç: If you specified STREAM_MUST_SEEK in options, the path returned in opened may not be the name of the actual stream that was returned to you. It will, however, be the name of the original resource from which the seekable stream was manufactured.
(no version information, might be only in CVS)
php_stream_read -- Read a number of bytes from a stream into a bufferphp_stream_read() reads up to count bytes of data from stream and copies them into the buffer buf.
php_stream_read() returns the number of bytes that were read successfully. There is no distinction between a failed read or an end-of-file condition - use php_stream_eof() to test for an EOF.
The internal position of the stream is advanced by the number of bytes that were read, so that subsequent reads will continue reading from that point.
If less than count bytes are available to be read, this call will block (or wait) until the required number are available, depending on the blocking status of the stream. By default, a stream is opened in blocking mode. When reading from regular files, the blocking mode will not usually make any difference: when the stream reaches the EOF php_stream_read() will return a value less than count, and 0 on subsequent reads.
(no version information, might be only in CVS)
php_stream_write -- Write a number of bytes from a buffer to a streamphp_stream_write() writes count bytes of data from buf into stream.
php_stream_write() returns the number of bytes that were written successfully. If there was an error, the number of bytes written will be less than count.
The internal position of the stream is advanced by the number of bytes that were written, so that subsequent writes will continue writing from that point.
(no version information, might be only in CVS)
php_stream_eof -- Check for an end-of-file condition on a streamphp_stream_eof() checks for an end-of-file condition on stream.
php_stream_eof() returns the 1 to indicate EOF, 0 if there is no EOF and -1 to indicate an error.
php_stream_getc() reads a single character from stream and returns it as an unsigned char cast as an int, or EOF if the end-of-file is reached, or an error occurred.
php_stream_getc() may block in the same way as php_stream_read() blocks.
The internal position of the stream is advanced by 1 if successful.
(no version information, might be only in CVS)
php_stream_gets -- Read a line of data from a stream into a bufferphp_stream_gets() reads up to count-1 bytes of data from stream and copies them into the buffer buf. Reading stops after an EOF or a newline. If a newline is read, it is stored in buf as part of the returned data. A NUL terminating character is stored as the last character in the buffer.
php_stream_read() returns buf when successful or NULL otherwise.
The internal position of the stream is advanced by the number of bytes that were read, so that subsequent reads will continue reading from that point.
This function may block in the same way as php_stream_read().
php_stream_close() safely closes stream and releases the resources associated with it. After stream has been closed, it's value is undefined and should not be used.
php_stream_close() returns 0 if the stream was closed or EOF to indicate an error. Regardless of the success of the call, stream is undefined and should not be used after a call to this function.
php_stream_flush() causes any data held in write buffers in stream to be committed to the underlying storage.
php_stream_flush() returns 0 if the buffers were flushed, or if the buffers did not need to be flushed, but returns EOF to indicate an error.
php_stream_seek() repositions the internal position of stream. The new position is determined by adding the offset to the position indicated by whence. If whence is set to SEEK_SET, SEEK_CUR or SEEK_END the offset is relative to the start of the stream, the current position or the end of the stream, respectively.
php_stream_seek() returns 0 on success, but -1 if there was an error.
Óçìåßùóç: Not all streams support seeking, although the streams API will emulate a seek if whence is set to SEEK_CUR and offset is positive, by calling php_stream_read() to read (and discard) offset bytes.
The emulation is only applied when the underlying stream implementation does not support seeking. If the stream is (for example) a file based stream that is wrapping a non-seekable pipe, the streams api will not apply emulation because the file based stream implements a seek operation; the seek will fail and an error result will be returned to the caller.
php_stream_tell() returns the internal position of stream, relative to the start of the stream. If there is an error, -1 is returned.
(no version information, might be only in CVS)
php_stream_copy_to_stream -- Copy data from one stream to anotherphp_stream_copy_to_stream() attempts to read up to maxlen bytes of data from src and write them to dest, and returns the number of bytes that were successfully copied.
If you want to copy all remaining data from the src stream, pass the constant PHP_STREAM_COPY_ALL as the value of maxlen.
Óçìåßùóç: This function will attempt to copy the data in the most efficient manner, using memory mapped files when possible.
(no version information, might be only in CVS)
php_stream_copy_to_mem -- Copy data from stream and into an allocated bufferphp_stream_copy_to_mem() allocates a buffer maxlen+1 bytes in length using pemalloc() (passing persistent). It then reads maxlen bytes from src and stores them in the allocated buffer.
The allocated buffer is returned in buf, and the number of bytes successfully read. You, the caller, are responsible for freeing the buffer by passing it and persistent to pefree().
If you want to copy all remaining data from the src stream, pass the constant PHP_STREAM_COPY_ALL as the value of maxlen.
Óçìåßùóç: This function will attempt to copy the data in the most efficient manner, using memory mapped files when possible.
(no version information, might be only in CVS)
php_stream_make_seekable -- Convert a stream into a stream is seekablephp_stream_make_seekable() checks if origstream is seekable. If it is not, it will copy the data into a new temporary stream. If successful, newstream is always set to the stream that is valid to use, even if the original stream was seekable.
flags allows you to specify your preference for the seekable stream that is returned: use PHP_STREAM_NO_PREFERENCE to use the default seekable stream (which uses a dynamically expanding memory buffer, but switches to temporary file backed storage when the stream size becomes large), or use PHP_STREAM_PREFER_STDIO to use "regular" temporary file backed storage.
Ðßíáêáò 43-1. php_stream_make_seekable() return values
Value | Meaning |
---|---|
PHP_STREAM_UNCHANGED | Original stream was seekable anyway. newstream is set to the value of origstream. |
PHP_STREAM_RELEASED | Original stream was not seekable and has been released. newstream is set to the new seekable stream. You should not access origstream anymore. |
PHP_STREAM_FAILED | An error occurred while attempting conversion. newstream is set to NULL; origstream is still valid. |
PHP_STREAM_CRITICAL | An error occurred while attempting conversion that has left origstream in an indeterminate state. newstream is set to NULL and it is highly recommended that you close origstream. |
Óçìåßùóç: If you need to seek and write to the stream, it does not make sense to use this function, because the stream it returns is not guaranteed to be bound to the same resource as the original stream.
Óçìåßùóç: If you only need to seek forwards, there is no need to call this function, as the streams API will emulate forward seeks when the whence parameter is SEEK_CUR.
Óçìåßùóç: If origstream is network based, this function will block until the whole contents have been downloaded.
Óçìåßùóç: NEVER call this function with an origstream that is reference by a file pointer in a PHP script! This function may cause the underlying stream to be closed which could cause a crash when the script next accesses the file pointer!
Óçìåßùóç: In many cases, this function can only succeed when origstream is a newly opened stream with no data buffered in the stream layer. For that reason, and because this function is complicated to use correctly, it is recommended that you use php_stream_open_wrapper() and pass in PHP_STREAM_MUST_SEEK in your options instead of calling this function directly.
(no version information, might be only in CVS)
php_stream_cast -- Convert a stream into another form, such as a FILE* or socketphp_stream_cast() attempts to convert stream into a resource indicated by castas. If ret is NULL, the stream is queried to find out if such a conversion is possible, without actually performing the conversion (however, some internal stream state *might* be changed in this case). If flags is set to REPORT_ERRORS, an error message will be displayed is there is an error during conversion.
Óçìåßùóç: This function returns SUCCESS for success or FAILURE for failure. Be warned that you must explicitly compare the return value with SUCCESS or FAILURE because of the underlying values of those constants. A simple boolean expression will not be interpreted as you intended.
Ðßíáêáò 43-1. Resource types for castas
Value | Meaning |
---|---|
PHP_STREAM_AS_STDIO | Requests an ANSI FILE* that represents the stream |
PHP_STREAM_AS_FD | Requests a POSIX file descriptor that represents the stream |
PHP_STREAM_AS_SOCKETD | Requests a network socket descriptor that represents the stream |
In addition to the basic resource types above, the conversion process can be altered by using the following flags by using the OR operator to combine the resource type with one or more of the following values:
Ðßíáêáò 43-2. Resource types for castas
Value | Meaning |
---|---|
PHP_STREAM_CAST_TRY_HARD | Tries as hard as possible, at the expense of additional resources, to ensure that the conversion succeeds |
PHP_STREAM_CAST_RELEASE | Informs the streams API that some other code (possibly a third party library) will be responsible for closing the underlying handle/resource. This causes the stream to be closed in such a way the underlying handle is preserved and returned in ret. If this function succeeds, stream should be considered closed and should no longer be used. |
Óçìåßùóç: If your system supports fopencookie() (systems using glibc 2 or later), the streams API will always be able to synthesize an ANSI FILE* pointer over any stream. While this is tremendously useful for passing any PHP stream to any third-party libraries, such behaviour is not portable. You are requested to consider the portability implications before distributing you extension. If the fopencookie synthesis is not desirable, you should query the stream to see if it naturally supports FILE* by using php_stream_is()
Óçìåßùóç: If you ask a socket based stream for a FILE*, the streams API will use fdopen() to create it for you. Be warned that doing so may cause data that was buffered in the streams layer to be lost if you intermix streams API calls with ANSI stdio calls.
See also php_stream_is() and php_stream_can_cast().
(no version information, might be only in CVS)
php_stream_can_cast -- Determines if a stream can be converted into another form, such as a FILE* or socketThis function is equivalent to calling php_stream_cast() with ret set to NULL and flags set to 0. It returns SUCCESS if the stream can be converted into the form requested, or FAILURE if the conversion cannot be performed.
Óçìåßùóç: Although this function will not perform the conversion, some internal stream state *might* be changed by this call.
Óçìåßùóç: You must explicitly compare the return value of this function with one of the constants, as described in php_stream_cast().
See also php_stream_cast() and php_stream_is().
(no version information, might be only in CVS)
php_stream_is_persistent -- Determines if a stream is a persistent streamphp_stream_is_persistent() returns 1 if the stream is a persistent stream, 0 otherwise.
(no version information, might be only in CVS)
php_stream_is -- Determines if a stream is of a particular typephp_stream_is() returns 1 if stream is of the type specified by istype, or 0 otherwise.
Ðßíáêáò 43-1. Values for istype
Value | Meaning |
---|---|
PHP_STREAM_IS_STDIO | The stream is implemented using the stdio implementation |
PHP_STREAM_IS_SOCKET | The stream is implemented using the network socket implementation |
PHP_STREAM_IS_USERSPACE | The stream is implemented using the userspace object implementation |
PHP_STREAM_IS_MEMORY | The stream is implemented using the grow-on-demand memory stream implementation |
Óçìåßùóç: The PHP_STREAM_IS_XXX "constants" are actually defined as pointers to the underlying stream operations structure. If your extension (or some other extension) defines additional streams, it should also declare a PHP_STREAM_IS_XXX constant in it's header file that you can use as the basis of this comparison.
Óçìåßùóç: This function is implemented as a simple (and fast) pointer comparison, and does not change the stream state in any way.
See also php_stream_cast() and php_stream_can_cast().
(no version information, might be only in CVS)
php_stream_passthru -- Outputs all remaining data from a streamphp_stream_passthru() outputs all remaining data from stream to the active output buffer and returns the number of bytes output. If buffering is disabled, the data is written straight to the output, which is the browser making the request in the case of PHP on a web server, or stdout for CLI based PHP. This function will use memory mapped files if possible to help improve performance.
(no version information, might be only in CVS)
php_register_url_stream_wrapper -- Registers a wrapper with the Streams APIphp_register_url_stream_wrapper() registers wrapper as the handler for the protocol specified by protocol.
Óçìåßùóç: If you call this function from a loadable module, you *MUST* call php_unregister_url_stream_wrapper() in your module shutdown function, otherwise PHP will crash.
(no version information, might be only in CVS)
php_unregister_url_stream_wrapper -- Unregisters a wrapper from the Streams APIphp_unregister_url_stream_wrapper() unregisters the wrapper associated with protocol.
(no version information, might be only in CVS)
php_stream_open_wrapper_ex -- Opens a stream on a file or URL, specifying contextphp_stream_open_wrapper_ex() is exactly like php_stream_open_wrapper(), but allows you to specify a php_stream_context object using context. To find out more about stream contexts, see XXX
(no version information, might be only in CVS)
php_stream_open_wrapper_as_file -- Opens a stream on a file or URL, and converts to a FILE*php_stream_open_wrapper_as_file() is exactly like php_stream_open_wrapper(), but converts the stream into an ANSI stdio FILE* and returns that instead of the stream. This is a convenient shortcut for extensions that pass FILE* to third-party libraries.
(no version information, might be only in CVS)
php_stream_filter_register_factory -- Registers a filter factory with the Streams APIUse this function to register a filter factory with the name given by filterpattern. filterpattern can be either a normal string name (i.e. myfilter) or a global pattern (i.e. myfilterclass.*) to allow a single filter to perform different operations depending on the exact name of the filter invoked (i.e. myfilterclass.foo, myfilterclass.bar, etc...)
Óçìåßùóç: Filters registered by a loadable extension must be certain to call php_stream_filter_unregister_factory() during MSHUTDOWN.
(no version information, might be only in CVS)
php_stream_filter_unregister_factory -- Deregisters a filter factory with the Streams APIDeregisters the filterfactory specified by the filterpattern making it no longer available for use.
Óçìåßùóç: Filters registered by a loadable extension must be certain to call php_stream_filter_unregister_factory() during MSHUTDOWN.
The functions listed in this section work on local files, as well as remote files (provided that the wrapper supports this functionality!).
(no version information, might be only in CVS)
php_stream_opendir -- Open a directory for file enumerationphp_stream_opendir() returns a stream that can be used to list the files that are contained in the directory specified by path. This function is functionally equivalent to POSIX opendir(). Although this function returns a php_stream object, it is not recommended to try to use the functions from the common API on these streams.
(no version information, might be only in CVS)
php_stream_readdir -- Fetch the next directory entry from an opened dirphp_stream_readdir() reads the next directory entry from dirstream and stores it into ent. If the function succeeds, the return value is ent. If the function fails, the return value is NULL. See php_stream_dirent for more details about the information returned for each directory entry.
(no version information, might be only in CVS)
php_stream_rewinddir -- Rewind a directory stream to the first entryphp_stream_rewinddir() rewinds a directory stream to the first entry. Returns 0 on success, but -1 on failure.
(no version information, might be only in CVS)
php_stream_fopen_from_file -- Convert an ANSI FILE* into a streamphp_stream_fopen_from_file() returns a stream based on the file. mode must be the same as the mode used to open file, otherwise strange errors may occur when trying to write when the mode of the stream is different from the mode on the file.
(no version information, might be only in CVS)
php_stream_fopen_tmpfile -- Open a FILE* with tmpfile() and convert into a streamphp_stream_fopen_from_file() returns a stream based on a temporary file opened with a mode of "w+b". The temporary file will be deleted automatically when the stream is closed or the process terminates.
(no version information, might be only in CVS)
php_stream_fopen_temporary_file -- Generate a temporary file name and open a stream on itphp_stream_fopen_temporary_file() generates a temporary file name in the directory specified by dir and with a prefix of pfx. The generated file name is returns in the opened parameter, which you are responsible for cleaning up using efree(). A stream is opened on that generated filename in "w+b" mode. The file is NOT automatically deleted; you are responsible for unlinking or moving the file when you have finished with it.
(no version information, might be only in CVS)
php_stream_sock_open_from_socket -- Convert a socket descriptor into a streamphp_stream_sock_open_from_socket() returns a stream based on the socket. persistent is a flag that controls whether the stream is opened as a persistent stream. Generally speaking, this parameter will usually be 0.
(no version information, might be only in CVS)
php_stream_sock_open_host -- Open a connection to a host and return a streamphp_stream_sock_open_host() establishes a connect to the specified host and port. socktype specifies the connection semantics that should apply to the connection. Values for socktype are system dependent, but will usually include (at a minimum) SOCK_STREAM for sequenced, reliable, two-way connection based streams (TCP), or SOCK_DGRAM for connectionless, unreliable messages of a fixed maximum length (UDP).
persistent is a flag the controls whether the stream is opened as a persistent stream. Generally speaking, this parameter will usually be 0.
If not NULL, timeout specifies a maximum time to allow for the connection to be made. If the connection attempt takes longer than the timeout value, the connection attempt is aborted and NULL is returned to indicate that the stream could not be opened.
Óçìåßùóç: The timeout value does not include the time taken to perform a DNS lookup. The reason for this is because there is no portable way to implement a non-blocking DNS lookup.
The timeout only applies to the connection phase; if you need to set timeouts for subsequent read or write operations, you should use php_stream_sock_set_timeout() to configure the timeout duration for your stream once it has been opened.
The streams API places no restrictions on the values you use for socktype, but encourages you to consider the portability of values you choose before you release your extension.
(no version information, might be only in CVS)
php_stream_sock_open_unix -- Open a Unix domain socket and convert into a streamphp_stream_sock_open_unix() attempts to open the Unix domain socket specified by path. pathlen specifies the length of path. If timeout is not NULL, it specifies a timeout period for the connection attempt. persistent indicates if the stream should be opened as a persistent stream. Generally speaking, this parameter will usually be 0.
Óçìåßùóç: This function will not work under Windows, which does not implement Unix domain sockets. A possible exception to this rule is if your PHP binary was built using cygwin. You are encouraged to consider this aspect of the portability of your extension before it's release.
Óçìåßùóç: This function treats path in a binary safe manner, suitable for use on systems with an abstract namespace (such as Linux), where the first character of path is a NUL character.
php_stream_dirent
char d_name[MAXPATHLEN] |
d_name holds the name of the file, relative to the directory being scanned.
typedef struct _php_stream_ops { /* all streams MUST implement these operations */ size_t (*write)(php_stream *stream, const char *buf, size_t count TSRMLS_DC); size_t (*read)(php_stream *stream, char *buf, size_t count TSRMLS_DC); int (*close)(php_stream *stream, int close_handle TSRMLS_DC); int (*flush)(php_stream *stream TSRMLS_DC); const char *label; /* name describing this class of stream */ /* these operations are optional, and may be set to NULL if the stream does not * support a particular operation */ int (*seek)(php_stream *stream, off_t offset, int whence TSRMLS_DC); char *(*gets)(php_stream *stream, char *buf, size_t size TSRMLS_DC); int (*cast)(php_stream *stream, int castas, void **ret TSRMLS_DC); int (*stat)(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC); } php_stream_ops; |
struct _php_stream_wrapper { php_stream_wrapper_ops *wops; /* operations the wrapper can perform */ void *abstract; /* context for the wrapper */ int is_url; /* so that PG(allow_url_fopen) can be respected */ /* support for wrappers to return (multiple) error messages to the stream opener */ int err_count; char **err_stack; } php_stream_wrapper; |
typedef struct _php_stream_wrapper_ops { /* open/create a wrapped stream */ php_stream *(*stream_opener)(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); /* close/destroy a wrapped stream */ int (*stream_closer)(php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC); /* stat a wrapped stream */ int (*stream_stat)(php_stream_wrapper *wrapper, php_stream *stream, php_stream_statbuf *ssb TSR$ /* stat a URL */ int (*url_stat)(php_stream_wrapper *wrapper, char *url, php_stream_statbuf *ssb TSRMLS_DC); /* open a "directory" stream */ php_stream *(*dir_opener)(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); const char *label; /* Delete/Unlink a file */ int (*unlink)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC); } php_stream_wrapper_ops; |
struct _php_stream_filter { php_stream_filter_ops *fops; void *abstract; /* for use by filter implementation */ php_stream_filter *next; php_stream_filter *prev; int is_persistent; /* link into stream and chain */ php_stream_filter_chain *chain; /* buffered buckets */ php_stream_bucket_brigade buffer; } php_stream_filter; |
typedef struct _php_stream_filter_ops { php_stream_filter_status_t (*filter)( php_stream *stream, php_stream_filter *thisfilter, php_stream_bucket_brigade *buckets_in, php_stream_bucket_brigade *buckets_out, size_t *bytes_consumed, int flags TSRMLS_DC); void (*dtor)(php_stream_filter *thisfilter TSRMLS_DC); const char *label; } php_stream_filter_ops; |
One or more of these values can be combined using the OR operator.
This is the default option for streams; it requests that the include_path is not to be searched for the requested file.
Requests that the include_path is to be searched for the requested file.
Requests that registered URL wrappers are to be ignored when opening the stream. Other non-URL wrappers will be taken into consideration when decoding the path. There is no opposite form for this flag; the streams API will use all registered wrappers by default.
On Windows systems, this is equivalent to IGNORE_URL. On all other systems, this flag has no effect.
Requests that the underlying stream implementation perform safe_mode checks on the file before opening the file. Omitting this flag will skip safe_mode checks and allow opening of any file that the PHP process has rights to access.
If this flag is set, and there was an error during the opening of the file or URL, the streams API will call the php_error function for you. This is useful because the path may contain username/password information that should not be displayed in the browser output (it would be a security risk to do so). When the streams API raises the error, it first strips username/password information from the path, making the error message safe to display in the browser.
This flag is useful when your extension really must be able to randomly seek around in a stream. Some streams may not be seekable in their native form, so this flag asks the streams API to check to see if the stream does support seeking. If it does not, it will copy the stream into temporary storage (which may be a temporary file or a memory stream) which does support seeking. Please note that this flag is not useful when you want to seek the stream and write to it, because the stream you are accessing might not be bound to the actual resource you requested.
Óçìåßùóç: If the requested resource is network based, this flag will cause the opener to block until the whole contents have been downloaded.
If your extension is using a third-party library that expects a FILE* or file descriptor, you can use this flag to request the streams API to open the resource but avoid buffering. You can then use php_stream_cast() to retrieve the FILE* or file descriptor that the library requires.
The is particularly useful when accessing HTTP URLs where the start of the actual stream data is found after an indeterminate offset into the stream.
Since this option disables buffering at the streams API level, you may experience lower performance when using streams functions on the stream; this is deemed acceptable because you have told streams that you will be using the functions to match the underlying stream implementation. Only use this option when you are sure you need it.
This section holds the most general questions about PHP: what it is and what it does.
From the preface of the manual:
PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.
A nice introduction to PHP by Stig Sæther Bakken can be found at http://www.zend.com/zend/art/intro.php on the Zend website. Also, much of the PHP Conference Material is freely available.
PHP stands for PHP: Hypertext Preprocessor. This confuses many people because the first word of the acronym is the acronym. This type of acronym is called a recursive acronym. The curious can visit Free On-Line Dictionary of Computing for more information on recursive acronyms.
PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3 is the successor to PHP/FI 2.0 and is a lot nicer. PHP 4 is the current generation of PHP, which uses the Zend engine under the hood. PHP 5 uses Zend engine 2 which, among other things, offers many additional OOP features. PHP 5 is experimental.
Yes. See the INSTALL file that is included in the PHP 4 source distribution. Also, read the related appendix.
There are a couple of articles written on this by the authors of PHP 4. Here's a list of some of the more important new features:
Extended API module
Generalized build process under Unix
Generic web server interface that also supports multi-threaded web servers
Improved syntax highlighter
Native HTTP session support
Output buffering support
More powerful configuration system
Reference counting
You should go to the PHP Bug Database and make sure the bug isn't a known bug. If you don't see it in the database, use the reporting form to report the bug. It is important to use the bug database instead of just sending an email to one of the mailing lists because the bug will have a tracking number assigned and it will then be possible for you to go back later and check on the status of the bug. The bug database can be found at http://bugs.php.net/.
This section holds questions about how to get in touch with the PHP community. The best way is the mailing lists.
Of course! There are many mailing lists for several subjects. A whole list of mailing lists can be found on our Support page.
The most general mailing list is php-general. To subscribe, send mail to php-general-subscribe@lists.php.net. You don't need to include anything special in the subject or body of the message. To unsubscribe, send mail to php-general-unsubscribe@lists.php.net.
You can also subscribe and unsubscribe using the web interface on our Support page.
There are countless of them around the world. We have links for example to some IRC servers and foreign language mailing lists on our Support page.
If you have problems subscribing to or unsubscribing from the php-general mailing list, it may be because the mailing list software can't figure out the correct mailing address to use. If your email address was joeblow@example.com, you can send your subscription request to php-general-subscribe-joeblow=example.com@lists.php.net, or your unsubscription request to php-general-unsubscribe-joeblow=example.com@lists.php.net. Use similar addresses for the other mailing lists.
Yes, you will find a list of archive sites on the Support page. The mailing list articles are also archived as news messages. You can access the news server at news://news.php.net/ with a news client. There is also an experimental web interface for the news server at http://news.php.net/
Since PHP is growing more and more popular by the day the traffic has increased on the php-general mailing list and as of now the list gets about 150 to 200 posts a day. Because of this it is in everyones interest that you use the list as a last resort when you have looked everywhere else.
Before you post to the list please have a look in this FAQ and the manual to see if you can find the help there. If there is nothing to be found there try out the mailing list archives (see above). If you're having problem with installing or configuring PHP please read through all included documentation and README's. If you still can't find any information that helps you out you're more than welcome to use the mailing list.
Before asking questions, you may want to read the paper on How To Ask Questions The Smart Way as this is a good idea for everyone.
Posts like "I can't get PHP up and running! Help me! What is wrong?" are of absolutely no use to anyone. If you're having problems getting PHP up and running you must include what operating system you are running on, what version of PHP you're trying to set up, how you got it (pre-compiled, CVS, RPMs and so on), what you have done so far, where you got stuck and the exact error message.
This goes for any other problem as well. You have to include information on what you have done, where you got stuck, what you're trying to do and, if applicable, exact error messages. If you're having problems with your source code you need to include the part of the code that isn't working. Do not include more code than necessary though! It makes the post hard to read and a lot of people might just skip it all together because of this. If you're unsure about how much information to include in the mail it's better that you include to much than to little.
Another important thing to remember is to summarize your problem on the subject line. A subject like "HELP MEEEE!!!" or "What is the problem here?" will be ignored by the majority of the readers.
And lastly, you're encouraged to read the paper on How To Ask Questions The Smart Way as this will be a great help for everyone, especially yourself.
This section has details about PHP download locations, and OS issues.
You can download PHP from any of the members of the PHP network of sites. These can be found at http://www.php.net/. You can also use anonymous CVS to get the absolute latest version of the source. For more information, go to http://www.php.net/anoncvs.php.
We only distribute precompiled binaries for Windows systems, as we are not able to compile PHP for every major Linux/Unix platform with every extension combination. Also note, that many Linux distributions come with PHP built in these days. Windows binaries can be downloaded from our Downloads page, for Linux binaries, please visit your distributions website.
Óçìåßùóç: Those marked with * are not thread-safe libraries, and should not be used with PHP as a server module in the multi-threaded Windows web servers (IIS, Netscape). This does not matter in Unix environments, yet.
LDAP (Unix/Win) : Netscape Directory (LDAP) SDK 1.1.
Berkeley DB2 (Unix/Win) : http://www.sleepycat.com/.
Sybase-CT* (Linux, libc5) : Available locally.
You will need to follow instructions provided with the library. Some of these libraries are detected automatically when you run the 'configure' script of PHP (such as the GD library), and others you will have to enable using '--with-EXTENSION' options to 'configure'. Run 'configure --help' for a listing of these.
5. I got the latest version of the PHP source code from the CVS repository on my Windows machine, what do I need to compile it?
First, you will need Microsoft Visual C++ v6 (v5 may do it also, but we do it with v6), and you will need some support files. See the manual section about building PHP from source on Windows.
You can find a browscap.ini file at http://www.garykeith.com/browsers/downloads.asp.
This section holds common questions about relation between PHP and databases. Yes, PHP can access virtually any database available today.
On Windows machines, you can simply use the included ODBC support and the correct ODBC driver.
On Unix machines, you can use the Sybase-CT driver to access Microsoft SQL Servers because they are (at least mostly) protocol-compatible. Sybase has made a free version of the necessary libraries for Linux systems. For other Unix operating systems, you need to contact Sybase for the correct libraries. Also see the answer to the next question.
Yes. You already have all the tools you need if you are running entirely under Windows 9x/Me, or NT/2000, where you can use ODBC and Microsoft's ODBC drivers for Microsoft Access databases.
If you are running PHP on a Unix box and want to talk to MS Access on a Windows box you will need Unix ODBC drivers. OpenLink Software has Unix-based ODBC drivers that can do this. There is a free pilot program where you can download an evaluation copy that doesn't expire and prices start at $675 for the commercial supported version.
Another alternative is to use an SQL server that has Windows ODBC drivers and use that to store the data, which you can then access from Microsoft Access (using ODBC) and PHP (using the built in drivers), or to use an intermediary file format that Access and PHP both understand, such as flat files or dBase databases. On this point Tim Hayes from OpenLink software writes:
Using another database as an intermediary is not a good idea, when you can use ODBC from PHP straight to your database - i.e. with OpenLink's drivers. If you do need to use an intermediary file format, OpenLink have now released Virtuoso (a virtual database engine) for NT, Linux and other Unix platforms. Please visit our website for a free download.
One option that has proved successful is to use MySQL and its MyODBC drivers on Windows and synchronizing the databases. Steve Lawrence writes:
Install MySQL on your platform according to instructions with MySQL. Latest available from www.mysql.com (get it from your mirror!). No special configuration required except when you set up a database, and configure the user account, you should put % in the host field, or the host name of the Windows computer you wish to access MySQL with. Make a note of your server name, username, and password.
Download the MyODBC for Windows driver from the MySQL site. Latest release is myodbc-2_50_19-win95.zip (NT available too, as well as source code). Install it on your Windows machine. You can test the operation with the utilities included with this program.
Create a user or system dsn in your ODBC administrator, located in the control panel. Make up a dsn name, enter your hostname, user name, password, port, etc for you MySQL database configured in step 1.
Install Access with a full install, this makes sure you get the proper add-ins.. at the least you will need ODBC support and the linked table manager.
Now the fun part! Create a new access database. In the table window right click and select Link Tables, or under the file menu option, select Get External Data and then Link Tables. When the file browser box comes up, select files of type: ODBC. Select System dsn and the name of your dsn created in step 3. Select the table to link, press OK, and presto! You can now open the table and add/delete/edit data on your MySQL server! You can also build queries, import/export tables to MySQL, build forms and reports, etc.
Tips and Tricks:
You can construct your tables in Access and export them to MySQL, then link them back in. That makes table creation quick.
When creating tables in Access, you must have a primary key defined in order to have write access to the table in access. Make sure you create a primary key in MySQL before linking in access
If you change a table in MySQL, you have to re-link it in Access. Go to tools>add-ins>linked table manager, cruise to your ODBC DSN, and select the table to re-link from there. you can also move your dsn source around there, just hit the always prompt for new location checkbox before pressing OK.
3. I upgraded to PHP 4, and now mysql keeps telling me "Warning: MySQL: Unable to save result set in ...". What's up?
Most likely what has happened is, PHP 4 was compiled with the '--with-mysql' option, without specifying the path to MySQL. This means PHP is using its built-in MySQL client library. If your system is running applications, such as PHP 3 as a concurrent Apache module, or auth-mysql, that use other versions of MySQL clients, then there is a conflict between the two differing versions of those clients.
Recompiling PHP 4, and adding the path to MySQL to the flag, '--with-mysql=/your/path/to/mysql' usually solves the problem.
4. PHP 5 no longer bundles MySQL client libraries, what does this mean to me? Can I still use MySQL with PHP? I try to use MySQL and get "function undefined" errors, what gives?
Yes. There will always be MySQL support in PHP of one kind or another. The only change in PHP 5 is that we are no longer bundling the client library itself. Some reasons in no particular order:
Most systems these days already have the client library installed.
Given the above, having multiple versions of the library can get messy. For example, if you link mod_auth_mysql against one version and PHP against another, and then enable both in Apache, you get a nice fat crash. Also, the bundled library didn't always play well with the installed server version. The most obvious symptom of this being disagreement over where to find the mysql.socket Unix domain socket file.
Maintenance was somewhat lax and it was falling further and further behind the released version.
Future versions of the library are under the GPL and thus we don't have an upgrade path since we cannot bundle a GPL'ed library in a BSD/Apache-style licensed project. A clean break in PHP 5 seemed like the best option.
This won't actually affect that many people. Unix users, at least the ones who know what they are doing, tend to always build PHP against their system's libmyqlclient library simply by doing --with-mysql=/usr when building PHP. Windows users may enable the extension php_mysql.dll inside php.ini. Also, copy libmySQL.dll into the appropriate %SYSTEMROOT% directory, just like you do with every other bundled DLL from the dll directory.
5. After installing shared MySQL support, Apache dumps core as soon as libphp4.so is loaded. Can this be fixed?
If your MySQL libs are linked against pthreads this will happen. Check using ldd. If they are, grab the MySQL tarball and compile from source, or recompile from the source rpm and remove the switch in the spec file that turns on the threaded client code. Either of these suggestions will fix this. Then recompile PHP with the new MySQL libs.
6. Why do I get an error that looks something like this: "Warning: 0 is not a MySQL result index in <file> on line <x>" or "Warning: Supplied argument is not a valid MySQL result resource in <file> on line <x>?
You are trying to use a result identifier that is 0. The 0 indicates that your query failed for some reason. You need to check for errors after submitting a query and before you attempt to use the returned result identifier. The proper way to do this is with code similar to the following:
<?php $result = mysql_query("SELECT * FROM tables_priv"); if (!$result) { echo mysql_error(); exit; } ?> |
<?php $result = mysql_query("SELECT * FROM tables_priv") or die("Bad query: " . mysql_error()); ?> |
This section holds common questions about the way to install PHP. PHP is available for almost any OS (except maybe for MacOS before OSX), and almost any web server.
To install PHP, follow the instructions in the INSTALL file located in the distribution. Windows users should also read the install.txt file. There are also some helpful hints for Windows users here.
[mybox:user /src/php4] root# apachectl configtest apachectl: /usr/local/apache/bin/httpd Undefined symbols: _compress _uncompress |
cgi error: The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: |
By default on Unix it should be in /usr/local/lib which is <install-path>/lib. Most people will want to change this at compile-time with the --with-config-file-path flag. You would, for example, set it with something like:
--with-config-file-path=/etc |
--with-config-file-scan-dir=PATH |
On Windows the default path for the php.ini file is the Windows directory. If you're using the Apache webserver, php.ini is first searched in the Apaches install directory, e.g. c:\program files\apache group\apache. This way you can have different php.ini files for different versions of Apache on the same machine.
See also the chapter about the configuration file.
2. Unix: I installed PHP, but every time I load a document, I get the message 'Document Contains No Data'! What's going on here?
This probably means that PHP is having some sort of problem and is core-dumping. Look in your server error log to see if this is the case, and then try to reproduce the problem with a small test case. If you know how to use 'gdb', it is very helpful when you can provide a backtrace with your bug report to help the developers pinpoint the problem. If you are using PHP as an Apache module try something like:
Stop your httpd processes
gdb httpd
Stop your httpd processes
> run -X -f /path/to/httpd.conf
Then fetch the URL causing the problem with your browser
> run -X -f /path/to/httpd.conf
If you are getting a core dump, gdb should inform you of this now
type: bt
You should include your backtrace in your bug report. This should be submitted to http://bugs.php.net/
If your script uses the regular expression functions (ereg() and friends), you should make sure that you compiled PHP and Apache with the same regular expression package. This should happen automatically with PHP and Apache 1.3.x
3. Unix: I installed PHP using RPMS, but Apache isn't processing the PHP pages! What's going on here?
Assuming you installed both Apache and PHP from RPM packages, you need to uncomment or add some or all of the following lines in your httpd.conf file:
# Extra Modules AddModule mod_php.c AddModule mod_php3.c AddModule mod_perl.c # Extra Modules LoadModule php_module modules/mod_php.so LoadModule php3_module modules/libphp3.so # for PHP 3 LoadModule php4_module modules/libphp4.so # for PHP 4 LoadModule perl_module modules/libperl.so |
AddType application/x-httpd-php3 .php3 # for PHP 3 AddType application/x-httpd-php .php # for PHP 4 |
4. Unix: I installed PHP 3 using RPMS, but it doesn't compile with the database support I need! What's going on here?
Due to the way PHP 3 built, it is not easy to build a complete flexible PHP RPM. This issue is addressed in PHP 4. For PHP 3, we currently suggest you use the mechanism described in the INSTALL.REDHAT file in the PHP distribution. If you insist on using an RPM version of PHP 3, read on...
The RPM packagers are setting up the RPMS to install without database support to simplify installations and because RPMS use /usr/ instead of the standard /usr/local/ directory for files. You need to tell the RPM spec file which databases to support and the location of the top-level of your database server.
This example will explain the process of adding support for the popular MySQL database server, using the mod installation for Apache.
Of course all of this information can be adjusted for any database server that PHP supports. We will assume you installed MySQL and Apache completely with RPMS for this example as well.
First remove mod_php3 :
rpm -e mod_php3 |
Then get the source rpm and INSTALL it, NOT --rebuild
rpm -Uvh mod_php3-3.0.5-2.src.rpm |
Then edit the /usr/src/redhat/SPECS/mod_php3.spec file
In the %build section add the database support you want, and the path.
For MySQL you would add
--with-mysql=/usr \ |
./configure --prefix=/usr \ --with-apxs=/usr/sbin/apxs \ --with-config-file-path=/usr/lib \ --enable-debug=no \ --enable-safe-mode \ --with-exec-dir=/usr/bin \ --with-mysql=/usr \ --with-system-regex |
Once this modification is made then build the binary rpm as follows:
rpm -bb /usr/src/redhat/SPECS/mod_php3.spec |
Then install the rpm
rpm -ivh /usr/src/redhat/RPMS/i386/mod_php3-3.0.5-2.i386.rpm |
5. Unix: I patched Apache with the FrontPage extensions patch, and suddenly PHP stopped working. Is PHP incompatible with the Apache FrontPage extensions?
No, PHP works fine with the FrontPage extensions. The problem is that the FrontPage patch modifies several Apache structures, that PHP relies on. Recompiling PHP (using 'make clean ; make') after the FP patch is applied would solve the problem.
6. Unix/Windows: I have installed PHP, but when I try to access a PHP script file via my browser, I get a blank screen.
Do a 'view source' in the web browser and you will probably find that you can see the source code of your PHP script. This means that the web server did not send the script to PHP for interpretation. Something is wrong with the server configuration - double check the server configuration against the PHP installation instructions.
7. Unix/Windows: I have installed PHP, but when try to access a PHP script file via my browser, I get a server 500 error.
Something went wrong when the server tried to run PHP. To get to see a sensible error message, from the command line, change to the directory containing the PHP executable (php.exe on Windows) and run php -i. If PHP has any problems running, then a suitable error message will be displayed which will give you a clue as to what needs to be done next. If you get a screen full of HTML codes (the output of the phpinfo() function) then PHP is working, and your problem may be related to your server configuration which you should double check.
8. Some operating systems: I have installed PHP without errors, but when I try to start apache I get undefined symbol errors:
[mybox:user /src/php4] root# apachectl configtest apachectl: /usr/local/apache/bin/httpd Undefined symbols: _compress _uncompress |
This has actually nothing to do with PHP, but with the MySQL client libraries. Some need --with-zlib, others do not. This is also covered in the MySQL FAQ.
9. Windows: I have installed PHP, but when I to access a PHP script file via my browser, I get the error:
cgi error: The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: |
This error message means that PHP failed to output anything at all. To get to see a sensible error message, from the command line, change to the directory containing the PHP executable (php.exe on Windows) and run php -i. If PHP has any problems running, then a suitable error message will be displayed which will give you a clue as to what needs to be done next. If you get a screen full of HTML codes (the output of the phpinfo() function) then PHP is working.
Once PHP is working at the command line, try accessing the script via the browser again. If it still fails then it could be one of the following:
File permissions on your PHP script, php.exe, php4ts.dll, php.ini or any PHP extensions you are trying to load are such that the anonymous internet user ISUR_<machinename> cannot access them.
The script file does not exist (or possibly isn't where you think it is relative to your web root directory). Note that for IIS you can trap this error by ticking the 'check file exists' box when setting up the script mappings in the Internet Services Manager. If a script file does not exist then the server will return a 404 error instead. There is also the additional benefit that IIS will do any authentication required for you based on the NTLanMan permissions on your script file.
Make sure any user who needs to run a PHP script has the rights to run php.exe! IIS uses an anonymous user which is added at the time IIS is installed. This user needs rights to php.exe. Also, any authenticated user will also need rights to execute php.exe. And for IIS4 you need to tell it that PHP is a script engine. Also, you will want to read this faq.
11. When running PHP as CGI with IIS, PWS, OmniHTTPD or Xitami, I get the following error: Security Alert! PHP CGI cannot be accessed directly..
You must set the cgi.force_redirect directive to 0. It defaults to 1 so be sure the directive isn't commented out (with a ;). Like all directives, this is set in php.ini
Because the default is 1, it's critical that you're 100% sure that the correct php.ini file is being read. Read this faq for details.
12. How do I know if my php.ini is being found and read? It seems like it isn't as my changes aren't being implemented.
To be sure your php.ini is being read by PHP, make a call to phpinfo() and near the top will be a listing called Configuration File (php.ini). This will tell you where PHP is looking for php.ini and whether or not it's being read. If just a directory PATH exists than it's not being read and you should put your php.ini in that directory. If php.ini is included within the PATH than it is being read.
If php.ini is being read and you're running PHP as a module, then be sure to restart your web server after making changes to php.ini
This section gathers most common errors that occur at build time.
1. I got the latest version of PHP using the anonymous CVS service, but there's no configure script!
You have to have the GNU autoconf package installed so you can generate the configure script from configure.in. Just run ./buildconf in the top-level directory after getting the sources from the CVS server. (Also, unless you run configure with the --enable-maintainer-mode option, the configure script will not automatically get rebuilt when the configure.in file is updated, so you should make sure to do that manually when you notice configure.in has changed. One symptom of this is finding things like @VARIABLE@ in your Makefile after configure or config.status is run.)
2. I'm having problems configuring PHP to work with Apache. It says it can't find httpd.h, but it's right where I said it is!
You need to tell the configure/setup script the location of the top-level of your Apache source tree. This means that you want to specify --with-apache=/path/to/apache and not --with-apache=/path/to/apache/src.
3. While configuring PHP (./configure), you come across an error similar to the following:
checking lex output file root... ./configure: lex: command not found configure: error: cannot find output from lex; giving up |
Be sure to read the installation instructions carefully and note that you need both flex and bison installed to compile PHP. Depending on your setup you will install bison and flex from either source or a package, such as a RPM.
4. When I try to start Apache, I get the following message:
fatal: relocation error: file /path/to/libphp4.so: symbol ap_block_alarms: referenced symbol not found |
This error usually comes up when one compiles the Apache core program as a DSO library for shared usage. Try to reconfigure apache, making sure to use at least the following flags:
--enable-shared=max --enable-rule=SHARED_CORE |
For more information, read the top-level Apache INSTALL file or the Apache DSO manual page.
5. When I run configure, it says that it can't find the include files or library for GD, gdbm, or some other package!
You can make the configure script looks for header files and libraries in non-standard locations by specifying additional flags to pass to the C preprocessor and linker, such as:
CPPFLAGS=-I/path/to/include LDFLAGS=-L/path/to/library ./configure |
env CPPFLAGS=-I/path/to/include LDFLAGS=-L/path/to/library ./configure |
6. When it is compiling the file language-parser.tab.c, it gives me errors that say yytname undeclared.
You need to update your version of Bison. You can find the latest version at http://www.gnu.org/software/bison/bison.html.
7. When I run make, it seems to run fine but then fails when it tries to link the final application complaining that it can't find some files.
Some old versions of make that don't correctly put the compiled versions of the files in the functions directory into that same directory. Try running cp *.o functions and then re-running make to see if that helps. If it does, you should really upgrade to a recent version of GNU make.
Take a look at the link line and make sure that all of the appropriate libraries are being included at the end. Common ones that you might have missed are '-ldl' and any libraries required for any database support you included.
If you're linking with Apache 1.2.x, did you remember to add the appropriate information to the EXTRA_LIBS line of the Configuration file and re-rerun Apache's Configure script? See the INSTALL file that comes with the distribution for more information.
Some people have also reported that they had to add '-ldl' immediately following libphp4.a when linking with Apache.
This is actually quite easy. Follow these steps carefully:
Grab the latest Apache 1.3 distribution from http://www.apache.org/dist/httpd/.
Ungzip and untar it somewhere, for example /usr/local/src/apache-1.3.
Compile PHP by first running ./configure --with-apache=/<path>/apache-1.3 (substitute <path> for the actual path to your apache-1.3 directory.
Type make followed by make install to build PHP and copy the necessary files to the Apache distribution tree.
Change directories into to your /<path>/apache-1.3/src directory and edit the Configuration file. Add to the file: AddModule modules/php4/libphp4.a.
Type: ./configure followed by make.
You should now have a PHP-enabled httpd binary!
Note: You can also use the new Apache ./configure script. See the instructions in the README.configure file which is part of your Apache distribution. Also have a look at the INSTALL file in the PHP distribution.
10. I have followed all the steps to install the Apache module version on Unix, and my PHP scripts show up in my browser or I am being asked to save the file.
This means that the PHP module is not getting invoked for some reason. Three things to check before asking for further help:
Make sure that the httpd binary you are running is the actual new httpd binary you just built. To do this, try running: /path/to/binary/httpd -l
If you don't see mod_php4.c listed then you are not running the right binary. Find and install the correct binary.
Make sure you have added the correct Mime Type to one of your Apache .conf files. It should be: AddType application/x-httpd-php3 .php3 (for PHP 3)
or AddType application/x-httpd-php .php (for PHP 4)
Also make sure that this AddType line is not hidden away inside a <Virtualhost> or <Directory> block which would prevent it from applying to the location of your test script.
Finally, the default location of the Apache configuration files changed between Apache 1.2 and Apache 1.3. You should check to make sure that the configuration file you are adding the AddType line to is actually being read. You can put an obvious syntax error into your httpd.conf file or some other obvious change that will tell you if the file is being read correctly.
11. It says to use: --activate-module=src/modules/php4/libphp4.a, but that file doesn't exist, so I changed it to --activate-module=src/modules/php4/libmodphp4.a and it doesn't work!? What's going on?
Note that the libphp4.a file is not supposed to exist. The apache process will create it!
12. When I try to build Apache with PHP as a static module using --activate-module=src/modules/php4/libphp4.a it tells me that my compiler is not ANSI compliant.
This is a misleading error message from Apache that has been fixed in more recent versions.
There are three things to check here. First, for some reason when Apache builds the apxs Perl script, it sometimes ends up getting built without the proper compiler and flags variables. Find your apxs script (try the command which apxs), it's sometimes found in /usr/local/apache/bin/apxs or /usr/sbin/apxs. Open it and check for lines similar to these:
my $CFG_CFLAGS_SHLIB = ' '; # substituted via Makefile.tmpl my $CFG_LD_SHLIB = ' '; # substituted via Makefile.tmpl my $CFG_LDFLAGS_SHLIB = ' '; # substituted via Makefile.tmpl |
my $CFG_CFLAGS_SHLIB = '-fpic -DSHARED_MODULE'; # substituted via Makefile.tmpl my $CFG_LD_SHLIB = 'gcc'; # substituted via Makefile.tmpl my $CFG_LDFLAGS_SHLIB = q(-shared); # substituted via Makefile.tmpl |
my $CFG_LIBEXECDIR = 'modules'; # substituted via APACI install |
my $CFG_LIBEXECDIR = '/usr/lib/apache'; # substituted via APACI install |
During the make portion of installation, if you encounter problems that look similar to this:
microtime.c: In function `php_if_getrusage': microtime.c:94: storage size of `usg' isn't known microtime.c:97: `RUSAGE_SELF' undeclared (first use in this function) microtime.c:97: (Each undeclared identifier is reported only once microtime.c:97: for each function it appears in.) microtime.c:103: `RUSAGE_CHILDREN' undeclared (first use in this function) make[3]: *** [microtime.lo] Error 1 make[3]: Leaving directory `/home/master/php-4.0.1/ext/standard' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/home/master/php-4.0.1/ext/standard' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/master/php-4.0.1/ext' make: *** [all-recursive] Error 1 |
Your system is broken. You need to fix your /usr/include files by installing a glibc-devel package that matches your glibc. This has absolutely nothing to do with PHP. To prove this to yourself, try this simple test:
$ cat >test.c <<X #include <sys/resource.h> X $ gcc -E test.c >/dev/null |
15. When compiling PHP with MySQL, configure runs fine but during make I get an error similar to the following: ext/mysql/libmysql/my_tempnam.o(.text+0x46): In function my_tempnam': /php4/ext/mysql/libmysql/my_tempnam.c:103: the use of tempnam' is dangerous, better use mkstemp', what's wrong?
First, it's important to realize that this is a Warning and not a fatal error. Because this is often the last output seen during make, it may seem like a fatal error but it's not. Of course, if you set your compiler to die on Warnings, it will. Also keep in mind that MySQL support is enabled by default.
Óçìåßùóç: As of PHP 4.3.2, you'll also see the following text after the build (make) completes:
Build complete. (It is safe to ignore warnings about tempnam and tmpnam).
16. I want to upgrade my PHP. Where can I find the ./configure line that was used to build my current PHP installation?
Either you look at config.nice file, in the source tree of your current PHP installation or, if this is not available, you simply run a
<?php phpinfo(); ?> |
17. When building PHP with the GD library it either gives strange compile errors or segfaults on execution.
Make sure your GD library and PHP are linked against the same depending libraries (e.g. libpng).
18. When compiling PHP I seemingly get random errors, like it hangs. I'm using Solaris if that matters.
Using non-GNU utilities while compiling PHP may cause problems. Be sure to use GNU tools in order to be certain that compiling PHP will work. For example, on Solaris, using either the SunOS BSD-compatible or Solaris versions of sed will not work, but using the GNU or Sun POSIX (xpg4) versions of sed will work. Links: GNU sed, GNU flex, and GNU bison.
This section gathers many common errors that you may face while writing PHP scripts.
<?php function myfunc($argument) { echo $argument + 10; } $variable = 10; echo "myfunc($variable) = " . myfunc($variable); ?> |
<pre> <?php echo "This should be the first line."; ?> <?php echo "This should show up after the new line above."; ?> </pre> |
1. I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available?
PHP offers many predefined variables, like the superglobal $_POST. You may loop through $_POST as it's an associate array of all POSTed values. For example, let's simply loop through it with foreach, check for empty() values, and print them out.
<?php $empty = $post = array(); foreach ($_POST as $varname => $varvalue) { if (empty($varvalue)) { $empty[$varname] = $varvalue; } else { $post[$varname] = $varvalue; } } print "<pre>"; if (empty($empty)) { print "None of the POSTed values are empty, posted:\n"; var_dump($post); } else { print "We have " . count($empty) . " empty values\n"; print "Posted:\n"; var_dump($post); print "Empty:\n"; var_dump($empty); exit; } ?> |
Superglobals: óçìåßùóç äéáèåóéìüôçôáò: Áðü ôçí PHP 4.1.0, superglobal arrays üðùò ôï $_GET , $_POST, $_SERVER, êëð. åßíáé äéáèÝóéìá. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äéáâÜóôå ôçí åíüôçôá ôïõ manual ó÷åôéêÜ ìå ôá superglobals
2. I need to convert all single-quotes (') to a backslash followed by a single-quote (\'). How can I do this with a regular expression? I'd also like to convert " to \" and \ to \\.
The function addslashes() will do this. See also mysql_escape_string(). You may also strip backslashes with stripslashes().
directive óçìåßùóç: magic_quotes_gpc: Ôï PHP directive magic_quotes_gpc Ý÷åé ðñïåðéëåãìÝíç ôéìÞ on. ÏõóéáóôéêÜ ôñÝ÷åé ôçí addslashes() óå üëá ôá GET, POST, êáé COOKIE äåäïìÝíá. Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí stripslashes() ãéá íá ôá áöáéñÝóåôå.
3. All my " turn into \" and my ' turn into \', how do I get rid of all these unwanted backslashes? How and why did they get there?
The PHP function stripslashes() will strip those backslashes from your string. Most likely the backslashes magically exist because the PHP directive magic_quotes_gpc is on.
directive óçìåßùóç: magic_quotes_gpc: Ôï PHP directive magic_quotes_gpc Ý÷åé ðñïåðéëåãìÝíç ôéìÞ on. ÏõóéáóôéêÜ ôñÝ÷åé ôçí addslashes() óå üëá ôá GET, POST, êáé COOKIE äåäïìÝíá. Ìðïñåßôå íá ÷ñçóéìïðïéÞóåôå ôçí stripslashes() ãéá íá ôá áöáéñÝóåôå.
5. Hey, what happened to my newlines?
<pre> <?php echo "This should be the first line."; ?> <?php echo "This should show up after the new line above."; ?> </pre> |
In PHP, the ending for a block of code is either "?>" or "?>\n" (where \n means a newline). So in the example above, the echoed sentences will be on one line, because PHP omits the newlines after the block ending. This means that you need to insert an extra newline after each block of PHP code to make it print out one newline.
Why does PHP do this? Because when formatting normal HTML, this usually makes your life easier because you don't want that newline, but you'd have to create extremely long lines or otherwise make the raw page source unreadable to achieve that effect.
6. I get the message 'Warning: Cannot send session cookie - headers already sent...' or 'Cannot add header information - headers already sent...'.
The functions header(), setcookie(), and the session functions need to add headers to the output stream but headers can only be sent before all other content. There can be no output before using these functions, output such as HTML. The function headers_sent() will check if your script has already sent headers and see also the Output Control functions.
The getallheaders() function will do this if you are running PHP as an Apache module. So, the following bit of code will show you all the request headers:
<?php $headers = getallheaders(); foreach ($headers as $name => $content) { echo "headers[$name] = $content<br />\n"; } ?> |
See also apache_lookup_uri(), apache_response_headers(), and fsockopen()
The security model of IIS is at fault here. This is a problem common to all CGI programs running under IIS. A workaround is to create a plain HTML file (not parsed by PHP) as the entry page into an authenticated directory. Then use a META tag to redirect to the PHP page, or have a link to the PHP page. PHP will then recognize the authentication correctly. With the ISAPI module, this is not a problem. This should not effect other NT web servers. For more information, see: http://support.microsoft.com/support/kb/articles/q160/4/22.asp and the manual section on HTTP Authentication .
9. My PHP script works on IE and Lynx, but on Netscape some of my output is missing. When I do a "View Source" I see the content in IE but not in Netscape.
Netscape is more strict regarding HTML tags (such as tables) then IE. Running your HTML output through a HTML validator, such as validator.w3.org, might be helpful. For example, a missing </table> might cause this.
Also, both IE and Lynx ignore any NULs (\0) in the HTML stream, Netscape does not. The best way to check for this is to compile the command line version of PHP (also known as the CGI version) and run your script from the command line. In *nix, pipe it through od -c and look for any \0 characters. If you are on Windows you need to find an editor or some other program that lets you look at binary files. When Netscape sees a NUL in a file it will typically not output anything else on that line whereas both IE and Lynx will.
In order to embed <?xml straight into your PHP code, you'll have to turn off short tags by having the PHP directive short_open_tags set to 0. You cannot set this directive with ini_set(). Regardless of short_open_tags being on or off, you can do something like: <?php echo '<?xml'; ?>. The default for this directive is on.
11. How can I use PHP with FrontPage or some other HTML editor that insists on moving my code around?
One of the easiest things to do is to enable using ASP tags in your PHP code. This allows you to use the ASP-style <% and %> code delimiters. Some of the popular HTML editors handle those more intelligently (for now). To enable the ASP-style tags, you need to set the asp_tags php.ini variable, or use the appropriate Apache directive.
Read the manual page on predefined variables as it includes a partial list of predefined variables available to your script. A complete list of available variables (and much more information) can be seen by calling the phpinfo() function. Be sure to read the manual section on variables from outside of PHP as it describes common scenarios for external variables, like from a HTML form, a Cookie, and the URL.
register_globals: óçìáíôéêÞ óçìåßùóç: Áðü ôçí PHP 4.2.0, ç ðñïåðéëåãìÝíç ôéìÞ ãéá ôï PHP directive register_globals åßíáé off. Ç êïéíüôçôá ôçò PHP åíèáññýíåé üëïõò íá ìçí âáóßæïíôáé óå áõôü ôï directive (åíôïëÞ, ïäçãßá) áëëÜ óôç èÝóç ôïõ óå Üëëá ìÝóá, üðùò ôï superglobals.
13. How can I generate PDF files without using the non-free and commercial libraries ClibPDF and PDFLib? I'd like something that's free and doesn't require external PDF libraries.
There are a few alternatives written in PHP such as http://www.ros.co.nz/pdf/, http://www.fpdf.org/, http://www.gnuvox.com/pdf4php/, and http://www.potentialtech.com/ppl.php. There is also the Panda module.
14. I'm trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can't seem to find it. What's wrong?
It's important to realize that the PHP directive register_globals also affects server and environment variables. When register_globals = off (the default is off since PHP 4.2.0), $DOCUMENT_ROOT will not exist. Instead, use $_SERVER['DOCUMENT_ROOT'] . If register_globals = on then the variables $DOCUMENT_ROOT and $GLOBALS['DOCUMENT_ROOT'] will also exist.
If you're sure register_globals = on and wonder why $DOCUMENT_ROOT isn't available inside functions, it's because these are like any other variables and would require global $DOCUMENT_ROOT inside the function. See also the manual page on variable scope. It's preferred to code with register_globals = off.
Superglobals: óçìåßùóç äéáèåóéìüôçôáò: Áðü ôçí PHP 4.1.0, superglobal arrays üðùò ôï $_GET , $_POST, $_SERVER, êëð. åßíáé äéáèÝóéìá. Ãéá ðåñéóóüôåñåò ðëçñïöïñßåò, äéáâÜóôå ôçí åíüôçôá ôïõ manual ó÷åôéêÜ ìå ôá superglobals
PHP and HTML interact a lot: PHP can generate HTML, and HTML can pass information to PHP. Before reading these faqs, it's important you learn how to retrieve variables from outside of PHP. The manual page on this topic includes many examples as well. Pay close attention to what register_globals means to you too.
There are several stages for which encoding is important. Assuming that you have a string $data, which contains the string you want to pass on in a non-encoded way, these are the relevant stages:
HTML interpretation. In order to specify a random string, you must include it in double quotes, and htmlspecialchars() the whole value.
URL: A URL consists of several parts. If you want your data to be interpreted as one item, you must encode it with urlencode().
Óçìåßùóç: It is wrong to urlencode() $data, because it's the browsers responsibility to urlencode() the data. All popular browsers do that correctly. Note that this will happen regardless of the method (i.e., GET or POST). You'll only notice this in case of GET request though, because POST requests are usually hidden.
Óçìåßùóç: The data is shown in the browser as intended, because the browser will interpret the HTML escaped symbols.
Upon submitting, either via GET or POST, the data will be urlencoded by the browser for transferring, and directly urldecoded by PHP. So in the end, you don't need to do any urlencoding/urldecoding yourself, everything is handled automagically.
Óçìåßùóç: In fact you are faking a HTML GET request, therefore it's necessary to manually urlencode() the data.
Óçìåßùóç: You need to htmlspecialchars() the whole URL, because the URL occurs as value of an HTML-attribute. In this case, the browser will first un-htmlspecialchars() the value, and then pass the URL on. PHP will understand the URL correctly, because you urlencoded() the data.
You'll notice that the & in the URL is replaced by &. Although most browsers will recover if you forget this, this isn't always possible. So even if your URL is not dynamic, you need to htmlspecialchars() the URL.
2. I'm trying to use an <input type="image"> tag, but the $foo.x and $foo.y variables aren't available. $_GET['foo.x'] isn't existing either. Where are they?
When submitting a form, it is possible to use an image instead of the standard submit button with a tag like:
<input type="image" src="image.gif" name="foo" /> |
Because foo.x and foo.y would make invalid variable names in PHP, they are automagically converted to foo_x and foo_y. That is, the periods are replaced with underscores. So, you'd access these variables like any other described within the section on retrieving variables from outside of PHP. For example, $_GET['foo_x'].
To get your <form> result sent as an array to your PHP script you name the <input>, <select> or <textarea> elements like this:
<input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyArray[]" /> |
<input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyOtherArray[]" /> <input name="MyOtherArray[]" /> |
<input name="AnotherArray[]" /> <input name="AnotherArray[]" /> <input name="AnotherArray[email]" /> <input name="AnotherArray[phone]" /> |
Óçìåßùóç: Specifying an arrays key is optional in HTML. If you do not specify the keys, the array gets filled in the order the elements appear in the form. Our first example will contain keys 0, 1, 2 and 3.
See also Array Functions and Variables from outside PHP.
The select multiple tag in an HTML construct allows users to select multiple items from a list. These items are then passed to the action handler for the form. The problem is that they are all passed with the same widget name. I.e.
<select name="var" multiple="yes"> |
var=option1 var=option2 var=option3 |
<select name="var[]" multiple="yes"> |
Note that if you are using JavaScript the [] on the element name might cause you problems when you try to refer to the element by name. Use it's numerical form element ID instead, or enclose the variable name in single quotes and use that as the index to the elements array, for example:
variable = documents.forms[0].elements['var[]']; |
Since Javascript is (usually) a client-side technology, and PHP is (usually) a server-side technology, and since HTTP is a "stateless" protocol, the two languages cannot directly share variables.
It is, however, possible to pass variables between the two. One way of accomplishing this is to generate Javascript code with PHP, and have the browser refresh itself, passing specific variables back to the PHP script. The example below shows precisely how to do this -- it allows PHP code to capture screen height and width, something that is normally only possible on the client side.
<?php if (isset($_GET['width']) AND isset($_GET['height'])) { // output the geometry variables echo "Screen width is: ". $_GET['width'] ."<br />\n"; echo "Screen height is: ". $_GET['height'] ."<br />\n"; } else { // pass the geometry variables // (preserve the original query string // -- post variables will need to handled differently) echo "<script language='javascript'>\n"; echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}" . "&width=\" + screen.width + \"&height=\" + screen.height;\n"; echo "</script>\n"; exit(); } ?> |
PHP can be used to access COM and DCOM objects on Win32 platforms.
If this is a simple DLL there is no way yet to run it from PHP. If the DLL contains a COM server you may be able to access it if it implements the IDispatch interface.
There are dozens of VARIANT types and combinations of them. Most of them are already supported but a few still have to be implemented. Arrays are not completely supported. Only single dimensional indexed only arrays can be passed between PHP and COM. If you find other types that aren't supported, please report them as a bug (if not already reported) and provide as much information as available.
Generally it is, but as PHP is mostly used as a web scripting language it runs in the web servers context, thus visual objects will never appear on the servers desktop. If you use PHP for application scripting e.g. in conjunction with PHP-GTK there is no limitation in accessing and manipulating visual objects through COM.
No, you can't. COM instances are treated as resources and therefore they are only available in a single script's context.
In PHP 5, the COM extension throws com_exception exceptions, which you can catch and then inspect the code member to determine what to do next.
In PHP 4 it's not possible to trap COM errors beside the ways provided by PHP itself (@, track_errors, ..).
No, unfortunately there is no such tool available for PHP.
7. What does 'Unable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' mean ?
This error can have multiple reasons:
the CLSID is wrong
the requested DLL is missing
the requested component doesn't implement the IDispatch interface
Exactly like you run local objects. You only have to pass the IP of the remote machine as second parameter to the COM constructor.
Make sure that you have set =TRUE in your php.ini.
Edit your php.ini and set =TRUE.
This has nothing to do with PHP. ActiveX objects are loaded on client side if they are requested by the HTML document. There is no relation to the PHP script and therefore there is no direct server side interaction possible.
This is possible with the help of monikers. If you want to get multiple references to the same word instance you can create that instance like shown:
<?php $word = new COM("C:\docs\word.doc"); ?> |
This will create a new instance if there is no running instance available or it will return a handle to the running instance, if available.
You can define an event sink and bind it using com_event_sink(). You can use com_print_typeinfo() to have PHP generate a skeleton for the event sink class.
13. I'm having problems when trying to invoke a method of a COM object which exposes more than one interface. What can I do ?
The answer is as simple as unsatisfying. I don't know exactly but i think you can do nothing. If someone has specific information about this, please let me know :)
COM+ extends COM by a framework for managing components through MTS and MSMQ but there is nothing special that PHP has to support to use such components.
15. If PHP can manipulate COM objects, can we imagine to use MTS to manage components resources, in conjunction with PHP ?
PHP itself doesn't handle transactions yet. Thus if an error occurs no rollback is initiated. If you use components that support transactions you will have to implement the transaction management yourself.
PHP is the best language for web programing, but what about other languages?
ASP is not really a language in itself, it's an acronym for Active Server Pages, the actual language used to program ASP with is Visual Basic Script or JScript. The biggest drawback of ASP is that it's a proprietary system that is natively used only on Microsoft Internet Information Server (IIS). This limits it's availability to Win32 based servers. There are a couple of projects in the works that allows ASP to run in other environments and webservers: InstantASP from Halcyon (commercial), Chili!Soft ASP from Chili!Soft (commercial). ASP is said to be a slower and more cumbersome language than PHP, less stable as well. Some of the pros of ASP is that since it primarily uses VBScript it's relatively easy to pick up the language if you're already know how to program in Visual Basic. ASP support is also enabled by default in the IIS server making it easy to get up and running. The components built in ASP are really limited, so if you need to use "advanced" features like interacting with FTP servers, you need to buy additional components.
Yes, the server-side asp2php is the one most often referred to as well as this client-side option.
PHP is commonly said to be faster and more efficient for complex programming tasks and trying out new ideas. PHP is generally referred to as more stable and less resource intensive as well. Cold Fusion has better error handling, database abstraction and date parsing although database abstraction is addressed in PHP 4. Another thing that is listed as one of Cold Fusion's strengths is its excellent search engine, but it has been mentioned that a search engine is not something that should be included in a web scripting language. PHP runs on almost every platform there is; Cold Fusion is only available on Win32, Solaris, Linux and HP/UX. Cold Fusion has a good IDE and is generally easier to get started with, whereas PHP initially requires more programming knowledge. Cold Fusion is designed with non-programmers in mind, while PHP is focused on programmers.
A great summary by Michael J Sheldon on this topic has been posted to the PHP mailing list. A copy can be found at http://marc.theaimsgroup.com/?l=php-general&m=95602167412542&w=1.
The biggest advantage of PHP over Perl is that PHP was designed for scripting for the web where Perl was designed to do a lot more and can because of this get very complicated. The flexibility / complexity of Perl makes it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format without losing flexibility. PHP is easier to integrate into existing HTML than Perl. PHP has pretty much all the 'good' functionality of Perl: constructs, syntax and so on, without making it as complicated as Perl can be. Perl is a very tried and true language, it's been around since the late eighties, but PHP is maturing very quickly.
PHP has already a long history behind him: Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP 4.0.
PHP/FI 2.0 is no longer supported. Please see appropriate manual section for information about migration from PHP/FI 2.0.
If you are still working with PHP 2, we strongly recommend you to upgrade straight to PHP 4.
PHP has already a long history behind him : Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP 4.0.
PHP 4 was designed to be as compatible with earlier versions of PHP as possible and very little functionality was broken in the process. If you're really unsure about compatibility you should install PHP 4 in a test environment and run your scripts there.
Also see the appropriate migration appendix of this manual.
Although native session support didn't exist in PHP 3, there are third-party applications that did (and still do) offer session functionality. The most common method was by using PHPLIB.
There can be some questions we can't put into other categories. Here you can find them.
If you don't have an archiver-tool to handle bz2 files download the commandline tool from Redhat (please find further information below).
If you would not like to use a command line tool, you can try free tools like Stuffit Expander, UltimateZip, 7-Zip, or Quick Zip. If you have tools like WinRAR or Power Archiver, you can easily decompress the bz2 files with it. If you use Windows Commander, a bz2 plugin for that program is available freely from the Windows Commander site.
The bzip2 commandline tool from Redhat:
Win2k Sp2 users grab the latest version 1.0.2, all other Windows user should grab version 1.00. After downloading rename the executable to bzip2.exe. For convenience put it into a directory in your path, e.g. C:\Windows where C represents your windows installation drive.
Note: lang stands for your language and x for the desired format, e.g.: pdf. To uncompress the php_manual_lang.x.bz2 follow these simple instructions:
open a command prompt window
cd to the folder where you stored the downloaded php_manual_lang.x.bz2
invoke bzip2 -d php_manual_lang.x.bz2, extracting php_manual_lang.x in the same folder
In case you downloaded the php_manual_lang.tar.bz2 with many html-files in it, the procedure is the same. The only difference is that you got a file php_manual_lang.tar. The tar format is known to be treated with most common archivers on Windows like e.g. WinZip.
PHP has come a long way in the last few years. Growing to be one of the most prominent languages powering the Web was not an easy task. Those of you interested in briefly seeing how PHP grew out to what it is today, read on. Old PHP releases can be found at the PHP Museum.
PHP succeeds an older product, named PHP/FI. PHP/FI was created by Rasmus Lerdorf in 1995, initially as a simple set of Perl scripts for tracking accesses to his online resume. He named this set of scripts 'Personal Home Page Tools'. As more functionality was required, Rasmus wrote a much larger C implementation, which was able to communicate with databases, and enabled users to develop simple dynamic Web applications. Rasmus chose to release the source code for PHP/FI for everybody to see, so that anybody can use it, as well as fix bugs in it and improve the code.
PHP/FI, which stood for Personal Home Page / Forms Interpreter, included some of the basic functionality of PHP as we know it today. It had Perl-like variables, automatic interpretation of form variables and HTML embedded syntax. The syntax itself was similar to that of Perl, albeit much more limited, simple, and somewhat inconsistent.
By 1997, PHP/FI 2.0, the second write-up of the C implementation, had a cult of several thousand users around the world (estimated), with approximately 50,000 domains reporting as having it installed, accounting for about 1% of the domains on the Internet. While there were several people contributing bits of code to this project, it was still at large a one-man project.
PHP/FI 2.0 was officially released only in November 1997, after spending most of its life in beta releases. It was shortly afterwards succeeded by the first alphas of PHP 3.0.
PHP 3.0 was the first version that closely resembles PHP as we know it today. It was created by Andi Gutmans and Zeev Suraski in 1997 as a complete rewrite, after they found PHP/FI 2.0 severely underpowered for developing an eCommerce application they were working on for a University project. In an effort to cooperate and start building upon PHP/FI's existing user-base, Andi, Rasmus and Zeev decided to cooperate and announce PHP 3.0 as the official successor of PHP/FI 2.0, and development of PHP/FI 2.0 was mostly halted.
One of the biggest strengths of PHP 3.0 was its strong extensibility features. In addition to providing end users with a solid infrastructure for lots of different databases, protocols and APIs, PHP 3.0's extensibility features attracted dozens of developers to join in and submit new extension modules. Arguably, this was the key to PHP 3.0's tremendous success. Other key features introduced in PHP 3.0 were the object oriented syntax support and the much more powerful and consistent language syntax.
The whole new language was released under a new name, that removed the implication of limited personal use that the PHP/FI 2.0 name held. It was named plain 'PHP', with the meaning being a recursive acronym - PHP: Hypertext Preprocessor.
By the end of 1998, PHP grew to an install base of tens of thousands of users (estimated) and hundreds of thousands of Web sites reporting it installed. At its peak, PHP 3.0 was installed on approximately 10% of the Web servers on the Internet.
PHP 3.0 was officially released in June 1998, after having spent about 9 months in public testing.
By the winter of 1998, shortly after PHP 3.0 was officially released, Andi Gutmans and Zeev Suraski had begun working on a rewrite of PHP's core. The design goals were to improve performance of complex applications, and improve the modularity of PHP's code base. Such applications were made possible by PHP 3.0's new features and support for a wide variety of third party databases and APIs, but PHP 3.0 was not designed to handle such complex applications efficiently.
The new engine, dubbed 'Zend Engine' (comprised of their first names, Zeev and Andi), met these design goals successfully, and was first introduced in mid 1999. PHP 4.0, based on this engine, and coupled with a wide range of additional new features, was officially released in May 2000, almost two years after its predecessor, PHP 3.0. In addition to the highly improved performance of this version, PHP 4.0 included other key features such as support for many more Web servers, HTTP sessions, output buffering, more secure ways of handling user input and several new language constructs.
PHP 4 is currently the latest released version of PHP. Work has already begun on modifying and improving the Zend Engine to integrate the features which were designed for PHP 5.0.
Today, PHP is being used by hundreds of thousands of developers (estimated), and several million sites report as having it installed, which accounts for over 20% of the domains on the Internet.
PHP's development team includes dozens of developers, as well as dozens others working on PHP-related projects such as PEAR and the documentation project.
The future of PHP is mainly driven by its core, the Zend Engine. PHP 5 will include the new Zend Engine 2.0. To get more information on this engine, see its webpage.
PEAR, the PHP Extension and Application Repository (originally, PHP Extension and Add-on Repository) is PHP's version of foundation classes, and may grow in the future to be one of the key ways to distribute PHP extensions among developers.
PEAR was born in discussions held in the PHP Developers' Meeting (PDM) held in January 2000 in Tel Aviv. It was created by Stig S. Bakken, and is dedicated to his first-born daughter, Malin Bakken.
Since early 2000, PEAR has grown to be a big, significant project with a large number of developers working on implementing common, reusable functionality for the benefit of the entire PHP community. PEAR today includes a wide variety of infrastructure foundation classes for database access, content caching, mathematical calculations, eCommerce and much more.
More information about PEAR can be found in the manual.
The PHP Quality Assurance Initiative was set up in the summer of 2000 in response to criticism that PHP releases were not being tested well enough for production environments. The team now consists of a core group of developers with a good understanding of the PHP code base. These developers spend a lot of their time localizing and fixing bugs within PHP. In addition there are many other team members who test and provide feedback on these fixes using a wide variety of platforms.
PHP-GTK is the PHP solution for writing client side GUI applications. Andrei Zmievski remembers the planing and creation process of PHP-GTK:
GUI programming has always been of my interests, and I found that Gtk+ is a very nice toolkit, except that programming with it in C is somewhat tedious. After witnessing PyGtk and GTK-Perl implementations, I decided to see if PHP could be made to interface with Gtk+, even minimally. Starting in August of 2000, I began to have a bit more free time so that is when I started experimenting. My main guideline was the PyGtk implementation as it was fairly feature complete and had a nice object-oriented interface. James Henstridge, the author of PyGtk, provided very helpful advice during those initial stages.
Hand-writing the interfaces to all the Gtk+ functions was out of the question, so I seized upon the idea of code-generator, similar to how PyGtk did it. The code generator is a PHP program that reads a set of .defs file containing the Gtk+ classes, constants, and methods information and generates C code that interfaces PHP with them. What cannot be generated automatically can be written by hand in .overrides file.
Working on the code generator and the infrastructure took some time, because I could spend little time on PHP-GTK during the fall of 2000. After I showed PHP-GTK to Frank Kromann, he got interested and started helping me out with code generator work and Win32 implementation. When we wrote the first Hello World program and fired it up, it was extremely exciting. It took a couple more months to get the project to a presentable condition and the initial version was released on March 1, 2001. The story promptly hit SlashDot.
Sensing that PHP-GTK might be extensive, I set up separate mailing lists and CVS repositories for it, as well as the gtk.php.net website with the help of Colin Viebrock. The documentation would also need to be done and James Moore came in to help with that.
Since its release PHP-GTK has been gaining popularity. We have our own documentation team, the manual keeps improving, people start writing extensions for PHP-GTK, and more and more exciting applications with it.
As PHP grew, it began to be recognized as a world-wide popular development platform. One of the most interesting ways of seeing this trend was by observing the books about PHP that came out throughout the years.
To the best of our knowledge, the first book dedicated to PHP was 'PHP - tvorba interaktivních internetových aplikací' - a Czech book published in April 1999, authored by Jirka Kosek. Next month followed a German book authored by Egon Schmid, Christian Cartus and Richard Blume. The first book in English about PHP was published shortly afterwards, and was 'Core PHP Programming' by Leon Atkinson. Both of these books covered PHP 3.0.
While these books were the first of their kind - they were followed by a large number of books from a host of authors and publishers. There are over 40 books in English, 50 books in German, and over 20 books in French! In addition, you can find books about PHP in many other languages, including Spanish, Korean, Japanese and Hebrew.
Clearly, this large number of books, written by different authors, published by many publishers, and their availability in so many languages - are a strong testimony for PHP's world-wide success.
To the best of our knowledge, the first article about PHP in a hard-copy magazine was published in the Czech mutation of Computerworld in the spring of 1998, and covered PHP 3.0. As with books, this was the first in a series of many articles published about PHP in various prominent magazines.
Articles about PHP appeared in Dr. Dobbs, Linux Enterprise, Linux Magazine and many more. Articles about migrating ASP-based applications to PHP under Windows even appear on Microsoft's very own MSDN!
PHP 5 and the integrated Zend Engine 2 have greatly improved PHP's performance and capabilities, but great care has been taken to break as little existing code as possible. So migrating your code from PHP 4 to 5 should be very easy. Most existing PHP 4 code should be ready to run without changes, but you should still know about the few differences and take care to test your code before switching versions in production environments.
Although most existing PHP 4 code should work without changes, you should pay attention to the following backward incompatible changes:
strrpos() and strripos() now use the entire string as a needle.
Illegal use of string offsets causes E_ERROR instead of E_WARNING.
array_merge() was changed to accept only arrays. If a non-array variable is passed, a E_WARNING will be thrown for every such parameter. Be careful because your code may start emitting E_WARNING out of the blue.
PATH_TRANSLATED server variable is no longer set implicitly under Apache2 SAPI in contrast to the situation in PHP 4, where it is set to the same value as the SCRIPT_FILENAME server variable when it is not populated by Apache. This change was made to comply with the CGI specification. Please refer to bug #23610 for further information.
The T_ML_CONSTANT constant is no longer defined by the Tokenizer extension. If error_reporting is set to E_ALL, PHP will generate a notice. Although the T_ML_CONSTANT was never used at all, it was defined in PHP 4. In both PHP 4 and PHP 5 // and /* */ are resolved as the T_COMMENT constant. However the PHPDoc style comments /** */ ,which starting PHP 5 are parsed by PHP, are recognized as T_DOC_COMMENT.
$_SERVER should be populated with argc and argv if variables_order includes "S". If you have specifically configured your system to not create $_SERVER, then of course it shouldn't be there. The change was to always make argc and argv available in the CLI version regardless of the variables_order setting. As in, the CLI version will now always populate the global $argc and $argv variables.
An object with no properties is no longer considered "empty".
Classes must be declared before used.
ÐáñÜäåéãìá B-1. strrpos() and strripos() now use the entire string as a needle
|
The following example was valid in PHP 4, although it will produce a fatal error in PHP 5.
In PHP 5 there were some changes in CLI and CGI filenames. In PHP 5, the CGI version was renamed to php-cgi.exe (previously php.exe) and the CLI version now sits in the main directory (previously cli/php.exe).
In PHP 5 it was also introduced a new mode: php-win.exe. This is equal to the CLI version, except that php-win doesn't output anything and thus provides no console (no "dos box" appears on the screen). This behavior is similar to php-gtk.
In PHP 5, the CLI version will always populate the global $argv and $argc variables.
Since the ISAPI modules changed their names, from php4xxx to php5xxx, you need to make some changes in the configuration files. There were also changes in the CLI and CGI filenames. Please refer to the corresponding section for more information.
Migrate the Apache configuration is extremely easy. See the example below to check the change you need to do:
# change this line: LoadModule php4_module /php/sapi/php4apache2.dll # with this one: LoadModule php5_module /php/php5apache2.dll |
If your webserver is running PHP in CGI mode, you should note that the CGI version has changed its name from php.exe to php-cgi.exe. In Apache you should do something like this:
# change this line: Action application/x-httpd-php "/php/php.exe" # with this one: Action application/x-httpd-php "/php/php-cgi.exe" |
In other webservers you need to change either the CGI or the ISAPI module filenames.
In PHP 5 there are some new functions. Here is the list of them:
Arrays:
array_combine() - Creates an array by using one array for keys and another for its values
array_diff_uassoc() - Computes the difference of arrays with additional index check which is performed by a user supplied callback function
array_udiff() - Computes the difference of arrays by using a callback function for data comparison
array_udiff_assoc() - Computes the difference of arrays with additional index check. The data is compared by using a callback function
array_udiff_uassoc() - Computes the difference of arrays with additional index check. The data is compared by using a callback function. The index check is done by a callback function also
array_walk_recursive() - Apply a user function recursively to every member of an array
InterBase:
ibase_affected_rows() - Return the number of rows that were affected by the previous query
ibase_backup() - Initiates a backup task in the service manager and returns immediately
ibase_commit_ret() - Commit a transaction without closing it
ibase_db_info() - Request statistics about a database
ibase_drop_db() - Drops a database
ibase_errcode() - Return an error code
ibase_free_event_handler() - Cancels a registered event handler
ibase_gen_id() - Increments the named generator and returns its new value
ibase_maintain_db() - Execute a maintenance command on the database server
ibase_name_result() - Assigns a name to a result set
ibase_num_params() - Return the number of parameters in a prepared query
ibase_param_info() - Return information about a parameter in a prepared query
ibase_restore() - Initiates a restore task in the service manager and returns immediately
ibase_rollback_ret() - Rollback transaction and retain the transaction context
ibase_server_info() - Request statistics about a database
ibase_service_attach() - Connect to the service manager
ibase_service_detach() - Disconnect from the service manager
ibase_set_event_handler() - Register a callback function to be called when events are posted
ibase_wait_event() - Wait for an event to be posted by the database
iconv:
iconv_mime_decode() - Decodes a MIME header field
iconv_mime_decode_headers() - Decodes multiple MIME header fields at once
iconv_mime_encode() - Composes a MIME header field
iconv_strlen() - Returns the character count of string
iconv_strpos() - Finds position of first occurrence of a needle within a haystack
iconv_strrpos() - Finds the last occurrence of a needle within the specified range of haystack
iconv_substr() - Cut out part of a string
Streams:
stream_copy_to_stream() - Copies data from one stream to another
stream_get_line() - Gets line from stream resource up to a given delimiter
stream_socket_accept() - Accept a connection on a socket created by stream_socket_server()
stream_socket_client() - Open Internet or Unix domain socket connection
stream_socket_get_name() - Retrieve the name of the local or remote sockets
stream_socket_recvfrom() - Receives data from a socket, connected or not
stream_socket_sendto() - Sends a message to a socket, whether it is connected or not
stream_socket_server() - Create an Internet or Unix domain server socket
Other:
convert_uudecode() - decode a uuencoded string
convert_uuencode() - uuencode a string
curl_copy_handle() - Copy a cURL handle along with all of it's preferences
dba_key_split() - Splits a key in string representation into array representation
dbase_get_header_info() - Get the header info of a dBase database
dbx_fetch_row() - Fetches rows from a query-result that had the DBX_RESULT_UNBUFFERED flag set
fbsql_set_password() - Change the password for a given user
file_put_contents() - Write a string to a file
ftp_alloc() - Allocates space for a file to be uploaded
get_declared_interfaces() - Returns an array of all declared interfaces
get_headers() - Fetches all the headers sent by the server in response to a HTTP request
headers_list() - Returns a list of response headers sent (or ready to send)
http_build_query() - Generate URL-encoded query string
idate() - Format a local time/date as integer
image_type_to_extension() - Get file extension for image-type returned by getimagesize(), exif_read_data(), exif_thumbnail(), exif_imagetype()
imagefilter() - Applies Filter an image using a custom angle
imap_getacl() - Gets the ACL for a given mailbox
ldap_sasl_bind() - Bind to LDAP directory using SASL
mb_list_encodings() - Returns an array of all supported encodings
pcntl_getpriority() - Get the priority of any process
pcntl_wait() - Waits on or returns the status of a forked child as defined by the waitpid() system call
pg_version() - Returns an array with client, protocol and server version (when available)
php_check_syntax() - Check the syntax of the specified file
php_strip_whitespace() - Return source with stripped comments and whitespace
proc_nice() - Change the priority of the current process
pspell_config_data_dir() - Change location of language data files
pspell_config_dict_dir() - Change location of the main word list
setrawcookie() - Send a cookie with no url encoding of the value
snmp_read_mib() - Reads and parses a MIB file into the active MIB tree
sqlite_fetch_column_types() - Return an array of column types from a particular table
str_split() - Convert a string to an array
strpbrk() - Search a string for any of a set of characters
substr_compare() - Binary safe optionally case insensitive comparison of two strings from an offset, up to length characters
time_nanosleep() - Delay for a number of seconds and nano seconds
Óçìåßùóç: The Tidy extension has also changed its API completely.
There were some new php.ini directives introduced in PHP 5. Here is a list of them:
mail.force_extra_parameters - Force the addition of the specified parameters to be passed as extra parameters to the sendmail binary. These parameters will always replace the value of the 5th parameter to mail(), even in safe mode
register_long_arrays - allow/disallow PHP to register the deprecated long $HTTP_*_VARS
session.hash_function - select a hash function (MD5 or SHA-1)
session.hash_bits_per_character - define how many bits are stored in each character when converting the binary hash data to something readable (from 4 to 6)
zend.ze1_compatibility_mode - Enable compatibility mode with Zend Engine 1 (PHP 4)
There were some changes in PHP 5 regarding databases (MySQL and SQLite).
In PHP 5 the MySQL client libraries are not bundled, because of license problems and some others. For more information, read the FAQ entry.
There is also a new extension, MySQLi (Improved MySQL), which is designed to work with MySQL 4.1 and above.
Since PHP 5, the SQLite extension is built-in PHP. SQLite is an embeddable SQL database engine and is not a client library used to connect to a big database server (like MySQL or PostgreSQL). The SQLite library reads and writes directly to and from the database files on disk.
In PHP 5 there is a new Object Model. PHP's handling of objects has been completely rewritten, allowing for better performance and more features. Please read http://www.php.net/zend-engine-2.php for more info.
PHP 4 and the integrated Zend engine have greatly improved PHP's performance and capabilities, but great care has been taken to break as little existing code as possible. So migrating your code from PHP 3 to 4 should be much easier than migrating from PHP/FI 2 to PHP 3. A lot of existing PHP 3 code should be ready to run without changes, but you should still know about the few differences and take care to test your code before switching versions in production environments. The following should give you some hints about what to look for.
Recent operating systems provide the ability to perform versioning and scoping. This features make it possible to let PHP 3 and PHP 4 run as concurrent modules in one Apache server.
This feature is known to work on the following platforms:
Linux with recent binutils (binutils 2.9.1.0.25 tested)
Solaris 2.5 or better
FreeBSD (3.2, 4.0 tested)
To enable it, configure PHP 3 and PHP 4 to use APXS (--with-apxs) and the necessary link extensions (--enable-versioning). Otherwise, all standard installations instructions apply. For example:
The global configuration file, php3.ini, has changed its name to php.ini.
For the Apache configuration file, there are slightly more changes. The MIME types recognized by the PHP module have changed.
application/x-httpd-php3 --> application/x-httpd-php application/x-httpd-php3-source --> application/x-httpd-php-source |
You can make your configuration files work with both versions of PHP (depending on which one is currently compiled into the server), using the following syntax:
AddType application/x-httpd-php3 .php3 AddType application/x-httpd-php3-source .php3s AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps |
In addition, the PHP directive names for Apache have changed.
Starting with PHP 4.0, there are only four Apache directives that relate to PHP:
php_value [PHP directive name] [value] php_flag [PHP directive name] [On|Off] php_admin_value [PHP directive name] [value] php_admin_flag [PHP directive name] [On|Off] |
There are two differences between the Admin values and the non admin values:
Admin values (or flags) can only appear in the server-wide Apache configuration files (e.g., httpd.conf).
Standard values (or flags) cannot control certain PHP directives, for example: safe mode (if you could override safe mode settings in .htaccess files, it would defeat safe mode's purpose). In contrast, Admin values can modify the value of any PHP directive.
To make the transition process easier, PHP 4 is bundled with scripts that automatically convert your Apache configuration and .htaccess files to work with both PHP 3 and PHP 4. These scripts do NOT convert the mime type lines! You have to convert these yourself.
To convert your Apache configuration files, run the apconf-conv.sh script (available in the scripts/apache/ directory). For example:
Your original configuration file will be saved in httpd.conf.orig.
To convert your .htaccess files, run the aphtaccess-conv.sh script (available in the scripts/apache/ directory as well):
Likewise, your old .htaccess files will be saved with an .orig prefix.
The conversion scripts require awk to be installed.
Parsing and execution are now two completely separated steps, no execution of a files code will happen until the complete file and everything it requires has completely and successfully been parsed.
One of the new requirements introduced with this split is that required and included files now have to be syntactically complete. You can no longer spread the different controlling parts of a control structure across file boundaries. That is you cannot start a for or while loop, an if statement or a switch block in one file and have the end of loop, else, endif, case or break statements in a different file.
It still perfectly legal to include additional code within loops or other control structures, only the controlling keywords and corresponding curly braces {...} have to be within the same compile unit (file or eval()ed string).
This should not harm too much as spreading code like this should be considered as very bad style anyway.
Another thing no longer possible, though rarely seen in PHP 3 code is returning values from a required file. Returning a value from an included file is still possible.
With PHP 3 the error reporting level was set as a simple numeric value formed by summing up the numbers related to different error levels. Usual values were 15 for reporting all errors and warnings or 7 for reporting everything but simple notice messages reporting bad style and things like that.
PHP 4 has a larger set of error and warning levels and comes with a configuration parser that now allows for symbolic constants to be used for setting the intended behavior.
Error reporting level should now be configured by explicitly taking away the warning levels you do not want to generate error messages by x-oring them from the symbolic constant E_ALL. Sounds complicated? Well, lets say you want the error reporting system to report all but the simple style warnings that are categorized by the symbolic constant E_NOTICE. Then you'll put the following into your php.ini: error_reporting = E_ALL & ~ ( E_NOTICE ). If you want to suppress warnings too you add up the appropriate constant within the braces using the binary or operator '|': error_reporting= E_ALL & ~ ( E_NOTICE | E_WARNING ).
Ðñïåéäïðïßçóç |
When upgrading code or servers from PHP 3 to PHP 4 you should check these settings and calls to error_reporting() or you might disable reporting the new error types, especially E_COMPILE_ERROR. This may lead to empty documents without any feedback of what happened or where to look for the problem. |
Ðñïåéäïðïßçóç |
Using the old values 7 and 15 for setting up error reporting is a very bad idea as this suppresses some of the newly added error classes including parse errors. This may lead to very strange behavior as scripts might no longer work without error messages showing up anywhere. This has lead to a lot of unreproducible bug reports in the past where people reported script engine problems they were not capable to track down while the TRUE case was usually some missing '}' in a required file that the parser was not able to report due to a misconfigured error reporting system. So checking your error reporting setup should be the first thing to do whenever your scripts silently die. The Zend engine can be considered mature enough nowadays to not cause this kind of strange behavior. |
A lot of existing PHP 3 code uses language constructs that should be considered as very bad style as this code, while doing the intended thing now, could easily be broken by changes in other places. PHP 4 will output a lot of notice messages in such situations where PHP 3 didn't. The easy fix is to just turn off E_NOTICE messages, but it is usually a good idea to fix the code instead.
The most common case that will now produce notice messages is the use of unquoted string constants as array indices. Both PHP 3 and 4 will fall back to interpret these as strings if no keyword or constant is known by that name, but whenever a constant by that name had been defined anywhere else in the code it might break your script. This can even become a security risk if some intruder manages to redefine string constants in a way that makes your script give him access rights he wasn't intended to have. So PHP 4 will now warn you whenever you use unquoted string constants as for example in $_SERVER[REQUEST_METHOD]. Changing it to $_SERVER['REQUEST_METHOD'] will make the parser happy and greatly improve the style and security of your code.
Another thing PHP 4 will now tell you about is the use of uninitialized variables or array elements.
Static variable and class member initializers only accept scalar values while in PHP 3 they accepted any valid expression. This is, once again, due to the split between parsing and execution as no code has yet been executed when the parser sees the initializer.
For classes you should use constructors to initialize member variables instead. For static variables anything but a simple static value rarely makes sense anyway.
The perhaps most controversial change in behavior has happened to the behavior of the empty(). A String containing only the character '0' (zero) is now considered empty while it wasn't in PHP 3.
This new behavior makes sense in web applications, with all input fields returning strings even if numeric input is requested, and with PHP's capabilities of automatic type conversion. But on the other hand it might break your code in a rather subtle way, leading to misbehavior that is hard to track down if you do not know about what to look for.
While PHP 4 comes with a lot of new features, functions and extensions, you may still find some functions from version 3 missing. A small number of core functions has vanished because they do not work with the new scheme of splitting parsing and execution as introduced into 4 with the Zend engine. Other functions and even complete extensions have become obsolete as newer functions and extensions serve the same task better and/or in a more general way. Some functions just simply haven't been ported yet and finally some functions or extensions may be missing due to license conflicts.
As PHP 4 now separates parsing from execution it is no longer possible to change the behavior of the parser (now embedded in the Zend engine) at runtime as parsing already happened by then. So the function short_tags() no longer exists. You can still change the parsers behavior by setting appropriate values in the php.ini file.
Another feature of PHP 3 that is not a part of PHP 4 is the bundled debugging interface. There are third-party add-ons for the Zend engine which add similar functionality.
The Adabas and Solid database extensions are no more. Long live the unified ODBC extension instead.
unset(), although still available, is implemented as a language construct rather than a function.
This does not have any consequences on the behavior of unset(), but testing for "unset" using function_exists() will return FALSE as it would with other language constructs that look like functions such as echo().
Another more practical change is that it is no longer possible to call unset() indirectly, that is $func="unset"; $func($somevar) won't work anymore.
Extensions written for PHP 3 will not work with PHP 4, neither as binaries nor at the source level. It is not difficult to port extensions to PHP 4 if you have access to the original source. A detailed description of the actual porting process is not part of this text.
PHP 4 adds a new mechanism to variable substitution in strings. You can now finally access object member variables and elements from multidimensional arrays within strings.
To do so you have to enclose your variables with curly braces with the dollar sign immediately following the opening brace: {$...}
To embed the value of an object member variable into a string you simply write "text {$obj->member} text" while in PHP 3 you had to use something like "text ".$obj->member." text".
This should lead to more readable code, while it may break existing scripts written for PHP 3. But you can easily check for this kind of problem by checking for the character combination {$ in your code and by replacing it with \{$ with your favorite search-and-replace tool.
PHP 3 had the bad habit of setting cookies in the reverse order of the setcookie() calls in your code. PHP 4 breaks with this habit and creates the cookie header lines in exactly the same order as you set the cookies in the code.
This might break some existing code, but the old behaviour was so strange to understand that it deserved a change to prevent further problems in the future.
While handling of global variables had the focus on to be easy in PHP 3 and early versions of PHP 4, the focus has changed to be more secure. While in PHP 3 the following example worked fine, in PHP 4 it has to be unset($GLOBALS["id"]);. This is only one issue of global variable handling. You should always have used $GLOBALS, with newer versions of PHP 4 you are forced to do so in most cases. Read more on this subject in the global references section.
PHP 3.0 is rewritten from the ground up. It has a proper parser that is much more robust and consistent than 2.0's. 3.0 is also significantly faster, and uses less memory. However, some of these improvements have not been possible without compatibility changes, both in syntax and functionality.
In addition, PHP's developers have tried to clean up both PHP's syntax and semantics in version 3.0, and this has also caused some incompatibilities. In the long run, we believe that these changes are for the better.
This chapter will try to guide you through the incompatibilities you might run into when going from PHP/FI 2.0 to PHP 3.0 and help you resolve them. New features are not mentioned here unless necessary.
A conversion program that can automatically convert your old PHP/FI 2.0 scripts exists. It can be found in the convertor subdirectory of the PHP 3.0 distribution. This program only catches the syntax changes though, so you should read this chapter carefully anyway.
The old_function statement allows you to declare a function using a syntax identical to PHP/FI2 (except you must replace 'function' with 'old_function'.
This is a deprecated feature, and should only be used by the PHP/FI2->PHP 3 convertor.
Ðñïåéäïðïßçóç |
Functions declared as old_function cannot be called from PHP's internal code. Among other things, this means you can't use them in functions such as usort(), array_walk(), and register_shutdown_function(). You can get around this limitation by writing a wrapper function (in normal PHP 3 form) to call the old_function. |
The first thing you probably will notice is that PHP's start and end tags have changed. The old <? > form has been replaced by three new possible forms:
The `alternative' way to write if/elseif/else statements, using if(); elseif(); else; endif; cannot be efficiently implemented without adding a large amount of complexity to the 3.0 parser. Because of this, the syntax has been changed:
Just like with if..endif, the syntax of while..endwhile has changed as well:
Ðñïåéäïðïßçóç |
If you use the old while..endwhile syntax in PHP 3.0, you will get a never-ending loop. |
PHP/FI 2.0 used the left side of expressions to determine what type the result should be. PHP 3.0 takes both sides into account when determining result types, and this may cause 2.0 scripts to behave unexpectedly in 3.0.
Consider this example:
In PHP/FI 2.0, this would display both of $a's indices. In PHP 3.0, it wouldn't display anything. The reason is that in PHP 2.0, because the left argument's type was string, a string comparison was made, and indeed "" does not equal "0", and the loop went through. In PHP 3.0, when a string is compared with an integer, an integer comparison is made (the string is converted to an integer). This results in comparing atoi("") which is 0, and variablelist which is also 0, and since 0==0, the loop doesn't go through even once.The fix for this is simple. Replace the while statement with:
PHP 3.0's error messages are usually more accurate than 2.0's were, but you no longer get to see the code fragment causing the error. You will be supplied with a file name and a line number for the error, though.
In PHP 3.0 boolean evaluation is short-circuited. This means that in an expression like (1 || test_me()), the function test_me() would not be executed since nothing can change the result of the expression after the 1.
This is a minor compatibility issue, but may cause unexpected side-effects.
Most internal functions have been rewritten so they return TRUE when successful and FALSE when failing, as opposed to 0 and -1 in PHP/FI 2.0, respectively. The new behaviour allows for more logical code, like $fp = fopen("/your/file") or fail("darn!");. Because PHP/FI 2.0 had no clear rules for what functions should return when they failed, most such scripts will probably have to be checked manually after using the 2.0 to 3.0 convertor.
The PHP 3.0 Apache module no longer supports Apache versions prior to 1.2. Apache 1.2 or later is required.
echo() no longer supports a format string. Use the printf() function instead.
In PHP/FI 2.0, an implementation side-effect caused $foo[0] to have the same effect as $foo. This is not true for PHP 3.0.
Reading arrays with $array[] is no longer supported
That is, you cannot traverse an array by having a loop that does $data = $array[]. Use current() and next() instead.
Also, $array1[] = $array2 does not append the values of $array2 to $array1, but appends $array2 as the last entry of $array1. See also multidimensional array support.
"+" is no longer overloaded as a concatenation operator for strings, instead it converts it's arguments to numbers and performs numeric addition. Use "." instead.
PHP 3 includes support for a network-based debugger.
PHP 4 does not have an internal debugging facility. You can use one of the external debuggers though. The Zend IDE includes a debugger, and there are also some free debugger extensions like DBG at http://dd.cron.ru/dbg/, the Advanced PHP Debugger (APD) or Xdebug which even has a compatible debugger interface as PHP 3's debugging functionality as is described in this section.
The internal debugger in PHP 3 is useful for tracking down evasive bugs. The debugger works by connecting to a TCP port for every time PHP 3 starts up. All error messages from that request will be sent to this TCP connection. This information is intended for "debugging server" that can run inside an IDE or programmable editor (such as Emacs).
How to set up the debugger:
Set up a TCP port for the debugger in the configuration file (debugger.port) and enable it (debugger.enabled).
Set up a TCP listener on that port somewhere (for example socket -l -s 1400 on Unix systems).
In your code, run "debugger_on(host)", where host is the IP number or name of the host running the TCP listener.
The PHP 3 debugger protocol is line-based. Each line has a type, and several lines compose a message. Each message starts with a line of the type start and terminates with a line of the type end. PHP 3 may send lines for different messages simultaneously.
A line has this format:
Date in ISO 8601 format (yyyy-mm-dd)
Time including microseconds: hh:mm:uuuuuu
DNS name or IP address of the host where the script error was generated.
PID (process id) on host of the process with the PHP 3 script that generated this error.
Type of line. Tells the receiving program about what it should treat the following data as:
Ðßíáêáò E-1. Debugger Line Types
Name | Meaning |
---|---|
start | Tells the receiving program that a debugger message starts here. The contents of data will be the type of error message, listed below. |
message | The PHP 3 error message. |
location | File name and line number where the error occurred. The first location line will always contain the top-level location. data will contain file:line. There will always be a location line after message and after every function. |
frames | Number of frames in the following stack dump. If there are four frames, expect information about four levels of called functions. If no "frames" line is given, the depth should be assumed to be 0 (the error occurred at top-level). |
function | Name of function where the error occurred. Will be repeated once for every level in the function call stack. |
end | Tells the receiving program that a debugger message ends here. |
Line data.
Ðßíáêáò E-2. Debugger Error Types
Debugger | PHP 3 Internal |
---|---|
warning | E_WARNING |
error | E_ERROR |
parse | E_PARSE |
notice | E_NOTICE |
core-error | E_CORE_ERROR |
core-warning | E_CORE_WARNING |
unknown | (any other) |
ÐáñÜäåéãìá E-1. Example Debugger Message
|
This section is rather outdated and demonstrates how to extend PHP 3. If you're interested in PHP 4, please read the section on the Zend API. Also, you'll want to read various files found in the PHP source, files such as README.SELF-CONTAINED-EXTENSIONS and README.EXT_SKEL.
All functions look like this:
void php3_foo(INTERNAL_FUNCTION_PARAMETERS) { } |
Arguments are always of type pval. This type contains a union which has the actual type of the argument. So, if your function takes two arguments, you would do something like the following at the top of your function:
When you change any of the passed parameters, whether they are sent by reference or by value, you can either start over with the parameter by calling pval_destructor on it, or if it's an ARRAY you want to add to, you can use functions similar to the ones in internal_functions.h which manipulate return_value as an ARRAY.
Also if you change a parameter to IS_STRING make sure you first assign the new estrdup()'ed string and the string length, and only later change the type to IS_STRING. If you change the string of a parameter which already IS_STRING or IS_ARRAY you should run pval_destructor on it first.
A function can take a variable number of arguments. If your function can take either 2 or 3 arguments, use the following:
The type of each argument is stored in the pval type field. This type can be any of the following:
Ðßíáêáò F-1. PHP Internal Types
IS_STRING | String |
IS_DOUBLE | Double-precision floating point |
IS_LONG | Long integer |
IS_ARRAY | Array |
IS_EMPTY | None |
IS_USER_FUNCTION | ?? |
IS_INTERNAL_FUNCTION | ?? (if some of these cannot be passed to a function - delete) |
IS_CLASS | ?? |
IS_OBJECT | ?? |
If you get an argument of one type and would like to use it as another, or if you just want to force the argument to be of a certain type, you can use one of the following conversion functions:
convert_to_long(arg1); convert_to_double(arg1); convert_to_string(arg1); convert_to_boolean_long(arg1); /* If the string is "" or "0" it becomes 0, 1 otherwise */ convert_string_to_number(arg1); /* Converts string to either LONG or DOUBLE depending on string */ |
These function all do in-place conversion. They do not return anything.
The actual argument is stored in a union; the members are:
IS_STRING: arg1->value.str.val
IS_LONG: arg1->value.lval
IS_DOUBLE: arg1->value.dval
Any memory needed by a function should be allocated with either emalloc() or estrdup(). These are memory handling abstraction functions that look and smell like the normal malloc() and strdup() functions. Memory should be freed with efree().
There are two kinds of memory in this program: memory which is returned to the parser in a variable, and memory which you need for temporary storage in your internal function. When you assign a string to a variable which is returned to the parser you need to make sure you first allocate the memory with either emalloc() or estrdup(). This memory should NEVER be freed by you, unless you later in the same function overwrite your original assignment (this kind of programming practice is not good though).
For any temporary/permanent memory you need in your functions/library you should use the three emalloc(), estrdup(), and efree() functions. They behave EXACTLY like their counterpart functions. Anything you emalloc() or estrdup() you have to efree() at some point or another, unless it's supposed to stick around until the end of the program; otherwise, there will be a memory leak. The meaning of "the functions behave exactly like their counterparts" is: if you efree() something which was not emalloc()'ed nor estrdup()'ed you might get a segmentation fault. So please take care and free all of your wasted memory.
If you compile with "-DDEBUG", PHP will print out a list of all memory that was allocated using emalloc() and estrdup() but never freed with efree() when it is done running the specified script.
A number of macros are available which make it easier to set a variable in the symbol table:
SET_VAR_STRING(name,value)
SET_VAR_DOUBLE(name,value)
SET_VAR_LONG(name,value)
Ðñïåéäïðïßçóç |
Be careful with SET_VAR_STRING. The value part must be malloc'ed manually because the memory management code will try to free this pointer later. Do not pass statically allocated memory into a SET_VAR_STRING. |
Symbol tables in PHP are implemented as hash tables. At any given time, &symbol_table is a pointer to the 'main' symbol table, and active_symbol_table points to the currently active symbol table (these may be identical like in startup, or different, if you're inside a function).
The following examples use 'active_symbol_table'. You should replace it with &symbol_table if you specifically want to work with the 'main' symbol table. Also, the same functions may be applied to arrays, as explained below.
If you want to define a new array in a symbol table, you should do the following.
First, you may want to check whether it exists and abort appropriately, using hash_exists() or hash_find().
Next, initialize the array:
Here's how to add new entries to it:
ÐáñÜäåéãìá F-6. Adding entries to a new array
|
hash_next_index_insert() uses more or less the same logic as "$foo[] = bar;" in PHP 2.0.
If you are building an array to return from a function, you can initialize the array just like above by doing:
if (array_init(return_value) == FAILURE) { failed...; } |
...and then adding values with the helper functions:
add_next_index_long(return_value,long_value); add_next_index_double(return_value,double_value); add_next_index_string(return_value,estrdup(string_value)); |
Of course, if the adding isn't done right after the array initialization, you'd probably have to look for the array first:
pval *arr; if (hash_find(active_symbol_table,"foo",sizeof("foo"),(void **)&arr)==FAILURE) { can't find... } else { use arr->value.ht... } |
Note that hash_find receives a pointer to a pval pointer, and not a pval pointer.
Just about any hash function returns SUCCESS or FAILURE (except for hash_exists(), which returns a boolean truth value).
A number of macros are available to make returning values from a function easier.
The RETURN_* macros all set the return value and return from the function:
RETURN
RETURN_FALSE
RETURN_TRUE
RETURN_LONG(l)
RETURN_STRING(s,dup) If dup is TRUE, duplicates the string
RETURN_STRINGL(s,l,dup) Return string (s) specifying length (l).
RETURN_DOUBLE(d)
The RETVAL_* macros set the return value, but do not return.
RETVAL_FALSE
RETVAL_TRUE
RETVAL_LONG(l)
RETVAL_STRING(s,dup) If dup is TRUE, duplicates the string
RETVAL_STRINGL(s,l,dup) Return string (s) specifying length (l).
RETVAL_DOUBLE(d)
The string macros above will all estrdup() the passed 's' argument, so you can safely free the argument after calling the macro, or alternatively use statically allocated memory.
If your function returns boolean success/error responses, always use RETURN_TRUE and RETURN_FALSE respectively.
Your function can also return a complex data type such as an object or an array.
Returning an object:
Call object_init(return_value).
Fill it up with values. The functions available for this purpose are listed below.
Possibly, register functions for this object. In order to obtain values from the object, the function would have to fetch "this" from the active_symbol_table. Its type should be IS_OBJECT, and it's basically a regular hash table (i.e., you can use regular hash functions on .value.ht). The actual registration of the function can be done using:
add_method( return_value, function_name, function_ptr ); |
The functions used to populate an object are:
add_property_long( return_value, property_name, l ) - Add a property named 'property_name', of type long, equal to 'l'
add_property_double( return_value, property_name, d ) - Same, only adds a double
add_property_string( return_value, property_name, str ) - Same, only adds a string
add_property_stringl( return_value, property_name, str, l ) - Same, only adds a string of length 'l'
Returning an array:
Call array_init(return_value).
Fill it up with values. The functions available for this purpose are listed below.
The functions used to populate an array are:
add_assoc_long(return_value,key,l) - add associative entry with key 'key' and long value 'l'
add_assoc_double(return_value,key,d)
add_assoc_string(return_value,key,str,duplicate)
add_assoc_stringl(return_value,key,str,length,duplicate) specify the string length
add_index_long(return_value,index,l) - add entry in index 'index' with long value 'l'
add_index_double(return_value,index,d)
add_index_string(return_value,index,str)
add_index_stringl(return_value,index,str,length) - specify the string length
add_next_index_long(return_value,l) - add an array entry in the next free offset with long value 'l'
add_next_index_double(return_value,d)
add_next_index_string(return_value,str)
add_next_index_stringl(return_value,str,length) - specify the string length
PHP has a standard way of dealing with various types of resources. This replaces all of the local linked lists in PHP 2.0.
Available functions:
php3_list_insert(ptr, type) - returns the 'id' of the newly inserted resource
php3_list_delete(id) - delete the resource with the specified id
php3_list_find(id,*type) - returns the pointer of the resource with the specified id, updates 'type' to the resource's type
Typical list code would look like this:
ÐáñÜäåéãìá F-8. Using an existing resource
|
PHP has a standard way of storing persistent resources (i.e., resources that are kept in between hits). The first module to use this feature was the MySQL module, and mSQL followed it, so one can get the general impression of how a persistent resource should be used by reading mysql.c. The functions you should look at are:
php3_mysql_do_connect |
php3_mysql_connect() |
php3_mysql_pconnect() |
The general idea of persistence modules is this:
Code all of your module to work with the regular resource list mentioned in section (9).
Code extra connect functions that check if the resource already exists in the persistent resource list. If it does, register it as in the regular resource list as a pointer to the persistent resource list (because of 1., the rest of the code should work immediately). If it doesn't, then create it, add it to the persistent resource list AND add a pointer to it from the regular resource list, so all of the code would work since it's in the regular resource list, but on the next connect, the resource would be found in the persistent resource list and be used without having to recreate it. You should register these resources with a different type (e.g. LE_MYSQL_LINK for non-persistent link and LE_MYSQL_PLINK for a persistent link).
If you read mysql.c, you'll notice that except for the more complex connect function, nothing in the rest of the module has to be changed.
The very same interface exists for the regular resource list and the persistent resource list, only 'list' is replaced with 'plist':
php3_plist_insert(ptr, type) - returns the 'id' of the newly inserted resource
php3_plist_delete(id) - delete the resource with the specified id
php3_plist_find(id,*type) - returns the pointer of the resource with the specified id, updates 'type' to the resource's type
However, it's more than likely that these functions would prove to be useless for you when trying to implement a persistent module. Typically, one would want to use the fact that the persistent resource list is really a hash table. For instance, in the MySQL/mSQL modules, when there's a pconnect() call (persistent connect), the function builds a string out of the host/user/passwd that were passed to the function, and hashes the SQL link with this string as a key. The next time someone calls a pconnect() with the same host/user/passwd, the same key would be generated, and the function would find the SQL link in the persistent list.
Until further documented, you should look at mysql.c or msql.c to see how one should use the plist's hash table abilities.
One important thing to note: resources going into the persistent resource list must *NOT* be allocated with PHP's memory manager, i.e., they should NOT be created with emalloc(), estrdup(), etc. Rather, one should use the regular malloc(), strdup(), etc. The reason for this is simple - at the end of the request (end of the hit), every memory chunk that was allocated using PHP's memory manager is deleted. Since the persistent list isn't supposed to be erased at the end of a request, one mustn't use PHP's memory manager for allocating resources that go to it.
When you register a resource that's going to be in the persistent list, you should add destructors to it both in the non-persistent list and in the persistent list. The destructor in the non-persistent list destructor shouldn't do anything. The one in the persistent list destructor should properly free any resources obtained by that type (e.g. memory, SQL links, etc). Just like with the non-persistent resources, you *MUST* add destructors for every resource, even it requires no destruction and the destructor would be empty. Remember, since emalloc() and friends aren't to be used in conjunction with the persistent list, you mustn't use efree() here either.
Many of the features of PHP can be configured at runtime. These configuration directives can appear in either the designated php3.ini file, or in the case of the Apache module version in the Apache .conf files. The advantage of having them in the Apache .conf files is that they can be configured on a per-directory basis. This means that one directory may have a certain safemodeexecdir for example, while another directory may have another. This configuration granularity is especially handy when a server supports multiple virtual hosts.
The steps required to add a new directive:
Add directive to php3_ini_structure struct in mod_php3.h.
In main.c, edit the php3_module_startup function and add the appropriate cfg_get_string() or cfg_get_long() call.
Add the directive, restrictions and a comment to the php3_commands structure in mod_php3.c. Note the restrictions part. RSRC_CONF are directives that can only be present in the actual Apache .conf files. Any OR_OPTIONS directives can be present anywhere, include normal .htaccess files.
In either php3take1handler() or php3flaghandler() add the appropriate entry for your directive.
In the configuration section of the _php3_info() function in functions/info.c you need to add your new directive.
And last, you of course have to use your new directive somewhere. It will be addressable as php3_ini.directive.
To call user functions from an internal function, you should use the call_user_function() function.
call_user_function() returns SUCCESS on success, and FAILURE in case the function cannot be found. You should check that return value! If it returns SUCCESS, you are responsible for destroying the retval pval yourself (or return it as the return value of your function). If it returns FAILURE, the value of retval is undefined, and you mustn't touch it.
All internal functions that call user functions must be reentrant. Among other things, this means they must not use globals or static variables.
call_user_function() takes six arguments:
This is a pointer to an object on which the function is invoked. This should be NULL if a global function is called. If it's not NULL (i.e. it points to an object), the function_table argument is ignored, and instead taken from the object's hash. The object *may* be modified by the function that is invoked on it (that function will have access to it via $this). If for some reason you don't want that to happen, send a copy of the object instead.
The name of the function to call. Must be a pval of type IS_STRING with function_name.str.val and function_name.str.len set to the appropriate values. The function_name is modified by call_user_function() - it's converted to lowercase. If you need to preserve the case, send a copy of the function name instead.
A pointer to a pval structure, into which the return value of the invoked function is saved. The structure must be previously allocated - call_user_function() does NOT allocate it by itself.
An array of pointers to values that will be passed as arguments to the function, the first argument being in offset 0, the second in offset 1, etc. The array is an array of pointers to pval's; The pointers are sent as-is to the function, which means if the function modifies its arguments, the original values are changed (passing by reference). If you don't want that behavior, pass a copy instead.
To report errors from an internal function, you should call the php3_error() function. This takes at least two parameters -- the first is the level of the error, the second is the format string for the error message (as in a standard printf() call), and any following arguments are the parameters for the format string. The error levels are:
Notices are not printed by default, and indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. For example, trying to access the value of a variable which has not been set, or calling stat() on a file that doesn't exist.
Warnings are printed by default, but do not interrupt script execution. These indicate a problem that should have been trapped by the script before the call was made. For example, calling ereg() with an invalid regular expression.
Errors are also printed by default, and execution of the script is halted after the function returns. These indicate errors that can not be recovered from, such as a memory allocation problem.
Parse errors should only be generated by the parser. The code is listed here only for the sake of completeness.
This is like an E_ERROR, except it is generated by the core of PHP. Functions should not generate this type of error.
This is like an E_WARNING, except it is generated by the core of PHP. Functions should not generate this type of error.
This is like an E_ERROR, except it is generated by the Zend Scripting Engine. Functions should not generate this type of error.
This is like an E_WARNING, except it is generated by the Zend Scripting Engine. Functions should not generate this type of error.
This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). Functions should not generate this type of error.
This is like an E_WARNING, except it is generated by using the PHP function trigger_error(). Functions should not generate this type of error.
This is like an E_NOTICE, except it is generated by using the PHP function trigger_error(). Functions should not generate this type of error.
Here is the aliases list. All aliases are listed here. It is usually a bad idea to use aliases, as they may be bound to obsolescence or renaming, which will lead to unportable script. This list is provided to help those who want to upgrade their old scripts to newer syntax.
However, some functions simply have two names, and there is no real preference. (For example, is_int() and is_integer() are equally good)
This list is consistent with PHP 4.0.6. For an alias list that updates daily, have a look at http://zend.com/phpfunc/all_aliases.php.
Ðßíáêáò G-1. Aliases
Alias | Master function | Extension used |
---|---|---|
_ | gettext() | Gettext |
add | swfmovie_add() | Ming (flash) |
add | swfsprite_add() | Ming (flash) |
add_root | domxml_add_root() | DOM XML |
addaction | swfbutton_addAction() | Ming (flash) |
addcolor | swfdisplayitem_addColor() | Ming (flash) |
addentry | swfgradient_addEntry() | Ming (flash) |
addfill | swfshape_addfill() | Ming (flash) |
addshape | swfbutton_addShape() | Ming (flash) |
addstring | swftext_addString() | Ming (flash) |
addstring | swftextfield_addString() | Ming (flash) |
align | swftextfield_align() | Ming (flash) |
attributes | domxml_attributes() | DOM XML |
children | domxml_children() | DOM XML |
chop | rtrim() | Base syntax |
close | closedir() | Base syntax |
com_get | com_propget() | COM |
com_propset | com_propput() | COM |
com_set | com_propput() | COM |
cv_add | ccvs_add() | CCVS |
cv_auth | ccvs_auth() | CCVS |
cv_command | ccvs_command() | CCVS |
cv_count | ccvs_count() | CCVS |
cv_delete | ccvs_delete() | CCVS |
cv_done | ccvs_done() | CCVS |
cv_init | ccvs_init() | CCVS |
cv_lookup | ccvs_lookup() | CCVS |
cv_new | ccvs_new() | CCVS |
cv_report | ccvs_report() | CCVS |
cv_return | ccvs_return() | CCVS |
cv_reverse | ccvs_reverse() | CCVS |
cv_sale | ccvs_sale() | CCVS |
cv_status | ccvs_status() | CCVS |
cv_textvalue | ccvs_textvalue() | CCVS |
cv_void | ccvs_void() | CCVS |
die | exit() | Miscellaneous functions |
dir | getdir() | Base syntax |
diskfreespace | disk_free_space() | Filesystem |
domxml_getattr | domxml_get_attribute() | DOM XML |
domxml_setattr | domxml_set_attribute() | DOM XML |
doubleval | floatval() | Base syntax |
drawarc | swfshape_drawarc() | Ming (flash) |
drawcircle | swfshape_drawcircle() | Ming (flash) |
drawcubic | swfshape_drawcubic() | Ming (flash) |
drawcubicto | swfshape_drawcubicto() | Ming (flash) |
drawcurve | swfshape_drawcurve() | Ming (flash) |
drawcurveto | swfshape_drawcurveto() | Ming (flash) |
drawglyph | swfshape_drawglyph() | Ming (flash) |
drawline | swfshape_drawline() | Ming (flash) |
drawlineto | swfshape_drawlineto() | Ming (flash) |
dtd | domxml_intdtd() | DOM XML |
dumpmem | domxml_dumpmem() | DOM XML |
fbsql | fbsql_db_query() | FrontBase |
fputs | fwrite() | Base syntax |
get_attribute | domxml_get_attribute() | DOM XML |
getascent | swffont_getAscent() | Ming (flash) |
getascent | swftext_getAscent() | Ming (flash) |
getattr | domxml_get_attribute() | DOM XML |
getdescent | swffont_getDescent() | Ming (flash) |
getdescent | swftext_getDescent() | Ming (flash) |
getheight | swfbitmap_getHeight() | Ming (flash) |
getleading | swffont_getLeading() | Ming (flash) |
getleading | swftext_getLeading() | Ming (flash) |
getshape1 | swfmorph_getShape1() | Ming (flash) |
getshape2 | swfmorph_getShape2() | Ming (flash) |
getwidth | swfbitmap_getWidth() | Ming (flash) |
getwidth | swffont_getWidth() | Ming (flash) |
getwidth | swftext_getWidth() | Ming (flash) |
gzputs | gzwrite() | Zlib |
i18n_convert | mb_convert_encoding() | Multi-bytes Strings |
i18n_discover_encoding | mb_detect_encoding() | Multi-bytes Strings |
i18n_http_input | mb_http_input() | Multi-bytes Strings |
i18n_http_output | mb_http_output() | Multi-bytes Strings |
i18n_internal_encoding | mb_internal_encoding() | Multi-bytes Strings |
i18n_ja_jp_hantozen | mb_convert_kana() | Multi-bytes Strings |
i18n_mime_header_decode | mb_decode_mimeheader() | Multi-bytes Strings |
i18n_mime_header_encode | mb_encode_mimeheader() | Multi-bytes Strings |
imap_create | imap_createmailbox() | IMAP |
imap_fetchtext | imap_body() | IMAP |
imap_getmailboxes | imap_list_full() | IMAP |
imap_getsubscribed | imap_lsub_full() | IMAP |
imap_header | imap_headerinfo() | IMAP |
imap_listmailbox | imap_list() | IMAP |
imap_listsubscribed | imap_lsub() | IMAP |
imap_rename | imap_renamemailbox() | IMAP |
imap_scan | imap_listscan() | IMAP |
imap_scanmailbox | imap_listscan() | IMAP |
ini_alter | ini_set() | Base syntax |
is_double | is_float() | Base syntax |
is_integer | is_int() | Base syntax |
is_long | is_int() | Base syntax |
is_real | is_float() | Base syntax |
is_writeable | is_writable() | Base syntax |
join | implode() | Base syntax |
labelframe | swfmovie_labelFrame() | Ming (flash) |
labelframe | swfsprite_labelFrame() | Ming (flash) |
last_child | domxml_last_child() | DOM XML |
lastchild | domxml_last_child() | DOM XML |
ldap_close | ldap_unbind() | LDAP |
magic_quotes_runtime | set_magic_quotes_runtime() | Base syntax |
mbstrcut | mb_strcut() | Multi-bytes Strings |
mbstrlen | mb_strlen() | Multi-bytes Strings |
mbstrpos | mb_strpos() | Multi-bytes Strings |
mbstrrpos | mb_strrpos() | Multi-bytes Strings |
mbsubstr | mb_substr() | Multi-bytes Strings |
ming_setcubicthreshold | ming_setCubicThreshold() | Ming (flash) |
ming_setscale | ming_setScale() | Ming (flash) |
move | swfdisplayitem_move() | Ming (flash) |
movepen | swfshape_movepen() | Ming (flash) |
movepento | swfshape_movepento() | Ming (flash) |
moveto | swfdisplayitem_moveTo() | Ming (flash) |
moveto | swffill_moveTo() | Ming (flash) |
moveto | swftext_moveTo() | Ming (flash) |
msql | msql_db_query() | mSQL |
msql_createdb | msql_create_db() | mSQL |
msql_dbname | msql_result() | mSQL |
msql_dropdb | msql_drop_db() | mSQL |
msql_fieldflags | msql_field_flags() | mSQL |
msql_fieldlen | msql_field_len() | mSQL |
msql_fieldname | msql_field_name() | mSQL |
msql_fieldtable | msql_field_table() | mSQL |
msql_fieldtype | msql_field_type() | mSQL |
msql_freeresult | msql_free_result() | mSQL |
msql_listdbs | msql_list_dbs() | mSQL |
msql_listfields | msql_list_fields() | mSQL |
msql_listtables | msql_list_tables() | mSQL |
msql_numfields | msql_num_fields() | mSQL |
msql_numrows | msql_num_rows() | mSQL |
msql_regcase | sql_regcase() | mSQL |
msql_selectdb | msql_select_db() | mSQL |
msql_tablename | msql_result() | mSQL |
mssql_affected_rows | sybase_affected_rows() | Sybase |
mssql_affected_rows | sybase_affected_rows() | Sybase |
mssql_close | sybase_close() | Sybase |
mssql_close | sybase_close() | Sybase |
mssql_connect | sybase_connect() | Sybase |
mssql_connect | sybase_connect() | Sybase |
mssql_data_seek | sybase_data_seek() | Sybase |
mssql_data_seek | sybase_data_seek() | Sybase |
mssql_fetch_array | sybase_fetch_array() | Sybase |
mssql_fetch_array | sybase_fetch_array() | Sybase |
mssql_fetch_field | sybase_fetch_field() | Sybase |
mssql_fetch_field | sybase_fetch_field() | Sybase |
mssql_fetch_object | sybase_fetch_object() | Sybase |
mssql_fetch_object | sybase_fetch_object() | Sybase |
mssql_fetch_row | sybase_fetch_row() | Sybase |
mssql_fetch_row | sybase_fetch_row() | Sybase |
mssql_field_seek | sybase_field_seek() | Sybase |
mssql_field_seek | sybase_field_seek() | Sybase |
mssql_free_result | sybase_free_result() | Sybase |
mssql_free_result | sybase_free_result() | Sybase |
mssql_get_last_message | sybase_get_last_message() | Sybase |
mssql_get_last_message | sybase_get_last_message() | Sybase |
mssql_min_client_severity | sybase_min_client_severity() | Sybase |
mssql_min_error_severity | sybase_min_error_severity() | Sybase |
mssql_min_message_severity | sybase_min_message_severity() | Sybase |
mssql_min_server_severity | sybase_min_server_severity() | Sybase |
mssql_num_fields | sybase_num_fields() | Sybase |
mssql_num_fields | sybase_num_fields() | Sybase |
mssql_num_rows | sybase_num_rows() | Sybase |
mssql_num_rows | sybase_num_rows() | Sybase |
mssql_pconnect | sybase_pconnect() | Sybase |
mssql_pconnect | sybase_pconnect() | Sybase |
mssql_query | sybase_query() | Sybase |
mssql_query | sybase_query() | Sybase |
mssql_result | sybase_result() | Sybase |
mssql_result | sybase_result() | Sybase |
mssql_select_db | sybase_select_db() | Sybase |
mssql_select_db | sybase_select_db() | Sybase |
multcolor | swfdisplayitem_multColor() | Ming (flash) |
mysql | mysql_db_query() | MySQL |
mysql_createdb | mysql_create_db() | MySQL |
mysql_db_name | mysql_result() | MySQL |
mysql_dbname | mysql_result() | MySQL |
mysql_dropdb | mysql_drop_db() | MySQL |
mysql_fieldflags | mysql_field_flags() | MySQL |
mysql_fieldlen | mysql_field_len() | MySQL |
mysql_fieldname | mysql_field_name() | MySQL |
mysql_fieldtable | mysql_field_table() | MySQL |
mysql_fieldtype | mysql_field_type() | MySQL |
mysql_freeresult | mysql_free_result() | MySQL |
mysql_listdbs | mysql_list_dbs() | MySQL |
mysql_listfields | mysql_list_fields() | MySQL |
mysql_listtables | mysql_list_tables() | MySQL |
mysql_numfields | mysql_num_fields() | MySQL |
mysql_numrows | mysql_num_rows() | MySQL |
mysql_selectdb | mysql_select_db() | MySQL |
mysql_tablename | mysql_result() | MySQL |
name | domxml_attrname() | DOM XML |
new_child | domxml_new_child() | DOM XML |
new_xmldoc | domxml_new_xmldoc() | DOM XML |
nextframe | swfmovie_nextFrame() | Ming (flash) |
nextframe | swfsprite_nextFrame() | Ming (flash) |
node | domxml_node() | DOM XML |
oci8append | ocicollappend() | OCI8 |
oci8assign | ocicollassign() | OCI8 |
oci8assignelem | ocicollassignelem() | OCI8 |
oci8close | ocicloselob() | OCI8 |
oci8free | ocifreecoll() | OCI8 |
oci8free | ocifreedesc() | OCI8 |
oci8getelem | ocicollgetelem() | OCI8 |
oci8load | ociloadlob() | OCI8 |
oci8max | ocicollmax() | OCI8 |
oci8ocifreecursor | ocifreestatement() | OCI8 |
oci8save | ocisavelob() | OCI8 |
oci8savefile | ocisavelobfile() | OCI8 |
oci8size | ocicollsize() | OCI8 |
oci8trim | ocicolltrim() | OCI8 |
oci8writetemporary | ociwritetemporarylob() | OCI8 |
oci8writetofile | ociwritelobtofile() | OCI8 |
odbc_do | odbc_exec() | OCI8 |
odbc_field_precision | odbc_field_len() | OCI8 |
output | swfmovie_output() | Ming (flash) |
parent | domxml_parent() | DOM XML |
pdf_add_outline | pdf_add_bookmark() | |
pg_clientencoding | pg_client_encoding() | PostgreSQL |
pg_setclientencoding | pg_set_client_encoding() | PostgreSQL |
pos | current() | Base syntax |
recode | recode_string() | Recode |
remove | swfmovie_remove() | Ming (flash) |
remove | swfsprite_remove() | Ming (flash) |
rewind | rewinddir() | Base syntax |
root | domxml_root() | DOM XML |
rotate | swfdisplayitem_rotate() | Ming (flash) |
rotateto | swfdisplayitem_rotateTo() | Ming (flash) |
rotateto | swffill_rotateTo() | Ming (flash) |
save | swfmovie_save() | Ming (flash) |
savetofile | swfmovie_saveToFile() | Ming (flash) |
scale | swfdisplayitem_scale() | Ming (flash) |
scaleto | swfdisplayitem_scaleTo() | Ming (flash) |
scaleto | swffill_scaleTo() | Ming (flash) |
set_attribute | domxml_set_attribute() | DOM XML |
set_content | domxml_set_content() | DOM XML |
setaction | swfbutton_setAction() | Ming (flash) |
setattr | domxml_set_attribute() | DOM XML |
setbackground | swfmovie_setBackground() | Ming (flash) |
setbounds | swftextfield_setBounds() | Ming (flash) |
setcolor | swftext_setColor() | Ming (flash) |
setcolor | swftextfield_setColor() | Ming (flash) |
setdepth | swfdisplayitem_setDepth() | Ming (flash) |
setdimension | swfmovie_setDimension() | Ming (flash) |
setdown | swfbutton_setDown() | Ming (flash) |
setfont | swftext_setFont() | Ming (flash) |
setfont | swftextfield_setFont() | Ming (flash) |
setframes | swfmovie_setFrames() | Ming (flash) |
setframes | swfsprite_setFrames() | Ming (flash) |
setheight | swftext_setHeight() | Ming (flash) |
setheight | swftextfield_setHeight() | Ming (flash) |
sethit | swfbutton_setHit() | Ming (flash) |
setindentation | swftextfield_setIndentation() | Ming (flash) |
setleftfill | swfshape_setleftfill() | Ming (flash) |
setleftmargin | swftextfield_setLeftMargin() | Ming (flash) |
setline | swfshape_setline() | Ming (flash) |
setlinespacing | swftextfield_setLineSpacing() | Ming (flash) |
setmargins | swftextfield_setMargins() | Ming (flash) |
setmatrix | swfdisplayitem_setMatrix() | Ming (flash) |
setname | swfdisplayitem_setName() | Ming (flash) |
setname | swftextfield_setName() | Ming (flash) |
setover | swfbutton_setOver() | Ming (flash) |
setrate | swfmovie_setRate() | Ming (flash) |
setratio | swfdisplayitem_setRatio() | Ming (flash) |
setrightfill | swfshape_setrightfill() | Ming (flash) |
setrightmargin | swftextfield_setRightMargin() | Ming (flash) |
setspacing | swftext_setSpacing() | Ming (flash) |
setup | swfbutton_setUp() | Ming (flash) |
show_source | highlight_file () | Base syntax |
sizeof | count() | Base syntax |
skewx | swfdisplayitem_skewX() | Ming (flash) |
skewxto | swfdisplayitem_skewXTo() | Ming (flash) |
skewxto | swffill_skewXTo() | Ming (flash) |
skewy | swfdisplayitem_skewY() | Ming (flash) |
skewyto | swfdisplayitem_skewYTo() | Ming (flash) |
skewyto | swffill_skewYTo() | Ming (flash) |
snmpwalkoid | snmprealwalk() | SNMP |
strchr | strstr() | Base syntax |
streammp3 | swfmovie_streamMp3() | Ming (flash) |
swfaction | swfaction_init() | Ming (flash) |
swfbitmap | swfbitmap_init() | Ming (flash) |
swfbutton | swfbutton_init() | Ming (flash) |
swffill | swffill_init() | Ming (flash) |
swffont | swffont_init() | Ming (flash) |
swfgradient | swfgradient_init() | Ming (flash) |
swfmorph | swfmorph_init() | Ming (flash) |
swfmovie | swfmovie_init() | Ming (flash) |
swfshape | swfshape_init() | Ming (flash) |
swfsprite | swfsprite_init() | Ming (flash) |
swftext | swftext_init() | Ming (flash) |
swftextfield | swftextfield_init() | Ming (flash) |
unlink | domxml_unlink_node() | DOM XML |
xptr_new_context | xpath_new_context() | DOM XML |
The following is a listing of predefined identifiers in PHP. None of the identifiers listed here should be used as identifiers in a your scripts. These lists include keywords and predefined variable, constant, and class names. These lists are neither exhaustive or complete.
These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on--but they're not, really: they are language constructs. You cannot use any of the following words as constants, class names, or function names. Using them as variable names is generally OK, but could lead to confusion.
Ðßíáêáò H-1. PHP Keywords
and | or | xor | __FILE__ | exception | php_user_filter |
__LINE__ | array() | as | break | case | |
cfunction | class | const | continue | declare | |
default | die() | do | echo() | else | |
elseif | empty() | enddeclare | endfor | endforeach | |
endif | endswitch | endwhile | eval() | exit() | |
extends | for | foreach | function | global | |
if | include() | include_once() | isset() | list() | |
new | old_function | print() | require() | require_once() | |
return() | static | switch | unset() | use | |
var | while | __FUNCTION__ | __CLASS__ | __METHOD__ |
Since PHP 4.1.0, the preferred method for retrieving external variables is with the superglobals mentioned below. Before this time, people relied on either register_globals or the long predefined PHP arrays ($HTTP_*_VARS). Áðü ôçí PHP 5.0.0, ôá ìåãÜëá ðñïêáèïñéóìÝíá óôáèåñÜ array ìðïñïýí íá áðåíåñãïðïéçèïýí ìå ôï register_long_arrays directive.
Óçìåßùóç: Introduced in 4.1.0. In earlier versions, use $HTTP_SERVER_VARS.
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the webserver. There is no guarantee that every webserver will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the CGI 1.1 specification, so you should be able to expect those.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SERVER; to access it within functions or methods, as you do with $HTTP_SERVER_VARS.
$HTTP_SERVER_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_SERVER_VARS and $_SERVER are different variables and that PHP handles them as such)
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_SERVER and $HTTP_SERVER_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
You may or may not find any of the following elements in $_SERVER. Note that few, if any, of these will be available (or indeed have any meaning) if running PHP on the command line.
The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.
If PHP is running as a command-line processor, this variable is not available.
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.
Contains the number of command line parameters passed to the script (if run on the command line).
What revision of the CGI specification the server is using; i.e. 'CGI/1.1'.
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
Server identification string, given in the headers when responding to requests.
Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';
Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
The query string, if any, via which the page was accessed.
The document root directory under which the current script is executing, as defined in the server's configuration file.
Contents of the Accept: header from the current request, if there is one.
Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.
Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'.
Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'.
Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.
Contents of the Host: header from the current request, if there is one.
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: 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 output to the capabilities of the user agent.
The IP address from which the user is viewing the current page.
The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user.
Óçìåßùóç: Your web server must be configured to create this variable. For example in Apache you'll need HostnameLookups On inside httpd.conf for it to exist. See also gethostbyaddr().
The port being used on the user's machine to communicate with the web server.
The absolute pathname of the currently executing script.
Óçìåßùóç: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
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.
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.
String containing the server version and virtual host name which are added to server-generated pages, if enabled.
Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.
Contains the current script's path. This is useful for pages which need to point to themselves.
The URI which was given in order to access this page; for instance, '/index.html'.
When running under Apache as module doing HTTP authentication this variable is set to the username provided by the user.
When running under Apache as module doing HTTP authentication this variable is set to the password provided by the user.
When running under Apache as module doing HTTP authenticated this variable is set to the authentication type.
Óçìåßùóç: Introduced in 4.1.0. In earlier versions, use $HTTP_ENV_VARS.
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.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_ENV; to access it within functions or methods, as you do with $HTTP_ENV_VARS.
$HTTP_ENV_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_ENV_VARS and $_ENV are different variables and that PHP handles them as such)
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_ENV and $HTTP_ENV_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
Óçìåßùóç: Introduced in 4.1.0. In earlier versions, use $HTTP_COOKIE_VARS.
An associative array of variables passed to the current script via HTTP cookies. Automatically global in any scope.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_COOKIE; to access it within functions or methods, as you do with $HTTP_COOKIE_VARS.
$HTTP_COOKIE_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_COOKIE_VARS and $_COOKIE are different variables and that PHP handles them as such)
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_COOKIE and $HTTP_COOKIE_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
Óçìåßùóç: Introduced in 4.1.0. In earlier versions, use $HTTP_GET_VARS.
An associative array of variables passed to the current script via the HTTP GET method. Automatically global in any scope.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_GET; to access it within functions or methods, as you do with $HTTP_GET_VARS.
$HTTP_GET_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_GET_VARS and $_GET are different variables and that PHP handles them as such)
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_GET and $HTTP_GET_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
Óçìåßùóç: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS.
An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.
$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
Óçìåßùóç: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_FILES.
An associative array of items uploaded to the current script via the HTTP POST method. Automatically global in any scope.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_FILES; to access it within functions or methods, as you do with $HTTP_POST_FILES.
$HTTP_POST_FILES contains the same information, but is not an autoglobal.
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_FILES and $HTTP_POST_FILES arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
Óçìåßùóç: Introduced in 4.1.0. There is no equivalent array in earlier versions.
Óçìåßùóç: Prior to PHP 4.3.0, $_FILES information was also included into $_REQUEST.
An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_REQUEST; to access it within functions or methods.
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_REQUEST array. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
Óçìåßùóç: Introduced in 4.1.0. In earlier versions, use $HTTP_SESSION_VARS.
An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS.
$HTTP_SESSION_VARS contains the same information, but is not an autoglobal.
If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_SESSION and $HTTP_SESSION_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
Óçìåßùóç: $GLOBALS has been available since PHP 3.0.0.
An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $GLOBALS; to access it within functions or methods.
$php_errormsg is a variable containing the text of the last error message generated by PHP. This variable will only be available within the scope in which the error occurred, and only if the track_errors configuration option is turned on (it defaults to off).
These classes are defined in the standard set of functions included in the PHP build.
The class from which dir is instantiated.
These additional predefined classes were introduced in PHP 5.0.0
These classes are defined in the Ming extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.
These constants are defined by the PHP core. This includes PHP, the Zend engine, and SAPI modules.
These constants are defined in PHP by default.
The following is a list of functions which create, use or destroy PHP resources. The function is_resource() can be used to determine if a variable is a resource and get_resource_type() will return the type of resource it is.
Ðßíáêáò I-1. Resource Types
Resource Type Name | Created By | Used By | Destroyed By | Definition |
---|---|---|---|---|
aspell | aspell_new() | aspell_check(), aspell_check_raw(), aspell_suggest() | None | Aspell dictionary |
bzip2 | bzopen() | bzerrno(), bzerror(), bzerrstr(), bzflush(), bzread(), bzwrite() | bzclose() | Bzip2 file |
COM | com_load() | com_invoke(), com_propget(), com_get(), com_propput(), com_set(), com_propput() | None | COM object reference |
VARIANT | ||||
cpdf | cpdf_open() | cpdf_page_init(), cpdf_finalize_page(), cpdf_finalize(), cpdf_output_buffer(), cpdf_save_to_file(), cpdf_set_current_page(), cpdf_begin_text(), cpdf_end_text(), cpdf_show(), cpdf_show_xy(), cpdf_text(), cpdf_set_font(), cpdf_set_leading(), cpdf_set_text_rendering(), cpdf_set_horiz_scaling(), cpdf_set_text_rise(), cpdf_set_text_matrix(), cpdf_set_text_pos(), cpdf_set_text_pos(), cpdf_set_word_spacing(), cpdf_continue_text(), cpdf_stringwidth(), cpdf_save(), cpdf_translate(), cpdf_restore(), cpdf_scale(), cpdf_rotate(), cpdf_setflat(), cpdf_setlinejoin(), cpdf_setlinecap(), cpdf_setmiterlimit(), cpdf_setlinewidth(), cpdf_setdash(), cpdf_moveto(), cpdf_rmoveto(), cpdf_curveto(), cpdf_lineto(), cpdf_rlineto(), cpdf_circle(), cpdf_arc(), cpdf_rect(), cpdf_closepath(), cpdf_stroke(), cpdf_closepath_fill_stroke(), cpdf_fill_stroke(), cpdf_clip(), cpdf_fill(), cpdf_setgray_fill(), cpdf_setgray_stroke(), cpdf_setgray(), cpdf_setrgbcolor_fill(), cpdf_setrgbcolor_stroke(), cpdf_setrgbcolor(), cpdf_add_outline(), cpdf_set_page_animation(), cpdf_import_jpeg(), cpdf_place_inline_image(), cpdf_add_annotation() | cpdf_close() | PDF document with CPDF lib |
cpdf outline | ||||
curl | curl_init() | curl_init(), curl_exec() | curl_close() | Curl session |
dbm | dbmopen() | dbmexists(), dbmfetch(), dbminsert(), dbmreplace(), dbmdelete(), dbmfirstkey(), dbmnextkey() | dbmclose() | Link to DBM database |
dba | dba_open() | dba_delete(), dba_exists(), dba_fetch(), dba_firstkey(), dba_insert(), dba_nextkey(), dba_optimize(), dba_replace(), dba_sync() | dba_close() | Link to DBA database |
dba persistent | dba_popen() | dba_delete(), dba_exists(), dba_fetch(), dba_firstkey(), dba_insert(), dba_nextkey(), dba_optimize(), dba_replace(), dba_sync() | None | Persistent link to DBA database |
dbase | dbase_open() | dbase_pack(), dbase_add_record(), dbase_replace_record(), dbase_delete_record(), dbase_get_record(), dbase_get_record_with_names(), dbase_numfields(), dbase_numrecords() | dbase_close() | Link to Dbase database |
dbx_link_object | dbx_connect() | dbx_query() | dbx_close() | dbx connection |
dbx_result_object | dbx_query() | None | dbx result | |
domxml attribute | ||||
domxml document | ||||
domxml node | ||||
xpath context | ||||
xpath object | ||||
fbsql database | fbsql_select_db() | None | fbsql database | |
fbsql link | fbsql_change_user(), fbsql_connect() | fbsql_autocommit(), fbsql_change_user(), fbsql_create_db(), fbsql_data_seek(), fbsql_db_query(), fbsql_drop_db(), (), fbsql_select_db(), fbsql_errno(), fbsql_error(), fbsql_insert_id(), fbsql_list_dbs() | fbsql_close() | Link to fbsql database |
fbsql plink | fbsql_change_user(), fbsql_pconnect() | fbsql_autocommit(), fbsql_change_user(), fbsql_create_db(), fbsql_data_seek(), fbsql_db_query(), fbsql_drop_db(), (), fbsql_select_db(), fbsql_errno(), fbsql_error(), fbsql_insert_id(), fbsql_list_dbs() | None | Persistent link to fbsql database |
fbsql result | fbsql_db_query(), fbsql_list_dbs(), fbsql_query(), fbsql_list_fields(), fbsql_list_tables(), fbsql_tablename() | fbsql_affected_rows(), fbsql_fetch_array(), fbsql_fetch_assoc(), fbsql_fetch_field(), fbsql_fetch_lengths(), fbsql_fetch_object(), fbsql_fetch_row(), fbsql_field_flags(), fbsql_field_name(), fbsql_field_len(), fbsql_field_seek(), fbsql_field_table(), fbsql_field_type(), fbsql_next_result(), fbsql_num_fields(), fbsql_num_rows(), fbsql_result(), fbsql_num_rows() | fbsql_free_result() | fbsql result |
fdf | fdf_open() | fdf_create(), fdf_save(), fdf_get_value(), fdf_set_value(), fdf_next_field_name(), fdf_set_ap(), fdf_set_status(), fdf_get_status(), fdf_set_file(), fdf_get_file(), fdf_set_flags(), fdf_set_opt(), fdf_set_submit_form_action(), fdf_set_javascript_action() | fdf_close() | FDF File |
ftp | ftp_connect() | ftp_login(), ftp_pwd(), ftp_cdup(), ftp_chdir(), ftp_mkdir(), ftp_rmdir(), ftp_nlist(), ftp_rawlist(), ftp_systype(), ftp_pasv(), ftp_get(), ftp_fget(), ftp_put(), ftp_fput(), ftp_size(), ftp_mdtm(), ftp_rename(), ftp_delete(), ftp_site() | ftp_quit() | FTP stream |
gd | imagecreate(), imagecreatefromgif(), imagecreatefromjpeg(), imagecreatefrompng(), imagecreatefromwbmp(), imagecreatefromstring(), imagecreatetruecolor() | imagearc(), imagechar(), imagecharup(), imagecolorallocate(), imagecolorat(), imagecolorclosest(), imagecolorexact(), imagecolorresolve(), imagegammacorrect(), imagegammacorrect(), imagecolorset(), imagecolorsforindex(), imagecolorstotal(), imagecolortransparent(), imagecopy(), imagecopyresized(), imagedashedline(), imagefill(), imagefilledpolygon(), imagefilledrectangle(), imagefilltoborder(), imagegif(), imagepng(), imagejpeg(), imagewbmp(), imageinterlace(), imageline(), imagepolygon(), imagepstext(), imagerectangle(), imagesetpixel(), imagestring(), imagestringup(), imagesx(), imagesy(), imagettftext(), imagefilledarc(), imageellipse(), imagefilledellipse(), imagecolorclosestalpha(), imagecolorexactalpha(), imagecolorresolvealpha(), imagecopymerge(), imagecopymergegray(), imagecopyresampled(), imagetruecolortopalette(), imagesetbrush(), imagesettile(), imagesetthickness() | imagedestroy() | GD Image |
gd font | imageloadfont() | imagechar(), imagecharup(), imagefontheight() | None | Font for GD |
gd PS encoding | ||||
gd PS font | imagepsloadfont() | imagepstext(), imagepsslantfont(), imagepsextendfont(), imagepsencodefont(), imagepsbbox() | imagepsfreefont() | PS font for GD |
GMP integer | gmp_init() | gmp_intval(), gmp_strval(), gmp_add(), gmp_sub(), gmp_mul(), gmp_div_q(), gmp_div_r(), gmp_div_qr(), gmp_div(), gmp_mod(), gmp_divexact(), gmp_cmp(), gmp_neg(), gmp_abs(), gmp_sign(), gmp_fact(), gmp_sqrt(), gmp_sqrtrm(), gmp_perfect_square(), gmp_pow(), gmp_powm(), gmp_prob_prime(), gmp_gcd(), gmp_gcdext(), gmp_invert(), gmp_legendre(), gmp_jacobi(), gmp_random(), gmp_and(), gmp_or(), gmp_xor(), gmp_setbit(), gmp_clrbit(), gmp_scan0(), gmp_scan1(), gmp_popcount(), gmp_hamdist() | None | GMP Number |
hyperwave document | hw_cp(), hw_docbyanchor(), hw_getremote(), hw_getremotechildren() | hw_children(), hw_childrenobj(), hw_getparents(), hw_getparentsobj(), hw_getchildcoll(), hw_getchildcollobj(), hw_getremote(), hw_getsrcbydestobj(), hw_getandlock(), hw_gettext(), hw_getobjectbyquerycoll(), hw_getobjectbyquerycollobj(), hw_getchilddoccoll(), hw_getchilddoccollobj(), hw_getanchors(), hw_getanchorsobj(), hw_inscoll(), hw_pipedocument(), hw_unlock() | hw_deleteobject() | Hyperwave object |
hyperwave link | hw_connect() | hw_children(), hw_childrenobj(), hw_cp(), hw_deleteobject(), hw_docbyanchor(), hw_docbyanchorobj(), hw_errormsg(), hw_edittext(), hw_error(), hw_getparents(), hw_getparentsobj(), hw_getchildcoll(), hw_getchildcollobj(), hw_getremote(), hw_getremotechildren(), hw_getsrcbydestobj(), hw_getobject(), hw_getandlock(), hw_gettext(), hw_getobjectbyquery(), hw_getobjectbyqueryobj(), hw_getobjectbyquerycoll(), hw_getobjectbyquerycollobj(), hw_getchilddoccoll(), hw_getchilddoccollobj(), hw_getanchors(), hw_getanchorsobj(), hw_mv(), hw_incollections(), hw_info(), hw_inscoll(), hw_insdoc(), hw_insertdocument(), hw_insertobject(), hw_mapid(), hw_modifyobject(), hw_pipedocument(), hw_unlock(), hw_who(), hw_getusername() | hw_close(), hw_free_document() | Link to Hyperwave server |
hyperwave link persistent | hw_pconnect() | hw_children(), hw_childrenobj(), hw_cp(), hw_deleteobject(), hw_docbyanchor(), hw_docbyanchorobj(), hw_errormsg(), hw_edittext(), hw_error(), hw_getparents(), hw_getparentsobj(), hw_getchildcoll(), hw_getchildcollobj(), hw_getremote(), hw_getremotechildren(), hw_getsrcbydestobj(), hw_getobject(), hw_getandlock(), hw_gettext(), hw_getobjectbyquery(), hw_getobjectbyqueryobj(), hw_getobjectbyquerycoll(), hw_getobjectbyquerycollobj(), hw_getchilddoccoll(), hw_getchilddoccollobj(), hw_getanchors(), hw_getanchorsobj(), hw_mv(), hw_incollections(), hw_info(), hw_inscoll(), hw_insdoc(), hw_insertdocument(), hw_insertobject(), hw_mapid(), hw_modifyobject(), hw_pipedocument(), hw_unlock(), hw_who(), hw_getusername() | None | Persistent link to Hyperwave server |
icap | icap_open() | icap_fetch_event(), icap_list_events(), icap_store_event(), icap_snooze(), icap_list_alarms(), icap_delete_event() | icap_close() | Link to icap server |
imap | imap_open() | imap_append(), imap_body(), imap_check(), imap_createmailbox(), imap_delete(), imap_deletemailbox(), imap_expunge(), imap_fetchbody(), imap_fetchstructure(), imap_headerinfo(), imap_header(), imap_headers(), imap_listmailbox(), imap_getmailboxes(), imap_get_quota(), imap_status(), imap_listsubscribed(), imap_set_quota(), imap_set_quota(), imap_getsubscribed(), imap_mail_copy(), imap_mail_move(), imap_num_msg(), imap_num_recent(), imap_ping(), imap_renamemailbox(), imap_reopen(), imap_subscribe(), imap_undelete(), imap_unsubscribe(), imap_scanmailbox(), imap_mailboxmsginfo(), imap_fetchheader(), imap_uid(), imap_msgno(), imap_search(), imap_fetch_overview() | imap_close() | Link to IMAP, POP3 server |
imap chain persistent | ||||
imap persistent | ||||
ingres | ingres_connect() | ingres_query(), ingres_num_rows(), ingres_num_fields(), ingres_field_name(), ingres_field_type(), ingres_field_nullable(), ingres_field_length(), ingres_field_precision(), ingres_field_scale(), ingres_fetch_array(), ingres_fetch_row(), ingres_fetch_object(), ingres_rollback(), ingres_commit(), ingres_autocommit() | ingres_close() | Link to ingresII base |
ingres persistent | ingres_pconnect() | ingres_query(), ingres_num_rows(), ingres_num_fields(), ingres_field_name(), ingres_field_type(), ingres_field_nullable(), ingres_field_length(), ingres_field_precision(), ingres_field_scale(), ingres_fetch_array(), ingres_fetch_row(), ingres_fetch_object(), ingres_rollback(), ingres_commit(), ingres_autocommit() | None | Persistent link to ingresII base |
interbase blob | ||||
interbase link | ibase_connect() | ibase_query(), ibase_prepare(), ibase_trans() | ibase_close() | Link to Interbase database |
interbase link persistent | ibase_pconnect() | ibase_query(), ibase_prepare(), ibase_trans() | None | Persistent link to Interbase database |
interbase query | ibase_prepare() | ibase_execute() | ibase_free_query() | Interbase query |
interbase result | ibase_query() | ibase_fetch_row(), ibase_fetch_object(), ibase_field_info(), ibase_num_fields() | ibase_free_result() | Interbase Result |
interbase transaction | ibase_trans() | ibase_commit() | ibase_rollback() | Interbase transaction |
java | ||||
ldap link | ldap_connect(), ldap_search() | ldap_count_entries(), ldap_first_attribute(), ldap_first_entry(), ldap_get_attributes(), ldap_get_dn(), ldap_get_entries(), ldap_get_values(), ldap_get_values_len(), ldap_next_attribute(), ldap_next_entry() | ldap_close() | ldap connection |
ldap result | ldap_read() | ldap_add(), ldap_compare(), ldap_bind(), ldap_count_entries(), ldap_delete(), ldap_errno(), ldap_error(), ldap_first_attribute(), ldap_first_entry(), ldap_get_attributes(), ldap_get_dn(), ldap_get_entries(), ldap_get_values(), ldap_get_values_len(), ldap_get_option(), ldap_list(), ldap_modify(), ldap_mod_add(), ldap_mod_replace(), ldap_next_attribute(), ldap_next_entry(), ldap_mod_del(), ldap_set_option(), ldap_unbind() | ldap_free_result() | ldap search result |
ldap result entry | ||||
mcal | mcal_open(), mcal_popen() | mcal_create_calendar(), mcal_rename_calendar(), mcal_rename_calendar(), mcal_delete_calendar(), mcal_fetch_event(), mcal_list_events(), mcal_append_event(), mcal_store_event(), mcal_delete_event(), mcal_list_alarms(), mcal_event_init(), mcal_event_set_category(), mcal_event_set_title(), mcal_event_set_description(), mcal_event_set_start(), mcal_event_set_end(), mcal_event_set_alarm(), mcal_event_set_class(), mcal_next_recurrence(), mcal_event_set_recur_none(), mcal_event_set_recur_daily(), mcal_event_set_recur_weekly(), mcal_event_set_recur_monthly_mday(), mcal_event_set_recur_monthly_wday(), mcal_event_set_recur_yearly(), mcal_fetch_current_stream_event(), mcal_event_add_attribute(), mcal_expunge() | mcal_close() | Link to calendar server |
SWFAction | ||||
SWFBitmap | ||||
SWFButton | ||||
SWFDisplayItem | ||||
SWFFill | ||||
SWFFont | ||||
SWFGradient | ||||
SWFMorph | ||||
SWFMovie | ||||
SWFShape | ||||
SWFSprite | ||||
SWFText | ||||
SWFTextField | ||||
mnogosearch agent | ||||
mnogosearch result | ||||
msql link | msql_connect() | msql(), msql_create_db(), msql_createdb(), msql_drop_db(), msql_drop_db(), msql_select_db(), msql_select_db() | msql_close() | Link to mSQL database |
msql link persistent | msql_pconnect() | msql(), msql_create_db(), msql_createdb(), msql_drop_db(), msql_drop_db(), msql_select_db(), msql_select_db() | None | Persistent link to mSQL |
msql query | msql_query() | msql(), msql_affected_rows(), msql_data_seek(), msql_dbname(), msql_fetch_array(), msql_fetch_field(), msql_fetch_object(), msql_fetch_row(), msql_fieldname(), msql_field_seek(), msql_fieldtable(), msql_fieldtype(), msql_fieldflags(), msql_fieldlen(), msql_num_fields(), msql_num_rows(), msql_numfields(), msql_numrows(), msql_result() | msql_free_result(), msql_free_result() | mSQL result |
mssql link | mssql_connect() | mssql_query(), mssql_select_db() | mssql_close() | Link to Microsft SQL Server database |
mssql link persistent | mssql_pconnect() | mssql_query(), mssql_select_db() | None | Persistent link to Microsft SQL Server |
mssql result | mssql_query() | mssql_data_seek(), mssql_fetch_array(), mssql_fetch_field(), mssql_fetch_object(), mssql_fetch_row(), mssql_field_length(), mssql_field_name(), mssql_field_seek(), mssql_field_type(), mssql_num_fields(), mssql_num_rows(), mssql_result() | mssql_free_result() | Microsft SQL Server result |
mysql link | mysql_connect() | mysql_affected_rows(), mysql_change_user(), mysql_create_db(), mysql_data_seek(), mysql_db_name(), mysql_db_query(), mysql_drop_db(), mysql_errno(), mysql_error(), mysql_insert_id(), mysql_list_dbs(), mysql_list_fields(), mysql_list_tables(), mysql_query(), mysql_result(), mysql_select_db(), mysql_tablename(), mysql_get_host_info(), mysql_get_proto_info(), mysql_get_server_info() | mysql_close() | Link to MySQL database |
mysql link persistent | mysql_pconnect() | mysql_affected_rows(), mysql_change_user(), mysql_create_db(), mysql_data_seek(), mysql_db_name(), mysql_db_query(), mysql_drop_db(), mysql_errno(), mysql_error(), mysql_insert_id(), mysql_list_dbs(), mysql_list_fields(), mysql_list_tables(), mysql_query(), mysql_result(), mysql_select_db(), mysql_tablename(), mysql_get_host_info(), mysql_get_proto_info(), mysql_get_server_info() | None | Persistent link to MySQL database |
mysql result | mysql_db_query(), mysql_list_dbs(), mysql_list_fields(), mysql_list_tables(), mysql_query() | mysql_data_seek(), mysql_db_name(), mysql_fetch_array(), mysql_fetch_assoc(), mysql_fetch_field(), mysql_fetch_lengths(), mysql_fetch_object(), mysql_fetch_row(), mysql_fetch_row(), mysql_field_flags(), mysql_field_name(), mysql_field_len(), mysql_field_seek(), mysql_field_table(), mysql_field_type(), mysql_num_fields(), mysql_num_rows(), mysql_result(), mysql_tablename() | mysql_free_result() | MySQL result |
oci8 collection | ||||
oci8 connection | ocilogon(), ociplogon(), ocinlogon() | ocicommit(), ociserverversion(), ocinewcursor(), ociparse(), ocierror() | ocilogoff() | Link to Oracle database |
oci8 descriptor | ||||
oci8 server | ||||
oci8 session | ||||
oci8 statement | ocinewdescriptor() | ocirollback(), ocinewdescriptor(), ocirowcount(), ocidefinebyname(), ocibindbyname(), ociexecute(), ocinumcols(), ociresult(), ocifetch(), ocifetchinto(), ocifetchstatement(), ocicolumnisnull(), ocicolumnname(), ocicolumnsize(), ocicolumntype(), ocistatementtype(), ocierror() | ocifreestatement() | Oracle Cursor |
odbc link | odbc_connect() | odbc_autocommit(), odbc_commit(), odbc_error(), odbc_errormsg(), odbc_exec(), odbc_tables(), odbc_tableprivileges(), odbc_do(), odbc_prepare(), odbc_columns(), odbc_columnprivileges(), odbc_procedurecolumns(), odbc_specialcolumns(), odbc_rollback(), odbc_setoption(), odbc_gettypeinfo(), odbc_primarykeys(), odbc_foreignkeys(), odbc_procedures(), odbc_statistics() | odbc_close() | Link to ODBC database |
odbc link persistent | odbc_connect() | odbc_autocommit(), odbc_commit(), odbc_error(), odbc_errormsg(), odbc_exec(), odbc_tables(), odbc_tableprivileges(), odbc_do(), odbc_prepare(), odbc_columns(), odbc_columnprivileges(), odbc_procedurecolumns(), odbc_specialcolumns(), odbc_rollback(), odbc_setoption(), odbc_gettypeinfo(), odbc_primarykeys(), odbc_foreignkeys(), odbc_procedures(), odbc_statistics() | None | Persistent link to ODBC database |
odbc result | odbc_prepare() | odbc_binmode(), odbc_cursor(), odbc_execute(), odbc_fetch_into(), odbc_fetch_row(), odbc_field_name(), odbc_field_num(), odbc_field_type(), odbc_field_len(), odbc_field_precision(), odbc_field_scale(), odbc_longreadlen(), odbc_num_fields(), odbc_num_rows(), odbc_result(), odbc_result_all(), odbc_setoption() | odbc_free_result() | ODBC result |
birdstep link | ||||
birdstep result | ||||
OpenSSL key | openssl_get_privatekey(), openssl_get_publickey() | openssl_sign(), openssl_seal(), openssl_open(), openssl_verify() | openssl_free_key() | OpenSSL key |
OpenSSL X.509 | openssl_x509_read() | openssl_x509_parse(), openssl_x509_checkpurpose() | openssl_x509_free() | Public Key |
oracle Cursor | ora_open() | ora_bind(), ora_columnname(), ora_columnsize(), ora_columntype(), ora_error(), ora_errorcode(), ora_exec(), ora_fetch(), ora_fetch_into(), ora_getcolumn(), ora_numcols(), ora_numrows(), ora_parse() | ora_close() | Oracle cursor |
oracle link | ora_logon() | ora_do(), ora_error(), ora_errorcode(), ora_rollback(), ora_commitoff(), ora_commiton(), ora_open(), ora_commit() | ora_logoff() | Link to oracle database |
oracle link persistent | ora_plogon() | ora_do(), ora_error(), ora_errorcode(), ora_rollback(), ora_commitoff(), ora_commiton(), ora_open(), ora_commit() | None | Persistent link to oracle database |
pdf document | pdf_new() | pdf_add_bookmark(), pdf_add_launchlink(), pdf_add_locallink(), pdf_add_note(), pdf_add_pdflink(), pdf_add_weblink(), pdf_arc(), pdf_attach_file(), pdf_begin_page(), pdf_circle(), pdf_clip(), pdf_closepath(), pdf_closepath_fill_stroke(), pdf_closepath_stroke(), pdf_concat(), pdf_continue_text(), pdf_curveto(), pdf_end_page(), pdf_endpath(), pdf_fill(), pdf_fill_stroke(), pdf_findfont(), pdf_get_buffer(), pdf_get_image_height(), pdf_get_image_width(), pdf_get_parameter(), pdf_get_value(), pdf_lineto(), pdf_moveto(), pdf_open_ccitt(), pdf_open_file(), pdf_open_image_file(), pdf_place_image(), pdf_rect(), pdf_restore(), pdf_rotate(), pdf_save(), pdf_scale(), pdf_setdash(), pdf_setflat(), pdf_setfont(), pdf_setgray(), pdf_setgray_fill(), pdf_setgray_stroke(), pdf_setlinecap(), pdf_setlinejoin(), pdf_setlinewidth(), pdf_setmiterlimit(), pdf_setpolydash(), pdf_setrgbcolor(), pdf_setrgbcolor_fill(), pdf_setrgbcolor_stroke(), pdf_set_border_color(), pdf_set_border_dash(), pdf_set_border_style(), pdf_set_char_spacing(), pdf_set_duration(), pdf_set_font(), pdf_set_horiz_scaling(), pdf_set_parameter(), pdf_set_text_pos(), pdf_set_text_rendering(), pdf_set_value(), pdf_set_word_spacing(), pdf_show(), pdf_show_boxed(), pdf_show_xy(), pdf_skew(), pdf_stringwidth(), pdf_stroke(), pdf_translate(), pdf_open_memory_image() | pdf_close(), pdf_delete() | PDF document |
pdf image | pdf_open_image(), pdf_open_image_file(), pdf_open_memory_image() | pdf_get_image_height(), pdf_get_image_width(), pdf_open_CCITT(), pdf_place_image() | pdf_close_image() | Image in PDF file |
pdf object | ||||
pdf outline | ||||
pgsql large object | pg_lo_open() | pg_lo_open(), pg_lo_create(), pg_lo_read(), pg_lo_read_all(), pg_lo_seek(), pg_lo_tell(), pg_lo_unlink(), pg_lo_write() | pg_lo_close() | PostgreSQL Large Object |
pgsql link | pg_connect() | pg_affected_rows(), pg_query(), pg_send_query(), pg_get_result(), pg_connection_busy(), pg_connection_reset(), pg_connection_status(), pg_last_error(), pg_last_notice(), pg_lo_create(), pg_lo_export(), pg_lo_import(), pg_lo_open(), pg_lo_unlink(), pg_host(), pg_port(), pg_dbname(), pg_options(), pg_copy_from(), pg_copy_to(), pg_end_copy(), pg_put_line(), pg_tty(), pg_trace(), pg_untrace(), pg_set_client_encoding(), pg_client_encoding(), pg_metadata(), pg_convert(), pg_insert(), pg_select(), pg_delete(), pg_update() | pg_close() | Link to PostgreSQL database |
pgsql link persistent | pg_pconnect() | pg_affected_rows(), pg_query(), pg_send_query(), pg_get_result(), pg_connection_busy(), pg_connection_reset(), pg_connection_status(), pg_last_error(), pg_last_notice(), pg_lo_create(), pg_lo_export(), pg_lo_import(), pg_lo_open(), pg_lo_unlink(), pg_host(), pg_port(), pg_dbname(), pg_options(), pg_copy_from(), pg_copy_to(), pg_end_copy(), pg_put_line(), pg_tty(), pg_trace(), pg_untrace(), pg_set_client_encoding(), pg_client_encoding(), pg_metadata(), pg_convert(), pg_insert(), pg_select(), pg_delete(), pg_update() | None | Persistent link to PostgreSQL database |
pgsql result | pg_query(), pg_get_result() | pg_fetch_array(), pg_fetch_object(), pg_fetch_result(), pg_fetch_row(), pg_field_is_null(), pg_field_name(), pg_field_num(), pg_field_prtlen(), pg_field_size(), pg_field_type(), pg_last_oid(), pg_num_fields(), pg_num_rows(), pg_result_error(), pg_result_status() | pg_free_result() | PostgreSQL result |
pgsql string | ||||
printer | ||||
printer brush | ||||
printer font | ||||
printer pen | ||||
pspell | pspell_new(), pspell_new_config(), pspell_new_personal() | pspell_add_to_personal(), pspell_add_to_session(), pspell_check(), pspell_clear_session(), pspell_config_ignore(), pspell_config_mode(), pspell_config_personal(), pspell_config_repl(), pspell_config_runtogether(), pspell_config_save_repl(), pspell_save_wordlist(), pspell_store_replacement(), pspell_suggest() | None | pspell dictionary |
pspell config | pspell_config_create() | pspell_new_config() | None | pspell configuration |
Sablotron XSLT | xslt_create() | xslt_closelog(), xslt_openlog(), xslt_run(), xslt_set_sax_handler(), xslt_errno(), xslt_error(), xslt_fetch_result(), xslt_free() | xslt_free() | XSLT parser |
shmop | shmop_open() | shmop_read(), shmop_write(), shmop_size(), shmop_delete() | shmop_close() | |
sockets file descriptor set | socket() | accept_connect(), bind(), connect(), listen(), read(), write() | close() | Socket |
sockets i/o vector | ||||
dir | dir() | readdir(), rewinddir() | closedir() | Dir handle |
file | fopen() | feof(), fflush(), fgetc(), fgetcsv(), fgets(), fgetss(), flock(), fpassthru(), fputs(), fwrite(), fread(), fseek(), ftell(), fstat(), ftruncate(), set_file_buffer(), rewind() | fclose() | File handle |
pipe | popen() | feof(), fflush(), fgetc(), fgetcsv(), fgets(), fgetss(), fpassthru(), fputs(), fwrite(), fread() | pclose() | Process handle |
socket | fsockopen() | fflush(), fgetc(), fgetcsv(), fgets(), fgetss(), fpassthru(), fputs(), fwrite(), fread() | fclose() | Socket handle |
stream | ||||
sybase-db link | sybase_connect() | sybase_query(), sybase_select_db() | sybase_close() | Link to Sybase database using DB library |
sybase-db link persistent | sybase_pconnect() | sybase_query(), sybase_select_db() | None | Persistent link to Sybase database using DB library |
sybase-db result | sybase_query() | sybase_data_seek(), sybase_fetch_array(), sybase_fetch_field(), sybase_fetch_object(), sybase_fetch_row(), sybase_field_seek(), sybase_num_fields(), sybase_num_rows(), sybase_result() | sybase_free_result() | Sybase result using DB library |
sybase-ct link | sybase_connect() | sybase_affected_rows(), sybase_query(), sybase_select_db() | sybase_close() | Link to Sybase database using CT library |
sybase-ct link persistent | sybase_pconnect() | sybase_affected_rows(), sybase_query(), sybase_select_db() | None | Persistent link to Sybase database using CT library |
sybase-ct result | sybase_query() | sybase_data_seek(), sybase_fetch_array(), sybase_fetch_field(), sybase_fetch_object(), sybase_fetch_row(), sybase_field_seek(), sybase_num_fields(), sybase_num_rows(), sybase_result() | sybase_free_result() | Sybase result using CT library |
sysvsem | sem_get() | sem_acquire() | sem_release() | System V Semaphore |
sysvshm | shm_attach() | shm_remove(), shm_put_var(), shm_get_var(), shm_remove_var() | shm_detach() | System V Shared Memory |
wddx | wddx_packet_start() | wddx_add_vars() | wddx_packet_end() | WDDX packet |
xml | xml_parser_create() | xml_set_object(), xml_set_element_handler(), xml_set_character_data_handler(), xml_set_processing_instruction_handler(), xml_set_default_handler(), xml_set_unparsed_entity_decl_handler(), xml_set_notation_decl_handler(), xml_set_external_entity_ref_handler(), xml_parse(), xml_get_error_code(), xml_error_string(), xml_get_current_line_number(), xml_get_current_column_number(), xml_get_current_byte_index(), xml_parse_into_struct(), xml_parser_set_option(), xml_parser_get_option() | xml_parser_free() | XML parser |
zlib | gzopen() | gzeof(), gzgetc(), gzgets(), gzgetss(), gzpassthru(), gzputs(), gzread(), gzrewind(), gzseek(), gztell(), gzwrite() | gzclose() | gz-compressed file |
The following is a list of the various URL style protocols that PHP has built-in for use with the filesystem functions such as fopen() and copy(). In addition to these wrappers, as of PHP 4.3.0, you can write your own wrappers using PHP script and stream_wrapper_register().
All versions of PHP. Explicitly using file:// since PHP 4.3.0
/path/to/file.ext
relative/path/to/file.ext
fileInCwd.ext
C:/path/to/winfile.ext
C:\path\to\winfile.ext
\\smbserver\share\path\to\winfile.ext
file:///path/to/file.ext
file:// is the default wrapper used with PHP and represents the local filesystem. When a relative path is specified (a path which does not begin with /, \, \\, or a windows drive letter) the path provided will be applied against the current working directory. In many cases this is the directory in which the script resides unless it has been changed. Using the CLI sapi, this defaults to the directory from which the script was called.
With some functions, such as fopen() and file_get_contents(), include_path may be optionally searched for relative paths as well.
PHP 3, PHP 4. https:// since PHP 4.3.0
http://example.com
http://example.com/file.php?var1=val1&var2=val2
http://user:password@example.com
https://example.com
https://example.com/file.php?var1=val1&var2=val2
https://user:password@example.com
Allows read-only access to files/resources via HTTP 1.0, using the HTTP GET method. A Host: header is sent with the request to handle name-based virtual hosts. If you have configured a user_agent string using your ini file or the stream context, it will also be included in the request.
Ðñïåéäïðïßçóç |
Some non-standard compliant webservers, such as IIS, send data in a way that causes PHP to raise warnings. When working with such servers you should lower your error_reporting level not to include warnings. |
Redirects have been supported since PHP 4.0.5; if you are using an earlier version you will need to include trailing slashes in your URLs. If it's important to know the URL of the resource where your document came from (after all redirects have been processed), you'll need to process the series of response headers returned by the stream.
<?php $url = 'http://www.example.com/redirecting_page.php'; $fp = fopen($url, 'r'); /* Prior to PHP 4.3.0 use $http_response_header instead of stream_get_meta_data() */ foreach(stream_get_meta_data($fp) as $response) { /* Were we redirected? */ if (substr(strtolower($response), 0, 10) == 'location: ') { /* update $url with where we were redirected to */ $url = substr($response, 10); } } ?> |
The stream allows access to the body of the resource; the headers are stored in the $http_response_header variable. Since PHP 4.3.0, the headers are available using stream_get_meta_data().
HTTP connections are read-only; you cannot write data or copy files to an HTTP resource.
Óçìåßùóç: HTTPS is supported starting from PHP 4.3.0, if you have compiled in support for OpenSSL.
Ðßíáêáò J-2. Wrapper Summary
Attribute | Supported |
---|---|
Restricted by allow_url_fopen. | Yes |
Allows Reading | Yes |
Allows Writing | No |
Allows Appending | No |
Allows Simultaneous Reading and Writing | N/A |
Supports stat() | No |
Supports unlink() | No |
Supports rename() | No |
Supports mkdir() | No |
Supports rmdir() | No |
Ðßíáêáò J-3. Context options (as of PHP 5.0.0)
Name | Usage | Default |
---|---|---|
method | GET, POST, or any other HTTP method supported by the remote server. | GET |
header | Additional headers to be sent during request. Values in this option will override other values (such as User-agent:, Host:, and Authentication:). | |
user_agent | Value to send with User-Agent: header. This value will only be used if user-agent is not specified in the header context option above. | php.ini setting: user_agent |
content | Additional data to be sent after the headers. Typically used with POST or PUT requests. | |
proxy | URI specifying address of proxy server. (e.g. tcp://proxy.example.com:5100 ). | |
request_fulluri | When set to TRUE, the entire URI will be used when constructing the request. (i.e. GET http://www.example.com/path/to/file.html HTTP/1.0). While this is a non-standard request format, some proxy servers require it. | FALSE |
Underlying socket stream context options: Additional context options may be supported by the underlying transport For http:// streams, refer to context options for the tcp:// transport. For https:// streams, refer to context options for the ssl:// transport.
PHP 3, PHP 4. ftps:// since PHP 4.3.0
ftp://example.com/pub/file.txt
ftp://user:password@example.com/pub/file.txt
ftps://example.com/pub/file.txt
ftps://user:password@example.com/pub/file.txt
Allows read access to existing files and creation of new files via FTP. If the server does not support passive mode ftp, the connection will fail.
You can open files for either reading or writing, but not both simultaneously. If the remote file already exists on the ftp server and you attempt to open it for writing but have not specified the context option overwrite, the connection will fail. If you need to overwrite existing files over ftp, specify the overwrite option in the context and open the file for writing. Alternatively, you can use the FTP extension.
Appending: As of PHP 5.0.0 files may be appended via the ftp:// URL wrapper. In prior versions, attempting to append to a file via ftp:// will result in failure.
ftps:// was introduced in PHP 4.3.0. It is the same as ftp://, but attempts to negotiate a secure connection with the ftp server. If the server does not support SSL, then the connection falls back to regular unencrypted ftp.
Óçìåßùóç: FTPS is supported starting from PHP 4.3.0, if you have compiled in support for OpenSSL.
Ðßíáêáò J-4. Wrapper Summary
Attribute | PHP 4 | PHP 5 |
---|---|---|
Restricted by allow_url_fopen. | Yes | Yes |
Allows Reading | Yes | Yes |
Allows Writing | Yes (new files only) | Yes (new files/existing files with overwrite) |
Allows Appending | No | Yes |
Allows Simultaneous Reading and Writing | No | No |
Supports stat() | No | filesize(), filetype(), file_exists(), is_file(), and is_dir() elements only. |
Supports unlink() | No | Yes |
Supports rename() | No | Yes |
Supports mkdir() | No | Yes |
Supports rmdir() | No | Yes |
Ðßíáêáò J-5. Context options (as of PHP 5.0.0)
Name | Usage | Default |
---|---|---|
overwrite | Allow overwriting of already existing files on remote server. Applies to write mode (uploading) only. | FALSE (Disabled) |
resume_pos | File offset at which to begin transfer. Applies to read mode (downloading) only. | 0 (Beginning of File) |
Underlying socket stream context options: Additional context options may be supported by the underlying transport For ftp:// streams, refer to context options for the tcp:// transport. For ftps:// streams, refer to context options for the ssl:// transport.
PHP 3.0.13 and up, php://output and php://input since PHP 4.3.0, php://filter since PHP 5.0.0
php://stdin
php://stdout
php://stderr
php://output
php://input
php://filter
php://stdin, php://stdout and php://stderr allow access to the corresponding input or output stream of the PHP process.
php://output allows you to write to the output buffer mechanism in the same way as print() and echo().
php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives.
php://stdin and php://input are read-only, whereas php://stdout, php://stderr and php://output are write-only.
php://filter is a kind of meta-wrapper designed to permit the application of filters to a stream at the time of opening. This is useful with all-in-one file functions such as readfile(), file(), and file_get_contents() where there is otherwise no opportunity to apply a filter to the stream prior the contents being read.
The php://filter target takes the following 'parameters' as parts of its 'path'.
/resource=<stream to be filtered> (required) This parameter must be located at the end of your php://filter specification and should point to the stream which you want filtered.
/read=<filter list to apply to read chain> (optional) This parameter takes one or more filternames separated by the pipe character |.
<?php /* This will output the contents of www.example.com entirely in uppercase */ readfile("php://filter/read=string.toupper/resource=http://www.example.com"); /* This will do the same as above but will also ROT13 encode it */ readfile("php://filter/read=string.toupper|string.rot13/resource=http://www.example.com"); ?> |
/write=<filter list to apply to write chain> (optional) This parameter takes one or more filternames separated by the pipe character |.
/<filter list to apply to both chains> (optional) Any filter lists which are not prefixed specifically by read= or write= will be applied to both the read and write chains (as appropriate).
Ðßíáêáò J-6. Wrapper Summary (For php://filter, refer to summary of wrapper being filtered.)
Attribute | Supported |
---|---|
Restricted by allow_url_fopen. | No |
Allows Reading | php://stdin and php://input only. |
Allows Writing | php://stdout, php://stderr, and php://output only. |
Allows Appending | php://stdout, php://stderr, and php://output only. (Equivalent to writing) |
Allows Simultaneous Reading and Writing | No. These wrappers are unidirectional. |
Supports stat() | No |
Supports unlink() | No |
Supports rename() | No |
Supports mkdir() | No |
Supports rmdir() | No |
zlib: PHP 4.0.4 - PHP 4.2.3 (systems with fopencookie only)
compress.zlib:// and compress.bzip2:// PHP 4.3.0 and up
zlib:
compress.zlib://
compress.bzip2://
zlib: works like gzopen(), except that the stream can be used with fread() and the other filesystem functions. This is deprecated as of PHP 4.3.0 due to ambiguities with filenames containing ':' characters; use compress.zlib:// instead.
compress.zlib:// and compress.bzip2:// are equivalent to gzopen() and bzopen() respectively, and operate even on systems that do not support fopencookie.
Ðßíáêáò J-7. Wrapper Summary
Attribute | Supported |
---|---|
Restricted by allow_url_fopen. | No |
Allows Reading | Yes |
Allows Writing | Yes |
Allows Appending | Yes |
Allows Simultaneous Reading and Writing | No |
Supports stat() | No, use the normal file:// wrapper to stat compressed files. |
Supports unlink() | No, use the normal file:// wrapper to unlink compressed files. |
Supports rename() | No |
Supports mkdir() | No |
Supports rmdir() | No |
The following is a list of a few built-in stream filters for use with stream_filter_append(). Your version of PHP may have more filters (or fewer) than those listed here.
It is worth noting a slight asymmetry between stream_filter_append() and stream_filter_prepend(). Every PHP stream contains a small read buffer where it stores blocks of data retrieved from the filesystem or other resource in order to process data in the most efficient manner. As soon as data is pulled from the resource into the stream's internal buffer, it is immediately processed through any attached filters whether the PHP application is actually ready for the data or not. If data is sitting in the read buffer when a filter is appended, this data will be immediately processed through that buffer making the fact that is was sitting in the buffer seem transparent. However, if data is sitting in the read buffer when a filter is prepended, this data will NOT be processed through that filter. It will instead wait until the next block of data is retrieved from the resource.
For a list of filters installed in your version of PHP use stream_get_filters().
Each of these filters does precisely what their name implies and correspond to the behavior of a built-in php string handling function. For more information on a given filter, refer to the manual page for the corresponding function.
string.rot13 (since PHP 4.3.0) Use of this filter is equivalent to processing all stream data through the str_rot13() function.
string.toupper (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the strtoupper() function.
string.tolower (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the strtolower() function.
string.strip_tags (since PHP 5.0.0) Use of this filter is equivalent to processing all stream data through the strip_tags() function. It accepts parameters in one of two forms: Either as a string containing a list of tags similar to the second parameter of the strip_tags() function, or as an array of tag names.
ÐáñÜäåéãìá K-4. string.strip_tags
|
Like the string.* filters, the convert.* filters perform actions similar to their names. The convert filters were added with PHP 5.0.0. For more information on a given filter, refer to the manual page for the corresponding function.
convert.base64-encode and convert.base64-decode Use of these filters are equivalent to processing all stream data through the base64_encode() and base64_decode() functions respectively. convert.base64-encode supports parameters given as an associative array. If line-length is given, the base64 output will be split into chunks of line-length characters each. If line-break-chars is given, each chunk will be delimited by the characters given. These parameters give the same effect as using base64_encode() with chunk_split().
ÐáñÜäåéãìá K-5. convert.base64-encode & convert.base64-decode
|
convert.quoted-printable-encode and convert.quoted-printable-decode Use of the decode version of this filter is equivalent to processing all stream data through the quoted_printable_decode() functions. There is no function equivalent to convert.quoted-printable-encode. convert.quoted-printable-encode supports parameters given as an associative array. In addition to the parameters supported by convert.base64-encode, convert.quoted-printable-encode also supports boolean arguments binary and force-encode-first. convert.base64-decode only supports the line-break-chars parameter as a type-hint for striping from the encoded payload.
While the ôï ôìÞìá ìå üíïìá Compression Streams óå ÐáñÜñôçìá J provide a way of creating gzip and bz2 compatable files on the local filesystem, they do not provide a means for generalized compression over network streams, nor do they provide a means to begin with a non-compressed stream and transition to a compressed one. For this, a compression filter may be applied to any stream resource at any time.
Óçìåßùóç: Compression filters do not generate headers and trailers used by commandline utilites such as gzip. They only compress and decompress the payload portions of compressed data streams.
zlib.deflate (compression) and zlib.inflate (decompression) are implementations of the compression methods described in RFC 1951. The deflate filter takes up to three parameters passed as an associative array. level describes the compression strength to use (1-9). Higher numbers will generally yield smaller payloads at the cost of additional processing time. Two special compression levels also exist: 0 (for no compression at all), and -1 (zlib internal default -- currently 6). window is the base-2 log of the compression loopback window size. Higher values (up to 15 -- 32768 bytes) yield better compression at a cost of memory, while lower values (down to 9 -- 512 bytes) yield worse compression in a smaller memory footprint. Default window size is currently 15. memory is a scale indicating how much work memory should be allocated. Valid values range from 1 (minimal allocation) to 9 (maximum allocation). This memory allocation affects speed only and does not impact the size of the generated payload.
Óçìåßùóç: Because compression level is the most commonly used parameter, it may be alternatively provided as a simple integer value (rather than an array element).
Óçìåßùóç: The zlib.* filters are not currently built into the PHP core. To enable these filters in PHP 5, install the zlib_filter package from PECL. These filters are not available for PHP 4.
ÐáñÜäåéãìá K-7. zlib.deflate and zlib.inflate
|
ÐáñÜäåéãìá K-8. zlib.deflate simple
|
bzip2.compress and bzip2.decompress work in the same manner as the zlib filters described above. The bzip2.compress filter accepts up to two parameters given as elements of an associative array: blocks is an integer value from 1 to 9 specifying the number of 100kbyte blocks of memory to allocate for workspace. work is also an integer value ranging from 0 to 250 indicating how much effort to expend using the normal compression method before falling back on a slower, but more reliable method. Tuning this parameter effects only compression speed. Neither size of compressed output nor memory usage are changed by this setting. A work factor of 0 instructs the bzip library to use an internal default. The bzip2.decompress filter only accepts one parameter, which can be passed as either an ordinary boolean value as the small element of an associative array. small, when set to a TRUE value, instructs the bzip library to perform decompression in a minimal memory footprint at the cost of speed.
Óçìåßùóç: The bzip2.* filters are not currently built into the PHP core. To enable these filters in PHP 5, install the bz2_filter package from PECL. These filters are not available for PHP 4.
ÐáñÜäåéãìá K-9. bzip2.compress and bzip2.decompress
|
The following is a list of the various URL style socket transports that PHP has built-in for use with the streams based socket functions such as fsockopen(), and stream_socket_client(). These transports do not apply to the Sockets Extension.
For a list of transports installed in your version of PHP use stream_get_transports().
PHP 3, PHP 4. ssl:// & tls:// since PHP 4.3
Óçìåßùóç: If no transport is specified, tcp:// will be assumed.
127.0.0.1
fe80::1
www.example.com
tcp://127.0.0.1
tcp://fe80::1
tcp://www.example.com
udp://www.example.com
ssl://www.example.com
tls://www.example.com
Internet Domain sockets expect a port number in addition to a target address. In the case of fsockopen() this is specified in a second parameter and therefore does not impact the formatting of transport URL. With stream_socket_client() and related functions as with traditional URLs however, the port number is specified as a suffix of the transport URL delimited by a colon.
tcp://127.0.0.1:80
tcp://[fe80::1]:80
tcp://www.example.com:80
IPv6 numeric addresses with port numbers: In the second example above, while the IPv4 and hostname examples are left untouched apart from the addition of their colon and portnumber, the IPv6 address is wrapped in square brackets: [fe80::1]. This is to distinguish between the colons used in an IPv6 address and the colon used to delimit the portnumber.
The ssl:// and tls:// transports (available only when openssl support is compiled into PHP) are extensions of the tcp:// transport which includes SSL encryption. Since PHP 4.3.0 OpenSSL support must be statically compiled into PHP, since PHP 5.0.0 it may be compiled as a module or statically.
Ðßíáêáò L-1. Context options for ssl:// and tls:// transports (since PHP 4.3.2)
Name | Usage | Default |
---|---|---|
verify_peer | TRUE or FALSE. Require verification of SSL certificate used. | FALSE |
allow_self_signed | TRUE or FALSE. Allow self-signed certificates. | FALSE |
cafile | Location of Certificate Authority file on local filesystem which should be used with the verify_peer context option to authenticate the identity of the remote peer. | |
capath | If cafile is not specified or if the certificate is not found there, the directory pointed to by capath is searched for a suitable certificate. capath must be a correctly hashed certificate directory. | |
local_cert | Path to local certificate file on filesystem. It must be a PEM encoded file which contains your certificate and private key. It can optionally contain the certificate chain of issuers. | |
passphrase | Passphrase with which your local_cert file was encoded. | |
CN_match | Common Name we are expecting. PHP will perform limited wildcard matching. If the Common Name does not match this, the connection attempt will fail. |
unix:// since PHP 3, udg:// since PHP 5
unix:///tmp/mysock
udg:///tmp/mysock
unix:// provides access to a socket stream connection in the Unix domain. udg:// provides an alternate transport to a Unix domain socket using the user datagram protocol.
Unix domain sockets, unlike Internet domain sockets, do not expect a port number. In the case of fsockopen() the portno parameter should be set to 0.
The following tables demonstrate behaviors for PHP types and comparison operators, for both loose and strict comparisons. This supplemental is also related to the manual section on type juggling. Inspiration was provided by various user comments and by the work over at BlueShoes.
Before utilizing these tables, it's important to understand types and their meanings. For example, "42" is a string while 42 is an integer. FALSE is a boolean while "false" is a string.
Óçìåßùóç: HTML Forms do not pass integers, floats, or booleans; they pass strings. To find out if a string is numeric, you may use is_numeric().
Óçìåßùóç: Simply doing if ($x) while $x is undefined will generate an error of level E_NOTICE. Instead, consider using empty() or isset() and/or initialize your variables.
Ðßíáêáò M-1. Comparisons of $x with PHP functions
Expression | gettype() | empty() | is_null() | isset() | boolean : if($x) |
---|---|---|---|---|---|
$x = ""; | string | TRUE | FALSE | TRUE | FALSE |
$x = NULL | NULL | TRUE | TRUE | FALSE | FALSE |
var $x; | NULL | TRUE | TRUE | FALSE | FALSE |
$x is undefined | NULL | TRUE | TRUE | FALSE | FALSE |
$x = array(); | array | TRUE | FALSE | TRUE | FALSE |
$x = false; | boolean | TRUE | FALSE | TRUE | FALSE |
$x = true; | boolean | FALSE | FALSE | TRUE | TRUE |
$x = 1; | integer | FALSE | FALSE | TRUE | TRUE |
$x = 42; | integer | FALSE | FALSE | TRUE | TRUE |
$x = 0; | integer | TRUE | FALSE | TRUE | FALSE |
$x = -1; | integer | FALSE | FALSE | TRUE | TRUE |
$x = "1"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "0"; | string | TRUE | FALSE | TRUE | FALSE |
$x = "-1"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "php"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "true"; | string | FALSE | FALSE | TRUE | TRUE |
$x = "false"; | string | FALSE | FALSE | TRUE | TRUE |
Ðßíáêáò M-2. Loose comparisons with ==
TRUE | FALSE | 1 | 0 | -1 | "1" | "0" | "-1" | NULL | array() | "php" | |
---|---|---|---|---|---|---|---|---|---|---|---|
TRUE | TRUE | FALSE | TRUE | FALSE | TRUE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE |
FALSE | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | TRUE | TRUE | FALSE |
1 | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
0 | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | TRUE | FALSE | TRUE |
-1 | TRUE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
"1" | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
"0" | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE |
"-1" | TRUE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
NULL | FALSE | TRUE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | TRUE | TRUE | FALSE |
array() | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | TRUE | FALSE |
"php" | TRUE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE |
Ðßíáêáò M-3. Strict comparisons with ===
TRUE | FALSE | 1 | 0 | -1 | "1" | "0" | "-1" | NULL | array() | "php" | |
---|---|---|---|---|---|---|---|---|---|---|---|
TRUE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
1 | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
0 | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
-1 | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
"1" | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
"0" | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE |
"-1" | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
NULL | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE |
array() | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE | FALSE |
"php" | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | TRUE |
PHP 3.0 note: The string value "0" was considered non-empty in PHP 3, this behavior changed in PHP 4 where it's now seen as empty.
Various parts of the PHP language are represented internally by types like T_SR. PHP outputs identifiers like this one in parse errors, like "Parse error: unexpected T_SR, expecting ',' or ';' in script.php on line 10."
You're supposed to know what T_SR means. For everybody who doesn't know that, here is a table with those identifiers, PHP-syntax and references to the appropriate places in the manual.
Ðßíáêáò N-1. Tokens
Token | Syntax | Reference |
---|---|---|
T_AND_EQUAL | &= | assignment operators |
T_ARRAY | array() | array(), array syntax |
T_ARRAY_CAST | (array) | type-casting |
T_AS | as | foreach |
T_BAD_CHARACTER | anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) | |
T_BOOLEAN_AND | && | logical operators |
T_BOOLEAN_OR | || | logical operators |
T_BOOL_CAST | (bool) or (boolean) | type-casting |
T_BREAK | break | break |
T_CASE | case | switch |
T_CHARACTER | ||
T_CLASS | class | classes and objects |
T_CLOSE_TAG | ?> or %> | |
T_COMMENT | // or # | comments |
T_CONCAT_EQUAL | .= | assignment operators |
T_CONST | const | |
T_CONSTANT_ENCAPSED_STRING | "foo" or 'bar' | string syntax |
T_CONTINUE | continue | |
T_CURLY_OPEN | ||
T_DEC | -- | incrementing/decrementing operators |
T_DECLARE | declare | declare |
T_DEFAULT | default | switch |
T_DIV_EQUAL | /= | assignment operators |
T_DNUMBER | 0.12, etc | floating point numbers |
T_DO | do | do..while |
T_DOLLAR_OPEN_CURLY_BRACES | ${ | complex variable parsed syntax |
T_DOUBLE_ARROW | => | array syntax |
T_DOUBLE_CAST | (real), (double) or (float) | type-casting |
T_ECHO | echo | echo() |
T_ELSE | else | else |
T_ELSEIF | elseif | elseif |
T_EMPTY | empty | empty() |
T_ENCAPSED_AND_WHITESPACE | ||
T_ENDDECLARE | enddeclare | declare, alternative syntax |
T_ENDFOR | endfor | for, alternative syntax |
T_ENDFOREACH | endforeach | foreach, alternative syntax |
T_ENDIF | endif | if, alternative syntax |
T_ENDSWITCH | endswitch | switch, alternative syntax |
T_ENDWHILE | endwhile | while, alternative syntax |
T_END_HEREDOC | heredoc syntax | |
T_EVAL | eval() | eval() |
T_EXIT | exit or die | exit(), die() |
T_EXTENDS | extends | extends, classes and objects |
T_FILE | __FILE__ | constants |
T_FOR | for | for |
T_FOREACH | foreach | foreach |
T_FUNCTION | function or cfunction | functions |
T_GLOBAL | global | variable scope |
T_IF | if | if |
T_INC | ++ | incrementing/decrementing operators |
T_INCLUDE | include() | include() |
T_INCLUDE_ONCE | include_once() | include_once() |
T_INLINE_HTML | ||
T_INT_CAST | (int) or (integer) | type-casting |
T_ISSET | isset() | isset() |
T_IS_EQUAL | == | comparison operators |
T_IS_GREATER_OR_EQUAL | >= | comparison operators |
T_IS_IDENTICAL | === | comparison operators |
T_IS_NOT_EQUAL | != or <> | comparison operators |
T_IS_NOT_IDENTICAL | !== | comparison operators |
T_SMALLER_OR_EQUAL | <= | comparison operators |
T_LINE | __LINE__ | constants |
T_LIST | list() | list() |
T_LNUMBER | 123, 012, 0x1ac, etc | integers |
T_LOGICAL_AND | and | logical operators |
T_LOGICAL_OR | or | logical operators |
T_LOGICAL_XOR | xor | logical operators |
T_MINUS_EQUAL | -= | assignment operators |
T_ML_COMMENT | /* and */ | comments |
T_MOD_EQUAL | %= | assignment operators |
T_MUL_EQUAL | *= | assignment operators |
T_NEW | new | classes and objects |
T_NUM_STRING | ||
T_OBJECT_CAST | (object) | type-casting |
T_OBJECT_OPERATOR | -> | classes and objects |
T_OLD_FUNCTION | old_function | old_function |
T_OPEN_TAG | <?php, <? or <% | escaping from HTML |
T_OPEN_TAG_WITH_ECHO | <?= or <%= | escaping from HTML |
T_OR_EQUAL | |= | assignment operators |
T_PAAMAYIM_NEKUDOTAYIM | :: | :: |
T_PLUS_EQUAL | += | assignment operators |
T_PRINT | print() | print() |
T_REQUIRE | require() | require() |
T_REQUIRE_ONCE | require_once() | require_once() |
T_RETURN | return | returning values |
T_SL | << | bitwise operators |
T_SL_EQUAL | <<= | assignment operators |
T_SR | >> | bitwise operators |
T_SR_EQUAL | >>= | assignment operators |
T_START_HEREDOC | <<< | heredoc syntax |
T_STATIC | static | variable scope |
T_STRING | ||
T_STRING_CAST | (string) | type-casting |
T_STRING_VARNAME | ||
T_SWITCH | switch | switch |
T_UNSET | unset() | unset() |
T_UNSET_CAST | (unset) | (not documented; casts to NULL) |
T_USE | use | (not implemented) |
T_VAR | var | classes and objects |
T_VARIABLE | $foo | variables |
T_WHILE | while | while, do..while |
T_WHITESPACE | ||
T_XOR_EQUAL | ^= | assignment operators |
T_FUNC_C | __FUNCTION__ | constants, since PHP 4.3.0 |
T_CLASS_C | __CLASS__ | constants, since PHP 4.3.0 |
The PHP manual is provided in several formats. These formats can be divided into two groups: online readable formats, and downloadable packages.
Óçìåßùóç: Some publishers have made available printed versions of this manual. We cannot recommend any of those, as they tend to become out-of-date very quickly.
You can read the manual online at http://www.php.net/ and on the numerous mirror sites. For best performance, you should choose the mirror site closest to you. You can view the manual in either its plain (print-friendly) HTML format or an HTML format that integrates the manual into the look and feel of the PHP website itself.
An advantage of the online manual over most of the offline formats is the integration of user-contributed notes. An obvious disadvantage is that you have to be online to view the manual in the online formats.
There are several offline formats of the manual, and the most appropriate format for you depends on what operating system you use and your personal reading style. For information on how the manual is generated in so many formats, read the 'How we generate the formats' section of this appendix.
The most cross-platform formats of the manual are the HTML and plain-text versions. The HTML format is provided both as a single HTML file and as a package of individual files for each section (which results in a collection of several thousand files). The HTML and plaintext formats are provided as tar files compressed using the bzip2 archiver.
Another popular cross-platform format, and the format most suited to printing, is PDF (also known as Adobe Acrobat). But before you rush to download this format and hit the Print button, be warned that the manual is nearly 2000 pages long, and constantly being revised.
Óçìåßùóç: If you do not already have a program capable of viewing PDF format files, you may need to download Adobe Acrobat Reader.
For owners of Palm-compatible handhelds, the Palm document and iSilo formats are ideal for this platform. You can bring your handheld with you on your daily commute and use a DOC or iSilo reader to brush up on your PHP knowledge, or just use it as a quick reference.
For Windows platforms, the Windows HTML Help version of the manual soups up the HTML format for use with the Windows HTML Help application. This version provides full-text search, a full index, and bookmarking. Many popular Windows PHP development environments also integrate with this version of the documentation to provide easy access.
The user-contributed notes play an important role in the development of this manual. By allowing readers of the manual to contribute examples, caveats, and further clarifications from their browser, we are able to incorporate that feedback into the main text of the manual. And until the notes have been incorporated, they can be viewed in their submitted form online and in some of the offline formats.
Óçìåßùóç: The user-contributed notes are not moderated before they appear online, so the quality of the writing or code examples, and even the veracity of the contribution, cannot be guaranteed. (Not that there is any guarantee of the quality or accuracy of the manual text itself.)
Óçìåßùóç: For the purposes of license coverage the user-contributed notes are considered part of the PHP manual, and are therefore covered by the same license that covers this documentation (Open Publication License at the moment). For more details see the Manual's Copyright page.
Each function is documented for quick reference. Knowing how to read and understand the manual will make using PHP much easier. Rather than relying on examples or cut/paste, you will want to know how to read function definitions (prototypes). Let's begin:
Prerequisite: Basic understanding of types: Although PHP is a loosely typed language, it's important to have a basic understanding of types as they have important meaning.
Function definitions tell us what type of value is returned. Let's use the definition for strlen() as our first example:
strlen (PHP 3, PHP 4 >= 4.0.0) strlen -- Get string length Description int strlen ( string str ) Returns the length of string. |
Ðßíáêáò O-1. Explanation of a function definition
Part | Description |
---|---|
strlen | The function name. |
(PHP 3, PHP 4 >= 4.0.0) | strlen() has been around in both all of PHP 3 and PHP 4 |
int | Type of value this function returns, which is an integer (i.e. The length of a string is measured in numbers). |
( string str ) | The first (and in this case the only) parameter/argument for the function strlen() is named str, and it's a string. |
We could rewrite the above function definition in a generic way:
returned type function name ( parameter type parameter name ) |
Many functions take on multiple parameters, such as in_array(). Its prototype is as follows:
bool in_array ( mixed needle, array haystack [, bool strict]) |
What does this mean? in_array() returns a boolean value, TRUE on success (if the needle was found in the haystack) or FALSE on failure (if the needle was not found in the haystack). The first parameter is named needle and it can be of many different types, so we call it "mixed". This mixed needle (what we're looking for) can be either a scalar value (string, integer, or float), or an array. haystack (the array we're searching in) is the second parameter. The third optional parameter is named strict. All optional parameters are seen in [ brackets ]. The manual states that the strict parameter defaults to boolean FALSE. See the manual page on each function for details on how they work.
This documentation contains information about PHP 4, with some added migration and compatibility notes regarding PHP 3. Behaviour, parameter, return value and other changes between different PHP versions are documented in notes and inline text in the manual.
You may find documentation pieces for the CVS version of PHP, which always means the very latest development version available through the CVS version handling system. If you are not a developer of PHP itself, and you are not keen on using the very latest development version of PHP, features marked with the "available in CVS" wording are not accessible to you. These features, though, will probably be available in the next stable version of PHP. If you would like to download the CVS version, see the anonymous CVS access page.
You may also encounter documentation for a PHP version which is not released (something like PHP 5.0.0 as the latest stable version is 4.3.x). Most of the time, this is not an error in the documentation. Explanation is often added for features not available in the current PHP release, but which will be available in a known future PHP version.
This manual does not attempt to provide instruction about general programming practices. If you are a first-time, or even just a beginning, programmer, you may find it difficult to learn how to program in PHP using just this manual. You may want to seek out a text more oriented towards beginners. You can find a list of PHP-related books at http://www.php.net/books.php.
There are a number of active mailing lists for discussion of all aspects of programming with PHP. If you find yourself stuck on a problem for which you can't find your own solution, you may be able to get help from someone on these lists. You can find a list of the mailing lists at http://www.php.net/support.php, as well as links to the mailing list archives and other online support resources. Furthermore, at http://www.php.net/links.php there is a list of websites devoted to PHP articles, forums, and code galleries.
There are three ways you can help to improve this documentation.
If you find errors in this manual, in any language, please report them using the bug system at http://bugs.php.net/. Classify the bug as "Documentation Problem". You can also submit problems related to specific manual formats here.
Óçìåßùóç: Please don't abuse the bug system by submitting requests for help. Use the mailing lists or community sites mentioned earlier, instead.
By contributing notes, you can provide additional examples, caveats, and clarifications for other readers. But please do not submit bug reports using the annotation system. You can read more about annotations in the 'About user notes' section of this appendix.
If you know English and some foreign language, you may also help out in the translations. If you would like to start a new translation, or help in a translation project, please read http://cvs.php.net/co.php/phpdoc/howto/howto.html.tar.gz.
This manual is written in XML using the DocBook XML DTD, using DSSSL (Document Style and Semantics Specification Language) for formatting, and experimentally the XSLT (Extensible Stylesheet Language Transformations) for maintenance and formatting.
Using XML as a source format gives us the ability to generate many output formats from the source files, while only maintaining one source document for all formats. The tools used for formatting HTML and TeX versions are Jade, written by James Clark; and The Modular DocBook Stylesheets, written by Norman Walsh. We use Microsoft HTML Help Workshop to generate the Windows HTML Help format of the manual, and of course PHP itself to do some additional conversions and formatting.
You can download the manual in various languages and formats, including plain text, plain HTML, PDF, PalmPilot DOC, PalmPilot iSilo, and Windows HTML Help, from http://www.php.net/docs.php. The manuals are updated periodically as the text is updated.
You can find more information about downloading the XML source code of this documentation at http://cvs.php.net/. The documentation is stored in the phpdoc module.
The PHP manual is available not only in various formats, but also in various languages. The text of the manual is first written in English, then teams of people across the world take care of translating it to their native languages. If a translation for a specified function or chapter has not yet been made, the manual's build system falls back to the English version of it.
People involved in the translations start from the XML source code available from http://cvs.php.net/ and from it they translate to their mother language. They do not use the HTML, the plain text, or the PDF version. It is the build system which takes care of the conversions from XML to human readable formats.
Óçìåßùóç: If you would like to help translate the documentation to your native language, please get in touch with the translation/documentation team by subscribing to the phpdoc mailing list: send an empty mail to phpdoc-subscribe@lists.php.net. The mailing list address is phpdoc@lists.php.net. State in the message that you are interested in translating the manual to a language and someone will get back to you, helping you start a new language translation or reach the already active documentation team for your language.
At the moment the manual is available, partly or not, in the following languages: Brazilian Portuguese, Chinese (Simplified), Chinese (Hong Kong Cantonese), Chinese (Traditional), Czech, Dutch, Finnish, French, German, Greek, Hebrew, Hungarian, Italian, Japanese, Korean, Polish, Romanian, Russian, Slovak, Slovenian, Spanish, Swedish, and Turkish.
They can all be downloaded here: http://www.php.net/docs.php.
v1.0, 8 June 1999
The Open Publication works may be reproduced and distributed in whole or in part, in any medium physical or electronic, provided that the terms of this license are adhered to, and that this license or an incorporation of it by reference (with any options elected by the author(s) and/or publisher) is displayed in the reproduction.
Proper form for an incorporation by reference is as follows:
Copyright (c) <year> by <author's name or designee>. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, vX.Y or later (the latest version is presently available at http://www.opencontent.org/openpub/
The reference must be immediately followed with any options elected by the author(s) and/or publisher of the document (see section VI). Commercial redistribution of Open Publication-licensed material is permitted. Any publication in standard (paper) book form shall require the citation of the original publisher and author. The publisher and author's names shall appear on all outer surfaces of the book. On all outer surfaces of the book the original publisher's name shall be as large as the title of the work and cited as possessive with respect to the title.
The following license terms apply to all Open Publication works, unless otherwise explicitly stated in the document.
Mere aggregation of Open Publication works or a portion of an Open Publication work with other works or programs on the same media shall not cause this license to apply to those other works. The aggregate work shall contain a notice specifying the inclusion of the Open Publication material and appropriate copyright notice.
SEVERABILITY. If any part of this license is found to be unenforceable in any jurisdiction, the remaining portions of the license remain in force.
NO WARRANTY. Open Publication works are licensed and provided "as is" without warranty of any kind, express or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose or a warranty of non-infringement.
All modified versions of documents covered by this license, including translations, anthologies, compilations and partial documents, must meet the following requirements:
The modified version must be labeled as such.
The person making the modifications must be identified and the modifications dated.
Acknowledgement of the original author and publisher if applicable must be retained according to normal academic citation practices.
The location of the original unmodified document must be identified.
The original author's (or authors') name(s) may not be used to assert or imply endorsement of the resulting document without the original author's (or authors') permission.
In addition to the requirements of this license, it is requested from and strongly recommended of redistributors that:
If you are distributing Open Publication works on hardcopy or CD-ROM, you provide email notification to the authors of your intent to redistribute at least thirty days before your manuscript or media freeze, to give the authors time to provide updated documents. This notification should describe modifications, if any, made to the document.
All substantive modifications (including deletions) be either clearly marked up in the document or else described in an attachment to the document.
Finally, while it is not mandatory under this license, it is considered good form to offer a free copy of any hardcopy and CD-ROM expression of an Open Publication-licensed work to its author(s).
The author(s) and/or publisher of an Open Publication-licensed document may elect certain options by appending language to the reference to or copy of the license. These options are considered part of the license instance and must be included with the license (or its incorporation by reference) in derived works.
A. To prohibit distribution of substantively modified versions without the explicit permission of the author(s). "Substantive modification" is defined as a change to the semantic content of the document, and excludes mere changes in format or typographical corrections.
To accomplish this, add the phrase `Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.' to the license reference or copy.
B. To prohibit any publication of this work or derivative works in whole or in part in standard (paper) book form for commercial purposes is prohibited unless prior permission is obtained from the copyright holder.
To accomplish this, add the phrase 'Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.' to the license reference or copy.