cvs: phpdoc / lang-nl.ent manual.xml.in /nl bookinfo.xml chapters.ent preface.xml /nl/appendices debugger.xml escaping.xml history.xml
http-stuff.xml migration.xml phpdevel.xml regexp.xml /nl/chapters config.xml copyright.xml install.xml intro.xml security.xml /nl/features
connection-handling.xml cookies.xml error-handling.xml file-upload.xml http-auth.xml images.xml persistent-connections.xml remote-files.xml
/nl/functions apache.xml array.xml aspell.xml bc.xml calendar.xml ccvs.xml classobj.xml com.xml cpdf.xml curl.xml cybercash.xml datetime.xml dba.xml
dbase.xml dbm.xml dir.xml dl.xml domxml.xml errorfunc.xml exec.xml fdf.xml filepro.xml filesystem.xml ftp.xml funchand.xml gettext.xml http.xml hw.xml
ibase.xml icap.xml ifx.xml image.xml imap.xml info.xml ldap.xml mail.xml math.xml mcal.xml mcrypt.xml mhash.xml misc.xml msql.xml mssql.xml mysql.xml
network.xml nis.xml oci8.xml oracle.xml outcontrol.xml pcre.xml pdf.xml pfpro.xml pgsql.xml posix.xml pspell.xml readline.xml recode.xml regex.xml
satellite.xml sem.xml session.xml shmop.xml snmp.xml sockets.xml strings.xml swf.xml sybase.xml uodbc.xml url.xml var.xml vmailmgr.xml wddx.xml
xml.xml yaz.xml zlib.xml /nl/language basic-syntax.xml constants.xml control-structures.xml expressions.xml functions.xml oop.xml operators.xml
references.xml types.xml variables.xml
| From: | Derick Rethans | Date: | Tue, 10 Oct 2000 22:07:58 +0000 |
| Subject: | cvs: phpdoc / lang-nl.ent manual.xml.in /nl bookinfo.xml chapters.ent preface.xml /nl/appendices debugger.xml escaping.xml history.xml http-stuff.xml migration.xml phpdevel.xml regexp.xml /nl/chapters config.xml copyright.xml install.xml intro.xml security.xml /nl/features connection-handling.xml cookies.xml error-handling.xml file-upload.xml http-auth.xml images.xml persistent-connections.xml remote-files.xml /nl/functions apache.xml array.xml aspell.xml bc.xml calendar.xml ccvs.xml classobj.xml com.xml cpdf.xml curl.xml cybercash.xml datetime.xml dba.xml dbase.xml dbm.xml dir.xml dl.xml domxml.xml errorfunc.xml exec.xml fdf.xml filepro.xml filesystem.xml ftp.xml funchand.xml gettext.xml http.xml hw.xml ibase.xml icap.xml ifx.xml image.xml imap.xml info.xml ldap.xml mail.xml math.xml mcal.xml mcrypt.xml mhash.xml misc.xml msql.xml mssql.xml mysql.xml network.xml nis.xml oci8.xml oracle.xml outcontrol.xml pcre.xml pdf.xml pfpro.xml pgsql.xml posix.xml pspell.xml readline.xml recode.xml regex.xml satellite.xml sem.xml session.xml shmop.xml snmp.xml sockets.xml strings.xml swf.xml sybase.xml uodbc.xml url.xml var.xml vmailmgr.xml wddx.xml xml.xml yaz.xml zlib.xml /nl/language basic-syntax.xml constants.xml control-structures.xml expressions.xml functions.xml oop.xml operators.xml references.xml types.xml variables.xml |
||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969332427@lists.php.net to get a copy of this message | ||
derick Tue Oct 10 15:07:58 2000 EDT
Added files:
/phpdoc lang-nl.ent
/phpdoc/nl bookinfo.xml chapters.ent preface.xml
/phpdoc/nl/appendices debugger.xml escaping.xml history.xml
http-stuff.xml migration.xml phpdevel.xml
regexp.xml
/phpdoc/nl/chapters config.xml copyright.xml install.xml intro.xml
security.xml
/phpdoc/nl/features connection-handling.xml cookies.xml
error-handling.xml file-upload.xml
http-auth.xml images.xml
persistent-connections.xml remote-files.xml
/phpdoc/nl/functions apache.xml array.xml aspell.xml bc.xml
calendar.xml ccvs.xml classobj.xml com.xml
cpdf.xml curl.xml cybercash.xml datetime.xml
dba.xml dbase.xml dbm.xml dir.xml dl.xml
domxml.xml errorfunc.xml exec.xml fdf.xml
filepro.xml filesystem.xml ftp.xml
funchand.xml gettext.xml http.xml hw.xml
ibase.xml icap.xml ifx.xml image.xml imap.xml
info.xml ldap.xml mail.xml math.xml mcal.xml
mcrypt.xml mhash.xml misc.xml msql.xml
mssql.xml mysql.xml network.xml nis.xml
oci8.xml oracle.xml outcontrol.xml pcre.xml
pdf.xml pfpro.xml pgsql.xml posix.xml
pspell.xml readline.xml recode.xml regex.xml
satellite.xml sem.xml session.xml shmop.xml
snmp.xml sockets.xml strings.xml swf.xml
sybase.xml uodbc.xml url.xml var.xml
vmailmgr.xml wddx.xml xml.xml yaz.xml zlib.xml
/phpdoc/nl/language basic-syntax.xml constants.xml
control-structures.xml expressions.xml
functions.xml oop.xml operators.xml
references.xml types.xml variables.xml
Modified files:
/phpdoc manual.xml.in
Log:
- Added the Dutch translation tree
Index: phpdoc/manual.xml.in
diff -u phpdoc/manual.xml.in:1.31 phpdoc/manual.xml.in:1.32
--- phpdoc/manual.xml.in:1.31 Sun Oct 1 08:10:25 2000
+++ phpdoc/manual.xml.in Tue Oct 10 15:07:52 2000
@@ -35,6 +35,10 @@
<!ENTITY % language-defs SYSTEM "lang-fr.ent">
]]>
+<![%lang-nl;[
+<!ENTITY % language-defs SYSTEM "lang-nl.ent">
+]]>
+
<![%lang-pt-BR;[
<!ENTITY % language-defs SYSTEM "lang-pt_BR.ent">
]]>
Index: phpdoc/lang-nl.ent
+++ phpdoc/lang-nl.ent
<!ENTITY PHPManual "PHP Handleiding">
<!ENTITY Date "Datum:">
<!ENTITY GettingStarted "Om te beginnen">
<!ENTITY LanguageReference "Syntax">
<!ENTITY Features "Functionaliteit">
<!ENTITY FunctionReference "Functie naslag">
<!ENTITY Appendixes "Appendixes">
<!ENTITY % global.chapters SYSTEM "nl/chapters.ent">
<!ENTITY available "beschikbaar in">
Index: phpdoc/nl/bookinfo.xml
+++ phpdoc/nl/bookinfo.xml
<bookinfo id="bookinfo">
<authorgroup id="authors">
<author>
<firstname>Stig</firstname><surname>Sæther Bakken</surname>
</author>
<author>
<firstname>Alexander</firstname><surname>Aulbach</surname>
</author>
<author>
<firstname>Egon</firstname><surname>Schmid</surname>
</author>
<author>
<firstname>Jim</firstname><surname>Winstead</surname>
</author>
<author>
<firstname>Lars Torben</firstname><surname>Wilson</surname>
</author>
<author>
<firstname>Rasmus</firstname><surname>Lerdorf</surname>
</author>
<author>
<firstname>Zeev</firstname><surname>Suraski</surname>
</author>
<author>
<firstname>Andrei</firstname><surname>Zmievski</surname>
</author>
</authorgroup>
<pubdate>&php.build-date;</pubdate>
<authorgroup id="editors">
<editor>
<firstname>Matthieu</firstname><surname>Koolman</surname>
</editor>
<editor>
<firstname>Derick</firstname><surname>Rethans</surname>
</editor>
</authorgroup>
<copyright>
<year>1997</year>
<year>1998</year>
<year>1999</year>
<year>2000</year>
<holder>the PHP Documentation Group</holder>
</copyright>
<legalnotice id="copyright">
<title>Copyright</title>
<simpara>
This manual is © Copyright 1997, 1998, 1999, 2000 by the PHP
Documentation Group. The members of this group are listed <link
linkend="authors">on the front page of this manual</link>.
</simpara>
<simpara>
This manual can be redistributed under the terms of the GNU
General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option)
any later version.
</simpara>
</legalnotice>
</bookinfo>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/chapters.ent
+++ phpdoc/nl/chapters.ent
<!ENTITY preface SYSTEM "preface.xml">
<!ENTITY bookinfo SYSTEM "bookinfo.xml">
<!ENTITY chapter.copyright SYSTEM "chapters/copyright.xml">
<!ENTITY chapter.introduction SYSTEM "chapters/intro.xml">
<!ENTITY chapter.install SYSTEM "chapters/install.xml">
<!ENTITY chapter.config SYSTEM "chapters/config.xml">
<!ENTITY chapter.security SYSTEM "chapters/security.xml">
<!ENTITY features.http-auth SYSTEM "features/http-auth.xml">
<!ENTITY features.cookies SYSTEM "features/cookies.xml">
<!ENTITY features.file-upload SYSTEM "features/file-upload.xml">
<!ENTITY features.remote-files SYSTEM "features/remote-files.xml">
<!ENTITY features.connection-handling SYSTEM "features/connection-handling.xml">
<!ENTITY features.error-handling SYSTEM "features/error-handling.xml">
<!ENTITY features.images SYSTEM "features/images.xml">
<!ENTITY features.persistent-connections SYSTEM
"features/persistent-connections.xml">
<!ENTITY language.basic-syntax SYSTEM "language/basic-syntax.xml">
<!ENTITY language.types SYSTEM "language/types.xml">
<!ENTITY language.variables SYSTEM "language/variables.xml">
<!ENTITY language.constants SYSTEM "language/constants.xml">
<!ENTITY language.expressions SYSTEM "language/expressions.xml">
<!ENTITY language.operators SYSTEM "language/operators.xml">
<!ENTITY language.functions SYSTEM "language/functions.xml">
<!ENTITY language.control-structures SYSTEM "language/control-structures.xml">
<!ENTITY language.oop SYSTEM "language/oop.xml">
<!ENTITY language.references SYSTEM "language/references.xml">
<!ENTITY reference.apache SYSTEM "functions/apache.xml">
<!ENTITY reference.array SYSTEM "functions/array.xml">
<!ENTITY reference.aspell SYSTEM "functions/aspell.xml">
<!ENTITY reference.bc SYSTEM "functions/bc.xml">
<!ENTITY reference.calendar SYSTEM "functions/calendar.xml">
<!ENTITY reference.ccvs SYSTEM "functions/ccvs.xml">
<!ENTITY reference.classobj SYSTEM "functions/classobj.xml">
<!ENTITY reference.com SYSTEM "functions/com.xml">
<!ENTITY reference.cpdf SYSTEM "functions/cpdf.xml">
<!ENTITY reference.curl SYSTEM "functions/curl.xml">
<!ENTITY reference.cybercash SYSTEM "functions/cybercash.xml">
<!ENTITY reference.datetime SYSTEM "functions/datetime.xml">
<!ENTITY reference.dba SYSTEM "functions/dba.xml">
<!ENTITY reference.dbase SYSTEM "functions/dbase.xml">
<!ENTITY reference.dbm SYSTEM "functions/dbm.xml">
<!ENTITY reference.dir SYSTEM "functions/dir.xml">
<!-- ENTITY reference.dl SYSTEM "functions/dl.xml" -->
<!ENTITY reference.domxml SYSTEM "functions/domxml.xml">
<!ENTITY reference.errorfunc SYSTEM "functions/errorfunc.xml">
<!ENTITY reference.exec SYSTEM "functions/exec.xml">
<!ENTITY reference.fdf SYSTEM "functions/fdf.xml">
<!ENTITY reference.filepro SYSTEM "functions/filepro.xml">
<!ENTITY reference.filesystem SYSTEM "functions/filesystem.xml">
<!ENTITY reference.ftp SYSTEM "functions/ftp.xml">
<!ENTITY reference.funchand SYSTEM "functions/funchand.xml">
<!ENTITY reference.gettext SYSTEM "functions/gettext.xml">
<!ENTITY reference.http SYSTEM "functions/http.xml">
<!ENTITY reference.hw SYSTEM "functions/hw.xml">
<!ENTITY reference.ibase SYSTEM "functions/ibase.xml">
<!ENTITY reference.icap SYSTEM "functions/icap.xml">
<!ENTITY reference.ifx SYSTEM "functions/ifx.xml">
<!ENTITY reference.image SYSTEM "functions/image.xml">
<!ENTITY reference.imap SYSTEM "functions/imap.xml">
<!ENTITY reference.info SYSTEM "functions/info.xml">
<!ENTITY reference.ldap SYSTEM "functions/ldap.xml">
<!ENTITY reference.mail SYSTEM "functions/mail.xml">
<!ENTITY reference.math SYSTEM "functions/math.xml">
<!ENTITY reference.mcal SYSTEM "functions/mcal.xml">
<!ENTITY reference.mcrypt SYSTEM "functions/mcrypt.xml">
<!ENTITY reference.mhash SYSTEM "functions/mhash.xml">
<!ENTITY reference.misc SYSTEM "functions/misc.xml">
<!ENTITY reference.msql SYSTEM "functions/msql.xml">
<!ENTITY reference.mssql SYSTEM "functions/mssql.xml">
<!ENTITY reference.mysql SYSTEM "functions/mysql.xml">
<!ENTITY reference.network SYSTEM "functions/network.xml">
<!ENTITY reference.nis SYSTEM "functions/nis.xml">
<!ENTITY reference.oci8 SYSTEM "functions/oci8.xml">
<!ENTITY reference.oracle SYSTEM "functions/oracle.xml">
<!ENTITY reference.outcontrol SYSTEM "functions/outcontrol.xml">
<!ENTITY reference.pcre SYSTEM "functions/pcre.xml">
<!ENTITY reference.pdf SYSTEM "functions/pdf.xml">
<!ENTITY reference.pfpro SYSTEM "functions/pfpro.xml">
<!ENTITY reference.pgsql SYSTEM "functions/pgsql.xml">
<!ENTITY reference.posix SYSTEM "functions/posix.xml">
<!ENTITY reference.pspell SYSTEM "functions/pspell.xml">
<!ENTITY reference.readline SYSTEM "functions/readline.xml">
<!ENTITY reference.recode SYSTEM "functions/recode.xml">
<!ENTITY reference.regex SYSTEM "functions/regex.xml">
<!ENTITY reference.satellite SYSTEM "functions/satellite.xml">
<!ENTITY reference.sem SYSTEM "functions/sem.xml">
<!ENTITY reference.session SYSTEM "functions/session.xml">
<!ENTITY reference.shmop SYSTEM "functions/shmop.xml">
<!ENTITY reference.snmp SYSTEM "functions/snmp.xml">
<!ENTITY reference.sockets SYSTEM "functions/sockets.xml">
<!ENTITY reference.strings SYSTEM "functions/strings.xml">
<!ENTITY reference.swf SYSTEM "functions/swf.xml">
<!ENTITY reference.sybase SYSTEM "functions/sybase.xml">
<!ENTITY reference.uodbc SYSTEM "functions/uodbc.xml">
<!ENTITY reference.url SYSTEM "functions/url.xml">
<!ENTITY reference.var SYSTEM "functions/var.xml">
<!ENTITY reference.vmailmgr SYSTEM "functions/vmailmgr.xml">
<!ENTITY reference.wddx SYSTEM "functions/wddx.xml">
<!ENTITY reference.xml SYSTEM "functions/xml.xml">
<!ENTITY reference.yaz SYSTEM "functions/yaz.xml">
<!ENTITY reference.zlib SYSTEM "functions/zlib.xml">
<!ENTITY appendix.migration SYSTEM "appendices/migration.xml">
<!ENTITY appendix.development SYSTEM "appendices/phpdevel.xml">
<!ENTITY appendix.debugger SYSTEM "appendices/debugger.xml">
Index: phpdoc/nl/preface.xml
+++ phpdoc/nl/preface.xml
<preface id="preface">
<title>Preface</title>
<abstract>
<simpara>
<acronym>PHP</acronym>, which stands for "PHP: Hypertext
Preprocessor", 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.
</simpara>
</abstract>
<sect1 id="about">
<title>About this Manual</title>
<para>
This manual is written in <acronym>XML</acronym> using the <ulink
url="&url.docbook.xml;">DocBook XML DTD</ulink>, using <ulink
url="&url.dsssl;"><acronym>DSSSL</acronym></ulink> (Document
Style and Semantics Specification Language) for formatting. The
tools used for formatting <acronym>HTML</acronym>,
<acronym>TeX</acronym> and <acronym>RTF</acronym> versions are
<ulink url="&url.jade;">Jade</ulink>, written by <ulink
url="&url.jclark;">James Clark</ulink> and <ulink
url="&url.dbstyle;">The Modular DocBook Stylesheets</ulink>
written by <ulink url="&url.nwalsh;">Norman Walsh</ulink>.
PHP's documentation framework is maintained by &link.stig;.
</para>
<para>
Daily HTML snapshots of the manual, including translations, can be
found at <ulink
url="&url.php.snaps.manual;">&url.php.snaps.manual;</ulink>.
</para>
</sect1>
</preface>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/appendices/debugger.xml
+++ phpdoc/nl/appendices/debugger.xml
<appendix id="debugger">
<title>The PHP Debugger</title>
<sect1 id="debugger-using">
<title>Using the Debugger</title>
<para>
PHP's internal debugger is useful for tracking down evasive bugs.
The debugger works by connecting to a <acronym>TCP</acronym> port
for every time PHP 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
<acronym>IDE</acronym> or programmable editor (such as Emacs).
</para>
<para>
How to set up the debugger:
<orderedlist>
<listitem>
<simpara>
Set up a TCP port for the debugger in the <link
linkend="configuration.file">configuration file</link> (<link
linkend="ini.debugger.port">debugger.port</link>) and enable it
(<link linkend="ini.debugger.enabled">debugger.enabled</link>).
</simpara>
</listitem>
<listitem>
<simpara>
Set up a TCP listener on that port somewhere (for example
<command>socket -l -s 1400</command> on UNIX).
</simpara>
</listitem>
<listitem>
<simpara>
In your code, run
"debugger_on(<replaceable>host</replaceable>)", where
<replaceable>host</replaceable> is the IP number or name of the
host running the <acronym>TCP</acronym> listener.
</simpara>
</listitem>
</orderedlist>
Now, all warnings, notices etc. will show up on that listener
socket, <emphasis>even if you them turned off with
<function>error_reporting</function></emphasis>.
</para>
<note>
<para>
The code for the debugger has not been ported to PHP 4, at the
present time only PHP 3 supports the debugger code.
</para>
</note>
</sect1>
<sect1 id="debugger-protocol">
<title>Debugger Protocol</title>
<para>
The debugger protocol is line-based. Each line has a
<emphasis>type</emphasis>, and several lines compose a
<emphasis>message</emphasis>. Each message starts with a line of
the type <literal>start</literal> and terminates with a line of
the type <literal>end</literal>. PHP may send lines for different
messages simultaneously.
</para>
<para>
A line has this format:
<informalexample>
<literallayout>
<replaceable>date</replaceable> <replaceable>time</replaceable>
<replaceable>host</replaceable>(<replaceable>pid</replaceable>)
<replaceable>type</replaceable>:
<replaceable>message-data</replaceable>
</literallayout>
</informalexample>
<variablelist>
<varlistentry>
<term><replaceable>date</replaceable></term>
<listitem>
<simpara>
Date in ISO 8601 format
(<replaceable>yyyy</replaceable>-<replaceable>mm</replaceable>-<replaceable>dd</replaceable>)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>time</replaceable></term>
<listitem>
<simpara>Time including microseconds:
<replaceable>hh</replaceable>:<replaceable>mm</replaceable>:<replaceable>uuuuuu</replaceable>
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>host</replaceable></term>
<listitem>
<simpara>
DNS name or IP address of the host where the script error was
generated.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>pid</replaceable></term>
<listitem>
<simpara>
PID (process id) on <replaceable>host</replaceable> of the
process with the PHP script that generated this error.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>type</replaceable></term>
<listitem>
<para>
Type of line. Tells the receiving program about what it
should treat the following data as:
<table>
<title>Debugger Line Types</title>
<tgroup cols="2">
<thead>
<row>
<entry>Name</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>start</literal></entry>
<entry>
Tells the receiving program that a debugger message
starts here. The contents of
<replaceable>data</replaceable> will be the type of error
message, listed below.
</entry>
</row>
<row>
<entry><literal>message</literal></entry>
<entry>The PHP error message.</entry>
</row>
<row>
<entry><literal>location</literal></entry>
<entry>
File name and line number where the error occured. The
first <literal>location</literal> line will always
contain the top-level location.
<replaceable>data</replaceable> will contain
<literal><replaceable>file</replaceable>:<replaceable>line</replaceable></literal>.
There will always be a <literal>location</literal> line
after <literal>message</literal> and after every
<literal>function</literal>.
</entry>
</row>
<row>
<entry>
<literal>frames</literal></entry> <entry>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 occured at top-level).
</entry>
</row>
<row>
<entry>
<literal>function</literal></entry>
<entry>
Name of function where the error occured. Will be
repeated once for every level in the function call
stack.
</entry>
</row>
<row>
<entry><literal>end</literal></entry>
<entry>
Tells the receiving program that a debugger message ends
here.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable>data</replaceable></term>
<listitem>
<simpara>Line data.</simpara>
</listitem>
</varlistentry>
</variablelist>
<table>
<title>Debugger Error Types</title>
<tgroup cols="2">
<thead>
<row>
<entry>Debugger</entry>
<entry>PHP Internal</entry>
</row>
</thead>
<tbody>
<row>
<entry><errortype>warning</errortype></entry>
<entry><errortype>E_WARNING</errortype></entry>
</row>
<row>
<entry><errortype>error</errortype></entry>
<entry><errortype>E_ERROR</errortype></entry>
</row>
<row>
<entry><errortype>parse</errortype></entry>
<entry><errortype>E_PARSE</errortype></entry>
</row>
<row>
<entry><errortype>notice</errortype></entry>
<entry><errortype>E_NOTICE</errortype></entry>
</row>
<row>
<entry><errortype>core-error</errortype></entry>
<entry><errortype>E_CORE_ERROR</errortype></entry>
</row>
<row>
<entry><errortype>core-warning</errortype></entry>
<entry><errortype>E_CORE_WARNING</errortype></entry>
</row>
<row>
<entry><errortype>unknown</errortype></entry>
<entry>(any other)</entry>
</row>
</tbody>
</tgroup>
</table>
<example>
<title>Example Debugger Message</title>
<literallayout>
1998-04-05 23:27:400966 lucifer.guardian.no(20481) start: notice
1998-04-05 23:27:400966 lucifer.guardian.no(20481) message: Uninitialized variable
1998-04-05 23:27:400966 lucifer.guardian.no(20481) location: (null):7
1998-04-05 23:27:400966 lucifer.guardian.no(20481) frames: 1
1998-04-05 23:27:400966 lucifer.guardian.no(20481) function: display
1998-04-05 23:27:400966 lucifer.guardian.no(20481) location: /home/ssb/public_html/test.php3:10
1998-04-05 23:27:400966 lucifer.guardian.no(20481) end: notice
</literallayout>
</example>
</para>
</sect1>
</appendix>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/appendices/escaping.xml
+++ phpdoc/nl/appendices/escaping.xml
<chapt>Escaping data
<sect>PHP string escape chars
<sect>URL encoding (GET)
<sect>POST method
<sect>Escaping for databases
Index: phpdoc/nl/appendices/history.xml
+++ phpdoc/nl/appendices/history.xml
<chapt>PHP's history
<sect>Overview of PHP's development
Index: phpdoc/nl/appendices/http-stuff.xml
+++ phpdoc/nl/appendices/http-stuff.xml
<chapt>Proxies, caching and misc. HTTP stuff
<sect>Setting an expiry date on generated pages
<sect>Using phpLastModified
<sect>CGI version: why does images break (w/solution)
Index: phpdoc/nl/appendices/migration.xml
+++ phpdoc/nl/appendices/migration.xml
<appendix id="migration">
<title>Migrating from PHP/FI 2.0 to PHP 3.0</title>
<sect1 id="migration-about">
<title>About the incompatbilities in 3.0</title>
<simpara>
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.</simpara>
<simpara>
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.</simpara>
<simpara>
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.</simpara>
<simpara>
A conversion program that can automatically convert your old
PHP/FI 2.0 scripts exists. It can be found in the <filename
class="directory">convertor</filename> subdirectory of the PHP 3.0
distribution. This program only catches the syntax changes though,
so you should read this chapter carefully anyway.</simpara></sect1>
<sect1 id="migration-startendtags">
<title>Start/end tags</title>
<para>
The first thing you probably will notice is that PHP's start and end
tags have changed. The old <literal><? ></literal> form has been
replaced by three new possible forms:
<example>
<title>Migration: old start/end tags</title>
<programlisting>
<? echo "This is PHP/FI 2.0 code.\n"; >
</programlisting></example>
As of version 2.0, PHP/FI also supports this variation:
<example><title>Migration: first new start/end tags</title>
<programlisting>
<? echo "This is PHP 3.0 code!\n"; ?>
</programlisting></example>
Notice that the end tag now consists of a question mark and a
greater-than character instead of just greater-than. However, if
you plan on using XML on your server, you will get problems with
the first new variant, because PHP may try to execute the XML
markup in XML documents as PHP code. Because of this, the
following variation was introduced:
<example><title>Migration: second new start/end tags</title>
<programlisting>
<?php echo "This is PHP 3.0 code!\n"; ?>
</programlisting></example>
Some people have had problems with editors that don't understand
the processing instruction tags at all. Microsoft FrontPage is one
such editor, and as a workaround for these, the following variation
was introduced as well:
<example><title>Migration: third new start/end tags</title>
<programlisting>
<script language="php">
echo "This is PHP 3.0 code!\n";
</script>
</programlisting></example></para></sect1>
<sect1 id="migration-if-endif">
<title>if..endif syntax</title>
<para>
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:
<example>
<title>Migration: old if..endif syntax</title>
<programlisting>
if ($foo);
echo "yep\n";
elseif ($bar);
echo "almost\n";
else;
echo "nope\n";
endif;
</programlisting></example>
<example>
<title>Migration: new if..endif syntax</title>
<programlisting>
if ($foo):
echo "yep\n";
elseif ($bar):
echo "almost\n";
else:
echo "nope\n";
endif;
</programlisting></example>
Notice that the semicolons have been replaced by colons in all
statements but the one terminating the expression (endif).</para></sect1>
<sect1 id="migration-while">
<title>while syntax</title>
<para>
Just like with if..endif, the syntax of while..endwhile has changed
as well:
<example><title>Migration: old while..endwhile syntax</title>
<programlisting>
while ($more_to_come);
...
endwhile;
</programlisting></example>
<example><title>Migration: new while..endwhile syntax</title>
<programlisting>
while ($more_to_come):
...
endwhile;
</programlisting></example>
</para>
<warning>
<simpara>
If you use the old while..endwhile syntax in PHP 3.0, you will get
a never-ending loop.
</simpara>
</warning></sect1>
<sect1 id="migration-expr">
<title>Expression types</title>
<simpara>
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.</simpara>
<simpara></simpara>
<para>
Consider this example:
<informalexample><programlisting>
$a[0]=5;
$a[1]=7;
$key = key($a);
while ("" != $key) {
echo "$keyn";
next($a);
}
</programlisting></informalexample>
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 <literal>""</literal> does not equal
<literal>"0"</literal>, 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 <literal>atoi("")</literal> which is
<literal>0</literal>, and <literal>variablelist</literal> which is
also <literal>0</literal>, and since <literal>0==0</literal>, the
loop doesn't go through even once.
</para>
<para>
The fix for this is simple. Replace the while statement with:
<informalexample><programlisting>
while ((string)$key != "") {
</programlisting></informalexample></para></sect1>
<sect1 id="migration-errors">
<title>Error messages have changed</title>
<simpara>
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.
</simpara></sect1>
<sect1 id="migration-booleval">
<title>Short-circuited boolean evaluation</title>
<simpara>
In PHP 3.0 boolean evaluation is short-circuited. This means that
in an expression like <literal>(1 || test_me())</literal>, the
function <function>test_me</function> would not be executed since
nothing can change the result of the expression after the
<literal>1</literal>.</simpara>
<simpara>
This is a minor compatibility issue, but may cause unexpected
side-effects.</simpara></sect1>
<sect1 id="migration-truefalse">
<title>Function true/false return values</title>
<simpara>
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 <literal>$fp = fopen("/your/file") or
fail("darn!");</literal>. 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.</simpara>
<para>
<example>
<title>Migration from 2.0: return values, old code</title>
<programlisting>
$fp = fopen($file, "r");
if ($fp == -1);
echo("Could not open $file for reading<br>\n");
endif;
</programlisting>
</example>
<example>
<title>Migration from 2.0: return values, new code</title>
<programlisting>
$fp = @fopen($file, "r") or print("Could not open $file for
reading<br>\n");
</programlisting>
</example></para></sect1>
<sect1 id="migration-other">
<title>Other incompatibilities</title>
<itemizedlist>
<listitem><simpara>
The PHP 3.0 Apache module no longer supports Apache versions
prior to 1.2. Apache 1.2 or later is required.</simpara></listitem>
<listitem><simpara> <function>echo</function> no longer
supports a format string. Use the
<function>printf</function> function instead.</simpara></listitem>
<listitem><simpara>
In PHP/FI 2.0, an implementation side-effect caused
<literal>$foo[0]</literal> to have the same effect as
<literal>$foo</literal>. This is not true for PHP
3.0.</simpara></listitem>
<listitem><simpara>
Reading arrays with <literal>$array[]</literal> is no longer
supported</simpara>
<simpara>
That is, you cannot traverse an array by having a loop that does
<literal>$data = $array[]</literal>. Use
<function>current</function> and <function>next</function>
instead.</simpara>
<simpara>
Also, <literal>$array1[] = $array2</literal> does not append the
values of <literal>$array2</literal> to <literal>$array1</literal>,
but appends <literal>$array2</literal> as the last entry of
<literal>$array1</literal>. See also multidimensional array
support.</simpara></listitem>
<listitem>
<simpara> <literal>"+"</literal> is no longer overloaded as a
concatenation operator for strings, instead it converts it's
arguments to numbers and performs numeric addition. Use
<literal>"."</literal> instead.</simpara></listitem>
</itemizedlist>
<example>
<title>Migration from 2.0: concatenation for strings</title>
<programlisting>
echo "1" + "1";
</programlisting>
<para>
In PHP 2.0 this would echo 11, in PHP 3.0 it would echo 2. Instead
use:
<programlisting>
echo "1"."1";
</programlisting>
<programlisting>
$a = 1;
$b = 1;
echo $a + $b;
</programlisting></para>
<para>
This would echo 2 in both PHP 2.0 and 3.0.
<programlisting>
$a = 1;
$b = 1;
echo $a.$b;
</programlisting>
This will echo 11 in PHP 3.0.</para>
</example></sect1>
</appendix>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/appendices/phpdevel.xml
+++ phpdoc/nl/appendices/phpdevel.xml
<appendix id="phpdevel">
<title>PHP development</title>
<simpara></simpara>
<sect1 id="phpdevel-addfunc">
<title>Adding functions to PHP 3</title>
<sect2 id="phpdevel-addfunc-prototype">
<title>Function Prototype</title>
<para>
All functions look like this:
<programlisting>
void php3_foo(INTERNAL_FUNCTION_PARAMETERS) {
}
</programlisting>
Even if your function doesn't take any arguments, this is how it is
called.</para></sect2>
<sect2 id="phpdevel-addfunc-args">
<title>Function Arguments</title>
<para>
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:</para>
<para>
<example>
<title>Fetching function arguments</title>
<programlisting>
pval *arg1, *arg2;
if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&arg1,&arg2)==FAILURE) {
WRONG_PARAM_COUNT;
}
</programlisting>
</example>
NOTE: Arguments can be passed either by value or by reference. In
both cases you will need to pass &(pval *) to getParameters. If
you want to check if the n'th parameter was sent to you by
reference or not, you can use the function,
ParameterPassedByReference(ht,n). It will return either 1 or 0.</para>
<simpara>
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.</simpara>
<simpara>
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.</simpara></sect2>
<sect2 id="phpdevel-addfunc-varargs">
<title>Variable Function Arguments</title>
<para>
A function can take a variable number of arguments. If your function can
take either 2 or 3 arguments, use the following:</para>
<para>
<example>
<title>Variable function arguments</title>
<programlisting>
pval *arg1, *arg2, *arg3;
int arg_count = ARG_COUNT(ht);
if (arg_count < 2 || arg_count > 3 ||
getParameters(ht,arg_count,&arg1,&arg2,&arg3)==FAILURE) {
WRONG_PARAM_COUNT;
}
</programlisting>
</example></para></sect2>
<sect2 id="phpdevel-addfunc-using-args">
<title>Using the Function Arguments</title>
<para>
The type of each argument is stored in the pval type field. This
type can be any of the following:
<table>
<title>PHP Internal Types</title>
<tgroup cols="2">
<tbody>
<row>
<entry>IS_STRING</entry>
<entry>String</entry>
</row>
<row>
<entry>IS_DOUBLE</entry>
<entry>Double-precision floating point</entry>
</row>
<row>
<entry>IS_LONG</entry>
<entry>Long integer</entry>
</row>
<row>
<entry>IS_ARRAY</entry>
<entry>Array</entry>
</row>
<row>
<entry>IS_EMPTY</entry>
<entry>None</entry>
</row>
<row>
<entry>IS_USER_FUNCTION</entry>
<entry>??</entry>
</row>
<row>
<entry>IS_INTERNAL_FUNCTION</entry>
<entry>?? (if some of these cannot be passed to a function - delete)</entry>
</row>
<row>
<entry>IS_CLASS</entry>
<entry>??</entry>
</row>
<row>
<entry>IS_OBJECT</entry>
<entry>??</entry>
</row>
</tbody>
</tgroup>
</table></para>
<para>
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:
<programlisting>
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 */
</programlisting></para>
<simpara>
These function all do in-place conversion. They do not return anything.</simpara>
<para>
The actual argument is stored in a union; the members are:
<itemizedlist>
<listitem><simpara>IS_STRING:
arg1->value.str.val</simpara></listitem>
<listitem><simpara>IS_LONG:
arg1->value.lval</simpara></listitem>
<listitem><simpara>IS_DOUBLE:
arg1->value.dval</simpara></listitem>
</itemizedlist></para></sect2>
<sect2 id="phpdevel-addfunc-memmgmt">
<title>Memory Management in Functions</title>
<simpara>
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().</simpara>
<simpara>
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).</simpara>
<simpara>
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.</simpara>
<simpara>
If you compile with "-DDEBUG", PHP 3 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.</simpara></sect2>
<sect2 id="phpdevel-addfunc-symtab">
<title>Setting Variables in the Symbol Table</title>
<para>
A number of macros are available which make it easier to set a
variable in the symbol table:
<itemizedlist>
<listitem><simpara>SET_VAR_STRING(name,value) <footnoteref
linkend="symtab-1"/></simpara></listitem>
<listitem><simpara>SET_VAR_DOUBLE(name,value)</simpara></listitem>
<listitem><simpara>SET_VAR_LONG(name,value)</simpara></listitem>
</itemizedlist></para>
<para>
<footnote id="symtab-1">
<simpara>
Be careful here. 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.</simpara>
</footnote></para>
<simpara>
Symbol tables in PHP 3.0 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).</simpara>
<para>
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.</para>
<para>
<example>
<title>Checking whether $foo exists in a symbol table</title>
<programlisting>
if (hash_exists(active_symbol_table,"foo",sizeof("foo"))) { exists... }
else { doesn't exist }
</programlisting>
</example>
<example>
<title>Finding a variable's size in a symbol table</title>
<programlisting>
hash_find(active_symbol_table,"foo",sizeof("foo"),&pvalue);
check(pvalue.type);
</programlisting>
</example>
Arrays in PHP 3.0 are implemented using the same hashtables as
symbol tables. This means the two above functions can also be
used to check variables inside arrays.</para>
<simpara>
If you want to define a new array in a symbol table, you should do
the following.</simpara>
<simpara>
First, you may want to check whether it exists and abort
appropiately, using hash_exists() or hash_find().</simpara>
<simpara>
Next, initialize the array:</simpara>
<para>
<example>
<title>Initializing a new array</title>
<programlisting>
pval arr;
if (array_init(&arr) == FAILURE) { failed... };
hash_update(active_symbol_table,"foo",sizeof("foo"),&arr,sizeof(pval),NULL);
</programlisting>
</example>
This code declares a new array, named $foo, in the active symbol
table. This array is empty.</para>
<simpara>
Here's how to add new entries to it:</simpara>
<para>
<example>
<title>Adding entries to a new array</title>
<programlisting>
pval entry;
entry.type = IS_LONG;
entry.value.lval = 5;
/* defines $foo["bar"] = 5 */
hash_update(arr.value.ht,"bar",sizeof("bar"),&entry,sizeof(pval),NULL);
/* defines $foo[7] = 5 */
hash_index_update(arr.value.ht,7,&entry,sizeof(pval),NULL);
/* defines the next free place in $foo[],
* $foo[8], to be 5 (works like php2)
*/
hash_next_index_insert(arr.value.ht,&entry,sizeof(pval),NULL);
</programlisting>
</example>
If you'd like to modify a value that you inserted to a hash, you
must first retrieve it from the hash. To prevent that overhead,
you can supply a pval ** to the hash add function, and it'll be
updated with the pval * address of the inserted element inside the
hash. If that value is NULL (like in all of the above examples) -
that parameter is ignored.</para>
<simpara>
hash_next_index_insert() uses more or less the same logic as
"$foo[] = bar;" in PHP 2.0.</simpara>
<simpara>
If you are building an array to return from a function, you can
initialize the array just like above by doing:</simpara>
<programlisting>
if (array_init(return_value) == FAILURE) { failed...; }
</programlisting>
<simpara>
...and then adding values with the helper functions:</simpara>
<programlisting>
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));
</programlisting>
<para>
Of course, if the adding isn't done right after the array
initialization, you'd probably have to look for the array first:
<programlisting>
pval *arr;
if (hash_find(active_symbol_table,"foo",sizeof("foo"),(void
**)&arr)==FAILURE) { can't find... }
else { use arr->value.ht... }
</programlisting></para>
<simpara>
Note that hash_find receives a pointer to a pval pointer, and not
a pval pointer.</simpara>
<simpara>
Just about any hash function returns SUCCESS or FAILURE (except
for hash_exists(), which returns a boolean truth value).</simpara></sect2>
<sect2 id="phpdevel-addfunc-retsimple">
<title>Returning simple values</title>
<simpara>
A number of macros are available to make returning values from a
function easier.</simpara>
<para>
The RETURN_* macros all set the return value and return from the
function:
<itemizedlist>
<listitem><simpara>RETURN</simpara></listitem>
<listitem><simpara>RETURN_FALSE</simpara></listitem>
<listitem><simpara>RETURN_TRUE</simpara></listitem>
<listitem><simpara>RETURN_LONG(l)</simpara></listitem>
<listitem><simpara>RETURN_STRING(s,dup) If dup is true, duplicates the
string</simpara></listitem>
<listitem><simpara>RETURN_STRINGL(s,l,dup) Return string (s) specifying length
(l).</simpara></listitem>
<listitem><simpara>RETURN_DOUBLE(d)</simpara></listitem>
</itemizedlist></para>
<para>
The RETVAL_* macros set the return value, but do not return.
<itemizedlist>
<listitem><simpara>RETVAL_FALSE</simpara></listitem>
<listitem><simpara>RETVAL_TRUE</simpara></listitem>
<listitem><simpara>RETVAL_LONG(l)</simpara></listitem>
<listitem><simpara>RETVAL_STRING(s,dup) If dup is true, duplicates the
string</simpara></listitem>
<listitem><simpara>RETVAL_STRINGL(s,l,dup) Return string (s) specifying length
(l).</simpara></listitem>
<listitem><simpara>RETVAL_DOUBLE(d)</simpara></listitem>
</itemizedlist></para>
<simpara>
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.</simpara>
<simpara>
If your function returns boolean success/error responses, always
use RETURN_TRUE and RETURN_FALSE respectively.</simpara></sect2>
<sect2 id="phpdevel-addfunc-retcomplex">
<title>Returning complex values</title>
<simpara>
Your function can also return a complex data type such as an
object or an array.</simpara>
<para>
Returning an object:
<orderedlist numeration="arabic">
<listitem><simpara>Call object_init(return_value).</simpara></listitem>
<listitem><para>Fill it up with values. The functions available
for this purpose are listed below.</para></listitem>
<listitem><para> 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:
<programlisting>
add_method( return_value, function_name, function_ptr );
</programlisting></para></listitem>
</orderedlist></para>
<para>
The functions used to populate an object are:
<itemizedlist>
<listitem><simpara>add_property_long( return_value,
property_name, l ) - Add a property named 'property_name', of
type long, equal to 'l'</simpara></listitem>
<listitem><simpara>add_property_double( return_value,
property_name, d ) - Same, only adds a double</simpara></listitem>
<listitem><simpara>add_property_string( return_value,
property_name, str ) - Same, only adds a string</simpara></listitem>
<listitem><simpara>add_property_stringl( return_value,
property_name, str, l ) - Same, only adds a string of length
'l'</simpara></listitem>
</itemizedlist></para>
<para>
Returning an array:
<orderedlist numeration="arabic">
<listitem><simpara>Call array_init(return_value).</simpara></listitem>
<listitem><simpara>Fill it up with values. The functions available
for this purpose are listed below.</simpara></listitem>
</orderedlist></para>
<para>
The functions used to populate an array are:
<itemizedlist>
<listitem><simpara>add_assoc_long(return_value,key,l) - add
associative entry with key 'key' and long value
'l'</simpara></listitem>
<listitem><simpara>add_assoc_double(return_value,key,d)</simpara></listitem>
<listitem><simpara>add_assoc_string(return_value,key,str,duplicate)</simpara></listitem>
<listitem><simpara>add_assoc_stringl(return_value,key,str,length,duplicate)
specify the string length</simpara></listitem>
<listitem><simpara>add_index_long(return_value,index,l) - add
entry in index 'index' with long value 'l'</simpara></listitem>
<listitem><simpara>add_index_double(return_value,index,d)</simpara></listitem>
<listitem><simpara>add_index_string(return_value,index,str)</simpara></listitem>
<listitem><simpara>add_index_stringl(return_value,index,str,length)
- specify the string length</simpara></listitem>
<listitem><simpara>add_next_index_long(return_value,l) - add an
array entry in the next free offset with long value
'l'</simpara></listitem>
<listitem><simpara>add_next_index_double(return_value,d)</simpara></listitem>
<listitem><simpara>add_next_index_string(return_value,str)</simpara></listitem>
<listitem><simpara>add_next_index_stringl(return_value,str,length)
- specify the string length</simpara></listitem>
</itemizedlist></para></sect2>
<sect2 id="phpdevel-addfunc-reslist">
<title>Using the resource list</title>
<simpara>
PHP 3.0 has a standard way of dealing with various types of
resources. This replaces all of the local linked lists in PHP 2.0.</simpara>
<para>
Available functions:
<itemizedlist>
<listitem><simpara>php3_list_insert(ptr, type) - returns the 'id'
of the newly inserted resource</simpara></listitem>
<listitem><simpara>php3_list_delete(id) - delete the resource
with the specified id</simpara></listitem>
<listitem><simpara>php3_list_find(id,*type)
- returns the pointer of the resource with the specified id,
updates 'type' to the resource's type</simpara></listitem>
</itemizedlist>
Typically, these functions are used for SQL drivers but they can
be used for anything else; for instance, maintaining file
descriptors.</para>
<simpara>
Typical list code would look like this:</simpara>
<para>
<example>
<title>Adding a new resource</title>
<programlisting>
RESOURCE *resource;
/* ...allocate memory for resource and acquire resource... */
/* add a new resource to the list */
return_value->value.lval = php3_list_insert((void *) resource, LE_RESOURCE_TYPE);
return_value->type = IS_LONG;
</programlisting>
</example>
<example>
<title>Using an existing resource</title>
<programlisting>
pval *resource_id;
RESOURCE *resource;
int type;
convert_to_long(resource_id);
resource = php3_list_find(resource_id->value.lval, &type);
if (type != LE_RESOURCE_TYPE) {
php3_error(E_WARNING,"resource index %d has the wrong
type",resource_id->value.lval);
RETURN_FALSE;
}
/* ...use resource... */
</programlisting>
</example>
<example>
<title>Deleting an existing resource</title>
<programlisting>
pval *resource_id;
RESOURCE *resource;
int type;
convert_to_long(resource_id);
php3_list_delete(resource_id->value.lval);
</programlisting>
</example>
The resource types should be registered in php3_list.h, in enum
list_entry_type. In addition, one should add shutdown code for
any new resource type defined, in list.c's list_entry_destructor()
(even if you don't have anything to do on shutdown, you must add
an empty case).</para></sect2>
<sect2 id="phpdevel-addfunc-prestable">
<title>Using the persistent resource table</title>
<para>
PHP 3.0 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:
<simplelist>
<member>php3_mysql_do_connect</member>
<member>php3_mysql_connect()</member>
<member>php3_mysql_pconnect()</member>
</simplelist></para>
<para>
The general idea of persistence modules is this:
<orderedlist numeration="arabic">
<listitem><simpara>Code all of your module to work with the
regular resource list mentioned in section (9).</simpara></listitem>
<listitem><simpara>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).</simpara></listitem>
</orderedlist></para>
<simpara>
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.</simpara>
<simpara>
The very same interface exists for the regular resource list and
the persistent resource list, only 'list' is replaced with
'plist':</simpara>
<itemizedlist>
<listitem><simpara>php3_plist_insert(ptr, type) - returns the 'id'
of the newly inserted resource</simpara></listitem>
<listitem><simpara>php3_plist_delete(id) - delete the resource
with the specified id</simpara></listitem>
<listitem><simpara>php3_plist_find(id,*type)
- returns the pointer of the resource with the specified id,
updates 'type' to the resource's type</simpara></listitem>
</itemizedlist>
<simpara>
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.</simpara>
<simpara>
Until further documented, you should look at mysql.c or msql.c to
see how one should use the plist's hash table abilities.</simpara>
<simpara>
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.</simpara>
<simpara>
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 destructotion 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.</simpara></sect2>
<sect2 id="phpdevel-addfunc-addcfg">
<title>Adding runtime configuration directives</title>
<para>
Many of the features of PHP 3 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.</para>
<para>
The steps required to add a new directive:
<orderedlist>
<listitem><simpara>Add directive to php3_ini_structure struct in
mod_php3.h.</simpara></listitem>
<listitem><simpara>In main.c, edit the php3_module_startup
function and add the appropriate cfg_get_string() or
cfg_get_long() call.</simpara></listitem>
<listitem><simpara>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.</simpara></listitem>
<listitem><simpara>In either php3take1handler() or
php3flaghandler() add the appropriate entry for your
directive.</simpara></listitem>
<listitem><simpara>In the configuration section of the
_php3_info() function in functions/info.c you need to add your
new directive.</simpara></listitem>
<listitem><simpara>And last, you of course have to use your new
directive somewhere. It will be addressable as
php3_ini.directive.</simpara></listitem>
</orderedlist></para></sect2></sect1>
<sect1 id="calling-user-functions">
<title>Calling User Functions</title>
<simpara>
To call user functions from an internal function, you should use
the <function>call_user_function</function> function.
</simpara>
<simpara>
<function>call_user_function</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.
</simpara>
<simpara>
All internal functions that call user functions
<emphasis>must</emphasis> be reentrant. Among other things, this
means they must not use globals or static variables.
</simpara>
<simpara>
<function>call_user_function</function> takes six arguments:
</simpara>
<sect2 id="calling-user-functions.function-table">
<title>HashTable *function_table</title>
<simpara>
This is the hash table in which the function is to be looked up.
</simpara></sect2>
<sect2 id="calling-user-functions.object">
<title>pval *object</title>
<simpara>
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.
</simpara></sect2>
<sect2 id="calling-user-functions.function-name">
<title>pval *function_name</title>
<simpara>
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.
</simpara></sect2>
<sect2 id="calling-user-functions.retval">
<title>pval *retval</title>
<simpara>
A pointer to a pval structure, into which the return value of
the invoked function is saved. The structure must be previously
allocated - <function>call_user_function</function> does NOT allocate
it by itself.
</simpara></sect2>
<sect2 id="calling-user-functions.param-count">
<title>int param_count</title>
<simpara>
The number of parameters being passed to the function.
</simpara></sect2>
<sect2 id="calling-user-functions.params">
<title>pval *params[]</title>
<simpara>
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.
</simpara></sect2></sect1>
<sect1 id="phpdevel-errors">
<title>Reporting Errors</title>
<simpara>
To report errors from an internal function, you should call the
<function>php3_error</function> 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
<function>printf</function> call), and any following arguments
are the parameters for the format string. The error levels are:
</simpara>
<sect2 id="internal.e-notice">
<title>E_NOTICE</title>
<simpara>
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 <function>stat</function> on a file that doesn't exist.
</simpara>
</sect2>
<sect2 id="internal.e-warning">
<title>E_WARNING</title>
<simpara>
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
<function>ereg</function> with an invalid regular expression.
</simpara>
</sect2>
<sect2 id="internal.e-error">
<title>E_ERROR</title>
<simpara>
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.
</simpara>
</sect2>
<sect2 id="internal.e-parse">
<title>E_PARSE</title>
<simpara>
Parse errors should only be generated by the parser. The code is
listed here only for the sake of completeness.
</simpara>
</sect2>
<sect2 id="internal.e-core-error">
<title>E_CORE_ERROR</title>
<simpara>
This is like an E_ERROR, except it is generated by the core
of PHP. Functions should not generate this type of error.
</simpara>
</sect2>
<sect2 id="internal.e-core-warning">
<title>E_CORE_WARNING</title>
<simpara>
This is like an E_WARNING, except it is generated by the core
of PHP. Functions should not generate this type of error.
</simpara>
</sect2>
<sect2 id="internal.e-compile-error">
<title>E_COMPILE_ERROR</title>
<simpara>
This is like an E_ERROR, except it is generated by the Zend Scripting
Engine. Functions should not generate this type of error.
</simpara>
</sect2>
<sect2 id="internal.e-compile-warning">
<title>E_COMPILE_WARNING</title>
<simpara>
This is like an E_WARNING, except it is generated by the Zend Scripting
Engine. Functions should not generate this type of error.
</simpara>
</sect2>
<sect2 id="internal.e-user-error">
<title>E_USER_ERROR</title>
<simpara>
This is like an E_ERROR, except it is generated in PHP code by using
the PHP function <function>trigger_error</function>. Functions should
not generate this type of error.
</simpara>
</sect2>
<sect2 id="internal.e-user-warning">
<title>E_USER_WARNING</title>
<simpara>
This is like an E_WARNING, except it is generated by using the PHP
function <function>trigger_error</function>. Functions should not
generate this type of error.
</simpara>
</sect2>
<sect2 id="internal.e-user-notice">
<title>E_USER_NOTICE</title>
<simpara>
This is like an E_NOTICE, except it is generated by using the PHP
function <function>trigger_error</function>. Functions should not
generate this type of error.
</simpara>
</sect2>
</sect1>
</appendix>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/appendices/regexp.xml
+++ phpdoc/nl/appendices/regexp.xml
<chapt>Regular expressions
<sect>Short overview to regexps with pointers to more info
Index: phpdoc/nl/chapters/config.xml
+++ phpdoc/nl/chapters/config.xml
<chapter id="configuration">
<title>Configuration</title>
<sect1 id="configuration.file">
<title>The configuration file</title>
<simpara>
The configuration file (called <filename>php3.ini</filename> in
PHP 3.0, and simply <filename>php.ini</filename> as of PHP 4.0)
is read when PHP starts up. For the server module versions of PHP,
this happens only once when the web server is started. For the
<acronym>CGI</acronym> version, it happens on every invocation.</simpara>
<simpara>
When using PHP as an Apache module, you can also change the
configuration settings using directives in Apache configuration
files and .htaccess files.</simpara>
<simpara>
With PHP 3.0, there are Apache directives that correspond to each
configuration setting in the <filename>php3.ini</filename> name,
except the name is prefixed by "php3_".</simpara>
<para>
With PHP 4.0, there are just a few Apache directives that allow you
to change the PHP configuration settings.
<variablelist>
<varlistentry>
<term>
<systemitem role="directive">php_value</systemitem>
<parameter>name</parameter>
<parameter>value</parameter>
</term>
<listitem>
<para>
This sets the value of the specified variable.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<systemitem role="directive">php_flag</systemitem>
<parameter>name</parameter>
<parameter>on|off</parameter>
</term>
<listitem>
<para>
This is used to set a Boolean configuration option.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<systemitem role="directive">php_admin_value</systemitem>
<parameter>name</parameter>
<parameter>value</parameter>
</term>
<listitem>
<para>
This sets the value of the specified variable. "Admin"
configuration settings can only be set from within the
main Apache configuration files, and not from .htaccess
files.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<systemitem role="directive">php_admin_flag</systemitem>
<parameter>name</parameter>
<parameter>on|off</parameter>
</term>
<listitem>
<para>
This is used to set a Boolean configuration option.</para>
</listitem>
</varlistentry>
</variablelist></para>
<simpara>
You can view the settings of the configuration values in
the output of <function>phpinfo</function>. You can also
access the values of individial configuration settings using
<function>get_cfg_var</function>.</simpara>
<sect2 id="ini.sect.general">
<title>General Configuration Directives</title>
<para>
<variablelist>
<varlistentry id="ini.asp-tags">
<term>
<parameter>asp_tags</parameter>
<type>boolean</type>
</term>
<listitem>
<simpara>
Enables the use of ASP-like <% %> tags in addition to
the usual <?php ?> tags. This includes the
variable-value printing shorthand of <%= $value %>. For
more information, see <link linkend="language.basic-syntax.phpmode">Escaping from
HTML</link>.
</simpara>
<note>
<para>Support for ASP-style tags was added in 3.0.4.</para>
</note>
</listitem>
</varlistentry>
<varlistentry id="ini.auto-append-file">
<term>
<parameter>auto_append_file</parameter>
<type>string</type>
</term>
<listitem>
<para>
Specifies the name of a file that is automatically parsed
after the main file. The file is included as if it was
called with the <function>include</function> function, so
<link linkend="ini.include-path">include_path</link> is used.</para>
<para>
The special value <systemitem class="constant">none</systemitem> disables
auto-appending.
<note>
<simpara>
If the script is terminated with <function>exit</function>,
auto-append will <emphasis>not</emphasis> occur.</simpara>
</note></para>
</listitem>
</varlistentry>
<varlistentry id="ini.auto-prepend-file">
<term>
<parameter>auto_prepend_file</parameter>
<type>string</type>
</term>
<listitem>
<para>
Specifies the name of a file that is automatically parsed
before the main file. The file is included as if it was
called with the <function>include</function> function, so
<link linkend="ini.include-path">include_path</link> is used.</para>
<para>
The special value <systemitem class="constant">none</systemitem> disables
auto-prepending.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.cgi-ext">
<term>
<parameter>cgi_ext</parameter>
<type>string</type>
</term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.display-errors">
<term>
<parameter>display_errors</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
This determines whether errors should be printed to the screen
as part of the HTML output or not.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.doc-root">
<term>
<parameter>doc_root</parameter>
<type>string</type>
</term>
<listitem>
<para>
PHP's "root directory" on the server. Only used if
non-empty. If PHP is configured with <link linkend="ini.safe-mode">safe
mode</link>, no files outside
this directory are served.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.engine">
<term>
<parameter>engine</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
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 <userinput>engine
off</userinput> in the appropriate places in the
<filename>httpd.conf</filename> file, PHP can be enabled or
disabled.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.error-log">
<term>
<parameter>error_log</parameter>
<type>string</type>
</term>
<listitem>
<para>
Name of file where script errors should be logged. If the
special value <literal>syslog</literal> 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.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.error-reporting">
<term>
<parameter>error_reporting</parameter>
<type>integer</type>
</term>
<listitem>
<para>
Set the error reporting level. The parameter is an integer
representing a bit field. Add the values of the error
reporting levels you want.
<table>
<title>Error Reporting Levels</title>
<tgroup cols="2">
<thead>
<row>
<entry>bit value</entry>
<entry>enabled reporting</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>normal errors</entry>
</row>
<row>
<entry>2</entry>
<entry>normal warnings</entry>
</row>
<row>
<entry>4</entry>
<entry>parser errors</entry>
</row>
<row>
<entry>8</entry>
<entry>non-critical style-related warnings</entry>
</row>
</tbody>
</tgroup>
</table>
The default value for this directive is 7 (normal errors,
normal warnings and parser errors are shown).
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.open-basedir">
<term>
<parameter>open_basedir</parameter>
<type>string</type>
</term>
<listitem>
<para>
Limit the files that can be opened by PHP to the specified
directory-tree.
</para>
<para>
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.
</para>
<para>
The special value <systemitem class="constant">.</systemitem>
indicates that the directory in which the script is stored will
be used as base-directory.
</para>
<para>
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.
</para>
<note>
<para>Support for multiple directories was added in 3.0.7.</para>
</note>
<para>
The default is to allow all files to be opened.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.gpc-order">
<term>
<parameter>gpc_order</parameter>
<type>string</type>
</term>
<listitem>
<para>
Set the order of GET/POST/COOKIE variable parsing. The
default setting of this directive is "GPC". Setting this to
"GP", for example, will cause PHP to completely ignore cookies
and to overwrite any GET method variables with POST-method
variables of the same name.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ignore-user-abort">
<term>
<parameter>ignore_user_abort</parameter>
<type>string</type>
</term>
<listitem>
<para>
On by default. If changed to Off scripts will be terminated as
soon as they try to output something after a client has aborted
their connection.
<function>ignore_user_abort</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.include-path">
<term>
<parameter>include_path</parameter>
<type>string</type>
</term>
<listitem>
<para>
Specifies a list of directories where the
<function>require</function>, <function>include</function>
and <function>fopen_with_path</function> functions look for
files. The format is like the system's <envar>PATH</envar>
environment variable: a list of directories separated with a
colon in UNIX or semicolon in Windows.
<example>
<title>UNIX include_path</title>
<programlisting role="php3.ini">
include_path=.:/home/httpd/php-lib
</programlisting>
</example>
<example>
<title>Windows include_path</title>
<programlisting role="php3.ini">
include_path=".;c:\www\phplib"
</programlisting>
</example>
The default value for this directive is <literal>.</literal>
(only the current directory).</para>
</listitem>
</varlistentry>
<varlistentry id="ini.isapi-ext">
<term>
<parameter>isapi_ext</parameter>
<type>string</type>
</term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.log-errors">
<term>
<parameter>log_errors</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Tells whether script error messages should be logged to the
server's error log. This option is thus server-specific.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.magic-quotes-gpc">
<term>
<parameter>magic_quotes_gpc</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
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 magic_quotes_sybase is
also on, a single-quote is escaped with a single-quote
instead of a backslash.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.magic-quotes-runtime">
<term>
<parameter>magic_quotes_runtime</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
If <parameter>magic_quotes_runtime</parameter> 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
<parameter>magic_quotes_sybase</parameter> is also on, a
single-quote is escaped with a single-quote instead of a
backslash.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.magic-quotes-sybase">
<term>
<parameter>magic_quotes_sybase</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
If <parameter>magic_quotes_sybase</parameter> is also on, a
single-quote is escaped with a single-quote instead of a
backslash if <parameter>magic_quotes_gpc</parameter> or
<parameter>magic_quotes_runtime</parameter> is enabled.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.max-execution-time">
<term>
<parameter>max_execution_time</parameter>
<type>integer</type>
</term>
<listitem>
<para>
This sets the maximum time in seconds a script is allowed to
take before it is terminated by the parser. This helps
prevent poorly written scripts from tying up the server. The
default setting is <literal>30</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.memory-limit">
<term>
<parameter>memory_limit</parameter>
<type>integer</type>
</term>
<listitem>
<para>
This sets the maximum amount of memory in bytes that a script
is allowed to allocate. This helps prevent poorly written
scripts for eating up all available memory on a server.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.nsapi-ext">
<term>
<parameter>nsapi_ext</parameter>
<type>string</type>
</term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.register-globals">
<term>
<parameter>register_globals</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Tells whether or not to register the EGPCS (Environment, GET,
POST, Cookie, Server) variables as global variables. You may
want to turn this off if you don't want to clutter your
scripts' global scope with user data. This makes the most
sense when coupled with <link
linkend="ini.track-vars">track_vars</link> - in which case
you can access all of the EGPCS variables through the
<varname>$HTTP_ENV_VARS</varname>,
<varname>$HTTP_GET_VARS</varname>,
<varname>$HTTP_POST_VARS</varname>,
<varname>$HTTP_COOKIE_VARS</varname>, and
<varname>$HTTP_SERVER_VARS</varname>
arrays in the global scope.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.short-open-tag">
<term>
<parameter>short_open_tag</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Tells whether the short form (<userinput><? ?></userinput>of
PHP's open tag should be allowed. If you want to use PHP in
combination with XML, you have to disable this option. If
disabled, you must use the long form of the open tag
(<userinput><?php ?></userinput>).</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sql.safe-mode">
<term>
<parameter>sql.safe_mode</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.track-errors">
<term>
<parameter>track_errors</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
If enabled, the last error message will always be present in the
global variable <symbol>$php_errormsg</symbol>.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.track-vars">
<term>
<parameter>track_vars</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
If enabled, then Environment, GET, POST, Cookie, and Server
variables can be found in the global associative arrays
<varname>$HTTP_ENV_VARS</varname>,
<varname>$HTTP_GET_VARS</varname>,
<varname>$HTTP_POST_VARS</varname>,
<varname>$HTTP_COOKIE_VARS</varname>, and
<varname>$HTTP_SERVER_VARS</varname>.
</para>
<para>
Note that as of PHP 4.0.3, <systemitem
role="directive">track_vars</systemitem> is always turned on.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.upload-tmp-dir">
<term>
<parameter>upload_tmp_dir</parameter>
<type>string</type>
</term>
<listitem>
<para>
The temporary directory used for storing files when doing
file upload. Must be writable by whatever user PHP is
running as.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.user-dir">
<term>
<parameter>user_dir</parameter>
<type>string</type>
</term>
<listitem>
<para>
The base name of the directory used on a user's home
directory for PHP files, for example
<literal>public_html</literal>.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.warn-plus-overloading">
<term>
<parameter>warn_plus_overloading</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
If enabled, this option makes PHP output a warning when the
plus (<literal>+</literal>) 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
(<literal>.</literal>).</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</sect2>
<sect2 id="ini.sect.mail">
<title>Mail Configuration Directives</title>
<variablelist>
<varlistentry id="ini.smtp">
<term>
<parameter>SMTP</parameter>
<type>string</type>
</term>
<listitem>
<para>
DNS name or IP address of the SMTP server PHP under Windows
should use for mail sent with the <function>mail</function>
function.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sendmail-from">
<term>
<parameter>sendmail_from</parameter>
<type>string</type>
</term>
<listitem>
<para>
Which "From:" mail address should be used in mail sent from
PHP under Windows.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sendmail-path">
<term>
<parameter>sendmail_path</parameter>
<type>string</type>
</term>
<listitem>
<para>
Where the <command>sendmail</command> program can be found,
usually <filename>/usr/sbin/sendmail</filename> or
<filename>/usr/lib/sendmail</filename>
<command>configure</command> does an honest attempt of
locating this one for you and set a default, but if it fails,
you can set it here.</para>
<para>
Systems not using sendmail should set this directive to the
sendmail wrapper/replacement their mail system offers, if any.
For example, <ulink url="&url.qmail;">Qmail</ulink>
users can normally set it to
<filename>/var/qmail/bin/sendmail</filename>.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.safe-mode">
<title>Safe Mode Configuration Directives</title>
<variablelist>
<varlistentry id="ini.safe-mode">
<term>
<parameter>safe_mode</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to enable PHP's safe mode. Read the <link linkend="security">Security
chapter</link> for more
more information.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.safe-mode-exec-dir">
<term>
<parameter>safe_mode_exec_dir</parameter>
<type>string</type>
</term>
<listitem>
<para>
If PHP is used in safe mode, <function>system</function> and
the other functions executing system programs refuse to start
programs that are not in this directory.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.debugger">
<title>Debugger Configuration Directives</title>
<variablelist>
<varlistentry id="ini.debugger.host">
<term>
<parameter>debugger.host</parameter>
<type>string</type>
</term>
<listitem>
<para>
DNS name or IP address of host used by the debugger.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.debugger.port">
<term>
<parameter>debugger.port</parameter>
<type>string</type>
</term>
<listitem>
<para>
Port number used by the debugger.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.debugger.enabled">
<term>
<parameter>debugger.enabled</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether the debugger is enabled.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.extension">
<title>Extension Loading Directives</title>
<variablelist>
<varlistentry id="ini.enable-dl">
<term>
<parameter>enable_dl</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
This directive is really only useful in the Apache module
version of PHP. You can turn dynamic loading of PHP
extensions with <function>dl</function> on and off per
virtual server or per directory.
</para>
<para>
The main reason for turning dynamic loading off is
security. With dynamic loading, it's possible to ignore all
the safe_mode and open_basedir restrictions.
</para>
<para>
The default is to allow dynamic loading, except when using
safe-mode. In safe-mode, it's always imposible to use
<function>dl</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.extension-dir">
<term>
<parameter>extension_dir</parameter>
<type>string</type>
</term>
<listitem>
<para>
In what directory PHP should look for dynamically loadable
extensions.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.extension">
<term>
<parameter>extension</parameter>
<type>string</type>
</term>
<listitem>
<para>
Which dynamically loadable extensions to load when PHP starts
up.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.mysql">
<title>MySQL Configuration Directives</title>
<variablelist>
<varlistentry id="ini.mysql.allow-persistent">
<term>
<parameter>mysql.allow_persistent</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to allow persistent MySQL connections.</para>
</listitem>
</varlistentry>
<varlistentry id="ini.mysql.default-host">
<term>
<parameter>mysql.default_host</parameter>
<type>string</type>
</term>
<listitem>
<para>
The default server host to use when connecting to the database
server if no other host is specified.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.mysql.default-user">
<term>
<parameter>mysql.default_user</parameter>
<type>string</type>
</term>
<listitem>
<para>
The default user name to use when connecting to the database
server if no other name is specified.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.mysql.default-password">
<term>
<parameter>mysql.default_password</parameter>
<type>string</type>
</term>
<listitem>
<para>
The default password to use when connecting to the database
server if no other password is specified.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.mysql.max-persistent">
<term>
<parameter>mysql.max_persistent</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of persistent MySQL connections per
process.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.mysql.max-links">
<term>
<parameter>mysql.max_links</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of MySQL connections per process, including
persistent connections.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.msql">
<title>mSQL Configuration Directives</title>
<variablelist>
<varlistentry id="ini.msql.allow-persistent">
<term>
<parameter>msql.allow_persistent</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to allow persistent mSQL connections.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.msql.max-persistent">
<term>
<parameter>msql.max_persistent</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of persistent mSQL connections per process.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.msql.max-links">
<term>
<parameter>msql.max_links</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of mSQL connections per process, including
persistent connections.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.pgsql">
<title>Postgres Configuration Directives</title>
<variablelist>
<varlistentry id="ini.pgsql.allow-persistent">
<term>
<parameter>pgsql.allow_persistent</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to allow persistent Postgres connections.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.pgsql.max-persistent">
<term>
<parameter>pgsql.max_persistent</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of persistent Postgres connections per
process.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.pgsql.max-links">
<term>
<parameter>pgsql.max_links</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of Postgres connections per process,
including persistent connections.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.sybase">
<title>Sybase Configuration Directives</title>
<variablelist>
<varlistentry id="ini.sybase.allow-persistent">
<term>
<parameter>sybase.allow_persistent</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to allow persistent Sybase connections.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybase.max-persistent">
<term>
<parameter>sybase.max_persistent</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of persistent Sybase connections per
process.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybase.max-links">
<term>
<parameter>sybase.max_links</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of Sybase connections per process,
including persistent connections.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.sybct">
<title>Sybase-CT Configuration Directives</title>
<variablelist>
<varlistentry id="ini.sybct.allow-persistent">
<term>
<parameter>sybct.allow_persistent</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to allow persistent Sybase-CT connections.
The default is on.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybct.max-persistent">
<term>
<parameter>sybct.max_persistent</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of persistent Sybase-CT connections per
process. The default is -1 meaning unlimited.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybct.max-links">
<term>
<parameter>sybct.max_links</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of Sybase-CT connections per process,
including persistent connections. The default is -1 meaning
unlimited.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybct.min-server-severity">
<term>
<parameter>sybct.min_server_severity</parameter>
<type>integer</type>
</term>
<listitem>
<para>
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
<function>sybase_min_server_severity</function>. The default
is 10 which reports errors of information severity or greater.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybct.min-client-severity">
<term>
<parameter>sybct.min_client_severity</parameter>
<type>integer</type>
</term>
<listitem>
<para>
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
<function>sybase_min_client_severity</function>. The default
is 10 which effectively disables reporting.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybct.login-timeout">
<term>
<parameter>sybct.login_timeout</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum time in seconds to wait for a connection attempt
to succeed before returning failure. Note that if
max_execution_time has been exceeded when a connection attempt
times out, your script will be terminated before it can take
action on failure. The default is one minute.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybct.timeout">
<term>
<parameter>sybct.timeout</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum time in seconds to wait for a select_db or query
operation to succeed before returning failure. Note that if
max_execution_time has been exceeded when am operation times
out, your script will be terminated before it can take action
on failure. The default is no limit.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.sybct.hostname">
<term>
<parameter>sybct.hostname</parameter>
<type>string</type>
</term>
<listitem>
<para>
The name of the host you claim to be connecting from, for
display by sp_who. The default is none.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.informix">
<title>Informix Configuration Directives</title>
<variablelist>
<varlistentry id="ini.ifx.allow-persistent">
<term>
<parameter>ifx.allow_persistent</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to allow persistent Informix connections.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.max-persistent">
<term>
<parameter>ifx.max_persistent</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of persistent Informix connections per
process.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.max-links">
<term>
<parameter>ifx.max_links</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of Informix connections per process, including
persistent connections.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.default-host">
<term>
<parameter>ifx.default_host</parameter>
<type>string</type>
</term>
<listitem>
<para>
The default host to connect to when no host is specified
in <function>ifx_connect</function> or
<function>ifx_pconnect</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.default-user">
<term>
<parameter>ifx.default_user</parameter>
<type>string</type>
</term>
<listitem>
<para>
The default user id to use when none is specified
in <function>ifx_connect</function> or
<function>ifx_pconnect</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.default-password">
<term>
<parameter>ifx.default_password</parameter>
<type>string</type>
</term>
<listitem>
<para>
The default password to use when none is specified
in <function>ifx_connect</function> or
<function>ifx_pconnect</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.blobinfile">
<term>
<parameter>ifx.blobinfile</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
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 <function>ifx_blobinfile_mode</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.textasvarchar">
<term>
<parameter>ifx.textasvarchar</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
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
<function>ifx_textasvarchar</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.byteasvarchar">
<term>
<parameter>ifx.byteasvarchar</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
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
<function>ifx_textasvarchar</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.charasvarchar">
<term>
<parameter>ifx.charasvarchar</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Set to true if you want to trim trailing spaces
from CHAR columns when fetching them.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.ifx.nullformat">
<term>
<parameter>ifx.nullformat</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
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
<function>ifx_nullformat</function>.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.bcmath">
<title>BC Math Configuration Directives</title>
<variablelist>
<varlistentry id="ini.bcmath.scale">
<term>
<parameter>bcmath.scale</parameter>
<type>integer</type>
</term>
<listitem>
<para>
Number of decimal digits for all bcmath functions.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.browscap">
<title>Browser Capability Configuration Directives</title>
<variablelist>
<varlistentry id="ini.browscap">
<term>
<parameter>browscap</parameter>
<type>string</type>
</term>
<listitem>
<para>
Name of browser capabilities file. See also
<function>get_browser</function>.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="ini.sect.uodbc">
<title>Unified ODBC Configuration Directives</title>
<variablelist>
<varlistentry id="ini.uodbc.default-db">
<term>
<parameter>uodbc.default_db</parameter>
<type>string</type>
</term>
<listitem>
<para>
ODBC data source to use if none is specified in
<function>odbc_connect</function> or
<function>odbc_pconnect</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.uodbc.default-user">
<term>
<parameter>uodbc.default_user</parameter>
<type>string</type>
</term>
<listitem>
<para>
User name to use if none is specified in
<function>odbc_connect</function> or
<function>odbc_pconnect</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.uodbc.default-pw">
<term>
<parameter>uodbc.default_pw</parameter>
<type>string</type>
</term>
<listitem>
<para>
Password to use if none is specified in
<function>odbc_connect</function> or
<function>odbc_pconnect</function>.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.uodbc.allow-persistent">
<term>
<parameter>uodbc.allow_persistent</parameter>
<type>boolean</type>
</term>
<listitem>
<para>
Whether to allow persistent ODBC connections.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.uodbc.max-persistent">
<term>
<parameter>uodbc.max_persistent</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of persistent ODBC connections per process.
</para>
</listitem>
</varlistentry>
<varlistentry id="ini.uodbc.max-links">
<term>
<parameter>uodbc.max_links</parameter>
<type>integer</type>
</term>
<listitem>
<para>
The maximum number of ODBC connections per process, including
persistent connections.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/chapters/copyright.xml
+++ phpdoc/nl/chapters/copyright.xml
<chapter id="copyright">
<title>Copyright, distribution, version history</title>
<simpara>
PHP 3.0 is copyright (C) 1997 the PHP Development Team. The
members of this team are listed in the CREDITS file that comes with
the PHP 3.0 source distribution.</simpara>
<simpara>
PHP 3.0 is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.</simpara>
<simpara>
PHP 3.0 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.</simpara>
<simpara>
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</simpara>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/chapters/install.xml
+++ phpdoc/nl/chapters/install.xml
<chapter id="installation">
<title>Installation</title>
<sect1 id="install.downloading">
<title>Downloading the latest version</title>
<simpara>
The source code, and binary distributions for some platforms
(including Windows), can be found at <literal><ulink
url="&url.php;">&url.php;</ulink></literal>.
</simpara>
</sect1>
<sect1 id="install.unix">
<title>Installation on UNIX systems</title>
<para>
This section will guide you through the configuration and
installation of PHP.
</para>
<para>
Prerequisite knowledge and software:
<itemizedlist>
<listitem>
<simpara>
Basic UNIX skills (being able to operate "make" and a C
compiler)
</simpara>
</listitem>
<listitem>
<simpara>
An ANSI C compiler
</simpara>
</listitem>
<listitem>
<simpara>
A web server
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
There are several ways to compile and configure PHP for the Unix
platform. The entire configuration process is controlled by the
use of commandline options to the <filename>configure</filename>
script. This page outlines the usage of the most common options,
but there are many others to play with. Check out the <link
linkend="install.configure">Complete list of configure
options</link> for an exhaustive rundown.
<itemizedlist>
<listitem>
<simpara>
As an <link linkend="install.unix.apache-module">Apache module</link>
</simpara>
</listitem>
<listitem>
<simpara>
As an <link linkend="install.unix.fhttpd">fhttpd module</link>
</simpara>
</listitem>
<listitem>
<simpara>
For use with <link
linkend="install.unix.otherhttpd">AOLServer, NSAPI,
phttpd, Pi3Web, Roxen, thttpd, or Zeus.</link>
</simpara>
</listitem>
<listitem>
<simpara>
As a <link linkend="install.unix.commandline">CGI executable</link>
</simpara>
</listitem>
</itemizedlist>
</para>
<sect2 id="install.unix.apache-module">
<title>Apache Module</title>
<para>
PHP can be compiled in a number of different ways as an Apache
module. First we show the quick instructions. Following this is
a list of various examples with explanations, to provide an
overview of how to accomplish certain things.
</para>
<para>
You can select arguments to add to the
<command>configure</command> on line 8 below from the <link
linkend="install.configure">Complete list of configure
options</link>.
</para>
<example id="install.unix.apache-module.quick">
<title>
Quick Installation Instructions (Apache Module Version)
</title>
<programlisting>
1. gunzip apache_1.3.x.tar.gz
2. tar xvf apache_1.3.x.tar
3. gunzip php-x.x.x.tar.gz
4. tar xvf php-x.x.x.tar
5. cd apache_1.3.x
6. ./configure --prefix=/www
7. cd ../php-x.x.x
8. ./configure --with-mysql --with-apache=../apache_1.3.x --enable-track-vars
9. make
10. make install
11. cd ../apache_1.3.x
12. for PHP 3: ./configure --activate-module=src/modules/php3/libphp3.a
for PHP 4: ./configure --activate-module=src/modules/php4/libphp4.a
13. make
14. make install
Instead of this step you may prefer to simply copy the httpd binary
overtop of your existing binary. Make sure you shut down your
server first though.
15. cd ../php-x.x.x
16. for PHP 3: cp php3.ini-dist /usr/local/lib/php3.ini
for PHP 4: cp php.ini-dist /usr/local/lib/php.ini
You can edit your .ini file to set PHP options. If
you prefer this file in another location, use
--with-config-file-path=/path in step 8.
17. Edit your httpd.conf or srm.conf file and add:
For PHP 3: AddType application/x-httpd-php3 .php3
For PHP 4: AddType application/x-httpd-php .php
You can choose any extension you wish here. .php is simply the one
we suggest. You can even include .html .
18. Use your normal procedure for starting the Apache server. (You must
stop and restart the server, not just cause the server to reload by
use a HUP or USR1 signal.)
</programlisting>
</example>
<para>
<informalexample>
<programlisting>
/configure --with-apxs --with-pgsql
</programlisting>
</informalexample>
</para>
<para>
This will create a <filename>libphp4.so</filename> shared
library that is loaded into Apache using a LoadModule line in
Apache's <filename>httpd.conf</filename> file. The PostgreSQL
support is embedded into this <filename>libphp4.so</filename>
library.
</para>
<para>
<informalexample>
<programlisting>
/configure --with-apxs --with-pgsql=shared
</programlisting>
</informalexample>
</para>
<para>
This will again create a <filename>libphp4.so</filename> shared
library for Apache, but it will also create a
<filename>pgsql.so</filename> shared library that is loaded into
PHP either by using the extension directive in
<filename>php.ini</filename> file or by loading it explicitly in
a script using the <function>dl</function> function.
</para>
<para>
<informalexample>
<programlisting>
/configure --with-apache=/path/to/apache_source --with-pgsql
</programlisting>
</informalexample>
</para>
<para>
This will create a <filename>libmodphp4.a</filename> library, a
<filename>mod_php4.c</filename> and some accompanying files and
copy this into the <literal>src/modules/php4</literal> directory
in the Apache source tree. Then you compile Apache using
<literal>--activate-module=src/modules/php4/libphp4.a</literal>
and the Apache build system will create
<filename>libphp4.a</filename> and link it statically into the
<filename>httpd</filename> binary. The PostgreSQL support is
included directly into this <filename>httpd</filename> binary,
so the final result here is a single <filename>httpd</filename>
binary that includes all of Apache and all of PHP.
</para>
<para>
<informalexample>
<programlisting>
/configure --with-apache=/path/to/apache_source --with-pgsql=shared
</programlisting>
</informalexample>
</para>
<para>
Same as before, except instead of including PostgreSQL support
directly into the final <filename>httpd</filename> you will get
a <filename>pgsql.so</filename> shared library that you can load
into PHP from either the <filename>php.ini</filename> file or
directly using <function>dl</function>.
</para>
<para>
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
<ulink url="&url.apachedso;">webpage on DSO support</ulink>.
</para>
</sect2>
<sect2 id="install.unix.fhttpd">
<title>fhttpd Module</title>
<para>
To build PHP as an fhttpd module, answer "yes" to "Build as an
fhttpd module?" (the <option><link
linkend="install.configure.with-fhttpd">
--with-fhttpd</link>=<replaceable>DIR</replaceable></option>
option to configure) and specify the fhttpd source base
directory. The default directory is <filename
class="directory">/usr/local/src/fhttpd</filename>. If you are
running fhttpd, building PHP as a module will give better
performance, more control and remote execution capability.
</para>
</sect2>
<sect2 id="install.unix.otherhttpd">
<title>Other web servers</title>
<para>
PHP can be built to support a large number of web servers. Please
see <link linkend="install.configure.servers">Server-related
options</link> for a full list of server-related configure
options.
</para>
</sect2>
<sect2 id="install.unix.commandline">
<title>CGI/Commandline version</title>
<para>
The default is to build PHP as a CGI program. This creates a
commandline interpreter, which can be used for CGI processing, or
for non-web-related PHP scripting. If you are running a web
server PHP has module support for, you should generally go for
that solution for performance reasons. However, the CGI version
enables Apache users to run different PHP-enabled pages under
different user-ids. Please make sure you read through the <link
linkend="security">Security chapter</link> if you are going to
run PHP as a CGI.
</para>
</sect2>
<sect2 id="database-support-options">
<title>Database Support Options</title>
<para>
PHP has native support for a number of databases (as well as
ODBC). To enable support for the various databases, options are
given to the <filename>configure</filename> script at compile
time. Read the <link linkend="install.configure.databases">list
of all database-related options</link> for more information.
</para>
<para>
For a list of all possible options to
<filename>configure</filename>, please see the <link
linkend="install.configure">Complete list of configure
options</link>.
</para>
</sect2>
<sect2>
<title>Building</title>
<simpara>
When PHP is configured, you are ready to build the CGI executable
or the PHP library. The command <command>make</command> should
take care of this. If it fails and you can't figure out why, see
the <link linkend="install-problems">Problems section</link>.
</simpara>
</sect2>
<sect2>
<title>Testing</title>
<simpara>
If you have built PHP as a CGI program, you may test your build
by typing <command>make test</command>. 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.
</simpara>
</sect2>
<sect2>
<title>Benchmarking</title>
<simpara>
If you have built PHP as a CGI program, you may benchmark your
build by typing <command>make bench</command>. 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
<function>set_time_limit</function> can not be used in safe
mode. Use the <link
linkend="ini.max-execution-time">max_execution_time</link>
configuration setting to control this time for your own
scripts. <command>make bench</command> ignores the <link
linkend="configuration.file">configuration file</link>.
</simpara>
</sect2>
</sect1>
<sect1 id="install.configure">
<title>Complete list of configure options</title>
<note>
<para>
These are only used at compile time. If you want to alter PHP's
runtime configuration, please go to <link
linkend="configuration">Configuration</link>.
</para>
</note>
<para>
The following is a complete list of options supported by the PHP 3
and PHP 4 <filename>configure</filename> scripts, used when
compiling in Unix-like environments. Some are available in PHP 3,
some in PHP 4, and some in both, as noted. There are many options
the names of which have changed between PHP 3 and PHP 4, but which
accomplish the same things. These entries are cross-referenced to
each other, so if you have a problem getting your PHP 3-era
configuration options to work, check here to see whether the names
have changed.
</para>
<itemizedlist>
<listitem>
<para>
<link linkend="install.configure.databases">Database</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.ecommerce">Ecommerce</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.graphics">Graphics</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.misc">Miscellaneous</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.networking">Networking</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.php">PHP Behaviour</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.servers">Server</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.text">Text and language</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="install.configure.xml">XML</link>
</para>
</listitem>
</itemizedlist>
<sect2 id="install.configure.databases">
<title>Database</title>
<variablelist>
<varlistentry id="install.configure.with-adabas">
<term>
<parameter>--with-adabas[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Adabas D support. DIR is the Adabas base
install directory, defaults to /usr/local.
</para>
<para>
<ulink url="&url.adabas;">Adabas home page</ulink>
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-dba">
<term>
<parameter>--enable-dba=shared</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Build DBA as a shared module
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-dbase">
<term>
<parameter>--enable-dbase</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available; use <link
linkend="install.configure.with-dbase">--with-dbase</link>
instead.
</para>
<para>
PHP 4: Enable the bundled dbase library. No external libraries
are required.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-dbase">
<term>
<parameter>--with-dbase</parameter>
</term>
<listitem>
<para>
PHP 3: Include the bundled dbase library. No external
libraries are required.
</para>
<para>
PHP 4: Option not available; use <link
linkend="install.configure.enable-dbase">--enable-dbase</link>
instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-db2">
<term>
<parameter>--with-db2[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Berkeley DB2 support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-db3">
<term>
<parameter>--with-db3[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Berkeley DB3 support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-dbm">
<term>
<parameter>--with-dbm[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include DBM support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-dbmaker">
<term>
<parameter>--with-dbmaker[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: 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).
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-empress">
<term>
<parameter>--with-empress[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Empress support. DIR is the Empress base install
directory, defaults to $EMPRESSPATH
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-filepro">
<term>
<parameter>--enable-filepro</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available; use <link
linkend="install.configure.with-filepro">--with-filepro</link>
instead.
</para>
<para>
PHP 4: Enable the bundled read-only filePro support. No
external libraries are required.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-filepro">
<term>
<parameter>--with-filepro</parameter>
</term>
<listitem>
<para>
PHP 3: Include the bundled read-only filePro support. No
external libraries are required.
</para>
<para>
PHP 4: Option not available; use <link
linkend="install.configure.enable-filepro">--enable-filepro</link>
instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-gdbm">
<term>
<parameter>--with-gdbm[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include GDBM support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-hyperwave">
<term>
<parameter>--with-hyperwave</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Hyperwave support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-ibm-db2">
<term>
<parameter>--with-ibm-db2[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include IBM DB2 support. DIR is the DB2 base
install directory, defaults to
<filename>/home/db2inst1/sqllib</filename>.
</para>
<para>
<ulink url="&url.ibmdb2;">IBM DB2 home page</ulink>
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-informix">
<term>
<parameter>--with-informix[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Informix support. DIR is the Informix base install
directory, defaults to nothing.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-ingres">
<term>
<parameter>--with-ingres[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Ingres II support. DIR is the Ingres base directory
(default /II/ingres)
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-interbase">
<term>
<parameter>--with-interbase[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include InterBase support. DIR is the InterBase base
install directory, which defaults to <filename>/usr/interbase</filename>.
</para>
<simpara>
<link linkend="ref.ibase">Interbase functions</link>
</simpara>
<simpara>
<ulink url="&url.ibase;">Interbase home page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-ldap">
<term>
<parameter>--with-ldap[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include LDAP support. DIR is the LDAP base install
directory. Defaults to <filename>/usr</filename> and
<filename>/usr/local</filename>
</para>
<para>
PHP 4: Include LDAP support. DIR is the LDAP base install directory.
</para>
<simpara>
This provides <acronym>LDAP</acronym> (Lightweight Directory Access
Protocol support). The parameter is the LDAP base install
directory, defaults to <filename
class="directory">/usr/local/ldap</filename>.
</simpara>
<simpara>
More information about LDAP can be found in <ulink
url="&url.rfc;rfc1777.html">RFC1777</ulink> and
<ulink
url="&url.rfc;rfc1778.html">RFC1778</ulink>.
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-msql">
<term>
<parameter>--with-msql[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enables mSQL support. The parameter to this
option is the mSQL install directory and defaults to <filename
class="directory">/usr/local/Hughes</filename>. This is the
default directory of the mSQL 2.0 distribution.
<command>configure</command> automatically detects which mSQL
version you are running and PHP supports both 1.0 and 2.0, but
if you compile PHP with mSQL 1.0, you can only access mSQL 1.0
databases, and vice-versa.
</para>
<simpara>
See also <link linkend="ini.sect.msql">mSQL
Configuration</link> Directives in the <link
linkend="configuration.file">configuration file</link>.
</simpara>
<simpara>
<ulink url="&url.msql;">mSQL home page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mysql">
<term>
<parameter>--with-mysql[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include MySQL support. DIR is the MySQL base install directory,
defaults to searching through a number of common places for the MySQL
files.
</para>
<para>
PHP 4: Include MySQL support. DIR is the MySQL base directory. If
unspecified, the bundled MySQL library will be used. This
option is turned on by default.
</para>
<para>
See also <link linkend="ini.sect.mysql">MySQL
Configuration</link> Directives in the <link
linkend="configuration.file">configuration file</link>.
</para>
<para>
<ulink url="&url.mysql;">MySQL home page</ulink>
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-ndbm">
<term>
<parameter>--with-ndbm[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include NDBM support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-oci8">
<term>
<parameter>--with-oci8[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Oracle-oci8 support. Default DIR is ORACLE_HOME.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-oracle">
<term>
<parameter>--with-oracle[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include Oracle database support. DIR is Oracle's home directory,
defaults to $ORACLE_HOME.
</para>
<para>
PHP 4: Include Oracle-oci7 support. Default DIR is ORACLE_HOME.
</para>
<simpara>
Includes Oracle support. Has been tested and should be
working at least with Oracle versions 7.0 through 7.3. The
parameter is the <envar>ORACLE_HOME</envar> directory. You do
not have to specify this parameter if your Oracle environment
has been set up.
</simpara>
<simpara>
<ulink url="&url.oracle;">Oracle home page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-pgsql">
<term>
<parameter>--with-pgsql[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include PostgresSQL support. DIR is the PostgresSQL base
install directory, which defaults to
<filename>/usr/local/pgsql</filename>.
</para>
<para>
PHP 4: Include PostgreSQL support. DIR is the PostgreSQL base
install directory, which defaults to
<filename>/usr/local/pgsql</filename>. Set DIR to shared to
build as a dl, or shared,DIR to build as a dl and still specify
DIR.
</para>
<simpara>
See also <link linkend="ini.sect.pgsql">Postgres
Configuration</link> Directives in the <link
linkend="configuration.file">configuration file</link>.
</simpara>
<simpara>
<ulink url="&url.pgsql;">PostgreSQL home page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-solid">
<term>
<parameter>--with-solid[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Solid support. DIR is the Solid base install
directory, defaults to /usr/local/solid
</para>
<simpara>
<ulink url="&url.solid;">Solid home page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-sybase-ct">
<term>
<parameter>--with-sybase-ct[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Sybase-CT support. DIR is the Sybase home
directory, defaults to /home/sybase.
</para>
<simpara>
See also <link linkend="ini.sect.sybct">Sybase-CT
Configuration</link> Directives in the <link
linkend="configuration.file">configuration
file</link>.
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-sybase">
<term>
<parameter>--with-sybase[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Sybase-DB support. DIR is the Sybase home
directory, which defaults to <filename>/home/sybase</filename>.
</para>
<simpara>
See also <link linkend="ini.sect.sybase">Sybase
Configuration</link> Directives in the <link
linkend="configuration.file">configuration file</link>.
</simpara>
<simpara>
<ulink url="&url.sybase;">Sybase home page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-openlink">
<term>
<parameter>--with-openlink[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include OpenLink ODBC support. DIR is the OpenLink base
install directory, defaults to /usr/local/openlink.
</para>
<simpara>
<ulink url="&url.openlink;">OpenLink Software's home
page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-iodbc">
<term>
<parameter>--with-iodbc[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include iODBC support. DIR is the iODBC base install
directory, defaults to <filename>/usr/local</filename>.
</para>
<para>
This feature was first developed for iODBC Driver Manager, a
freely redistributable ODBC driver manager which runs under
many flavors of UNIX.
</para>
<simpara>
<ulink url="&url.freeodbc;">FreeODBC home page</ulink>
or <ulink url="&url.iodbc;">iODBC home page</ulink>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-custom-odbc">
<term>
<parameter>--with-custom-odbc[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Includes support for an arbitrary custom ODBC
library. The parameter is the base directory and defaults to
<filename class="directory">/usr/local</filename>.
</para>
<simpara>
This option implies that you have defined CUSTOM_ODBC_LIBS
when you run the configure script. You also must have a valid
odbc.h header somewhere in your include path. If you don't
have one, create it and include your specific header from
there. Your header may also require some extra definitions,
particularly when it is multiplatform. Define them in
CFLAGS.
</simpara>
<simpara>
For example, you can use Sybase SQL Anywhere on QNX as
following:
<literal>
CFLAGS=-DODBC_QNX LDFLAGS=-lunix CUSTOM_ODBC_LIBS="-ldblib
-lodbc" ./configure --with-custom-odbc=/usr/lib/sqlany50
</literal>
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-unified-odbc">
<term>
<parameter>--disable-unified-odbc</parameter>
</term>
<listitem>
<para>
PHP 3: Disable unified ODBC support. Only applicable if iODBC, Adabas,
Solid, Velocis or a custom ODBC interface is enabled.
</para>
<para>
PHP 4: Option not available in PHP 4
</para>
<simpara>
The Unified ODBC module, which is a common interface to all
the databases with ODBC-based interfaces, such as Solid, IBM
DB2 and Adabas D. It also works for normal ODBC libraries.
Has been tested with iODBC, Solid, Adabas D, IBM DB2 and
Sybase SQL Anywhere. Requires that one (and only one) of these
modules or the Velocis module is enabled, or a custom ODBC
library specified. This option is only applicable if one of
the following options is used: <link
linkend="install.configure.with-iodbc">--with-iodbc</link>,
<link
linkend="install.configure.with-solid">--with-solid</link>,
<link
linkend="install.configure.with-ibm-db2">--with-ibm-db2</link>,
<link
linkend="install.configure.with-adabas">--with-adabas</link>,
<link
linkend="install.configure.with-velocis">--with-velocis</link>,
or <link
linkend="install.configure.with-custom-odbc">--with-custom-odbc</link>.
</simpara>
<simpara>
See also <link linkend="ini.sect.uodbc">Unified ODBC
Configuration</link> Directives in the <link
linkend="configuration.file">configuration
file</link>.
</simpara>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-unixODBC">
<term>
<parameter>--with-unixODBC[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include unixODBC support. DIR is the unixODBC base install
directory, defaults to /usr/local.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-velocis">
<term>
<parameter>--with-velocis[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include Velocis support. DIR is the Velocis base install
directory, defaults to /usr/local/velocis.
</para>
<simpara>
<ulink url="&url.velocis;">Velocis home page</ulink>
</simpara>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.ecommerce">
<title>Ecommerce</title>
<variablelist>
<varlistentry id="install.configure.with-ccvs">
<term>
<parameter>--with-ccvs[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Compile CCVS support into PHP4. Please specify your CCVS base
install directory as DIR.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mck">
<term>
<parameter>--with-mck[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include Cybercash MCK support. DIR is the cybercash mck
build directory, which defaults to
<filename>/usr/src/mck-3.2.0.3-linux</filename>. For help, look
in <filename>extra/cyberlib</filename>.
</para>
<para>
PHP 4: Option not available; use <link
linkend="install.configure.with-cybercash">--with-cybercash</link>
instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-cybercash">
<term>
<parameter>--with-cybercash[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available; use <link
linkend="install.configure.with-mck">--with-mck</link>
instead.
</para>
<para>
PHP 4: Include CyberCash support. DIR is the CyberCash MCK install
directory.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-pfpro">
<term>
<parameter>--with-pfpro[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Verisign Payflow Pro support
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.graphics">
<title>Graphics</title>
<variablelist>
<varlistentry id="install.configure.enable-freetype-4bit-antialias-hack">
<term>
<parameter>--enable-freetype-4bit-antialias-hack</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include support for FreeType2 (experimental).
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-gd">
<term>
<parameter>--with-gd[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include GD support (DIR is GD's install dir).
</para>
<para>
PHP 4: Include GD support (DIR is GD's install dir). Set DIR to shared
to build as a dl, or shared,DIR to build as a dl and still specify DIR.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.without-gd">
<term>
<parameter>--without-gd</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Disable GD support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-imagick">
<term>
<parameter>--with-imagick[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include ImageMagick support. DIR is the install
directory, and if left out, PHP will try to find it on its
own. [experimental]
</para>
<para>
PHP 4: Option not available in PHP 4
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-jpeg-dir">
<term>
<parameter>--with-jpeg-dir[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: jpeg dir for pdflib 2.0
</para>
<para>
PHP 4: jpeg dir for pdflib 3.x
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-png-dir">
<term>
<parameter>--with-png-dir[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: png dir for pdflib 3.x
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-t1lib">
<term>
<parameter>--enable-t1lib</parameter>
</term>
<listitem>
<para>
PHP 3: Enable t1lib support.
</para>
<para>
PHP 4: Option not available; use <link
linkend="install.configure.with-t1lib">--with-t1lib</link>
instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-t1lib">
<term>
<parameter>--with-t1lib[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available; use <link
linkend="install.configure.enable-t1lib">--enable-t1lib</link>
instead.
</para>
<para>
PHP 4: Include T1lib support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-tiff-dir">
<term>
<parameter>--with-tiff-dir[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: tiff dir for pdflib 2.0
</para>
<para>
PHP 4: tiff dir for pdflib 3.x
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-ttf">
<term>
<parameter>--with-ttf[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include FreeType support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-xpm-dir">
<term>
<parameter>--with-xpm-dir[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: xpm dir for gd-1.8+
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.misc">
<title>Miscellaneous</title>
<para>
These are being classified over time, where appropriate.
</para>
<variablelist>
<varlistentry id="install.configure.disable-bcmath">
<term>
<parameter>--disable-bcmath</parameter>
</term>
<listitem>
<para>
PHP 3: Compile without BC arbitrary precision math
functions. These functions allow you to operate with numbers
outside of the ranges allowed by regular integers and floats;
see <link linkend="ref.bc">BCMath Arbitrary Precision
Mathematics Functions</link> for more information.
</para>
<para>
PHP 4: Option not available; bcmath is not compiled in by
default. Use <link
linkend="install.configure.enable-bcmath">--enable-bcmath</link>
to compile it in.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-display-source">
<term>
<parameter>--disable-display-source</parameter>
</term>
<listitem>
<para>
PHP 3: Compile without displaying source support
</para>
<para>
PHP 4: Option not available in PHP 4
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-libtool-lock">
<term>
<parameter>--disable-libtool-lock</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: avoid locking (might break parallel builds)
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-pear">
<term>
<parameter>--disable-pear</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Do not install PEAR
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-pic">
<term>
<parameter>--disable-pic</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Disable PIC for shared objects
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-posix">
<term>
<parameter>--disable-posix</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3; use <link
linkend="install.configure.without-posix">--without-posix</link>
instead.
</para>
<para>
PHP 4: Disable POSIX-like functions
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-rpath">
<term>
<parameter>--disable-rpath</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Disable passing additional runtime library search paths
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-session">
<term>
<parameter>--disable-session</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Disable session support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-bcmath">
<term>
<parameter>--enable-bcmath</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3; bcmath is compiled in
by default. Use <link
linkend="install.configure.disable-bcmath">--disable-bcmath</link>
to disable it.
</para>
<para>
PHP 4: Compile with bc style precision math functions. Read
README-BCMATH for instructions on how to get this module
installed. These functions allow you to operate with numbers
outside of the ranges allowed by regular integers and floats;
see <link linkend="ref.bc">BCMath Arbitrary Precision
Mathematics Functions</link> for more information.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-c9x-inline">
<term>
<parameter>--enable-c9x-inline</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable C9x-inline semantics
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-calendar">
<term>
<parameter>--enable-calendar</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable support for calendar conversion
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-debug">
<term>
<parameter>--enable-debug</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Compile with debugging symbols.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-debugger">
<term>
<parameter>--enable-debugger</parameter>
</term>
<listitem>
<para>
PHP 3: Compile with remote debugging functions
</para>
<para>
PHP 4: Option not available in PHP 4
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-discard-path">
<term>
<parameter>--enable-discard-path</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: If this is enabled, the PHP CGI binary can safely be
placed outside of the web tree and people will not be able to circumvent
.htaccess security.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-dmalloc">
<term>
<parameter>--enable-dmalloc</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable dmalloc
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-exif">
<term>
<parameter>--enable-exif</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable exif support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-experimental-zts">
<term>
<parameter>--enable-experimental-zts</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: This will most likely break your build
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-fast-install">
<term>
<parameter>--enable-fast-install[=PKGS]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: optimize for fast installation [default=yes]
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-force-cgi-redirect">
<term>
<parameter>--enable-force-cgi-redirect</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable the security check for internal server redirects.
You should use this if you are running the CGI version with Apache.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-inline-optimization">
<term>
<parameter>--enable-inline-optimization</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: If you have much memory and are using gcc, you might try this.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-libgcc">
<term>
<parameter>--enable-libgcc</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable explicitly linking against libgcc
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-maintainer-mode">
<term>
<parameter>--enable-maintainer-mode</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: enable make rules and dependencies not useful (and
sometimes confusing) to the casual installer
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-memory-limit">
<term>
<parameter>--enable-memory-limit</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Compile with memory limit support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-safe-mode">
<term>
<parameter>--enable-safe-mode</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable safe mode by default.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-satellite">
<term>
<parameter>--enable-satellite</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable CORBA support via Satellite (Requires ORBit)
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-shared">
<term>
<parameter>--enable-shared[=PKGS]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: build shared libraries [default=yes]
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-sigchild">
<term>
<parameter>--enable-sigchild</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable PHP's own SIGCHLD handler.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-static">
<term>
<parameter>--enable-static[=PKGS]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: build static libraries [default=yes]
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-sysvsem">
<term>
<parameter>--enable-sysvsem</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable System V semaphore support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-sysvshm">
<term>
<parameter>--enable-sysvshm</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable the System V shared memory support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-trans-sid">
<term>
<parameter>--enable-trans-sid</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable transparent session id propagation
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-cdb">
<term>
<parameter>--with-cdb[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include CDB support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-config-file-path">
<term>
<parameter>--with-config-file-path=PATH</parameter>
</term>
<listitem>
<para>
PHP 3: Sets the path in which to look for php3.ini. Defaults to
<filename>/usr/local/lib</filename>
</para>
<para>
PHP 4: Sets the path in which to look for php.ini. Defaults to
<filename>/usr/local/lib</filename>
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-cpdflib">
<term>
<parameter>--with-cpdflib[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include ClibPDF support. DIR is the ClibPDF install directory,
defaults to /usr/local.
</para>
<para>
PHP 4: Include cpdflib support (requires cpdflib >= 2). DIR is the
cpdfllib install directory, defaults to /usr.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-esoob">
<term>
<parameter>--with-esoob[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Easysoft OOB support. DIR is the OOB base install
directory, defaults to /usr/local/easysoft/oob/client.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-exec-dir">
<term>
<parameter>--with-exec-dir[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Only allow executables in DIR when in safe mode defaults
to /usr/local/php/bin
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-fdftk">
<term>
<parameter>--with-fdftk[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include fdftk support. DIR is the fdftk install directory,
defaults to /usr/local.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-gnu-ld">
<term>
<parameter>--with-gnu-ld</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: assume the C compiler uses GNU ld [default=no]
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-icap">
<term>
<parameter>--with-icap[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include ICAP support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-imap">
<term>
<parameter>--with-imap[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include IMAP support. DIR is the IMAP include and
c-client.a directory.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-imsp">
<term>
<parameter>--with-imsp[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include IMSP support (DIR is IMSP's include dir and libimsp.a
dir).
</para>
<para>
PHP 4: Option not available in PHP 4
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-java">
<term>
<parameter>--with-java[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Java support. DIR is the base install directory for the
JDK. This extension can only be built as a shared dl.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-kerberos">
<term>
<parameter>--with-kerberos[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Kerberos support in IMAP.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mcal">
<term>
<parameter>--with-mcal[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include MCAL support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mcrypt">
<term>
<parameter>--with-mcrypt[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include mcrypt support. DIR is the mcrypt install
directory.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mhash">
<term>
<parameter>--with-mhash[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include mhash support. DIR is the mhash install directory.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mm">
<term>
<parameter>--with-mm[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include mm support for session storage
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mod_charset">
<term>
<parameter>--with-mod_charset</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable transfer tables for mod_charset (Rus Apache).
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-pdflib">
<term>
<parameter>--with-pdflib[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include pdflib support (tested with 0.6 and 2.0). DIR is
the pdflib install directory, which defaults to
<filename>/usr/local</filename>.
</para>
<para>
PHP 4: Include pdflib 3.x support. DIR is the pdflib install
directory, which defaults to <filename>/usr/local</filename>.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-readline">
<term>
<parameter>--with-readline[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include readline support. DIR is the readline install directory.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-regex">
<term>
<parameter>--with-regex=TYPE</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: regex library type: system, apache, php
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-servlet">
<term>
<parameter>--with-servlet[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include servlet support. DIR is the base install
directory for the JSDK. This SAPI requires that the Java
extension be built as a shared dl.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-swf">
<term>
<parameter>--with-swf[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include swf support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-system-regex">
<term>
<parameter>--with-system-regex</parameter>
</term>
<listitem>
<para>
PHP 3: Do not use the bundled regex library
</para>
<para>
PHP 4: (deprecated) Use system regex library
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-tsrm-pth">
<term>
<parameter>--with-tsrm-pth[=pth-config]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Use GNU Pth.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-tsrm-pthreads">
<term>
<parameter>--with-tsrm-pthreads</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Use POSIX threads (default)
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-x">
<term>
<parameter>--with-x</parameter>
</term>
<listitem>
<para>
PHP 3: use the X Window System
</para>
<para>
PHP 4: Option not available in PHP 4
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-zlib-dir">
<term>
<parameter>--with-zlib-dir[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: zlib dir for pdflib 2.0 or include zlib support
</para>
<para>
PHP 4: zlib dir for pdflib 3.x or include zlib support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-zlib">
<term>
<parameter>--with-zlib[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include zlib support (requires zlib >= 1.0.9). DIR is
the zlib install directory, defaults to /usr.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.without-pcre-regex">
<term>
<parameter>--without-pcre-regex</parameter>
</term>
<listitem>
<para>
PHP 3: Don't include Perl Compatible Regular Expressions support
</para>
<para>
PHP 4: Do not include Perl Compatible Regular Expressions support. Use
--with-pcre-regex=DIR to specify DIR where PCRE's include and library
files are located, if not using bundled library.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.without-posix">
<term>
<parameter>--without-posix</parameter>
</term>
<listitem>
<para>
PHP 3: Don't include POSIX functions
</para>
<para>
PHP 4: Option not available in PHP 4; use <link
linkend="install.configure.disable-posix">--disable-posix</link>
instead.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.networking">
<title>Networking</title>
<variablelist>
<varlistentry id="install.configure.with-curl">
<term>
<parameter>--with-curl[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include CURL support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-ftp">
<term>
<parameter>--enable-ftp</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available; use <link
linkend="install.configure.with-ftp">--with-ftp</link>
instead.
</para>
<para>
PHP 4: Enable FTP support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-ftp">
<term>
<parameter>--with-ftp</parameter>
</term>
<listitem>
<para>
PHP 3: Include FTP support.
</para>
<para>
PHP 4: Option not available; use <link
linkend="install.configure.enable-ftp">--enable-ftp</link>
instead
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-url-fopen-wrapper">
<term>
<parameter>--disable-url-fopen-wrapper</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Disable the URL-aware fopen wrapper that allows accessing
files via http or ftp.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-mod-dav">
<term>
<parameter>--with-mod-dav=DIR</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include DAV support through Apache's mod_dav, DIR is
mod_dav's installation directory (Apache module version only!)
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-openssl">
<term>
<parameter>--with-openssl[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include OpenSSL support in SNMP.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-snmp">
<term>
<parameter>--with-snmp[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include SNMP support. DIR is the SNMP base install
directory, defaults to searching through a number of common locations
for the snmp install. Set DIR to shared to build as a dl, or shared,DIR
to build as a dl and still specify DIR.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-ucd-snmp-hack">
<term>
<parameter>--enable-ucd-snmp-hack</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable UCD SNMP hack
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-sockets">
<term>
<parameter>--enable-sockets</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable sockets support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-yaz">
<term>
<parameter>--with-yaz[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include YAZ support (ANSI/NISO Z39.50). DIR is the YAZ bin
install directory
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-yp">
<term>
<parameter>--enable-yp</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available; use <link
linkend="install.configure.with-yp">--with-yp</link>
instead.
</para>
<para>
PHP 4: Include YP support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-yp">
<term>
<parameter>--with-yp</parameter>
</term>
<listitem>
<para>
PHP 3: Include YP support
</para>
<para>
PHP 4: Option not available; use <link
linkend="install.configure.enable-yp">--enable-yp</link>
instead.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.php">
<title>PHP Behaviour</title>
<variablelist>
<varlistentry id="install.configure.enable-magic-quotes">
<term>
<parameter>--enable-magic-quotes</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Enable magic quotes by default.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-short-tags">
<term>
<parameter>--disable-short-tags</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Disable the short-form <? start tag by default.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-track-vars">
<term>
<parameter>--enable-track-vars</parameter>
</term>
<listitem>
<para>
PHP 3: Enable GET/POST/Cookie track variables by default.
</para>
<para>
PHP 4: Option not available in PHP 4; as of PHP 4.0.2,
track_vars is always on.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.servers">
<title>Server</title>
<variablelist>
<varlistentry id="install.configure.with-aolserver-src">
<term>
<parameter>--with-aolserver-src=DIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Specify path to the source distribution of AOLserver
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-aolserver">
<term>
<parameter>--with-aolserver=DIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Specify path to the installed AOLserver
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-apache">
<term>
<parameter>--with-apache[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Build Apache module. DIR is the top-level Apache build
directory, defaults to /usr/local/etc/httpd.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-apxs">
<term>
<parameter>--with-apxs[=FILE]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Build shared Apache module. FILE is the optional pathname
to the Apache apxs tool; defaults to apxs.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-versioning">
<term>
<parameter>--enable-versioning</parameter>
</term>
<listitem>
<para>
PHP 3: Take advantage of versioning and scoping Provided by Solaris 2.x
and Linux
</para>
<para>
PHP 4: Export only required symbols. See INSTALL for more information
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-fhttpd">
<term>
<parameter>--with-fhttpd[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Build fhttpd module. DIR is the fhttpd sources directory,
defaults to /usr/local/src/fhttpd.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-nsapi">
<term>
<parameter>--with-nsapi=DIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Specify path to the installed Netscape
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-phttpd">
<term>
<parameter>--with-phttpd=DIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4:
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-pi3web">
<term>
<parameter>--with-pi3web=DIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Build PHP as a module for use with Pi3Web.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-roxen">
<term>
<parameter>--with-roxen=DIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Build PHP as a Pike module. DIR is the base Roxen directory,
normally /usr/local/roxen/server.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-roxen-zts">
<term>
<parameter>--enable-roxen-zts</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Build the Roxen module using Zend Thread Safety.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-thttpd">
<term>
<parameter>--with-thttpd=SRCDIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4:
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-zeus">
<term>
<parameter>--with-zeus=DIR</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Build PHP as an ISAPI module for use with Zeus.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.text">
<title>Text and language</title>
<variablelist>
<varlistentry id="install.configure.with-aspell">
<term>
<parameter>--with-aspell[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include ASPELL support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-gettext">
<term>
<parameter>--with-gettext[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3, PHP 4: Include GNU gettext support. DIR is the gettext install
directory, defaults to /usr/local
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-pspell">
<term>
<parameter>--with-pspell[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include PSPELL support.
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-recode">
<term>
<parameter>--with-recode[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Include GNU recode support.
</para>
<para>
PHP 4: Include recode support. DIR is the recode install directory.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="install.configure.xml">
<title>XML</title>
<variablelist>
<varlistentry id="install.configure.with-dom">
<term>
<parameter>--with-dom[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include DOM support (requires libxml >= 2.0). DIR is the
libxml install directory, defaults to <filename>/usr</filename>
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-sablot-errors-descriptive">
<term>
<parameter>--enable-sablot-errors-descriptive</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable Descriptive errors
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-sablot">
<term>
<parameter>--with-sablot[=DIR]</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Include Sablotron support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.enable-wddx">
<term>
<parameter>--enable-wddx</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3
</para>
<para>
PHP 4: Enable WDDX support
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.disable-xml">
<term>
<parameter>--disable-xml</parameter>
</term>
<listitem>
<para>
PHP 3: Option not available in PHP 3; XML functionality is
not built in by default. Use <link
linkend="install.configure.with-xml">--with-xml</link>
to turn it on.
</para>
<para>
PHP 4: Disable XML support using bundled expat lib
</para>
</listitem>
</varlistentry>
<varlistentry id="install.configure.with-xml">
<term>
<parameter>--with-xml</parameter>
</term>
<listitem>
<para>
PHP 3: Include XML support
</para>
<para>
PHP 4: Option not available; XML support is built in by
default. Use <link
linkend="install.configure.disable-xml">--disable-xml</link> to
turn it off.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1>
<sect1 id="install-windows95-nt">
<title>Installation on Windows 95/98/NT systems</title>
<simpara>
This install guide will help you install and configure PHP on your
Windows 9x/NT webservers. This guide was compiled by
&link.bob;. The latest revision can be found at <ulink
url="&url.win32install;">&url.win32install;</ulink>.
</simpara>
<para>
This guide provides installation support for:
<itemizedlist>
<listitem>
<para>
Personal Web Server (Newest version recommended)
</para>
</listitem>
<listitem>
<para>
Internet Information Server 3 or 4
</para>
</listitem>
<listitem>
<para>
Apache 1.3.x
</para>
</listitem>
<listitem>
<para>
Omni HTTPd 2.0b1
</para>
</listitem>
</itemizedlist>
</para>
<sect2>
<title>General Installation Steps</title>
<para>
The following steps should be performed on all installations
before the server specific instructions.
<itemizedlist>
<listitem>
<para>
Extract the distribution file to a directory of your choice.
"C:\PHP\" is a good start.
</para>
</listitem>
<listitem>
<para>
Copy the file, 'php.ini-dist' to your '%WINDOWS%' directory
and rename it to 'php.ini'. Your '%WINDOWS%' directory is
typically:
<simplelist>
<member>c:\windows for Windows 95/98</member>
<member>c:\winnt or c:\winnt40 for NT servers</member>
</simplelist>
</para>
</listitem>
<listitem>
<para>
Edit your 'php.ini' file:
<itemizedlist>
<listitem>
<simpara>
You will need to change the 'extension_dir' setting to
point to your php-install-dir, or where you have placed
your 'php_*.dll' files. ex: c:\php
</simpara>
</listitem>
<listitem>
<simpara>
If you are using Omni Httpd, do not follow the next step.
Set the 'doc_root' to point to your webservers
document_root. ex: c:\apache\htdocs or c:\webroot
</simpara>
</listitem>
<listitem>
<simpara>
Choose which modules you would like to load when PHP
starts. You can uncomment the: 'extension=php_*.dll' lines
to load these modules. Some modules require you to have
additional libraries installed on your system for the
module to work correctly. The PHP <ulink
url="&url.php.faq;">FAQ</ulink> has more information on
where to get supporting libraries. You can also load a
module dynamically in your script using:
<command>dl("php_*.dll");</command>
</simpara>
</listitem>
<listitem>
<simpara>
On PWS and IIS, you can set the browscap.ini to point to:
'c:\windows\system\inetsrv\browscap.ini' on Windows 95/98
and 'c:\winnt\system32\inetsrv\browscap.ini' on NT
Server. Additional information on using the browscap
functionality in PHP can be found at this <ulink
url="&url.browscap;">mirror</ulink>, select the
"source"
button to see it in action.
</simpara>
</listitem>
</itemizedlist>
</para>
</listitem>
</itemizedlist></para>
<simpara>
The DLLs for PHP extensions are prefixed with 'php_'. This
prevents confusion between PHP extensions and their supporting
libraries.
</simpara>
</sect2>
<sect2>
<title>Windows 95/98/NT and PWS/IIS 3</title>
<simpara>
The recommended method for configuring these servers is to use
the INF file included with the distribution
(php_iis_reg.inf). You may want to edit this file and make sure
the extensions and PHP install directories match your
configuration. Or you can follow the steps below to do it
manually.
</simpara>
<simpara>
WARNING: These steps involve working directly with the windows
registry. One error here can leave your system in an unstable
state. We highly recommend that you back up your registry
first. The PHP Development team will not be held responsible if
you damage your registry.
</simpara>
<para>
<itemizedlist>
<listitem>
<simpara>
Run Regedit.
</simpara>
</listitem>
<listitem>
<simpara>
Navigate to: <literal>HKEY_LOCAL_MACHINE /System
/CurrentControlSet /Services /W3Svc /Parameters
/ScriptMap</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
On the edit menu select: <literal>New->String Value</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Type in the extension you wish to use for your php
scripts. ex: <literal>.php</literal>
</simpara>
</listitem>
<listitem>
<simpara>
Double click on the new string value and enter the path to
<literal>php.exe</literal> in the value data field. ex:
<literal>c:\php\php.exe %s %s</literal>. The '%s %s' is VERY
important, PHP will not work properly without it.
</simpara>
</listitem>
<listitem>
<simpara>
Repeat these steps for each extension you wish to associate
with PHP scripts.
</simpara>
</listitem>
<listitem>
<simpara>
Now navigate to: <literal>HKEY_CLASSES_ROOT</literal>
</simpara>
</listitem>
<listitem>
<simpara>
On the edit menu select: <literal>New->Key</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Name the key to the extension you setup in the previous
section. ex: <literal>.php</literal>
</simpara>
</listitem>
<listitem>
<simpara>
Highlight the new key and in the right side pane, double click
the "default value" and enter <literal>phpfile</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Repeat the last step for each extension you set up in the
previous section.
</simpara>
</listitem>
<listitem>
<simpara>
Now create another <literal>New->Key</literal> under
<literal>HKEY_CLASSES_ROOT</literal> and name it
<literal>phpfile</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Highlight the new key <literal>phpfile</literal> and in the
right side pane, double click the "default value" and enter
<literal>PHP Script</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Right click on the <literal>phpfile</literal> key and select
<literal>New->Key</literal>, name it <literal>Shell</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Right click on the <literal>Shell</literal> key and select
<literal>New->Key</literal>, name it <literal>open</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Right click on the <literal>open</literal> key and select
<literal>New->Key</literal>, name it
<literal>command</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
Highlight the new key <literal>command</literal> and in the
right side pane, double click the "default value" and enter
the path to <literal>php.exe</literal>. ex:
<literal>c:\php\php.exe -q %1</literal>. (don't forget the
<literal>%1</literal>).
</simpara>
</listitem>
<listitem>
<simpara>
Exit Regedit.
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
PWS and IIS 3 users now have a fully operational system. IIS 3
users can use a nifty <ulink
url="&url.iiscfg;">tool</ulink> from
Steven Genusa to configure their script maps.
</simpara>
</sect2>
<sect2>
<title>Windows NT and IIS 4</title>
<simpara>
To install PHP on an NT Server running IIS 4, follow these
instructions:
</simpara>
<para>
<itemizedlist>
<listitem>
<simpara>
In Internet Service Manager (MMC), select the Web site or the
starting point directory of an application.
</simpara>
</listitem>
<listitem>
<simpara>
Open the directory's property sheets (by right clicking and
selecting properties), and then click the Home Directory,
Virtual Directory, or Directory tab.
</simpara>
</listitem>
<listitem>
<simpara>
Click the Configuration button, and then click the App
Mappings tab.
</simpara>
</listitem>
<listitem>
<simpara>
Click Add, and in the Executable box, type:
<literal>c:\path-to-php-dir\php.exe %s %s</literal>. You MUST
have the %s %s on the end, PHP will not function properly if
you fail to do this.
</simpara>
</listitem>
<listitem>
<simpara>
In the Extension box, type the file name extension you want
associated with PHP scripts. (You must repeat step 5 and 6 for
each extension you want accociated with PHP
scripts. (<literal>.php</literal> and
<literal>.phtml</literal> are common.)
</simpara>
</listitem>
<listitem>
<simpara>
Set up the appropriate security. (This is done in Internet
Service Manager), and if your NT Server uses NTFS file system,
add execute rights for I_USR_ to the directory that contains
<literal>php.exe</literal>.
</simpara>
</listitem>
</itemizedlist>
</para>
</sect2>
<sect2>
<title>Windows 9x/NT and Apache 1.3.x</title>
<simpara>
You must edit your <literal>srm.conf</literal> or
<literal>httpd.conf</literal> to configure Apache to work with
the PHP CGI binary.
</simpara>
<simpara>
Although there can be a few variations of configuring PHP under
Apache, this one is simple enough to be used by the
newcomer. Please consult the Apache Docs for further
configuration directives.
</simpara>
<para>
<itemizedlist>
<listitem>
<simpara>
<literal>
ScriptAlias /php/ "c:/path-to-php-dir/"
</literal>
</simpara>
</listitem>
<listitem>
<simpara>
<literal>
AddType application/x-httpd-php .php
</literal>
</simpara>
</listitem>
<listitem>
<simpara>
<literal>
AddType application/x-httpd-php .phtml
</literal>
</simpara>
</listitem>
<listitem>
<simpara>
<literal>
Action application/x-httpd-php "/php/php.exe"
</literal>
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
To use the source code highlighting feature, simply create a PHP
script file and stick this code in: <literal><?php show_source
("original_php_script.php"); ?></literal>. Substitute
<literal>original_php_script.php</literal> with the name of the
file you wish to show the source of. (this is only one way of
doing it). <emphasis>Note:</emphasis> On Win-Apache all back
slashes in a path statement such as: "c:\directory\file.ext",
must be converted to forward slashes.
</simpara>
</sect2>
<sect2>
<title>Omni HTTPd 2.0b1 for Windows</title>
<simpara>
This has got to be the easiest config there is:
</simpara>
<para>
<itemizedlist>
<listitem>
<para>
Step 1: Install Omni server
</para>
</listitem>
<listitem>
<para>
Step 2: Right click on the blue OmniHTTPd icon in the system
tray and select <literal>Properties</literal>
</para>
</listitem>
<listitem>
<para>
Step 3: Click on <literal>Web Server Global Settings</literal>
</para>
</listitem>
<listitem>
<para>
Step 4: On the 'External' tab, enter: <literal>virtual = .php
| actual = c:\path-to-php-dir\php.exe</literal>
</para>
</listitem>
<listitem>
<para>
Step 5: On the <literal>Mime</literal> tab, enter:
<literal>virtual = wwwserver/stdcgi | actual = .php</literal>
</para>
</listitem>
<listitem>
<para>
Step 6: Click <literal>OK</literal>
</para>
</listitem>
</itemizedlist>
</para>
<simpara>
Repeat steps 2 - 6 for each extension you want to associate with
PHP.
</simpara>
</sect2>
<sect2>
<title>PHP Modules</title>
<para>
<table>
<title>PHP Modules</title>
<tgroup cols="2">
<tbody>
<row>
<entry>php_calendar.dll</entry>
<entry>Calendar conversion functions</entry>
</row>
<row>
<entry>php_crypt.dll</entry>
<entry>Crypt functions</entry>
</row>
<row>
<entry>php_dbase.dll</entry>
<entry>DBase functions</entry>
</row>
<row>
<entry>php_dbm.dll</entry>
<entry>GDBM emulation via Berkely DB2 library</entry>
</row>
<row>
<entry>php_filepro.dll</entry>
<entry>READ ONLY access to filepro databases</entry>
</row>
<row>
<entry>php_gd.dll</entry>
<entry>GD Library functions for gif manipulation</entry>
</row>
<row>
<entry>php_hyperwave.dll</entry>
<entry>HyperWave functions</entry>
</row>
<row>
<entry>php_imap4r2.dll</entry>
<entry>IMAP 4 functions</entry>
</row>
<row>
<entry>php_ldap.dll</entry>
<entry>LDAP functions</entry>
</row>
<row>
<entry>php_msql1.dll</entry>
<entry>mSQL 1 client</entry>
</row>
<row>
<entry>php_msql2.dll</entry>
<entry>mSQL 2 client</entry>
</row>
<row>
<entry>php_mssql.dll</entry>
<entry>MSSQL client (requires MSSQL DB-Libraries</entry>
</row>
<row>
<entry>php3_mysql.dll (Built into PHP 4)</entry>
<entry>MySQL functions</entry>
</row>
<row>
<entry>php_nsmail.dll</entry>
<entry>Netscape mail functions</entry>
</row>
<row>
<entry>php_oci73.dll</entry>
<entry>Oracle functions</entry>
</row>
<row>
<entry>php_snmp.dll</entry>
<entry>SNMP get and walk functions (NT only!)</entry>
</row>
<row>
<entry>php_zlib.dll</entry>
<entry>ZLib functions</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect2>
</sect1>
<sect1 id="install-problems">
<title>Problems?</title>
<sect2>
<title>Read the FAQ</title>
<simpara>
Some problems are more common than others. The most common ones
are listed in the PHP FAQ, found at <ulink
url="&url.php.faq;">&url.php.faq;</ulink>
</simpara>
</sect2>
<sect2>
<title>Bug reports</title>
<simpara>
If you think you have found a bug in PHP, please report it. The
PHP developers probably don't know about it, and unless you
report it, chances are it won't be fixed. You can report bugs
using the bug-tracking system at <ulink
url="&url.php.bugs;">&url.php.bugs;</ulink>.
</simpara>
</sect2>
<sect2>
<title>Other problems</title>
<simpara>
If you are still stuck, someone on the PHP mailing list may be
able to help you. You should check out the archive first, in case
someone already answered someone else who had the same problem as
you. The archives are available from the support page on <ulink
url="&url.php;">&url.php;</ulink>. To subscribe to the PHP
mailing list, send an empty mail to <ulink
url="mailto:&email.php3.subscribe;">&email.php3.subscribe;</ulink>.
The mailing list address is
<literal>&email.php3;</literal>.
</simpara>
<simpara>
If you want to get help on the mailing list, please try to be
precise and give the necessary details about your environment
(which operating system, what PHP version, what web server, if
you are running PHP as CGI or a server module, etc.), and
preferably enough code to make others able to reproduce and test
your problem.
</simpara>
</sect2>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/chapters/intro.xml
+++ phpdoc/nl/chapters/intro.xml
<chapter id="introduction">
<title>Introduction</title>
<sect1 id="intro-whatis">
<title>What is PHP?</title>
<simpara>
PHP (officially "PHP: Hypertext Preprocessor") is a server-side
HTML-embedded scripting language.
</simpara>
<para>
Simple answer, but what does that mean? An example:
</para>
<para>
<example>
<title>An introductory example</title>
<programlisting role="php">
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Hi, I'm a PHP script!";
?>
</body>
</html>
</programlisting>
</example>
</para>
<para>
Notice how this is different from a CGI script written in other
languages like Perl or C -- instead of writing a program with lots
of commands to output HTML, you write an HTML script with a some
embedded code to do something (in this case, output some
text). The PHP code is enclosed in special <link
linkend="language.basic-syntax.phpmode">start and end tags</link>
that allow you to jump into and out of PHP mode.
</para>
<para>
What distinguishes PHP from something like client-side Javascript
is that the code is executed on the server. If you were to have a
script similar to the above on your server, the client would receive
the results of running that script, with no way of determining what
the underlying code may be. You can even configure your web server
to process all your HTML files with PHP, and then there's really no
way that users can tell what you have up your sleeve.
</para>
</sect1>
<sect1 id="intro-whatcando">
<title>What can PHP do?</title>
<para>
At the most basic level, PHP can do anything any other CGI
program can do, such as collect form data, generate dynamic
page content, or send and receive cookies.
</para>
<para>
Perhaps the strongest and most significant feature in PHP is its
support for a wide range of databases. Writing a database-enabled
web page is incredibly simple. The following databases are currently
supported:
<blockquote>
<simplelist columns="3">
<member>Adabas D</member>
<member>dBase</member>
<member>Empress</member>
<member>FilePro (read-only)</member>
<member>IBM DB2</member>
<member>Informix</member>
<member>Ingres</member>
<member>InterBase</member>
<member>FrontBase</member>
<member>mSQL</member>
<member>Direct MS-SQL</member>
<member>MySQL</member>
<member>ODBC</member>
<member>Oracle (OCI7 and OCI8)</member>
<member>PostgreSQL</member>
<member>Solid</member>
<member>Sybase</member>
<member>Velocis</member>
<member>Unix dbm</member>
</simplelist>
</blockquote>
</para>
<para>
PHP also has support for talking to other services using protocols
such as IMAP, SNMP, NNTP, POP3, HTTP and countless others. You can also
open raw network sockets and interact using other protocols.
</para>
<!--
<figure>
<title>Internal Structure</title>
<graphic fileref="../images/php3_internal_structure.gif"/>
</figure>
<figure>
<title>Request Scheme</title>
<graphic fileref="../images/php3_request_scheme.gif"/>
</figure>
-->
</sect1>
<sect1 id="intro-history">
<title>A brief history of PHP</title>
<simpara>
PHP was conceived sometime in the fall of 1994 by &link.rasmus;.
Early non-released versions were used on his home page to keep
track of who was looking at his online resume. The first version
used by others was available sometime in early 1995 and was known
as the Personal Home Page Tools. It consisted of a very
simplistic parser engine that only understood a few special macros
and a number of utilities that were in common use on home pages
back then. A guestbook, a counter and some other stuff. The
parser was rewritten in mid-1995 and named PHP/FI Version 2. The
FI came from another package Rasmus had written which interpreted
html form data. He combined the Personal Home Page tools scripts
with the Form Interpreter and added mSQL support and PHP/FI was
born. PHP/FI grew at an amazing pace and people started
contributing code to it.
</simpara>
<simpara>
It is difficult to give any hard statistics, but it is estimated
that by late 1996 PHP/FI was in use on at least 15,000 web sites
around the world. By mid-1997 this number had grown to over
50,000. Mid-1997 also saw a change in the development of PHP. It
changed from being Rasmus' own pet project that a handful of
people had contributed to, to being a much more organized team
effort. The parser was rewritten from scratch by Zeev Suraski and
Andi Gutmans and this new parser formed the basis for PHP Version
3. A lot of the utility code from PHP/FI was ported over to PHP 3
and a lot of it was completely rewritten.
</simpara>
<simpara>
Today (end-1999) either PHP/FI or PHP 3 ships with a number of
commercial products such as C2's StrongHold web server and RedHat
Linux. A conservative estimate based on an extrapolation from
numbers provided by <ulink url="&url.netcraft;">NetCraft</ulink>
(see also <ulink url="&url.netcraft-survey;">Netcraft Web Server
Survey</ulink>) would be that PHP is in use on over 1,000,000
sites around the world. To put that in perspective, that is more
sites than run Netscape's flagship Enterprise server on the
Internet.
</simpara>
<!--
<figure>
<title>NetCraft Webserver Survey</title>
<graphic fileref="&url.php.stats;"/>
</figure>
-->
<simpara>
Also as of this writing, work is underway on the next generation
of PHP, which will utilize the powerful <ulink
url="&url.zend;">Zend</ulink> scripting engine to deliver higher
performance, and will also support running under webservers other
than Apache as a native server module.
</simpara>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/chapters/security.xml
+++ phpdoc/nl/chapters/security.xml
<chapter id="security">
<title>Security</title>
<simpara>
PHP is a powerful language and the interpreter, whether included
in a web server as a module or executed as a separate
<acronym>CGI</acronym> 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 it gives you
exactly the combination of freedom and security you need.
</simpara>
<simpara>
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. This chapter explains the different configuration option
combinations and the situations they can be safely used.
</simpara>
<sect1 id="security.cgi">
<title>CGI binary</title>
<sect2>
<title>Possible attacks</title>
<simpara>
Using PHP as a <acronym>CGI</acronym> 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 <ulink url="&url.cert;">CA-96.11</ulink> 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:
</simpara>
<itemizedlist>
<listitem>
<simpara>
Accessing system files: <filename
role="url">http://my.host/cgi-bin/php?/etc/passwd</filename>
</simpara>
<simpara>
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.
</simpara>
<simpara>
When invoked as a CGI binary, PHP refuses to interpret the
command line arguments.
</simpara>
</listitem>
<listitem>
<simpara>
Accessing any web document on server: <filename
role="url">http://my.host/cgi-bin/php/secret/doc.html</filename>
</simpara>
<simpara>
The path information part of the url after the PHP binary name,
<filename role="uri">/secret/doc.html</filename> is
conventionally used to specify the name of the file to be
opened and interpreted by the <acronym>CGI</acronym> program.
Usually some web server configuration directives (Apache:
Action) are used to redirect requests to documents like
<filename
role="url">http://my.host/secret/script.php3</filename>
to the
PHP interpreter. With this setup, the web server first checks
the access permissions to the directory <filename
role="uri">/secret</filename>, and after that creates the
redirected request <filename
role="url">http://my.host/cgi-bin/php/secret/script.php3</filename>.
Unfortunately, if the request is originally given in this form,
no access checks are made by web server for file <filename
role="uri">/secret/script.php3</filename>, but only for the
<filename role="uri">/cgi-bin/php</filename> file. This way
any user able to access <filename
role="uri">/cgi-bin/php</filename> is able to access any
protected document on the web server.
</simpara>
<simpara>
In PHP, compile-time configuration option <link
linkend="install.configure.enable-force-cgi-redirect">--enable-force-cgi-redirect</link>
and runtime configuration directives <link
linkend="ini.doc-root">doc_root</link> and <link
linkend="ini.user-dir">user_dir</link> 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.
</simpara>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="security.cgi.default">
<title>Case 1: only public files served</title>
<simpara>
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 <link
linkend="install.configure.enable-force-cgi-redirect">--enable-force-cgi-redirect</link>
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 <filename
role="php">http://my.host/cgi-bin/php/dir/script.php3</filename>
nor by redirection <filename
role="php">http://my.host/dir/script.php3</filename>.
</simpara>
<simpara>
Redirection can be configured in Apache by using AddHandler and
Action directives (see below).
</simpara>
</sect2>
<sect2 id="security.cgi.force-redirect">
<title>Case 2: using --enable-force-cgi-redirect</title>
<simpara>
This compile-time option prevents anyone from calling PHP
directly with a url like <filename
role="php">http://my.host/cgi-bin/php/secretdir/script.php3</filename>.
Instead, PHP will only parse in this mode if it has gone through
a web server redirect rule.
</simpara>
<simpara>
Usually the redirection in the Apache configuration is done with
the following directives:
</simpara>
<programlisting role="apache-conf">
Action php3-script /cgi-bin/php
AddHandler php3-script .php3
</programlisting>
<simpara>
This option has only been tested with the Apache web server, and
relies on Apache to set the non-standard CGI environment variable
<envar>REDIRECT_STATUS</envar> 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.
</simpara>
</sect2>
<sect2 id="security.cgi.doc-root">
<title>Case 3: setting doc_root or user_dir</title>
<simpara>
To include active content, like scripts and executables, in the
web server document directories is sometimes consider 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.
</simpara>
<simpara>
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.
</simpara>
<simpara>
You can set the PHP script document root by the configuration
directive <link linkend="ini.doc-root">doc_root</link> in the
<link linkend="configuration.file">configuration file</link>, or
you can set the environment variable
<envar>PHP_DOCUMENT_ROOT</envar>. If it is set, the CGI version
of PHP will always construct the file name to open with this
<parameter>doc_root</parameter> and the path information in the
request, so you can be sure no script is executed outside this
directory (except for <parameter>user_dir</parameter>
below).
</simpara>
<simpara>
Another option usable here is <link
linkend="ini.user-dir">user_dir</link>. When user_dir is unset,
only thing controlling the opened file name is
<parameter>doc_root</parameter>. Opening an url like <filename
role="url">http://my.host/~user/doc.php3</filename>
does not
result in opening a file under users home directory, but a file
called <filename role="uri">~user/doc.php3</filename> under
doc_root (yes, a directory name starting with a tilde
[<literal>~</literal>]).
</simpara>
<simpara>
If user_dir is set to for example <filename
role="dir">public_php</filename>, a request like <filename
role="url">http://my.host/~user/doc.php3</filename>
will open a
file called <filename>doc.php3</filename> under the directory
named <filename role="dir">public_php</filename> under the home
directory of the user. If the home of the user is <filename
role="dir">/home/user</filename>, the file executed is
<filename>/home/user/public_php/doc.php3</filename>.
</simpara>
<simpara>
<parameter>user_dir</parameter> expansion happens regardless of
the <parameter>doc_root</parameter> setting, so you can control
the document root and user directory access
separately.
</simpara>
</sect2>
<sect2 id="security.cgi.shell">
<title>Case 4: PHP parser outside of web tree</title>
<para>
A very secure option is to put the PHP parser binary somewhere
outside of the web tree of files. In <filename
role="dir">/usr/local/bin</filename>, for example. The only real
downside to this option is that you will now have to put a line
similar to:
<informalexample>
<programlisting>
#!/usr/local/bin/php
</programlisting>
</informalexample>
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
<literal>#!</literal> shell-escape mechanism for launching
itself.
</para>
<para>
To get PHP to handle <envar>PATH_INFO</envar> and
<envar>PATH_TRANSLATED</envar> information correctly with this
setup, the php parser should be compiled with the <link
linkend="install.configure.enable-discard-path">--enable-discard-path</link>
configure option.
</para>
</sect2>
</sect1>
<sect1 id="security.apache">
<title>Apache module</title>
<simpara>
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 accessable to the
"nobody" user. This means a malicious script could access and modify
the databse, even without a username and password. It's entirely
possible that a web spider could stumble across a database
adminisitror'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.
</simpara>
<simpara>
Often, once security is established to the point where the PHP user
(in this case, the apache user) has very little risk, it is
discovered that PHP now has been prevented from writing virus files
to user directories. Or perhaps it has been prevented from accessing
or changing a non-public database. It has equally been secured from
writing files that it should, or entering database transactions.
</simpara>
<simpara>
A frequent security mistake made at this point is to allow apache
root permissions.
</simpara>
<simpara>
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.
</simpara>
</sect1>
<sect1 id="security.filesystem">
<title>Filesystem Security</title>
<simpara>
PHP honors 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.
</simpara>
<simpara>
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/password. This has some obvious
implications, in that you need to ensure that the files that you
read and write are the appropriate ones.
</simpara>
<simpara>
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.
</simpara>
<para>
<example>
<title>Filesystem attack</title>
<programlisting role="php">
<?php
// remove a file from the user's home directory
$username = $user_submitted_name;
$homedir = "/home/$username";
$file_to_delete = "$userfile";
unlink ($homedir/$userfile);
echo "$file_to_delete has been deleted!";
?>
</programlisting>
</example>
Since the username is postable from a user form, they can submit
a username and file belonging to someone else, and delete files.
In this case, you'd want to use some other form of authentication.
</para>
</sect1>
<sect1 id="security.errors">
<title>Error Reporting</title>
<simpara>
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.
</simpara>
<simpara>
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.
</simpara>
<simpara>
For example, the very style of 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.
</simpara>
<simpara>
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.
</simpara>
<simpara>
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.
</simpara>
<simpara>
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.
</simpara>
</sect1>
<sect1 id="security.variables">
<title>User Submitted Data</title>
<para>
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.
<example>
<title>Dangerous Variable Usage</title>
<programlisting role="php">
<?php
// remove a file from the user's home directory... or maybe
// somebody else's?
unlink ($evil_var);
// Write logging of their access... or maybe not?
fputs ($evil_var);
// Execute something trivial.. or rm -rf *?
system ($evil_var);
exec ($evil_var);
?>
</programlisting>
</example>
You should always carefully examine your code to make sure that any
variables being submitted from a web browser are being properly
checked, and ask yourself the following questions:
<itemizedlist>
<listitem>
<simpara>
Will this script only affect the intended files?
</simpara>
</listitem>
<listitem>
<simpara>
Can unusual or undesirable data be acted upon?
</simpara>
</listitem>
<listitem>
<simpara>
Can this script be used in unintended ways?
</simpara>
</listitem>
<listitem>
<simpara>
Can this be used in conjunction with other scripts in a negative
manner?
</simpara>
</listitem>
<listitem>
<simpara>
Will any transactions be adequately logged?
</simpara>
</listitem>
</itemizedlist>
By adequately asking these questions while writing the script,
rather than later, you prevent an unfortunate re-write when you
need to oncrease your security.
</para>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/connection-handling.xml
+++ phpdoc/nl/features/connection-handling.xml
<chapter id="features.connection-handling">
<title>Connection handling</title>
<note>
<para>The following applies to 3.0.7 and later.</para>
</note>
<para>
Internally in PHP a connection status is maintained. There are 3
possible states:
<itemizedlist>
<listitem><simpara>0 - NORMAL</simpara></listitem>
<listitem><simpara>1 - ABORTED</simpara></listitem>
<listitem><simpara>2 - TIMEOUT</simpara></listitem>
</itemizedlist>
</para>
<simpara>
When a PHP script is running normally the NORMAL state, is active.
If the remote client disconnects the ABORTED state flag is
turned on. A remote client disconnect is usually caused by the
user hitting his STOP button. If the PHP-imposed time limit (see
<function>set_time_limit</function>) is hit, the TIMEOUT state flag
is turned on.</simpara>
<simpara>
You can decide whether or not you want a client disconnect to cause
your script to be aborted. Sometimes it is handy to always have your
scripts run to completion even if there is no remote browser receiving
the output. The default behaviour is however for your script to be
aborted when the remote client disconnects. This behaviour can be
set via the ignore_user_abort php3.ini directive as well as through
the corresponding php3_ignore_user_abort Apache .conf directive or
with the <function>ignore_user_abort</function> function. If you do
not tell PHP to ignore a user abort and the user aborts, your script
will terminate. The one exception is if you have registered a shutdown
function using <function>register_shutdown_function</function>. With a
shutdown function, when the remote user hits his STOP button, the
next time your script tries to output something PHP will detect that
the connection has been aborted and the shutdown function is called.
This shutdown function will also get called at the end of your script
terminating normally, so to do something different in case of a client
diconnect you can use the <function>connection_aborted</function>
function. This function will return true if the connection was
aborted.</simpara>
<simpara>
Your script can also be terminated by the built-in script timer.
The default timeout is 30 seconds. It can be changed using
the max_execution_time php3.ini directive or the corresponding
php3_max_execution_time Apache .conf directive as well as with
the <function>set_time_limit</function> function. When the timer
expires the script will be aborted and as with the above client
disconnect case, if a shutdown function has been registered it will
be called. Within this shutdown function you can check to see if
a timeout caused the shutdown function to be called by calling the
<function>connection_timeout</function> function. This function will
return true if a timeout caused the shutdown function to be called.</simpara>
<simpara>
One thing to note is that both the ABORTED and the TIMEOUT states
can be active at the same time. This is possible if you tell
PHP to ignore user aborts. PHP will still note the fact that
a user may have broken the connection, but the script will keep
running. If it then hits the time limit it will be aborted and
your shutdown function, if any, will be called. At this point
you will find that <function>connection_timeout</function>
and <function>connection_aborted</function> return true.
You can also check both states in a single call by using the
<function>connection_status</function>. This function returns a
bitfield of the active states. So, if both states are active it
would return 3, for example.</simpara>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/cookies.xml
+++ phpdoc/nl/features/cookies.xml
<chapter id="features.cookies">
<title>Cookies</title>
<para>
PHP transparently supports HTTP cookies. Cookies are a mechanism
for storing data in the remote browser and thus tracking
or identifying return users. You can set cookies using the
<function>setcookie</function> function. Cookies are part of the
HTTP header, so <function>setcookie</function> must be called before
any output is sent to the browser. This is the same limitation that
<function>header</function> has.</para>
<para>
Any cookies sent to you from the client will automatically be
turned into a PHP variable just like GET and POST method data. If
you wish to assign multiple values to a single cookie, just add
<emphasis>[]</emphasis> to the cookie name. For more details see
the <function>setcookie</function> function.</para>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/error-handling.xml
+++ phpdoc/nl/features/error-handling.xml
<chapter id="features.error-handling">
<title>Error Handling</title>
<para>
There are several types of errors and warnings in PHP. They are:
<table>
<title>PHP error types</title>
<tgroup cols="4">
<thead>
<row>
<entry>Value</entry>
<entry>Constant</entry>
<entry>Description</entry>
<entry>Note</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>E_ERROR</entry>
<entry>fatal run-time errors</entry>
<entry></entry>
</row>
<row>
<entry>2</entry>
<entry>E_WARNING</entry>
<entry>run-time warnings (non fatal errors)</entry>
<entry></entry>
</row>
<row>
<entry>4</entry>
<entry>E_PARSE</entry>
<entry>compile-time parse errors</entry>
<entry></entry>
</row>
<row>
<entry>8</entry>
<entry>E_NOTICE </entry>
<entry>
run-time notices (less serious than warnings)
</entry>
<entry></entry>
</row>
<row>
<entry>16</entry>
<entry>E_CORE_ERROR</entry>
<entry>fatal errors that occur during PHP's initial startup</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>32</entry>
<entry>E_CORE_WARNING</entry>
<entry>
warnings (non fatal errors) that occur during PHP's initial
startup
</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>64</entry>
<entry>E_COMPILE_ERROR</entry>
<entry>fatal compile-time errors</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>128</entry>
<entry>E_COMPILE_WARNING</entry>
<entry>compile-time warnings (non fatal errors)</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>256</entry>
<entry>E_USER_ERROR</entry>
<entry>user-generated error message</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>512</entry>
<entry>E_USER_WARNING</entry>
<entry>user-generated warning message</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry>1024</entry>
<entry>E_USER_NOTICE </entry>
<entry>user-generated notice message</entry>
<entry>PHP 4 only</entry>
</row>
<row>
<entry></entry>
<entry>E_ALL</entry>
<entry>all of the above, as supported</entry>
<entry></entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
The above values (either numerical or symbolic) are used to build
up a bitmask that specifies which errors to report. You can use the
<link linkend="language.operators.bitwise">bitwise operators</link>
to combine these values or mask out certain types of errors. Note
that only '|', '~', '!', and '&' will be
understood within
<filename>php.ini</filename>, however, and that no bitwise
operators will be understood within <filename>php3.ini</filename>.
</para>
<para>
In PHP 4, the default <link
linkend="ini.error-reporting">error_reporting</link> setting is
<literal>E_ALL & ~E_NOTICE</literal>, meaning to display all errors
and warnings which are not E_NOTICE-level. In PHP 3, the default
setting is <literal>(E_ERROR | E_WARNING | E_PARSE)</literal>,
meaning the same thing. Note, however, that since constants are not
supported in PHP 3's <filename>php3.ini</filename>, the <link
linkend="ini.error-reporting">error_reporting</link> setting there
must be numeric; hence, it is <literal>7</literal>.
</para>
<para>
The initial setting can be changed in the ini file with the <link
linkend="ini.error-reporting">error_reporting</link> directive, in
your Apache <filename>httpd.conf</filename> file with the
php_error_reporting (php3_error_reporting for PHP 3) directive, and
lastly it may be set at runtime within a script by using the
<function>error_reporting</function> function.
</para>
<warning>
<para>
When upgrading code or servers from PHP 3 to PHP 4 you should
check these settings and calls to
<function>error_reporting</function> 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.
</para>
</warning>
<para>
All <link linkend="language.expressions">PHP expressions</link> can
also be called with the "@" prefix, which turns off error reporting
for that particular expression. If an error occurred during such
an expression and the <link
linkend="ini.track-errors">track_errors</link> feature is enabled,
you can find the error message in the global variable
$php_errormsg.
</para>
<warning>
<para>
Currently the <link linkend="language.operators.errorcontrol">@
error-control operator</link> prefix will even disable error
reporting for critical errors that will terminate script
execution. Among other things, this means that if you use <link
linkend="language.operators.errorcontrol">@</link> to suppress
errors from a certain function and either it isn't available or
has been mistyped, the script will die right there with no
indication as to why.
</para>
</warning>
<para>
Below we can see an example of using the error handling capabilities in
PHP. We define a 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.
<example>
<title>Using error handling in a script</title>
<programlisting role="php">
<?php
// we will do our own error handling
error_reporting(0);
// user defined error handling function
function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) {
// timestamp for the error entry
$dt = date("Y-m-d H:i:s (T)");
// define an assoc array of error string
// in reality the only entries we should
// consider are 2,8,256,512 and 1024
$errortype = array (
1 => "Error",
2 => "Warning",
4 => "Parsing Error",
8 => "Notice",
16 => "Core Error",
32 => "Core Warning",
64 => "Compile Error",
128 => "Compile Warning",
256 => "User Error",
512 => "User Warning",
1024=> "User Notice"
);
// set of errors for which a var trace will be saved
$user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
$err = "<errorentry>\n";
$err .=
"\t<datetime>".$dt."</datetime>\n";
$err .=
"\t<errornum>".$errno."</errnumber>\n";
$err .=
"\t<errortype>".$errortype[$errno]."</errortype>\n";
$err .=
"\t<errormsg>".$errmsg."</errormsg>\n";
$err .=
"\t<scriptname>".$filename."</scriptname>\n";
$err .=
"\t<scriptlinenum>".$linenum."</scriptlinenum>\n";
if (in_array($errno, $user_errors))
$err .=
"\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n";
$err .= "</errorentry>\n\n";
// for testing
// echo $err;
// save to the error log, and e-mail me if there is a critical user error
error_log($err, 3, "/usr/local/php4/error.log");
if ($errno == E_USER_ERROR)
mail("phpdev@mydomain.com","Critical User Error",$err);
}
function distance ($vect1, $vect2) {
if (!is_array($vect1) || !is_array($vect2)) {
trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR);
return NULL;
}
if (count($vect1) != count($vect2)) {
trigger_error("Vectors need to be of the same size", E_USER_ERROR);
return NULL;
}
for ($i=0; $i<count($vect1); $i++) {
$c1 = $vect1[$i]; $c2 = $vect2[$i];
$d = 0.0;
if (!is_numeric($c1)) {
trigger_error("Coordinate $i in vector 1 is not a number, using zero",
E_USER_WARNING);
$c1 = 0.0;
}
if (!is_numeric($c2)) {
trigger_error("Coordinate $i in vector 2 is not a number, using zero",
E_USER_WARNING);
$c2 = 0.0;
}
$d += $c2*$c2 - $c1*$c1;
}
return sqrt($d);
}
$old_error_handler = set_error_handler("userErrorHandler");
// undefined constant, generates a warning
$t = I_AM_NOT_DEFINED;
// define some "vectors"
$a = array(2,3,"foo");
$b = array(5.5, 4.3, -1.6);
$c = array (1,-3);
// generate a user error
$t1 = distance($c,$b)."\n";
// generate another user error
$t2 = distance($b,"i am not an array")."\n";
// generate a warning
$t3 = distance($a,$b)."\n";
?>
</programlisting>
</example>
This is just a simple example showing how to use the
<link linkend="ref.errorfunc">Error Handling and Logging
functions</link>.
</para>
<para>
See also <function>error_reporting</function>,
<function>error_log</function>,
<function>set_error_handler</function>,
<function>restore_error_handler</function>,
<function>trigger_error</function>,
<function>user_error</function>
</para>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/file-upload.xml
+++ phpdoc/nl/features/file-upload.xml
<chapter id="features.file-upload">
<title>Handling file uploads</title>
<sect1 id="features.file-upload.post-method">
<title>POST method uploads</title>
<simpara>
PHP is capable of receiving file uploads from any RFC-1867
compliant browser (which includes Netscape Navigator 3 or later,
Microsoft Internet Explorer 3 with a patch from Microsoft, or
later without a patch). This feature lets people upload both text
and binary files. With PHP's authentication and file manipulation
functions, you have full control over who is allowed to upload and
what is to be done with the file once it has been uploaded.
</simpara>
<para>
Note that PHP also supports PUT-method file uploads as used by
Netscape Composer and W3C's Amaya clients. See the <link
linkend="features.file-upload.put-method">PUT Method
Support</link> for more details.
</para>
<para>
A file upload screen can be built by creating a special form which
looks something like this:
<example>
<title>File Upload Form</title>
<programlisting>
<FORM ENCTYPE="multipart/form-data" ACTION="_URL_"
METHOD=POST>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE"
value="1000">
Send this file: <INPUT NAME="userfile"
TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
</FORM>
</programlisting>
</example>
The _URL_ should point to a PHP file. The MAX_FILE_SIZE hidden
field must precede the file input field and its value is the
maximum filesize accepted. The value is in bytes.
</para>
<para>
In PHP 3, the following variables will be defined within the
destination script upon a successful upload, assuming that <link
linkend="ini.register-globals">register_globals</link> is turned
on in <filename>php.ini</filename>. If <link
linkend="ini.track-vars">track_vars</link> is turned on, they will
also be available within the global array
<varname>$HTTP_POST_VARS</varname>. Note that the following
variable names assume the use of the file upload name 'userfile',
as used in the example above:
<itemizedlist>
<listitem>
<simpara>
<varname>$userfile</varname> - The temporary filename in which
the uploaded file was stored on the server machine.
</simpara>
</listitem>
<listitem>
<simpara>
<varname>$userfile_name</varname> - The original name or path
of the file on the sender's system.
</simpara>
</listitem>
<listitem>
<simpara>
<varname>$userfile_size</varname> - The size of the uploaded
file in bytes.
</simpara>
</listitem>
<listitem>
<simpara>
<varname>$userfile_type</varname> - The mime type of the file
if the browser provided this information. An example would be
"image/gif".
</simpara>
</listitem>
</itemizedlist>
Note that the "$userfile" part of the above variables is
whatever the name of the INPUT field of TYPE=file is in the upload
form. In the above upload form example, we chose to call it
"userfile"
</para>
<para>
In PHP 4, the behaviour is slightly different, in that the new
global array <varname>$HTTP_POST_FILES</varname> is provided to
contain the uploaded file information. This is still only
available if <link linkend="ini.track-vars">track_vars</link> is
turned on, but <link linkend="ini.track-vars">track_vars</link> is
always turned on in versions of PHP after PHP 4.0.2.
</para>
<para>
The contents of <varname>$HTTP_POST_FILES</varname> are as
follows. Note that this assumes the use of the file upload name
'userfile', as used in the example above:
<variablelist>
<varlistentry>
<term><varname>$HTTP_POST_FILES['userfile']['name']</varname></term>
<listitem>
<para>
The original name of the file on the client machine.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>$HTTP_POST_FILES['userfile']['type']</varname></term>
<listitem>
<para>
The mime type of the file, if the browser provided this
information. An example would be
<literal>"image/gif"</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>$HTTP_POST_FILES['userfile']['size']</varname></term>
<listitem>
<para>
The size, in bytes, of the uploaded file.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>$HTTP_POST_FILES['userfile']['tmp_name']</varname></term>
<listitem>
<para>
The temporary filename of the file in which the uploaded file
was stored on the server.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
Files will by default be stored in the server's default temporary
directory, unless another location has been given with the <link
linkend="ini.upload-tmp-dir">upload_tmp_dir</link> directive in
<filename>php.ini</filename>. The server's default directory can
be changed by setting the environment variable
<envar>TMPDIR</envar> in the environment in which PHP runs.
Setting it using <function>putenv</function> from within a PHP
script will not work. This environment variable can also be used
to make sure that other operations are working on uploaded files,
as well.
<example>
<title>Validating file uploads</title>
<para>
The following examples are for versions of PHP 3 greater than
3.0.16, and versions of PHP 4 greater than 4.0.2. See the
function entries for <function>is_uploaded_file</function> and
<function>move_uploaded_file</function>.
</para>
<programlisting role="php">
<?php
if (is_uploaded_file($userfile)) {
copy($userfile, "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack: filename '$userfile'.";
}
/* ...or... */
move_uploaded_file($userfile, "/place/to/put/uploaded/file");
?>
</programlisting>
<para>
For earlier versions of PHP, you'll need to do something like
the following.
<note>
<para>
This will <emphasis>not</emphasis> work in versions of PHP 4
after 4.0.2. It depends on internal functionality of PHP which
changed after that version.
</para>
</note>
</para>
<programlisting role="php">
<?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);
}
if (is_uploaded_file($userfile)) {
copy($userfile, "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack: filename '$userfile'.";
}
?>
</programlisting>
</example>
</para>
<simpara>
The PHP script which receives the uploaded file should implement
whatever logic is necessary for determining what should be done
with the uploaded file. You can for example use the
<varname>$file_size</varname> variable to throw away any files
that are either too small or too big. You could use the
<varname>$file_type</varname> variable to throw away any files
that didn't match a certain type criteria. Whatever the logic,
you should either delete the file from the temporary directory or
move it elsewhere.
</simpara>
<simpara>
The file will be deleted from the temporary directory at the end
of the request if it has not been moved away or renamed.
</simpara>
</sect1>
<sect1 id="features.file-upload.common-pitfalls">
<title>Common Pitfalls</title>
<simpara>
The MAX_FILE_SIZE item cannot specify a file size greater than the file
size that has been set in the upload_max_filesize in the PHP 3.ini file
or the corresponding php3_upload_max_filesize Apache .conf directive.
The default is 2 Megabytes.
</simpara>
<simpara>
Not validating which file you operate on may mean that users can access
sensitive information in other directories.
</simpara>
<simpara>
Please note that the CERN httpd seems to strip off everything
starting at the first whitespace in the content-type mime header
it gets from the client. As long as this is the case, CERN httpd
will not support the file upload feature.
</simpara>
</sect1>
<sect1 id="feature-fileupload.multiple">
<title>Uploading multiple files</title>
<simpara>
It is possible to upload multiple files simultaneously and have
the information organized automatically in arrays for you. To
do so, you need to use the same array submission syntax in the
HTML form as you do with multiple selects and checkboxes:
</simpara>
<note>
<para>
Support for multiple file uploads was added in version 3.0.10.
</para>
</note>
<para>
<example>
<title>Uploading multiple files</title>
<programlisting>
<form action="file-upload.html" method="post"
enctype="multipart/form-data">
Send these files:<br>
<input name="userfile[]"
type="file"><br>
<input name="userfile[]"
type="file"><br>
<input type="submit" value="Send files">
</form>
</programlisting>
</example>
</para>
<simpara>
When the above form is submitted, the arrays
<computeroutput>$userfile</computeroutput>,
<computeroutput>$userfile_name</computeroutput>, and
<computeroutput>$userfile_size</computeroutput> will be formed in
the global scope (as well as in $HTTP_POST_FILES ($HTTP_POST_VARS
in PHP 3)). Each of these will be a numerically indexed array of
the appropriate values for the submitted files.
</simpara>
<simpara>
For instance, assume that the filenames
<filename>/home/test/review.html</filename> and
<filename>/home/test/xwp.out</filename> are submitted. In this
case, <computeroutput>$userfile_name[0]</computeroutput> would
contain the value <computeroutput>review.html</computeroutput>,
and <computeroutput>$userfile_name[1]</computeroutput> would
contain the value
<computeroutput>xwp.out</computeroutput>. Similarly,
<computeroutput>$userfile_size[0]</computeroutput> would contain
<filename>review.html</filename>'s filesize, and so forth.
</simpara>
<simpara>
<computeroutput>$userfile['name'][0]</computeroutput>,
<computeroutput>$userfile['tmp_name'][0]</computeroutput>,
<computeroutput>$userfile['size'][0]</computeroutput>, and
<computeroutput>$userfile['type'][0]</computeroutput> are also set.
</simpara>
</sect1>
<sect1 id="features.file-upload.put-method">
<title>PUT method support</title>
<para>
PHP provides support for the HTTP PUT method used by clients such
as Netscape Composer and W3C Amaya. PUT requests are much simpler
than a file upload and they look something like this:
<informalexample>
<programlisting>
PUT /path/filename.html HTTP/1.1
</programlisting>
</informalexample>
</para>
<para>
This would normally mean that the remote client would like to save
the content that follows as: /path/filename.html in your web tree.
It is obviously not a good idea for Apache or PHP to automatically
let everybody overwrite any files in your web tree. So, to handle
such a request you have to first tell your web server that you
want a certain PHP script to handle the request. In Apache you do
this with the <emphasis>Script</emphasis> directive. It can be
placed almost anywhere in your Apache configuration file. A
common place is inside a <Directory> block or perhaps inside
a <Virtualhost> block. A line like this would do the trick:
<informalexample>
<programlisting>
Script PUT /put.php3
</programlisting>
</informalexample>
</para>
<simpara>
This tells Apache to send all PUT requests for URIs that match the
context in which you put this line to the put.php3 script. This
assumes, of course, that you have PHP enabled for the .php3
extension and PHP is active.
</simpara>
<simpara>
Inside your put.php3 file you would then do something like this:
</simpara>
<para>
<informalexample><programlisting>
<? copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?>
</programlisting></informalexample>
</para>
<simpara>
This would copy the file to the location requested by the remote
client. You would probably want to perform some checks and/or
authenticate the user before performing this file copy. The only
trick here is that when PHP sees a PUT-method request it stores
the uploaded file in a temporary file just like those handled but
the <link
linkend="features.file-upload.post-method">POST-method</link>.
When the request ends, this temporary file is deleted. So, your
PUT handling PHP script has to copy that file somewhere. The
filename of this temporary file is in the $PHP_PUT_FILENAME
variable, and you can see the suggested destination filename in
the $REQUEST_URI (may vary on non-Apache web servers). This
destination filename is the one that the remote client specified.
You do not have to listen to this client. You could, for example,
copy all uploaded files to a special uploads directory.
</simpara>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/http-auth.xml
+++ phpdoc/nl/features/http-auth.xml
<chapter id="features.http-auth">
<title>HTTP authentication with PHP</title>
<simpara>
The HTTP Authentication hooks in PHP are only available when it is
running as an Apache module and is hence not available in the CGI version.
In an Apache module PHP script, it is possible to use the
<function>Header</function> function to send an "Authentication Required"
message to the client browser causing it to pop up a Username/Password
input window. Once the user has filled in a username and a password,
the URL containing the PHP script will be called again with the variables,
$PHP_AUTH_USER, $PHP_AUTH_PW and $PHP_AUTH_TYPE set to the user
name, password and authentication type respectively. Only "Basic"
authentication is supported at this point. See the <function>Header</function>
function for more information.</simpara>
<para>
An example script fragment which would force client authentication
on a page would be the following:
<example>
<title>HTTP Authentication example</title>
<programlisting role="php">
<?php
if(!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm=\"My Realm\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Text to send if user hits Cancel button\n";
exit;
} else {
echo "Hello $PHP_AUTH_USER.<P>";
echo "You entered $PHP_AUTH_PW as your password.<P>";
}
?>
</programlisting>
</example></para>
<para>
Instead of simply printing out the $PHP_AUTH_USER and
$PHP_AUTH_PW, you would probably want to check the username and
password for validity. Perhaps by sending a query to a database,
or by looking up the user in a dbm file.</para>
<para>
Watch out for buggy Internet Explorer browsers out there. They
seem very picky about the order of the headers. Sending the
<emphasis>WWW-Authenticate</emphasis> header before the
<errorcode>HTTP/1.0 401</errorcode> header seems to do the trick
for now.</para>
<simpara>
In order to prevent someone from writing a script which reveals
the password for a page that was authenticated through a
traditional external mechanism, the PHP_AUTH variables will not be
set if external authentication is enabled for that particular
page. In this case, the $REMOTE_USER variable can be used to
identify the externally-authenticated user.</simpara>
<simpara>
Note, however, that the above does not prevent someone who
controls a non-authenticated URL from stealing passwords from
authenticated URLs on the same server.</simpara>
<simpara>
Both Netscape and Internet Explorer will clear the local browser
window's authentication cache for the realm upon receiving a
server response of 401. This can effectively "log out" a user,
forcing them to re-enter their username and password. Some people
use this to "time out" logins, or provide a "log-out" button.</simpara>
<simpara></simpara>
<example>
<title>HTTP Authentication example forcing a new name/password</title>
<programlisting role="php">
<?php
function authenticate() {
Header( "WWW-authenticate: basic realm=\"Test Authentication
System\"");
Header( "HTTP/1.0 401 Unauthorized");
echo "You must enter a valid login ID and password to access this
resource\n";
exit;
}
if(!isset($PHP_AUTH_USER) || ($SeenBefore == 1 && !strcmp($OldAuth,
$PHP_AUTH_USER)) ) {
authenticate();
}
else {
echo "Welcome: $PHP_AUTH_USER<BR>";
echo "Old: $OldAuth";
echo "<FORM ACTION=\"$PHP_SELF\"
METHOD=POST>\n";
echo "<INPUT TYPE=HIDDEN NAME=\"SeenBefore\"
VALUE=\"1\">\n";
echo "<INPUT TYPE=HIDDEN NAME=\"OldAuth\"
VALUE=\"$PHP_AUTH_USER\">\n";
echo "<INPUT TYPE=Submit VALUE=\"Re
Authenticate\">\n";
echo "</FORM>\n";
}
?>
</programlisting>
</example>
<simpara>
This behavior is not required by the HTTP Basic authentication
standard, so you should never depend on this. Testing with Lynx
has shown that Lynx does not clear the authentication credentials
with a 401 server response, so pressing back and then forward
again will open the resource (as long as the credential
requirements haven't changed).</simpara>
<simpara>
Also note that this does not work using Microsoft's IIS server and
the CGI version of PHP due to a limitation of IIS.</simpara>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/images.xml
+++ phpdoc/nl/features/images.xml
<chapter id="features.images">
<title>Creating and manipulating images</title>
<simpara>
PHP is not limited to creating just HTML output. It can also be
used to create and manipulate image files in a variety of different
image formats, including gif, png, jpg, wbmp, and xpm. Even more
convenient, php can output image streams directly to a browser. You
will need to compile PHP with the GD library of image functions for
this to work. GD and PHP may also require other libraries, depending
on which image formats you want to work with.
</simpara>
<para>
<example>
<title>GIF creation with PHP</title>
<programlisting role="php">
<?php
Header("Content-type: image/gif");
$string=implode($argv," ");
$im = imagecreatefromgif("images/button1.gif");
$orange = ImageColorAllocate($im, 220, 210, 60);
$px = (imagesx($im)-7.5*strlen($string))/2;
ImageString($im,3,$px,9,$string,$orange);
ImageGif($im);
ImageDestroy($im);
?>
</programlisting>
</example>
This example would be called from a page with a tag like: <img
src="button.php?text"> The above button.php script
then takes this "text" string an overlays it on top of a
base image which in this case is "images/button1.gif"
and outputs the resulting image. This is a very convenient way to
avoid having to draw new button images every time you want to
change the text of a button. With this method they are
dynamically generated.
</para>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/persistent-connections.xml
+++ phpdoc/nl/features/persistent-connections.xml
<chapter id="features.persistent-connections">
<title>Persistent Database Connections</title>
<simpara>
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).
</simpara>
<simpara>
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 <emphasis>not</emphasis> give
you an ability to open 'user sessions' on the same SQL link, they
do <emphasis>not</emphasis> give you an ability to build up a
transaction efficently, 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 <emphasis>any</emphasis>
functionality that wasn't possible with their non-persistent
brothers.
</simpara>
<simpara>
Why?
</simpara>
<simpara>
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.
</simpara>
<simpara>
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.
</simpara>
<simpara>
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 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 us of such a connection. When another page then
requires a connection to the SQL server, it can reuse the
connection that child established earlier.
</simpara>
<simpara>
The last method is to use PHP as a plug-in for a multithreaded web
server. Currently this is only theoretical -- PHP does not yet work
as a plug-in for any multithreaded web servers. Work is progressing
on support for ISAPI, WSAPI, and NSAPI (on Windows), which will all
allow PHP to be used as a plug-in on multithreaded servers like
Netscape FastTrack, Microsoft's Internet Information Server (IIS),
and O'Reilly's WebSite Pro. When this happens, the behavior will be
essentially the same as for the multiprocess model described
before.
</simpara>
<simpara>
If persistent connections don't have any added functionality, what
are they good for?
</simpara>
<simpara>
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.
</simpara>
<simpara>
Note, however, that this can have some drawbacks if you are using a
database with connection limits that are exceeded by persistant
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), a database with only 32 connections
may be rapidly swamped. Check your database documentation for
information on handling abandoned or idle connections.
</simpara>
<simpara>
An important summary. Persistent connections were designed to have
one-to-one mapping to regular connections. That means that you
should <emphasis>always</emphasis> be able to replace persistent
connections with non-persistent connections, and it won't change
the way your script behaves. It <emphasis>may</emphasis> (and
probably will) change the efficiency of the script, but not its
behavior!
</simpara>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/features/remote-files.xml
+++ phpdoc/nl/features/remote-files.xml
<chapter id="features.remote-files">
<title>Using remote files</title>
<para>
As long as support for the "URL fopen wrapper" is enabled when
you configure PHP (which it is unless you explicitly pass the
<option>--disable-url-fopen-wrapper</option> flag to configure),
you can use HTTP and FTP URLs with most functions that take a
filename as a parameter, including the <function>require</function>
and <function>include</function> statements.
</para>
<para>
<note>
<para>
You can't use remote files in <function>include</function> and
<function>require</function> statements on Windows.
</para>
</note>
</para>
<para>
For example, you can use this to open a file on a remote web server,
parse the output for the data you want, and then use that data in a
database query, or simply to output it in a style matching the rest
of your website.
</para>
<para>
<example>
<title>Getting the title of a remote page</title>
<programlisting role="php">
<![CDATA[
<?php
$file = fopen ("http://www.php.net/",
"r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
/* This only works if the title and its tags are on one line */
if (eregi ("<title>(.*)</title>", $line, $out)) {
$title = $out[1];
break;
}
}
fclose($file);
?>
]]>
</programlisting>
</example>
</para>
<para>
You can also write to files on an FTP as long you connect as a user
with the correct access rights, and the file doesn't exist already.
To connect as a user other than 'anonymous', you need to specify
the username (and possibly password) within the URL, such as
'ftp://user:password@ftp.example.com/path/to/file'.
(You can use the
same sort of syntax to access files via HTTP when they require Basic
authentication.)
</para>
<para>
<example>
<title>Storing data on a remote server</title>
<programlisting role="php">
<![CDATA[
<?php
$file = fopen ("ftp://ftp.php.net/incoming/outputfile",
"w");
if (!$file) {
echo "<p>Unable to open remote file for writing.\n";
exit;
}
/* Write the data here. */
fputs ($file, "$HTTP_USER_AGENT\n");
fclose ($file);
?>
]]>
</programlisting>
</example>
</para>
<para>
<note>
<para>
You might get the idea from the example above to use this
technique to write to a remote log, but as mentioned above, you
can only write to a new file using the URL fopen() wrappers. To
do distributed logging like that, you should take a look at
<function>syslog</function>.
</para>
</note>
</para>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/apache.xml
+++ phpdoc/nl/functions/apache.xml
<reference id="ref.apache">
<title>Apache-specific Functions</title>
<titleabbrev>Apache</titleabbrev>
<refentry id="function.apache-lookup-uri">
<refnamediv>
<refname>apache_lookup_uri</refname>
<refpurpose>
Perform a partial request for the specified URI and return all
info about it
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>class <function>apache_lookup_uri</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This performs a partial request for a URI. It goes just far
enough to obtain all the important information about the given
resource and returns this information in a class. The properties
of the returned class are:
<simplelist>
<member>status</member>
<member>the_request</member>
<member>status_line</member>
<member>method</member>
<member>content_type</member>
<member>handler</member>
<member>uri</member>
<member>filename</member>
<member>path_info</member>
<member>args</member>
<member>boundary</member>
<member>no_cache</member>
<member>no_local_copy</member>
<member>allowed</member>
<member>send_bodyct</member>
<member>bytes_sent</member>
<member>byterange</member>
<member>clength</member>
<member>unparsed_uri</member>
<member>mtime</member>
<member>request_time</member>
</simplelist>
</para>
<note>
<simpara>
<function>Apache_lookup_uri</function> only works when PHP
is installed as an Apache module.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.apache-note">
<refnamediv>
<refname>apache_note</refname>
<refpurpose>Get and set apache request notes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>apache_note</function></funcdef>
<paramdef>string <parameter>note_name</parameter></paramdef>
<paramdef>string
<parameter>
<optional>note_value</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Apache_note</function> is an Apache-specific function
which gets and sets values in a request's
<literal>notes</literal> table. If called with one argument, it
returns the current value of note
<literal>note_name</literal>. If called with two arguments, it
sets the value of note <literal>note_name</literal> to
<literal>note_value</literal> and returns the previous value of
note <literal>note_name</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.getallheaders">
<refnamediv>
<refname>getallheaders</refname>
<refpurpose>Fetch all HTTP request headers</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>getallheaders</function></funcdef>
<paramdef>void<parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an associative array of all the HTTP
headers in the current request.
</para>
<para>
<note>
<para>
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
<function>phpinfo</function> to see a list of all of the
environment variables defined this way.
</para>
</note>
</para>
<para>
<example>
<title><function>getallheaders</function> Example</title>
<programlisting role="php">
$headers = getallheaders();
while (list ($header, $value) = each ($headers)) {
echo "$header: $value<br>\n";
}
</programlisting>
</example>
</para>
<para>
This example will display all the request headers for the current
request.
<note>
<simpara>
<function>Getallheaders</function> is currently only supported
when PHP runs as an <productname>Apache</productname> module.
</simpara>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.virtual">
<refnamediv>
<refname>virtual</refname>
<refpurpose>Perform an Apache sub-request</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>virtual</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Virtual</function> is an Apache-specific function which
is equivalent to <!--#include virtual...--> in mod_include.
It performs an Apache sub-request. It is useful for including
CGI scripts or .shtml files, or anything else that you would
parse through Apache. Note that for a CGI script, the script
must generate valid CGI headers. At the minimum that means it
must generate a Content-type header. For PHP files, you need to
use <function>include</function> or <function>require</function>;
<function>virtual</function> cannot be used to include a document
which is itself a PHP file.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/array.xml
+++ phpdoc/nl/functions/array.xml
<reference id="ref.array">
<title>Array Functions</title>
<titleabbrev>Arrays</titleabbrev>
<partintro>
<simpara>
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.
</simpara>
<simpara>
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.
</simpara>
<para>
See also <function>explode</function>, <function>implode</function>,
<function>split</function> and <function>join</function>.
</para>
</partintro>
<refentry id="function.array">
<refnamediv>
<refname>array</refname>
<refpurpose>
Create an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array</function></funcdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of the parameters. The parameters can be given
an index with the <literal>=></literal> operator.
</para>
<para>
<note>
<para>
<function>Array</function> is a language construct used to
represent literal arrays, and not a regular function.
</para>
</note>
</para>
<para>
The following example demonstrates how to create a
two-dimensional array, how to specify keys for associative
arrays, and how to skip-and-continue numeric indices in normal
arrays.
<example>
<title><function>Array</function> example</title>
<programlisting role="php">
$fruits = array (
"fruits" => array ("a"=>"orange",
"b"=>"banana", "c"=>"apple"),
"numbers" => array (1, 2, 3, 4, 5, 6),
"holes" => array ("first", 5 => "second",
"third")
);
</programlisting>
</example>
</para>
<para>
See also: <function>list</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-count-values">
<refnamediv>
<refname>array_count_values</refname>
<refpurpose>Counts all the values of an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_count_values</function></funcdef>
<paramdef>array <parameter>input</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_count_values</function> returns an array using
the values of the <parameter>input</parameter> array as keys and
their frequency in <parameter>input</parameter> as values.
</para>
<para>
<example>
<title><function>Array_count_values</function> example</title>
<programlisting role="php">
$array = array (1, "hello", 1, "world", "hello");
array_count_values ($array); // returns array (1=>2, "hello"=>2,
"world"=>1)
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.array-diff">
<refnamediv>
<refname>array_diff</refname>
<refpurpose>Computes the difference of arrays</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_diff</function></funcdef>
<paramdef>array <parameter>array1</parameter></paramdef>
<paramdef>array <parameter>array2</parameter></paramdef>
<paramdef>array
<parameter><optional> ...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_diff</function> returns an array
containing all the values of <parameter>array1</parameter>
that are not present in any of the other arguments.
Note that keys are preserved.
</para>
<para>
<example>
<title><function>Array_diff</function> example</title>
<programlisting role="php">
$array1 = array ("a" => "green", "red", "blue");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_diff ($array1, $array2);
</programlisting>
</example>
</para>
<para>
This makes <varname>$result</varname> have <literal>array
("blue");</literal>
</para>
<para>
See also <function>array_intersect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-flip">
<refnamediv>
<refname>array_flip</refname>
<refpurpose>Flip all the values of an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_flip</function></funcdef>
<paramdef>array <parameter>trans</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_flip</function> returns an array in flip order.
</para>
<para>
<example>
<title><function>Array_flip</function> example</title>
<programlisting role="php">
$trans = array_flip ($trans);
$original = strtr ($str, $trans);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.array-intersect">
<refnamediv>
<refname>array_intersect</refname>
<refpurpose>Computes the intersection of arrays</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_intersect</function></funcdef>
<paramdef>array <parameter>array1</parameter></paramdef>
<paramdef>array <parameter>array2</parameter></paramdef>
<paramdef>array
<parameter><optional> ...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_intersect</function> returns an array
containing all the values of <parameter>array1</parameter>
that are present in all the arguments.
Note that keys are preserved.
</para>
<para>
<example>
<title><function>Array_intersect</function> example</title>
<programlisting role="php">
$array1 = array ("a" => "green", "red", "blue");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_intersect ($array1, $array2);
</programlisting>
</example>
</para>
<para>
This makes <varname>$result</varname> have <literal>array ("a"
=> "green", "red");</literal>
</para>
<para>
See also <function>array_diff</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-keys">
<refnamediv>
<refname>array_keys</refname>
<refpurpose>Return all the keys of an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_keys</function></funcdef>
<paramdef>array <parameter>input</parameter></paramdef>
<paramdef>mixed
<parameter>
<optional>search_value</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_keys</function> returns the keys, numeric and
string, from the <parameter>input</parameter> array.
</para>
<para>
If the optional <parameter>search_value</parameter> is specified,
then only the keys for that value are returned. Otherwise, all
the keys from the <parameter>input</parameter> are returned.
</para>
<para>
<example>
<title><function>Array_keys</function> example</title>
<programlisting role="php">
$array = array (0 => 100, "color" => "red");
array_keys ($array); // returns array (0, "color")
$array = array ("blue", "red", "green", "blue",
"blue");
array_keys ($array, "blue"); // returns array (0, 3, 4)
</programlisting>
</example>
</para>
<note>
<para>
This function was added to PHP 4, below is an implementation for
those still using PHP 3.
<example>
<title>
Implementation of <function>array_keys</function> for PHP 3
users
</title>
<programlisting role="php">
function array_keys ($arr, $term="") {
$t = array();
while (list($k,$v) = each($arr)) {
if ($term && $v != $term)
continue;
$t[] = $k;
}
return $t;
}
</programlisting>
</example>
</para>
</note>
<para>
See also <function>array_values</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-merge">
<refnamediv>
<refname>array_merge</refname>
<refpurpose>Merge two or more arrays</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_merge</function></funcdef>
<paramdef>array <parameter>array1</parameter></paramdef>
<paramdef>array <parameter>array2</parameter></paramdef>
<paramdef>array
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_merge</function> 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.
</para>
<para>
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 have the same numeric key, the later value will not
overwrite the original value, but will be appended.
</para>
<para>
<example>
<title><function>array_merge</function> example</title>
<programlisting role="php">
$array1 = array ("color" => "red", 2, 4);
$array2 = array ("a", "b", "color" => "green",
"shape" => "trapezoid", 4);
array_merge ($array1, $array2);
</programlisting>
</example>
</para>
<para>
Resulting array will be <literal>array("color" => "green", 2,
4,
"a", "b", "shape" => "trapezoid",
4)</literal>.
</para>
<para>
See also <function>array_merge_recursive</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-merge-recursive">
<refnamediv>
<refname>array_merge_recursive</refname>
<refpurpose>Merge two or more arrays recursively</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_merge_recursive</function></funcdef>
<paramdef>array <parameter>array1</parameter></paramdef>
<paramdef>array <parameter>array2</parameter></paramdef>
<paramdef>array
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_merge_recursive</function> 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.
</para>
<para>
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.
</para>
<para>
<example>
<title><function>Array_merge_recursive</function> example</title>
<programlisting role="php">
$ar1 = array ("color" => array ("favorite" => "red"),
5);
$ar2 = array (10, "color" => array ("favorite" =>
"green", "blue"));
$result = array_merge_recursive ($ar1, $ar2);
</programlisting>
</example>
</para>
<para>
Resulting array will be <literal>array ("color" => array
("favorite" => array ("red", "green"), "blue"),
5, 10)</literal>.
</para>
<para>
See also <function>array_merge</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-multisort">
<refnamediv>
<refname>array_multisort</refname>
<refpurpose>Sort multiple or multi-dimensional arrays</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>array_multisort</function></funcdef>
<paramdef>array <parameter>ar1</parameter></paramdef>
<paramdef>mixed
<parameter><optional>arg</optional></parameter>
</paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
<paramdef>array
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_multisort</function> can be used to sort several
arrays at once or a multi-dimensional array according by one of
more dimensions. It maintains key association when sorting.
</para>
<para>
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.
</para>
<para>
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.
</para>
<para>
Sorting order flags:
<itemizedlist>
<listitem>
<simpara>SORT_ASC - sort in ascending order</simpara>
</listitem>
<listitem>
<simpara>SORT_DESC - sort in descending order</simpara>
</listitem>
</itemizedlist>
</para>
<para>
Sorting type flags:
<itemizedlist>
<listitem>
<simpara>SORT_REGULAR - compare items normally</simpara>
</listitem>
<listitem>
<simpara>SORT_NUMERIC - compare items numerically</simpara>
</listitem>
<listitem>
<simpara>SORT_STRING - compare items as strings</simpara>
</listitem>
</itemizedlist>
</para>
<para>
No two sorting flags of the same type can be specified after each
array. The sortings flags specified after an array argument apply
only to that array - they are reset to default SORT_ASC and
SORT_REGULAR after before each new array argument.
</para>
<para>
Returns true on success, false on failure.
</para>
<para>
<example>
<title>Sorting multiple arrays</title>
<programlisting role="php">
$ar1 = array ("10", 100, 100, "a");
$ar2 = array (1, 3, "2", 1);
array_multisort ($ar1, $ar2);
</programlisting>
</example>
</para>
<para>
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.
</para>
<para>
<example>
<title>Sorting multi-dimensional array</title>
<programlisting role="php">
$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1));
array_multisort ($ar[0], SORT_ASC, SORT_STRING,
$ar[1], SORT_NUMERIC, SORT_DESC);
</programlisting>
</example>
</para>
<para>
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).
</para>
</refsect1>
</refentry>
<refentry id="function.array-pad">
<refnamediv>
<refname>array_pad</refname>
<refpurpose>
Pad array to the specified length with a value
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_pad</function></funcdef>
<paramdef>array <parameter>input</parameter></paramdef>
<paramdef>int <parameter>pad_size</parameter></paramdef>
<paramdef>mixed <parameter>pad_value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_pad</function> returns a copy of the
<parameter>input</parameter> padded to size specified by
<parameter>pad_size</parameter> with value
<parameter>pad_value</parameter>. If
<parameter>pad_size</parameter> is positive then the array is
padded on the right, if it's negative then on the left. If the
absolute value of <parameter>pad_size</parameter> is less than or
equal to the length of the <parameter>input</parameter> then no
padding takes place.
</para>
<para>
<example>
<title><function>Array_pad</function> example</title>
<programlisting role="php">
$input = array (12, 10, 9);
$result = array_pad ($input, 5, 0);
// result is array (12, 10, 9, 0, 0)
$result = array_pad ($input, -7, -1);
// result is array (-1, -1, -1, -1, 12, 10, 9)
$result = array_pad ($input, 2, "noop");
// not padded
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.array-pop">
<refnamediv>
<refname>array_pop</refname>
<refpurpose>Pop the element off the end of array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>array_pop</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_pop</function> pops and returns the last value of
the <parameter>array</parameter>, shortening the
<parameter>array</parameter> by one element.
</para>
<para>
<example>
<title><function>Array_pop</function> example</title>
<programlisting role="php">
$stack = array ("orange", "apple", "raspberry");
$fruit = array_pop ($stack);
</programlisting>
</example>
</para>
<para>
After this, <varname>$stack</varname> has only 2 elements:
"orange" and "apple", and <varname>$fruit</varname> has
"raspberry".
</para>
<para>
See also <function>array_push</function>,
<function>array_shift</function>, and
<function>array_unshift</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-push">
<refnamediv>
<refname>array_push</refname>
<refpurpose>
Push one or more elements onto the end of array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>array_push</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_push</function> treats
<parameter>array</parameter> as a stack, and pushes the passed
variables onto the end of <parameter>array</parameter>. The
length of <parameter>array</parameter> increases by the number of
variables pushed. Has the same effect as:
<programlisting role="php">
$array[] = $var;
</programlisting>
repeated for each <parameter>var</parameter>.
</para>
<para>
Returns the new number of elements in the array.
</para>
<para>
<example>
<title><function>Array_push</function> example</title>
<programlisting role="php">
$stack = array (1, 2);
array_push ($stack, "+", 3);
</programlisting>
</example>
</para>
<para>
This example would result in <varname>$stack</varname> having 4
elements: 1, 2, "+", and 3.
</para>
<para>
See also: <function>array_pop</function>,
<function>array_shift</function>, and
<function>array_unshift</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-rand">
<refnamediv>
<refname>array_rand</refname>
<refpurpose>
Pick one or more random entries out of an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>array_rand</function></funcdef>
<paramdef>array <parameter>input</parameter></paramdef>
<paramdef>int
<parameter><optional>num_req</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_rand</function> is rather useful when you want to
pick one or more random entries out of an array. It takes an
<parameter>input</parameter> array and an optional argument
<parameter>num_req</parameter> which specifies how many entries you
want to pick - if not specified, it defaults to 1.
</para>
<para>
If you are picking only one entry, <function>array_rand</function>
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.
</para>
<para>
Don't forget to call <function>srand</function> to seed the random
number generator.
</para>
<para>
<example>
<title><function>Array_rand</function> example</title>
<programlisting role="php">
srand ((double) microtime() * 10000000);
$input = array ("Neo", "Morpheus", "Trinity", "Cypher",
"Tank");
$rand_keys = array_rand ($input, 2);
print $input[$rand_keys[0]]."\n";
print $input[$rand_keys[1]]."\n";
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.array-reverse">
<refnamediv>
<refname>array_reverse</refname>
<refpurpose>
Return an array with elements in reverse order
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_reverse</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_reverse</function> takes input
<parameter>array</parameter> and returns a new array with the
order of the elements reversed.
</para>
<para>
<example>
<title><function>Array_reverse</function> example</title>
<programlisting role="php">
$input = array ("php", 4.0, array ("green", "red"));
$result = array_reverse ($input);
</programlisting>
</example>
</para>
<para>
This makes <varname>$result</varname> have <literal>array
(array ("green", "red"), 4.0, "php")</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-shift">
<refnamediv>
<refname>array_shift</refname>
<refpurpose>
Pop an element off the beginning of array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>array_shift</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_shift</function> shifts the first value of the
<parameter>array</parameter> off and returns it, shortening the
<parameter>array</parameter> by one element and moving everything
down.
</para>
<para>
<example>
<title><function>Array_shift</function> example</title>
<programlisting role="php">
$args = array ("-v", "-f");
$opt = array_shift ($args);
</programlisting>
</example>
</para>
<para>
This would result in <varname>$args</varname> having one element
"-f" left, and <varname>$opt</varname> being "-v".
</para>
<para>
See also <function>array_unshift</function>,
<function>array_push</function>, and
<function>array_pop</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-slice">
<refnamediv>
<refname>array_slice</refname>
<refpurpose>Extract a slice of the array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_slice</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>int <parameter>offset</parameter></paramdef>
<paramdef>int
<parameter>
<optional>length</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_slice</function> returns a sequence of elements
from the <parameter>array</parameter> specified by the
<parameter>offset</parameter> and <parameter>length</parameter>
parameters.
</para>
<para>
If <parameter>offset</parameter> is positive, the sequence will
start at that offset in the <parameter>array</parameter>. If
<parameter>offset</parameter> is negative, the sequence will
start that far from the end of the <parameter>array</parameter>.
</para>
<para>
If <parameter>length</parameter> is given and is positive, then
the sequence will have that many elements in it. If
<parameter>length</parameter> 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 <parameter>offset</parameter> up until the end of the
<parameter>array</parameter>.
</para>
<para>
<example>
<title><function>Array_slice</function> examples</title>
<programlisting role="php">
$input = array ("a", "b", "c", "d", "e");
$output = array_slice ($input, 2); // returns "c", "d", and "e"
$output = array_slice ($input, 2, -1); // returns "c", "d"
$output = array_slice ($input, -2, 1); // returns "d"
$output = array_slice ($input, 0, 3); // returns "a", "b", and "c"
</programlisting>
</example>
</para>
<para>
See also <function>array_splice</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-splice">
<refnamediv>
<refname>array_splice</refname>
<refpurpose>
Remove a portion of the array and replace it with something
else
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_splice</function></funcdef>
<paramdef>array <parameter>input</parameter></paramdef>
<paramdef>int <parameter>offset</parameter></paramdef>
<paramdef>int
<parameter><optional>length</optional></parameter>
</paramdef>
<paramdef>array
<parameter>
<optional>replacement</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_splice</function> removes the elements designated
by <parameter>offset</parameter> and
<parameter>length</parameter> from the
<parameter>input</parameter> array, and replaces them with the
elements of the <parameter>replacement</parameter> array, if
supplied.
</para>
<para>
If <parameter>offset</parameter> is positive then the start of
removed portion is at that offset from the beginning of the
<parameter>input</parameter> array. If
<parameter>offset</parameter> is negative then it starts that far
from the end of the <parameter>input</parameter> array.
</para>
<para>
If <parameter>length</parameter> is omitted, removes everything
from <parameter>offset</parameter> to the end of the array. If
<parameter>length</parameter> is specified and is positive, then
that many elements will be removed. If
<parameter>length</parameter> 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
<parameter>offset</parameter> to the end of the array when
<parameter>replacement</parameter> is also specified, use
<literal>count($input)</literal> for
<parameter>length</parameter>.
</para>
<para>
If <parameter>replacement</parameter> array is specified, then
the removed elements are replaced with elements from this array.
If <parameter>offset</parameter> and
<parameter>length</parameter> are such that nothing is removed,
then the elements from the <parameter>replacement</parameter>
array are inserted in the place specified by the
<parameter>offset</parameter>. Tip: if the replacement is just
one element it is not necessary to put <literal>array()</literal>
around it, unless the element is an array itself.
</para>
<para>
The following equivalences hold:
<programlisting>
array_push ($input, $x, $y) array_splice ($input, count ($input), 0,
array ($x, $y))
array_pop ($input) array_splice ($input, -1)
array_shift ($input) array_splice ($input, 0, 1)
array_unshift ($input, $x, $y) array_splice ($input, 0, 0, array ($x, $y))
$a[$x] = $y array_splice ($input, $x, 1, $y)
</programlisting>
</para>
<para>
Returns the array consisting of removed elements.
</para>
<para>
<example>
<title><function>Array_splice</function> examples</title>
<programlisting role="php">
$input = array ("red", "green", "blue", "yellow");
array_splice ($input, 2); // $input is now array ("red", "green")
array_splice ($input, 1, -1); // $input is now array ("red", "yellow")
array_splice ($input, 1, count($input), "orange");
// $input is now array ("red", "orange")
array_splice ($input, -1, 1, array("black", "maroon"));
// $input is now array ("red", "green",
// "blue", "black", "maroon")
</programlisting>
</example>
</para>
<para>
See also <function>array_slice</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-unique">
<refnamediv>
<refname>array_unique</refname>
<refpurpose>Removes duplicate values from an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_unique</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_unique</function> takes input
<parameter>array</parameter> and returns a new array
without duplicate values.
Note that keys are preserved.
</para>
<para>
<example>
<title><function>Array_unique</function> example</title>
<programlisting role="php">
$input = array ("a" => "green", "red", "b" =>
"green", "blue", "red");
$result = array_unique ($input);
</programlisting>
</example>
</para>
<para>
This makes <varname>$result</varname> have <literal>array ("a"
=>
"green", "red", "blue");</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-unshift">
<refnamediv>
<refname>array_unshift</refname>
<refpurpose>
Push one or more elements onto the beginning of array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>array_unshift</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
<paramdef>mixed
<parameter>
<optional>...</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_unshift</function> prepends passed elements to
the front of the <parameter>array</parameter>. Note that the list
of elements is prepended as a whole, so that the prepended
elements stay in the same order.
</para>
<para>
Returns the new number of elements in the
<parameter>array</parameter>.
</para>
<para>
<example>
<title><function>Array_unshift</function> example</title>
<programlisting role="php">
$queue = array ("p1", "p3");
array_unshift ($queue, "p4", "p5", "p6");
</programlisting>
</example>
</para>
<para>
This would result in <varname>$queue</varname> having 5
elements: "p4", "p5", "p6", "p1", and "p3".
</para>
<para>
See also <function>array_shift</function>,
<function>array_push</function>, and
<function>array_pop</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.array-values">
<refnamediv>
<refname>array_values</refname>
<refpurpose>Return all the values of an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>array_values</function></funcdef>
<paramdef>array <parameter>input</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Array_values</function> returns all the values from the
<parameter>input</parameter> array.
</para>
<para>
<example>
<title><function>Array_values</function> example</title>
<programlisting role="php">
$array = array ("size" => "XL", "color" =>
"gold");
array_values ($array); // returns array ("XL", "gold")
</programlisting>
</example>
</para>
<note>
<para>
This function was added to PHP 4, below is an implementation for
those still using PHP 3.
<example>
<title>
Implementation of <function>array_values</function> for PHP 3
users
</title>
<programlisting role="php">
function array_values ($arr) {
$t = array();
while (list($k, $v) = each ($arr)) {
$t[] = $v;
return $t;
}
}
</programlisting>
</example>
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.array-walk">
<refnamediv>
<refname>array_walk</refname>
<refpurpose>
Apply a user function to every member of an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>array_walk</function></funcdef>
<paramdef>array <parameter>arr</parameter></paramdef>
<paramdef>string <parameter>func</parameter></paramdef>
<paramdef>mixed <parameter>userdata</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Applies the function named by <parameter>func</parameter> to each
element of <parameter>arr</parameter>.
<parameter>func</parameter> will be passed array value as the
first parameter and array key as the second parameter. If
<parameter>userdata</parameter> is supplied, it will be passed as
the third parameter to the user function.
</simpara>
<simpara>
If <parameter>func</parameter> requires more than two or three
arguments, depending on <parameter>userdata</parameter>, a
warning will be generated each time
<function>array_walk</function> calls
<parameter>func</parameter>. These warnings may be suppressed by
prepending the '@' sign to the <function>array_walk</function>
call, or by using <function>error_reporting</function>.
</simpara>
<note>
<para>
If <parameter>func</parameter> needs to be working with the
actual values of the array, specify that the first parameter of
<parameter>func</parameter> should be passed by reference. Then
any changes made to those elements will be made in the array
itself.
</para>
</note>
<note>
<para>
Passing the key and userdata to <parameter>func</parameter> was
added in 4.0.
</para>
<para>
In PHP 4 <function>reset</function> needs to be called as
necessary since <function>array_walk</function> does not reset
the array by default.
</para>
</note>
<para>
<example>
<title><function>Array_walk</function> example</title>
<programlisting role="php">
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana", "c"=>"apple");
function test_alter (&$item1, $key, $prefix) {
$item1 = "$prefix: $item1";
}
function test_print ($item2, $key) {
echo "$key. $item2<br>\n";
}
array_walk ($fruits, 'test_print');
reset ($fruits);
array_walk ($fruits, 'test_alter', 'fruit');
reset ($fruits);
array_walk ($fruits, 'test_print');
</programlisting>
</example>
</para>
<simpara>
See also <function>each</function> and <function>list</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.arsort">
<refnamediv>
<refname>arsort</refname>
<refpurpose>
Sort an array in reverse order and maintain index association
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>arsort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>int
<parameter><optional>sort_flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function sorts an array such that array indices maintain
their correlation with the array elements they are associated
with. This is used mainly when sorting associative arrays where
the actual element order is significant.
<example>
<title><function>Arsort</function> example</title>
<programlisting role="php">
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana", "c"=>"apple");
arsort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key = $val\n";
}
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
fruits[a] = orange
fruits[d] = lemon
fruits[b] = banana
fruits[c] = apple
</programlisting>
</informalexample>
</para>
<para>
The fruits have been sorted in reverse alphabetical order, and
the index associated with each element has been maintained.
</para>
<para>
You may modify the behavior of the sort using the optional
parameter <parameter>sort_flags</parameter>, for details
see <function>sort</function>.
</para>
<para>
See also: <function>asort</function>, <function>rsort</function>,
<function>ksort</function>, and <function>sort</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.asort">
<refnamediv>
<refname>asort</refname>
<refpurpose>Sort an array and maintain index association</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>asort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>int
<parameter><optional>sort_flags</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function sorts an array such that array indices maintain
their correlation with the array elements they are associated
with. This is used mainly when sorting associative arrays where
the actual element order is significant.
<example>
<title><function>Asort</function> example</title>
<programlisting role="php">
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana", "c"=>"apple");
asort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key = $val\n";
}
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
fruits[c] = apple
fruits[b] = banana
fruits[d] = lemon
fruits[a] = orange
</programlisting>
</informalexample>
</para>
<para>
The fruits have been sorted in alphabetical order, and the index
associated with each element has been maintained.
</para>
<para>
You may modify the behavior of the sort using the optional
parameter <parameter>sort_flags</parameter>, for details
see <function>sort</function>.
</para>
<para>
See also <function>arsort</function>, <function>rsort</function>,
<function>ksort</function>, and <function>sort</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.compact">
<refnamediv>
<refname>compact</refname>
<refpurpose>
Create array containing variables and their values
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>compact</function></funcdef>
<paramdef>mixed <parameter>varname</parameter></paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Compact</function> 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;
<function>compact</function> handles it recursively.
</para>
<para>
For each of these, <function>compact</function> 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 <function>extract</function>.
It returns the output array with all the variables added to it.
</para>
<para>
<example>
<title><function>Compact</function> example</title>
<programlisting role="php">
$city = "San Francisco";
$state = "CA";
$event = "SIGGRAPH";
$location_vars = array ("city", "state");
$result = compact ("event", $location_vars);
</programlisting>
<para>
After this, <varname>$result</varname> will be <literal>array
("event"
=> "SIGGRAPH", "city" => "San Francisco",
"state" => "CA")</literal>.
</para>
</example>
</para>
<para>
See also <function>extract</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.count">
<refnamediv>
<refname>count</refname>
<refpurpose>Count elements in a variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>count</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of elements in <parameter>var</parameter>,
which is typically an array (since anything else will have one
element).
</para>
<para>
Returns 1 if the variable is not an array.
</para>
<para>
Returns 0 if the variable is not set.
<warning>
<para>
<function>Count</function> 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
<function>isset</function> to test if a variable is set.
</para>
</warning>
</para>
<para>
See also: <function>sizeof</function>,
<function>isset</function>, and
<function>is_array</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.current">
<refnamediv>
<refname>current</refname>
<refpurpose>Return the current element in an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>current</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Every array has an internal pointer to its "current" element,
which is initialized to the first element inserted into the
array.
</para>
<para>
The <function>current</function> function simply returns the
array element that's currently being pointed 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,
<function>current</function> returns false.
<warning>
<para>
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
<function>current</function>. To properly traverse an array
that may contain empty elements, use the
<function>each</function> function.
</para>
</warning>
</para>
<para>
See also: <function>end</function>, <function>next</function>,
<function>prev</function>, and <function>reset</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.each">
<refnamediv>
<refname>each</refname>
<refpurpose>
Return the next key and value pair from an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>each</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the current key and value pair from the array
<parameter>array</parameter> and advances the array cursor. This
pair is returned in a four-element array, with the keys
<emphasis>0</emphasis>, <emphasis>1</emphasis>,
<emphasis>key</emphasis>, and
<emphasis>value</emphasis>. Elements <emphasis>0</emphasis> and
<emphasis>key</emphasis> contain the key name of the array
element, and <emphasis>1</emphasis> and
<emphasis>value</emphasis> contain the data.
</para>
<para>
If the internal pointer for the array points past the end of the
array contents, <function>each</function> returns false.
</para>
<para>
<example>
<title><function>Each</function> examples</title>
<programlisting role="php">
$foo = array ("bob", "fred", "jussi", "jouni",
"egon", "marliese");
$bar = each ($foo);
</programlisting>
<para>
<varname>$bar</varname> now contains the following key/value
pairs:
<itemizedlist spacing="compact">
<listitem><simpara>0 => 0</simpara></listitem>
<listitem><simpara>1 => 'bob'</simpara></listitem>
<listitem><simpara>key => 0</simpara></listitem>
<listitem><simpara>value =>
'bob'</simpara></listitem>
</itemizedlist>
<programlisting role="php">
$foo = array ("Robert" => "Bob", "Seppo" =>
"Sepi");
$bar = each ($foo);
</programlisting>
</para>
<para>
<varname>$bar</varname> now contains the following key/value
pairs:
<itemizedlist spacing="compact">
<listitem><simpara>0 =>
'Robert'</simpara></listitem>
<listitem><simpara>1 => 'Bob'</simpara></listitem>
<listitem><simpara>key =>
'Robert'</simpara></listitem>
<listitem><simpara>value =>
'Bob'</simpara></listitem>
</itemizedlist>
</para>
</example>
</para>
<para>
<function>Each</function> is typically used in conjunction with
<function>list</function> to traverse an array; for instance,
<varname>$HTTP_POST_VARS</varname>:
<example>
<title>
Traversing <varname>$HTTP_POST_VARS</varname> with
<function>each</function>
</title>
<programlisting role="php">
echo "Values submitted via POST method:<br>";
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
echo "$key => $val<br>";
}
</programlisting>
</example>
</para>
<para>
After <function>each</function> has executed, the array cursor
will be left on the next element of the array, or on the last
element if it hits the end of the array.
</para>
<para>
See also <function>key</function>, <function>list</function>,
<function>current</function>, <function>reset</function>,
<function>next</function>, and <function>prev</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.end">
<refnamediv>
<refname>end</refname>
<refpurpose>
Set the internal pointer of an array to its last element
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>end</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>End</function> advances <parameter>array</parameter>'s
internal pointer to the last element, and returns that element.
</para>
<para>
See also: <function>current</function>,
<function>each</function>, <function>end</function>,
<function>next</function>, and <function>reset</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.extract">
<refnamediv>
<refname>extract</refname>
<refpurpose>
Import variables into the symbol table from an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>extract</function></funcdef>
<paramdef>array <parameter>var_array</parameter></paramdef>
<paramdef>int
<parameter><optional>extract_type</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>prefix</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is used to import variables from an array into the
current symbol table. It takes associative array
<parameter>var_array</parameter> 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
<parameter>extract_type</parameter> and
<parameter>prefix</parameter> parameters.
</para>
<para>
<function>Extract</function> checks for colissions with existing
variables. The way collisions are treated is determined by
<parameter>extract_type</parameter>. It can be one of the
following values:
<variablelist>
<varlistentry>
<term>EXTR_OVERWRITE</term>
<listitem>
<simpara>
If there is a collision, overwrite the existing variable.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>EXTR_SKIP</term>
<listitem>
<simpara>
If there is a collision, don't overwrite the existing
variable.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>EXTR_PREFIX_SAME</term>
<listitem>
<simpara>If there is a collision, prefix the new variable with
<parameter>prefix</parameter>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>EXTR_PREFIX_ALL</term>
<listitem>
<simpara>
Prefix all variables with <parameter>prefix</parameter>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If <parameter>extract_type</parameter> is not specified, it is
assumed to be EXTR_OVERWRITE.
</para>
<para>
Note that <parameter>prefix</parameter> is only required if
<parameter>extract_type</parameter> is EXTR_PREFIX_SAME or
EXTR_PREFIX_ALL.
</para>
<para>
<function>Extract</function> checks each key to see if it
constitues a valid variable name, and if it does only then does
it proceed to import it.
</para>
<para>
A possible use for extract is to import into symbol table
variables contained in an associative array returned by
<function>wddx_deserialize</function>.
</para>
<para>
<example>
<title><function>Extract</function> example</title>
<programlisting role="php">
<php?
/* Suppose that $var_array is an array returned from
wddx_deserialize */
$size = "large";
$var_array = array ("color" => "blue",
"size" => "medium",
"shape" => "sphere");
extract ($var_array, EXTR_PREFIX_SAME, "wddx");
print "$color, $size, $shape, $wddx_size\n";
?>
</programlisting>
</example>
</para>
<para>
The above example will produce:
<programlisting>
blue, large, sphere, medium
</programlisting>
</para>
<para>
The <varname>$size</varname> wasn't overwritten, becaus we
specified EXTR_PREFIX_SAME, which resulted in
<varname>$wddx_size</varname> being created. If EXTR_SKIP was
specified, then $wddx_size wouldn't even have been created.
EXTR_OVERWRITE would have cause <varname>$size</varname> to have
value "medium", and EXTR_PREFIX_ALL would result in new variables
being named <varname>$wddx_color</varname>,
<varname>$wddx_size</varname>, and
<varname>$wddx_shape</varname>.
</para>
</refsect1>
</refentry>
<refentry id="function.in-array">
<refnamediv>
<refname>in_array</refname>
<refpurpose>Return true if a value exists in an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool in_array</funcdef>
<paramdef>mixed <parameter>needle</parameter></paramdef>
<paramdef>array <parameter>haystack</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches <parameter>haystack</parameter> for
<parameter>needle</parameter> and returns true if it is found in
the array, false otherwise.
</para>
<para>
<example>
<title><function>In_array</function> example</title>
<programlisting role="php">
$os = array ("Mac", "NT", "Irix", "Linux");
if (in_array ("Irix", $os))
print "Got Irix";
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.key">
<refnamediv>
<refname>key</refname>
<refpurpose>Fetch a key from an associative array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>key</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Key</function> returns the index element of the
current array position.
</para>
<para>
See also <function>current</function> and <function>next</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.krsort">
<refnamediv>
<refname>krsort</refname>
<refpurpose>Sort an array by key in reverse order</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>krsort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>int
<parameter><optional>sort_flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sorts an array by key in reverse order, maintaining key to data
correlations. This is useful mainly for associative arrays.
<example>
<title><function>Krsort</function> example</title>
<programlisting role="php">
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana", "c"=>"apple");
krsort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key -> $val\n";
}
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
fruits[d] = lemon
fruits[c] = apple
fruits[b] = banana
fruits[a] = orange
</programlisting>
</informalexample>
</para>
<para>
You may modify the behavior of the sort using the optional
parameter <parameter>sort_flags</parameter>, for details
see <function>sort</function>.
</para>
<simpara>
See also <function>asort</function>, <function>arsort</function>,
<function>ksort</function> <function>sort</function>,
<function>natsort</function>and <function>rsort</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ksort">
<refnamediv>
<refname>ksort</refname>
<refpurpose>Sort an array by key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ksort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>int
<parameter><optional>sort_flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sorts an array by key, maintaining key to data correlations. This
is useful mainly for associative arrays.
<example>
<title><function>Ksort</function> example</title>
<programlisting role="php">
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana", "c"=>"apple");
ksort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key -> $val\n";
}
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
fruits[a] = orange
fruits[b] = banana
fruits[c] = apple
fruits[d] = lemon
</programlisting>
</informalexample>
</para>
<para>
You may modify the behavior of the sort using the optional
parameter <parameter>sort_flags</parameter>, for details
see <function>sort</function>.
</para>
<simpara>
See also <function>asort</function>, <function>arsort</function>,
<function>sort</function>, <function>natsort</function>, and
<function>rsort</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.list">
<refnamediv>
<refname>list</refname>
<refpurpose>
Assign variables as if they were an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>list</function></funcdef>
<varargs/>
</funcprototype>
</funcsynopsis>
<para>
Like <function>array</function>, this is not really a function,
but a language construct. <function>list</function> is used to
assign a list of variables in one operation.
<example>
<title><function>List</function> example</title>
<programlisting role="php">
<table>
<tr>
<th>Employee name</th>
<th>Salary</th>
</tr>
<?php
$result = mysql ($conn, "SELECT id, name, salary FROM employees");
while (list ($id, $name, $salary) = mysql_fetch_row ($result)) {
print (" <tr>\n".
" <td><a
href=\"info.php3?id=$id\">$name</a></td>\n".
" <td>$salary</td>\n".
" </tr>\n");
}
?>
</table>
</programlisting>
</example>
</para>
<para>
See also <function>each</function> and <function>array</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.natsort">
<refnamediv>
<refname>natsort</refname>
<refpurpose>
Sort an array using a "natural order" algorithm
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>natsort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function implements a sort algorithm that orders
alphanumeric strings in the way a human being would. This is
described as a "natural ordering". An example of the difference
between this algorithm and the regular computer string sorting
algorithms (used in <function>sort</function>) can be seen below:
</para>
<para>
<example>
<title><function>natsort</function> example</title>
<programlisting role="php">
$array1 = $array2 = array
("img12.png","img10.png","img2.png","img1.png");
sort($array1);
echo "Standard sorting\n";
print_r($array1);
natsort($array2);
echo "\nNatural order sorting\n";
print_r($array2);
</programlisting>
</example>
</para>
<para>
The code above will generate the following output:
</para>
<para>
<informalexample>
<programlisting>
Standard sorting
Array
(
[0] => img1.png
[1] => img10.png
[2] => img12.png
[3] => img2.png
)
Natural order sorting
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)
</programlisting>
</informalexample>
For more infomation see: Martin Pool's <ulink
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
page.
</para>
<para>
See also <function>natcasesort</function>,
<function>strnatcmp</function> and
<function>strnatcasecmp</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.natcasesort">
<refnamediv>
<refname>natcasesort</refname>
<refpurpose>
Sort an array using a case insensitive "natural order" algorithm
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>natcasesort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function implements a sort algorithm that orders
alphanumeric strings in the way a human being would. This is
described as a "natural ordering".
</para>
<para>
<function>natcasesort</function> is a case insensitive version of
<function>natsort</function>. See <function>natsort</function>
for an example of the difference between this algorithm and the
regular computer string sorting algorithms.
</para>
<para>
For more infomation see: Martin Pool's <ulink
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
page.
</para>
<para>
See also <function>sort</function>,
<function>natsort</function>,
<function>strnatcmp</function> and
<function>strnatcasecmp</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.next">
<refnamediv>
<refname>next</refname>
<refpurpose>
Advance the internal array pointer of an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>next</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the array element in the next place that's pointed by the
internal array pointer, or false if there are no more elements.
</para>
<para>
<function>Next</function> behaves like
<function>current</function>, with one difference. It advances
the internal array pointer one place forward before returning the
element. That means it returns the next array element and
advances the internal array pointer by one. If advancing the
internal array pointer results in going beyond the end of the
element list, <function>next</function> returns false.
<warning>
<para>
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
<function>each</function> function.
</para>
</warning>
</para>
<para>
See also:
<function>current</function>, <function>end</function>,
<function>prev</function>, and <function>reset</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pos">
<refnamediv>
<refname>pos</refname>
<refpurpose>Get the current element from an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>pos</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This is an alias for <function>current</function>.
</simpara>
<para>
See also:
<function>end</function>, <function>next</function>,
<function>prev</function> and <function>reset</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.prev">
<refnamediv>
<refname>prev</refname>
<refpurpose>Rewind the internal array pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>prev</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the array element in the previous place that's pointed by
the internal array pointer, or false if there are no more
elements.
<warning>
<para>
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
<function>each</function> function.
</para>
</warning>
</para>
<para>
<function>Prev</function> behaves just like
<function>next</function>, except it rewinds the internal array
pointer one place instead of advancing it.
</para>
<para>
See also: <function>current</function>, <function>end</function>,
<function>next</function>, and <function>reset</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.range">
<refnamediv>
<refname>range</refname>
<refpurpose>
Create an array containing a range of integers
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>range</function></funcdef>
<paramdef>int <parameter>low</parameter></paramdef>
<paramdef>int <parameter>high</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Range</function> returns an array of integers from
<parameter>low</parameter> to <parameter>high</parameter>,
inclusive.
</para>
<para>
See <function>shuffle</function> for an example of its use.
</para>
</refsect1>
</refentry>
<refentry id="function.reset">
<refnamediv>
<refname>reset</refname>
<refpurpose>
Set the internal pointer of an array to its first element
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>reset</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Reset</function> rewinds <parameter>array</parameter>'s
internal pointer to the first element.
</para>
<para>
<function>Reset</function> returns the value of the first array
element.
</para>
<para>
See also: <function>current</function>,
<function>each</function>, <function>next</function>,
and <function>prev</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.rsort">
<refnamediv>
<refname>rsort</refname>
<refpurpose>Sort an array in reverse order</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>rsort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>int
<parameter><optional>sort_flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function sorts an array in reverse order (highest to lowest).
<example>
<title><function>Rsort</function> example</title>
<programlisting role="php">
$fruits = array ("lemon", "orange", "banana", "apple");
rsort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key -> $val\n";
}
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
fruits[0] = orange
fruits[1] = lemon
fruits[2] = banana
fruits[3] = apple
</programlisting>
</informalexample>
</para>
<para>
The fruits have been sorted in reverse alphabetical order.
</para>
<para>
You may modify the behavior of the sort using the optional
parameter <parameter>sort_flags</parameter>, for details
see <function>sort</function>.
</para>
<para>
See also: <function>arsort</function>,
<function>asort</function>, <function>ksort</function>,
<function>sort</function>, and <function>usort</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.shuffle">
<refnamediv>
<refname>shuffle</refname>
<refpurpose>Shuffle an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>shuffle</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function shuffles (randomizes the order of the elements in)
an array.
<example>
<title><function>Shuffle</function> example</title>
<programlisting role="php">
$numbers = range (1,20);
srand (time());
shuffle ($numbers);
while (list (, $number) = each ($numbers)) {
echo "$number ";
}
</programlisting>
</example>
</para>
<para>
See also <function>arsort</function>, <function>asort</function>,
<function>ksort</function>, <function>rsort</function>,
<function>sort</function> and <function>usort</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sizeof">
<refnamediv>
<refname>sizeof</refname>
<refpurpose>Get the number of elements in an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sizeof</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of elements in the array.
</para>
<para>
See also <function>count</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sort">
<refnamediv>
<refname>sort</refname>
<refpurpose>Sort an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>sort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>int
<parameter><optional>sort_flags</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function sorts an array. Elements will be arranged from
lowest to highest when this function has completed.
<example>
<title><function>Sort</function> example</title>
<programlisting role="php">
<?php
$fruits = array ("lemon", "orange", "banana", "apple");
sort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "fruits[".$key."] = ".$val;
}
?>
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
</programlisting>
</informalexample>
</para>
<para>
The fruits have been sorted in alphabetical order.
</para>
<para>
The optional second parameter <parameter>sort_flags</parameter>
may be used to modify the sorting behavior using theese valies:
</para>
<para>
Sorting type flags:
<itemizedlist>
<listitem>
<simpara>SORT_REGULAR - compare items normally</simpara>
</listitem>
<listitem>
<simpara>SORT_NUMERIC - compare items numerically</simpara>
</listitem>
<listitem>
<simpara>SORT_STRING - compare items as strings</simpara>
</listitem>
</itemizedlist>
</para>
<para>
See also: <function>arsort</function>,
<function>asort</function>, <function>ksort</function>,
<function>natsort</function>, <function>natcasesort</function>,
<function>rsort</function>, <function>usort</function>
and <function>uksort</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.uasort">
<refnamediv>
<refname>uasort</refname>
<refpurpose>
Sort an array with a user-defined comparison function and
maintain index association
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>uasort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>function <parameter>cmp_function</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function sorts an array such that array indices maintain
their correlation with the array elements they are associated
with. This is used mainly when sorting associative arrays where
the actual element order is significant. The comparison function
is user-defined.
</para>
<note>
<para>
Please see <function>usort</function> and
<function>uksort</function> for examples of user-defined
comparison functions.
</para>
</note>
<para>
See also: <function>usort</function>, <function>uksort</function>,
<function>sort</function>, <function>asort</function>,
<function>arsort</function>, <function>ksort</function>
and <function>rsort</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.uksort">
<refnamediv>
<refname>uksort</refname>
<refpurpose>
Sort an array by keys using a user-defined comparison function
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>uksort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>function <parameter>cmp_function</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function will sort the keys of an array using a
user-supplied comparison function. If the array you wish to sort
needs to be sorted by some non-trivial criteria, you should use
this function.
</para>
<para>
<example>
<title><function>Uksort</function> example</title>
<programlisting role="php">
function cmp ($a, $b) {
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
$a = array (4 => "four", 3 => "three", 20 =>
"twenty", 10 => "ten");
uksort ($a, "cmp");
while (list ($key, $value) = each ($a)) {
echo "$key: $value\n";
}
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
20: twenty
10: ten
4: four
3: three
</programlisting>
</informalexample>
</para>
<para>
See also: <function>usort</function>, <function>uasort</function>,
<function>sort</function>, <function>asort</function>,
<function>arsort</function>, <function>ksort</function>,
<function>natsort</function> and <function>rsort</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.usort">
<refnamediv>
<refname>usort</refname>
<refpurpose>
Sort an array by values using a user-defined comparison function
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>usort</function></funcdef>
<paramdef>array <parameter>array</parameter></paramdef>
<paramdef>string <parameter>cmp_function</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function will sort an array by its values using a
user-supplied comparison function. If the array you wish to sort
needs to be sorted by some non-trivial criteria, you should use
this function.
</para>
<para>
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.
</para>
<para>
<example>
<title><function>Usort</function> example</title>
<programlisting role="php">
function cmp ($a, $b) {
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
$a = array (3, 2, 5, 6, 1);
usort ($a, "cmp");
while (list ($key, $value) = each ($a)) {
echo "$key: $value\n";
}
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
0: 6
1: 5
2: 3
3: 2
4: 1
</programlisting>
</informalexample>
</para>
<note>
<para>
Obviously in this trivial case the <function>rsort</function>
function would be more appropriate.
</para>
</note>
<para>
<example>
<title>
<function>Usort</function> example using multi-dimensional array
</title>
<programlisting role="php">
function cmp ($a, $b) {
return strcmp($a["fruit"],$b["fruit"]);
}
$fruits[0]["fruit"] = "lemons";
$fruits[1]["fruit"] = "apples";
$fruits[2]["fruit"] = "grapes";
usort($fruits, "cmp");
while (list ($key, $value) = each ($fruits)) {
echo "\$fruits[$key]: " . $value["fruit"] . "\n";
}
</programlisting>
</example>
</para>
<para>
When sorting a multi-dimensional array, $a and $b contain
references to the first index of the array.
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
$fruits[0]: apples
$fruits[1]: grapes
$fruits[2]: lemons
</programlisting>
</informalexample>
</para>
<para>
<warning>
<para>
The underlying quicksort function in some C libraries (such as
on Solaris systems) may cause PHP to crash if the comparison
function does not return consistent values.
</para>
</warning>
</para>
<para>
See also: <function>uasort</function>, <function>uksort</function>,
<function>sort</function>, <function>asort</function>,
<function>arsort</function>,<function>ksort</function>,
<function>natsort</function>, and <function>rsort</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/aspell.xml
+++ phpdoc/nl/functions/aspell.xml
<reference id="ref.aspell">
<title>Aspell functions</title>
<titleabbrev>Aspell</titleabbrev>
<partintro>
<simpara>
The <function>aspell</function> functions allows you to check the
spelling on a word and offer suggestions.
</simpara>
<note>
<simpara>
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. If you want to use
spell-checking capabilities in php, use <link
linkend="ref.pspell">pspell</link> instead. It uses pspell
library and works with newer versions of aspell.
</simpara>
</note>
<simpara>
You need the aspell library, available from: <ulink
url="&url.aspell;">&url.aspell;</ulink>.
</simpara>
</partintro>
<refentry id="function.aspell-new">
<refnamediv>
<refname>aspell_new</refname>
<refpurpose>Load a new dictionary</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>aspell_new</function></funcdef>
<paramdef>string <parameter>master</parameter></paramdef>
<paramdef>string <parameter>personal</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Aspell_new</function> opens up a new dictionary and
returns the dictionary link identifier for use in other aspell
functions.</simpara>
<para>
<example>
<title><function>Aspell_new</function></title>
<programlisting role="php">
$aspell_link=aspell_new ("english");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.aspell-check">
<refnamediv>
<refname>aspell_check</refname>
<refpurpose>Check a word</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>aspell_check</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>word</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Aspell_check</function> checks the spelling of a word
and returns true if the spelling is correct, false if not.
</simpara>
<para>
<example>
<title><function>Aspell_check</function></title>
<programlisting>
$aspell_link=aspell_new ("english");
if (aspell_check ($aspell_link, "testt")) {
echo "This is a valid spelling";
} else {
echo "Sorry, wrong spelling";
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.aspell-check-raw">
<refnamediv>
<refname>aspell_check_raw</refname>
<refpurpose>
Check a word without changing its case or trying to trim it
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>aspell_check_raw</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>word</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Aspell_check_raw</function> 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.
</simpara>
<para>
<example>
<title><function>Aspell_check_raw</function></title>
<programlisting role="php">
$aspell_link=aspell_new ("english");
if (aspell_check_raw ($aspell_link, "test")) {
echo "This is a valid spelling";
} else {
echo "Sorry, wrong spelling";
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.aspell-suggest">
<refnamediv>
<refname>aspell_suggest</refname>
<refpurpose>Suggest spellings of a word</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>aspell_suggest</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>word</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Aspell_suggest</function> returns an array of possible
spellings for the given word.
</simpara>
<para>
<example>
<title><function>Aspell_suggest</function></title>
<programlisting role="php">
$aspell_link=aspell_new ("english");
if (!aspell_check ($aspell_link, "test")) {
$suggestions=aspell_suggest ($aspell_link, "test");
for ($i=0; $i < count ($suggestions); $i++) {
echo "Possible spelling: " . $suggestions[$i] . "<br>";
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/bc.xml
+++ phpdoc/nl/functions/bc.xml
<reference id="ref.bc">
<title>BCMath Arbitrary Precision Mathematics Functions</title>
<titleabbrev>BC math</titleabbrev>
<partintro>
<para>
These functions are only available if PHP was configured with
<option role="configure">--enable-bcmath</option>.
</para>
<note>
<para>
Due to changes in the licensing, the BCMATH library is distributed
separate from the standard PHP source distribution.
You can download the tar-gzipped archive at the url:
<ulink url="&url.bcmath;">&url.bcmath;</ulink>. Read the
file <filename>README.BCMATH</filename> in the PHP distribution
for more information.
</para>
</note>
</partintro>
<refentry id="function.bcadd">
<refnamediv>
<refname>bcadd</refname>
<refpurpose>Add two arbitrary precision numbers</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcadd</function></funcdef>
<paramdef>string <parameter>left operand</parameter></paramdef>
<paramdef>string <parameter>right operand</parameter></paramdef>
<paramdef>int
<parameter><optional>scale</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Adds the <parameter>left operand</parameter> to the
<parameter>right operand</parameter> and returns the sum in a
string. The optional <parameter>scale</parameter> parameter is
used to set the number of digits after the decimal place in the
result.
</para>
<para>
See also <function>bcsub</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bccomp">
<refnamediv>
<refname>bccomp</refname>
<refpurpose>Compare two arbitrary precision numbers</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>bccomp</function></funcdef>
<paramdef>string <parameter>left operand</parameter></paramdef>
<paramdef>string <parameter>right operand</parameter></paramdef>
<paramdef>int
<parameter><optional>scale</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Compares the <parameter>left operand</parameter> to the
<parameter>right operand</parameter> and returns the result as an
integer. The optional <parameter>scale</parameter> parameter is
used to set the number of digits after the decimal place which
will be used in the comparion. The return value is 0 if the two
operands are equal. If the <parameter>left operand</parameter>
is larger than the <parameter>right operand</parameter> the
return value is +1 and if the <parameter>left operand</parameter>
is less than the <parameter>right operand</parameter> the return
value is -1.
</para>
</refsect1>
</refentry>
<refentry id="function.bcdiv">
<refnamediv>
<refname>bcdiv</refname>
<refpurpose>Divide two arbitrary precision numbers</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcdiv</function></funcdef>
<paramdef>string <parameter>left operand</parameter></paramdef>
<paramdef>string <parameter>right operand</parameter></paramdef>
<paramdef>int
<parameter><optional>scale</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Divides the <parameter>left operand</parameter> by the
<parameter>right operand</parameter> and returns the result. The
optional <parameter>scale</parameter> sets the number of digits
after the decimal place in the result.
</para>
<para>
See also <function>bcmul</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bcmod">
<refnamediv>
<refname>bcmod</refname>
<refpurpose>
Get modulus of an arbitrary precision number
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcmod</function></funcdef>
<paramdef>string <parameter>left operand</parameter></paramdef>
<paramdef>string <parameter>modulus</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Get the modulus of the <parameter>left operand</parameter> using
<parameter>modulus</parameter>.
</para>
<para>
See also <function>bcdiv</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bcmul">
<refnamediv>
<refname>bcmul</refname>
<refpurpose>Multiply two arbitrary precision number</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcmul</function></funcdef>
<paramdef>string <parameter>left operand</parameter></paramdef>
<paramdef>string <parameter>right operand</parameter></paramdef>
<paramdef>int
<parameter><optional>scale</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Multiply the <parameter>left operand</parameter> by the
<parameter>right operand</parameter> and returns the result. The
optional <parameter>scale</parameter> sets the number of digits
after the decimal place in the result.
</para>
<para>
See also <function>bcdiv</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bcpow">
<refnamediv>
<refname>bcpow</refname>
<refpurpose>
Raise an arbitrary precision number to another
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcpow</function></funcdef>
<paramdef>string <parameter>x</parameter></paramdef>
<paramdef>string <parameter>y</parameter></paramdef>
<paramdef>int
<parameter><optional>scale</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Raise <parameter>x</parameter> to the power
<parameter>y</parameter>. The optional
<parameter>scale</parameter> can be used to set the number of
digits after the decimal place in the result.
</para>
<para>
See also <function>bcsqrt</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bcscale">
<refnamediv>
<refname>bcscale</refname>
<refpurpose>
Set default scale parameter for all bc math functions
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcscale</function></funcdef>
<paramdef>int <parameter>scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function sets the default scale parameter for all subsequent
bc math functions that do not explicitly specify a scale
parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.bcsqrt">
<refnamediv>
<refname>bcsqrt</refname>
<refpurpose>
Get the square root of an arbitray precision number
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcsqrt</function></funcdef>
<paramdef>string <parameter>operand</parameter></paramdef>
<paramdef>int <parameter>scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the square root of the <parameter>operand</parameter>.
The optional <parameter>scale</parameter> parameter sets the
number of digits after the decimal place in the result.
</para>
<para>
See also <function>bcpow</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bcsub">
<refnamediv>
<refname>bcsub</refname>
<refpurpose>
Subtract one arbitrary precision number from another
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bcsub</function></funcdef>
<paramdef>string <parameter>left operand</parameter></paramdef>
<paramdef>string <parameter>right operand</parameter></paramdef>
<paramdef>int
<parameter><optional>scale</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Subtracts the <parameter>right operand</parameter> from the
<parameter>left operand</parameter> and returns the result in a
string. The optional <parameter>scale</parameter> parameter is
used to set the number of digits after the decimal place in the
result.
</para>
<para>
See also <function>bcadd</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/calendar.xml
+++ phpdoc/nl/functions/calendar.xml
<reference id="ref.calendar">
<title>Calendar functions</title>
<titleabbrev>Calendar</titleabbrev>
<partintro>
<para>
The calendar functions are only available if you have compiled
the calendar extension, found in either the "dl" or "ext"
subdirectories of your PHP source code.
Please see the README file before using it.
</para>
<para>
The calendar extension presents a series of functions to simplify
converting between different calendar formats. The intermediary
or standard it is based on is the Julian Day Count. The Julian
Day Count is a count of days starting way earlier than any date
most people would need to track (somewhere around 4000bc). To
convert between calendar systems, you must first convert to Julian
Day Count, then to the calendar system of your choice. Julian Day
Count is very different from the Julian Calendar! For more
information on calendar systems visit <ulink
url="&url.calendar;">&url.calendar;</ulink>. Excerpts from this
page are included in these instructions, and are in quotes.
</para>
</partintro>
<refentry id="function.jdtogregorian">
<refnamediv>
<refname>JDToGregorian</refname>
<refpurpose>Converts Julian Day Count to Gregorian date</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>jdtogregorian</function></funcdef>
<paramdef>int <parameter>julianday</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts Julian Day Count to a string containing the Gregorian
date in the format of "month/day/year".
</para>
</refsect1>
</refentry>
<refentry id="function.gregoriantojd">
<refnamediv>
<refname>GregorianToJD</refname>
<refpurpose>
Converts a Gregorian date to Julian Day Count
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gregoriantojd</function></funcdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Valid Range for Gregorian Calendar 4714 B.C. to 9999 A.D.</para>
<para>
Although this software can handle dates all the way back to 4714
B.C., such use may not be meaningful. The Gregorian calendar was
not instituted until October 15, 1582 (or October 5, 1582 in the
Julian calendar). Some countries did not accept it until much
later. For example, Britain converted in 1752, The USSR in 1918
and Greece in 1923. Most European countries used the Julian
calendar prior to the Gregorian.
<example>
<title>Calendar functions</title>
<programlisting role="php">
<?php
$jd = GregorianToJD (10,11,1970);
echo "$jd\n";
$gregorian = JDToGregorian ($jd);
echo "$gregorian\n";
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.jdtojulian">
<refnamediv>
<refname>JDToJulian</refname>
<refpurpose>
Converts a Julian Day Count to a Julian Calendar Date
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>jdtojulian</function></funcdef>
<paramdef>int <parameter>julianday</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts Julian Day Count to a string containing the Julian
Calendar Date in the format of "month/day/year".
</para>
</refsect1>
</refentry>
<refentry id="function.juliantojd">
<refnamediv>
<refname>JulianToJD</refname>
<refpurpose>
Converts a Julian Calendar date to Julian Day Count
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>juliantojd</function></funcdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Valid Range for Julian Calendar 4713 B.C. to 9999 A.D.
</para>
<para>
Although this software can handle dates all the way back to 4713
B.C., such use may not be meaningful. The calendar was created in
46 B.C., but the details did not stabilize until at least 8 A.D.,
and perhaps as late at the 4th century. Also, the beginning of a
year varied from one culture to another - not all accepted
January as the first month.
</para>
</refsect1>
</refentry>
<refentry id="function.jdtojewish">
<refnamediv>
<refname>JDToJewish</refname>
<refpurpose>
Converts a Julian Day Count to the Jewish Calendar
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>jdtojewish</function></funcdef>
<paramdef>int <parameter>julianday</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts a Julian Day Count the the Jewish Calendar.
</para>
</refsect1>
</refentry>
<refentry id="function.jewishtojd">
<refnamediv>
<refname>JewishToJD</refname>
<refpurpose>
Converts a date in the Jewish Calendar to Julian Day Count
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>jewishtojd</function></funcdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Valid Range Although this software can handle dates all the way
back to the year 1 (3761 B.C.), such use may not be meaningful.
</para>
<para>
The Jewish calendar has been in use for several thousand years,
but in the early days there was no formula to determine the start
of a month. A new month was started when the new moon was first
observed.
</para>
</refsect1>
</refentry>
<refentry id="function.jdtofrench">
<refnamediv>
<refname>JDToFrench</refname>
<refpurpose>
Converts a Julian Day Count to the French Republican Calendar
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>jdtofrench</function></funcdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts a Julian Day Count to the French Republican Calendar.
</para>
</refsect1>
</refentry>
<refentry id="function.frenchtojd">
<refnamediv>
<refname>FrenchToJD</refname>
<refpurpose>
Converts a date from the French Republican Calendar to a Julian
Day Count
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>frenchtojd</function></funcdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts a date from the French Republican Calendar to a Julian
Day Count.
</para>
<para>
These routines only convert dates in years 1 through 14
(Gregorian dates 22 September 1792 through 22 September
1806). This more than covers the period when the calendar was in
use.
</para>
</refsect1>
</refentry>
<refentry id="function.jdmonthname">
<refnamediv>
<refname>JDMonthName</refname>
<refpurpose>Returns a month name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>jdmonthname</function></funcdef>
<paramdef>int <parameter>julianday</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a month name.
<parameter>mode</parameter> tells this function which calendar to
convert the Julian Day Count to, and what type of month names are
to be returned.
<table>
<title>Calendar modes</title>
<tgroup cols="2">
<thead>
<row>
<entry>Mode</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry>0</entry>
<entry>Gregorian - abbreviated</entry>
</row>
<row>
<entry>1</entry>
<entry>Gregorian</entry>
</row>
<row>
<entry>2</entry>
<entry>Julian - abbreviated</entry>
</row>
<row>
<entry>3</entry>
<entry>Julian</entry>
</row>
<row>
<entry>4</entry>
<entry>Jewish</entry>
</row>
<row>
<entry>5</entry>
<entry>French Republican</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</refsect1>
</refentry>
<refentry id="function.jddayofweek">
<refnamediv>
<refname>JDDayOfWeek</refname>
<refpurpose>Returns the day of the week</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>jddayofweek</function></funcdef>
<paramdef>int <parameter>julianday</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the day of the week. Can return a string or an int
depending on the mode.
<table>
<title>Calendar week modes</title>
<tgroup cols="2">
<thead>
<row>
<entry>Mode</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry>0</entry>
<entry>
Returns the day number as an int (0=sunday, 1=monday, etc)
</entry>
</row>
<row>
<entry>1</entry>
<entry>
Returns string containing the day of week
(english-gregorian)
</entry>
</row>
<row>
<entry>2</entry>
<entry>
Returns a string containing the abbreviated day of week
(english-gregorian)
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</refsect1>
</refentry>
<refentry id="function.easter-date">
<refnamediv>
<refname>easter_date</refname>
<refpurpose>
Get UNIX timestamp for midnight on Easter of a given year
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>easter_date</function></funcdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the UNIX timestamp corresponding to midnight on Easter of
the given year. If no year is specified, the current year is
assumed.
</para>
<para>
<emphasis>Warning:</emphasis> This function will generate
a warning if the year is outside of the range for UNIX
timestamps (i.e. before 1970 or after 2037).
<example>
<title><function>easter_date</function> example</title>
<programlisting role="php">
echo date ("M-d-Y", easter_date(1999)); /* "Apr-04-1999" */
echo date ("M-d-Y", easter_date(2000)); /* "Apr-23-2000" */
echo date ("M-d-Y", easter_date(2001)); /* "Apr-15-2001" */
</programlisting>
</example>
</para>
<para>
The date of Easter Day was defined by the Council of Nicaea in
AD325 as the Sunday after the first full moon which falls on or
after the Spring Equinox. The Equinox is assumed to always fall
on 21st March, so the calculation reduces to determining the date
of the full moon and the date of the following Sunday. The
algorithm used here was introduced around the year 532 by
Dionysius Exiguus. Under the Julian Calendar (for years before
1753) a simple 19-year cycle is used to track the phases of the
Moon. Under the Gregorian Calendar (for years after 1753 -
devised by Clavius and Lilius, and introduced by Pope Gregory
XIII in October 1582, and into Britain and its then colonies in
September 1752) two correction factors are added to make the
cycle more accurate.
</para>
<para>
(The code is based on a C program by Simon Kershaw,
<webmaster@ely.anglican.org>)
</para>
<para>
See <function>easter_days</function> for calculating Easter
before 1970 or after 2037.
</para>
</refsect1>
</refentry>
<refentry id="function.easter-days">
<refnamediv>
<refname>easter_days</refname>
<refpurpose>
Get number of days after March 21 on which Easter falls for a
given year
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>easter_days</function></funcdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of days after March 21 on which Easter falls
for a given year. If no year is specified, the current year is
assumed.
</para>
<para>
This function can be used instead of
<function>easter_date</function> to calculate Easter for years
which fall outside the range of UNIX timestamps (i.e. before 1970
or after 2037).
<example>
<title><function>Easter_date</function> example</title>
<programlisting role="php">
echo easter_days (1999); /* 14, i.e. April 4 */
echo easter_days (1492); /* 32, i.e. April 22 */
echo easter_days (1913); /* 2, i.e. March 23 */
</programlisting>
</example>
</para>
<para>
The date of Easter Day was defined by the Council of Nicaea in
AD325 as the Sunday after the first full moon which falls on or
after the Spring Equinox. The Equinox is assumed to always fall
on 21st March, so the calculation reduces to determining the date
of the full moon and the date of the following Sunday. The
algorithm used here was introduced around the year 532 by
Dionysius Exiguus. Under the Julian Calendar (for years before
1753) a simple 19-year cycle is used to track the phases of the
Moon. Under the Gregorian Calendar (for years after 1753 -
devised by Clavius and Lilius, and introduced by Pope Gregory
XIII in October 1582, and into Britain and its then colonies in
September 1752) two correction factors are added to make the
cycle more accurate.
</para>
<para>
(The code is based on a C program by Simon Kershaw,
<webmaster@ely.anglican.org>)
</para>
<para>
See also <function>easter_date</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.unixtojd">
<refnamediv>
<refname>unixtojd</refname>
<refpurpose>Convert UNIX timestamp to Julian Day</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>unixtojd</function></funcdef>
<paramdef>int
<parameter><optional>timestamp</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the Julian Day for a UNIX <parameter>timestamp</parameter>
(seconds since 1.1.1970), or for the current day if no
<parameter>timestamp</parameter> is given.
</para>
<para>
See also <function>jdtounix</function>.
</para>
<note>
<para>
This function is only available in PHP versions after PHP4RC1.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.jdtounix">
<refnamediv>
<refname>jdtounix</refname>
<refpurpose>Convert Julian Day to UNIX timestamp</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>jdtounix</function></funcdef>
<paramdef>int <parameter>jday</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function will return a UNIX timestamp corresponding to the
Julian Day given in <parameter>jday</parameter> or false if
<parameter>jday</parameter> is not inside the UNIX epoch
(Gregorian years between 1970 and 2037 or 2440588 <=
<parameter>jday</parameter> <= 2465342 )
</para>
<para>
See also <function>jdtounix</function>.
</para>
<note>
<para>
This function is only available in PHP versions after PHP4RC1.
</para>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/ccvs.xml
+++ phpdoc/nl/functions/ccvs.xml
<!--
CCVS Documentation by Brendan W. McAdams <brendan@plexmedia.com>
Copyright (c) 2000 by the PHP Group
-Special Thanks to RedHat, Inc. for the contribution of their original
documentation for the php3 version of this module, which helped us
start this document.
-->
<reference id="ref.ccvs">
<title>CCVS API Functions</title>
<titleabbrev>CCVS</titleabbrev>
<partintro>
<simpara>
These functions interface the CCVS API, allowing you to directly
work with CCVS from your PHP scripts. CCVS is <ulink
url="&url.redhat;">RedHat's</ulink> 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.
</simpara>
<simpara>
To enable CCVS Support in PHP, first verify your CCVS installation
directory. You will then need to configure PHP with the <option
role="configure">--with-ccvs</option> 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: <option
role="configure">--with-ccvs=$ccvs_path</option>, where $ccvs_path
is the path to your CCVS installation. Please note that CCVS
support requires that $ccvs_path/lib and $ccvs_path/include exist,
and include cv_api.h under the include directory and libccvs.a
under the lib directory.
</simpara>
<simpara>
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.)
</simpara>
<simpara>
Additional information about CCVS can be found at <ulink
url="&url.redhat.ccvs;">&url.redhat.ccvs;</ulink>.
</simpara>
<simpara>
This documentation section is being worked on. Until then, RedHat
maintains slightly outdated but still useful documentation at
<ulink url="&url.redhat.support;">&url.redhat.support;</ulink>.
</simpara>
</partintro>
<refentry>
<refnamediv>
<refname></refname>
<refpurpose></refpurpose>
</refnamediv>
<refsect1>
<title></title>
<funcsynopsis>
<funcprototype>
<funcdef> <function></function></funcdef>
<paramdef> <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/classobj.xml
+++ phpdoc/nl/functions/classobj.xml
<reference id="ref.classobj">
<title>Class/Object Functions</title>
<titleabbrev>Classes/Objects</titleabbrev>
<partintro>
<sect1 id="classobj.partintro">
<title>Introduction</title>
<sect2 id="classobj.intro">
<title>About</title>
<para>
These functions allow you to obtain information about classes
and instance objects. You can obtain the name of the class to
which a object belongs, as well as its member properties and
methods. Using these functions, you can find out not only the
class membership of an object, but also its parentage (i.e.
what class is the object class extending).
</para>
</sect2>
<sect2>
<title>An example of use</title>
<para>
In this example, we first define a base class and an extension
of the class. The base class describes a general vegetable,
whether it is edible or not and what is its color. The subclass
<varname>Spinach</varname> adds a method to cook it and another to
find out if it is cooked.
</para>
<para>
<example>
<title>classes.inc</title>
<programlisting role="php">
<?php
// base class with member properties and methods
class Vegetable {
var $edible;
var $color;
function Vegetable( $edible, $color="green" ) {
$this->edible = $edible;
$this->color = $color;
}
function is_edible() {
return $this->edible;
}
function what_color() {
return $this->color;
}
} // end of class Vegetable
// extends the base class
class Spinach extends Vegetable {
var $cooked = false;
function Spinach() {
$this->Vegetable( true, "green" );
}
function cook_it() {
$this->cooked = true;
}
function is_cooked() {
return $this->cooked;
}
} // end of class Spinach
?>
</programlisting>
</example>
</para>
<para>
We then instantiate 2 objects from these classes and print out
information about them, including their class parentage.
We also define some utility functions, mainly to have a nice printout
of the variables.
</para>
<para>
<example>
<title>test_script.php</title>
<programlisting role="php">
<pre>
<?php
include "classes.inc";
// utility functions
function print_vars($obj) {
$arr = get_object_vars($obj);
while (list($prop, $val) = each($arr))
echo "\t$prop = $val\n";
}
function print_methods($obj) {
$arr = get_class_methods(get_class($obj));
foreach ($arr as $method)
echo "\tfunction $method()\n";
}
function class_parentage($obj, $class) {
global $$obj;
if (is_subclass_of($$obj, $class)) {
echo "Object $obj belongs to class ".get_class($$obj);
echo " a subclass of $class\n";
} else {
echo "Object $obj does not belong to a subclass of $class\n";
}
}
// instantiate 2 objects
$veggie = new Vegetable(true,"blue");
$leafy = new Spinach();
// print out information about objects
echo "veggie: CLASS ".get_class($veggie)."\n";
echo "leafy: CLASS ".get_class($leafy);
echo ", PARENT ".get_parent_class($leafy)."\n";
// show veggie properties
echo "\nveggie: Properties\n";
print_vars($veggie);
// and leafy methods
echo "\nleafy: Methods\n";
print_methods($leafy);
echo "\nParentage:\n";
class_parentage("leafy", "Spinach");
class_parentage("leafy", "Vegetable");
?>
</pre>
</programlisting>
</example>
</para>
<para>
One important thing to note in the example above is that
the object <varname>$leafy</varname> is an instance of the class
<classname>Spinach</classname> which is a subclass of
<classname>Vegetable</classname>,
therefore the last part of the script above will output:
</para>
<para>
<informalexample>
<programlisting>
[...]
Parentage:
Object leafy does not belong to a subclass of Spinach
Object leafy belongs to class spinach a subclass of Vegetable
</programlisting>
</informalexample>
</para>
</sect2>
</sect1>
</partintro>
<refentry id="function.call-user-method">
<refnamediv>
<refname>call_user_method</refname>
<refpurpose>
Call a user method on an specific object
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed
<function>call_user_method</function>
</funcdef>
<paramdef>string
<parameter>method_name</parameter>
</paramdef>
<paramdef>object
<parameter>obj</parameter>
</paramdef>
<paramdef>mixed
<parameter><optional>parameter</optional></parameter>
</paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Calls a the method referred by <parameter>method_name</parameter> from
the user defined <parameter>obj</parameter> object. An example of usage
is below, where we define a class, instantiate an object and use
<function>call_user_method</function> to call indirectly its
<varname>print_info</varname> method.
<informalexample>
<programlisting role="php">
<?php
class Country {
var $NAME;
var $TLD;
function Country($name, $tld) {
$this->NAME = $name;
$this->TLD = $tld;
}
function print_info($prestr="") {
echo $prestr."Country: ".$this->NAME."\n";
echo $prestr."Top Level Domain:
".$this->TLD."\n";
}
}
$cntry = new Country("Peru","pe");
echo "* Calling the object method directly\n";
$cntry->print_info();
echo "\n* Calling the same method indirectly\n";
call_user_method ("print_info", $cntry, "\t");
?>
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>call_user_func</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.class-exists">
<refnamediv>
<refname>class_exists</refname>
<refpurpose>Checks if the class has been defined</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>class_exists</function></funcdef>
<paramdef>string <parameter>class_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns true if the class given by
<parameter>class_name</parameter> has been defined,
false otherwise.
</para>
</refsect1>
</refentry>
<refentry id="function.get-class">
<refnamediv>
<refname>get_class</refname>
<refpurpose>Returns the name of the class of an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>get_class</function></funcdef>
<paramdef>object <parameter>obj</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the name of the class of which the
object <parameter>obj</parameter> is an instance.
</para>
<simpara>
See also <function>get_parent_class</function>,
<function>is_subclass_of</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-class-methods">
<refnamediv>
<refname>get_class_methods</refname>
<refpurpose>Returns an array of class methods' names</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_class_methods</function></funcdef>
<paramdef>string <parameter>class_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an array of method names defined for the
class specified by <parameter>class_name</parameter>.
</para>
<simpara>
See also <function>get_class_vars</function>,
<function>get_object_vars</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-class-vars">
<refnamediv>
<refname>get_class_vars</refname>
<refpurpose>
Returns an array of default properties of the class
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_class_vars</function></funcdef>
<paramdef>string <parameter>class_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function will return an array of default properties of the
class.
</para>
<simpara>
See also <function>get_class_methods</function>,
<function>get_object_vars</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-declared-classes">
<refnamediv>
<refname>get_declared_classes</refname>
<refpurpose>Returns an array with the name of the defined classes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_declared_classes</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an array of the names of the declared classes
in the current script.
</para>
<note>
<para>
In PHP 4.0.1pl2, three extra classes are returned at the beginning of
the array: <classname>stdClass</classname> (defined in
<filename>Zend/zend.c</filename>),
<classname>OverloadedTestClass</classname> (defined in
<filename>ext/standard/basic_functions.c</filename>)
and <classname>Directory</classname>
(defined in <filename>ext/standard/dir.c</filename>).
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.get-object-vars">
<refnamediv>
<refname>get_object_vars</refname>
<refpurpose>Returns an associative array of object properties</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_object_vars</function></funcdef>
<paramdef>object <parameter>obj</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an associative array of defined object properties
for the specified object <parameter>obj</parameter>. If variables
declared in the class of which the <parameter>obj</parameter> is an
instance, have not been assigned a value, those will not be returned
in the array.
<example>
<title>Use of <function>get_object_vars</function></title>
<programlisting role="php">
<?php
class Point2D {
var $x, $y;
var $label;
function Point2D($x, $y) {
$this->x = $x;
$this->y = $y;
}
function setLabel($label) {
$this->label = $label;
}
function getPoint() {
return array("x" => $this->x,
"y" => $this->y,
"label" => $this->label);
}
}
$p1 = new Point2D(1.233, 3.445);
print_r(get_object_vars($p1));
// "$label" is declared but not defined
// Array
// (
// [x] => 1.233
// [y] => 3.445
// )
$p1->setLabel("point #1");
print_r(get_object_vars($p1));
// Array
// (
// [x] => 1.233
// [y] => 3.445
// [label] => point #1
// )
?>
</programlisting>
</example>
</para>
<simpara>
See also <function>get_class_methods</function>,
<function>get_class_vars</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-parent-class">
<refnamediv>
<refname>get_parent_class</refname>
<refpurpose>Returns the name of the parent class of an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>get_parent_class</function></funcdef>
<paramdef>object <parameter>obj</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the name of the parent class to
the class of which the object <parameter>obj</parameter>
is an instance.
</para>
<simpara>
See also <function>get_class</function>,
<function>is_subclass_of</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.is-subclass-of">
<refnamediv>
<refname>is_subclass_of</refname>
<refpurpose>
Determines if an object belongs to a subclass
of the specified class
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_subclass_of</function></funcdef>
<paramdef>object <parameter>obj</parameter></paramdef>
<paramdef>string <parameter>superclass</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns true if the object <parameter>obj</parameter>,
belongs to a class which is a subclass of
<parameter>superclass</parameter>, false otherwise.
</para>
<simpara>
See also <function>get_class</function>,
<function>get_parent_class</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.method-exists">
<refnamediv>
<refname>method_exists</refname>
<refpurpose>Checks if the class method exists</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>method_exists</function></funcdef>
<paramdef>object <parameter>object</parameter></paramdef>
<paramdef>string <parameter>method_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns true if the method given by
<parameter>method_name</parameter> has been defined for the given
<parameter>object</parameter>, false otherwise.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/com.xml
+++ phpdoc/nl/functions/com.xml
<reference id="ref.com">
<title>COM support functions for Windows</title>
<titleabbrev>COM</titleabbrev>
<partintro>
<simpara>
These functions are only available on the Windows version of
PHP. These functions have been added in PHP 4.
</simpara>
</partintro>
<refentry id="function.com-load">
<refnamediv>
<refname>com_load</refname>
<refpurpose>
Creates a new reference to a COM component
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>com_load</function></funcdef>
<paramdef>string <parameter>module name</parameter></paramdef>
<paramdef>string
<parameter>
<optional>server name</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>com_load</function> creates a new COM component and
returns a reference to it. Returns <literal>false</literal> on
failiure.
</para>
</refsect1>
</refentry>
<refentry id="function.com-invoke">
<refnamediv>
<refname>com_invoke</refname>
<refpurpose>
Calls a COM component's method.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>com_invoke</function></funcdef>
<paramdef>resource <parameter>com_object</parameter></paramdef>
<paramdef>string <parameter>function_name</parameter></paramdef>
<paramdef>mixed
<parameter>
<optional>function parameters, ...</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Com_invoke</function> invokes a method of the COM
component referenced by
<parameter>com_object</parameter>. Returns
<literal>false</literal> on error, returns the
<parameter>function_name</parameter>'s return value on success.
</para>
</refsect1>
</refentry>
<refentry id="function.com-propget">
<refnamediv>
<refname>com_propget</refname>
<refpurpose>
Gets the value of a COM Component's property
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>com_propget</function></funcdef>
<paramdef>resource <parameter>com_object</parameter></paramdef>
<paramdef>string <parameter>property</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is an alias for <function>com_get</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.com-get">
<refnamediv>
<refname>com_get</refname>
<refpurpose>
Gets the value of a COM Component's property
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>com_get</function></funcdef>
<paramdef>resource <parameter>com_object</parameter></paramdef>
<paramdef>string <parameter>property</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the value of the <parameter>property</parameter> of the
COM component referenced by <parameter>com_object</parameter>.
Returns <literal>false</literal> on error.
</para>
</refsect1>
</refentry>
<refentry id="function.com-propput">
<refnamediv>
<refname>com_propput</refname>
<refpurpose>
Assigns a value to a COM component's property
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>com_propput</function></funcdef>
<paramdef>resource <parameter>com_object</parameter></paramdef>
<paramdef>string <parameter>property</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is an alias for <function>com_set</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.com-propset">
<refnamediv>
<refname>com_propset</refname>
<refpurpose>
Assigns a value to a COM component's property
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>com_propset</function></funcdef>
<paramdef>resource <parameter>com_object</parameter></paramdef>
<paramdef>string <parameter>property</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is an alias for <function>com_set</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.com-set">
<refnamediv>
<refname>com_set</refname>
<refpurpose>
Assigns a value to a COM component's property
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>com_set</function></funcdef>
<paramdef>resource <parameter>com_object</parameter></paramdef>
<paramdef>string <parameter>property</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the value of the <parameter>property</parameter> of the COM
component referenced by <parameter>com_object</parameter>.
Returns <literal>true</literal> if
<parameter>property</parameter> is set. Returns
<literal>false</literal> on error.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/cpdf.xml
+++ phpdoc/nl/functions/cpdf.xml
<reference id="ref.cpdf">
<title>ClibPDF functions</title>
<titleabbrev>ClibPDF</titleabbrev>
<partintro>
<simpara>
ClibPDF lets you create PDF documents with PHP. It is available at
<ulink url="&url.fastio;">FastIO</ulink> but it isn't free
software. You should definitely read the licence before you start
playing with ClibPDF. If you cannot fullfil the licence agreement
consider using pdflib by Thomas Merz, which is also very powerful.
ClibPDF functionality and API is similar to Thomas Merz's pdflib but,
according to FastIO, ClibPDF is faster and creates smaller documents.
This may have changed with the new version 2.0 of pdflib. A simple
benchmark (the pdfclock.c example from pdflib 2.0 turned into a php
script) actually shows no difference in speed at all. The file size
is also similar if compression is turned off. So, try them both
and see which one does the job for you.
</simpara>
<simpara>
This documentation should be read alongside the ClibPDF manual since it
explains the library in much greater detail.
</simpara>
<simpara>
Many functions in the native ClibPDF and the PHP module, as
well as in pdflib, have the same name. All functions except for
<function>cpdf_open</function> take the handle for the document as
their first parameter.
</simpara>
<simpara>
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.
</simpara>
<note>
<simpara>
The function <function>cpdf_set_font</function> has changed since PHP 3
to support asian fonts. The encoding parameter is no longer an integer
but a string.
</simpara>
</note>
<simpara>
One big advantage of ClibPDF over pdflib used to be the possibility
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 is a handy feature but can be simulated with
<function>pdf_translate</function>.
</simpara>
<simpara>
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
<function>cpdf_set_current_page</function> allows to leave the current
page and presume modifying an other page.
</simpara>
<simpara>
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.
</simpara>
<example>
<title>Simple ClibPDF Example</title>
<programlisting>
<?php
$cpdf = cpdf_open(0);
cpdf_page_init($cpdf, 1, 0, 595, 842);
cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1");
cpdf_begin_text($cpdf);
cpdf_set_font($cpdf, "Times-Roman", 30, "WinAnsiEncoding");
cpdf_set_text_rendering($cpdf, 1);
cpdf_text($cpdf, "Times Roman outlined", 50, 750);
cpdf_end_text($cpdf);
cpdf_moveto($cpdf, 50, 740);
cpdf_lineto($cpdf, 330, 740);
cpdf_stroke($cpdf);
cpdf_finalize($cpdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($cpdf);
cpdf_close($cpdf);
?>
</programlisting>
</example>
<simpara>
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:
</simpara>
<example>
<title>pdfclock example from pdflib 2.0 distribution</title>
<programlisting>
<?php
$radius = 200;
$margin = 20;
$pagecount = 40;
$pdf = cpdf_open(0);
cpdf_set_creator($pdf, "pdf_clock.php3");
cpdf_set_title($pdf, "Analog Clock");
while($pagecount-- > 0) {
cpdf_page_init($pdf, $pagecount+1, 0, 2 * ($radius + $margin), 2 * ($radius + $margin), 1.0);
cpdf_set_page_animation($pdf, 4, 0.5, 0, 0, 0); /* wipe */
cpdf_translate($pdf, $radius + $margin, $radius + $margin);
cpdf_save($pdf);
cpdf_setrgbcolor($pdf, 0.0, 0.0, 1.0);
/* minute strokes */
cpdf_setlinewidth($pdf, 2.0);
for ($alpha = 0; $alpha < 360; $alpha += 6)
{
cpdf_rotate($pdf, 6.0);
cpdf_moveto($pdf, $radius, 0.0);
cpdf_lineto($pdf, $radius-$margin/3, 0.0);
cpdf_stroke($pdf);
}
cpdf_restore($pdf);
cpdf_save($pdf);
/* 5 minute strokes */
cpdf_setlinewidth($pdf, 3.0);
for ($alpha = 0; $alpha < 360; $alpha += 30)
{
cpdf_rotate($pdf, 30.0);
cpdf_moveto($pdf, $radius, 0.0);
cpdf_lineto($pdf, $radius-$margin, 0.0);
cpdf_stroke($pdf);
}
$ltime = getdate();
/* draw hour hand */
cpdf_save($pdf);
cpdf_rotate($pdf, -(($ltime['minutes']/60.0) + $ltime['hours'] - 3.0) * 30.0);
cpdf_moveto($pdf, -$radius/10, -$radius/20);
cpdf_lineto($pdf, $radius/2, 0.0);
cpdf_lineto($pdf, -$radius/10, $radius/20);
cpdf_closepath($pdf);
cpdf_fill($pdf);
cpdf_restore($pdf);
/* draw minute hand */
cpdf_save($pdf);
cpdf_rotate($pdf, -(($ltime['seconds']/60.0) + $ltime['minutes'] - 15.0) *
6.0);
cpdf_moveto($pdf, -$radius/10, -$radius/20);
cpdf_lineto($pdf, $radius * 0.8, 0.0);
cpdf_lineto($pdf, -$radius/10, $radius/20);
cpdf_closepath($pdf);
cpdf_fill($pdf);
cpdf_restore($pdf);
/* draw second hand */
cpdf_setrgbcolor($pdf, 1.0, 0.0, 0.0);
cpdf_setlinewidth($pdf, 2);
cpdf_save($pdf);
cpdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
cpdf_moveto($pdf, -$radius/5, 0.0);
cpdf_lineto($pdf, $radius, 0.0);
cpdf_stroke($pdf);
cpdf_restore($pdf);
/* draw little circle at center */
cpdf_circle($pdf, 0, 0, $radius/30);
cpdf_fill($pdf);
cpdf_restore($pdf);
cpdf_finalize_page($pdf, $pagecount+1);
}
cpdf_finalize($pdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($pdf);
cpdf_close($pdf);
?>
</programlisting>
</example>
</partintro>
<refentry id="function.cpdf-global-set-document-limits">
<refnamediv>
<refname>cpdf_global_set_document_limits</refname>
<refpurpose>Sets document limits for any pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>
void <function>cpdf_global_set_document_limits</function>
</funcdef>
<paramdef>int <parameter>maxpages</parameter></paramdef>
<paramdef>int <parameter>maxfonts</parameter></paramdef>
<paramdef>int <parameter>maximages</parameter></paramdef>
<paramdef>int <parameter>maxannotations</parameter></paramdef>
<paramdef>int <parameter>maxobjects</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_global_set_document_limits</function> function sets
several document limits. This function has to be called before
<function>cpdf_open</function> to take effect. It sets the limits
for any document open afterwards.
</para>
<para>
See also <function>cpdf_open</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-creator">
<refnamediv>
<refname>cpdf_set_creator</refname>
<refpurpose>Sets the creator field in the pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_creator</function></funcdef>
<paramdef>string <parameter>creator</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_creator</function> function sets the
creator of a pdf document.
</para>
<para>
See also <function>cpdf_set_subject</function>,
<function>cpdf_set_title</function>,
<function>cpdf_set_keywords</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-title">
<refnamediv>
<refname>cpdf_set_title</refname>
<refpurpose>Sets the title field of the pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_title</function></funcdef>
<paramdef>string <parameter>title</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_title</function> function sets the
title of a pdf document.
</para>
<para>
See also <function>cpdf_set_subject</function>,
<function>cpdf_set_creator</function>,
<function>cpdf_set_keywords</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-subject">
<refnamediv>
<refname>cpdf_set_subject</refname>
<refpurpose>Sets the subject field of the pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_subject</function></funcdef>
<paramdef>string <parameter>subject</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_subject</function> function sets the
subject of a pdf document.
</para>
<para>
See also <function>cpdf_set_title</function>,
<function>cpdf_set_creator</function>,
<function>cpdf_set_keywords</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-keywords">
<refnamediv>
<refname>cpdf_set_keywords</refname>
<refpurpose>Sets the keywords field of the pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_keywords</function></funcdef>
<paramdef>string <parameter>keywords</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_keywords</function> function sets the
keywords of a pdf document.
</para>
<para>
See also <function>cpdf_set_title</function>,
<function>cpdf_set_creator</function>,
<function>cpdf_set_subject</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-open">
<refnamediv>
<refname>cpdf_open</refname>
<refpurpose>Opens a new pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>cpdf_open</function></funcdef>
<paramdef>int <parameter>compression</parameter></paramdef>
<paramdef>
string <parameter><optional>filename</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_open</function> 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 <function>cpdf_save_to_file</function> or written to standard
output with <function>cpdf_output_buffer</function>.
<note>
<simpara>
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.
</simpara>
<simpara>
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 <function>cpdf_output_buffer</function> to
output the pdf document.
</simpara>
</note>
</para>
<para>
See also <function>cpdf_close</function>,
<function>cpdf_output_buffer</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-close">
<refnamediv>
<refname>cpdf_close</refname>
<refpurpose>Closes the pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_close</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_close</function> function closes the pdf document.
This should be the last function even after
<function>cpdf_finalize</function>,
<function>cpdf_output_buffer</function>
and <function>cpdf_save_to_file</function>.
</para>
<para>
See also <function>cpdf_open</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-page-init">
<refnamediv>
<refname>cpdf_page_init</refname>
<refpurpose>Starts new page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_page_init</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>page number</parameter></paramdef>
<paramdef>int <parameter>orientation</parameter></paramdef>
<paramdef>double <parameter>height</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
<paramdef>
double <parameter><optional>unit</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_page_init</function> function starts a new
page with height <parameter>height</parameter> and width
<parameter>width</parameter>. The page has number
<parameter>page number</parameter> and orientation
<parameter>orientation</parameter>. <parameter>orientation</parameter>
can be 0 for portrait and 1 for landscape. The last optional parameter
<parameter>unit</parameter> 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.
</para>
<para>
See also <function>cpdf_set_current_page</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-finalize-page">
<refnamediv>
<refname>cpdf_finalize_page</refname>
<refpurpose>Ends page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_finalize_page</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>page number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_finalize_page</function> function ends the page
with page number <parameter>page number</parameter>.
</para>
<para>
This function is only for saving memory. A finalized page takes
less memory but cannot be modified anymore.
</para>
<para>
See also <function>cpdf_page_init</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-finalize">
<refnamediv>
<refname>cpdf_finalize</refname>
<refpurpose>Ends document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_finalize</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_finalize</function> function ends the document.
You still have to call <function>cpdf_close</function>
</para>
<para>
See also <function>cpdf_close</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-output-buffer">
<refnamediv>
<refname>cpdf_output_buffer</refname>
<refpurpose>Outputs the pdf document in memory buffer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_output_buffer</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_output_buffer</function> function outputs
the pdf document to stdout. The document has to be created in memory which
is the case if <function>cpdf_open</function> has been called with
no filename parameter.
</para>
<para>
See also <function>cpdf_open</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-save-to-file">
<refnamediv>
<refname>cpdf_save_to_file</refname>
<refpurpose>Writes the pdf document into a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_save_to_file</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_save_to_file</function> function outputs
the pdf document into a file if it has been created in memory.
</para>
<para>
This function is not needed if the pdf document has been open
by specifying a filename as a parameter of <function>cpdf_open</function>.
</para>
<para>
See also <function>cpdf_output_buffer</function>,
<function>cpdf_open</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-current-page">
<refnamediv>
<refname>cpdf_set_current_page</refname>
<refpurpose>Sets current page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_current_page</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>page number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_current_page</function> function set the page
on which all operations are performed. One can switch between pages
until a page is finished with <function>cpdf_finalize_page</function>.
</para>
<para>
See also <function>cpdf_finalize_page</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-begin-text">
<refnamediv>
<refname>cpdf_begin_text</refname>
<refpurpose>Starts text section</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_begin_text</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_begin_text</function> function starts a text
section. It must be ended with <function>cpdf_end_text</function>.
<example>
<title>Text output</title>
<programlisting>
<?php
cpdf_begin_text($pdf);
cpdf_set_font($pdf, 16, "Helvetica", "WinAnsiEncoding");
cpdf_text($pdf, 100, 100, "Some text");
cpdf_end_text($pdf)
?>
</programlisting>
</example>
</para>
<para>
See also <function>cpdf_end_text</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-end-text">
<refnamediv>
<refname>cpdf_end_text</refname>
<refpurpose>Ends text section</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_end_text</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_end_text</function> function ends a text
section which was started with <function>cpdf_begin_text</function>.
<example>
<title>Text output</title>
<programlisting>
<?php
cpdf_begin_text($pdf);
cpdf_set_font($pdf, 16, "Helvetica", "WinAnsiEncoding");
cpdf_text($pdf, 100, 100, "Some text");
cpdf_end_text($pdf)
?>
</programlisting>
</example>
</para>
<para>
See also <function>cpdf_begin_text</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-show">
<refnamediv>
<refname>cpdf_show</refname>
<refpurpose>Output text at current position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_show</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_show</function> function outputs the
string in <parameter>text</parameter> at the current position.
</para>
<para>
See also <function>cpdf_text</function>,
<function>cpdf_begin_text</function>,
<function>cpdf_end_text</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-show-xy">
<refnamediv>
<refname>cpdf_show_xy</refname>
<refpurpose>Output text at position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_show_xy</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_show_xy</function> function outputs the
string <parameter>text</parameter> at position with coordinates
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
<note>
<simpara>
The function <function>cpdf_show_xy</function> is identical to
<function>cpdf_text</function> without the optional parameters.
</simpara>
</note>
</para>
<para>
See also <function>cpdf_text</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-text">
<refnamediv>
<refname>cpdf_text</refname>
<refpurpose>Output text with parameters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_text</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
<paramdef>
double <parameter><optional>orientation</optional></parameter>
</paramdef>
<paramdef>
int <parameter><optional>alignmode</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_text</function> function outputs the string
<parameter>text</parameter> at position with coordinates
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the
unit length. If it's 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 <parameter>orientation</parameter> is the rotation of
the text in degree. The optional parameter
<parameter>alignmode</parameter> determines how the text is
aligned.
</para>
<para>
See the ClibPDF documentation for possible values.
</para>
<para>
See also <function>cpdf_show_xy</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-font">
<refnamediv>
<refname>cpdf_set_font</refname>
<refpurpose>Select the current font face and size</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_font</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>font name</parameter></paramdef>
<paramdef>double <parameter>size</parameter></paramdef>
<paramdef>string <parameter>encoding</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_font</function> function sets the
current font face, font size and encoding. Currently only
the standard postscript fonts are supported.
</para>
<para>
The last parameter <parameter>encoding</parameter> can take the
following values: "MacRomanEncoding", "MacExpertEncoding",
"WinAnsiEncoding", and "NULL". "NULL" stands for the font's
built-in encoding.
</para>
<para>
See the ClibPDF Manual for more information, especially how to support
asian fonts.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-leading">
<refnamediv>
<refname>cpdf_set_leading</refname>
<refpurpose>Sets distance between text lines</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set leading</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>distance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_leading</function> function sets the distance
between text lines. This will be used if text is output by
<function>cpdf_continue_text</function>.
</para>
<para>
See also <function>cpdf_continue_text</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-text-rendering">
<refnamediv>
<refname>cpdf_set_text_rendering</refname>
<refpurpose>Determines how text is rendered</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_text_rendering</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_text_rendering</function> function
determines how text is rendered.
</para>
<para>
The possible values for <parameter>mode</parameter> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-horiz-scaling">
<refnamediv>
<refname>cpdf_set_horiz_scaling</refname>
<refpurpose>Sets horizontal scaling of text</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_horiz_scaling</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_horiz_scaling</function> function sets the
horizontal scaling to <parameter>scale</parameter> percent.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-text-rise">
<refnamediv>
<refname>cpdf_set_text_rise</refname>
<refpurpose>Sets the text rise</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_text_rise</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_text_rise</function> function sets the
text rising to <parameter>value</parameter> units.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-text-matrix">
<refnamediv>
<refname>cpdf_set_text_matrix</refname>
<refpurpose>Sets the text matrix</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_text_matrix</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>array <parameter>matrix</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_text_matrix</function> function sets
a matrix which describes a transformation applied on the current
text font.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-text-pos">
<refnamediv>
<refname>cpdf_set_text_pos</refname>
<refpurpose>Sets text position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_text_pos</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_text_pos</function> function sets the
position of text for the next <function>cpdf_show</function>
function call.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
<para>
See also <function>cpdf_show</function>,
<function>cpdf_text</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-char-spacing">
<refnamediv>
<refname>cpdf_set_char_spacing</refname>
<refpurpose>Sets character spacing</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_char_spacing</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>space</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_char_spacing</function> function sets the
spacing between characters.
</para>
<para>
See also <function>cpdf_set_word_spacing</function>,
<function>cpdf_set_leading</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-word-spacing">
<refnamediv>
<refname>cpdf_set_word_spacing</refname>
<refpurpose>Sets spacing between words</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_word_spacing</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>space</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_word_spacing</function> function sets the
spacing between words.
</para>
<para>
See also <function>cpdf_set_char_spacing</function>,
<function>cpdf_set_leading</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-continue-text">
<refnamediv>
<refname>cpdf_continue_text</refname>
<refpurpose>Output text in next line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_continue_text</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_continue_text</function> function outputs the
string in <parameter>text</parameter> in the next line.
</para>
<para>
See also <function>cpdf_show_xy</function>,
<function>cpdf_text</function>,
<function>cpdf_set_leading</function>,
<function>cpdf_set_text_pos</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-stringwidth">
<refnamediv>
<refname>cpdf_stringwidth</refname>
<refpurpose>Returns width of text in current font</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>cpdf_stringwidth</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_stringwidth</function> function returns the
width of the string in <parameter>text</parameter>. It requires
a font to be set before.
</para>
<para>
See also <function>cpdf_set_font</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-save">
<refnamediv>
<refname>cpdf_save</refname>
<refpurpose>Saves current enviroment</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_save</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_save</function> function saves the current
enviroment. It works like the postscript command gsave. Very
useful if you want to translate or rotate an object without effecting
other objects.
</para>
<para>
See also <function>cpdf_restore</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-restore">
<refnamediv>
<refname>cpdf_restore</refname>
<refpurpose>Restores formerly saved enviroment</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_restore</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_restore</function> function restores the
enviroment saved with <function>cpdf_save</function>. It works
like the postscript command grestore. Very useful if you want
to translate or rotate an object without effecting other objects.
<example>
<title>Save/Restore</title>
<programlisting>
<?php
cpdf_save($pdf);
// do all kinds of rotations, transformations, ...
cpdf_restore($pdf)
?>
</programlisting>
</example>
</para>
<para>
See also <function>cpdf_save</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-translate">
<refnamediv>
<refname>cpdf_translate</refname>
<refpurpose>Sets origin of coordinate system</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_translate</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_translate</function> function set the origin of
coordinate system to the point (<parameter>x-coor</parameter>,
<parameter>y-coor</parameter>).
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-scale">
<refnamediv>
<refname>cpdf_scale</refname>
<refpurpose>Sets scaling</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_scale</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-scale</parameter></paramdef>
<paramdef>double <parameter>y-scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_scale</function> function set the scaling factor
in both directions.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-rotate">
<refnamediv>
<refname>cpdf_rotate</refname>
<refpurpose>Sets rotation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_rotate</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>angle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_rotate</function> function set the rotation in
degress to <parameter>angle</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setflat">
<refnamediv>
<refname>cpdf_setflat</refname>
<refpurpose>Sets flatness</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setflat</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setflat</function> function set the flatness to
a value between 0 and 100.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setlinejoin">
<refnamediv>
<refname>cpdf_setlinejoin</refname>
<refpurpose>Sets linejoin parameter</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setlinejoin</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>long <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setlinejoin</function> function set the
linejoin parameter between a value of 0 and 2. 0 = miter, 1 =
round, 2 = bevel.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setlinecap">
<refnamediv>
<refname>cpdf_setlinecap</refname>
<refpurpose>Sets linecap parameter</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setlinecap</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setlinecap</function> function set the linecap
parameter between a value of 0 and 2. 0 = butt end, 1 = round,
2 = projecting square.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setmiterlimit">
<refnamediv>
<refname>cpdf_setmiterlimit</refname>
<refpurpose>Sets miter limit</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setmiterlimit</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setmiterlimit</function> function set the
miter limit to a value greater or equal than 1.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setlinewidth">
<refnamediv>
<refname>cpdf_setlinewidth</refname>
<refpurpose>Sets line width</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setlinewidth</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setlinewidth</function> function set the line
width to <parameter>width</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setdash">
<refnamediv>
<refname>cpdf_setdash</refname>
<refpurpose>Sets dash pattern</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setdash</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>white</parameter></paramdef>
<paramdef>double <parameter>black</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setdash</function> function set the dash
pattern <parameter>white</parameter> white units and
<parameter>black</parameter> black units. If both are 0 a solid
line is set.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-newpath">
<refnamediv>
<refname>cpdf_newpath</refname>
<refpurpose>Starts a new path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>cpdf_newpath</function>
</funcdef>
<paramdef>int
<parameter>pdf_document</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_newpath</function> starts a new path on the
document given by the <parameter>pdf_document</parameter>
parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-moveto">
<refnamediv>
<refname>cpdf_moveto</refname>
<refpurpose>Sets current point</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_moveto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_moveto</function> function set the current
point to the coordinates <parameter>x-coor</parameter> and
<parameter>y-coor</parameter>.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the
unit length. If it's 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.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-rmoveto">
<refnamediv>
<refname>cpdf_rmoveto</refname>
<refpurpose>Sets current point</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_rmoveto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_rmoveto</function> function set the current point
relative to the coordinates <parameter>x-coor</parameter> and
<parameter>y-coor</parameter>.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
<para>
See also <function>cpdf_moveto</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-curveto">
<refnamediv>
<refname>cpdf_curveto</refname>
<refpurpose>Draws a curve</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_curveto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x1</parameter></paramdef>
<paramdef>double <parameter>y1</parameter></paramdef>
<paramdef>double <parameter>x2</parameter></paramdef>
<paramdef>double <parameter>y2</parameter></paramdef>
<paramdef>double <parameter>x3</parameter></paramdef>
<paramdef>double <parameter>y3</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_curveto</function> function draws a Bezier curve
from the current point to the point
(<parameter>x3</parameter>, <parameter>y3</parameter>) using
(<parameter>x1</parameter>, <parameter>y1</parameter>) and
(<parameter>x2</parameter>, <parameter>y2</parameter>) as control
points.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
<para>
See also <function>cpdf_moveto</function>,
<function>cpdf_rmoveto</function>,
<function>cpdf_rlineto</function>,
<function>cpdf_lineto</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-lineto">
<refnamediv>
<refname>cpdf_lineto</refname>
<refpurpose>Draws a line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_lineto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_lineto</function> function draws a line from
the current point to the point with coordinates
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
<para>
See also <function>cpdf_moveto</function>,
<function>cpdf_rmoveto</function>,
<function>cpdf_curveto</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-rlineto">
<refnamediv>
<refname>cpdf_rlineto</refname>
<refpurpose>Draws a line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_rlineto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_rlineto</function> function draws a line from
the current point to the relative point with coordinates
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
<para>
See also <function>cpdf_moveto</function>,
<function>cpdf_rmoveto</function>,
<function>cpdf_curveto</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-circle">
<refnamediv>
<refname>cpdf_circle</refname>
<refpurpose>Draw a circle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_circle</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>radius</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_circle</function> function draws a circle with
center at point
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>)
and radius <parameter>radius</parameter>.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
<para>
See also <function>cpdf_arc</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-arc">
<refnamediv>
<refname>cpdf_arc</refname>
<refpurpose>Draws an arc</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_arc</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>radius</parameter></paramdef>
<paramdef>double <parameter>start</parameter></paramdef>
<paramdef>double <parameter>end</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_arc</function> function draws an arc with
center at point
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>)
and radius <parameter>radius</parameter>, starting at angle
<parameter>start</parameter> and ending at angle
<parameter>end</parameter>.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
<para>
See also <function>cpdf_circle</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-rect">
<refnamediv>
<refname>cpdf_rect</refname>
<refpurpose>Draw a rectangle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_rect</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
<paramdef>double <parameter>height</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_rect</function> function draws a rectangle with
its lower left corner at point
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
This width is set to <parameter>widgth</parameter>.
This height is set to <parameter>height</parameter>.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the unit
length. If it's 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.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-closepath">
<refnamediv>
<refname>cpdf_closepath</refname>
<refpurpose>Close path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_closepath</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_closepath</function> function closes the
current path.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-stroke">
<refnamediv>
<refname>cpdf_stroke</refname>
<refpurpose>Draw line along path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_stroke</function> function draws a line along
current path.
</para>
<para>
See also <function>cpdf_closepath</function>,
<function>cpdf_closepath_stroke</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-closepath-stroke">
<refnamediv>
<refname>cpdf_closepath_stroke</refname>
<refpurpose>Close path and draw line along path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_closepath_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_closepath_stroke</function> function is a
combination of <function>cpdf_closepath</function> and
<function>cpdf_stroke</function>. Than clears the path.
</para>
<para>
See also <function>cpdf_closepath</function>,
<function>cpdf_stroke</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-fill">
<refnamediv>
<refname>cpdf_fill</refname>
<refpurpose>Fill current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_fill</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_fill</function> function fills the interior of
the current path with the current fill color.
</para>
<para>
See also <function>cpdf_closepath</function>,
<function>cpdf_stroke</function>,
<function>cpdf_setgray_fill</function>,
<function>cpdf_setgray</function>,
<function>cpdf_setrgbcolor_fill</function>,
<function>cpdf_setrgbcolor</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-fill-stroke">
<refnamediv>
<refname>cpdf_fill_stroke</refname>
<refpurpose>Fill and stroke current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_fill_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_fill_stroke</function> function fills the interior of
the current path with the current fill color and draws current path.
</para>
<para>
See also <function>cpdf_closepath</function>,
<function>cpdf_stroke</function>,
<function>cpdf_fill</function>,
<function>cpdf_setgray_fill</function>,
<function>cpdf_setgray</function>,
<function>cpdf_setrgbcolor_fill</function>,
<function>cpdf_setrgbcolor</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-closepath-fill-stroke">
<refnamediv>
<refname>cpdf_closepath_fill_stroke</refname>
<refpurpose>Close, fill and stroke current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>cpdf_closepath_fill_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_closepath_fill_stroke</function> function closes,
fills the interior of the current path with the current fill color and
draws current path.
</para>
<para>
See also <function>cpdf_closepath</function>,
<function>cpdf_stroke</function>,
<function>cpdf_fill</function>,
<function>cpdf_setgray_fill</function>,
<function>cpdf_setgray</function>,
<function>cpdf_setrgbcolor_fill</function>,
<function>cpdf_setrgbcolor</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-clip">
<refnamediv>
<refname>cpdf_clip</refname>
<refpurpose>Clips to current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_clip</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_clip</function> function clips all drawing
to the current path.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setgray-fill">
<refnamediv>
<refname>cpdf_setgray_fill</refname>
<refpurpose>Sets filling color to gray value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setgray_fill</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setgray_fill</function> function sets the current
gray value to fill a path.
</para>
<para>
See also <function>cpdf_setrgbcolor_fill</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setgray-stroke">
<refnamediv>
<refname>cpdf_setgray_stroke</refname>
<refpurpose>Sets drawing color to gray value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setgray_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>gray value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setgray_stroke</function> function sets the current
drawing color to the given gray value.
</para>
<para>
See also <function>cpdf_setrgbcolor_stroke</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setgray">
<refnamediv>
<refname>cpdf_setgray</refname>
<refpurpose>Sets drawing and filling color to gray value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setgray</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>gray value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setgray_stroke</function> function sets the current
drawing and filling color to the given gray value.
</para>
<para>
See also <function>cpdf_setrgbcolor_stroke</function>,
<function>cpdf_setrgbcolor_fill</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setrgbcolor-fill">
<refnamediv>
<refname>cpdf_setrgbcolor_fill</refname>
<refpurpose>Sets filling color to rgb color value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setrgbcolor_fill</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>red value</parameter></paramdef>
<paramdef>double <parameter>green value</parameter></paramdef>
<paramdef>double <parameter>blue value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setrgbcolor_fill</function> function sets the current
rgb color value to fill a path.
</para>
<para>
See also <function>cpdf_setrgbcolor_stroke</function>,
<function>cpdf_setrgbcolor</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setrgbcolor-stroke">
<refnamediv>
<refname>cpdf_setrgbcolor_stroke</refname>
<refpurpose>Sets drawing color to rgb color value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setrgbcolor_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>red value</parameter></paramdef>
<paramdef>double <parameter>green value</parameter></paramdef>
<paramdef>double <parameter>blue value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setrgbcolor_stroke</function> function sets the current
drawing color to the given rgb color value.
</para>
<para>
See also <function>cpdf_setrgbcolor_fill</function>,
<function>cpdf_setrgbcolor</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-setrgbcolor">
<refnamediv>
<refname>cpdf_setrgbcolor</refname>
<refpurpose>Sets drawing and filling color to rgb color value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_setrgbcolor</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>red value</parameter></paramdef>
<paramdef>double <parameter>green value</parameter></paramdef>
<paramdef>double <parameter>blue value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_setrgbcolor_stroke</function> function sets the current
drawing and filling color to the given rgb color value.
</para>
<para>
See also <function>cpdf_setrgbcolor_stroke</function>,
<function>cpdf_setrgbcolor_fill</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-add-outline">
<refnamediv>
<refname>cpdf_add_outline</refname>
<refpurpose>Adds bookmark for current page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_add_outline</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_add_outline</function> function adds a bookmark
with text <parameter>text</parameter> that points to the current page.
<example>
<title>Adding a page outline</title>
<programlisting>
<?php
$cpdf = cpdf_open(0);
cpdf_page_init($cpdf, 1, 0, 595, 842);
cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1");
// ...
// some drawing
// ...
cpdf_finalize($cpdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($cpdf);
cpdf_close($cpdf);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-set-page-animation">
<refnamediv>
<refname>cpdf_set_page_animation</refname>
<refpurpose>Sets duration between pages</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_set_page_animation</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>transition</parameter></paramdef>
<paramdef>double <parameter>duration</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_set_page_animation</function> function set the
transition between following pages.
</para>
<para>
The value of <parameter>transition</parameter>
can be
<simplelist>
<member>0 for none,</member>
<member>
1 for two lines sweeping across the screen reveal the page,
</member>
<member>
2 for multiple lines sweeping across the screen reveal the page,
</member>
<member>3 for a box reveals the page,</member>
<member>
4 for a single line sweeping across the screen reveals the page,
</member>
<member>5 for the old page dissolves to reveal the page,</member>
<member>
6 for the dissolve effect moves from one screen edge to another,
</member>
<member>
7 for the old page is simply replaced by the new page (default)
</member>
</simplelist>
</para>
<para>
The value of <parameter>duration</parameter> is the number of seconds
between page flipping.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-import-jpeg">
<refnamediv>
<refname>cpdf_import_jpeg</refname>
<refpurpose>Opens a JPEG image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>cpdf_import_jpeg</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>file name</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>angle</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
<paramdef>double <parameter>height</parameter></paramdef>
<paramdef>double <parameter>x-scale</parameter></paramdef>
<paramdef>double <parameter>y-scale</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_import_jpeg</function> function opens an image
stored in the file with the name <parameter>file
name</parameter>. The format of the image has to be jpeg. The
image is placed on the current page at position
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
The image is rotated by <parameter>angle</parameter> degres.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the
unit length. If it's 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.
</para>
<para>
See also <function>cpdf_place_inline_image</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-place-inline-image">
<refnamediv>
<refname>cpdf_place_inline_image</refname>
<refpurpose>Places an image on the page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_place_inline_image</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>image</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>angle</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
<paramdef>double <parameter>height</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_place_inline_image</function> function places
an image created with the php image functions on the page at
postion (<parameter>x-coor</parameter>,
<parameter>y-coor</parameter>). The image can be scaled at the
same time.
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the
unit length. If it's 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.
</para>
<para>
See also <function>cpdf_import_jpeg</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.cpdf-add-annotation">
<refnamediv>
<refname>cpdf_add_annotation</refname>
<refpurpose>Adds annotation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>cpdf_add_annotation</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>llx</parameter></paramdef>
<paramdef>double <parameter>lly</parameter></paramdef>
<paramdef>double <parameter>urx</parameter></paramdef>
<paramdef>double <parameter>ury</parameter></paramdef>
<paramdef>string <parameter>title</parameter></paramdef>
<paramdef>string <parameter>content</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>cpdf_add_annotation</function> adds a note with the
lower left corner at (<parameter>llx</parameter>,
<parameter>lly</parameter>) and the upper right corner at
(<parameter>urx</parameter>, <parameter>ury</parameter>).
</para>
<para>
The optional parameter <parameter>mode</parameter> determines the
unit length. If it's 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.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/curl.xml
+++ phpdoc/nl/functions/curl.xml
<reference id="ref.curl">
<title>CURL, Client URL Library Functions</title>
<titleabbrev>CURL</titleabbrev>
<partintro id="curl.partintro">
<para>
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.
</para>
<para>
In order to use the CURL functions you need to install the <ulink
url="&url.curl;">CURL</ulink> 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.
</para>
<para>
To use PHP's CURL support you must also compile PHP <option
role="configure">--with-curl[=DIR]</option> 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.
</para>
<para>
These functions have been added in PHP 4.0.2.
</para>
<para>
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
<function>curl_init</function>, then you can set all your
options for the transfer via the <function>curl_exec</function>
and then you finish off your session using the
<function>curl_close</function>. Here is an example that uses
the CURL functions to fetch the PHP homepage into a file:
<example>
<title>Using PHP's CURL module to fetch the PHP homepage</title>
<programlisting role="php">
<?php
$ch = curl_init ("http://www.php.net/");
$fp = fopen ("php_homepage.txt", "w");
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
?>
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.curl-init">
<refnamediv>
<refname>curl_init</refname>
<refpurpose>Initialize a CURL session</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>curl_init</function>
</funcdef>
<paramdef>string
<parameter>
<optional>url</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>curl_init</function> will initialize a new session
and return a CURL handle for use with the
<function>curl_setopt</function>, <function>curl_exec</function>,
and <function>curl_close</function> functions. If the optional
<parameter>url</parameter> parameter is supplied then the
CURLOPT_URL option will be set to the value of the parameter.
You can manually set this using the
<function>curl_setopt</function> function.
<example>
<title>
Initializing a new CURL session and fetching a webpage
</title>
<programlisting role="php">
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.zend.com/");
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
?>
</programlisting>
</example>
</para>
<para>
See also: <function>curl_close</function>,
<function>curl_setopt</function>
</para>
</refsect1>
</refentry>
<refentry id="function.curl-setopt">
<refnamediv>
<refname>curl_setopt</refname>
<refpurpose>Set an option for a CURL transfer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>curl_setopt</function>
</funcdef>
<paramdef>int
<parameter>ch</parameter>
</paramdef>
<paramdef>string
<parameter>option</parameter>
</paramdef>
<paramdef>mixed
<parameter>value</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>curl_setopt</function> function will set options
for a CURL session identified by the <parameter>ch</parameter>
parameter. The <parameter>option</parameter> parameter is the
option you want to set, and the <parameter>value</parameter> is
the value of the option given by the
<parameter>option</parameter>.
</para>
<para>
The <parameter>value</parameter> should be a long for the
following options (specified in the <parameter>option</parameter>
parameter):
<itemizedlist>
<listitem>
<simpara>
<parameter>CURLOPT_INFILESIZE</parameter>: 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.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_VERBOSE</parameter>: Set this option to a
non-zero value if you want CURL to report everything that is
happening.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_HEADER</parameter>: Set this option to a
non-zero value if you want the header to be included in the
output.
</simpara>
</listitem>
<listitem>
<para>
<parameter>CURLOPT_NOPROGRESS</parameter>: Set this option to
a non-zero value if you don't want PHP to display a progress
meter for CURL transfers
<note>
<simpara>
PHP automatically sets this option to a non-zero parameter,
this should only be changed for debugging purposes.
</simpara>
</note>
</para>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_NOBODY</parameter>: Set this option to a
non-zero value if you don't want the body included with the
output.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_FAILONERROR</parameter>: 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 behaviour is
to return the page normally, ignoring the code.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_UPLOAD</parameter>: Set this option to a
non-zero value if you want PHP to prepare for an upload.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_POST</parameter>: 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-from-urlencoded kind,
most commonly used by HTML forms.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_FTPLISTONLY</parameter>: Set this option to
a non-zero value and PHP will just list the names of an FTP
directory.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_FTPAPPEND</parameter>: Set this option to a
non-zero value and PHP will append to the remote file instead
of overwriting it.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_NETRC</parameter>: 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.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_FOLLOWLOCATION</parameter>: 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.)
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_PUT</parameter>: Set this option a non-zero
value to HTTP PUT a file. The file to PUT must be set with
the CURLOPT_INFILE and CURLOPT_INFILESIZE.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_MUTE</parameter>: Set this option to a
non-zero value and PHP will be completely silent with regards
to the CURL functions.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_TIMEOUT</parameter>: Pass a long as a
parameter that contains the maximum time, in seconds, that
you'll allow the curl functions to take.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_LOW_SPEED_LIMIT</parameter>: 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 it too slow
and abort.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_LOW_SPEED_TIME</parameter>: 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.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_RESUME_FROM</parameter>: Pass a long as a
parameter that contains the offset, in bytes, that you want
the transfer to start from.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_SSLVERSION</parameter>: 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.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_TIMECONDITION</parameter>: 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.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_TIMEVALUE</parameter>: 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_TIMEVALUE
option, or by default the TIMECOND_IFMODSINCE will be used.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
The <parameter>value</parameter> parameter should be a string for
the following values of the <parameter>option</parameter>
parameter:
<itemizedlist>
<listitem>
<simpara>
<parameter>CURLOPT_URL</parameter>: This is the URL that you
want PHP to fetch. You can also set this option when
initializing a session with the <function>curl_init</function>
function.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_USERPWD</parameter>: Pass a string
formatted in the [username]:[password] manner, for PHP to use
for the connection. connection.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_PROXYUSERPWD</parameter>: Pass a string
formatted in the [username]:[password] format for connection
to the HTTP proxy.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_RANGE</parameter>: 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, seperated with commas as in X-Y,N-M.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_POSTFIELDS</parameter>: Pass a string
containing the full data to post in an HTTP "POST" operation.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_REFERER</parameter>: Pass a string
containing the "referer" header to be used in an HTTP request.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_USERAGENT</parameter>: Pass a string
containing the "user-agent" header to be used in an HTTP
request.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_FTPPORT</parameter>: Pass a string
containing the which will be used to get the IP address to use
for the ftp "PORT" 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.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_COOKIE</parameter>: Pass a string
containing the content of the cookie to be set in the HTTP
header.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_SSLCERT</parameter>: Pass a string
containing the filename of PEM formatted certificate.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_SSLCERTPASSWD</parameter>: Pass a string
containing the password required to use the CURLOPT_SSLCERT
certificate.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_COOKIEFILE</parameter>: Pass a string
containing the name of the file containing the cookiee data.
The cookie file can be in Netscape format, or just plain
HTTP-style headers dumped into a file.
</simpara>
</listitem>
<listitem>
<para>
<parameter>CURLOPT_CUSTOMREQUEST</parameter>: Pass a string to
be used instead of GET or HEAD when doing an HTTP request.
This is useful for doing DELETE or another, more obscure, HTTP
request.
<note>
<simpara>
Don't do this without making sure your server supports the
command first.
</simpara>
</note>
</para>
</listitem>
</itemizedlist>
</para>
<para>
The following options expect a file descriptor that is obtained
by using the <function>fopen</function> function:
<itemizedlist>
<listitem>
<simpara>
<parameter>CURLOPT_FILE</parameter>: The file where the output
of your transfer should be placed, the default is STDOUT.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_INFILE</parameter>: The file where the
input of your transfer comes from.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_WRITEHEADER</parameter>: The file to write
the header part of the output into.
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>CURLOPT_STDERR</parameter>: The file to write
errors to instead of stderr.
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.curl-exec">
<refnamediv>
<refname>curl_exec</refname>
<refpurpose>Perform a CURL session</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>curl_exec</function>
</funcdef>
<paramdef>int
<parameter>ch</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is 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
<parameter>ch</parameter>).
</para>
</refsect1>
</refentry>
<refentry id="function.curl-close">
<refnamediv>
<refname>curl_close</refname>
<refpurpose>Close a CURL session</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>curl_close</function>
</funcdef>
<paramdef>int
<parameter>ch</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This functions closes a CURL session and frees all ressources.
The CURL handle, <parameter>ch</parameter>, is also deleted.
</para>
</refsect1>
</refentry>
<refentry id="function.curl-version">
<refnamediv>
<refname>curl_version</refname>
<refpurpose>Return the current CURL version</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>curl_version</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>curl_version</function> function returns a string
containing the current CURL version.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/cybercash.xml
+++ phpdoc/nl/functions/cybercash.xml
<reference id="ref.cybercash">
<title>Cybercash payment functions</title>
<titleabbrev>Cybercash</titleabbrev>
<partintro>
<simpara>
These functions are only available if the interpreter has been
compiled with the <option
role="configure">--with-cybercash=[DIR]</option>. These functions
have been added in PHP 4.
</simpara>
</partintro>
<refentry id="function.cybercash-encr">
<refnamediv>
<refname>cybercash_encr</refname>
<refpurpose>???</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>cybercash_encr</function></funcdef>
<paramdef>string <parameter>wmk</parameter></paramdef>
<paramdef>string <parameter>sk</parameter></paramdef>
<paramdef>string <parameter>inbuff</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function returns an associative array with the elements
"errcode" and, if "errcode" is false, "outbuff" (string),
"outLth" (long) and "macbuff" (string).
</para>
</refsect1>
</refentry>
<refentry id="function.cybercash-decr">
<refnamediv>
<refname>cybercash_decr</refname>
<refpurpose>???</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>cybercash_decr</function></funcdef>
<paramdef>string <parameter>wmk</parameter></paramdef>
<paramdef>string <parameter>sk</parameter></paramdef>
<paramdef>string <parameter>inbuff</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function returns an associative array with the elements
"errcode" and, if "errcode" is false, "outbuff" (string),
"outLth" (long) and "macbuff" (string).
</para>
</refsect1>
</refentry>
<refentry id="function.cybercash-base64-encode">
<refnamediv>
<refname>cybercash_base64_encode</refname>
<refpurpose>???</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>cybercash_base64_encode</function>
</funcdef>
<paramdef>string <parameter>inbuff</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
</para>
</refsect1>
</refentry>
<refentry id="function.cybercash-base64-decode">
<refnamediv>
<refname>cybercash_base64_decode</refname>
<refpurpose></refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>cybercash_base64_decode</function>
</funcdef>
<paramdef>string <parameter>inbuff</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/datetime.xml
+++ phpdoc/nl/functions/datetime.xml
<reference id="ref.datetime">
<title>Date and Time functions</title>
<titleabbrev>Date/time</titleabbrev>
<refentry id="function.checkdate">
<refnamediv>
<refname>checkdate</refname>
<refpurpose>Validate a gregorian date/time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>checkdate</function></funcdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the date given is valid; otherwise returns false.
Checks the validity of the date formed by the arguments. A date
is considered valid if:
<itemizedlist>
<listitem>
<simpara>
year is between 1 and 32767 inclusive
</simpara>
</listitem>
<listitem>
<simpara>
month is between 1 and 12 inclusive
</simpara>
</listitem>
<listitem>
<simpara>
<parameter>Day</parameter> is within the allowed number of
days for the given <parameter>month</parameter>. Leap
<parameter>year</parameter>s are taken into consideration.
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.date">
<refnamediv>
<refname>date</refname>
<refpurpose>Format a local time/date</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>date</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>int
<parameter>
<optional>timestamp</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string formatted according to the given format string
using the given <parameter>timestamp</parameter> or the current
local time if no timestamp is given.
</para>
<para>
The following characters are recognized in the format string:
<itemizedlist>
<listitem>
<simpara>
a - "am" or "pm"
</simpara>
</listitem>
<listitem>
<simpara>
A - "AM" or "PM"
</simpara>
</listitem>
<listitem>
<simpara>
B - Swatch Internet time
</simpara>
</listitem>
<listitem>
<simpara>
d - day of the month, 2 digits with leading zeros; i.e. "01"
to "31"
</simpara>
</listitem>
<listitem>
<simpara>
D - day of the week, textual, 3 letters; i.e. "Fri"
</simpara>
</listitem>
<listitem>
<simpara>
F - month, textual, long; i.e. "January"
</simpara>
</listitem>
<listitem>
<simpara>
g - hour, 12-hour format without leading zeros; i.e. "1" to
"12"
</simpara>
</listitem>
<listitem>
<simpara>
G - hour, 24-hour format without leading zeros; i.e. "0" to
"23"
</simpara>
</listitem>
<listitem>
<simpara>
h - hour, 12-hour format; i.e. "01" to "12"
</simpara>
</listitem>
<listitem>
<simpara>
H - hour, 24-hour format; i.e. "00" to "23"
</simpara>
</listitem>
<listitem>
<simpara>
i - minutes; i.e. "00" to "59"
</simpara>
</listitem>
<listitem>
<simpara>
I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
</simpara>
</listitem>
<listitem>
<simpara>
j - day of the month without leading zeros; i.e. "1" to "31"
</simpara>
</listitem>
<listitem>
<simpara>
l (lowercase 'L') - day of the week, textual, long;
i.e. "Friday"
</simpara>
</listitem>
<listitem>
<simpara>
L - boolean for whether it is a leap year; i.e. "0" or "1"
</simpara>
</listitem>
<listitem>
<simpara>
m - month; i.e. "01" to "12"
</simpara>
</listitem>
<listitem>
<simpara>
M - month, textual, 3 letters; i.e. "Jan"
</simpara>
</listitem>
<listitem>
<simpara>
n - month without leading zeros; i.e. "1" to "12"
</simpara>
</listitem>
<listitem>
<simpara>
s - seconds; i.e. "00" to "59"
</simpara>
</listitem>
<listitem>
<simpara>
S - English ordinal suffix, textual, 2 characters; i.e. "th",
"nd"
</simpara>
</listitem>
<listitem>
<simpara>
t - number of days in the given month; i.e. "28" to "31"
</simpara>
</listitem>
<listitem>
<simpara>
T - Timezone setting of this machine; i.e. "MDT"
</simpara>
</listitem>
<listitem>
<simpara>
U - seconds since the epoch
</simpara>
</listitem>
<listitem>
<simpara>
w - day of the week, numeric, i.e. "0" (Sunday) to "6"
(Saturday)
</simpara>
</listitem>
<listitem>
<simpara>
Y - year, 4 digits; i.e. "1999"
</simpara>
</listitem>
<listitem>
<simpara>
y - year, 2 digits; i.e. "99"
</simpara>
</listitem>
<listitem>
<simpara>
z - day of the year; i.e. "0" to "365"
</simpara>
</listitem>
<listitem>
<simpara>
Z - timezone offset in seconds (i.e. "-43200" to "43200")
</simpara>
</listitem>
</itemizedlist>
Unrecognized characters in the format string will be printed
as-is. The "Z" format will always return "0" when using
<function>gmdate</function>.
<example>
<title><function>Date</function> example</title>
<programlisting role="php">
print (date ("l dS of F Y h:i:s A"));
print ("July 1, 2000 is on a " . date ("l", mktime(0,0,0,7,1,2000)));
</programlisting>
</example>
</para>
<para>
It is possible to use <function>date</function> and
<function>mktime</function> together to find dates in the future
or the past.
<example>
<title>
<function>Date</function> and <function>mktime</function>
example
</title>
<programlisting>
$tomorrow = mktime (0,0,0,date("m") ,date("d")+1,date("Y"));
$lastmonth = mktime (0,0,0,date("m")-1,date("d"), date("Y"));
$nextyear = mktime (0,0,0,date("m"), date("d"), date("Y")+1);
</programlisting>
</example>
</para>
<para>
To format dates in other languages, you should use the
<function>setlocale</function> and <function>strftime</function>
functions.
</para>
<para>
See also <function>gmdate</function> and
<function>mktime</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getdate">
<refnamediv>
<refname>getdate</refname>
<refpurpose>Get date/time information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>getdate</function></funcdef>
<paramdef>int <parameter>timestamp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array containing the date information of
the <parameter>timestamp</parameter> as the following array
elements:
<itemizedlist>
<listitem>
<simpara>
"seconds" - seconds
</simpara>
</listitem>
<listitem>
<simpara>
"minutes" - minutes
</simpara>
</listitem>
<listitem>
<simpara>
"hours" - hours
</simpara>
</listitem>
<listitem>
<simpara>
"mday" - day of the month
</simpara>
</listitem>
<listitem>
<simpara>
"wday" - day of the week, numeric
</simpara>
</listitem>
<listitem>
<simpara>
"mon" - month, numeric
</simpara>
</listitem>
<listitem>
<simpara>
"year" - year, numeric
</simpara>
</listitem>
<listitem>
<simpara>
"yday" - day of the year, numeric; i.e. "299"
</simpara>
</listitem>
<listitem>
<simpara>
"weekday" - day of the week, textual, full; i.e. "Friday"
</simpara>
</listitem>
<listitem>
<simpara>
"month" - month, textual, full; i.e. "January"
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.gettimeofday">
<refnamediv>
<refname>gettimeofday</refname>
<refpurpose>Get current time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>gettimeofday</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This is an interface to gettimeofday(2). It returns an
associative array containing the data returned from the system
call.
<itemizedlist>
<listitem>
<simpara>
"sec" - seconds
</simpara>
</listitem>
<listitem>
<simpara>
"usec" - microseconds
</simpara>
</listitem>
<listitem>
<simpara>
"minuteswest" - minutes west of Greenwich
</simpara>
</listitem>
<listitem>
<simpara>
"dsttime" - type of dst correction
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.gmdate">
<refnamediv>
<refname>gmdate</refname>
<refpurpose>Format a GMT/CUT date/time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gmdate</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>int <parameter>timestamp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to the <function>date</function> function except that
the time returned is Greenwich Mean Time (GMT). For example, when
run in Finland (GMT +0200), the first line below prints "Jan 01
1998 00:00:00", while the second prints "Dec 31 1997 22:00:00".
<example>
<title><function>Gmdate</function> example</title>
<programlisting role="php">
echo date ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
echo gmdate ("M d Y H:i:s", mktime (0,0,0,1,1,1998));
</programlisting>
</example>
</para>
<para>
See also <function>date</function>, <function>mktime</function>,
and <function>gmmktime</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gmmktime">
<refnamediv>
<refname>gmmktime</refname>
<refpurpose>Get UNIX timestamp for a GMT date</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gmmktime</function></funcdef>
<paramdef>int <parameter>hour</parameter></paramdef>
<paramdef>int <parameter>minute</parameter></paramdef>
<paramdef>int <parameter>second</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int
<parameter><optional>is_dst</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>mktime</function> except the passed
parameters represents a GMT date.
</para>
</refsect1>
</refentry>
<refentry id="function.gmstrftime">
<refnamediv>
<refname>gmstrftime</refname>
<refpurpose>
Format a GMT/CUT time/date according to locale settings
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gmstrftime</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>int <parameter>timestamp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Behaves the same as <function>strftime</function> except that the
time returned is Greenwich Mean Time (GMT). For example, when run
in Eastern Standard Time (GMT -0500), the first line below prints
"Dec 31 1998 20:00:00", while the second prints "Jan 01 1999
01:00:00".
<example>
<title><function>Gmstrftime</function> example</title>
<programlisting role="php">
setlocale ('LC_TIME', 'en_US');
echo strftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n";
echo gmstrftime ("%b %d %Y %H:%M:%S", mktime (20,0,0,12,31,98))."\n";
</programlisting>
</example>
</para>
<para>
See also <function>strftime</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.localtime">
<refnamediv>
<refname>localtime</refname>
<refpurpose>Get the local time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>localtime</function></funcdef>
<paramdef>int
<parameter>
<optional>timestamp</optional>
</parameter>
</paramdef>
<paramdef>bool
<parameter>
<optional>is_associative</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>localtime</function> function returns an array
identical to that of the structure returned by the C function
call. The first argument to <function>localtime</function> is
the timestamp, if this is not given the current time is used.
The second argument to the <function>localtime</function> is the
<parameter>is_associative</parameter>, if this is set to 0 or not
supplied than the array is returned as a regular, numerically
indexed array. If the argument is set to 1 then
<function>localtime</function> is an associative array containing
all the different elements of the structure returned by the C
function call to localtime. The names of the different keys of
the associative array are as follows:
<itemizedlist>
<listitem>
<simpara>
"tm_sec" - seconds
</simpara>
</listitem>
<listitem>
<simpara>
"tm_min" - minutes
</simpara>
</listitem>
<listitem>
<simpara>
"tm_hour" - hour
</simpara>
</listitem>
<listitem>
<simpara>
"tm_mday" - day of the month
</simpara>
</listitem>
<listitem>
<simpara>
"tm_mon" - month of the year
</simpara>
</listitem>
<listitem>
<simpara>
"tm_year" - Year, not y2k compliant
</simpara>
</listitem>
<listitem>
<simpara>
"tm_wday" - Day of the week
</simpara>
</listitem>
<listitem>
<simpara>
"tm_yday" - Day of the year
</simpara>
</listitem>
<listitem>
<simpara>
"tm_isdst" - Is daylight savings time in effect
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.microtime">
<refnamediv>
<refname>microtime</refname>
<refpurpose>
Return current UNIX timestamp with microseconds</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>microtime</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Returns the string "msec sec" where sec is the current time
measured in the number of seconds since the Unix Epoch (0:00:00
January 1, 1970 GMT), and msec is the microseconds part. This
function is only available on operating systems that support the
gettimeofday() system call.
</para>
<para>
See also <function>time</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mktime">
<refnamediv>
<refname>mktime</refname>
<refpurpose>Get UNIX timestamp for a date</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mktime</function></funcdef>
<paramdef>int <parameter>hour</parameter></paramdef>
<paramdef>int <parameter>minute</parameter></paramdef>
<paramdef>int <parameter>second</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int
<parameter><optional>is_dst</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<emphasis>Warning:</emphasis> Note the strange order of
arguments, which differs from the order of arguments in a regular
UNIX mktime() call and which does not lend itself well to leaving
out parameters from right to left (see below). It is a common
error to mix these values up in a script.
</para>
<para>
Returns the Unix timestamp corresponding to the arguments
given. This timestamp is a long integer containing the number of
seconds between the Unix Epoch (January 1 1970) and the time
specified.
</para>
<para>
Arguments may be left out in order from right to left; any
arguments thus omitted will be set to the current value according
to the local date and time.
</para>
<para>
<parameter>Is_dst</parameter> can be set to 1 if the time is
during daylight savings time, 0 if it is not, or -1 (the default)
if it is unknown whether the time is within daylight savings time
or not.
</para>
<note>
<para>
<parameter>Is_dst</parameter> was added in 3.0.10.
</para>
</note>
<para>
<function>Mktime</function> is useful for doing date arithmetic
and validation, as it will automatically calculate the correct
value for out-of-range input. For example, each of the following
lines produces the string "Jan-01-1998".
<example>
<title><function>Mktime</function> example</title>
<programlisting>
echo date ("M-d-Y", mktime (0,0,0,12,32,1997));
echo date ("M-d-Y", mktime (0,0,0,13,1,1997));
echo date ("M-d-Y", mktime (0,0,0,1,1,1998));
echo date ("M-d-Y", mktime (0,0,0,1,1,98));
</programlisting>
</example>
<parameter>Year</parameter> may be a two or four digit value,
with values between 0-69 mapping to 2000-2069 and 70-99 to
1970-1999 (on systems where time_t is a 32bit signed integer, as
most common today, the valid range for
<parameter>year</parameter> is somewhere between 1902 and 2037).
</para>
<para>
The last day of any given month can be expressed as the "0" day
of the next month, not the -1 day. Both of the following examples
will produce the string "The last day in Feb 2000 is: 29".
<example>
<title>Last day of next month</title>
<programlisting role="php">
$lastday = mktime (0,0,0,3,0,2000);
echo strftime ("Last day in Feb 2000 is: %d", $lastday);
$lastday = mktime (0,0,0,4,-31,2000);
echo strftime ("Last day in Feb 2000 is: %d", $lastday);
</programlisting>
</example>
</para>
<simpara>
Date with year, month and day equal to zero is considered illegal
(otherwise it what be regarded as 30.11.1999, which would be strange
behaviour).
</simpara>
<para>
See also <function>date</function> and <function>time</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strftime">
<refnamediv>
<refname>strftime</refname>
<refpurpose>
Format a local time/date according to locale settings
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strftime</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>int
<parameter>
<optional>timestamp</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string formatted according to the given format string
using the given <parameter>timestamp</parameter> or the current
local time if no timestamp is given. Month and weekday names and
other language dependent strings respect the current locale set
with <function>setlocale</function>.
</para>
<para>
The following conversion specifiers are recognized in the format
string:
<itemizedlist>
<listitem>
<simpara>
%a - abbreviated weekday name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%A - full weekday name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%b - abbreviated month name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%B - full month name according to the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%c - preferred date and time representation for the current
locale
</simpara>
</listitem>
<listitem>
<simpara>
%C - century number (the year divided by 100 and truncated to
an integer, range 00 to 99)
</simpara>
</listitem>
<listitem>
<simpara>
%d - day of the month as a decimal number (range 00 to 31)
</simpara>
</listitem>
<listitem>
<simpara>
%D - same as %m/%d/%y
</simpara>
</listitem>
<listitem>
<simpara>
%e - day of the month as a decimal number, a single digit is
preceded by a space (range ' 1' to '31')
</simpara>
</listitem>
<listitem>
<simpara>
%h - same as %b
</simpara>
</listitem>
<listitem>
<simpara>
%H - hour as a decimal number using a 24-hour clock (range 00
to 23)
</simpara>
</listitem>
<listitem>
<simpara>
%I - hour as a decimal number using a 12-hour clock (range 01
to 12)
</simpara>
</listitem>
<listitem>
<simpara>
%j - day of the year as a decimal number (range 001 to 366)
</simpara>
</listitem>
<listitem>
<simpara>
%m - month as a decimal number (range 01 to 12)
</simpara>
</listitem>
<listitem>
<simpara>
%M - minute as a decimal number
</simpara>
</listitem>
<listitem>
<simpara>
%n - newline character
</simpara>
</listitem>
<listitem>
<simpara>
%p - either
am' or pm' according to the given time value, or
the corresponding strings for the current locale
</simpara>
</listitem>
<listitem>
<simpara>
%r - time in a.m. and p.m. notation
</simpara>
</listitem>
<listitem>
<simpara>
%R - time in 24 hour notation
</simpara>
</listitem>
<listitem>
<simpara>
%S - second as a decimal number
</simpara>
</listitem>
<listitem>
<simpara>
%t - tab character
</simpara>
</listitem>
<listitem>
<simpara>
%T - current time, equal to %H:%M:%S
</simpara>
</listitem>
<listitem>
<simpara>
%u - weekday as a decimal number [1,7], with 1 representing
Monday
</simpara>
</listitem>
<listitem>
<simpara>
%U - week number of the current year as a decimal number,
starting with the first Sunday as the first day of the first
week
</simpara>
</listitem>
<listitem>
<simpara>
%V - The ISO 8601:1988 week number of the current year as a
decimal number, range 01 to 53, where week 1 is the first
week that has at least 4 days in the current year, and with
Monday as the first day of the week.
</simpara>
</listitem>
<listitem>
<simpara>
%W - week number of the current year as a decimal number,
starting with the first Monday as the first day of the first
week
</simpara>
</listitem>
<listitem>
<simpara>
%w - day of the week as a decimal, Sunday being 0
</simpara>
</listitem>
<listitem>
<simpara>
%x - preferred date representation for the current locale
without the time
</simpara>
</listitem>
<listitem>
<simpara>
%X - preferred time representation for the current locale
without the date
</simpara>
</listitem>
<listitem>
<simpara>
%y - year as a decimal number without a century (range 00 to
99)
</simpara>
</listitem>
<listitem>
<simpara>
%Y - year as a decimal number including the century
</simpara>
</listitem>
<listitem>
<simpara>
%Z - time zone or name or abbreviation
</simpara>
</listitem>
<listitem>
<simpara>
%% - a literal `%' character
</simpara>
</listitem>
</itemizedlist>
<example>
<title><function>Strftime</function> example</title>
<programlisting role="php">
setlocale ("LC_TIME", "C");
print (strftime ("%A in Finnish is "));
setlocale ("LC_TIME", "fi_FI");
print (strftime ("%A, in French "));
setlocale ("LC_TIME", "fr_CA");
print (strftime ("%A and in German "));
setlocale ("LC_TIME", "de_DE");
print (strftime ("%A.\n"));
</programlisting>
</example>
This example works if you have the respective locales installed
in your system.
</para>
<para>
See also <function>setlocale</function> and
<function>mktime</function> and the <ulink
url="&spec.strftime;">
Open Group specification of
<function>strftime</function></ulink>.
</para>
</refsect1>
</refentry>
<refentry id="function.time">
<refnamediv>
<refname>time</refname>
<refpurpose>Return current UNIX timestamp</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>time</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Returns the current time measured in the number of seconds since
the Unix Epoch (January 1 1970 00:00:00 GMT).
</para>
<para>
See also <function>date</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strtotime">
<refnamediv>
<refname>strtotime</refname>
<refpurpose>
Parse about any english textual datetime description into a UNIX
timestamp
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strtotime</function></funcdef>
<paramdef>string <parameter>time</parameter></paramdef>
<paramdef>int
<parameter><optional>now</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function expects to be given a string containing an english
date format and will try to parse that format into a UNIX
timestamp.
<example>
<title><function>Strtotime</function> examples</title>
<programlisting role="php">
echo strtotime ("now") . "\n";
echo strtotime ("10 September 2000") . "\n";
echo strtotime ("+1 day") . "\n";
echo strtotime ("+1 week") . "\n";
echo strtotime ("+1 week 2 days 4 hours 2 seconds") . "\n";
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/dba.xml
+++ phpdoc/nl/functions/dba.xml
<reference id="ref.dba">
<title>Database (dbm-style) abstraction layer functions</title>
<titleabbrev>dba</titleabbrev>
<partintro>
<para>
These functions build the foundation for accessing Berkeley DB
style databases.
</para>
<para>
This is a general abstraction layer for several file-based databases. As
such, functionality is limited to a subset of features modern databases
such as <ulink url="&url.sleepycat;">Sleepycat Software's
DB2</ulink>
support. (This is not to be confused with IBM's DB2 software, which is
supported through the <link linkend="ref.odbc">ODBC functions</link>.)
</para>
<para>
The behaviour of various aspects depend on the implementation of the
underlying database. Functions such as <function>dba_optimize</function>
and <function>dba_sync</function> will do what they promise for one
database and will do nothing for others.
</para>
<para>
To add support for any of the following handlers, add the
specified --with configure switch to your PHP configure line:
<itemizedlist>
<listitem>
<simpara>
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. (--with-dbm)
</simpara>
</listitem>
<listitem>
<simpara>
Ndbm is a newer type and more flexible than dbm. It still has
most of the arbitrary limits of dbm (therefore it is
deprecated). (--with-ndbm)
</simpara>
</listitem>
<listitem>
<simpara>
Gdbm is the <ulink url="&url.gdbm;">GNU database
manager</ulink>. (--with-gdbm)
</simpara>
</listitem>
<listitem>
<simpara>
DB2 is <ulink url="&url.sleepycat;">Sleepycat Software's
DB2</ulink>. It is described as "a programmatic toolkit that
provides high-performance built-in database support for both
standalone and client/server applications." (--with-db2)
</simpara>
</listitem>
<listitem>
<simpara>
DB3 is <ulink url="&url.sleepycat;">Sleepycat Software's
DB3</ulink>. (--with-db3)
</simpara>
</listitem>
<listitem>
<simpara>
Cdb is "a fast, reliable, lightweight package for creating and
reading constant databases." It is from the author of qmail and
can be found <ulink url="&url.cdb;">here</ulink>. Since it is
constant, we support only reading operations. (--with-cdb)
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title>DBA example</title>
<programlisting role="php">
<?php
$id = dba_open ("/tmp/test.db", "n", "db2");
if (!$id) {
echo "dba_open failed\n";
exit;
}
dba_replace ("key", "This is an example!", $id);
if (dba_exists ("key", $id)) {
echo dba_fetch ("key", $id);
dba_delete ("key", $id);
}
dba_close ($id);
?>
</programlisting>
</example>
</para>
<para>
DBA is binary safe and does not have any arbitrary limits. It inherits all
limits set by the underlying database implementation.
</para>
<para>
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
<function>dba_open</function> or <function>dba_popen</function>.
</para>
<para>
You can access all entries of a database in a linear way by using the
<function>dba_firstkey</function> and <function>dba_nextkey</function>
functions. You may not change the database while traversing it.
</para>
<para>
<example>
<title>Traversing a database</title>
<programlisting role="php">
<?php
# ...open database...
$key = dba_firstkey ($id);
while ($key != false) {
if (...) { # remember the key to perform some action later
$handle_later[] = $key;
}
$key = dba_nextkey ($id);
}
for ($i = 0; $i < count($handle_later); $i++)
dba_delete ($handle_later[$i], $id);
?>
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.dba-close">
<refnamediv>
<refname>dba_close</refname>
<refpurpose>Close database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>dba_close</function></funcdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Dba_close</function> closes the established database
and frees all resources specified by
<parameter>handle</parameter>.
</para>
<para>
<parameter>handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>Dba_close</function> does not return any value.
</para>
<para>
See also: <function>dba_open</function> and
<function>dba_popen</function>
</para>
</refsect1>
</refentry>
<refentry id="function.dba-delete">
<refnamediv>
<refname>dba_delete</refname>
<refpurpose>Delete entry specified by key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dba_delete</function></funcdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_delete</function> deletes the entry specified by
<parameter>key</parameter> from the database specified with
<parameter>handle</parameter>.
</para>
<para>
<parameter>key</parameter> is the key of the entry which is
deleted.
</para>
<para>
<parameter>handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>dba_delete</function> returns true or false, if the entry is
deleted or not deleted, respectively.
</para>
<para>
See also: <function>dba_exists</function>,
<function>dba_fetch</function>, <function>dba_insert</function>,
and <function>dba_replace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.dba-exists">
<refnamediv>
<refname>dba_exists</refname>
<refpurpose>Check whether key exists</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dba_exists</function></funcdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Dba_exists</function> checks whether the specified
<parameter>key</parameter> exists in the database specified by
<parameter>handle</parameter>.
</para>
<para>
<parameter>Key</parameter> is the key the check is performed for.
</para>
<para>
<parameter>Handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>Dba_exists</function> returns true or false, if the key is found
or not found, respectively.
</para>
<para>
See also: <function>dba_fetch</function>,
<function>dba_delete</function>, <function>dba_insert</function>,
and <function>dba_replace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.dba-fetch">
<refnamediv>
<refname>dba_fetch</refname>
<refpurpose>Fetch data specified by key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dba_fetch</function></funcdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Dba_fetch</function> fetches the data specified by
<parameter>key</parameter> from the database specified with
<parameter>handle</parameter>.
</para>
<para>
<parameter>Key</parameter> is the key the data is specified by.
</para>
<para>
<parameter>Handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>Dba_fetch</function> returns the associated string or false, if
the key/data pair is found or not found, respectively.
</para>
<para>
See also: <function>dba_exists</function>,
<function>dba_delete</function>, <function>dba_insert</function>,
and <function>dba_replace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.dba-firstkey">
<refnamediv>
<refname>dba_firstkey</refname>
<refpurpose>Fetch first key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dba_firstkey</function></funcdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Dba_firstkey</function> returns the first key of the
database specified by <parameter>handle</parameter> and resets
the internal key pointer. This permits a linear search through
the whole database.
</para>
<para>
<parameter>Handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>Dba_firstkey</function> returns the key or false
depending on whether it succeeds or fails, respectively.
</para>
<para>
See also:
<function>Dba_nextkey</function>
</para>
</refsect1>
</refentry>
<refentry id="function.dba-insert">
<refnamediv>
<refname>dba_insert</refname>
<refpurpose>Insert entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dba_insert</function></funcdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_insert</function> inserts the entry described with
<parameter>key</parameter> and <parameter>value</parameter> into the
database specified by <parameter>handle</parameter>. It fails, if an entry
with the same <parameter>key</parameter> already exists.
</para>
<para>
<parameter>key</parameter> is the key of the entry to be inserted.
</para>
<para>
<parameter>value</parameter> is the value to be inserted.
</para>
<para>
<parameter>handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>dba_insert</function> returns true or false, depending on
whether it succeeds of fails, respectively.
</para>
<para>
See also:
<function>dba_exists</function>
<function>dba_delete</function>
<function>dba_fetch</function>
<function>dba_replace</function>
</para>
</refsect1>
</refentry>
<refentry id="function.dba-nextkey">
<refnamediv>
<refname>dba_nextkey</refname>
<refpurpose>Fetch next key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dba_nextkey</function></funcdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_nextkey</function> returns the next key of the database
specified by <parameter>handle</parameter> and increments the internal
key pointer.
</para>
<para>
<parameter>handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>dba_nextkey</function> returns the key or false depending on
whether it succeeds or fails, respectively.
</para>
<para>
See also:
<function>dba_firstkey</function>
</para>
</refsect1>
</refentry>
<refentry id="function.dba-popen">
<refnamediv>
<refname>dba_popen</refname>
<refpurpose>Open database persistently</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dba_popen</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
<paramdef><parameter><optional>...</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_popen</function> establishes a persistent database instance
for <parameter>path</parameter> with <parameter>mode</parameter> using
<parameter>handler</parameter>.
</para>
<para>
<parameter>path</parameter> is commonly a regular path in your filesystem.
</para>
<para>
<parameter>mode</parameter> 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.
</para>
<para>
<parameter>handler</parameter> is the name of the handler which shall be
used for accessing <parameter>path</parameter>. It is passed all optional
parameters given to <function>dba_popen</function> and can act on behalf
of them.
</para>
<para>
<function>dba_popen</function> returns a positive handler id or false, in
the case the open is successful or fails, respectively.
</para>
<para>
See also:
<function>dba_open</function>
<function>dba_close</function>
</para>
</refsect1>
</refentry>
<refentry id="function.dba-open">
<refnamediv>
<refname>dba_open</refname>
<refpurpose>Open database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dba_open</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
<paramdef><parameter><optional>...</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_open</function> establishes a database instance for
<parameter>path</parameter> with <parameter>mode</parameter> using
<parameter>handler</parameter>.
</para>
<para>
<parameter>path</parameter> is commonly a regular path in your filesystem.
</para>
<para>
<parameter>mode</parameter> 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.
</para>
<para>
<parameter>handler</parameter> is the name of the handler which shall be
used for accessing <parameter>path</parameter>. It is passed all optional
parameters given to <function>dba_open</function> and can act on behalf of
them.
</para>
<para>
<function>dba_open</function> returns a positive handler id or false, in
the case the open is successful or fails, respectively.
</para>
<para>
See also:
<function>dba_popen</function>
<function>dba_close</function>
</para>
</refsect1>
</refentry>
<refentry id="function.dba-optimize">
<refnamediv>
<refname>dba_optimize</refname>
<refpurpose>Optimize database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dba_optimize</function></funcdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_optimize</function> optimizes the underlying database
specified by <parameter>handle</parameter>.
</para>
<para>
<parameter>handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>dba_optimize</function> returns true or false, if the
optimization succeeds or fails, respectively.
</para>
<para>
See also:
<function>dba_sync</function>
</para>
</refsect1>
</refentry>
<refentry id="function.dba-replace">
<refnamediv>
<refname>dba_replace</refname>
<refpurpose>Replace or insert entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dba_replace</function></funcdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_replace</function> replaces or inserts the entry described
with <parameter>key</parameter> and <parameter>value</parameter> into
the
database specified by <parameter>handle</parameter>.
</para>
<para>
<parameter>key</parameter> is the key of the entry to be inserted.
</para>
<para>
<parameter>value</parameter> is the value to be inserted.
</para>
<para>
<parameter>handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>dba_replace</function> returns true or false, depending on
whether it succeeds of fails, respectively.
</para>
<para>
See also: <function>dba_exists</function>,
<function>dba_delete</function>, <function>dba_fetch</function>,
and <function>dba_insert</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.dba-sync">
<refnamediv>
<refname>dba_sync</refname>
<refpurpose>Synchronize database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dba_sync</function></funcdef>
<paramdef>int <parameter>handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>dba_sync</function> synchronizes the database specified by
<parameter>handle</parameter>. This will probably trigger a physical write
to disk, if supported.
</para>
<para>
<parameter>handle</parameter> is a database handle returned by
<function>dba_open</function>.
</para>
<para>
<function>dba_sync</function> returns true or false, if the
synchronization succeeds or fails, respectively.
</para>
<para>
See also: <function>dba_optimize</function>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/dbase.xml
+++ phpdoc/nl/functions/dbase.xml
<reference id="ref.dbase">
<title>dBase functions</title>
<titleabbrev>dBase</titleabbrev>
<partintro>
<simpara>
These functions allow you to access records stored in dBase-format
(dbf) databases.
</simpara>
<simpara>
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.
</simpara>
<simpara>
Unlike SQL databases, dBase "databases" cannot change the database
definition afterwards. Once the file is created, the database
definition is fixed. There are no indexes that speed searching or
otherwise organize your data. 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
<function>dbase_pack()</function>.
</simpara>
<simpara>
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, since the
file format is commonly understood with Windows spreadsheets and
organizers. Import and export of data is about all that dBase
support is good for.
</simpara>
</partintro>
<refentry id="function.dbase-create">
<refnamediv>
<refname>dbase_create</refname>
<refpurpose>Creates a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dbase_create</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>array <parameter>fields</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <parameter>fields</parameter> 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.
</para>
<para>
The types of fields available are:
<variablelist>
<varlistentry>
<term>L</term>
<listitem>
<simpara>
Boolean. These do not have a length or precision.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>M</term>
<listitem>
<simpara>
Memo. (Note that these aren't supported by PHP.) These do
not have a length or precision.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>D</term>
<listitem>
<simpara>
Date (stored as YYYYMMDD). These do not have a length or
precision.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>N</term>
<listitem>
<simpara>
Number. These have both a length and a precision (the number
of digits after the decimal point).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>C</term>
<listitem>
<simpara>
String.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If the database is successfully created, a dbase_identifier is
returned, otherwise false is returned.
<example>
<title>Creating a dBase database file</title>
<programlisting role="php">
// "database" name
$dbname = "/tmp/test.dbf";
// database "definition"
$def =
array(
array("date", "D"),
array("name", "C", 50),
array("age", "N", 3, 0),
array("email", "C", 128),
array("ismember", "L")
);
// creation
if (!dbase_create($dbname, $def))
print "<strong>Error!</strong>";
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-open">
<refnamediv>
<refname>dbase_open</refname>
<refpurpose>Opens a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dbase_open</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The flags correspond to those for the open() system call.
(Typically 0 means read-only, 1 means write-only, and 2 means
read and write.)
</para>
<para>
Returns a dbase_identifier for the opened database, or false if
the database couldn't be opened.
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-close">
<refnamediv>
<refname>dbase_close</refname>
<refpurpose>Close a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbase_close</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Closes the database associated with
<parameter>dbase_identifier</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-pack">
<refnamediv>
<refname>dbase_pack</refname>
<refpurpose>Packs a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbase_pack</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Packs the specified database (permanently deleting all records
marked for deletion using
<function>dbase_delete_record</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-add-record">
<refnamediv>
<refname>dbase_add_record</refname>
<refpurpose>Add a record to a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbase_add_record</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>array <parameter>record</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Adds the data in the <parameter>record </parameter>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.
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-replace-record">
<refnamediv>
<refname>dbase_replace_record</refname>
<refpurpose>Replace a record in a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbase_replace_record</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>array <parameter>record</parameter></paramdef>
<paramdef>int <parameter>dbase_record_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Replaces the data associated with the record
<parameter>record_number</parameter> with the data in the
<parameter>record</parameter> 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.
</simpara>
<simpara>
<parameter>dbase_record_number</parameter> is an integer which
spans from 1 to the number of records in the database (as
returned by <function>dbase_numrecords</function>).
</simpara>
</refsect1>
</refentry>
<refentry id="function.dbase-delete-record">
<refnamediv>
<refname>dbase_delete_record</refname>
<refpurpose>Deletes a record from a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbase_delete_record</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>int <parameter>record</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Marks <parameter>record</parameter> to be deleted from the
database. To actually remove the record from the database, you
must also call <function>dbase_pack</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-get-record">
<refnamediv>
<refname>dbase_get_record</refname>
<refpurpose>Gets a record from a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>dbase_get_record</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>int <parameter>record</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the data from <parameter>record</parameter> 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
<function>dbase_delete_record</function>.
</para>
<para>
Each field is converted to the appropriate PHP type. (Dates are
left as strings.)
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-get-record-with-names">
<refnamediv>
<refname>dbase_get_record_with_names</refname>
<refpurpose>
Gets a record from a dBase database as an associative array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array
<function>dbase_get_record_with_names</function>
</funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>int <parameter>record</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the data from <parameter>record</parameter> 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 <function>dbase_delete_record</function>.
</para>
<para>
Each field is converted to the appropriate PHP type. (Dates are
left as strings.)
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-numfields">
<refnamediv>
<refname>dbase_numfields</refname>
<refpurpose>
Find out how many fields are in a dBase database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dbase_numfields</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of fields (columns) in the specified
database. Field numbers are between 0 and dbase_numfields($db)-1,
while record numbers are between 1 and dbase_numrecords($db).
<example>
<title>Using <function>dbase_numfields</function></title>
<programlisting role="php">
$rec = dbase_get_record($db, $recno);
$nf = dbase_numfields($db);
for ($i=0; $i < $nf; $i++) {
print $rec[$i]."<br>\n";
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.dbase-numrecords">
<refnamediv>
<refname>dbase_numrecords</refname>
<refpurpose>
Find out how many records are in a dBase database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dbase_numrecords</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/dbm.xml
+++ phpdoc/nl/functions/dbm.xml
<reference id="ref.dbm">
<title>DBM Functions</title>
<titleabbrev>DBM</titleabbrev>
<partintro>
<simpara>
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).
</simpara>
<para>
<example>
<title>DBM example</title>
<programlisting role="php">
$dbm = dbmopen ("lastseen", "w");
if (dbmexists ($dbm, $userid)) {
$last_seen = dbmfetch ($dbm, $userid);
} else {
dbminsert ($dbm, $userid, time());
}
do_stuff();
dbmreplace ($dbm, $userid, time());
dbmclose ($dbm);
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.dbmopen">
<refnamediv>
<refname>dbmopen</refname>
<refpurpose>Opens a DBM database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dbmopen</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>string <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
Returns an identifer to be passed to the other DBM functions on
success, or false on failure.
</para>
<para>
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>filename.db</filename> 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
<filename>.lck</filename> 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
<ulink url="&url.gdbm;">GNU's GDBM</ulink>.
</para>
</refsect1>
</refentry>
<refentry id="function.dbmclose">
<refnamediv>
<refname>dbmclose</refname>
<refpurpose>Closes a dbm database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbmclose</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Unlocks and closes the specified database.
</para>
</refsect1>
</refentry>
<refentry id="function.dbmexists">
<refnamediv>
<refname>dbmexists</refname>
<refpurpose>
Tells if a value exists for a key in a DBM database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbmexists</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns TRUE if there is a value associated with the
<parameter>key</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.dbmfetch">
<refnamediv>
<refname>dbmfetch</refname>
<refpurpose>
Fetches a value for a key from a DBM database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dbmfetch</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the value associated with <parameter>key</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.dbminsert">
<refnamediv>
<refname>dbminsert</refname>
<refpurpose>
Inserts a value for a key in a DBM database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dbminsert</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Adds the value to the database with the specified key.
</para>
<para>
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 <function>dbmreplace</function>.)
</para>
</refsect1>
</refentry>
<refentry id="function.dbmreplace">
<refnamediv>
<refname>dbmreplace</refname>
<refpurpose>
Replaces the value for a key in a DBM database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbmreplace</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Replaces the value for the specified key in the database.
</para>
<para>
This will also add the key to the database if it didn't already
exist.
</para>
</refsect1>
</refentry>
<refentry id="function.dbmdelete">
<refnamediv>
<refname>dbmdelete</refname>
<refpurpose>
Deletes the value for a key from a DBM database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>dbmdelete</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes the value for <parameter>key</parameter> in the database.
</para>
<para>
Returns false if the key didn't exist in the database.
</para>
</refsect1>
</refentry>
<refentry id="function.dbmfirstkey">
<refnamediv>
<refname>dbmfirstkey</refname>
<refpurpose>
Retrieves the first key from a DBM database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dbmfirstkey</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.dbmnextkey">
<refnamediv>
<refname>dbmnextkey</refname>
<refpurpose>
Retrieves the next key from a DBM database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dbmnextkey</function></funcdef>
<paramdef>int <parameter>dbm_identifier</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the next key after <parameter>key</parameter>. By calling
<function>dbmfirstkey</function> followed by successive
calls to <function>dbmnextkey</function> it is possible to
visit every key/value pair in the dbm database. For example:
<example>
<title>Visiting every key/value pair in a DBM database</title>
<programlisting role="php">
$key = dbmfirstkey ($dbm_id);
while ($key) {
echo "$key = " . dbmfetch ($dbm_id, $key) . "\n";
$key = dbmnextkey ($dbm_id, $key);
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.dblist">
<refnamediv>
<refname>dblist</refname>
<refpurpose>
Describes the DBM-compatible library being used
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dblist</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/dir.xml
+++ phpdoc/nl/functions/dir.xml
<reference id="ref.dir">
<title>Directory functions</title>
<titleabbrev>Directories</titleabbrev>
<refentry id="function.chdir">
<refnamediv>
<refname>chdir</refname>
<refpurpose>change directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>chdir</function></funcdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Changes PHP's current directory to
<parameter>directory</parameter>. Returns FALSE if unable to
change directory, TRUE otherwise.
</para>
</refsect1>
</refentry>
<refentry id="class.dir">
<refnamediv>
<refname>dir</refname>
<refpurpose>directory class</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>new <function>dir</function></funcdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
A pseudo-object oriented mechanism for reading a directory. The
given <parameter>directory</parameter> is opened. Two properties
are available once directory has been opened. The handle
property can be used with other directory functions such as
<function>readdir</function>, <function>rewinddir</function> and
<function>closedir</function>. The path property is set to path
the directory that was opened. Three methods are available:
read, rewind and close.
<example>
<title><function>Dir</function> Example</title>
<programlisting role="php">
$d = dir("/etc");
echo "Handle: ".$d->handle."<br>\n";
echo "Path: ".$d->path."<br>\n";
while($entry=$d->read()) {
echo $entry."<br>\n";
}
$d->close();
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.closedir">
<refnamediv>
<refname>closedir</refname>
<refpurpose>close directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>closedir</function></funcdef>
<paramdef>int <parameter>dir_handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Closes the directory stream indicated by
<parameter>dir_handle</parameter>. The stream must have previously
been opened by <function>opendir</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getcwd">
<refnamediv>
<refname>getcwd</refname>
<refpurpose>gets the current working directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>getcwd</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Returns the current working directory.
</para>
</refsect1>
</refentry>
<refentry id="function.opendir">
<refnamediv>
<refname>opendir</refname>
<refpurpose>open directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>opendir</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a directory handle to be used in subsequent
<function>closedir</function>, <function>readdir</function>, and
<function>rewinddir</function> calls.
</para>
</refsect1>
</refentry>
<refentry id="function.readdir">
<refnamediv>
<refname>readdir</refname>
<refpurpose>read entry from directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>readdir</function></funcdef>
<paramdef>int <parameter>dir_handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the filename of the next file from the directory. The
filenames are not returned in any particular order.
<example>
<title>List all files in the current directory</title>
<programlisting role="php">
// Note that !== did not exist until 4.0.0-RC2
<?php
$handle=opendir('.');
echo "Directory handle: $handle\n";
echo "Files:\n";
while (($file = readdir($handle))!==false) {
echo "$file\n";
}
closedir($handle);
?>
</programlisting>
</example>
</para>
<para>
Note that <function>readdir</function> will return the . and
.. entries. If you don't want these, simply strip them out:
<example>
<title>
List all files in the current directory and strip out . and
..
</title>
<programlisting role="php">
<?php
$handle=opendir('.');
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.rewinddir">
<refnamediv>
<refname>rewinddir</refname>
<refpurpose>rewind directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>rewinddir</function></funcdef>
<paramdef>int <parameter>dir_handle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Resets the directory stream indicated by
<parameter>dir_handle</parameter> to the beginning of the
directory.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/dl.xml
+++ phpdoc/nl/functions/dl.xml
<reference id="ref.dl">
<title>Dynamic Loading functions</title>
<titleabbrev>Dyn.loading</titleabbrev>
<refentry id="function.dl">
<refnamediv>
<refname>dl</refname>
<refpurpose>load a PHP extension at runtime</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dl</function></funcdef>
<paramdef>string <parameter>library</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Loads the PHP extension defined in
<parameter>library</parameter>. See also the <link
linkend="ini.extension-dir">extension_dir</link> configuration
directive.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/domxml.xml
+++ phpdoc/nl/functions/domxml.xml
<reference id="ref.domxml">
<title>DOM XML functions</title>
<titleabbrev>DOM XML</titleabbrev>
<partintro>
<simpara>
These functions are only available if PHP was configured with
<option role="configure">--with-dom=[DIR]</option>, using the
GNOME xml library. You will need at least libxml-2.0.0 (the beta
version will not work). These functions have been added in PHP 4.
</simpara>
<simpara>
This module defines the following constants:
</simpara>
<table>
<title>XML constants</title>
<tgroup cols="3">
<thead>
<row>
<entry>Constant</entry>
<entry>Value</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>XML_ELEMENT_NODE</entry>
<entry>1</entry>
<entry></entry>
</row>
<row>
<entry>XML_ATTRIBUTE_NODE</entry>
<entry>2</entry>
<entry></entry>
</row>
<row>
<entry>XML_TEXT_NODE</entry>
<entry>3</entry>
<entry></entry>
</row>
<row>
<entry>XML_CDATA_SECTION_NODE</entry>
<entry>4</entry>
<entry></entry>
</row>
<row>
<entry>XML_ENTITY_REF_NODE</entry>
<entry>5</entry>
<entry></entry>
</row>
<row>
<entry>XML_ENTITY_NODE</entry>
<entry>6</entry>
<entry></entry>
</row>
<row>
<entry>XML_PI_NODE</entry>
<entry>7</entry>
<entry></entry>
</row>
<row>
<entry>XML_COMMENT_NODE</entry>
<entry>8</entry>
<entry></entry>
</row>
<row>
<entry>XML_DOCUMENT_NODE</entry>
<entry>9</entry>
<entry></entry>
</row>
<row>
<entry>XML_DOCUMENT_TYPE_NODE</entry>
<entry>10</entry>
<entry></entry>
</row>
<row>
<entry>XML_DOCUMENT_FRAG_NODE</entry>
<entry>11</entry>
<entry></entry>
</row>
<row>
<entry>XML_NOTATION_NODE</entry>
<entry>12</entry>
<entry></entry>
</row>
<row>
<entry>XML_GLOBAL_NAMESPACE</entry>
<entry>1</entry>
<entry></entry>
</row>
<row>
<entry>XML_LOCAL_NAMESPACE</entry>
<entry>2</entry>
<entry></entry>
</row>
</tbody>
</tgroup>
</table>
<simpara>
This module defines a number of classes. The DOM XML functions
return a parsed tree of the XML document with each node being an
object belonging to one of these classes.
</simpara>
</partintro>
<!-- class Dom document -->
<!-- has member functions
array root([int doc_handle])
returns array of root nodes of this document. Array
elements are objects of class "Dom node" having properties of
"node" (resource), "type" (long), "name" (string)
and optionally "content" (string).
array children([ int node ])
returns an array of child nodes of this element. Array
elements are objects of class "Dom node" having properties
of "node" (resource), "type" (long), "name" (string)
and optionally "content" (string).
object add_root([int doc_handle,] string name)
Add a root node to document.
returns an object of class "Dom node" having properties
of "node" (resource), "type" (long), "name" (string)
and optionally "content" (string).
object intdtd([int doc_handle])
returns the DTD of document.
returns an object of class "Dtd" having properties
of "dtd" (resource), "sysid" (string), "name" (string)
and optionally "extid" (string).
string dumpmem([int doc_handle])
dumps document into string.
-->
<!-- class Dom node
object lastchild([int node])
returns Dom node object
array children([int node])
as above
object parent([ int node])
returns Dom node object
(parent of this node)
new_child
string getattr([int node,] string attrname)
get value of attribute named attrname
bool setattr([int node,] string attrname, string value)
set value of given attribute.
array attributes([int node])
returns associative array of (string name, string value)
pairs.
object node(string name)
creates a named Dom node object.
-->
<!-- class Dom Attribute
name
-->
<!-- class Dom Namespace
-->
<!-- class Dtd
-->
<refentry id="function.xmldoc">
<refnamediv>
<refname>xmldoc</refname>
<refpurpose>Creates a DOM object of an XML document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>xmldoc</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function parses the XML document in
<parameter>str</parameter> and returns an object of class "Dom
document", having the properties "doc" (resource), "version"
(string) and "type" (long).
</para>
</refsect1>
</refentry>
<refentry id="function.xmldocfile">
<refnamediv>
<refname>xmldocfile</refname>
<refpurpose>Creates a DOM object from XML file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>xmldocfile</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function parses the XML document in the file named
<parameter>filename</parameter> and returns an object of class
"Dom document", having the properties "doc" (resource), "version"
(string).
<!-- conspiciously the file attribute is missing? -->
</para>
</refsect1>
</refentry>
<refentry id="function.xmltree">
<refnamediv>
<refname>xmltree</refname>
<refpurpose>
Creates a tree of php objects from XML document
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>xmltree</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function parses the XML document in
<parameter>str</parameter> and returns a tree PHP objects as the
parsed document.
</para>
</refsect1>
</refentry>
</reference>
<!--
TODO
domxml_root
domxml_add_root
domxml_dumpmem
domxml_attributes
domxml_getattr
domxml_setattr
domxml_children
domxml_new_child
domxml_node
domxml_new_xmldoc alias new_xmldoc
-->
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/errorfunc.xml
+++ phpdoc/nl/functions/errorfunc.xml
<reference id="ref.errorfunc">
<title>Error Handling and Logging Functions</title>
<titleabbrev>Errors and Logging</titleabbrev>
<partintro>
<para>
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.
</para>
<para>
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.
</para>
<para>
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.
</para>
</partintro>
<refentry id="function.error-log">
<refnamediv>
<refname>error_log</refname>
<refpurpose>send an error message somewhere</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>error_log</function></funcdef>
<paramdef>string <parameter>message</parameter></paramdef>
<paramdef>int <parameter>message_type</parameter></paramdef>
<paramdef>string
<parameter><optional>destination</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>extra_headers</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sends an error message to the web server's error log, a
<acronym>TCP</acronym> port or to a file. The first parameter,
<parameter>message</parameter>, is the error message that should
be logged. The second parameter,
<parameter>message_type</parameter> says where the message should
go:
<table>
<title><function>error_log</function> log types</title>
<tgroup cols="2">
<tbody>
<row>
<entry>0</entry>
<entry>
<parameter>message</parameter> is sent to PHP's system
logger, using the Operating System's system logging
mechanism or a file, depending on what the <link
linkend="ini.error-log">error_log</link> configuration
directive is set to.
</entry>
</row>
<row>
<entry>1</entry>
<entry>
<parameter>message</parameter> is sent by email to the
address in the <parameter>destination</parameter> parameter.
This is the only message type where the fourth parameter,
<parameter>extra_headers</parameter> is used. This message
type uses the same internal function as
<function>Mail</function> does.
</entry>
</row>
<row>
<entry>2</entry>
<entry>
<parameter>message</parameter> is sent through the PHP debugging
connection. This option is only available if <link
linkend="install.configure.enable-debugger">remote debugging has
been enabled</link>. In this case, the
<parameter>destination</parameter> parameter specifies the host
name or IP address and optionally, port number, of the socket
receiving the debug information.
</entry>
</row>
<row>
<entry>3</entry>
<entry>
<parameter>message</parameter> is appended to the file
<parameter>destination</parameter>.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<example role="php">
<title><function>error_log</function> examples</title>
<programlisting role="php">
// Send notification through the server log if we can not
// connect to the database.
if (!Ora_Logon ($username, $password)) {
error_log ("Oracle database not available!", 0);
}
// Notify administrator by email if we run out of FOO
if (!($foo = allocate_new_foo()) {
error_log ("Big trouble, we're all out of FOOs!", 1,
"operator@mydomain.com");
}
// other ways of calling error_log():
error_log ("You messed up!", 2, "127.0.0.1:7000");
error_log ("You messed up!", 2, "loghost");
error_log ("You messed up!", 3, "/var/tmp/my-errors.log");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.error-reporting">
<refnamediv>
<refname>error_reporting</refname>
<refpurpose>set which PHP errors are reported</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>error_reporting</function></funcdef>
<paramdef>int
<parameter><optional>level</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets PHP's error reporting level and returns the old level. The
error reporting level is either a bitmask, or named constant. 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.
<example role="php">
<title>Error Integer changes</title>
<programlisting role="php">
error_reporting (55); // PHP 3 equivalent to E_ALL ^ E_NOTICE
/* ...in PHP 4, '55' would mean (E_ERROR | E_WARNING | E_PARSE |
E_CORE_ERROR | E_CORE_WARNING) */
error_reporting (2039); // PHP 4 equivalent to E_ALL ^ E_NOTICE
error_reporting (E_ALL ^ E_NOTICE); // The same in both PHP 3 and 4
</programlisting>
</example>
Follow the links for the internal values to get their meanings:
<table>
<title><function>error_reporting</function> bit values</title>
<tgroup cols="2">
<thead>
<row>
<entry>constant</entry>
<entry>value</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>
<link linkend="internal.e-error">E_ERROR</link>
</entry>
</row>
<row>
<entry>2</entry>
<entry>
<link linkend="internal.e-warning">E_WARNING</link>
</entry>
</row>
<row>
<entry>4</entry>
<entry>
<link linkend="internal.e-parse">E_PARSE</link>
</entry>
</row>
<row>
<entry>8</entry>
<entry>
<link linkend="internal.e-notice">E_NOTICE</link>
</entry>
</row>
<row>
<entry>16</entry>
<entry>
<link linkend="internal.e-core-error">E_CORE_ERROR</link>
</entry>
</row>
<row>
<entry>32</entry>
<entry>
<link linkend="internal.e-core-warning">E_CORE_WARNING</link>
</entry>
</row>
<row>
<entry>64</entry>
<entry>
<link linkend="internal.e-compile-error">E_COMPILE_ERROR</link>
</entry>
</row>
<row>
<entry>128</entry>
<entry>
<link linkend="internal.e-compile-warning">E_COMPILE_WARNING</link>
</entry>
</row>
<row>
<entry>256</entry>
<entry>
<link linkend="internal.e-user-error">E_USER_ERROR</link>
</entry>
</row>
<row>
<entry>512</entry>
<entry>
<link linkend="internal.e-user-warning">E_USER_WARNING</link>
</entry>
</row>
<row>
<entry>1024</entry>
<entry>
<link linkend="internal.e-user-error">E_USER_NOTICE</link>
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<example role="php">
<title><function>error_reporting</function> examples</title>
<programlisting role="php">
error_reporting(0);
/* Turn off all reporting */
error_reporting (7); // Old syntax, PHP 2/3
error_reporting (E_ERROR | E_WARNING | E_PARSE); // New syntax for PHP 3/4
/* Good to use for simple running errors */
error_reporting (15); // Old syntax, PHP 2/3
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // New syntax for PHP 3/4
/* good for code authoring to report uninitialized or (possibly mis-spelled) variables */
error_reporting (63); // Old syntax, PHP 2/3
error_reporting (E_ALL); // New syntax for PHP 3/4
/* report all PHP errors */
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.restore-error-handler">
<refnamediv>
<refname>restore_error_handler</refname>
<refpurpose>
Restores the previous error handler function
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>restore_error_handler</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Used after changing the error handler function using
<function>set_error_handler</function>, to revert to the previous error
handler (which could be the built-in or a user defined function)
</para>
<para>
See also <function>error_reporting</function>,
<function>set_error_handler</function>,
<function>trigger_error</function>, <function>user_error</function>
</para>
</refsect1>
</refentry>
<refentry id="function.set-error-handler">
<refnamediv>
<refname>set_error_handler</refname>
<refpurpose>
Sets a user-defined error handler function.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>set_error_handler</function></funcdef>
<paramdef>string <parameter>error_handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets a user function (<parameter>error_handler</parameter>) 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
<function>trigger_error</function>)
</para>
<para>
The user function needs to accept 2 parameters: the error code, and a
string describing the error. The example below shows the handling of
internal execptions by triggering errors and handling them with a user
defined function:
<example>
<title>
Error handling with <function>set_error_handler</function> and
<function>trigger_error</function>
</title>
<programlisting role="php">
<?php
// redefine the user error constants - PHP 4 only
define (FATAL,E_USER_ERROR);
define (ERROR,E_USER_WARNING);
define (WARNING,E_USER_NOTICE);
// set the error reporting level for this script
error_reporting (FATAL + ERROR + WARNING);
// error handler function
function myErrorHandler ($errno, $errstr) {
switch ($errno) {
case FATAL:
echo "<b>FATAL</b> [$errno]
$errstr<br>\n";
echo " Fatal error in line ".__LINE__." of file ".__FILE__;
echo ", PHP ".PHP_VERSION."
(".PHP_OS.")<br>\n";
echo "Aborting...<br>\n";
exit -1;
break;
case ERROR:
echo "<b>ERROR</b> [$errno]
$errstr<br>\n";
break;
case WARNING:
echo "<b>WARNING</b> [$errno]
$errstr<br>\n";
break;
default:
echo "Unkown error type: [$errno] $errstr<br>\n";
break;
}
}
// function to test the error handling
function scale_by_log ($vect, $scale) {
if ( !is_numeric($scale) || $scale <= 0 )
trigger_error("log(x) for x <= 0 is undefined, you used: scale =
$scale",
FATAL);
if (!is_array($vect)) {
trigger_error("Incorrect input vector, array of values expected", ERROR);
return null;
}
for ($i=0; $i<count($vect); $i++) {
if (!is_numeric($vect[$i]))
trigger_error("Value at position $i is not a number, using 0 (zero)",
WARNING);
$temp[$i] = log($scale) * $vect[$i];
}
return $temp;
}
// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");
// trigger some errors, first define a mixed array with a non-numeric item
echo "vector a\n";
$a = array(2,3,"foo",5.5,43.3,21.11);
print_r($a);
// now generate second array, generating a warning
echo "----\nvector b - a warning (b = log(PI) * a)\n";
$b = scale_by_log($a, M_PI);
print_r($b);
// this is trouble, we pass a string instead of an array
echo "----\nvector c - an error\n";
$c = scale_by_log("not array",2.3);
var_dump($c);
// this is a critical error, log of zero or negative number is undefined
echo "----\nvector d - fatal error\n";
$d = scale_by_log($a, -2.5);
?>
</programlisting>
</example>
And when you run this sample script, the output will be
<informalexample>
<programlisting>
vector a
Array
(
[0] => 2
[1] => 3
[2] => foo
[3] => 5.5
[4] => 43.3
[5] => 21.11
)
----
vector b - a warning (b = log(PI) * a)
<b>WARNING</b> [1024] Value at position 2 is not a number, using 0
(zero)<br>
Array
(
[0] => 2.2894597716988
[1] => 3.4341896575482
[2] => 0
[3] => 6.2960143721717
[4] => 49.566804057279
[5] => 24.165247890281
)
----
vector c - an error
<b>ERROR</b> [512] Incorrect input vector, array of values
expected<br>
NULL
----
vector d - fatal error
<b>FATAL</b> [256] log(x) for x <= 0 is undefined, you used:
scale = -2.5<br>
Fatal error in line 16 of file trigger_error.php, PHP 4.0.1pl2 (Linux)<br>
Aborting...<br>
</programlisting>
</informalexample>
</para>
<para>
See also <function>error_reporting</function>,
<function>restore_error_handler</function>,
<function>trigger_error</function>, <function>user_error</function>
</para>
</refsect1>
</refentry>
<refentry id="function.trigger-error">
<refnamediv>
<refname>trigger_error</refname>
<refpurpose>
Generates a user-level error/warning/notice message
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>trigger_error</function></funcdef>
<paramdef>string <parameter>error_msg</parameter></paramdef>
<paramdef>int
<parameter><optional>error_type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
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
(<function>set_error_handler</function>). This function is useful when
you need to generate a particular response to an exception at runtime.
For example:
<informalexample>
<programlisting>
if (assert ($divisor == 0))
trigger_error ("Cannot divide by zero", E_USER_ERROR);
</programlisting>
</informalexample>
<note>
<para>
See <function>set_error_handler</function> for a more extensive example.
</para>
</note>
</para>
<para>
See also <function>error_reporting</function>,
<function>set_error_handler</function>,
<function>restore_error_handler</function>,
<function>user_error</function>
</para>
</refsect1>
</refentry>
<refentry id="function.user-error">
<refnamediv>
<refname>user_error</refname>
<refpurpose>
Generates a user-level error/warning/notice message
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>user_error</function></funcdef>
<paramdef>string <parameter>error_msg</parameter></paramdef>
<paramdef>int
<parameter><optional>error_type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This is an alias for the function <function>trigger_error</function>.
</para>
<para>
See also <function>error_reporting</function>,
<function>set_error_handler</function>,
<function>restore_error_handler</function>, and
<function>trigger_error</function>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/exec.xml
+++ phpdoc/nl/functions/exec.xml
<reference id="ref.exec">
<title>Program Execution functions</title>
<titleabbrev>Program Execution</titleabbrev>
<refentry id="function.escapeshellarg">
<refnamediv>
<refname>escapeshellarg</refname>
<refpurpose>escape a string to be used as a shell argument</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>escapeshellarg</function></funcdef>
<paramdef>string <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>EscapeShellArg</function> 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 <function>exec</function>, <function>system</function> and the
<link linkend="language.operators.execution">backtick operator</link>.
A standard use would be:</para>
<para>
<informalexample>
<programlisting role="php">
system("ls ".EscapeShellArg($dir))
</programlisting>
</informalexample>
</para>
<para>
See also <function>exec</function>, <function>popen</function>,
<function>system</function>, and the <link
linkend="language.operators.execution">backtick operator</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.escapeshellcmd">
<refnamediv>
<refname>escapeshellcmd</refname>
<refpurpose>escape shell metacharacters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>escapeshellcmd</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>EscapeShellCmd</function> 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 <function>exec</function> or
<function>system</function> functions, or to the <link
linkend="language.operators.execution">backtick
operator</link>. A standard use would be:</para>
<para>
<informalexample>
<programlisting role="php">
$e = EscapeShellCmd($userinput);
system("echo $e"); // here we don't care if $e has spaces
$f = EscapeShellCmd($filename);
system("touch \"/tmp/$f\"; ls -l \"/tmp/$f\""); // and here we do, so
we use quotes
</programlisting>
</informalexample>
</para>
<para>
See also <function>escapeshellarg</function>,
<function>exec</function>,
<function>popen</function>, <function>system</function>, and the <link
linkend="language.operators.execution">backtick operator</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.exec">
<refnamediv>
<refname>exec</refname>
<refpurpose>Execute an external program</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>exec</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
<paramdef>string
<parameter><optional>array</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter><optional>return_var</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>exec</function> executes the given
<parameter>command</parameter>, 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 <function>PassThru</function> function.
</para>
<para>
If the <parameter>array</parameter> argument is present, then the
specified array will be filled with every line of output from the
command. Note that if the array already contains some elements,
<function>exec</function> will append to the end of the array.
If you do not want the function to append elements, call
<function>unset</function> on the array before passing it to
<function>exec</function>.
</para>
<para>
If the <parameter>return_var</parameter> argument is present
along with the <parameter>array</parameter> argument, then the
return status of the executed command will be written to this
variable.
</para>
<para>
Note that if you are going to allow data coming from user input
to be passed to this function, then you should be using
<function>EscapeShellCmd</function> to make sure that users
cannot trick the system into executing arbitrary commands.
</para>
<para>
Note also that 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.
</para>
<para>
See also <function>system</function>,
<function>PassThru</function>, <function>popen</function>,
<function>EscapeShellCmd</function>, and the <link
linkend="language.operators.execution">backtick operator</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.passthru">
<refnamediv>
<refname>passthru</refname>
<refpurpose>
Execute an external program and display raw output
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>passthru</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
<paramdef>int
<parameter><optional>return_var</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>passthru</function> function is similar to the
<function>Exec</function> function in that it executes a
<parameter>command</parameter>. If the
<parameter>return_var</parameter> argument is present, the return
status of the Unix command will be placed here. This function
should be used in place of <function>Exec</function> or
<function>System</function> 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 <emphasis>image/gif</emphasis> and
then calling a pbmplus program to output a gif, you can create
PHP scripts that output images directly.</para>
<para>
Note that 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.
</para>
<para>
See also <function>exec</function>, <function>system</function>,
<function>popen</function>, <function>EscapeShellCmd</function>,
and the <link linkend="language.operators.execution">backtick
operator</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.system">
<refnamediv>
<refname>system</refname>
<refpurpose>Execute an external program and display output</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>system</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
<paramdef>int
<parameter><optional>return_var</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>System</function> is just like the C version of the
function in that it executes the given
<parameter>command</parameter> 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.
</para>
<para>
Note, that if you are going to allow data coming from user input
to be passed to this function, then you should be using the
<function>EscapeShellCmd</function> function to make sure that
users cannot trick the system into executing arbitrary
commands.
</para>
<para>
Note also that 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.
</para>
<para>
The <function>System</function> 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.
</para>
<para>
Returns the last line of the command output on success, and false
on failure.
</para>
<para>
If you need to execute a command and have all the data from the
command passed directly back without any interference, use the
<function>PassThru</function> function.
</para>
<para>
See also <function>exec</function>,
<function>PassThru</function>, <function>popen</function>,
<function>EscapeShellCmd</function>, and the <link
linkend="language.operators.execution">backtick operator</link>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/fdf.xml
+++ phpdoc/nl/functions/fdf.xml
<reference id="ref.fdf">
<title>Forms Data Format functions</title>
<titleabbrev>FDF</titleabbrev>
<partintro>
<simpara>
Forms Data Format (FDF) is a format for handling
forms within PDF documents. You should read the documentation at
<ulink url="&spec.pdf.fdf;">&spec.pdf.fdf;</ulink>
for more information on what FDF is and how it is used in general.
</simpara>
<note><simpara>
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. They should be in fdftk-dir/include and
fdftk-dir/lib. This will not be the case if you just unpack
the FdfTk distribution.
</simpara></note>
<simpara>
The general idea of FDF is similar to HTML forms. The diffence 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
(<function>fdf_create</function>) set the values of each input field
(<function>fdf_set_value</function>) and associate it with a PDF form
(<function>fdf_set_file</function>). Finally it has to be sent to the
browser with MimeType <literal>application/vnd.fdf</literal>. The Acrobat
reader plugin of your browser recognizes the MimeType, reads the
associated PDF form and fills in the data from the FDF document.
</simpara>
<simpara>
If you look at an FDF-document with a text editor you will find a
catalogue object with the name <literal>FDF</literal>. Such an object may
contain a number of entries like <literal>Fields</literal>,
<literal>F</literal>, <literal>Status</literal> etc..
The most commonly used entries are <literal>Fields</literal> whicht points
to a list of input fields, and <literal>F</literal> which contains the
filename of the PDF-document this data belongs to. Those entries are
referred to in the FDF documention as /F-Key or /Status-Key.
Modifying this entries
is done by functions like <function>fdf_set_file</function> and
<function>fdf_set_status</function>. Fields are modified with
<function>fdf_set_value</function>, <function>fdf_set_opt</function>
etc..
</simpara>
<simpara>
The following examples shows just the evaluation of form data.</simpara>
<simpara></simpara>
<example>
<title>Evaluating a FDF document</title>
<programlisting>
<?php
// Save the FDF data into a temp file
$fdffp = fopen("test.fdf", "w");
fwrite($fdffp, $HTTP_FDF_DATA, strlen($HTTP_FDF_DATA));
fclose($fdffp);
// Open temp file and evaluate data
// The pdf form contained several input text fields with the names
// volume, date, comment, publisher, preparer, and two checkboxes
// show_publisher and show_preparer.
$fdf = fdf_open("test.fdf");
$volume = fdf_get_value($fdf, "volume");
echo "The volume field has the value
'<B>$volume</B>'<BR>";
$date = fdf_get_value($fdf, "date");
echo "The date field has the value
'<B>$date</B>'<BR>";
$comment = fdf_get_value($fdf, "comment");
echo "The comment field has the value
'<B>$comment</B>'<BR>";
if(fdf_get_value($fdf, "show_publisher") == "On") {
$publisher = fdf_get_value($fdf, "publisher");
echo "The publisher field has the value
'<B>$publisher</B>'<BR>";
} else
echo "Publisher shall not be shown.<BR>";
if(fdf_get_value($fdf, "show_preparer") == "On") {
$preparer = fdf_get_value($fdf, "preparer");
echo "The preparer field has the value
'<B>$preparer</B>'<BR>";
} else
echo "Preparer shall not be shown.<BR>";
fdf_close($fdf);
?>
</programlisting>
</example>
</partintro>
<refentry id="function.fdf-open">
<refnamediv>
<refname>fdf_open</refname>
<refpurpose>Open a FDF document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fdf_open</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_open</function> function opens
a file with form data. This file must contain the data as returned
from a PDF form. Currently, the file has to be created 'manually'
by using <function>fopen</function> and writing the content
of HTTP_FDF_DATA with <function>fwrite</function> into it.
A mechanism like for HTML form data where for each input
field a variable is created does not exist.</para>
<para>
<example>
<title>Accessing the form data</title>
<programlisting>
<?php
// Save the FDF data into a temp file
$fdffp = fopen("test.fdf", "w");
fwrite($fdffp, $HTTP_FDF_DATA, strlen($HTTP_FDF_DATA));
fclose($fdffp);
// Open temp file and evaluate data
$fdf = fdf_open("test.fdf");
..
fdf_close($fdf);
?>
</programlisting>
</example></para>
<para>
See also <function>fdf_close</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-close">
<refnamediv>
<refname>fdf_close</refname>
<refpurpose>Close an FDF document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_close</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_close</function> function closes the FDF document.</para>
<para>
See also <function>fdf_open</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-create">
<refnamediv>
<refname>fdf_create</refname>
<refpurpose>Create a new FDF document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fdf_create</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_create</function> creates a new
FDF document. This function is needed if one would like to
populate input fields in a PDF document with data.</para>
<para>
<example>
<title>Populating a PDF document</title>
<programlisting>
<?php
$outfdf = fdf_create();
fdf_set_value($outfdf, "volume", $volume, 0);
fdf_set_file($outfdf, "http:/testfdf/resultlabel.pdf");
fdf_save($outfdf, "outtest.fdf");
fdf_close($outfdf);
Header("Content-type: application/vnd.fdf");
$fp = fopen("outtest.fdf", "r");
fpassthru($fp);
unlink("outtest.fdf");
?>
</programlisting>
</example></para>
<para>
See also <function>fdf_close</function>,
<function>fdf_save</function>,
<function>fdf_open</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-save">
<refnamediv>
<refname>fdf_save</refname>
<refpurpose>Save a FDF document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fdf_save</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_save</function> function saves
a FDF document.
The FDF Toolkit provides a way to output the document to stdout if
the parameter <parameter>filename</parameter>
is '.'. This does not work if PHP is used as an apache module.
In such a case one will have to write to a file and use e.g.
<function>fpassthru</function>. to output it.</para>
<para>
See also <function>fdf_close</function> and example for
<function>fdf_create</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-get-value">
<refnamediv>
<refname>fdf_get_value</refname>
<refpurpose>Get the value of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fdf_get_value</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_get_value</function> function returns the
value of a field.</para>
<para>
See also <function>fdf_set_value</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-value">
<refnamediv>
<refname>fdf_set_value</refname>
<refpurpose>Set the value of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_set_value</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
<paramdef>int <parameter>isName</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_value</function> function sets the
value of a field. The last parameter determines if the field value
is to be converted to a PDF Name (<parameter>isName</parameter> = 1)
or set to a PDF String (<parameter>isName</parameter> = 0).</para>
<para>
See also <function>fdf_get_value</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-next-field-name">
<refnamediv>
<refname>fdf_next_field_name</refname>
<refpurpose>Get the next field name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fdf_next_field_name</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_next_field_name</function> function returns the
name of the field after the field in
<parameter>fieldname</parameter> or the field name of the first field
if the second paramter is NULL.</para>
<para>
See also <function>fdf_set_field</function>,
<function>fdf_get_field</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-ap">
<refnamediv>
<refname>fdf_set_ap</refname>
<refpurpose>Set the appearance of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_set_ap</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>field_name</parameter></paramdef>
<paramdef>int <parameter>face</parameter></paramdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int <parameter>page_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_ap</function> function sets the
appearance of a field (i.e. the value of the /AP key).
The possible values of <parameter>face</parameter>
are 1=FDFNormalAP, 2=FDFRolloverAP, 3=FDFDownAP.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-status">
<refnamediv>
<refname>fdf_set_status</refname>
<refpurpose>Set the value of the /STATUS key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_set_status</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>status</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_status</function> sets the value
of the /STATUS key.</para>
<para>
See also <function>fdf_get_status</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-get-status">
<refnamediv>
<refname>fdf_get_status</refname>
<refpurpose>Get the value of the /STATUS key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fdf_get_status</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_get_status</function> returns the value
of the /STATUS key.</para>
<para>
See also <function>fdf_set_status</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-file">
<refnamediv>
<refname>fdf_set_file</refname>
<refpurpose>Set the value of the /F key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_set_file</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_file</function> sets the value
of the /F key. The /F key is just a reference to a PDF form
which is to be populated with data.
In a web environment it is a URL (e.g. http:/testfdf/resultlabel.pdf).</para>
<para>
See also <function>fdf_get_file</function> and example for
<function>fdf_create</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-get-file">
<refnamediv>
<refname>fdf_get_file</refname>
<refpurpose>Get the value of the /F key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fdf_get_file</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_file</function> returns the value
of the /F key.</para>
<para>
See also <function>fdf_set_file</function>.</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-flags">
<refnamediv>
<refname>fdf_set_flags</refname>
<refpurpose>Sets a flag of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_set_flags</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
<paramdef>int <parameter>whichFlags</parameter></paramdef>
<paramdef>int <parameter>newFlags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_flags</function> sets certain flags
of the given field <parameter>fieldname</parameter>.
</para>
<para>
See also <function>fdf_set_opt</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-opt">
<refnamediv>
<refname>fdf_set_opt</refname>
<refpurpose>Sets an option of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_set_opt</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
<paramdef>int <parameter>element</parameter></paramdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_opt</function> sets options
of the given field <parameter>fieldname</parameter>.
</para>
<para>
See also <function>fdf_set_flags</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-submit-form-action">
<refnamediv>
<refname>fdf_set_submit_form_action</refname>
<refpurpose>Sets an javascript action of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>fdf_set_submit_form_action</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
<paramdef>int <parameter>trigger</parameter></paramdef>
<paramdef>string <parameter>script</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_submit_form_action</function> sets a submit form
action for the given field <parameter>fieldname</parameter>.
</para>
<para>
See also <function>fdf_set_javascript_action</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fdf-set-javascript-action">
<refnamediv>
<refname>fdf_set_javascript_action</refname>
<refpurpose>Sets an javascript action of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>fdf_set_javascript_action</function></funcdef>
<paramdef>int <parameter>fdf_document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
<paramdef>int <parameter>trigger</parameter></paramdef>
<paramdef>string <parameter>script</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>fdf_set_javascript_action</function> sets a javascript
action for the given field <parameter>fieldname</parameter>.
</para>
<para>
See also <function>fdf_set_submit_form_action</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/filepro.xml
+++ phpdoc/nl/functions/filepro.xml
<reference id="ref.filepro">
<title>filePro functions</title>
<titleabbrev>filePro</titleabbrev>
<partintro>
<simpara>
These functions allow read-only access to data stored in filePro databases.</simpara>
<simpara>
filePro is a registered trademark of Fiserv, Inc. You can find more
information about filePro at <ulink
url="&url.filepro;">&url.filepro;</ulink>.</simpara>
</partintro>
<refentry id="function.filepro">
<refnamediv>
<refname>filepro</refname>
<refpurpose>read and verify the map file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>filepro</function></funcdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This reads and verifies the map file, storing the field count
and info.</para>
<para>
No locking is done, so you should avoid modifying your filePro
database while it may be opened in PHP.</para>
</refsect1>
</refentry>
<refentry id="function.filepro-fieldname">
<refnamediv>
<refname>filepro_fieldname</refname>
<refpurpose>gets the name of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>filepro_fieldname</function></funcdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the name of the field corresponding to
<parameter>field_number</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.filepro-fieldtype">
<refnamediv>
<refname>filepro_fieldtype</refname>
<refpurpose>gets the type of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>filepro_fieldtype</function></funcdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the edit type of the field corresponding to
<parameter>field_number</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.filepro-fieldwidth">
<refnamediv>
<refname>filepro_fieldwidth</refname>
<refpurpose>gets the width of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>filepro_fieldwidth</function></funcdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the width of the field corresponding to
<parameter>field_number</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.filepro-retrieve">
<refnamediv>
<refname>filepro_retrieve</refname>
<refpurpose>retrieves data from a filePro database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>filepro_retrieve</function></funcdef>
<paramdef>int <parameter>row_number</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the data from the specified location in the database.</para>
</refsect1>
</refentry>
<refentry id="function.filepro-fieldcount">
<refnamediv>
<refname>filepro_fieldcount</refname>
<refpurpose>find out how many fields are in a filePro database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>filepro_fieldcount</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of fields (columns) in the opened filePro
database.</para>
<para>
See also <function>filepro</function>.</para>
</refsect1>
</refentry>
<refentry id="function.filepro-rowcount">
<refnamediv>
<refname>filepro_rowcount</refname>
<refpurpose>find out how many rows are in a filePro database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>filepro_rowcount</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of rows in the opened filePro database.</para>
<para>
See also <function>filepro</function>.</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/filesystem.xml
+++ phpdoc/nl/functions/filesystem.xml
<reference id="ref.filesystem">
<title>Filesystem functions</title>
<titleabbrev>Filesystem</titleabbrev>
<refentry id="function.basename">
<refnamediv>
<refname>basename</refname>
<refpurpose>
Returns filename component of path
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>basename</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Given a string containing a path to a file, this function will
return the base name of the file.
</para>
<para>
On Windows, both slash (<literal>/</literal>) and backslash
(<literal>\</literal>) are used as path separator character. In
other environments, it is the forward slash
(<literal>/</literal>).
</para>
<para>
<example>
<title><function>basename</function> example</title>
<programlisting role="php">
$path = "/home/httpd/html/index.php3";
$file = basename ($path); // $file is set to "index.php3"
</programlisting>
</example>
</para>
<para>
See also: <function>dirname</function>
</para>
</refsect1>
</refentry>
<refentry id="function.chgrp">
<refnamediv>
<refname>chgrp</refname>
<refpurpose>Changes file group</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>chgrp</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>mixed <parameter>group</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Attempts to change the group of the file
<parameter>filename</parameter> to
<parameter>group</parameter>. 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.
</para>
<para>
Returns true on success; otherwise returns false.
</para>
<para>
See also <function>chown</function> and
<function>chmod</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.chmod">
<refnamediv>
<refname>chmod</refname>
<refpurpose>Changes file mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>chmod</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Attempts to change the mode of the file specified by
<parameter>filename</parameter> to that given in
<parameter>mode</parameter>.
</para>
<para>
Note that <parameter>mode</parameter> 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 <parameter>mode</parameter> with a zero (0):
<informalexample>
<programlisting role="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
</programlisting>
</informalexample>
</para>
<para>
Returns true on success and false otherwise.
</para>
<para>
See also <function>chown</function> and
<function>chgrp</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.chown">
<refnamediv>
<refname>chown</refname>
<refpurpose>Changes file owner</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>chown</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>mixed <parameter>user</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Attempts to change the owner of the file filename to user
user. Only the superuser may change the owner of a file.
</para>
<para>
Returns true on success; otherwise returns false.
</para>
<para>
See also <function>chown</function> and
<function>chmod</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.clearstatcache">
<refnamediv>
<refname>clearstatcache</refname>
<refpurpose>Clears file stat cache</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>clearstatcache</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Invoking the <systemitem>stat</systemitem> or
<systemitem>lstat</systemitem> system call on most systems is
quite expensive. Therefore, the result of the last call to any of
the status functions (listed below) is stored for use on the next
such call using the same filename. If you wish to force a new
status check, for instance if the file is being checked many
times and may change or disappear, use this function to clear the
results of the last call from memory.
</para>
<para>
This value is only cached for the lifetime of a single request.
</para>
<para>
Affected functions include <function>stat</function>,
<function>lstat</function>,
<function>file_exists</function>,
<function>is_writeable</function>,
<function>is_readable</function>,
<function>is_executable</function>,
<function>is_file</function>,
<function>is_dir</function>,
<function>is_link</function>,
<function>filectime</function>,
<function>fileatime</function>,
<function>filemtime</function>,
<function>fileinode</function>,
<function>filegroup</function>,
<function>fileowner</function>,
<function>filesize</function>,
<function>filetype</function>, and
<function>fileperms</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.copy">
<refnamediv>
<refname>copy</refname>
<refpurpose>Copies file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>copy</function></funcdef>
<paramdef>string <parameter>source</parameter></paramdef>
<paramdef>string <parameter>dest</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Makes a copy of a file. Returns true if the copy succeeded,
false otherwise.
<example>
<title><function>Copy</function> example</title>
<programlisting role="php">
if (!copy($file, $file.'.bak')) {
print ("failed to copy $file...<br>\n");
}
</programlisting>
</example>
</para>
<para>
See also: <function>rename</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.delete">
<refnamediv>
<refname>delete</refname>
<refpurpose>A dummy manual entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>delete</function></funcdef>
<paramdef>string <parameter>file</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This is a dummy manual entry to satisfy those people who are
looking for <function>unlink</function> or
<function>unset</function> in the wrong place.
</para>
<para>
See also: <function>unlink</function> to delete files,
<function>unset</function> to delete variables.
</para>
</refsect1>
</refentry>
<refentry id="function.dirname">
<refnamediv>
<refname>dirname</refname>
<refpurpose>Returns directory name component of path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dirname</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Given a string containing a path to a file, this function will
return the name of the directory.</para>
<para>
On Windows, both slash (<literal>/</literal>) and backslash
(<literal>\</literal>) are used as path separator character. In
other environments, it is the forward slash
(<literal>/</literal>).</para>
<para>
<example>
<title><function>Dirname</function> example</title>
<programlisting role="php">
$path = "/etc/passwd";
$file = dirname ($path); // $file is set to "/etc"
</programlisting>
</example>
</para>
<para>
See also: <function>basename</function>
</para>
</refsect1>
</refentry>
<refentry id="function.diskfreespace">
<refnamediv>
<refname>diskfreespace</refname>
<refpurpose>Returns available space in directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>diskfreespace</function></funcdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Given a string containing a directory, this function will return
the number of bytes available on the corresponding filesystem or
disk partition.
</para>
<para>
<example>
<title><function>diskfreespace</function> example</title>
<programlisting role="php">
$df = diskfreespace("/"); // $df contains the number of bytes
// available on "/"
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.fclose">
<refnamediv>
<refname>fclose</refname>
<refpurpose>Closes an open file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fclose</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The file pointed to by fp is closed.
</para>
<para>
Returns true on success and false on failure.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function> or
<function>fsockopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.feof">
<refnamediv>
<refname>feof</refname>
<refpurpose>Tests for end-of-file on a file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>feof</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the file pointer is at EOF or an error occurs;
otherwise returns false.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function>,
<function>popen</function>, or <function>fsockopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fgetc">
<refnamediv>
<refname>fgetc</refname>
<refpurpose>Gets character from file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fgetc</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a single character read from the
file pointed to by fp. Returns FALSE on EOF.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function>,
<function>popen</function>, or <function>fsockopen</function>.
</para>
<para>
See also <function>fread</function>, <function>fopen</function>,
<function>popen</function>, <function>fsockopen</function>, and
<function>fgets</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fgetcsv">
<refnamediv>
<refname>fgetcsv</refname>
<refpurpose>
Gets line from file pointer and parse for CSV fields
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>fgetcsv</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
<paramdef>string
<parameter>
<optional>delimiter</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Similar to <function>fgets</function> except that
<function>fgetcsv</function> parses the line it reads for fields
in <acronym>CSV</acronym> format and returns an array containing
the fields read. The field delimiter is a comma, unless you
specify another delimiter with the optional third parameter.
</simpara>
<simpara>
<parameter>Fp</parameter> must be a valid file pointer to a file
successfully opened by <function>fopen</function>,
<function>popen</function>, or <function>fsockopen</function>
</simpara>
<simpara>
Length must be greater than the longest line to be found in the
CSV file (allowing for trailing line-end characters).
</simpara>
<simpara>
<function>Fgetcsv</function> returns false on error, including
end of file.
</simpara>
<simpara>
N.B. 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.
</simpara>
<example>
<title>
<function>Fgetcsv</function> example - Read and print entire
contents of a CSV file
</title>
<programlisting role="php">
$row = 1;
$fp = fopen ("test.csv","r");
while ($data = fgetcsv ($fp, 1000, ",")) {
$num = count ($data);
print "<p> $num fields in line $row: <br>";
$row++;
for ($c=0; $c<$num; $c++) {
print $data[$c] . "<br>";
}
}
fclose ($fp);
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.fgets">
<refnamediv>
<refname>fgets</refname>
<refpurpose>Gets line from file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fgets</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string of up to length - 1 bytes read from the file
pointed to by fp. Reading ends when length - 1 bytes have been
read, on a newline (which is included in the return value), or on
EOF (whichever comes first).
</para>
<para>
If an error occurs, returns false.
</para>
<para>
Common Pitfalls:
</para>
<simpara>
People used to the 'C' semantics of fgets should note the
difference in how EOF is returned.
</simpara>
<simpara>
The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function>,
<function>popen</function>, or
<function>fsockopen</function>.
</simpara>
<para>
A simple example follows:
<example>
<title>Reading a file line by line</title>
<programlisting role="php">
$fd = fopen ("/tmp/inputfile.txt", "r");
while (!feof ($fd)) {
$buffer = fgets($fd, 4096);
echo $buffer;
}
fclose ($fd);
</programlisting>
</example>
</para>
<para>
See also <function>fread</function>, <function>fopen</function>,
<function>popen</function>, <function>fgetc</function>,
<function>fsockopen</function>, and
<function>socket_set_timeout</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fgetss">
<refnamediv>
<refname>fgetss</refname>
<refpurpose>
Gets line from file pointer and strip HTML tags
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fgetss</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
<paramdef>string
<parameter>
<optional>allowable_tags</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>fgets</function>, except that fgetss
attempts to strip any HTML and PHP tags from the text it
reads.
</para>
<para>
You can use the optional third parameter to specify tags which
should not be stripped.
<note>
<para>
<parameter>allowable_tags</parameter> was added in PHP 3.0.13,
PHP4B3.
</para>
</note>
</para>
<para>
See also <function>fgets</function>, <function>fopen</function>,
<function>fsockopen</function>, <function>popen</function>, and
<function>strip_tags</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.file">
<refnamediv>
<refname>file</refname>
<refpurpose>Reads entire file into an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>file</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int
<parameter><optional>use_include_path</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>readfile</function>, except that
<function>file</function> returns the file in an array. Each
element of the array corresponds to a line in the file, with the
newline still attached.
</para>
<para>
You can use the optional second parameter and set it to "1", if
you want to search for the file in the <link
linkend="ini.include-path">include_path</link>, too.
</para>
<para>
<informalexample>
<programlisting role="php">
<?php
// get a web page into an array and print it out
$fcontents = file ('http://www.php.net');
while (list ($line_num, $line) = each ($fcontents)) {
echo "<b>Line $line_num:</b> " . htmlspecialchars ($line)
. "<br>\n";
}
// get a web page into a string
$fcontents = join ('', file ('http://www.php.net'));
?>
</programlisting>
</informalexample>
</para>
<para>
See also <function>readfile</function>,
<function>fopen</function>, <function>fsockopen</function>, and
<function>popen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.file-exists">
<refnamediv>
<refname>file_exists</refname>
<refpurpose>Checks whether a file exists</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>file_exists</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns true if the file specified by
<parameter>filename</parameter> exists; false otherwise.
</simpara>
<simpara>
<function>file_exists</function> will not work on remote files;
the file to be examined must be accessible via the server's
filesystem.
</simpara>
<simpara>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</simpara>
</refsect1>
</refentry>
<refentry id="function.fileatime">
<refnamediv>
<refname>fileatime</refname>
<refpurpose>Gets last access time of file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fileatime</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the time the file was last accessed, or false in case of
an error. The time is returned as a Unix timestamp.
</simpara>
<simpara>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</simpara>
<simpara>
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 appliation 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.
</simpara>
</refsect1>
</refentry>
<refentry id="function.filectime">
<refnamediv>
<refname>filectime</refname>
<refpurpose>Gets inode change time of file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>filectime</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the time the file was last changed, or false in case of
an error. The time is returned as a Unix timestamp.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>Note: In most Unix filesystem, a file is considered
changed, when it's Inode data is changed, that is, when
the permissions, the owner, the group or other metadata
from the Inode is written to. See also
<function>filemtime</function> (this is what you want to use
when you want to create "Last Modified" footers on web pages) and
<function>fileatime</function>.
</para>
<para>Note: In some Unix texts the ctime of a file is being
referred to as the creation time of the file. This is wrong.
There is no creation time for Unix files in most Unix
filesystems.
</para>
</refsect1>
</refentry>
<refentry id="function.filegroup">
<refnamediv>
<refname>filegroup</refname>
<refpurpose>Gets file group</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>filegroup</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the group ID of the owner of the file, or false in case
of an error. The group ID is returned in numerical format, use
<function>posix_getgrgid</function> to resolve it to a group name.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.fileinode">
<refnamediv>
<refname>fileinode</refname>
<refpurpose>Gets file inode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fileinode</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the inode number of the file, or false in case of an
error.</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.filemtime">
<refnamediv>
<refname>filemtime</refname>
<refpurpose>Gets file modification time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>filemtime</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the time the file was last modified, or false in case of
an error. The time is returned as a Unix timestamp.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>Note: 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. Use
<function>date</function> on the result of this function
to get a printable modification date for use in page footers.
</para>
</refsect1>
</refentry>
<refentry id="function.fileowner">
<refnamediv>
<refname>fileowner</refname>
<refpurpose>Gets file owner</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fileowner</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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
<function>posix_getpwuid</function> to resolve it to a username.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.fileperms">
<refnamediv>
<refname>fileperms</refname>
<refpurpose>Gets file permissions</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fileperms</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the permissions on the file, or false in case of an error.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
</refsect1>
</refentry>
<refentry id="function.filesize">
<refnamediv>
<refname>filesize</refname>
<refpurpose>Gets file size</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>filesize</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the size of the file, or false in case of an error.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
</refsect1>
</refentry>
<refentry id="function.filetype">
<refnamediv>
<refname>filetype</refname>
<refpurpose>Gets file type</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>filetype</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the type of the file. Possible values are fifo, char,
dir, block, link, file, and unknown.</para> <para> Returns false
if an error occurs.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
</refsect1>
</refentry>
<refentry id="function.flock">
<refnamediv>
<refname>flock</refname>
<refpurpose>Portable advisory file locking</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>flock</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>operation</parameter></paramdef>
<paramdef>int
<parameter>
<optional>wouldblock</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
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).
</simpara>
<simpara>
<function>flock</function> operates on <parameter>fp</parameter>
which must be an open file
pointer. <parameter>operation</parameter> is one of the following
values:
</simpara>
<para>
<itemizedlist>
<listitem>
<simpara>
To acquire a shared lock (reader), set
<parameter>operation</parameter> to LOCK_SH (set to 1 prior to
PHP 4.0.1).
</simpara>
</listitem>
<listitem>
<simpara>
To acquire an exclusive lock (writer), set
<parameter>operation</parameter> to LOCK_EX (set to 2 prior to
PHP 4.0.1).
</simpara>
</listitem>
<listitem>
<simpara>
To release a lock (shared or exclusive), set
<parameter>operation</parameter> to LOCK_UN (set to 3 prior to
PHP 4.0.1).
</simpara>
</listitem>
<listitem>
<simpara>
If you don't want <function>flock</function> to block while
locking, add LOCK_NB (4 prior to PHP 4.0.1) to
<parameter>operation</parameter>.
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
<function>Flock</function> allows you to perform a simple
reader/writer model which can be used on virtually every platform
(including most Unices and even Windows). The optional 3rd
argument is set to true if the lock would block (EWOULDBLOCK
errno condition)
</simpara>
<simpara>
<function>Flock</function> returns true on success and false on
error (e.g. when a lock could not be acquired).
</simpara>
</refsect1>
</refentry>
<refentry id="function.fopen">
<refnamediv>
<refname>fopen</refname>
<refpurpose>Opens file or URL</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fopen</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>int
<parameter>
<optional>use_include_path</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
If <parameter>filename</parameter> begins with "http://" (not
case sensitive), an HTTP 1.0 connection is opened to the
specified server and a file pointer is returned to the beginning
of the text of the response. A 'Host:' header is sent with the
request in order to handle name-based virtual hosts.
</simpara>
<simpara>
Does not handle HTTP redirects, so you must include trailing
slashes on directories.
</simpara>
<simpara>
If <parameter>filename</parameter> begins with "ftp://" (not case
sensitive), an ftp connection to the specified server is opened
and a pointer to the requested file is returned. If the server
does not support passive mode ftp, this will fail. You can open
files for either reading and writing via ftp (but not both
simultaneously).
</simpara>
<simpara>
If <parameter>filename</parameter> is one of "php://stdin",
"php://stdout", or "php://stderr", the corresponding stdio
stream will be opened. (This was introduced in PHP 3.0.13;
in earlier versions, a filename such as "/dev/stdin" or
"/dev/fd/0" must be used to access the stdio streams.)
</simpara>
<simpara>
If <parameter>filename</parameter> begins with anything else, the
file will be opened from the filesystem, and a file pointer to
the file opened is returned.
</simpara>
<simpara>
If the open fails, the function returns false.
</simpara>
<para>
<parameter>mode</parameter> may be any of the following:
<itemizedlist>
<listitem>
<simpara>
'r' - Open for reading only; place the file pointer at the
beginning of the file.
</simpara>
</listitem>
<listitem>
<simpara>
'r+' - Open for reading and writing; place the file pointer at
the beginning of the file.
</simpara>
</listitem>
<listitem>
<simpara>
'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.
</simpara>
</listitem>
<listitem>
<simpara>
'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.
</simpara>
</listitem>
<listitem>
<simpara>
'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.
</simpara>
</listitem>
<listitem>
<simpara>
'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.
</simpara>
</listitem>
</itemizedlist>
The <parameter>mode</parameter> may contain the letter
'b'. This is useful only on systems which differentiate between
binary and text files (i.e., it's useless on Unix). If not
needed, this will be ignored.
</para>
<para>
You can use the optional third parameter and set it to "1", if
you want to search for the file in the <link
linkend="ini.include-path">include_path</link>, too.
</para>
<para>
<example>
<title><function>Fopen</function> example</title>
<programlisting role="php">
$fp = fopen ("/home/rasmus/file.txt", "r");
$fp = fopen ("/home/rasmus/file.gif", "wb");
$fp = fopen ("http://www.php.net/",
"r");
$fp = fopen ("ftp://user:password@example.com/",
"w");
</programlisting>
</example>
</para>
<simpara>
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.
</simpara>
<para>
On the Windows platform, be careful to escape any backslashes
used in the path to the file, or use forward slashes.
<informalexample>
<programlisting role="php">
$fp = fopen ("c:\\data\\info.txt", "r");
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>fclose</function>,
<function>fsockopen</function>,
<function>socket_set_timeout</function>, and
<function>popen</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.fpassthru">
<refnamediv>
<refname>fpassthru</refname>
<refpurpose>
Output all remaining data on a file pointer
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fpassthru</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Reads to EOF on the given file pointer and writes the results to
standard output.
</simpara>
<simpara>
If an error occurs, <function>fpassthru</function> returns
false.
</simpara>
<simpara>
The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function>,
<function>popen</function>, or <function>fsockopen</function>.
The file is closed when <function>fpassthru</function> is done
reading it (leaving <parameter>fp</parameter> useless).
</simpara>
<simpara>
If you just want to dump the contents of a file to stdout you may
want to use the <function>readfile</function>, which saves you
the <function>fopen</function> call.
</simpara>
<simpara>
See also <function>readfile</function>,
<function>fopen</function>, <function>popen</function>, and
<function>fsockopen</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.fputs">
<refnamediv>
<refname>fputs</refname>
<refpurpose>Writes to a file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fputs</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>int
<parameter>
<optional>length</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Fputs</function> is an alias to
<function>fwrite</function>, and is identical in every way. Note
that the <parameter>length</parameter> parameter is optional and
if not specified the entire string will be written.
</para>
</refsect1>
</refentry>
<refentry id="function.fread">
<refnamediv>
<refname>fread</refname>
<refpurpose>Binary-safe file read</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>fread</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Fread</function> reads up to
<parameter>length</parameter> bytes from the file pointer
referenced by <parameter>fp</parameter>. Reading stops when
<parameter>length</parameter> bytes have been read or EOF is
reached, whichever comes first.
</simpara>
<para>
<informalexample>
<programlisting role="php">
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>fwrite</function>, <function>fopen</function>,
<function>fsockopen</function>, <function>popen</function>,
<function>fgets</function>, <function>fgetss</function>,
<function>fscanf</function>, <function>file</function>, and
<function>fpassthru</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.fscanf">
<refnamediv>
<refname>fscanf</refname>
<refpurpose>Parses input from a file according to a format</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>fscanf</function></funcdef>
<paramdef>int <parameter>handle</parameter></paramdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>string
<parameter><optional>var1</optional></parameter>...
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function <function>fscanf</function> is similar to
<function>sscanf</function>, but it takes its input from a file
associated with <parameter>handle</parameter> and interprets the
input according to the specified
<parameter>format</parameter>. 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.
<example>
<title><function>Fscanf</function> Example</title>
<programlisting role="php">
$fp = fopen ("users.txt","r");
while ($userinfo = fscanf ($fp, "%s\t%s\t%s\n")) {
list ($name, $profession, $countrycode) = $userinfo;
//... do something with the values
}
fclose($fp);
</programlisting>
</example>
<example>
<title>users.txt</title>
<programlisting>
javier argonaut pe
hiroshi sculptor jp
robert slacker us
luigi florist it
</programlisting>
</example>
</para>
<para>
See also <function>fread</function>, <function>fgets</function>,
<function>fgetss</function>, <function>sscanf</function>,
<function>printf</function>, and <function>sprintf</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fseek">
<refnamediv>
<refname>fseek</refname>
<refpurpose>Seeks on a file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fseek</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>offset</parameter></paramdef>
<paramdef>int
<parameter><optional>whence</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the file position indicator for the file referenced by
<parameter>fp</parameter>.The new position, measured in bytes
from the beginning of the file, is obtained by adding
<parameter>offset</parameter> to the position specified by
<parameter>whence</parameter>, whose values are defined as
follows:
<simplelist>
<member>SEEK_SET - Set position equal to
<parameter>offset</parameter> bytes.</member> <member>SEEK_CUR -
Set position to current location plus
<parameter>offset</parameter>.</member> <member>SEEK_END - Set
position to end-of-file plus
<parameter>offset</parameter>.</member>
</simplelist>
</para>
<para>If <parameter>whence is not specified, it is assumed to be
SEEK_SET.</parameter>
</para>
<para>
Upon success, returns 0; otherwise, returns -1. Note that seeking
past EOF is not considered an error.
</para>
<para>
May not be used on file pointers returned by
<function>fopen</function> if they use the "http://" or "ftp://"
formats.
</para>
<note>
<para>
The <parameter>whence</parameter> argument was added after PHP 4.0 RC1.
</para>
</note>
<para>
See also <function>ftell</function> and
<function>rewind</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fstat">
<refnamediv>
<refname>fstat</refname>
<refpurpose>
Gets information about a file using an open file pointer
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>fstat</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Gathers the statistics of the file opened by the file
pointer fp. This function is similar to the
<function>stat</function> function except that it operates
on an open file pointer instead of a filename.
</para>
<para>
Returns an array with the statistics of the file with the
following elements:
<orderedlist>
<listitem><simpara>device</simpara></listitem>
<listitem><simpara>inode</simpara></listitem>
<listitem><simpara>number of links</simpara></listitem>
<listitem><simpara>user id of owner</simpara></listitem>
<listitem><simpara>group id owner</simpara></listitem>
<listitem><simpara>device type if inode device *</simpara></listitem>
<listitem><simpara>size in bytes</simpara></listitem>
<listitem><simpara>time of last access</simpara></listitem>
<listitem><simpara>time of last modification</simpara></listitem>
<listitem><simpara>time of last change</simpara></listitem>
<listitem><simpara>blocksize for filesystem I/O *</simpara></listitem>
<listitem><simpara>number of blocks allocated</simpara></listitem>
</orderedlist>
* - only valid on systems supporting the st_blksize type--other
systems (i.e. Windows) return -1</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
</refsect1>
</refentry>
<refentry id="function.ftell">
<refnamediv>
<refname>ftell</refname>
<refpurpose>Tells file pointer read/write position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftell</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the position of the file pointer referenced by fp; i.e.,
its offset into the file stream.
</para>
<para>
If an error occurs, returns false.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function> or
<function>popen</function>.
</para>
<para>
See also <function>fopen</function>, <function>popen</function>,
<function>fseek</function> and <function>rewind</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ftruncate">
<refnamediv>
<refname>ftruncate</refname>
<refpurpose>
Truncates a file to a given length.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftruncate</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>size</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Takes the filepointer, fp, and truncates the file to length, size.
This function returns true on success and false on failure.
</para>
</refsect1>
</refentry>
<refentry id="function.fwrite">
<refnamediv>
<refname>fwrite</refname>
<refpurpose>Binary-safe file write</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fwrite</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter>
<optional>length</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>fwrite</function> writes the contents of
<parameter>string</parameter> to the file stream pointed to by
<parameter>fp</parameter>. If the <parameter>length</parameter>
argument is given, writing will stop after
<parameter>length</parameter> bytes have been written or the end
of <parameter>string</parameter> is reached, whichever comes
first.
</simpara>
<simpara>
Note that if the <parameter>length</parameter> argument is given,
then the <link
linkend="ini.magic-quotes-runtime">magic_quotes_runtime</link>
configuration option will be ignored and no slashes will be
stripped from <parameter>string</parameter>.
</simpara>
<simpara>
See also <function>fread</function>, <function>fopen</function>,
<function>fsockopen</function>, <function>popen</function>, and
<function>fputs</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.set-file-buffer">
<refnamediv>
<refname>set_file_buffer</refname>
<refpurpose>
Sets file buffering on the given file pointer
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>set_file_buffer</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>buffer</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Output using <function>fwrite</function> is normally buffered at
8K. This means that if there are two processess wanting to write
to the same output stream (a file), each is paused after 8K of
data to allow the other to write. <function>set_file_buffer</function>
sets the buffering for write operations on the given filepointer
<parameter>fp</parameter> to <parameter>buffer</parameter> bytes.
If <parameter>buffer</parameter> is 0 then write operations are
unbuffered. This ensures that all writes with
<function>fwrite</function> are completed before other processes
are allowed to write to that output stream.
</simpara>
<simpara>
The function returns 0 on success, or EOF if the request cannot
be honored.
</simpara>
<para>
The following example demonstrates how to use
<function>set_file_buffer</function> to create an unbuffered stream.
<example>
<title><function>set_file_buffer</function> example</title>
<programlisting role="php">
$fp=fopen($file, "w");
if($fp){
set_file_buffer($fp, 0);
fputs($fp, $output);
fclose($fp);
}
</programlisting>
</example>
</para>
<simpara>
See also <function>fopen</function>, <function>fwrite</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.is-dir">
<refnamediv>
<refname>is_dir</refname>
<refpurpose>Tells whether the filename is a directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_dir</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the filename exists and is a directory.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>
See also <function>is_file</function> and
<function>is_link</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-executable">
<refnamediv>
<refname>is_executable</refname>
<refpurpose>Tells whether the filename is executable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_executable</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the filename exists and is executable.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>
See also <function>is_file</function> and
<function>is_link</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-file">
<refnamediv>
<refname>is_file</refname>
<refpurpose>
Tells whether the filename is a regular file
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_file</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the filename exists and is a regular file.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>
See also <function>is_dir</function> and
<function>is_link</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-link">
<refnamediv>
<refname>is_link</refname>
<refpurpose>
Tells whether the filename is a symbolic link
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_link</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the filename exists and is a symbolic link.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>
See also <function>is_dir</function> and
<function>is_file</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.is-readable">
<refnamediv>
<refname>is_readable</refname>
<refpurpose>
Tells whether the filename is readable
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_readable</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the filename exists and is readable.
</para>
<para>
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.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>
See also <function>is_writeable</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-writeable">
<refnamediv>
<refname>is_writeable</refname>
<refpurpose>Tells whether the filename is writeable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_writeable</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the filename exists and is writeable. The
filename argument may be a directory name allowing you to check
if a directory is writeable.
</para>
<para>
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.
</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
<para>
See also <function>is_readable</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-uploaded-file">
<refnamediv>
<refname>is_uploaded_file</refname>
<refpurpose>Tells whether the file was uploaded via HTTP POST.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>is_uploaded_file</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is available only in versions of PHP 3 after PHP
3.0.16, and in versions of PHP 4 after 4.0.2.
</para>
<para>
Returns true if the file named by <varname>filename</varname> 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,
<filename>/etc/passwd</filename>.
</para>
<para>
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.
</para>
<para>
See also <function>move_uploaded_file</function>, and the section
<link linkend="features.file-upload">Handling file uploads</link>
for a simple usage example.
</para>
</refsect1>
</refentry>
<refentry id="function.link">
<refnamediv>
<refname>link</refname>
<refpurpose>Create a hard link</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>link</function></funcdef>
<paramdef>string <parameter>target</parameter></paramdef>
<paramdef>string <parameter>link</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Link</function> creates a hard link.</para>
<para>
See also the <function>symlink</function> to create soft links,
and <function>readlink</function> along with
<function>linkinfo</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.linkinfo">
<refnamediv>
<refname>linkinfo</refname>
<refpurpose>Gets information about a link</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>linkinfo</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Linkinfo</function> 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
<parameter>path</parameter>) really exists (using the same method
as the S_ISLNK macro defined in stat.h). Returns 0 or FALSE in
case of error.
</para>
<para>
See also <function>symlink</function>, <function>link</function>,
and <function>readlink</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.mkdir">
<refnamediv>
<refname>mkdir</refname>
<refpurpose>Makes directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mkdir</function></funcdef>
<paramdef>string <parameter>pathname</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Attempts to create the directory specified by pathname.
</para>
<para>
Note that you probably want to specify the mode as an
octal number, which means it should have a leading zero.
<informalexample>
<programlisting role="php">
mkdir ("/path/to/my/dir", 0700);
</programlisting>
</informalexample>
</para>
<para>
Returns true on success and false on failure.
</para>
<para>
See also <function>rmdir</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.move-uploaded-file">
<refnamediv>
<refname>move_uploaded_file</refname>
<refpurpose>Moves an uploaded file to a new location.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>move_uploaded_file</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>string <parameter>destination</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is available only in versions of PHP 3 after PHP
3.0.16, and in versions of PHP 4 after 4.0.2.
</para>
<para>
This function checks to ensure that the file designated by
<parameter>filename</parameter> 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
<parameter>destination</parameter>.
</para>
<para>
If <parameter>filename</parameter> is not a valid upload file,
then no action will occur, and
<function>move_uploaded_file</function> will return
<literal>false</literal>.
</para>
<para>
If <parameter>filename</parameter> is a valid upload file, but
cannot be moved for some reason, no action will occur, and
<function>move_uploaded_file</function> will return
<literal>false</literal>. Additionally, a warning will be issued.
</para>
<para>
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.
</para>
<para>
See also <function>is_uploaded_file</function>, and the section
<link linkend="features.file-upload">Handling file uploads</link>
for a simple usage example.
</para>
</refsect1>
</refentry>
<refentry id="function.pclose">
<refnamediv>
<refname>pclose</refname>
<refpurpose>Closes process file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pclose</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Closes a file pointer to a pipe opened by
<function>popen</function>.
</para>
<para>
The file pointer must be valid, and must have been returned by a
successful call to <function>popen</function>.
</para>
<para>
Returns the termination status of the process that was
run.
</para>
<para>
See also <function>popen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.popen">
<refnamediv>
<refname>popen</refname>
<refpurpose>Opens process file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>popen</function></funcdef>
<paramdef>string <parameter>command</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Opens a pipe to a process executed by forking the command given
by command.
</para>
<para>
Returns a file pointer identical to that returned by
<function>fopen</function>, except that it is unidirectional (may
only be used for reading or writing) and must be closed with
<function>pclose</function>. This pointer may be used with
<function>fgets</function>, <function>fgetss</function>, and
<function>fputs</function>.
</para>
<para>
If an error occurs, returns false.
</para>
<para>
<informalexample>
<programlisting role="php">
$fp = popen ("/bin/ls", "r");
</programlisting>
</informalexample>
</para>
<para>
See also <function>pclose</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.readfile">
<refnamediv>
<refname>readfile</refname>
<refpurpose>Outputs a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>readfile</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int
<parameter>
<optional>use_include_path</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Reads a file and writes it to standard output.
</para>
<para>
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.
</para>
<para>
If <parameter>filename</parameter> begins with "http://"
(not case sensitive), an HTTP 1.0 connection is opened to the
specified server and the text of the response is written to
standard output.
</para>
<para>
Does not handle HTTP redirects, so you must include trailing
slashes on directories.
</para>
<para>
If <parameter>filename</parameter> begins with "ftp://"
(not case sensitive), an ftp connection to the specified server is
opened and the requested file is written to standard output. If the server
does not support passive mode ftp, this will fail.
</para>
<para>
If <parameter>filename</parameter> begins with neither
of these strings, the file will be opened from the filesystem and
its contents written to standard output.
</para>
<para>
You can use the optional second parameter and set it to "1", if
you want to search for the file in the <link
linkend="ini.include-path">include_path</link>, too.
</para>
<para>
See also <function>fpassthru</function>,
<function>file</function>, <function>fopen</function>,
<function>include</function>, <function>require</function>, and
<function>virtual</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.readlink">
<refnamediv>
<refname>readlink</refname>
<refpurpose>Returns the target of a symbolic link</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>readlink</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Readlink</function> does the same as the readlink C
function and returns the contents of the symbolic link path or 0
in case of error.
</para>
<para>
See also <function>symlink</function>,
<function>readlink</function> and
<function>linkinfo</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.rename">
<refnamediv>
<refname>rename</refname>
<refpurpose>Renames a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>rename</function></funcdef>
<paramdef>string <parameter>oldname</parameter></paramdef>
<paramdef>string <parameter>newname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Attempts to rename <parameter>oldname</parameter> to
<parameter>newname</parameter>.
</para>
<para>
Returns true on success and false on failure.
</para>
</refsect1>
</refentry>
<refentry id="function.rewind">
<refnamediv>
<refname>rewind</refname>
<refpurpose>Rewind the position of a file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>rewind</function></funcdef>
<paramdef>int <parameter>fp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the file position indicator for fp to the beginning of the
file stream.</para> <para> If an error occurs, returns 0.</para>
<para> The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function>.
</para>
<para>
See also <function>fseek</function> and
<function>ftell</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.rmdir">
<refnamediv>
<refname>rmdir</refname>
<refpurpose>Removes directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>rmdir</function></funcdef>
<paramdef>string <parameter>dirname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Attempts to remove the directory named by pathname. The directory
must be empty, and the relevant permissions must permit.
this.
</para>
<para>
If an error occurs, returns 0.
</para>
<para>
See also <function>mkdir</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.stat">
<refnamediv>
<refname>stat</refname>
<refpurpose>Gives information about a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>stat</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Gathers the statistics of the file named by filename.</para>
<para>
Returns an array with the statistics of the file with the
following elements:
<orderedlist>
<listitem><simpara>device</simpara></listitem>
<listitem><simpara>inode</simpara></listitem>
<listitem><simpara>inode protection mode</simpara></listitem>
<listitem><simpara>number of links</simpara></listitem>
<listitem><simpara>user id of owner</simpara></listitem>
<listitem><simpara>group id owner</simpara></listitem>
<listitem><simpara>device type if inode device *</simpara></listitem>
<listitem><simpara>size in bytes</simpara></listitem>
<listitem><simpara>time of last access</simpara></listitem>
<listitem><simpara>time of last modification</simpara></listitem>
<listitem><simpara>time of last change</simpara></listitem>
<listitem><simpara>blocksize for filesystem I/O *</simpara></listitem>
<listitem><simpara>number of blocks allocated</simpara></listitem>
</orderedlist>
* - only valid on systems supporting the st_blksize type--other
systems (i.e. Windows) return -1</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
</refsect1>
</refentry>
<refentry id="function.lstat">
<refnamediv>
<refname>lstat</refname>
<refpurpose>
Gives information about a file or symbolic link
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>lstat</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Gathers the statistics of the file or symbolic link named by
filename. This function is identical to the
<function>stat</function> function except that if the
<parameter>filename</parameter> 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.
</para>
<para>
Returns an array with the statistics of the file with the
following elements:
<orderedlist>
<listitem><simpara>device</simpara></listitem>
<listitem><simpara>inode</simpara></listitem>
<listitem><simpara>inode protection mode</simpara></listitem>
<listitem><simpara>number of links</simpara></listitem>
<listitem><simpara>user id of owner</simpara></listitem>
<listitem><simpara>group id owner</simpara></listitem>
<listitem><simpara>device type if inode device *</simpara></listitem>
<listitem><simpara>size in bytes</simpara></listitem>
<listitem><simpara>time of last access</simpara></listitem>
<listitem><simpara>time of last modification</simpara></listitem>
<listitem><simpara>time of last change</simpara></listitem>
<listitem><simpara>blocksize for filesystem I/O *</simpara></listitem>
<listitem><simpara>number of blocks allocated</simpara></listitem>
</orderedlist>
* - only valid on systems supporting the st_blksize type--other
systems (i.e. Windows) return -1</para>
<para>
The results of this function are cached. See
<function>clearstatcache</function> for more details.
</para>
</refsect1>
</refentry>
<refentry id="function.realpath">
<refnamediv>
<refname>realpath</refname>
<refpurpose>Returns canonicalized absolute pathname</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>realpath</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>realpath</function> expands all symbolic links and
resolves references to '/./', '/../' and extra '/' characters in
the input <parameter>path</parameter> and return the canonicalized
absolute pathname. The resulting path will have no symbolic link,
'/./' or '/../' components.
</para>
<para>
<example>
<title><function>realpath</function> example</title>
<programlisting role="php">
$real_path = realpath ("../../index.php");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.symlink">
<refnamediv>
<refname>symlink</refname>
<refpurpose>Creates a symbolic link</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>symlink</function></funcdef>
<paramdef>string <parameter>target</parameter></paramdef>
<paramdef>string <parameter>link</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>symlink</function> creates a symbolic link
from the existing <parameter>target</parameter> with
the specified name <parameter>link</parameter>.
</para>
<para>
See also <function>link</function> to create hard links,
and <function>readlink</function> along with
<function>linkinfo</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.tempnam">
<refnamediv>
<refname>tempnam</refname>
<refpurpose>Creates unique file name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>tempnam</function></funcdef>
<paramdef>string <parameter>dir</parameter></paramdef>
<paramdef>string <parameter>prefix</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Creates a unique temporary filename in the specified directory.
If the directory does not exist, <function>tempnam</function> may
generate a filename in the system's temporary directory.
</para>
<para>
The behaviour of the <function>tempnam</function> function is
system dependent. On Windows the TMP environment variable will
override the <parameter>dir</parameter> parameter, on Linux the
TMPDIR environment variable has precedence, while SVR4 will always
use your <parameter>dir</parameter> parameter if the directory it
points to exists. Consult your system documentation on the
tempnam(3) function if in doubt.
</para>
<para>
Returns the new temporary filename, or the null string on
failure.
<example>
<title><function>Tempnam</function> example</title>
<programlisting role="php">
$tmpfname = tempnam ("/tmp", "FOO");
</programlisting>
</example>
</para>
<para>
See also <function>tmpfile</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.tmpfile">
<refnamediv>
<refname>tmpfile</refname>
<refpurpose>Creates a temporary file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>tmpfile</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Creates a temporary file with an unique name in write mode,
returning a file handle similar to the one returned by
<function>fopen</function>.
The file is automatically removed when closed (using
<function>fclose</function>), or when the script ends.
</para>
<para>
For details, consult your system documentation on the
<literal>tmpfile(3)</literal> function, as well as the
<filename>stdio.h</filename> header file.
</para>
<para>
See also <function>tempnam</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.touch">
<refnamediv>
<refname>touch</refname>
<refpurpose>Sets modification time of file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>touch</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int
<parameter>
<optional>time</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Attempts to set the modification time of the file named by
filename to the value given by time. If the option time is not
given, uses the present time.
</para>
<para>
If the file does not exist, it is created.
</para>
<para>
Returns true on success and false otherwise.
<example>
<title><function>Touch</function> example</title>
<programlisting role="php">
if (touch ($FileName)) {
print "$FileName modification time has been
changed to todays date and time";
} else {
print "Sorry Could Not change modification time of $FileName";
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.umask">
<refnamediv>
<refname>umask</refname>
<refpurpose>Changes the current umask</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>umask</function></funcdef>
<paramdef>int <parameter>mask</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Umask</function> 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.
</para>
<para>
<function>Umask</function> without arguments simply returns the
current umask.
</para>
<note>
<simpara>
This function may not work on Windows systems.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.unlink">
<refnamediv>
<refname>unlink</refname>
<refpurpose>Deletes a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>unlink</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes <parameter>filename</parameter>. Similar to the Unix C
unlink() function.
</para>
<para>
Returns 0 or FALSE on an error.
</para>
<para>
See also <function>rmdir</function> for removing directories.
</para>
<note>
<simpara>
This function may not work on Windows systems.
</simpara>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/ftp.xml
+++ phpdoc/nl/functions/ftp.xml
<reference id="ref.ftp">
<title>FTP functions</title>
<titleabbrev>FTP</titleabbrev>
<partintro>
<para>
FTP stands for File Transfer Protocol.</para>
<para>
The following constants are defined when using the FTP module:
<constant>FTP_ASCII</constant> and <constant>FTP_BINARY</constant>.
</para>
<para>
<example>
<title><function>ftp</function> example</title>
<programlisting>
<?php
// set up basic connection
$conn_id = ftp_connect("$ftp_server");
// login with username and password
$login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass");
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
echo "Attempted to connect to $ftp_server for user $user";
die;
} else {
echo "Connected to $ftp_server, for user $user";
}
// upload the file
$upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY);
// check upload status
if (!$upload) {
echo "Ftp upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_quit($conn_id);
?>
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.ftp-connect">
<refnamediv>
<refname>ftp_connect</refname>
<refpurpose>Opens up an FTP connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_connect</function></funcdef>
<paramdef>string <parameter>host</parameter></paramdef>
<paramdef>int <parameter><optional>port</optional>
</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a FTP stream on success, false on error.</para>
<para>
<function>ftp_connect</function> opens up a FTP connection to the
specified <parameter>host</parameter>. The <parameter>port</parameter>
parameter specifies an alternate port to connect to. If it is
omitted or zero, then the default FTP port, 21, will be used.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-login">
<refnamediv>
<refname>ftp_login</refname>
<refpurpose>Logs in an FTP connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_login</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
Logs in the given FTP stream.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-pwd">
<refnamediv>
<refname>ftp_pwd</refname>
<refpurpose>Returns the current directory name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ftp_pwd</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the current directory, or false on error.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-cdup">
<refnamediv>
<refname>ftp_cdup</refname>
<refpurpose>Changes to the parent directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_cdup</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
Changes to the parent directory.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-chdir">
<refnamediv>
<refname>ftp_chdir</refname>
<refpurpose>Changes directories on a FTP server</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_chdir</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
Changes to the specified <parameter>directory</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-mkdir">
<refnamediv>
<refname>ftp_mkdir</refname>
<refpurpose>Creates a directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ftp_mkdir</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the newly created directory name on success, false on error.</para>
<para>
Creates the specified <parameter>directory</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-rmdir">
<refnamediv>
<refname>ftp_rmdir</refname>
<refpurpose>Removes a directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_rmdir</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
Removes the specified <parameter>directory</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-nlist">
<refnamediv>
<refname>ftp_nlist</refname>
<refpurpose>Returns a list of files in the given directory.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ftp_nlist</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of filenames on success, false on error.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-rawlist">
<refnamediv>
<refname>ftp_rawlist</refname>
<refpurpose>
Returns a detailed list of files in the given directory.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_rawlist</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ftp_rawlist</function> executes the FTP LIST command,
and returns the result as an array. Each array element corresponds
to one line of text. The output is not parsed in any way. The
system type identifier returned by <function>ftp_systype</function>
can be used to determine how the results should be interpreted.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-systype">
<refnamediv>
<refname>ftp_systype</refname>
<refpurpose>
Returns the system type identifier of the remote FTP server.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ftp_systype</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the remote system type, or false on error.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-pasv">
<refnamediv>
<refname>ftp_pasv</refname>
<refpurpose>Turns passive mode on or off.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_pasv</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>int <parameter>pasv</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_pasv</function> turns on passive mode if the
<parameter>pasv</parameter> parameter is true (it turns off
passive mode if <parameter>pasv</parameter> is false.) In
passive mode, data connections are initiated by the client,
rather than by the server.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-get">
<refnamediv>
<refname>ftp_get</refname>
<refpurpose>Downloads a file from the FTP server.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_get</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>local_file</parameter></paramdef>
<paramdef>string <parameter>remote_file</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_get</function> retrieves
<parameter>remote_file</parameter>
from the FTP server, and saves it to <parameter>local_file</parameter>
locally. The transfer <parameter>mode</parameter> specified must
be either <constant>FTP_ASCII</constant> or
<constant>FTP_BINARY</constant>.
</para>
</refsect1>
</refentry>
<refentry id="function.ftp-fget">
<refnamediv>
<refname>ftp_fget</refname>
<refpurpose>Downloads a file from the FTP server and saves to an
open file.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_fget</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>string <parameter>remote_file</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_fget</function> retrieves
<parameter>remote_file</parameter>
from the FTP server, and writes it to the given file pointer,
<parameter>fp</parameter>. The transfer <parameter>mode</parameter>
specified must be either FTP_ASCII or FTP_BINARY.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-put">
<refnamediv>
<refname>ftp_put</refname>
<refpurpose>Uploads a file to the FTP server.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_put</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>remote_file</parameter></paramdef>
<paramdef>string <parameter>local_file</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_put</function> stores <parameter>local_file</parameter>
on the FTP server, as <parameter>remote_file</parameter>. The transfer
<parameter>mode</parameter> specified must be either
<constant>FTP_ASCII</constant> or <constant>FTP_BINARY</constant>.
</para>
<para>
<example>
<title><function>Ftp_put</function> example</title>
<programlisting role="php">
$upload = ftp_put ($conn_id, "$destination_file", "$source_file", FTP_ASCII);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.ftp-fput">
<refnamediv>
<refname>ftp_fput</refname>
<refpurpose>Uploads from an open file to the FTP server.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_fput</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>remote_file</parameter></paramdef>
<paramdef>int <parameter>fp</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_fput</function> uploads the data from the file pointer
<parameter>fp</parameter> until end of file. The results are stored
in <parameter>remote_file</parameter> on the FTP server. The transfer
<parameter>mode</parameter> specified must be either
<constant>FTP_ASCII</constant> or <constant>FTP_BINARY</constant>
</para>
</refsect1>
</refentry>
<refentry id="function.ftp-size">
<refnamediv>
<refname>ftp_size</refname>
<refpurpose>Returns the size of the given file.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_size</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>remote_file</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the file size on success, or -1 on error.</para>
<para>
<function>ftp_size</function> returns the size of a file. If an
error occurs, of if the file does not exist, -1 is returned. Not
all servers support this feature.</para>
</refsect1>
</refentry>
<refentry id="function.ftp-mdtm">
<refnamediv>
<refname>ftp_mdtm</refname>
<refpurpose>Returns the last modified time of the given file.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_mdtm</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>remote_file</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a UNIX timestamp on success, or -1 on error.</para>
<para>
<function>ftp_mdtm</function> checks the last-modified time for a
file, and returns it as a UNIX timestamp. If an error occurs, or
the file does not exist, -1 is returned. Note that not all servers
support this feature.
</para>
<note>
<para>
<function>ftp_mdtm</function> does not work with directories.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.ftp-rename">
<refnamediv>
<refname>ftp_rename</refname>
<refpurpose>Renames a file on the ftp server.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_rename</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>from</parameter></paramdef>
<paramdef>string <parameter>to</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_rename</function> renames the file specified
by <parameter>from</parameter> to the new name
<parameter>to</parameter>
</para>
</refsect1>
</refentry>
<refentry id="function.ftp-delete">
<refnamediv>
<refname>ftp_delete</refname>
<refpurpose>Deletes a file on the ftp server.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_delete</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_delete</function> deletes the file specified by
<parameter>path</parameter> from the FTP server.
</para>
</refsect1>
</refentry>
<refentry id="function.ftp-site">
<refnamediv>
<refname>ftp_site</refname>
<refpurpose>Sends a SITE command to the server.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_site</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
<paramdef>string <parameter>cmd</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ftp_site</function> sends the command specified by
<parameter>cmd</parameter> to the FTP server. SITE commands
are not standardized, and vary from server to server. They are
useful for handling such things as file permissions and group
membership. </para>
</refsect1>
</refentry>
<refentry id="function.ftp-quit">
<refnamediv>
<refname>ftp_quit</refname>
<refpurpose>Closes an FTP connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ftp_quit</function></funcdef>
<paramdef>int <parameter>ftp_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ftp_connect</function> closes
<parameter>ftp_stream</parameter>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/funchand.xml
+++ phpdoc/nl/functions/funchand.xml
<reference id="ref.funchand">
<title>Function Handling functions</title>
<titleabbrev>Functions</titleabbrev>
<partintro>
<para>
These functions all handle various operations involved in working
with functions.
</para>
</partintro>
<refentry id="function.call-user-func">
<refnamediv>
<refname>call_user_func</refname>
<refpurpose>
Call a user function given by the first parameter
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed
<function>call_user_func</function>
</funcdef>
<paramdef>string
<parameter>function_name</parameter>
</paramdef>
<paramdef>mixed
<parameter><optional>parameter</optional></parameter>
</paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Call a user defined function given by the
<parameter>function_name</parameter> parameter. Take the
following:
<informalexample>
<programlisting role="php">
function barber ($type) {
print "You wanted a $type haircut, no problem";
}
call_user_func ('barber', "mushroom");
call_user_func ('barber', "shave");
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.create-function">
<refnamediv>
<refname>create_function</refname>
<refpurpose>Create an anonymous (lambda-style) function</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>create_function</function></funcdef>
<paramdef>string <parameter>args</parameter></paramdef>
<paramdef>string <parameter>code</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Creates an anonymous function from the parameters passed, and
returns a unique name for it. Usually the
<parameter>args</parameter> will be passed as a single quote
delimited string, and this is also recommended for the
<parameter>code</parameter>. 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.
<literal>\$avar</literal>.
</para>
<para>
You can use this function, to (for example) create a function
from information gathered at run time:
<example>
<title>
Creating an anonymous function with <function>create_function</function>
</title>
<programlisting role="php">
$newfunc = create_function('$a,$b','return "ln($a) + ln($b) = ".log($a *
$b);');
echo "New anonymous function: $newfunc\n";
echo $newfunc(2,M_E)."\n";
// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599
</programlisting>
</example>
Or, perhaps to have general handler function that can apply a set
of operations to a list of parameters:
<example>
<title>
Making a general processing function with
<function>create_function</function>
</title>
<programlisting role="php">
function process($var1, $var2, $farr) {
for ($f=0; $f < count($farr); $f++)
echo $farr[$f]($var1,$var2)."\n";
}
// create a bunch of math functions
$f1 = 'if ($a >=0) {return "b*a^2 = ".$b*sqrt($a);} else {return
false;}';
$f2 = "return \"min(b^2+a, a^2,b) = \".min(\$a*\$a+\$b,\$b*\$b+\$a);";
$f3 = 'if ($a > 0 && $b != 0) {return "ln(a)/b =
".log($a)/$b;} else {return false;}';
$farr = array(
create_function('$x,$y', 'return "some trig: ".(sin($x) +
$x*cos($y));'),
create_function('$x,$y', 'return "a hypotenuse: ".sqrt($x*$x +
$y*$y);'),
create_function('$a,$b', $f1),
create_function('$a,$b', $f2),
create_function('$a,$b', $f3)
);
echo "\nUsing the first array of anonymous functions\n";
echo "parameters: 2.3445, M_PI\n";
process(2.3445, M_PI, $farr);
// now make a bunch of string processing functions
$garr = array(
create_function('$b,$a','if (strncmp($a,$b,3) == 0) return "**
\"$a\" '.
'and \"$b\"\n** Look the same to me! (looking at the first 3
chars)";'),
create_function('$a,$b','; return "CRCs: ".crc32($a)." ,
".crc32(b);'),
create_function('$a,$b','; return "similar(a,b) =
".similar_text($a,$b,&$p)."($p%)";')
);
echo "\nUsing the second array of anonymous functions\n";
process("Twas brilling and the slithy toves", "Twas the night", $garr);
</programlisting>
</example>
and when you run the code above, the output will be:
<informalexample>
<programlisting>
Using the first array of anonymous functions
parameters: 2.3445, M_PI
some trig: -1.6291725057799
a hypotenuse: 3.9199852871011
b*a^2 = 4.8103313314525
min(b^2+a, a^2,b) = 8.6382729035898
ln(a/b) = 0.27122299212594
Using the second array of anonymous functions
** "Twas the night" and "Twas brilling and the slithy toves"
** Look the same to me! (looking at the first 3 chars)
CRCs: -725381282 , 1908338681
similar(a,b) = 11(45.833333333333%)
</programlisting>
</informalexample>
But perhaps the most common use for of lambda-style (anonymous) functions
is to create callback functions, for example when using
<function>array_walk</function> or <function>usort</function>
<example>
<title>Using anonymous functions as callback functions</title>
<programlisting role="php">
$av = array("the ","a ","that ","this ");
array_walk($av, create_function('&$v,$k','$v = $v."mango";'));
print_r($av); // for PHP 3 use var_dump()
// outputs:
// Array
// (
// [0] => the mango
// [1] => a mango
// [2] => that mango
// [3] => this mango
// )
// an array of strings ordered from shorter to longer
$sv = array("small","larger","a big string","it is a string
thing");
print_r($sv);
// outputs:
// Array
// (
// [0] => small
// [1] => larger
// [2] => a big string
// [3] => it is a string thing
// )
// sort it from longer to shorter
usort($sv, create_function('$a,$b','return strlen($b) - strlen($a);'));
print_r($sv);
// outputs:
// Array
// (
// [0] => it is a string thing
// [1] => a big string
// [2] => larger
// [3] => small
// )
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.func-get-arg">
<refnamediv>
<refname>func_get_arg</refname>
<refpurpose>Return an item from the argument list</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>func_get_arg</function></funcdef>
<paramdef>int <parameter>arg_num</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the argument which is at the
<parameter>arg_num</parameter>'th offset into a user-defined
function's argument list. Function arguments are counted starting
from zero. <function>Func_get_arg</function> will generate a
warning if called from outside of a function definition.
</simpara>
<simpara>
If <parameter>arg_num</parameter> is greater than the number of
arguments actually passed, a warning will be generated and
<function>func_get_arg</function> will return FALSE.
</simpara>
<para>
<informalexample>
<programlisting role="php">
<?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);
?>
</programlisting>
</informalexample>
</para>
<simpara>
<function>Func_get_arg</function> may be used in conjunction with
<function>func_num_args</function> and
<function>func_get_args</function> to allow user-defined
functions to accept variable-length argument lists.
</simpara>
<note>
<simpara>
This function was added in PHP 4.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.func-get-args">
<refnamediv>
<refname>func_get_args</refname>
<refpurpose>
Returns an array comprising a function's argument list
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>func_get_args</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns an array in which each element is the corresponding
member of the current user-defined function's argument
list. <function>Func_get_args</function> will generate a warning
if called from outside of a function definition.
</simpara>
<para>
<informalexample>
<programlisting role="php">
<?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);
?>
</programlisting>
</informalexample>
</para>
<simpara>
<function>Func_get_args</function> may be used in conjunction
with <function>func_num_args</function> and
<function>func_get_arg</function> to allow user-defined functions
to accept variable-length argument lists.
</simpara>
<note>
<simpara>
This function was added in PHP 4.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.func-num-args">
<refnamediv>
<refname>func_num_args</refname>
<refpurpose>
Returns the number of arguments passed to the function
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>func_num_args</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the number of arguments passed into the current
user-defined function. <function>Func_num_args</function> will
generate a warning if called from outside of a function
definition.
</simpara>
<para>
<informalexample>
<programlisting role="php">
<?php
function foo() {
$numargs = func_num_args();
echo "Number of arguments: $numargs\n";
}
foo (1, 2, 3); // Prints 'Number of arguments: 3'
?>
</programlisting>
</informalexample>
</para>
<simpara>
<function>Func_num_args</function> may be used in conjunction
with <function>func_get_arg</function> and
<function>func_get_args</function> to allow user-defined
functions to accept variable-length argument lists.
</simpara>
<note>
<simpara>
This function was added in PHP 4.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.function-exists">
<refnamediv>
<refname>function_exists</refname>
<refpurpose>
Return true if the given function has been defined
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>function_exists</function></funcdef>
<paramdef>string <parameter>function_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Checks the list of defined functions for
<parameter>function_name</parameter>. Returns true if the given
function name was found, false otherwise.
</simpara>
</refsect1>
</refentry>
<refentry id="function.register-shutdown-function">
<refnamediv>
<refname>register_shutdown_function</refname>
<refpurpose>
Register a function for execution on shutdown
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>register_shutdown_function</function>
</funcdef>
<paramdef>string <parameter>func</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Registers the function named by <parameter>func</parameter> to be
executed when script processing is complete.</simpara>
<para>
Common Pitfalls:
</para>
<simpara>
Since no output is allowed to the browser in this function, you
will be unable to debug it using statements such as print or
echo.
</simpara>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/gettext.xml
+++ phpdoc/nl/functions/gettext.xml
<reference id="ref.gettext">
<title>GNU Gettext</title>
<titleabbrev>gettext</titleabbrev>
<partintro>
<simpara>
The gettext functions implement a NLS (Native Language Support)
API which can be used to internationalize your PHP applications.
Please see the GNU gettext documentation for a thorough explanation
of these functions.
</simpara>
</partintro>
<refentry id="function.bindtextdomain">
<refnamediv>
<refname>bindtextdomain</refname>
<refpurpose>Sets the path for a domain</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bindtextdomain</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>bindtextdomain</function> function sets the path
for a domain.
</para>
</refsect1>
</refentry>
<refentry id="function.dcgettext">
<refnamediv>
<refname>dcgettext</refname>
<refpurpose>Overrides the domain for a single lookup</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dcgettext</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>message</parameter></paramdef>
<paramdef>int <parameter>category</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function allows you to override the current domain for a
single message lookup. It also allows you to specify a category.
</para>
</refsect1>
</refentry>
<refentry id="function.dgettext">
<refnamediv>
<refname>dgettext</refname>
<refpurpose>Override the current domain</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dgettext</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>message</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>dgettext</function> function allows you to override
the current domain for a single message lookup.
</para>
</refsect1>
</refentry>
<refentry id="function.gettext">
<refnamediv>
<refname>gettext</refname>
<refpurpose>Lookup a message in the current domain</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gettext</function></funcdef>
<paramdef>string <parameter>message</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns a translated string if one is found in the
translation table, or the submitted message if not found. You may
use an underscore character as an alias to this function.
</para>
<example>
<title><function>Gettext</function>-check</title>
<programlisting>
<?php
// Set language to German
putenv ("LANG=de");
// Specify location of translation tables
bindtextdomain ("myPHPApp", "./locale");
// Choose domain
textdomain ("myPHPApp");
// Print a test message
print (gettext ("Welcome to My PHP Application"));
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.textdomain">
<refnamediv>
<refname>textdomain</refname>
<refpurpose>Sets the default domain</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>textdomain</function></funcdef>
<paramdef>string
<parameter><optional>library</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function sets the domain to search within when calls are
made to <function>gettext</function>, usually the named after an
application. The previous default domain is returned. Call it
with no parameters to get the current setting without changing
it.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/http.xml
+++ phpdoc/nl/functions/http.xml
<reference id="ref.http">
<title>HTTP functions</title>
<titleabbrev>HTTP</titleabbrev>
<partintro>
<simpara>
These functions let you manipulate the output sent back to the
remote browser right down to the HTTP protocol level.
</simpara>
</partintro>
<refentry id="function.header">
<refnamediv>
<refname>header</refname>
<refpurpose>Send a raw HTTP header</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>header</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>Header</function> function is used at the top of an
<acronym>HTML</acronym> file to send raw <acronym>HTTP</acronym>
header strings. See the <ulink url="&spec.http1.1;">HTTP 1.1
Specification</ulink> for more information on raw http headers.
<emphasis>Note:</emphasis> Remember that the
<function>Header</function> function must be called before any
actual output is sent either by normal HTML tags or from PHP. It
is a very common error to read code with
<function>include</function> or with auto_prepend and have spaces
or empty lines in this code that force output before
<function>header</function> is called.
</para>
<para>
There are two special-case header calls. The first is the
"Location" header. Not only does it send this header
back to the browser, it also returns a REDIRECT status code to
Apache. From a script writer's point of view this should not be
important, but for people who understand Apache internals it is
important to understand.
<informalexample>
<programlisting role="php">
header ("Location: http://www.php.net"); /*
Redirect browser
to PHP web site */
exit; /* Make sure that code below does
not get executed when we redirect. */
</programlisting>
</informalexample>
</para>
<para>
The second special-case is any header that starts with the
string, "HTTP/" (case is not significant). For
example, if you have your ErrorDocument 404 Apache directive
pointed to a PHP script, it would be a good idea to make sure
that your PHP script is actually generating a 404. The first
thing you do in your script should then be:
<informalexample>
<programlisting role="php">
header ("HTTP/1.0 404 Not Found");
</programlisting>
</informalexample>
</para>
<para>
PHP scripts often generate dynamic HTML that must not be cached
by the client browser or any proxy caches between the server and the
client browser. Many proxies and clients can be forced to disable
caching with
<informalexample>
<programlisting role="php">
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
</programlisting>
</informalexample>
</para>
<para>
See also <function>headers_sent</function>
</para>
</refsect1>
</refentry>
<refentry id="function.headers-sent">
<refnamediv>
<refname>headers_sent</refname>
<refpurpose>Returns true if headers have been sent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>headers_sent</function></funcdef>
<paramdef><parameter>void</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns true if the HTTP headers have already been
sent, false otherwise.
</para>
<para>
See also <function>header</function>
</para>
</refsect1>
</refentry>
<refentry id="function.setcookie">
<refnamediv>
<refname>setcookie</refname>
<refpurpose>Send a cookie</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>setcookie</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>string
<parameter><optional>value</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>expire</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>path</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>domain</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>secure</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Setcookie</function> defines a cookie to be sent along
with the rest of the header information. Cookies must be sent
<emphasis>before</emphasis> any other headers are sent (this is a
restriction of cookies, not PHP). This requires you to place
calls to this function before any <literal><html></literal> or
<literal><head></literal> tags.
</para>
<para>
All the arguments except the <parameter>name</parameter> argument
are optional. If only the name argument is present, the cookie
by that name will be deleted from the remote client. You may
also replace any argument with an empty string
(<emphasis>""</emphasis>) in order to skip that
argument. The <parameter>expire</parameter> and
<parameter>secure</parameter> arguments are integers and cannot
be skipped with an empty string. Use a zero
(<emphasis>0</emphasis>) instead. The
<parameter>expire</parameter> argument is a regular Unix time
integer as returned by the <function>time</function> or
<function>mktime</function> functions. The
<parameter>secure</parameter> indicates that the cookie should
only be transmitted over a secure HTTPS connection.
</para>
<para>
Common Pitfalls:
<itemizedlist>
<listitem>
<simpara>
Cookies will not become visible until the next loading of a page that
the cookie should be visible for.
</simpara>
</listitem>
<listitem>
<simpara>
Cookies must be deleted with the same parameters as they were set with.
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
In PHP 3, multiple calls to <function>setcookie</function> in the same
script will be performed in reverse order. If you are trying to
delete one cookie before inserting another you should put the
insert before the delete. In PHP 4, multiple calls to
<function>setcookie</function> are performed in the order called.
</simpara>
<para>
Some examples follow how to send cookies:
<example>
<title><function>Setcookie</function> send examples</title>
<programlisting role="php">
setcookie ("TestCookie", "Test Value");
setcookie ("TestCookie", $value,time()+3600); /* expire in 1 hour */
setcookie ("TestCookie", $value,time()+3600, "/~rasmus/",
".utoronto.ca", 1);
</programlisting>
</example>
</para>
<para>
Examples follow how to delete cookies send in previous example:
<example>
<title><function>setcookie</function> delete examples</title>
<programlisting role="php">
setcookie ("TestCookie");
// set the expiration date to one hour ago
setcookie ("TestCookie", "", time() - 3600);
setcookie ("TestCookie", "", time() - 3600, "/~rasmus/",
".utoronto.ca", 1);
</programlisting>
</example>
When deleting a cookie you should assure that the expiration date
is in the past, to trigger the removal mechanism in your browser.
</para>
<para>
Note that the value portion of the cookie will automatically be
urlencoded when you send the cookie, and when it is received, it
is automatically decoded and assigned to a variable by the same
name as the cookie name. To see the contents of our test
cookie in a script, simply use one of the following examples:
<informalexample>
<programlisting role="php">
echo $TestCookie;
echo $HTTP_COOKIE_VARS["TestCookie"];
</programlisting>
</informalexample>
</para>
<para>
You may also set array cookies by using array notation in the
cookie name. This has the effect of setting as many cookies as
you have array elements, but when the cookie is received by your
script, the values are all placed in an array with the cookie's
name:
<informalexample>
<programlisting role="php">
setcookie ("cookie[three]", "cookiethree");
setcookie ("cookie[two]", "cookietwo");
setcookie ("cookie[one]", "cookieone");
if (isset ($cookie)) {
while (list ($name, $value) = each ($cookie)) {
echo "$name == $value<br>\n";
}
}
</programlisting>
</informalexample>
</para>
<para>
For more information on cookies, see Netscape's cookie
specification at <ulink
url="&spec.cookies;">&spec.cookies;</ulink>.
</para>
<simpara>
Microsoft Internet Explorer 4 with Service Pack 1 applied does
not correctly deal with cookies that have their path parameter
set.
</simpara>
<simpara>
Netscape Communicator 4.05 and Microsoft Internet Explorer 3.x
appear to handle cookies incorrectly when the path and time
are not set.
</simpara>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/hw.xml
+++ phpdoc/nl/functions/hw.xml
<reference id="ref.hyperwave">
<title>Hyperwave functions</title>
<titleabbrev>Hyperwave</titleabbrev>
<partintro>
<sect1 id="hw-intro">
<title>Introduction</title>
<para>
<productname>Hyperwave</productname> has been developed at <ulink
url="&url.iicm;">IICM</ulink> in Graz. It started with
the name <acronym>Hyper-G</acronym> and changed to Hyperwave when
it was commercialised (If I remember properly it was in 1996).
</para>
<para>
Hyperwave is not free software. The current version, 4.1, is
available at <ulink url="&url.hyperwave;">www.hyperwave.com</ulink>.
A time limited version can be ordered for free (30 days).
</para>
<para>
Hyperwave is an information system similar to a database
(<acronym>HIS</acronym>, 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.
</para>
<para>
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.)
</para>
<para>
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
<function>hw_pipedocument</function> and
<function>hw_gettext</function>
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.
</para>
<para>
Saying that <function>hw_pipedocument</function> and
<function>hw_gettext</function> 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.
</para>
<para>
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/php3_script/my_object' and the
script 'php3_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.
</para>
<para>
Based on the above mechanism links are insert into documents.
</para>
<para>
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. '_'. to be continued.
</para>
<para>
The network protocol to communicate
with the Hyperwave server is called <ulink
url="&spec.hyperwave;">HG-CSP</ulink>
(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 <abbrev>HTTP</abbrev> to <abbrev>HG-CSP</abbrev>. 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 <abbrev>PLACE</abbrev> Language.
<abbrev>PLACE</abbrev> 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.
</para>
<para>
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
<abbrev>HG-CSP</abbrev> but also provides more powerful commands
to e.g. retrieve complete documents.
</para>
<para>
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.
<itemizedlist>
<listitem>
<simpara>
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.
</simpara>
</listitem>
<listitem>
<simpara>
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 <function>hw_object2array</function>.
Several functions return object records. The names of those
functions end with obj.
</simpara>
</listitem>
<listitem>
<simpara>
object array: An associated array with all attributes of an
object. The key is the attribute name. If an attribute occurs
more than once in an object record it will result in another
indexed or associated array. Attributes which are language
depended (like the title, keyword, description) will form an
associated array with the key set to the language
abbreviation. All other multiple attributes will form an
indexed array. PHP functions never return object arrays.
</simpara>
</listitem>
<listitem>
<simpara>
hw_document: This is a complete new data type which holds the
actual document, e.g. HTML, PDF etc. It is somewhat optimised
for HTML documents but may be used for any format.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
Several functions which return an array of object records do also
return an associated array with statistical information about
them. The array is the last element of the object record
array. The statistical array contains the following entries:
<variablelist>
<varlistentry>
<term>Hidden</term>
<listitem>
<simpara>
Number of object records with attribute PresentationHints
set to Hidden.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>CollectionHead</term>
<listitem>
<simpara>
Number of object records with attribute
PresentationHints set to CollectionHead.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>FullCollectionHead</term>
<listitem>
<simpara>
Number of object records with attribute
PresentationHints set to FullCollectionHead.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>CollectionHeadNr</term>
<listitem>
<simpara>
Index in array of object records with
attribute PresentationHints set to CollectionHead.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>FullCollectionHeadNr</term>
<listitem>
<simpara>
Index in array of object records with
attribute PresentationHints set to FullCollectionHead.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>Total</term>
<listitem>
<simpara>
Total: Number of object records.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</sect1>
<sect1 id="hw-apache">
<title>Integration with Apache</title>
<para>
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.
</para>
<para>
Since PHP with Hyperwave support built into Apache is intended
to replace the native Hyperwave solution based on Wavemaster I
will assume that the Apache server will only serve as a Hyperwave
web interface. 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 <envar>PATH_INFO</envar>
variable and treats its value as the name of a Hyperwave
object. Let's call this script 'Hyperwave'. The URL
<systemitem role="url">http://your.hostname/Hyperwave/name_of_object</systemitem>
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
<systemitem role="url">http://your.hostname/name_of_object</systemitem>
would
return the object. The rewriting rule is quite easy:
<informalexample><programlisting role="apache-conf">
RewriteRule ^/(.*) /usr/local/apache/htdocs/HyperWave/$1 [L]
</programlisting></informalexample>
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:
<informalexample><programlisting role="apache-conf">
RewriteRule ^/hw/(.*) /usr/local/apache/htdocs/hw/$1 [L]
</programlisting></informalexample>
This will reserve the directory <filename
class="directory">/usr/local/apache/htdocs/hw</filename> 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. Finally, don't forget to turn on the
rewriting engine with
<informalexample><programlisting role="apache-conf">
RewriteEngine on
</programlisting></informalexample>
My experiences have shown that you will need the following
scripts:
<itemizedlist>
<listitem>
<simpara>
to return the object itself
</simpara>
</listitem>
<listitem>
<simpara>
to allow searching
</simpara>
</listitem>
<listitem>
<simpara>
to identify yourself
</simpara>
</listitem>
<listitem>
<simpara>
to set your profile
</simpara>
</listitem>
<listitem>
<simpara>
one for each additional function like to show
the object attributes, to show information about users,
to show the status of the server, etc.
</simpara>
</listitem>
</itemizedlist>
</para>
</sect1>
<sect1 id="hw-todo">
<title>Todo</title>
<para>
There are still some things todo:
<itemizedlist>
<listitem><simpara>The hw_InsertDocument has to be split into
<function>hw_InsertObject</function> and
<function>hw_PutDocument</function>.</simpara></listitem>
<listitem><simpara>The names of several functions are not fixed, yet.
</simpara></listitem>
<listitem><simpara>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.</simpara></listitem>
<listitem><simpara>Conversion form object record into object array
needs to handle any multiple attribute.
</simpara></listitem>
</itemizedlist>
</para>
</sect1>
</partintro>
<refentry id="function.hw-array2objrec">
<refnamediv>
<refname>hw_Array2Objrec</refname>
<refpurpose>convert attributes from object array to object record</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>strin <function>hw_array2objrec</function></funcdef>
<paramdef>array <parameter>object_array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts an <parameter>object_array</parameter> into an object record.
Multiple attributes like 'Title' in different languages are treated
properly.
</para>
<para>
See also <function>hw_objrec2array</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-children">
<refnamediv>
<refname>hw_Children</refname>
<refpurpose>object ids of children</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_children</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of object ids. Each id
belongs to a child of the collection with ID
<parameter>objectID</parameter>.
The array contains all children both documents and collections.</para>
</refsect1>
</refentry>
<refentry id="function.hw-childrenobj">
<refnamediv>
<refname>hw_ChildrenObj</refname>
<refpurpose>object records of children</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_childrenobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of object records. Each object record
belongs to a child of the collection with ID
<parameter>objectID</parameter>.
The array contains all children both documents and collections.</para>
</refsect1>
</refentry>
<refentry id="function.hw-close">
<refnamediv>
<refname>hw_Close</refname>
<refpurpose>closes the Hyperwave connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_close</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-connect">
<refnamediv>
<refname>hw_Connect</refname>
<refpurpose>opens a connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_connect</function></funcdef>
<paramdef>string <parameter>host</parameter></paramdef>
<paramdef>int <parameter>port</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 <parameter>username</parameter> and
<parameter>password</parameter> 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.
</para>
<para>
See also <function>hw_pConnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-cp">
<refnamediv>
<refname>hw_Cp</refname>
<refpurpose>copies objects</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_cp</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>array <parameter>object_id_array</parameter></paramdef>
<paramdef>int <parameter>destination id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Copies the objects with object ids as specified in the second
parameter to the collection
with the id <parameter>destination id</parameter>.
</para>
<para>
The value return is the number of copied objects.
</para>
<para>
See also <function>hw_mv</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-deleteobject">
<refnamediv>
<refname>hw_Deleteobject</refname>
<refpurpose>deletes object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_deleteobject</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>object_to_delete</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes the object with the given object id in the second
parameter. It will delete all instances of the object.
</para>
<para>
Returns TRUE if no error occurs otherwise FALSE.
</para>
<para>
See also <function>hw_mv</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-docbyanchor">
<refnamediv>
<refname>hw_DocByAnchor</refname>
<refpurpose>object id object belonging to anchor</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_docbyanchor</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>anchorID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an th object id of the document to
which <parameter>anchorID</parameter> belongs.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-docbyanchorobj">
<refnamediv>
<refname>hw_DocByAnchorObj</refname>
<refpurpose>object record object belonging to anchor</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_docbyanchorobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>anchorID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an th object record of the document to
which <parameter>anchorID</parameter> belongs.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-document-attributes">
<refnamediv>
<refname>hw_Document_Attributes</refname>
<refpurpose>object record of hw_document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_document_attributes</function></funcdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the object record of the document.
</para>
<para>
For backward compatibility, <function>hw_DocumentAttributes</function>
is also accepted. This is deprecated, however.
</para>
<para>
See also <function>hw_Document_BodyTag</function>,
and <function>hw_Document_Size</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-document-bodytag">
<refnamediv>
<refname>hw_Document_BodyTag</refname>
<refpurpose>body tag of hw_document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_document_bodytag</function></funcdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the BODY tag of the document. If the document is an HTML
document the BODY tag should be printed before the document.
</para>
<para>
See also <function>hw_Document_Attributes</function>,
and <function>hw_Document_Size</function>.
</para>
<para>
For backward compatibility, <function>hw_DocumentBodyTag</function>
is also accepted. This is deprecated, however.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-document-content">
<refnamediv>
<refname>hw_Document_Content</refname>
<refpurpose>returns content of hw_document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_document_content</function></funcdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
See also <function>hw_Document_Attributes</function>,
<function>hw_Document_Size</function>,
and <function>hw_DocumentSetContent</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-document-setcontent">
<refnamediv>
<refname>hw_Document_SetContent</refname>
<refpurpose>sets/replaces content of hw_document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_document_setcontent</function></funcdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
<paramdef>string <parameter>content</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
See also <function>hw_Document_Attributes</function>,
<function>hw_Document_Size</function>,
and <function>hw_Document_Content</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-document-size">
<refnamediv>
<refname>hw_Document_Size</refname>
<refpurpose>size of hw_document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_document_size</function></funcdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the size in bytes of the document.</para>
<para>
See also <function>hw_Document_BodyTag</function>,
and <function>hw_Document_Attributes</function>.
</para>
<para>
For backward compatibility, <function>hw_DocumentSize</function>
is also accepted. This is deprecated, however.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-errormsg">
<refnamediv>
<refname>hw_ErrorMsg</refname>
<refpurpose>returns error message</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_errormsg</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-edittext">
<refnamediv>
<refname>hw_EditText</refname>
<refpurpose>retrieve text document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_edittext</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
See also <function>hw_PipeDocument</function>,
<function>hw_FreeDocument</function>,
<function>hw_Document_BodyTag</function>,
<function>hw_Document_Size</function>,
<function>hw_Output_Document</function>,
<function>hw_GetText</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-error">
<refnamediv>
<refname>hw_Error</refname>
<refpurpose>error number</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_error</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the last error number. If the return value is 0 no error has
occurred. The error relates to the last command.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-free-document">
<refnamediv>
<refname>hw_Free_Document</refname>
<refpurpose>frees hw_document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_free_document</function></funcdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Frees the memory occupied by the Hyperwave document.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getparents">
<refnamediv>
<refname>hw_GetParents</refname>
<refpurpose>object ids of parents</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getparents</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an indexed array of object ids. Each object id belongs to
a parent of the object with ID <parameter>objectID</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getparentsobj">
<refnamediv>
<refname>hw_GetParentsObj</refname>
<refpurpose>object records of parents</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getparentsobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 <parameter>objectID</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getchildcoll">
<refnamediv>
<refname>hw_GetChildColl</refname>
<refpurpose>object ids of child collections</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getchildcoll</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of object ids. Each object ID
belongs to a child collection of the collection with ID
<parameter>objectID</parameter>. The function will not
return child documents.</para>
<para>
See also <function>hw_GetChildren</function>,
and <function>hw_GetChildDocColl</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getchildcollobj">
<refnamediv>
<refname>hw_GetChildCollObj</refname>
<refpurpose>object records of child collections</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getchildcollobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of object records. Each object records
belongs to a child collection of the collection with ID
<parameter>objectID</parameter>. The function will not return
child documents.
</para>
<para>
See also <function>hw_ChildrenObj</function>,
and <function>hw_GetChildDocCollObj</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getremote">
<refnamediv>
<refname>hw_GetRemote</refname>
<refpurpose>Gets a remote document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_getremote</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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
throught 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 <function>hw_GetRemote</function> 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.
</para>
<para>
See also <function>hw_GetRemoteChildren</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getremotechildren">
<refnamediv>
<refname>hw_GetRemoteChildren</refname>
<refpurpose>Gets children of remote document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_getremotechildren</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>string <parameter>object record</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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
<function>hw_GetRemoteChildren</function>. Those object records are
virtual and do not exist in the Hyperwave server, therefore they
do not have a valid object ID. How exactely 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.
</para>
<para>
See also <function>hw_GetRemote</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getsrcbydestobj">
<refnamediv>
<refname>hw_GetSrcByDestObj</refname>
<refpurpose>Returns anchors pointing at object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getsrcbydestobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the object records of all anchors pointing to the object with ID
<parameter>objectID</parameter>. The object can either be a document
or an anchor of type destination.</para>
<para>
See also <function>hw_GetAnchors</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getobject">
<refnamediv>
<refname>hw_GetObject</refname>
<refpurpose>object record</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getobject</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>[int|array] <parameter>objectID</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the object record for the object with ID
<parameter>objectID</parameter> 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.
</para>
<para>
The query string has the following syntax:</para>
<simpara>
<expr> ::= "(" <expr> ")" |</simpara>
<simpara>
"!" <expr> | /* NOT */</simpara><simpara>
<expr> "||" <expr> | /* OR
*/</simpara><simpara>
<expr> "&&" <expr> | /* AND
*/</simpara><simpara>
<attribute> <operator>
<value></simpara><simpara>
<attribute> ::= /* any attribute name (Title, Author, DocumentType ...)
*/</simpara><simpara>
<operator> ::= "=" | /* equal */</simpara><simpara>
"<" | /* less than (string compare)
*/</simpara><simpara>
">" | /* greater than (string compare)
*/</simpara><simpara>
"~" /* regular expression matching
*/</simpara><simpara></simpara>
<para>
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.
</para>
<para>
See also <function>hw_GetAndLock</function>,
and <function>hw_GetObjectByQuery</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getandlock">
<refnamediv>
<refname>hw_GetAndLock</refname>
<refpurpose>return bject record and lock object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_getandlock</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the object record for the object with ID
<parameter>objectID</parameter>.
It will also lock the object, so other users cannot access
it until it is unlocked.
</para>
<para>
See also <function>hw_Unlock</function>,
and <function>hw_GetObject</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-gettext">
<refnamediv>
<refname>hw_GetText</refname>
<refpurpose>retrieve text document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_gettext</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
<paramdef>mixed
<parameter>
<optional>rootID/prefix</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the document with object ID
<parameter>objectID</parameter>. If the document
has anchors which can be inserted, they will be inserted already.
The optional parameter <parameter>rootID/prefix</parameter> 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 hierachy 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
<parameter>rootID/prefix</parameter> to any prefix which
is used instead. Is this case it has to be a string.
</para>
<para>
If <parameter>rootID/prefix</parameter> is an integer and
unequal to 0 the link is constructed from all the names
starting at the object with the id <parameter>rootID/prefix</parameter>
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 seperator between
hierachy 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 hierachy onto the file system.
</para>
<para>
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.
</para>
<para>
See also <function>hw_PipeDocument</function>,
<function>hw_FreeDocument</function>,
<function>hw_Document_BodyTag</function>,
<function>hw_Document_Size</function>,
and <function>hw_Output_Document</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getobjectbyquery">
<refnamediv>
<refname>hw_GetObjectByQuery</refname>
<refpurpose>search object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getobjectbyquery</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>max_hits</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches for objects on the whole server and returns an array of
object ids. The maximum number of matches is limited to
<parameter>max_hits</parameter>. If <parameter>max_hits</parameter>
is set to -1 the maximum number of matches is unlimited.
</para>
<para>
The query will only work with indexed attributes.
</para>
<para>
See also <function>hw_GetObjectByQueryObj</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getobjectbyqueryobj">
<refnamediv>
<refname>hw_GetObjectByQueryObj</refname>
<refpurpose>search object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getobjectbyqueryobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>max_hits</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches for objects on the whole server and returns an array of
object records. The maximum number of matches is limited to
<parameter>max_hits</parameter>. If <parameter>max_hits</parameter>
is set to -1 the maximum number of matches is unlimited.
</para>
<para>
The query will only work with indexed attributes.
</para>
<para>
See also <function>hw_GetObjectByQuery</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getobjectbyquerycoll">
<refnamediv>
<refname>hw_GetObjectByQueryColl</refname>
<refpurpose>search object in collection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getobjectbyquerycoll</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>max_hits</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches for objects in collection with ID
<parameter>objectID</parameter> and returns an array of
object ids. The maximum number of matches is limited to
<parameter>max_hits</parameter>.
If <parameter>max_hits</parameter>
is set to -1 the maximum number of matches is unlimited.
</para>
<para>
The query will only work with indexed attributes.</para>
<para>
See also <function>hw_GetObjectByQueryCollObj</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getobjectbyquerycollobj">
<refnamediv>
<refname>hw_GetObjectByQueryCollObj</refname>
<refpurpose>search object in collection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array
<function>hw_getobjectbyquerycollobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>max_hits</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches for objects in collection with ID
<parameter>objectID</parameter> and returns an array of
object records. The maximum number of matches is limited to
<parameter>max_hits</parameter>.
If <parameter>max_hits</parameter>
is set to -1 the maximum number of matches is unlimited.
</para>
<para>
The query will only work with indexed attributes.
</para>
<para>
See also <function>hw_GetObjectByQueryColl</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getchilddoccoll">
<refnamediv>
<refname>hw_GetChildDocColl</refname>
<refpurpose>object ids of child documents of collection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getchilddoccoll</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns array of object ids for child documents of a collection.
</para>
<para>
See also <function>hw_GetChildren</function>,
and <function>hw_GetChildColl</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getchilddoccollobj">
<refnamediv>
<refname>hw_GetChildDocCollObj</refname>
<refpurpose>object records of child documents of collection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getchilddoccollobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of object records for child documents of a collection.</para>
<para>
See also <function>hw_ChildrenObj</function>,
and <function>hw_GetChildCollObj</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getanchors">
<refnamediv>
<refname>hw_GetAnchors</refname>
<refpurpose>object ids of anchors of document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getanchors</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of object ids with anchors of the document
with object ID <parameter>objectID</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getanchorsobj">
<refnamediv>
<refname>hw_GetAnchorsObj</refname>
<refpurpose>object records of anchors of document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_getanchorsobj</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of object records with anchors of the document
with object ID <parameter>objectID</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-mv">
<refnamediv>
<refname>hw_Mv</refname>
<refpurpose>moves objects</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_mv</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>array <parameter>object id array</parameter></paramdef>
<paramdef>int <parameter>source id</parameter></paramdef>
<paramdef>int <parameter>destination id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Moves the objects with object ids as specified in the second
parameter from the collection with id <parameter>source id</parameter>
to the collection with the id <parameter>destination id</parameter>.
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 <function>hw_deleteobject</function>.
</para>
<para>
The value return is the number of moved objects.
</para>
<para>
See also <function>hw_cp</function>,
and <function>hw_deleteobject</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-identify">
<refnamediv>
<refname>hw_Identify</refname>
<refpurpose>identifies as user</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_identify</function></funcdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identifies as user with <parameter>username</parameter> and
<parameter>password</parameter>. 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.
</para>
<para>
See also <function>hw_Connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-incollections">
<refnamediv>
<refname>hw_InCollections</refname>
<refpurpose>check if object ids in collections</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_incollections</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>array <parameter>object_id_array</parameter></paramdef>
<paramdef>array <parameter>collection_id_array</parameter></paramdef>
<paramdef>int <parameter>return_collections</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Checks whether a set of objects (documents or collections)
specified by the <parameter>object_id_array</parameter> is part of
the collections listed in <parameter>collection_id_array</parameter>.
When the fourth parameter <parameter>return_collections</parameter> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-info">
<refnamediv>
<refname>hw_Info</refname>
<refpurpose>info about connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_info</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns information about the current connection. The returned string
has the following format: <Serverstring>, <Host>,
<Port>, <Username>, <Port of Client>,
<Byte swapping>
</para>
</refsect1>
</refentry>
<refentry id="function.hw-inscoll">
<refnamediv>
<refname>hw_InsColl</refname>
<refpurpose>insert collection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_inscoll</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
<paramdef>array <parameter>object_array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Inserts a new collection with attributes as in
<parameter>object_array</parameter> into
collection with object ID <parameter>objectID</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-insdoc">
<refnamediv>
<refname>hw_InsDoc</refname>
<refpurpose>insert document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_insdoc</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>parentID</parameter></paramdef>
<paramdef>string <parameter>object_record</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Inserts a new document with attributes as in
<parameter>object_record</parameter> into collection with object ID
<parameter>parentID</parameter>. This function inserts either
an object record only or an object record and a pure ascii text in
<parameter>text</parameter> if <parameter>text</parameter> is given.
If you want to insert a general document of any kind use
<function>hw_insertdocument</function> instead.
</para>
<para>
See also <function>hw_InsertDocument</function>,
and <function>hw_InsColl</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-insertdocument">
<refnamediv>
<refname>hw_InsertDocument</refname>
<refpurpose>upload any document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_insertdocument</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>parent_id</parameter></paramdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Uploads a document into the collection with
<parameter>parent_id</parameter>.
The document has to be created before with
<function>hw_NewDocument</function>. 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.
</para>
<para>
See also <function>hw_PipeDocument</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-insertobject">
<refnamediv>
<refname>hw_InsertObject</refname>
<refpurpose>inserts an object record</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_insertobject</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>string <parameter>object rec</parameter></paramdef>
<paramdef>string <parameter>parameter</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
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 correspondig link in the annotation text.
</para>
<para>
See also <function>hw_PipeDocument</function>,
<function>hw_InsertDocument</function>,
<function>hw_InsDoc</function>,
and <function>hw_InsColl</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-mapid">
<refnamediv>
<refname>hw_mapid</refname>
<refpurpose>Maps global id on virtual local id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_mapid</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>server id</parameter></paramdef>
<paramdef>int <parameter>object id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Maps a global object id on any hyperwave server, even those
you did not connect to with <function>hw_connect</function>,
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 <function>hw_getobject</function>. 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.
</para>
<para>
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
</para>
</refsect1>
</refentry>
<refentry id="function.hw-modifyobject">
<refnamediv>
<refname>hw_Modifyobject</refname>
<refpurpose>modifies object record</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_modifyobject</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>object_to_change</parameter></paramdef>
<paramdef>array <parameter>remove</parameter></paramdef>
<paramdef>array <parameter>add</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This command allows to remove, add, or modify individual attributes
of an object record. The object is specified by the Object ID
<parameter>object_to_change</parameter>. The first array
<parameter>remove</parameter> is a list of attributes to remove.
The second array <parameter>add</parameter> 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. <function>hw_modifyobject</function>
will always remove the attributes before it adds attributes unless
the value of the attribute to remove is not a string or array.
</para>
<para>
The last parameter determines if the modification is performed
recursively. 1 means recurive modification. If some of the objects
cannot be modified they will be skiped without notice.
<function>hw_error</function> may not indicate an error though
some of the objects could not be modified.
</para>
<para>
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 neccessary 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.
</para>
<para>
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 <function>hw_modifyobject</function>.
<example>
<title>modifying an attribute</title>
<programlisting role="php">
// $connect is an existing connection to the Hyperwave server
// $objid is the ID of the object to modify
$remarr = array("Name" => "books");
$addarr = array("Name" => "articles");
$hw_modifyobject($connect, $objid, $remarr, $addarr);
</programlisting>
</example>
In order to delete/add a name=value pair from/to the object record just
pass the remove/add array and set the last/third parameter to an empty
array. If the attribute is the first one with that name to add, set
attribute value in the remove array to an integer.
<example>
<title>adding a completely new attribute</title>
<programlisting role="php">
// $connect is an existing connection to the Hyperwave server
// $objid is the ID of the object to modify
$remarr = array("Name" => 0);
$addarr = array("Name" => "articles");
$hw_modifyobject($connect, $objid, $remarr, $addarr);
</programlisting>
</example>
</para>
<para>
<note>
<simpara>
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:
</simpara>
</note>
<example>
<title>modifying Title attribute</title>
<programlisting role="php">
$remarr = array("Title" => "en:Books");
$addarr = array("Title" => "en:Articles");
$hw_modifyobject($connect, $objid, $remarr, $addarr);
</programlisting>
</example>
or
<example>
<title>modifying Title attribute</title>
<programlisting role="php">
$remarr = array("Title" => array("en" => "Books"));
$addarr = array("Title" => array("en" => "Articles",
"ge"=>"Artikel"));
$hw_modifyobject($connect, $objid, $remarr, $addarr);
</programlisting>
</example>
This removes the english title 'Books' and adds the english title
'Articles' and the german title 'Artikel'.
<example>
<title>removing attribute</title>
<programlisting role="php">
$remarr = array("Title" => "");
$addarr = array("Title" => "en:Articles");
$hw_modifyobject($connect, $objid, $remarr, $addarr);
</programlisting>
</example>
<note>
<simpara>
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.
</simpara>
</note>
<note>
<simpara>
If you need to delete all attributes with a certain name you
will have to pass an empty string as the attribute value.
</simpara>
</note>
<note>
<simpara>
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.
</simpara>
</note>
<note>
<simpara>
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.
</simpara>
</note>
<note>
<simpara>
You may not suround this function by calls to
<function>hw_getandlock</function> and
<function>hw_unlock</function>.
<function>hw_modifyobject</function> does this internally.
</simpara>
</note>
</para>
<para>
Returns TRUE if no error occurs otherwise FALSE.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-new-document">
<refnamediv>
<refname>hw_New_Document</refname>
<refpurpose>create new document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_new_document</function></funcdef>
<paramdef>string <parameter>object_record</parameter></paramdef>
<paramdef>string <parameter>document_data</parameter></paramdef>
<paramdef>int <parameter>document_size</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a new Hyperwave document with document data set to
<parameter>document_data</parameter> and object record set to
<parameter>object_record</parameter>. The length of the
<parameter>document_data</parameter> has to passed in
<parameter>document_size</parameter>This function does not
insert the document into the Hyperwave server.
</para>
<para>
See also <function>hw_FreeDocument</function>,
<function>hw_Document_Size</function>,
<function>hw_Document_BodyTag</function>,
<function>hw_Output_Document</function>,
and <function>hw_InsertDocument</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-objrec2array">
<refnamediv>
<refname>hw_Objrec2Array</refname>
<refpurpose>convert attributes from object record to object array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>hw_objrec2array</function></funcdef>
<paramdef>string <parameter>object_record</parameter></paramdef>
<paramdef>array
<parameter>
<optional>format</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts an <parameter>object_record</parameter> 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
<literal>HW_ATTR_LANG</literal> or <literal>HW_ATTR_NONE</literal>
</para>
<para>
See also <function>hw_array2objrec</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-output-document">
<refnamediv>
<refname>hw_Output_Document</refname>
<refpurpose>prints hw_document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_output_document</function></funcdef>
<paramdef>int <parameter>hw_document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Prints the document without the BODY tag.
</para>
<para>
For backward compatibility, <function>hw_OutputDocument</function> is
also accepted. This is deprecated, however.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-pconnect">
<refnamediv>
<refname>hw_pConnect</refname>
<refpurpose>make a persistent database connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_pconnect</function></funcdef>
<paramdef>string <parameter>host</parameter></paramdef>
<paramdef>int <parameter>port</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 <parameter>username</parameter>
and <parameter>password</parameter> 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.</para>
<para>
See also <function>hw_Connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-pipedocument">
<refnamediv>
<refname>hw_PipeDocument</refname>
<refpurpose>retrieve any document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_pipedocument</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the Hyperwave document with object ID
<parameter>objectID</parameter>. If the document
has anchors which can be inserted, they will have been inserted already.
The document will be transfered via a special data connection which
does not block the control connection.</para>
<para>
See also <function>hw_GetText</function> for more on link insertion,
<function>hw_FreeDocument</function>,
<function>hw_Document_Size</function>,
<function>hw_Document_BodyTag</function>,
and <function>hw_Output_Document</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-root">
<refnamediv>
<refname>hw_Root</refname>
<refpurpose>root object id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_root</function></funcdef>
<paramdef><parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-unlock">
<refnamediv>
<refname>hw_Unlock</refname>
<refpurpose>unlock object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_unlock</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int <parameter>objectID</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Unlocks a document, so other users regain access.
</para>
<para>
See also <function>hw_GetAndLock</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-who">
<refnamediv>
<refname>hw_Who</refname>
<refpurpose>List of currently logged in users</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hw_who</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 initianted the request.
</para>
</refsect1>
</refentry>
<refentry id="function.hw-getusername">
<refnamediv>
<refname>hw_getusername</refname>
<refpurpose>name of currently logged in user</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hw_getusername</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the username of the connection.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/ibase.xml
+++ phpdoc/nl/functions/ibase.xml
<reference id="ref.ibase">
<title>InterBase functions</title>
<titleabbrev>InterBase</titleabbrev>
<partintro>
<para>
InterBase is a popular database put out by Borland/Inprise. More
information about InterBase is available at <ulink
url="&url.ibase;">&url.ibase;</ulink>. Oh, by the way, InterBase
just joined the open source movement!
</para>
<note>
<para>
Full support for InterBase 6 was added in PHP 4.0.
</para>
<para>
This database uses a single quote (') character for escaping, a
behavior similar to the Sybase database, add to your
<filename>php.ini</filename> the following directive:
<informalexample>
<programlisting>
magic_quotes_sybase = On
</programlisting>
</informalexample>
</para>
</note>
</partintro>
<refentry id="function.ibase-connect">
<refnamediv>
<refname>ibase_connect</refname>
<refpurpose>
Open a connection to an InterBase database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_connect</function></funcdef>
<paramdef>string <parameter>database</parameter></paramdef>
<paramdef>string
<parameter><optional>username</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>password</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>charset</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>buffers</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>dialect</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>role</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Establishes a connection to an InterBase server.
The <parameter>database</parameter> 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. <parameter>username</parameter>
and <parameter>password</parameter> can also
be specified with PHP configuration directives ibase.default_user and
ibase.default_password. <parameter>charset</parameter> is the default
character set for a database. <parameter>buffers</parameter> is the number
of database buffers to allocate for the server-side cache. If 0 or omitted,
server chooses its own default. <parameter>dialect</parameter> selects
the default SQL dialect for any statement executed within a connection,
and it defaults to the highest one supported by client libraries.
</para>
<para>
In case a second call is made to
<function>ibase_connect</function> 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
<function>ibase_close</function>.
<example>
<title><function>Ibase_connect</function> example</title>
<programlisting role="php">
<?php
$dbh = ibase_connect ($host, $username, $password);
$stmt = 'SELECT * FROM tblname';
$sth = ibase_query ($dbh, $stmt);
while ($row = ibase_fetch_object ($sth)) {
print $row->email . "\n";
}
ibase_close ($dbh);
?>
</programlisting>
</example>
</para>
<note>
<para>
<parameter>buffers</parameter> was added in PHP4-RC2.
</para>
</note>
<note>
<para>
<parameter>dialect</parameter> was added in PHP4-RC2. It is functional
only with InterBase 6 and versions higher than that.
</para>
</note>
<note>
<para>
<parameter>role</parameter> was added in PHP4-RC2. It is functional
only with InterBase 5 and versions higher than that.
</para>
</note>
<para>
See also: <function>ibase_pconnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ibase-pconnect">
<refnamediv>
<refname>ibase_pconnect</refname>
<refpurpose>
Creates an persistent connection to an InterBase database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_connect</function></funcdef>
<paramdef>string <parameter>database</parameter></paramdef>
<paramdef>string
<parameter><optional>username</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>password</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>charset</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>role</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ibase_pconnect</function> acts very much like
<function>ibase_connect</function> 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
(<function>ibase_close</function> will not close links established
by <function>ibase_pconnect</function>). This type of link is
therefore called 'persistent'.
</para>
<para>
See also <function>ibase_connect</function> for the meaning of
parameters passed to this function. They are exactly the same.
</para>
</refsect1>
</refentry>
<refentry id="function.ibase-close">
<refnamediv>
<refname>ibase_close</refname>
<refpurpose>
Close a connection to an InterBase database
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_close</function></funcdef>
<paramdef>int
<parameter><optional>connection_id</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Closes the link to an InterBase database that's associated with
a connection id returned from <function>ibase_connect</function>.
If the connection id is omitted, the last opened link is assumed.
Default transaction on link is committed, other transactions are
rolled back.
</para>
</refsect1>
</refentry>
<refentry id="function.ibase-query">
<refnamediv>
<refname>ibase_query</refname>
<refpurpose>Execute a query on an InterBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_query</function></funcdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
<paramdef>string
<parameter>query</parameter>
</paramdef>
<paramdef>int
<parameter><optional>bind_args</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Performs a query on an InterBase database, returning a result
identifier for use with <function>ibase_fetch_row</function>,
<function>ibase_fetch_object</function>,
<function>ibase_free_result</function> and
<function>ibase_free_query</function>.
</simpara>
<note>
<para>
Although this function supports variable binding to parameter
placeholders, there is not very much meaning using this capability
with it. For real life use and an example, see
<function>ibase_prepare</function> and
<function>ibase_execute</function>.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.ibase-fetch-row">
<refnamediv>
<refname>ibase_fetch_row</refname>
<refpurpose>Fetch a row from an InterBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ibase_fetch_row</function></funcdef>
<paramdef>int
<parameter>result_identifier</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the next row specified by the result identifier obtained
using the <function>ibase_query</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ibase-fetch-object">
<refnamediv>
<refname>ibase_fetch_object</refname>
<refpurpose>Get an object from a InterBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>ibase_fetch_object</function></funcdef>
<paramdef>int
<parameter>result_id</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Fetches a row as a pseudo-object from a
<parameter>result_id</parameter> obtained either by
<function>ibase_query</function> or
<function>ibase_execute</function>.
<informalexample>
<programlisting role="php">
<php
$dbh = ibase_connect ($host, $username, $password);
$stmt = 'SELECT * FROM tblname';
$sth = ibase_query ($dbh, $stmt);
while ($row = ibase_fetch_object ($sth)) {
print $row->email . "\n";
}
ibase_close ($dbh);
?>
</programlisting>
</informalexample>
</para>
<para>
See also <function>ibase_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ibase-free-result">
<refnamediv>
<refname>ibase_free_result</refname>
<refpurpose>Free a result set</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_free_result</function></funcdef>
<paramdef>int
<parameter>result_identifier</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Free's a result set the has been created by
<function>ibase_query</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ibase-prepare">
<refnamediv>
<refname>ibase_prepare</refname>
<refpurpose>
Prepare a query for later binding of parameter placeholders and
execution
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_prepare</function></funcdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Prepare a query for later binding of parameter placeholders and
execution (via <function>ibase_execute</function>).
</simpara>
</refsect1>
</refentry>
<refentry id="function.ibase-execute">
<refnamediv>
<refname>ibase_execute</refname>
<refpurpose>Execute a previously prepared query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_execute</function></funcdef>
<paramdef>int
<parameter>query</parameter>
</paramdef>
<paramdef>int
<parameter><optional>bind_args</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Execute a query prepared by <function>ibase_prepare</function>.
This is a lot more effective than using <function>ibase_query</function>
if you are repeating a same kind of query several times with only
some parameters changing.
<informalexample>
<programlisting role="php">
<?php
$updates = array(
1 => 'Eric',
5 => 'Filip',
7 => 'Larry'
);
$query = ibase_prepare("UPDATE FOO SET BAR = ? WHERE BAZ = ?");
while (list($baz, $bar) = each($updates)) {
ibase_execute($query, $bar, $baz);
}
?>
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.ibase-free-query">
<refnamediv>
<refname>ibase_free_query</refname>
<refpurpose>
Free memory allocated by a prepared query
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_free_query</function></funcdef>
<paramdef>int
<parameter>query</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Free a query prepared by <function>ibase_prepare</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ibase-timefmt">
<refnamediv>
<refname>ibase_timefmt</refname>
<refpurpose>
Sets the format of timestamp, date and time type columns returned from queries
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_timefmt</function></funcdef>
<paramdef>string
<parameter>format</parameter>
</paramdef>
<paramdef>int
<parameter><optional>columntype</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the format of timestamp, date or time type columns returned
from queries. Internally, the columns are formatted by c-function
strftime(), so refer to it's documentation regarding to the format
of the string. <parameter>columntype</parameter> is one of the
constants IBASE_TIMESTAMP, IBASE_DATE and IBASE_TIME. If omitted,
defaults to IBASE_TIMESTAMP for backwards compatibility.
<informalexample>
<programlisting role="php">
<?php
// InterBase 6 TIME-type columns will be returned in
// the form '05 hours 37 minutes'.
ibase_timefmt("%H hours %M minutes", IBASE_TIME);
?>
</programlisting>
</informalexample>
</para>
<para>
You can also set defaults for these formats with PHP configuration
directives ibase.timestampformat, ibase.dateformat and ibase.timeformat.
</para>
<note>
<para>
<parameter>columntype</parameter> was added in PHP 4.0. It has any
meaning only with InterBase version 6 and higher.
</para>
</note>
<note>
<para>
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.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.ibase-num-fields">
<refnamediv>
<refname>ibase_num_fields</refname>
<refpurpose>
Get the number of fields in a result set
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ibase_num_fields</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an integer containing the number of fields in a result
set.
<informalexample>
<programlisting role="php">
<?php
$dbh = ibase_connect ($host, $username, $password);
$stmt = 'SELECT * FROM tblname';
$sth = ibase_query ($dbh, $stmt);
if (ibase_num_fields($sth) > 0) {
while ($row = ibase_fetch_object ($sth)) {
print $row->email . "\n";
}
} else {
die ("No Results were found for your query");
}
ibase_close ($dbh);
?>
</programlisting>
</informalexample>
</para>
<para>
See also: <function>ibase_field_info</function>.
</para>
<note>
<para>
<function>Ibase_num_fields</function> is currently not functional
in PHP 4.
</para>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/icap.xml
+++ phpdoc/nl/functions/icap.xml
<reference id="ref.icap">
<title>ICAP Functions</title>
<titleabbrev>ICAP</titleabbrev>
<partintro>
<simpara>
To get these functions to work, you have to compile PHP with
<option role="configure">--with-icap</option>. That requires the
icap library to be installed. Grab the latest version from <ulink
url="&url.icap;">&url.icap;</ulink> and compile and install it.
</simpara>
</partintro>
<refentry id="function.icap-open">
<refnamediv>
<refname>icap_open</refname>
<refpurpose>Opens up an ICAP connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>stream <function>icap_open</function></funcdef>
<paramdef>string <parameter>calendar</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an ICAP stream on success, false on error.</para>
<para>
<function>icap_open</function> opens up an ICAP connection to the
specified <parameter>calendar</parameter> store. If the optional
<parameter>options</parameter> is specified, passes the
<parameter>options</parameter> to that mailbox also.
</para>
</refsect1>
</refentry>
<refentry id="function.icap-close">
<refnamediv>
<refname>icap_close</refname>
<refpurpose>Close an ICAP stream</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>icap_close</function></funcdef>
<paramdef>int <parameter>icap_stream</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Closes the given icap stream.
</para>
</refsect1>
</refentry>
<refentry id="function.icap-fetch-event">
<refnamediv>
<refname>icap_fetch_event</refname>
<refpurpose>Fetches an event from the calendar stream/</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>icap_fetch_event</function></funcdef>
<paramdef>int <parameter>stream_id</parameter></paramdef>
<paramdef>int <parameter>event_id</parameter></paramdef>
<paramdef>int
<parameter><optional>options</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Icap_fetch_event</function> fetches an event from the
calendar stream specified by <parameter>event_id</parameter>.
</para>
<para>
Returns an event object consisting of:
<itemizedlist>
<listitem>
<simpara>
int id - ID of that event.
</simpara>
</listitem>
<listitem>
<simpara>
int public - TRUE if the event if public, FALSE if it is private.
</simpara>
</listitem>
<listitem>
<simpara>
string category - Category string of the event.
</simpara>
</listitem>
<listitem>
<simpara>
string title - Title string of the event.
</simpara>
</listitem>
<listitem>
<simpara>
string description - Description string of the event.
</simpara>
</listitem>
<listitem>
<simpara>
int alarm - number of minutes before the event to send an
alarm/reminder.
</simpara>
</listitem>
<listitem>
<simpara>
object start - Object containing a datetime entry.
</simpara>
</listitem>
<listitem>
<simpara>
object end - Object containing a datetime entry.
</simpara>
</listitem>
</itemizedlist>
All datetime entries consist of an object that contains:
<itemizedlist>
<listitem>
<simpara>
int year - year
</simpara>
</listitem>
<listitem>
<simpara>
int month - month
</simpara>
</listitem>
<listitem>
<simpara>
int mday - day of month
</simpara>
</listitem>
<listitem>
<simpara>
int hour - hour
</simpara>
</listitem>
<listitem>
<simpara>
int min - minutes
</simpara>
</listitem>
<listitem>
<simpara>
int sec - seconds
</simpara></listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.icap-list-events">
<refnamediv>
<refname>icap_list_events</refname>
<refpurpose>
Return a list of events between two given datetimes
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>icap_list_events</function></funcdef>
<paramdef>int <parameter>stream_id</parameter></paramdef>
<paramdef>int <parameter>begin_date</parameter></paramdef>
<paramdef>int
<parameter><optional>end_date</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of event ID's that are between the two given
datetimes.
</para>
<para>
<function>Icap_list_events</function> function takes in a
beginning datetime and an end datetime for a calendar stream. An
array of event id's that are between the given datetimes are
returned.
</para>
<para>
All datetime entries consist of an object that contains:
<itemizedlist>
<listitem>
<simpara>
int year - year
</simpara>
</listitem>
<listitem>
<simpara>
int month - month
</simpara>
</listitem>
<listitem>
<simpara>
int mday - day of month
</simpara>
</listitem>
<listitem>
<simpara>
int hour - hour
</simpara>
</listitem>
<listitem>
<simpara>
int min - minutes
</simpara>
</listitem>
<listitem>
<simpara>
int sec - seconds
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.icap-store-event">
<refnamediv>
<refname>icap_store_event</refname>
<refpurpose>Store an event into an ICAP calendar</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>icap_store_event</function></funcdef>
<paramdef>int <parameter>stream_id</parameter></paramdef>
<paramdef>object <parameter>event</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Icap_store_event</function> Stores an event into
an ICAP calendar. An event object consists of:
<itemizedlist>
<listitem>
<simpara>
int public - 1 if public, 0 if private;
</simpara>
</listitem>
<listitem>
<simpara>
string caegory - Category string of the event.
</simpara>
</listitem>
<listitem>
<simpara>
string title - Title string of the event.
</simpara>
</listitem>
<listitem>
<simpara>
string description - Description string of the event.
</simpara>
</listitem>
<listitem>
<simpara>
int alarm - Number of minutes before the event to sned out an alarm.
</simpara>
</listitem>
<listitem>
<simpara>
datetime start - datetime object of the start of the event.
</simpara>
</listitem>
<listitem>
<simpara>
datetime end - datetime object of the end of the event.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
All datetime entries consist of an object that contains:
<itemizedlist>
<listitem>
<simpara>
int year - year
</simpara>
</listitem>
<listitem>
<simpara>
int month - month
</simpara>
</listitem>
<listitem>
<simpara>
int mday - day of month
</simpara>
</listitem>
<listitem>
<simpara>
int hour - hour
</simpara>
</listitem>
<listitem>
<simpara>
int min - minutes
</simpara>
</listitem>
<listitem>
<simpara>
int sec - seconds
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
Returns true on success and false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.icap-delete-event">
<refnamediv>
<refname>icap_delete_event</refname>
<refpurpose>Delete an event from an ICAP calendar</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>icap_delete_event</function></funcdef>
<paramdef>int <parameter>sream_id</parameter></paramdef>
<paramdef>int <parameter>uid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Icap_delete_event</function> deletes the calendar event
specified by the <parameter>uid</parameter>.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.icap-snooze">
<refnamediv>
<refname>icap_snooze</refname>
<refpurpose>Snooze an alarm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>icap_snooze</function></funcdef>
<paramdef>int <parameter>stream_id</parameter></paramdef>
<paramdef>int <parameter>uid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Icap_snooze</function> turns on an alarm for a
calendar event specified by the <parameter>uid</parameter>.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.icap-list-alarms">
<refnamediv>
<refname>icap_list_alarms</refname>
<refpurpose>
Return a list of events that has an alarm triggered at the given
datetime
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>icap_list_alarms</function></funcdef>
<paramdef>int <parameter>stream_id</parameter></paramdef>
<paramdef>array <parameter>date</parameter></paramdef>
<paramdef>array <parameter>time</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of event ID's that has an alarm going off at the
given datetime.
</para>
<para>
<function>Icap_list_alarms</function> function takes in a
datetime for a calendar stream. An array of event id's that has
an alarm should be going off at the datetime are returned.
</para>
<para>
All datetime entries consist of an object that contains:
<itemizedlist>
<listitem>
<simpara>
int year - year
</simpara>
</listitem>
<listitem>
<simpara>
int month - month
</simpara>
</listitem>
<listitem>
<simpara>
int mday - day of month
</simpara>
</listitem>
<listitem>
<simpara>
int hour - hour
</simpara>
</listitem>
<listitem>
<simpara>
int min - minutes
</simpara>
</listitem>
<listitem>
<simpara>
int sec - seconds
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/ifx.xml
+++ phpdoc/nl/functions/ifx.xml
<reference id="ref.ifx">
<title>Informix functions</title>
<titleabbrev>Informix</titleabbrev>
<partintro>
<para>
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.
</para>
<note>
<title>Configuration notes</title>
<para>
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.
</para>
<para>
Make sure that the "INFORMIXDIR" variable has been set, and that
$INFORMIXDIR/bin is in your PATH before you run the "configure"
script.
</para>
<para>
The configure script will autodetect the libraries and include
directories, if you run "configure --with_informix=yes". You can
overide this detection by specifying "IFX_LIBDIR", "IFX_LIBS" and
"IFX_INCDIR" in the environment. The configure script will also
try to detect your Informix server version. It will set the
"HAVE_IFX_IUS" conditional compilation variable if your Informix
version >= 9.00.
</para>
</note>
<note>
<title>Runtime considerations</title>
<para>
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 <function>phpinfo()</function>
before you start testing. The <function>phpinfo()</function>
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.
</para>
<para>
The Informix shared libraries should also be available to the
loader (check LD_LINBRARY_PATH or ld.so.conf/ldconfig).
</para>
</note>
<note>
<title>
Some notes on the use of BLOBs (TEXT and BYTE columns)
</title>
<para>
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.
</para>
<para>
For insert/update queries you must create these "blob id's"
yourself with "<function>ifx_create_blob</function>;". 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 <function>ifx_update_blob</function>.
</para>
<para>
The behaviour of BLOB columns can be altered by configuration
variables that also can be set at runtime :
</para>
<para>
configuration variable : ifx.textasvarchar
</para>
<para>
configuration variable : ifx.byteasvarchar
</para>
<para>
runtime functions :
</para>
<para>
ifx_textasvarchar(0) : use blob id's for select queries with TEXT
columns
</para>
<para>
ifx_byteasvarchar(0) : use blob id's for select queries with BYTE
columns
</para>
<para>
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.
</para>
<para>
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.
</para>
<para>
configuration variable : ifx.blobinfile
</para>
<para>
runtime function :
</para>
<para>
ifx_blobinfile_mode(0) : return BYTE columns in memory, the blob
id lets you get at the contents.
</para>
<para>
ifx_blobinfile_mode(1) : return BYTE columns in a file, the blob
id lets you get at the file name.
</para>
<para>
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.
</para>
<para>
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.
</para>
<para>
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").
</para>
</note>
<note>
<title>Automatically trimming "char" (SQLCHAR and SQLNCHAR) data</title>
<para>
This can be set with the configuration variable
</para>
<para>
ifx.charasvarchar : if set to 1 trailing spaces will be
automatically trimmed, to save you some "chopping".
</para>
</note>
<note>
<title>NULL values</title>
<para>
The configuration variable ifx.nullformat (and the runtime
function <function>ifx_nullformat</function>) 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.
</para>
</note>
</partintro>
<refentry id="function.ifx-connect">
<refnamediv>
<refname>ifx_connect</refname>
<refpurpose>Open Informix server connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_connect</function></funcdef>
<paramdef>string <parameter><optional>database</optional>
</parameter></paramdef>
<paramdef>string <parameter><optional>userid</optional>
</parameter></paramdef>
<paramdef>string <parameter><optional>password</optional>
</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a connection identifier on success, or FALSE on
error.
</para>
<para>
<function>ifx_connect</function> 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 <link
linkend="configuration.file">configuration file</link>
(ifx.default_host for the host (Informix libraries will use
<envar>INFORMIXSERVER</envar> environment value if not defined),
ifx.default_user for user, ifx.default_password for the password
(none if not defined).
</para>
<para>
In case a second call is made to
<function>ifx_connect</function> with the same arguments, no
new link will be established, but instead, the link identifier of
the already opened link will be returned.
</para>
<para>
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
<function>ifx_close</function>.
</para>
<para>
See also <function>ifx_pconnect</function>, and
<function>ifx_close</function>.
<example>
<title>Connect to a Informix database</title>
<programlisting role="php3">
$conn_id = ifx_connect ("mydb@ol_srv1", "imyself", "mypassword");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-pconnect">
<refnamediv>
<refname>ifx_pconnect</refname>
<refpurpose>Open persistent Informix connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_pconnect</function></funcdef>
<paramdef>string
<parameter><optional>database</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>userid</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>password</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive Informix persistent link identifier on success,
or false on error
</para>
<para>
<function>ifx_pconnect</function> acts very much like
<function>ifx_connect</function> with two major differences.
</para>
<para>
This function behaves exactly like <function>ifx_connect</function>
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.
</para>
<para>
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 (<function>ifx_close</function> will not
close links established by <function>ifx_pconnect</function>).
</para>
<para>
This type of links is therefore called 'persistent'.
</para>
<para>
See also: <function>ifx_connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-close">
<refnamediv>
<refname>ifx_close</refname>
<refpurpose>Close Informix connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_close</function></funcdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: always true.
</para>
<para>
<function>ifx_close</function> 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.
</para>
<para>
Note that this isn't usually necessary, as non-persistent open
links are automatically closed at the end of the script's
execution.
</para>
<para>
<function>ifx_close</function> will not close persistent links
generated by <function>ifx_pconnect</function>.
</para>
<para>
See also: <function>ifx_connect</function>, and
<function>ifx_pconnect</function>.
<example>
<title>Closing a Informix connection</title>
<programlisting role="php3">
$conn_id = ifx_connect ("mydb@ol_srv", "itsme", "mypassword");
.. some queries and stuff ...
ifx_close($conn_id);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-query">
<refnamediv>
<refname>ifx_query</refname>
<refpurpose>Send Informix query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_query</function></funcdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>cursor_type</optional></parameter>
</paramdef>
<paramdef>mixed
<parameter>
<optional>blobidarray</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive Informix result identifier on success, or
false on error.
</para>
<para>
A "result_id" resource used by other functions to retrieve the
query results. Sets "affected_rows" for retrieval by the
<function>ifx_affected_rows</function> function.
</para>
<para>
<function>ifx_query</function> 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
<function>ifx_connect</function> was called, and use it.
</para>
<para>
Executes <parameter>query</parameter> on connection
<parameter>conn_id</parameter>. For "select-type" queries a
cursor is declared and opened. The optional
<parameter>cursor_type</parameter> 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.
</para>
<para>
For either query type the number of (estimated or real) affected
rows is saved for retrieval by
<function>ifx_affected_rows</function>.
</para>
<para>
If you have BLOB (BYTE or TEXT) columns in an update query, you
can add a <parameter>blobidarray</parameter> parameter containing
the corresponding "blob ids", and you should replace those
columns with a "?" in the query text.
</para>
<para>
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.
</para><para>
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).
</para>
<para>
See also: <function>ifx_connect</function>.
<example>
<title>
Show all rows of the "orders" table as a html table
</title>
<programlisting role="php3">
ifx_textasvarchar(1); // use "text mode" for blobs
$res_id = ifx_query("select * from orders", $conn_id);
if (! $res_id) {
printf("Can't select orders : %s\n<br>%s<br>\n",
ifx_error());
ifx_errormsg();
die;
}
ifx_htmltbl_result($res_id, "border=\"1\"");
ifx_free_result($res_id);
</programlisting>
</example>
<example>
<title>Insert some values into the "catalog" table</title>
<programlisting role="php3">
// create blob id's for a byte and text column
$textid = ifx_create_blob(0, 0, "Text column in memory");
$byteid = ifx_create_blob(1, 0, "Byte column in memory");
// store blob id's in a blobid array
$blobidarray[] = $textid;
$blobidarray[] = $byteid;
// launch query
$query = "insert into catalog (stock_num, manu_code, " .
"cat_descr,cat_picture) values(1,'HRO',?,?)";
$res_id = ifx_query($query, $conn_id, $blobidarray);
if (! $res_id) {
... error ...
}
// free result id
ifx_free_result($res_id);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-prepare">
<refnamediv>
<refname>ifx_prepare</refname>
<refpurpose>Prepare an SQL-statement for execution</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_prepare</function></funcdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>conn_id</parameter></paramdef>
<paramdef>int
<parameter><optional>cursor_def</optional></parameter>
</paramdef>
<paramdef>mixed <parameter>blobidarray</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a integer <parameter>result_id</parameter> for use by
<function>ifx_do</function>. Sets
<parameter>affected_rows</parameter> for retrieval by the
<function>ifx_affected_rows</function> function.
</para>
<para>
Prepares <parameter>query</parameter> on connection
<parameter>conn_id</parameter>. For "select-type" queries a
cursor is declared and opened. The optional
<parameter>cursor_type</parameter> 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.
</para>
<para>
For either query type the estimated number of affected rows is
saved for retrieval by <function>ifx_affected_rows</function>.
</para>
<para>
If you have BLOB (BYTE or TEXT) columns in the query, you can add
a <parameter>blobidarray</parameter> parameter containing the
corresponding "blob ids", and you should replace those columns
with a "?" in the query text.
</para>
<para>
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.
</para>
<para>
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).
</para>
<para>
See also: <function>ifx_do</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-do">
<refnamediv>
<refname>ifx_do</refname>
<refpurpose>
Execute a previously prepared SQL-statement
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_do</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns TRUE on success, FALSE on error.
</para>
<para>
Executes a previously prepared query or opens a cursor for it.
</para>
<para>
Does NOT free <parameter>result_id</parameter> on error.
</para>
<para>
Also sets the real number of
<function>ifx_affected_rows</function> for non-select statements
for retrieval by <function>ifx_affected_rows</function>
</para>
<para>
See also: <function>ifx_prepare</function>. There is a example.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-error">
<refnamediv>
<refname>ifx_error</refname>
<refpurpose>Returns error code of last Informix call</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ifx_error</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The Informix error codes (SQLSTATE & SQLCODE) formatted as
follows :
</para>
<para>
x [SQLSTATE = aa bbb SQLCODE=cccc]
</para>
<para>
where x = space : no error
</para>
<para>
E : error
</para>
<para>
N : no more data
</para>
<para>
W : warning
</para>
<para>
? : undefined
</para>
<para>
If the "x" character is anything other than space, SQLSTATE and
SQLCODE describe the error in more detail.
</para>
<para>
See the Informix manual for the description of SQLSTATE and
SQLCODE
</para>
<para>
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 '<literal> </literal>'
(space) (success), '<literal>W</literal>' (the statement caused
some warning), '<literal>E</literal>' (an error happened when
executing the statement) or '<literal>N</literal>' (the statement
didn't return any data).
</para>
<para>
See also: <function>ifx_errormsg</function>
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-errormsg">
<refnamediv>
<refname>ifx_errormsg</refname>
<refpurpose>Returns error message of last Informix call</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ifx_errormsg</function></funcdef>
<paramdef>int
<parameter><optional>errorcode</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the Informix error message associated with the most
recent Informix error, or, when the optional
"<parameter>errorcode</parameter>" param is present, the error
message corresponding to "<parameter>errorcode</parameter>".
</para>
<para>
See also: <function>ifx_error</function>
</para>
<informalexample>
<programlisting role="php3">
printf("%s\n<br>", ifx_errormsg(-201));
</programlisting>
</informalexample>
</refsect1>
</refentry>
<refentry id="function.ifx-affected-rows">
<refnamediv>
<refname>ifx_affected_rows</refname>
<refpurpose>Get number of rows affected by a query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_affected_rows</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<parameter>result_id</parameter> is a valid result id returned by
<function>ifx_query</function> or
<function>ifx_prepare</function>.
</para>
<para>
Returns the number of rows affected by a query associated with
<parameter>result_id</parameter>.
</para>
<para>
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).
</para>
<para>
Useful after <function>ifx_prepare</function> to limit queries to
reasonable result sets.
</para>
<para>
See also: <function>ifx_num_rows</function>
</para>
<example>
<title>Informix affected rows</title>
<programlisting role="php3">
$rid = ifx_prepare ("select * from emp
where name like " . $name, $connid);
if (! $rid) {
... error ...
}
$rowcount = ifx_affected_rows ($rid);
if ($rowcount > 1000) {
printf ("Too many rows in result set (%d)\n<br>", $rowcount);
die ("Please restrict your query<br>\n");
}
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ifx-getsqlca">
<refnamediv>
<refname>ifx_getsqlca</refname>
<refpurpose>
Get the contents of sqlca.sqlerrd[0..5] after a query
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ifx_getsqlca</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<parameter>result_id</parameter> is a valid result id returned by
<function>ifx_query</function> or
<function>ifx_prepare</function>.
</para>
<para>
Returns a pseudo-row (assiociative array) with sqlca.sqlerrd[0]
... sqlca.sqlerrd[5] after the query associated with
<parameter>result_id</parameter>.
</para>
<para>
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.
</para>
<example>
<title>Retrieve Informix sqlca.sqlerrd[x] values</title>
<programlisting role="php3">
/* assume the first column of 'sometable' is a serial */
$qid = ifx_query("insert into sometable
values (0, '2nd column', 'another column') ", $connid);
if (! $qid) {
... error ...
}
$sqlca = ifx_getsqlca ($qid);
$serial_value = $sqlca["sqlerrd1"];
echo "The serial value of the inserted row is : " . $serial_value<br>\n";
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ifx-fetch-row">
<refnamediv>
<refname>ifx_fetch_row</refname>
<refpurpose>Get row as enumerated array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ifx_fetch_row</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>mixed
<parameter><optional>position</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array that corresponds to the fetched row,
or false if there are no more rows.
</para>
<para>
Blob columns are returned as integer blob id values for use in
<function>ifx_get_blob</function> unless you have used
ifx_textasvarchar(1) or ifx_byteasvarchar(1), in which case blobs
are returned as string values. Returns FALSE on error
</para>
<para>
<parameter>result_id</parameter> is a valid resultid returned by
<function>ifx_query</function> or
<function>ifx_prepare</function> (select type queries only!).
</para>
<para>
<parameter><optional>position</optional></parameter> 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.
</para>
<para>
<function>ifx_fetch_row</function> 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.
</para>
<para>
Subsequent calls to <function>ifx_fetch_row</function> would
return the next row in the result set, or false if there are no
more rows.
</para>
<example>
<title>Informix fetch rows</title>
<programlisting role="php3">
$rid = ifx_prepare ("select * from emp where name like " . $name,
$connid, IFX_SCROLL);
if (! $rid) {
... error ...
}
$rowcount = ifx_affected_rows($rid);
if ($rowcount > 1000) {
printf ("Too many rows in result set (%d)\n<br>", $rowcount);
die ("Please restrict your query<br>\n");
}
if (! ifx_do ($rid)) {
... error ...
}
$row = ifx_fetch_row ($rid, "NEXT");
while (is_array($row)) {
for(reset($row); $fieldname=key($row); next($row)) {
$fieldvalue = $row[$fieldname];
printf ("%s = %s,", $fieldname, $fieldvalue);
}
printf("\n<br>");
$row = ifx_fetch_row ($rid, "NEXT");
}
ifx_free_result ($rid);
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ifx-htmltbl-result">
<refnamediv>
<refname>ifx_htmltbl_result</refname>
<refpurpose>
Formats all rows of a query into a HTML table
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_htmltbl_result</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>string
<parameter><optional>html_table_options</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of rows fetched or FALSE on error.
</para>
<para>
Formats all rows of the <parameter>result_id</parameter> query
into a html table. The optional second argument is a string of
<table> tag options
</para>
<example>
<title>Informix results as HTML table</title>
<programlisting role="php3">
$rid = ifx_prepare ("select * from emp where name like " . $name,
$connid, IFX_SCROLL);
if (! $rid) {
... error ...
}
$rowcount = ifx_affected_rows ($rid);
if ($rowcount > 1000) {
printf ("Too many rows in result set (%d)\n<br>", $rowcount);
die ("Please restrict your query<br>\n");
}
if (! ifx_do($rid) {
... error ...
}
ifx_htmltbl_result ($rid, "border=\"2\"");
ifx_free_result($rid);
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ifx-fieldtypes">
<refnamediv>
<refname>ifx_fieldtypes</refname>
<refpurpose>List of Informix SQL fields</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ifx_fieldtypes</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array with fieldnames as key and the SQL
fieldtypes as data for query with
<parameter>result_id</parameter>. Returns FALSE on error.
</para>
<example>
<title>Fielnames and SQL fieldtypes</title>
<programlisting role="php3">
$types = ifx_fieldtypes ($resultid);
if (! isset ($types)) {
... error ...
}
for ($i = 0; $i < count($types); $i++) {
$fname = key($types);
printf("%s :\t type = %s\n", $fname, $types[$fname]);
next($types);
}
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ifx-fieldproperties">
<refnamediv>
<refname>ifx_fieldproperties</refname>
<refpurpose>List of SQL fieldproperties</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ifx_fieldproperties</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array with fieldnames as key and the SQL
fieldproperties as data for a query with
<parameter>result_id</parameter>. Returns FALSE on error.
</para>
<para>
Returns the Informix SQL fieldproperies 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".
</para>
<example>
<title>Informix SQL fieldproperties</title>
<programlisting role="php3">
$properties = ifx_fieldproperties ($resultid);
if (! isset($properties)) {
... error ...
}
for ($i = 0; $i < count($properties); $i++) {
$fname = key ($properties);
printf ("%s:\t type = %s\n", $fname, $properties[$fname]);
next ($properties);
}
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ifx-num-fields">
<refnamediv>
<refname>ifx_num_fields</refname>
<refpurpose>Returns the number of columns in the query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_num_fields</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of columns in query for
<parameter>result_id</parameter> or FALSE on error
</para>
<para>
After preparing or executing a query, this call gives you the
number of columns in the query.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-num-rows">
<refnamediv>
<refname>ifx_num_rows</refname>
<refpurpose>Count the rows already fetched a query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_num_rows</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Gives the number of rows fetched so far for a query with
<parameter>result_id</parameter> after a
<function>ifx_query</function> or <function>ifx_do</function>
query.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-free-result">
<refnamediv>
<refname>ifx_free_result</refname>
<refpurpose>Releases resources for the query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_free_result</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Releases resources for the query associated with
<parameter>result_id</parameter>. Returns FALSE on error.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-create-char">
<refnamediv>
<refname>ifx_create_char</refname>
<refpurpose>Creates an char object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_create_char</function></funcdef>
<paramdef>string <parameter>param</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Creates an char object. <parameter>param</parameter> should
be the char content.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-free-char">
<refnamediv>
<refname>ifx_free_char</refname>
<refpurpose>Deletes the char object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_free_char</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes the charobject for the given char object-id
<parameter>bid</parameter>. Returns FALSE on error otherwise
TRUE.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-update-char">
<refnamediv>
<refname>ifx_update_char</refname>
<refpurpose>Updates the content of the char object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_update_char</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
<paramdef>string <parameter>content</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Updates the content of the char object for the given char object
<parameter>bid</parameter>. <parameter>content</parameter> is a
string with new data. Returns FALSE on error otherwise TRUE.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-get-char">
<refnamediv>
<refname>ifx_get_char</refname>
<refpurpose>Return the content of the char object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_get_char</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the content of the char object for the given char
object-id <parameter>bid</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-create-blob">
<refnamediv>
<refname>ifx_create_blob</refname>
<refpurpose>Creates an blob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_create_blob</function></funcdef>
<paramdef>int <parameter>type</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string <parameter>param</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Creates an blob object.
</para>
<para>
type: 1 = TEXT, 0 = BYTE
</para>
<para>
mode: 0 = blob-object holds the content in memory,
1 = blob-object holds the content in file.
</para>
<para>
param: if mode = 0: pointer to the content,
if mode = 1: pointer to the filestring.
</para>
<para>
Return FALSE on error, otherwise the new blob object-id.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-copy-blob">
<refnamediv>
<refname>ifx_copy_blob</refname>
<refpurpose>Duplicates the given blob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_copy_blob</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Duplicates the given blob object. <parameter>bid</parameter> is
the ID of the blob object.
</para>
<para>
Returns FALSE on error otherwise the new blob object-id.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-free-blob">
<refnamediv>
<refname>ifx_free_blob</refname>
<refpurpose>Deletes the blob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_free_blob</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes the blobobject for the given blob object-id
<parameter>bid</parameter>. Returns FALSE on error otherwise
TRUE.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-get-blob">
<refnamediv>
<refname>ifx_get_blob</refname>
<refpurpose>Return the content of a blob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifx_get_blob</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the content of the blob object for the given blob
object-id <parameter>bid</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-update-blob">
<refnamediv>
<refname>ifx_update_blob</refname>
<refpurpose>Updates the content of the blob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef><function>ifx_update_blob</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
<paramdef>string <parameter>content</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Updates the content of the blob object for the given blob object
<parameter>bid</parameter>. <parameter>content</parameter> is a
string with new data. Returns FALSE on error otherwise TRUE.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-blobinfile-mode">
<refnamediv>
<refname>ifx_blobinfile_mode</refname>
<refpurpose>Set the default blob mode for all select queries</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ifx_blobinfile_mode</function></funcdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Set 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.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-textasvarchar">
<refnamediv>
<refname>ifx_textasvarchar</refname>
<refpurpose>Set the default text mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ifx_textasvarchar</function></funcdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-byteasvarchar">
<refnamediv>
<refname>ifx_byteasvarchar</refname>
<refpurpose>Set the default byte mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ifx_byteasvarchar</function></funcdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.ifx-nullformat">
<refnamediv>
<refname>ifx_nullformat</refname>
<refpurpose>
Sets the default return value on a fetch row
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ifx_nullformat</function></funcdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the default return value of a NULL-value on a fetch row.
Mode "0" returns "", and mode "1" returns "NULL".
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-create-slob">
<refnamediv>
<refname>ifxus_create_slob</refname>
<refpurpose>Creates an slob object and opens it</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_create_slob</function></funcdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-free-slob">
<refnamediv>
<refname>ifxus_free_slob</refname>
<refpurpose>Deletes the slob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_free_slob</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes the slob object. <parameter>bid</parameter> is the Id of
the slob object. Returns FALSE on error otherwise TRUE.
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-close-slob">
<refnamediv>
<refname>ifxus_close_slob</refname>
<refpurpose>Deletes the slob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_close_slob</function></funcdef>
<paramdef>int <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes the slob object on the given slob object-id
<parameter>bid</parameter>. Return FALSE on error otherwise
TRUE.
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-open-slob">
<refnamediv>
<refname>ifxus_open_slob</refname>
<refpurpose>Opens an slob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_open_slob</function></funcdef>
<paramdef>long <parameter>bid</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Opens an slob object. <parameter>bid</parameter> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-tell-slob">
<refnamediv>
<refname>ifxus_tell_slob</refname>
<refpurpose>Returns the current file or seek position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_tell_slob</function></funcdef>
<paramdef>long <parameter>bid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the current file or seek position of an open slob object
<parameter>bid</parameter> should be an existing slob id. Return
FALSE on error otherwise the seek position.
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-seek-slob">
<refnamediv>
<refname>ifxus_seek_slob</refname>
<refpurpose>Sets the current file or seek position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_seek_blob</function></funcdef>
<paramdef>long <parameter>bid</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>long <parameter>offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the current file or seek position of an open slob object.
<parameter>bid</parameter> should be an existing slob id. Modes:
0 = LO_SEEK_SET, 1 = LO_SEEK_CUR, 2 = LO_SEEK_END and
<parameter>offset</parameter> is an byte offset. Return FALSE on
error otherwise the seek position.
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-read-slob">
<refnamediv>
<refname>ifxus_read_slob</refname>
<refpurpose>Reads nbytes of the slob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_read_slob</function></funcdef>
<paramdef>long <parameter>bid</parameter></paramdef>
<paramdef>long <parameter>nbytes</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Reads nbytes of the slob object. <parameter>bid</parameter> is a
existing slob id and <parameter>nbytes</parameter> is the number
of bytes zu read. Return FALSE on error otherwise the string.
</para>
</refsect1>
</refentry>
<refentry id="function.ifxus-write-slob">
<refnamediv>
<refname>ifxus_write_slob</refname>
<refpurpose>Writes a string into the slob object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ifxus_write_slob</function></funcdef>
<paramdef>long <parameter>bid</parameter></paramdef>
<paramdef>string <parameter>content</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Writes a string into the slob object. <parameter>bid</parameter>
is a existing slob id and <parameter>content</parameter> the
content to write. Return FALSE on error otherwise bytes written.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/image.xml
+++ phpdoc/nl/functions/image.xml
<reference id="ref.image">
<title>Image functions</title>
<titleabbrev>Graphics</titleabbrev>
<partintro>
<simpara>
You can use the image functions in PHP to get the size of
<acronym>JPEG</acronym>, <acronym>GIF</acronym>,
<acronym>PNG</acronym>, and <acronym>SWF</acronym> images, and if
you have the <acronym>GD</acronym> library (available at <ulink
url="&url.gd;">&url.gd;</ulink>) you will also be able to create
and manipulate images.
</simpara>
<simpara>
The format of images you are able to manipulate depend on the
version of gd you install, and any other libraries gd might need
to access those image formats. Versions of gd older than gd-1.6
support gif format images, and do not support png, where versions
greater than gd-1.6 support png, not gif.
</simpara>
<simpara>
In order to read and write images in jpeg format, you will need to
obtain and install jpeg-6b (available at
<ulink url="&url.jpeg;">&url.jpeg;</ulink>), and then recompile gd
to
make use of jpeg-6b. You will also have to compile PHP with
<option role="configure">--with-jpeg-dir=/path/to/jpeg-6b</option>.
</simpara>
<simpara>
To add support for Type 1 fonts, you can install t1lib (available
at <ulink url="&url.t1lib;">&url.t1lib;</ulink>), and then add
<option role="configure">--with-t1lib[=dir]</option>.
</simpara>
</partintro>
<refentry id="function.getimagesize">
<refnamediv>
<refname>GetImageSize</refname>
<refpurpose>Get the size of a GIF, JPEG, PNG or SWF image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>getimagesize</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>array
<parameter><optional>imageinfo</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>GetImageSize</function> function will determine the
size of any <acronym>GIF</acronym>, <acronym>JPG</acronym>,
<acronym>PNG</acronym> or <acronym>SWF</acronym> image file and
return the dimensions along with the file type and a height/width
text string to be used inside a normal <acronym>HTML</acronym>
<sgmltag>IMG</sgmltag> tag.
</para>
<para>
Returns an array with 4 elements. Index 0 contains the width of
the image in pixels. Index 1 contains the height. Index 2 a
flag indicating the type of the image. 1 = GIF, 2 = JPG, 3 =
PNG, 4 = SWF. Index 3 is a text string with the correct
"height=xxx width=xxx" string that can be used directly in an IMG
tag.
<example>
<title>GetImageSize</title>
<programlisting role="php">
<?php $size = GetImageSize ("img/flag.jpg"); ?>
<IMG SRC="img/flag.jpg" <?php echo $size[3]; ?>
</programlisting>
</example>
</para>
<para>
The optional <parameter>imageinfo</parameter> parameter allows
you to extract some extended information from the image
file. Currently this will return the diffrent
<acronym>JPG</acronym> APP markers in an associative Array. Some
Programs use these APP markers to embedd text information in
images. A very common one in to embed <acronym>IPTC</acronym>
<ulink url="&url.iptc;">&url.iptc;</ulink> information in the
APP13 marker. You can use the <function>iptcparse</function>
function to parse the binary APP13 marker into something
readable.
<example>
<title>GetImageSize returning IPTC</title>
<programlisting>
<?php
$size = GetImageSize ("testimg.jpg",&$info);
if (isset ($info["APP13"])) {
$iptc = iptcparse ($info["APP13"]);
var_dump ($iptc);
}
?>
</programlisting>
</example>
<note>
<simpara>
This function does not require the GD image library.
</simpara>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.imagearc">
<refnamediv>
<refname>ImageArc</refname>
<refpurpose>Draw a partial ellipse</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagearc</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>cx</parameter></paramdef>
<paramdef>int <parameter>cy</parameter></paramdef>
<paramdef>int <parameter>w</parameter></paramdef>
<paramdef>int <parameter>h</parameter></paramdef>
<paramdef>int <parameter>s</parameter></paramdef>
<paramdef>int <parameter>e</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageArc</function> draws a partial ellipse centered at
<parameter>cx</parameter>, <parameter>cy</parameter> (top left is
0, 0) in the image represented by im. <parameter>W</parameter>
and <parameter>h</parameter> specifies the ellipse's width and
height respectively while the start and end points are specified
in degrees indicated by the <parameter>s</parameter> and
<parameter>e</parameter>. arguments.
</para>
</refsect1>
</refentry>
<refentry id="function.imagechar">
<refnamediv>
<refname>ImageChar</refname>
<refpurpose>Draw a character horizontally</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagechar</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>font</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>string <parameter>c</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageChar</function> draws the first character of
<parameter>c</parameter> in the image identified by
<parameter>id</parameter> with its upper-left at
<parameter>x</parameter>,<parameter>y</parameter> (top left is 0,
0) with the color <parameter>col</parameter>. If font is 1, 2, 3,
4 or 5, a built-in font is used (with higher numbers
corresponding to larger fonts).
</para>
<para>
See also <function>imageloadfont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecharup">
<refnamediv>
<refname>ImageCharUp</refname>
<refpurpose>Draw a character vertically</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecharup</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>font</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>string <parameter>c</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageCharUp</function> draws the character
<parameter>c</parameter> vertically in the image identified by
<parameter>im</parameter> at coordinates
<parameter>x</parameter>, <parameter>y</parameter> (top left is
0, 0) with the color <parameter>col</parameter>. If font is 1,
2, 3, 4 or 5, a built-in font is used.
</para>
<para>
See also <function>imageloadfont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorallocate">
<refnamediv>
<refname>ImageColorAllocate</refname>
<refpurpose>Allocate a color for an image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecolorallocate</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>red</parameter></paramdef>
<paramdef>int <parameter>green</parameter></paramdef>
<paramdef>int <parameter>blue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageColorAllocate</function> returns a color
identifier representing the color composed of the given
<acronym>RGB</acronym> components. The <parameter>im</parameter>
argument is the return from the <function>imagecreate</function>
function. <function>ImageColorAllocate</function> must be called
to create each color that is to be used in the image represented
by <parameter>im</parameter>.
<informalexample>
<programlisting role="php">
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolordeallocate">
<refnamediv>
<refname>ImageColorDeAllocate</refname>
<refpurpose>
De-allocate a color for an image
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>imagecolordeallocate</function>
</funcdef>
<paramdef>int
<parameter>im</parameter>
</paramdef>
<paramdef>int
<parameter>index</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>ImageColorDeAllocate</function> function
de-allocates a color previously allocated with the
<function>ImageColorAllocate</function> function.
<informalexample>
<programlisting role="php">
$white = ImageColorAllocate($im, 255, 255, 255);
ImageColorDeAllocate($im, $white);
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorat">
<refnamediv>
<refname>ImageColorAt</refname>
<refpurpose>Get the index of the color of a pixel</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecolorat</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the index of the color of the pixel at the
specified location in the image.
</para>
<para>
See also <function>imagecolorset</function> and
<function>imagecolorsforindex</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorclosest">
<refnamediv>
<refname>ImageColorClosest</refname>
<refpurpose>
Get the index of the closest color to the specified color
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecolorclosest</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>red</parameter></paramdef>
<paramdef>int <parameter>green</parameter></paramdef>
<paramdef>int <parameter>blue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the index of the color in the palette of the image which
is "closest" to the specified <acronym>RGB</acronym> value.
</para>
<para>
The "distance" between the desired color and each color in the
palette is calculated as if the <acronym>RGB</acronym> values
represented points in three-dimensional space.
</para>
<para>
See also <function>imagecolorexact</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorexact">
<refnamediv>
<refname>ImageColorExact</refname>
<refpurpose>Get the index of the specified color</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecolorexact</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>red</parameter></paramdef>
<paramdef>int <parameter>green</parameter></paramdef>
<paramdef>int <parameter>blue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the index of the specified color in the palette of the
image.
</para>
<para>
If the color does not exist in the image's palette, -1 is
returned.
</para>
<para>
See also <function>imagecolorclosest</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorresolve">
<refnamediv>
<refname>ImageColorResolve</refname>
<refpurpose>
Get the index of the specified color or its closest possible
alternative
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecolorresolve</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>red</parameter></paramdef>
<paramdef>int <parameter>green</parameter></paramdef>
<paramdef>int <parameter>blue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is guaranteed to return a color index for a
requested color, either the exact color or the closest possible
alternative.
</para>
<para>
See also <function>imagecolorclosest</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagegammacorrect">
<refnamediv>
<refname>ImageGammaCorrect</refname>
<refpurpose>
Apply a gamma correction to a GD image
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>imagegammacorrect</function>
</funcdef>
<paramdef>int
<parameter>im</parameter>
</paramdef>
<paramdef>double
<parameter>inputgamma</parameter>
</paramdef>
<paramdef>double
<parameter>outputgamma</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>ImageGammaCorrect</function> function applies gamma
correction to a gd image stream (<parameter>im</parameter>) given
an input gamma, the parameter <parameter>inputgamma</parameter>
and an output gamma, the parameter
<parameter>outputgamma</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorset">
<refnamediv>
<refname>ImageColorSet</refname>
<refpurpose>
Set the color for the specified palette index
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>imagecolorset</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>index</parameter></paramdef>
<paramdef>int <parameter>red</parameter></paramdef>
<paramdef>int <parameter>green</parameter></paramdef>
<paramdef>int <parameter>blue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This sets the specified index in the palette to the specified
color. This is useful for creating flood-fill-like effects in
paletted images without the overhead of performing the actual
flood-fill.
</para>
<para>
See also <function>imagecolorat</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorsforindex">
<refnamediv>
<refname>ImageColorsForIndex</refname>
<refpurpose>Get the colors for an index</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imagecolorsforindex</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>index</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This returns an associative array with red, green, and blue keys
that contain the appropriate values for the specified color
index.
</para>
<para>
See also <function>imagecolorat</function> and
<function>imagecolorexact</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolorstotal">
<refnamediv>
<refname>ImageColorsTotal</refname>
<refpurpose>
Find out the number of colors in an image's palette
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecolorstotal</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This returns the number of colors in the specified image's
palette.
</para>
<para>
See also <function>imagecolorat</function> and
<function>imagecolorsforindex</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecolortransparent">
<refnamediv>
<refname>ImageColorTransparent</refname>
<refpurpose>Define a color as transparent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecolortransparent</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int
<parameter><optional>col</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageColorTransparent</function> sets the transparent
color in the <parameter>im</parameter> image to
<parameter>col</parameter>. <parameter>Im</parameter> is the
image identifier returned by <function>ImageCreate</function> and
<parameter>col</parameter> is a color identifier returned by
<function>ImageColorAllocate</function>.
</para>
<para>
The identifier of the new (or current, if none is specified)
transparent color is returned.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecopy">
<refnamediv>
<refname>ImageCopy</refname>
<refpurpose>
Copy part of an image
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>ImageCopy</function>
</funcdef>
<paramdef>int
<parameter>dst_im</parameter>
</paramdef>
<paramdef>int
<parameter>src_im</parameter>
</paramdef>
<paramdef>int
<parameter>dst_x</parameter>
</paramdef>
<paramdef>int
<parameter>dst_y</parameter>
</paramdef>
<paramdef>int
<parameter>src_x</parameter>
</paramdef>
<paramdef>int
<parameter>src_y</parameter>
</paramdef>
<paramdef>int
<parameter>src_w</parameter>
</paramdef>
<paramdef>int
<parameter>src_h</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Copy a part of <parameter>src_im</parameter> onto
<parameter>dst_im</parameter> starting at the x,y coordinates
<parameter>src_x</parameter>, <parameter>src_y </parameter> with
a width of <parameter>src_w</parameter> and a height of
<parameter>src_h</parameter>. The portion defined will be copied
onto the x,y coordinates, <parameter>dst_x</parameter> and
<parameter>dst_y</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecopyresized">
<refnamediv>
<refname>ImageCopyResized</refname>
<refpurpose>Copy and resize part of an image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecopyresized</function></funcdef>
<paramdef>int <parameter>dst_im</parameter></paramdef>
<paramdef>int <parameter>src_im</parameter></paramdef>
<paramdef>int <parameter>dstX</parameter></paramdef>
<paramdef>int <parameter>dstY</parameter></paramdef>
<paramdef>int <parameter>srcX</parameter></paramdef>
<paramdef>int <parameter>srcY</parameter></paramdef>
<paramdef>int <parameter>dstW</parameter></paramdef>
<paramdef>int <parameter>dstH</parameter></paramdef>
<paramdef>int <parameter>srcW</parameter></paramdef>
<paramdef>int <parameter>srcH</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageCopyResized</function> copies a rectangular
portion of one image to another image.
<parameter>Dst_im</parameter> is the destination image,
<parameter>src_im</parameter> is the source image identifier. If
the source and destination coordinates and width and heights
differ, appropriate stretching or shrinking of the image fragment
will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the
same image (if <parameter>dst_im</parameter> is the same as
<parameter>src_im</parameter>) but if the regions overlap the
results will be unpredictable.
</para>
</refsect1>
</refentry>
<refentry id="function.imagecreate">
<refnamediv>
<refname>ImageCreate</refname>
<refpurpose>Create a new image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecreate</function></funcdef>
<paramdef>int <parameter>x_size</parameter></paramdef>
<paramdef>int <parameter>y_size</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageCreate</function> returns an image identifier
representing a blank image of size <parameter>x_size</parameter>
by <parameter>y_size</parameter>.
<example>
<title>
Creating a new GD image stream and outputting an image.
</title>
<programlisting role="php">
<?php
header ("Content-type: image/png");
$im = @ImageCreate (50, 100)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
ImageString ($im, 1, 5, 5, "A Simple Text String", $text_color);
ImagePng ($im);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imagecreatefromgif">
<refnamediv>
<refname>ImageCreateFromGIF</refname>
<refpurpose>Create a new image from file or URL</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecreatefromgif</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageCreateFromGif</function> returns an image identifier
representing the image obtained from the given filename.
</para>
<para>
<function>ImageCreateFromGif</function> returns an empty string
on failure. It also outputs an error message, which unfortunately
displays as a broken link in a browser. To ease debugging the
following example will produce an error GIF:
<example>
<title>
Example to handle an error during creation (courtesy
vic@zymsys.com)
</title>
<programlisting role="php">
function LoadGif ($imgname) {
$im = @ImageCreateFromGIF ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = ImageCreate (150, 30); /* Create a blank image */
$bgc = ImageColorAllocate ($im, 255, 255, 255);
$tc = ImageColorAllocate ($im, 0, 0, 0);
ImageFilledRectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
ImageString($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
</programlisting>
</example>
<note>
<para>
Since all GIF support was removed from the GD library in
version 1.6, this function is not available if you are using
that version of the GD library.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.imagecreatefromjpeg">
<refnamediv>
<refname>ImageCreateFromJPEG</refname>
<refpurpose>Create a new image from file or URL</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecreatefromjpeg</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageCreateFromJPEG</function> returns an image identifier
representing the image obtained from the given filename.
</para>
<para>
<function>ImagecreateFromJPEG</function> returns an empty string
on failure. It also outputs an error message, which unfortunately
displays as a broken link in a browser. To ease debugging the
following example will produce an error <acronym>JPEG</acronym>:
<example>
<title>
Example to handle an error during creation (courtesy
vic@zymsys.com )
</title>
<programlisting role="php">
function LoadJpeg ($imgname) {
$im = @ImageCreateFromJPEG ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = ImageCreate (150, 30); /* Create a blank image */
$bgc = ImageColorAllocate ($im, 255, 255, 255);
$tc = ImageColorAllocate ($im, 0, 0, 0);
ImageFilledRectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
ImageString ($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imagecreatefrompng">
<refnamediv>
<refname>ImageCreateFromPNG</refname>
<refpurpose>Create a new image from file or URL</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagecreatefrompng</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageCreateFromPNG</function> returns an image identifier
representing the image obtained from the given filename.
</para>
<para>
<function>ImageCreateFromPNG</function> returns an empty string
on failure. It also outputs an error message, which unfortunately
displays as a broken link in a browser. To ease debugging the
following example will produce an error <acronym>PNG</acronym>:
<example>
<title>
Example to handle an error during creation (courtesy
vic@zymsys.com)
</title>
<programlisting role="php">
function LoadPNG ($imgname) {
$im = @ImageCreateFromPNG ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = ImageCreate (150, 30); /* Create a blank image */
$bgc = ImageColorAllocate ($im, 255, 255, 255);
$tc = ImageColorAllocate ($im, 0, 0, 0);
ImageFilledRectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
ImageString ($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imagedashedline">
<refnamediv>
<refname>ImageDashedLine</refname>
<refpurpose>Draw a dashed line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagedashedline</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x1</parameter></paramdef>
<paramdef>int <parameter>y1</parameter></paramdef>
<paramdef>int <parameter>x2</parameter></paramdef>
<paramdef>int <parameter>y2</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageDashedLine</function> draws a dashed line from
<parameter>x1</parameter>, <parameter>y1</parameter> to
<parameter>x2</parameter>, <parameter>y2</parameter> (top left is
0, 0) in image <parameter>im</parameter> of color
<parameter>col</parameter>.
</para>
<para>
See also <function>ImageLine</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagedestroy">
<refnamediv>
<refname>ImageDestroy</refname>
<refpurpose>Destroy an image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagedestroy</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageDestroy</function> frees any memory associated
with image <parameter>im</parameter>. <parameter>Im</parameter>
is the image identifier returned by the
<function>ImageCreate</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.imagefill">
<refnamediv>
<refname>ImageFill</refname>
<refpurpose>Flood fill</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagefill</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageFill</function> performs a flood fill starting at
coordinate <parameter>x</parameter>, <parameter>y</parameter>
(top left is 0, 0) with color <parameter>col</parameter> in the
image <parameter>im</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagefilledpolygon">
<refnamediv>
<refname>ImageFilledPolygon</refname>
<refpurpose>Draw a filled polygon</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagefilledpolygon</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>array <parameter>points</parameter></paramdef>
<paramdef>int <parameter>num_points</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageFilledPolygon</function> creates a filled polygon
in image <parameter>im</parameter>.
<parameter>Points</parameter> is a PHP array containing the
polygon's vertices, ie. points[0] = x0, points[1] = y0, points[2]
= x1, points[3] = y1, etc. <parameter>Num_points</parameter> is
the total number of vertices.
</para>
</refsect1>
</refentry>
<refentry id="function.imagefilledrectangle">
<refnamediv>
<refname>ImageFilledRectangle</refname>
<refpurpose>Draw a filled rectangle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagefilledrectangle</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x1</parameter></paramdef>
<paramdef>int <parameter>y1</parameter></paramdef>
<paramdef>int <parameter>x2</parameter></paramdef>
<paramdef>int <parameter>y2</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageFilledRectangle</function> creates a filled
rectangle of color <function>col</function> in image
<parameter>im</parameter> starting at upper left coordinates
<parameter>x1</parameter>, <parameter>y1</parameter> and ending
at bottom right coordinates <parameter>x2</parameter>,
<parameter>y2</parameter>. 0, 0 is the top left corner of the
image.
</para>
</refsect1>
</refentry>
<refentry id="function.imagefilltoborder">
<refnamediv>
<refname>ImageFillToBorder</refname>
<refpurpose>Flood fill to specific color</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagefilltoborder</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>int <parameter>border</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageFillToBorder</function> performs a flood fill
whose border color is defined by <parameter>border</parameter>.
The starting point for the fill is <parameter>x</parameter>,
<parameter>y</parameter> (top left is 0, 0) and the region is
filled with color <parameter>col</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagefontheight">
<refnamediv>
<refname>ImageFontHeight</refname>
<refpurpose>Get font height</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagefontheight</function></funcdef>
<paramdef>int <parameter>font</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the pixel height of a character in the specified font.
</para>
<para>
See also <function>ImageFontWidth</function> and
<function>ImageLoadFont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagefontwidth">
<refnamediv>
<refname>ImageFontWidth</refname>
<refpurpose>Get font width</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagefontwidth</function></funcdef>
<paramdef>int <parameter>font</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the pixel width of a character in font.
</para>
<para>
See also <function>ImageFontHeight</function> and
<function>ImageLoadFont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagegif">
<refnamediv>
<refname>ImageGIF</refname>
<refpurpose>Output image to browser or file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagegif</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>string
<parameter><optional>filename</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageGIF</function> creates the <acronym>GIF</acronym>
file in filename from the image <parameter>im</parameter>. The
<parameter>im</parameter> argument is the return from the
<function>imagecreate</function> function.
</para>
<para>
The image format will be <acronym>GIF87a</acronym> unless the
image has been made transparent with
<function>ImageColorTransparent</function>, in which case the
image format will be <acronym>GIF89a</acronym>.
</para>
<para>
The filename argument is optional, and if left off, the raw image
stream will be output directly. By sending an image/gif
content-type using <function>header</function>, you can create a
PHP script that outputs <acronym>GIF</acronym> images directly.
<note>
<para>
Since all <acronym>GIF</acronym> support was removed from the
<acronym>GD</acronym> library in version 1.6, this function is
not available if you are using that version of the GD library.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.imagepng">
<refnamediv>
<refname>ImagePNG</refname>
<refpurpose>
Output a PNG image to either the browser or a file
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>imagepng</function>
</funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>string
<parameter><optional>filename</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>ImagePng</function> outputs a GD image stream
(<parameter>im</parameter>) in PNG format to standard output
(usually the browser) or, if a filename is given by the
<parameter>filename</parameter> it outputs the image to the file.
<informalexample>
<programlisting role="php">
<?php
$im = ImageCreateFromPng("test.png");
ImagePng($im);
?>
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.imagejpeg">
<refnamediv>
<refname>ImageJPEG</refname>
<refpurpose>Output image to browser or file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagejpeg</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>string
<parameter><optional>filename</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>quality</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageJPEG</function> creates the
<acronym>JPEG</acronym> file in filename from the image
<parameter>im</parameter>. The <parameter>im</parameter> argument
is the return from the <function>ImageCreate</function> function.
</para>
<para>
The filename argument is optional, and if left off, the raw image
stream will be output directly. To skip the filename argument in
order to provide a quality argument just use an empty string
(''). By sending an image/jpeg content-type using
<function>header</function>, you can create a PHP script that
outputs JPEG images directly.
<note>
<para>
JPEG support is only available in PHP if PHP was compiled
against GD-1.8 or later.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.imageinterlace">
<refnamediv>
<refname>ImageInterlace</refname>
<refpurpose>Enable or disable interlace</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imageinterlace</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int
<parameter><optional>interlace</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageInterlace</function> turns the interlace bit on or off.
If interlace is 1 the im image will be interlaced, and if interlace
is 0 the interlace bit is turned off.
</para>
<para>
This functions returns whether the interlace bit is set for the
image.
</para>
</refsect1>
</refentry>
<refentry id="function.imageline">
<refnamediv>
<refname>ImageLine</refname>
<refpurpose>Draw a line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imageline</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x1</parameter></paramdef>
<paramdef>int <parameter>y1</parameter></paramdef>
<paramdef>int <parameter>x2</parameter></paramdef>
<paramdef>int <parameter>y2</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageLine</function> draws a line from
<parameter>x1</parameter>, <parameter>y1</parameter> to
<parameter>x2</parameter>, <parameter>y2</parameter> (top left is
0, 0) in image im of color <parameter>col</parameter>.
</para>
<para>
See also <function>ImageCreate</function> and
<function>ImageColorAllocate</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imageloadfont">
<refnamediv>
<refname>ImageLoadFont</refname>
<refpurpose>Load a new font</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imageloadfont</function></funcdef>
<paramdef>string <parameter>file</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageLoadFont</function> loads a user-defined bitmap
font and returns an identifier for the font (that is always
greater than 5, so it will not conflict with the built-in fonts).
</para>
<para>
The font file format is currently binary and architecture
dependent. This means you should generate the font files on the
same type of CPU as the machine you are running PHP on.
</para>
<para>
<table>
<title>Font file format</title>
<tgroup cols="3">
<thead>
<row>
<entry>byte position</entry>
<entry>C data type</entry>
<entry>description</entry>
</row>
</thead>
<tbody>
<row>
<entry>byte 0-3</entry>
<entry>int</entry>
<entry>number of characters in the font</entry>
</row>
<row>
<entry>byte 4-7</entry>
<entry>int</entry>
<entry>
value of first character in the font (often 32 for space)
</entry>
</row>
<row>
<entry>byte 8-11</entry>
<entry>int</entry>
<entry>pixel width of each character</entry>
</row>
<row>
<entry>byte 12-15</entry>
<entry>int</entry>
<entry>pixel height of each character</entry>
</row>
<row>
<entry>byte 16-</entry>
<entry>char</entry>
<entry>
array with character data, one byte per pixel in each
character, for a total of (nchars*width*height) bytes.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
See also <function>ImageFontWidth</function> and
<function>ImageFontHeight</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagepolygon">
<refnamediv>
<refname>ImagePolygon</refname>
<refpurpose>Draw a polygon</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagepolygon</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>array <parameter>points</parameter></paramdef>
<paramdef>int <parameter>num_points</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImagePolygon</function> creates a polygon in image id.
<parameter>Points</parameter> is a PHP array containing the
polygon's vertices, ie. points[0] = x0, points[1] = y0, points[2]
= x1, points[3] = y1, etc. <parameter>Num_points</parameter> is
the total number of vertices.
</para>
<para>
See also <function>imagecreate</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagepsbbox">
<refnamediv>
<refname>ImagePSBBox</refname>
<refpurpose>
Give the bounding box of a text rectangle using PostScript Type1
fonts
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imagepsbbox</function></funcdef>
<paramdef>string <parameter>text</parameter></paramdef>
<paramdef>int <parameter>font</parameter></paramdef>
<paramdef>int <parameter>size</parameter></paramdef>
<paramdef>int
<parameter><optional>space</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>tightness</optional></parameter></paramdef>
<paramdef>float
<parameter><optional>angle</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<parameter>Size</parameter> is expressed in pixels.
</para>
<para>
<parameter>Space</parameter> allows you to change the default
value of a space in a font. This amount is added to the normal
value and can also be negative.
</para>
<para>
<parameter>Tightness</parameter> allows you to control the amount
of white space between characters. This amount is added to the
normal character width and can also be negative.
</para>
<para>
<parameter>Angle</parameter> is in degrees.
</para>
<para>
Parameters <parameter>space</parameter> and
<parameter>tightness</parameter> are expressed in character space
units, where 1 unit is 1/1000th of an em-square.
</para>
<para>
Parameters <parameter>space</parameter>,
<parameter>tightness</parameter>, and <parameter>angle</parameter>
are optional.
</para>
<para>
The bounding box is calculated using information available from
character metrics, and unfortunately tends to differ slightly
from the results achieved by actually rasterizing the text. If
the angle is 0 degrees, you can expect the text to need 1 pixel
more to every direction.
</para>
<para>
This function returns an array containing the following elements:
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>0</entry>
<entry>lower left x-coordinate</entry>
</row>
<row>
<entry>1</entry>
<entry>lower left y-coordinate</entry>
</row>
<row>
<entry>2</entry>
<entry>upper right x-coordinate</entry>
</row>
<row>
<entry>3</entry>
<entry>upper right y-coordinate</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
See also <function>imagepstext</function>.
</para>
</refsect1>
</refentry>
<!-- The function in t1lib which this function uses seems to be buggy...
Currently, just comment out everywhere in the docs and source until time
permits to find a solution.
<refentry id="function.imagepscopyfont">
<refnamediv>
<refname>ImagePSCopyFont</refname>
<refpurpose>
Make a copy of an already loaded font for further modification
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagepscopyfont</function></funcdef>
<paramdef>int <parameter>fontindex</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Use this function if you need make further modifications to the
font, for example extending/condensing, slanting it or changing
it's character encoding vector, but need to keep the original
along as well. Note that the font you want to copy must be one
obtained using <function>ImagePSLoadFont</function>, not a font
that is itself a copied one. You can although make modifications
to it before copying.
</para>
<para>
If you use this function, you <emphasis>must</emphasis> free the
fonts obtained this way yourself and in reverse order. Otherwise
your script <emphasis>will</emphasis> hang.
</para>
<para>
In the case everything went right, a valid font index will be
returned and can be used for further purposes. Otherwise the
function returns false and prints a message describing what went
wrong.
</para>
<para>
See also <function>ImagePSLoadFont</function>.
</para>
</refsect1>
</refentry>
-->
<refentry id="function.imagepsencodefont">
<refnamediv>
<refname>ImagePSEncodeFont</refname>
<refpurpose>
Change the character encoding vector of a font
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagepsencodefont</function></funcdef>
<paramdef>string <parameter>encodingfile</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Loads a character encoding vector from from a file and changes
the fonts encoding vector to it. As a PostScript fonts default
vector lacks most of the character positions above 127, you'll
definitely want to change this if you use an other language than
english. The exact format of this file is described in T1libs
documentation. T1lib comes with two ready-to-use files,
IsoLatin1.enc and IsoLatin2.enc.
</para>
<para>
If you find yourself using this function all the time, a much
better way to define the encoding is to set ps.default_encoding in
the <link linkend="configuration.file">configuration file</link>
to point to the right encoding file and all fonts you load will
automatically have the right encoding.
</para>
</refsect1>
</refentry>
<refentry id="function.imagepsfreefont">
<refnamediv>
<refname>ImagePSFreeFont</refname>
<refpurpose>Free memory used by a PostScript Type 1 font</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>imagepsfreefont</function></funcdef>
<paramdef>int <parameter>fontindex</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
See also <function>ImagePSLoadFont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagepsloadfont">
<refnamediv>
<refname>ImagePSLoadFont</refname>
<refpurpose>Load a PostScript Type 1 font from file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagepsloadfont</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
In the case everything went right, a valid font index will be
returned and can be used for further purposes. Otherwise the
function returns false and prints a message describing what went
wrong.
</para>
<para>
See also <function>ImagePSFreeFont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagepsextendfont">
<refnamediv>
<refname>ImagePsExtendFont</refname>
<refpurpose>
Extend or condense a font
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>imagepsextendfont</function>
</funcdef>
<paramdef>int
<parameter>font_index</parameter>
</paramdef>
<paramdef>double
<parameter>extend</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Extend or condense a font (<parameter>font_index</parameter>), if
the value of the <parameter>extend</parameter> parameter is less
than one you will be condensing the font.
</para>
</refsect1>
</refentry>
<refentry id="function.imagepsslantfont">
<refnamediv>
<refname>ImagePsSlantFont</refname>
<refpurpose>
Slant a font
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>imagepsslantfont</function>
</funcdef>
<paramdef>int
<parameter>font_index</parameter>
</paramdef>
<paramdef>double
<parameter>slant</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Slant a font given by the <parameter>font_index</parameter>
parameter with a slant of the value of the
<parameter>slant</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.imagepstext">
<refnamediv>
<refname>ImagePSText</refname>
<refpurpose>
To draw a text string over an image using PostScript Type1 fonts
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imagepstext</function></funcdef>
<paramdef>int <parameter>image</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
<paramdef>int <parameter>font</parameter></paramdef>
<paramdef>int <parameter>size</parameter></paramdef>
<paramdef>int <parameter>foreground</parameter></paramdef>
<paramdef>int <parameter>background</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>int
<parameter>
<optional>space</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>tightness</optional>
</parameter>
</paramdef>
<paramdef>float
<parameter>
<optional>angle</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>antialias_steps</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<parameter>Size</parameter> is expressed in pixels.
</para>
<para>
<parameter>Foreground</parameter> is the color in which the text
will be painted. <parameter>Background</parameter> is the color
to which the text will try to fade in with antialiasing. No
pixels with the color <parameter>background</parameter> are
actually painted, so the background image does not need to be of
solid color.
</para>
<para>
The coordinates given by <parameter>x</parameter>,
<parameter>y</parameter> will define the origin (or reference
point) of the first character (roughly the lower-left corner of
the character). This is different from the
<function>ImageString</function>, where <parameter>x</parameter>,
<parameter>y</parameter> define the upper-right corner of the
first character. Refer to PostScipt documentation about fonts and
their measuring system if you have trouble understanding how this
works.
</para>
<para>
<parameter>Space</parameter> allows you to change the default
value of a space in a font. This amount is added to the normal
value and can also be negative.
</para>
<para>
<parameter>Tightness</parameter> allows you to control the amount
of white space between characters. This amount is added to the
normal character width and can also be negative.
</para>
<para>
<parameter>Angle</parameter> is in degrees.
</para>
<para>
<parameter>Antialias_steps</parameter> allows you to control the
number of colours used for antialiasing text. Allowed values are
4 and 16. The higher value is recommended for text sizes lower
than 20, where the effect in text quality is quite visible. With
bigger sizes, use 4. It's less computationally intensive.
</para>
<para>
Parameters <parameter>space</parameter> and
<parameter>tightness</parameter> are expressed in character space
units, where 1 unit is 1/1000th of an em-square.
</para>
<para>
Parameters <parameter>space</parameter>,
<parameter>tightness</parameter>, <parameter>angle</parameter>
and <parameter>antialias</parameter> are optional.
</para>
<para>
This function returns an array containing the following elements:
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>0</entry>
<entry>lower left x-coordinate</entry>
</row>
<row>
<entry>1</entry>
<entry>lower left y-coordinate</entry>
</row>
<row>
<entry>2</entry>
<entry>upper right x-coordinate</entry>
</row>
<row>
<entry>3</entry>
<entry>upper right y-coordinate</entry>
</row>
</tbody>
</tgroup>
</informaltable></para>
<para>
See also <function>imagepsbbox</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagerectangle">
<refnamediv>
<refname>ImageRectangle</refname>
<refpurpose>Draw a rectangle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagerectangle</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x1</parameter></paramdef>
<paramdef>int <parameter>y1</parameter></paramdef>
<paramdef>int <parameter>x2</parameter></paramdef>
<paramdef>int <parameter>y2</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageRectangle</function> creates a rectangle of color
col in image im starting at upper left coordinate x1, y1 and
ending at bottom right coordinate x2, y2. 0, 0 is the top left
corner of the image.
</para>
</refsect1>
</refentry>
<refentry id="function.imagesetpixel">
<refnamediv>
<refname>ImageSetPixel</refname>
<refpurpose>Set a single pixel</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagesetpixel</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageSetPixel</function> draws a pixel at
<parameter>x</parameter>, <parameter>y</parameter> (top left is
0, 0) in image <parameter>im</parameter> of color
<parameter>col</parameter>.
</para>
<para>
See also <function>ImageCreate</function> and
<function>ImageColorAllocate</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagestring">
<refnamediv>
<refname>ImageString</refname>
<refpurpose>Draw a string horizontally</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagestring</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>font</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>string <parameter>s</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageString</function> draws the string
<parameter>s</parameter> in the image identified by
<parameter>im</parameter> at coordinates
<parameter>x</parameter>, <parameter>y</parameter> (top left is
0, 0) in color <parameter>col</parameter>. If font is 1, 2, 3, 4
or 5, a built-in font is used.
</para>
<para>
See also <function>ImageLoadFont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagestringup">
<refnamediv>
<refname>ImageStringUp</refname>
<refpurpose>Draw a string vertically</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagestringup</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>font</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>string <parameter>s</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageStringUp</function> draws the string
<parameter>s</parameter> vertically in the image identified by
<parameter>im</parameter> at coordinates
<parameter>x</parameter>, <parameter>y</parameter> (top left is
0, 0) in color <parameter>col</parameter>. If font is 1, 2, 3, 4
or 5, a built-in font is used.
</para>
<para>
See also <function>ImageLoadFont</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagesx">
<refnamediv>
<refname>ImageSX</refname>
<refpurpose>Get image width</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagesx</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageSX</function> returns the width of the image
identified by <parameter>im</parameter>.
</para>
<para>
See also <function>ImageCreate</function> and
<function>ImageSY</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagesy">
<refnamediv>
<refname>ImageSY</refname>
<refpurpose>Get image height</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagesy</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageSY</function> returns the height of the image
identified by <parameter>im</parameter>.
</para>
<para>
See also <function>ImageCreate</function> and
<function>ImageSX</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagettfbbox">
<refnamediv>
<refname>ImageTTFBBox</refname>
<refpurpose>
Give the bounding box of a text using TypeType fonts
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imagettfbbox</function></funcdef>
<paramdef>int <parameter>size</parameter></paramdef>
<paramdef>int <parameter>angle</parameter></paramdef>
<paramdef>string <parameter>fontfile</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function calculates and returns the bounding box in pixels
for a TrueType text.
<variablelist>
<varlistentry>
<term>
<parameter>text</parameter>
</term>
<listitem>
<simpara>The string to be measured.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>size</parameter>
</term>
<listitem>
<simpara>The font size.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>fontfile</parameter>
</term>
<listitem>
<simpara>
The name of the TrueType font file. (Can also be an URL.)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>angle</parameter>
</term>
<listitem>
<simpara>
Angle in degrees in which <parameter>text</parameter> will be
measured.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<function>ImageTTFBBox</function> returns an array with 8
elements representing four points making the bounding box of the
text:
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>0</entry>
<entry>lower left corner, X position</entry>
</row>
<row>
<entry>1</entry>
<entry>lower left corner, Y position</entry>
</row>
<row>
<entry>2</entry>
<entry>lower right corner, X position</entry>
</row>
<row>
<entry>3</entry>
<entry>lower right corner, Y position</entry>
</row>
<row>
<entry>4</entry>
<entry>upper right corner, X position</entry>
</row>
<row>
<entry>5</entry>
<entry>upper right corner, Y position</entry>
</row>
<row>
<entry>6</entry>
<entry>upper left corner, X position</entry>
</row>
<row>
<entry>7</entry>
<entry>upper left corner, Y position</entry>
</row>
</tbody>
</tgroup>
</informaltable>
The points are relative to the <emphasis>text</emphasis>
regardless of the angle, so "upper left" means in the top
left-hand corner seeing the text horizontallty.
</para>
<para>
This function requires both the GD library and the FreeType
library.
</para>
<para>
See also <function>ImageTTFText</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagettftext">
<refnamediv>
<refname>ImageTTFText</refname>
<refpurpose>
Write text to the image using TrueType fonts
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imagettftext</function></funcdef>
<paramdef>int <parameter>im</parameter></paramdef>
<paramdef>int <parameter>size</parameter></paramdef>
<paramdef>int <parameter>angle</parameter></paramdef>
<paramdef>int <parameter>x</parameter></paramdef>
<paramdef>int <parameter>y</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
<paramdef>string <parameter>fontfile</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ImageTTFText</function> draws the string
<parameter>text</parameter> in the image identified by
<parameter>im</parameter>, starting at coordinates
<parameter>x</parameter>, <parameter>y</parameter> (top left is
0, 0), at an angle of <parameter>angle</parameter> in color
<parameter>col</parameter>, using the TrueType font file
identified by <parameter>fontfile</parameter>.
</para>
<para>
The coordinates given by <parameter>x</parameter>,
<parameter>y</parameter> will define the basepoint of the first
character (roughly the lower-left corner of the character). This
is different from the <function>ImageString</function>, where x,
y define the upper-right corner of the first character.
</para>
<para>
<parameter>Angle</parameter> is in degrees, with 0 degrees being
left-to-right reading text (3 o'clock direction), and higher
values representing a counter-clockwise rotation. (i.e., a value
of 90 would result in bottom-to-top reading text).
</para>
<para>
<parameter>Fontfile</parameter> is the path to the TrueType font
you wish to use.
</para>
<para>
<parameter>Text</parameter> is the text string which may include
UTF-8 character sequences (of the form: &#123;) to access
characters in a font beyond the first 255.
</para>
<para>
<parameter>Col</parameter> is the color index. Using the
negative of a color index has the effect of turning off
antialiasing.
</para>
<para>
<function>ImageTTFText</function> returns an array with 8
elements representing four points making the bounding box of the
text. The order of the points is upper left, upper right, lower
right, lower left. The points are relative to the text
regardless of the angle, so "upper left" means in the top
left-hand corner when you see the text horizontallty.
</para>
<para>
This example script will produce a black GIF 400x30 pixels, with
the words "Testing..." in white in the font Arial.
<example>
<title>ImageTTFText</title>
<programlisting role="php">
<?php
Header ("Content-type: image/gif");
$im = imagecreate (400, 30);
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
ImageTTFText ($im, 20, 0, 10, 20, $white, "/path/arial.ttf",
"Testing... Omega: &#937;");
ImageGif ($im);
ImageDestroy ($im);
?>
</programlisting>
</example>
</para>
<para>
This function requires both the GD library and the <ulink
url="&url.freetype;">FreeType</ulink> library.
</para>
<para>
See also <function>ImageTTFBBox</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imagetypes">
<refnamediv>
<refname>ImageTypes</refname>
<refpurpose>
Return the image types supported by this PHP build
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imagetypes</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
This function returns a bit-field corresponding to the image
formats supported by the version of GD linked into PHP. The
following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG |
IMG_WBMP. To check for PNG support, for example, do this:
<example>
<title>ImageTypes</title>
<programlisting role="php">
<?php
if (ImageTypes() & IMG_PNG) {
echo "PNG Support is enabled";
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.read-exif-data">
<refnamediv>
<refname>read_exif_data</refname>
<refpurpose>Read the EXIF headers from a JPEG</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>read_exif_data</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>read_exif_data</function> function reads the
EXIF headers from a JPEG image file. It returns an associative
array where the indexes are the Exif header names and the values
are the values associated with those Exif headers. Exif headers
tend to be present in JPEG images generated by digital cameras, but
unfortunately each digital camera maker has a different idea of how
to actually tag their images, so you can't always rely on a specific
Exif header being present.
<example>
<title>read_exif_data</title>
<programlisting role="php">
<?php
$exif = read_exif_data ('p0001807.jpg');
while(list($k,$v)=each($exif)) {
echo "$k: $v<br>\n";
}
?>
Output:
FileName: p0001807.jpg
FileDateTime: 929353056
FileSize: 378599
CameraMake: Eastman Kodak Company
CameraModel: KODAK DC265 ZOOM DIGITAL CAMERA (V01.00)
DateTime: 1999:06:14 01:37:36
Height: 1024
Width: 1536
IsColor: 1
FlashUsed: 0
FocalLength: 8.0mm
RawFocalLength: 8
ExposureTime: 0.004 s (1/250)
RawExposureTime: 0.0040000001899898
ApertureFNumber: f/ 9.5
RawApertureFNumber: 9.5100002288818
FocusDistance: 16.66m
RawFocusDistance: 16.659999847412
Orientation: 1
ExifVersion: 0200
</programlisting>
</example>
</para>
<para>
<note>
<simpara>
This function is only available in PHP 4 compiled using --enable-exif
</simpara>
<simpara>
This function does not require the GD image library.
</simpara>
</note>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/imap.xml
+++ phpdoc/nl/functions/imap.xml
<reference id="ref.imap">
<title>IMAP, POP3 and NNTP functions</title>
<titleabbrev>IMAP</titleabbrev>
<partintro>
<simpara>
To get these functions to work, you have to compile PHP with
<option role="configure">--with-imap</option>. That requires the
c-client library to be installed. Grab the latest version from
<ulink url="&url.imap;">&url.imap;</ulink> and compile it. Then
copy <filename>c-client/c-client.a</filename> to
<filename>/usr/local/lib/libc-client.a</filename> or some other
directory on your link path and copy
<filename>c-client/rfc822.h</filename>,
<filename>mail.h</filename> and <filename>linkage.h</filename> to
<filename>/usr/local/include</filename> or some other directory in
your include path.
</simpara>
<simpara>
Note that these functions are not limited to the
<acronym>IMAP</acronym> protocol, despite their name. The
underlying c-client library also supports <acronym>NNTP</acronym>,
<acronym>POP3</acronym> and local mailbox access methods.
</simpara>
<para>
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
(<filename>docs/internal.txt</filename>). and the following RFC
documents:
<itemizedlist>
<listitem>
<simpara>
<ulink url="&url.rfc;rfc821.html">RFC821</ulink>: Simple Mail
Transfer Protocol (SMTP).
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="&url.rfc;rfc822.html">RFC822</ulink>: Standard for
ARPA internet text messages.
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="&url.rfc;rfc2060.html">RFC2060</ulink>: Internet
Message Access Protocol (IMAP) Version 4rev1.
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="&url.rfc;rfc1939.html">RFC1939</ulink>: Post
Office Protocol Version 3 (POP3).
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="&url.rfc;rfc977.html">RFC977</ulink>: Network News
Transfer Protocol (NNTP).
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="&url.rfc;rfc2076.html">RFC2076</ulink>: Common
Internet Message Headers.
</simpara>
</listitem>
<listitem>
<simpara>
<ulink url="&url.rfc;rfc2045.html">RFC2045</ulink> , <ulink
url="&url.rfc;rfc2046.html">RFC2046</ulink> , <ulink
url="&url.rfc;rfc2047.html">RFC2047</ulink> , <ulink
url="&url.rfc;rfc2048.html">RFC2048</ulink> & <ulink
url="&url.rfc;rfc2049.html">RFC2049</ulink>: Multipurpose
Internet Mail Extensions (MIME).
</simpara>
</listitem>
</itemizedlist>
A detailed overview is also available in the books
<ulink url="&url.email.book;">Programming Internet Email</ulink>
by David Wood and <ulink url="&url.imap.book;">Managing
IMAP</ulink> by Dianna Mullet & Kevin Mullet.
</para>
</partintro>
<refentry id="function.imap-append">
<refnamediv>
<refname>imap_append</refname>
<refpurpose>
Append a string message to a specified mailbox
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_append</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>mbox</parameter></paramdef>
<paramdef>string <parameter>message</parameter></paramdef>
<paramdef>string
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on sucess, false on error.
</para>
<para>
<function>imap_append</function> appends a string message to the
specified mailbox <parameter>mbox</parameter>. If the optional
<parameter>flags</parameter> is specified, writes the
<parameter>flags</parameter> to that mailbox also.
</para>
<para>
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.
</para>
<para>
<example>
<title><function>imap_append</function> example</title>
<programlisting role="php">
$stream = imap_open("{your.imap.host}INBOX.Drafts","username",
"password");
$check = imap_check($stream);
print "Msg Count before append: ". $check->Nmsgs."\n";
imap_append($stream,"{your.imap.host}INBOX.Drafts"
,"From: me@my.host\r\n"
."To: you@your.host\r\n"
."Subject: test\r\n"
."\r\n"
."this is a test message, please ignore\r\n"
);
$check = imap_check($stream);
print "Msg Count after append : ". $check->Nmsgs."\n";
imap_close($stream);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-base64">
<refnamediv>
<refname>imap_base64</refname>
<refpurpose>Decode BASE64 encoded text</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_base64</function></funcdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>imap_base64</function> function decodes BASE-64 encoded
text (see <ulink url="&url.rfc;rfc2045.html">RFC2045</ulink>,
Section 6.8). The decoded message is returned as a string.
</para>
<para>
See also <function>imap_binary</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-body">
<refnamediv>
<refname>imap_body</refname>
<refpurpose>Read the message body</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_body</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msg_number</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>imap_body</function> returns the body of the message,
numbered <parameter> msg_number</parameter> in the current
mailbox. The optional <parameter>flags</parameter> are a bit mask
with one or more of the following:
<itemizedlist>
<listitem>
<simpara>
FT_UID - The <parameter>msgno</parameter> is a UID
</simpara>
</listitem>
<listitem>
<simpara>
FT_PEEK - Do not set the \Seen flag if not already set
</simpara>
</listitem>
<listitem>
<simpara>
FT_INTERNAL - The return string is in internal format, will
not canonicalize to CRLF.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<function>imap_body</function> will only return a verbatim copy of the
message body. To extract single parts of a multipart MIME-encoded
message you have to use <function>imap_fetch_structure</function> to
analyze its structure and <function>imap_fetch_body</function> to
extract a copy of a single body component.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-check">
<refnamediv>
<refname>imap_check</refname>
<refpurpose>Check current mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>imap_check</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns information about the current mailbox. Returns FALSE on
failure.
</para>
<para>
The <function>imap_check</function> function checks the current
mailbox status on the server and returns the information in an
object with following properties:
</para>
<para>
<itemizedlist>
<listitem>
<simpara>
Date - last change of mailbox contents
</simpara>
</listitem>
<listitem>
<simpara>
Driver - protocol used to access this mailbox: POP3, IMAP, NNTP
</simpara>
</listitem>
<listitem>
<simpara>
Mailbox - the mailbox name
</simpara>
</listitem>
<listitem>
<simpara>
Nmsgs - number of messages in the mailbox
</simpara>
</listitem>
<listitem>
<simpara>
Recent - number of recent messages in the mailbox
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-close">
<refnamediv>
<refname>imap_close</refname>
<refpurpose>Close an IMAP stream</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_close</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Close the imap stream. Takes an optional
<parameter>flag</parameter> CL_EXPUNGE, which will silently
expunge the mailbox before closing, removing all messages marked for
deletion.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-createmailbox">
<refnamediv>
<refname>imap_createmailbox</refname>
<refpurpose>Create a new mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_createmailbox</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>mbox</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>imap_createmailbox</function> creates a new mailbox
specified by <parameter>mbox</parameter>. Names containing
international characters should be encoded by <function>imap_utf7_encode</function>
</para>
<para>
Returns true on success and false on error.
</para>
<para>
See also <function>imap_renamemailbox</function>,
<function>imap_deletemailbox</function> and
<function>imap_open</function> for the format
of <parameter>mbox</parameter> names.
</para>
<para>
<example>
<title><function>imap_createmailbox</function> example</title>
<programlisting>
$mbox =
imap_open("{your.imap.host}","username","password",OP_HALFOPEN)
|| die("can't connect: ".imap_last_error());
$name1 = "phpnewbox";
$name2 = imap_utf7_encode("phpnewböx");
$newname = $name1;
echo "Newname will be '$name1'<br>\n";
# we will now create a new mailbox "phptestbox" in your inbox folder,
# check its status after creation and finaly remove it to restore
# your inbox to its initial state
if(@imap_createmailbox($mbox,imap_utf7_encode("{your.imap.host}INBOX.$newname"))) {
$status = @imap_status($mbox,"{your.imap.host}INBOX.$newname",SA_ALL);
if($status) {
print("your new mailbox '$name1' has the following
status:<br>\n");
print("Messages: ". $status->messages )."<br>\n";
print("Recent: ". $status->recent )."<br>\n";
print("Unseen: ". $status->unseen )."<br>\n";
print("UIDnext: ". $status->uidnext )."<br>\n";
print("UIDvalidity:". $status->uidvalidity)."<br>\n";
if(imap_renamemailbox($mbox,"{your.imap.host}INBOX.$newname","{your.imap.host}INBOX.$name2"))
{
echo "renamed new mailbox from '$name1' to
'$name2'<br>\n";
$newname=$name2;
} else {
print "imap_renamemailbox on new mailbox failed:
".imap_last_error()."<br>\n";
}
} else {
print "imap_status on new mailbox failed:
".imap_last_error()."<br>\n";
}
if(@imap_deletemailbox($mbox,"{your.imap.host}INBOX.$newname")) {
print "new mailbox removed to restore initial state<br>\n";
} else {
print "imap_deletemailbox on new mailbox failed:
".implode("<br>\n",imap_errors())."<br>\n";
}
} else {
print "could not create new mailbox:
".implode("<br>\n",imap_errors())."<br>\n";
}
imap_close($mbox);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-delete">
<refnamediv>
<refname>imap_delete</refname>
<refpurpose>
Mark a messge for deletion from current mailbox
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_delete</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msg_number</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true.
</para>
<para>
<function>imap_delete</function> function marks message pointed
by <parameter>msg_number</parameter> for deletion. The optional
<parameter>flags</parameter> parameter only has a single option,
<parameter>FT_UID</parameter>, which tells the function to treat
the <parameter>msg_number</parameter> argument as a
<parameter>UID</parameter>. Messages marked for deletion will
stay in the mailbox until either
<function>imap_expunge</function> is called or
<function>imap_close</function> is called with the optional
parameter CL_EXPUNGE.
</para>
<para>
<example>
<title><function>Imap_delete</function> Beispiel</title>
<programlisting role="php">
$mbox = imap_open ("{your.imap.host}INBOX", "username", "password")
|| die ("can't connect: " . imap_last_error());
$check = imap_mailboxmsginfo ($mbox);
print "Messages before delete: " . $check->Nmsgs . "<br>\n" ;
imap_delete ($mbox, 1);
$check = imap_mailboxmsginfo ($mbox);
print "Messages after delete: " . $check->Nmsgs . "<br>\n" ;
imap_expunge ($mbox);
$check = imap_mailboxmsginfo ($mbox);
print "Messages after expunge: " . $check->Nmsgs . "<br>\n" ;
imap_close ($mbox);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-deletemailbox">
<refnamediv>
<refname>imap_deletemailbox</refname>
<refpurpose>Delete a mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_deletemailbox</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>mbox</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>imap_deletemailbox</function> deletes the specified
mailbox (see <function>imap_open</function> for the format
of <parameter>mbox</parameter> names).
</para>
<para>
Returns true on success and false on error.
</para>
<para>
See also <function>imap_createmailbox</function>,
<function>imap_renamemailbox</function>, and
<function>imap_open</function> for the format of
<parameter>mbox</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-expunge">
<refnamediv>
<refname>imap_expunge</refname>
<refpurpose>Delete all messages marked for deletion</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_expunge</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>imap_expunge</function> deletes all the messages marked
for deletion by <function>imap_delete</function>,
<function>imap_mail_move</function>, or
<function>imap_setflag_full</function>.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-fetchbody">
<refnamediv>
<refname>imap_fetchbody</refname>
<refpurpose>
Fetch a particular section of the body of the message
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_fetchbody</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msg_number</parameter></paramdef>
<paramdef>string <parameter>part_number</parameter></paramdef>
<paramdef>flags
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
The options for <function>imap_fetchbody</function> is a bitmask
with one or more of the following:
<itemizedlist>
<listitem>
<simpara>
FT_UID - The <parameter>msg_number</parameter> is a UID
</simpara>
</listitem>
<listitem>
<simpara>
FT_PEEK - Do not set the \Seen flag if not already set
</simpara>
</listitem>
<listitem>
<simpara>
FT_INTERNAL - The return string is in "internal" format,
without any attempt to canonicalize CRLF.
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-fetchstructure">
<refnamediv>
<refname>imap_fetchstructure</refname>
<refpurpose>
Read the structure of a particular message
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object
<function>imap_fetchstructure</function>
</funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msg_number</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function fetches all the structured information for a given
message. The optional <parameter>flags</parameter> parameter only
has a single option, <parameter>FT_UID</parameter>, which tells
the function to treat the <parameter>msg_number</parameter>
argument as a <parameter>UID</parameter>. The returned object
includes the envelope, internal date, size, flags and body
structure along with a similar object for each mime
attachement. The structure of the returned objects is as follows:
</para>
<para>
<table>
<title>
Returned Objects for <function>imap_fetchstructure</function>
</title>
<tgroup cols="2">
<tbody>
<row>
<entry>type</entry>
<entry>Primary body type</entry>
</row>
<row>
<entry>encoding</entry>
<entry>Body transfer encoding</entry>
</row>
<row>
<entry>ifsubtype</entry>
<entry>True if there is a subtype string</entry>
</row>
<row>
<entry>subtype</entry>
<entry><acronym>MIME</acronym> subtype</entry>
</row>
<row>
<entry>ifdescription</entry>
<entry>True if there is a description string</entry>
</row>
<row>
<entry>description</entry>
<entry>Content description string</entry>
</row>
<row>
<entry>ifid</entry>
<entry>True if there is an identification string</entry>
</row>
<row>
<entry>id</entry>
<entry>Identification string</entry>
</row>
<row>
<entry>lines</entry>
<entry>Number of lines</entry>
</row>
<row>
<entry>bytes</entry>
<entry>Number of bytes</entry>
</row>
<row>
<entry>ifdisposition</entry>
<entry>True if there is a disposition string</entry>
</row>
<row>
<entry>disposition</entry>
<entry>Disposition string</entry>
</row>
<row>
<entry>ifdparameters</entry>
<entry>True if the dparameters array exists</entry>
</row>
<row>
<entry>dparameters</entry>
<entry>Disposition parameter array</entry>
</row>
<row>
<entry>ifparameters</entry>
<entry>True if the parameters array exists</entry>
</row>
<row>
<entry>parameters</entry>
<entry><acronym>MIME</acronym> parameters array</entry>
</row>
<row>
<entry>parts</entry>
<entry>Array of objects describing each message part</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<note>
<orderedlist>
<listitem>
<para>
dparameters is an array of objects where each object has an
"attribute" and a "value" property.
</para>
</listitem>
<listitem>
<para>
Parameter is an array of objects where each object has an
"attributte" and a "value" property.
</para>
</listitem>
<listitem>
<para>
Parts is an array of objects identical in structure to the
top-level object, with the limitation that it cannot contain
further 'parts' objects.
</para>
</listitem>
</orderedlist>
</note>
<para>
<table>
<title>Primary body type</title>
<tgroup cols="2">
<tbody>
<row><entry>0</entry><entry>text</entry></row>
<row><entry>1</entry><entry>multipart</entry></row>
<row><entry>2</entry><entry>message</entry></row>
<row><entry>3</entry><entry>application</entry></row>
<row><entry>4</entry><entry>audio</entry></row>
<row><entry>5</entry><entry>image</entry></row>
<row><entry>6</entry><entry>video</entry></row>
<row><entry>7</entry><entry>other</entry></row>
</tbody>
</tgroup>
</table>
</para>
<para>
<table>
<title>Transfer encodings</title>
<tgroup cols="2">
<tbody>
<row><entry>0</entry><entry>7BIT</entry></row>
<row><entry>1</entry><entry>8BIT</entry></row>
<row><entry>2</entry><entry>BINARY</entry></row>
<row><entry>3</entry><entry>BASE64</entry></row>
<row><entry>4</entry><entry>QUOTED-PRINTABLE</entry></row>
<row><entry>5</entry><entry>OTHER</entry></row>
</tbody>
</tgroup>
</table>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-headerinfo">
<refnamediv>
<refname>imap_headerinfo</refname>
<refpurpose>Read the header of the message</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>object <function>imap_headerinfo</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msg_number</parameter></paramdef>
<paramdef>int
<parameter><optional>fromlength</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>subjectlength</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>defaulthost</optional></parameter>
</paramdef>
</funcsynopsis>
<para>
This function returns an object of various header elements.
</para>
<para>
<informalexample>
<literallayout>
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 <parameter>fromlength</parameter>
characters)
fetchsubject (subject line formatted to fit <parameter>subjectlength</parameter>
characters)
</literallayout>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-header">
<refnamediv>
<refname>imap_header</refname>
<refpurpose>Read the header of the message</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>object <function>imap_header</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msg_number</parameter></paramdef>
<paramdef>int
<parameter><optional>fromlength</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>subjectlength</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>defaulthost</optional></parameter>
</paramdef>
</funcsynopsis>
<para>
This is an alias to <function>imap_headerinfo</function>
and is identical to this in any way.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-rfc822-parse-headers">
<refnamediv>
<refname>imap_rfc822_parse_headers</refname>
<refpurpose>Parse mail headers from a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object
<function>imap_rfc822_parse_headers</function></funcdef>
<paramdef>string <parameter>headers</parameter></paramdef>
<paramdef>string
<parameter><optional>defaulthost</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an object of various header elements,
similar to <function>imap_header</function>, except without the
flags and other elements that come from the IMAP server.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-headers">
<refnamediv>
<refname>imap_headers</refname>
<refpurpose>
Returns headers for all messages in a mailbox
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_headers</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of string formatted with header info. One
element per mail message.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-listmailbox">
<refnamediv>
<refname>imap_listmailbox</refname>
<refpurpose>Read the list of mailboxes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_listmailbox</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>ref</parameter></paramdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array containing the names of the mailboxes.
See <function>imap_getmailboxes</function> for a description
of <parameter>ref</parameter> and <parameter>pattern</parameter>.
</para>
<para>
<example>
<title><function>imap_listmailbox</function> example</title>
<programlisting role="php">
$mbox =
imap_open("{your.imap.host}","username","password",OP_HALFOPEN)
|| die("can't connect: ".imap_last_error());
$list = imap_listmailbox($mbox,"{your.imap.host}","*");
if(is_array($list)) {
reset($list);
while (list($key, $val) = each($list))
print imap_utf7_decode($val)."<br>\n";
} else
print "imap_listmailbox failed: ".imap_last_error()."\n";
imap_close($mbox);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-getmailboxes">
<refnamediv>
<refname>imap_getmailboxes</refname>
<refpurpose>
Read the list of mailboxes, returning detailed information on
each one
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_getmailboxes</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>ref</parameter></paramdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of objects containing mailbox information. Each
object has the attributes <parameter>name</parameter>, specifying
the full name of the mailbox; <parameter>delimiter</parameter>,
which is the hierarchy delimiter for the part of the hierarchy
this mailbox is in; and
<parameter>attributes</parameter>. <parameter>Attributes</parameter>
is a bitmask that can be tested against:
<itemizedlist>
<listitem>
<simpara>
LATT_NOINFERIORS - This mailbox has no "children" (there are
no mailboxes below this one).
</simpara>
</listitem>
<listitem>
<simpara>
LATT_NOSELECT - This is only a container, not a mailbox - you
cannot open it.
</simpara>
</listitem>
<listitem>
<simpara>
LATT_MARKED - This mailbox is marked. Only used by UW-IMAPD.
</simpara>
</listitem>
<listitem>
<simpara>
LATT_UNMARKED - This mailbox is not marked. Only used by
UW-IMAPD.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
Mailbox names containing international Characters outside the
printable ASCII range will be encoded and may be decoded by
<function>imap_utf7_decode</function>.
</para>
<para>
<parameter>ref</parameter> should normally be just the server
specification as described in <function>imap_open</function>, and
<parameter>pattern</parameter> specifies where in the mailbox
hierarchy to start searching. If you want all mailboxes, pass
'*' for <parameter>pattern</parameter>.
</para>
<para>
There are two special characters you can pass as part of the
<parameter>pattern</parameter>: '*' and '%'. '*'
means to return
all mailboxes. If you pass <parameter>pattern</parameter> as '*',
you will get a list of the entire mailbox hierarchy. '%' means to
return the current level only. '%' as the
<parameter>pattern</parameter> 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.
</para>
<para>
<example>
<title><function>imap_getmailboxes</function> example</title>
<programlisting role="php">
$mbox =
imap_open("{your.imap.host}","username","password",OP_HALFOPEN)
|| die("can't connect: ".imap_last_error());
$list = imap_getmailboxes($mbox,"{your.imap.host}","*");
if(is_array($list)) {
reset($list);
while (list($key, $val) = each($list))
{
print "($key) ";
print imap_utf7_decode($val->name).",";
print "'".$val->delimiter."',";
print $val->attributes."<br>\n";
}
} else
print "imap_getmailboxes failed: ".imap_last_error()."\n";
imap_close($mbox);
</programlisting>
</example>
</para>
<para>
See also <function>imap_getsubscribed</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-listsubscribed">
<refnamediv>
<refname>imap_listsubscribed</refname>
<refpurpose>List all the subscribed mailboxes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_listsubscribed</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>ref</parameter></paramdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of all the mailboxes that you have
subscribed. This is almost identical to
<function>imap_listmailbox</function>, but will only return
mailboxes the user you logged in as has subscribed.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-getsubscribed">
<refnamediv>
<refname>imap_getsubscribed</refname>
<refpurpose>List all the subscribed mailboxes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_getsubscribed</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>ref</parameter></paramdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is identical to
<function>imap_getmailboxes</function>, except that it only
returns mailboxes that the user is subscribed to.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-mail-copy">
<refnamediv>
<refname>imap_mail_copy</refname>
<refpurpose>Copy specified messages to a mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_mail_copy</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>msglist</parameter></paramdef>
<paramdef>string <parameter>mbox</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success and false on error.
</para>
<para>
Copies mail messages specified by <parameter>msglist</parameter>
to specified mailbox. <parameter>msglist</parameter> is a range
not just message numbers (as described in
<ulink url="&url.rfc;rfc2060.html">RFC2060</ulink>).
</para>
<para>
Flags is a bitmask of one or more of
<itemizedlist>
<listitem>
<simpara>
CP_UID - the sequence numbers contain UIDS
</simpara>
</listitem>
<listitem>
<simpara>
CP_MOVE - Delete the messages from the current mailbox after
copying
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-mail-move">
<refnamediv>
<refname>imap_mail_move</refname>
<refpurpose>Move specified messages to a mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_mail_move</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>msglist</parameter></paramdef>
<paramdef>string <parameter>mbox</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Moves mail messages specified by <parameter>msglist</parameter>
to specified mailbox. <parameter>msglist</parameter> is a range
not just message numbers (as described in
<ulink url="&url.rfc;rfc2060.html">RFC2060</ulink>).
</para>
<para>
Flags is a bitmask and may contain the single option
<itemizedlist>
<listitem>
<simpara>
CP_UID - the sequence numbers contain UIDS
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
Returns true on success and false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-num-msg">
<refnamediv>
<refname>imap_num_msg</refname>
<refpurpose>
Gives the number of messages in the current mailbox
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_num_msg</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the number of messages in the current mailbox.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-num-recent">
<refnamediv>
<refname>imap_num_recent</refname>
<refpurpose>Gives the number of recent messages in current
mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_num_recent</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of recent messages in the current mailbox.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-open">
<refnamediv>
<refname>imap_open</refname>
<refpurpose>Open an IMAP stream to a mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_open</function></funcdef>
<paramdef>string <parameter>mailbox</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 not available
on IMAP servers.
</para>
<para>
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, a protocol
secification (beginning with '/') and an optional port specifier
beginnung with ':'. 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 <function>imap_utf7_encode</function>.
</para>
<para>
The options are a bit mask with one or more of the following:
<itemizedlist>
<listitem>
<simpara>
OP_READONLY - Open mailbox read-only
</simpara>
</listitem>
<listitem>
<simpara>
OP_ANONYMOUS - Dont use or update a
<filename>.newsrc</filename> for news (NNTP only)
</simpara>
</listitem>
<listitem>
<simpara>
OP_HALFOPEN - For IMAP and NNTP names, open a connection but
dont open a mailbox
</simpara>
</listitem>
<listitem>
<simpara>
CL_EXPUNGE - Expunge mailbox automatically upon mailbox close
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
To connect to an IMAP server running on port 143 on the
local machine, do the following:
<informalexample>
<programlisting role="php">
$mbox = imap_open ("{localhost:143}INBOX", "user_id", "password");
</programlisting>
</informalexample>
To connect to a POP3 server on port 110 on the local server, use:
<informalexample>
<programlisting role="php">
$mbox = imap_open ("{localhost/pop3:110}INBOX", "user_id",
"password");
</programlisting>
</informalexample>
To connect to an NNTP server on port 119 on the local server, use:
<informalexample>
<programlisting role="php">
$nntp = imap_open ("{localhost/nntp:119}comp.test", "", "");
</programlisting>
</informalexample>
To connect to a remote server replace "localhost" with the name
or the IP address of the server you want to connect to.
</para>
<para>
<example>
<title><function>imap_open</function> example</title>
<programlisting role="php">
$mbox = imap_open ("{your.imap.host:143}", "username", "password");
echo "<p><h1>Mailboxes</h1>\n";
$folders = imap_listmailbox ($mbox, "{your.imap.host:143}", "*");
if ($folders == false) {
echo "Call failed<br>\n";
} else {
while (list ($key, $val) = each ($folders)) {
echo $val."<br>\n";
}
}
echo "<p><h1>Headers in INBOX</h1>\n";
$headers = imap_headers ($mbox);
if ($headers == false) {
echo "Call failed<br>\n";
} else {
while (list ($key,$val) = each ($headers)) {
echo $val."<br>\n";
}
}
imap_close($mbox);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-ping">
<refnamediv>
<refname>imap_ping</refname>
<refpurpose>Check if the IMAP stream is still active</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_ping</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the stream is still alive, false otherwise.
</para>
<para>
<function>imap_ping</function> 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 usefull to anyone.)
</para>
</refsect1>
</refentry>
<refentry id="function.imap-renamemailbox">
<refnamediv>
<refname>imap_renamemailbox</refname>
<refpurpose>Rename an old mailbox to new mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_renamemailbox</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>old_mbox</parameter></paramdef>
<paramdef>string <parameter>new_mbox</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function renames on old mailbox to new mailbox (see
<function>imap_open</function> for the format of
<parameter>mbox</parameter> names).
</para>
<para>
Returns true on success and false on error.
</para>
<para>
See also <function>imap_createmailbox</function>,
<function>imap_deletemailbox</function>, and
<function>imap_open</function> for the format of
<parameter>mbox</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-reopen">
<refnamediv>
<refname>imap_reopen</refname>
<refpurpose>Reopen IMAP stream to new mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_reopen</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>mailbox</parameter></paramdef>
<paramdef>string
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function reopens the specified stream to a new mailbox on
an IMAP or NNTP server.
</para>
<para>
The options are a bit mask with one or more of the following:
<itemizedlist>
<listitem>
<simpara>
OP_READONLY - Open mailbox read-only
</simpara>
</listitem>
<listitem>
<simpara>
OP_ANONYMOUS - Dont use or update a
<filename>.newsrc</filename> for news (NNTP only)
</simpara>
</listitem>
<listitem>
<simpara>
OP_HALFOPEN - For IMAP and NNTP names, open a connection but
dont open a mailbox.
</simpara>
</listitem>
<listitem>
<simpara>
CL_EXPUNGE - Expunge mailbox automatically upon mailbox close
(see also <function>imap_delete</function> and
<function>imap_expunge</function>)
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
Returns true on success and false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-subscribe">
<refnamediv>
<refname>imap_subscribe</refname>
<refpurpose>Subscribe to a mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_subscribe</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>mbox</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Subscribe to a new mailbox.
</para>
<para>
Returns true on success and false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-undelete">
<refnamediv>
<refname>imap_undelete</refname>
<refpurpose>
Unmark the message which is marked deleted
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_undelete</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msg_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function removes the deletion flag for a specified message,
which is set by <function>imap_delete</function> or
<function>imap_mail_move</function>.
</para>
<para>
Returns true on success and false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-unsubscribe">
<refnamediv>
<refname>imap_unsubscribe</refname>
<refpurpose>Unsubscribe from a mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_unsubscribe</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>mbox</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Unsubscribe from a specified mailbox.
</para>
<para>
Returns true on success and false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-qprint">
<refnamediv>
<refname>imap_qprint</refname>
<refpurpose>Convert a quoted-printable string to an 8 bit
string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_qprint</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Convert a quoted-printable string to an 8 bit string (according
to <ulink url="&url.rfc;rfc2045.html">RFC2045</ulink>, section
6.7).
</para>
<para>
Returns an 8 bit (binary) string.
</para>
<para>
See also <function>imap_8bit</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-8bit">
<refnamediv>
<refname>imap_8bit</refname>
<refpurpose>
Convert an 8bit string to a quoted-printable string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_8bit</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Convert an 8bit string to a quoted-printable string (according to
<ulink url="&url.rfc;rfc2045.html">RFC2045</ulink>, section
6.7).
</para>
<para>
Returns a quoted-printable string.
</para>
<para>
See also <function>imap_qprint</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-binary">
<refnamediv>
<refname>imap_binary</refname>
<refpurpose>
Convert an 8bit string to a base64 string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_binary</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Convert an 8bit string to a base64 string (according to <ulink
url="&url.rfc;rfc2045.html">RFC2045</ulink>, Section 6.8).
</para>
<para>
Returns a base64 string.
</para>
<para>
See also <function>imap_base64</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-scanmailbox">
<refnamediv>
<refname>imap_scanmailbox</refname>
<refpurpose>
Read the list of mailboxes, takes a string to search for in the
text of the mailbox
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_scanmailbox</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>ref</parameter></paramdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>content</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array containing the names of the mailboxes that have
<parameter>string</parameter> in the text of the mailbox.
This function is similar to <function>imap_listmailbox</function>,
but it will additionally check for the presence of the string
<parameter>content</parameter> inside the mailbox data.
See <function>imap_getmailboxes</function> for a description
of <parameter>ref</parameter> and <parameter>pattern</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-mailboxmsginfo">
<refnamediv>
<refname>imap_mailboxmsginfo</refname>
<refpurpose>Get information about the current mailbox</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>imap_mailboxmsginfo</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns information about the current mailbox. Returns FALSE on
failure.
</para>
<para>
The <function>imap_mailboxmsginfo</function> function checks the
current mailbox status on the server. It is similar to
<function>imap_status</function>, 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.
</para>
<para>
<table>
<title>Mailbox properties</title>
<tgroup cols="2">
<tbody>
<row>
<entry>Date</entry>
<entry>date of last change</entry>
</row>
<row>
<entry>Driver</entry>
<entry>driver</entry>
</row>
<row>
<entry>Mailbox</entry>
<entry>name of the mailbox</entry>
</row>
<row>
<entry>Nmsgs</entry>
<entry>number of messages</entry>
</row>
<row>
<entry>Recent</entry>
<entry>number of recent messages</entry>
</row>
<row>
<entry>Unread</entry>
<entry>number of unread messages</entry>
</row>
<row>
<entry>Deleted</entry>
<entry>number of deleted messages</entry>
</row>
<row>
<entry>Size</entry>
<entry>mailbox size</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<example>
<title><function>imap_mailboxmsginfo</function> example</title>
<programlisting role="php">
<?php
$mbox = imap_open("{your.imap.host}INBOX","username", "password")
|| die("can't connect: ".imap_last_error());
$check = imap_mailboxmsginfo($mbox);
if($check) {
print "Date: " . $check->Date ."<br>\n" ;
print "Driver: " . $check->Driver ."<br>\n" ;
print "Mailbox: " . $check->Mailbox ."<br>\n" ;
print "Messages: ". $check->Nmsgs ."<br>\n" ;
print "Recent: " . $check->Recent ."<br>\n" ;
print "Unread: " . $check->Unread ."<br>\n" ;
print "Deleted: " . $check->Deleted ."<br>\n" ;
print "Size: " . $check->Size ."<br>\n" ;
} else {
print "imap_check() failed: ".imap_lasterror(). "<br>\n";
}
imap_close($mbox);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-rfc822-write-address">
<refnamediv>
<refname>imap_rfc822_write_address</refname>
<refpurpose>
Returns a properly formatted email address given the mailbox,
host, and personal info.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>imap_rfc822_write_address</function>
</funcdef>
<paramdef>string <parameter>mailbox</parameter></paramdef>
<paramdef>string <parameter>host</parameter></paramdef>
<paramdef>string <parameter>personal</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a properly formatted email address as defined in
<ulink url="&url.rfc;rfc822.html">RFC822</ulink>
given the mailbox, host, and personal info.
</para>
<para>
<example>
<title><function>imap_rfc822_write_address</function> example</title>
<programlisting role="php">
print imap_rfc822_write_address("hartmut","cvs.php.net","Hartmut
Holzgraefe")."\n";
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-rfc822-parse-adrlist">
<refnamediv>
<refname>imap_rfc822_parse_adrlist</refname>
<refpurpose>Parses an address string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array
<function>imap_rfc822_parse_adrlist</function>
</funcdef>
<paramdef>string <parameter>address</parameter></paramdef>
<paramdef>string <parameter>default_host</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function parses the address string as defined in
<ulink url="&url.rfc;rfc822.html">RFC822</ulink> and
for each address, returns an array of objects.
The objects properties are:
</para>
<para>
<itemizedlist>
<listitem>
<simpara>
mailbox - the mailbox name (username)
</simpara>
</listitem>
<listitem>
<simpara>
host - the host name
</simpara>
</listitem>
<listitem>
<simpara>
personal - the personal name
</simpara>
</listitem>
<listitem>
<simpara>
adl - at domain source route
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title><function>imap_rfc822_parse_adrlist</function> example</title>
<programlisting role="php">
$address_string = "Hartmut Holzgraefe <hartmut@cvs.php.net>,
postmaster@somedomain.net, root";
$address_array = imap_rfc822_parse_adrlist($address_string,"somedomain.net");
if(! is_array($address_array)) die("somethings wrong\n");
reset($address_array);
while(list($key,$val)=each($address_array)){
print "mailbox : ".$val->mailbox."<br>\n";
print "host : ".$val->host."<br>\n";
print "personal: ".$val->personal."<br>\n";
print "adl : ".$val->adl."<p>\n";
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-setflag-full">
<refnamediv>
<refname>imap_setflag_full</refname>
<refpurpose>Sets flags on messages</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_setflag_full</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>string <parameter>sequence</parameter></paramdef>
<paramdef>string <parameter>flag</parameter></paramdef>
<paramdef>string <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function causes a store to add the specified flag to the
flags set for the messages in the specified sequence.
</para>
<para>
The flags which you can set are "\\Seen", "\\Answered",
"\\Flagged", "\\Deleted", "\\Draft", and "\\Recent" (as
defined
by RFC2060).
</para>
<para>
The options are a bit mask with one or more of the following:
<informalexample>
<literallayout>
ST_UID The sequence argument contains UIDs instead of
sequence numbers
</literallayout>
</informalexample>
</para>
<para>
<example>
<title><function>imap_setflag_full</function> example</title>
<programlisting role="php">
$mbox = imap_open("{your.imap.host:143}","username","password")
|| die("can't connect: ".imap_last_error());
$status = imap_setflag_full($mbox,"2,5","\\Seen \\Flagged");
print gettype($status)."\n";
print $status."\n";
imap_close($mbox);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-clearflag-full">
<refnamediv>
<refname>imap_clearflag_full</refname>
<refpurpose>Clears flags on messages</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>imap_clearflag_full</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>string <parameter>sequence</parameter></paramdef>
<paramdef>string <parameter>flag</parameter></paramdef>
<paramdef>string <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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", "\\Draft", and "\\Recent" (as
defined
by RFC2060).
</para>
<para>
The options are a bit mask with one or more of the following:
<informalexample>
<literallayout>
ST_UID The sequence argument contains UIDs instead of
sequence numbers
</literallayout>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-sort">
<refnamediv>
<refname>imap_sort</refname>
<refpurpose>Sort an array of message headers</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_sort</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>criteria</parameter></paramdef>
<paramdef>int <parameter>reverse</parameter></paramdef>
<paramdef>int <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of message numbers sorted by the given
parameters.
</para>
<para>
<parameter>Reverse</parameter> is 1 for reverse-sorting.
</para>
<para>
Criteria can be one (and only one) of the following:
<informalexample>
<literallayout>
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
</literallayout>
</informalexample>
</para>
<para>
The flags are a bitmask of one or more of the following:
<informalexample>
<literallayout>
SE_UID Return UIDs instead of sequence numbers
SE_NOPREFETCH Don't prefetch searched messages.
</literallayout>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-fetchheader">
<refnamediv>
<refname>imap_fetchheader</refname>
<refpurpose>Returns header for a message</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_fetchheader</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msgno</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function causes a fetch of the complete, unfiltered
<ulink url="&url.rfc;rfc822.html">RFC822</ulink>
format header of the specified message as a text string and
returns that text string.
</para>
<para>
The options are:
<informalexample>
<literallayout>
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)
</literallayout>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-uid">
<refnamediv>
<refname>imap_uid</refname>
<refpurpose>
This function returns the UID for the given message sequence
number
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_uid</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>msgno</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This 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
<function>imap_msgno</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-msgno">
<refnamediv>
<refname>imap_msgno</refname>
<refpurpose>
This function returns the message sequence number for the given
UID
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>imap_msgno</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>int <parameter>uid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the message sequence number for the given
UID. It is the inverse of <function>imap_uid</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-search">
<refnamediv>
<refname>imap_search</refname>
<refpurpose>
This function returns an array of messages matching the given
search criteria
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_search</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>criteria</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function performs a search on the mailbox currently opened
in the given imap stream. <parameter>criteria</parameter> is a
string, delimited by spaces, in which the following keywords are
allowed. Any multi-word arguments (eg. FROM "joey smith") must be
quoted.
<itemizedlist>
<listitem>
<simpara>
ALL - return all messages matching the rest of the criteria
</simpara>
</listitem>
<listitem>
<simpara>
ANSWERED - match messages with the \\ANSWERED flag set
</simpara>
</listitem>
<listitem>
<simpara>
BCC "string" - match messages with "string" in the Bcc: field
</simpara>
</listitem>
<listitem>
<simpara>
BEFORE "date" - match messages with Date: before "date"
</simpara>
</listitem>
<listitem>
<simpara>
BODY "string" - match messages with "string" in the body of the message
</simpara>
</listitem>
<listitem>
<simpara>
CC "string" - match messages with "string" in the Cc: field
</simpara>
</listitem>
<listitem>
<simpara>
DELETED - match deleted messages
</simpara>
</listitem>
<listitem>
<simpara>
FLAGGED - match messages with the \\FLAGGED (sometimes
referred to as Important or Urgent) flag set
</simpara>
</listitem>
<listitem>
<simpara>
FROM "string" - match messages with "string" in the From: field
</simpara>
</listitem>
<listitem>
<simpara>
KEYWORD "string" - match messages with "string" as a keyword
</simpara>
</listitem>
<listitem>
<simpara>
NEW - match new messages
</simpara>
</listitem>
<listitem>
<simpara>
OLD - match old messages
</simpara>
</listitem>
<listitem>
<simpara>
ON "date" - match messages with Date: matching "date"
</simpara>
</listitem>
<listitem>
<simpara>
RECENT - match messages with the \\RECENT flag set
</simpara>
</listitem>
<listitem>
<simpara>
SEEN - match messages that have been read (the \\SEEN flag is set)
</simpara>
</listitem>
<listitem>
<simpara>
SINCE "date" - match messages with Date: after "date"
</simpara>
</listitem>
<listitem>
<simpara>
SUBJECT "string" - match messages with "string" in the Subject:
</simpara>
</listitem>
<listitem>
<simpara>
TEXT "string" - match messages with text "string"
</simpara>
</listitem>
<listitem>
<simpara>
TO "string" - match messages with "string" in the To:
</simpara>
</listitem>
<listitem>
<simpara>
UNANSWERED - match messages that have not been answered
</simpara>
</listitem>
<listitem>
<simpara>
UNDELETED - match messages that are not deleted
</simpara>
</listitem>
<listitem>
<simpara>
UNFLAGGED - match messages that are not flagged
</simpara>
</listitem>
<listitem>
<simpara>
UNKEYWORD "string" - match messages that do not have the
keyword "string"
</simpara>
</listitem>
<listitem>
<simpara>
UNSEEN - match messages which have not been read yet
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
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 uncomplete or
inaccurate (see also RFC2060, section 6.4.4).
</para>
<para>
Valid values for flags are SE_UID, which causes the returned
array to contain UIDs instead of messages sequence numbers.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-last-error">
<refnamediv>
<refname>imap_last_error</refname>
<refpurpose>
This function returns the last IMAP error (if any) that occurred
during this page request
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_last_error</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the full text of the last IMAP error
message that occurred on the current page. The error stack is
untouched; calling <function>imap_last_error</function>
subsequently, with no intervening errors, will return the same
error.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-errors">
<refnamediv>
<refname>imap_errors</refname>
<refpurpose>
This function returns all of the IMAP errors (if any) that have
occurred during this page request or since the error stack was
reset.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_errors</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an array of all of the IMAP error messages
generated since the last <function>imap_errors</function> call,
or the beginning of the page. When
<function>imap_errors</function> is called, the error stack is
subsequently cleared.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-alerts">
<refnamediv>
<refname>imap_alerts</refname>
<refpurpose>
This function returns all IMAP alert messages (if any) that have
occurred during this page request or since the alert stack was
reset
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_alerts</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an array of all of the IMAP alert messages
generated since the last <function>imap_alerts</function> call,
or the beginning of the page. When
<function>imap_alerts</function> is called, the alert stack is
subsequently cleared. The IMAP specification requires that these
messages be passed to the user.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-status">
<refnamediv>
<refname>imap_status</refname>
<refpurpose>
This function returns status information on a mailbox other than
the current one
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>imap_status</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>mailbox</parameter></paramdef>
<paramdef>int <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an object containing status
information. Valid flags are:
<itemizedlist>
<listitem>
<simpara>
SA_MESSAGES - set status->messages to the number of messages
in the mailbox
</simpara>
</listitem>
<listitem>
<simpara>
SA_RECENT - set status->recent to the number of recent
messages in the mailbox
</simpara>
</listitem>
<listitem>
<simpara>
SA_UNSEEN - set status->unseen to the number of unseen (new)
messages in the mailbox
</simpara>
</listitem>
<listitem>
<simpara>
SA_UIDNEXT - set status->uidnext to the next uid to be used in
the mailbox
</simpara>
</listitem>
<listitem>
<simpara>
SA_UIDVALIDITY - set status->uidvalidity to a constant that
changes when uids for the mailbox may no longer be valid
</simpara>
</listitem>
<listitem>
<simpara>
SA_ALL - set all of the above
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
status->flags is also set, which contains a bitmask which can be
checked against any of the above constants.
</para>
<para>
<example>
<title><function>imap_status</function> example</title>
<programlisting role="php">
$mbox =
imap_open("{your.imap.host}","username","password",OP_HALFOPEN)
|| die("can't connect: ".imap_last_error());
$status = imap_status($mbox,"{your.imap.host}INBOX",SA_ALL);
if($status) {
print("Messages: ". $status->messages )."<br>\n";
print("Recent: ". $status->recent )."<br>\n";
print("Unseen: ". $status->unseen )."<br>\n";
print("UIDnext: ". $status->uidnext )."<br>\n";
print("UIDvalidity:". $status->uidvalidity)."<br>\n";
} else
print "imap_status failed: ".imap_lasterror()."\n";
imap_close($mbox);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-utf7-decode">
<refnamediv>
<refname>imap_utf7_decode</refname>
<refpurpose>
Decodes a modified UTF-7 encoded string.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_utf7_decode</function></funcdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Decodes modified UTF-7 <parameter>text</parameter> into 8bit data.
</para>
<para>
Returns the decoded 8bit data, or false if the input string was
not valid modified UTF-7. This function is needed to decode
mailbox names that contain international characters outside of
the printable ASCII range. The modified UTF-7 encoding is defined
in <ulink url="&url.rfc;rfc2060.html">RFC 2060</ulink>, section
5.1.3 (original UTF-7 was defned in <ulink
url="&url.rfc;rfc1642.html">RFC1642</ulink>).
</para>
</refsect1>
</refentry>
<refentry id="function.imap-utf7-encode">
<refnamediv>
<refname>imap_utf7_encode</refname>
<refpurpose>
Converts 8bit data to modified UTF-7 text.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_utf7_encode</function></funcdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts 8bit <parameter>data</parameter> to modified UTF-7
text. This is needed to encode mailbox names that contain
international characters outside of the printable ASCII
range. The modified UTF-7 encoding is defined in <ulink
url="&url.rfc;rfc2060.html">RFC 2060</ulink>, section 5.1.3
(original UTF-7 was defned in <ulink
url="&url.rfc;rfc1642.html">RFC1642</ulink>).
</para>
<para>
Returns the modified UTF-7 text.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-utf8">
<refnamediv>
<refname>imap_utf8</refname>
<refpurpose>
Converts text to UTF8
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_utf8</function></funcdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Converts the given <parameter>text</parameter> to
UTF8 (as defined in
<ulink url="&url.rfc;rfc2044.html">RFC2044</ulink>).
</para>
</refsect1>
</refentry>
<refentry id="function.imap-fetch-overview">
<refnamediv>
<refname>imap_fetch_overview</refname>
<refpurpose>
Read an overview of the information in the headers of the given message
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_fetch_overview</function></funcdef>
<paramdef>int <parameter>imap_stream</parameter></paramdef>
<paramdef>string <parameter>sequence</parameter></paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function fetches mail headers for the given
<parameter>sequence</parameter> and returns an overview of their
contents. <parameter>sequence</parameter> will contain a sequence
of message indices or UIDs, if <parameter>flags</parameter>
contains FT_UID. The returned value is an array of objects
describing one message header each:
<itemizedlist>
<listitem>
<simpara>
subject - the messages subject
</simpara>
</listitem>
<listitem>
<simpara>
from - who sent it
</simpara>
</listitem>
<listitem>
<simpara>
date - when was it sent
</simpara>
</listitem>
<listitem>
<simpara>
message_id - Message-ID
</simpara>
</listitem>
<listitem>
<simpara>
references - is a reference to this message id
</simpara>
</listitem>
<listitem>
<simpara>
size - size in bytes
</simpara>
</listitem>
<listitem>
<simpara>
uid - UID the message has in the mailbox
</simpara>
</listitem>
<listitem>
<simpara>
msgno - message sequence number in the maibox
</simpara>
</listitem>
<listitem>
<simpara>
recent - this message is flagged as recent
</simpara>
</listitem>
<listitem>
<simpara>
flagged - this message is flagged
</simpara>
</listitem>
<listitem>
<simpara>
answered - this message is flagged as answered
</simpara>
</listitem>
<listitem>
<simpara>
deleted - this message is flagged for deletion
</simpara>
</listitem>
<listitem>
<simpara>
seen - this message is flagged as already read
</simpara>
</listitem>
<listitem>
<simpara>
draft - this message is flagged as being a draft
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title><function>imap_fetch_overview</function> example</title>
<programlisting role="php">
$mbox = imap_open("{your.imap.host:143}","username","password")
|| die("can't connect: ".imap_last_error());
$overview = imap_fetch_overview($mbox,"2,4:6",0);
if(is_array($overview)) {
reset($overview);
while( list($key,$val) = each($overview)) {
print $val->msgno
. " - " . $val->date
. " - " . $val->subject
. "\n";
}
}
imap_close($mbox);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-mime-header-decode">
<refnamediv>
<refname>imap_mime_header_decode</refname>
<refpurpose>Decode MIME header elements</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>imap_header_decode</function></funcdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>imap_mime_header_decode</function> function decodes
MIME message header extensions that are non ASCII text
(see <ulink url="&url.rfc;rfc2047.html">RFC2047</ulink>)
The decoded elements are returned in an array of objects,
where each object has two properties, "charset" & "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".
</para>
<para>
<example>
<title><function>imap_mime_header_decode</function> example</title>
<programlisting role="php">
$text="=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>";
$elements=imap_mime_header_decode($text);
for($i=0;$i<count($elements);$i++) {
echo "Charset: {$elements[$i]->charset}\n";
echo "Text: {$elements[$i]->text}\n\n";
}
</programlisting>
</example>
</para>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.imap-mail-compose">
<refnamediv>
<refname>imap_mail_compose</refname>
<refpurpose>
Create a MIME message based on given envelope and body sections
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_mail_compose</function></funcdef>
<paramdef>array <parameter>envelope</parameter></paramdef>
<paramdef>array <parameter>body</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
</para>
<para>
<example>
<title><function>imap_mail_compose</function> example</title>
<programlisting role="php">
<?php
$envelope["from"]="musone@afterfive.com";
$envelope["to"]="musone@darkstar";
$envelope["cc"]="musone@edgeglobal.com";
$part1["type"]=TYPEMULTIPART;
$part1["subtype"]="mixed";
$filename="/tmp/imap.c.gz";
$fp=fopen($filename,"r");
$contents=fread($fp,filesize($filename));
fclose($fp);
$part2["type"]=TYPEAPPLICATION;
$part2["encoding"]=ENCBINARY;
$part2["subtype"]="octet-stream";
$part2["description"]=basename($filename);
$part2["contents.data"]=$contents;
$part3["type"]=TYPETEXT;
$part3["subtype"]="plain";
$part3["description"]="description3";
$part3["contents.data"]="contents.data3\n\n\n\t";
$body[1]=$part1;
$body[2]=$part2;
$body[3]=$part3;
echo nl2br(imap_mail_compose($envelope,$body));
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.imap-mail">
<refnamediv>
<refname>imap_mail</refname>
<refpurpose>
Send an email message
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>imap_mail</function></funcdef>
<paramdef>string <parameter>to</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>string <parameter>message</parameter></paramdef>
<paramdef>string
<parameter><optional>additional_headers</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>cc</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>bcc</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>rpath</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is currently only available in PHP 3.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/info.xml
+++ phpdoc/nl/functions/info.xml
<reference id="ref.info">
<title>PHP options & information</title>
<titleabbrev>PHP options/info</titleabbrev>
<refentry id="function.assert">
<refnamediv>
<refname>assert</refname>
<refpurpose>Checks if assertion is false</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>assert</function></funcdef>
<paramdef>string|bool <parameter>assertion</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>assert</function> will check the given
<parameter>assertion</parameter> and take appropriate
action if its result is <literal>false</literal>.
</para>
<para>
If the <parameter>assertion</parameter> is given as a string it
will be evaluated as PHP code by <function>assert</function>.
The advantages of a string <parameter>assertion</parameter>
are less overhead when assertion checking is off and messages
containing the <parameter>assertion</parameter> expression when
an assertion failes.
</para>
<para>
Assertion 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.
</para>
<para>
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 correct if assertion checking
is not activated.
</para>
<para>
The behavior of <function>assert</function> may be configured
by <function>assert_options</function> or by .ini-settings
described in that functions manual page.
</para>
</refsect1>
</refentry>
<refentry id="function.assert-options">
<refnamediv>
<refname>assert_options</refname>
<refpurpose>Set/get the various assert flags</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>assert_options</function></funcdef>
<paramdef>int <parameter>what</parameter></paramdef>
<paramdef>mixed
<parameter><optional>value</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Using <function>assert_options</function> you may set the various
<function>assert</function> control options or just query their
current settings.
</para>
<table>
<title>assert options</title>
<tgroup cols="4">
<thead>
<row>
<entry>option</entry>
<entry>ini-parameter</entry>
<entry>default</entry>
<entry>description</entry>
</row>
</thead>
<tbody>
<row>
<entry>ASSERT_ACTIVE</entry>
<entry>assert.active</entry>
<entry>1</entry>
<entry>enable <function>assert</function> evaluation</entry>
</row>
<row>
<entry>ASSERT_WARNING</entry>
<entry>assert.warning</entry>
<entry>1</entry>
<entry>issue a PHP warning for each failed assertion</entry>
</row>
<row>
<entry>ASSERT_BAIL</entry>
<entry>assert.bail</entry>
<entry>0</entry>
<entry>terminate execution on failed assertions</entry>
</row>
<row>
<entry>ASSERT_QUIET_EVAL</entry>
<entry>assert.quiet_eval</entry>
<entry>0</entry>
<entry>
disable error_reporting during assertion expression
evaluation
</entry>
</row>
<row>
<entry>ASSERT_CALLBACK</entry>
<entry>assert_callback</entry>
<entry>(null)</entry>
<entry>user function to call on failed assertions</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<function>assert_options</function> will return the original
setting of any option or <literal>false</literal> on errors.
</para>
</refsect1>
</refentry>
<refentry id="function.extension-loaded">
<refnamediv>
<refname>extension_loaded</refname>
<refpurpose>find out whether an extension is loaded</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>extension_loaded</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns true if the extension identified by
<parameter>name</parameter> is loaded. You can see the names of
various extensions by using <function>phpinfo</function>.
</simpara>
<para>
See also <function>phpinfo</function>.
<note>
<para>
This function was added in 3.0.10.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.dl">
<refnamediv>
<refname>dl</refname>
<refpurpose>load a PHP extension at runtime</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>dl</function></funcdef>
<paramdef>string <parameter>library</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Loads the PHP extension defined in
<parameter>library</parameter>. See also the <link
linkend="ini.extension-dir">extension_dir</link> configuration
directive.
</para>
</refsect1>
</refentry>
<refentry id="function.getenv">
<refnamediv>
<refname>getenv</refname>
<refpurpose>Get the value of an environment variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>getenv</function></funcdef>
<paramdef>string <parameter>varname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the value of the environment variable
<parameter>varname</parameter>, or false on an error.
<informalexample>
<programlisting>
$ip = getenv ("REMOTE_ADDR"); // get the ip number of the user
</programlisting>
</informalexample>
</para>
<para>
You can see a list of all the environmental variables by using
<function>phpinfo</function>. You can find out what many of them
mean by taking a look at the <ulink url="&url.cgispecs;">CGI
specification</ulink>, specifically the <ulink
url="&url.cgispec;">page on
environmental variables</ulink>.
<note>
<para>
This function does not work in ISAPI mode.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.get-cfg-var">
<refnamediv>
<refname>get_cfg_var</refname>
<refpurpose>
Get the value of a PHP configuration option.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>get_cfg_var</function></funcdef>
<paramdef>string <parameter>varname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the current value of the PHP configuration variable
specified by <parameter>varname</parameter>, or false if an error
occurs.
</simpara>
<simpara>
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).
</simpara>
<simpara>
To check whether the system is using a <link
linkend="configuration.file">configuration file</link>, try
retrieving the value of the cfg_file_path configuration
setting. If this is available, a configuration file is being
used.
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-current-user">
<refnamediv>
<refname>get_current_user</refname>
<refpurpose>
Get the name of the owner of the current PHP script.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>get_current_user</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the name of the owner of the current PHP script.
</simpara>
<simpara>
See also <function>getmyuid</function>,
<function>getmypid</function>, <function>getmyinode</function>,
and <function>getlastmod</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-magic-quotes-gpc">
<refnamediv>
<refname>get_magic_quotes_gpc</refname>
<refpurpose>
Get the current active configuration setting of magic quotes gpc.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>long <function>get_magic_quotes_gpc</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the current active configuration setting of
<link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link>.
(0 for off, 1 for on).
</simpara>
<simpara>
See also <function>get_magic_quotes_runtime</function>,
<function>set_magic_quotes_runtime</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-magic-quotes-runtime">
<refnamediv>
<refname>get_magic_quotes_runtime</refname>
<refpurpose>
Get the current active configuration setting of
magic_quotes_runtime.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>long
<function>get_magic_quotes_runtime</function>
</funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the current active configuration setting of
<link linkend="ini.magic-quotes-runtime">magic_quotes_runtime</link>.
(0 for off, 1 for on).
</simpara>
<simpara>
See also <function>get_magic_quotes_gpc</function>,
<function>set_magic_quotes_runtime</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.getlastmod">
<refnamediv>
<refname>getlastmod</refname>
<refpurpose>Get time of last page modification.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getlastmod</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the time of the last modification of the current
page. The value returned is a Unix timestamp, suitable for
feeding to <function>date</function>. Returns false on error.
<example>
<title>getlastmod() example</title>
<programlisting role="php">
// outputs e.g. 'Last modified: March 04 1998 20:43:59.'
echo "Last modified: ".date ("F d Y H:i:s.", getlastmod());
</programlisting>
</example>
</para>
<para>
See alse <function>date</function>,
<function>getmyuid</function>,
<function>get_current_user</function>,
<function>getmyinode</function>, and
<function>getmypid</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getmyinode">
<refnamediv>
<refname>getmyinode</refname>
<refpurpose>Get the inode of the current script.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getmyinode</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the current script's inode, or false on error.
</para>
<para>
See also <function>getmyuid</function>,
<function>get_current_user</function>,
<function>getmypid</function>, and
<function>getlastmod</function>.
</para>
<note>
<simpara>
This function is not supported on Windows systems.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.getmypid">
<refnamediv>
<refname>getmypid</refname>
<refpurpose>Get PHP's process ID.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getmypid</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the current PHP process ID, or false on error.
</para>
<para>
Note that when running as a server module, separate invocations
of the script are not guaranteed to have distinct pids.
</para>
<para>
See also <function>getmyuid</function>,
<function>get_current_user</function>,
<function>getmyinode</function>, and
<function>getlastmod</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getmyuid">
<refnamediv>
<refname>getmyuid</refname>
<refpurpose>Get PHP script owner's UID.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getmyuid</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the user ID of the current script, or false on error.
</simpara>
<simpara>
See also <function>getmypid</function>,
<function>get_current_user</function>,
<function>getmyinode</function>, and
<function>getlastmod</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.getrusage">
<refnamediv>
<refname>getrusage</refname>
<refpurpose>Get the current resource usages.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>getrusage</function></funcdef>
<paramdef>int
<parameter><optional>who</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
All entries are accessible by using their documented field names.
<example>
<title>Getrusage Example</title>
<programlisting role="php">
$dat = getrusage();
echo $dat["ru_nswap"]; # number of swaps
echo $dat["ru_majflt"]; # number of page faults
echo $dat["ru_utime.tv_sec"]; # user time used (seconds)
echo $dat["ru_utime.tv_usec"]; # user time used (microseconds)
</programlisting>
</example>
See your system's man page for more details.
</para>
</refsect1>
</refentry>
<refentry id="function.ini-alter">
<refnamediv>
<refname>ini_alter</refname>
<refpurpose>Change the value of a configuration option</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ini_alter</function></funcdef>
<paramdef>string <parameter>varname</parameter></paramdef>
<paramdef>string <parameter>newvalue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Changes the value of a configuration option, returns
<literal>false</literal> on failure, and the previous value of the
configuration option on success.
</para>
<note>
<para>
This is an alias of <function>ini_set</function>
</para>
</note>
<para>
See also <function>ini_get</function>,
<function>ini_restore</function>,
<function>ini_set</function>
</para>
</refsect1>
</refentry>
<refentry id="function.ini-get">
<refnamediv>
<refname>ini_get</refname>
<refpurpose>Get the value of a configuration option</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ini_get</function></funcdef>
<paramdef>string <parameter>varname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the value of the configuration option on success,
<literal>false</literal> on failure.
</para>
<para>
See also <function>ini_alter</function>,
<function>ini_restore</function>,
<function>ini_set</function>
</para>
</refsect1>
</refentry>
<refentry id="function.ini-restore">
<refnamediv>
<refname>ini_restore</refname>
<refpurpose>Restore the value of a configuration option</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ini_restore</function></funcdef>
<paramdef>string <parameter>varname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Restores a given configuration option to its original value.
</para>
<para>
See also <function>ini_alter</function>,
<function>ini_get</function>,
<function>ini_set</function>
</para>
</refsect1>
</refentry>
<refentry id="function.ini-set">
<refnamediv>
<refname>ini_set</refname>
<refpurpose>Set the value of a configuration option</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ini_set</function></funcdef>
<paramdef>string <parameter>varname</parameter></paramdef>
<paramdef>string <parameter>newvalue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the value of the given configuration option. Returns the old
value on success, <literal>false</literal> on failure.
</para>
<para>
See also <function>ini_alter</function>,
<function>ini_get</function>,
<function>ini_restore</function>
</para>
</refsect1>
</refentry>
<refentry id="function.phpcredits">
<refnamediv>
<refname>phpcredits</refname>
<refpurpose>Prints out the credits for PHP.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>phpcredits</function></funcdef>
<paramdef>int <parameter>flag</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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. A parameter indicating what will be
printed (a pre-defined constant flag, see table below) needs
to be passed. For example to print the general credits, you will
use somewhere in your code:
<informalexample>
<programlisting role="php">
..
phpcredits(CREDITS_GENERAL);
..
</programlisting>
</informalexample>
And if you want to print the core developers and the documentation
group, in a page of its own, you will use:
<informalexample>
<programlisting role="php">
<?php
phpcredits(CREDITS_GROUP + CREDITS_DOCS + CREDITS_FULLPAGE);
?>
</programlisting>
</informalexample>
And if you feel like embedding all the credits in your page, then
code like the one below will do it:
<informalexample>
<programlisting role="php">
<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>
</programlisting>
</informalexample>
</para>
<para>
</para>
<para>
<table>
<title>Pre-defined <function>phpcredits</function> flags</title>
<tgroup cols="2">
<thead>
<row>
<entry>name</entry>
<entry>description</entry>
</row>
</thead>
<tbody>
<row>
<entry>CREDITS_ALL</entry>
<entry>
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.
</entry>
</row>
<row>
<entry>CREDITS_DOCS</entry>
<entry>The credits for the documentation team</entry>
</row>
<row>
<entry>CREDITS_FULLPAGE</entry>
<entry>
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.
</entry>
</row>
<row>
<entry>CREDITS_GENERAL</entry>
<entry>
General credits: Language design and concept, PHP 4.0 authors
and SAPI module.
</entry>
</row>
<row>
<entry>CREDITS_GROUP</entry>
<entry>A list of the core developers</entry>
</row>
<row>
<entry>CREDITS_MODULES</entry>
<entry>A list of the extension modules for PHP, and their authors</entry>
</row>
<row>
<entry>CREDITS_SAPI</entry>
<entry>This flag is defined but, as of PHP 4.0.1pl2, it is not used</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
See also <function>phpinfo</function>,
<function>phpversion</function>,
<function>php_logo_guid</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.phpinfo">
<refnamediv>
<refname>phpinfo</refname>
<refpurpose>Output lots of PHP information.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>phpinfo</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 GNU Public License.
</para>
<para>
See also <function>phpversion</function>,
<function>phpcredits</function>,
<function>php_logo_guid</function>
</para>
</refsect1>
</refentry>
<refentry id="function.phpversion">
<refnamediv>
<refname>phpversion</refname>
<refpurpose>Get the current PHP version.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>phpversion</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing the version of the currently running
PHP parser.
<example>
<title>phpversion() example</title>
<programlisting role="php">
// prints e.g. 'Current PHP version: 3.0rel-dev'
echo "Current PHP version: ".phpversion();
</programlisting>
</example>
</para>
<para>
See also <function>phpinfo</function>,
<function>phpcredits</function>,
<function>php_logo_guid</function>
</para>
</refsect1>
</refentry>
<refentry id="function.php-logo-guid">
<refnamediv>
<refname>php_logo_guid</refname>
<refpurpose>Get the logo guid</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>php_logo_guid</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<note>
<para>
This funcionality was added in PHP 4 Beta 4.
</para>
</note>
</para>
<para>
See also <function>phpinfo</function>.
<function>phpversion</function>,
<function>phpcredits</function>
</para>
</refsect1>
</refentry>
<refentry id="function.php-sapi-name">
<refnamediv>
<refname>php_sapi_name</refname>
<refpurpose>
Returns the type of interface between web server and PHP
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>php_sapi_name</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Php_sapi_name</function> 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.
</simpara>
<para>
<example>
<title><function>Php_sapi_name</function> Example</title>
<programlisting role="php">
$inter_type = php_sapi_name();
if ($inter_type == "cgi")
print "You are using CGI PHP\n";
else
print "You are not using CGI PHP\n";
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.php-uname">
<refnamediv>
<refname>php_uname</refname>
<refpurpose>
Returns information about the operating system PHP was built on
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>php_uname</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<simpara>
<function>php_uname</function> returns a string with a description
of the operating system PHP is built on.
</simpara>
<para>
<example>
<title><function>php_uname</function> Example</title>
<programlisting role="php">
if (substr(php_uname(), 0, 7) == "Windows") {
die("Sorry, this script doesn't run on Windows.\n");
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.putenv">
<refnamediv>
<refname>putenv</refname>
<refpurpose>Set the value of an environment variable.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>putenv</function></funcdef>
<paramdef>string <parameter>setting</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Adds <parameter>setting</parameter> to the server environment.
</para>
<para>
<example>
<title>Setting an Environment Variable</title>
<programlisting role="php">
putenv ("UNIQID=$uniqid");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.set-magic-quotes-runtime">
<refnamediv>
<refname>set_magic_quotes_runtime</refname>
<refpurpose>
Set the current active configuration setting of
magic_quotes_runtime.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>long
<function>set_magic_quotes_runtime</function>
</funcdef>
<paramdef>int <parameter>new_setting</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Set the current active configuration setting of <link
linkend="ini.magic-quotes-runtime">magic_quotes_runtime</link>.
(0 for off, 1 for on)
</simpara>
<simpara>
See also <function>get_magic_quotes_gpc</function>,
<function>get_magic_quotes_runtime</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.set-time-limit">
<refnamediv>
<refname>set_time_limit</refname>
<refpurpose>limit the maximum execution time</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>set_time_limit</function></funcdef>
<paramdef>int <parameter>seconds</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
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 <link linkend="configuration.file">configuration
file</link>. If seconds is set to zero, no time limit is
imposed.
</simpara>
<simpara>
When called, <function>set_time_limit</function> 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.
</simpara>
<simpara>
Note that <function>set_time_limit</function> 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 <link
linkend="configuration.file">configuration file</link>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.zend-logo-guid">
<refnamediv>
<refname>zend_logo_guid</refname>
<refpurpose>Get the zend guid</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>zend_logo_guid</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<note>
<para>
This funcionality was added in PHP 4 Beta 4.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.get-loaded-extensions">
<refnamediv>
<refname>get_loaded_extensions</refname>
<refpurpose>
Returns an array with the names of all modules compiled and
loaded
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_loaded_extensions</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the names of all the modules compiled and
loaded in the PHP interpreter.
</para>
<para>
For example the line below
<informalexample>
<programlisting>
print_r (get_loaded_extensions());
</programlisting>
</informalexample>
will print a list like:
<informalexample>
<programlisting>
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
)
</programlisting>
</informalexample>
</para>
<para>
See also: <function>get_extension_funcs</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.get-extension-funcs">
<refnamediv>
<refname>get_extension_funcs</refname>
<refpurpose>
Returns an array with the names of the functions of a module
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_extension_funcs</function></funcdef>
<paramdef>string <parameter>module_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the names of all the functions defined in
the module indicated by <parameter>module_name</parameter>.
</para>
<para>
For example the lines below
<informalexample>
<programlisting>
print_r (get_extension_funcs ("xml"));
print_r (get_extension_funcs ("gd"));
</programlisting>
</informalexample>
will print a list of the functions in the modules
<varname>xml</varname> and <varname>gd</varname> respectively.
</para>
<para>
See also: <function>get_loaded_extensions</function>
</para>
</refsect1>
</refentry>
<refentry id="function.get-required-files">
<refnamediv>
<refname>get_required_files</refname>
<refpurpose>
Returns an array with the names of the files require_once()'d in
a script
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_required_files</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an associtative array of the names of all
the files that have been loaded into a script using
<function>require_once</function>. The indexes of the array are
the file names as used in the <function>require_once</function>
without the ".php" extension.
</para>
<para>
The example below
<example>
<title>Printing the required and included files</title>
<programlisting>
<?php
require_once ("local.php");
require_once ("../inc/global.php");
for ($i=1; $i<5; $i++)
include "util".$i."php";
echo "Required_once files\n";
print_r (get_required_files());
echo "Included_once files\n";
print_r (get_included_files());
?>
</programlisting>
</example>
will generate the following output:
<informalexample>
<programlisting>
Required_once files
Array
(
[local] => local.php
[../inc/global] => /full/path/to/inc/global.php
)
Included_once files
Array
(
[util1] => util1.php
[util2] => util2.php
[util3] => util3.php
[util4] => util4.php
)
</programlisting>
</informalexample>
</para>
<para>
<note>
<para>
As of PHP 4.0.1pl2 this function assumes that the
<varname>required_once</varname> files end in the extension
".php", other extensions do not work.
</para>
</note>
</para>
<para>
See also: <function>require_once</function>,
<function>include_once</function>,
<function>get_included_files</function>
</para>
</refsect1>
</refentry>
<refentry id="function.get-included-files">
<refnamediv>
<refname>get_included_files</refname>
<refpurpose>
Returns an array with the names of the files include_once()'d in
a script
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_included_files</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an associtative array of the names of all
the files that have been loaded into a script using
<function>include_once</function>. The indexes of the array are
the file names as used in the <function>include_once</function>
without the ".php" extension.
</para>
<para>
<note>
<para>
As of PHP 4.0.1pl2 this function assumes that the
<varname>include_once</varname> files end in the extension
".php", other extensions do not work.
</para>
</note>
</para>
<para>
See also: <function>require_once</function>,
<function>include_once</function>,
<function>get_required_files</function>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/ldap.xml
+++ phpdoc/nl/functions/ldap.xml
<reference id="ref.ldap">
<title>LDAP functions</title>
<titleabbrev>LDAP</titleabbrev>
<partintro>
<title>Introduction to LDAP</title>
<para>
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.
</para><para>
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.
</para><para>
To refer to a file in a subdirectory on your hard disk, you might
use something like
</para>
<literallayout>
/usr/local/myapp/docs
</literallayout>
<para>
The forwards slash marks each division in the reference, and the
sequence is read from left to right.
</para><para>
The equivalent to the fully qualified file reference in LDAP is
the "distinguished name", referred to simply as "dn". An example
dn might be.
</para>
<literallayout>
cn=John Smith,ou=Accounts,o=My Company,c=US
</literallayout>
<para>
The comma marks each division in the reference, and the sequence
is read from right to left. You would read this dn as ..
</para>
<literallayout>
country = US
organization = My Company
organizationalUnit = Accounts
commonName = John Smith
</literallayout>
<para>
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.
</para>
<sect1 id="ldap-example">
<title>Complete code example</title>
<para>
Retrieve information for all entries where the surname starts
with "S" from a directory server, displaying an extract with
name and email address.
</para>
<example>
<title>LDAP search example</title>
<programlisting role="php">
<?php
// basic sequence with LDAP is connect, bind, search, interpret search
// result, close connection
echo "<h3>LDAP query test</h3>";
echo "Connecting ...";
$ds=ldap_connect("localhost"); // must be a valid LDAP server!
echo "connect result is ".$ds."<p>";
if ($ds) {
echo "Binding ...";
$r=ldap_bind($ds); // this is an "anonymous" bind, typically
// read-only access
echo "Bind result is ".$r."<p>";
echo "Searching for (sn=S*) ...";
// Search surname entry
$sr=ldap_search($ds,"o=My Company, c=US", "sn=S*");
echo "Search result is ".$sr."<p>";
echo "Number of entires returned is
".ldap_count_entries($ds,$sr)."<p>";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for ".$info["count"]." items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: ". $info[$i]["dn"] ."<br>";
echo "first cn entry is: ". $info[$i]["cn"][0]
."<br>";
echo "first email entry is: ". $info[$i]["mail"][0]
."<p>";
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
?>
</programlisting>
</example>
<sect2>
<title>Using the PHP LDAP calls</title>
<para>
You will need to get and compile LDAP client libraries from
either the University of Michigan ldap-3.3 package or the
Netscape Directory SDK 3.0. You will also need to recompile PHP
with LDAP support enabled before PHP's LDAP calls will work.
</para><para>
Before you can use the LDAP calls you will need to know ..
<itemizedlist>
<listitem>
<para>
The name or address of the directory server you will use
</para>
</listitem>
<listitem>
<para>
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")
</para>
</listitem>
<listitem>
<para>
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)
</para>
</listitem>
</itemizedlist></para>
<para>
The typical sequence of LDAP calls you will make in an
application will follow this pattern:
<literallayout>
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"
</literallayout></para>
</sect2>
<sect2>
<title>More Information</title>
<para>
Lots of information about LDAP can be found at
</para>
<itemizedlist>
<listitem>
<para>
<ulink url="&url.ldap.netscape;">Netscape</ulink>
</para>
</listitem>
<listitem>
<para>
<ulink url="&url.ldap.michigan;">University of Michigan</ulink>
</para>
</listitem>
<listitem>
<para>
<ulink url="&url.ldap.openldap;">OpenLDAP Project</ulink>
</para>
</listitem>
<listitem>
<para>
<ulink url="&url.ldap.ldapworld;">LDAP World</ulink>
</para>
</listitem>
</itemizedlist>
<para>
The Netscape SDK contains a helpful Programmer's Guide in .html
format.
</para>
</sect2>
</sect1>
</partintro>
<refentry id="function.ldap-add">
<refnamediv>
<refname>ldap_add</refname>
<refpurpose>Add entries to LDAP directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_add</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>dn</parameter></paramdef>
<paramdef>array <parameter>entry</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
returns true on success and false on error.
</para><para>
The <function>ldap_add</function> 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.
</para>
<informalexample>
<literallayout>
entry["attribute1"] = value
entry["attribute2"][0] = value1
entry["attribute2"][1] = value2
</literallayout>
</informalexample>
<example>
<title>Complete example with authenticated bind</title>
<programlisting role="php">
<?php
$ds=ldap_connect("localhost"); // assuming the LDAP server is on this host
if ($ds) {
// bind with appropriate dn to give update access
$r=ldap_bind($ds,"cn=root, o=My Company, c=US", "secret");
// prepare data
$info["cn"]="John Jones";
$info["sn"]="Jones";
$info["mail"]="jonj@here.and.now";
$info["objectclass"]="person";
// add data to directory
$r=ldap_add($ds, "cn=John Jones, o=My Company, c=US", $info);
ldap_close($ds);
} else {
echo "Unable to connect to LDAP server";
}
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ldap-bind">
<refnamediv>
<refname>ldap_bind</refname>
<refpurpose>Bind to LDAP directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_bind</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string
<parameter><optional>bind_rdn</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>bind_password</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Binds to the LDAP directory with specified RDN and
password. Returns true on success and false on error.</para>
<para>
<function>ldap_bind</function> does a bind operation on the
directory. bind_rdn and bind_password are optional. If not
specified, anonymous bind is attempted.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-close">
<refnamediv>
<refname>ldap_close</refname>
<refpurpose>Close link to LDAP server</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_close</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.</para>
<para>
<function>ldap_close</function> closes the link to the LDAP
server that's associated with the specified
<parameter>link_identifier</parameter>.</para>
<para>
This call is internally identical to
<function>ldap_unbind</function>. The LDAP API uses the call
<function>ldap_unbind</function>, so perhaps you should use this
in preference to <function>ldap_close</function>.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-compare">
<refnamediv>
<refname>ldap_compare</refname>
<refpurpose>Compare value of attribute found in entry specified with DN</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_compare</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>dn</parameter></paramdef>
<paramdef>string <parameter>attribute</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns true if <parameter>value</parameter> matches otherwise returns false.
Returns -1 on error.
</simpara>
<para>
<function>ldap_compare</function> is used to compare
<parameter>value</parameter>
of <parameter>attribute</parameter> to value of same attribute in LDAP directory
entry specified with <parameter>dn</parameter>.
</para>
<simpara>
The following example demonstrates how to check whether or not given password matches
the one defined in DN specified entry.
</simpara>
<example>
<title>Complete example of password check</title>
<programlisting role="php">
<?php
$ds=ldap_connect("localhost"); // assuming the LDAP server is on this host
if ($ds) {
// bind
if(ldap_bind($ds)) {
// prepare data
$dn = "cn=Matti Meikku, ou=My Unit, o=My Company, c=FI";
$value = "secretpassword";
$attr = "password";
// compare value
$r=ldap_compare($ds, $dn, $attr, $value);
if ($r === -1) {
echo "Error: ".ldap_error($ds);
} elseif ($r === TRUE) {
echo "Password correct.";
} elseif ($r === FALSE) {
echo "Wrong guess! Password incorrect.";
}
} else {
echo "Unable to bind to LDAP server.";
}
ldap_close($ds);
} else {
echo "Unable to connect to LDAP server.";
}
?>
</programlisting>
</example>
<note>
<para>
<function>ldap_compare</function> can NOT be used to compare BINARY values!
</para>
</note>
<note>
<para>
This function was added in 4.0.2.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.ldap-connect">
<refnamediv>
<refname>ldap_connect</refname>
<refpurpose>Connect to an LDAP server</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_connect</function></funcdef>
<paramdef>string
<parameter><optional>hostname</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>port</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a positive LDAP link identifier on success, or false on
error.</para>
<para>
<function>ldap_connect</function> establishes a connection to a
LDAP server on a specified <parameter>hostname</parameter> and
<parameter>port</parameter>. Both the arguments are optional. If
no arguments are specified then the link identifier of the
already opened link will be returned. If only
<parameter>hostname</parameter> is specified, then the port
defaults to 389.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-count-entries">
<refnamediv>
<refname>ldap_count_entries</refname>
<refpurpose>Count the number of entries in a search</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_count_entries</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int <parameter>result_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns number of entries in the result or false on error.</para>
<para>
<function>ldap_count_entries</function> returns the number of
entries stored in the result of previous search
operations. <parameter>result_identifier</parameter> identifies
the internal ldap result.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-delete">
<refnamediv>
<refname>ldap_delete</refname>
<refpurpose>Delete an entry from a directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_delete</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>dn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success and false on error.</para>
<para>
<function>ldap_delete</function> function delete a particular
entry in LDAP directory specified by dn.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-dn2ufn">
<refnamediv>
<refname>ldap_dn2ufn</refname>
<refpurpose>Convert DN to User Friendly Naming format</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ldap_dn2ufn</function></funcdef>
<paramdef>string <parameter>dn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ldap_dn2ufn</function> function is used to turn a DN
into a more user-friendly form, stripping off type names.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-err2str">
<refnamediv>
<refname>ldap_err2str</refname>
<refpurpose>
Convert LDAP error number into string error message
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ldap_err2str</function></funcdef>
<paramdef>int <parameter>errno</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
returns string error message.</para>
<para>
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.</para>
<para>
See also <function>ldap_errno</function> and
<function>ldap_error</function>.
<example>
<title>Enumerating all LDAP error messages</title>
<programlisting role="php">
<?php
for($i=0; $i<100; $i++) {
printf("Error $i: %s<br>\n", ldap_err2str($i));
}
?>
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.ldap-errno">
<refnamediv>
<refname>ldap_errno</refname>
<refpurpose>
Return the LDAP error number of the last LDAP command
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_errno</function></funcdef>
<paramdef>int <parameter>link_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
return the LDAP error number of the last LDAP command for this
link.</para>
<para>
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
<function>ldap_err2str</function>.</para>
<para>
Unless you lower your warning level in your php3.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.
<example>
<title>Generating and catching an error</title>
<programlisting role="php">
<?php
// This example contains an error, which we will catch.
$ld = ldap_connect("localhost");
$bind = ldap_bind($ld);
// syntax error in filter expression (errno 87),
// must be "objectclass=*" to work.
$res = @ldap_search($ld, "o=Myorg, c=DE", "objectclass");
if (!$res) {
printf("LDAP-Errno: %s<br>\n", ldap_errno($ld));
printf("LDAP-Error: %s<br>\n", ldap_error($ld));
die("Argh!<br>\n");
}
$info = ldap_get_entries($ld, $res);
printf("%d matching entries.<br>\n", $info["count"]);
?>
</programlisting>
</example></para>
<para>
see also <function>ldap_err2str</function> and
<function>ldap_error</function>.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-error">
<refnamediv>
<refname>ldap_error</refname>
<refpurpose>
Return the LDAP error message of the last LDAP command
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ldap_error</function></funcdef>
<paramdef>int <parameter>link_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
returns string error message.</para>
<para>
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.</para>
<para>
Unless you lower your warning level in your
<filename>php3.ini</filename> sufficiently or prefix your LDAP
commands with <literal>@</literal> (at) characters to suppress
warning output, the errors generated will also show up in your
HTML output.</para>
<para>
see also <function>ldap_err2str</function> and
<function>ldap_errno</function>.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-explode-dn">
<refnamediv>
<refname>ldap_explode_dn</refname>
<refpurpose>Splits DN into its component parts</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ldap_explode_dn</function></funcdef>
<paramdef>string <parameter>dn</parameter></paramdef>
<paramdef>int <parameter>with_attrib</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ldap_explode_dn</function> function is used to split
the a DN returned by <function>ldap_get_dn</function> and breaks
it up into its component parts. Each part is known as Relative
Distinguished Name, or RDN. <function>ldap_explode_dn</function>
returns an array of all those components.
<parameter>with_attrib</parameter> 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
<parameter>with_attrib</parameter> to 0 and to get only values
set it to 1.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-first-attribute">
<refnamediv>
<refname>ldap_first_attribute</refname>
<refpurpose>Return first attribute</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ldap_first_attribute</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int
<parameter>result_entry_identifier</parameter></paramdef>
<paramdef>int <parameter>ber_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the first attribute in the entry on success and false on
error.
</para>
<para>
Similar to reading entries, attributes are also read one by one
from a particular entry.
<function>ldap_first_attribute</function> returns the first
attribute in the entry pointed by the entry identifier.
Remaining attributes are retrieved by calling
<function>ldap_next_attribute</function> successively.
<parameter>ber_identifier</parameter> is the identifier to
internal memory location pointer. It is passed by reference. The
same <parameter>ber_identifier</parameter> is passed to the
<function>ldap_next_attribute</function> function, which modifies
that pointer.
</para>
<para>
see also <function>ldap_get_attributes</function></para>
</refsect1>
</refentry>
<refentry id="function.ldap-first-entry">
<refnamediv>
<refname>ldap_first_entry</refname>
<refpurpose>Return first result id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_first_entry</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int <parameter>result_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the result entry identifier for the first entry on
success and false on error.</para>
<para>
Entries in the LDAP result are read sequentially using the
<function>ldap_first_entry</function> and
<function>ldap_next_entry</function>
functions. <function>ldap_first_entry</function> returns the
entry identifier for first entry in the result. This entry
identifier is then supplied to
<function>lap_next_entry</function> routine to get successive
entries from the result.</para>
<para>
see also <function>ldap_get_entries</function>.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-free-result">
<refnamediv>
<refname>ldap_free_result</refname>
<refpurpose>Free result memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_free_result</function></funcdef>
<paramdef>int <parameter>result_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success and false on error.</para>
<para>
<function>ldap_free_result</function> frees up the memory
allocated internally to store the result and pointed by the
<parameter>result_identifier</parameter>. All result memory will
be automatically freed when the script terminates.</para>
<para>
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,
<function>ldap_free_result</function> could be called to keep the
runtime memory usage by the script low.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-get-attributes">
<refnamediv>
<refname>ldap_get_attributes</refname>
<refpurpose>Get attributes from a search result entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ldap_get_attributes</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int
<parameter>result_entry_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a complete entry information in a multi-dimensional array
on success and false on error.</para>
<para>
<function>ldap_get_attributes</function> 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.</para>
<para>
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.</para>
<para>
<informalexample><literallayout>
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] = ith value of the attribute
</literallayout></informalexample>
<example>
<title>Show the list of attributes held for a particular directory
entry </title>
<programlisting role="php">
// $ds is the link identifier for the directory
// $sr is a valid search result from a prior call to
// one of the ldap directory search calls
$entry = ldap_first_entry($ds, $sr);
$attrs = ldap_get_attributes($ds, $entry);
echo $attrs["count"]." attributes held for this entry:<p>";
for ($i=0; $i<$attrs["count"]; $i++)
echo $attrs[$i]."<br>";
</programlisting>
</example></para>
<para>
see also <function>ldap_first_attribute</function> and
<function>ldap_next_attribute</function></para>
</refsect1>
</refentry>
<refentry id="function.ldap-get-dn">
<refnamediv>
<refname>ldap_get_dn</refname>
<refpurpose>Get the DN of a result entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ldap_get_dn</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int
<parameter>result_entry_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the DN of the result entry and false on error.</para>
<para>
<function>ldap_get_dn</function> function is used to find out the
DN of an entry in the result.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-get-entries">
<refnamediv>
<refname>ldap_get_entries</refname>
<refpurpose>Get all result entries</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ldap_get_entries</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int <parameter>result_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a complete result information in a multi-dimenasional
array on success and false on error.</para>
<para>
<function>ldap_get_entries</function> function is used to
simplify reading multiple entries from the result 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.</para>
<para>
The attribute index is converted to lowercase. (Attributes are
case-insensitive for directory servers, but not when used as
array indices)
<informalexample>
<literallayout>
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
</literallayout>
</informalexample></para>
<para>
see also <function>ldap_first_entry</function> and
<function>ldap_next_entry</function></para>
</refsect1>
</refentry>
<refentry id="function.ldap-get-values">
<refnamediv>
<refname>ldap_get_values</refname>
<refpurpose>Get all values from a result entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ldap_get_values</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int
<parameter>result_entry_identifier</parameter></paramdef>
<paramdef>string <parameter>attribute</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of values for the attribute on success and false
on error.</para>
<para>
<function>ldap_get_values</function> function is used to read all
the values of the attribute in the entry in the result. entry is
specified by the
<parameter>result_entry_identifier</parameter>. 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.</para>
<para>
This call needs a <parameter>result_entry_identifier</parameter>,
so needs to be preceded by one of the ldap search calls and one
of the calls to get an individual entry.</para>
<para>
You application will either be hard coded to look for certain
attributes (such as "surname" or "mail") or you will have to use
the <function>ldap_get_attributes</function> call to work out
what attributes exist for a given entry.</para>
<para>
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"
<informalexample>
<literallayout>
return_value["count"] = number of values for attribute
return_value[0] = first value of attribute
return_value[i] = ith value of attribute
</literallayout>
</informalexample>
<example>
<title>List all values of the "mail" attribute for a
directory entry </title>
<programlisting role="php">
// $ds is a valid link identifier for a directory server
// $sr is a valid search result from a prior call to
// one of the ldap directory search calls
// $entry is a valid entry identifier from a prior call to
// one of the calls that returns a directory entry
$values = ldap_get_values($ds, $entry,"mail");
echo $values["count"]." email addresses for this entry.<p>";
for ($i=0; $i < $values["count"]; $i++)
echo $values[$i]."<br>";
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.ldap-get-values-len">
<refnamediv>
<refname>ldap_get_values_len</refname>
<refpurpose>Get all binary values from a result entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>ldap_get_values_len</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int
<parameter>result_entry_identifier</parameter></paramdef>
<paramdef>string <parameter>attribute</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of values for the attribute on success and false
on error.</para>
<para>
<function>ldap_get_values_len</function> function is used to read all
the values of the attribute in the entry in the result. entry is
specified by the
<parameter>result_entry_identifier</parameter>. 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.</para>
<para>
This function is used exactly like
<function>ldap_get_values</function> except that it handles
binary data and not string data.</para>
<note>
<para>
This function was added in 4.0.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.ldap-list">
<refnamediv>
<refname>ldap_list</refname>
<refpurpose>Single-level search</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_list</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>base_dn</parameter></paramdef>
<paramdef>string <parameter>filter</parameter></paramdef>
<paramdef>array
<parameter><optional>attributes</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>attrsonly</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>sizelimit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>timelimit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>deref</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a search result identifier or false on error.</para>
<para>
<function>ldap_list</function> performs the search for a specified
filter on the directory with the scope LDAP_SCOPE_ONELEVEL.</para>
<para>
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.)</para>
<para>
This call takes 5 optional parameters. See <function>ldap_search</function>
notes.
<note>
<para>
These optional parameters were added in 4.0.2:
<parameter>attrsonly</parameter>,
<parameter>sizelimit</parameter>,
<parameter>timelimit</parameter>,
<parameter>deref</parameter>.
</para>
</note>
<example>
<title>Produce a list of all organizational units of an organization
</title>
<programlisting role="php3">
// $ds is a valid link identifier for a directory server
$basedn = "o=My Company, c=US";
$justthese = array("ou");
$sr=ldap_list($ds, $basedn, "ou=*", $justthese);
$info = ldap_get_entries($ds, $sr);
for ($i=0; $i<$info["count"]; $i++)
echo $info[$i]["ou"][0] ;
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.ldap-modify">
<refnamediv>
<refname>ldap_modify</refname>
<refpurpose>Modify an LDAP entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_modify</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>dn</parameter></paramdef>
<paramdef>array <parameter>entry</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success and false on error.</para>
<para>
<function>ldap_modify</function> function is used to modify the
existing entries in the LDAP directory. The structure of the
entry is same as in <function>ldap_add</function>.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-mod-add">
<refnamediv>
<refname>ldap_mod_add</refname>
<refpurpose>Add attribute values to current attributes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_mod_add</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>dn</parameter></paramdef>
<paramdef>array <parameter>entry</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
returns true on success and false on error.</para>
<para>
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
<function>ldap_add</function> function.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-mod-del">
<refnamediv>
<refname>ldap_mod_del</refname>
<refpurpose>Delete attribute values from current attributes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_mod_del</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>dn</parameter></paramdef>
<paramdef>array <parameter>entry</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
returns true on success and false on error.</para>
<para>
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
<function>ldap_del</function> function.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-mod-replace">
<refnamediv>
<refname>ldap_mod_replace</refname>
<refpurpose>Replace attribute values with new ones</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_mod_replace</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>dn</parameter></paramdef>
<paramdef>array <parameter>entry</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
returns true on success and false on error.</para>
<para>
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
<function>ldap_modify</function> function.</para>
</refsect1>
</refentry>
<refentry id="function.ldap-next-attribute">
<refnamediv>
<refname>ldap_next_attribute</refname>
<refpurpose>Get the next attribute in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ldap_next_attribute</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int
<parameter>result_entry_identifier</parameter></paramdef>
<paramdef>int <parameter>ber_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the next attribute in an entry on success and false on
error.</para>
<para>
<function>ldap_next_attribute</function> is called to retrieve
the attributes in an entry. The internal state of the pointer is
maintained by the <parameter>ber_identifier</parameter>. It is
passed by reference to the function. The first call to
<function>ldap_next_attribute</function> is made with the
<parameter>result_entry_identifier</parameter> returned from
<function>ldap_first_attribute</function>.</para>
<para>
see also <function>ldap_get_attributes</function></para>
</refsect1>
</refentry>
<refentry id="function.ldap-next-entry">
<refnamediv>
<refname>ldap_next_entry</refname>
<refpurpose>Get next result entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_next_entry</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>int
<parameter>result_entry_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns entry identifier for the next entry in the result whose
entries are being read starting with
<function>ldap_first_entry</function>. If there are no more
entries in the result then it returns false.</para>
<para>
<function>ldap_next_entry</function> function is used to retrieve
the entries stored in the result. Successive calls to the
<function>ldap_next_entry</function> return entries one by one
till there are no more entries. The first call to
<function>ldap_next_entry</function> is made after the call to
<function>ldap_first_entry</function> with the result_identifier
as returned from the <function>ldap_first_entry</function>.</para>
<para>
see also <function>ldap_get_entries</function></para>
</refsect1>
</refentry>
<refentry id="function.ldap-read">
<refnamediv>
<refname>ldap_read</refname>
<refpurpose>Read an entry</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_read</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>base_dn</parameter></paramdef>
<paramdef>string <parameter>filter</parameter></paramdef>
<paramdef>array
<parameter><optional>attributes</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>attrsonly</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>sizelimit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>timelimit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>deref</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a search result identifier or false on error.</para>
<para>
<function>ldap_read</function> 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.</para>
<para>
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".</para>
<para>
This call takes 5 optional parameters. See <function>ldap_search</function>
notes.
</para>
<note>
<para>
These optional parameters were added in 4.0.2:
<parameter>attrsonly</parameter>,
<parameter>sizelimit</parameter>,
<parameter>timelimit</parameter>,
<parameter>deref</parameter>.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.ldap-search">
<refnamediv>
<refname>ldap_search</refname>
<refpurpose>Search LDAP tree</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_search</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
<paramdef>string <parameter>base_dn</parameter></paramdef>
<paramdef>string <parameter>filter</parameter></paramdef>
<paramdef>array
<parameter><optional>attributes</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>attrsonly</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>sizelimit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>timelimit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>deref</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a search result identifier or false on error.</para>
<para>
<function>ldap_search</function> 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. <parameter>base_dn</parameter> specifies the base DN
for the directory.</para>
<para>
There is a 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.</para>
<para>
The fourth parameter is a standard PHP string array of the
required attributes, eg array("mail","sn","cn") Note that the
"dn" is always returned irrespective of which attributes types
are requested.</para>
<para>
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
<parameter>sizelimit</parameter> has been used to limit the count
of fetched entries.
</para>
<para>
The fifth parameter <parameter>attrsonly</parameter> 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.
</para>
<para>
With the sixth parameter <parameter>sizelimit</parameter> 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.
</para>
<para>
The seventh parameter <parameter>timelimit</parameter> 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.
</para>
<para>
The eigth parameter <parameter>deref</parameter> specifies how aliases
should be handled during the search. It can be one of the following:
<itemizedlist>
<listitem>
<simpara>
LDAP_DEREF_NEVER - (default) aliases are never dereferenced.
</simpara>
</listitem>
<listitem>
<simpara>
LDAP_DEREF_SEARCHING - aliases should be dereferenced during the search
but not when locating the base object of the search.
</simpara>
</listitem>
<listitem>
<simpara>
LDAP_DEREF_FINDING - aliases should be dereferenced when
locating the base object but not during the search.
</simpara>
</listitem>
<listitem>
<simpara>
LDAP_DEREF_ALWAYS - aliases should be dereferenced always.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
These optional parameters were added in 4.0.2:
<parameter>attrsonly</parameter>,
<parameter>sizelimit</parameter>,
<parameter>timelimit</parameter>,
<parameter>deref</parameter>.
</para>
<para>
The search filter can be simple or advanced, using boolean
operators in the format described in the LDAP doumentation (see
the <ulink url="&url.ldap.filters;">Netscape Directory SDK</ulink>
for full information on filters).</para>
<para>
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.
<example>
<title>LDAP search</title>
<programlisting role="php">
// $ds is a valid link identifier for a directory server
// $person is all or part of a person's name, eg "Jo"
$dn = "o=My Company, c=US";
$filter="(|(sn=$person*)(givenname=$person*))";
$justthese = array( "ou", "sn", "givenname", "mail");
$sr=ldap_search($ds, $dn, $filter, $justthese);
$info = ldap_get_entries($ds, $sr);
print $info["count"]." entries returned<p>";
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.ldap-unbind">
<refnamediv>
<refname>ldap_unbind</refname>
<refpurpose>Unbind from LDAP directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ldap_unbind</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success and false on error.</para>
<para>
<function>ldap_unbind</function> function unbinds from the LDAP
directory.</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/mail.xml
+++ phpdoc/nl/functions/mail.xml
<reference id="ref.mail">
<title>Mail functions</title>
<titleabbrev>Mail</titleabbrev>
<partintro>
<simpara>
The <function>mail</function> function allows you to send mail.</simpara>
</partintro>
<refentry id="function.mail">
<refnamediv>
<refname>mail</refname>
<refpurpose>send mail</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>mail</function></funcdef>
<paramdef>string <parameter>to</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>string <parameter>message</parameter></paramdef>
<paramdef>string
<parameter><optional>additional_headers</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Mail</function> automatically mails the message specified
in <parameter>message</parameter> to the receiver specified in
<parameter>to</parameter>. Multiple recipients can be specified by
putting a comma between each address in <parameter>to</parameter>.</simpara>
<para>
<example>
<title>Sending mail.</title>
<programlisting>
mail("rasmus@lerdorf.on.ca", "My Subject", "Line 1\nLine 2\nLine 3");
</programlisting>
</example></para>
<simpara>
If a fourth string argument is passed, this string is inserted at
the end of the header. This is typically used to add extra
headers. Multiple extra headers are separated with a newline.</simpara>
<para>
<example>
<title>Sending mail with extra headers.</title>
<programlisting>
mail("nobody@aol.com", "the subject", $message,
"From: webmaster@$SERVER_NAME\nReply-To: webmaster@$SERVER_NAME\nX-Mailer: PHP/" .
phpversion());
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.ezmlm-hash">
<refnamediv>
<refname>ezmlm_hash</refname>
<refpurpose>Calculate the hash value needed by EZMLM</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ezmlm_hash</function></funcdef>
<paramdef>string <parameter>addr</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>ezmlm_hash</function> calculates the hash value needed
when keeping EZMLM mailing lists in a MySQL database.
</simpara>
<para>
<example>
<title>Calculating the hash and subscribing a user</title>
<programlisting>
$user = "kris@koehntopp.de";
$hash = ezmlm_hash ($user);
$query = sprintf ("INSERT INTO sample VALUES (%s, '%s')", $hash, $user);
$db->query($query); // using PHPLIB db interface
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/math.xml
+++ phpdoc/nl/functions/math.xml
<reference id="ref.math">
<title>Mathematical Functions</title>
<titleabbrev>Math.</titleabbrev>
<partintro>
<sect1>
<title>Introduction</title>
<para>
These math functions will only handle values within the range of
the long and double types on your computer. If you need to
handle bigger numbers, take a look at the <link
linkend="ref.bc">arbitrary precision math functions</link>.
</para>
<sect2>
<title>Math constants</title>
<para>
The following values are defined as constants in PHP by the math
extension:
<table>
<title>Math constants</title>
<tgroup cols="3">
<thead>
<row>
<entry>Constant</entry>
<entry>Value</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>M_PI</entry>
<entry>3.14159265358979323846</entry>
<entry>Der Wert π (Pi)</entry>
</row>
<row>
<entry>M_E</entry>
<entry>2.7182818284590452354</entry>
<entry>e</entry>
</row>
<row>
<entry>M_LOG2E</entry>
<entry>1.4426950408889634074</entry>
<entry>log_2 e</entry>
</row>
<row>
<entry>M_LOG10E</entry>
<entry>0.43429448190325182765</entry>
<entry>log_10 e</entry>
</row>
<row>
<entry>M_LN2</entry>
<entry>0.69314718055994530942</entry>
<entry>log_e 2</entry>
</row>
<row>
<entry>M_LN10</entry>
<entry>2.30258509299404568402</entry>
<entry>log_e 10</entry>
</row>
<row>
<entry>M_PI_2</entry>
<entry>1.57079632679489661923</entry>
<entry>pi/2</entry>
</row>
<row>
<entry>M_PI_4</entry>
<entry>0.78539816339744830962</entry>
<entry>pi/4</entry>
</row>
<row>
<entry>M_1_PI</entry>
<entry>0.31830988618379067154</entry>
<entry>1/pi</entry>
</row>
<row>
<entry>M_2_PI</entry>
<entry>0.63661977236758134308</entry>
<entry>2/pi</entry>
</row>
<row>
<entry>M_SQRTPI</entry>
<entry>1.77245385090551602729</entry>
<entry>sqrt(pi) [4.0.2]</entry>
</row>
<row>
<entry>M_2_SQRTPI</entry>
<entry>1.12837916709551257390</entry>
<entry>2/sqrt(pi)</entry>
</row>
<row>
<entry>M_SQRT2</entry>
<entry>1.41421356237309504880</entry>
<entry>sqrt(2)</entry>
</row>
<row>
<entry>M_SQRT3</entry>
<entry>1.73205080756887729352</entry>
<entry>sqrt(3) [4.0.2]</entry>
</row>
<row>
<entry>M_SQRT1_2</entry>
<entry>0.70710678118654752440</entry>
<entry>1/sqrt(2)</entry>
</row>
<row>
<entry>M_LNPI</entry>
<entry>1.14472988584940017414</entry>
<entry>log_e(pi) [4.0.2]</entry>
</row>
<row>
<entry>M_EULER</entry>
<entry>0.57721566490153286061</entry>
<entry>Euler constant [4.0.2]</entry>
</row>
</tbody>
</tgroup>
</table>
Only M_PI is available in PHP versions up to and including PHP4RC1.
All other constants are available starting with PHP 4.0. Constants
labelled [4.0.2] were added in PHP 4.0.2.
</para>
</sect2>
</sect1>
</partintro>
<refentry id="function.abs">
<refnamediv>
<refname>abs</refname>
<refpurpose>Absolute value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>abs</function></funcdef>
<paramdef>mixed <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the absolute value of number. If the argument number is
float, return type is also float, otherwise it is int.
</para>
</refsect1>
</refentry>
<refentry id="function.acos">
<refnamediv>
<refname>acos</refname>
<refpurpose>Arc cosine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>acos</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the arc cosine of arg in radians.
</para>
<para>
See also <function>asin</function> and <function>atan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.asin">
<refnamediv>
<refname>asin</refname>
<refpurpose>Arc sine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>asin</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the arc sine of arg in radians.
</para>
<para>
See also <function>acos</function> and <function>atan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.atan">
<refnamediv>
<refname>atan</refname>
<refpurpose>Arc tangent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>atan</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the arc tangent of arg in radians.
</para>
<para>
See also <function>asin</function> and <function>acos</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.atan2">
<refnamediv>
<refname>atan2</refname>
<refpurpose>arc tangent of two variables</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>atan2</function></funcdef>
<paramdef>float <parameter>y</parameter></paramdef>
<paramdef>float <parameter>x</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function calculates the arc tangent of the two variables
<parameter>x</parameter> and <parameter>y</parameter>. It is
similar to calculating the arc tangent of
<parameter>y</parameter> / <parameter>x</parameter>, except that
the signs of both arguments are used to determine the quadrant of
the result.
</simpara>
<simpara>
The function returns the result in radians, which is between -PI
and PI (inclusive).
</simpara>
<para>
See also <function>acos</function> and <function>atan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.base-convert">
<refnamediv>
<refname>base_convert</refname>
<refpurpose>Convert a number between arbitrary bases</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>base_convert</function></funcdef>
<paramdef>string <parameter>number</parameter></paramdef>
<paramdef>int <parameter>frombase</parameter></paramdef>
<paramdef>int <parameter>tobase</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing <parameter>number</parameter>
represented in base <parameter>tobase</parameter>. The base in
which <parameter>number</parameter> is given is specified in
<parameter>frombase</parameter>. Both
<parameter>frombase</parameter> and <parameter>tobase</parameter>
have to be between 2 and 36, inclusive. Digits in numbers with a
base higher than 10 will be represented with the letters a-z,
with a meaning 10, b meaning 11 and z meaning 35.
<example>
<title><function>Base_convert</function></title>
<programlisting role="php">
$binary = base_convert ($hexadecimal, 16, 2);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.bindec">
<refnamediv>
<refname>bindec</refname>
<refpurpose>Binary to decimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>bindec</function></funcdef>
<paramdef>string <parameter>binary_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the decimal equivalent of the binary number represented by
the binary_string argument.
</para>
<para>
Octdec converts a binary number to a decimal number. The largest
number that can be converted is 31 bits of 1's or 2147483647 in
decimal.
</para>
<para>
See also the <function>decbin</function>
function.
</para>
</refsect1>
</refentry>
<refentry id="function.ceil">
<refnamediv>
<refname>ceil</refname>
<refpurpose>Round fractions up</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ceil</function></funcdef>
<paramdef>float <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the next highest integer value from
<parameter>number</parameter>. Using <function>ceil</function>
on integers is absolutely a waste of time.
</simpara>
<simpara>
NOTE: PHP/FI 2's <function>ceil</function> returned a
float. Use: <literal>$new = (double)ceil($number);</literal> to
get the old behaviour.
</simpara>
<simpara>
See also <function>floor</function> and
<function>round</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.cos">
<refnamediv>
<refname>cos</refname>
<refpurpose>Cosine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>cos</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the cosine of arg in radians.
</para>
<para>
See also <function>sin</function> and <function>tan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.decbin">
<refnamediv>
<refname>decbin</refname>
<refpurpose>Decimal to binary</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>decbin</function></funcdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a binary representation of the given
number argument. The largest number that can be converted is
2147483647 in decimal resulting to a string of 31 1's.
</para>
<para>
See also the <function>bindec</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.dechex">
<refnamediv>
<refname>dechex</refname>
<refpurpose>Decimal to hexadecimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>dechex</function></funcdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a hexadecimal representation of the
given number argument. The largest number that can
be converted is 2147483647 in decimal resulting to "7fffffff".
</para>
<para>
See also the <function>hexdec</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.decoct">
<refnamediv>
<refname>decoct</refname>
<refpurpose>Decimal to octal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>decoct</function></funcdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing an octal representation of the given
number argument. The largest number that can be converted is
2147483647 in decimal resulting to "17777777777".
</para>
<para>
See also <function>octdec</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.deg2rad">
<refnamediv>
<refname>deg2rad</refname>
<refpurpose>
Converts the number in degrees to the radian equivalent
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>deg2rad</function></funcdef>
<paramdef>double <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function converts <parameter>number</parameter> from degrees
to the radian equivalent.
</para>
<para>
See also <function>rad2deg</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.exp">
<refnamediv>
<refname>exp</refname>
<refpurpose>e to the power of ...</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>exp</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns e raised to the power of <parameter>arg</parameter>.
</para>
<para>
See also <function>pow</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.floor">
<refnamediv>
<refname>floor</refname>
<refpurpose>Round fractions down</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>floor</function></funcdef>
<paramdef>float <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the next lowest integer value from
<parameter>number</parameter>. Using <function>floor</function>
on integers is absolutely a waste of time.
</simpara>
<simpara>
NOTE: PHP/FI 2's <function>floor</function> returned a
float. Use: <literal>$new = (double)floor($number);</literal> to
get the old behaviour.
</simpara>
<simpara>
See also <function>ceil</function> and
<function>round</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.getrandmax">
<refnamediv>
<refname>getrandmax</refname>
<refpurpose>Show largest possible random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getrandmax</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the maximum value that can be returned by a call to
<function>rand</function>.
</simpara>
<simpara>
See also <function>rand</function>, <function>srand</function>,
<function>mt_rand</function>, <function>mt_srand</function>, and
<function>mt_getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.hexdec">
<refnamediv>
<refname>hexdec</refname>
<refpurpose>Hexadecimal to decimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>hexdec</function></funcdef>
<paramdef>string <parameter>hex_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the decimal equivalent of the hexadecimal number
represented by the hex_string argument. HexDec converts a
hexadecimal string to a decimal number. The largest number that
can be converted is 7fffffff or 2147483647 in decimal.
</para>
<para>
See also the <function>dechex</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.lcg-value">
<refnamediv>
<refname>lcg_value</refname>
<refpurpose>Combined linear congruential generator</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>lcg_value</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>lcg_value</function> returns a pseudo random number in
the range of (0, 1). The function combines two CGs with periods
of 2^31 - 85 and 2^31 - 249. The period of this function is equal
to the product of both primes.
</para>
</refsect1>
</refentry>
<refentry id="function.log">
<refnamediv>
<refname>log</refname>
<refpurpose>Natural logarithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>log</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the natural logarithm of arg.
</para>
</refsect1>
</refentry>
<refentry id="function.log10">
<refnamediv>
<refname>log10</refname>
<refpurpose>Base-10 logarithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>log10</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the base-10 logarithm of <parameter>arg</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.max">
<refnamediv>
<refname>max</refname>
<refpurpose>Find highest value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>max</function></funcdef>
<paramdef>mixed <parameter>arg1</parameter></paramdef>
<paramdef>mixed <parameter>arg2</parameter></paramdef>
<paramdef>mixed <parameter>argn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>max</function> returns the numerically highest of the
parameter values.
</para>
<para>
If the first parameter is an array, <function>max</function>
returns the highest value in that array. If the first parameter
is an integer, string or double, you need at least two parameters
and <function>max</function> returns the biggest of these values.
You can compare an unlimited number of values.
</para>
<para>
If one or more of the values is a double, all the values will be
treated as doubles, and a double is returned. If none of the
values is a double, all of them will be treated as integers, and
an integer is returned.
</para>
</refsect1>
</refentry>
<refentry id="function.min">
<refnamediv>
<refname>min</refname>
<refpurpose>Find lowest value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>min</function></funcdef>
<paramdef>mixed <parameter>arg1</parameter></paramdef>
<paramdef>mixed <parameter>arg2</parameter></paramdef>
<paramdef>mixed <parameter>argn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Min</function> returns the numerically lowest of the
parameter values.
</para>
<para>
If the first parameter is an array, <function>min</function>
returns the lowest value in that array. If the first parameter
is an integer, string or double, you need at least two parameters
and <function>min</function> returns the lowest of these values.
You can compare an unlimited number of values.
</para>
<para>
If one or more of the values is a double, all the values will be
treated as doubles, and a double is returned. If none of the
values is a double, all of them will be treated as integers, and
an integer is returned.
</para>
</refsect1>
</refentry>
<refentry id="function.mt-rand">
<refnamediv>
<refname>mt_rand</refname>
<refpurpose>Generate a better random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mt_rand</function></funcdef>
<paramdef>int
<parameter><optional>min</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>max</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Many random number generators of older libcs have dubious or
unknown characteristics and are slow. By default, PHP uses the
libc random number generator with the <function>rand</function>
function. <function>mt_rand</function> function is a drop-in
replacement for this. It uses a random number generator with
known characteristics, the Mersenne Twister, which will produce
random numbers that should be suitable for seeding some kinds
of cryptography (see the home pages for details) and is four
times faster than what the average libc provides. The Homepage
of the Mersenne Twister can be found at
<ulink url="&url.mersenne;">&url.mersenne;</ulink>, and an
optimized version of the MT source is available from
<ulink url="&url.mersenne.twister;">&url.mersenne.twister;
</ulink>.
</simpara>
<simpara>
If called without the optional <parameter>min</parameter>,
<parameter>max</parameter> arguments <function>mt_rand</function>
returns a pseudo-random value between 0 and
<constant>RAND_MAX</constant>. If you want a random number
between 5 and 15 (inclusive), for example, use <literal>mt_rand
(5, 15)</literal>.
</simpara>
<simpara>
Remember to seed the random number generator before use with
<function>mt_srand</function>.
</simpara>
<note>
<para>
In versions before 3.0.7 the meaning of
<parameter>max</parameter> was <parameter>range</parameter>. To
get the same results in these versions the short example should
be <literal>mt_rand (5, 11)</literal> to get a random number
between 5 and 15.
</para>
</note>
<simpara>
See also <function>mt_srand</function>,
<function>mt_getrandmax</function>, <function>srand</function>,
<function>rand</function> and <function>getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.mt-srand">
<refnamediv>
<refname>mt_srand</refname>
<refpurpose>Seed the better random number generator</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>mt_srand</function></funcdef>
<paramdef>int <parameter>seed</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeds the random number generator with
<parameter>seed</parameter>.
<informalexample>
<programlisting role="php">
// seed with microseconds since last "whole" second
mt_srand ((double) microtime() * 1000000);
$randval = mt_rand();
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>mt_rand</function>,
<function>mt_getrandmax</function>, <function>srand</function>,
<function>rand</function>, and
<function>getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.mt-getrandmax">
<refnamediv>
<refname>mt_getrandmax</refname>
<refpurpose>Show largest possible random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mt_getrandmax</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the maximum value that can be returned by a call to
<function>mt_rand</function>.
</simpara>
<simpara>
See also <function>mt_rand</function>,
<function>mt_srand</function> <function>rand</function>,
<function>srand</function>, and
<function>getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.number-format">
<refnamediv>
<refname>number_format</refname>
<refpurpose>Format a number with grouped thousands</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>number_format</function></funcdef>
<paramdef>float <parameter>number</parameter></paramdef>
<paramdef>int <parameter>decimals</parameter></paramdef>
<paramdef>string <parameter>dec_point</parameter></paramdef>
<paramdef>string <parameter>thousands_sep</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Number_format</function> returns a formatted version of
<parameter>number</parameter>. This function accepts either one,
two or four parameters (not three):
</para>
<para>If only one parameter is given,
<parameter>Number</parameter> will be formatted without decimals,
but with a comma (",") between every group of thousands.
</para>
<para>
If two parameters are given, <parameter>number</parameter> will
be formatted with <parameter>decimals</parameter> decimals with a
dot (".") in front, and a comma (",") between every group of
thousands.
</para>
<para>
If all four parameters are given, <parameter>number</parameter>
will be formatted with <parameter>decimals</parameter> decimals,
<parameter>dec_point</parameter> instead of a dot (".") before
the decimals and <parameter>thousands_sep</parameter> instead of
a comma (",") between every group of thousands.
</para>
</refsect1>
</refentry>
<refentry id="function.octdec">
<refnamediv>
<refname>octdec</refname>
<refpurpose>Octal to decimal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>octdec</function></funcdef>
<paramdef>string <parameter>octal_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the decimal equivalent of the octal number
represented by the octal_string argument.
OctDec converts an octal string to a decimal number. The largest
number that can be converted is 17777777777 or 2147483647 in
decimal.
</para>
<para>
See also <function>decoct</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pi">
<refnamediv>
<refname>pi</refname>
<refpurpose>Get value of pi</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>pi</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns an approximation of pi.
</simpara>
</refsect1>
</refentry>
<refentry id="function.pow">
<refnamediv>
<refname>pow</refname>
<refpurpose>Exponential expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>pow</function></funcdef>
<paramdef>float <parameter>base</parameter></paramdef>
<paramdef>float <parameter>exp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns base raised to the power of exp.
</para>
<para>
See also <function>exp</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.rad2deg">
<refnamediv>
<refname>rad2deg</refname>
<refpurpose>
Converts the radian number to the equivalent number in degrees
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>rad2deg</function></funcdef>
<paramdef>double <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function converts <parameter>number</parameter> from radian
to degrees.
</para>
<para>
See also <function>deg2rad</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.rand">
<refnamediv>
<refname>rand</refname>
<refpurpose>Generate a random value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>rand</function></funcdef>
<paramdef>
<parameter><optional>int min</optional></parameter>
</paramdef>
<paramdef>
<parameter><optional>int max</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
If called without the optional <parameter>min</parameter>,
<parameter>max</parameter> arguments <function>rand</function>
returns a pseudo-random value between 0 and
<constant>RAND_MAX</constant>. If you want a random number
between 5 and 15 (inclusive), for example, use <literal>rand (5,
15)</literal>.
</simpara>
<simpara>
Remember to seed the random number generator before use with
<function>srand</function>.
</simpara>
<note>
<para>
In versions before 3.0.7 the meaning of
<parameter>max</parameter> was <parameter>range</parameter>. To
get the same results in these versions the short example should
be <literal>rand (5, 11)</literal> to get a random number
between 5 and 15.
</para>
</note>
<simpara>
See also <function>srand</function>,
<function>getrandmax</function>, <function>mt_rand</function>,
<function>mt_srand</function>, and
<function>mt_getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.round">
<refnamediv>
<refname>round</refname>
<refpurpose>Rounds a float</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>round</function></funcdef>
<paramdef>double <parameter>val</parameter></paramdef>
<paramdef>int
<parameter><optional>precision</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the rounded value of <parameter>val</parameter> to
specified precision.
<informalexample>
<programlisting role="php">
$foo = round (3.4); // $foo == 3.0
$foo = round (3.5); // $foo == 4.0
$foo = round (3.6); // $foo == 4.0
$foo = round (1.95583, 2); // $foo == 1.96
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>ceil</function> and
<function>floor</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.sin">
<refnamediv>
<refname>sin</refname>
<refpurpose>Sine</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>sin</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the sine of arg in radians.
</para>
<para>
See also <function>cos</function> and <function>tan</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sqrt">
<refnamediv>
<refname>sqrt</refname>
<refpurpose>Square root</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>sqrt</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the square root of <parameter>arg</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.srand">
<refnamediv>
<refname>srand</refname>
<refpurpose>Seed the random number generator</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>srand</function></funcdef>
<paramdef>int <parameter>seed</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeds the random number generator with
<parameter>seed</parameter>.
<informalexample>
<programlisting role="php">
// seed with microseconds since last "whole" second
srand ((double) microtime() * 1000000);
$randval = rand();
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>rand</function>,
<function>getrandmax</function>, <function>mt_rand</function>,
<function>mt_srand</function>, and
<function>mt_getrandmax</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.tan">
<refnamediv>
<refname>tan</refname>
<refpurpose>Tangent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>tan</function></funcdef>
<paramdef>float <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the tangent of arg in radians.
</para>
<para>
See also <function>sin</function> and <function>cos</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/mcal.xml
+++ phpdoc/nl/functions/mcal.xml
<reference id="ref.mcal">
<title>MCAL functions</title>
<titleabbrev>MCAL</titleabbrev>
<partintro>
<para>
MCAL stands for Modular Calendar Access Library.
</para>
<para>
Libmcal is a C library for accessing calendars. It's written to be
very modular, with plugable drivers. MCAL is the calendar
equivalent of the IMAP module for mailboxes.
</para>
<para>
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.
</para>
<para>
Calendar events can be pulled up, queried, and stored. There is
also support for calendar triggers (alarms) and reoccuring events.
</para>
<para>
With libmcal, central calendar servers can be accessed and used,
removing the need for any specific database or local file
programming.
</para>
<para>
To get these functions to work, you have to compile PHP with
<option role="configure">--with-mcal</option>. That requires the
mcal library to be installed. Grab the latest version from
<ulink url="&url.mcal;">&url.mcal;</ulink> and compile and install
it.
</para>
<para>
The following constants are defined when using the MCAL module:
MCAL_SUNDAY,
MCAL_MONDAY,
MCAL_TUESDAY,
MCAL_WEDNESDAY,
MCAL_THURSDAY,
MCAL_FRIDAY,
MCAL_SATURDAY,
MCAL_RECUR_NONE,
MCAL_RECUR_DAILY,
MCAL_RECUR_WEEKLY,
MCAL_RECUR_MONTHLY_MDAY,
MCAL_RECUR_MONTHLY_WDAY,
MCAL_RECUR_YEARLY,
MCAL_JANUARY,
MCAL_FEBRUARY,
MCAL_MARCH,
MCAL_APRIL,
MCAL_MAY,
MCAL_JUNE,
MCAL_JULY,
MCAL_AUGUGT,
MCAL_SEPTEMBER,
MCAL_OCTOBER,
MCAL_NOVEMBER, and
MCAL_DECEMBER.
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.
</para>
</partintro>
<refentry id="function.mcal-open">
<refnamediv>
<refname>mcal_open</refname>
<refpurpose>Opens up an MCAL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_open</function></funcdef>
<paramdef>string <parameter>calendar</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>int <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an MCAL stream on success, false on error.
</para>
<para>
<function>mcal_open</function> opens up an MCAL connection to the
specified <parameter>calendar</parameter> store. If the optional
<parameter>options</parameter> is specified, passes the
<parameter>options</parameter> to that mailbox also. The streams
internal event structure is also initialized upon connection.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-popen">
<refnamediv>
<refname>mcal_popen</refname>
<refpurpose>Opens up a persistant MCAL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_popen</function></funcdef>
<paramdef>string <parameter>calendar</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>int <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an MCAL stream on success, false on error.
</para>
<para>
<function>mcal_popen</function> opens up an MCAL connection to the
specified <parameter>calendar</parameter> store. If the optional
<parameter>options</parameter> is specified, passes the
<parameter>options</parameter> to that mailbox also. The streams
internal event structure is also initialized upon connection.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-reopen">
<refnamediv>
<refname>mcal_reopen</refname>
<refpurpose>Reopens an MCAL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_reopen</function></funcdef>
<paramdef>string <parameter>calendar</parameter></paramdef>
<paramdef>int <parameter>options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Reopens an MCAL stream to a new calendar.
</para>
<para>
<function>mcal_reopen</function> reopens an MCAL connection to the
specified <parameter>calendar</parameter> store. If the optional
<parameter>options</parameter> is specified, passes the
<parameter>options</parameter> to that mailbox also.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-close">
<refnamediv>
<refname>mcal_close</refname>
<refpurpose>Close an MCAL stream</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_close</function></funcdef>
<paramdef>int <parameter>mcal_stream</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Closes the given mcal stream.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-create-calendar">
<refnamediv>
<refname>mcal_create_calendar</refname>
<refpurpose>Create a new MCAL calendar </refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>stream</function></funcdef>
<paramdef>string <parameter>calendar</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Creates a new calendar named <parameter>calendar</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-rename-calendar">
<refnamediv>
<refname>mcal_rename_calendar</refname>
<refpurpose>Rename an MCAL calendar </refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>stream</function></funcdef>
<paramdef>string <parameter>old_name</parameter></paramdef>
<paramdef>string <parameter>new_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Renames the calendar <parameter>old_name</parameter> to
<parameter>new_name</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-delete-calendar">
<refnamediv>
<refname>mcal_delete_calendar</refname>
<refpurpose>Delete an MCAL calendar </refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>stream</function></funcdef>
<paramdef>string <parameter>calendar</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Deletes the calendar named <parameter>calendar</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-fetch-event">
<refnamediv>
<refname>mcal_fetch_event</refname>
<refpurpose>
Fetches an event from the calendar stream
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>mcal_fetch_event</function></funcdef>
<paramdef>int <parameter>mcal_stream</parameter></paramdef>
<paramdef>int <parameter>event_id</parameter></paramdef>
<paramdef>int
<parameter><optional>options</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_fetch_event</function> fetches an event from the
calendar stream specified by <parameter>id</parameter>.
</para>
<para>
Returns an event object consisting of:
<itemizedlist>
<listitem><simpara>
int id - ID of that event.</simpara></listitem>
<listitem><simpara>
int public - TRUE if the event if public, FALSE if it is
private.</simpara></listitem>
<listitem><simpara>
string category - Category string of the event.</simpara></listitem>
<listitem><simpara>
string title - Title string of the event.</simpara></listitem>
<listitem><simpara>
string description - Description string of the event.</simpara></listitem>
<listitem><simpara>
int alarm - number of minutes before the event to send an
alarm/reminder.</simpara></listitem>
<listitem><simpara>
object start - Object containing a datetime entry.</simpara></listitem>
<listitem><simpara>
object end - Object containing a datetime entry.</simpara></listitem>
<listitem><simpara>
int recur_type - recurrence type</simpara></listitem>
<listitem><simpara>
int recur_interval - recurrence interval</simpara></listitem>
<listitem><simpara>
datetime recur_enddate - recurrence end date</simpara></listitem>
<listitem><simpara>
int recur_data - recurrence data</simpara></listitem>
</itemizedlist>
All datetime entries consist of an object that contains:
<itemizedlist>
<listitem><simpara>
int year - year</simpara></listitem>
<listitem><simpara>
int month - month</simpara></listitem>
<listitem><simpara>
int mday - day of month</simpara></listitem>
<listitem><simpara>
int hour - hour</simpara></listitem>
<listitem><simpara>
int min - minutes</simpara></listitem>
<listitem><simpara>
int sec - seconds</simpara></listitem>
<listitem><simpara>
int alarm - minutes before event to send an alarm</simpara></listitem>
</itemizedlist></para>
</refsect1>
</refentry>
<refentry id="function.mcal-list-events">
<refnamediv>
<refname>mcal_list_events</refname>
<refpurpose>
Return a list of IDs for a date or a range of dates.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mcal_list_events</function></funcdef>
<paramdef>int <parameter>mcal_stream</parameter></paramdef>
<paramdef>object<parameter>begin_date</parameter></paramdef>
<paramdef>object
<parameter><optional>end_date</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
<function>mcal_list_events</function> function 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.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-append-event">
<refnamediv>
<refname>mcal_append_event</refname>
<refpurpose>Store a new event into an MCAL calendar</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_append_event</function></funcdef>
<paramdef>int <parameter>mcal_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_append_event</function> Stores the global event
into an MCAL calendar for the given stream.
</para>
<para>
Returns the id of the newly inserted event.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-store-event">
<refnamediv>
<refname>mcal_store_event</refname>
<refpurpose>Modify an existing event in an MCAL calendar</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_store_event</function></funcdef>
<paramdef>int <parameter>mcal_stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_store_event</function> Stores the modifications
to the current global event for the given stream.
</para>
<para>
Returns true on success and false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-delete-event">
<refnamediv>
<refname>mcal_delete_event</refname>
<refpurpose>Delete an event from an MCAL calendar</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_delete_event</function></funcdef>
<paramdef>int <parameter>mcal_stream</parameter></paramdef>
<paramdef>int
<parameter><optional>event_id</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_delete_event</function> deletes the calendar event
specified by the event_id.</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-snooze">
<refnamediv>
<refname>mcal_snooze</refname>
<refpurpose>Turn off an alarm for an event</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_snooze</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_snooze</function> turns off an alarm for a
calendar event specified by the id.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-list-alarms">
<refnamediv>
<refname>mcal_list_alarms</refname>
<refpurpose>
Return a list of events that has an alarm triggered at the given
datetime
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mcal_list_events</function></funcdef>
<paramdef>int <parameter>mcal_stream</parameter></paramdef>
<paramdef>int
<parameter><optional>begin_year</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>begin_month</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>begin_day</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>end_year</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>end_month</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>end_day</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns 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.
</para>
<para>
<function>mcal_list_events</function> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-init">
<refnamediv>
<refname>mcal_event_init</refname>
<refpurpose>
Initializes a streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_event_init</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_init</function> initializes a streams global
event structure. this effectively sets all elements of the
structure to 0, or the default settings.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-category">
<refnamediv>
<refname>mcal_event_set_category</refname>
<refpurpose>
Sets the category of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_event_set_category</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>string <parameter>category</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_category</function> sets the streams
global event structure's category to the given string.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-title">
<refnamediv>
<refname>mcal_event_set_title</refname>
<refpurpose>
Sets the title of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_event_set_title</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>string <parameter>title</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_title</function> sets the streams global
event structure's title to the given string.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-description">
<refnamediv>
<refname>mcal_event_set_description</refname>
<refpurpose>
Sets the description of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_event_set_description</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>string <parameter>description</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_description</function> sets the streams
global event structure's description to the given string.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-start">
<refnamediv>
<refname>mcal_event_set_start</refname>
<refpurpose>
Sets the start date and time of the streams global event
structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_event_set_start</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int
<parameter>
<optional>day</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>hour</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>min</optional></parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>sec</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_start</function> sets the streams global
event structure's start date and time to the given values.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-end">
<refnamediv>
<refname>mcal_event_set_end</refname>
<refpurpose>
Sets the end date and time of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_event_set_end</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int
<parameter>
<optional>day</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>hour</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>min</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>sec</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_end</function> sets the streams global
event structure's end date and time to the given values.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-alarm">
<refnamediv>
<refname>mcal_event_set_alarm</refname>
<refpurpose>
Sets the alarm of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_event_set_alarm</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>alarm</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_alarm</function> sets the streams global
event structure's alarm to the given minutes before the event.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-class">
<refnamediv>
<refname>mcal_event_set_class</refname>
<refpurpose>
Sets the class of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_event_set_class</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>class</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_class</function> sets the streams global
event structure's class to the given value. The class is either 1
for public, or 0 for private.
</para>
<para>
Returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-is-leap-year">
<refnamediv>
<refname>mcal_is_leap_year</refname>
<refpurpose>
Returns if the given year is a leap year or not
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_is_leap_year</function></funcdef>
<paramdef>int <parameter>year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_is_leap_year</function> returns 1 if the given
year is a leap year, 0 if not.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-days-in-month">
<refnamediv>
<refname>mcal_days_in_month</refname>
<refpurpose>
Returns the number of days in the given month
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_days_in_month</function></funcdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>leap year</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_days_in_month</function> Returns the number of
days in the given month, taking into account if the given year is
a leap year or not.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-date-valid">
<refnamediv>
<refname>mcal_date_valid</refname>
<refpurpose>
Returns true if the given year, month, day is a valid date
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_date_valid</function></funcdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_date_valid</function> Returns true if the given
year, month and day is a valid date, false if not.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-time-valid">
<refnamediv>
<refname>mcal_time_valid</refname>
<refpurpose>
Returns true if the given year, month, day is a valid time
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_time_valid</function></funcdef>
<paramdef>int <parameter>hour</parameter></paramdef>
<paramdef>int <parameter>minutes</parameter></paramdef>
<paramdef>int <parameter>seconds</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_time_valid</function> Returns true if the given
hour, minutes and seconds is a valid time, false if not.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-day-of-week">
<refnamediv>
<refname>mcal_day_of_week</refname>
<refpurpose>
Returns the day of the week of the given date
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_</function></funcdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_day_of_week</function> returns the day of the week
of the given date.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-day-of-year">
<refnamediv>
<refname>mcal_day_of_year</refname>
<refpurpose>
Returns the day of the year of the given date
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_</function></funcdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_day_of_year</function> returns the day of the year
of the given date.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-date-compare">
<refnamediv>
<refname>mcal_date_compare</refname>
<refpurpose>Compares two dates</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_date_compare</function></funcdef>
<paramdef>int <parameter>a_year</parameter></paramdef>
<paramdef>int <parameter>a_month</parameter></paramdef>
<paramdef>int <parameter>a_day</parameter></paramdef>
<paramdef>int <parameter>b_year</parameter></paramdef>
<paramdef>int <parameter>b_month</parameter></paramdef>
<paramdef>int <parameter>b_day</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_date_compare</function> Compares the two given
dates, returns <0, 0, >0 if a<b, a==b, a>b respectively.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-next-recurrence">
<refnamediv>
<refname>mcal_next_recurrence</refname>
<refpurpose>Returns the next recurrence of the event</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcal_next_recurrence</function></funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>weekstart</parameter></paramdef>
<paramdef>array <parameter>next</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_next_recurrence</function> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-recur-none">
<refnamediv>
<refname>mcal_event_set_recur_none</refname>
<refpurpose>
Sets the recurrence of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_event_set_recur_none</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_recur_none</function> sets the streams
global event structure to not recur (event->recur_type is set to
MCAL_RECUR_NONE).
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-recur-daily">
<refnamediv>
<refname>mcal_event_set_recur_daily</refname>
<refpurpose>
Sets the recurrence of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_event_set_recur_daily</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>interval</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_recur_daily</function> sets the streams
global event structure's recurrence to the given value to be
reoccuring on a daily basis, ending at the given date.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-recur-weekly">
<refnamediv>
<refname>mcal_event_set_recur_weekly</refname>
<refpurpose>
Sets the recurrence of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_event_set_recur_weekly</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>interval</parameter></paramdef>
<paramdef>int <parameter>weekdays</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_recur_weekly</function> sets the streams
global event structure's recurrence to the given value to be
reoccuring on a weekly basis, ending at the given date.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-recur-monthly-mday">
<refnamediv>
<refname>mcal_event_set_recur_monthly_mday</refname>
<refpurpose>
Sets the recurrence of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_event_set_recur_monthly_mday</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>interval</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_recur_monthly_mday</function> sets the
streams global event structure's recurrence to the given value to
be reoccuring on a monthly by month day basis, ending at the
given date.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-recur-monthly-wday">
<refnamediv>
<refname>mcal_event_set_recur_monthly_wday</refname>
<refpurpose>
Sets the recurrence of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_event_set_recur_monthly_wday</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>interval</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_recur_monthly_wday</function> sets the
streams global event structure's recurrence to the given value to
be reoccuring on a monthly by week basis, ending at the given
date.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-set-recur-yearly">
<refnamediv>
<refname>mcal_event_set_recur_yearly</refname>
<refpurpose>
Sets the recurrence of the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_event_set_recur_yearly</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>int <parameter>year</parameter></paramdef>
<paramdef>int <parameter>month</parameter></paramdef>
<paramdef>int <parameter>day</parameter></paramdef>
<paramdef>int <parameter>interval</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_set_recur_yearly</function> sets the streams
global event structure's recurrence to the given value to be
reoccuring on a yearly basis,ending at the given date.
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-fetch-current-stream-event">
<refnamediv>
<refname>mcal_fetch_current_stream_event</refname>
<refpurpose>
Returns an object containing the current streams event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_fetch_current_stream_event</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_fetch_current_stream_event</function>
returns the current stream's event structure as an object
containing:
<itemizedlist>
<listitem><simpara>
int id - ID of that event.</simpara></listitem>
<listitem><simpara>
int public - TRUE if the event if public, FALSE if it is
private.</simpara></listitem>
<listitem><simpara>
string category - Category string of the event.</simpara></listitem>
<listitem><simpara>
string title - Title string of the event.</simpara></listitem>
<listitem><simpara>
string description - Description string of the event.</simpara></listitem>
<listitem><simpara>
int alarm - number of minutes before the event to send an
alarm/reminder.</simpara></listitem>
<listitem><simpara>
object start - Object containing a datetime entry.</simpara></listitem>
<listitem><simpara>
object end - Object containing a datetime entry.</simpara></listitem>
<listitem><simpara>
int recur_type - recurrence type</simpara></listitem>
<listitem><simpara>
int recur_interval - recurrence interval</simpara></listitem>
<listitem><simpara>
datetime recur_enddate - recurrence end date</simpara></listitem>
<listitem><simpara>
int recur_data - recurrence data</simpara></listitem>
</itemizedlist>
All datetime entries consist of an object that contains:
<itemizedlist>
<listitem><simpara>
int year - year</simpara></listitem>
<listitem><simpara>
int month - month</simpara></listitem>
<listitem><simpara>
int mday - day of month</simpara></listitem>
<listitem><simpara>
int hour - hour</simpara></listitem>
<listitem><simpara>
int min - minutes</simpara></listitem>
<listitem><simpara>
int sec - seconds</simpara></listitem>
<listitem><simpara>
int alarm - minutes before event to send an alarm</simpara></listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-event-add-attribute">
<refnamediv>
<refname>mcal_event_add_attribute</refname>
<refpurpose>
Adds an attribute and a value to the streams global event structure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>mcal_event_add_attribute</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
<paramdef>string <parameter>attribute</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_event_add_attribute</function> adds an attribute
to the stream's global event structure with the value given by
"value".
</para>
</refsect1>
</refentry>
<refentry id="function.mcal-expunge">
<refnamediv>
<refname>mcal_expunge</refname>
<refpurpose>
Deletes all events marked for being expunged.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcal_expunge</function>
</funcdef>
<paramdef>int <parameter>stream</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mcal_expunge</function> Deletes all events which have
been previously marked for deletion.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/mcrypt.xml
+++ phpdoc/nl/functions/mcrypt.xml
<reference id="ref.mcrypt">
<title>Mcrypt Encryption Functions</title>
<titleabbrev>mcrypt</titleabbrev>
<partintro>
<para>
These functions work using <ulink
url="&url.mcrypt;">mcrypt</ulink>.
</para>
<para>
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".
</para>
<para>
If you linked against libmcrypt 2.4.x, 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 another cipher mode is also
available; nOFB.
</para>
<para>
To use it, download libmcrypt-x.x.tar.gz from <ulink
url="&url.mcrypt;">here</ulink> and follow the included
installation instructions. You need to compile PHP with the
<option role="configure">--with-mcrypt</option> parameter to
enable this extension. Make sure you compile libmcrypt with the
option <option role="configure">--disable-posix-threads</option>.
</para>
<para>
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 (<function>mcrypt_cfb</function>,
<function>mcrypt_cbc</function>, <function>mcrypt_ecb</function>,
and <function>mcrypt_ofb</function>) can operate in both modes
which are named MCRYPT_ENCRYPT and MCRYPT_DECRYPT, respectively.
<example>
<title>Encrypt an input value with TripleDES in ECB mode</title>
<programlisting role="php">
<?php
$key = "this is a very secret key";
$input = "Let us meet at 9 o'clock at the secret place.";
$encrypted_data = mcrypt_ecb (MCRYPT_TripleDES, $key, $input, MCRYPT_ENCRYPT);
?>
</programlisting>
</example>
This example will give you the encrypted data as a string in
<literal>$encrypted_data</literal>.
</para>
<para>
If you linked against libmcrypt 2.4.x, these functions are still
available, but it is recommended that you use the advanced functions.
<example>
<title>Encrypt an input value with TripleDES in ECB mode</title>
<programlisting role="php">
<?php
$key = "this is a very secret key";
$input = "Let us meet at 9 o'clock at the secret place.";
$td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
mcrypt_generic_init ($td, $key, $iv);
$encrypted_data = mcrypt_generic ($td, $input);
mcrypt_generic_end ($td);
?>
</programlisting>
</example>
This example will give you the encrypted data as a string in
<literal>$encrypted_data</literal>.
</para>
<para>
Mcrypt can operate in four block cipher modes (CBC, OFB, CFB, and
ECB). If linked against libmcrypt-2.4.x mcrypt can also operate
in the block cipher mode nOFB and in STREAM mode. Then there are
also constants in the form MCRYPT_MODE_mode for use with several
functions. We will outline the normal use for each of these modes.
For a more complete reference and discussion see
&book.applied.cryptography;.
<itemizedlist>
<listitem>
<simpara>
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.
</simpara>
</listitem>
<listitem>
<simpara>
CBC (cipher block chaining) is especially suitable for
encrypting files where the security is increased over ECB
significantly.
</simpara>
</listitem>
<listitem>
<simpara>
CFB (cipher feedback) is the best mode for encrypting byte
streams where single bytes must be encrypted.
</simpara>
</listitem>
<listitem>
<simpara>
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.
</simpara>
</listitem>
<listitem>
<simpara>
nOFB (output feedback, in nbit) is comparable to OFB, but
more secure because it operates on the block size of the
algorithm.
</simpara>
</listitem>
<listitem>
<simpara>
STREAM is an extra mode to include some stream algorithms
like WAKE or RC4.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
PHP does not support encrypting/decrypting bit streams
currently. As of now, PHP only supports handling of strings.
</para>
<para>
For a complete list of supported ciphers, see the defines at the
end of <filename>mcrypt.h</filename>. The general rule with the
mcrypt-2.2.x API is that you can access the cipher from PHP with
MCRYPT_ciphername. With the mcrypt-2.4.x API these constants also
work, but it is possible to specify the name of the cipher as
a string with a call to <function>mcrypt_module_open</function>.
</para>
<para>
Here is a short list of ciphers which are currently supported by
the mcrypt extension. If a cipher is not listed here, but is
listed by mcrypt as supported, you can safely assume that this
documentation is outdated.
<itemizedlist>
<listitem>
<simpara>
MCRYPT_ARCFOUR_IV (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_ARCFOUR (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_BLOWFISH
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_CAST_128
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_CAST_256
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_CRYPT
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_DES
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_DES_COMPAT (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_ENIGMA (libmcrypt 2.4.x only, alias for MCRYPT_CRYPT)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_GOST
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_IDEA (non-free)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_LOKI97 (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_MARS (libmcrypt 2.4.x only, non-free)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_PANAMA (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RIJNDAEL_128 (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RIJNDAEL_192 (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RIJNDAEL_256 (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RC2
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RC4 (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RC6 (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RC6_128 (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RC6_192 (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_RC6_256 (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SAFER64
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SAFER128
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SAFERPLUS (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SERPENT (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SERPENT_128 (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SERPENT_192 (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SERPENT_256 (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_SKIPJACK (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_TEAN (libmcrypt 2.2.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_THREEWAY
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_TRIPLEDES
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_TWOFISH (for older mcrypt 2.x versions, or mcrypt 2.4.x )
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_TWOFISH128 (TWOFISHxxx are available in newer 2.x versions, but not in the 2.4.x
versions)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_TWOFISH192
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_TWOFISH256
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_WAKE (libmcrypt 2.4.x only)
</simpara>
</listitem>
<listitem>
<simpara>
MCRYPT_XTEA (libmcrypt 2.4.x only)
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
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 &book.applied.cryptography; for a
discussion of this topic).
</para>
</partintro>
<refentry id="function.mcrypt-get-cipher-name">
<refnamediv>
<refname>mcrypt_get_cipher_name</refname>
<refpurpose>Get the name of the specified cipher</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_get_cipher_name</function></funcdef>
<paramdef>int <parameter>cipher</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_get_cipher_name</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mcrypt_get_cipher_name</function> is used to get the
name of the specified cipher.
</para>
<para>
<function>Mcrypt_get_cipher_name</function> takes the cipher
number as an argument (libmcrypt 2.2.x) or takes the cipher name
as an argument (libmcrypt 2.4.x) and returns the name of the cipher
or false, if the cipher does not exist.
</para>
<para>
<example>
<title><function>Mcrypt_get_cipher_name</function> Example</title>
<programlisting role="php">
<?php
$cipher = MCRYPT_TripleDES;
print mcrypt_get_cipher_name ($cipher);
?>
</programlisting>
</example>
</para>
<para>
The above example will produce:
<programlisting>
TripleDES
</programlisting>
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-get-block-size">
<refnamediv>
<refname>mcrypt_get_block_size</refname>
<refpurpose>Get the block size of the specified cipher</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_get_block_size</function></funcdef>
<paramdef>int <parameter>cipher</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>mcrypt_get_block_size</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>module</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first prototype is when linked against libmcrypt 2.2.x, the
second when linked against libmcrypt 2.4.x.
</para>
<para>
<function>Mcrypt_get_block_size</function> is used to get the
size of a block of the specified <parameter>cipher</parameter>.
</para>
<para>
<function>Mcrypt_get_block_size</function> takes one or two
arguments, the <parameter>cipher</parameter> and
<parameter>module</parameter>, and returns the size in bytes.
</para>
<para>
See also: <function>mcrypt_get_key_size</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-get-key-size">
<refnamediv>
<refname>mcrypt_get_key_size</refname>
<refpurpose>Get the key size of the specified cipher</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_get_key_size</function></funcdef>
<paramdef>int <parameter>cipher</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>mcrypt_get_key_size</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>module</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first prototype is when linked against libmcrypt 2.2.x, the
second when linked against libmcrypt 2.4.x.
</para>
<para>
<function>Mcrypt_get_key_size</function> is used to get the size
of a key of the specified <parameter>cipher</parameter>.
</para>
<para>
<function>Mcrypt_get_key_size</function> takes one or two
arguments, the <parameter>cipher</parameter> and
<parameter>module</parameter>, and returns the size in bytes.
</para>
<para>
See also: <function>mcrypt_get_block_size</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-create-iv">
<refnamediv>
<refname>mcrypt_create_iv</refname>
<refpurpose>
Create an initialization vector (IV) from a random source
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>mcrypt_create_iv</function></funcdef>
<paramdef>int <parameter>size</parameter></paramdef>
<paramdef>int <parameter>source</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mcrypt_create_iv</function> is used to create an IV.
</para>
<para>
<function>mcrypt_create_iv</function> takes two arguments,
<parameter>size</parameter> determines the size of the IV,
<parameter>source</parameter> specifies the source of the IV.
</para>
<para>
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.
</para>
<para>
<example>
<title><function>Mcrypt_create_iv</function> example</title>
<programlisting role="php">
<?php
$cipher = MCRYPT_TripleDES;
$block_size = mcrypt_get_block_size ($cipher);
$iv = mcrypt_create_iv ($block_size, MCRYPT_DEV_RANDOM);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-cbc">
<refnamediv>
<refname>mcrypt_cbc</refname>
<refpurpose>Encrypt/decrypt data in CBC mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_cbc</function></funcdef>
<paramdef>int <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter><optional>iv</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_cbc</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter><optional>iv</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first prototype is when linked against libmcrypt 2.2.x, the
second when linked against libmcrypt 2.4.x.
</para>
<para>
<function>Mcrypt_cbc</function> encrypts or decrypts (depending
on <parameter>mode</parameter>) the <parameter>data</parameter>
with <parameter>cipher</parameter> and <parameter>key</parameter>
in CBC cipher mode and returns the resulting string.
</para>
<para>
<parameter>Cipher</parameter> is one of the MCRYPT_ciphername
constants.
</para>
<para>
<parameter>Key</parameter> is the key supplied to the
algorithm. It must be kept secret.
</para>
<para>
<parameter>Data</parameter> is the data which shall be
encrypted/decrypted.
</para>
<para>
<parameter>Mode</parameter> is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
</para>
<para>
<parameter>IV</parameter> is the optional initialization vector.
</para>
<para>
See also: <function>mcrypt_cfb</function>,
<function>mcrypt_ecb</function>, and
<function>mcrypt_ofb</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-cfb">
<refnamediv>
<refname>mcrypt_cfb</refname>
<refpurpose>Encrypt/decrypt data in CFB mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_cfb</function></funcdef>
<paramdef>int <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string <parameter>iv</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_cfb</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter><optional>iv</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first prototype is when linked against libmcrypt 2.2.x, the
second when linked against libmcrypt 2.4.x.
</para>
<para>
<function>Mcrypt_cfb</function> encrypts or decrypts (depending
on <parameter>mode</parameter>) the <parameter>data</parameter>
with <parameter>cipher</parameter> and <parameter>key</parameter>
in CFB cipher mode and returns the resulting string.
</para>
<para>
<parameter>Cipher</parameter> is one of the MCRYPT_ciphername
constants.
</para>
<para>
<parameter>Key</parameter> is the key supplied to the
algorithm. It must be kept secret.
</para>
<para>
<parameter>Data</parameter> is the data which shall be
encrypted/decrypted.
</para>
<para>
<parameter>Mode</parameter> is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
</para>
<para>
<parameter>IV</parameter> is the initialization vector.
</para>
<para>
See also: <function>mcrypt_cbc</function>,
<function>mcrypt_ecb</function>, and
<function>mcrypt_ofb</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-ecb">
<refnamediv>
<refname>mcrypt_ecb</refname>
<refpurpose>Encrypt/decrypt data in ECB mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_ecb</function></funcdef>
<paramdef>int <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_ecb</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter><optional>iv</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first prototype is when linked against libmcrypt 2.2.x, the
second when linked against libmcrypt 2.4.x.
</para>
<para>
<function>Mcrypt_ecb</function> encrypts or decrypts (depending
on <parameter>mode</parameter>) the <parameter>data</parameter>
with <parameter>cipher</parameter> and <parameter>key</parameter>
in ECB cipher mode and returns the resulting string.
</para>
<para>
<parameter>Cipher</parameter> is one of the MCRYPT_ciphername
constants.
</para>
<para>
<parameter>Key</parameter> is the key supplied to the
algorithm. It must be kept secret.
</para>
<para>
<parameter>Data</parameter> is the data which shall be
encrypted/decrypted.
</para>
<para>
<parameter>Mode</parameter> is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
</para>
<para>
See also: <function>mcrypt_cbc</function>,
<function>mcrypt_cfb</function>, and
<function>mcrypt_ofb</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-ofb">
<refnamediv>
<refname>mcrypt_ofb</refname>
<refpurpose>Encrypt/decrypt data in OFB mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_ofb</function></funcdef>
<paramdef>int <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string <parameter>iv</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_ofb</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter><optional>iv</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first prototype is when linked against libmcrypt 2.2.x, the
second when linked against libmcrypt 2.4.x.
</para>
<para>
<function>Mcrypt_ofb</function> encrypts or decrypts (depending
on <parameter>mode</parameter>) the <parameter>data</parameter>
with <parameter>cipher</parameter> and <parameter>key</parameter>
in OFB cipher mode and returns the resulting string.
</para>
<para>
<parameter>Cipher</parameter> is one of the MCRYPT_ciphername
constants.
</para>
<para>
<parameter>Key</parameter> is the key supplied to the
algorithm. It must be kept secret.
</para>
<para>
<parameter>Data</parameter> is the data which shall be
encrypted/decrypted.
</para>
<para>
<parameter>Mode</parameter> is MCRYPT_ENCRYPT or MCRYPT_DECRYPT.
</para>
<para>
<parameter>IV</parameter> is the initialization vector.
</para>
<para>
See also: <function>mcrypt_cbc</function>,
<function>mcrypt_cfb</function>, and
<function>mcrypt_ecb</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-list-algorithms">
<refnamediv>
<refname>mcrypt_list_algorithms</refname>
<refpurpose>Get an array of all supported ciphers</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mcrypt_list_algorithms</function></funcdef>
<paramdef>string
<parameter>
<optional>lib_dir</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mcrypt_list_algorithms</function> is used to get an
array of all supported algorithms in the
</para>
<para>
<parameter>lib_dir</parameter>.
<function>Mcrypt_list_algorithms</function> takes as optional
parameter a directory which specifies the directory where all
algorithms are located. If not specifies, the value of the
mcrypt.algorithms_dir php.ini directive is used.
</para>
<para>
<example>
<title><function>Mcrypt_list_algorithms</function> Example</title>
<programlisting role="php">
<?php
$algorithms = mcrypt_list_algorithms ("/usr/local/lib/libmcrypt");
foreach ($algorithms as $cipher) {
echo $cipher."/n";
}
?>
</programlisting>
</example>
</para>
<para>
The above example will produce a list with all supported
algorithms in the "/usr/local/lib/libmcrypt" directory.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-list-modes">
<refnamediv>
<refname>mcrypt_list_modes</refname>
<refpurpose>Get an array of all supported modes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mcrypt_list_modes</function></funcdef>
<paramdef>string
<parameter>
<optional>lib_dir</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mcrypt_list_modes</function> is used to get an
array of all supported modes in the
<parameter>lib_dir</parameter>.
</para>
<para>
<function>Mcrypt_list_modes</function> 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.
</para>
<para>
<example>
<title><function>Mcrypt_list_modes</function> Example</title>
<programlisting role="php">
<?php
$modes = mcrypt_list_modes ();
foreach ($modes as $mode) {
echo $mode."/n";
}
?>
</programlisting>
</example>
</para>
<para>
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).
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-get-iv-size">
<refnamediv>
<refname>mcrypt_get_iv_size</refname>
<refpurpose>Returns the size of the IV belonging to a specific cipher/mode
combination</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_get_iv_size</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>mcrypt_get_iv_size</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first prototype is when linked against libmcrypt 2.2.x, the
second when linked against libmcrypt 2.4.x.
</para>
<para>
<function>Mcrypt_get_iv_size</function> 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.
</para>
<para>
<parameter>Cipher</parameter> is one of the MCRYPT_ciphername
constants of the name of the algorithm as string.
</para>
<para>
<parameter>Mode</parameter> is one of the MCRYPT_MODE_modename
constants of one of "ecb", "cbc", "cfb", "ofb",
"nofb" or
"stream".
</para>
<para>
<parameter>Td</parameter> is the algorithm specified.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-encrypt">
<refnamediv>
<refname>mcrypt_encrypt</refname>
<refpurpose>Encrypts plaintext with given parameters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_encrypt</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter>
<optional>iv</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mcrypt_encrypt</function> encrypts the data
and returns the encrypted data.
</para>
<para>
<parameter>Cipher</parameter> is one of the MCRYPT_ciphername
constants of the name of the algorithm as string.
</para>
<para>
<parameter>Key</parameter> is the key with which the data
will be encrypted. If it's smaller that the required keysize, it
is padded with '\0'.
</para>
<para>
<parameter>Data</parameter> 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 <parameter>data</parameter>.
</para>
<para>
<parameter>Mode</parameter> is one of the MCRYPT_MODE_modename
constants of one of "ecb", "cbc", "cfb", "ofb",
"nofb" or
"stream".
</para>
<para>
The <parameter>IV</parameter> 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'.
</para>
<para>
<example>
<title><function>Mcrypt_encrypt</function> Example</title>
<programlisting role="php">
<?php
$iv = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$key = "This is a very secret key";
$text = "Meet me at 11 o'clock behind the monument.";
echo strlen ($text)."\n";
$crypttext = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
echo strlen ($crypttext)."\n";
?>
</programlisting>
</example>
The above example will print out:
<programlisting>
42
64
</programlisting>
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-decrypt">
<refnamediv>
<refname>mcrypt_decrypt</refname>
<refpurpose>Decrypts crypttext with given parameters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_decrypt</function></funcdef>
<paramdef>string <parameter>cipher</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter>
<optional>iv</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mcrypt_decrypt</function> decrypts the data
and returns the unencrypted data.
</para>
<para>
<parameter>Cipher</parameter> is one of the MCRYPT_ciphername
constants of the name of the algorithm as string.
</para>
<para>
<parameter>Key</parameter> is the key with which the data
is encrypted. If it's smaller that the required keysize, it
is padded with '\0'.
</para>
<para>
<parameter>Data</parameter> 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'.
</para>
<para>
<parameter>Mode</parameter> is one of the MCRYPT_MODE_modename
constants of one of "ecb", "cbc", "cfb", "ofb",
"nofb" or
"stream".
</para>
<para>
The <parameter>IV</parameter> 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'.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-open">
<refnamediv>
<refname>mcrypt_module_open</refname>
<refpurpose>This function opens the module of the algorithm and the mode to be
used</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>resource <function>mcrypt_module_open</function></funcdef>
<paramdef>string <parameter>algorithm</parameter></paramdef>
<paramdef>string <parameter>algorithm_directory</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>string <parameter>mode_directory</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function opens the module of the algorithm and the mode
to be used. The name of the algorithm is specified in algorithm,
eg "twofish" or is one of the MCRYPT_ciphername constants.
The library is closed by calling
<function>mcrypt_module_close</function>, but there is no need
to call that function if <function>mcrypt_generic_end</function>
is called. Normally it returns an encryption descriptor, or
FALSE on error.
</para>
<para>
The <parameter>algorithm_directory</parameter> and
<parameter>mode_directory</parameter> 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 <parameter>mcrypt.algorithms_dir</parameter> or
<parameter>mcrypt.modes_dir</parameter> ini-directive is used.
When these are not set, the default directory are used that are
compiled in into libmcrypt (usally /usr/local/lib/libmcrypt).
</para>
<para>
<example>
<title><function>Mcrypt_module_open</function> Example</title>
<programlisting role="php">
<?php
$td = mcrypt_module_open (MCRYPT_DES, "", MCRYPT_MODE_ECB,
"/usr/lib/mcrypt-modes");
?>
</programlisting>
</example>
The above example will try to open the DES cipher from the default
directory and the EBC mode from the directory /usr/lib/mcrypt-modes.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-generic-init">
<refnamediv>
<refname>mcrypt_generic_init</refname>
<refpurpose>This function initializes all buffers needed for encryption</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_generic_init</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
<paramdef>string <parameter>iv</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The maximum length of the key should be the one obtained by
calling <function>mcrypt_enc_get_key_size</function> 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 <function>mcrypt_enc_get_iv_size</function>.
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 (-1) on error.
</para>
<para>
You need to call this function before every
<function>mcrypt_generic</function> or
<function>mdecrypt_generic</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-generic">
<refnamediv>
<refname>mcrypt_generic</refname>
<refpurpose>This function encrypts data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_generic</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.mdecrypt-generic">
<refnamediv>
<refname>mdecrypt_generic</refname>
<refpurpose>This function decrypts data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mdecrypt_generic</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
<para>
<example>
<title><function>Mdecrypt_generic</function> Example</title>
<programlisting role="php">
<?php
$iv_size = mcrypt_enc_get_iv_size ($td));
$iv = @mcrypt_create_iv ($iv_size, MCRYPT_RAND);
if (@mcrypt_generic_init ($td, $key, $iv) != -1)
{
$c_t = mcrypt_generic ($td, $plain_text);
@mcrypt_generic_init ($td, $key, $iv);
$p_t = mdecrypt_generic ($td, $c_t);
}
if (strncmp ($p_t, $plain_text, strlen($plain_text)) == 0)
echo "ok";
else
echo "error";
?>
</programlisting>
</example>
The above example shows how to check if the data before the
encryption is the same as the data after the decryption.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-generic-end">
<refnamediv>
<refname>mcrypt_generic_end</refname>
<refpurpose>This function terminates encryption</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>mcrypt_generic_end</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 succes.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-self-test">
<refnamediv>
<refname>mcrypt_enc_self_test</refname>
<refpurpose>This function runs a self test on the opened module</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_enc_self_test</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function runs the self test on the algorithm specified by the
descriptor td. If the self test succeeds it returns zero. In case
of an error, it returns 1.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-is-block-algorithm-mode">
<refnamediv>
<refname>mcrypt_enc_is_block_algorithm_mode</refname>
<refpurpose>Checks whether the encryption of the opened mode works on
blocks</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcrypt_enc_is_block_algorithm_mode</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns 1 if the mode is for use with block algorithms,
otherwise it returns 0. (eg. 0 for stream, and 1 for cbc, cfb, ofb).
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-is-block-algorithm">
<refnamediv>
<refname>mcrypt_enc_is_block_algorithm</refname>
<refpurpose>Checks whether the algorithm of the opened mode is a block
algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcrypt_enc_is_block_algorithm</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns 1 if the algorithm is a block algorithm,
or 0 if it is a stream algorithm.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-is-block-mode">
<refnamediv>
<refname>mcrypt_enc_is_block_mode</refname>
<refpurpose>Checks whether the opened mode outputs blocks</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_enc_is_block_mode</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns 1 if the mode outputs blocks of bytes or
0 if it outputs bytes. (eg. 1 for cbc and ecb, and 0 for cfb and
stream).
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-get-block-size">
<refnamediv>
<refname>mcrypt_enc_get_block_size</refname>
<refpurpose>Returns the blocksize of the opened algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_enc_get_block_size</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the block size of the algorithm specified by
the encryption descriptor td in bytes.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-get-key-size">
<refnamediv>
<refname>mcrypt_enc_get_key_size</refname>
<refpurpose>Returns the maximum supported keysize of the opened mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_enc_get_key_size</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the maximum supported key size of the
algorithm specified by the encryption descriptor td in bytes.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-get-supported-key-sizes">
<refnamediv>
<refname>mcrypt_enc_get_supported_key_sizes</refname>
<refpurpose>Returns an array with the supported keysizes of the opened
algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array
<function>mcrypt_enc_get_supported_key_sizes</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns 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
<function>mcrypt_enc_get_key_size</function> are supported by the
algorithm.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-get-iv-size">
<refnamediv>
<refname>mcrypt_enc_get_iv_size</refname>
<refpurpose>Returns the size of the IV of the opened algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mcrypt_enc_get_iv_size</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-get-algorithms-name">
<refnamediv>
<refname>mcrypt_enc_get_algorithms_name</refname>
<refpurpose>Returns the name of the opened algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>mcrypt_enc_get_algorithms_name</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the name of the algorithm.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-enc-get-modes-name">
<refnamediv>
<refname>mcrypt_enc_get_modes_name</refname>
<refpurpose>Returns the name of the opened mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>mcrypt_enc_get_modes_name</function></funcdef>
<paramdef>resource <parameter>td</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the name of the mode.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-self-test">
<refnamediv>
<refname>mcrypt_module_self_test</refname>
<refpurpose>This function runs a self test on the specified module</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>mcrypt_module_self_test</function></funcdef>
<paramdef>string <parameter>algorithm</parameter></paramdef>
<paramdef>string
<parameter><optional>lib_dir</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function runs the self test on the algorithm specified.
The optional <parameter>lib_dir</parameter> parameter can contain
the location of where the algorithm module is on the system.
</para>
<para>
The function returns TRUE if the self test succeeds, or FALSE when
if fails.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-is-block-algorithm-mode">
<refnamediv>
<refname>mcrypt_module_is_block_algorithm_mode</refname>
<refpurpose>This function returns if the the specified module is a block algorithm or
not</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>mcrypt_module_is_block_algorithm_mode</function></funcdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter><optional>lib_dir</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns TRUE if the mode is for use with block algorithms,
otherwise it returns 0. (eg. 0 for stream, and 1 for cbc, cfb, ofb).
The optional <parameter>lib_dir</parameter> parameter can contain
the location where the mode module is on the system.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-is-block-algorithm">
<refnamediv>
<refname>mcrypt_module_is_block_algorithm</refname>
<refpurpose>This function checks whether the specified algorithm is a block
algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>mcrypt_module_is_block_algorithm</function></funcdef>
<paramdef>string <parameter>algorithm</parameter></paramdef>
<paramdef>string
<parameter><optional>lib_dir</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns TRUE if the specified algorithm is a block
algorithm, or FALSE is it is a stream algorithm.
The optional <parameter>lib_dir</parameter> parameter can contain
the location where the algorithm module is on the system.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-is-block-mode">
<refnamediv>
<refname>mcrypt_module_is_block_mode</refname>
<refpurpose>This function returns if the the specified mode outputs blocks or
not</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>mcrypt_module_is_block_mode</function></funcdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>string
<parameter><optional>lib_dir</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns TRUE if the mode outputs blocks of bytes or
FALSE if it outputs just bytes. (eg. 1 for cbc and ecb, and 0 for cfb
and stream). The optional <parameter>lib_dir</parameter> parameter
can contain the location where the mode module is on the system.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-get-algo-block-size">
<refnamediv>
<refname>mcrypt_module_get_algo_block_size</refname>
<refpurpose>Returns the blocksize of the specified algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcrypt_module_get_algo_block_size</function></funcdef>
<paramdef>string <parameter>algorithm</parameter></paramdef>
<paramdef>string
<parameter><optional>lib_dir</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the block size of the algorithm specified in
bytes. The optional <parameter>lib_dir</parameter> parameter
can contain the location where the mode module is on the system.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-get-algo-key-size">
<refnamediv>
<refname>mcrypt_module_get_algo_key_size</refname>
<refpurpose>Returns the maximum supported keysize of the opened mode</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>mcrypt_module_get_algo_key_size</function></funcdef>
<paramdef>string <parameter>algorithm</parameter></paramdef>
<paramdef>string
<parameter><optional>lib_dir</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the maximum supported key size of the
algorithm specified in bytes. The optional
<parameter>lib_dir</parameter> parameter can contain the
location where the mode module is on the system.
</para>
</refsect1>
</refentry>
<refentry id="function.mcrypt-module-get-algo-supported-key-sizes">
<refnamediv>
<refname>mcrypt_module_get_algo_supported_key_sizes</refname>
<refpurpose>Returns an array with the supported keysizes of the opened
algorithm</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array
<function>mcrypt_module_enc_get_algo_supported_key_sizes</function></funcdef>
<paramdef>string <parameter>algorithm</parameter></paramdef>
<paramdef>string
<parameter><optional>lib_dir</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array with the key sizes supported by the specified
algorithm. If it returns an empty array then all key sizes
between 1 and <function>mcrypt_module_get_algo_key_size</function>
are supported by the algorithm. The optional
<parameter>lib_dir</parameter> parameter can contain the
location where the mode module is on the system.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/mhash.xml
+++ phpdoc/nl/functions/mhash.xml
<reference id="ref.mhash">
<title>Mhash Functions</title>
<titleabbrev>mhash</titleabbrev>
<partintro>
<para>
These functions are intended to work with <ulink
url="&url.mhash;">mhash</ulink>.</para>
<para>
This is an interface to the mhash library. mhash supports a wide
variety of hash algorithms such as MD5, SHA1, GOST, and many
others.
</para>
<para>
To use it, download the mhash distribution from <ulink
url="&url.mhash;">its web site</ulink> and follow the included
installation instructions. You need to compile PHP with the
<option role="configure">--with-mhash</option> parameter to enable
this extension.
</para>
<para>
Mhash can be used to create checksums, message digests, and
more.
</para>
<para>
<example>
<title>Compute the SHA1 key and print it out as hex</title>
<programlisting role="php">
<?php
$input = "Let us meet at 9 o' clock at the secret place.";
$hash = mhash (MHASH_SHA1, $input);
print "The hash is ".bin2hex ($hash)."\n";
?>
</programlisting>
</example>
This will produce:
<programlisting>
The hash is d3b85d710d8f6e4e5efd4d5e67d041f9cecedafe
</programlisting>
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 HAVAL you use the PHP constant MHASH_HAVAL.
</para>
<para>
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.
<itemizedlist>
<listitem>
<simpara>
MHASH_MD5
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_SHA1
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_HAVAL
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_RIPEMD160
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_RIPEMD128
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_SNEFRU
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_TIGER
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_GOST
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_CRC32
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_CRC32B
</simpara>
</listitem>
</itemizedlist>
</para>
</partintro>
<refentry id="function.mhash-get-hash-name">
<refnamediv>
<refname>mhash_get_hash_name</refname>
<refpurpose>Get the name of the specified hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mhash_get_hash_name</function></funcdef>
<paramdef>int <parameter>hash</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mhash_get_hash_name</function> is used to get the name
of the specified hash.
</para>
<para>
<function>mhash_get_hash_name</function> takes the hash id as an
argument and returns the name of the hash or false, if the hash
does not exist.
</para>
<para>
<example>
<title><function>Mhash_get_hash_name</function> Example</title>
<programlisting>
<?php
$hash = MHASH_MD5;
print mhash_get_hash_name ($hash);
?>
</programlisting>
</example>
The above example will print out:
<programlisting>
MD5
</programlisting>
</para>
</refsect1>
</refentry>
<refentry id="function.mhash-get-block-size">
<refnamediv>
<refname>mhash_get_block_size</refname>
<refpurpose>Get the block size of the specified hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mhash_get_block_size</function></funcdef>
<paramdef>int <parameter>hash</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mhash_get_block_size</function> is used to get the size
of a block of the specified <parameter>hash</parameter>.
</para>
<para>
<function>Mhash_get_block_size</function> takes one argument, the
<parameter>hash</parameter> and returns the size in bytes or
false, if the <parameter>hash</parameter> does not exist.
</para>
</refsect1>
</refentry>
<refentry id="function.mhash-count">
<refnamediv>
<refname>mhash_count</refname>
<refpurpose>Get the highest available hash id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mhash_count</function></funcdef>
<paramdef>void </paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mhash_count</function> returns the highest available hash
id. Hashes are numbered from 0 to this hash id.
</para>
<para>
<example>
<title>Traversing all hashes</title>
<programlisting role="php">
<?php
$nr = mhash_count();
for ($i = 0; $i <= $nr; $i++) {
echo sprintf ("The blocksize of %s is %d\n",
mhash_get_hash_name ($i),
mhash_get_block_size ($i));
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.mhash">
<refnamediv>
<refname>mhash</refname>
<refpurpose>Compute hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mhash</function></funcdef>
<paramdef>int <parameter>hash</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mhash</function> applies a hash function specified by
<parameter>hash</parameter> to the <parameter>data</parameter> and
returns the resulting hash (also called digest).
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/misc.xml
+++ phpdoc/nl/functions/misc.xml
<reference id="ref.misc">
<title>Miscellaneous functions</title>
<titleabbrev>Misc.</titleabbrev>
<partintro>
<para>
These functions were placed here because none of the other
categories seemed to fit.
</para>
</partintro>
<refentry id="function.connection-aborted">
<refnamediv>
<refname>connection_aborted</refname>
<refpurpose>Returns true if client disconnected</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>connection_aborted</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns true if client disconnected. See the <link
linkend="features.connection-handling">Connection Handling</link>
description in the <link linkend="features">Features</link>
chapter for a complete explanation.
</simpara>
</refsect1>
</refentry>
<refentry id="function.connection-status">
<refnamediv>
<refname>connection_status</refname>
<refpurpose>Returns connection status bitfield</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>connection_status</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the connection status bitfield. See the <link
linkend="features.connection-handling">Connection Handling</link>
description in the <link linkend="features">Features</link>
chapter for a complete explanation.
</simpara>
</refsect1>
</refentry>
<refentry id="function.connection-timeout">
<refnamediv>
<refname>connection_timeout</refname>
<refpurpose>Return true if script timed out</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>connection_timeout</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns true if script timed out. See the <link
linkend="features.connection-handling">Connection Handling</link>
description in the <link linkend="features">Features</link>
chapter for a complete explanation.
</simpara>
</refsect1>
</refentry>
<refentry id="function.define">
<refnamediv>
<refname>define</refname>
<refpurpose>Defines a named constant.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>define</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
<paramdef>int
<parameter><optional>case_insensitive</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Defines a named constant, which is similar to a variable except:
<itemizedlist>
<listitem>
<simpara>
Constants do not have a dollar sign '$' before them;
</simpara>
</listitem>
<listitem>
<simpara>
Constants may be accessed anywhere without regard to variable
scoping rules;
</simpara>
</listitem>
<listitem>
<simpara>
Constants may not be redefined or undefined once they have
been set; and
</simpara>
</listitem>
<listitem>
<simpara>
Constants may only evaluate to scalar values.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
The name of the constant is given by <parameter>name</parameter>;
the value is given by <parameter>value</parameter>.
</para>
<para>
The optional third parameter
<parameter>case_insensitive</parameter> is also available. If the
value <emphasis>1</emphasis> is given, then the constant will be
defined case-insensitive. The default behaviour is
case-sensitive; i.e. CONSTANT and Constant represent different
values.
</para>
<para>
<example>
<title>Defining Constants</title>
<programlisting role="php">
<?php
define ("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
?>
</programlisting>
</example>
</para>
<para>
<function>Define</function> returns TRUE on success and FALSE if
an error occurs.
</para>
<para>
See also <function>defined</function> and the section on <link
linkend="language.constants">Constants</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.defined">
<refnamediv>
<refname>defined</refname>
<refpurpose>
Checks whether a given named constant exists
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>defined</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the named constant given by
<parameter>name</parameter> has been defined, false otherwise.
</para>
<para>
See also <function>define</function> and the section on <link
linkend="language.constants">Constants</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.die">
<refnamediv>
<refname>die</refname>
<refpurpose>
Output a message and terminate the current script
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>die</function></funcdef>
<paramdef>string <parameter>message</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This language construct outputs a message and terminates parsing
of the script. It does not return anything.
</simpara>
<para>
<example>
<title>die example</title>
<programlisting role="php">
<?php
$filename = '/path/to/data-file';
$file = fopen ($filename, 'r')
or die("unable to open file ($filename)");
?>
</programlisting>
</example>
</para>
<simpara>
See also <function>exit</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.eval">
<refnamediv>
<refname>eval</refname>
<refpurpose>Evaluate a string as PHP code</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>eval</function></funcdef>
<paramdef>string <parameter>code_str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>eval</function> evaluates the string given in
<parameter>code_str</parameter> as PHP code. Among other things,
this can be useful for storing code in a database text field for
later execution.
</simpara>
<simpara>
There are some factors to keep in mind when using
<function>eval</function>. 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
<function>eval</function>, and properly escaping things in
<parameter>code_str</parameter>.
</simpara>
<simpara>
Also remember that variables given values under
<function>eval</function> will retain these values in the main
script afterwards.
</simpara>
<simpara>
A <literal>return</literal> statement will terminate the evaluation of
the string immediatley. In PHP 4 you may use <literal>return</literal>
to return a value that will become the result of the
<function>eval</function> function while in PHP 3
<function>eval</function> was of type <literal>void</literal> and did
never return anything.
</simpara>
<para>
<example>
<title>
<function>Eval</function> example - simple text merge
</title>
<programlisting role="php">
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.<br>';
echo $str;
eval ("\$str = \"$str\";");
echo $str;
?>
</programlisting>
</example>
</para>
<para>
The above example will show:
<programlisting>
This is a $string with my $name in it.
This is a cup with my coffee in it.
</programlisting>
</para>
</refsect1>
</refentry>
<refentry id="function.exit">
<refnamediv>
<refname>exit</refname>
<refpurpose>Terminate current script</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>exit</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<simpara>
This language construct terminates parsing of the script. It
does not return.
</simpara>
<simpara>
See also <function>die</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-browser">
<refnamediv>
<refname>get_browser</refname>
<refpurpose>
Tells what the user's browser is capable of
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>get_browser</function></funcdef>
<paramdef>string
<parameter><optional>user_agent</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>get_browser</function> attempts to determine the
capabilities of the user's browser. This is done by looking up
the browser's information in the
<filename>browscap.ini</filename> file. By default, the value of
$HTTP_USER_AGENT is used; however, you can alter this (i.e., look
up another browser's info) by passing the optional
<parameter>user_agent</parameter> parameter to
<function>get_browser</function>.
</simpara>
<simpara>
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.
</simpara>
<simpara>
While <filename>browscap.ini</filename> contains information on
many browsers, it relies on user updates to keep the database
current. The format of the file is fairly self-explanatory.
</simpara>
<para>
The following example shows how one might list all available
information retrieved about the user's browser.
<example>
<title><function>Get_browser</function> example</title>
<programlisting role="php">
<?php
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "<b>$key:</b> $value<br>\n";
}
return $str;
}
echo "$HTTP_USER_AGENT<hr>\n";
$browser = get_browser();
echo list_array ((array) $browser);
?>
</programlisting>
</example>
</para>
<simpara>
The output of the above script would look something like this:
</simpara>
<programlisting>
Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)<hr>
<b>browser_name_pattern:</b> Mozilla/4\.5.*<br>
<b>parent:</b> Netscape 4.0<br>
<b>platform:</b> Unknown<br>
<b>majorver:</b> 4<br>
<b>minorver:</b> 5<br>
<b>browser:</b> Netscape<br>
<b>version:</b> 4<br>
<b>frames:</b> 1<br>
<b>tables:</b> 1<br>
<b>cookies:</b> 1<br>
<b>backgroundsounds:</b> <br>
<b>vbscript:</b> <br>
<b>javascript:</b> 1<br>
<b>javaapplets:</b> 1<br>
<b>activexcontrols:</b> <br>
<b>beta:</b> <br>
<b>crawler:</b> <br>
<b>authenticodeupdate:</b> <br>
<b>msn:</b> <br>
</programlisting>
<simpara>
In order for this to work, your <link
linkend="ini.sect.browscap">browscap</link> configuration file
setting must point to the correct location of the
<filename>browscap.ini</filename> file.
</simpara>
<simpara>
For more information (including locations from which you may
obtain a <filename>browscap.ini</filename> file), check the PHP
FAQ at <ulink
url="&url.php.faq;">&url.php.faq;</ulink>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.highlight-file">
<refnamediv>
<refname>highlight_file</refname>
<refpurpose>Syntax highlighting of a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>highlight_file</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
The <function>highlight_file</function> function prints out a syntax
higlighted version of the code contained in <parameter>filename</parameter>
using the colors defined in the built-in syntax highlighter for PHP.
</simpara>
<para>
<example>
<title>Creating a source highlighting URL</title>
<simpara>
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 <function>highlight_file</function> to show a nice looking
code list.
</simpara>
<simpara>
In your httpd.conf you can add the following:
</simpara>
<para>
<informalexample><programlisting>
<Location /source>
ForceType application/x-httpd-php
</Location>
</programlisting></informalexample>
</para>
<simpara>
And then make a file named "source" and put it in your
web root directory.
</simpara>
<para>
<programlisting role="php">
<HTML>
<HEAD>
<TITLE>Source Display</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<?php
$script = getenv ("PATH_TRANSLATED");
if(!$script) {
echo "<BR><B>ERROR: Script Name
needed</B><BR>";
} else {
if (ereg("(\.php|\.inc)$",$script)) {
echo "<H1>Source of:
$PATH_INFO</H1>\n<HR>\n";
highlight_file($script);
} else {
echo "<H1>ERROR: Only PHP or include script names are
allowed</H1>";
}
}
echo "<HR>Processed: ".date("Y/M/d
H:i:s",time());
?>
</BODY>
</HTML>
</programlisting>
</para>
<simpara>
Then you can use an URL like the one below to display a colorized
version of a script located in "/path/to/script.php"
in your web site.
</simpara>
<para>
<informalexample>
<programlisting>
http://your.server.com/source/path/to/script.php
</programlisting>
</informalexample>
</para>
</example>
</para>
<simpara>
See also <function>highlight_string</function>,
<function>show_source</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.highlight-string">
<refnamediv>
<refname>highlight_string</refname>
<refpurpose>Syntax highlighting of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>highlight_string</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
The <function>highlight_string</function> function prints out a syntax
highlighted version of <parameter>str</parameter> using the colors defined
in the built-in syntax highlighter for PHP.
</simpara>
<simpara>
See also <function>highlight_file</function>,
<function>show_source</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ignore-user-abort">
<refnamediv>
<refname>ignore_user_abort</refname>
<refpurpose>
Set whether a client disconnect should abort script execution
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ignore_user_abort</function></funcdef>
<paramdef>int
<parameter><optional>setting</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This 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 <link
linkend="features.connection-handling">Connection Handling</link>
section in the <link linkend="features">Features</link> chapter
for a complete description of connection handling in PHP.
</simpara>
</refsect1>
</refentry>
<refentry id="function.iptcparse">
<refnamediv>
<refname>iptcparse</refname>
<refpurpose>
Parse a binary IPTC <ulink url="&url.iptc;">&url.iptc;</ulink>
block into single tags.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>iptcparse</function></funcdef>
<paramdef>string <parameter>iptcblock</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function parses a binary IPTC block into its single tags. It
returns an array using the tagmarker as an index and the value as
the value. It returns false on error or if no IPTC data was
found. See <function>GetImageSize</function> for a sample.
</simpara>
</refsect1>
</refentry>
<refentry id="function.leak">
<refnamediv>
<refname>leak</refname>
<refpurpose>Leak memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>leak</function></funcdef>
<paramdef>int <parameter>bytes</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Leak</function> leaks the specified amount of memory.
</simpara>
<simpara>
This is useful when debugging the memory manager, which
automatically cleans up "leaked" memory when each request is
completed.
</simpara>
</refsect1>
</refentry>
<refentry id="function.pack">
<refnamediv>
<refname>pack</refname>
<refpurpose>Pack data into binary string.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pack</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>mixed
<parameter><optional>args</optional></parameter> ...
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Pack given arguments into binary string according to
<parameter>format</parameter>. Returns binary string containing
data.
</para>
<para>
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
<itemizedlist>
<listitem>
<simpara>
a NUL-padded string
</simpara>
</listitem>
<listitem>
<simpara>
A SPACE-padded string
</simpara>
</listitem>
<listitem>
<simpara>
h Hex string, low nibble first
</simpara>
</listitem>
<listitem>
<simpara>
H Hex string, high nibble first
</simpara>
</listitem>
<listitem>
<simpara>
c signed char
</simpara>
</listitem>
<listitem>
<simpara>
C unsigned char
</simpara>
</listitem>
<listitem>
<simpara>
s signed short (always 16 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
S unsigned short (always 16 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
n unsigned short (always 16 bit, big endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
v unsigned short (always 16 bit, little endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
i signed integer (machine dependent size and byte order)
</simpara>
</listitem>
<listitem>
<simpara>
I unsigned integer (machine dependent size and byte order)
</simpara>
</listitem>
<listitem>
<simpara>
l signed long (always 32 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
L unsigned long (always 32 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
N unsigned long (always 32 bit, big endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
V unsigned long (always 32 bit, little endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
f float (machine dependent size and representation)
</simpara>
</listitem>
<listitem>
<simpara>
d double (machine dependent size and representation)
</simpara>
</listitem>
<listitem>
<simpara>
x NUL byte
</simpara>
</listitem>
<listitem>
<simpara>
X Back up one byte
</simpara>
</listitem>
<listitem>
<simpara>
@ NUL-fill to absolute position
</simpara>
</listitem>
</itemizedlist>
<example>
<title><function>Pack</function> format string</title>
<programlisting role="php">
$binarydata = pack ("nvc*", 0x1234, 0x5678, 65, 66);
</programlisting>
<para>
The resulting binary string will be 6 bytes long and contain
the byte sequence 0x12, 0x34, 0x78, 0x56, 0x41, 0x42.
</para>
</example>
</para>
<para>
Note that the distinction between signed and unsigned values only
affects the function <function>unpack</function>, where as
function <function>pack</function> gives the same result for
signed and unsigned format codes.
</para>
<para>
Also note that PHP internally stores integral values as signed
values of a machine dependent size. If you give it an unsigned
integral value too large to be stored that way it is converted to
a double which often yields an undesired result.
</para>
</refsect1>
</refentry>
<refentry id="function.show-source">
<refnamediv>
<refname>show_source</refname>
<refpurpose>Syntax highlighting of a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>show_source</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
The <function>show_source</function> function prints out a syntax
higlighted version of the code contained in <parameter>filename</parameter>
using the colors defined in the built-in syntax highlighter for PHP.
</simpara>
<note>
<simpara>
This function is an alias for the function
<function>highlight_file</function>
</simpara>
</note>
<simpara>
See also <function>highlight_string</function>,
<function>highlight_file</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.sleep">
<refnamediv>
<refname>sleep</refname>
<refpurpose>Delay execution</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>sleep</function></funcdef>
<paramdef>int <parameter>seconds</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
The sleep function delays program execution for the given number
of <parameter>seconds</parameter>.
</simpara>
<simpara>
See also <function>usleep</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.uniqid">
<refnamediv>
<refname>uniqid</refname>
<refpurpose>Generate a unique id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>uniqid</function></funcdef>
<paramdef>string <parameter>prefix</parameter></paramdef>
<paramdef>boolean
<parameter><optional>lcg</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Uniqid</function> 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. <parameter>Prefix</parameter> can be up to 114
characters long.
</simpara>
<simpara>
If the optional <parameter>lcg</parameter> parameter is true,
<function>uniqid</function> will add additional "combined LCG"
entropy at the end of the return value, which should make the
results more unique.
</simpara>
<simpara>
With an empty <parameter>prefix</parameter>, the returned string
will be 13 characters long. If <parameter>lcg</parameter> is
true, it will be 23 characters.
</simpara>
<note>
<simpara>
The <parameter>lcg</parameter> parameter is only available in
PHP 4 and PHP 3.0.13 and later.
</simpara>
</note>
<para>
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 the lines of
<informalexample>
<programlisting role="php">
$token = md5 (uniqid ("")); // no random portion
$better_token = md5 (uniqid (rand())); // better, difficult to guess
</programlisting>
</informalexample>
</para>
<simpara>
This will create a 32 character identifier (a 128 bit hex number)
that is extremely difficult to predict.
</simpara>
</refsect1>
</refentry>
<refentry id="function.unpack">
<refnamediv>
<refname>unpack</refname>
<refpurpose>Unpack data from binary string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>unpack</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Unpack</function> from binary string into array
according to <parameter>format</parameter>. Returns array
containing unpacked elements of binary string.
</para>
<para>
<function>Unpack</function> 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 /.
<example>
<title><function>Unpack</function> format string</title>
<programlisting role="php">
$array = unpack ("c2chars/nint", $binarydata);
</programlisting>
<para>
The resulting array will contain the entries "chars1",
"chars2" and "int".
</para>
</example>
</para>
<para>
For an explanation of the format codes see also:
<function>pack</function>
</para>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.usleep">
<refnamediv>
<refname>usleep</refname>
<refpurpose>Delay execution in microseconds</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>usleep</function></funcdef>
<paramdef>int <parameter>micro_seconds</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
The <function>usleep</function> function delays program execution
for the given number of <parameter>micro_seconds</parameter>.
</simpara>
<simpara>
See also <function>sleep</function>.
</simpara>
<note>
<simpara>
This function does not work on Windows systems.
</simpara>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/msql.xml
+++ phpdoc/nl/functions/msql.xml
<reference id="ref.msql">
<title>mSQL functions</title>
<titleabbrev>mSQL</titleabbrev>
<partintro>
<simpara>
These functions allow you to access mSQL database servers. In
order to have these functions available, you must compile php
with msql support by using the
<option role="configure">--with-msql[=dir]</option> option. The default
location is /usr/local/Hughes.
</simpara>
<simpara>
More information about mSQL can be found at <ulink
url="&url.msql;">&url.msql;</ulink>.
</simpara>
</partintro>
<refentry id="function.msql">
<refnamediv>
<refname>msql</refname>
<refpurpose>Send mSQL query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql</function></funcdef>
<paramdef>string <parameter>database</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a positive mSQL query identifier to the query result, or
false on error.
</para>
<para>
<function>msql</function> 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 mSQL server and if
no such link is found it'll try to create one as if
<function>msql_connect</function> was called with no arguments
(see <function>msql_connect</function>).
</para>
</refsect1>
</refentry>
<refentry id="function.msql-affected-rows">
<refnamediv>
<refname>msql_affected_rows</refname>
<refpurpose>Returns number of affected rows</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_affected_rows</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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).
</para>
<para>
See also: <function>msql_query</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-close">
<refnamediv>
<refname>msql_close</refname>
<refpurpose>Close mSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_close</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.
</para>
<para>
<function>msql_close</function> 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.
</para>
<para>
Note that this isn't usually necessary, as non-persistent open
links are automatically closed at the end of the script's
execution.
</para>
<para>
<function>msql_close</function> will not close persistent links
generated by <function>msql_pconnect</function>.
</para>
<para>
See also: <function>msql_connect</function> and
<function>msql_pconnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-connect">
<refnamediv>
<refname>msql_connect</refname>
<refpurpose>Open mSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_connect</function></funcdef>
<paramdef>string
<parameter>
<optional>hostname</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>hostname<optional>:port</optional></optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>username</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>password</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a positive mSQL link identifier on success, or false on
error.
</para>
<para>
<function>msql_connect</function> establishes a connection to a
mSQL server. The hostname argument is optional, and if it's
missing, localhost is assumed.
</para>
<para>
In case a second call is made to
<function>msql_connect</function> with the same arguments, no new
link will be established, but instead, the link identifier of the
already opened link will be returned.
</para>
<para>
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
<function>msql_close</function>.
</para>
<para>
See also <function>msql_pconnect</function>,
<function>msql_close</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-create-db">
<refnamediv>
<refname>msql_create_db</refname>
<refpurpose>Create mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_create_db</function></funcdef>
<paramdef>string <parameter>database name</parameter></paramdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
msql_create_db() attempts to create a new database on the server
associated with the specified link identifier.
</para>
<para> See also: <function>msql_drop_db</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-createdb">
<refnamediv>
<refname>msql_createdb</refname>
<refpurpose>Create mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_createdb</function></funcdef>
<paramdef>string <parameter>database name</parameter></paramdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>msql_create_db</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-data-seek">
<refnamediv>
<refname>msql_data_seek</refname>
<refpurpose>Move internal row pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_data_seek</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>row_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on failure.
</para>
<para>
<function>msql_data_seek</function> moves the internal row
pointer of the mSQL result associated with the specified query
identifier to pointer to the specifyed row number. The next call
to <function>msql_fetch_row</function> would return that
row.
</para>
<para>
See also: <function>msql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-dbname">
<refnamediv>
<refname>msql_dbname</refname>
<refpurpose>Get current mSQL database name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>msql_dbname</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>i</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_dbname</function> returns the database name stored
in position <parameter>i</parameter> of the result pointer
returned from the <function>msql_listdbs</function> function. The
<function>msql_numrows</function> function can be used to
determine how many database names are available.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-drop-db">
<refnamediv>
<refname>msql_drop_db</refname>
<refpurpose>Drop (delete) mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_drop_db</function></funcdef>
<paramdef>string <parameter>database_name</parameter></paramdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on failure.
</para>
<para>
<function>msql_drop_db</function> attempts to drop (remove) an
entire database from the server associated with the specified
link identifier.
</para>
<para>
See also: <function>msql_create_db</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-dropdb">
<refnamediv>
<refname>msql_dropdb</refname>
<refpurpose>Drop (delete) mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>
See <function>msql_drop_db</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-error">
<refnamediv>
<refname>msql_error</refname>
<refpurpose>Returns error message of last msql call</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>msql_error</function></funcdef>
<paramdef> <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Errors coming back from the mSQL database backend no longer
issue warnings. Instead, use these functions to retrieve the
error string.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fetch-array">
<refnamediv>
<refname>msql_fetch_array</refname>
<refpurpose>Fetch row as array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_fetch_array</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int
<parameter><optional>result_type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array that corresponds to the fetched row, or false if
there are no more rows.
</para>
<para>
<function>msql_fetch_array</function> is an extended version of
<function>msql_fetch_row</function>. 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.
</para>
<para>
The second optional argument <parameter>result_type</parameter>
in <function>msql_fetch_array</function> is a constant and can
take the following values: MSQL_ASSOC, MSQL_NUM, and MYSQL_BOTH.
</para>
<para>
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).
</para>
<para>
An important thing to note is that using
<function>msql_fetch_array</function> is NOT significantly slower
than using <function>msql_fetch_row</function>, while it provides
a significant added value.
</para>
<para>
For further details, also see
<function>msql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fetch-field">
<refnamediv>
<refname>msql_fetch_field</refname>
<refpurpose>Get field information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>msql_fetch_field</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an object containing field information
</para>
<para>
<function>msql_fetch_field</function> 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
retreived by <function>msql_fetch_field</function> is retreived.
</para>
<para>
The properties of the object are:
<itemizedlist>
<listitem>
<simpara>
name - column name
</simpara>
</listitem>
<listitem>
<simpara>
table - name of the table the column belongs to
</simpara>
</listitem>
<listitem>
<simpara>
not_null - 1 if the column cannot be null
</simpara>
</listitem>
<listitem>
<simpara>
primary_key - 1 if the column is a primary key
</simpara>
</listitem>
<listitem>
<simpara>
unique - 1 if the column is a unique key
</simpara>
</listitem>
<listitem>
<simpara>
type - the type of the column
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
See also <function>msql_field_seek</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fetch-object">
<refnamediv>
<refname>msql_fetch_object</refname>
<refpurpose>Fetch row as object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_fetch_object</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int
<parameter><optional>result_type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an object with properties that correspond to the fetched
row, or false if there are no more rows.
</para>
<para>
<function>msql_fetch_object</function> is similar to
<function>msql_fetch_array</function>, 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).
</para>
<para>
The optional second argument <parameter>result_type</parameter>
in <function>msql_fetch_array</function> is a constant and can
take the following values: MSQL_ASSOC, MSQL_NUM, and MSQL_BOTH.
</para>
<para>
Speed-wise, the function is identical to
<function>msql_fetch_array</function>, and almost as quick as
<function>msql_fetch_row</function> (the difference is
insignificant).
</para>
<para> See also:
<function>msql_fetch_array</function> and
<function>msql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fetch-row">
<refnamediv>
<refname>msql_fetch_row</refname>
<refpurpose>Get row as enumerated array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>msql_fetch_row</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array that corresponds to the fetched row, or false if
there are no more rows.
</para>
<para>
<function>msql_fetch_row</function> 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.
</para>
<para>
Subsequent call to <function>msql_fetch_row</function> would
return the next row in the result set, or false if there are no
more rows.
</para>
<para>
See also: <function>msql_fetch_array</function>,
<function>msql_fetch_object</function>,
<function>msql_data_seek</function>, and
<function>msql_result</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fieldname">
<refnamediv>
<refname>msql_fieldname</refname>
<refpurpose>Get field name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>msql_fieldname</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_fieldname</function> returns the name of the
specified field. <parameter>query_identifier</parameter> is the
query identifier, and <parameter>field</parameter> is the field
index. <literal>msql_fieldname($result, 2);</literal> will
return the name of the second field in the result associated with
the result identifier.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-field-seek">
<refnamediv>
<refname>msql_field_seek</refname>
<refpurpose>Set field offset</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_field_seek</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeks to the specified field offset. If the next call to
<function>msql_fetch_field</function> won't include a field
offset, this field would be returned.
</para>
<para>
See also: <function>msql_fetch_field</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fieldtable">
<refnamediv>
<refname>msql_fieldtable</refname>
<refpurpose>Get table name for field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_fieldtable</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the name of the table <parameter>field</parameter> was
fetched from.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fieldtype">
<refnamediv>
<refname>msql_fieldtype</refname>
<refpurpose>Get field type</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>msql_fieldtype</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>i</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_fieldtype</function> is similar to the
<function>msql_fieldname</function> function. The arguments are
identical, but the field type is returned. This will be one of
"int", "string" or "real".
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fieldflags">
<refnamediv>
<refname>msql_fieldflags</refname>
<refpurpose>Get field flags</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>msql_fieldflags</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>i</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_fieldflags</function> 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).
</para>
</refsect1>
</refentry>
<refentry id="function.msql-fieldlen">
<refnamediv>
<refname>msql_fieldlen</refname>
<refpurpose>Get field length</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_fieldlen</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>i</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_fieldlen</function> returns the length of the
specified field.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-free-result">
<refnamediv>
<refname>msql_free_result</refname>
<refpurpose>Free result memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_free_result</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_free_result</function> frees the memory associated
with <parameter>query_identifier</parameter>. 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.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-freeresult">
<refnamediv>
<refname>msql_freeresult</refname>
<refpurpose>Free result memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>See <function>msql_free_result</function></para>
</refsect1>
</refentry>
<refentry id="function.msql-list-fields">
<refnamediv>
<refname>msql_list_fields</refname>
<refpurpose>List result fields</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_list_fields</function></funcdef>
<paramdef>string <parameter>database</parameter></paramdef>
<paramdef>string <parameter>tablename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_list_fields</function> 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
<function>msql_fieldflags</function>,
<function>msql_fieldlen</function>,
<function>msql_fieldname</function>, and
<function>msql_fieldtype</function>. A query identifier is a
positive integer. The function returns <literal>-1</literal> if a
error occurs. A string describing the error will be placed in
<literal>$phperrmsg</literal>, and unless the function was called
as <literal>@msql_list_fields()</literal> then this error string
will also be printed out.
</para>
<para>
See also <function>msql_error</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-listfields">
<refnamediv>
<refname>msql_listfields</refname>
<refpurpose>List result fields</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>
See <function>msql_list_fields</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-list-dbs">
<refnamediv>
<refname>msql_list_dbs</refname>
<refpurpose>List mSQL databases on server</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_list_dbs</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_list_dbs</function> will return a result pointer
containing the databases available from the current msql
daemon. Use the <function>msql_dbname</function> function to
traverse this result pointer.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-listdbs">
<refnamediv>
<refname>msql_listdbs</refname>
<refpurpose>List mSQL databases on server</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>
See <function>msql_list_dbs</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-list-tables">
<refnamediv>
<refname>msql_list_tables</refname>
<refpurpose>List tables in an mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_list_tables</function></funcdef>
<paramdef>string <parameter>database</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_list_tables</function> takes a database name and
result pointer much like the <function>msql</function>
function. The <function>msql_tablename</function> function should
be used to extract the actual table names from the result
pointer.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-listtables">
<refnamediv>
<refname>msql_listtables</refname>
<refpurpose>List tables in an mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>
See <function>msql_list_tables</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-num-fields">
<refnamediv>
<refname>msql_num_fields</refname>
<refpurpose>Get number of fields in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_num_fields</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_num_fields</function> returns the number of fields
in a result set.
</para>
<para>
See also: <function>msql</function>,
<function>msql_query</function>,
<function>msql_fetch_field</function>, and
<function>msql_num_rows</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-num-rows">
<refnamediv>
<refname>msql_num_rows</refname>
<refpurpose>Get number of rows in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_num_rows</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Msql_num_rows</function> returns the number of rows in
a result set.
</para>
<para>
See also: <function>msql</function>,
<function>msql_query</function>, and
<function>msql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-numfields">
<refnamediv>
<refname>msql_numfields</refname>
<refpurpose>Get number of fields in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_numfields</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>msql_num_fields</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-numrows">
<refnamediv>
<refname>msql_numrows</refname>
<refpurpose>Get number of rows in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_numrows</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>msql_num_rows</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-pconnect">
<refnamediv>
<refname>msql_pconnect</refname>
<refpurpose>Open persistent mSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_pconnect</function></funcdef>
<paramdef>string
<parameter>
<optional>hostname</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>hostname<optional>:port</optional></optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>username</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>password</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a positive mSQL persistent link identifier on success, or
false on error.
</para>
<para>
<function>msql_pconnect</function> acts very much like
<function>msql_connect</function> with two major differences.
</para>
<para>
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.
</para>
<para>
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 (<function>msql_close</function> will not
close links established by <function>msql_pconnect</function>).
</para>
<para>
This type of links is therefore called 'persistent'.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-query">
<refnamediv>
<refname>msql_query</refname>
<refpurpose>Send mSQL query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_query</function></funcdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_query</function> 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
<function>msql_connect</function> was called, and use it.
</para>
<para>
Returns a positive mSQL query identifier on success, or false on
error.
</para>
<para>
See also: <function>msql</function>,
<function>msql_select_db</function>, and
<function>msql_connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-regcase">
<refnamediv>
<refname>msql_regcase</refname>
<refpurpose>
Make regular expression for case insensitive match
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>See <function>sql_regcase</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-result">
<refnamediv>
<refname>msql_result</refname>
<refpurpose>Get result data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_result</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>i</parameter></paramdef>
<paramdef>mixed <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the contents of the cell at the row and offset in the
specified mSQL result set.
</para>
<para>
<function>msql_result</function> 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.
</para>
<para>
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
<function>msql_result</function>. Also, note that specifying a
numeric offset for the field argument is much quicker than
specifying a fieldname or tablename.fieldname argument.
</para>
<para>
Recommended high-performance alternatives:
<function>msql_fetch_row</function>,
<function>msql_fetch_array</function>, and
<function>msql_fetch_object</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-select-db">
<refnamediv>
<refname>msql_select_db</refname>
<refpurpose>Select mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>msql_select_db</function></funcdef>
<paramdef>string <parameter>database_name</parameter></paramdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error.
</para>
<para>
<function>msql_select_db</function> 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 <function>msql_connect</function> was
called, and use it.
</para>
<para>
Every subsequent call to <function>msql_query</function> will be
made on the active database.
</para>
<para>
See also: <function>msql_connect</function>,
<function>msql_pconnect</function>, and
<function>msql_query</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-selectdb">
<refnamediv>
<refname>msql_selectdb</refname>
<refpurpose>Select mSQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>See <function>msql_select_db</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.msql-tablename">
<refnamediv>
<refname>msql_tablename</refname>
<refpurpose>Get table name of field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>msql_tablename</function></funcdef>
<paramdef>int <parameter>query_identifier</parameter></paramdef>
<paramdef>int <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>msql_tablename</function> takes a result pointer
returned by the <function>msql_list_tables</function> function as
well as an integer index and returns the name of a table. The
<function>msql_numrows</function> function may be used to
determine the number of tables in the result pointer.
<example>
<title><function>msql_tablename</function> example</title>
<programlisting role="php">
<?php
msql_connect ("localhost");
$result = msql_list_tables ("wisconsin");
$i = 0;
while ($i < msql_numrows ($result)) {
$tb_names[$i] = msql_tablename ($result, $i);
echo $tb_names[$i] . "<BR>";
$i++;
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/mssql.xml
+++ phpdoc/nl/functions/mssql.xml
<reference id="ref.mssql">
<title>Microsoft SQL Server functions</title>
<titleabbrev>MS SQL Server</titleabbrev>
<refentry id="function.mssql-close">
<refnamediv>
<refname>mssql_close</refname>
<refpurpose>Close MS SQL Server connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_close</function></funcdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on error.
</para>
<para>
<function>Mssql_close</function> 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.
</para>
<para>
Note that this isn't usually necessary, as non-persistent open
links are automatically closed at the end of the script's
execution.
</para>
<para>
<function>Mssql_close</function> will not close persistent links
generated by <function>mssql_pconnect</function>.
</para>
<para>
See also: <function>mssql_connect</function>,
<function>mssql_pconnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-connect">
<refnamediv>
<refname>mssql_connect</refname>
<refpurpose>Open MS SQL server connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_connect</function></funcdef>
<paramdef>string
<parameter><optional>servername</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>username</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>password</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive MS SQL link identifier on success, or false
on error.
</para>
<para>
<function>Mssql_connect</function> establishes a connection to a
MS SQL server. The servername argument has to be a valid
servername that is defined in the 'interfaces' file.
</para>
<para>
In case a second call is made to
<function>mssql_connect</function> with the same arguments, no
new link will be established, but instead, the link identifier of
the already opened link will be returned.
</para>
<para>
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
<function>mssql_close</function>.
</para>
<para>
See also <function>mssql_pconnect</function>,
<function>mssql_close</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-data-seek">
<refnamediv>
<refname>mssql_data_seek</refname>
<refpurpose>Move internal row pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_data_seek</function></funcdef>
<paramdef>int <parameter>result_identifier</parameter></paramdef>
<paramdef>int <parameter>row_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on failure.
</para>
<para>
<function>Mssql_data_seek</function> moves the internal row
pointer of the MS SQL result associated with the specified result
identifier to point to the specified row number. The next call
to <function>mssql_fetch_row</function> would return that row.
</para>
<para>
See also: <function>mssql_data_seek</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-fetch-array">
<refnamediv>
<refname>mssql_fetch_array</refname>
<refpurpose>Fetch row as array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_fetch_array</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An array that corresponds to the fetched row, or false
if there are no more rows.
</para>
<para>
<function>Mssql_fetch_array</function> is an extended version of
<function>mssql_fetch_row</function>. 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.
</para>
<para>
An important thing to note is that using
<function>mssql_fetch_array</function> is NOT significantly
slower than using <function>mssql_fetch_row</function>, while it
provides a significant added value.
</para>
<para>
For further details, also see
<function>mssql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-fetch-field">
<refnamediv>
<refname>mssql_fetch_field</refname>
<refpurpose>Get field information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>mssql_fetch_field</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int
<parameter><optional>field_offset</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an object containing field information.
</para>
<para>
<function>Mssql_fetch_field</function> 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 <function>mssql_fetch_field</function> is retrieved.
</para>
<para>
The properties of the object are:
</para>
<itemizedlist>
<listitem>
<simpara>
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.
</simpara>
</listitem>
<listitem>
<simpara>
column_source - the table from which the column was taken
</simpara>
</listitem>
<listitem>
<simpara>
max_length - maximum length of the column
</simpara>
</listitem>
<listitem>
<simpara>
numeric - 1 if the column is numeric
</simpara></listitem>
</itemizedlist>
<para>
See also <function>mssql_field_seek</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-fetch-object">
<refnamediv>
<refname>mssql_fetch_object</refname>
<refpurpose>Fetch row as object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_fetch_object</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An object with properties that correspond to the fetched
row, or false if there are no more rows.
</para>
<para>
<function>Mssql_fetch_object</function> is similar to
<function>mssql_fetch_array</function>, 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).
</para>
<para>
Speed-wise, the function is identical to
<function>mssql_fetch_array</function>, and almost as quick as
<function>mssql_fetch_row</function> (the difference is
insignificant).
</para>
<para>
See also: <function>mssql_fetch-array</function> and
<function>mssql_fetch-row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-fetch-row">
<refnamediv>
<refname>mssql_fetch_row</refname>
<refpurpose>Get row as enumerated array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mssql_fetch_row</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An array that corresponds to the fetched row, or false
if there are no more rows.
</para>
<para>
<function>Mssql_fetch_row</function> 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.
</para>
<para>
Subsequent call to <function>mssql_fetch_rows</function> would
return the next row in the result set, or false if there are no
more rows.
</para>
<para>
See also: <function>mssql_fetch_array</function>,
<function>mssql_fetch_object</function>,
<function>mssql_data_seek</function>,
<function>mssql_fetch_lengths</function>, and
<function>mssql_result</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-field-length">
<refnamediv>
<refname>mssql_field_length</refname>
<refpurpose>Get the length of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_field_length</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int
<parameter><optional>offset</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
<refentry id="function.mssql-field-name">
<refnamediv>
<refname>mssql_field_name</refname>
<refpurpose>Get the name of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_field_name</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int
<parameter><optional>offset</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
<refentry id="function.mssql-field-seek">
<refnamediv>
<refname>mssql_field_seek</refname>
<refpurpose>Set field offset</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_field_seek</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeks to the specified field offset. If the next call to
<function>mssql_fetch_field</function> won't include a field
offset, this field would be returned.</para>
<para></para>
<para>
See also: <function>mssql_fetch_field</function>.</para>
</refsect1>
</refentry>
<refentry id="function.mssql-field-type">
<refnamediv>
<refname>mssql_field_type</refname>
<refpurpose>Get the type of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mssql_field_type</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int
<parameter><optional>offset</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
<refentry id="function.mssql-free-result">
<refnamediv>
<refname>mssql_free_result</refname>
<refpurpose>Free result memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_free_result</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mssql_free_result</function> 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 <function>mssql_free_result</function>
with the result identifier as an argument and the associated
result memory will be freed.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-get-last-message">
<refnamediv>
<refname>mssql_get_last_message</refname>
<refpurpose>
Returns the last message from server (over
min_message_severity?)
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>mssql_get_last_message</function>
</funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
<refentry id="function.mssql-min-error-severity">
<refnamediv>
<refname>mssql_min_error_severity</refname>
<refpurpose>Sets the lower error severity</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>mssql_min_error_severity</function>
</funcdef>
<paramdef>int <parameter>severity</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
<refentry id="function.mssql-min-message-severity">
<refnamediv>
<refname>mssql_min_message_severity</refname>
<refpurpose>Sets the lower message severity</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>mssql_min_message_severity</function>
</funcdef>
<paramdef>int <parameter>severity</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
<refentry id="function.mssql-num-fields">
<refnamediv>
<refname>mssql_num_fields</refname>
<refpurpose>Get number of fields in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_num_fields</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mssql_num_fields</function> returns the number of
fields in a result set.
</para>
<para>
See also: <function>mssql_db_query</function>,
<function>mssql_query</function>,
<function>mssql_fetch_field</function>, and
<function>mssql_num_rows</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-num-rows">
<refnamediv>
<refname>mssql_num_rows</refname>
<refpurpose>Get number of rows in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_num_rows</function></funcdef>
<paramdef>string <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mssql_num_rows</function> returns the number of rows in
a result set.
</para>
<para>
See also: <function>mssql_db_query</function>,
<function>mssql_query</function>, and
<function>mssql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-pconnect">
<refnamediv>
<refname>mssql_pconnect</refname>
<refpurpose>Open persistent MS SQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_pconnect</function></funcdef>
<paramdef>string
<parameter><optional>servername</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>username</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>password</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive MS SQL persistent link identifier on success,
or false on error.
</para>
<para>
<function>Mssql_pconnect</function> acts very much like
<function>mssql_connect</function> with two major differences.
</para>
<para>
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.
</para>
<para>
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 (<function>mssql_close</function> will not
close links established by <function>mssql_pconnect</function>).
</para>
<para>
This type of links is therefore called 'persistent'.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-query">
<refnamediv>
<refname>mssql_query</refname>
<refpurpose>Send MS SQL query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_query</function></funcdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive MS SQL result identifier on success, or false
on error.
</para>
<para>
<function>Mssql_query</function> 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
<function>mssql_connect</function> was called, and use it.
</para>
<para>
See also: <function>mssql_db_query</function>,
<function>mssql_select_db</function>, and
<function>mssql_connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-result">
<refnamediv>
<refname>mssql_result</refname>
<refpurpose>Get result data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_result</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>i</parameter></paramdef>
<paramdef>mixed <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Mssql_result</function> 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.
</para>
<para>
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
<function>mssql_result</function>. Also, note that specifying a
numeric offset for the field argument is much quicker than
specifying a fieldname or tablename.fieldname argument.
</para>
<para>
Recommended high-performance alternatives:
<function>mssql_fetch_row</function>,
<function>mssql_fetch_array</function>, and
<function>mssql_fetch_object</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mssql-select-db">
<refnamediv>
<refname>mssql_select_db</refname>
<refpurpose>Select MS SQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mssql_select_db</function></funcdef>
<paramdef>string <parameter>database_name</parameter></paramdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: true on success, false on error
</para>
<para>
<function>Mssql_select_db</function> 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 <function>mssql_connect</function> was
called, and use it.
</para>
<para>
Every subsequent call to <function>mssql_query</function> will be
made on the active database.
</para>
<para> See also:
<function>mssql_connect</function>,
<function>mssql_pconnect</function>, and
<function>mssql_query</function>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/mysql.xml
+++ phpdoc/nl/functions/mysql.xml
<reference id="ref.mysql">
<title>MySQL functions</title>
<titleabbrev>MySQL</titleabbrev>
<partintro>
<simpara>
These functions allow you to access MySQL database servers. In
order to have these functions available, you must compile php
with mysql support by using the
<option role="configure">--with-mysql</option> option. If you
use this option without specifying the path to mysql, php will
use the built-in mysql client libraries. Users who run other
applications that use mysql (for example, running php3 and php4
as concurrent apache modules, or auth-mysql) should always
specify the path to mysql:
<option role="configure">--with-mysql=/path/to/mysql</option>.
This will force php to use the client libraries installed by
mysql, avoiding any conflicts.
</simpara>
<simpara>
More information about MySQL can be found at <ulink
url="&url.mysql;">&url.mysql;</ulink>.
</simpara>
<simpara>
Documentation for MySQL can be found at <ulink
url="&url.mysql.docs;">&url.mysql.docs;</ulink>.
</simpara>
</partintro>
<refentry id="function.mysql-affected-rows">
<refnamediv>
<refname>mysql_affected_rows</refname>
<refpurpose>Get number of affected rows in previous MySQL
operation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_affected_rows</function></funcdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_affected_rows</function> 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.
</para>
<para>
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.
</para>
<para>
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 <function>mysql_num_rows</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-change-user">
<refnamediv>
<refname>mysql_change_user</refname>
<refpurpose>
Change logged in user of the active connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_change_user</function></funcdef>
<paramdef>string <parameter>user</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string
<parameter>
<optional>database</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_change_user</function> 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.</para>
<note><para>This function was introduced in PHP 3.0.13 and
requires MySQL 3.23.3 or higher.
</para></note>
</refsect1>
</refentry>
<refentry id="function.mysql-close">
<refnamediv>
<refname>mysql_close</refname>
<refpurpose>Close MySQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_close</function></funcdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on error.
</para>
<para> <function>mysql_close</function> closes the connection to
the MySQL server that's associated with the specified link
identifier. If <parameter>link_identifier</parameter> isn't
specified, the last opened link is used.
</para>
<para>
Using <function>mysql_close</function> isn't usually necessary,
as non-persistent open links are automatically closed at the end
of the script's execution.
</para>
<note>
<para>
<function>mysql_close</function> will not close persistent links
created by <function>mysql_pconnect</function>.
</para>
</note>
<example>
<title>MySQL close example</title>
<programlisting role="php">
<?php
$link = mysql_connect ("kraemer", "marliesle", "secret")
or die ("Could not connect");
print ("Connected successfully");
mysql_close ($link);
?>
</programlisting>
</example>
<para>
See also: <function>mysql_connect</function>, and
<function>mysql_pconnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-connect">
<refnamediv>
<refname>mysql_connect</refname>
<refpurpose>Open a connection to a MySQL Server</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_connect</function></funcdef>
<paramdef>string
<parameter>
<optional>hostname
<optional>:port</optional>
<optional>:/path/to/socket</optional>
</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>username</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>password</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a positive MySQL link identifier on success, or an error
message on failure.
</para>
<para>
<function>mysql_connect</function> establishes a connection
to a MySQL server. The following defaults are assumed for
missing optional parameters: <parameter>host:port</parameter> =
'localhost:3306', <parameter>username</parameter> = name of the
user that owns the server process and
<parameter>password</parameter> = empty password.
</para>
<para>
The hostname string can also include a port
number. eg. "hostname:port" or a path to a socket
eg. ":/path/to/socket" for the localhost.
<note>
<para>
Support for ":port" was added in PHP 3.0B4.
</para>
<para>
Support for ":/path/to/socket" was added in
PHP 3.0.10.
</para>
<para>
You can suppress the error message on failure by prepending '@'
to the function name.
</para>
</note>
</para>
<para>
If a second call is made to <function>mysql_connect</function>
with the same arguments, no new link will be established, but
instead, the link identifier of the already opened link will be
returned.
</para>
<para>
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
<function>mysql_close</function>.
</para>
<example>
<title>MySQL connect example</title>
<programlisting role="php">
<?php
$link = mysql_connect ("kraemer", "marliesle", "secret")
or die ("Could not connect");
print ("Connected successfully");
mysql_close ($link);
?>
</programlisting>
</example>
<para> See also
<function>mysql_pconnect</function>, and
<function>mysql_close</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-create-db">
<refnamediv>
<refname>mysql_create_db</refname>
<refpurpose>Create a MySQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_create_db</function></funcdef>
<paramdef>string <parameter>database name</parameter></paramdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_create_db</function> attempts to create a new
database on the server associated with the specified link
identifier.
</para>
<example>
<title>MySQL create database example</title>
<programlisting role="php">
<?php
$link = mysql_pconnect ("kron", "jutta", "geheim")
or die ("Could not connect");
if (mysql_create_db ("my_db")) {
print ("Database created successfully\n");
} else {
printf ("Error creating database: %s\n", mysql_error ());
}
?>
</programlisting>
</example>
<para>
For downwards compatibility <function>mysql_createdb</function>
can also be used.
</para>
<para>
See also: <function>mysql_drop_db</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-data-seek">
<refnamediv>
<refname>mysql_data_seek</refname>
<refpurpose>Move internal result pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_data_seek</function></funcdef>
<paramdef>int <parameter>result_identifier</parameter></paramdef>
<paramdef>int <parameter>row_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on failure.
</para>
<para>
<function>mysql_data_seek</function> 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 <function>mysql_fetch_row</function> would return that row.
</para>
<para>
<parameter>Row_number</parameter> starts at 0.
</para>
<example>
<title>MySQL data seek example</title>
<programlisting role="php">
<?php
$link = mysql_pconnect ("kron", "jutta", "geheim")
or die ("Could not connect");
mysql_select_db ("samp_db")
or die ("Could not select database");
$query = "SELECT last_name, first_name FROM friends";
$result = mysql_query ($query)
or die ("Query failed");
# fetch rows in reverse order
for ($i = mysql_num_rows ($result) - 1; $i >=0; $i--) {
if (!mysql_data_seek ($result, $i)) {
printf ("Cannot seek to row %d\n", $i);
continue;
}
if(!($row = mysql_fetch_object ($result)))
continue;
printf ("%s %s<BR>\n", $row->last_name, $row->first_name);
}
mysql_free_result ($result);
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.mysql-db-name">
<refnamediv>
<refname>mysql_db_name</refname>
<refpurpose>Get result data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_db_name</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>row</parameter></paramdef>
<paramdef>mixed
<parameter>
<optional>field</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_db_name</function> takes as its first parameter
the result pointer from a call to
<function>mysql_list_dbs</function>. The
<parameter>row</parameter> parameter is an index into the result
set.
</para>
<para>
If an error occurs, FALSE is returned. Use
<function>mysql_errno</function> and
<function>mysql_error</function> to determine the nature of the
error.
</para>
<example>
<title><function>Mysql_db_name</function> example</title>
<programlisting role="php">
<?php
error_reporting(E_ALL);
mysql_connect('dbhost', 'username', 'password');
$db_list = mysql_list_dbs();
$i = 0;
$cnt = mysql_numrows($db_list);
while ($i < $cnt) {
echo mysql_db_name($db_list, $i) . "\n";
$i++;
}
?>
</programlisting>
</example>
<para>
For backward compatibility, <function>mysql_dbname</function> is
also accepted. This is deprecated, however.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-db-query">
<refnamediv>
<refname>mysql_db_query</refname>
<refpurpose>Send a MySQL query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_db_query</function></funcdef>
<paramdef>string <parameter>database</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive MySQL result identifier to the query result,
or false on error.
</para>
<para>
<function>mysql_db_query</function> 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 <function>mysql_connect</function> was called with no
arguments
</para>
<para>
See also <function>mysql_connect</function>.
</para>
<para>
For downwards
compatibility <function>mysql</function> can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-drop-db">
<refnamediv>
<refname>mysql_drop_db</refname>
<refpurpose>Drop (delete) a MySQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_drop_db</function></funcdef>
<paramdef>string <parameter>database_name</parameter></paramdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on failure.
</para>
<para>
<function>mysql_drop_db</function> attempts to drop (remove) an
entire database from the server associated with the specified
link identifier.
</para>
<para>
See also: <function>mysql_create_db</function>. For downward
compatibility <function>mysql_dropdb</function> can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-errno">
<refnamediv>
<refname>mysql_errno</refname>
<refpurpose>Returns the numerical value of the error message from previous
MySQL operation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_errno</function></funcdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the error number from the last mySQL function, or
<literal>0</literal> (zero) if no error occurred.
</para>
<para>
Errors coming back from the mySQL database backend no longer
issue warnings. Instead, use <function>mysql_errno</function> to
retrieve the error code. Note that this function only returns the
error code from the most recently executed mySQL function (not
including <function>mysql_error</function> and
<function>mysql_errno</function>), so if you want to use it,
make sure you check the value before calling another mySQL
function.
<informalexample>
<programlisting role="php">
<?php
mysql_connect("marliesle");
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_select_db("nonexistentdb");
echo mysql_errno().": ".mysql_error()."<BR>";
$conn = mysql_query("SELECT * FROM nonexistenttable");
echo mysql_errno().": ".mysql_error()."<BR>";
?>
</programlisting>
</informalexample>
</para>
<para>
See also: <function>mysql_error</function>
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-error">
<refnamediv>
<refname>mysql_error</refname>
<refpurpose>Returns the text of the error message from previous
MySQL operation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mysql_error</function></funcdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the error text from the last mySQL function, or
<literal>''</literal> (the empty string) if no error occurred.
</para>
<para>
Errors coming back from the mySQL database backend no longer
issue warnings. Instead, use <function>mysql_error</function> to
retrieve the error text. Note that this function only returns the
error text from the most recently executed mySQL function (not
including <function>mysql_error</function> and
<function>mysql_errno</function>), so if you want to use it, make
sure you check the value before calling another mySQL function.
<informalexample>
<programlisting role="php">
<?php
mysql_connect("marliesle");
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_select_db("nonexistentdb");
echo mysql_errno().": ".mysql_error()."<BR>";
$conn = mysql_query("SELECT * FROM nonexistenttable");
echo mysql_errno().": ".mysql_error()."<BR>";
?>
</programlisting>
</informalexample>
</para>
<para>
See also: <function>mysql_errno</function>
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-fetch-array">
<refnamediv>
<refname>mysql_fetch_array</refname>
<refpurpose>
Fetch a result row as an associative array, a numeric array, or both.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mysql_fetch_array</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int
<parameter>
<optional>result_type</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array that corresponds to the fetched row, or false
if there are no more rows.</para>
<para>
<function>mysql_fetch_array</function> is an extended version of
<function>mysql_fetch_row</function>. 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.
</para>
<para>
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.
<informalexample>
<programlisting>
select t1.f1 as foo t2.f1 as bar from t1, t2
</programlisting>
</informalexample>
</para>
<para>
An important thing to note is that using
<function>mysql_fetch_array</function> is NOT significantly
slower than using <function>mysql_fetch_row</function>, while it
provides a significant added value.
</para>
<para>
The optional second argument <parameter>result_type</parameter>
in <function>mysql_fetch_array</function> 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)
</para>
<para>
For further details, see also
<function>mysql_fetch_row</function> and
<function>mysql_fetch_assoc</function>.
</para>
<example>
<title><function>Mysql_fetch_array</function></title>
<programlisting role="php">
<?php
mysql_connect ($host, $user, $password);
$result = mysql_db_query ("database","select user_id, fullname from table");
while ($row = mysql_fetch_array ($result)) {
echo "user_id: ".$row["user_id"]."<br>\n";
echo "user_id: ".$row[0]."<br>\n";
echo "fullname: ".$row["fullname"]."<br>\n";
echo "fullname: ".$row[1]."<br>\n";
}
mysql_free_result ($result);
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.mysql-fetch-assoc">
<refnamediv>
<refname>mysql_fetch_assoc</refname>
<refpurpose>
Fetch a result row as an associative array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mysql_fetch_assoc</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array that corresponds to the fetched row,
or false if there are no more rows.</para>
<para>
<function>mysql_fetch_assoc</function> is eqivilant to calling
<function>mysql_fetch_array</function> with MYSQL_ASSOC for the
optional second parameter. It only returns an associative array.
This is the way <function>mysql_fetch_array</function> originally
worked. If you need the numeric indices as well as the
associative, use <function>mysql_fetch_array</function>.
</para>
<para>
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 <function>mysql_fetch_array</function> and
have it return the numeric indices as well.
</para>
<para>
An important thing to note is that using
<function>mysql_fetch_assoc</function> is NOT significantly
slower than using <function>mysql_fetch_row</function>, while it
provides a significant added value.
</para>
<para>
For further details, see also
<function>mysql_fetch_row</function> and
<function>mysql_fetch_array</function>.
</para>
<example>
<title><function>Mysql_fetch_assoc</function></title>
<programlisting role="php">
<?php
mysql_connect ($host, $user, $password);
$result = mysql_db_query ("database","select * from table");
while ($row = mysql_fetch_assoc ($result)) {
echo $row["user_id"];
echo $row["fullname"];
}
mysql_free_result ($result);
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.mysql-fetch-field">
<refnamediv>
<refname>mysql_fetch_field</refname>
<refpurpose>
Get column information from a result and return as an object
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>mysql_fetch_field</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int
<parameter>
<optional>field_offset</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an object containing field information.
</para>
<para>
<function>mysql_fetch_field</function> 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 <function>mysql_fetch_field</function> is retrieved.
</para>
<para>
The properties of the object are:
<itemizedlist>
<listitem>
<simpara>
name - column name
</simpara>
</listitem>
<listitem>
<simpara>
table - name of the table the column belongs to
</simpara>
</listitem>
<listitem>
<simpara>
max_length - maximum length of the column
</simpara>
</listitem>
<listitem>
<simpara>
not_null - 1 if the column cannot be null
</simpara>
</listitem>
<listitem>
<simpara>
primary_key - 1 if the column is a primary key
</simpara>
</listitem>
<listitem>
<simpara>
unique_key - 1 if the column is a unique key
</simpara>
</listitem>
<listitem>
<simpara>
multiple_key - 1 if the column is a non-unique key
</simpara>
</listitem>
<listitem>
<simpara>
numeric - 1 if the column is numeric
</simpara>
</listitem>
<listitem>
<simpara>
blob - 1 if the column is a BLOB
</simpara>
</listitem>
<listitem>
<simpara>
type - the type of the column
</simpara>
</listitem>
<listitem>
<simpara>
unsigned - 1 if the column is unsigned
</simpara>
</listitem>
<listitem>
<simpara>
zerofill - 1 if the column is zero-filled
</simpara>
</listitem>
</itemizedlist>
</para>
<example>
<title><function>Mysql_fetch_field</function></title>
<programlisting role="php">
<?php
mysql_connect ($host, $user, $password)
or die ("Could not connect");
$result = mysql_db_query ("database", "select * from table")
or die ("Query failed");
# get column metadata
$i = 0;
while ($i < mysql_num_fields ($result)) {
echo "Information for column $i:<BR>\n";
$meta = mysql_fetch_field ($result);
if (!$meta) {
echo "No information available<BR>\n";
}
echo "<PRE>
blob: $meta->blob
max_length: $meta->max_length
multiple_key: $meta->multiple_key
name: $meta->name
not_null: $meta->not_null
numeric: $meta->numeric
primary_key: $meta->primary_key
table: $meta->table
type: $meta->type
unique_key: $meta->unique_key
unsigned: $meta->unsigned
zerofill: $meta->zerofill
</PRE>";
$i++;
}
mysql_free_result ($result);
?>
</programlisting>
</example>
<para>
See also <function>mysql_field_seek</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-fetch-lengths">
<refnamediv>
<refname>mysql_fetch_lengths</refname>
<refpurpose>
Get the length of each output in a result
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mysql_fetch_lengths</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An array that corresponds to the lengths of each field
in the last row fetched by <function>mysql_fetch_row</function>,
or false on error.
</para>
<para>
<function>mysql_fetch_lengths</function> stores the lengths of
each result column in the last row returned by
<function>mysql_fetch_row</function>,
<function>mysql_fetch_array</function>, and
<function>mysql_fetch_object</function> in an array, starting at
offset 0.
</para>
<para>
See also: <function>mysql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-fetch-object">
<refnamediv>
<refname>mysql_fetch_object</refname>
<refpurpose>Fetch a result row as an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>mysql_fetch_object</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int
<parameter>
<optional>result_type</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an object with properties that correspond to the fetched
row, or false if there are no more rows.
</para>
<para>
<function>mysql_fetch_object</function> is similar to
<function>mysql_fetch_array</function>, 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).
</para>
<para>
The optional argument <parameter>result_type</parameter> is a
constant and can take the following values: MYSQL_ASSOC,
MYSQL_NUM, and MYSQL_BOTH.
</para>
<para>
Speed-wise, the function is identical to
<function>mysql_fetch_array</function>, and almost as quick as
<function>mysql_fetch_row</function> (the difference is
insignificant).
<example>
<title><function>mysql_fetch_object</function> example</title>
<programlisting role="php">
<?php
mysql_connect ($host, $user, $password);
$result = mysql_db_query ("database", "select * from table");
while ($row = mysql_fetch_object ($result)) {
echo $row->user_id;
echo $row->fullname;
}
mysql_free_result ($result);
?>
</programlisting>
</example>
</para>
<para>
See also: <function>mysql_fetch_array</function> and
<function>mysql_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-fetch-row">
<refnamediv>
<refname>mysql_fetch_row</refname>
<refpurpose>Get a result row as an enumerated array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>mysql_fetch_row</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An array that corresponds to the fetched row, or false
if there are no more rows.
</para>
<para>
<function>mysql_fetch_row</function> 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.
</para>
<para>
Subsequent call to <function>mysql_fetch_row</function> would
return the next row in the result set, or false if there are no
more rows.
</para>
<para>
See also: <function>mysql_fetch_array</function>,
<function>mysql_fetch_object</function>,
<function>mysql_data_seek</function>,
<function>mysql_fetch_lengths</function>, and
<function>mysql_result</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-field-flags">
<refnamediv>
<refname>mysql_field_flags</refname>
<refpurpose>
Get the flags associated with the specified field in a result
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mysql_field_flags</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_field_flags</function> 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 <function>explode</function>.
</para>
<para>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".
</para>
<para>
For downward compatibility <function>mysql_fieldflags</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-field-name">
<refnamediv>
<refname>mysql_field_name</refname>
<refpurpose>
Get the name of the specified field in a result
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mysql_field_name</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_index</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_field_name</function> returns the name of the
specified field index. <parameter>result</parameter> must be a
valid result identifier and <parameter>field_index</parameter> is
the numerical offset of the field.
</para>
<note>
<para>
<parameter>field_index</parameter> starts at 0.
</para>
<para>
e.g. The index of the third field would actually be 2, the index
of the fourth field would be 3 and so on.
</para>
</note>
<para>
<example>
<title><function>mysql_field_name</function> example</title>
<programlisting role="php">
// The users table consists of three fields:
// user_id
// username
// password.
$res = mysql_db_query("users", "select * from users", $link);
echo mysql_field_name($res, 0) . "\n";
echo mysql_field_name($res, 2);
</programlisting>
</example>
</para>
<para>
The above example would produce the following output:
<informalexample>
<programlisting>
user_id
password
</programlisting>
</informalexample>
</para>
<para>
For downwards compatibility <function>mysql_fieldname</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-field-len">
<refnamediv>
<refname>mysql_field_len</refname>
<refpurpose>
Returns the length of the specified field
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_field_len</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_field_len</function> returns the length of the
specified field.
</para>
<para>
For downward compatibility <function>mysql_fieldlen</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-field-seek">
<refnamediv>
<refname>mysql_field_seek</refname>
<refpurpose>
Set result pointer to a specified field offset
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_field_seek</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeks to the specified field offset. If the next call to
<function>mysql_fetch_field</function> doesn't include a field
offset, the field offset specified in
<function>mysql_field_seek</function> will be returned.
</para>
<para>
See also: <function>mysql_fetch_field</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-field-table">
<refnamediv>
<refname>mysql_field_table</refname>
<refpurpose>
Get name of the table the specified field is in
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mysql_field_table</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the name of the table that the specifed field is
in.
</para>
<para>
For downward compatibility <function>mysql_fieldtable</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-field-type">
<refnamediv>
<refname>mysql_field_type</refname>
<refpurpose>
Get the type of the specified field in a result
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mysql_field_type</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_field_type</function> is similar to the
<function>mysql_field_name</function> 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 <ulink url="&url.mysql.docs;">MySQL
documentation</ulink>.
<example>
<title>mysql field types</title>
<programlisting role="php">
<?php
mysql_connect ("localhost:3306");
mysql_select_db ("wisconsin");
$result = mysql_query ("SELECT * FROM onek");
$fields = mysql_num_fields ($result);
$rows = mysql_num_rows ($result);
$i = 0;
$table = mysql_field_table ($result, $i);
echo "Your '".$table."' table has ".$fields." fields and
".$rows." records <BR>";
echo "The table has the following fields <BR>";
while ($i < $fields) {
$type = mysql_field_type ($result, $i);
$name = mysql_field_name ($result, $i);
$len = mysql_field_len ($result, $i);
$flags = mysql_field_flags ($result, $i);
echo $type." ".$name." ".$len."
".$flags."<BR>";
$i++;
}
mysql_close();
?>
</programlisting>
</example>
</para>
<para>
For downward compatibility <function>mysql_fieldtype</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-free-result">
<refnamediv>
<refname>mysql_free_result</refname>
<refpurpose>Free result memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_free_result</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_free_result</function> will free all memory
associated with the result identifier <parameter>result</parameter>.
</para>
<para>
<function>mysql_free_result</function> 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.
</para>
<para>
For downward compatibility <function>mysql_freeresult</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-insert-id">
<refnamediv>
<refname>mysql_insert_id</refname>
<refpurpose>
Get the id generated from the previous INSERT operation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_insert_id</function></funcdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_insert_id</function> returns the ID generated for
an AUTO_INCREMENT column by the previous INSERT query using the
given <parameter>link_identifier</parameter>. If
<parameter>link_identifier</parameter> isn't specified, the last
opened link is assumed.
</para>
<para>
<function>mysql_insert_id</function> 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.
</para>
<note>
<para>
The value of the MySQL SQL function
<literal>LAST_INSERT_ID()</literal> always contains the most
recently generated AUTO_INCREMENT value, and is not reset
between queries.
</para>
</note>
<warning>
<para>
<function>mysql_insert_id</function> converts the return type of
the native MySQL C API function
<literal>mysql_insert_id()</literal> to a type of
<literal>long</literal>. If your AUTO_INCREMENT column has
a column type of BIGINT, the value returned by
<function>mysql_insert_id</function> will be incorrect.
Instead, use the internal MySQL SQL function
<literal>LAST_INSERT_ID()</literal>.
</para>
</warning>
</refsect1>
</refentry>
<refentry id="function.mysql-list-dbs">
<refnamediv>
<refname>mysql_list_dbs</refname>
<refpurpose>
List databases available on a MySQL server
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_list_dbs</function></funcdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_list_dbs</function> will return a result pointer
containing the databases available from the current mysql
daemon. Use the <function>mysql_tablename</function> function to
traverse this result pointer.
</para>
<para>
<example>
<title><function>mysql_list_dbs</function> example</title>
<programlisting role="php">
$link = mysql_connect('localhost', 'myname', 'secret');
$db_list = mysql_list_dbs($link);
while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}
</programlisting>
</example>
</para>
<para>
The above example would produce the following output:
<informalexample>
<programlisting>
database1
database2
database3
..
</programlisting>
</informalexample>
</para>
<note>
<para>
The above code would just as easily work with
<function>mysql_fetch_row</function> or other similar functions.
</para>
</note>
<para>
For downward compatibility <function>mysql_listdbs</function> can
also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-list-fields">
<refnamediv>
<refname>mysql_list_fields</refname>
<refpurpose>List MySQL result fields</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_list_fields</function></funcdef>
<paramdef>string <parameter>database_name</parameter></paramdef>
<paramdef>string <parameter>table_name</parameter></paramdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_list_fields</function> 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 <function>mysql_field_flags</function>,
<function>mysql_field_len</function>,
<function>mysql_field_name</function>, and
<function>mysql_field_type</function>.
</para>
<para>
A result identifier is a positive integer. The function returns
-1 if a error occurs. A string describing the error will be
placed in <literal>$phperrmsg</literal>, and unless the function
was called as <literal>@mysql()</literal> then this error string
will also be printed out.
</para>
<para>
<example>
<title><function>mysql_list_fields</function> example</title>
<programlisting role="php">
$link = mysql_connect('localhost', 'myname', 'secret');
$fields = mysql_list_fields("database1", "table1", $link);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
echo mysql_field_name($fields, $i) . "\n";;
}
</programlisting>
</example>
</para>
<para>
The above example would produce the following output:
<informalexample>
<programlisting>
field1
field2
field3
..
</programlisting>
</informalexample>
</para>
<para>
For downward compatibility <function>mysql_listfields</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-list-tables">
<refnamediv>
<refname>mysql_list_tables</refname>
<refpurpose>List tables in a MySQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_list_tables</function></funcdef>
<paramdef>string <parameter>database</parameter></paramdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_list_tables</function> takes a database name and
returns a result pointer much like the
<function>mysql_db_query</function> function. The
<function>mysql_tablename</function> function should be used to
extract the actual table names from the result pointer.
</para>
<para>
For downward compatibility <function>mysql_listtables</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-num-fields">
<refnamediv>
<refname>mysql_num_fields</refname>
<refpurpose>Get number of fields in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_num_fields</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_num_fields</function> returns the number of
fields in a result set.
</para>
<para>
See also:
<function>mysql_db_query</function>,
<function>mysql_query</function>,
<function>mysql_fetch_field</function>,
<function>mysql_num_rows</function>.</para>
<para>
For downward compatibility <function>mysql_numfields</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-num-rows">
<refnamediv>
<refname>mysql_num_rows</refname>
<refpurpose>Get number of rows in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_num_rows</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_num_rows</function> 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, use <function>mysql_affected_rows</function>.
</para>
<para>
See also:
<function>mysql_db_query</function>,
<function>mysql_query</function> and,
<function>mysql_fetch_row</function>.
</para>
<para>
For downward compatibility <function>mysql_numrows</function> can
also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-pconnect">
<refnamediv>
<refname>mysql_pconnect</refname>
<refpurpose>
Open a persistent connection to a MySQL Server
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_pconnect</function></funcdef>
<paramdef>string
<parameter>
<optional>hostname
<optional>:port</optional>
<optional>:/path/to/socket</optional>
</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter><optional>username</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>password</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive MySQL persistent link identifier on success,
or false on error.
</para>
<para>
<function>mysql_pconnect</function> establishes a connection
to a MySQL server. The following defaults are assumed for
missing optional parameters: <parameter>host:port</parameter> =
'localhost:3306', <parameter>username</parameter> = name of the
user that owns the server process and
<parameter>password</parameter> = empty password.
</para>
<para>
The hostname string can also include a port
number. eg. "hostname:port" or a path to a socket
eg. ":/path/to/socket" for the localhost.
<note>
<para>
Support for ":port" wass added in 3.0B4.
</para>
<para>
Support for the ":/path/to/socket" was added in
3.0.10.
</para>
</note>
</para>
<para>
<function>mysql_pconnect</function> acts very much like
<function>mysql_connect</function> with two major differences.
</para>
<para>
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.
</para>
<para>
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 (<function>mysql_close</function> will not
close links established by <function>mysql_pconnect</function>).
</para>
<para>
This type of links is therefore called 'persistent'.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-query">
<refnamediv>
<refname>mysql_query</refname>
<refpurpose>Send a MySQL query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_query</function></funcdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int
<parameter><optional>link_identifier</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_query</function> sends a query to the currently
active database on the server that's associated with the
specified link identifier. If
<parameter>link_identifier</parameter> isn't specified, the last
opened link is assumed. If no link is open, the function tries
to establish a link as if <function>mysql_connect</function> was
called with no arguments, and use it.
</para>
<note>
<para>
The query string should not end with a semicolon.
</para>
</note>
<para>
<function>mysql_query</function> 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.
</para>
<para>
The following query is syntactically invalid, so
<function>mysql_query</function> fails and returns FALSE:
<example>
<title><function>mysql_query</function></title>
<programlisting role="php">
<?php
$result = mysql_query ("SELECT * WHERE 1=1")
or die ("Invalid query");
?>
</programlisting>
</example>
</para>
<para>
The following query is semantically invalid if
<literal>my_col</literal> is not a column in the table
<literal>my_tbl</literal>, so <function>mysql_query</function>
fails and returns FALSE:
<example>
<title><function>mysql_query</function></title>
<programlisting role="php">
<?php
$result = mysql_query ("SELECT my_col FROM my_tbl")
or die ("Invalid query");
?>
</programlisting>
</example>
</para>
<para>
<function>mysql_query</function> will also fail and return FALSE
if you don't have permission to access the table(s) referenced by
the query.
</para>
<para>
Assuming the query succeeds, you can call
<function>mysql_num_rows</function> to find out how many rows
were returned for a SELECT statment or
<function>mysql_affected_rows</function> to find out how many
rows were affected by a DELETE, INSERT, REPLACE, or UPDATE
statement.
</para>
<para>
For SELECT statements, <function>mysql_query</function> returns a
new result identifier that you can pass to
<function>mysql_result</function>. When you are done with the
result set, you can free the resources associated with it by
calling <function>mysql_free_result</function>. Although, the
memory will automatically be freed at the end of the script's
execution.
</para>
<para>
See also: <function>mysql_affected_rows</function>,
<function>mysql_db_query</function>,
<function>mysql_free_result</function>,
<function>mysql_result</function>,
<function>mysql_select_db</function>, and
<function>mysql_connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-result">
<refnamediv>
<refname>mysql_result</refname>
<refpurpose>Get result data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>mysql_result</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>row</parameter></paramdef>
<paramdef>mixed
<parameter>
<optional>field</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_result</function> 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's name (fieldname.tablename). If the column name has been
aliased ('select foo as bar from...'), use the alias instead of
the column name.
</para>
<para>
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
<function>mysql_result</function>. Also, note that specifying a
numeric offset for the field argument is much quicker than
specifying a fieldname or tablename.fieldname argument.
</para>
<para>
Calls to <function>mysql_result</function> should not be mixed
with calls to other functions that deal with the result set.
</para>
<para>
Recommended high-performance alternatives:
<function>mysql_fetch_row</function>,
<function>mysql_fetch_array</function>, and
<function>mysql_fetch_object</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-select-db">
<refnamediv>
<refname>mysql_select_db</refname>
<refpurpose>Select a MySQL database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>mysql_select_db</function></funcdef>
<paramdef>string <parameter>database_name</parameter></paramdef>
<paramdef>int
<parameter>
<optional>link_identifier</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on error.
</para>
<para>
<function>mysql_select_db</function> 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 <function>mysql_connect</function> was
called, and use it.
</para>
<para>
Every subsequent call to <function>mysql_query</function> will be
made on the active database.
</para>
<para> See also:
<function>mysql_connect</function>,
<function>mysql_pconnect</function>, and
<function>mysql_query</function>.
</para>
<para>
For downward compatibility <function>mysql_selectdb</function>
can also be used.
</para>
</refsect1>
</refentry>
<refentry id="function.mysql-tablename">
<refnamediv>
<refname>mysql_tablename</refname>
<refpurpose>Get table name of field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mysql_tablename</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>i</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>mysql_tablename</function> takes a result pointer
returned by the <function>mysql_list_tables</function> function
as well as an integer index and returns the name of a table. The
<function>mysql_num_rows</function> function may be used to
determine the number of tables in the result pointer.
<example>
<title><function>Mysql_tablename</function> Example</title>
<programlisting role="php">
<?php
mysql_connect ("localhost:3306");
$result = mysql_list_tables ("wisconsin");
$i = 0;
while ($i < mysql_num_rows ($result)) {
$tb_names[$i] = mysql_tablename ($result, $i);
echo $tb_names[$i] . "<BR>";
$i++;
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/network.xml
+++ phpdoc/nl/functions/network.xml
<reference id="ref.network">
<title>Network Functions</title>
<titleabbrev>Network</titleabbrev>
<refentry id="function.checkdnsrr">
<refnamediv>
<refname>checkdnsrr</refname>
<refpurpose>
Check DNS records corresponding to a given Internet host name or
IP address
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>checkdnsrr</function></funcdef>
<paramdef>string <parameter>host</parameter></paramdef>
<paramdef>string
<parameter><optional>type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Searches DNS for records of type <parameter>type</parameter>
corresponding to <parameter>host</parameter>. Returns true if any
records are found; returns false if no records were found or if
an error occurred.
</simpara>
<simpara>
<parameter>type</parameter> may be any one of: A, MX, NS, SOA,
PTR, CNAME, or ANY. The default is MX.
</simpara>
<simpara>
<parameter>Host</parameter> may either be the IP address in
dotted-quad notation or the host name.
</simpara>
<simpara>
See also <function>getmxrr</function>,
<function>gethostbyaddr</function>,
<function>gethostbyname</function>,
<function>gethostbynamel</function>, and the named(8) manual
page.
</simpara>
</refsect1>
</refentry>
<refentry id="function.closelog">
<refnamediv>
<refname>closelog</refname>
<refpurpose>Close connection to system logger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>closelog</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>Closelog</function> closes the descriptor being used to
write to the system logger. The use of
<function>closelog</function> is optional.
</para>
<para>
See also <function>define_syslog_variables</function>,
<function>syslog</function> and
<function>openlog</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.debugger-off">
<refnamediv>
<refname>debugger_off</refname>
<refpurpose>Disable internal PHP debugger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>debugger_off</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Disables the internal PHP debugger. The debugger is still under
development.
</para>
</refsect1>
</refentry>
<refentry id="function.debugger-on">
<refnamediv>
<refname>debugger_on</refname>
<refpurpose>Enable internal PHP debugger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>debugger_on</function></funcdef>
<paramdef>string <parameter>address</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Enables the internal PHP debugger, connecting it to
<parameter>address</parameter>. The debugger is still under
development.
</para>
</refsect1>
</refentry>
<refentry id="function.define-syslog-variables">
<refnamediv>
<refname>define_syslog_variables</refname>
<refpurpose>Initializes all syslog related constants</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>define_syslog_varaibles</function></funcdef>
<paramdef>void</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Initializes all constants used in the syslog functions.
</para>
<para>
See also <function>openlog</function>,
<function>syslog</function> and
<function>closelog</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fsockopen">
<refnamediv>
<refname>fsockopen</refname>
<refpurpose>
Open Internet or Unix domain socket connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>fsockopen</function></funcdef>
<paramdef>
string <parameter><optional>udp://</optional>hostname</parameter>
</paramdef>
<paramdef>int <parameter>port</parameter></paramdef>
<paramdef>int
<parameter><optional>errno</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>errstr</optional></parameter>
</paramdef>
<paramdef>double
<parameter><optional>timeout</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Initiates a stream connection in the Internet (AF_INET, using TCP
or UDP) or Unix (AF_UNIX) domain. For the Internet domain, it
will open a TCP socket connection to
<parameter>hostname</parameter> on port
<parameter>port</parameter>. <parameter>hostname</parameter> may
in this case be either a fully qualified domain name or an IP
address. For UDP connections, you need to explicitly specify the
protocol: <parameter>udp://hostname</parameter>. For the Unix
domain, <parameter>hostname</parameter> will be used as the path
to the socket, <parameter>port</parameter> must be set to 0 in
this case. The optional <parameter>timeout</parameter> can be
used to set a timeout in seconds for the connect system call.
</para>
<para>
<function>Fsockopen</function> returns a file pointer which may
be used together with the other file functions (such as
<function>fgets</function>, <function>fgetss</function>,
<function>fputs</function>, <function>fclose</function>, and
<function>feof</function>).
</para>
<para>
If the call fails, it will return false and if the optional
<parameter>errno</parameter> and <parameter>errstr</parameter>
arguments are present they will be set to indicate the actual
system level error that occurred on the system-level
<literal>connect()</literal> call. If the returned errno is 0 and
the function returned false, it is an indication that the error
occurred before the <literal>connect()</literal> call. This is
most likely due to a problem initializing the socket. Note that
the <parameter>errno</parameter> and
<parameter>errstr</parameter> arguments must be passed by
reference.
</para>
<para>
Depending on the environment, the Unix domain or the optional
connect timeout may not be available.
</para>
<para>
The socket will by default be opened in blocking mode. You can
switch it to non-blocking mode by using
<function>socket_set_blocking</function>.
<example>
<title><function>Fsockopen</function> Example</title>
<programlisting role="php">
$fp = fsockopen ("www.php.net", 80, &$errno, &$errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
</programlisting>
</example>
The example below shows how to retrieve the day and time
from the UDP service "daytime" (port 13) in your own machine.
<example>
<title>Using UDP connection</title>
<programlisting role="php">
<?php
$fp = fsockopen("udp://127.0.0.1", 13, &$errno, &$errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br>\n";
} else {
fwrite($fp,"\n");
echo fread($fp, 26);
fclose($fp);
}
?>
</programlisting>
</example>
See also: <function>pfsockopen</function>,
<function>socket_set_blocking</function>,
<function>socket_set_timeout</function>, <function>fgets</function>,
<function>fgetss</function>, <function>fputs</function>,
<function>fclose</function>, and <function>feof</function>).
</para>
</refsect1>
</refentry>
<refentry id="function.gethostbyaddr">
<refnamediv>
<refname>gethostbyaddr</refname>
<refpurpose>
Get the Internet host name corresponding to a given IP address
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gethostbyaddr</function></funcdef>
<paramdef>string <parameter>ip_address</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the host name of the Internet host specified by
<parameter>ip_address</parameter>. If an error occurs, returns
<parameter>ip_address</parameter>.
</para>
<para>
See also <function>gethostbyname</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gethostbyname">
<refnamediv>
<refname>gethostbyname</refname>
<refpurpose>
Get the IP address corresponding to a given Internet host name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gethostbyname</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the IP address of the Internet host specified by
<parameter>hostname</parameter>.
</para>
<para>
See also <function>gethostbyaddr</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gethostbynamel">
<refnamediv>
<refname>gethostbynamel</refname>
<refpurpose>
Get a list of IP addresses corresponding to a given Internet host
name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>gethostbynamel</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a list of IP addresses to which the Internet host
specified by <parameter>hostname</parameter> resolves.
</para>
<para>
See also <function>gethostbyname</function>,
<function>gethostbyaddr</function>,
<function>checkdnsrr</function>, <function>getmxrr</function>,
and the <literal>named(8)</literal> manual page.
</para>
</refsect1>
</refentry>
<refentry id="function.getmxrr">
<refnamediv>
<refname>getmxrr</refname>
<refpurpose>
Get MX records corresponding to a given Internet host name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getmxrr</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>array <parameter>mxhosts</parameter></paramdef>
<paramdef>array
<parameter><optional>weight</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Searches DNS for MX records corresponding to
<parameter>hostname</parameter>. Returns true if any records are
found; returns false if no records were found or if an error
occurred.
</simpara>
<simpara>
A list of the MX records found is placed into the array
<parameter>mxhosts</parameter>. If the
<parameter>weight</parameter> array is given, it will be filled
with the weight information gathered.
</simpara>
<simpara>
See also <function>checkdnsrr</function>,
<function>gethostbyname</function>,
<function>gethostbynamel</function>,
<function>gethostbyaddr</function>, and the
<literal>named(8)</literal> manual page.
</simpara>
</refsect1>
</refentry>
<refentry id="function.getprotobyname">
<refnamediv>
<refname>getprotobyname</refname>
<refpurpose>
Get protocol number associated with protocol name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getprotobyname</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Getprotobyname</function> returns the protocol number
associated with the protocol <parameter>name</parameter> as per
/etc/protocols.
</para>
<para>
See also: <function>getprotobynumber</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getprotobynumber">
<refnamediv>
<refname>getprotobynumber</refname>
<refpurpose>
Get protocol name associated with protocol number
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>getprotobynumber</function></funcdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Getprotobynumber</function> returns the protocol name
associated with protocol <parameter>number</parameter> as per
/etc/protocols.
</para>
<para>
See also: <function>getprotobyname</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getservbyname">
<refnamediv>
<refname>getservbyname</refname>
<refpurpose>
Get port number associated with an Internet service and protocol
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>getservbyname</function></funcdef>
<paramdef>string <parameter>service</parameter></paramdef>
<paramdef>string <parameter>protocol</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Getservbyname</function> returns the Internet port
which corresponds to <parameter>service</parameter> for the
specified <parameter>protocol</parameter> as per
<filename>/etc/services</filename>.
<parameter>protocol</parameter> is either <literal>TCP</literal>
or <literal>UDP</literal>.
</para>
<para>
See also: <function>getservbyport</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getservbyport">
<refnamediv>
<refname>getservbyport</refname>
<refpurpose>
Get Internet service which corresponds to port and protocol
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>getservbyport</function></funcdef>
<paramdef>int <parameter>port</parameter></paramdef>
<paramdef>string <parameter>protocol</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Getservbyport</function> returns the Internet service
associated with <parameter>port</parameter> for the specified
<parameter>protocol</parameter> as per /etc/services.
<parameter>protocol</parameter> is either <literal>TCP</literal>
or <literal>UDP</literal>.
</para>
<para>
See also: <function>getservbyname</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ip2long">
<refnamediv>
<refname>ip2long</refname>
<refpurpose>
Converts a string containing an (IPv4) Internet Protocol dotted address
into a proper address.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ip2long</function></funcdef>
<paramdef>string <parameter>ip_address</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function <function>ip2long</function> generates an IPv4 Internet
network address from its Internet standard format (dotted string)
representation.
<example>
<title><function>Ip2long</function> Example</title>
<programlisting role="php">
<?
$ip = gethostbyname("www.php.net");
$out = "The following URLs are equivalent:<br>\n";
$out .= "http://www.php.net/, http://".$ip."/, and
http://".ip2long($ip)."/<br>\n";
echo $out;
?>
</programlisting>
</example>
</para>
<para>
See also: <function>long2ip</function>
</para>
</refsect1>
</refentry>
<refentry id="function.long2ip">
<refnamediv>
<refname>long2ip</refname>
<refpurpose>
Converts an (IPv4) Internet network address into a string in Internet
standard dotted format
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>long2ip</function></funcdef>
<paramdef>int <parameter>proper_address</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function <function>long2ip</function> generates an Internet address
in dotted format (i.e.: aaa.bbb.ccc.ddd) from the proper address
representation.
</para>
<para>
See also: <function>ip2long</function>
</para>
</refsect1>
</refentry>
<refentry id="function.openlog">
<refnamediv>
<refname>openlog</refname>
<refpurpose>Open connection to system logger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>openlog</function></funcdef>
<paramdef>string <parameter>ident</parameter></paramdef>
<paramdef>int <parameter>option</parameter></paramdef>
<paramdef>int <parameter>facility</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Openlog</function> opens a connection to the system
logger for a program. The string <parameter>ident</parameter> is
added to each message. Values for <parameter>option</parameter>
and <parameter>facility</parameter> are given below.
The <parameter>option</parameter> argument is used to indicate
what loggin options will be used when generating a log message.
The <parameter>facility</parameter> 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 <function>openlog</function> is optional. It
will automatically be called by <function>syslog</function> if
necessary, in which case <parameter>ident</parameter> will default
to false.
</para>
<para>
<table>
<title><function>Openlog</function> Options</title>
<tgroup cols="2">
<thead>
<row>
<entry>Constant</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>LOG_CONS</entry>
<entry>
if there is an error while sending data to the system logger,
write directly to the system console
</entry>
</row>
<row>
<entry>LOG_NDELAY</entry>
<entry>
open the connection to the logger immediately
</entry>
</row>
<row>
<entry>LOG_ODELAY</entry>
<entry>
(default) delay openning the connection until the first
message is logged
</entry>
</row>
<row>
<entry>LOG_PERROR</entry>
<entry>print log message also to standard error</entry>
</row>
<row>
<entry>LOG_PID</entry>
<entry>include PID with each message</entry>
</row>
</tbody>
</tgroup>
</table>
You can use one or more of this options. When using multiple options
you need to <literal>OR</literal> them, i.e. to open the connection
immediately, write to the consoloe and include the PID in each message,
you will use: <literal>LOG_CONS | LOG_NDELAY | LOG_PID</literal>
</para>
<para>
<table>
<title><function>Openlog</function> Facilities</title>
<tgroup cols="2">
<thead>
<row>
<entry>Constant</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>LOG_AUTH</entry>
<entry>
security/authorization messages (use LOG_AUTHPRIV instead
in systems where that constant is defined)
</entry>
</row>
<row>
<entry>LOG_AUTHPRIV</entry>
<entry>security/authorization messages (private)</entry>
</row>
<row>
<entry>LOG_CRON</entry>
<entry>clock daemon (cron and at)</entry>
</row>
<row>
<entry>LOG_DAEMON</entry>
<entry>other system daemons</entry>
</row>
<row>
<entry>LOG_KERN</entry>
<entry>kernel messages</entry>
</row>
<row>
<entry>LOG_LOCAL0 ... LOG_LOCAL7</entry>
<entry>reserved for local use</entry>
</row>
<row>
<entry>LOG_LPR</entry>
<entry>line printer subsystem</entry>
</row>
<row>
<entry>LOG_MAIL</entry>
<entry>mail subsystem</entry>
</row>
<row>
<entry>LOG_NEWS</entry>
<entry>USENET news subsystem</entry>
</row>
<row>
<entry>LOG_SYSLOG</entry>
<entry>messages generated internally by syslogd</entry>
</row>
<row>
<entry>LOG_USER</entry>
<entry>generic user-level messages</entry>
</row>
<row>
<entry>LOG_UUCP</entry>
<entry>UUCP subsystem</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
See also <function>define_syslog_variables</function>,
<function>syslog</function> and
<function>closelog</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pfsockopen">
<refnamediv>
<refname>pfsockopen</refname>
<refpurpose>
Open persistent Internet or Unix domain socket connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pfsockopen</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>int <parameter>port</parameter></paramdef>
<paramdef>int
<parameter><optional>errno</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>errstr</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>timeout</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function behaves exactly as <function>fsockopen</function>
with the difference that the connection is not closed after the
script finishes. It is the persistent version of
<function>fsockopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.socket-get-status">
<refnamediv>
<refname>socket_get_status</refname>
<refpurpose>
Returns information about existing socket resource
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>socket_get_status</function></funcdef>
<paramdef>resource
<parameter>socket_get_status</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns information about an existing socket resource. Currently
returns four entries in the result array:
</para>
<itemizedlist>
<listitem>
<para>
<parameter>timed_out</parameter> (bool) - The socket timed out
waiting for data
</para>
</listitem>
<listitem>
<para>
<parameter>blocked</parameter> (bool) - The socket was blocked
</para>
</listitem>
<listitem>
<para>
<parameter>eof</parameter> (bool) - Indicates EOF event
</para>
</listitem>
<listitem>
<para>
<parameter>unread_bytes</parameter> (int) - Number of bytes
left in the socket buffer
</para>
</listitem>
</itemizedlist>
<para>
See also
<function>accept_connect</function>,
<function>bind</function>,
<function>connect</function>,
<function>listen</function>, and
<function>strerror</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.socket-set-blocking">
<refnamediv>
<refname>socket_set_blocking</refname>
<refpurpose>Set blocking/non-blocking mode on a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>socket_set_blocking</function></funcdef>
<paramdef>int <parameter>socket descriptor</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
If <parameter>mode</parameter> is false, the given socket
descriptor will be switched to non-blocking mode, and if true, it
will be switched to blocking mode. This affects calls like
<function>fgets</function> that read from the socket. In
non-blocking mode an <function>fgets</function> call will always
return right away while in blocking mode it will wait for data to
become available on the socket.
</para>
<para>
This function was previously called as
<function>set_socket_blocking</function> but this usage is deprecated.
</para>
</refsect1>
</refentry>
<refentry id="function.socket-set-timeout">
<refnamediv>
<refname>socket_set_timeout</refname>
<refpurpose>Set timeout period on a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>socket_set_timeout</function></funcdef>
<paramdef>int <parameter>socket descriptor</parameter></paramdef>
<paramdef>int <parameter>seconds</parameter></paramdef>
<paramdef>int <parameter>microseconds</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the timeout value on <parameter>socket descriptor</parameter>,
expressed in the sum of <parameter>seconds</parameter> and
<parameter>microseconds</parameter>.
<example>
<title><function>socket_set_timeout</function> Example</title>
<programlisting role="php">
<?php
$fp = fsockopen("www.php.net", 80);
if(!$fp) {
echo "Unable to open\n";
} else {
fputs($fp,"GET / HTTP/1.0\n\n");
$start = time();
socket_set_timeout($fp, 2);
$res = fread($fp, 2000);
var_dump(socket_get_status($fp));
fclose($fp);
print $res;
}
?>
</programlisting>
</example>
</para>
<para>
This function was previously called as
<function>set_socket_timeout</function> but this usage is deprecated.
</para>
<para>
See also: <function>fsockopen</function> and
<function>fopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.syslog">
<refnamediv>
<refname>syslog</refname>
<refpurpose>Generate a system log message</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>syslog</function></funcdef>
<paramdef>int <parameter>priority</parameter></paramdef>
<paramdef>string <parameter>message</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Syslog</function> generates a log message that will be
distributed by the system logger.
<parameter>priority</parameter> 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 <literal>%m</literal> will be replaced by the
error message string (strerror) corresponding to the present
value of <errortype>errno</errortype>.
</para>
<para>
<table>
<title><function>Syslog</function> Priorities (in descending
order)</title>
<tgroup cols="2">
<thead>
<row>
<entry>Constant</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>LOG_EMERG</entry>
<entry>system is unusable</entry>
</row>
<row>
<entry>LOG_ALERT</entry>
<entry>action must be taken immediately</entry>
</row>
<row>
<entry>LOG_CRIT</entry>
<entry>critical conditions</entry>
</row>
<row>
<entry>LOG_ERR</entry>
<entry>error conditions</entry>
</row>
<row>
<entry>LOG_WARNING</entry>
<entry>warning conditions</entry>
</row>
<row>
<entry>LOG_NOTICE</entry>
<entry>normal, but significant, condition</entry>
</row>
<row>
<entry>LOG_INFO</entry>
<entry>informational message</entry>
</row>
<row>
<entry>LOG_DEBUG</entry>
<entry>debug-level message</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<example>
<title>Using <function>syslog</function></title>
<programlisting role="php">
<?php
define_syslog_variables();
// open syslog, include the process ID and also send
// the log to standard error, and use a user defined
// logging mechanism
openlog("myScripLog", LOG_PID | LOG_PERROR, LOG_LOCAL0);
// some code
if (authorized_client()) {
// do something
} else {
// unauthorized client!
// log the attempt
$access = date("Y/m/d H:i:s");
syslog(LOG_WARNING,"Unauthorized client: $access $REMOTE_ADDR
($HTTP_USER_AGENT)");
}
closelog();
?>
</programlisting>
</example>
For information on setting up a user defined log handler, see the
<citerefentry><refentrytitle>syslog.conf</refentrytitle>
<manvolnum>5</manvolnum></citerefentry> Unix manual page. More
information on the syslog facilities and option can be found in the man
pages for <citerefentry><refentrytitle>syslog</refentrytitle>
<manvolnum>3</manvolnum></citerefentry> on Unix machines.
</para>
<para>
On Windows NT, the syslog service is emulated using the Event
Log.
</para>
<para>
See also <function>define_syslog_variables</function>,
<function>openlog</function> and
<function>closelog</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/nis.xml
+++ phpdoc/nl/functions/nis.xml
<reference id="ref.nis">
<title>YP/NIS Functions</title>
<titleabbrev>YP/NIS</titleabbrev>
<partintro>
<para>
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 <ulink url="&url.nis;">
Introduction to YP/NIS</ulink>. There is also a book called <ulink
url="&url.nis.book;">Managing NFS and NIS</ulink> by Hal Stern.
</para>
<para>
To get these functions to work, you have to configure PHP with
<option role="configure">--with-yp</option>.
</para>
</partintro>
<refentry id="function.yp-get-default-domain">
<refnamediv>
<refname>yp_get_default_domain</refname>
<refpurpose>Fetches the machine's default NIS domain</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yp_get_default_domain</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_get_default_domain</function> returns the default
domain of the node or FALSE. Can be used as the domain parameter
for successive NIS calls.
</para>
<para>
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.
</para>
<para>
<example>
<title>Example for the default domain</title>
<programlisting role="php">
<?php
$domain = yp_get_default_domain();
echo "Default NIS domain is: " . $domain;
?>
</programlisting>
</example>
</para>
<!--
<para>
See also: <link linkend="function.yp-errno">yp_errno</link> and
<link linkend="function.yp-err-string">yp_err_string</link>
</para>
-->
</refsect1>
</refentry>
<refentry id="function.yp-order">
<refnamediv>
<refname>yp_order</refname>
<refpurpose>Returns the order number for a map</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yp_order</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>map</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_order</function> returns the order number for a map
or FALSE.
</para>
<para>
<example>
<title>Example for the NIS order</title>
<programlisting role="php">
<?php
$number = yp_order($domain,$mapname);
echo "Order number for this map is: " . $order;
?>
</programlisting>
</example>
</para>
<para>
See also <function>yp-get-default-domain</function>.
<!--
linkend="function.yp-errno">yp_errno</link> and <link
linkend="function.yp-err-string">yp_err_string</link>
-->
</para>
</refsect1>
</refentry>
<refentry id="function.yp-master">
<refnamediv>
<refname>yp_master</refname>
<refpurpose>
Returns the machine name of the master NIS server for a map
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>yp_master</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>map</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_master</function> returns the machine name of
the master NIS server for a map.
</para>
<para>
<example>
<title>Example for the NIS master</title>
<programlisting role="php">
<?php
$number = yp_master ($domain, $mapname);
echo "Master for this map is: " . $master;
?>
</programlisting>
</example>
</para>
<para>
See also <function>yp-get-default-domain</function>.
<!--
linkend="function.yp-errno">yp_errno</link> and <link
linkend="function.yp-err-string">yp_err_string</link>
-->
</para>
</refsect1>
</refentry>
<refentry id="function.yp-match">
<refnamediv>
<refname>yp_match</refname>
<refpurpose>Returns the matched line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>yp_match</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>map</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_match</function> returns the value associated with
the passed key out of the specified map or FALSE. This key must
be exact.</para>
<para>
<example>
<title>Example for NIS match</title>
<programlisting role="php">
<?php
$entry = yp_match ($domain, "passwd.byname", "joe");
echo "Matched entry is: " . $entry;
?>
</programlisting>
</example>
</para>
<para>
In this case this could be: joe:##joe:11111:100:Joe
User:/home/j/joe:/usr/local/bin/bash
</para>
<para>
See also <function>yp-get-default-domain</function>
<!--
linkend="function.yp-errno">yp_errno</link> and <link
linkend="function.yp-err-string">yp_err_string</link>
-->
</para>
</refsect1>
</refentry>
<refentry id="function.yp-first">
<refnamediv>
<refname>yp_first</refname>
<refpurpose>
Returns the first key-value pair from the named map
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>yp_first</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>map</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_first</function> returns the first key-value
pair from the named map in the named domain, otherwise FALSE.
</para>
<para>
<example>
<title>Example for the NIS first</title>
<programlisting role="php">
<?php
$entry = yp_first($domain, "passwd.byname");
$key = key($entry);
echo "First entry in this map has key " . $key
. " and value " . $entry[$key];
?>
</programlisting>
</example>
</para>
<para>
See also <function>yp-get-default-domain</function>
<!--
<link linkend="function.yp-errno">yp_errno</link> and <link
linkend="function.yp-err-string">yp_err_string</link>
-->
</para>
</refsect1>
</refentry>
<refentry id="function.yp-next">
<refnamediv>
<refname>yp_next</refname>
<refpurpose>Returns the next key-value pair in the named
map.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>yp_next</function></funcdef>
<paramdef>string <parameter>domain</parameter></paramdef>
<paramdef>string <parameter>map</parameter></paramdef>
<paramdef>string <parameter>key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_next</function> returns the next key-value pair in
the named map after the specified key or FALSE.
</para>
<para>
<example>
<title>Example for NIS next</title>
<programlisting role="php">
<?php
$entry = yp_next ($domain, "passwd.byname", "joe");
if (!$entry) {
echo yp_errno() . ": " . yp_err_string();
}
$key = key ($entry);
echo "The next entry after joe has key " . $key
. " and value " . $entry[$key];
?>
</programlisting>
</example>
</para>
<para>
See also <function>yp-get-default-domain</function>.
<!--
<link linkend="function.yp-errno">yp_errno</link> and <link
linkend="function.yp-err-string">yp_err_string</link>
-->
</para>
</refsect1>
</refentry>
<!-- Function doesn't exist
<refentry id="function.yp-errno">
<refnamediv>
<refname>yp_errno</refname>
<refpurpose>
Returns the error code of the previous operation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yp_errno</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_errno</function> returns the error code of the
previous operation.
</para>
<para>
Possible errors are:
</para>
<para>
<simplelist>
<member>1 args to function are bad</member>
<member>2 RPC failure - domain has been unbound</member>
<member>3 can't bind to server on this domain</member>
<member>4 no such map in server's domain</member>
<member>5 no such key in map</member>
<member>6 internal yp server or client error</member>
<member>7 resource allocation failure</member>
<member>8 no more records in map database</member>
<member>9 can't communicate with portmapper</member>
<member>10 can't communicate with ypbind</member>
<member>11 can't communicate with ypserv</member>
<member>12 local domain name not set</member>
<member>13 yp database is bad</member>
<member>14 yp version mismatch</member>
<member>15 access violation</member>
<member>16 database busy</member>
</simplelist>
</para>
<para>
See also <function>yp_err_string</function>.
</para>
</refsect1>
</refentry>
-->
<!-- Function doesn't exist
<refentry id="function.yp-err-string">
<refnamediv>
<refname>yp_err_string</refname>
<refpurpose>
Returns the error string associated with the previous operation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>yp_err_string</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yp_err_string</function> returns the error message
associated with the previous operation. Useful to indicate what
exactly went wrong.
</para>
<para>
<example>
<title>Example for NIS errors</title>
<programlisting role="php">
<?php
echo "Error: " . yp_err_string();
?>
</programlisting>
</example>
</para>
<para>
See also <function>yp_errno</function>.
</para>
</refsect1>
</refentry>
-->
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/oci8.xml
+++ phpdoc/nl/functions/oci8.xml
<reference id="ref.oci8">
<title>Oracle 8 functions</title>
<titleabbrev>OCI8</titleabbrev>
<partintro>
<para>
These functions allow you to access Oracle8 and Oracle7 databases.
It uses the Oracle8 Call-Interface (OCI8). You will need the Oracle8
client libraries to use this extension.
</para>
<para>
This extension is more flexible than the standard 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.
</para>
<para>
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:
<itemizedlist>
<listitem>
<simpara>
ORACLE_HOME
</simpara>
</listitem>
<listitem>
<simpara>
ORACLE_SID
</simpara>
</listitem>
<listitem>
<simpara>
LD_PRELOAD
</simpara>
</listitem>
<listitem>
<simpara>
LD_LIBRARY_PATH
</simpara>
</listitem>
<listitem>
<simpara>
NLS_LANG
</simpara>
</listitem>
<listitem>
<simpara>
ORA_NLS33
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
After setting up the environment variables for your webserver user,
be sure to also add the webserver user (nobody, www) to the oracle
group.
</para>
<para>
<example>
<title>OCI Hints</title>
<programlisting role="php">
<?php
// by sergo@bacup.ru
// Use option: OCI_DEFAULT for execute command to delay execution
OCIExecute($stmt, OCI_DEFAULT);
// for retrieve data use (after fetch):
$result = OCIResult($stmt, $n);
if (is_object ($result)) $result = $result->load();
// For INSERT or UPDATE statetment use:
$sql = "insert into table (field1, field2) values (field1 = 'value',
field2 = empty_clob()) returning field2 into :field2";
OCIParse($conn, $sql);
$clob = OCINewDescriptor($conn, OCI_D_LOB);
OCIBindByName ($stmt, ":field2", &$clob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);
$clob->save ("some text");
?>
</programlisting>
</example>
</para>
<para>
You can easily access stored procedures in the same way as you
would from the commands line.
<example>
<title>Using Stored Procedures</title>
<programlisting role="php">
<?php
// by webmaster@remoterealty.com
$sth = OCIParse ( $dbh, "begin sp_newaddress( :address_id, '$firstname',
'$lastname', '$company', '$address1', '$address2',
'$city', '$state',
'$postalcode', '$country', :error_code );end;" );
// This calls stored procedure sp_newaddress, with :address_id being an
// in/out variable and :error_code being an out variable.
// Then you do the binding:
OCIBindByName ( $sth, ":address_id", $addr_id, 10 );
OCIBindByName ( $sth, ":error_code", $errorcode, 10 );
OCIExecute ( $sth );
?>
</programlisting>
</example>
</para>
</partintro>
<!--
OCIBindByName
OCIDefineByName
OCIColumnIsNULL
OCIColumnName
OCIColumnSize
OCIColumnType
OCIExecute
OCIFetch
OCIFetchInto
OCIFetchStatement
OCIInternalDebug
OCILogoff
OCILogon
OCIPLogon
OCINLogon
OCIError
OCICommit
OCIRollback
OCINewCursor
OCINewDescriptor
OCIRowCount
OCINumCols
OCIParse
OCIResult
OCIServerVersion
OCIStatementType
OCIFreeStatement
OCIFreeCursor
-->
<refentry id="function.ocidefinebyname">
<refnamediv>
<refname>OCIDefineByName</refname>
<refpurpose>
Use a PHP variable for the define-step during a SELECT
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIDefineByName</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>string <parameter>Column-Name</parameter></paramdef>
<paramdef>mixed &<parameter>variable</parameter></paramdef>
<paramdef>int
<parameter><optional>type</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIDefineByName</function> uses fetches SQL-Columns
into user-defined PHP-Variables. Be careful that Oracle user
ALL-UPPERCASE column-names, whereby in your select you can also
write lower-case. <function>OCIDefineByName</function> expects
the <parameter>Column-Name</parameter> to be in uppercase. If you
define a variable that doesn't exists in you select statement, no
error will be given!
</para>
<para>
If you need to define an abstract Datatype (LOB/ROWID/BFILE) you
need to allocate it first using
<function>OCINewDescriptor</function> function. See also the
<function>OCIBindByName</function> function.
</para>
<example>
<title>OCIDefineByName</title>
<programlisting>
<?php
/* OCIDefineByPos example thies@digicol.de (980219) */
$conn = OCILogon("scott","tiger");
$stmt = OCIParse($conn,"select empno, ename from emp");
/* the define MUST be done BEFORE ociexecute! */
OCIDefineByName($stmt,"EMPNO",&$empno);
OCIDefineByName($stmt,"ENAME",&$ename);
OCIExecute($stmt);
while (OCIFetch($stmt)) {
echo "empno:".$empno."\n";
echo "ename:".$ename."\n";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ocibindbyname">
<refnamediv>
<refname>OCIBindByName</refname>
<refpurpose>Bind a PHP variable to an Oracle Placeholder</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIBindByName</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>string <parameter>ph_name</parameter></paramdef>
<paramdef>mixed &<parameter>variable</parameter></paramdef>
<paramdef>int<parameter>length</parameter></paramdef>
<paramdef>int
<parameter><optional>type</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIBindByName</function> binds the PHP variable
<parameter>variable</parameter> to the Oracle placeholder
<parameter>ph_name</parameter>. Whether it will be used for
input or output will be determined run-time, and the necessary
storage space will be allocated. The
<parameter>length</parameter> paramter sets the maximum length
for the bind. If you set <parameter>length</parameter> to -1
<function>OCIBindByName</function> will use the current length of
<parameter>variable</parameter> to set the maximum length.
</para>
<para>
If you need to bind an abstract Datatype (LOB/ROWID/BFILE) you
need to allocate it first using
<function>OCINewDescriptor</function> function. The
<parameter>length</parameter> is not used for abstract Datatypes
and should be set to -1. The <parameter>type</parameter> 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).
</para>
<example>
<title>OCIDefineByName</title>
<programlisting>
<?php
/* OCIBindByPos example thies@digicol.de (980221)
inserts 3 resords into emp, and uses the ROWID for updating the
records just after the insert.
*/
$conn = OCILogon("scott","tiger");
$stmt = OCIParse($conn,"insert into emp (empno, ename) ".
"values (:empno,:ename) ".
"returning ROWID into :rid");
$data = array(1111 => "Larry", 2222 => "Bill", 3333 =>
"Jim");
$rowid = OCINewDescriptor($conn,OCI_D_ROWID);
OCIBindByName($stmt,":empno",&$empno,32);
OCIBindByName($stmt,":ename",&$ename,32);
OCIBindByName($stmt,":rid",&$rowid,-1,OCI_B_ROWID);
$update = OCIParse($conn,"update emp set sal = :sal where ROWID = :rid");
OCIBindByName($update,":rid",&$rowid,-1,OCI_B_ROWID);
OCIBindByName($update,":sal",&$sal,32);
$sal = 10000;
while (list($empno,$ename) = each($data)) {
OCIExecute($stmt);
OCIExecute($update);
}
$rowid->free();
OCIFreeStatement($update);
OCIFreeStatement($stmt);
$stmt = OCIParse($conn,"select * from emp where empno in (1111,2222,3333)");
OCIExecute($stmt);
while (OCIFetchInto($stmt,&$arr,OCI_ASSOC)) {
var_dump($arr);
}
OCIFreeStatement($stmt);
/* delete our "junk" from the emp table.... */
$stmt = OCIParse($conn,"delete from emp where empno in (1111,2222,3333)");
OCIExecute($stmt);
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ocilogon">
<refnamediv>
<refname>OCILogon</refname>
<refpurpose>Establishes a connection to Oracle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCILogon</function></funcdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string
<parameter><optional>db</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCILogon</function> 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.
</para>
<para>Connections are shared at the page level when using
<function>OCILogon</function>. This means that commits and
rollbacks apply to all open transactions in the page, even if you
have created multiple connections.
</para>
<para>
This example demonstrates how the connections are shared.
<example>
<title>OCILogon</title>
<programlisting>
<?php
print "<HTML><PRE>";
$db = "";
$c1 = ocilogon("scott","tiger",$db);
$c2 = ocilogon("scott","tiger",$db);
function create_table($conn)
{ $stmt = ociparse($conn,"create table scott.hallo (test varchar2(64))");
ociexecute($stmt);
echo $conn." created table\n\n";
}
function drop_table($conn)
{ $stmt = ociparse($conn,"drop table scott.hallo");
ociexecute($stmt);
echo $conn." dropped table\n\n";
}
function insert_data($conn)
{ $stmt = ociparse($conn,"insert into scott.hallo
values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY
HH24:MI:SS'))");
ociexecute($stmt,OCI_DEFAULT);
echo $conn." inserted hallo\n\n";
}
function delete_data($conn)
{ $stmt = ociparse($conn,"delete from scott.hallo");
ociexecute($stmt,OCI_DEFAULT);
echo $conn." deleted hallo\n\n";
}
function commit($conn)
{ ocicommit($conn);
echo $conn." commited\n\n";
}
function rollback($conn)
{ ocirollback($conn);
echo $conn." rollback\n\n";
}
function select_data($conn)
{ $stmt = ociparse($conn,"select * from scott.hallo");
ociexecute($stmt,OCI_DEFAULT);
echo $conn."----selecting\n\n";
while (ocifetch($stmt))
echo $conn." <".ociresult($stmt,"TEST").">\n\n";
echo $conn."----done\n\n";
}
create_table($c1);
insert_data($c1); // Insert a row using c1
insert_data($c2); // Insert a row using c2
select_data($c1); // Results of both inserts are returned
select_data($c2);
rollback($c1); // Rollback using c1
select_data($c1); // Both inserts have been rolled back
select_data($c2);
insert_data($c2); // Insert a row using c2
commit($c2); // commit using c2
select_data($c1); // result of c2 insert is returned
delete_data($c1); // delete all rows in table using c1
select_data($c1); // no rows returned
select_data($c2); // no rows returned
commit($c1); // commit using c1
select_data($c1); // no rows returned
select_data($c2); // no rows returned
drop_table($c1);
print "</PRE></HTML>";
?></programlisting></example></para>
<simpara>
See also <function>OCIPLogon</function> and
<function>OCINLogon</function>.</simpara>
</refsect1>
</refentry>
<refentry id="function.ociplogon">
<refnamediv>
<refname>OCIPLogon</refname>
<refpurpose>Connect to an Oracle database and log on using a persistant connection.
Returns a new session.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIPLogon</function></funcdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string
<parameter><optional>db</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIPLogon</function> 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.
</para>
<simpara>
See also <function>OCILogon</function> and
<function>OCINLogon</function>.</simpara>
</refsect1></refentry>
<refentry id="function.ocinlogon">
<refnamediv>
<refname>OCINLogon</refname>
<refpurpose>Connect to an Oracle database and log on using a new connection.
Returns a new session.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCINLogon</function></funcdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string
<parameter><optional>db</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCINLogon</function> 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.
</para>
<para>
<function>OCINLogon</function> 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
<function>OCILogon</function> or at the web server process level
if using <function>OCIPLogon</function>. If you have multiple
connections open using <function>OCINLogon</function>, all
commits and rollbacks apply to the specified connection only.
</para>
<para>
This example demonstrates how the connections are separated.
<example>
<title>OCINLogon</title>
<programlisting>
<?php
print "<HTML><PRE>";
$db = "";
$c1 = ocilogon("scott","tiger",$db);
$c2 = ocinlogon("scott","tiger",$db);
function create_table($conn)
{ $stmt = ociparse($conn,"create table scott.hallo (test
varchar2(64))");
ociexecute($stmt);
echo $conn." created table\n\n";
}
function drop_table($conn)
{ $stmt = ociparse($conn,"drop table scott.hallo");
ociexecute($stmt);
echo $conn." dropped table\n\n";
}
function insert_data($conn)
{ $stmt = ociparse($conn,"insert into scott.hallo
values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY
HH24:MI:SS'))");
ociexecute($stmt,OCI_DEFAULT);
echo $conn." inserted hallo\n\n";
}
function delete_data($conn)
{ $stmt = ociparse($conn,"delete from scott.hallo");
ociexecute($stmt,OCI_DEFAULT);
echo $conn." deleted hallo\n\n";
}
function commit($conn)
{ ocicommit($conn);
echo $conn." commited\n\n";
}
function rollback($conn)
{ ocirollback($conn);
echo $conn." rollback\n\n";
}
function select_data($conn)
{ $stmt = ociparse($conn,"select * from scott.hallo");
ociexecute($stmt,OCI_DEFAULT);
echo $conn."----selecting\n\n";
while (ocifetch($stmt))
echo $conn." <".ociresult($stmt,"TEST").">\n\n";
echo $conn."----done\n\n";
}
create_table($c1);
insert_data($c1);
select_data($c1);
select_data($c2);
rollback($c1);
select_data($c1);
select_data($c2);
insert_data($c2);
commit($c2);
select_data($c1);
delete_data($c1);
select_data($c1);
select_data($c2);
commit($c1);
select_data($c1);
select_data($c2);
drop_table($c1);
print "</PRE></HTML>";
?></programlisting></example></para>
<simpara>
See also <function>OCILogon</function> and
<function>OCIPLogon</function>.</simpara>
</refsect1></refentry>
<refentry id="function.ocilogoff">
<refnamediv>
<refname>OCILogOff</refname>
<refpurpose>Disconnects from Oracle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCILogOff</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCILogOff</function> closes an Oracle connection.
</para>
</refsect1>
</refentry>
<refentry id="function.ociexecute">
<refnamediv>
<refname>OCIExecute</refname>
<refpurpose>Execute a statement</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIExecute</function></funcdef>
<paramdef>int <parameter>statement</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIExecute</function> executes a previously parsed statement.
(see <function>OCIParse</function>). The optional
<parameter>mode</parameter>
allows you to specify the execution-mode (default is OCI_COMMIT_ON_SUCCESS).
If you don't want statements to be commited automaticly specify OCI_DEFAULT as
your mode.
</para>
</refsect1>
</refentry>
<refentry id="function.ocicommit">
<refnamediv>
<refname>OCICommit</refname>
<refpurpose>Commits outstanding transactions</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCICommit</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCICommit</function> commits all outstanding statements for
Oracle connection <parameter>connection</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.ocirollback">
<refnamediv>
<refname>OCIRollback</refname>
<refpurpose>Rolls back outstanding transactions</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIRollback</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIRollback</function> rolls back all outstanding statements for
Oracle connection <parameter>connection</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.ocinewdescriptor">
<refnamediv>
<refname>OCINewDescriptor</refname>
<refpurpose>Initialize a new empty descriptor LOB/FILE (LOB is default)</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>OCINewDescriptor</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>int
<parameter><optional>type</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCINewDescriptor</function> Allocates storage to hold
descriptors or LOB locators. Valid values for the valid
<parameter>type</parameter> are OCI_D_FILE, OCI_D_LOB, OCI_D_ROWID.
For LOB desriptors, the methods load, save, and savefile are
associated with the descriptor, for BFILE only the load method exists.
See the second example usage hints.
</para>
<example>
<title>OCINewDescriptor</title>
<programlisting>
<?php
/* This script is designed to be called from a HTML form.
* It expects $user, $password, $table, $where, and $commitsize
* to be passed in from the form. The script then deletes
* the selected rows using the ROWID and commits after each
* set of $commitsize rows. (Use with care, there is no rollback)
*/
$conn = OCILogon($user, $password);
$stmt = OCIParse($conn,"select rowid from $table $where");
$rowid = OCINewDescriptor($conn,OCI_D_ROWID);
OCIDefineByName($stmt,"ROWID",&$rowid);
OCIExecute($stmt);
while ( OCIFetch($stmt) ) {
$nrows = OCIRowCount($stmt);
$delete = OCIParse($conn,"delete from $table where ROWID = :rid");
OCIBindByName($delete,":rid",&$rowid,-1,OCI_B_ROWID);
OCIExecute($delete);
print "$nrows\n";
if ( ($nrows % $commitsize) == 0 ) {
OCICommit($conn);
}
}
$nrows = OCIRowCount($stmt);
print "$nrows deleted...\n";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
</programlisting>
<programlisting>
<?php
/* This script demonstrates file upload to LOB columns
* The formfield used for this example looks like this
* <form action="upload.php3" method="post"
enctype="multipart/form-data">
* <input type="file" name="lob_upload">
* ...
*/
if(!isset($lob_upload) || $lob_upload == 'none'){
?>
<form action="upload.php3" method="post"
enctype="multipart/form-data">
Upload file: <input type="file" name="lob_upload"><br>
<input type="submit" value="Upload"> - <input
type="reset">
</form>
<?php
} else {
// $lob_upload contains the temporary filename of the uploaded file
$conn = OCILogon($user, $password);
$lob = OCINewDescriptor($conn, OCI_D_LOB);
$stmt = OCIParse($conn,"insert into $table (id, the_blob)
values(my_seq.NEXTVAL, EMPTY_BLOB()) returning the_blob into :the_blob");
OCIBindByName($stmt, ':the_blob', &$lob, -1, OCI_B_BLOB);
OCIExecute($stmt);
if($lob->savefile($lob_upload)){
OCICommit($conn);
echo "Blob successfully uploaded\n";
}else{
echo "Couldn't upload Blob\n";
}
OCIFreeDesc($lob);
OCIFreeStatement($stmt);
OCILogoff($conn);
}
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ocirowcount">
<refnamediv>
<refname>OCIRowCount</refname>
<refpurpose>Gets the number of affected rows</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIRowCount</function></funcdef>
<paramdef>int <parameter>statement</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIRowCount</function> returns the number of rows affected
for eg update-statements. This funtions will not tell you the number
of rows that a select will return!</para>
<para>
<example>
<title>OCIRowCount</title>
<programlisting>
<?php
print "<HTML><PRE>";
$conn = OCILogon("scott","tiger");
$stmt = OCIParse($conn,"create table emp2 as select * from emp");
OCIExecute($stmt);
print OCIRowCount($stmt) . " rows inserted.<BR>";
OCIFreeStatement($stmt);
$stmt = OCIParse($conn,"delete from emp2");
OCIExecute($stmt);
print OCIRowCount($stmt) . " rows deleted.<BR>";
OCICommit($conn);
OCIFreeStatement($stmt);
$stmt = OCIParse($conn,"drop table emp2");
OCIExecute($stmt);
OCIFreeStatement($stmt);
OCILogOff($conn);
print "</PRE></HTML>";
?> </programlisting></example></para>
</refsect1>
</refentry>
<refentry id="function.ocinumcols">
<refnamediv>
<refname>OCINumCols</refname>
<refpurpose>Return the number of result columns in a statement</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCINumCols</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCINumCols</function> returns the number of columns in a
statement
</para>
<example>
<title>OCINumCols</title>
<programlisting>
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
while ( OCIFetch($stmt) ) {
print "\n";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_value = OCIResult($stmt,$i);
print $column_name . ': ' . $column_value . "\n";
}
print "\n";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
print "</PRE>";
print "</HTML>\n";
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.ociresult">
<refnamediv>
<refname>OCIResult</refname>
<refpurpose>Returns coulumn value for fetched row</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>OCIResult</function></funcdef>
<paramdef>int <parameter>statement</parameter></paramdef>
<paramdef>mixed <parameter>column</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIResult</function> returns the data for column
<parameter>column</parameter> in the current row (see
<function>OCIFetch</function>).<function>OCIResult</function> will
return everything as strings except for abstract types (ROWIDs, LOBs and FILEs).
</para>
</refsect1>
</refentry>
<refentry id="function.ocifetch">
<refnamediv>
<refname>OCIFetch</refname>
<refpurpose>Fetches the next row into result-buffer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIFetch</function></funcdef>
<paramdef>int <parameter>statement</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIFetch</function> fetches the next row (for SELECT statements)
into the internal result-buffer.
</para>
</refsect1>
</refentry>
<refentry id="function.ocifetchinto">
<refnamediv>
<refname>OCIFetchInto</refname>
<refpurpose>Fetches the next row into result-array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIFetchInto</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>array &<parameter>result</parameter></paramdef>
<paramdef>int
<parameter><optional>mode</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIFetchInto</function> fetches the next row (for SELECT statements)
into the <parameter>result</parameter> array.
<function>OCIFetchInto</function>
will overwrite the previous content of <parameter>result</parameter>. By default
<parameter>result</parameter> will contain a one-based array of all columns
that are not NULL.
</para>
<para>
The <parameter>mode</parameter> parameter allows you to change the default
behaviour. You can specify more than one flag by simply addig them up
(eg OCI_ASSOC+OCI_RETURN_NULLS). The known flags are:
<simplelist>
<member><literal>OCI_ASSOC</literal> Return an associative
array.</member>
<member><literal>OCI_NUM</literal> Return an numbered array
starting with one. (DEFAULT)</member>
<member><literal>OCI_RETURN_NULLS</literal> Return empty
columns.</member>
<member><literal>OCI_RETURN_LOBS</literal> Return the value of a LOB instead
of the desxriptor.</member>
</simplelist>
</para>
<para>
</para>
</refsect1>
</refentry>
<refentry id="function.ocifetchstatement">
<refnamediv>
<refname>OCIFetchStatement</refname>
<refpurpose>Fetch all rows of result data into an array.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIFetchStatement</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>array &<parameter>variable</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIFetchStatement</function> fetches all the rows from a
result into a user-defined array. <function>OCIFetchStatement</function>
returns the number of rows fetched.
</para>
<example>
<title>OCIFetchStatement</title>
<programlisting>
<?php
/* OCIFetchStatement example mbritton@verinet.com (990624) */
$conn = OCILogon("scott","tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
$nrows = OCIFetchStatement($stmt,$results);
if ( $nrows > 0 ) {
print "<TABLE BORDER=\"1\">\n";
print "<TR>\n";
while ( list( $key, $val ) = each( $results ) ) {
print "<TH>$key</TH>\n";
}
print "</TR>\n";
for ( $i = 0; $i < $nrows; $i++ ) {
reset($results);
print "<TR>\n";
while ( $column = each($results) ) {
$data = $column['value'];
print "<TD>$data[$i]</TD>\n";
}
print "</TR>\n";
}
print "</TABLE>\n";
} else {
echo "No data found<BR>\n";
}
print "$nrows Records Selected<BR>\n";
OCIFreeStatement($stmt);
OCILogoff($conn);
?></programlisting></example>
</refsect1>
</refentry>
<refentry id="function.ocicolumnisnull">
<refnamediv>
<refname>OCIColumnIsNULL</refname>
<refpurpose>test whether a result column is NULL</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIColumnIsNULL</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>mixed <parameter>column</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIColumnIsNULL</function> returns true if the returned
column <parameter>column</parameter> in the result from the
statement <parameter>stmt</parameter> is NULL. You can either use
the column-number (1-Based) or the column-name for the <parameter>col</parameter>
parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.ocicolumnsize">
<refnamediv>
<refname>OCIColumnSize</refname>
<refpurpose>return result column size</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIColumnSize</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>mixed <parameter>column</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIColumnSize</function> 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 <parameter>col</parameter>
parameter.
</para>
<para>
<example>
<title>OCIColumnSize</title>
<programlisting>
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>Name</TH>";
print "<TH>Type</TH>";
print "<TH>Length</TH>";
print "</TR>";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_type = OCIColumnType($stmt,$i);
$column_size = OCIColumnSize($stmt,$i);
print "<TR>";
print "<TD>$column_name</TD>";
print "<TD>$column_type</TD>";
print "<TD>$column_size</TD>";
print "</TR>";
}
print "</TABLE>";
OCIFreeStatement($stmt);
OCILogoff($conn);
print "</PRE>";
print "</HTML>\n";
?>
</programlisting>
</example>
</para>
<simpara>
See also <function>OCINumCols</function>,
<function>OCIColumnName</function>,
and <function>OCIColumnSize</function>.</simpara>
</refsect1>
</refentry>
<refentry id="function.ociserverversion">
<refnamediv>
<refname>OCIServerVersion</refname>
<refpurpose>Return a string containing server version information.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>OCIServerVersion</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<example>
<title>OCIServerVersion</title>
<programlisting>
<?php
$conn = OCILogon("scott","tiger");
print "Server Version: " . OCIServerVersion($conn);
OCILogOff($conn);
?></programlisting></example></para>
</refsect1>
</refentry>
<refentry id="function.ocistatementtype">
<refnamediv>
<refname>OCIStatementType</refname>
<refpurpose>Return the type of an OCI statement.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>OCIStatementType</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIStatementType</function> returns on of the following values:
<orderedlist>
<listitem><simpara> "SELECT"</simpara></listitem>
<listitem><simpara> "UPDATE"</simpara></listitem>
<listitem><simpara> "DELETE"</simpara></listitem>
<listitem><simpara> "INSERT"</simpara></listitem>
<listitem><simpara> "CREATE"</simpara></listitem>
<listitem><simpara> "DROP"</simpara></listitem>
<listitem><simpara> "ALTER"</simpara></listitem>
<listitem><simpara> "BEGIN"</simpara></listitem>
<listitem><simpara> "DECLARE"</simpara></listitem>
<listitem><simpara> "UNKNOWN"</simpara></listitem>
</orderedlist></para>
<para>
<example>
<title>Code examples</title>
<programlisting>
<?php
print "<HTML><PRE>";
$conn = OCILogon("scott","tiger");
$sql = "delete from emp where deptno = 10";
$stmt = OCIParse($conn,$sql);
if ( OCIStatementType($stmt) == "DELETE" ) {
die "You are not allowed to delete from this table<BR>";
}
OCILogoff($conn);
print "</PRE></HTML>";
?>
</programlisting></example></para>
</refsect1>
</refentry>
<refentry id="function.ocinewcursor">
<refnamediv>
<refname>OCINewCursor</refname>
<refpurpose>return a new cursor (Statement-Handle) - use this to bind
ref-cursors!</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCINewCursor</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCINewCursor</function> allocates a new statement handle on the specified
connection.
</para>
<para>
<example>
<title>Using a REF CURSOR from a stored procedure</title>
<programlisting>
<?php
// suppose your stored procedure info.output returns a ref cursor in :data
$conn = OCILogon("scott","tiger");
$curs = OCINewCursor($conn);
$stmt = OCIParse($conn,"begin info.output(:data); end;");
ocibindbyname($stmt,"data",&$curs,-1,OCI_B_CURSOR);
ociexecute($stmt);
ociexecute($curs);
while (OCIFetchInto($curs,&$data)) {
var_dump($data);
}
OCIFreeCursor($stmt);
OCIFreeStatement($curs);
OCILogoff($conn);
?>
</programlisting>
</example>
</para>
<para>
<example>
<title>Using a REF CURSOR in a select statement</title>
<programlisting>
<?php
print "<HTML><BODY>";
$conn = OCILogon("scott","tiger");
$count_cursor = "CURSOR(select count(empno) num_emps from emp " .
"where emp.deptno = dept.deptno) as EMPCNT from dept";
$stmt = OCIParse($conn,"select deptno,dname,$count_cursor");
ociexecute($stmt);
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>DEPT NAME</TH>";
print "<TH>DEPT #</TH>";
print "<TH># EMPLOYEES</TH>";
print "</TR>";
while (OCIFetchInto($stmt,&$data,OCI_ASSOC)) {
print "<TR>";
$dname = $data["DNAME"];
$deptno = $data["DEPTNO"];
print "<TD>$dname</TD>";
print "<TD>$deptno</TD>";
ociexecute($data[ "EMPCNT" ]);
while (OCIFetchInto($data[ "EMPCNT" ],&$subdata,OCI_ASSOC)) {
$num_emps = $subdata["NUM_EMPS"];
print "<TD>$num_emps</TD>";
}
print "</TR>";
}
print "</TABLE>";
print "</BODY></HTML>";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.ocifreestatement">
<refnamediv>
<refname>OCIFreeStatement</refname>
<refpurpose>Free all resources associated with a statement.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIFreeStatement</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIFreeStatement</function> returns true if successful, or false if
unsuccessful.
</para>
</refsect1>
</refentry>
<refentry id="function.ocifreecursor">
<refnamediv>
<refname>OCIFreeCursor</refname>
<refpurpose>Free all resources associated with a cursor.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIFreeCursor</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIFreeCursor</function> returns true if successful, or false if
unsuccessful.
</para>
</refsect1>
</refentry>
<refentry id="function.ocifreedesc">
<refnamediv>
<refname>OCIFreeDesc</refname>
<refpurpose>Deletes a large object descriptor.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIFreeDesc</function></funcdef>
<paramdef>object <parameter>lob</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>OCIFreeDesc</function> returns true if successful, or false if
unsuccessful.
</para>
</refsect1>
</refentry>
<refentry id="function.ocicolumnname">
<refnamediv>
<refname>OCIColumnName</refname>
<refpurpose>Returns the name of a column.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>OCIColumnName</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>OCIColumnName</function> returns the name of the column
corresponding to the column number (1-based) that is passed in.</simpara>
<para>
<example>
<title>OCIColumnName</title>
<programlisting>
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>Name</TH>";
print "<TH>Type</TH>";
print "<TH>Length</TH>";
print "</TR>";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_type = OCIColumnType($stmt,$i);
$column_size = OCIColumnSize($stmt,$i);
print "<TR>";
print "<TD>$column_name</TD>";
print "<TD>$column_type</TD>";
print "<TD>$column_size</TD>";
print "</TR>";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
print "</PRE>";
print "</HTML>\n";
?>
</programlisting>
</example>
</para>
<simpara>
See also <function>OCINumCols</function>,
<function>OCIColumnType</function>,
and <function>OCIColumnSize</function>.</simpara>
</refsect1>
</refentry>
<refentry id="function.ocicolumntype">
<refnamediv>
<refname>OCIColumnType</refname>
<refpurpose>Returns the data type of a column.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>OCIColumnType</function></funcdef>
<paramdef>int <parameter>stmt</parameter></paramdef>
<paramdef>int <parameter>col</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>OCIColumnType</function> returns the data type of the column
corresponding to the column number (1-based) that is passed in.</simpara>
<para>
<example>
<title>OCIColumnType</title>
<programlisting>
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>Name</TH>";
print "<TH>Type</TH>";
print "<TH>Length</TH>";
print "</TR>";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_type = OCIColumnType($stmt,$i);
$column_size = OCIColumnSize($stmt,$i);
print "<TR>";
print "<TD>$column_name</TD>";
print "<TD>$column_type</TD>";
print "<TD>$column_size</TD>";
print "</TR>";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
print "</PRE>";
print "</HTML>\n";
?>
</programlisting>
</example>
</para>
<simpara>
See also <function>OCINumCols</function>,
<function>OCIColumnName</function>,
and <function>OCIColumnSize</function>.</simpara>
</refsect1>
</refentry>
<refentry id="function.ociparse">
<refnamediv>
<refname>OCIParse</refname>
<refpurpose>Parse a query and return a statement</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>OCIParse</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
<paramdef>strint <parameter>query</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>OCIParse</function> parses the <parameter>query</parameter>
using <parameter>conn</parameter>. It returns the statement
identity if the query is valid, false if not. The
<parameter>query</parameter> can be any valid SQL statement.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ocierror">
<refnamediv>
<refname>OCIError</refname>
<refpurpose>Return the last error of stmt|conn|global.
If no error happened returns false.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>OCIError</function></funcdef>
<paramdef>int
<parameter><optional>stmt|conn|global</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>OCIError</function> returns the last error found. If
the optional <parameter>stmt|conn|global</parameter> is not
provided, the last error encountered is returned. If no error is
found, <function>OCIError</function> returns
false. <function>OCIError</function> returns the error as an
associative array. In this array, <parameter>code</parameter>
consists the oracle error code and <parameter>message</parameter>
the oracle errorstring.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ociinternaldebug">
<refnamediv>
<refname>OCIInternalDebug</refname>
<refpurpose>
Enables or disables internal debug output. By default it is
disabled
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>OCIInternalDebug</function></funcdef>
<paramdef>int <parameter>onoff</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>OCIInternalDebug</function> enables internal debug output. Set
<parameter>onoff</parameter>
to 0 to turn debug output off, 1 to turn it on.</simpara>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/oracle.xml
+++ phpdoc/nl/functions/oracle.xml
<reference id="ref.oracle">
<title>Oracle functions</title>
<titleabbrev>Oracle</titleabbrev>
<refentry id="function.ora-bind">
<refnamediv>
<refname>Ora_Bind</refname>
<refpurpose>bind a PHP variable to an Oracle parameter</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_bind</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
<paramdef>string <parameter>PHP variable name</parameter></paramdef>
<paramdef>string <parameter>SQL parameter name</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
<paramdef>int
<parameter><optional>type</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the bind succeeds, otherwise false. Details
about the error can be retrieved using the
<function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
<para>
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.
</para>
<para>
ora_bind must be called after <function>ora_parse</function> and
before <function>ora_exec</function>. Input values can be given
by assignment to the bound PHP variables, after calling
<function>ora_exec</function> the bound PHP variables contain the output
values if available.
<informalexample>
<programlisting role="php">
<?php
ora_parse($curs, "declare tmp INTEGER; begin tmp := :in; :out := tmp; :x := 7.77; end;");
ora_bind($curs, "result", ":x", $len, 2);
ora_bind($curs, "input", ":in", 5, 1);
ora_bind($curs, "output", ":out", 5, 2);
$input = 765;
ora_exec($curs);
echo "Result: $result<BR>Out: $output<BR>In: $input";
?>
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.ora-close">
<refnamediv>
<refname>Ora_Close</refname>
<refpurpose>close an Oracle cursor</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_close</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the close succeeds, otherwise false. Details
about the error can be retrieved using the
<function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
<para>
This function closes a data cursor opened with
<function>ora_open</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-columnname">
<refnamediv>
<refname>Ora_ColumnName</refname>
<refpurpose>get name of Oracle result column</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>Ora_ColumnName</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
<paramdef>int <parameter>column</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the name of the field/column
<parameter>column</parameter> on the cursor
<parameter>cursor</parameter>. The returned name is in all
uppercase letters.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-columnsize">
<refnamediv>
<refname>Ora_ColumnSize</refname>
<refpurpose>get size of Oracle result column</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>Ora_ColumnSize</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
<paramdef>int <parameter>column</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the size of the Oracle column
<parameter>column</parameter> on the cursor
<parameter>cursor</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-columntype">
<refnamediv>
<refname>Ora_ColumnType</refname>
<refpurpose>get type of Oracle result column</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>Ora_ColumnType</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
<paramdef>int <parameter>column</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the Oracle data type name of the field/column
<parameter>column</parameter> on the cursor
<parameter>cursor</parameter>. The returned type will be one of
the following:
<simplelist>
<member><literal>"VARCHAR2"</literal></member>
<member><literal>"VARCHAR"</literal></member>
<member><literal>"CHAR"</literal></member>
<member><literal>"NUMBER"</literal></member>
<member><literal>"LONG"</literal></member>
<member><literal>"LONG RAW"</literal></member>
<member><literal>"ROWID"</literal></member>
<member><literal>"DATE"</literal></member>
<member><literal>"CURSOR"</literal></member>
</simplelist>
</para>
</refsect1>
</refentry>
<refentry id="function.ora-commit">
<refnamediv>
<refname>Ora_Commit</refname>
<refpurpose>commit an Oracle transaction</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_commit</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error. Details about the
error can be retrieved using the <function>ora_error</function>
and <function>ora_errorcode</function> functions.
</para>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-commitoff">
<refnamediv>
<refname>Ora_CommitOff</refname>
<refpurpose>disable automatic commit</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_commitoff</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error. Details about the error
can be retrieved using the <function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
<para>
This function turns off automatic commit after each
<function>ora_exec</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-commiton">
<refnamediv>
<refname>Ora_CommitOn</refname>
<refpurpose>enable automatic commit</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_commiton</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function turns on automatic commit after each
<function>ora_exec</function> on the given connection.
</para>
<para>
Returns true on success, false on error. Details about the error
can be retrieved using the <function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-do">
<refnamediv>
<refname>Ora_Do</refname>
<refpurpose>Parse, Exec, Fetch</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_do</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is quick combination of <function>ora_parse</function>,
<function>ora_exec</function> and <function>ora_fetch</function>.
It will parse and execute a statement, then fetch the first result row.
</para>
<para>
Returns true on success, false on error. Details about the error
can be retrieved using the <function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
<para>
See also <function>ora_parse</function>,<function>ora_exec</function>,
and <function>ora_fetch</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-error">
<refnamediv>
<refname>Ora_Error</refname>
<refpurpose>get Oracle error message</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>Ora_Error</function></funcdef>
<paramdef>int <parameter>cursor_or_connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an error message of the form
<replaceable>XXX</replaceable>-<replaceable>NNNNN</replaceable>
where <replaceable>XXX</replaceable> is where the error comes
from and <replaceable>NNNNN</replaceable> identifies the error
message.
</para>
<para>
<note>
<para>Support for connection ids was added in 3.0.4.</para>
</note>
</para>
<para>
On UNIX versions of Oracle, you can find details about an error
message like this:
<computeroutput>
<prompt>$</prompt> <userinput>oerr ora
<replaceable>00001</replaceable></userinput> 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
</computeroutput>
</para>
</refsect1>
</refentry>
<refentry id="function.ora-errorcode">
<refnamediv>
<refname>Ora_ErrorCode</refname>
<refpurpose>get Oracle error code</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>Ora_ErrorCode</function></funcdef>
<paramdef>int <parameter>cursor_or_connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the numeric error code of the last executed statement on
the specified cursor or connection.
<comment>FIXME: should possible values be listed?</comment>
<note>
<para>Support for connection ids was added in 3.0.4.</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.ora-exec">
<refnamediv>
<refname>Ora_Exec</refname>
<refpurpose>execute parsed statement on an Oracle cursor</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_exec</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error. Details about the error
can be retrieved using the <function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
<simpara>
See also <function>ora_parse</function>,
<function>ora_fetch</function>, and <function>ora_do</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ora-fetch">
<refnamediv>
<refname>Ora_Fetch</refname>
<refpurpose>fetch a row of data from a cursor</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_fetch</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true (a row was fetched) or false (no more rows, or an
error occured). If an error occured, details can be retrieved
using the <function>ora_error</function> and
<function>ora_errorcode</function> functions. If there was no
error, <function>ora_errorcode</function> will return 0.
</para>
<para>
Retrieves a row of data from the specified cursor.
</para>
<simpara>
See also <function>ora_parse</function>,<function>ora_exec</function>,
and <function>ora_do</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ora-fetch-into">
<refnamediv>
<refname>Ora_Fetch_Into</refname>
<refpurpose>Fetch a row into the specified result array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_fetch_into</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
<paramdef>array <parameter>result</parameter></paramdef>
<paramdef>int
<parameter>
<optional>flags</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
You can fetch a row into an array with this function.
<example>
<title>Oracle fetch into array</title>
<programlisting role="php">
<?php
array($results);
ora_fetch_into($cursor, &$results);
echo $results[0];
echo $results[1];
?>
</programlisting>
</example>
Note that you need to fetch the array by reference.
</para>
<simpara>
See also <function>ora_parse</function>,<function>ora_exec</function>,
<function>ora_fetch</function>, and <function>ora_do</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ora-getcolumn">
<refnamediv>
<refname>Ora_GetColumn</refname>
<refpurpose>get data from a fetched column</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>ora_getcolumn</function></funcdef>
<paramdef>int <parameter>cursor</parameter></paramdef>
<paramdef>mixed <parameter>column</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the column data. If an error occurs, False is returned
and <function>ora_errorcode</function>
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").
</para>
<para>
Fetches the data for a column or function result.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-logoff">
<refnamediv>
<refname>Ora_Logoff</refname>
<refpurpose>close an Oracle connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_logoff</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true on success, false on error. Details about the error
can be retrieved using the <function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
<para>
Logs out the user and disconnects from the server.
</para>
<simpara>
See also <function>ora_logon</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ora-logon">
<refnamediv>
<refname>Ora_Logon</refname>
<refpurpose>open an Oracle connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_logon</function></funcdef>
<paramdef>string <parameter>user</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Establishes a connection between PHP and an Oracle database with the
given username and password.
</para>
<para>
Connections can be made using <productname>SQL*Net</productname>
by supplying the <acronym>TNS</acronym> name to
<parameter>user</parameter> like this:
<informalexample>
<programlisting role="php">
$conn = Ora_Logon("user<emphasis>@TNSNAME</emphasis>", "pass");
</programlisting>
</informalexample>
</para>
<para>
If you have character data with non-ASCII characters, you should
make sure that <envar>NLS_LANG</envar> is set in your
environment. For server modules, you should set it in the
server's environment before starting the server.
</para>
<para>
Returns a connection index on success, or false on failure.
Details about the error can be retrieved using the
<function>ora_error</function> and <function>ora_errorcode</function>
functions.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-plogon">
<refnamediv>
<refname>Ora_pLogon</refname>
<refpurpose>
Open a persistent Oracle connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_plogon</function></funcdef>
<paramdef>string <parameter>user</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Establishes a persistant connection between PHP and an Oracle database with
the given username and password.
</para>
<simpara>
See also <function>ora_logon</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ora-numcols">
<refnamediv>
<refname>Ora_Numcols</refname>
<refpurpose>Returns the number of columns</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_numcols</function></funcdef>
<paramdef>int <parameter>cursor_ind</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ora_numcols</function> returns the number of columns in a result.
Only returns meaningful values after an parse/exec/fetch sequence.
</para>
<simpara>
See also <function>ora_parse</function>,<function>ora_exec</function>,
<function>ora_fetch</function>, and <function>ora_do</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ora-numrows">
<refnamediv>
<refname>Ora_Numrows</refname>
<refpurpose>Returns the number of rows</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_numrows</function></funcdef>
<paramdef>int <parameter>cursor_ind</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ora_numrows</function> returns the number of rows in a result.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-open">
<refnamediv>
<refname>Ora_Open</refname>
<refpurpose>open an Oracle cursor</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_open</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Opens an Oracle cursor associated with connection.
</para>
<para>
Returns a cursor index or False on failure. Details about the
error can be retrieved using the <function>ora_error</function>
and <function>ora_errorcode</function> functions.
</para>
</refsect1>
</refentry>
<refentry id="function.ora-parse">
<refnamediv>
<refname>Ora_Parse</refname>
<refpurpose>parse an SQL statement</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_parse</function></funcdef>
<paramdef>int <parameter>cursor_ind</parameter></paramdef>
<paramdef>string <parameter>sql_statement</parameter></paramdef>
<paramdef>int <parameter>defer</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function parses an SQL statement or a PL/SQL block and
associates it with the given cursor.
</para>
<para>
Returns 0 on success or -1 on
error.
</para>
<simpara>
See also <function>ora_exec</function>,
<function>ora_fetch</function>, and <function>ora_do</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ora-rollback">
<refnamediv>
<refname>Ora_Rollback</refname>
<refpurpose>roll back transaction</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ora_rollback</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function undoes an Oracle transaction. (See
<function>ora_commit</function> for the definition of a
transaction.)
</para>
<para>
Returns true on success, false on error. Details about the error
can be retrieved using the <function>ora_error</function> and
<function>ora_errorcode</function> functions.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/outcontrol.xml
+++ phpdoc/nl/functions/outcontrol.xml
<reference id="ref.outcontrol">
<title>Output Control Functions</title>
<titleabbrev>Output Control</titleabbrev>
<partintro>
<para>
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 outputing data. The Output Control
functions do not affect headers sent using
<function>header</function> or <function>setcookie</function>,
only functions such as <function>echo</function> and data between
blocks of PHP code.
</para>
<para>
<example>
<title>Output Control example</title>
<programlisting role="php">
<?php
ob_start();
echo "Hello\n";
setcookie ("cookiename", "cookiedata");
ob_end_flush();
?>
</programlisting>
</example>
</para>
<para>
In the above example, the output from <function>echo</function>
would be stored in the output buffer until
<function>ob_end_flush</function> was called. In the mean time,
the call to <function>setcookie</function> successfully stored a
cookie without causing an error. (You can not normally send
headers to the browser after data has already been sent.)
</para>
<para>
See also <function>header</function> and
<function>setcookie</function>.
</para>
</partintro>
<refentry id="function.flush">
<refnamediv>
<refname>flush</refname>
<refpurpose>Flush the output buffer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>flush</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<simpara>
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.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ob-start">
<refnamediv>
<refname>ob_start</refname>
<refpurpose>Turn on output buffering</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ob_start</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
This function will turn output buffering on. While output buffering
is active no output is sent from the script, instead the output
is stored in an internal buffer.
</para>
<para>
The contents of this internal buffer may be copied into a string
variable using <function>ob_get_contents</function>. To output
what is stored in the internal buffer, use
<function>ob_end_flush</function>. Alternatively,
<function>ob_end_clean</function> will silently discard the
buffer contents.
</para>
<para>
See also <function>ob_get_contents</function>,
<function>ob_end_flush</function>,
<function>ob_end_clean</function>, and
<function>ob_implicit_flush</function>
</para>
</refsect1>
</refentry>
<refentry id="function.ob-get-contents">
<refnamediv>
<refname>ob_get_contents</refname>
<refpurpose>
Return the contents of the output buffer
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ob_get_contents</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
This will return the contents of the output buffer or FALSE, if
output buffering isn't active.
</para>
<para>
See also <function>ob_start</function> and
<function>ob_get_length</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ob-get-length">
<refnamediv>
<refname>ob_get_length</refname>
<refpurpose>
Return the length of the output buffer
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ob_get_length</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
This will return the length of the contents in the output buffer
or FALSE, if output buffering isnt't active.
</para>
<para>
See also <function>ob_start</function> and
<function>ob_get_contents</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ob-end-flush">
<refnamediv>
<refname>ob_end_flush</refname>
<refpurpose>
Flush (send) the output buffer and turn off output buffering
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ob_end_flush</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
This function will send the contents of the output buffer (if
any) and turn output buffering off. If you want to further
process the buffer's contents you have to call
<function>ob_get_contents</function> before
<function>ob_end_flush</function> as the buffer contents are
discarded after <function>ob_get_contents</function> is called.
</para>
<para>
See also <function>ob_start</function>,
<function>ob_get_contents</function>, and
<function>ob_end_clean</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ob-end-clean">
<refnamediv>
<refname>ob_end_clean</refname>
<refpurpose>
Clean (erase) the output buffer and turn off output buffering
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ob_end_clean</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
This function discards the contents of the output buffer and
turns off output buffering.
</para>
<para>
See also <function>ob_start</function> and
<function>ob_end_flush</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ob-implicit-flush">
<refnamediv>
<refname>ob_implicit_flush</refname>
<refpurpose>
Turn implicit flush on/off
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>ob_implicit_flush</function></funcdef>
<paramdef>int
<parameter><optional>flag</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>ob_implicit_flush</function> will turn implicit
flushing on or off (if no <parameter>flag</parameter> is given,
it defaults to on). Implicit flushing will result in a flush
operation after every output call, so that explicit calls to
<function>flush</function> will no longer be needed.
</para>
<para>
Turning implicit flushing on will disable output buffering, the
output buffers current output will be sent as if
<function>ob_end_flush</function> had been called.
</para>
<para>
See also <function>flush</function>,
<function>ob_start</function>, and
<function>ob_end_flush</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/pcre.xml
+++ phpdoc/nl/functions/pcre.xml
<reference id="ref.pcre">
<title>Regular Expression Functions (Perl-Compatible)</title>
<titleabbrev>PCRE</titleabbrev>
<partintro>
<para>
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.
</para>
<para>
The ending delimiter may be followed by various modifiers that
affect the matching.
See <link linkend="pcre.pattern.modifiers">Pattern Modifiers</link>.
</para>
<para>
<example>
<title>Examples of valid patterns</title>
<itemizedlist>
<listitem><simpara>/<\/\w+>/</simpara></listitem>
<listitem><simpara>|(\d{3})-\d+|Sm</simpara></listitem>
<listitem><simpara>/^(?i)php[34]/</simpara></listitem>
</itemizedlist>
</example>
</para>
<para>
<example>
<title>Examples of invalid patterns</title>
<itemizedlist>
<listitem>
<simpara>
/href='(.*)' - missing ending delimiter
</simpara>
</listitem>
<listitem>
<simpara>
/\w+\s*\w+/J - unknown modifier 'J'
</simpara>
</listitem>
<listitem>
<simpara>
1-\d3-\d3-\d4| - missing starting delimiter
</simpara>
</listitem>
</itemizedlist>
</example>
</para>
<note>
<simpara>
The Perl-compatible regular expression functions are available in
PHP 4 and in PHP 3.0.9 and up.
</simpara>
</note>
</partintro>
<refentry id="function.preg-match">
<refnamediv>
<refname>preg_match</refname>
<refpurpose>Perform a regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>preg_match</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>array
<parameter><optional>matches</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches <parameter>subject</parameter> for a match to the regular
expression given in <parameter>pattern</parameter>.
</para>
<para>
If <parameter>matches</parameter> is provided, then it is filled
with the results of search. $matches[0] will contain the text that
match the full pattern, $matches[1] will have the text that matched
the first captured parenthesized subpattern, and so on.
</para>
<para>
Returns true if a match for <parameter>pattern</parameter> was
found in the subject string, or false if not match was found
or an error occurred.</para>
<para>
<example>
<title>find the string of text "php"</title>
<programlisting role="php">
// the "i" after the pattern delimiter indicates a case-insensitive search
if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) {
print "A match was found.";
} else {
print "A match was not found.";
}
</programlisting>
</example>
<example>
<title>find the word "web"</title>
<programlisting role="php">
// the \b in the pattern indicates a word boundary, so only the distinct
// word "web" is matched, and not a word partial like "webbing" or
"cobweb"
if (preg_match ("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
print "A match was found.";
} else {
print "A match was not found.";
}
if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of
choice.")) {
print "A match was found.";
} else {
print "A match was not found.";
}
</programlisting>
</example>
<example>
<title>Getting the domain name out of a URL</title>
<programlisting role="php">
// get host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.php.net/index.html",
$matches);
$host = $matches[2];
// get last two segments of host name
preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$matches);
echo "domain name is: ".$matches[0]."\n";
</programlisting>
</example>
This example will produce:
<programlisting>
domain name is: php.net
</programlisting>
See also <function>preg_match_all</function>,
<function>preg_replace</function>, and
<function>preg_split</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.preg-match-all">
<refnamediv>
<refname>preg_match_all</refname>
<refpurpose>Perform a global regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>preg_match_all</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>array <parameter>matches</parameter></paramdef>
<paramdef>int
<parameter><optional>order</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches <parameter>subject</parameter> for all matches to the regular
expression given in <parameter>pattern</parameter> and puts them in
<parameter>matches</parameter> in the order specified by
<parameter>order</parameter>.
</para>
<para>
After the first match is found, the subsequent searches are continued
on from end of the last match.
</para>
<para>
<parameter>order</parameter> can be one of two things:
<variablelist>
<varlistentry>
<term>PREG_PATTERN_ORDER</term>
<listitem>
<para>
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.
<informalexample>
<programlisting role="php">
preg_match_all ("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a
test</div>",
$out, PREG_PATTERN_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
</programlisting>
</informalexample>
This example will produce:
<informalexample>
<programlisting>
<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test
</programlisting>
</informalexample>
So, $out[0] contains array of strings that matched full pattern,
and $out[1] contains array of strings enclosed by tags.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>PREG_SET_ORDER</term>
<listitem>
<para>
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.
<informalexample>
<programlisting role="php">
preg_match_all ("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a
test</div>",
$out, PREG_SET_ORDER);
print $out[0][0].", ".$out[0][1]."\n";
print $out[1][0].", ".$out[1][1]."\n"
</programlisting>
</informalexample>
This example will produce:
<informalexample>
<programlisting role="php">
<b>example: </b>, example:
<div align=left>this is a test</div>, this is a test
</programlisting>
</informalexample>
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.
</para>
</listitem>
</varlistentry>
</variablelist></para>
<para>
If <parameter>order</parameter> is not specified, it is assumed
to be PREG_PATTERN_ORDER.
</para>
<para>
Returns the number of full pattern matches, or false if
no match is found or an error occurred.
</para>
<para>
<example>
<title>Getting all phone numbers out of some text.</title>
<programlisting role="php">
preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
"Call 555-1212 or 1-800-555-1212", $phones);
</programlisting>
</example>
</para>
<para>
<example>
<title>Find matching HTML tags (greedy)</title>
<programlisting role="php">
// the \\2 is an example of backreferencing. This tells pcre that
// it must match the 2nd set of parenthesis in the regular expression
// itself, which would be the ([\w]+) in this case.
$html = "<b>bold text</b><a href=howdy.html>click
me</a>
preg_match_all ("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/",
$html, $matches);
for ($i=0; $i< count($matches[0]); $i++) {
echo "matched: ".$matches[0][$i]."\n";
echo "part 1: ".$matches[1][$i]."\n";
echo "part 2: ".$matches[3][$i]."\n";
echo "part 3: ".$matches[4][$i]."\n\n";
}
</programlisting>
</example>
This example will produce:
<programlisting>
matched: <b>bold text</b>
part 1: <b>
part 2: bold text
part 3: </b>
matched: <a href=howdy.html>click me</a>
part 1: <a href=howdy.html>
part 2: click me
part 3: </a>
</programlisting>
</para>
<simpara>
See also <function>preg_match</function>,
<function>preg_replace</function>,
and <function>preg_split</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.preg-replace">
<refnamediv>
<refname>preg_replace</refname>
<refpurpose>Perform a regular expression search and replace</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>preg_replace</function></funcdef>
<paramdef>mixed <parameter>pattern</parameter></paramdef>
<paramdef>mixed <parameter>replacement</parameter></paramdef>
<paramdef>mixed <parameter>subject</parameter></paramdef>
<paramdef>int
<parameter><optional>limit</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Searches <parameter>subject</parameter> for matches to
<parameter> pattern</parameter> and replaces them with
<parameter>replacement </parameter>. If
<parameter>limit</parameter> is specified, then only
<parameter>limit</parameter> matches will be replaced; if
<parameter>limit</parameter> is omitted or is -1, then all
matches are replaced.
</para>
<para>
<parameter>Replacement</parameter> may contain references of the
form <literal>\\<replaceable>n</replaceable></literal>. Every
such reference will be replaced by the text captured by the
<replaceable>n</replaceable>'th parenthesized pattern.
<replaceable>n </replaceable>can be from 0 to 99, and
<literal>\\0</literal> 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.
</para>
<para>
If no matches are found in <parameter>subject</parameter>, then
it will be returned unchanged.
</para>
<para>
Every parameter to <function>preg_replace</function> can be an
array.
</para>
<para>
If <parameter>subject</parameter> is an array, then the search
and replace is performed on every entry of
<parameter>subject</parameter>, and the return value is an array
as well.
</para>
<para>
If <parameter>pattern</parameter> and
<parameter>replacement</parameter> are arrays, then
<function>preg_replace</function> takes a value from each array
and uses them to do search and replace on
<parameter>subject</parameter>. If
<parameter>replacement</parameter> has fewer values than
<parameter>pattern</parameter>, then empty string is used for the
rest of replacement values. If <parameter>pattern </parameter>
is an array and <parameter>replacement</parameter> is a string;
then this replacement string is used for every value of
<parameter>pattern</parameter>. The converse would not make
sense, though.
</para>
<para>
<literal>/e</literal> modifier makes
<function>preg_replace</function> treat the
<parameter>replacement</parameter> parameter as PHP code after
the appropriate references substitution is done. Tip: make sure
that <parameter>replacement</parameter> constitutes a valid PHP
code string, otherwise PHP will complain about a parse error at
the line containing <function>preg_replace</function>.
</para>
<para>
<example>
<title>Replacing several values</title>
<programlisting>
$patterns = array ("/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/",
"/^\s*{(\w+)}\s*=/");
$replace = array ("\\3/\\4/\\1\\2", "$\\1 =");
print preg_replace ($patterns, $replace, "{startDate} = 1999-5-27");
</programlisting>
</example>
This example will produce:
<programlisting>
$startDate = 5/27/1999
</programlisting>
<example>
<title>Using /e modifier</title>
<programlisting role="php">
preg_replace ("/(<\/?)(\w+)([^>]*>)/e",
"'\\1'.strtoupper('\\2').'\\3'",
$html_body);
</programlisting>
<para>
This would capitalize all HTML tags in the input text.
</para>
</example>
<example>
<title>Convert HTML to text</title>
<programlisting role="php">
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array
("'<script[^>]*?>.*?</script>'si", // Strip
out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip
out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$text = preg_replace ($search, $replace, $document);
</programlisting>
</example>
</para>
<note>
<para>
Parameter <parameter>limit</parameter> was added after PHP 4.0.1pl2.
</para>
</note>
<para>
See also <function>preg_match</function>,
<function>preg_match_all</function>, and
<function>preg_split</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.preg-split">
<refnamediv>
<refname>preg_split</refname>
<refpurpose>Split string by a regular expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array preg_split</funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>subject</parameter></paramdef>
<paramdef>int
<parameter><optional>limit</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>flags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<note>
<para>
Parameter <parameter>flags</parameter> was added in PHP 4 Beta 3.
</para>
</note>
<para>
Returns an array containing substrings of
<parameter>subject</parameter> split along boundaries matched by
<parameter>pattern</parameter>.
</para>
<para>
If <parameter>limit</parameter> is specified, then only substrings
up to <parameter>limit</parameter> are returned.
</para>
<para>
If flags is <constant>PREG_SPLIT_NO_EMPTY</constant> then only
non-empty pieces will be returned by <function>preg_split</function>.
</para>
<example>
<title><function>preg_split</function> example</title>
<para>
Get the parts of a search string.
</para>
<programlisting role="php">
// split the phrase by any number of commas or space characters,
// which include " ", \r, \t, \n and \f
$keywords = preg_split ("/[\s,]+/", "hypertext language, programming");
</programlisting>
<para>
Splitting a string into component characters.
</para>
<programlisting role="php">
$str = 'string';
$chars = preg_split('//', $str, 0, PREG_SPLIT_NO_EMPTY);
print_r($chars);
</programlisting>
</example>
<para>
See also <function>preg_match</function>,
<function>preg_match_all</function>, and
<function>preg_replace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.preg-quote">
<refnamediv>
<refname>preg_quote</refname>
<refpurpose>Quote regular expression characters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>preg_quote</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string
<parameter><optional>delimiter</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>preg_quote</function> takes <parameter>str</parameter>
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.
</para>
<para>
If the optional <parameter>delimiter</parameter> is specified, it
will also be escaped. This is useful for escaping the delimeter
that is required by the PCRE functions. The / is the most commonly
used delimiter.</para>
<para>
The special regular expression characters are:
<screen>. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :</screen>
</para>
<para>
<example>
<title></title>
<programlisting role="php">
$keywords = "$40 for a g3/400";
$keywords = preg_quote ($keywords, "/");
echo $keywords; // returns \$40 for a g3\/400
</programlisting>
</example>
<example>
<title>Italicizing a word within some text</title>
<programlisting role="php">
// In this example, preg_quote($word) is used to keep the
// asterisks from having special meaning to the regular
// expression.
$textbody = "This book is *very* difficult to find.";
$word = "*very*";
$textbody = preg_replace ("/".preg_quote($word)."/",
"<i>".$word."</i>",
$textbody);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.preg-grep">
<refnamediv>
<refname>preg_grep</refname>
<refpurpose>
Return array entries that match the pattern
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>preg_grep</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>array <parameter>input</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>preg_grep</function> returns the array consisting of
the elements of the <parameter>input</parameter> array that match
the given <parameter>pattern</parameter>.</para>
<para>
<example>
<title><function>preg_grep</function> example</title>
<programlisting role="php">
// return all array elements
// containing floating point numbers
$fl_array = preg_grep ("/^(\d+)?\.\d+$/", $array);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="pcre.pattern.modifiers">
<refnamediv>
<refname>Pattern Modifiers</refname>
<refpurpose>Describes possible modifiers in regex
patterns</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>
The current possible PCRE modifiers are listed below. The names
in parentheses refer to internal PCRE names for these modifiers.
</para>
<para>
<blockquote>
<variablelist>
<varlistentry>
<term><emphasis>i</emphasis> (PCRE_CASELESS)</term>
<listitem>
<simpara>
If this modifier is set, letters in the pattern match both
upper and lower case letters.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>m</emphasis> (PCRE_MULTILINE)</term>
<listitem>
<simpara>
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
<emphasis>E</emphasis> modifier is set). This is the same as
Perl.
</simpara>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>s</emphasis> (PCRE_DOTALL)</term>
<listitem>
<simpara>
If this modifier is set, a dot metacharater 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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>x</emphasis> (PCRE_EXTENDED)</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>e</emphasis></term>
<listitem>
<simpara>
If this modifier is set, <function>preg_replace</function>
does normal substitution of \\ references in the
replacement string, evaluates it as PHP code, and uses the
result for replacing the search string.
</simpara>
<simpara>
Only <function>preg_replace</function> uses this modifier;
it is ignored by other PCRE functions.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>A</emphasis> (PCRE_ANCHORED)</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>D</emphasis> (PCRE_DOLLAR_ENDONLY)</term>
<listitem>
<simpara>
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 <emphasis>m</emphasis>
modifier is set. There is no equivalent to this modifier in
Perl.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>S</emphasis></term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>U</emphasis> (PCRE_UNGREEDY)</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis>X</emphasis> (PCRE_EXTRA)</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</blockquote>
</para>
</refsect1>
</refentry>
<refentry id="pcre.pattern.syntax">
<refnamediv>
<refname>Pattern Syntax</refname>
<refpurpose>Describes PCRE regex syntax</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<literallayout>
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.
</literallayout>
</refsect1>
<refsect1>
<title>Differences From Perl</title>
<literallayout>
The differences described here are with respect to Perl
5.005.
1. 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 char-
acters. The \v escape that was in the Perl documentation for
a long time was never in fact recognized. However, the char-
acter itself was treated as whitespace at least up to 5.002.
In 5.004 and 5.005 it does not match \s.
2. 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.
3. Capturing subpatterns that occur inside negative looka-
head assertions are counted, but their entries in the
offsets vector are never set. Perl sets its numerical vari-
ables 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.
4. Though binary zero characters are supported in the sub-
ject string, they are not allowed in a pattern string
because it is passed as a normal C string, terminated by
zero. The escape sequence "\0" can be used in the pattern to
represent a binary zero.
5. 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 pat-
tern matching engine.
6. The Perl \G assertion is not supported as it is not
relevant to single pattern matches.
7. Fairly obviously, PCRE does not support the (?{code})
construction.
8. 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.
9. 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.
10. PCRE provides some extensions to the Perl regular
expression facilities:
(a) 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.
(b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not
set, the $ meta- character matches only at the very end of
the string.
(c) If PCRE_EXTRA is set, a backslash followed by a letter
with no special meaning is faulted.
(d) If PCRE_UNGREEDY is set, the greediness of the repeti-
tion quantifiers is inverted, that is, by default they are
not greedy, but if followed by a question mark they are.
</literallayout>
</refsect1>
<refsect1>
<title>Regular Expression Details</title>
<literallayout>
The syntax and semantics of the regular expressions sup-
ported 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 charac-
ters 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 pat-
tern. These are encoded in the pattern by the use of <emphasis>meta</emphasis>-
<emphasis>characters</emphasis>, 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
| 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
Part of a pattern that is in square brackets is called a
"character class". In a character class the only meta-
characters are:
\ general escape character
^ negate the class, but only if the first character
- indicates character range
] terminates the character class
The following sections describe the use of each of the
meta-characters.
BACKSLASH
The backslash character has several uses. Firstly, if it is
followed by a non-alphameric 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 follow-
ing character would otherwise be interpreted as a meta-
character, so it is always safe to precede a non-alphameric
with "\" to specify that it stands for itself. In particu-
lar, if you want to match a backslash, you write "\\".
If a pattern is compiled with the PCRE_EXTENDED option, whi-
tespace 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 charac-
ters, 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:
\a alarm, that is, the BEL character (hex 07)
\cx "control-x", where x is any character
\e escape (hex 1B)
\f formfeed (hex 0C)
\n newline (hex 0A)
\r carriage return (hex 0D)
\t tab (hex 09)
\xhh character with hex code hh
\ddd 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 <emphasis>back</emphasis>
<emphasis>reference</emphasis>. 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 follow-
ing the backslash, and generates a single byte from the
least significant 8 bits of the value. Any subsequent digits
stand for themselves. For example:
\040 is another way of writing a space
\40 is the same, provided there are fewer than 40
previous capturing subpatterns
\7 is always a back reference
\11 might be a back reference, or another way of
writing a tab
\011 is always a tab
\0113 is a tab followed by the character "3"
\113 is the character with octal code 113 (since there
can be no more than 99 back references)
\377 is a byte consisting entirely of 1 bits
\81 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 intro-
duced 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 charac-
ter types:
\d any decimal digit
\D any character that is not a decimal digit
\s any whitespace character
\S any character that is not a whitespace character
\w any "word" character
\W 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 con-
trolled 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 char-
acter 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 asser-
tions. 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
\b word boundary
\B not a word boundary
\A start of subject (independent of multiline mode)
\Z end of subject or newline at end (independent of
multiline mode)
\z 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_NOTBOL or PCRE_NOTEOL 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.
CIRCUMFLEX AND DOLLAR
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 alter-
natives 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 con-
structs 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. Conse-
quently, patterns that are anchored in single line mode
because all branches start with "^" are not anchored in mul-
tiline 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.
FULL STOP (PERIOD, DOT)
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 han-
dling of dot is entirely independent of the handling of cir-
cumflex and dollar, the only relationship being that they
both involve newline characters. Dot has no special meaning
in a character class.
SQUARE BRACKETS
An opening square bracket introduces a character class, ter-
minated 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 cir-
cumflex, 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 cir-
cumflex, 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 con-
venient 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 case-
ful 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 inter-
preted 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 "-") fol-
lowed 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 inter-
preted 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 res-
tricted set of characters than the matching lower case type.
For example, the class [^\W_] matches any letter or digit,
but not underscore.
All non-alphameric 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
Vertical bar characters are used to separate alternative
patterns. For example, the pattern
gilbert|sullivan
matches either "gilbert" or "sullivan". Any number of alter-
natives 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.
INTERNAL OPTION SETTING
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
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" set-
tings apply to the whole pattern (unless there are other
changes inside subpatterns). If there is more than one set-
ting 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 oth-
erwise.
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
Subpatterns are delimited by parentheses (round brackets),
which can be nested. Marking part of a pattern as a subpat-
tern does two things:
1. It localizes a set of alternatives. For example, the pat-
tern
cat(aract|erpillar|)
matches one of the words "cat", "cataract", or "caterpil-
lar". 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 por-
tion of the subject string that matched the subpattern is
passed back to the caller via the <emphasis>ovector</emphasis> argument of
<function>pcre_exec</function>. Opening parentheses are counted from left to
right (starting from 1) to obtain the numbers of the captur-
ing 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 sub-
pattern 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 sub-
strings 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
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 quantif-
ier, 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:
* is equivalent to {0,}
+ is equivalent to {1,}
? is equivalent to {0,1}
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 per-
mitted 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 com-
ments 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 pre-
ferred number of matches. Do not confuse this use of ques-
tion 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 max-
imum, 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 charac-
ter 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 pat-
tern 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 exam-
ple, after
(tweedle[dume]{3}\s*)+
has matched "tweedledum tweedledee" the value of the cap-
tured substring is "tweedledee". However, if there are
nested capturing subpatterns, the corresponding captured
values may have been set in previous iterations. For exam-
ple, after
/(a|(b))+/
matches "aba" the value of the second captured substring is
"b".
BACK REFERENCES
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 han-
dling of digits following a backslash.
A back reference matches whatever actually matched the cap-
turing 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 responsi-
bility", 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 case-
lessly.
There may be more than one back reference to the same sub-
pattern. 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 pat-
tern
(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 itera-
tion. 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.
ASSERTIONS
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 compli-
cated 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 asser-
tions 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 dif-
ferent 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 rewrit-
ten 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 match-
ing 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".
Furthermore, 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".
Assertion subpatterns are not capturing subpatterns, and may
not be repeated, because it makes no sense to assert the
same thing several times. If an assertion contains capturing
subpatterns within it, these are always counted for the pur-
poses of numbering the capturing subpatterns in the whole
pattern. Substring capturing is carried out for positive
assertions, but it does not make sense for negative asser-
tions.
Assertions count towards the maximum of 200 parenthesized
subpatterns.
ONCE-ONLY 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. Back-
tracking past it to previous items, however, works as nor-
mal.
An alternative description is that a subpattern of this type
matches the string of characters that an identical stan-
dalone 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 max-
imizing 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 compli-
cated 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 it.
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, 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 pat-
tern 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 process-
ing time.
CONDITIONAL SUBPATTERNS
It is possible to cause the matching process to obey a sub-
pattern 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; oth-
erwise 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 con-
dition is satisfied if the capturing subpattern of that
number has previously matched. Consider the following pat-
tern, 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 contain-
ing non-significant white space, and with the two alterna-
tives 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.
COMMENTS
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 contin-
ues up to the next newline character in the pattern.
PERFORMANCE
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.
</literallayout>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/pdf.xml
+++ phpdoc/nl/functions/pdf.xml
<reference id="ref.pdf">
<title>PDF functions</title>
<titleabbrev>PDF</titleabbrev>
<partintro>
<sect1>
<title>Introduction</title>
<simpara>
You can use the PDF functions in PHP to create PDF files if you
have the PDF library by Thomas Merz (available at
<ulink url="&url.pdf;">&url.pdf;</ulink>;
you will also need <ulink url="&url.jpeg;">the JPEG library</ulink>
and <ulink url="&url.tiff;">the TIFF library</ulink> to
compile this. These two libs also quite often make problems when
configuring php. Follow the messages of configure to fix possible
problems.
</simpara>
<simpara>
Please consult the excellent documentation for
pdflib shipped with the source distribution of pdflib.
It provides a very good overview of what pdflib capable of doing.
Most of the functions in pdflib
and the PHP module have the same name. The parameters are also
identical. You should also understand some of the concepts of PDF
or Postscript to efficiently use this module.
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.
</simpara>
<simpara>
There is another PHP module for pdf document creation based on
<ulink url="&url.cpdf;">FastIO's</ulink>.
ClibPDF. It has a slightly different API. Check the
<link linkend="ref.cpdf">ClibPDF functions</link> section for
details.
</simpara>
<simpara>
The pdf module introduces two new type of variable.
It is called <parameter>pdfdoc</parameter>
<parameter>pdfdoc</parameter> is a pointer to a pdf document and
almost all functions need it as its first parameter.
</simpara>
</sect1>
<sect1>
<title>Confusion with old pdflib versions</title>
<simpara>
Since the very begining of PDF support in PHP — starting with
pdflib 0.6 —
there has been tons of changes especially to the pdflib API. Most of
these changes has been somehow covered by PHP, some has even required
changes to the PHP API. Since pdflib
3.x the API seems to be stabilzed and PHP 4 has adopted the version as a
minimum requirement for PDF support. The consequence will be that many
functions will disappear or be replaced by alternatives sooner or later.
Support for pdflib 0.6 is already completely given up.
The following table list all the functions which are deprecated
in PHP 4.02 and should be replaced by their new versions.
</simpara>
<para>
<table>
<title>Deprecated functions and its replacements</title>
<tgroup cols="2">
<thead>
<row>
<entry>Old function</entry>
<entry>Replacement</entry>
</row>
</thead>
<tbody>
<row>
<entry><function>pdf_put_image</function></entry>
<entry>Not needed anymore.</entry>
</row>
<row>
<entry><function>pdf_get_font</function></entry>
<entry><function>pdf_get_value</function> passing
<literal>"font"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_get_fontsize</function></entry>
<entry><function>pdf_get_value</function> passing
<literal>"fontsize"</literal> as the second
parameter.</entry>
</row>
<row>
<entry><function>pdf_get_fontname</function></entry>
<entry><function>pdf_get_parameter</function> passing
<literal>"fontname"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_info_creator</function></entry>
<entry><function>pdf_set_info</function> passing
<literal>"Creator"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_info_title</function></entry>
<entry><function>pdf_set_info</function> passing
<literal>"Title"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_info_subject</function></entry>
<entry><function>pdf_set_info</function> passing
<literal>"Subject"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_info_author</function></entry>
<entry><function>pdf_set_info</function> passing
<literal>"Author"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_info_keywords</function></entry>
<entry><function>pdf_set_info</function> passing
<literal>"Keywords"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_leading</function></entry>
<entry><function>pdf_set_value</function> passing
<literal>"leading"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_text_rendering</function></entry>
<entry><function>pdf_set_value</function> passing
<literal>"textrendering"</literal> as the second
parameter.</entry>
</row>
<row>
<entry><function>pdf_set_text_rise</function></entry>
<entry><function>pdf_set_value</function> passing
<literal>"textrise"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_set_horiz_scaling</function></entry>
<entry><function>pdf_set_value</function> passing
<literal>"horizscaling"</literal> as the second
parameter.</entry>
</row>
<row>
<entry><function>pdf_set_text_matrix</function></entry>
<entry>Not available anymore</entry>
</row>
<row>
<entry><function>pdf_set_char_spacing</function></entry>
<entry><function>pdf_set_value</function> passing
<literal>"charspacing"</literal> as the second
parameter.</entry>
</row>
<row>
<entry><function>pdf_set_word_spacing</function></entry>
<entry><function>pdf_set_value</function> passing
<literal>"wordspacing"</literal> as the second
parameter.</entry>
</row>
<row>
<entry><function>pdf_set_transition</function></entry>
<entry><function>pdf_set_parameter</function> passing
<literal>"transition"</literal> as the second
parameter.</entry>
</row>
<row>
<entry><function>pdf_set_duration</function></entry>
<entry><function>pdf_set_value</function> passing
<literal>"duration"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_open_gif</function></entry>
<entry><function>pdf_open_image_file</function> passing
<literal>"gif"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_open_jpeg</function></entry>
<entry><function>pdf_open_image_file</function> passing
<literal>"jpeg"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_open_tiff</function></entry>
<entry><function>pdf_open_image_file</function> passing
<literal>"tiff"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_open_png</function></entry>
<entry><function>pdf_open_image_file</function> passing
<literal>"png"</literal> as the second parameter.</entry>
</row>
<row>
<entry><function>pdf_get_imagewidth</function></entry>
<entry><function>pdf_get_value</function> passing
<literal>"imagewidth"</literal> as the second parameter and the image
as the third parameter.</entry>
</row>
<row>
<entry><function>pdf_get_imageheight</function></entry>
<entry><function>pdf_get_value</function> passing
<literal>"imageheight"</literal> as the second parameter and the
image as the third parameter.</entry>
</row>
<row>
<entry><function></function></entry>
<entry><function></function></entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect1>
<sect1>
<title>Hints for installation of pdflib 3.x</title>
<simpara>
Since version 3.0 of pdflib you should configure pdflib with the option
<literal>--enable-shared-pdflib</literal>.
</simpara>
</sect1>
<sect1>
<title>Issues with older versions of pdflib</title>
<simpara>
If you use pdflib 2.01 check how the lib was installed.
There should be a file or a to link libpdf.so. Version 2.01 just creates
a lib with the name libpdf2.01.so which cannot be found when linking
the test programm in configure. You will have to create a symbolic
link from libpdf.so to libpdf2.01.so.).
</simpara>
<simpara>
Version 2.20 of pdflib has introduced more changes to its API and
support for chinese and japanese fonts. This unfortunately causes
some changes of the pdf module of php4 (not php3). If you use pdflib 2.20
handle the in memory generation of PDF documents with care. Until
pdflib 3.0 is released it might be unstable. The encoding parameter
of <function>pdf_set_font</function> has changed to a string. This
means that instead of e.g. 4 you have to use 'winansi'.
</simpara>
<simpara>
If you use pdflib 2.30 the <function>pdf_set_text_matrix</function>
will have gone. It is not supported any more. In general it is a good
advise to consult the release notes of the used version of pdflib
for possible changes.
</simpara>
<simpara>
Any version of PHP 4 after March, 9th 2000 do not support versions
of pdflib older than 3.0. PHP 3 on the other hand should not be used
with version newer than 2.01.
</simpara>
</sect1>
<sect1>
<title>Examples</title>
<simpara>
Most of the functions are fairly easy to use. The most difficult part
is probably to create a very simple pdf document at all. The following
example should help to get started.
It creates the file <filename>test.pdf</filename>
with one page. The page contains the text "Times-Roman" in an
outlined 30pt font. The text is also underlined.
</simpara>
<para>
<example>
<title>Creating a PDF document with pdflib</title>
<programlisting>
<?php
$fp = fopen("test.pdf", "w");
$pdf = pdf_open($fp);
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0");
pdf_set_info($pdf, "Creator", "See Author");
pdf_set_info($pdf, "Subject", "Testing");
pdf_begin_page($pdf, 595, 842);
pdf_add_outline($pdf, "Page 1");
pdf_set_font($pdf, "Times-Roman", 30, "host");
pdf_set_value($pdf, "textrendering", 1);
pdf_show_xy($pdf, "Times Roman outlined", 50, 750);
pdf_moveto($pdf, 50, 740);
pdf_lineto($pdf, 330, 740);
pdf_stroke($pdf);
pdf_end_page($pdf);
pdf_close($pdf);
fclose($fp);
echo "<A HREF=getpdf.php>finished</A>";
?>
</programlisting>
<simpara>
The script <filename>getpdf.php</filename> just returns the pdf document.
</simpara>
<informalexample>
<programlisting>
<?php
$fp = fopen("test.pdf", "r");
header("Content-type: application/pdf");
fpassthru($fp);
fclose($fp);
?>
</programlisting>
</informalexample>
</example>
</para>
<para>
The pdflib distribution contains a more complex example which
creates a serious of pages with an analog clock. This example
converted into PHP using pdflib looks as the following (you
can see the same example in the documentation for the
<link linkend="ref.cpdf">clibpdf module)</link>:
</para>
<para>
<example>
<title>pdfclock example from pdflib distribution</title>
<programlisting>
<?php
$pdffilename = "clock.pdf";
$radius = 200;
$margin = 20;
$pagecount = 40;
$fp = fopen($pdffilename, "w");
$pdf = pdf_open($fp);
pdf_set_info($pdf, "Creator", "pdf_clock.php3");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Analog Clock");
while($pagecount-- > 0) {
pdf_begin_page($pdf, 2 * ($radius + $margin), 2 * ($radius + $margin));
pdf_set_parameter($pdf, "transition", "wipe");
pdf_set_value($pdf, "duration", 0.5);
pdf_translate($pdf, $radius + $margin, $radius + $margin);
pdf_save($pdf);
pdf_setrgbcolor($pdf, 0.0, 0.0, 1.0);
/* minute strokes */
pdf_setlinewidth($pdf, 2.0);
for ($alpha = 0; $alpha < 360; $alpha += 6) {
pdf_rotate($pdf, 6.0);
pdf_moveto($pdf, $radius, 0.0);
pdf_lineto($pdf, $radius-$margin/3, 0.0);
pdf_stroke($pdf);
}
pdf_restore($pdf);
pdf_save($pdf);
/* 5 minute strokes */
pdf_setlinewidth($pdf, 3.0);
for ($alpha = 0; $alpha < 360; $alpha += 30) {
pdf_rotate($pdf, 30.0);
pdf_moveto($pdf, $radius, 0.0);
pdf_lineto($pdf, $radius-$margin, 0.0);
pdf_stroke($pdf);
}
$ltime = getdate();
/* draw hour hand */
pdf_save($pdf);
pdf_rotate($pdf,-(($ltime['minutes']/60.0)+$ltime['hours']-3.0)*30.0);
pdf_moveto($pdf, -$radius/10, -$radius/20);
pdf_lineto($pdf, $radius/2, 0.0);
pdf_lineto($pdf, -$radius/10, $radius/20);
pdf_closepath($pdf);
pdf_fill($pdf);
pdf_restore($pdf);
/* draw minute hand */
pdf_save($pdf);
pdf_rotate($pdf,-(($ltime['seconds']/60.0)+$ltime['minutes']-15.0)*6.0);
pdf_moveto($pdf, -$radius/10, -$radius/20);
pdf_lineto($pdf, $radius * 0.8, 0.0);
pdf_lineto($pdf, -$radius/10, $radius/20);
pdf_closepath($pdf);
pdf_fill($pdf);
pdf_restore($pdf);
/* draw second hand */
pdf_setrgbcolor($pdf, 1.0, 0.0, 0.0);
pdf_setlinewidth($pdf, 2);
pdf_save($pdf);
pdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
pdf_moveto($pdf, -$radius/5, 0.0);
pdf_lineto($pdf, $radius, 0.0);
pdf_stroke($pdf);
pdf_restore($pdf);
/* draw little circle at center */
pdf_circle($pdf, 0, 0, $radius/30);
pdf_fill($pdf);
pdf_restore($pdf);
pdf_end_page($pdf);
}
$pdf = pdf_close($pdf);
fclose($fp);
echo "<A
HREF=getpdf.php?filename=".$pdffilename.">finished</A>";
?>
</programlisting>
<simpara>
The PHP script <filename>getpdf.php</filename> just outputs the pdf document.
</simpara>
<programlisting>
<?php
$fp = fopen($filename, "r");
header("Content-type: application/pdf");
fpassthru($fp);
fclose($fp);
?>
</programlisting>
</example></para>
</sect1>
</partintro>
<refentry id="function.pdf-set-info">
<refnamediv>
<refname>pdf_set_info</refname>
<refpurpose>Fills a field of the document information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_info</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>fieldname</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_info</function> function sets an information field
of a pdf document.
Possible values for the fieldname are 'Subject', 'Title',
'Creator',
'Author', 'Keywords' and one user-defined name.
It can be called before beginning a page.
<example>
<title>Setting document information</title>
<programlisting>
<?php
$fd = fopen("test.pdf", "w");
$pdfdoc = pdf_open($fd);
pdf_set_info($pdfdoc, "Author", "Uwe Steinmann");
pdf_set_info($pdfdoc, "Creator", "Uwe Steinmann");
pdf_set_info($pdfdoc, "Title", "Testing Info Fields");
pdf_set_info($pdfdoc, "Subject", "Test");
pdf_set_info($pdfdoc, "Keywords", "Test, Fields");
pdf_set_info($pdfdoc, "CustomField", "What ever makes sense");
pdf_begin_page($pdfdoc, 595, 842);
pdf_end_page($pdfdoc);
pdf_close($pdfdoc);
?>
</programlisting></example></para>
<note><simpara>
This function replaces <function>pdf_set_info_keywords</function>,
<function>pdf_set_info_title</function>,
<function>pdf_set_info_subject</function>,
<function>pdf_set_info_creator</function>,
<function>pdf_set_info_sybject</function>.
</simpara></note>
</refsect1>
</refentry>
<refentry id="function.pdf-open">
<refnamediv>
<refname>pdf_open</refname>
<refpurpose>Opens a new pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_open</function></funcdef>
<paramdef>int <parameter>file</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_open</function> function opens
a new pdf document. The corresponding file has to be opened
with <function>fopen</function> and the file descriptor passed
as argument <parameter>file</parameter>.
If you do not pass any parameters, the document will be created in memory
and outputed page by page either to stdout or to the web browser.
<note><simpara>
The return value is needed as the first parameter in all other
functions writing to the pdf document.
</simpara></note>
</para>
<para>
See also <function>fopen</function>,
<function>pdf_close</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-close">
<refnamediv>
<refname>pdf_close</refname>
<refpurpose>Closes a pdf document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_close</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_close</function> function closes the pdf document.
</para>
<para>
See also <function>pdf_open</function>,
<function>fclose</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-begin-page">
<refnamediv>
<refname>pdf_begin_page</refname>
<refpurpose>Starts new page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_begin_page</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
<paramdef>double <parameter>height</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_begin_page</function> function starts a new
page with height <parameter>height</parameter> and width
<parameter>width</parameter>. In order to create a valid
document you must call this function and
<function>pdf_end_page</function> at least once.</para>
<para>
See also <function>pdf_end_page</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-end-page">
<refnamediv>
<refname>pdf_end_page</refname>
<refpurpose>Ends a page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_end_page</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_end_page</function> function ends a page.
Once a page is ended it cannot be modified anymore.</para>
<para>
See also <function>pdf_begin_page</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-show">
<refnamediv>
<refname>pdf_show</refname>
<refpurpose>Output text at current position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_show</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_show</function> function outputs the
string <parameter>text</parameter> at the current text position
using the current font.</para>
<para>
See also <function>pdf_show_xy</function>,
<function>pdf_show_boxed</function>,
<function>pdf_set_text_pos</function>,
<function>pdf_set_font</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-show-boxed">
<refnamediv>
<refname>pdf_show_boxed</refname>
<refpurpose>Output text in a box</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_show_boxed</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
<paramdef>double <parameter>height</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_show_boxed</function> function outputs the
string <parameter>text</parameter> in a box with its lower left position
at (<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
The boxes dimension is <parameter>height</parameter> by
<parameter>width</parameter>. The parameter <parameter>mode</parameter>
determines how the text is type set. If <parameter>width</parameter>
and <parameter>height</parameter> are zero, the
<parameter>mode</parameter> can be "left", "right" or
"center".
If <parameter>width</parameter> or <parameter>height</parameter> is
unequal zero it can also be "justify" and "fulljustify".
</para>
<para>Returns the number of characters that could not be processed because
they did not fit into the box.
</para>
<para>
See also <function>pdf_show</function>,
<function>pdf_show_xy</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pdf-show-xy">
<refnamediv>
<refname>pdf_show_xy</refname>
<refpurpose>Output text at given position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_show_xy</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_show_xy</function> function outputs the
string <parameter>text</parameter> at position
(<parameter>x-coor</parameter>,
<parameter>y-coor</parameter>).</para>
<para>
See also <function>pdf_show</function>,
<function>pdf_show_boxed</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-font">
<refnamediv>
<refname>pdf_set_font</refname>
<refpurpose>Selects a font face and size</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_font</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>font name</parameter></paramdef>
<paramdef>double <parameter>size</parameter></paramdef>
<paramdef>string <parameter>encoding</parameter></paramdef>
<paramdef>int
<parameter><optional>embed</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_font</function> function sets the
current font face, font size and encoding. If you use pdflib 0.6
you will need to
provide the Adobe Font Metrics (afm-files) for the font in the
font path (default is ./fonts). If you use php3 or a version of
pdflib older than 2.20 the fourth parameter
<parameter>encoding</parameter> can take the following values:
0 = builtin, 1 = pdfdoc, 2 = macroman, 3 = macexpert, 4 = winansi.
An encoding greater than 4 and less than 0 will default to winansi.
winansi is often a good choice.
If you use php4 and a version of pdflib >= 2.20 the encoding parameter
has changed to a string. Use 'winansi', 'builtin', 'host',
'macroman' etc. instead.
If the last parameter is set to
1 the font is embedded into the pdf document otherwise it is not.
To embed a font is usually a good idea if the font is not widely spread
and you cannot ensure that the person watching your document has
access on fonts in the document.
I font is only embedded once even if you call
<function>pdf_set_font</function> several times.
</para>
<note>
<simpara>
This function has to be called after
<function>pdf_begin_page</function> in order to create a valid
pdf document.
</simpara>
</note>
<note>
<simpara>
If you reference a font in a .upr file make sure the name
in the afm file and the font name are the same. Otherwise,
the font will be embedded several times (Thanks to Paul Haddon
for finding this.)
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.pdf-set-leading">
<refnamediv>
<refname>pdf_set_leading</refname>
<refpurpose>Sets distance between text lines</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_leading</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>distance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_leading</function> function sets the distance
between text lines. This will be used if text is output by
<function>pdf_continue_text</function>.</para>
<para>
See also <function>pdf_continue_text</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-parameter">
<refnamediv>
<refname>pdf_set_parameter</refname>
<refpurpose>Sets certain parameters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_parameter</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>string <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_parameter</function> function sets several
parameters of pdflib which are of the type string.</para>
<para>
See also <function>pdf_get_value</function>,
<function>pdf_set_value</function>,
<function>pdf_get_parameter</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-get-parameter">
<refnamediv>
<refname>pdf_get_parameter</refname>
<refpurpose>Gets certain parameters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pdf_get_parameter</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>double
<parameter><optional>modifier</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_get_parameter</function> function gets several
parameters of pdflib which are of the type string. The function parameter
<parameter>modifier</parameter> characterizes the parameter to get.
If the modifier is not needed it has to be 0 or not passed at all.</para>
<para>
See also <function>pdf_get_value</function>,
<function>pdf_set_value</function>,
<function>pdf_set_parameter</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-value">
<refnamediv>
<refname>pdf_set_value</refname>
<refpurpose>Sets certain numerical value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_value</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>double <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_value</function> function sets several
numerical parameters of pdflib.</para>
<para>
See also <function>pdf_get_value</function>,
<function>pdf_get_parameter</function>,
<function>pdf_set_parameter</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-get-value">
<refnamediv>
<refname>pdf_get_value</refname>
<refpurpose>Gets certain numerical value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>pdf_get_value</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>double
<parameter><optional>modifier</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_get_value</function> function gets several
numerical parameters of pdflib. The function parameter
<parameter>modifier</parameter> characterizes the parameter to get.
If the modifier is not needed it has to be 0 or not passed at all.</para>
<para>
See also <function>pdf_set_value</function>,
<function>pdf_get_parameter</function>,
<function>pdf_set_parameter</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-get-image-height">
<refnamediv>
<refname>pdf_get_image_height</refname>
<refpurpose>Returns height of an image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pdf_get_image_height</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>image</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_get_image_height</function> function returns the
heights of a pdf image in pixel.</para>
<para>
See also <function>pdf_open_image_file</function>,
<function>pdf_open_memory_image</function>,
<function>pdf_get_image_width</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-get-image-width">
<refnamediv>
<refname>pdf_get_image_width</refname>
<refpurpose>Returns width of an image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pdf_get_image_width</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>image</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_get_image_width</function> function returns the
widths of a pdf image in pixel.</para>
<para>
See also <function>pdf_open_image_file</function>,
<function>pdf_open_memory_image</function>,
<function>pdf_get_image_height</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-text-rendering">
<refnamediv>
<refname>pdf_set_text_rendering</refname>
<refpurpose>Determines how text is rendered</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_text_rendering</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_text_rendering</function> function determines
how text is rendered. The possible values for <parameter>mode</parameter>
are 0=fill text, 1=stroke text, 2=fill and stroke text, 3=invisible,
4=fill text and add it to cliping path, 5=stroke text and add it to
clipping path, 6=fill and stroke text and add
it to cliping path, 7=add it to clipping path.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-horiz-scaling">
<refnamediv>
<refname>pdf_set_horiz_scaling</refname>
<refpurpose>Sets horizontal scaling of text</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_horiz_scaling</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_horiz_scaling</function> function sets the
horizontal scaling to <parameter>scale</parameter> percent.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-text-rise">
<refnamediv>
<refname>pdf_set_text_rise</refname>
<refpurpose>Sets the text rise</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_text_rise</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>rise</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_text_rise</function> function sets the
text rising to <parameter>rise</parameter> points.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-text-matrix">
<refnamediv>
<refname>pdf_set_text_matrix</refname>
<refpurpose>Sets the text matrix</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_text_matrix</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>array <parameter>matrix</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_text_matrix</function> function sets
a matrix which describes a transformation applied on the current
text font. The matrix has to passed as an array with six elements.</para>
<note><simpara>This function is not available anymore since pdflib 2.3
</simpara></note>
</refsect1>
</refentry>
<refentry id="function.pdf-set-text-pos">
<refnamediv>
<refname>pdf_set_text_pos</refname>
<refpurpose>Sets text position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_text_pos</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_text_pos</function> function sets the
position of text for the next <function>pdf_show</function>
function call.</para>
<para>
See also <function>pdf_show</function>,
<function>pdf_show_xy</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-char-spacing">
<refnamediv>
<refname>pdf_set_char_spacing</refname>
<refpurpose>Sets character spacing</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_char_spacing</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>space</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_char_spacing</function> function sets the
spacing between characters.</para>
<para>
See also <function>pdf_set_word_spacing</function>,
<function>pdf_set_leading</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-word-spacing">
<refnamediv>
<refname>pdf_set_word_spacing</refname>
<refpurpose>Sets spacing between words</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_word_spacing</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>space</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_word_spacing</function> function sets the
spacing between words.</para>
<para>
See also <function>pdf_set_char_spacing</function>,
<function>pdf_set_leading</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-skew">
<refnamediv>
<refname>pdf_skew</refname>
<refpurpose>Skews the coordinate system</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_skew</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>alpha</parameter></paramdef>
<paramdef>double <parameter>beta</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_skew</function> function skew the coordinate
system by <parameter>alpha</parameter> (x) and
<parameter>beta</parameter> (y) degrees.
<parameter>alpha</parameter> and <parameter>beta</parameter> may
not be 90 or 270 degrees.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-continue-text">
<refnamediv>
<refname>pdf_continue_text</refname>
<refpurpose>Outputs text in next line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_continue_text</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_continue_text</function> function outputs the
string in <parameter>text</parameter> in the next line.
The distance between the lines can be set with
<function>pdf_set_leading</function>.</para>
<para>
See also <function>pdf_show_xy</function>,
<function>pdf_set_leading</function>,
<function>pdf_set_text_pos</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-stringwidth">
<refnamediv>
<refname>pdf_stringwidth</refname>
<refpurpose>Returns width of text using current font</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>pdf_stringwidth</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_stringwidth</function> function returns the
width of the string in <parameter>text</parameter> by using the
current font. It requires a font to be set before with
<function>pdf_set_font</function>.</para>
<para>
See also <function>pdf_set_font</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-save">
<refnamediv>
<refname>pdf_save</refname>
<refpurpose>Saves the current environment</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_save</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_save</function> 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. <function>pdf_save</function> should always be
followed by <function>pdf_restore</function> to restore the environment
before <function>pdf_save</function>.</para>
<para>
See also <function>pdf_restore</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-restore">
<refnamediv>
<refname>pdf_restore</refname>
<refpurpose>Restores formerly saved environment</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_restore</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_restore</function> function restores the
environment saved with <function>pdf_save</function>. It works
like the postscript command grestore.
<example>
<title>Save and Restore</title>
<programlisting>
<?php pdf_save($pdf);
// do all kinds of rotations, transformations, ...
pdf_restore($pdf) ?>
</programlisting></example></para>
<para>
See also <function>pdf_save</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-translate">
<refnamediv>
<refname>pdf_translate</refname>
<refpurpose>Sets origin of coordinate system</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_translate</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_translate</function> function sets the origin of
coordinate system to the point (<parameter>x-coor</parameter>,
<parameter>y-coor</parameter>) relativ the current origin.
The following example draws
a line from (0, 0) to (200, 200) relative to the initial coordinate
system. You have to set the current point after
<function>pdf_translate</function> and before you start drawing
more objects.
<example>
<title>Translation</title>
<programlisting>
<?php pdf_moveto($pdf, 0, 0);
pdf_lineto($pdf, 100, 100);
pdf_stroke($pdf);
pdf_translate($pdf, 100, 100);
pdf_moveto($pdf, 0, 0);
pdf_lineto($pdf, 100, 100);
pdf_stroke($pdf);
?>
</programlisting></example></para>
</refsect1>
</refentry>
<refentry id="function.pdf-scale">
<refnamediv>
<refname>pdf_scale</refname>
<refpurpose>Sets scaling</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_scale</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-scale</parameter></paramdef>
<paramdef>double <parameter>y-scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_scale</function> function sets the scaling factor
in both directions. The following example scales x and y direction
by 72. The following line will therefore be drawn one inch in both
directions.
<example>
<title>Scaling</title>
<programlisting>
<?php pdf_scale($pdf, 72.0, 72.0);
pdf_lineto($pdf, 1, 1);
pdf_stroke($pdf);
?>
</programlisting></example></para>
</refsect1>
</refentry>
<refentry id="function.pdf-rotate">
<refnamediv>
<refname>pdf_rotate</refname>
<refpurpose>Sets rotation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_rotate</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>angle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_rotate</function> function sets the rotation in
degress to <parameter>angle</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setflat">
<refnamediv>
<refname>pdf_setflat</refname>
<refpurpose>Sets flatness</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setflat</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setflat</function> function sets the flatness to
a value between 0 and 100.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setlinejoin">
<refnamediv>
<refname>pdf_setlinejoin</refname>
<refpurpose>Sets linejoin parameter</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setlinejoin</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>long <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setlinejoin</function> function sets the linejoin
parameter between a value of 0 and 2.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setlinecap">
<refnamediv>
<refname>pdf_setlinecap</refname>
<refpurpose>Sets linecap parameter</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setlinecap</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setlinecap</function> function sets the linecap
parameter between a value of 0 and 2.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setmiterlimit">
<refnamediv>
<refname>pdf_setmiterlimit</refname>
<refpurpose>Sets miter limit</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setmiterlimit</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setmiterlimit</function> function sets the miter limit
to a value greater of equal than 1.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setlinewidth">
<refnamediv>
<refname>pdf_setlinewidth</refname>
<refpurpose>Sets line width</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setlinewidth</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setlinewidth</function> function sets the line width
to <parameter>width</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setdash">
<refnamediv>
<refname>pdf_setdash</refname>
<refpurpose>Sets dash pattern</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setdash</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>white</parameter></paramdef>
<paramdef>double <parameter>black</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setdash</function> function sets the dash pattern
<parameter>white</parameter> white points and
<parameter>black</parameter>
black points. If both are 0 a solid line is set.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-moveto">
<refnamediv>
<refname>pdf_moveto</refname>
<refpurpose>Sets current point</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_moveto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_moveto</function> function sets the current point
to the coordinates <parameter>x-coor</parameter> and
<parameter>y-coor</parameter>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-curveto">
<refnamediv>
<refname>pdf_curveto</refname>
<refpurpose>Draws a curve</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_curveto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x1</parameter></paramdef>
<paramdef>double <parameter>y1</parameter></paramdef>
<paramdef>double <parameter>x2</parameter></paramdef>
<paramdef>double <parameter>y2</parameter></paramdef>
<paramdef>double <parameter>x3</parameter></paramdef>
<paramdef>double <parameter>y3</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_curveto</function> function draws a Bezier curve
from the current point to the point
(<parameter>x3</parameter>, <parameter>y3</parameter>) using
(<parameter>x1</parameter>, <parameter>y1</parameter>) and
(<parameter>x2</parameter>, <parameter>y2</parameter>) as control
points.</para>
<para>
See also <function>pdf_moveto</function>,
<function>pdf_lineto</function>,
<function>pdf_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-lineto">
<refnamediv>
<refname>pdf_lineto</refname>
<refpurpose>Draws a line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_lineto</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_lineto</function> function draws a line from
the current point to the point with coordinates
(<parameter>x-coor</parameter>,
<parameter>y-coor</parameter>).</para>
<para>
See also <function>pdf_moveto</function>,
<function>pdf_curveto</function>,
<function>pdf_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-circle">
<refnamediv>
<refname>pdf_circle</refname>
<refpurpose>Draws a circle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_circle</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>radius</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_circle</function> function draws a circle with
center at point
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>)
and radius <parameter>radius</parameter>.</para>
<para>
See also <function>pdf_arc</function>,
<function>pdf_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-arc">
<refnamediv>
<refname>pdf_arc</refname>
<refpurpose>Draws an arc</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_arc</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>radius</parameter></paramdef>
<paramdef>double <parameter>start</parameter></paramdef>
<paramdef>double <parameter>end</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_arc</function> function draws an arc with
center at point
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>)
and radius <parameter>radius</parameter>, starting at angle
<parameter>start</parameter> and ending at angle
<parameter>end</parameter>.</para>
<para>
See also <function>pdf_circle</function>,
<function>pdf_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-rect">
<refnamediv>
<refname>pdf_rect</refname>
<refpurpose>Draws a rectangle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_rect</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
<paramdef>double <parameter>height</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_rect</function> function draws a rectangle with
its lower left corner at point
(<parameter>x-coor</parameter>, <parameter>y-coor</parameter>).
This width is set to <parameter>widgth</parameter>.
This height is set to <parameter>height</parameter>.</para>
<para>
See also <function>pdf_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-closepath">
<refnamediv>
<refname>pdf_closepath</refname>
<refpurpose>Closes path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_closepath</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_closepath</function> function closes the
current path. This means, it draws a line from current point to
the point where the first line was started. Many functions like
<function>pdf_moveto</function>, <function>pdf_circle</function>
and <function>pdf_rect</function> start a new path.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-stroke">
<refnamediv>
<refname>pdf_stroke</refname>
<refpurpose>Draws line along path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_stroke</function> function draws a line along
current path. The current path is the sum of all line drawing.
Without this function the line would not be drawn.</para>
<para>
See also <function>pdf_closepath</function>,
<function>pdf_closepath_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-closepath-stroke">
<refnamediv>
<refname>pdf_closepath_stroke</refname>
<refpurpose>Closes path and draws line along path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_closepath_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_closepath_stroke</function> function is a
combination of <function>pdf_closepath</function> and
<function>pdf_stroke</function>. It also clears the path.</para>
<para>
See also <function>pdf_closepath</function>,
<function>pdf_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-fill">
<refnamediv>
<refname>pdf_fill</refname>
<refpurpose>Fills current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_fill</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_fill</function> function fills the interior of
the current path with the current fill color.</para>
<para>
See also <function>pdf_closepath</function>,
<function>pdf_stroke</function>,
<function>pdf_setgray_fill</function>,
<function>pdf_setgray</function>,
<function>pdf_setrgbcolor_fill</function>,
<function>pdf_setrgbcolor</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-fill-stroke">
<refnamediv>
<refname>pdf_fill_stroke</refname>
<refpurpose>Fills and strokes current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_fill_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_fill_stroke</function> function fills the interior of
the current path with the current fill color and draws current path.</para>
<para>
See also <function>pdf_closepath</function>,
<function>pdf_stroke</function>,
<function>pdf_fill</function>,
<function>pdf_setgray_fill</function>,
<function>pdf_setgray</function>,
<function>pdf_setrgbcolor_fill</function>,
<function>pdf_setrgbcolor</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-closepath-fill-stroke">
<refnamediv>
<refname>pdf_closepath_fill_stroke</refname>
<refpurpose>Closes, fills and strokes current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_closepath_fill_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_closepath_fill_stroke</function> function closes,
fills the interior of
the current path with the current fill color and draws current path.</para>
<para>
See also <function>pdf_closepath</function>,
<function>pdf_stroke</function>,
<function>pdf_fill</function>,
<function>pdf_setgray_fill</function>,
<function>pdf_setgray</function>,
<function>pdf_setrgbcolor_fill</function>,
<function>pdf_setrgbcolor</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-endpath">
<refnamediv>
<refname>pdf_endpath</refname>
<refpurpose>Ends current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_endpath</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_endpath</function> function ends
the current path but does not close it.</para>
<para>
See also <function>pdf_closepath</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-clip">
<refnamediv>
<refname>pdf_clip</refname>
<refpurpose>Clips to current path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_clip</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_clip</function> function clips all drawing
to the current path.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setgray-fill">
<refnamediv>
<refname>pdf_setgray_fill</refname>
<refpurpose>Sets filling color to gray value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setgray_fill</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>gray value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setgray_fill</function> function sets the current
gray value to fill a path.</para>
<para>
See also <function>pdf_setrgbcolor_fill</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setgray-stroke">
<refnamediv>
<refname>pdf_setgray_stroke</refname>
<refpurpose>Sets drawing color to gray value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setgray_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>gray value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setgray_stroke</function> function sets the current
drawing color to the given gray value.</para>
<para>
See also <function>pdf_setrgbcolor_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setgray">
<refnamediv>
<refname>pdf_setgray</refname>
<refpurpose>Sets drawing and filling color to gray value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setgray</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>gray value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setgray</function> function sets the current
drawing and filling color to the given gray value.</para>
<para>
See also <function>pdf_setrgbcolor_stroke</function>,
<function>pdf_setrgbcolor_fill</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setrgbcolor-fill">
<refnamediv>
<refname>pdf_setrgbcolor_fill</refname>
<refpurpose>Sets filling color to rgb color value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setrgbcolor_fill</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>red value</parameter></paramdef>
<paramdef>double <parameter>green value</parameter></paramdef>
<paramdef>double <parameter>blue value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setrgbcolor_fill</function> function sets the current
rgb color value to fill a path.</para>
<para>
See also <function>pdf_setrgbcolor_fill</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setrgbcolor-stroke">
<refnamediv>
<refname>pdf_setrgbcolor_stroke</refname>
<refpurpose>Sets drawing color to rgb color value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setrgbcolor_stroke</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>red value</parameter></paramdef>
<paramdef>double <parameter>green value</parameter></paramdef>
<paramdef>double <parameter>blue value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setrgbcolor_stroke</function> function sets the current
drawing color to the given rgb color value.</para>
<para>
See also <function>pdf_setrgbcolor_stroke</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-setrgbcolor">
<refnamediv>
<refname>pdf_setrgbcolor</refname>
<refpurpose>Sets drawing and filling color to rgb color value</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_setrgbcolor</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>red value</parameter></paramdef>
<paramdef>double <parameter>green value</parameter></paramdef>
<paramdef>double <parameter>blue value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_setrgbcolor_stroke</function> function sets the current
drawing and filling color to the given rgb color value.</para>
<para>
See also <function>pdf_setrgbcolor_stroke</function>,
<function>pdf_setrgbcolor_fill</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-add-outline">
<refnamediv>
<refname>pdf_add_outline</refname>
<refpurpose>Adds bookmark for current page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_add_outline</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>text</parameter></paramdef>
<paramdef>int
<parameter><optional>parent</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>open</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_add_outline</function> function adds a bookmark
with text <parameter>text</parameter> that points to the current page.
The bookmark is inserted as a child of <parameter>parent</parameter> and
is by default open if <parameter>open</parameter> is not 0. The
return value is an identifier for the bookmark which can be used
as a parent for other bookmarks. Therefore you can build up hierarchies
of bookmarks.
</para>
<simpara>
Unfortunately pdflib does not make a copy of the string, which forces
PHP to allocate the memory. Currently this piece of memory is not
been freed by any PDF function but it will be taken care of by the
PHP memory manager.</simpara>
</refsect1>
</refentry>
<refentry id="function.pdf-set-transition">
<refnamediv>
<refname>pdf_set_transition</refname>
<refpurpose>Sets transition between pages</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_transition</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>transition</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_transition</function> function set the transition
between following pages. The value of <parameter>transition</parameter>
can be
<simplelist>
<member>
0 for none,
</member>
<member>
1 for two lines sweeping across the screen reveal the page,
</member>
<member>
2 for multiple lines sweeping across the screen reveal the page,
</member>
<member>
3 for a box reveals the page,
</member>
<member>
4 for a single line sweeping across the screen reveals the page,
</member>
<member>
5 for the old page dissolves to reveal the page,
</member>
<member>
6 for the dissolve effect moves from one screen edge to another,
</member>
<member>
7 for the old page is simply replaced by the new page (default)
</member>
</simplelist></para>
<para>
See also <function>pdf_set_duration</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-duration">
<refnamediv>
<refname>pdf_set_duration</refname>
<refpurpose>Sets duration between pages</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_duration</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>duration</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_duration</function> function set the duration
between following pages in seconds.</para>
<para>
See also <function>pdf_set_transition</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-open-gif">
<refnamediv>
<refname>pdf_open_gif</refname>
<refpurpose>Opens a GIF image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_open_gif</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_open_gif</function> function opens an image stored
in the file with the name <parameter>filename</parameter>.
The format of the image has to be gif. The function returns a pdf
image identifier.
<note><simpara>This function shouldn't be used anymore. Please use
the function <function>pdf_open_image_file</function> instead.
</simpara></note>
<example>
<title>Including a gif image</title>
<programlisting>
<?php
$im = pdf_open_gif($pdf, "test.gif");
pdf_place_image($pdf, $im, 100, 100, 1);
pdf_close_image($pdf, $im);
?>
</programlisting>
</example></para>
<para>
See also <function>pdf_close_image</function>,
<function>pdf_open_jpeg</function>,
<function>pdf_open_memory_image</function>,
<function>pdf_execute_image</function>,
<function>pdf_place_image</function>,
<function>pdf_put_image</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-open-png">
<refnamediv>
<refname>pdf_open_png</refname>
<refpurpose>
Opens a PNG image
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>pdf_open_png</function>
</funcdef>
<paramdef>int
<parameter>pdf</parameter>
</paramdef>
<paramdef>string
<parameter>png_file</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_open_png</function> function opens an image stored
in the file with the name <parameter>filename</parameter>.
The format of the image has to be png. The function returns a pdf
image identifier.
<note><simpara>This function shouldn't be used anymore. Please use
the function <function>pdf_open_image_file</function> instead.
</simpara></note>
<example>
<title>Including a PNG image</title>
<programlisting>
<?php
$im = pdf_open_png ($pdf, "test.png");
pdf_place_image ($pdf, $im, 100, 100, 1);
pdf_close_image ($pdf, $im);
?>
</programlisting>
</example>
</para>
<para>
See also <function>pdf_close_image</function>,
<function>pdf_open_jpeg</function>,
<function>pdf_open_gif</function>,
<function>pdf_open_memory_image</function>,
<function>pdf_execute_image</function>,
<function>pdf_place_image</function>,
<function>pdf_put_image</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pdf-open-image-file">
<refnamediv>
<refname>pdf_open_image_file</refname>
<refpurpose>Reads an image from a file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_open_image_file</function></funcdef>
<paramdef>int <parameter>PDF-document</parameter></paramdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function <function>pdf_open_image_file</function> reads an image
of format <parameter>format</parameter> from the file
<parameter>filename</parameter>.
Possible formats are 'png', 'tiff', 'jpeg' and 'gif'.
The function returns a pdf image identifier.
<example>
<title>Inserting an image</title>
<programlisting>
<?php
$pim = pdf_open_image_file($pdf, "png", "picture.png");
pdf_place_image($pdf, $pim, 100, 100, 1);
pdf_close_image($pdf, $pim);
?>
</programlisting>
</example></para>
<para>
See also <function>pdf_close_image</function>,
<function>pdf_open_jpeg</function>,
<function>pdf_open_gif</function>,
<function>pdf_open_tiff</function>,
<function>pdf_open_png</function>,
<function>pdf_execute_image</function>,
<function>pdf_place_image</function>,
<function>pdf_put_image</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-open-memory-image">
<refnamediv>
<refname>pdf_open_memory_image</refname>
<refpurpose>Opens an image created with PHP's image functions</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_open_memory_image</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>image</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_open_memory_image</function> function takes
an image created with the PHP's image functions and makes it available
for the pdf document. The function returns a pdf
image identifier.
<example>
<title>Including a memory image</title>
<programlisting>
<?php
$im = ImageCreate(100, 100);
$col = ImageColorAllocate($im, 80, 45, 190);
ImageFill($im, 10, 10, $col);
$pim = pdf_open_memory_image($pdf, $im);
ImageDestroy($im);
pdf_place_image($pdf, $pim, 100, 100, 1);
pdf_close_image($pdf, $pim);
?>
</programlisting>
</example></para>
<para>
See also <function>pdf_close_image</function>,
<function>pdf_open_jpeg</function>,
<function>pdf_open_gif</function>,
<function>pdf_open_png</function>
<function>pdf_execute_image</function>,
<function>pdf_place_image</function>,
<function>pdf_put_image</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-open-jpeg">
<refnamediv>
<refname>pdf_open_jpeg</refname>
<refpurpose>Opens a JPEG image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_open_jpeg</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_open_jpeg</function> function opens an image stored
in the file with the name <parameter>filename</parameter>.
The format of the image has to be jpeg. The function returns a pdf
image identifier.
<note><simpara>This function shouldn't be used anymore. Please use
the function <function>pdf_open_image_file</function> instead.
</simpara></note></para>
<para>
See also <function>pdf_close_image</function>,
<function>pdf_open_gif</function>,
<function>pdf_open_png</function>,
<function>pdf_open_memory_image</function>,
<function>pdf_execute_image</function>,
<function>pdf_place_image</function>,
<function>pdf_put_image</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-open-tiff">
<refnamediv>
<refname>pdf_open_tiff</refname>
<refpurpose>Opens a TIFF image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pdf_open_tiff</function></funcdef>
<paramdef>int <parameter>PDF-document</parameter></paramdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_open_tiff</function> function opens an image stored
in the file with the name <parameter>filename</parameter>.
The format of the image has to be tiff. The function returns a pdf
image identifier.
<note><simpara>This function shouldn't be used anymore. Please use
the function <function>pdf_open_image_file</function> instead.
</simpara></note>
</para>
<para>
See also <function>pdf_close_image</function>,
<function>pdf_open_gif</function>,
<function>pdf_open_jpeg</function>,
<function>pdf_open_png</function>,
<function>pdf_open_memory_image</function>,
<function>pdf_execute_image</function>,
<function>pdf_place_image</function>,
<function>pdf_put_image</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pdf-close-image">
<refnamediv>
<refname>pdf_close_image</refname>
<refpurpose>Closes an image</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_close_image</function></funcdef>
<paramdef>int <parameter>image</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_close_image</function> function closes an image
which has been opened with any of the <function>pdf_open_xxx</function>
functions.</para>
<para>
See also <function>pdf_open_jpeg</function>,
<function>pdf_open_gif</function>,
<function>pdf_open_memory_image</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-place-image">
<refnamediv>
<refname>pdf_place_image</refname>
<refpurpose>Places an image on the page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_place_image</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>image</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_place_image</function> function places an image
on the page at postion (<parameter>x-coor</parameter>,
<parameter>x-coor</parameter>). The image can be scaled at the same
time.
</para>
<para>
See also <function>pdf_put_image</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pdf-put-image">
<refnamediv>
<refname>pdf_put_image</refname>
<refpurpose>Stores an image in the PDF for later use</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_put_image</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>image</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_put_image</function> function places an image
in the PDF file without showing it. The stored image can be
displayed with the <function>pdf_execute_image</function>
function as many times as needed. This is useful when using the same
image multiple times in order to keep the file size small. Using
<function>pdf_put_image</function> and
<function>pdf_execute_image</function> is highly recommended for
larger images (several kb) if they show up more than once in the
document.
<note><simpara>This function has become meaningless with version
2.01 of pdflib. It will just output a warning.</simpara>
</note></para>
<para>
See also <function>pdf_put_image</function>,
<function>pdf_place_image</function>,
<function>pdf_execute_image</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-execute-image">
<refnamediv>
<refname>pdf_execute_image</refname>
<refpurpose>Places a stored image on the page</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_execute_image</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>int <parameter>image</parameter></paramdef>
<paramdef>double <parameter>x-coor</parameter></paramdef>
<paramdef>double <parameter>y-coor</parameter></paramdef>
<paramdef>double <parameter>scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_execute_image</function> function displays an image that has been
put in the PDF file with the <function>pdf_put_image</function>
function on the current page at the given coordinates.</para>
<para>
The image can be scaled while displaying it. A scale of 1.0
will show the image in the original size.
<note><simpara>This function has become meaningless with version
2.01 of pdflib. It will just output a warning.</simpara>
</note>
<example>
<title>Multiple show of an image</title>
<programlisting>
<?php
$im = ImageCreate(100, 100);
$col1 = ImageColorAllocate($im, 80, 45, 190);
ImageFill($im, 10, 10, $col1);
$pim = pdf_open_memory_image($pdf, $im);
pdf_put_image($pdf, $pim);
pdf_execute_image($pdf, $pim, 100, 100, 1);
pdf_execute_image($pdf, $pim, 200, 200, 2);
pdf_close_image($pdf, $pim);
?>
</programlisting>
</example></para>
</refsect1>
</refentry>
<refentry id="function.pdf-add-annotation">
<refnamediv>
<refname>pdf_add_annotation</refname>
<refpurpose>Adds annotation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_add_annotation</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>llx</parameter></paramdef>
<paramdef>double <parameter>lly</parameter></paramdef>
<paramdef>double <parameter>urx</parameter></paramdef>
<paramdef>double <parameter>ury</parameter></paramdef>
<paramdef>string <parameter>title</parameter></paramdef>
<paramdef>string <parameter>content</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_add_annotation</function> adds a note with
the lower left corner at (<parameter>llx</parameter>,
<parameter>lly</parameter>) and the upper right corner at
(<parameter>urx</parameter>, <parameter>ury</parameter>).</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-border-style">
<refnamediv>
<refname>pdf_set_border_style</refname>
<refpurpose>Sets style of border around links and annotations</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_border_style</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>string <parameter>style</parameter></paramdef>
<paramdef>double <parameter>width</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_border_style</function> function sets the
style and width of the suroundig box of links and annotations.
The parameter <parameter>style</parameter> can be 'solid' or
'dashed'.</para>
<para>
See also <function>pdf_set_border_color</function>,
<function>pdf_set_border_dash</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-border-color">
<refnamediv>
<refname>pdf_set_border_color</refname>
<refpurpose>Sets color of border around links and annotations</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_border_color</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>red</parameter></paramdef>
<paramdef>double <parameter>green</parameter></paramdef>
<paramdef>double <parameter>blue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_border_color</function> function sets the
color of the suroundig box of links and annotations.
The three color components have to have a value between 0.0 and
1.0.</para>
<para>
See also <function>pdf_set_border_style</function>,
<function>pdf_set_border_dash</function>.</para>
</refsect1>
</refentry>
<refentry id="function.pdf-set-border-dash">
<refnamediv>
<refname>pdf_set_border_dash</refname>
<refpurpose>Sets dash style of border around links and annotations</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pdf_set_border_dash</function></funcdef>
<paramdef>int <parameter>pdf document</parameter></paramdef>
<paramdef>double <parameter>black</parameter></paramdef>
<paramdef>double <parameter>white</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>pdf_set_border_dash</function> function sets the
lenght of
black and white areas of a dashed line of the suroundig box of
links and annotations.</para>
<para>
See also <function>pdf_set_border_style</function>,
<function>pdf_set_border_color</function>.</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/pfpro.xml
+++ phpdoc/nl/functions/pfpro.xml
<reference id="ref.pfpro">
<title>Verisign Payflow Pro functions</title>
<titleabbrev>Verisign Payflow Pro</titleabbrev>
<partintro>
<simpara>
This extension allows you to process credit cards and other financial
transactions using Verisign Payment Services, formerly known as Signio
(<ulink url="&url.pfpro;">&url.pfpro;</ulink>).
</simpara>
<simpara>
These functions are only available if PHP has been compiled with the
<option role="configure">--with-pfpro[=DIR]</option> option. You will
require the appropriate SDK for your platform, which may be
downloaded <ulink url="&url.pfpro.download;">from within the manager
interface</ulink> once you have registered.
</simpara>
<simpara>
Once you have downloaded the SDK you should copy the files from
the <filename class="directory">lib</filename> directory of the
distribution. Copy the header file <filename>pfpro.h</filename>
to <filename class="directory">/usr/local/include</filename>
and the library file <filename>libpfpro.so</filename> to
<filename class="directory">/usr/local/lib</filename>.
</simpara>
<simpara>
When using these functions, you may omit calls to
<function>pfpro_init</function> and <function>pfpro_cleanup</function>
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 <function>pfpro_process</function> between the two.
</simpara>
<simpara>
These functions have been added in PHP 4.0.2.
</simpara>
<note><para>
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.
</para></note>
</partintro>
<refentry id="function.pfpro-init">
<refnamediv>
<refname>pfpro_init</refname>
<refpurpose>Initialises the Payflow Pro library</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pfpro_init</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>pfpro_init</function> is used to initialise
the Payflow Pro library. You may omit this call, in which case
this extension will automatically call <function>pfpro_init</function>
before the first transaction.
</para>
<para>
See also <function>pfpro_cleanup</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pfpro-cleanup">
<refnamediv>
<refname>pfpro_cleanup</refname>
<refpurpose>Shuts down the Payflow Pro library</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pfpro_cleanup</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>pfpro_cleanup</function> 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 <function>pfpro_cleanup</function>
after your script terminates.
</para>
<para>
See also <function>pfpro_init</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pfpro-process">
<refnamediv>
<refname>pfpro_process</refname>
<refpurpose>Process a transaction with Payflow Pro</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>pfpro_process</function></funcdef>
<paramdef>array <parameter>parameters</parameter></paramdef>
<paramdef>string
<parameter><optional>address</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>port</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>timeout</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>proxy address</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>proxy port</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>proxy logon</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>proxy password</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An associative array containing the response
</para>
<para>
<function>pfpro_process</function> 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.
</para>
<para>
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.
</para>
<para>
The third parameter specifies the port to connect on. It
defaults to 443, the standard SSL port.
</para>
<para>
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.
</para>
<para>
The fifth parameter, if required, specifies the hostname of your
SSL proxy. The sixth parameter specifies the port to use.
</para>
<para>
The seventh and eighth parameters specify the logon identity
and password to use on the proxy.
</para>
<para>
The function returns an associative array of the keys and values
in the response.
</para>
<note><para>
Be sure to read the Payflow Pro Developers Guide for full details
of the required parameters.
</para></note>
<example>
<title>Payflow Pro example</title>
<programlisting role="php">
<?php
pfpro_init();
$transaction = array(USER => 'mylogin',
PWD => 'mypassword',
TRXTYPE => 'S',
TENDER => 'C',
AMT => 1.50,
ACCT => '4111111111111111',
EXPDATE => '0904'
);
$response = pfpro_process($transaction);
if (!$response) {
die("Couldn't establish link to Verisign.\n");
}
echo "Verisign response code was ".$response[RESULT];
echo ", which means: ".$response[RESPMSG]."\n";
echo "\nThe transaction request: ";
print_r($transaction);
echo "\nThe response: ";
print_r($response);
pfpro_cleanup();
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.pfpro-process-raw">
<refnamediv>
<refname>pfpro_process_raw</refname>
<refpurpose>Process a raw transaction with Payflow Pro</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pfpro_process_raw</function></funcdef>
<paramdef>string <parameter>parameters</parameter></paramdef>
<paramdef>string
<parameter><optional>address</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>port</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>timeout</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>proxy address</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>proxy port</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>proxy logon</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>proxy password</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A string containing the response.
</para>
<para>
<function>pfpro_process_raw</function> processes a raw transaction
string with Payflow Pro. You should really use
<function>pfpro_process</function> instead, as the encoding
rules of these transactions are non-standard.
</para>
<para>
The first parameter in this case is a string containing the raw
transaction request. All other parameters are the same as with
<function>pfpro_process</function>. The return value is a string
containing the raw response.
</para>
<note><para>
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 <function>pfpro_process</function> instead.
</para></note>
<example>
<title>Payflow Pro raw example</title>
<programlisting role="php">
<?php
pfpro_init();
$response =
pfpro_process("USER=mylogin&PWD[5]=m&ndy&TRXTYPE=S&TENDER=C&AMT=1.50&ACCT=4111111111111111&EXPDATE=0904");
if (!$response) {
die("Couldn't establish link to Verisign.\n");
}
echo "Verisign raw response was ".$response;
pfpro_cleanup();
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.pfpro-version">
<refnamediv>
<refname>pfpro_version</refname>
<refpurpose>Returns the version of the Payflow Pro software</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pfpro_version</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>pfpro_version</function> returns the version string
of the Payflow Pro library. At the time of writing, this was L211.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/pgsql.xml
+++ phpdoc/nl/functions/pgsql.xml
<reference id="ref.pgsql">
<title>PostgreSQL functions</title>
<titleabbrev>PostgreSQL</titleabbrev>
<partintro>
<para>
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/SQL3 language support, transaction integrity, and type
extensibility. PostgreSQL is an open source descendant of this
original Berkeley code.
</para>
<para>
PostgreSQL is available without cost. The current version is
available at <ulink url="&url.pgsql;">www.PostgreSQL.org</ulink>.
</para>
<para>
Since version 6.3 (03/02/1998) PostgreSQL uses unix domain sockets.
A table is shown below describing these new connection possibilities.
This socket will be found in <filename>/tmp/.s.PGSQL.5432</filename>.
This option can be enabled with the '-i' flag to <command>postmaster
</command> and it's meaning is: "listen on TCP/IP sockets as well as
Unix domain sockets".
<table>
<title>Postmaster and PHP</title>
<tgroup cols="3">
<thead>
<row>
<entry>Postmaster</entry>
<entry>PHP</entry>
<entry>Status</entry>
</row>
</thead>
<tbody>
<row>
<entry>postmaster &</entry>
<entry>pg_connect("dbname=MyDbName");</entry>
<entry>OK</entry>
</row>
<row>
<entry>postmaster -i &</entry>
<entry>pg_connect("dbname=MyDbName");</entry>
<entry>OK</entry>
</row>
<row>
<entry>postmaster &</entry>
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
<entry>
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.php3 on line 20.
</entry>
</row>
<row>
<entry>postmaster -i &</entry>
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
<entry>OK</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
One can establish a connection with the following value pairs
set in the command string:
<command>$conn = pg_Connect("host=myHost port=myPort tty=myTTY
options=myOptions user=myUser password=myPassword dbname=myDB");
</command>
</para>
<para>
The previous syntax of:
<command>$conn = pg_connect ("host", "port", "options",
"tty",
"dbname")
</command>
has been deprecated.
</para>
<para>
To use the large object (lo) interface, it is necessary to enclose
it within a transaction block. A transaction block starts with a
<command>begin</command> and if the transaction was valid ends
with <command>commit</command> or <command>end</command>. If the
transaction fails the transaction should be closed with
<command>rollback</command> or <command>abort</command>.
<example>
<title>Using Large Objects</title>
<programlisting role="php">
<?php
$database = pg_Connect ("dbname=jacarta");
pg_exec ($database, "begin");
$oid = pg_locreate ($database);
echo ("$oid\n");
$handle = pg_loopen ($database, $oid, "w");
echo ("$handle\n");
pg_lowrite ($handle, "gaga");
pg_loclose ($handle);
pg_exec ($database, "commit");
?>
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.pg-close">
<refnamediv>
<refname>pg_close</refname>
<refpurpose>Close a PostgreSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>pg_close</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns false if connection is not a valid connection index, true
otherwise. Closes down the connection to a PostgreSQL database
associated with the given connection index.
</para>
<note><para>
This isn't usually necessary, as non-persistent open
links are automatically closed at the end of the script's
execution.
</para></note>
<para>
<function>pg_close</function> will not close persistent links
generated by <function>pg_pconnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-cmdtuples">
<refnamediv>
<refname>pg_cmdtuples</refname>
<refpurpose>Returns number of affected tuples</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_cmdtuples</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_cmdtuples</function> returns the number of tuples
(instances) affected by INSERT, UPDATE, and DELETE queries. If no
tuple is affected the function will return 0.
<example>
<title><function>Pg_cmdtuples</function></title>
<programlisting role="php">
<?php
$result = pg_exec ($conn, "INSERT INTO publisher VALUES ('Author')");
$cmdtuples = pg_cmdtuples ($result);
echo $cmdtuples . " <- cmdtuples affected.";
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pg-connect">
<refnamediv>
<refname>pg_connect</refname>
<refpurpose>Open a PostgreSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_connect</function></funcdef>
<paramdef>string <parameter>conn_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a connection index on success, or false if the connection
could not be made. Opens a connection to a PostgreSQL database.
The arguments should be within a quoted string.
<example>
<title>Using pg_connect arguments</title>
<programlisting role="php">
<?php
$dbconn = pg_Connect ("dbname=mary");
//connect to a database named "mary"
$dbconn2 = pg_Connect ("host=localhost port=5432 dbname=mary");
//connect to a database named "mary" on "localhost" at port "5432"
$dbconn3 = pg_Connect ("user=lamb password=baaaa dbname=mary ");
//connect to a database named "mary" with a username and password
?>
</programlisting>
</example>
The arguments available include <parameter>dbname</parameter>
<parameter>port</parameter>, <parameter>host</parameter>,
<parameter>tty</parameter>, <parameter>options</parameter>,
<parameter>user</parameter>, and <parameter>password</parameter>
</para>
<para>
This function returns a connection index that is needed by other
PostgreSQL functions. You can have multiple connections open at
once.
</para>
<para>
The previous syntax of:
<command>$conn = pg_connect ("host", "port", "options",
"tty",
"dbname")
</command>
has been deprecated.
</para>
<para>
See also <function>pg_pconnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-dbname">
<refnamediv>
<refname>pg_dbname</refname>
<refpurpose>Get the database name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_dbname</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the name of the database that the given PostgreSQL
connection index is connected to, or false if connection is not a
valid connection index.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-end-copy">
<refnamediv>
<refname>pg_end_copy</refname>
<refpurpose>Sync with PostgreSQL backend</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>pg_end_copy</function></funcdef>
<paramdef>resource
<parameter><optional>connection</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>pg_end_copy</function> syncs PostgreSQL frontend with
the backend after doing a copy operation. It must be issued or
the backend may get "out of sync" with the frontend. Returns
TRUE if successfull, FALSE otherwise.
</para>
<para>
For further details and an example, see also
<function>pg_put_line</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-errormessage">
<refnamediv>
<refname>pg_errormessage</refname>
<refpurpose>Get the error message string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_errormessage</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing the error message, false on failure.
Details about the error probably cannot be retrieved using the
<function>pg_errormessage</function> function if an error occured
on the last database action for which a valid connection exists,
this function will return a string containing the error message
generated by the backend server.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-exec">
<refnamediv>
<refname>pg_exec</refname>
<refpurpose>Execute a query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_exec</function></funcdef>
<paramdef>int <parameter>connection</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a result index if query could be executed, false on
failure or if connection is not a valid connection index. Details
about the error can be retrieved using the
<function>pg_ErrorMessage</function> function if connection is
valid. Sends an SQL statement to the PostgreSQL database
specified by the connection index. The connection must be a valid
index that was returned by <function>pg_Connect</function>. The
return value of this function is an index to be used to access
the results from other PostgreSQL functions.
<note>
<simpara>
PHP/FI returned 1 if the query was not expected to return data
(inserts or updates, for example) and greater than 1 even on
selects that did not return anything. No such assumption can be
made in PHP.
</simpara>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fetch-array">
<refnamediv>
<refname>pg_fetch_array</refname>
<refpurpose>Fetch a row as an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>pg_fetch_array</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>row</parameter></paramdef>
<paramdef>int
<parameter><optional>result_type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An array that corresponds to the fetched row, or false
if there are no more rows.
</para>
<para>
<function>Pg_fetch_array</function> is an extended version of
<function>pg_fetch_row</function>. 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.
</para>
<para>
The third optional argument <parameter>result_type</parameter> in
<function>pg_fetch_array</function> is a constant and can take the
following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH.
<note>
<para>
<parameter>Result_type</parameter> was added in PHP 4.0.
</para>
</note>
</para>
<para>
An important thing to note is that using
<function>pg_fetch_array</function> is NOT significantly
slower than using <function>pg_fetch_row</function>, while it
provides a significant added value.
</para>
<para>
For further details, see also
<function>pg_fetch_row</function>
</para>
<example>
<title>PostgreSQL fetch array</title>
<programlisting role="php">
<?php
$conn = pg_pconnect ("dbname=publisher");
if (!$conn) {
echo "An error occured.\n";
exit;
}
$result = pg_Exec ($conn, "SELECT * FROM authors");
if (!$result) {
echo "An error occured.\n";
exit;
}
$arr = pg_fetch_array ($result, 0);
echo $arr[0] . " <- array\n";
$arr = pg_fetch_array ($result, 1);
echo $arr["author"] . " <- array\n";
?>
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.pg-fetch-object">
<refnamediv>
<refname>pg_fetch_object</refname>
<refpurpose>Fetch a row as an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>pg_fetch_object</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>row</parameter></paramdef>
<paramdef>int
<parameter><optional>result_type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An object with properties that correspond to the fetched
row, or false if there are no more rows.
</para>
<para>
<function>Pg_fetch_object</function> is similar to
<function>pg_fetch_array</function>, 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).
</para>
<para>
The third optional argument <parameter>result_type</parameter> in
<function>pg_fetch_object</function> is a constant and can take the
following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH.
<note>
<para>
<parameter>Result_type</parameter> was added in PHP 4.0.
</para>
</note>
</para>
<para>
Speed-wise, the function is identical to
<function>pg_fetch_array</function>, and almost as quick as
<function>pg_fetch_row</function> (the difference is
insignificant).
</para>
<para>
See also: <function>pg_fetch_array</function> and
<function>pg_fetch_row</function>.
<example>
<title>Postgres fetch object</title>
<programlisting role="php">
<?php
$database = "verlag";
$db_conn = pg_connect ("host=localhost port=5432 dbname=$database");
if (!$db_conn): ?>
<H1>Failed connecting to postgres database <? echo $database
?></H1> <?
exit;
endif;
$qu = pg_exec ($db_conn, "SELECT * FROM verlag ORDER BY autor");
$row = 0; // postgres needs a row counter other dbs might not
while ($data = pg_fetch_object ($qu, $row)):
echo $data->autor." (";
echo $data->jahr ."): ";
echo $data->titel."<BR>";
$row++;
endwhile; ?>
<PRE><?php
$fields[] = Array ("autor", "Author");
$fields[] = Array ("jahr", " Year");
$fields[] = Array ("titel", " Title");
$row= 0; // postgres needs a row counter other dbs might not
while ($data = pg_fetch_object ($qu, $row)):
echo "----------\n";
reset ($fields);
while (list (,$item) = each ($fields)):
echo $item[1].": ".$data->$item[0]."\n";
endwhile;
$row++;
endwhile;
echo "----------\n"; ?>
</PRE> <?php
pg_freeResult ($qu);
pg_close ($db_conn);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fetch-row">
<refnamediv>
<refname>pg_fetch_row</refname>
<refpurpose>Get a row as an enumerated array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>pg_fetch_row</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>row</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: An array that corresponds to the fetched row, or false
if there are no more rows.
</para>
<para>
<function>Pg_fetch_row</function> 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.
</para>
<para>
See also: <function>pg_fetch_array</function>,
<function>pg_fetch_object</function>,
<function>pg_result</function>.
<example>
<title>Postgres fetch row</title>
<programlisting role="php">
<?php
$conn = pg_pconnect ("dbname=publisher");
if (!$conn) {
echo "An error occured.\n";
exit;
}
$result = pg_Exec ($conn, "SELECT * FROM authors");
if (!$result) {
echo "An error occured.\n";
exit;
}
$num = pg_numrows($result);
for ($i=0; $i<$num; $i++) {
$r = pg_fetch_row($result, $i);
for ($j=0; $j<count($r); $j++) {
echo "$r[$j]&nbsp;";
}
echo "<BR>";
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fieldisnull">
<refnamediv>
<refname>pg_fieldisnull</refname>
<refpurpose>Test if a field is NULL</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_fieldisnull</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>row</parameter></paramdef>
<paramdef>mixed <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Test if a field is NULL or not. Returns 0 if the field in the
given row is not NULL. Returns 1 if the field in the given row is
NULL. Field can be specified as number or fieldname. Row
numbering starts at 0.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fieldname">
<refnamediv>
<refname>pg_fieldname</refname>
<refpurpose>Returns the name of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_fieldname</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_fieldname</function> will return the name of the
field occupying the given column number in the given PostgreSQL
result identifier. Field numbering starts from 0.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fieldnum">
<refnamediv>
<refname>pg_fieldnum</refname>
<refpurpose>Returns the field number of the named field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_fieldnum</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>string <parameter>field_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_fieldnum</function> will return the number of the
column slot that corresponds to the named field in the given
PosgreSQL result identifier. Field numbering starts at 0. This
function will return -1 on error.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fieldprtlen">
<refnamediv>
<refname>pg_fieldprtlen</refname>
<refpurpose>Returns the printed length</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_fieldprtlen</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>row_number</parameter></paramdef>
<paramdef>string <parameter>field_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_fieldprtlen</function> will return 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.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fieldsize">
<refnamediv>
<refname>pg_fieldsize</refname>
<refpurpose>
Returns the internal storage size of the named field
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_fieldsize</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_fieldsize</function> will return 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.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-fieldtype">
<refnamediv>
<refname>pg_fieldtype</refname>
<refpurpose>
Returns the type name for the corresponding field number
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_fieldtype</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_fieldtype</function> will return a string containing
the type name of the given field in the given PostgreSQL result
identifier. Field numbering starts at 0.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-freeresult">
<refnamediv>
<refname>pg_freeresult</refname>
<refpurpose>Free reult memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_freeresult</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_freeresult</function> 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
<function>pg_freeresult</function> with the result identifier as
an argument and the associated result memory will be freed.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-getlastoid">
<refnamediv>
<refname>pg_getlastoid</refname>
<refpurpose>Returns the last object identifier</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_getlastoid</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_getlastoid</function> can be used to retrieve the
<varname>oid</varname> assigned to an inserted tuple if the
result identifier is used from the last command sent via
<function>pg_exec</function> and was an SQL INSERT. This
function will return a positive integer if there was a valid
<varname>oid</varname>. It will return -1 if an error occured or
the last command sent via <function>pg_exec</function> was not an
INSERT.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-host">
<refnamediv>
<refname>pg_host</refname>
<refpurpose>
Returns the host name associated with the connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_host</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_host</function> will return the host name of the
given PostgreSQL connection identifier is connected to.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-loclose">
<refnamediv>
<refname>pg_loclose</refname>
<refpurpose>Close a large object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pg_loclose</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_loclose</function> closes an Inversion Large
Object. <parameter>Fd</parameter> is a file descriptor for the
large object from <function>pg_loopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-locreate">
<refnamediv>
<refname>pg_locreate</refname>
<refpurpose>Create a large object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_locreate</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_locreate</function> creates an Inversion Large
Object and returns the <varname>oid</varname> of the large
object. <parameter>conn</parameter> specifies a valid database
connection. 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).
</para>
</refsect1>
</refentry>
<refentry id="function.pg-loexport">
<refnamediv>
<refname>pg_loexport</refname>
<refpurpose>Export a large object to file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>pg_loexport</function></funcdef>
<paramdef>int
<parameter>oid</parameter>
</paramdef>
<paramdef>int
<parameter>file</parameter>
</paramdef>
<paramdef>int
<parameter><optional>connection_id</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <parameter>oid</parameter> argument specifies the object id
of the large object to export and the
<parameter>filename</parameter> argument specifies the pathname
of the file. Returns FALSE if an error occurred, TRUE
otherwise. Remember that handling large objects in PostgreSQL
must happen inside a transaction.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-loimport">
<refnamediv>
<refname>pg_loimport</refname>
<refpurpose>Import a large object from file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_loimport</function></funcdef>
<paramdef>int
<parameter>file</parameter>
</paramdef>
<paramdef>int
<parameter><optional>connection_id</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <parameter>filename</parameter> argument specifies the
pathname of the file to be imported as a large object. Returns
FALSE if an error occurred, object id of the just created large
object otherwise. Remember that handling large objects in
PostgreSQL must happen inside a transaction.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-loopen">
<refnamediv>
<refname>pg_loopen</refname>
<refpurpose>Open a large object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_loopen</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
<paramdef>int <parameter>objoid</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_loopen</function> open an Inversion Large Object and
returns file descriptor of the large object. The file descriptor
encapsulates information about the connection. Do not close the
connection before closing the large object file descriptor.
<parameter>objoid</parameter> specifies a valid large object oid
and <parameter>mode</parameter> can be either "r", "w", or
"rw".
</para>
</refsect1>
</refentry>
<refentry id="function.pg-loread">
<refnamediv>
<refname>pg_loread</refname>
<refpurpose>Read a large object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_loread</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
<paramdef>int <parameter>len</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>pg_loread</function> reads at most
<parameter>len</parameter> bytes from a large object and
returns it as a string.
<parameter>fd</parameter> specifies a valid large object file
descriptor and<parameter>len</parameter> specifies the maximum
allowable size of the large object segment.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-loreadall">
<refnamediv>
<refname>pg_loreadall</refname>
<refpurpose>
Read a entire large object and send straight to browser
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pg_loreadall</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_loreadall</function> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-lounlink">
<refnamediv>
<refname>pg_lounlink</refname>
<refpurpose>Delete a large object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>pg_lounlink</function></funcdef>
<paramdef>int <parameter>conn</parameter></paramdef>
<paramdef>int <parameter>lobjid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_lounlink</function> deletes a large object with the
<parameter>lobjid</parameter> identifier for that large object.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-lowrite">
<refnamediv>
<refname>pg_lowrite</refname>
<refpurpose>Write a large object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_lowrite</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
<paramdef>string <parameter>buf</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_lowrite</function> writes at most to a large object
from a variable <parameter>buf</parameter> and returns the number
of bytes actually written, or false in the case of an error.
<parameter>fd</parameter> is a file descriptor for the large
object from <function>pg_loopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-numfields">
<refnamediv>
<refname>pg_numfields</refname>
<refpurpose>Returns the number of fields</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_numfields</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_numfields</function> will return the number of
fields (columns) in a PostgreSQL result. The argument is a valid
result identifier returned by <function>pg_exec</function>. This
function will return -1 on error.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-numrows">
<refnamediv>
<refname>pg_numrows</refname>
<refpurpose>Returns the number of rows</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_numrows</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_numrows</function> will return the number of rows in a
PostgreSQL result. The argument is a valid result identifier
returned by <function>pg_exec</function>. This function will
return -1 on error.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-options">
<refnamediv>
<refname>pg_options</refname>
<refpurpose>Get the options associated with the connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_options</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_options</function> will return a string containing
the options specified on the given PostgreSQL connection
identifier.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-pconnect">
<refnamediv>
<refname>pg_pconnect</refname>
<refpurpose>Open a persistant PostgreSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_pconnect</function></funcdef>
<paramdef>string <parameter>conn_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a connection index on success, or false if the connection
could not be made. Opens a connection to a PostgreSQL database.
The arguments should be within a quoted string.
The arguments available include <parameter>dbname</parameter>
<parameter>port</parameter>, <parameter>host</parameter>,
<parameter>tty</parameter>, <parameter>options</parameter>,
<parameter>user</parameter>, and <parameter>password</parameter>
</para>
<para>
This function returns a connection index that is needed by other
PostgreSQL functions. You can have multiple connections open at
once.
</para>
<para>
The previous syntax of:
<command>$conn = pg_pconnect ("host", "port", "options",
"tty",
"dbname")
</command>
has been deprecated.
</para>
<para>
See also <function>pg_connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-port">
<refnamediv>
<refname>pg_port</refname>
<refpurpose>
Return the port number associated with the connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_port</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_port</function> will return the port number that the
given PostgreSQL connection identifier is connected to.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-put-line">
<refnamediv>
<refname>pg_put_line</refname>
<refpurpose>Send a NULL-terminated string to PostgreSQL backend</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>pg_put_line</function></funcdef>
<paramdef>resource
<parameter><optional>connection_id</optional></parameter>
</paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>pg_put_line</function> 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. Returns TRUE if successfull, FALSE
otherwise.
</para>
<note>
<para>
Note the application must explicitly send the two characters "\."
on a final line to indicate to the backend that it has finished
sending its data.
</para>
</note>
<para>
See also <function>pg_end_copy</function>.
<example>
<title>High-speed insertion of data into a table</title>
<programlisting role="php">
<?php
$conn = pg_pconnect ("dbname=foo");
pg_exec($conn, "create table bar (a int4, b char(16), d float8)");
pg_exec($conn, "copy bar from stdin");
pg_put_line($conn, "3\thello world\t4.5\n");
pg_put_line($conn, "4\tgoodbye world\t7.11\n");
pg_put_line($conn, "\\.\n");
pg_end_copy($conn);
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pg-result">
<refnamediv>
<refname>pg_result</refname>
<refpurpose>Returns values from a result identifier</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>pg_result</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>row_number</parameter></paramdef>
<paramdef>mixed <parameter>fieldname</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_result</function> will return values from a result
identifier produced by <function>pg_Exec</function>. The
<parameter>row_number</parameter> and
<parameter>fieldname</parameter> sepcify 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.
</para>
<para>
PostgreSQL has many built in types and only the basic ones are
directly supported here. All forms of integer, boolean and oid
types are returned as integer values. All forms of float, and
real types are returned as double values. All other types,
including arrays are returned as strings formatted in the same
default PostgreSQL manner that you would see in the
<command>psql</command> program.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-set-client-encoding">
<refnamediv>
<refname>pg_set_client_encoding</refname>
<refpurpose>
Set the client encoding
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pg_set_client_encoding</function></funcdef>
<paramdef>int
<parameter><optional>connection</optional></parameter>
</paramdef>
<paramdef>string <parameter>encoding</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function set the client encoding and return 0 if success or
-1 if error.
</para>
<para>
<parameter>encoding</parameter> 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.
</para>
<note>
<para>
This function requires PHP-4.0.2 or higher and PostgreSQL-7.0 or
higher.
</para>
<para>
The function used to be called
<function>pg_setclientencoding</function>.
</para>
</note>
<para>
See also <function>pg_client_encoding</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-client-encoding">
<refnamediv>
<refname>pg_client_encoding</refname>
<refpurpose>
Get the client encoding
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_client_encoding</function></funcdef>
<paramdef>int
<parameter><optional>connection</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The functions 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.
</para>
<note>
<para>
This function requires PHP-4.0.2 or higher and PostgreSQL-7.0 or
higher.
</para>
<para>
The function used to be called
<function>pg_clientencoding</function>.
</para>
</note>
<para>
See also <function>pg_set_client_encoding</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-trace">
<refnamediv>
<refname>pg_trace</refname>
<refpurpose>Enable tracing a PostgreSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>pg_trace</function></funcdef>
<paramdef>string
<parameter>filename</parameter>
</paramdef>
<paramdef>string
<parameter><optional>mode</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>connection</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Enables tracing of the PostgreSQL frontend/backend communication
to a debugging file. 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 <command>grep '^To backend' trace.log</command> and see
what query actually were sent to the PostgreSQL server.
</para>
<para>
<parameter>Filename</parameter> and <parameter>mode</parameter>
are the same as in <function>fopen</function>
(<parameter>mode</parameter> defaults to 'w'),
<parameter>connection</parameter> specifies the connection to
trace and defaults to the last one opened.
</para>
<para>
Returns TRUE if <parameter>filename</parameter> could be opened
for logging, FALSE otherwise.
</para>
<para>
See also <function>fopen</function> and
<function>pg_untrace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-tty">
<refnamediv>
<refname>pg_tty</refname>
<refpurpose>
Return the tty name associated with the connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>pg_tty</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Pg_tty</function> will return the tty name that server
side debugging output is sent to on the given PostgreSQL
connection identifier.
</para>
</refsect1>
</refentry>
<refentry id="function.pg-untrace">
<refnamediv>
<refname>pg_untrace</refname>
<refpurpose>Disable tracing of a PostgreSQL connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>pg_untrace</function></funcdef>
<paramdef>int
<parameter><optional>connection</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Stop tracing started by <function>pg_trace</function>.
<parameter>connection</parameter> specifies the connection that was
traced and defaults to the last one opened.
</para>
<para>
Returns always TRUE.
</para>
<para>
See also <function>pg_trace</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/posix.xml
+++ phpdoc/nl/functions/posix.xml
<reference id="ref.posix">
<title>POSIX functions</title>
<titleabbrev>POSIX</titleabbrev>
<partintro>
<para>
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.
</para>
</partintro>
<refentry id="function.posix-kill">
<refnamediv>
<refname>posix_kill</refname>
<refpurpose>Send a signal to a process</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>posix_kill</function></funcdef>
<paramdef>int <parameter>pid</parameter></paramdef>
<paramdef>int <parameter>sig</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Send the signal <parameter>sig</parameter> to the process
with the process identifier <parameter>pid</parameter>.
Returns FALSE, if unable to send the signal, TRUE otherwise.</para>
<para>
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.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getpid">
<refnamediv>
<refname>posix_getpid</refname>
<refpurpose>Return the current process identifier</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getpid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the process identifier of the current process.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getppid">
<refnamediv>
<refname>posix_getppid</refname>
<refpurpose>Return the parent process identifier</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getppid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the process identifier of the parent process of the current
process.
</para>
</refsect1>
</refentry>
<refentry id="function.posix-getuid">
<refnamediv>
<refname>posix_getuid</refname>
<refpurpose>
Return the real user ID of the current process
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getuid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the numeric real user ID of the current process. See also
<function>posix_getpwuid</function> for information on how to
convert this into a useable username.</para>
</refsect1>
</refentry>
<refentry id="function.posix-geteuid">
<refnamediv>
<refname>posix_geteuid</refname>
<refpurpose>
Return the effective user ID of the current process
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_geteuid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the numeric effective user ID of the current process. See
also <function>posix_getpwuid</function> for information on how
to convert this into a useable username.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getgid">
<refnamediv>
<refname>posix_getgid</refname>
<refpurpose>
Return the real group ID of the current process
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getgid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the numeric real group ID of the current process. See also
<function>posix_getgrgid</function> for information on how to
convert this into a useable group name.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getegid">
<refnamediv>
<refname>posix_getegid</refname>
<refpurpose>
Return the effective group ID of the current process
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getegid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the numeric effective group ID of the current process. See
also <function>posix_getgrgid</function> for information on how
to convert this into a useable group name.</para>
</refsect1>
</refentry>
<refentry id="function.posix-setuid">
<refnamediv>
<refname>posix_setuid</refname>
<refpurpose>
Set the effective UID of the current process
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>posix_setuid</function></funcdef>
<paramdef>int <parameter>uid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.</para>
<para>
Returns TRUE on success, FALSE otherwise. See also
<function>posix_setgid</function>.</para>
</refsect1>
</refentry>
<refentry id="function.posix-setgid">
<refnamediv>
<refname>posix_setgid</refname>
<refpurpose>
Set the effective GID of the current process
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>posix_setgid</function></funcdef>
<paramdef>int <parameter>gid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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
<function>posix_setgid</function> first,
<function>posix_setuid</function> last.</para>
<para>
Returns TRUE on success, FALSE otherwise.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getgroups">
<refnamediv>
<refname>posix_getgroups</refname>
<refpurpose>
Return the group set of the current process
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_getgroups</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of integers containing the numeric group ids of
the group set of the current process. See also
<function>posix_getgrgid</function> for information on how to
convert this into useable group names.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getlogin">
<refnamediv>
<refname>posix_getlogin</refname>
<refpurpose>Return login name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>posix_getlogin</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the login name of the user owning the current process.
See <function>posix_getpwnam</function> for information how to
get more information about this user.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getpgrp">
<refnamediv>
<refname>posix_getpgrp</refname>
<refpurpose>
Return the current process group identifier
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getpgrp</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.</para>
</refsect1>
</refentry>
<refentry id="function.posix-setsid">
<refnamediv>
<refname>posix_setsid</refname>
<refpurpose>Make the current process a session leader</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_setsid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.</para>
</refsect1>
</refentry>
<refentry id="function.posix-setpgid">
<refnamediv>
<refname>posix_setpgid</refname>
<refpurpose>set process group id for job control</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_setpgid</function></funcdef>
<paramdef>int <parameter>pid</parameter></paramdef>
<paramdef>int <parameter>pgid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Let the process <parameter>pid</parameter> join the process
group <parameter>pgid</parameter>. 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.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getpgid">
<refnamediv>
<refname>posix_getpgid</refname>
<refpurpose>Get process group id for job control</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getpgid</function></funcdef>
<paramdef>int <parameter>pid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the process group identifier of the process
<parameter>pid</parameter>.</para>
<para>
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.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getsid">
<refnamediv>
<refname>posix_getsid</refname>
<refpurpose>Get the current sid of the process</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>posix_getsid</function></funcdef>
<paramdef>int <parameter>pid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return the sid of the process <parameter>pid</parameter>.
If <parameter>pid</parameter> is 0, the sid of the
current process is returned.</para>
<para>
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.</para>
</refsect1>
</refentry>
<refentry id="function.posix-uname">
<refnamediv>
<refname>posix_uname</refname>
<refpurpose>Get system name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_uname</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a hash of strings with information about the
system. The indices of the hash are
<itemizedlist>
<listitem><simpara>
sysname - operating system name (e.g. Linux)
</simpara></listitem>
<listitem><simpara>
nodename - system name (e.g. valiant)
</simpara></listitem>
<listitem><simpara>
release - operating system release (e.g. 2.2.10)
</simpara></listitem>
<listitem><simpara>
version - operating system version (e.g. #4 Tue Jul 20
17:01:36 MEST 1999)
</simpara></listitem>
<listitem><simpara>
machine - system architecture (e.g. i586)
</simpara></listitem>
</itemizedlist></para>
<para>
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.</para>
</refsect1>
</refentry>
<refentry id="function.posix-times">
<refnamediv>
<refname>posix_times</refname>
<refpurpose>Get process times</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_times</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a hash of strings with information about the
current process CPU usage. The indices of the hash are
<itemizedlist>
<listitem><simpara>
ticks - the number of clock ticks that have elapsed since
reboot.
</simpara></listitem>
<listitem><simpara>
utime - user time used by the current process.
</simpara></listitem>
<listitem><simpara>
stime - system time used by the current process.
</simpara></listitem>
<listitem><simpara>
cutime - user time used by current process and children.
</simpara></listitem>
<listitem><simpara>
cstime - system time used by current process and children.
</simpara></listitem>
</itemizedlist></para>
</refsect1>
</refentry>
<refentry id="function.posix-ctermid">
<refnamediv>
<refname>posix_ctermid</refname>
<refpurpose>Get path name of controlling terminal</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>posix_ctermid</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written.</para>
</refsect1>
</refentry>
<refentry id="function.posix-ttyname">
<refnamediv>
<refname>posix_ttyname</refname>
<refpurpose>Determine terminal device name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>posix_ttyname</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written.</para>
</refsect1>
</refentry>
<refentry id="function.posix-isatty">
<refnamediv>
<refname>posix_isatty</refname>
<refpurpose>
Determine if a file descriptor is an interactive terminal
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>posix_isatty</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getcwd">
<refnamediv>
<refname>posix_getcwd</refname>
<refpurpose>Pathname of current directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>posix_getcwd</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written ASAP.</para>
</refsect1>
</refentry>
<refentry id="function.posix-mkfifo">
<refnamediv>
<refname>posix_mkfifo</refname>
<refpurpose>
Create a fifo special file (a named pipe)
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>posix_getcwd</function></funcdef>
<paramdef>string <parameter>pathname</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written ASAP..</para>
</refsect1>
</refentry>
<refentry id="function.posix-getgrnam">
<refnamediv>
<refname>posix_getgrnam</refname>
<refpurpose>Return info about a group by name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_getgrnam</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getgrgid">
<refnamediv>
<refname>posix_getgrgid</refname>
<refpurpose>Return info about a group by group id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_getgrgid</function></funcdef>
<paramdef>int <parameter>gid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written.</para>
</refsect1>
</refentry>
<refentry id="function.posix-getpwnam">
<refnamediv>
<refname>posix_getpwnam</refname>
<refpurpose>Return info about a user by username</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_getpwnam</function></funcdef>
<paramdef>string <parameter>username</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array containing information about a
user referenced by an alphanumeric username, passed in the
<parameter>username</parameter> parameter.
</para>
<para>
The array elements returned are:
<table>
<title>The user information array</title>
<tgroup cols="2">
<thead>
<row>
<entry>Element</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>name</entry>
<entry>
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
<parameter>username</parameter> parameter used when calling the
function, and hence redundant.
</entry>
</row>
<row>
<entry>passwd</entry>
<entry>
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.
</entry>
</row>
<row>
<entry>uid</entry>
<entry>
User ID of the user in numeric form.
</entry>
</row>
<row>
<entry>gid</entry>
<entry>
The group ID of the user. Use the function
<function>posix_getgrgid</function> to resolve the
group name and a list of its members.
</entry>
</row>
<row>
<entry>gecos</entry>
<entry>
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.
</entry>
</row>
<row>
<entry>dir</entry>
<entry>
This element contains the absolute path to the
home directory of the user.
</entry>
</row>
<row>
<entry>shell</entry>
<entry>
The shell element contains the absolute path to the executable of
the user's default shell.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</refsect1>
</refentry>
<refentry id="function.posix-getpwuid">
<refnamediv>
<refname>posix_getpwuid</refname>
<refpurpose>Return info about a user by user id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_getpwuid</function></funcdef>
<paramdef>int <parameter>uid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array containing information about a
user referenced by a numeric user ID, passed in the
<parameter>uid</parameter> parameter.
</para>
<para>
The array elements returned are:
<table>
<title>The user information array</title>
<tgroup cols="2">
<thead>
<row>
<entry>Element</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>name</entry>
<entry>
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.
</entry>
</row>
<row>
<entry>passwd</entry>
<entry>
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.
</entry>
</row>
<row>
<entry>uid</entry>
<entry>
User ID, should be the same as the <parameter>uid</parameter>
parameter used when calling the function, and hence redundant.
</entry>
</row>
<row>
<entry>gid</entry>
<entry>
The group ID of the user. Use the function
<function>posix_getgrgid</function> to resolve the
group name and a list of its members.
</entry>
</row>
<row>
<entry>gecos</entry>
<entry>
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.
</entry>
</row>
<row>
<entry>dir</entry>
<entry>
This element contains the absolute path to the
home directory of the user.
</entry>
</row>
<row>
<entry>shell</entry>
<entry>
The shell element contains the absolute path to the executable of
the user's default shell.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</refsect1>
</refentry>
<refentry id="function.posix-getrlimit">
<refnamediv>
<refname>posix_getrlimit</refname>
<refpurpose>Return info about system ressource limits</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>posix_getrlimit</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Needs to be written ASAP.</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/pspell.xml
+++ phpdoc/nl/functions/pspell.xml
<reference id="ref.pspell">
<title>Pspell Functions</title>
<titleabbrev>Pspell</titleabbrev>
<partintro>
<simpara>
These functions allow you to check the spelling of a word and offer
suggestions.
</simpara>
<simpara>
You need the aspell and pspell libraries, available from <ulink
url="&url.aspell;">&url.aspell;</ulink> and
<ulink url="&url.pspell;">&url.pspell;</ulink> respectively, and
add the <option role="configure">--with-pspell[=dir]</option> option
when compiling php.
</simpara>
</partintro>
<refentry id="function.pspell-add-to-personal">
<refnamediv>
<refname>pspell_add_to_personal</refname>
<refpurpose>Add the word to a personal wordlist.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_add_to_personal</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>word</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_add_to_personal</function> adds a word to the personal
wordlist. If you used <function>pspell_new_config</function> with
<function>pspell_config_personal</function> to open the dictionary,
you can save the wordlist later with
<function>pspell_save_wordlist</function>. Please, note that this function
will not work unless you have pspell .11.2 and aspell .32.5 or later.
</simpara>
<para>
<example>
<title><function>Pspell_add_to_personal</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config ($pspell_config);
pspell_add_to_personal ($pspell_link, "Vlad");
pspell_save_wordlist ($pspell_link);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-add-to-session">
<refnamediv>
<refname>pspell_add_to_session</refname>
<refpurpose>Add the word to the wordlist in the current session.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_add_to_session</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>word</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_add_to_session</function> adds a word to the wordlist
associated with the current session. It is very similar to
<function>pspell_add_to_personal</function>
</simpara>
</refsect1>
</refentry>
<refentry id="function.pspell-check">
<refnamediv>
<refname>pspell_check</refname>
<refpurpose>Check a word</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>pspell_check</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>word</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_check</function> checks the spelling of a word
and returns true if the spelling is correct, false if not.
</simpara>
<para>
<example>
<title><function>Pspell_check</function></title>
<programlisting role="php">
$pspell_link = pspell_new ("en");
if (pspell_check ($pspell_link, "testt")) {
echo "This is a valid spelling";
} else {
echo "Sorry, wrong spelling";
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-clear-session">
<refnamediv>
<refname>pspell_clear_session</refname>
<refpurpose>Clear the current session.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_clear_session</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_clear_session</function> clears the current session.
The current wordlist becomes blank, and, for example, if you try to save
it with <function>pspell_save_wordlist</function>, nothing happens.
</simpara>
<para>
<example>
<title><function>Pspell_add_to_personal</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config ($pspell_config);
pspell_add_to_personal ($pspell_link, "Vlad");
pspell_clear_session ($pspell_link);
pspell_save_wordlist ($pspell_link); //"Vlad" will not be saved
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-config-create">
<refnamediv>
<refname>pspell_config_create</refname>
<refpurpose>Create a config used to open a dictionary.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_config_create</function></funcdef>
<paramdef>string <parameter>language</parameter></paramdef>
<paramdef>string
<parameter>
<optional>spelling</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>jargon</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>encoding</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_config_create</function> has a very similar syntax to
<function>pspell_new</function>. In fact, using
<function>pspell_config_create</function> immediatelly followed by
<function>pspell_new_config</function> will produce the exact same result.
However, after creating a new config, you can also use
<function>pspell_config_*</function> functions before calling
<function>pspell_new_config</function> to take advantage of some
advanced functionality.
</simpara>
<para>
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.
</para>
<para>
The spelling parameter is the requested spelling for languages
with more than one spelling such as English. Known values are
'american', 'british', and 'canadian'.
</para>
<para>
The jargon parameter contains extra information to distinguish
two different words lists that have the same language and
spelling parameters.
</para>
<para>
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.
</para>
<para>
The mode parameter is the mode in which spellchecker will work.
There are several modes available:
<itemizedlist>
<listitem>
<simpara>
PSPELL_FAST - Fast mode (least number of suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_NORMAL - Normal mode (more suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
For more information and examples, check out inline manual pspell
website:<ulink url="&url.pspell;">&url.pspell;</ulink>.
</para>
<para>
<example>
<title><function>Pspell_config_create</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_personal (pspell_config);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-config-ignore">
<refnamediv>
<refname>pspell_config_ignore</refname>
<refpurpose>Ignore words less than N characters long.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_config_ignore</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>int <parameter>n</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_config_ignore</function> should be used on a config
before calling <function>pspell_new_config</function>. This function
allows short words to be skipped by the spellchecker. Words less then
n characters will be skipped.
</simpara>
<para>
<example>
<title><function>Pspell_config_ignore</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_ignore($pspell_config, 5);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "abcd"); //will not result in an error
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-config-mode">
<refnamediv>
<refname>pspell_config_mode</refname>
<refpurpose>Change the mode number of suggestions returned.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_config_mode</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_config_mode</function> should be used on a config
before calling <function>pspell_new_config</function>. This function
determines how many suggestions will be returned by
<function>pspell_suggest</function>.
</simpara>
<para>
The mode parameter is the mode in which spellchecker will work.
There are several modes available:
<itemizedlist>
<listitem>
<simpara>
PSPELL_FAST - Fast mode (least number of suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_NORMAL - Normal mode (more suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title><function>Pspell_config_mode</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_mode($pspell_config, PSPELL_FAST);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-config-personal">
<refnamediv>
<refname>pspell_config_personal</refname>
<refpurpose>Set a file that contains personal wordlist.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_config_personal</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>file</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_config_personal</function> should be used on a config
before calling <function>pspell_new_config</function>. The personal
wordlist will be loaded and used in addition to the standard one after
you call <function>pspell_new_config</function>. If the file does not
exist, it will be created. The file is also the file where
<function>pspell_save_wordlist</function> 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.
</simpara>
<para>
<example>
<title><function>Pspell_config_personal</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config ($pspell_config);
pspell_check ($pspell_link, "thecat");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-config-repl">
<refnamediv>
<refname>pspell_config_repl</refname>
<refpurpose>Set a file that contains replacement pairs.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_config_repl</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>file</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_config_repl</function> should be used on a config
before calling <function>pspell_new_config</function>. The replacement
pairs improve the quality of the spellchecker. When a word is misspelled,
and a proper suggestion was not found in the list,
<function>pspell_store_replacement</function> can be used to store a
replacement pair and then <function>pspell_save_wordlist</function> 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.
</simpara>
<para>
<example>
<title><function>Pspell_config_repl</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config ($pspell_config);
pspell_check ($pspell_link, "thecat");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-config-runtogether">
<refnamediv>
<refname>pspell_config_runtogether</refname>
<refpurpose>Consider run-together words as valid compounds.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_config_runtogether</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>boolean <parameter>flag</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_config_runtogether</function> should be used on a config
before calling <function>pspell_new_config</function>. This function
determines whether run-together words will be treated as legal
compounds. That is, "thecat" will be a legal compound,
athough there should be a space between the two
words. Changing this setting only affects the results returned
by <function>pspell_check</function>;
<function>pspell_suggest</function> will still return suggestions.
</simpara>
<para>
<example>
<title><function>Pspell_config_runtogether</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_runtogether ($pspell_config, true);
$pspell_link = pspell_new_config ($pspell_config);
pspell_check ($pspell_link, "thecat");
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-config-save-repl">
<refnamediv>
<refname>pspell_config_save_repl</refname>
<refpurpose>Determine whether to save a replacement pairs list
along with the wordlist.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_config_save_repl</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>boolean <parameter>flag</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_config_save_repl</function> should be used on a config
before calling <function>pspell_new_config</function>. It determines
whether <function>pspell_save_wordlist</function> will save the
replacement pairs along with the wordlist. Usually there is no need to use
this function because if <function>pspell_config_repl</function> is used,
the replacement pairs will be saved by
<function>pspell_save_wordlist</function> 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.
</simpara>
</refsect1>
</refentry>
<refentry id="function.pspell-new">
<refnamediv>
<refname>pspell_new</refname>
<refpurpose>Load a new dictionary</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_new</function></funcdef>
<paramdef>string <parameter>language</parameter></paramdef>
<paramdef>string
<parameter>
<optional>spelling</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>jargon</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>encoding</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>mode</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_new</function> opens up a new dictionary and
returns the dictionary link identifier for use in other pspell
functions.
</simpara>
<para>
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.
</para>
<para>
The spelling parameter is the requested spelling for languages
with more than one spelling such as English. Known values are
'american', 'british', and 'canadian'.
</para>
<para>
The jargon parameter contains extra information to distinguish
two different words lists that have the same language and
spelling parameters.
</para>
<para>
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.
</para>
<para>
The mode parameter is the mode in which spellchecker will work.
There are several modes available:
<itemizedlist>
<listitem>
<simpara>
PSPELL_FAST - Fast mode (least number of suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_NORMAL - Normal mode (more suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_RUN_TOGETHER - Consider run-together words as legal
compounds. That is, "thecat" will be a legal compound,
athough there should be a space between the two
words. Changing this setting only affects the results returned
by <function>pspell_check</function>;
<function>pspell_suggest</function> will still return
suggestions.
</simpara>
</listitem>
</itemizedlist>
Mode is a bitmask constructed from different constants listed
above. However, PSPELL_FAST, PSPELL_NORMAL and
PSPELL_BAD_SPELLERS are mutually exclusive, so you should select
only one of them.
</para>
<para>
For more information and examples, check out inline manual pspell
website:<ulink url="&url.pspell;">&url.pspell;</ulink>.
</para>
<para>
<example>
<title><function>Pspell_new</function></title>
<programlisting role="php">
$pspell_link = pspell_new ("en", "", "", "",
(PSPELL_FAST|PSPELL_RUN_TOGETHER));
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-new-config">
<refnamediv>
<refname>pspell_new_config</refname>
<refpurpose>Load a new dictionary with settings based on a given config
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_new_config</function></funcdef>
<paramdef>int <parameter>config</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_new_config</function> opens up a new dictionary with
settings specified in a config, created with with
<function>pspell_config_create</function> and modified with
<function>pspell_config_*</function> functions. This method provides you
with the most flexibility and has all the functionality provided by
<function>pspell_new</function> and
<function>pspell_new_personal</function>.
</simpara>
<para>
The config parameter is the one returned by
<function>pspell_config_create</function> when the config was created.
</para>
<para>
<example>
<title><function>Pspell_new_config</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_personal (pspell_config);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-new-personal">
<refnamediv>
<refname>pspell_new_personal</refname>
<refpurpose>Load a new dictionary with personal wordlist</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_new_personal</function></funcdef>
<paramdef>string <parameter>personal</parameter></paramdef>
<paramdef>string <parameter>language</parameter></paramdef>
<paramdef>string
<parameter>
<optional>spelling</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>jargon</optional>
</parameter>
</paramdef>
<paramdef>string
<parameter>
<optional>encoding</optional>
</parameter>
</paramdef>
<paramdef>int
<parameter>
<optional>mode</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_new_personal</function> 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
<function>pspell_save_wordlist</function>, if desired. However, the
replacement pairs are not saved. In order to save replacement pairs, you
should create a config using <function>pspell_config_create</function>,
set the personal wordlist file with <function>pspell_config_personal
</function>, set the file for replacement pairs with
<function>pspell_config_repl</function>, and open a new dictionary with
<function>pspell_new_config</function>.
</simpara>
<para>
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.
</para>
<para>
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.
</para>
<para>
The spelling parameter is the requested spelling for languages
with more than one spelling such as English. Known values are
'american', 'british', and 'canadian'.
</para>
<para>
The jargon parameter contains extra information to distinguish
two different words lists that have the same language and
spelling parameters.
</para>
<para>
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.
</para>
<para>
The mode parameter is the mode in which spellchecker will work.
There are several modes available:
<itemizedlist>
<listitem>
<simpara>
PSPELL_FAST - Fast mode (least number of suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_NORMAL - Normal mode (more suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_BAD_SPELLERS - Slow mode (a lot of suggestions)
</simpara>
</listitem>
<listitem>
<simpara>
PSPELL_RUN_TOGETHER - Consider run-together words as legal
compounds. That is, "thecat" will be a legal compound,
athough there should be a space between the two
words. Changing this setting only affects the results returned
by <function>pspell_check</function>;
<function>pspell_suggest</function> will still return
suggestions.
</simpara>
</listitem>
</itemizedlist>
Mode is a bitmask constructed from different constants listed
above. However, PSPELL_FAST, PSPELL_NORMAL and
PSPELL_BAD_SPELLERS are mutually exclusive, so you should select
only one of them.
</para>
<para>
For more information and examples, check out inline manual pspell
website:<ulink url="&url.pspell;">&url.pspell;</ulink>.
</para>
<para>
<example>
<title><function>Pspell_new_personal</function></title>
<programlisting role="php">
$pspell_link = pspell_new_personal ("/var/dictionaries/custom.pws",
"en", "", "", "", PSPELL_FAST|PSPELL_RUN_TOGETHER));
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-save-wordlist">
<refnamediv>
<refname>pspell_save_wordlist</refname>
<refpurpose>Save the personal wordlist to a file.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_save_wordlist</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_save_wordlist</function> saves the personal wordlist
from the current session. The dictionary has to be open with
<function>pspell_new_personal</function>, and the location of files to be
saved specified with <function>pspell_config_personal</function> and
(optionally) <function>pspell_config_repl</function>. Please, note that
this function will not work unless you have pspell .11.2 and aspell .32.5
or later.
</simpara>
<para>
<example>
<title><function>Pspell_add_to_personal</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/tmp/dicts/newdict");
$pspell_link = pspell_new_config ($pspell_config);
pspell_add_to_personal ($pspell_link, "Vlad");
pspell_save_wordlist ($pspell_link);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-store-replacement">
<refnamediv>
<refname>pspell_store_replacement</refname>
<refpurpose>Store a replacement pair for a word</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>pspell_store_replacement</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>misspelled</parameter></paramdef>
<paramdef>string <parameter>correct</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_store_replacement</function> stores a replacement pair for
a word, so that replacement can be returned by
<function>pspell_suggest</function> later. In order to be able to take
advantage of this function, you have to use
<function>pspell_new_personal</function> to open the dictionary. In order
to permanently save the replacement pair, you have to
use <function>pspell_config_personal</function> and
<function>pspell_config_repl</function> to set the path where to save your
custom wordlists, and then use <function>pspell_save_wordlist</function>
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.
</simpara>
<para>
<example>
<title><function>Pspell_store_replacement</function></title>
<programlisting role="php">
$pspell_config = pspell_config_create ("en");
pspell_config_personal ($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl ($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config ($pspell_config);
pspell_store_replacement ($pspell_link, $misspelled, $correct);
pspell_save_wordlist ($pspell_link);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.pspell-suggest">
<refnamediv>
<refname>pspell_suggest</refname>
<refpurpose>Suggest spellings of a word</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>pspell_suggest</function></funcdef>
<paramdef>int <parameter>dictionary_link</parameter></paramdef>
<paramdef>string <parameter>word</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Pspell_suggest</function> returns an array of possible
spellings for the given word.
</simpara>
<para>
<example>
<title><function>Pspell_suggest</function></title>
<programlisting role="php">
$pspell_link = pspell_new ("en");
if (!pspell_check ($pspell_link, "testt")) {
$suggestions = pspell_suggest ($pspell_link, "testt");
for ($i=0; $i < count ($suggestions); $i++) {
echo "Possible spelling: " . $suggestions[$i] . "<br>";
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/readline.xml
+++ phpdoc/nl/functions/readline.xml
<reference id="ref.readline">
<title>GNU Readline</title>
<titleabbrev>Readline</titleabbrev>
<partintro>
<simpara>
The <function>readline</function> 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 to be run from a
shell.
</simpara>
<simpara>
The home page of the GNU Readline project is
<ulink url="&url.readline;">&url.readline;</ulink>. It's
maintained
by Chet Ramey, who's also the author of Bash.
</simpara>
</partintro>
<refentry id="function.readline">
<refnamediv>
<refname>readline</refname>
<refpurpose>Reads a line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>readline</function></funcdef>
<paramdef>string
<parameter><optional>prompt</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
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
<function>readline_add_history</function>.
</para>
<example>
<title><function>Readline</function></title>
<programlisting role="php">
//get 3 commands from user
for ($i=0; $i < 3; $i++) {
$line = readline ("Command: ");
readline_add_history ($line);
}
//dump history
print_r (readline_list_history());
//dump variables
print_r (readline_info());
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.readline-add-history">
<refnamediv>
<refname>readline_add_history</refname>
<refpurpose>Adds a line to the history</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>readline_add_history</function></funcdef>
<paramdef>string <parameter>line</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function adds a line to the command line history.
</para>
</refsect1>
</refentry>
<refentry id="function.readline-clear-history">
<refnamediv>
<refname>readline_clear_history</refname>
<refpurpose>Clears the history</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>readline_clear_history</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function clears the entire command line history.
</para>
</refsect1>
</refentry>
<refentry id="function.readline-completion-function">
<refnamediv>
<refname>readline_completion_function</refname>
<refpurpose>Registers a completion function</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean
<function>readline_completion_function</function>
</funcdef>
<paramdef>string <parameter>line</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.readline-info">
<refnamediv>
<refname>readline_info</refname>
<refpurpose>Gets/sets various internal readline variables</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>readline_info</function></funcdef>
<paramdef>string
<parameter><optional>varname</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>newvalue</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
If called with no parameters, this function returns an array of
values for all the setting readline uses. The elements will 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.
</para>
<para>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.readline-list-history">
<refnamediv>
<refname>readline_list_history</refname>
<refpurpose>Lists the history</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>readline_list_history</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an array of the entire command line
history. The elements are indexed by integers starting at zero.
</para>
</refsect1>
</refentry>
<refentry id="function.readline-read-history">
<refnamediv>
<refname>readline_read_history</refname>
<refpurpose>Reads the history</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean
<function>readline_read_history</function>
</funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function reads a command history from a file.
</para>
</refsect1>
</refentry>
<refentry id="function.readline-write-history">
<refnamediv>
<refname>readline_write_history</refname>
<refpurpose>Writes the history</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean
<function>readline_write_history</function>
</funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function writes the command history to a file.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/recode.xml
+++ phpdoc/nl/functions/recode.xml
<reference id="ref.recode">
<title>GNU Recode functions</title>
<titleabbrev>Recode</titleabbrev>
<partintro>
<para>
This module contains an interface to the GNU Recode library,
version 3.5. To be able to use the functions defined in this
module you must compile you PHP interpreter using the --with-recode
option. In order to do so, you must have GNU Recode 3.5 or higher
installed on your system.
</para>
<para>
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.
</para>
</partintro>
<refentry id="function.recode-string">
<refnamediv>
<refname>recode_string</refname>
<refpurpose>Recode a string according to a recode request</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>recode_string</function></funcdef>
<paramdef>string <parameter>request</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Recode the string <parameter>string</parameter> according to
the recode request <parameter>request</parameter>. Returns
FALSE, if unable to comply, TRUE otherwise.
</para>
<para>
A simple recode request may be "lat1..iso646-de".
See also the GNU Recode documentation of your installation
for detailed instructions about recode requests.
</para>
</refsect1>
</refentry>
<refentry id="function.recode">
<refnamediv>
<refname>recode</refname>
<refpurpose>Recode a string according to a recode request</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>recode_string</function></funcdef>
<paramdef>string <parameter>request</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<note>
<simpara>
This is an alias for <function>recode_string</function>. It has
been added in PHP 4.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.recode-file">
<refnamediv>
<refname>recode_file</refname>
<refpurpose>
Recode from file to file according to recode request
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>recode_file</function></funcdef>
<paramdef>int <parameter>input</parameter></paramdef>
<paramdef>int <parameter>output</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Recode the file referenced by file handle
<parameter>input</parameter> into the file referenced by file
handle <parameter>output</parameter> according to the recode
request. Returns FALSE, if unable to comply, TRUE
otherwise.
</para>
<para>
This function does not currently process filehandles referencing
remote files (URLs). Both filehandles must refer to local files.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/regex.xml
+++ phpdoc/nl/functions/regex.xml
<reference id="ref.regex">
<title>Regular Expression Functions (POSIX Extended)</title>
<titleabbrev>Regexps</titleabbrev>
<partintro>
<para>
Regular expressions are used for complex string manipulation in
PHP. The functions that support regular expressions are:
<itemizedlist>
<listitem>
<simpara><function>ereg</function></simpara>
</listitem>
<listitem>
<simpara><function>ereg_replace</function></simpara>
</listitem>
<listitem>
<simpara><function>eregi</function></simpara>
</listitem>
<listitem>
<simpara><function>eregi_replace</function></simpara>
</listitem>
<listitem>
<simpara><function>split</function></simpara>
</listitem>
<listitem>
<simpara><function>spliti</function></simpara>
</listitem>
</itemizedlist>
These functions all take a regular expression string as their
first argument. PHP uses the POSIX extended regular expressions
as defined by POSIX 1003.2. For a full description of POSIX
regular expressions see the regex man pages included in the regex
directory in the PHP distribution. It's in manpage format, so
you'll want to do something along the lines of <command>man
/usr/local/src/regex/regex.7</command> in order to read it.
<!-- Should add discussion of PCRE functions here. -->
</para>
<para>
<example>
<title>Regular Expression Examples</title>
<programlisting role="php">
ereg ("abc", $string);
/* Returns true if "abc"
is found anywhere in $string. */
ereg ("^abc", $string);
/* Returns true if "abc"
is found at the beginning of $string. */
ereg ("abc$", $string);
/* Returns true if "abc"
is found at the end of $string. */
eregi ("(ozilla.[23]|MSIE.3)", $HTTP_USER_AGENT);
/* Returns true if client browser
is Netscape 2, 3 or MSIE 3. */
ereg ("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)", $string,$regs);
/* Places three space separated words
into $regs[1], $regs[2] and $regs[3]. */
$string = ereg_replace ("^", "<BR>", $string);
/* Put a <BR> tag at the beginning of $string. */
$string = ereg_replace ("$", "<BR>", $string);
/* Put a <BR> tag at the end of $string. */
$string = ereg_replace ("\n", "", $string);
/* Get rid of any newline
characters in $string. */
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.ereg">
<refnamediv>
<refname>ereg</refname>
<refpurpose>Regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ereg</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>array
<parameter><optional>regs</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Searches a <parameter>string</parameter> for matches to the regular
expression given in <parameter>pattern</parameter>.
</simpara>
<simpara>
If matches are found for parenthesized substrings of
<parameter>pattern</parameter> and the function is called with
the third argument <parameter>regs</parameter>, the matches will
be stored in the elements of the array
<parameter>regs</parameter>. $regs[1] will contain the substring
which starts at the first left parenthesis; $regs[2] will contain
the substring starting at the second, and so on. $regs[0] will
contain a copy of <parameter>string</parameter>.
</simpara>
<simpara>
If <function>ereg</function> finds any matches at all, $regs will
be filled with exactly ten elements, even though more or fewer
than ten parenthesized substrings may actually have matched.
This has no effect on <function>ereg</function>'s ability to
match more substrings. If no matches are found, $regs will not be
altered by <function>ereg</function>.
</simpara>
<simpara>
Searching is case sensitive.
</simpara>
<simpara>
Returns true if a match for <parameter>pattern</parameter> was
found in <parameter>string</parameter>, or false if no matches
were found or an error occurred.
</simpara>
<para>
The following code snippet takes a date in ISO format
(YYYY-MM-DD) and prints it in DD.MM.YYYY format:
<example>
<title><function>Ereg</function> Example</title>
<programlisting role="php">
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";
} else {
echo "Invalid date format: $date";
}
</programlisting>
</example>
</para>
<simpara>
See also <function>eregi</function>,
<function>ereg_replace</function>, and
<function>eregi_replace</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.ereg-replace">
<refnamediv>
<refname>ereg_replace</refname>
<refpurpose>Replace regular expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ereg_replace</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>replacement</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function scans <parameter>string</parameter> for matches to
<parameter>pattern</parameter>, then replaces the matched text
with <parameter>replacement</parameter>.
</simpara>
<simpara>
The modified string is returned. (Which may mean that the
original string is returned if there are no matches to be
replaced.)
</simpara>
<simpara>
If <parameter>pattern</parameter> contains parenthesized
substrings, <parameter>replacement</parameter> may contain
substrings of the form
<literal>\\<replaceable>digit</replaceable></literal>, which will
be replaced by the text matching the digit'th parenthesized
substring; <literal>\\0</literal> will produce the entire
contents of string. Up to nine substrings may be used.
Parentheses may be nested, in which case they are counted by the
opening parenthesis.
</simpara>
<simpara>
If no matches are found in <parameter>string</parameter>, then
<parameter>string</parameter> will be returned unchanged.
</simpara>
<para>
For example, the following code snippet prints "This was a test"
three times:
<example>
<title><function>Ereg_replace</function> Example</title>
<programlisting>
$string = "This is a test";
echo ereg_replace (" is", " was", $string);
echo ereg_replace ("( )is", "\\1was", $string);
echo ereg_replace ("(( )is)", "\\2was", $string);
</programlisting>
</example>
</para>
<para>
One thing to take note of is that if you use an integer value as
the <parameter>replacement</parameter> parameter, you may not get
the results you expect. This is because
<function>ereg_replace</function> will interpret the number as
the ordinal value of a character, and apply that. For instance:
<example>
<title><function>ereg_replace</function> Example</title>
<programlisting>
<?php
/* This will not work as expected. */
$num = 4;
$string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string; /* Output: 'This string has words.' */
/* This will work. */
$num = '4';
$string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string; /* Output: 'This string has 4 words.' */
?>
</programlisting>
</example>
</para>
<simpara>
See also <function>ereg</function>, <function>eregi</function>,
and <function>eregi_replace</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.eregi">
<refnamediv>
<refname>eregi</refname>
<refpurpose>case insensitive regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>eregi</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>array
<parameter><optional>regs</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is identical to <function>ereg</function> except
that this ignores case distinction when matching alphabetic
characters.
</para>
<para>
See also <function>ereg</function>,
<function>ereg_replace</function>, and
<function>eregi_replace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.eregi-replace">
<refnamediv>
<refname>eregi_replace</refname>
<refpurpose>replace regular expression case insensitive</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>eregi_replace</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>replacement</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is identical to <function>ereg_replace</function>
except that this ignores case distinction when matching
alphabetic characters.
</para>
<para>
See also <function>ereg</function>, <function>eregi</function>,
and <function>ereg_replace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.split">
<refnamediv>
<refname>split</refname>
<refpurpose>split string into array by regular expression</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>split</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter><optional>limit</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of strings, each of which is a substring of
<parameter>string</parameter> formed by splitting it on
boundaries formed by the regular expression
<parameter>pattern</parameter>. If <parameter>limit</parameter>
is set, the returned array will contain a maximum of
<parameter>limit</parameter> elements with the last element
containing the whole rest of <parameter>string</parameter>. If
an error occurs, <function>split</function> returns false.
</para>
<para>
To get the first five fields from a line from
<filename>/etc/passwd</filename>:
<example>
<title><function>Split</function> Example</title>
<programlisting role="php">
$passwd_list = split (":", $passwd_line, 5);
</programlisting>
</example>
</para>
<para>
To parse a date which may be delimited with slashes, dots, or
hyphens:
<example>
<title><function>Split</function> Example</title>
<programlisting role="php">
$date = "04/30/1973"; // Delimiters may be slash, dot, or hyphen
list ($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br>\n";
</programlisting>
</example>
</para>
<para>
Note that <parameter>pattern</parameter> is case-sensitive.
</para>
<para>
Note that if you don't require the power of regular expressions,
it is faster to use <function>explode</function>, which doesn't
incur the overhead of the regular expression engine.
</para>
<para>
For users looking for a way to emulate perl's <command>$chars =
split('', $str)</command> behaviour, please see the examples for
<function>preg_split</function>.
</para>
<para>
Please note that <parameter>pattern</parameter> is a regular
expression. If you want to split on any of the characters which
are considered special by regular expressions, you'll need to
escape them first. If you think <function>split</function> (or
any other regex function, for that matter) is doing something
weird, please read the file <filename>regex.7</filename>,
included in the <filename>regex/</filename> subdirectory of the
PHP distribution. It's in manpage format, so you'll want to do
something along the lines of <command>man
/usr/local/src/regex/regex.7</command> in order to read it.
</para>
<para>
See also: <function>spliti</function>,
<function>explode</function>, and <function>implode</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.spliti">
<refnamediv>
<refname>spliti</refname>
<refpurpose>
Split string into array by regular expression case insensitive
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>split</function></funcdef>
<paramdef>string <parameter>pattern</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter><optional>limit</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is identical to <function>split</function> except
that this ignores case distinction when matching alphabetic
characters.
</para>
<para>
See also: <function>split</function>,
<function>explode</function>, and <function>implode</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sql-regcase">
<refnamediv>
<refname>sql_regcase</refname>
<refpurpose>
Make regular expression for case insensitive match
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>sql_regcase</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a valid regular expression which will match
<parameter>string</parameter>, ignoring case. This expression is
<parameter>string</parameter> with each character converted to a
bracket expression; this bracket expression contains that
character's uppercase and lowercase form if applicable, otherwise
it contains the original character twice.
<example>
<title><function>Sql_regcase</function> Example</title>
<programlisting role="php">
echo sql_regcase ("Foo bar");
</programlisting>
</example>
prints <screen>[Ff][Oo][Oo][ ][Bb][Aa][Rr]</screen>.
</para>
<para>
This can be used to achieve case insensitive pattern matching in
products which support only case sensitive regular expressions.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/satellite.xml
+++ phpdoc/nl/functions/satellite.xml
<!--
$Id: satellite.xml,v 1.1 2000/10/10 22:07:53 derick Exp $
Author: David Eriksson <david@2good.com>
-->
<reference id="ref.satellite">
<title>Satellite CORBA client extension</title>
<titleabbrev>Satellite</titleabbrev>
<partintro>
<para>
The Satellite extension is used for accessing CORBA objects. You
will need to set the idl_directory= entry in php.ini to a path
where you store all IDL files you use.
</para>
</partintro>
<refentry id="class.orbitobject">
<refnamediv>
<refname>OrbitObject</refname>
<refpurpose>Access CORBA objects</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>new <function>OrbitObject</function></funcdef>
<paramdef>string <parameter>ior</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This class provides access to a CORBA object. The
<parameter>ior</parameter> parameter should be a string
containing the IOR (Interoperable Object Reference) that
identifies the remote object.
</para>
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
interface MyInterface {
void SetInfo (string info);
string GetInfo();
attribute int value;
}
</programlisting>
</example>
</para>
<para>
<example>
<title>PHP code for accessing MyInterface</title>
<programlisting role="php">
<?php
$obj = new OrbitObject ($ior);
$obj->SetInfo ("A 2GooD object");
echo $obj->GetInfo();
$obj->value = 42;
echo $obj->value;
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="class.orbitenum">
<refnamediv>
<refname>OrbitEnum</refname>
<refpurpose>Use CORBA enums</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>new <function>OrbitEnum</function></funcdef>
<paramdef>string <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This class represents the enumeration identified with the
<parameter>id</parameter> parameter. The
<parameter>id</parameter> can be either the name of the
enumeration (e.g "MyEnum"), or the full repository id
(e.g. "IDL:MyEnum:1.0").
</para>
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
enum MyEnum {
a,b,c,d,e
};
</programlisting>
</example>
</para>
<para>
<example>
<title>PHP code for accessing MyEnum</title>
<programlisting role="php">
<?php
$enum = new OrbitEnum ("MyEnum");
echo $enum->a; /* write 0 */
echo $enum->c; /* write 2 */
echo $enum->e; /* write 4 */
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="class.orbitstruct">
<refnamediv>
<refname>OrbitStruct</refname>
<refpurpose>Use CORBA structs</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>new <function>OrbitStruct</function></funcdef>
<paramdef>string <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This class represents the structure identified with the
<parameter>id</parameter> parameter. The
<parameter>id</parameter> can be either the name of the struct
(e.g "MyStruct"), or the full repository id
(e.g. "IDL:MyStruct:1.0").
</para>
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
struct MyStruct {
short shortvalue;
string stringvalue;
};
interface SomeInterface {
void SetValues (MyStruct values);
MyStruct GetValues();
}
</programlisting>
</example>
</para>
<para>
<example>
<title>PHP code for accessing MyStruct</title>
<programlisting role="php">
<?php
$obj = new OrbitObject ($ior);
$initial_values = new OrbitStruct ("IDL:MyStruct:1.0");
$initial_values->shortvalue = 42;
$initial_values->stringvalue = "HGTTG";
$obj->SetValues ($initial_values);
$values = $obj->GetValues();
echo $values->shortvalue;
echo $values->stringvalue;
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.satellite_caught_exception">
<refnamediv>
<refname>satellite_caught_exception</refname>
<refpurpose>
See if an exception was caught from the previous function
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool
<function>satellite_caught_exception</function>
</funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns true if an exception has been caught.
</para>
<para>
<example>
<title>Sample IDL file</title>
<programlisting>
/* ++?????++ Out of Cheese Error. Redo From Start. */
exception OutOfCheeseError {
int parameter;
}
interface AnotherInterface {
void AskWhy() raises (OutOfCheeseError);
}
</programlisting>
</example>
</para>
<para>
<example>
<title>PHP code for handling CORBA exceptions</title>
<programlisting role="php">
<?php
$obj = new OrbitObject ($ior);
$obj->AskWhy();
if (satellite_caught_exception()) {
if ("IDL:OutOfCheeseError:1.0" == satellite_exception_id()) {
$exception = satellite_exception_value();
echo $exception->parameter;
}
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.satellite_exception_id">
<refnamediv>
<refname>satellite_exception_id</refname>
<refpurpose>Get the repository id for the latest excetpion.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>satellite_exception_id</function></funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return a repository id string. (E.g. "IDL:MyException:1.0".) For
example usage see
<function>satellite_caught_exception</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.satellite_exception_value">
<refnamediv>
<refname>satellite_exception_value</refname>
<refpurpose>
Get the exception struct for the latest exception
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>OrbitStruct
<function>satellite_exception_value</function>
</funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Return an exception struct. For example usage see
<function>satellite_caught_exception</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/sem.xml
+++ phpdoc/nl/functions/sem.xml
<reference id="ref.sem">
<title>Semaphore and Shared Memory Functions</title>
<titleabbrev>Semaphore</titleabbrev>
<partintro>
<para>
This module provides semaphore functions using System V
semaphores. 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.
</para>
<para>
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.
<table>
<title>Limits of Shared Memory by the Unix OS</title>
<tgroup cols="2">
<tbody>
<row>
<entry>SHMMAX</entry>
<entry>max size of shared memory, normally 131072 bytes</entry>
</row>
<row>
<entry>SHMMIN</entry>
<entry>minimum size of shared memory, normally 1 byte</entry>
</row>
<row>
<entry>SHMMNI</entry>
<entry>max amount of shared memory segments, normally 100</entry>
</row>
<row>
<entry>SHMSEG</entry>
<entry>max amount of shared memory per process, normally 6</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<note>
<simpara>
These functions do not work on Windows systems.
</simpara>
</note>
</partintro>
<refentry id="function.sem-get">
<refnamediv>
<refname>sem_get</refname>
<refpurpose>Get a semaphore id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sem_get</function></funcdef>
<paramdef>int <parameter>key</parameter></paramdef>
<paramdef>int
<parameter><optional>max_acquire</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>perm</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive semaphore identifier on success, or false on
error.
</para>
<para>
<function>Sem_get</function> 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.
</para>
<para>
A second call to <function>sem_get</function> for the same key
will return a different semaphore identifier, but both
identifiers access the same underlying semaphore.
</para>
<para>
See also: <function>sem_acquire</function> and
<function>sem_release</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.sem-acquire">
<refnamediv>
<refname>sem_acquire</refname>
<refpurpose>Acquire a semaphore</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sem_acquire</function></funcdef>
<paramdef>int <parameter>sem_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on error.
</para>
<para>
<function>Sem_acquire</function> 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 max_acquire value to
be exceeded.
</para>
<para>
After processing a request, any semaphores acquired by the
process but not explicitly released will be released automatically
and a warning will be generated.
</para>
<para>
See also: <function>sem_get</function> and
<function>sem_release</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sem-release">
<refnamediv>
<refname>sem_release</refname>
<refpurpose>Release a semaphore</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sem_release</function></funcdef>
<paramdef>int <parameter>sem_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: true on success, false on error.
</para>
<para>
<function>Sem_release</function> releases the semaphore if it
is currently acquired by the calling process, otherwise
a warning is generated.
</para>
<para>
After releasing the semaphore, <function>sem_acquire</function>
may be called to re-acquire it.
</para>
<para>
See also: <function>sem_get</function> and
<function>sem_acquire</function>.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.shm-attach">
<refnamediv>
<refname>shm_attach</refname>
<refpurpose>Creates or open a shared memory segment</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_attach</function></funcdef>
<paramdef>int <parameter>key</parameter></paramdef>
<paramdef>int
<parameter><optional>memsize</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>perm</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Shm_attach</function> 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 mem_size
(default: sysvshm.init_mem in the <link
linkend="configuration.file">configuration file</link>, otherwise
10000 bytes) and the optional perm-bits (default: 0666).
</para>
<para>
A second call to <function>shm_attach</function> for the same
<parameter>key</parameter> will return a different shared memory
identifier, but both identifiers access the same underlying
shared memory. <parameter>Memsize</parameter> and
<parameter>perm</parameter> will be ignored.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.shm-detach">
<refnamediv>
<refname>shm_detach</refname>
<refpurpose>Disconnects from shared memory segment</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_detach</function></funcdef>
<paramdef>int <parameter>shm_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Shm_detach</function> disconnects from the shared
memory given by the <parameter>shm_identifier</parameter> created
by <function>shm_attach</function>. Remember, that shared memory
still exist in the Unix system and the data is still present.
</para>
</refsect1>
</refentry>
<refentry id="function.shm-remove">
<refnamediv>
<refname>shm_remove</refname>
<refpurpose>Removes shared memory from Unix systems</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_remove</function></funcdef>
<paramdef>int <parameter>shm_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Removes shared memory from Unix systems. All data will be
destroyed.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.shm-put-var">
<refnamediv>
<refname>shm_put_var</refname>
<refpurpose>Inserts or updates a variable in shared
memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_put_var</function></funcdef>
<paramdef>int <parameter>shm_identifier</parameter></paramdef>
<paramdef>int <parameter>variable_key</parameter></paramdef>
<paramdef>mixed <parameter>variable</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Inserts or updates a <parameter>variable</parameter> with a given
<parameter>variable_key</parameter>. All variable-types (double,
int, string, array) are supported.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.shm-get-var">
<refnamediv>
<refname>shm_get_var</refname>
<refpurpose>Returns a variable from shared memory
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>shm_get_var</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>int <parameter>variable_key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Shm_get_var</function> returns the variable with a given
<parameter>variable_key</parameter>. The variable is still present
in the shared memory.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.shm-remove-var">
<refnamediv>
<refname>shm_remove_var</refname>
<refpurpose>Removes a variable from shared memory
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_remove_var</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>int <parameter>variable_key</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Removes a variable with a given <parameter>variable_key</parameter>
and frees the occupied memory.
</para>
<note>
<simpara>
This function does not work on Windows systems
</simpara>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/session.xml
+++ phpdoc/nl/functions/session.xml
<reference id="ref.session">
<title>Session handling functions</title>
<titleabbrev>Sessions</titleabbrev>
<partintro>
<para>
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.
</para>
<para>
If you are familiar with the session management of PHPLIB, you
will notice that some concepts are similar to PHP's session
support.
</para>
<para>
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.
</para>
<para>
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
<function>session_start</function> or implicitly through
<function>session_register</function>) whether a specific session
id has been sent with the request. If this is the case, the prior
saved environment is recreated.
</para>
<para>
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.
</para>
<para>
The <link
linkend="ini.track-vars"><literal>track_vars</literal></link> and
<link
linkend="ini.register-globals"><literal>register_globals</literal></link>
configuration settings influence how the session variables get
stored and restored.
</para>
<note>
<para>
As of PHP 4.0.3, <link
linkend="ini.track-vars"><literal>track_vars</literal></link> is
always turned on.
</para>
</note>
<para>
If <link
linkend="ini.track-vars"><literal>track_vars</literal></link> is
enabled and <link
linkend="ini.register-globals"><literal>register_globals</literal></link>
is disabled, only members of the global associative array
$HTTP_SESSION_VARS can be registered as session variables. The
restored session variables will only be available in the array
$HTTP_SESSION_VARS.
<example>
<title>
Registering a variable with <link
linkend="ini.track-vars"><literal>track_vars</literal></link>
enabled
</title>
<programlisting role="php">
<?php
session_register("count");
$HTTP_SESSION_VARS["count"]++;
?>
</programlisting>
</example>
</para>
<para>
If <link
linkend="ini.register-globals"><literal>register_globals</literal></link>
is enabled, then all global variables can be registered as session
variables and the session variables will be restored to
corresponding global variables.
<example>
<title>
Registering a variable with <link
linkend="ini.register-globals"><literal>register_globals</literal></link>
enabled
</title>
<programlisting role="php">
<?php
session_register("count");
$count++;
?>
</programlisting>
</example>
</para>
<para>
If both <link
linkend="ini.track-vars"><literal>track_vars</literal></link> and
<link
linkend="ini.register-globals"><literal>register_globals</literal></link>
are enabled, then the globals variables and the $HTTP_SESSION_VARS
entries will reference the same value.
</para>
<para>
There are two methods to propagate a session id:
<itemizedlist>
<listitem>
<simpara>
Cookies
</simpara>
</listitem>
<listitem>
<simpara>
URL parameter
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
The session module supports both methods. Cookies are optimal, but
since they are not reliable (clients are not bound to accept
them), we cannot rely on them. The second method embeds the
session id directly into URLs.
</para>
<para>
PHP is capable of doing this transparently when compiled with
<literal>--enable-trans-sid</literal>. If you enable this option,
relative URIs will be changed to contain the session id
automatically. Alternatively, you can use the constant
<literal>SID</literal> which is defined, if the client did not
send the appropriate cookie. <literal>SID</literal> is either of
the form <literal>session_name=session_id</literal> or is an empty
string.
</para>
<para>
The following example demonstrates how to register a variable, and
how to link correctly to another page using SID.
<example>
<title>Counting the number of hits of a single user</title>
<programlisting role="php">
<?php
session_register ("count");
$count++;
?>
Hello visitor, you have seen this page <? echo $count; ?> times.<p>
<php?
# the <?=SID?> is necessary to preserve the session id
# in the case that the user has disabled cookies
?>
To continue, <A HREF="nextpage.php?<?=SID?>">click
here</A>
</programlisting>
</example>
</para>
<para>
The <literal><?=SID?></literal> is not necessary, if
<literal>--enable-trans-sid</literal> was used to compile PHP.
</para>
<para>
To implement database storage, or any other storage method, you
will need to use <function>session_set_save_handler</function> to
create a set of user-level storage functions.
</para>
<para>
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.
<itemizedlist>
<listitem>
<simpara>
<literal>session.save_handler</literal> defines the name of the
handler which is used for storing and retrieving data
associated with a session. Defaults to
<literal>files</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.save_path</literal> 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 <literal>/tmp</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.name</literal> specifies the name of the
session which is used as cookie name. It should only contain
alphanumeric characters. Defaults to
<literal>PHPSESSID</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.auto_start</literal> specifies whether the
session module starts a session automatically on request
startup. Defaults to <literal>0</literal> (disabled).
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.cookie_lifetime</literal> 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
<literal>0</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.serialize_handler</literal> defines the name
of the handler which is used to serialize/deserialize
data. Currently, a PHP internal format (name
<literal>php</literal>) and WDDX is supported (name
<literal>wddx</literal>). WDDX is only available, if PHP is
compiled with <link linkend="ref.wddx">WDDX
support</link>. Defaults to <literal>php</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.gc_probability</literal> specifies the
probability that the gc (garbage collection) routine is started
on each request in percent. Defaults to <literal>1</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.gc_maxlifetime</literal> specifies the number
of seconds after which data will be seen as 'garbage' and
cleaned up.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.referer_check</literal> 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.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.entropy_file</literal> 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
<literal>/dev/random</literal> or
<literal>/dev/urandom</literal> which are available on many
Unix systems.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.entropy_length</literal> specifies the number
of bytes which will be read from the file specified
above. Defaults to <literal>0</literal> (disabled).
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.use_cookies</literal> specifies whether the
module will use cookies to store the session id on the client
side. Defaults to <literal>1</literal> (enabled).
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.cookie_path</literal> specifies path to set
in session_cookie. Defaults to <literal>/</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.cookie_domain</literal> specifies domain to
set in session_cookie. Default is none at all.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.cache_limiter</literal> specifies cache control
method to use for session pages (nocache/private/public).
Defaults to <literal>nocache</literal>.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>session.cache_expire</literal> specifies time-to-live
for cached session pages in minutes, this has no effect for
nocache limiter. Defaults to <literal>180</literal>.
</simpara>
</listitem>
</itemizedlist>
<note>
<para>
Session handling was added in PHP 4.0.
</para>
</note>
</para>
</partintro>
<refentry id="function.session-start">
<refnamediv>
<refname>session_start</refname>
<refpurpose>Initialize session data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>session_start</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<simpara>
<function>session_start</function> creates a session (or resumes
the current one based on the session id being passed via a GET
variable or a cookie).</simpara>
<simpara>
This function always returns true.
</simpara>
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.session-destroy">
<refnamediv>
<refname>session_destroy</refname>
<refpurpose>Destroys all data registered to a session</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>session_destroy</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<simpara>
<function>session_destroy</function> destroys all of the data
associated with the current session.
</simpara>
<simpara>
This function returns true on success and false on failure to destroy
the session data.
</simpara>
</refsect1>
</refentry>
<refentry id="function.session-name">
<refnamediv>
<refname>session_name</refname>
<refpurpose>Get and/or set the current session name</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>session_name</function></funcdef>
<paramdef>string
<parameter><optional>name</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_name</function> returns the name of the current
session. If <parameter>name</parameter> is specified, the name of
the current session is changed to its value.
</para>
<para>
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 <literal>session.name</literal> at request startup
time. Thus, you need to call <function>session_name</function>
for every request (and before <function>session_start</function>
or <function>session_register</function> are called).
</para>
<example>
<title><function>session_name</function> examples</title>
<programlisting role="php">
<?php
# set the session name to WebsiteID
$previous_name = session_name ("WebsiteID");
echo "The previous session name was $previous_name<p>";
?>
</programlisting>
</example>
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.session-module-name">
<refnamediv>
<refname>session_module_name</refname>
<refpurpose>Get and/or set the current session module</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>session_module_name</function></funcdef>
<paramdef>string
<parameter><optional>module</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_module_name</function> returns the name of the
current session module. If <parameter>module</parameter> is
specified, that module will be used instead.
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.session-save-path">
<refnamediv>
<refname>session_save_path</refname>
<refpurpose>Get and/or set the current session save path</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>session_save_path</function></funcdef>
<paramdef>string
<parameter><optional>path</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_save_path</function> returns the path of the current
directory used to save session data. If <parameter>path</parameter>
is specified, the path to which data is saved will be changed.
<note>
<para>
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.
</para>
</note>
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.session-id">
<refnamediv>
<refname>session_id</refname>
<refpurpose>Get and/or set the current session id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>session_id</function></funcdef>
<paramdef>string
<parameter><optional>id</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_id</function> returns the session id for the
current session. If <parameter>id</parameter> is specified, it
will replace the current session id.
</para>
<para>
The constant <systemitem>SID</systemitem> can also be used to
retrieve the current name and session id as a string suitable for
adding to URLs.
</para>
</refsect1>
</refentry>
<refentry id="function.session-register">
<refnamediv>
<refname>session_register</refname>
<refpurpose>
Register one or more variables with the current session
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>session_register</function></funcdef>
<paramdef>mixed <parameter>name</parameter></paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_register</function> variable number of
arguments, any of which can be either a string holding the
variable name or an array consisting of such variable names or
other arrays. For each encountered variable name,
<function>session_register</function> registers the global
variable named by it with the current session.
</para>
<para>
This function returns true when the variable is successfully
registered with the session.
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.session-unregister">
<refnamediv>
<refname>session_unregister</refname>
<refpurpose>
Unregister a variable from the current session
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>session_unregister</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_unregister</function> unregisters (forgets)
the global variable named <parameter>name</parameter> from the
current session.
</para>
<para>
This function returns true when the variable is successfully
unregistered from the session.
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.session-unset">
<refnamediv>
<refname>session_unset</refname>
<refpurpose>
Free all session variables
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>session_unset</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>session_unset</function> function free's all session variables
currently registered.
</para>
</refsect1>
</refentry>
<refentry id="function.session-is-registered">
<refnamediv>
<refname>session_is_registered</refname>
<refpurpose>
Find out if a variable is registered in a session
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>session_is_registered</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_is_registered</function> returns true if there
is a variable with the name <parameter>name</parameter>
registered in the current session.
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.session-get-cookie-params">
<refnamediv>
<refname>session_get_cookie_params</refname>
<refpurpose>
Get the session cookie parameters
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>
array <function>session_get_cookie_params</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>session_get_cookie_params</function> function returns an
array with the current session cookie information, the array contains
the following items:
<itemizedlist>
<listitem>
<simpara>
"lifetime" - The lifetime of the cookie.
</simpara>
</listitem>
<listitem>
<simpara>
"path" - The path where information is stored.
</simpara>
</listitem>
<listitem>
<simpara>
"domain" - The domain of the cookie.
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.session-set-cookie-params">
<refnamediv>
<refname>session_set_cookie_params</refname>
<refpurpose>
Set the session cookie parameters
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>session_set_cookie_params</function></funcdef>
<paramdef>
int <parameter>lifetime</parameter>
</paramdef>
<paramdef>
string <parameter><optional>path</optional></parameter>
</paramdef>
<paramdef>
string <parameter><optional>domain</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Set cookie parameters defined in the php.ini file. The effect of this
function only lasts for the duration of the script.
</para>
</refsect1>
</refentry>
<refentry id="function.session-decode">
<refnamediv>
<refname>session_decode</refname>
<refpurpose>Decodes session data from a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>session_decode</function></funcdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_decode</function> decodes the session data in
<parameter>data</parameter>, setting variables stored in the
session.
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.session-encode">
<refnamediv>
<refname>session_encode</refname>
<refpurpose>
Encodes the current session data as a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>session_encode</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>session_encode</function> returns a string with the
contents of the current session encoded within.
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.session-set-save-handler">
<refnamediv>
<refname>session_set_save_handler</refname>
<refpurpose>
Sets user-level session storage functions
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>session_set_save_handler</function>
</funcdef>
<paramdef>string
<parameter>open</parameter></paramdef><paramdef>string
<parameter>close</parameter></paramdef><paramdef>string
<parameter>read</parameter></paramdef><paramdef>string
<parameter>write</parameter></paramdef><paramdef>string
<parameter>destroy</parameter></paramdef><paramdef>string
<parameter>gc</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_set_save_handler</function> 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.
</para>
<note>
<para>
You must set the configuration option
<parameter>session.save_handler</parameter> to
<parameter>user</parameter> in your php.ini file for
<function>session_set_save_handler</function> to take effect.
</para>
</note>
<para>
The following example provides file based session
storage similar to the PHP sessions default save handler
<parameter>files</parameter>. This example could easily be
extended to cover database storage using your favorite PHP
supported database engine.
</para>
<para>
<example>
<title>
<function>session_set_save_handler</function> example
</title>
<programlisting role="php">
<?php
function open ($save_path, $session_name) {
global $sess_save_path, $sess_session_name;
$sess_save_path = $save_path;
$sess_session_name = $session_name;
return(true);
}
function close() {
return(true);
}
function read ($id) {
global $sess_save_path, $sess_session_name;
$sess_file = "$sess_save_path/sess_$id";
if ($fp = @fopen($sess_file, "r")) {
$sess_data = fread($fp, filesize($sess_file));
return($sess_data);
} else {
return("");
}
}
function write ($id, $sess_data) {
global $sess_save_path, $sess_session_name;
$sess_file = "$sess_save_path/sess_$id";
if ($fp = @fopen($sess_file, "w")) {
return(fwrite($fp, $sess_data));
} else {
return(false);
}
}
function destroy ($id) {
global $sess_save_path, $sess_session_name;
$sess_file = "$sess_save_path/sess_$id";
return(@unlink($sess_file));
}
/*********************************************
* WARNING - You will need to implement some *
* sort of garbage collection routine here. *
*********************************************/
function gc ($maxlifetime) {
return true;
}
session_set_save_handler ("open", "close", "read", "write",
"destroy", "gc");
session_start();
// proceed to use sessions normally
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.session-cache-limiter">
<refnamediv>
<refname>session_cache_limiter</refname>
<refpurpose>Get and/or set the current cache limiter</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>session_cache_limiter</function></funcdef>
<paramdef>string
<parameter><optional>cache_limiter</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>session_cache_limiter</function> returns the name of the
current cache limiter. If <parameter>cache_limiter</parameter> is
specified, the name of the current cache limiter is changed to the
new value.
</para>
<para>
The cache limiter controls the cache control HTTP headers sent to the
client. These headers determine the rules by which the page content
may be cached. Setting the cache limiter to <literal>nocache</literal>,
for example, would disallow any client-side caching. A value of
<literal>public</literal>, however, would permit caching. It can also
be set to <literal>private</literal>, which is slightly more restrictive
than <literal>public</literal>.
</para>
<para>
The cache limiter is reset to the default value stored in
<literal>session.cache_limiter</literal> at request startup time. Thus,
you need to call <function>session_cache_limiter</function> for every
request (and before <function>session_start</function> is called).
</para>
<example>
<title><function>session_cache_limiter</function> examples</title>
<programlisting role="php">
<?php
# set the cache limiter to 'private'
session_cache_limiter('private');
$cache_limiter = session_cache_limiter();
echo "The cache limiter is now set to $cache_limiter<p>";
?>
</programlisting>
</example>
<note>
<para>
This function was added in PHP 4.0.3.
</para>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/shmop.xml
+++ phpdoc/nl/functions/shmop.xml
<reference id="ref.shmop">
<title>Shared Memory Functions</title>
<titleabbrev>shmop</titleabbrev>
<partintro>
<para>
Shmop is an easy to use set of functions that allows php to read,
write, create and delete UNIX shared memory segments. The functions
will not work on windows, as it does not support shared memory. To
use shmop you will need to compile php with the --enable-shmop parameter
in your configure line.
</para>
<para>
<example>
<title>Shared Memory Operations Overview</title>
<programlisting role="php">
<?php
// Create 100 byte shared memory block with system id if 0xff3
$shm_id = shm_open(0xff3, "c", 0644, 100);
if(!$shm_id) {
echo "Couldn't create shared memory segment\n";
}
// Get shared memory block's size
$shm_size = shm_size($shm_id);
echo "SHM Block Size: ".$shm_size. " has been created.\n";
// Lets write a test string into shared memory
$shm_bytes_written = shm_write($shm_id, "my shared memory block", 0);
if($shm_bytes_written != strlen("my shared memory block")) {
echo "Couldn't write the entire length of data\n";
}
// Now lets read the string back
$my_string = shm_read($shm_id, 0, $shm_size);
if(!$my_string) {
echo "Couldn't read from shared memory block\n";
}
echo "The data inside shared memory was: ".$my_string."\n";
//Now lets delete the block and close the shared memory segment
if(!shm_delete($shm_id)) {
echo "Couldn't mark shared memory block for deletion.
}
shm_close($shm_id);
?>
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.shm_open">
<refnamediv>
<refname>shm_open</refname>
<refpurpose>Create or open shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_open</function></funcdef>
<paramdef>int <parameter>key</parameter></paramdef>
<paramdef>string <parameter>flags</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>int <parameter>size</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>shm_open</function> can create or open a shared memory block.
</para>
<para>
<function>shm_open</function> 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:
<itemizedlist>
<listitem>
<simpara>
"a" for access (sets IPC_EXCL)
use this flag when you need to open an existing shared memory segment
</simpara>
</listitem>
<listitem>
<simpara>
"c" for create (sets IPC_CREATE)
use this flag when you need to create a new shared memory segment.
</simpara>
</listitem>
</itemizedlist>
The third parameter is the mode, which are the permissions that you
wish to assign to your memory segment, those are the same as permission
for a file. Permissions need to be passed in octal form ex. 0644.
The last parameter is size of the shared memory block you wish to create
in bytes.
<note><simpara>
Note: the 3rd and 4th should be entered as 0 if you are opening an
existing memory segment. On success <function>shm_open</function> will
return an id that you can use to access the shared memory segment
you've created.
</simpara></note>
</para>
<para>
<example>
<title>Create a new shared memory block</title>
<programlisting role="php">
<?php
$shm_id = shm_open(0x0fff, "c", 0644, 100);
?>
</programlisting>
</example>
</para>
<para>
This example opened a shared memory block with a system id of 0x0fff.
</para>
</refsect1>
</refentry>
<refentry id="function.shm_read">
<refnamediv>
<refname>shm_read</refname>
<refpurpose>Read data from shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>shm_read</function></funcdef>
<paramdef>int <parameter>shmid</parameter></paramdef>
<paramdef>int <parameter>start</parameter></paramdef>
<paramdef>int <parameter>count</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>shm_read</function> will read a string from shared memory block.
</para>
<para>
<function>shm_read</function> takes 3 parameters: shmid, which is the shared
memory block identifier created by <function>shm_open</function>, offset from
which to start reading and count on the number of bytes to read.
</para>
<para>
<example>
<title>Reading shared memory block</title>
<programlisting role="php">
<?php
$shm_data = shm_read($shm_id, 0, 50);
?>
</programlisting>
</example>
</para>
<para>
This example will read 50 bytes from shared memory block and place the data
inside <literal>$shm_data</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.shm_write">
<refnamediv>
<refname>shm_write</refname>
<refpurpose>Write data into shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_write</function></funcdef>
<paramdef>int <parameter>shmid</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int <parameter>offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>shm_write</function> will write a string into shared memory block.
</para>
<para>
<function>shm_write</function> takes 3 parameters: shmid, which is the
shared memory block identifier created by <function>shm_open</function>,
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.
</para>
<para>
<example>
<title>Writing to shared memory block</title>
<programlisting role="php">
<?php
$shm_bytes_written = shm_write($shm_id, $my_string, 0);
?>
</programlisting>
</example>
</para>
<para>
This example will write data inside <literal>$my_string</literal> into
shared memory block, <literal>$shm_bytes_written</literal> will contain
the number of bytes written.
</para>
</refsect1>
</refentry>
<refentry id="function.size">
<refnamediv>
<refname>shm_size</refname>
<refpurpose>Get size of shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_size</function></funcdef>
<paramdef>int <parameter>shmid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>shm_size</function> is used to get the size, in bytes of the
shared memory block.
</para>
<para>
<function>shm_size</function> takes the shmid, which is the shared memory
block identifier created by <function>shm_open</function>, the function
will return and int, which represents the number of bytes the shared memory
block occupies.
</para>
<para>
<example>
<title>Getting the size of the shared memory block</title>
<programlisting role="php">
<?php
$shm_size = shm_size($shm_id);
?>
</programlisting>
</example>
</para>
<para>
This example will put the size of shared memory block identified by
<literal>$shm_id</literal> into <literal>$shm_size</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.shm_delete">
<refnamediv>
<refname>shm_delete</refname>
<refpurpose>Delete shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_delete</function></funcdef>
<paramdef>int <parameter>shmid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>shm_delete</function> is used to delete a shared memory block.
</para>
<para>
<function>shm_delete</function> takes the shmid, which is the shared memory
block identifier created by <function>shm_open</function>. On success 1 is
returned, on failure 0 is returned.
</para>
<para>
<example>
<title>Deleting shared memory block</title>
<programlisting role="php">
<?php
shm_delete($shm_id);
?>
</programlisting>
</example>
</para>
<para>
This example will delete shared memory block identified by
<literal>$shm_id</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.shm_close">
<refnamediv>
<refname>shm_close</refname>
<refpurpose>Close shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>shm_close</function></funcdef>
<paramdef>int <parameter>shmid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>shm_close</function> is used to close a shared memory block.
</para>
<para>
<function>shm_close</function> takes the shmid, which is the shared memory
block identifier created by <function>shm_open</function>.
</para>
<para>
<example>
<title>Closing shared memory block</title>
<programlisting role="php">
<?php
shm_close($shm_id);
?>
</programlisting>
</example>
</para>
<para>
This example will close shared memory block identified by
<literal>$shm_id</literal>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/snmp.xml
+++ phpdoc/nl/functions/snmp.xml
<reference id="ref.snmp">
<title>SNMP functions</title>
<titleabbrev>SNMP</titleabbrev>
<partintro>
<simpara>
In order to use the SNMP functions on Unix you need to install the <ulink
url="&url.ucd-snmp;">UCD SNMP</ulink> package. On Windows these functions
are only available on NT and not on Win95/98.</simpara>
<simpara>
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:</simpara>
<para>
<programlisting>
#define NO_ZEROLENGTH_COMMUNITY 1
</programlisting>
</para>
<simpara>
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.</simpara>
</partintro>
<refentry id="function.snmpget">
<refnamediv>
<refname>snmpget</refname>
<refpurpose>Fetch an SNMP object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>snmpget</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>int
<parameter><optional>timeout</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>retries</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns SNMP object value on success and false on error.</para>
<para>
The <function>snmpget</function> function is used to read the
value of an SNMP object specified by the
<parameter>object_id</parameter>. SNMP agent is specified by the
<parameter>hostname</parameter> and the read community is
specified by the <parameter>community</parameter> parameter.</para>
<para>
<informalexample>
<programlisting role="php">
$syscontact = snmpget("127.0.0.1", "public", "system.SysContact.0");
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.snmpset">
<refnamediv>
<refname>snmpset</refname>
<refpurpose>Set an SNMP object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>snmpset</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>string <parameter>type</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
<paramdef>int
<parameter><optional>timeout</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>retries</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the specified SNMP object value, returning true on success
and false on error.</para>
<para>
The <function>snmpset</function> function is used
to set the value of an SNMP object specified by the
<parameter>object_id</parameter>. SNMP agent is specified by the
<parameter>hostname</parameter> and the read community is specified
by the <parameter>community</parameter> parameter.</para>
</refsect1>
</refentry>
<refentry id="function.snmpwalk">
<refnamediv>
<refname>snmpwalk</refname>
<refpurpose>Fetch all the SNMP objects from an agent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>snmpwalk</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>int
<parameter><optional>timeout</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>retries</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of SNMP object values starting from the
<function>object_id</function> as root and false on error.</para>
<para>
<function>snmpwalk</function> function is used to read all the
values from an SNMP agent specified by the
<parameter>hostname</parameter>. <parameter>Community</parameter>
specifies the read community for that agent. A null
<parameter>object_id</parameter> is taken as the root of the SNMP
objects tree and all objects under that tree are returned as an
array. If <parameter>object_id</parameter> is specified, all the
SNMP objects below that <parameter>object_id</parameter> are
returned.
<informalexample>
<programlisting role="php">
$a = snmpwalk("127.0.0.1", "public", "");
</programlisting>
</informalexample></para>
<para>
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
<informalexample>
<programlisting role="php">
for ($i=0; $i<count($a); $i++) {
echo $a[$i];
}
</programlisting>
</informalexample></para>
</refsect1>
</refentry>
<refentry id="function.snmpwalkoid">
<refnamediv>
<refname>snmpwalkoid</refname>
<refpurpose>Query for a tree of information about a network entity
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>snmpwalkoid</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>int
<parameter><optional>timeout</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>retries</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an associative array with object ids and their respective
object value starting from the <parameter>object_id</parameter>
as root and false on error.</para>
<para>
<function>snmpwalkoid</function> function is used to read all
object ids and their respective values from an SNMP agent
specified by the hostname. Community specifies the read
<parameter>community</parameter> for that agent. A null
<parameter>object_id</parameter> is taken as the root of the SNMP
objects tree and all objects under that tree are returned as an
array. If <parameter>object_id</parameter> is specified, all the
SNMP objects below that <parameter>object_id</parameter> are
returned.</para>
<para>
The existence of <function>snmpwalkoid</function> and
<function>snmpwalk</function> has historical reasons. Both
functions are provided for backward compatibility.
<informalexample>
<programlisting role="php">
$a = snmpwalkoid("127.0.0.1", "public", "");
</programlisting>
</informalexample></para>
<para>
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
<informalexample>
<programlisting role="php">
for (reset($a); $i = key($a); next($a)) {
echo "$i: $a[$i]<br>\n";
}
</programlisting>
</informalexample></para>
</refsect1>
</refentry>
<refentry id="function.snmp-get-quick-print">
<refnamediv>
<refname>snmp_get_quick_print</refname>
<refpurpose>Fetch the current value of the UCD library's quick_print setting
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>snmp_get_quick_print</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the current value stored in the UCD Library for quick_print.
quick_print is off by default.
<informalexample>
<programlisting role="php">
$quickprint = snmp_get_quick_print();
</programlisting>
</informalexample></para>
<para>
Above function call would return <systemitem>false</systemitem> if
quick_print is on, and <systemitem>true</systemitem> if quick_print
is on.</para>
<para>
<function>snmp_get_quick_print</function> is only available when using
the UCD SNMP library. This function is not available when using the
Windows SNMP library.</para>
<para>
See: <function>snmp_set_quick_print</function> for a full description
of what quick_print does.</para>
</refsect1>
</refentry>
<refentry id="function.snmp-set-quick-print">
<refnamediv>
<refname>snmp_set_quick_print</refname>
<refpurpose>Set the value of quick_print within the UCD SNMP library.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>snmp_set_quick_print</function></funcdef>
<paramdef>boolean <parameter>quick_print</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets 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.</para>
<para>
Setting quick_print is often used when using the information returned
rather then displaying it.
<informalexample>
<programlisting role="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";
</programlisting>
</informalexample></para>
<para>
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.</para>
<para>
By default the UCD SNMP library returns verbose values, quick_print is
used to return only the value.</para>
<para>
Currently strings are still returned with extra quotes, this will be
corrected in a later release.</para>
<para>
<function>snmp_set_quick_print</function> is only available when using
the UCD SNMP library. This function is not available when using
the Windows SNMP library.</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/sockets.xml
+++ phpdoc/nl/functions/sockets.xml
<reference id="ref.sockets">
<title>Socket functions</title>
<titleabbrev>Sockets</titleabbrev>
<partintro>
<simpara>
The socket extension implements a low-level interface to the
socket communication functions, providing the possibility to act
as a socket server as well as a client.
</simpara>
<para>
The socket functions described here are part of an extension to
PHP which must be enabled at compile time by giving the <option
role="configure">--enable-sockets</option> option to
<command>configure</command>.
</para>
<para>
For a more generic client-side socket interface, see
<function>fsockopen</function> and
<function>pfsockopen</function>.
</para>
<para>
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.
</para>
<para>
That said, those unfamiliar with socket programming can still 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.
</para>
<para>
<example>
<title>Socket example: Simple TCP/IP server</title>
<para>
This example shows a simple talkback server. Change the
<varname>address</varname> and <varname>port</varname> variables
to suit your setup and execute. You may then connect to the
server with a command similar to: <command>telnet 192.168.1.53
10000</command> (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'.
</para>
<programlisting role="php">
<?php
error_reporting (E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit (0);
$address = '192.168.1.53';
$port = 10000;
if (($sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
echo "socket() failed: reason: " . strerror ($sock) . "\n";
}
if (($ret = bind ($sock, $address, $port)) < 0) {
echo "bind() failed: reason: " . strerror ($ret) . "\n";
}
if (($ret = listen ($sock, 5)) < 0) {
echo "listen() failed: reason: " . strerror ($ret) . "\n";
}
do {
if (($msgsock = accept_connect($sock)) < 0) {
echo "accept_connect() failed: reason: " . strerror ($msgsock) . "\n";
break;
}
do {
$buf = '';
$ret = read ($msgsock, $buf, 2048);
if ($ret < 0) {
echo "read() failed: reason: " . strerror ($ret) . "\n";
break 2;
}
if ($ret == 0) {
break 2;
}
$buf = trim ($buf);
if ($buf == 'quit') {
close ($msgsock);
break 2;
}
$talkback = "PHP: You said '$buf'.\n";
write ($msgsock, $talkback, strlen ($talkback));
echo "$buf\n";
} while (true);
close ($msgsock);
} while (true);
close ($sock);
?>
</programlisting>
</example>
</para>
<para>
<example>
<title>Socket example: Simple TCP/IP client</title>
<para>
This example shows a simple, one-shot HTTP client. It simply
connects to a page, submits a HEAD request, echoes the reply,
and exits.
</para>
<programlisting>
<?php
error_reporting (E_ALL);
echo "<h2>TCP/IP Connection</h2>\n";
/* Get the port for the WWW service. */
$service_port = getservbyname ('www', 'tcp');
/* Get the IP address for the target host. */
$address = gethostbyname ('www.php.net');
/* Create a TCP/IP socket. */
$socket = socket (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
echo "socket() failed: reason: " . strerror ($socket) . "\n";
} else {
"socket() successful: " . strerror ($socket) . "\n";
}
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = connect ($socket, $address, $service_port);
if ($result < 0) {
echo "connect() failed.\nReason: ($result) " . strerror($result) . "\n";
} else {
echo "OK.\n";
}
$in = "HEAD / HTTP/1.0\r\n\r\n";
$out = '';
echo "Sending HTTP HEAD request...";
write ($socket, $in, strlen ($in));
echo "OK.\n";
echo "Reading response:\n\n";
while (read ($socket, $out, 2048)) {
echo $out;
}
echo "Closing socket...";
close ($socket);
echo "OK.\n\n";
?>
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.accept-connect">
<refnamediv>
<refname>accept_connect</refname>
<refpurpose>Accepts a connection on a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>accept_connect</function></funcdef>
<paramdef>int <parameter>socket</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
After the socket <parameter>socket</parameter> has been created
using <function>socket</function>, bound to a name with
<function>bind</function>, and told to listen for connections
with <function>listen</function>, this function will accept
incoming connections on that socket. Once a successful connection
is made, a new socket descriptor 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, <function>accept_connect</function> will block until
a connection becomes present. If <parameter>socket</parameter>
has been made non-blocking using
<function>socket_set_blocking</function> or
<function>set_nonblock</function>, an error code will be
returned.
</para>
<para>
The socket descriptor returned by
<function>accept_connect</function> may not be used to accept new
connections. The original listening socket
<parameter>socket</parameter>, however, remains open and may be
reused.
</para>
<para>
Returns a new socket descriptor on success, or a negative error
code on failure. This code may be passed to
<function>strerror</function> to get a textual explanation of the
error.
</para>
<para>
See also
<function>bind</function>,
<function>connect</function>,
<function>listen</function>,
<function>socket</function>,
<function>socket_get_status</function>, and
<function>strerror</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bind">
<refnamediv>
<refname>bind</refname>
<refpurpose>Binds a name to a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>bind</function></funcdef>
<paramdef>int <parameter>socket</parameter></paramdef>
<paramdef>string <parameter>address</parameter></paramdef>
<paramdef>int
<parameter><optional>port</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>bind</function> binds the name given in
<parameter>address</parameter> to the socket described by
<parameter>socket</parameter>, which must be a valid socket
descriptor created with <function>socket</function>.
</para>
<para>
The <parameter>address</parameter> parameter is either an IP
address in dotted-quad notation
(e.g. <literal>127.0.0.1</literal>), if the socket is of the
<constant>AF_INET</constant> family; or the pathname of a
Unix-domain socket, if the socket family is
<constant>AF_UNIX</constant>.
</para>
<para>
The <parameter>port</parameter> parameter is only used when
connecting to an <constant>AF_INET</constant> socket, and
designates the port on the remote host to which a connection
should be made.
</para>
<para>
Returns zero on success, or a negative error code on
failure. This code may be passed to <function>strerror</function>
to get a textual explanation of the error.
</para>
<para>
See also
<function>accept_connect</function>,
<function>connect</function>,
<function>listen</function>,
<function>socket</function>,
<function>socket_get_status</function>, and
<function>strerror</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.close">
<refnamediv>
<refname>close</refname>
<refpurpose>Closes a file descriptor</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>close</function></funcdef>
<paramdef>int <parameter>socket</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>close</function> closes the file (or socket) descriptor
given by <parameter>socket</parameter>.
</para>
<para>
Note that <function>close</function> should not be used on PHP
file descriptors created with <function>fopen</function>,
<function>popen</function>, <function>fsockopen</function>, or
<function>psockopen</function>; it is meant for sockets created
with <function>socket</function> or
<function>accept_connect</function>.
</para>
<para>
Returns true on success, or false if an error occurs (i.e.,
<parameter>socket</parameter> is invalid).
</para>
<para>
See also <function>bind</function>, <function>listen</function>,
<function>socket</function>,
<function>socket_get_status</function>, and
<function>strerror</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.connect">
<refnamediv>
<refname>connect</refname>
<refpurpose>Initiates a connection on a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>connect</function></funcdef>
<paramdef>int <parameter>socket</parameter></paramdef>
<paramdef>string <parameter>address</parameter></paramdef>
<paramdef>int
<parameter><optional>port</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Initiates a connection using the socket descriptor
<parameter>socket</parameter>, which must be a valid socket
descriptor created with <function>socket</function>.
</para>
<para>
The <parameter>address</parameter> parameter is either an IP
address in dotted-quad notation
(e.g. <literal>127.0.0.1</literal>), if the socket is of the
<constant>AF_INET</constant> family; or the pathname of a
Unix-domain socket, if the socket family is
<constant>AF_UNIX</constant>.
</para>
<para>
The <parameter>port</parameter> parameter is only used when
connecting to an <constant>AF_INET</constant> socket, and
designates the port on the remote host to which a connection
should be made.
</para>
<para>
Returns zero on success, or a negative error code on
failure. This code may be passed to <function>strerror</function>
to get a textual explanation of the error.
</para>
<para>
See also
<function>bind</function>,
<function>listen</function>,
<function>socket</function>,
<function>socket_get_status</function>, and
<function>strerror</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.listen">
<refnamediv>
<refname>listen</refname>
<refpurpose>Listens for a connection on a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>listen</function></funcdef>
<paramdef>int <parameter>socket</parameter></paramdef>
<paramdef>int <parameter>backlog</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
After the socket <parameter>socket</parameter> has been created
using <function>socket</function> and bound to a name with
<function>bind</function>, it may be told to listen for incoming
connections on <parameter>socket</parameter>. A maximum of
<parameter>backlog</parameter> incoming connections will be
queued for processing.
</para>
<para>
<function>listen</function> is applicable only to sockets with
type <literal>SOCK_STREAM</literal> or
<literal>SOCK_SEQPACKET</literal>.
</para>
<para>
Returns zero on success, or a negative error code on
failure. This code may be passed to <function>strerror</function>
to get a textual explanation of the error.
</para>
<para>
See also
<function>accept_connect</function>,
<function>bind</function>,
<function>connect</function>,
<function>socket</function>,
<function>socket_get_status</function>, and
<function>strerror</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.socket">
<refnamediv>
<refname>socket</refname>
<refpurpose>Create a socket (endpoint for communication)</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>socket</function></funcdef>
<paramdef>int <parameter>domain</parameter></paramdef>
<paramdef>int <parameter>type</parameter></paramdef>
<paramdef>int <parameter>protocol</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Creates a communication endpoint (a socket), and returns a
descriptor to the socket.
</para>
<para>
The <parameter>domain</parameter> parameter sets the
domain. Currently, <constant>AF_INET</constant> and
<constant>AF_UNIX</constant> are understood.
</para>
<para>
The <parameter>type</parameter> parameter selects the socket
type. This is one of <constant>SOCK_STREAM</constant>,
<constant>SOCK_DGRAM</constant>,
<constant>SOCK_SEQPACKET</constant>,
<constant>SOCK_RAW</constant>, <constant>SOCK_RDM</constant>, or
<constant>SOCK_PACKET</constant>.
</para>
<para>
<parameter>protocol</parameter> sets the protocol.
</para>
<para>
Returns a valid socket descriptor on success, or a negative error
code on failure. This code may be passed to
<function>strerror</function> to get a textual explanation of the
error.
</para>
<para>
For more information on the usage of <function>socket</function>,
as well as on the meanings of the various parameters, see the
Unix man page socket (2).
</para>
<para>
See also
<function>accept_connect</function>,
<function>bind</function>,
<function>connect</function>,
<function>listen</function>,
<function>strerror</function>, and
<function>socket_get_status</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strerror">
<refnamediv>
<refname>strerror</refname>
<refpurpose>Return a string describing a socket error</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strerror</function></funcdef>
<paramdef>int <parameter>errno</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>strerror</function> takes as its
<parameter>errno</parameter> parameter the return value of one of
the socket functions, 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 <function>strerror</function>, and it tells you
what happened.
</para>
<para>
<example>
<title><function>strerror</function> example</title>
<programlisting role="php">
<?php
if (($socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
echo "socket() failed: reason: " . strerror ($socket) . "\n";
}
if (($ret = bind ($socket, '127.0.0.1', 80)) < 0) {
echo "bind() failed: reason: " . strerror ($ret) . "\n";
}
?>
</programlisting>
<para>
The expected output from the above example (assuming the script
is not run with root privileges):
<screen>
bind() failed: reason: Permission denied
</screen>
</para>
</example>
</para>
<para>
See also
<function>accept_connect</function>,
<function>bind</function>,
<function>connect</function>,
<function>listen</function>,
<function>socket</function>, and
<function>socket_get_status</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/strings.xml
+++ phpdoc/nl/functions/strings.xml
<reference id="ref.strings">
<title>String functions</title>
<titleabbrev>Strings</titleabbrev>
<partintro>
<simpara>
These functions all manipulate strings in various ways. Some more
specialized sections can be found in the regular expression and
URL handling sections.
</simpara>
<para>
For information on how strings behave, especially with regard to
usage of single quotes, double quotes, and escape sequences, see
the <link linkend="language.types.string">Strings</link> entry in
the <link linkend="language.types">Types</link> section of the
manual.
</para>
</partintro>
<refentry id="function.addcslashes">
<refnamediv>
<refname>AddCSlashes</refname>
<refpurpose>Quote string with slashes in a C style</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>addcslashes</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string <parameter>charlist</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string with backslashes before characters that are
listed in <parameter>charlist</parameter> parameter. It escapes
<literal>\n</literal>, <literal>\r</literal> etc. in C-like
style, characters with ASCII code lower than 32 and higher than
126 are converted to octal representation. Be carefull when
escaping alphanumeric characters. You can specify a range in
<parameter>charlist</parameter> like "\0..\37", which would
escape all characters with ASCII code between 0 and 31.
<example>
<title><function>Addcslashes</function> example</title>
<programlisting role="php">
$escaped = addcslashes ($not_escaped, "\0..\37!@\177..\377");
</programlisting>
</example>
<note>
<simpara>
Added in PHP4b3-dev.</simpara>
</note>
</para>
<para>
See also <function>stripcslashes</function>,
<function>stripslashes</function>,
<function>htmlspecialchars</function>,
<function>htmlspecialchars</function>, and
<function>quotemeta</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.addslashes">
<refnamediv>
<refname>AddSlashes</refname>
<refpurpose>Quote string with slashes</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>addslashes</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string with backslashes before characters that need
to be quoted in database queries etc. These characters are
single quote (<literal>'</literal>), double quote
(<literal>"</literal>), backslash (<literal>\</literal>)
and NUL (the null byte).
</para>
<para>
See also <function>stripslashes</function>,
<function>htmlspecialchars</function>, and
<function>quotemeta</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.bin2hex">
<refnamediv>
<refname>bin2hex</refname>
<refpurpose>
Convert binary data into hexadecimal representation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>bin2hex</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an ASCII string containing the hexadecimal representation
of <parameter>str</parameter>. The conversion is done byte-wise
with the high-nibble first.
</para>
</refsect1>
</refentry>
<refentry id="function.chop">
<refnamediv>
<refname>Chop</refname>
<refpurpose>Remove trailing whitespace</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>chop</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the argument string without trailing whitespace,
including newlines.
<example>
<title><function>Chop</function> example</title>
<programlisting role="php">
$trimmed = chop ($line);
</programlisting>
</example>
</para>
<note>
<para>
<function>chop</function> is different than the Perl
<parameter>chop()</parameter> function, which removes the last
character in the string.
</para>
</note>
<para>
See also <function>trim</function>, <function>ltrim</function>,
<function>rtrim</function>, and <function>chop</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.chr">
<refnamediv>
<refname>Chr</refname>
<refpurpose>Return a specific character</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>chr</function></funcdef>
<paramdef>int <parameter>ascii</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a one-character string containing the character specified
by <parameter>ascii</parameter>.
<example>
<title><function>Chr</function> example</title>
<programlisting role="php">
$str .= chr (27); /* add an escape character at the end of $str */
/* Often this is more useful */
$str = sprintf ("The string ends in escape: %c", 27);
</programlisting>
</example>
This function complements <function>ord</function>. See also
<function>sprintf</function> with a format string of
<literal>%c</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.chunk-split">
<refnamediv>
<refname>chunk_split</refname>
<refpurpose>Split a string into smaller chunks</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>chunk_split</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter><optional>chunklen</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>end</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Can be used to split a string into smaller chunks which is useful
for e.g. converting <link
linkend="function.base64-encode">base64_encode</link> output to
match RFC 2045 semantics. It inserts every
<parameter>chunklen</parameter> (defaults to 76) chars the string
<parameter>end</parameter> (defaults to "\r\n"). It returns the
new string leaving the original string untouched.
<example>
<title><function>Chunk_split</function> example</title>
<programlisting role="php">
# format $data using RFC 2045 semantics
$new_string = chunk_split (base64_encode($data));
</programlisting>
</example>
This function is significantly faster than
<function>ereg_replace</function>.
<note>
<para>
This function was added in 3.0.6.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.convert-cyr-string">
<refnamediv>
<refname>convert_cyr_string</refname>
<refpurpose>
Convert from one Cyrillic character set to another
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>convert_cyr_string</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string <parameter>from</parameter></paramdef>
<paramdef>string <parameter>to</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function converts the given string from one Cyrillic
character set to another. The <parameter>from</parameter> and
<parameter>to</parameter> arguments are single characters that
represent the source and target Cyrillic character sets. The
supported types are:
<itemizedlist>
<listitem>
<simpara>
k - koi8-r
</simpara>
</listitem>
<listitem>
<simpara>
w - windows-1251
</simpara>
</listitem>
<listitem>
<simpara>
i - iso8859-5
</simpara>
</listitem>
<listitem>
<simpara>
a - x-cp866
</simpara>
</listitem>
<listitem>
<simpara>
d - x-cp866
</simpara>
</listitem>
<listitem>
<simpara>
m - x-mac-cyrillic
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.count-chars">
<refnamediv>
<refname>count_chars</refname>
<refpurpose>
Return information abouts characters used in a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>count_chars</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>
<parameter>
<optional>mode</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Counts the number of occurances of every byte-value (0..255) in
<parameter>string</parameter> and returns it in various ways.
The optional parameter <parameter>Mode</parameter> default to
0. Depending on <parameter>mode</parameter>
<function>count_chars</function> returns one of the following:
<itemizedlist>
<listitem>
<simpara>
0 - an array with the byte-value as key and the freqency of
every byte as value.
</simpara>
</listitem>
<listitem>
<simpara>
1 - same as 0 but only byte-values with a frequency greater
than zero are listed.
</simpara>
</listitem>
<listitem>
<simpara>
2 - same as 0 but only byte-values with a frequency equal to
zero are listed.
</simpara>
</listitem>
<listitem>
<simpara>
3 - a string containing all used byte-values is returned.
</simpara>
</listitem>
<listitem>
<simpara>
4 - a string containing all not used byte-values is returned.
</simpara>
</listitem>
</itemizedlist>
</para>
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.crc32">
<refnamediv>
<refname>crc32</refname>
<refpurpose>Calculates the crc32 polynomial of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>crc32</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Generates the cyclic redundancy checksum polynomial of 32-bit lengths of
the <parameter>str</parameter>. This is usually used to validate the
integrity of data being trasmited.
</para>
<para>
See also: <function>md5</function>
</para>
</refsect1>
</refentry>
<refentry id="function.crypt">
<refnamediv>
<refname>crypt</refname>
<refpurpose>DES-encrypt a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>crypt</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string
<parameter><optional>salt</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>crypt</function> will encrypt a string using the
standard Unix <abbrev>DES</abbrev> encryption method. Arguments
are a string to be encrypted and an optional two-character salt
string to base the encryption on. See the Unix man page for your
crypt function for more information.
</para>
<simpara>
If the salt argument is not provided, one will be randomly
generated by PHP.
</simpara>
<simpara>
Some operating systems support more than one type of encryption.
In fact, sometimes the standard DES encryption is replaced by an
MD5 based encryption algorithm. The encryption type is triggered
by the salt argument. At install time, PHP determines the
capabilities of the crypt function and will accept salts for
other encryption types. If no salt is provided, PHP will
auto-generate a standard 2-character DES salt by default, unless
the default encryption type on the system is MD5, in which case a
random MD5-compatible salt is generated. PHP sets a constant
named CRYPT_SALT_LENGTH which tells you whether a regular
2-character salt applies to your system or the longer 12-char MD5
salt is applicable.
</simpara>
<simpara>
If you are using the supplied salt, you should be aware that the
salt is generated once. If you are calling this function
recursively, this may impact both appearance and, to a certain
extent, security.
</simpara>
<simpara>
The standard DES encryption <function>crypt</function> contains
the salt as the first two characters of the output.
</simpara>
<simpara>
On systems where the crypt() function supports multiple
encryption types, the following constants are set to 0 or 1
depending on whether the given type is available:
</simpara>
<itemizedlist>
<listitem>
<simpara>
CRYPT_STD_DES - Standard DES encryption with a 2-char SALT
</simpara>
</listitem>
<listitem>
<simpara>
CRYPT_EXT_DES - Extended DES encryption with a 9-char SALT
</simpara>
</listitem>
<listitem>
<simpara>
CRYPT_MD5 - MD5 encryption with a 12-char SALT starting with
$1$
</simpara>
</listitem>
<listitem>
<simpara>
CRYPT_BLOWFISH - Extended DES encryption with a 16-char SALT
starting with $2$
</simpara>
</listitem>
</itemizedlist>
<simpara>
There is no decrypt function, since <function>crypt</function>
uses a one-way algorithm.
</simpara>
<simpara>
See also: <function>md5</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.echo">
<refnamediv>
<refname>echo</refname>
<refpurpose>Output one or more strings</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef><function>echo</function></funcdef>
<paramdef>string <parameter>arg1</parameter></paramdef>
<paramdef>string
<parameter><optional>argn</optional>...</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Outputs all parameters.
</simpara>
<para>
<function>Echo</function> is not actually a function (it is a
language construct) so you are not required to use parantheses
with it.
<example>
<title><function>Echo</function> example</title>
<programlisting role="php">
echo "Hello World";
echo "This spans
multiple lines. The newlines will be
output as well";
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
</programlisting>
</example>
</para>
<note>
<para>
In fact, if you want to pass more than one parameter to echo,
you must not enclose the parameters within parentheses.
</para>
</note>
<simpara>
See also:
<function>print</function>,
<function>printf</function>, and
<function>flush</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.explode">
<refnamediv>
<refname>explode</refname>
<refpurpose>Split a string by string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>explode</function></funcdef>
<paramdef>string <parameter>separator</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter><optional>limit</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an array of strings, each of which is a substring of
<parameter>string</parameter> formed by splitting it on boundaries formed
by the string <parameter>delim</parameter>.
If <parameter>limit</parameter> is set, the returned array will contaion
a maximum of <parameter>limit</parameter> elements with the last element
containing the whole rest of <parameter>string</parameter>.
</para>
<para>
<example>
<title><function>Explode</function> example</title>
<programlisting role="php">
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode (" ", $pizza);
</programlisting>
</example>
</para>
<note>
<para>
Although <function>implode</function> can for historical reasons
accept its parameters in either order,
<function>explode</function> cannot. You must ensure that the
<parameter>separator</parameter> argument comes before the
<parameter>string</parameter> argument.
</para>
</note>
<para>
See also <function>split</function> and
<function>implode</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.get-html-translation-table">
<refnamediv>
<refname>get_html_translation_table</refname>
<refpurpose>
Returns the translation table used by
<function>htmlspecialchars</function> and
<function>htmlentities</function>
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>get_html_translation_table</function>
</funcdef>
<paramdef>int <parameter>table</parameter></paramdef>
<paramdef>int
<parameter><optional>quote_style</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>get_html_translation_table</function> will return the
translation table that is used internally for
<function>htmlspecialchars</function> and
<function>htmlentities</function>. There are two new defines
(<parameter>HTML_ENTITIES</parameter>,
<parameter>HTML_SPECIALCHARS</parameter>) that allow you to
specify the table you want. And as in the
<function>htmlspecialchars</function> and
<function>htmlentities</function> functions you can optionally specify the
quote_style you are working with. The default is ENT_COMPAT mode. See
the description of these modes in <function>htmlspecialchars</function>.
<example>
<title>Translation Table Example</title>
<programlisting role="php">
$trans = get_html_translation_table (HTML_ENTITIES);
$str = "Hallo & <Frau> & Krämer";
$encoded = strtr ($str, $trans);
</programlisting>
</example>
The <literal>$encoded</literal> variable will now contain: "Hallo
&<sgmltag>amp</sgmltag>;
&<sgmltag>lt</sgmltag>;Frau&<sgmltag>gt</sgmltag>;
&<sgmltag>amp</sgmltag>;
Kr&<sgmltag>auml</sgmltag>;mer".
</para>
<para>
The cool thing is using <function>array_flip</function> to change
the direction of the translation.
<informalexample>
<programlisting role="php">
$trans = array_flip ($trans);
$original = strtr ($str, $trans);
</programlisting>
</informalexample>
The content of <literal>$original</literal> would be: "Hallo &
<Frau> & Krämer".
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
<para>
See also: <function>htmlspecialchars</function>,
<function>htmlentities</function>, <function>strtr</function>,
and <function>array_flip</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.get-meta-tags">
<refnamediv>
<refname>get_meta_tags</refname>
<refpurpose>
Extracts all meta tag content attributes from a file and returns
an array
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>get_meta_tags</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int
<parameter><optional>use_include_path</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Opens <parameter>filename</parameter> and parses it line by line
for <meta> tags of the form
<example>
<title>Meta Tags Example</title>
<programlisting role="html">
<meta name="author" content="name">
<meta name="tags" content="php3 documentation">
</head> <!-- parsing stops here -->
</programlisting>
</example>
(pay attention to line endings - PHP uses a native function to
parse the input, so a Mac file won't work on Unix).
</para>
<para>
The value of the name property becomes the key, the value of the
content property becomes the value of the returned array, so you
can easily use standard array functions to traverse it or access
single values. Special characters in the value of the name
property are substituted with '_', the rest is converted to lower
case.
</para>
<para>
Setting <parameter>use_include_path</parameter> to 1 will result
in PHP trying to open the file along the standard include path.
</para>
</refsect1>
</refentry>
<refentry id="function.hebrev">
<refnamediv>
<refname>hebrev</refname>
<refpurpose>
Convert logical Hebrew text to visual text
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hebrev</function></funcdef>
<paramdef>string <parameter>hebrew_text</parameter></paramdef>
<paramdef>int
<parameter><optional>max_chars_per_line</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The optional parameter <parameter>max_chars_per_line</parameter>
indicates maximum number of characters per line will be output. The
function tries to avoid breaking words.
</para>
<para>
See also <function>hebrevc</function>
</para>
</refsect1>
</refentry>
<refentry id="function.hebrevc">
<refnamediv>
<refname>hebrevc</refname>
<refpurpose>
Convert logical Hebrew text to visual text with newline conversion
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>hebrevc</function></funcdef>
<paramdef>string <parameter>hebrew_text</parameter></paramdef>
<paramdef>int
<parameter><optional>max_chars_per_line</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is similar to <function>hebrev</function> with the
difference that it converts newlines (\n) to "<br>\n".
The optional parameter <parameter>max_chars_per_line</parameter>
indicates maximum number of characters per line will be output. The
function tries to avoid breaking words.
</para>
<para>
See also <function>hebrev</function>
</para>
</refsect1>
</refentry>
<refentry id="function.htmlentities">
<refnamediv>
<refname>htmlentities</refname>
<refpurpose>
Convert all applicable characters to HTML entities
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>htmlentities</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter><optional>quote_style</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is identical to
<function>htmlspecialchars</function> in all ways, except that
all characters which have HTML character entity equivalents are
translated into these entities. Like
<function>htmlspecialchars</function>, it takes an optional
second argument which indicates what should be done with single
and double quotes. <constant>ENT_COMPAT</constant> (the default)
will only convert double-quotes and leave single-quotes alone.
<constant>ENT_QUOTES</constant> will convert both double and
single quotes, and <constant>ENT_NOQUOTES</constant> will leave
both double and single quotes unconverted.
</para>
<para>
At present, the ISO-8859-1 character set is used. Note that the optional
second argument was added in PHP 3.0.17 and PHP 4.0.3.
</para>
<para>
See also <function>htmlspecialchars</function> and
<function>nl2br</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.htmlspecialchars">
<refnamediv>
<refname>htmlspecialchars</refname>
<refpurpose>
Convert special characters to HTML entities
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>htmlspecialchars</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter><optional>quote_style</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Certain characters have special significance in HTML, and should
be represented by HTML entities if they are to preserve their
meanings. This function returns a string with some of these
conversions made; the translations made are those most
useful for everyday web programming. If you require all HTML
character entities to be translated, use
<function>htmlentities</function> instead.
</para>
<simpara>
This function is useful in preventing user-supplied text from
containing HTML markup, such as in a message board or guest book
application. The optional second argument, quote_style, tells the
function what to do with single and double quote characters. The
default mode, ENT_COMPAT, is the backwards compatible mode which only
translates the double-quote character and leaves the single-quote
untranslated. If ENT_QUOTES is set, both single and double quotes
are translated and if ENT_NOQUOTES is set neither single nor double quotes
are translated.
</simpara>
<para>
The translations performed are:
<itemizedlist>
<listitem>
<simpara>
'&' (ampersand) becomes '&amp;'
</simpara>
</listitem>
<listitem>
<simpara>
'"' (double quote) becomes '&quot;' when ENT_NOQUOTES
is not set.
</simpara>
</listitem>
<listitem>
<simpara>
''' (single quote) becomes '&#039;' only when
ENT_QUOTES is set.
</simpara>
</listitem>
<listitem>
<simpara>
'<' (less than) becomes '&lt;'
</simpara>
</listitem>
<listitem>
<simpara>
'>' (greater than) becomes '&gt;'
</simpara>
</listitem>
</itemizedlist>
<example>
<title><function>htmlspecialchars</function> example</title>
<programlisting role="php">
$new = htmlspecialchars("<a href='test'>Test</a>",
ENT_QUOTES);
</programlisting>
</example>
</para>
<para>
Note that this function does not translate anything beyond what
is listed above. For full entity translation, see
<function>htmlentities</function>. Also note that the optional second
argument was added in PHP 3.0.17 and PHP 4.0.3.
</para>
<para>
See also <function>htmlentities</function> and
<function>nl2br</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.implode">
<refnamediv>
<refname>implode</refname>
<refpurpose>Join array elements with a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>implode</function></funcdef>
<paramdef>string <parameter>glue</parameter></paramdef>
<paramdef>array <parameter>pieces</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a string representation of all the
array elements in the same order, with the glue string between
each element.
<example>
<title><function>Implode</function> example</title>
<programlisting role="php">
$colon_separated = implode (":", $array);
</programlisting>
</example>
</para>
<note>
<para>
<function>implode</function> can, for historical reasons, accept
its parameters in either order. For consistency with
<function>explode</function>, however, it may be less confusing
to use the documented order of arguments.
</para>
</note>
<simpara>
See also <function>explode</function>, <function>join</function>,
and <function>split</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.join">
<refnamediv>
<refname>join</refname>
<refpurpose>Join array elements with a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>join</function></funcdef>
<paramdef>string <parameter>glue</parameter></paramdef>
<paramdef>array <parameter>pieces</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>join</function> is an alias to
<function>implode</function>, and is identical in every way.
</simpara>
<simpara>
See also <function>explode</function>, <function>implode</function>,
and <function>split</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.levenshtein">
<refnamediv>
<refname>levenshtein</refname>
<refpurpose>
Calculate Levenshtein distance between two strings
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>levenshtein</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>levenshtein</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
<paramdef>int <parameter>cost_ins</parameter></paramdef>
<paramdef>int <parameter>cost_rep</parameter></paramdef>
<paramdef>int <parameter>cost_del</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>levenshtein</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
<paramdef>function <parameter>cost</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the Levenshtein-Distance between the
two argument strings or -1, if one of the argument strings
is longer than the limit of 255 characters (255 should be
more than enough for name or dictionary comparison, and
nobody serious would be doing genetic analysis with PHP).
</para>
<para>
The Levenshtein distance is defined as the minimal number of
characters you have to replace, insert or delete to transform
<parameter>str1</parameter> into <parameter>str2</parameter>.
The complexity of the algorithm is <literal>O(m*n)</literal>,
where <literal>n</literal> and <literal>m</literal> are the
length of <parameter>str1</parameter> and
<parameter>str2</parameter> (rather good when compared to
<function>similar_text</function>, which is O(max(n,m)**3),
but still expensive).
</para>
<para>
In its simpelest form the function will take only the two
strings as parameter and will calculate just the number of
insert, replace and delete operations needed to transform
<parameter>str1</parameter> into <parameter>str2</parameter>.
</para>
<para>
A second variant will take three additional parameters that
define the cost of insert, replace and delete operations.
This is more general and adaptive than variant one, but not
as efficient.
</para>
<para>
The third variant (which is not implemented yet) will be
the most general and adaptive, but also the slowest alternative.
It will call a user-supplied function that will determine the
cost for every possible operation.
</para>
<para>
The user-supplied function will be called with the following
arguments:
<itemizedlist>
<listitem>
<simpara>
operation to apply: 'I', 'R' or 'D'
</simpara>
</listitem>
<listitem>
<simpara>
actual character in string 1
</simpara>
</listitem>
<listitem>
<simpara>
actual character in string 2
</simpara>
</listitem>
<listitem>
<simpara>
position in string 1
</simpara>
</listitem>
<listitem>
<simpara>
position in string 2
</simpara>
</listitem>
<listitem>
<simpara>
remaining characters in string 1
</simpara>
</listitem>
<listitem>
<simpara>
remaining characters in string 2
</simpara>
</listitem>
</itemizedlist>
The user-supplied function has to return a positive integer
describing the cost for this particular operation, but it
may decide to use only some of the supplied arguments.
</para>
<para>
The user-supplied function approach offers the possibility to
take into account the relevance of and/or difference between
certain symbols (characters) or even the context those symbols
appear in to determine the cost of insert, replace and delete
operations, but at the cost of loosing all optimizations done
regarding cpu register utilization and cache misses that have
been worked into the other two variants.
</para>
<para>
See also <function>soundex</function>,
<function>similar_text</function>
and <function>metaphone</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ltrim">
<refnamediv>
<refname>ltrim</refname>
<refpurpose>
Strip whitespace from the beginning of a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ltrim</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function strips whitespace from the start of a string and
returns the stripped string. The whitespace
characters it currently strips are: "\n", "\r", "\t",
"\v", "\0",
and a plain space.
</para>
<para>
See also <function>chop</function>, <function>rtrim</function>, and
<function>trim</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.md5">
<refnamediv>
<refname>md5</refname>
<refpurpose>Calculate the md5 hash of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>md5</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Calculates the MD5 hash of <parameter>str</parameter> using the
<ulink url="&url.rfc;rfc1321.html">RSA Data Security, Inc.
MD5 Message-Digest Algorithm</ulink>.
</para>
<para>
See also: <function>crc32</function>
</para>
</refsect1>
</refentry>
<refentry id="function.metaphone">
<refnamediv>
<refname>Metaphone</refname>
<refpurpose>Calculate the metaphone key of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>metaphone</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Calculates the metaphone key of <parameter>str</parameter>.
</para>
<para>
Similar to <function>soundex</function> metaphone creates the
same key for similar sounding words. It's more accurate than
<function>soundex</function> as it knows the basic rules of
English pronunciation. The metaphone generated keys are of
variable length.
</para>
<para>
Metaphone was developed by Lawrence Philips
<lphilips@verity.com>. It is described in ["Practical
Algorithms for Programmers", Binstock & Rex, Addison Wesley,
1995].
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.nl2br">
<refnamediv>
<refname>nl2br</refname>
<refpurpose>Converts newlines to HTML line breaks</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>nl2br</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns <parameter>string</parameter> with '<BR>' inserted
before all newlines.
</para>
<para>
See also <function>htmlspecialchars</function>,
<function>htmlentities</function> and
<function>wordwrap</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ord">
<refnamediv>
<refname>Ord</refname>
<refpurpose>Return ASCII value of character</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>ord</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the ASCII value of the first character of
<parameter>string</parameter>. This function complements
<function>chr</function>.
<example>
<title><function>Ord</function> example</title>
<programlisting role="php">
if (ord ($str) == 10) {
echo "The first character of \$str is a line feed.\n";
}
</programlisting>
</example>
</para>
<simpara>
See also <function>chr</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.parse-str">
<refnamediv>
<refname>parse_str</refname>
<refpurpose>Parses the string into variables</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>parse_str</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>array
<parameter><optional>arr</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Parses <parameter>str</parameter> as if it were the query string
passed via an URL and sets variables in the current scope. If
the second parameter <parameter>arr</parameter> is present,
variables are stored in this variable as an array elements instead.
</para>
<para>
<example>
<title>Using <function>parse_str</function></title>
<programlisting role="php">
$str = "first=value&second[]=this+works&second[]=another";
parse_str($str);
echo $first; /* prints "value" */
echo $second[0]; /* prints "this works" */
echo $second[1]; /* prints "another" */
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.print">
<refnamediv>
<refname>print</refname>
<refpurpose>Output a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef><function>print</function></funcdef>
<paramdef>string <parameter>arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Outputs <parameter>arg</parameter>.
</simpara>
<simpara>
See also: <function>echo</function>, <function>printf</function>,
and <function>flush</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.printf">
<refnamediv>
<refname>printf</refname>
<refpurpose>Output a formatted string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>printf</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>mixed
<parameter><optional>args</optional></parameter>...
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Produces output according to <parameter>format</parameter>, which
is described in the documentation for <function>sprintf</function>.
</simpara>
<simpara>
See also: <function>print</function>, <function>sprintf</function>,
<function>sscanf</function>, <function>fscanf</function>,
and <function>flush</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.quoted-printable-decode">
<refnamediv>
<refname>quoted_printable_decode</refname>
<refpurpose>
Convert a quoted-printable string to an 8 bit string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>quoted_printable_decode</function>
</funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function returns an 8-bit binary string corresponding to the
decoded quoted printable string. This function is similar to
<function>imap_qprint</function>, except this one does not
require the IMAP module to work.
</simpara>
</refsect1>
</refentry>
<refentry id="function.quotemeta">
<refnamediv>
<refname>quotemeta</refname>
<refpurpose>Quote meta characters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>quotemeta</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a version of str with a backslash character
(<literal>\</literal>) before every character that is among
these: <screen>. \\ + * ? [ ^ ] ( $ )</screen>
</para>
<simpara>
See also <function>addslashes</function>,
<function>htmlentities</function>,
<function>htmlspecialchars</function>,
<function>nl2br</function>, and
<function>stripslashes</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.rtrim">
<refnamediv>
<refname>rtrim</refname>
<refpurpose>Remove trailing whitespace.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>rtrim</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcsynopsis>
<para>
Returns the argument string without trailing whitespace,
including newlines. This is an alias for <function>chop</function>.
<example>
<title><function>rtrim</function> example</title>
<programlisting role="php">
$trimmed = rtrim ($line);
</programlisting>
</example>
</para>
<para>
See also <function>trim</function>, <function>ltrim</function>, and
<function>rtrim</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sscanf">
<refnamediv>
<refname>sscanf</refname>
<refpurpose>Parses input from a string according to a format</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>sscanf</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>string
<parameter><optional>var1</optional></parameter>...
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The function <function>sscanf</function> is the input analog of
<function>printf</function>. <function>Sscanf</function> reads from
the string <parameter>str</parameter> and interprets it according to
the specified <parameter>format</parameter>. If only two parameters were
passed to this function, the values parsed will be returned as an array.
<example>
<title><function>Sscanf</function> Example</title>
<programlisting role="php">
// getting the serial number
$serial = sscanf("SN/2350001","SN/%d");
// and the date of manufacturing
$mandate = "January 01 2000";
list($month, $day, $year) = sscanf($mandate,"%s %d %d");
echo "Item $serial was manufactured on: $year-".substr($month,0,3)."-$day\n";
</programlisting>
</example>
If optional parameters are passed, the function will return the number of
assigned values. The optional parameters must be passed by reference.
<example>
<title><function>Sscanf</function> - using optional parameters</title>
<programlisting role="php">
// get author info and generate DocBook entry
$auth = "24\tLewis Carroll";
$n = sscanf($auth,"%d\t%s %s", &$id, &$first, &$last);
echo "<author id='$id'>
<firstname>$first</firstname>
<surname>$last</surname>
</author>\n";
</programlisting>
</example>
</para>
<para>
See also: <function>fscanf</function>, <function>printf</function>,
and <function>sprintf</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.setlocale">
<refnamediv>
<refname>setlocale</refname>
<refpurpose>Set locale information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>setlocale</function></funcdef>
<paramdef>string <parameter>category</parameter></paramdef>
<paramdef>string <parameter>locale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<parameter>Category</parameter> is a string specifying the
category of the functions affected by the locale setting:
<itemizedlist>
<listitem>
<simpara>
LC_ALL for all of the below
</simpara>
</listitem>
<listitem>
<simpara>
LC_COLLATE for string comparison - not currently implemented in PHP
</simpara>
</listitem>
<listitem>
<simpara>
LC_CTYPE for character classification and conversion, for
example <function>strtoupper</function>
</simpara>
</listitem>
<listitem>
<simpara>
LC_MONETARY for localeconv() - not currently implemented in
PHP
</simpara>
</listitem>
<listitem>
<simpara>
LC_NUMERIC for decimal separator
</simpara>
</listitem>
<listitem>
<simpara>
LC_TIME for date and time formatting with
<function>strftime</function>
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
If <parameter>locale</parameter> is the empty string
<literal>""</literal>, the locale names will be set from the
values of environment variables with the same names as the above
categories, or from "LANG".
</para>
<para>
If locale is zero or <literal>"0"</literal>, the locale setting
is not affected, only the current setting is returned.
</para>
<para>
Setlocale returns the new current locale, or false if the locale
functionality is not implemented in the plattform, the specified
locale does not exist or the category name is invalid.
An invalid category name also causes a warning message.
</para>
</refsect1>
</refentry>
<refentry id="function.similar-text">
<refnamediv>
<refname>similar_text</refname>
<refpurpose>
Calculate the similarity between two strings
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>similar_text</function></funcdef>
<paramdef>string <parameter>first</parameter></paramdef>
<paramdef>string <parameter>second</parameter></paramdef>
<paramdef>double
<parameter><optional>percent</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This calculates the similarity between two strings as described
in Oliver [1993]. Note that this implementation does not use a
stack as in Oliver's pseudo code, but recursive calls which may
or may not speed up the whole process. Note also that the
complexity of this algorithm is O(N**3) where N is the length of
the longest string.
</para>
<para>
By passing a reference as third argument,
<function>similar_text</function> will calculate the similarity
in percent for you. It returns the number of matching chars in
both strings.
</para>
</refsect1>
</refentry>
<refentry id="function.soundex">
<refnamediv>
<refname>soundex</refname>
<refpurpose>Calculate the soundex key of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>soundex</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Calculates the soundex key of <parameter>str</parameter>.
</para>
<para>
Soundex keys have the property that words pronounced similarly
produce the same soundex key, and can thus be used to simplify
searches in databases where you know the pronunciation but not
the spelling. This soundex function returns a string 4 characters
long, starting with a letter.
</para>
<para>
This particular soundex function is one described by Donald Knuth
in "The Art Of Computer Programming, vol. 3: Sorting And
Searching", Addison-Wesley (1973), pp. 391-392.
</para>
<para>
<example>
<title>Soundex Examples</title>
<programlisting role="php">
soundex ("Euler") == soundex ("Ellery") == 'E460';
soundex ("Gauss") == soundex ("Ghosh") == 'G200';
soundex ("Hilbert") == soundex ("Heilbronn") == 'H416';
soundex ("Knuth") == soundex ("Kant") == 'K530';
soundex ("Lloyd") == soundex ("Ladd") == 'L300';
soundex ("Lukasiewicz") == soundex ("Lissajous") == 'L222';
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.sprintf">
<refnamediv>
<refname>sprintf</refname>
<refpurpose>Return a formatted string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>sprintf</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>mixed
<parameter><optional>args</optional></parameter>...
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns a string produced according to the formatting string
<parameter>format</parameter>.
</simpara>
<simpara>
The format string is composed of zero or more directives:
ordinary characters (excluding <literal>%</literal>) that are
copied directly to the result, and <emphasis>conversion
specifications</emphasis>, each of which results in fetching its
own parameter. This applies to both <function>sprintf</function>
and <function>printf</function>.
</simpara>
<para>
Each conversion specification consists of a percent sign
(<literal>%</literal>), followed by one or more of these
elements, in order:
<orderedlist>
<listitem>
<simpara>
An optional <emphasis>padding specifier</emphasis> that says
what character will be used for padding the results to the
right string size. This may be a space character or a
<literal>0</literal> (zero character). The default is to pad
with spaces. An alternate padding character can be specified
by prefixing it with a single quote (<literal>'</literal>).
See the examples below.
</simpara>
</listitem>
<listitem>
<simpara>
An optional <emphasis>alignment specifier</emphasis> that says
if the result should be left-justified or right-justified.
The default is right-justified; a <literal>-</literal>
character here will make it left-justified.
</simpara>
</listitem>
<listitem>
<simpara>
An optional number, a <emphasis>width specifier</emphasis>
that says how many characters (minimum) this conversion should
result in.
</simpara>
</listitem>
<listitem>
<simpara>
An optional <emphasis>precision specifier</emphasis> that says
how many decimal digits should be displayed for floating-point
numbers. This option has no effect for other types than
double. (Another function useful for formatting numbers is
<function>number_format</function>.)
</simpara>
</listitem>
<listitem>
<para>
A <emphasis>type specifier</emphasis> that says what type the
argument data should be treated as. Possible types:
<simplelist>
<member>
<literal>%</literal> - a literal percent character. No
argument is required.
</member>
<member>
<literal>b</literal> - the argument is treated as an
integer, and presented as a binary number.
</member>
<member>
<literal>c</literal> - the argument is treated as an
integer, and presented as the character with that ASCII
value.
</member>
<member>
<literal>d</literal> - the argument is treated as an
integer, and presented as a decimal number.
</member>
<member>
<literal>f</literal> - the argument is treated as a double,
and presented as a floating-point number.
</member>
<member>
<literal>o</literal> - the argument is treated as an
integer, and presented as an octal number.
</member>
<member>
<literal>s</literal> - the argument is treated as and
presented as a string.
</member>
<member>
<literal>x</literal> - the argument is treated as an integer
and presented as a hexadecimal number (with lowercase
letters).
</member>
<member>
<literal>X</literal> - the argument is treated as an integer
and presented as a hexadecimal number (with uppercase
letters).
</member>
</simplelist>
</para>
</listitem>
</orderedlist>
</para>
<simpara>
See also: <function>printf</function>, <function>sscanf</function>,
<function>fscanf</function>, and <function>number_format</function>.
</simpara>
</refsect1>
<refsect1>
<title>Examples</title>
<para>
<example>
<title><function>Sprintf</function>: zero-padded integers</title>
<programlisting role="php">
$isodate = sprintf ("%04d-%02d-%02d", $year, $month, $day);
</programlisting>
</example>
<example>
<title><function>Sprintf</function>: formatting currency</title>
<programlisting role="php">
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf ("%01.2f", $money);
// echo $formatted will output "123.10"
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.strcasecmp">
<refnamediv>
<refname>strcasecmp</refname>
<refpurpose>
Binary safe case-insensitive string comparison
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strcasecmp</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns < 0 if <parameter>str1</parameter> is less than
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
is greater than <parameter>str2</parameter>, and 0 if they are
equal.
<example>
<title><function>strcasecmp</function> example</title>
<programlisting role="php">
$var1 = "Hello";
$var2 = "hello";
if (!strcasecmp ($var1, $var2)) {
echo '$var1 is equal to $var2 in a case-insensitive string comparison';
}
</programlisting>
</example>
</para>
<simpara>
See also <function>ereg</function>, <function>strcmp</function>,
<function>substr</function>, <function>stristr</function>, and
<function>strstr</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.strchr">
<refnamediv>
<refname>strchr</refname>
<refpurpose>
Find the first occurrence of a character
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strchr</function></funcdef>
<paramdef>string <parameter>haystack</parameter></paramdef>
<paramdef>string <parameter>needle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is an alias for <function>strstr</function>, and is
identical in every way.
</para>
</refsect1>
</refentry>
<refentry id="function.strcmp">
<refnamediv>
<refname>strcmp</refname>
<refpurpose>Binary safe string comparison</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strcmp</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns < 0 if <parameter>str1</parameter> is less than
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
is greater than <parameter>str2</parameter>, and 0 if they are
equal.
</simpara>
<simpara>
Note that this comparison is case sensitive.
</simpara>
<simpara>
See also <function>ereg</function>,
<function>strcasecmp</function>, <function>substr</function>,
<function>stristr</function>, <function>strncmp</function>,
and <function>strstr</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.strcspn">
<refnamediv>
<refname>strcspn</refname>
<refpurpose>
Find length of initial segment not matching mask
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strcspn</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the length of the initial segment of
<parameter>str1</parameter> which does <emphasis>not</emphasis>
contain any of the characters in <parameter>str2</parameter>.
</simpara>
<simpara>
See also <function>strspn</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.strip-tags">
<refnamediv>
<refname>strip_tags</refname>
<refpurpose>Strip HTML and PHP tags from a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strip_tags</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string
<parameter><optional>allowable_tags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function tries to strip all HTML and PHP tags from the given
string. It errors on the side of caution in case of incomplete
or bogus tags. It uses the same tag stripping state machine as
the <function>fgetss</function> function.
</para>
<para>
You can use the optional second parameter to specify tags which
should not be stripped.
<note>
<para>
<parameter>Allowable_tags</parameter> was added in PHP 3.0.13,
PHP4B3.
</para>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.stripcslashes">
<refnamediv>
<refname>stripcslashes</refname>
<refpurpose>
Un-quote string quoted with <function>addcslashes</function>
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>stripcslashes</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string with backslashes stripped off. Recognizes
C-like <literal>\n</literal>, <literal>\r</literal> ..., octal
and hexadecimal representation.
<note>
<simpara>
Added in PHP4b3-dev.
</simpara>
</note>
</para>
<simpara>
See also <function>addcslashes</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.stripslashes">
<refnamediv>
<refname>stripslashes</refname>
<refpurpose>
Un-quote string quoted with <function>addslashes</function>
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>stripslashes</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string with backslashes stripped off.
(<literal>\'</literal> becomes <literal>'</literal> and so
on.)
Double backslashes are made into a single backslash.
</para>
<simpara>
See also <function>addslashes</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.stristr">
<refnamediv>
<refname>stristr</refname>
<refpurpose>
Case-insensitive <function>strstr</function>
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>stristr</function></funcdef>
<paramdef>string <parameter>haystack</parameter></paramdef>
<paramdef>string <parameter>needle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns all of <parameter>haystack</parameter> from the first
occurrence of <parameter>needle</parameter> to the end.
<parameter>needle</parameter> and <parameter>haystack</parameter>
are examined in a case-insensitive manner.
</para>
<para>
If <parameter>needle</parameter> is not found, returns false.
</para>
<para>
If <parameter>needle</parameter> is not a string, it is converted
to an integer and applied as the ordinal value of a character.
</para>
<para>
See also <function>strchr</function>,
<function>strrchr</function>, <function>substr</function>, and
<function>ereg</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strlen">
<refnamediv>
<refname>strlen</refname>
<refpurpose>Get string length</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strlen</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the length of <parameter>string</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.strnatcmp">
<refnamediv>
<refname>strnatcmp</refname>
<refpurpose>
String comparisons using a "natural order" algorithm
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strnatcmp</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function implements a comparison algorithm that orders
alphanumeric strings in the way a human being would, this is
described as a "natural ordering". An example of the difference
between this algorithm and the regular computer string sorting
algorithms (used in <function>strcmp</function>) can be seen
below:
<informalexample>
<programlisting>
$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);
</programlisting>
</informalexample>
The code above will generate the following output:
<informalexample>
<programlisting>
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
)
</programlisting>
</informalexample>
For more infomation see: Martin Pool's <ulink
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
page.
</para>
<simpara>
Similar to other string comparison functions, this one returns
< 0 if <parameter>str1</parameter> is less than
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
is greater than <parameter>str2</parameter>, and 0 if they are
equal.
</simpara>
<simpara>
Note that this comparison is case sensitive.
</simpara>
<simpara>
See also <function>ereg</function>,
<function>strcasecmp</function>, <function>substr</function>,
<function>stristr</function>, <function>strcmp</function>,
<function>strncmp</function>, <function>strnatcasecmp</function>,
<function>strstr</function>, <function>natsort</function> and
<function>natcasesort</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.strnatcasecmp">
<refnamediv>
<refname>strnatcasecmp</refname>
<refpurpose>
Case insensitive string comparisons using a "natural order" algorithm
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strnatcasecmp</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function implements a comparison algorithm that orders
alphanumeric strings in the way a human being would. The
behavior of this function is similar to
<function>strnatcmp</function>, except that the comparison is
not case sensitive. For more infomation see: Martin Pool's
<ulink url="&url.strnatcmp;">Natural Order String
Comparison</ulink> page.
</para>
<simpara>
Similar to other string comparison functions, this one returns
< 0 if <parameter>str1</parameter> is less than
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
is greater than <parameter>str2</parameter>, and 0 if they are
equal.
</simpara>
<simpara>
See also <function>ereg</function>,
<function>strcasecmp</function>, <function>substr</function>,
<function>stristr</function>, <function>strcmp</function>,
<function>strncmp</function>, <function>strnatcmp</function>,
and <function>strstr</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.strncmp">
<refnamediv>
<refname>strncmp</refname>
<refpurpose>
Binary safe string comparison of the first n characters
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strncmp</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
<paramdef>int <parameter>len</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is similar to <function>strcmp</function>, with the
difference that you can specify the (upper limit of the) number of
characters (<parameter>len</parameter>) from each string to be
used in the comparison. If any of the strings is shorter than
<parameter>len</parameter>, then the length of that string will be
used for the comparison.
</para>
<simpara>
Returns < 0 if <parameter>str1</parameter> is less than
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
is greater than <parameter>str2</parameter>, and 0 if they are
equal.
</simpara>
<simpara>
Note that this comparison is case sensitive.
</simpara>
<simpara>
See also <function>ereg</function>,
<function>strcasecmp</function>, <function>substr</function>,
<function>stristr</function>, <function>strcmp</function>,
and <function>strstr</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.str-pad">
<refnamediv>
<refname>str_pad</refname>
<refpurpose>Pad a string to a certain length with another string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>str_pad</function></funcdef>
<paramdef>string <parameter>input</parameter></paramdef>
<paramdef>int <parameter>pad_length</parameter></paramdef>
<paramdef>string
<parameter><optional>pad_string</optional></parameter></paramdef>
<paramdef>int
<parameter><optional>pad_type</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This functions pads the <parameter>input</parameter> string on
the left, the right, or both sides to the specifed padding
length. If the optional argument
<parameter>pad_string</parameter> is not supplied, the
<parameter>input</parameter> is padded with spaces, otherwise it
is padded with characters from <parameter>pad_string</parameter>
up to the limit.
</para>
<para>
Optional argument <parameter>pad_type</parameter> can be
STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If
<parameter>pad_type</parameter> is not specified it is assumed to
be STR_PAD_RIGHT.
</para>
<para>
If the value of <parameter>pad_length</parameter> is negative or
less than the length of the input string, no padding takes
place.
</para>
<para>
<example>
<title><function>str_pad</function> example</title>
<programlisting role="php">
$input = "Alien";
print str_pad($input, 10); // produces "Alien "
print str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
print str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.strpos">
<refnamediv>
<refname>strpos</refname>
<refpurpose>
Find position of first occurrence of a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strpos</function></funcdef>
<paramdef>string <parameter>haystack</parameter></paramdef>
<paramdef>string <parameter>needle</parameter></paramdef>
<paramdef>int
<parameter><optional>offset</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the numeric position of the first occurrence of
<parameter>needle</parameter> in the
<parameter>haystack</parameter> string. Unlike the
<function>strrpos</function>, this function can take a full
string as the <parameter>needle</parameter> parameter and the
entire string will be used.
</para>
<para>
If <parameter>needle</parameter> is not found, returns false.
<note>
<para>
It is easy to mistake the return values for "character found at
position 0" and "character not found". Here's how to detect
the difference:
<informalexample>
<programlisting role="php">
// in PHP 4.0b3 and newer:
$pos = strpos ($mystring, "b");
if ($pos === false) { // note: three equal signs
// not found...
}
// in versions older than 4.0b3:
$pos = strpos ($mystring, "b");
if (is_string ($pos) && !$pos) {
// not found...
}
</programlisting>
</informalexample>
</para>
</note>
</para>
<para>
If <parameter>needle</parameter> is not a string, it is converted
to an integer and applied as the ordinal value of a character.
</para>
<para>
The optional <parameter>offset</parameter> parameter allows you
to specify which character in <parameter>haystack</parameter> to
start searching. The position returned is still relative to the
the beginning of <parameter>haystack</parameter>.
</para>
<para>
See also <function>strrpos</function>,
<function>strrchr</function>, <function>substr</function>,
<function>stristr</function>, and <function>strstr</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strrchr">
<refnamediv>
<refname>strrchr</refname>
<refpurpose>
Find the last occurrence of a character in a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strrchr</function></funcdef>
<paramdef>string <parameter>haystack</parameter></paramdef>
<paramdef>string <parameter>needle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns the portion of
<parameter>haystack</parameter> which starts at the last
occurrence of <parameter>needle</parameter> and goes until the
end of <parameter>haystack</parameter>.
</para>
<para>
Returns false if <parameter>needle</parameter> is not found.
</para>
<para>
If <parameter>needle</parameter> contains more than one
character, the first is used.
</para>
<para>
If <parameter>needle</parameter> is not a string, it is converted
to an integer and applied as the ordinal value of a character.
<example>
<title><function>Strrchr</function> example</title>
<programlisting role="php">
// get last directory in $PATH
$dir = substr (strrchr ($PATH, ":"), 1);
// get everything after last newline
$text = "Line 1\nLine 2\nLine 3";
$last = substr (strrchr ($text, 10), 1 );
</programlisting>
</example>
</para>
<para>
See also <function>substr</function>,
<function>stristr</function>, and <function>strstr</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.str-repeat">
<refnamediv>
<refname>str_repeat</refname>
<refpurpose>Repeat a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>str_repeat</function></funcdef>
<paramdef>string <parameter>input</parameter></paramdef>
<paramdef>int <parameter>multiplier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns <parameter>input_str</parameter> repeated
<parameter>multiplier</parameter> times.
<parameter>multiplier</parameter> has to be greater than 0.
</para>
<example>
<title><function>Str_repeat</function> example</title>
<programlisting role="php">
echo str_repeat ("-=", 10);
</programlisting>
</example>
<para>
This will output "-=-=-=-=-=-=-=-=-=-=".
</para>
<note>
<para>
This function was added in PHP 4.0.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.strrev">
<refnamediv>
<refname>strrev</refname>
<refpurpose>Reverse a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strrev</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns <parameter>string</parameter>, reversed.
</para>
</refsect1>
</refentry>
<refentry id="function.strrpos">
<refnamediv>
<refname>strrpos</refname>
<refpurpose>
Find position of last occurrence of a char in a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strrpos</function></funcdef>
<paramdef>string <parameter>haystack</parameter></paramdef>
<paramdef>char <parameter>needle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the numeric position of the last occurrence of
<parameter>needle</parameter> in the
<parameter>haystack</parameter> string. Note that the needle in
this case can only be a single character. If a string is passed
as the needle, then only the first character of that string will
be used.
</para>
<para>
If <parameter>needle</parameter> is not found, returns false.
</para>
<para>
If <parameter>needle</parameter> is not a string, it is converted
to an integer and applied as the ordinal value of a character.
</para>
<para>
See also <function>strpos</function>,
<function>strrchr</function>, <function>substr</function>,
<function>stristr</function>, and <function>strstr</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strspn">
<refnamediv>
<refname>strspn</refname>
<refpurpose>
Find length of initial segment matching mask
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>strspn</function></funcdef>
<paramdef>string <parameter>str1</parameter></paramdef>
<paramdef>string <parameter>str2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the length of the initial segment of
<parameter>str1</parameter> which consists entirely of characters
in <parameter>str2</parameter>.
</simpara>
<para>
<informalexample>
<programlisting role="php">
strspn ("42 is the answer, what is the question ...", "1234567890");
</programlisting>
<para>
will return 2 as result.
</para>
</informalexample>
</para>
<simpara>
See also <function>strcspn</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.strstr">
<refnamediv>
<refname>strstr</refname>
<refpurpose>Find first occurrence of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strstr</function></funcdef>
<paramdef>string <parameter>haystack</parameter></paramdef>
<paramdef>string <parameter>needle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns all of <parameter>haystack</parameter> from the first
occurrence of <parameter>needle</parameter> to the end.
</para>
<para>
If <parameter>needle</parameter> is not found, returns false.
</para>
<para>
If <parameter>needle</parameter> is not a string, it is converted
to an integer and applied as the ordinal value of a character.
</para>
<para>
<note>
<para>
Note that this function is case-sensitive. For
case-insensitive searches, use <function>stristr</function>.
</para>
</note>
</para>
<para>
<example>
<title><function>Strstr</function> example</title>
<programlisting role="php">
$email = 'sterling@designmultimedia.com';
$domain = strstr ($email, '@');
print $domain; // prints @designmultimedia.com
</programlisting>
</example>
</para>
<para>
See also <function>stristr</function>,
<function>strrchr</function>, <function>substr</function>, and
<function>ereg</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strtok">
<refnamediv>
<refname>strtok</refname>
<refpurpose>Tokenize string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strtok</function></funcdef>
<paramdef>string <parameter>arg1</parameter></paramdef>
<paramdef>string <parameter>arg2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>strtok</function> is used to tokenize a string. That
is, if you have a string like "This is an example string" you
could tokenize this string into its individual words by using the
space character as the token.
<example>
<title><function>Strtok</function> example</title>
<programlisting role="php">
$string = "This is an example string";
$tok = strtok ($string," ");
while ($tok) {
echo "Word=$tok<br>";
$tok = strtok (" ");
}
</programlisting>
</example>
</para>
<para>
Note that only the first call to strtok uses the string argument.
Every subsequent call to strtok only needs the token to use, as
it keeps track of where it is in the current string. To start
over, or to tokenize a new string you simply call strtok with the
string argument again to initialize it. Note that you may put
multiple tokens in the token parameter. The string will be
tokenized when any one of the characters in the argument are
found.
</para>
<para>
Also be careful that your tokens may be equal to "0". This
evaluates to false in conditional expressions.
</para>
<para>
See also <function>split</function> and
<function>explode</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strtolower">
<refnamediv>
<refname>strtolower</refname>
<refpurpose>Make a string lowercase</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strtolower</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns <parameter>string</parameter> with all alphabetic
characters converted to lowercase.
</para>
<para>
Note that 'alphabetic' is determined by the current locale. This
means that in i.e. the default "C" locale, characters such as
umlaut-A (Ä) will not be converted.
</para>
<example>
<title><function>Strtolower</function> example</title>
<programlisting role="php">
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtolower($str);
print $str; # Prints mary had a little lamb and she loved it so
</programlisting>
</example>
<para>
See also <function>strtoupper</function>
and <function>ucfirst</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strtoupper">
<refnamediv>
<refname>strtoupper</refname>
<refpurpose>Make a string uppercase</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strtoupper</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns <parameter>string</parameter> with all alphabetic
characters converted to uppercase.
</para>
<para>
Note that 'alphabetic' is determined by the current locale. For
instance, in the default "C" locale characters such as umlaut-a
(ä) will not be converted.
</para>
<example>
<title><function>Strtoupper</function> example</title>
<programlisting role="php">
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper ($str);
print $str; # Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
</programlisting>
</example>
<para>
See also <function>strtolower</function>
and <function>ucfirst</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.str-replace">
<refnamediv>
<refname>str_replace</refname>
<refpurpose>
Replace all occurrences of needle in haystack with str
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>str_replace</function></funcdef>
<paramdef>string <parameter>needle</parameter></paramdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string <parameter>haystack</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function replaces all occurences of
<parameter>needle</parameter> in <parameter>haystack</parameter>
with the given <parameter>str</parameter>. If you don't need
fancy replacing rules, you should always use this function
instead of <function>ereg_replace</function>.</para>
<para>
<example>
<title><function>Str_replace</function> example</title>
<programlisting role="php">
$bodytag = str_replace ("%body%", "black", "<body
text=%body%>");
</programlisting>
</example>
</para>
<para>
This function is binary safe.
</para>
<note>
<para>
<function>Str_replace</function> was added in PHP 3.0.6, but was
buggy up until PHP 3.0.8.
</para>
</note>
<para>
See also <function>ereg_replace</function> and
<function>strtr</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strtr">
<refnamediv>
<refname>strtr</refname>
<refpurpose>Translate certain characters</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strtr</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>string <parameter>from</parameter></paramdef>
<paramdef>string <parameter>to</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function operates on <parameter>str</parameter>, translating
all occurrences of each character in <parameter>from</parameter>
to the corresponding character in <parameter>to</parameter> and
returning the result.
</para>
<para>
If <parameter>from</parameter> and <parameter>to</parameter> are
different lengths, the extra characters in the longer of the two
are ignored.
<example>
<title><function>Strtr</function> example</title>
<programlisting role="php">
$addr = strtr($addr, "äåö", "aao");
</programlisting>
</example>
</para>
<para>
<function>strtr</function> can be called with only two
arguments. If called with two arguments it behaves in a new way:
<parameter>from</parameter> then has to be an array that contains
string -> string pairs that will be replaced in the source
string. <function>strtr</function> will always look for the
longest possible match first and will *NOT* try to replace stuff
that it has already worked on.
</para>
<para>
Examples:
<informalexample>
<programlisting role="php">
$trans = array ("hello" => "hi", "hi" =>
"hello");
echo strtr("hi all, I said hello", $trans) . "\n";
</programlisting>
</informalexample>
This will show: "hello all, I said hi",
</para>
<note>
<simpara>
This feature (two arguments) was added in PHP 4.0.
</simpara>
</note>
<para>
See also <function>ereg_replace</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.substr">
<refnamediv>
<refname>substr</refname>
<refpurpose>Return part of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>substr</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int <parameter>start</parameter></paramdef>
<paramdef>int
<parameter><optional>length</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Substr returns the portion of <parameter>string</parameter>
specified by the <parameter>start</parameter> and
<parameter>length</parameter> parameters.
</para>
<para>
If <parameter>start</parameter> is positive, the returned string
will start at the <parameter>start</parameter>'th position in
<parameter>string</parameter>, counting from zero. For instance,
in the string '<literal>abcdef</literal>', the character at
position <literal>0</literal> is '<literal>a</literal>', the
character at position <literal>2</literal> is
'<literal>c</literal>', and so forth.
</para>
<para>
Examples:
<informalexample>
<programlisting role="php">
$rest = substr ("abcdef", 1); // returns "bcdef"
$rest = substr ("abcdef", 1, 3); // returns "bcd"
</programlisting>
</informalexample>
</para>
<para>
If <parameter>start</parameter> is negative, the returned string
will start at the <parameter>start</parameter>'th character
from the end of <parameter>string</parameter>.</para>
<para>
Examples:
<informalexample>
<programlisting role="php">
$rest = substr ("abcdef", -1); // returns "f"
$rest = substr ("abcdef", -2); // returns "ef"
$rest = substr ("abcdef", -3, 1); // returns "d"
</programlisting>
</informalexample>
</para>
<para>
If <parameter>length</parameter> is given and is positive, the
string returned will end <parameter>length</parameter> characters
from <parameter>start</parameter>. If this would result in a
string with negative length (because the start is past the end of
the string), then the returned string will contain the single
character at <parameter>start</parameter>.
</para>
<para>
If <parameter>length</parameter> is given and is negative, the
string returned will end <parameter>length</parameter> characters
from the end of <parameter>string</parameter>. If this would
result in a string with negative length, then the returned string
will contain the single character at
<parameter>start</parameter>.
</para>
<para>
Examples:
<informalexample>
<programlisting role="php">
$rest = substr ("abcdef", 1, -1); // returns "bcde"
</programlisting>
</informalexample>
</para>
<para>
See also <function>strrchr</function> and
<function>ereg</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.substr-count">
<refnamediv>
<refname>substr_count</refname>
<refpurpose>Count the number of substring occurrences</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>substr_count</function></funcdef>
<paramdef>string <parameter>haystrack</parameter></paramdef>
<paramdef>string <parameter>needle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>substr_count</function> returns the number of times the
<parameter>needle</parameter> substring occurs in the
<parameter>haystack</parameter> string.
</para>
<para>
<example>
<title><function>substr_count</function> example</title>
<programlisting>
print substr_count("This is a test", "is"); // prints out 2
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.substr-replace">
<refnamediv>
<refname>substr_replace</refname>
<refpurpose>Replace text within a portion of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>substr_replace</function></funcdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>string <parameter>replacement</parameter></paramdef>
<paramdef>int <parameter>start</parameter></paramdef>
<paramdef>int
<parameter><optional>length</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>substr_replace</function> replaces the part of
<parameter>string</parameter> delimited by the
<parameter>start</parameter> and (optionally)
<parameter>length</parameter> parameters with the string given in
<parameter>replacement</parameter>. The result is returned.
</para>
<para>
If <parameter>start</parameter> is positive, the replacing will
begin at the <parameter>start</parameter>'th offset into
<parameter>string</parameter>.
</para>
<para>
If <parameter>start</parameter> is negative, the replacing will
begin at the <parameter>start</parameter>'th character from the
end of <parameter>string</parameter>.
</para>
<para>
If <parameter>length</parameter> is given and is positive, it
represents the length of the portion of
<parameter>string</parameter> which is to be replaced. If it is
negative, it represents the number of characters from the end of
<parameter>string</parameter> at which to stop replacing. If it
is not given, then it will default to strlen(
<parameter>string</parameter> ); i.e. end the replacing at the
end of <parameter>string</parameter>.
</para>
<para>
<example>
<title><function>Substr_replace</function> example</title>
<programlisting role="php">
<?php
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var<hr>\n";
/* These two examples replace all of $var with 'bob'. */
echo substr_replace ($var, 'bob', 0) . "<br>\n";
echo substr_replace ($var, 'bob', 0, strlen ($var)) . "<br>\n";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace ($var, 'bob', 0, 0) . "<br>\n";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace ($var, 'bob', 10, -1) . "<br>\n";
echo substr_replace ($var, 'bob', -7, -1) . "<br>\n";
/* Delete 'MNRPQR' from $var. */
echo substr_replace ($var, '', 10, -1) . "<br>\n";
?>
</programlisting>
</example>
</para>
<para>
See also <function>str_replace</function> and
<function>substr</function>.
</para>
<note>
<simpara>
<function>Substr_replace</function> was added in PHP 4.0.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.trim">
<refnamediv>
<refname>trim</refname>
<refpurpose>
Strip whitespace from the beginning and end of a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>trim</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function strips whitespace from the start and the end of a
string and returns the stripped string. The whitespace
characters it currently strips are: "\n", "\r", "\t",
"\v", "\0",
and a plain space.
</para>
<para>
See also <function>chop</function>, <function>rtrim</function> and
<function>ltrim</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ucfirst">
<refnamediv>
<refname>ucfirst</refname>
<refpurpose>Make a string's first character uppercase</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ucfirst</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Capitalizes the first character of <parameter>str</parameter> if
that character is alphabetic.
</para>
<para>
Note that 'alphabetic' is determined by the current locale. For
instance, in the default "C" locale characters such as umlaut-a
(ä) will not be converted.
<example>
<title><function>Ucfirst</function> example</title>
<programlisting role="php">
$text = 'mary had a little lamb and she loved it so.';
$text = ucfirst ($text); // $text is now Mary had a little lamb
// and she loved it so.
</programlisting>
</example>
</para>
<para>
See also <function>strtoupper</function> and
<function>strtolower</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ucwords">
<refnamediv>
<refname>ucwords</refname>
<refpurpose>
Uppercase the first character of each word in a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ucwords</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Capitalizes the first character of each word in
<parameter>str</parameter> if that character is alphabetic.
<example>
<title><function>ucwords</function> example</title>
<programlisting role="php">
$text = "mary had a little lamb and she loved it so.";
$text = ucwords($text); // $text is now: Mary Had A Little
// Lamb And She Loved It So.
</programlisting>
</example>
</para>
<para>
See also <function>strtoupper</function>,
<function>strtolower</function> and <function>ucfirst</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.wordwrap">
<refnamediv>
<refname>wordwrap</refname>
<refpurpose>
Wraps a string to a given number of characters using a string
break character.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>wordwrap</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>int
<parameter><optional>width</optional></parameter>
</paramdef>
<paramdef>string
<parameter><optional>break</optional></parameter>
</paramdef>
<paramdef>int
<parameter><optional>cut</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Wraps the string <parameter>str</parameter> at the column number
specified by the (optional) <parameter>width</parameter>
parameter. The line is broken using the (optional)
<parameter>break</parameter> parameter.
</para>
<para>
<function>wordwrap</function> will automatically wrap at column
75 and break using '\n' (newline) if <parameter>width</parameter>
or <parameter>break</parameter> are not given.
</para>
<para>
If the <parameter>cut</parameter> is set to 1, the string is
always wrapped at the specified width. So if you have a word
that is larger than the given width, it is broken appart.
(See second example).
</para>
<para>
<example>
<title><function>wordwrap</function> example</title>
<programlisting role="php">
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap( $text, 20 );
echo "$newtext\n";
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
The quick brown fox
jumped over the lazy dog.
</programlisting>
</informalexample>
</para>
<para>
<example>
<title><function>wordwrap</function> example</title>
<programlisting role="php">
$text = "A very long woooooooooooord.";
$newtext = wordwrap( $text, 8, "\n", 1);
echo "$newtext\n";
</programlisting>
</example>
</para>
<para>
This example would display:
</para>
<para>
<informalexample>
<programlisting>
A very
long
wooooooo
ooooord.
</programlisting>
</informalexample>
</para>
<para>
See also <function>nl2br</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/swf.xml
+++ phpdoc/nl/functions/swf.xml
<reference id="ref.swf">
<title>Shockwave Flash functions</title>
<titleabbrev>SWF</titleabbrev>
<partintro>
<simpara>
PHP offers the ability to create Shockwave Flash files via Paul
Haeberli's libswf module. You can download libswf at <ulink
url="&url.swf;">&url.swf;</ulink>. Once you have libswf all you
need to do is to configure <option
role="configure">--with-swf[=DIR]</option> 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.
</simpara>
<para>
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:
<example>
<title>SWF example</title>
<programlisting role="php">
<?php
swf_openfile ("test.swf", 256, 256, 30, 1, 1, 1);
swf_ortho2 (-100, 100, -100, 100);
swf_defineline (1, -70, 0, 70, 0, .2);
swf_definerect (4, 60, -10, 70, 0, 0);
swf_definerect (5, -60, 0, -70, 10, 0);
swf_addcolor (0, 0, 0, 0);
swf_definefont (10, "Mod");
swf_fontsize (5);
swf_fontslant (10);
swf_definetext (11, "This be Flash wit PHP!", 1);
swf_pushmatrix ();
swf_translate (-50, 80, 0);
swf_placeobject (11, 60);
swf_popmatrix ();
for ($i = 0; $i < 30; $i++) {
$p = $i/(30-1);
swf_pushmatrix ();
swf_scale (1-($p*.9), 1, 1);
swf_rotate (60*$p, 'z');
swf_translate (20+20*$p, $p/1.5, 0);
swf_rotate (270*$p, 'z');
swf_addcolor ($p, 0, $p/1.2, -$p);
swf_placeobject (1, 50);
swf_placeobject (4, 50);
swf_placeobject (5, 50);
swf_popmatrix ();
swf_showframe ();
}
for ($i = 0; $i < 30; $i++) {
swf_removeobject (50);
if (($i%4) == 0) {
swf_showframe ();
}
}
swf_startdoaction ();
swf_actionstop ();
swf_enddoaction ();
swf_closefile ();
?>
</programlisting>
</example>
It will produce the animation found at the following <ulink
url="&url.swf.test;">url</ulink>.
</para>
<note>
<para>
SWF support was added in PHP 4 RC2.
</para>
</note>
</partintro>
<refentry id="function.swf-openfile">
<refnamediv>
<refname>swf_openfile</refname>
<refpurpose>Open a new Shockwave Flash file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_openfile</function>
</funcdef>
<paramdef>string
<parameter>filename</parameter>
</paramdef>
<paramdef>float
<parameter>width</parameter>
</paramdef>
<paramdef>float
<parameter>height</parameter>
</paramdef>
<paramdef>float
<parameter>framerate</parameter>
</paramdef>
<paramdef>float
<parameter>r</parameter>
</paramdef>
<paramdef>float
<parameter>g</parameter>
</paramdef>
<paramdef>float
<parameter>b</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_openfile</function> function opens a new file
named <parameter>filename</parameter> with a width of
<parameter>width</parameter> and a height of
<parameter>height</parameter> a frame rate of
<parameter>framerate</parameter> and background with a red color
of <parameter>r</parameter> a green color of
<parameter>g</parameter> and a blue color of
<parameter>b</parameter>.
</para>
<para>
The <function>swf_openfile</function> 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).
</para>
</refsect1>
</refentry>
<refentry id="function.swf-closefile">
<refnamediv>
<refname>swf_closefile</refname>
<refpurpose>Close the current Shockwave Flash file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_closefile</function>
</funcdef>
<paramdef>int
<parameter>
<optional>return_file</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Close a file that was opened by the
<function>swf_openfile</function> function. If the
<parameter>return_file</parameter> parameter is set then the contents
of the SWF file are returned from the function.
</para>
<para>
<example>
<title>
Creating a simple flash file based on user input and outputting it
and saving it in a database
</title>
<programlisting role="php">
<?php
// The $text variable is submitted by the
// user
// Global variables for database
// access (used in the swf_savedata() function)
$DBHOST = "localhost";
$DBUSER = "sterling";
$DBPASS = "secret";
swf_openfile ("php://stdout", 256, 256, 30, 1, 1, 1);
swf_definefont (10, "Ligon-Bold");
swf_fontsize (12);
swf_fontslant (10);
swf_definetext (11, $text, 1);
swf_pushmatrix ();
swf_translate (-50, 80, 0);
swf_placeobject (11, 60);
swf_popmatrix ();
swf_showframe ();
swf_startdoaction ();
swf_actionstop ();
swf_enddoaction ();
$data = swf_closefile (1);
$data ?
swf_savedata ($data) :
die ("Error could not save SWF file");
// void swf_savedata (string data)
// Save the generated file a database
// for later retrieval
function swf_savedata ($data)
{
global $DBHOST,
$DBUSER,
$DBPASS;
$dbh = @mysql_connect ($DBHOST, $DBUSER, $DBPASS);
if (!$dbh) {
die (sprintf ("Error [%d]: %s",
mysql_errno (), mysql_error ()));
}
$stmt = "INSERT INTO swf_files (file) VALUES ('$data')";
$sth = @mysql_query ($stmt, $dbh);
if (!$sth) {
die (sprintf ("Error [%d]: %s",
mysql_errno (), mysql_error ()));
}
@mysql_free_result ($sth);
@mysql_close ($dbh);
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.swf-labelframe">
<refnamediv>
<refname>swf_labelframe</refname>
<refpurpose>Label the current frame</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_labelframe</function>
</funcdef>
<paramdef>string
<parameter>name</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Label the current frame with the name given by the
<parameter>name</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-showframe">
<refnamediv>
<refname>swf_showframe</refname>
<refpurpose>Display the current frame</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_showframe</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The swf_showframe function will output the current frame.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-setframe">
<refnamediv>
<refname>swf_setframe</refname>
<refpurpose>Switch to a specified frame</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_setframe</function>
</funcdef>
<paramdef>int
<parameter>framenumber</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_setframe</function> changes the active frame to
the frame specified by <parameter>framenumber</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-getframe">
<refnamediv>
<refname>swf_getframe</refname>
<refpurpose>Get the frame number of the current frame</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>swf_getframe</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_getframe</function> function gets the number of
the current frame.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-mulcolor">
<refnamediv>
<refname>swf_mulcolor</refname>
<refpurpose>
Sets the global multiply color to the rgba value specified
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_mulcolor</function>
</funcdef>
<paramdef>float
<parameter>r</parameter>
</paramdef>
<paramdef>float
<parameter>g</parameter>
</paramdef>
<paramdef>float
<parameter>b</parameter>
</paramdef>
<paramdef>float
<parameter>a</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_mulcolor</function> function sets the global
multiply color to the <parameter>rgba</parameter> color
specified. This color is then used (implicitly) by the
<function>swf_placeobject</function>,
<function>swf_modifyobject</function> and the
<function>swf_addbuttonrecord</function> functions. The color of
the object will be multiplied by the <parameter>rgba</parameter>
values when the object is written to the screen.
</para>
<note>
<para>
The <parameter>rgba</parameter> values can be either positive or
negative.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.swf-addcolor">
<refnamediv>
<refname>swf_addcolor</refname>
<refpurpose>
Set the global add color to the rgba value specified
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_addcolor</function>
</funcdef>
<paramdef>float
<parameter>r</parameter>
</paramdef>
<paramdef>float
<parameter>g</parameter>
</paramdef>
<paramdef>float
<parameter>b</parameter>
</paramdef>
<paramdef>float
<parameter>a</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_addcolor</function> function sets the global
add color to the <parameter>rgba</parameter> color specified.
This color is then used (implicitly) by the
<function>swf_placeobject</function>,
<function>swf_modifyobject</function> and the
<function>swf_addbuttonrecord</function> functions. The color of
the object will be add by the <parameter>rgba</parameter> values
when the object is written to the screen.
</para>
<note>
<para>
The <parameter>rgba</parameter> values can be either positive or
negative.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.swf-placeobject">
<refnamediv>
<refname>swf_placeobject</refname>
<refpurpose>Place an object onto the screen</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_placeobject</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
<paramdef>int
<parameter>depth</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Places the object specified by <parameter>objid</parameter> in
the current frame at a depth of <parameter>depth</parameter>.
The <parameter>objid</parameter> parameter and the
<parameter>depth</parameter> must be between 1 and 65535.
</para>
<para>
This uses the current mulcolor (specified by
<function>swf_mulcolor</function>) and the current addcolor
(specified by <function>swf_addcolor</function>) to color the
object and it uses the current matrix to position the object.
</para>
<note>
<para>
Full RGBA colors are supported.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.swf-modifyobject">
<refnamediv>
<refname>swf_modifyobject</refname>
<refpurpose>Modify an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_modifyobject</function>
</funcdef>
<paramdef>int
<parameter>depth</parameter>
</paramdef>
<paramdef>int
<parameter>how</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Updates the position and/or color of the object at the specified
depth, <parameter>depth</parameter>. The parameter
<parameter>how</parameter> determines what is updated.
<parameter>how</parameter> can either be the constant MOD_MATRIX
or MOD_COLOR or it can be a combination of both
(MOD_MATRIX|MOD_COLOR).
</para>
<para>
MOD_COLOR uses the current mulcolor (specified by the function
<function>swf_mulcolor</function>) and addcolor (specified by the
function <function>swf_addcolor</function>) to color the object.
MOD_MATRIX uses the current matrix to position the object.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-removeobject">
<refnamediv>
<refname>swf_removeobject</refname>
<refpurpose>Remove an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_removeobject</function>
</funcdef>
<paramdef>int
<parameter>depth</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Removes the object at the depth specified by
<parameter>depth</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-nextid">
<refnamediv>
<refname>swf_nextid</refname>
<refpurpose>Returns the next free object id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>swf_nextid</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_nextid</function> function returns the next
available object id.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-startdoaction">
<refnamediv>
<refname>swf_startdoaction</refname>
<refpurpose>
Start a description of an action list for the current frame
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_startdoaction</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_startdoaction</function> function starts the
description of an action list for the current frame. This must
be called before actions are defined for the current frame.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actiongotoframe">
<refnamediv>
<refname>swf_actiongotoframe</refname>
<refpurpose>Play a frame and then stop</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actiongotoframe</function>
</funcdef>
<paramdef>int
<parameter>framenumber</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_actionGotoFrame</function> function will go to
the frame specified by <parameter>framenumber</parameter>, play
it, and then stop.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actiongeturl">
<refnamediv>
<refname>swf_actiongeturl</refname>
<refpurpose>Get a URL from a Shockwave Flash movie</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actiongeturl</function>
</funcdef>
<paramdef>string
<parameter>url</parameter>
</paramdef>
<paramdef>string
<parameter>target</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_actionGetUrl</function> function gets the URL
specified by the parameter <parameter>url</parameter> with the
target <parameter> target</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actionnextframe">
<refnamediv>
<refname>swf_actionnextframe</refname>
<refpurpose>Go foward one frame</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actionnextframe</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Go foward one frame.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actionprevframe">
<refnamediv>
<refname>swf_actionprevframe</refname>
<refpurpose>Go backwards one frame</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actionprevframe</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
</refsect1>
</refentry>
<refentry id="function.swf-actionplay">
<refnamediv>
<refname>swf_actionplay</refname>
<refpurpose>
Start playing the flash movie from the current frame
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actionplay</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Start playing the flash movie from the current frame.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actionstop">
<refnamediv>
<refname>swf_actionstop</refname>
<refpurpose>
Stop playing the flash movie at the current frame
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actionstop</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Stop playing the flash movie at the current frame.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actiontogglequality">
<refnamediv>
<refname>swf_actiontogglequality</refname>
<refpurpose>
Toggle between low and high quality
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actiontogglequality</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Toggle the flash movie between high and low quality.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actionwaitforframe">
<refnamediv>
<refname>swf_actionwaitforframe</refname>
<refpurpose>
Skip actions if a frame has not been loaded
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actionwaitforframe</function>
</funcdef>
<paramdef>int
<parameter>framenumber</parameter>
</paramdef>
<paramdef>int
<parameter>skipcount</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_actionWaitForFrame</function> function will
check to see if the frame, specified by the
<parameter>framenumber</parameter> parameter has been loaded, if
not it will skip the number of actions specified by the
<parameter>skipcount</parameter> parameter. This can be useful
for "Loading..." type animations.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actionsettarget">
<refnamediv>
<refname>swf_actionsettarget</refname>
<refpurpose>Set the context for actions</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actionsettarget</function>
</funcdef>
<paramdef>string
<parameter>target</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_actionSetTarget</function> function sets the
context for all actions. You can use this to control other flash
movies that are currently playing.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-actiongotolabel">
<refnamediv>
<refname>swf_actiongotolabel</refname>
<refpurpose>
Display a frame with the specified label
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_actiongotolabel</function>
</funcdef>
<paramdef>string
<parameter>label</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_actionGotoLabel</function> function displays
the frame with the label given by the
<parameter>label</parameter> parameter and then stops.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-enddoaction">
<refnamediv>
<refname>swf_enddoaction</refname>
<refpurpose>End the current action</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_enddoaction</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
Ends the current action started by the
<function>swf_startdoaction</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-defineline">
<refnamediv>
<refname>swf_defineline</refname>
<refpurpose>Define a line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_defineline</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
<paramdef>float
<parameter>x1</parameter>
</paramdef>
<paramdef>float
<parameter>y1</parameter>
</paramdef>
<paramdef>float
<parameter>x2</parameter>
</paramdef>
<paramdef>float
<parameter>y2</parameter>
</paramdef>
<paramdef>float
<parameter>width</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_defineline</function> defines a line starting
from the x coordinate given by <parameter>x1</parameter> and the
y coordinate given by <parameter>y1 </parameter> parameter. Up
to the x coordinate given by the <parameter>x2</parameter>
parameter and the y coordinate given by the
<parameter>y2</parameter> parameter. It will have a width
defined by the <parameter>width</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-definerect">
<refnamediv>
<refname>swf_definerect</refname>
<refpurpose>Define a rectangle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_definerect</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
<paramdef>float
<parameter>x1</parameter>
</paramdef>
<paramdef>float
<parameter>y1</parameter>
</paramdef>
<paramdef>float
<parameter>x2</parameter>
</paramdef>
<paramdef>float
<parameter>y2</parameter>
</paramdef>
<paramdef>float
<parameter>width</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_definerect</function> defines a rectangle with
an upper left hand coordinate given by the x,
<parameter>x1</parameter>, and the y, <parameter>y1</parameter>.
And a lower right hand coordinate given by the x coordinate,
<parameter>x2</parameter>, and the y coordinate, <parameter>y2
</parameter>. Width of the rectangles border is given by the
<parameter>width</parameter> parameter, if the width is 0.0 then
the rectangle is filled.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-definepoly">
<refnamediv>
<refname>swf_definepoly</refname>
<refpurpose>
Define a polygon
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_definepoly</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
<paramdef>array
<parameter>coords</parameter>
</paramdef>
<paramdef>int
<parameter>npoints</parameter>
</paramdef>
<paramdef>float
<parameter>width</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_definepoly</function> function defines a
polygon given an array of x, y coordinates (the coordinates are
defined in the parameter <parameter>coords</parameter>). The
parameter <parameter>npoints</parameter> is the number of overall
points that are contained in the array given by
<parameter>coords</parameter>. The <parameter>width</parameter>
is the width of the polygon's border, if set to 0.0 the polygon
is filled.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-startshape">
<refnamediv>
<refname>swf_startshape</refname>
<refpurpose>Start a complex shape</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_startshape</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_startshape</function> function starts a complex
shape, with an object id given by the
<parameter>objid</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapelinesold">
<refnamediv>
<refname>swf_shapelinesolid</refname>
<refpurpose>Set the current line style</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapelinesolid</function>
</funcdef>
<paramdef>float
<parameter>r</parameter>
</paramdef>
<paramdef>float
<parameter>g</parameter>
</paramdef>
<paramdef>float
<parameter>b</parameter>
</paramdef>
<paramdef>float
<parameter>a</parameter>
</paramdef>
<paramdef>float
<parameter>width</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_shapeLineSolid</function> function sets the
current line style to the color of the
<parameter>rgba</parameter> parameters and width to the
<parameter>width</parameter> parameter. If 0.0 is given as a
width then no lines are drawn.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapefilloff">
<refnamediv>
<refname>swf_shapefilloff</refname>
<refpurpose>Turns off filling</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapefilloff</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_shapeFillOff</function> function turns off
filling for the current shape.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapefillsolid">
<refnamediv>
<refname>swf_shapefillsolid</refname>
<refpurpose>
Set the current fill style to the specified color
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapefillsolid</function>
</funcdef>
<paramdef>float
<parameter>r</parameter>
</paramdef>
<paramdef>float
<parameter>g</parameter>
</paramdef>
<paramdef>float
<parameter>b</parameter>
</paramdef>
<paramdef>float
<parameter>a</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_shapeFillSolid</function> function sets the
current fill style to solid, and then sets the fill color to the
values of the <parameter>rgba</parameter> parameters.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapefillbitmapclip">
<refnamediv>
<refname>swf_shapefillbitmapclip</refname>
<refpurpose>
Set current fill mode to clipped bitmap
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapefillbitmapclip</function>
</funcdef>
<paramdef>int
<parameter>bitmapid</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the fill to bitmap clipped, empty spaces will be filled by
the bitmap given by the <parameter>bitmapid</parameter>
parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapefillbitmaptile">
<refnamediv>
<refname>swf_shapefillbitmaptile</refname>
<refpurpose>
Set current fill mode to tiled bitmap
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapefillbitmaptile</function>
</funcdef>
<paramdef>int
<parameter>bitmapid</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the fill to bitmap tile, empty spaces will be filled by the
bitmap given by the <parameter>bitmapid</parameter> parameter
(tiled).
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapemoveto">
<refnamediv>
<refname>swf_shapemoveto</refname>
<refpurpose>Move the current position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapemoveto</function>
</funcdef>
<paramdef>float
<parameter>x</parameter>
</paramdef>
<paramdef>float
<parameter>y</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_shapeMoveTo</function> function moves the
current position to the x coordinate given by the
<parameter>x</parameter> parameter and the y position given by
the <parameter>y</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapelineto">
<refnamediv>
<refname>swf_shapelineto</refname>
<refpurpose>Draw a line</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapelineto</function>
</funcdef>
<paramdef>float
<parameter>x</parameter>
</paramdef>
<paramdef>float
<parameter>y</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_shapeLineTo</function> draws a line to the x,y
coordinates given by the <parameter>x</parameter> parameter & the
<parameter>y</parameter> parameter. The current position is then
set to the x,y parameters.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapecurveto">
<refnamediv>
<refname>swf_shapecurveto</refname>
<refpurpose>
Draw a quadratic bezier curve between two points
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapecurveto</function>
</funcdef>
<paramdef>float
<parameter>x1</parameter>
</paramdef>
<paramdef>float
<parameter>y1</parameter>
</paramdef>
<paramdef>float
<parameter>x2</parameter>
</paramdef>
<paramdef>float
<parameter>y2</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_shapecurveto</function> function draws a
quadratic bezier curve from the x coordinate given by
<parameter>x1</parameter> and the y coordinate given by
<parameter>y1</parameter> to the x coordinate given by
<parameter>x2</parameter> and the y coordinate given by
<parameter>y2</parameter>. The current position is then set to
the x,y coordinates given by the <parameter>x2</parameter> and
<parameter>y2</parameter> parameters
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapecurveto3">
<refnamediv>
<refname>swf_shapecurveto3</refname>
<refpurpose>Draw a cubic bezier curve</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapecurveto3</function>
</funcdef>
<paramdef>float
<parameter>x1</parameter>
</paramdef>
<paramdef>float
<parameter>y1</parameter>
</paramdef>
<paramdef>float
<parameter>x2</parameter>
</paramdef>
<paramdef>float
<parameter>y2</parameter>
</paramdef>
<paramdef>float
<parameter>x3</parameter>
</paramdef>
<paramdef>float
<parameter>y3</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Draw a cubic bezier curve using the x,y coordinate pairs
<parameter>x1</parameter>, <parameter>y1</parameter> and
<parameter>x2</parameter>,<parameter>y2</parameter> as off curve
control points and the x,y coordinate
<parameter>x3</parameter>,<parameter> y3</parameter> as an
endpoint. The current position is then set to the x,y coordinate
pair given by
<parameter>x3</parameter>,<parameter>y3</parameter>.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-shapearc">
<refnamediv>
<refname>swf_shapearc</refname>
<refpurpose>Draw a circular arc</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_shapearc</function>
</funcdef>
<paramdef>float
<parameter>x</parameter>
</paramdef>
<paramdef>float
<parameter>y</parameter>
</paramdef>
<paramdef>float
<parameter>r</parameter>
</paramdef>
<paramdef>float
<parameter>ang1</parameter>
</paramdef>
<paramdef>float
<parameter>ang2</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_shapeArc</function> function draws a circular
arc from angle A given by the <parameter>ang1</parameter>
parameter to angle B given by the <parameter>ang2</parameter>
parameter. The center of the circle has an x coordinate given by
the <parameter>x</parameter> parameter and a y coordinate given
by the <parameter>y</parameter>, the radius of the circle is
given by the <parameter>r</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-endshape">
<refnamediv>
<refname>swf_endshape</refname>
<refpurpose>
Completes the definition of the current shape
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_endshape</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_endshape</function> completes the definition of
the current shape.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-definefont">
<refnamediv>
<refname>swf_definefont</refname>
<refpurpose>
Defines a font
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_definefont</function>
</funcdef>
<paramdef>int
<parameter>fontid</parameter>
</paramdef>
<paramdef>string
<parameter>fontname</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_definefont</function> function defines a font
given by the <parameter>fontname</parameter> parameter and gives
it the id specified by the <parameter>fontid</parameter>
parameter. It then sets the font given by <parameter>
fontname</parameter> to the current font.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-setfont">
<refnamediv>
<refname>swf_setfont</refname>
<refpurpose>Change the current font</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_setfont</function>
</funcdef>
<paramdef>int
<parameter>fontid</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_setfont</function> sets the current font to the
value given by the <parameter>fontid</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-fontsize">
<refnamediv>
<refname>swf_fontsize</refname>
<refpurpose>Change the font size</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_fontsize</function>
</funcdef>
<paramdef>float
<parameter>size</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_fontsize</function> function changes the font
size to the value given by the <parameter>size</parameter>
parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-fontslant">
<refnamediv>
<refname>swf_fontslant</refname>
<refpurpose>Set the font slant</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_fontslant</function>
</funcdef>
<paramdef>float
<parameter>slant</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Set the current font slant to the angle indicated by the
<parameter>slant</parameter> parameter. Positive values create a
foward slant, negative values create a negative slant.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-fonttracking">
<refnamediv>
<refname>swf_fonttracking</refname>
<refpurpose>Set the current font tracking</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_fonttracking</function>
</funcdef>
<paramdef>float
<parameter>tracking</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Set the font tracking to the value specified by the
<parameter>tracking</parameter> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-getfontinfo">
<refnamediv>
<refname>swf_getfontinfo</refname>
<refpurpose>
The height in pixels of a capital A and a lowercase x
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array
<function>swf_getfontinfo</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_getfontinfo</function> function returns an
associative array with the following parameters:
<itemizedlist>
<listitem>
<simpara>
Aheight - The height in pixels of a capital A.
</simpara>
</listitem>
<listitem>
<simpara>
xheight - The height in pixels of a lowercase x.
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.swf-definetext">
<refnamediv>
<refname>swf_definetext</refname>
<refpurpose>Define a text string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_definetext</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
<paramdef>string
<parameter>str</parameter>
</paramdef>
<paramdef>int
<parameter>docenter</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Define a text string (the <parameter>str</parameter> parameter)
using the current font and font size. The
<parameter>docenter</parameter> is where the word is centered, if
<parameter>docenter</parameter> is 1, then the word is centered
in x.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-textwidth">
<refnamediv>
<refname>swf_textwidth</refname>
<refpurpose>Get the width of a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>float
<function>swf_textwidth</function>
</funcdef>
<paramdef>string
<parameter>str</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_textwidth</function> function gives the width
of the string, <parameter>str</parameter>, in pixels, using the
current font and font size.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-definebitmap">
<refnamediv>
<refname>swf_definebitmap</refname>
<refpurpose>Define a bitmap</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_definebitmap</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
<paramdef>string
<parameter>image_name</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_definebitmap</function> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-getbitmapinfo">
<refnamediv>
<refname>swf_getbitmapinfo</refname>
<refpurpose>Get information about a bitmap</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array
<function>swf_getbitmapinfo</function>
</funcdef>
<paramdef>int
<parameter>bitmapid</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_getbitmapinfo</function> function returns an
array of information about a bitmap given by the
<parameter>bitmapid</parameter> parameter. The returned array
has the following elements:
<itemizedlist>
<listitem>
<simpara>
"size" - The size in bytes of the bitmap.
</simpara>
</listitem>
<listitem>
<simpara>
"width" - The width in pixels of the bitmap.
</simpara>
</listitem>
<listitem>
<simpara>
"height" - The height in pixels of the bitmap.
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.swf-startsymbol">
<refnamediv>
<refname>swf_startsymbol</refname>
<refpurpose>Define a symbol</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_startsymbol</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Define an object id as a symbol. Symbols are tiny flash movies
that can be played simultaneously. The
<parameter>objid</parameter> parameter is the object id you want
to define as a symbol.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-endsymbol">
<refnamediv>
<refname>swf_endsymbol</refname>
<refpurpose>End the definition of a symbol</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_endsymbol</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_endsymbol</function> function ends the
definition of a symbol that was started by the
<function>swf_startsymbol</function> function.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-startbutton">
<refnamediv>
<refname>swf_startbutton</refname>
<refpurpose>Start the definition of a button</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_startbutton</function>
</funcdef>
<paramdef>int
<parameter>objid</parameter>
</paramdef>
<paramdef>int
<parameter>type</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_startbutton</function> function starts off the
definition of a button. The <parameter>type</parameter>
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.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-addbuttonrecord">
<refnamediv>
<refname>swf_addbuttonrecord</refname>
<refpurpose>
Controls location, appearance and active area of the current button
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_addbuttonrecord</function>
</funcdef>
<paramdef>int
<parameter>states</parameter>
</paramdef>
<paramdef>int
<parameter>shapeid</parameter>
</paramdef>
<paramdef>int
<parameter>depth</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_addbuttonrecord</function> function allows you
to define the specifics of using a button. The first parameter,
<parameter>states</parameter>, 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
<parameter>shapeid</parameter> is the look of the button, this is
usually the object id of the shape of the button. The
<parameter>depth</parameter> parameter is the placement of the
button in the current frame.
<example>
<title>
<function>Swf_addbuttonrecord</function> function example
</title>
<programlisting role="php">
swf_startButton ($objid, TYPE_MENUBUTTON);
swf_addButtonRecord (BSDown|BSOver, $buttonImageId, 340);
swf_onCondition (MenuEnter);
swf_actionGetUrl ("http://www.designmultimedia.com",
"_level1");
swf_onCondition (MenuExit);
swf_actionGetUrl ("", "_level1");
swf_endButton ();
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.swf-oncondition">
<refnamediv>
<refname>swf_oncondition</refname>
<refpurpose>
Describe a transition used to trigger an action list
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_oncondition</function>
</funcdef>
<paramdef>int
<parameter>transition</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_onCondition</function> 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:
<itemizedlist>
<listitem>
<simpara>
IdletoOverUp
</simpara>
</listitem>
<listitem>
<simpara>
OverUptoIdle
</simpara>
</listitem>
<listitem>
<simpara>
OverUptoOverDown
</simpara>
</listitem>
<listitem>
<simpara>
OverDowntoOverUp
</simpara>
</listitem>
<listitem>
<simpara>
IdletoOverDown
</simpara>
</listitem>
<listitem>
<simpara>
OutDowntoIdle
</simpara>
</listitem>
<listitem>
<simpara>
MenuEnter (IdletoOverUp|IdletoOverDown)
</simpara>
</listitem>
<listitem>
<simpara>
MenuExit (OverUptoIdle|OverDowntoIdle)
</simpara>
</listitem>
</itemizedlist>
For TYPE_PUSHBUTTON there are the following options:
<itemizedlist>
<listitem>
<simpara>
IdletoOverUp
</simpara>
</listitem>
<listitem>
<simpara>
OverUptoIdle
</simpara>
</listitem>
<listitem>
<simpara>
OverUptoOverDown
</simpara>
</listitem>
<listitem>
<simpara>
OverDowntoOverUp
</simpara>
</listitem>
<listitem>
<simpara>
OverDowntoOutDown
</simpara>
</listitem>
<listitem>
<simpara>
OutDowntoOverDown
</simpara>
</listitem>
<listitem>
<simpara>
OutDowntoIdle
</simpara>
</listitem>
<listitem>
<simpara>
ButtonEnter (IdletoOverUp|OutDowntoOverDown)
</simpara>
</listitem>
<listitem>
<simpara>
ButtonExit (OverUptoIdle|OverDowntoOutDown)
</simpara>
</listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.swf-endbutton">
<refnamediv>
<refname>swf_endbutton</refname>
<refpurpose>
End the definition of the current button
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_endbutton</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_endButton</function> function ends the
definition of the current button.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-viewport">
<refnamediv>
<refname>swf_viewport</refname>
<refpurpose>Select an area for future drawing</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_viewport</function>
</funcdef>
<paramdef>double
<parameter>xmin</parameter>
</paramdef>
<paramdef>double
<parameter>xmax</parameter>
</paramdef>
<paramdef>double
<parameter>ymin</parameter>
</paramdef>
<paramdef>double
<parameter>ymax</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_viewport</function> function selects an area
for future drawing for <parameter>xmin</parameter> to
<parameter>xmax</parameter> and <parameter>ymin</parameter> to
<parameter>ymax</parameter>, if this function is not called the
area defaults to the size of the screen.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-ortho">
<refnamediv>
<refname>swf_ortho</refname>
<refpurpose>
Defines an orthographic mapping of user coordinates onto the
current viewport
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_ortho</function>
</funcdef>
<paramdef>double
<parameter>xmin</parameter>
</paramdef>
<paramdef>double
<parameter>xmax</parameter>
</paramdef>
<paramdef>double
<parameter>ymin</parameter>
</paramdef>
<paramdef>double
<parameter>ymax</parameter>
</paramdef>
<paramdef>double
<parameter>zmin</parameter>
</paramdef>
<paramdef>double
<parameter>zmax</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_ortho</function> funcion defines a orthographic
mapping of user coordinates onto the current viewport.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-ortho2">
<refnamediv>
<refname>swf_ortho2</refname>
<refpurpose>
Defines 2D orthographic mapping of user coordinates onto the
current viewport
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_ortho2</function>
</funcdef>
<paramdef>double
<parameter>xmin</parameter>
</paramdef>
<paramdef>double
<parameter>xmax</parameter>
</paramdef>
<paramdef>double
<parameter>ymin</parameter>
</paramdef>
<paramdef>double
<parameter>ymax</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_ortho2</function> 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 <function>swf_perspective </function> function can be used.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-perspective">
<refnamediv>
<refname>swf_perspective</refname>
<refpurpose>
Define a perspective projection transformation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_perspective</function>
</funcdef>
<paramdef>double
<parameter>fovy</parameter>
</paramdef>
<paramdef>double
<parameter>aspect</parameter>
</paramdef>
<paramdef>double
<parameter>near</parameter>
</paramdef>
<paramdef>double
<parameter>far</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_perspective</function> function defines a
perspective projection transformation. The
<parameter>fovy</parameter> parameter is field-of-view angle in
the y direction. The <parameter>aspect</parameter> parameter
should be set to the aspect ratio of the viewport that is being
drawn onto. The <parameter>near</parameter> parameter is the
near clipping plane and the <parameter>far</parameter> parameter
is the far clipping plane.
</para>
<note>
<para>
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.
</para>
</note>
</refsect1>
</refentry>
<refentry id="function.swf-polarview">
<refnamediv>
<refname>swf_polarview</refname>
<refpurpose>
Define the viewer's position with polar coordinates
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_polarview</function>
</funcdef>
<paramdef>double
<parameter>dist</parameter>
</paramdef>
<paramdef>double
<parameter>azimuth</parameter>
</paramdef>
<paramdef>double
<parameter>incidence</parameter>
</paramdef>
<paramdef>double
<parameter>twist</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_polarview</function> function defines the
viewer's position in polar coordinates. The
<parameter>dist</parameter> parameter gives the distance between
the viewpoint to the world space origin. The
<parameter>azimuth</parameter> parameter defines the azimuthal
angle in the x,y coordinate plane, measured in distance from the
y axis. The <parameter>incidence</parameter> 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
<parameter>twist</parameter> specifies the amount that the
viewpoint is to be rotated about the line of sight using the
right hand rule.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-lookat">
<refnamediv>
<refname>swf_lookat</refname>
<refpurpose>Define a viewing transformation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_lookat</function>
</funcdef>
<paramdef>double
<parameter>view_x</parameter>
</paramdef>
<paramdef>double
<parameter>view_y</parameter>
</paramdef>
<paramdef>double
<parameter>view_z</parameter>
</paramdef>
<paramdef>double
<parameter>reference_x</parameter>
</paramdef>
<paramdef>double
<parameter>reference_y</parameter>
</paramdef>
<paramdef>double
<parameter>reference_z</parameter>
</paramdef>
<paramdef>double
<parameter>twist</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_lookat</function> function defines a viewing
transformation by giving the viewing position (the parameters
<parameter>view_x</parameter>, <parameter>view_y</parameter>, and
<parameter>view_z</parameter>) and the coordinates of a reference
point in the scene, the reference point is defined by the
<parameter>reference_x</parameter>, <parameter>reference_y
</parameter>, and <parameter>reference_z</parameter> parameters.
The <parameter>twist </parameter> controls the rotation along
with viewer's z axis.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-pushmatrix">
<refnamediv>
<refname>swf_pushmatrix</refname>
<refpurpose>
Push the current transformation matrix back unto the stack
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_pushmatrix</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_pushmatrix</function> function pushes the
current transformation matrix back onto the stack.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-popmatrix">
<refnamediv>
<refname>swf_popmatrix</refname>
<refpurpose>
Restore a previous transformation matrix
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_popmatrix</function>
</funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_popmatrix</function> function pushes the
current transformation matrix back onto the stack.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-scale">
<refnamediv>
<refname>swf_scale</refname>
<refpurpose>Scale the current transformation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_scale</function>
</funcdef>
<paramdef>double
<parameter>x</parameter>
</paramdef>
<paramdef>double
<parameter>y</parameter>
</paramdef>
<paramdef>double
<parameter>z</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_scale</function> scales the x coordinate of the
curve by the value of the <parameter>x</parameter> parameter, the
y coordinate of the curve by the value of the
<parameter>y</parameter> parameter, and the z coordinate of the
curve by the value of the <parameter>z</parameter> parameter.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-translate">
<refnamediv>
<refname>swf_translate</refname>
<refpurpose>Translate the current transformations</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_translate</function>
</funcdef>
<paramdef>double
<parameter>x</parameter>
</paramdef>
<paramdef>double
<parameter>y</parameter>
</paramdef>
<paramdef>double
<parameter>z</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_translate</function> function translates the
current transformation by the <parameter>x</parameter>,
<parameter>y</parameter>, and <parameter>z</parameter> values
given.
</para>
</refsect1>
</refentry>
<refentry id="function.swf-rotate">
<refnamediv>
<refname>swf_rotate</refname>
<refpurpose>Rotate the current transformation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_rotate</function>
</funcdef>
<paramdef>double
<parameter>angle</parameter>
</paramdef>
<paramdef>string
<parameter>axis</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_rotate</function> rotates the current
transformation by the angle given by the
<parameter>angle</parameter> parameter around the axis given by
the <parameter>axis</parameter> parameter. Valid values for the
axis are 'x' (the x axis), 'y' (the y axis) or 'z' (the z axis).
</para>
</refsect1>
</refentry>
<refentry id="function.swf-posround">
<refnamediv>
<refname>swf_posround</refname>
<refpurpose>
Enables or Disables the rounding of the translation when objects
are placed or moved
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void
<function>swf_posround</function>
</funcdef>
<paramdef>int
<parameter>round</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
The <function>swf_posround</function> 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 <parameter>round</parameter> 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.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/sybase.xml
+++ phpdoc/nl/functions/sybase.xml
<reference id="ref.sybase">
<title>Sybase functions</title>
<titleabbrev>Sybase</titleabbrev>
<refentry id="function.sybase-affected-rows">
<refnamediv>
<refname>sybase_affected_rows</refname>
<refpurpose>get number of affected rows in last query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_affected_rows</function></funcdef>
<paramdef>int <parameter><optional>link_identifier</optional>
</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: The number of affected rows by the last query.</para>
<para>
<function>sybase_affected_rows</function> 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.</para>
<para>
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 <function>sybase_num_rows</function>.
<note>
<para>
This function is only available using the CT library interface
to Sybase, and not the DB library.
</para>
</note></para>
</refsect1>
</refentry>
<refentry id="function.sybase-close">
<refnamediv>
<refname>sybase_close</refname>
<refpurpose>close Sybase connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_close</function></funcdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>Returns: true on success, false on error
</para>
<para> sybase_close() closes the link to a Sybase database that's
associated with the specified link identifier. If the link
identifier isn't specified, the last opened link is assumed.
</para>
<para> Note that this isn't usually necessary, as non-persistent
open links are automatically closed at the end of the script's
execution.
</para>
<para> sybase_close() will not close persistent links generated by
sybase_pconnect().
</para>
<para> See also: <function>sybase_connect</function>,
<function>sybase_pconnect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-connect">
<refnamediv>
<refname>sybase_connect</refname>
<refpurpose>open Sybase server connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_connect</function></funcdef>
<paramdef>string <parameter>servername</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string
<parameter><optional>charset</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: A positive Sybase link identifier on success, or
false on error.
</para>
<para> 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.
</para>
<para> 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.
</para>
<para> 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 <function>sybase_close</function>.
</para>
<para>See also <function>sybase_pconnect</function>,
<function>sybase_close</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-data-seek">
<refnamediv>
<refname>sybase_data_seek</refname>
<refpurpose>move internal row pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_data_seek</function></funcdef>
<paramdef>int <parameter>result_identifier</parameter></paramdef>
<paramdef>int <parameter>row_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: true on success, false on failure
</para>
<para> sybase_data_seek() moves the internal row pointer of the
Sybase result associated with the specified result identifier to
pointer to the specifyed row number. The next call to
<function>sybase_fetch_row</function> would return that row.
</para>
<para> See also: <function>sybase_data_seek</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-fetch-array">
<refnamediv>
<refname>sybase_fetch_array</refname>
<refpurpose>fetch row as array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_fetch_array</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: An array that corresponds to the fetched row, or
false if there are no more rows.
</para>
<para>
sybase_fetch_array() is an extended version of
<function>sybase_fetch_row</function>. 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.
</para>
<para>
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.</para>
<para>
For further details, also see
<function>sybase_fetch_row</function>
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-fetch-field">
<refnamediv>
<refname>sybase_fetch_field</refname>
<refpurpose>get field information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>object <function>sybase_fetch_field</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an object containing field information.
</para>
<para>
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 retreived by
sybase_fetch_field() is retreived.
</para>
<para>
The properties of the object are:
</para>
<itemizedlist>
<listitem><simpara>
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.
</simpara></listitem>
<listitem><simpara>
column_source - the table from which the column was taken
</simpara></listitem>
<listitem><simpara>
max_length - maximum length of the column
</simpara></listitem>
<listitem><simpara>
numeric - 1 if the column is numeric
</simpara></listitem>
</itemizedlist>
<para>
See also <function>sybase_field_seek</function>
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-fetch-object">
<refnamediv>
<refname>sybase_fetch_object</refname>
<refpurpose>fetch row as object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_fetch_object</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: An object with properties that correspond to the
fetched row, or false if there are no more rows.
</para>
<para> sybase_fetch_object() is similar to
<function>sybase_fetch_array</function>, 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).</para>
<para>
Speed-wise, the function is identical to
<function>sybase_fetch_array</function>, and almost as quick as
<function>sybase_fetch_row</function> (the difference is
insignificant).
</para>
<para> See also: <function>sybase_fetch-array</function> and
<function>sybase_fetch-row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-fetch-row">
<refnamediv>
<refname>sybase_fetch_row</refname>
<refpurpose>get row as enumerated array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>sybase_fetch_row</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: An array that corresponds to the fetched row, or
false if there are no more rows.
</para>
<para>
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.
</para>
<para>
Subsequent call to sybase_fetch_rows() would return the next row
in the result set, or false if there are no more rows.
</para>
<para>
See also: <function>sybase_fetch_array</function>,
<function>sybase_fetch_object</function>,
<function>sybase_data_seek</function>,
<function>sybase_fetch_lengths</function>, and
<function>sybase_result</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-field-seek">
<refnamediv>
<refname>sybase_field_seek</refname>
<refpurpose>set field offset</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_field_seek</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>field_offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Seeks to the specified field offset. If the next call to
<function>sybase_fetch_field</function> won't include a field
offset, this field would be returned.</para>
<para></para>
<para>
See also: <function>sybase_fetch_field</function>.</para>
</refsect1>
</refentry>
<refentry id="function.sybase-free-result">
<refnamediv>
<refname>sybase_free_result</refname>
<refpurpose>free result memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_free_result</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>sybase_free_result</function> 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 <function>sybase_free_result</function>
with the result identifier as an argument and the associated
result memory will be freed.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-num-fields">
<refnamediv>
<refname>sybase_num_fields</refname>
<refpurpose>get number of fields in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_num_fields</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> sybase_num_fields() returns the number of fields in a result
set.
</para>
<para>
See also:
<function>sybase_db_query</function>,
<function>sybase_query</function>,
<function>sybase_fetch_field</function>,
<function>sybase_num_rows</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-num-rows">
<refnamediv>
<refname>sybase_num_rows</refname>
<refpurpose>get number of rows in result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_num_rows</function></funcdef>
<paramdef>string <parameter>result</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
sybase_num_rows() returns the number of rows in a result set.
</para>
<para>
See also:
<function>sybase_db_query</function>,
<function>sybase_query</function> and,
<function>sybase_fetch_row</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-pconnect">
<refnamediv>
<refname>sybase_pconnect</refname>
<refpurpose>open persistent Sybase connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_pconnect</function></funcdef>
<paramdef>string <parameter>servername</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string
<parameter><optional>charset</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: A positive Sybase persistent link identifier on success,
or false on error</para>
<para>
sybase_pconnect() acts very much like
<function>sybase_connect</function> with two major differences.</para>
<para>
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.</para>
<para>
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 (<function>sybase_close</function> will not
close links established by <literal>sybase_pconnect()</literal>).</para>
<para>
This type of links is therefore called 'persistent'.</para>
</refsect1>
</refentry>
<refentry id="function.sybase-query">
<refnamediv>
<refname>sybase_query</refname>
<refpurpose>send Sybase query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_query</function></funcdef>
<paramdef>string <parameter>query</parameter></paramdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: A positive Sybase result identifier on success, or
false on error.
</para>
<para> 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 <function>sybase_connect</function> was
called, and use it.
</para>
<para>
See also:
<function>sybase_db_query</function>,
<function>sybase_select_db</function>, and
<function>sybase_connect</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-result">
<refnamediv>
<refname>sybase_result</refname>
<refpurpose>get result data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_result</function></funcdef>
<paramdef>int <parameter>result</parameter></paramdef>
<paramdef>int <parameter>row</parameter></paramdef>
<paramdef>mixed <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: The contents of the cell at the row and offset in
the specified Sybase result set.
</para>
<para>
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.
</para>
<para>
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.
</para>
<para>
Recommended high-performance alternatives:
<function>sybase_fetch_row</function>,
<function>sybase_fetch_array</function>, and
<function>sybase_fetch_object</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.sybase-select-db">
<refnamediv>
<refname>sybase_select_db</refname>
<refpurpose>select Sybase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>sybase_select_db</function></funcdef>
<paramdef>string <parameter>database_name</parameter></paramdef>
<paramdef>int <parameter>link_identifier</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para> Returns: true on success, false on error
</para>
<para> 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 <function>sybase_connect</function> was called, and use it.
</para>
<para>
Every subsequent call to <function>sybase_query</function> will be
made on the active database.
</para>
<para> See also:
<function>sybase_connect</function>,
<function>sybase_pconnect</function>, and
<function>sybase_query</function>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/uodbc.xml
+++ phpdoc/nl/functions/uodbc.xml
<reference id="ref.odbc">
<title>Unified ODBC functions</title>
<titleabbrev>ODBC</titleabbrev>
<partintro>
<simpara>
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.
</simpara>
<simpara>
The following databases are supported by the Unified ODBC
functions: <ulink url="&url.adabas;">Adabas D</ulink>, <ulink
url="&url.ibmdb2;">IBM DB2</ulink>, <ulink
url="&url.iodbc;">iODBC</ulink>, <ulink
url="&url.solid;">Solid</ulink>, and <ulink
url="&url.sybase;">Sybase SQL Anywhere</ulink>.
</simpara>
<simpara>
Please see the <link
linkend="database-support-options">Installation on Unix
Systems</link> chapter for more information about configuring PHP
with these databases.
</simpara>
<note>
<simpara>
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.
</simpara>
</note>
</partintro>
<refentry id="function.odbc-autocommit">
<refnamediv>
<refname>odbc_autocommit</refname>
<refpurpose>Toggle autocommit behaviour</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_autocommit</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>int
<parameter><optional>OnOff</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Without the <parameter>OnOff</parameter> parameter, this function
returns auto-commit status for
<parameter>connection_id</parameter>. True is returned if
auto-commit is on, false if it is off or an error occurs.
</para>
<para>
If <parameter>OnOff</parameter> is true, auto-commit is enabled,
if it is false auto-commit is disabled. Returns
<literal>true</literal> on success, <literal>false</literal> on
failure.
</para>
<para>
By default, auto-commit is on for a connection. Disabling
auto-commit is equivalent with starting a transaction.
</para>
<simpara>
See also
<function>odbc_commit</function> and
<function>odbc_rollback</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-binmode">
<refnamediv>
<refname>odbc_binmode</refname>
<refpurpose>Handling of binary column data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_binmode</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>mode</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
(ODBC SQL types affected: BINARY, VARBINARY, LONGVARBINARY)
</para>
<itemizedlist>
<listitem>
<simpara>
ODBC_BINMODE_PASSTHRU: Passthru BINARY data
</simpara>
</listitem>
<listitem>
<simpara>
ODBC_BINMODE_RETURN: Return as is
</simpara>
</listitem>
<listitem>
<simpara>
ODBC_BINMODE_CONVERT: Convert to char and return
</simpara>
</listitem>
</itemizedlist>
<para>
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 <literal>"01"</literal> and a binary 11111111 is
converted to <literal>"FF"</literal>.
<table>
<title>LONGVARBINARY handling</title>
<tgroup cols="3">
<thead>
<row>
<entry>binmode</entry>
<entry>longreadlen</entry>
<entry>result</entry>
</row>
</thead>
<tbody>
<row>
<entry>ODBC_BINMODE_PASSTHRU</entry>
<entry>0</entry>
<entry>passthru</entry>
</row>
<row>
<entry>ODBC_BINMODE_RETURN</entry>
<entry>0</entry>
<entry>passthru</entry>
</row>
<row>
<entry>ODBC_BINMODE_CONVERT</entry>
<entry>0</entry>
<entry>passthru</entry>
</row>
<row>
<entry>ODBC_BINMODE_PASSTHRU</entry>
<entry>0</entry>
<entry>passthru</entry>
</row>
<row>
<entry>ODBC_BINMODE_PASSTHRU</entry>
<entry>>0</entry>
<entry>passthru</entry>
</row>
<row>
<entry>ODBC_BINMODE_RETURN</entry>
<entry>>0</entry>
<entry>return as is</entry>
</row>
<row>
<entry>ODBC_BINMODE_CONVERT</entry>
<entry>>0</entry>
<entry>return as char</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
If <function>odbc_fetch_into</function> is used, passthru means
that an empty string is returned for these columns.
</para>
<para>
If <parameter>result_id</parameter> is <literal>0</literal>, the
settings apply as default for new results.
<note>
<simpara>
Default for longreadlen is <literal>4096</literal> and binmode
defaults to <literal>ODBC_BINMODE_RETURN</literal>. Handling
of binary long columns is also affected by
<function>odbc_longreadlen</function>
</simpara>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-close">
<refnamediv>
<refname>odbc_close</refname>
<refpurpose>Close an ODBC connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>odbc_close</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_close</function> will close down the connection to
the database server associated with the given connection
identifier.
<note>
<simpara>
This function will fail if there are open transactions on this
connection. The connection will remain open in this case.
</simpara>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-close-all">
<refnamediv>
<refname>odbc_close_all</refname>
<refpurpose>Close all ODBC connections</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>odbc_close_all</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_close_all</function> will close down all
connections to database server(s).
<note>
<simpara>
This function will fail if there are open transactions on a
connection. This connection will remain open in this case.
</simpara>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-commit">
<refnamediv>
<refname>odbc_commit</refname>
<refpurpose>Commit an ODBC transaction</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_commit</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns: <literal>true</literal> on success,
<literal>false</literal> on failure. All pending transactions on
<parameter>connection_id</parameter> are committed.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-connect">
<refnamediv>
<refname>odbc_connect</refname>
<refpurpose>Connect to a datasource</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_connect</function></funcdef>
<paramdef>string <parameter>dsn</parameter></paramdef>
<paramdef>string <parameter>user</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>int
<parameter><optional>cursor_type</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an ODBC connection id or 0 (<literal>false</literal>) on
error.
</para>
<simpara>
The connection id returned by this functions is needed by other
ODBC functions. You can have multiple connections open at once.
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.
</simpara>
<simpara>
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
<function>odbc_fetch_row</function>. SQL_CUR_USE_ODBC might help
in that case, too.
</simpara>
<simpara>
The following constants are defined for cursortype:
</simpara>
<para>
<itemizedlist>
<listitem>
<simpara>
SQL_CUR_USE_IF_NEEDED
</simpara>
</listitem>
<listitem>
<simpara>
SQL_CUR_USE_ODBC
</simpara>
</listitem>
<listitem>
<simpara>
SQL_CUR_USE_DRIVER
</simpara>
</listitem>
<listitem>
<simpara>
SQL_CUR_DEFAULT
</simpara></listitem>
</itemizedlist>
</para>
<simpara>
For persistent connections see
<function>odbc_pconnect</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-cursor">
<refnamediv>
<refname>odbc_cursor</refname>
<refpurpose>Get cursorname</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>odbc_cursor</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
odbc_cursor will return a cursorname for the given result_id.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-do">
<refnamediv>
<refname>odbc_do</refname>
<refpurpose>Synonym for <function>odbc_exec</function></refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_do</function></funcdef>
<paramdef>int <parameter>conn_id</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Odbc_do</function> will execute a query on the given
connection.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-exec">
<refnamediv>
<refname>odbc_exec</refname>
<refpurpose>Prepare and execute a SQL statement</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_exec</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string <parameter>query_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns <literal>false</literal> on error. Returns an ODBC
result identifier if the SQL command was executed successfully.
</para>
<para>
<function>odbc_exec</function> will send an SQL statement to the
database server specified by
<parameter>connection_id</parameter>. This parameter must be a
valid identifier returned by <function>odbc_connect</function> or
<function>odbc_pconnect</function>.
</para>
<simpara>
See also: <function>odbc_prepare</function> and
<function>odbc_execute</function> for multiple execution of SQL
statements.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-execute">
<refnamediv>
<refname>odbc_execute</refname>
<refpurpose>Execute a prepared statement</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_execute</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>array
<parameter><optional>parameters_array</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Executes a statement prepared with
<function>odbc_prepare</function>. Returns
<literal>true</literal> on successful execution,
<literal>false</literal> otherwise. The array
<parameter>arameters_array</parameter> only needs to
be given if you really have parameters in your statement.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-fetch-into">
<refnamediv>
<refname>odbc_fetch_into</refname>
<refpurpose>Fetch one result row into array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_fetch_into</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int
<parameter><optional>rownumber</optional></parameter></paramdef>
<paramdef>array <parameter>result_array</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of columns in the result;
<literal>false</literal> on error.
<parameter>result_array</parameter> 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.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-fetch-row">
<refnamediv>
<refname>odbc_fetch_row</refname>
<refpurpose>Fetch a row</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_fetch_row</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int
<parameter><optional>row_number</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
If <function>odbc_fetch_row</function> was succesful (there was a
row), <literal>true</literal> is returned. If there are no more
rows, <literal>false</literal> is returned.
</para>
<para>
<function>odbc_fetch_row</function> fetches a row of the data
that was returned by <function>odbc_do</function> /
<function>odbc_exec</function>. After
<function>odbc_fetch_row</function> is called, the fields of that
row can be accessed with <function>odbc_result</function>.
</para>
<para>
If <parameter>row_number</parameter> is not specified,
<function>odbc_fetch_row</function> will try to fetch the next
row in the result set. Calls to
<function>odbc_fetch_row</function> with and without
<parameter>row_number</parameter> can be mixed.
</para>
<para>
To step through the result more than once, you can call
<function>odbc_fetch_row</function> with
<parameter>row_number</parameter> 1, and then continue doing
<function>odbc_fetch_row</function> without
<parameter>row_number</parameter> to review the result. If a
driver doesn't support fetching rows by number, the
<parameter>row_number</parameter> parameter is ignored.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-field-name">
<refnamediv>
<refname>odbc_field_name</refname>
<refpurpose>Get the columnname</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>odbc_field_name</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_field_name</function> will return the name of the
field occupying the given column number in the given ODBC result
identifier. Field numbering starts at 1.
<literal>false</literal> is returned on error.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-field-num">
<refnamediv>
<refname>odbc_field_num</refname>
<refpurpose>Return column number</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_field_num</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>string <parameter>field_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_field_num</function> 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.
<literal>false</literal> is returned on error.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-field-type">
<refnamediv>
<refname>odbc_field_type</refname>
<refpurpose>Datatype of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>odbc_field_type</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_field_type</function> will return the SQL type of
the field referecend by number in the given ODBC result
identifier. Field numbering starts at 1.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-field-len">
<refnamediv>
<refname>odbc_field_len</refname>
<refpurpose>Get the length (precision) of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_field_len</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_field_len</function> will return the length of
the field referecend by number in the given ODBC result
identifier. Field numbering starts at 1.
</para>
<simpara>
See also: <function>odbc_field_scale</function> to get the scale of a
floating point number.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-field-precision">
<refnamediv>
<refname>odbc_field_precision</refname>
<refpurpose>Synonym for <function>odbc_field_len</function></refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>odbc_field_precision</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_field_precision</function> will return the precision
of the field referecend by number in the given ODBC result
identifier.
</para>
<para>
See also: <function>odbc_field_scale</function> to get the scale of a
floating point number.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-field-scale">
<refnamediv>
<refname>odbc_field_scale</refname>
<refpurpose>Get the scale of a field</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>odbc_field_scale</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>field_number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_field_precision</function> will return the scale
of the field referecend by number in the given ODBC result
identifier.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-free-result">
<refnamediv>
<refname>odbc_free_result</refname>
<refpurpose>Free resources associated with a result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_free_result</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Always returns <literal>true</literal>.
</para>
<para>
<function>odbc_free_result</function> 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
<function>odbc_free_result</function>, and the memory associated
with <parameter>result_id</parameter> will be freed.
</para>
<para>
<note>
<simpara>
If auto-commit is disabled (see
<function>odbc_autocommit</function>) and you call
<function>odbc_free_result</function> before commiting, all
pending transactions are rolled back.
</simpara>
</note>
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-longreadlen">
<refnamediv>
<refname>odbc_longreadlen</refname>
<refpurpose>Handling of LONG columns</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_longreadlen</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
(ODBC SQL types affected: LONG, LONGVARBINARY) The number of
bytes returned to PHP is controled by the parameter length. If it
is set to 0, Long column data is passed thru to the
client.
</para>
<note>
<simpara>
Handling of LONGVARBINARY columns is also affected by
<function>odbc_binmode</function>.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.odbc-num-fields">
<refnamediv>
<refname>odbc_num_fields</refname>
<refpurpose>Number of columns in a result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_num_fields</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Odbc_num_fields</function> 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
<function>odbc_exec</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-pconnect">
<refnamediv>
<refname>odbc_pconnect</refname>
<refpurpose>Open a persistent database connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_pconnect</function></funcdef>
<paramdef>string <parameter>dsn</parameter></paramdef>
<paramdef>string <parameter>user</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>int
<parameter><optional>cursor_type</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns an ODBC connection id or 0 (<literal>false</literal>) on
error. This function is much like
<function>odbc_connect</function>, except that the connection is
not really closed when the script has finished. Future requests
for a connection with the same <parameter>dsn</parameter>,
<parameter>user</parameter>, <parameter>password</parameter>
combination (via <function>odbc_connect</function> and
<function>odbc_pconnect</function>) can reuse the persistent
connection.
</para>
<para>
<note>
<simpara>
Persistent connections have no effect if PHP is used as a CGI
program.
</simpara>
</note>
</para>
<para>
For information about the optional cursor_type parameter see the
<function>odbc_connect</function> function. For more information
on persistent connections, refer to the PHP FAQ.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-prepare">
<refnamediv>
<refname>odbc_prepare</refname>
<refpurpose>Prepares a statement for execution</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_prepare</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string <parameter>query_string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns <literal>false</literal> on error.
</para>
<para>
Returns an ODBC result identifier if the SQL command was prepared
successfully. The result identifier can be used later to execute
the statement with <function>odbc_execute</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-num-rows">
<refnamediv>
<refname>odbc_num_rows</refname>
<refpurpose>Number of rows in a result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_num_rows</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>odbc_num_rows</function> will return the number of rows
in an ODBC result. This function will return -1 on error. For
INSERT, UPDATE and DELETE statements
<function>odbc_num_rows</function> returns the number of rows
affected. For a SELECT clause this <literal>can</literal> be
the number of rows available.
</para>
<para>
Note: Using <function>odbc_num_rows</function> to determine the
number of rows available after a SELECT will return -1 with many
drivers.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-result">
<refnamediv>
<refname>odbc_result</refname>
<refpurpose>Get result data</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>odbc_result</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>mixed <parameter>field</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the contents of the field.
</para>
<para>
<parameter>field</parameter> 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:
<informalexample><programlisting>
$item_3 = odbc_result ($Query_ID, 3);
$item_val = odbc_result ($Query_ID, "val");
</programlisting>
</informalexample>
</para>
<para>
The first call to <function>odbc_result</function> returns the
value of the third field in the current record of the query
result. The second function call to
<function>odbc_result</function> 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.
</para>
<para>
Field indices start from 1. Regarding the way binary or
long column data is returned refer to <function>odbc_binmode
</function> and <function>odbc_longreadlen</function>.
<!--
If the requested field contains
binary data or is of datatype LONG,
longer than 4096 bytes, the contents is not
returned, instead it is sent directly to the client. Hint: If you
need to have binary data returned, use the SQL function HEX() to
retrieve the field in hexadecimal notation. E.g. "SELECT
HEX(binary_col) FROM mytable"
-->
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-result-all">
<refnamediv>
<refname>odbc_result_all</refname>
<refpurpose>Print result as HTML table</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_result_all</function></funcdef>
<paramdef>int <parameter>result_id</parameter></paramdef>
<paramdef>string
<parameter><optional>format</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the number of rows in the result or
<literal>false</literal> on error.
</para>
<para>
<function>Odbc_result_all</function> will print all rows from a
result identifier produced by <function>odbc_exec</function>. The
result is printed in HTML table format. With the optional string
argument <parameter>format</parameter>, additional overall table
formatting can be done.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-rollback">
<refnamediv>
<refname>odbc_rollback</refname>
<refpurpose>Rollback a transaction</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_rollback</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Rolls back all pending statements on
<parameter>connection_id</parameter>. Returns
<literal>true</literal> on success, <literal>false</literal> on
failure.
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-setoption">
<refnamediv>
<refname>odbc_setoption</refname>
<refpurpose>
Adjust ODBC settings. Returns false if an error occurs, otherwise
true.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_setoption</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>int <parameter>function</parameter></paramdef>
<paramdef>int <parameter>option</parameter></paramdef>
<paramdef>int <parameter>param</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function allows fiddling with the ODBC options for a
particular connection or query result. It was written to help
find work arounds 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.
</para>
<para>
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.
</para>
<para>
<parameter>ID</parameter> 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.
</para>
<para>
<parameter>Function</parameter> is the ODBC function to use. The
value should be 1 for SQLSetConnectOption() and 2 for
SQLSetStmtOption().
</para>
<para>
Parameter <parameter>option</parameter> is the option to set.</para>
<para>
Parameter <parameter>param</parameter> is the value for the
given <parameter>option</parameter>.
<example>
<title>ODBC Setoption Examples</title>
<programlisting role="php">
// 1. Option 102 of SQLSetConnectOption() is SQL_AUTOCOMMIT.
// Value 1 of SQL_AUTOCOMMIT is SQL_AUTOCOMMIT_ON.
// This example has the same effect as
// odbc_autocommit($conn, true);
odbc_setoption ($conn, 1, 102, 1);
// 2. Option 0 of SQLSetStmtOption() is SQL_QUERY_TIMEOUT.
// This example sets the query to timeout after 30 seconds.
$result = odbc_prepare ($conn, $sql);
odbc_setoption ($result, 2, 0, 30);
odbc_execute ($result);
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-tables">
<refnamediv>
<refname>odbc_tables</refname>
<refpurpose>
Get the list of table names stored in a specific data source.
Returns a result identifier containing the
information.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_tables</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string
<parameter><optional>qualifier</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>owner</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>name</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>types</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Lists all tables in the requested range. Returns an ODBC result
identifier or <literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>TABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>TABLE_OWNER</simpara></listitem>
<listitem><simpara>TABLE_NAME</simpara></listitem>
<listitem><simpara>TABLE_TYPE</simpara></listitem>
<listitem><simpara>REMARKS</simpara></listitem>
</itemizedlist>
</para>
<simpara>
The result set is ordered by TABLE_TYPE, TABLE_QUALIFIER,
TABLE_OWNER and TABLE_NAME.
</simpara>
<para>
The <parameter>owner</parameter> and <parameter>name</parameter>
arguments accept search patterns ('%' to match zero or more
characters and '_' to match a single character).
</para>
<para>
To support enumeration of qualifiers, owners, and table types,
the following special semantics for the
<parameter>qualifier</parameter>, <parameter>owner</parameter>,
<parameter>name</parameter>, and
<parameter>table_type</parameter> are available:
<itemizedlist>
<listitem>
<simpara>
If <parameter>qualifier</parameter> is a single percent
character (%) and <parameter>owner</parameter> and
<parameter>name</parameter> 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.)
</simpara>
</listitem>
<listitem>
<simpara>
If <parameter>owner</parameter> is a single percent character
(%) and <parameter>qualifier</parameter> and
<parameter>name</parameter> 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.)
</simpara>
</listitem>
<listitem>
<simpara>
If <parameter>table_type</parameter> is a single percent
character (%) and <parameter>qualifier</parameter>,
<parameter>owner</parameter> and <parameter>name</parameter>
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.)
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
If <parameter>table_type</parameter> 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,
<function>odbc_tables</function> does not return any results for
that type.
</para>
<simpara>
See also <function>odbc_tableprivileges</function> to retrieve
associated privileges.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-tableprivileges">
<refnamediv>
<refname>odbc_tableprivileges</refname>
<refpurpose>
Lists tables and the privileges associated with each table
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_tableprivileges</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string
<parameter><optional>qualifier</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>owner</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>name</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Lists tables in the requested range and the privileges associated
with each table. Returns an ODBC result identifier or
<literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>TABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>TABLE_OWNER</simpara></listitem>
<listitem><simpara>TABLE_NAME</simpara></listitem>
<listitem><simpara>GRANTOR</simpara></listitem>
<listitem><simpara>GRANTEE</simpara></listitem>
<listitem><simpara>PRIVILEGE</simpara></listitem>
<listitem><simpara>IS_GRANTABLE</simpara></listitem>
</itemizedlist>
</para>
<simpara>
The result set is ordered by TABLE_QUALIFIER, TABLE_OWNER and
TABLE_NAME.
</simpara>
<para>
The <parameter>owner</parameter> and <parameter>name</parameter>
arguments accept search patterns ('%' to match zero or more
characters and '_' to match a single character).
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-columns">
<refnamediv>
<refname>odbc_columns</refname>
<refpurpose>
Lists the column names in specified tables. Returns a result
identifier containing the information.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_columns</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string
<parameter><optional>qualifier</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>owner</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>table_name</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>column_name</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Lists all columns in the requested range. Returns an ODBC result
identifier or <literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>TABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>TABLE_OWNER</simpara></listitem>
<listitem><simpara>TABLE_NAME</simpara></listitem>
<listitem><simpara>COLUMN_NAME</simpara></listitem>
<listitem><simpara>DATA_TYPE</simpara></listitem>
<listitem><simpara>TYPE_NAME</simpara></listitem>
<listitem><simpara>PRECISION</simpara></listitem>
<listitem><simpara>LENGTH</simpara></listitem>
<listitem><simpara>SCALE</simpara></listitem>
<listitem><simpara>RADIX</simpara></listitem>
<listitem><simpara>NULLABLE</simpara></listitem>
<listitem><simpara>REMARKS</simpara></listitem>
</itemizedlist>
</para>
<simpara>
The result set is ordered by TABLE_QUALIFIER, TABLE_OWNER and
TABLE_NAME.
</simpara>
<para>
The <parameter>owner</parameter>,
<parameter>table_name</parameter> and
<parameter>column_name</parameter> arguments accept search
patterns ('%' to match zero or more characters and '_' to match a
single character).
</para>
<simpara>
See also <function>odbc_columnprivileges</function> to retrieve
associated privileges.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-columnprivileges">
<refnamediv>
<refname>odbc_columnprivileges</refname>
<refpurpose>
Returns a result identifier that can be used to fetch a list of
columns and associated privileges
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_columnprivileges</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string
<parameter><optional>qualifier</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>owner</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>table_name</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>column_name</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Lists columns and associated privileges for the given table.
Returns an ODBC result identifier or <literal>false</literal> on
failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>TABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>TABLE_OWNER</simpara></listitem>
<listitem><simpara>TABLE_NAME</simpara></listitem>
<listitem><simpara>GRANTOR</simpara></listitem>
<listitem><simpara>GRANTEE</simpara></listitem>
<listitem><simpara>PRIVILEGE</simpara></listitem>
<listitem><simpara>IS_GRANTABLE</simpara></listitem>
</itemizedlist>
</para>
<simpara>
The result set is ordered by TABLE_QUALIFIER, TABLE_OWNER and
TABLE_NAME.
</simpara>
<para>
The <parameter>column_name</parameter> argument accepts search
patterns ('%' to match zero or more characters and '_' to match a
single character).
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-gettypeinfo">
<refnamediv>
<refname>odbc_gettypeinfo</refname>
<refpurpose>
Returns a result identifier containing information about data
types supported by the data source.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_gettypeinfo</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>int
<parameter><optional>data_type</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Retrieves information about data types supported by the data
source. Returns an ODBC result identifier or
<literal>false</literal> on failure. The optional argument
<parameter>data_type</parameter> can be used to restrict the
information to a single data type.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>TYPE_NAME</simpara></listitem>
<listitem><simpara>DATA_TYPE</simpara></listitem>
<listitem><simpara>PRECISION</simpara></listitem>
<listitem><simpara>LITERAL_PREFIX</simpara></listitem>
<listitem><simpara>LITERAL_SUFFIX</simpara></listitem>
<listitem><simpara>CREATE_PARAMS</simpara></listitem>
<listitem><simpara>NULLABLE</simpara></listitem>
<listitem><simpara>CASE_SENSITIVE</simpara></listitem>
<listitem><simpara>SEARCHABLE</simpara></listitem>
<listitem><simpara>UNSIGNED_ATTRIBUTE</simpara></listitem>
<listitem><simpara>MONEY</simpara></listitem>
<listitem><simpara>AUTO_INCREMENT</simpara></listitem>
<listitem><simpara>LOCAL_TYPE_NAME</simpara></listitem>
<listitem><simpara>MINIMUM_SCALE</simpara></listitem>
<listitem><simpara>MAXIMUM_SCALE</simpara></listitem>
</itemizedlist>
</para>
<simpara>The result set is ordered by DATA_TYPE and TYPE_NAME.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-primarykeys">
<refnamediv>
<refname>odbc_primarykeys</refname>
<refpurpose>
Returns a result identifier that can be used to fetch the column
names that comprise the primary key for a table
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_primarykeys</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string <parameter>qualifier</parameter></paramdef>
<paramdef>string <parameter>owner</parameter></paramdef>
<paramdef>string <parameter>table</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the column names that comprise the primary key for a
table. Returns an ODBC result identifier or
<literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>TABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>TABLE_OWNER</simpara></listitem>
<listitem><simpara>TABLE_NAME</simpara></listitem>
<listitem><simpara>COLUMN_NAME</simpara></listitem>
<listitem><simpara>KEY_SEQ</simpara></listitem>
<listitem><simpara>PK_NAME</simpara></listitem>
</itemizedlist>
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-foreignkeys">
<refnamediv>
<refname>odbc_foreignkeys</refname>
<refpurpose>
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 table
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_foreignkeys</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string <parameter>pk_qualifier</parameter></paramdef>
<paramdef>string <parameter>pk_owner</parameter></paramdef>
<paramdef>string <parameter>pk_table</parameter></paramdef>
<paramdef>string <parameter>fk_qualifier</parameter></paramdef>
<paramdef>string <parameter>fk_owner</parameter></paramdef>
<paramdef>string <parameter>fk_table</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Odbc_foreignkeys</function> retrieves information about
foreign keys. Returns an ODBC result identifier or
<literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>PKTABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>PKTABLE_OWNER</simpara></listitem>
<listitem><simpara>PKTABLE_NAME</simpara></listitem>
<listitem><simpara>PKCOLUMN_NAME</simpara></listitem>
<listitem><simpara>FKTABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>FKTABLE_OWNER</simpara></listitem>
<listitem><simpara>FKTABLE_NAME</simpara></listitem>
<listitem><simpara>FKCOLUMN_NAME</simpara></listitem>
<listitem><simpara>KEY_SEQ</simpara></listitem>
<listitem><simpara>UPDATE_RULE</simpara></listitem>
<listitem><simpara>DELETE_RULE</simpara></listitem>
<listitem><simpara>FK_NAME</simpara></listitem>
<listitem><simpara>PK_NAME</simpara></listitem>
</itemizedlist>
</para>
<simpara>
If <parameter>pk_table</parameter> contains a table name,
<function>odbc_foreignkeys</function> returns a result set
containing the primary key of the specified table and all of the
foreign keys that refer to it.
</simpara>
<simpara>
If <parameter>fk_table</parameter> contains a table name,
<function>odbc_foreignkeys</function> 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.
</simpara>
<simpara>
If both <parameter>pk_table</parameter> and
<parameter>fk_table</parameter> contain table names,
<function>odbc_foreignkeys</function> returns the foreign keys in
the table specified in <parameter>fk_table</parameter> that refer
to the primary key of the table specified in
<parameter>pk_table</parameter>. This should be one key at most.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-procedures">
<refnamediv>
<refname>odbc_procedures</refname>
<refpurpose>
Get the list of procedures stored in a specific data source.
Returns a result identifier containing the information.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_procedures</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string
<parameter><optional>qualifier</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>owner</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>name</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Lists all procedures in the requested range. Returns an ODBC
result identifier or <literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>PROCEDURE_QUALIFIER</simpara></listitem>
<listitem><simpara>PROCEDURE_OWNER</simpara></listitem>
<listitem><simpara>PROCEDURE_NAME</simpara></listitem>
<listitem><simpara>NUM_INPUT_PARAMS</simpara></listitem>
<listitem><simpara>NUM_OUTPUT_PARAMS</simpara></listitem>
<listitem><simpara>NUM_RESULT_SETS</simpara></listitem>
<listitem><simpara>REMARKS</simpara></listitem>
<listitem><simpara>PROCEDURE_TYPE</simpara></listitem>
</itemizedlist>
</para>
<para>
The <parameter>owner</parameter> and <parameter>name</parameter>
arguments accept search patterns ('%' to match zero or more
characters and '_' to match a single character).
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-procedurecolumns">
<refnamediv>
<refname>odbc_procedurecolumns</refname>
<refpurpose>
Retrieve information about parameters to procedures
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_procedurecolumns</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string
<parameter><optional>qualifier</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>owner</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>proc</optional></parameter></paramdef>
<paramdef>string
<parameter><optional>column</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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 <literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>PROCEDURE_QUALIFIER</simpara></listitem>
<listitem><simpara>PROCEDURE_OWNER</simpara></listitem>
<listitem><simpara>PROCEDURE_NAME</simpara></listitem>
<listitem><simpara>COLUMN_NAME</simpara></listitem>
<listitem><simpara>COLUMN_TYPE</simpara></listitem>
<listitem><simpara>DATA_TYPE</simpara></listitem>
<listitem><simpara>TYPE_NAME</simpara></listitem>
<listitem><simpara>PRECISION</simpara></listitem>
<listitem><simpara>LENGTH</simpara></listitem>
<listitem><simpara>SCALE</simpara></listitem>
<listitem><simpara>RADIX</simpara></listitem>
<listitem><simpara>NULLABLE</simpara></listitem>
<listitem><simpara>REMARKS</simpara></listitem>
</itemizedlist>
</para>
<simpara>The result set is ordered by PROCEDURE_QUALIFIER, PROCEDURE_OWNER,
PROCEDURE_NAME and COLUMN_TYPE.
</simpara>
<para>
The <parameter>owner</parameter>, <parameter>proc</parameter> and
<parameter>column</parameter> arguments accept search patterns
('%' to match zero or more characters and '_' to match a single
character).
</para>
</refsect1>
</refentry>
<refentry id="function.odbc-specialcolumns">
<refnamediv>
<refname>odbc_specialcolumns</refname>
<refpurpose>
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 transaction
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_specialcolumns</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>int <parameter>type</parameter></paramdef>
<paramdef>string <parameter>qualifier</parameter></paramdef>
<paramdef>string <parameter>owner</parameter></paramdef>
<paramdef>string <parameter>table</parameter></paramdef>
<paramdef>int <parameter>scope</parameter></paramdef>
<paramdef>int <parameter>nullable</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
When the type argument is SQL_BEST_ROWID,
<function>odbc_specialcolumns</function> returns the
column or columns that uniquely identify each row in the table.
</simpara>
<simpara>
When the type argument is SQL_ROWVER,
<function>odbc_specialcolumns</function> 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.
</simpara>
<simpara>
Returns an ODBC result identifier or <literal>false</literal> on
failure.
</simpara>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>SCOPE</simpara></listitem>
<listitem><simpara>COLUMN_NAME</simpara></listitem>
<listitem><simpara>DATA_TYPE</simpara></listitem>
<listitem><simpara>TYPE_NAME</simpara></listitem>
<listitem><simpara>PRECISION</simpara></listitem>
<listitem><simpara>LENGTH</simpara></listitem>
<listitem><simpara>SCALE</simpara></listitem>
<listitem><simpara>PSEUDO_COLUMN</simpara></listitem>
</itemizedlist>
</para>
<simpara>
The result set is ordered by SCOPE.
</simpara>
</refsect1>
</refentry>
<refentry id="function.odbc-statistics">
<refnamediv>
<refname>odbc_statistics</refname>
<refpurpose>Retrieve statistics about a table</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>odbc_statistics</function></funcdef>
<paramdef>int <parameter>connection_id</parameter></paramdef>
<paramdef>string <parameter>qualifier</parameter></paramdef>
<paramdef>string <parameter>owner</parameter></paramdef>
<paramdef>string <parameter>table_name</parameter></paramdef>
<paramdef>int <parameter>unique</parameter></paramdef>
<paramdef>int <parameter>accuracy</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Get statistics about a table and it's indexes. Returns an ODBC
result identifier or <literal>false</literal> on failure.
</para>
<para>
The result set has the following columns:
<itemizedlist>
<listitem><simpara>TABLE_QUALIFIER</simpara></listitem>
<listitem><simpara>TABLE_OWNER</simpara></listitem>
<listitem><simpara>TABLE_NAME</simpara></listitem>
<listitem><simpara>NON_UNIQUE</simpara></listitem>
<listitem><simpara>INDEX_QUALIFIER</simpara></listitem>
<listitem><simpara>INDEX_NAME</simpara></listitem>
<listitem><simpara>TYPE</simpara></listitem>
<listitem><simpara>SEQ_IN_INDEX</simpara></listitem>
<listitem><simpara>COLUMN_NAME</simpara></listitem>
<listitem><simpara>COLLATION</simpara></listitem>
<listitem><simpara>CARDINALITY</simpara></listitem>
<listitem><simpara>PAGES</simpara></listitem>
<listitem><simpara>FILTER_CONDITION</simpara></listitem>
</itemizedlist>
</para>
<simpara>
The result set is ordered by NON_UNIQUE, TYPE, INDEX_QUALIFIER,
INDEX_NAME and SEQ_IN_INDEX.
</simpara>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/url.xml
+++ phpdoc/nl/functions/url.xml
<reference id="ref.url">
<title>URL Functions</title>
<titleabbrev>URLs</titleabbrev>
<refentry id="function.base64-decode">
<refnamediv>
<refname>base64_decode</refname>
<refpurpose>Decodes data encoded with MIME base64</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>base64_decode</function></funcdef>
<paramdef>string <parameter>encoded_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Base64_decode</function> decodes
<parameter>encoded_data</parameter> and returns the original
data. The returned data may be binary.
</para>
<para>
See also: <function>base64_encode</function>, RFC-2045 section
6.8.
</para>
</refsect1>
</refentry>
<refentry id="function.base64-encode">
<refnamediv>
<refname>base64_encode</refname>
<refpurpose>Encodes data with MIME base64</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>base64_encode</function></funcdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Base64_encode</function> returns
<parameter>data</parameter> encoded with base64. This encoding
is designed to make binary data survive transport through
transport layers that are not 8-bit clean, such as mail bodies.
</para>
<para>
Base64-encoded data takes about 33% more space than the original
data.</para>
<para>
See also:
<function>base64_decode</function>,
<function>chunk_split</function>,
RFC-2045 section 6.8.
</para>
</refsect1>
</refentry>
<refentry id="function.parse-url">
<refnamediv>
<refname>parse_url</refname>
<refpurpose>Parse a URL and return its components</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>parse_url</function></funcdef>
<paramdef>string <parameter>url</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns an associative array returning any of the
various components of the URL that are present. This includes the
"scheme", "host", "port", "user", "pass",
"path", "query", and
"fragment".
</para>
</refsect1>
</refentry>
<refentry id="function.rawurldecode">
<refnamediv>
<refname>rawurldecode</refname>
<refpurpose>Decode URL-encoded strings</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>rawurldecode</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string in which the sequences with percent
(<literal>%</literal>) signs followed by two hex digits have been
replaced with literal characters. For example, the string
<screen>foo%20bar%40baz</screen> decodes into <screen>foo
bar@baz</screen>.
</para>
<simpara>
See also <function>rawurlencode</function>,
<function>urldecode</function>,
<function>urlencode</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.rawurlencode">
<refnamediv>
<refname>rawurlencode</refname>
<refpurpose>URL-encode according to RFC1738</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>rawurlencode</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string in which all non-alphanumeric characters except
<screen>-_.</screen> have been replaced with a percent
(<literal>%</literal>) sign followed by two hex digits. This is
the encoding described in RFC1738 for protecting literal
characters from being interpreted as special URL delimiters, and
for protecting URL's from being mangled by transmission media
with character conversions (like some email systems). For
example, if you want to include a password in an ftp url:
<example>
<title><function>Rawurlencode</function> example 1</title>
<programlisting role="php">
echo '<A HREF="ftp://user:', rawurlencode
('foo @+%/'),
'@ftp.my.com/x.txt">';
</programlisting>
</example>
Or, if you pass information in a path info component of the url:
<example>
<title><function>Rawurlencode</function> example 2</title>
<programlisting role="php">
echo '<A HREF="http://x.com/department_list_script/',
rawurlencode ('sales and marketing/Miami'), '">';
</programlisting>
</example>
</para>
<simpara>
See also <function>rawurldecode</function>,
<function>urldecode</function>,
<function>urlencode</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.urldecode">
<refnamediv>
<refname>urldecode</refname>
<refpurpose>Decodes URL-encoded string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>urldecode</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Decodes any <literal>%<replaceable>##</replaceable></literal>
encoding in the given string. The decoded string is returned.
<example>
<title><function>Urldecode</function> example</title>
<programlisting role="php">
$a = split ('&', $querystring);
$i = 0;
while ($i < count ($a)) {
$b = split ('=', $a [$i]);
echo 'Value for parameter ', htmlspecialchars (urldecode ($b [0])),
' is ', htmlspecialchars (urldecode ($b [1])), "<BR>";
$i++;
}
</programlisting>
</example>
</para>
<para>
See also <function>urlencode</function>,
<function>rawurlencode</function>,
<function>rawurldecode</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.urlencode">
<refnamediv>
<refname>urlencode</refname>
<refpurpose>URL-encodes string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>urlencode</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string in which all non-alphanumeric characters except
<literal>-_.</literal> have been replaced with a percent
(<literal>%</literal>) sign followed by two hex digits and spaces
encoded as plus (<literal>+</literal>) signs. It is encoded the
same way that the posted data from a WWW form is encoded, that is
the same way as in
<literal>application/x-www-form-urlencoded</literal> media type.
This differs from the RFC1738 encoding (see
<function>rawurlencode</function>) 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:
<example>
<title><function>Urlencode</function> example</title>
<programlisting role="php">
echo '<A HREF="mycgi?foo=', urlencode ($userinput),
'">';
</programlisting>
</example>
</para>
<para>Note: Be careful about variables that may match HTML entities.
Things like &amp, &copy and &pound 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: <ulink url="&url.argsep;">&url.argsep;</ulink>
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 &amp; 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
<function>htmlentities</function>(urlencode($data)).
<example>
<title><function>Urlencode/htmlentities</function> example</title>
<programlisting role="php">
echo '<A HREF="mycgi?foo=', htmlentities (urlencode ($userinput) ),
'">';
</programlisting>
</example>
</para>
<para>
See also <function>urldecode</function>,
<function>htmlentities</function>,
<function>rawurldecode</function>,
<function>rawurlencode</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/var.xml
+++ phpdoc/nl/functions/var.xml
<reference id="ref.var">
<title>Variable Functions</title>
<titleabbrev>Variables</titleabbrev>
<refentry id="function.doubleval">
<refnamediv>
<refname>doubleval</refname>
<refpurpose>Get double value of a variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>double <function>doubleval</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the double (floating point) value of
<parameter>var</parameter>.
</simpara>
<para>
<parameter>Var</parameter> may be any scalar type. You cannot use
<function>doubleval</function> on arrays or objects.
<informalexample>
<programlisting role="php">
$var = '122.34343The';
$double_value_of_var = doubleval ($var);
print $double_value_of_var; // prints 122.34343
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>intval</function>,
<function>strval</function>, <function>settype</function> and
<link linkend="language.types.type-juggling">Type
juggling</link>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.empty">
<refnamediv>
<refname>empty</refname>
<refpurpose>Determine whether a variable is set</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>empty</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns false if <parameter>var</parameter> is set and has a
non-empty or non-zero value; true otherwise.
<informalexample>
<programlisting role="php">
$var = 0;
if (empty($var)) { // evaluates true
echo '$var is either 0 or not set at all';
}
if (!isset($var)) { // evaluates false
echo '$var is not set at all';
}
</programlisting>
</informalexample>
</para>
<simpara>
Note that this is meaningless when used on anything which isn't a
variable; i.e. <command>empty (addslashes ($name))</command> has
no meaning since it would be checking whether something which
isn't a variable is a variable with a false value.
</simpara>
<simpara>
See also <function>isset</function> and
<function>unset</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.gettype">
<refnamediv>
<refname>gettype</refname>
<refpurpose>Get the type of a variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gettype</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the type of the PHP variable
<parameter>var</parameter>.
</para>
<para>
Possibles values for the returned string are:
<itemizedlist>
<listitem>
<simpara>"boolean"</simpara>
</listitem>
<listitem>
<simpara>"integer"</simpara>
</listitem>
<listitem>
<simpara>"double"</simpara>
</listitem>
<listitem>
<simpara>"string"</simpara>
</listitem>
<listitem>
<simpara>"array"</simpara>
</listitem>
<listitem>
<simpara>"object"</simpara>
</listitem>
<listitem>
<simpara>"resource"</simpara>
</listitem>
<listitem>
<simpara>"user function"</simpara>
</listitem>
<listitem>
<simpara>"unknown type"</simpara>
</listitem>
</itemizedlist>
</para>
<para>
See also <function>settype</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.intval">
<refnamediv>
<refname>intval</refname>
<refpurpose>Get integer value of a variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>intval</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
<paramdef>int
<parameter><optional>base</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the integer value of <parameter>var</parameter>,
using the specified base for the conversion (the default is
base 10).
</simpara>
<simpara>
<parameter>Var</parameter> may be any scalar type. You cannot use
<function>intval</function> on arrays or objects.
</simpara>
<simpara>
See also <function>doubleval</function>,
<function>strval</function>, <function>settype</function> and
<link linkend="language.types.type-juggling">Type
juggling</link>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.is-array">
<refnamediv>
<refname>is_array</refname>
<refpurpose>Finds whether a variable is an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_array</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if <parameter>var</parameter> is an array, false
otherwise.
</para>
<para>
See also <function>is_double</function>,
<function>is_float</function>,
<function>is_int</function>,
<function>is_integer</function>,
<function>is_real</function>,
<function>is_string</function>,
<function>is_long</function>, and
<function>is_object</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-bool">
<refnamediv>
<refname>is_bool</refname>
<refpurpose>
Finds out whether a variable is a boolean
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>is_bool</function>
</funcdef>
<paramdef>mixed
<parameter>var</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the <parameter>var</parameter> parameter is
a boolean.
</para>
<para>
See also <function>is_array</function>,
<function>is_double</function>,
<function>is_float</function>,
<function>is_int</function>,
<function>is_integer</function>,
<function>is_real</function>,
<function>is_string</function>,
<function>is_long</function>, and
<function>is_object</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-double">
<refnamediv>
<refname>is_double</refname>
<refpurpose>Finds whether a variable is a double</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_double</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if <parameter>var</parameter> is a double,
false otherwise.
</para>
<para>
See also <function>is_array</function>,
<function>is_bool</function>,
<function>is_float</function>,
<function>is_int</function>,
<function>is_integer</function>,
<function>is_real</function>,
<function>is_string</function>,
<function>is_long</function>, and
<function>is_object</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-float">
<refnamediv>
<refname>is_float</refname>
<refpurpose>Finds whether a variable is a float</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_float</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function is an alias for <function>is_double</function>.
</simpara>
<simpara>
See also <function>is_double</function>,
<function>is_bool</function>,
<function>is_real</function>,
<function>is_int</function>,
<function>is_integer</function>,
<function>is_string</function>,
<function>is_object</function>,
<function>is_array</function>, and
<function>is_long</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.is-int">
<refnamediv>
<refname>is_int</refname>
<refpurpose>Find whether a variable is an integer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_int</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function is an alias for <function>is_long</function>.
</simpara>
<simpara>
See also <function>is_bool</function>,
<function>is_double</function>,
<function>is_float</function>,
<function>is_integer</function>,
<function>is_string</function>,
<function>is_real</function>,
<function>is_object</function>,
<function>is_array</function>, and
<function>is_long</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.is-integer">
<refnamediv>
<refname>is_integer</refname>
<refpurpose>Find whether a variable is an integer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_integer</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function is an alias for
<function>is_long</function>.
</simpara>
<simpara>
See also <function>is_bool</function>,
<function>is_double</function>,
<function>is_float</function>,
<function>is_int</function>,
<function>is_string</function>,
<function>is_real</function>,
<function>is_object</function>,
<function>is_array</function>, and
<function>is_long</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.is-long">
<refnamediv>
<refname>is_long</refname>
<refpurpose>Finds whether a variable is an integer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_long</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if <parameter>var</parameter> is an integer (long),
false otherwise.
</para>
<para>
See also <function>is_bool</function>,
<function>is_double</function>,
<function>is_float</function>,
<function>is_int</function>,
<function>is_real</function>,
<function>is_string</function>,
<function>is_object</function>,
<function>is_array</function>, and
<function>is_integer</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-numeric">
<refnamediv>
<refname>is_numeric</refname>
<refpurpose>
Finds whether a variable is a number or a numeric string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_numeric</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if <parameter>var</parameter> is a number or a
numeric string, false otherwise.
</para>
<para>
See also <function>is_bool</function>,
<function>is_double</function>,
<function>is_float</function>,
<function>is_int</function>,
<function>is_real</function>,
<function>is_string</function>,
<function>is_object</function>,
<function>is_array</function>, and
<function>is_integer</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-object">
<refnamediv>
<refname>is_object</refname>
<refpurpose>Finds whether a variable is an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_object</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if <parameter>var</parameter> is an object, false
otherwise.
</para>
<para>
See also <function>is_bool</function>,
<function>is_long</function>,
<function>is_int</function>,
<function>is_integer</function>,
<function>is_float</function>,
<function>is_double</function>,
<function>is_real</function>,
<function>is_string</function>, and
<function>is_array</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.is-real">
<refnamediv>
<refname>is_real</refname>
<refpurpose>Finds whether a variable is a real</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_real</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function is an alias for <function>is_double</function>.
</simpara>
<simpara>
See also <function>is_bool</function>,
<function>is_long</function>,
<function>is_int</function>,
<function>is_integer</function>,
<function>is_float</function>,
<function>is_double</function>,
<function>is_object</function>,
<function>is_string</function>, and
<function>is_array</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.is-resource">
<refnamediv>
<refname>is_resource</refname>
<refpurpose>
Finds whether a variable is a resource
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>is_resource</function>
</funcdef>
<paramdef>mixed
<parameter>var</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>is_resource</function> returns true if the variable
given by the <parameter>var</parameter> parameter is a resource,
otherwise it returns false.
</para>
<para>
Resources are things like file or database result handles that
are allocated and freed by internal PHP functions and that may
need some cleanup when they are no longer in use but haven't been
freed by user code.
</para>
</refsect1>
</refentry>
<refentry id="function.is-string">
<refnamediv>
<refname>is_string</refname>
<refpurpose>Finds whether a variable is a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>is_string</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if <parameter>var</parameter> is a string,
false otherwise.
</para>
<para>
See also <function>is_bool</function>,
<function>is_long</function>,
<function>is_int</function>,
<function>is_integer</function>,
<function>is_float</function>,
<function>is_double</function>,
<function>is_real</function>,
<function>is_object</function>, and
<function>is_array</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.isset">
<refnamediv>
<refname>isset</refname>
<refpurpose>Determine whether a variable is set</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>isset</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns true if <parameter>var</parameter> exists;
false otherwise.
</simpara>
<para>
If a variable has been unset with <function>unset</function>,
it will no longer be <function>isset</function>.
<informalexample>
<programlisting role="php">
$a = "test";
echo isset ($a); // true
unset ($a);
echo isset ($a); // false
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>empty</function> and
<function>unset</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.print-r">
<refnamediv>
<refname>print_r</refname>
<refpurpose>
Prints human-readable information about a variable
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>print_r</function></funcdef>
<paramdef>mixed <parameter>expression</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function displays information about the values of variables
in a way that's readable by humans. If given a string, integer
or double, 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.
</simpara>
<simpara>
Compare <function>print_r</function> to
<function>var_dump</function>.
</simpara>
<para>
<informalexample>
<programlisting role="php">
<?php
$a = array (1, 2, array ("a", "b", "c"));
print_r ($a);
?>
</programlisting>
</informalexample>
</para>
<warning>
<para>
This function will continue forever if given an array or object
that contains a direct or indirect reference to itself or that
contains an array or object on a deeper level that does so.
This is especially true for <literal>print_r($GLOBALS)</literal>,
as <literal>$GLOBALS</literal> is itself a global variable and
contains a reference to itself as such.
</para>
</warning>
</refsect1>
</refentry>
<refentry id="function.serialize">
<refnamediv>
<refname>serialize</refname>
<refpurpose>
Generates a storable representation of a value
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>serialize</function></funcdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Serialize</function> returns a string containing a
byte-stream representation of <parameter>value</parameter> that
can be stored anywhere.
</simpara>
<simpara>
This is useful for storing or passing PHP values around without
losing their type and structure.
</simpara>
<simpara>
To make the serialized string into a PHP value again, use
<function>unserialize</function>. <function>Serialize</function>
handles the types <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> (multidimensional) and
<type>object</type> (object properties will be serialized, but
methods are lost).
</simpara>
<para>
<example>
<title><function>Serialize</function> example</title>
<programlisting role="php">
// $session_data contains a multi-dimensional array with session
// information for the current user. We use serialize() to store
// it in a database at the end of the request.
$conn = odbc_connect ("webdb", "php", "chicken");
$stmt = odbc_prepare ($conn,
"UPDATE sessions SET data = ? WHERE id = ?");
$sqldata = array (serialize($session_data), $PHP_AUTH_USER);
if (!odbc_execute ($stmt, &$sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
if (!odbc_execute($stmt, &$sqldata)) {
/* Something went wrong. Bitch, whine and moan. */
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.settype">
<refnamediv>
<refname>settype</refname>
<refpurpose>Set the type of a variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>settype</function></funcdef>
<paramdef>string <parameter>var</parameter></paramdef>
<paramdef>string <parameter>type</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Set the type of variable <parameter>var</parameter> to
<parameter>type</parameter>.
</para>
<para>
Possibles values of <parameter>type</parameter> are:
<itemizedlist>
<listitem><simpara>"integer"</simpara></listitem>
<listitem><simpara>"double"</simpara></listitem>
<listitem><simpara>"string"</simpara></listitem>
<listitem><simpara>"array"</simpara></listitem>
<listitem><simpara>"object"</simpara></listitem>
</itemizedlist>
</para>
<para>
Returns true if successful; otherwise returns false.
</para>
<para>
See also <function>gettype</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.strval">
<refnamediv>
<refname>strval</refname>
<refpurpose>Get string value of a variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>strval</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Returns the string value of <parameter>var</parameter>.
</simpara>
<simpara>
<parameter>var</parameter> may be any scalar type. You cannot use
<function>strval</function> on arrays or objects.
</simpara>
<simpara>
See also <function>doubleval</function>,
<function>intval</function>, <function>settype</function> and
<link linkend="language.types.type-juggling">Type
juggling</link>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.unserialize">
<refnamediv>
<refname>unserialize</refname>
<refpurpose>
Creates a PHP value from a stored representation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>unserialize</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>unserialize</function> takes a single serialized
variable (see <function>serialize</function>) and converts it
back into a PHP value. The converted value is returned, and can
be an <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> or
<type>object</type>.
If an object was serialized, its methods are not preserved in the
returned value.
</simpara>
<para>
<example>
<title><function>Unserialize</function> example</title>
<programlisting role="php">
// Here, we use unserialize() to load session data from a database
// into $session_data. This example complements the one described
// with <function>serialize</function>.
$conn = odbc_connect ("webdb", "php", "chicken");
$stmt = odbc_prepare ($conn, "SELECT data FROM sessions WHERE id = ?");
$sqldata = array ($PHP_AUTH_USER);
if (!odbc_execute ($stmt, &$sqldata) || !odbc_fetch_into ($stmt, &$tmp)) {
// if the execute or fetch fails, initialize to empty array
$session_data = array();
} else {
// we should now have the serialized data in $tmp[0].
$session_data = unserialize ($tmp[0]);
if (!is_array ($session_data)) {
// something went wrong, initialize to empty array
$session_data = array();
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.unset">
<refnamediv>
<refname>unset</refname>
<refpurpose>Unset a given variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>unset</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
<paramdef>mixed
<parameter><optional>var</optional></parameter></paramdef>
<paramdef><parameter><optional>...</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>unset</function> destroys the specified variables and
returns true.
</para>
<para>
<example>
<title><function>Unset</function> example</title>
<programlisting role="php">
// destroy a single variable
unset ($foo);
// destroy a single element of an array
unset ($bar['quux']);
// destroy more than one variable
unset ($foo1, $foo2, $foo3);
</programlisting>
</example>
</para>
<para>
The behavior of <function>unset</function> inside of a function
can vary depending on what type of variable you are attempting to
destroy.
</para>
<para>
If a globalized variable is <function>unset</function> inside of
a function, only the local variable is destroyed. The variable
in the calling environment will retain the same value as before
<function>unset</function> was called.
<informalexample>
<programlisting role="php">
function destroy_foo() {
global $foo;
unset($foo);
}
$foo = 'bar';
destroy_foo();
echo $foo;
</programlisting>
</informalexample>
The above example would output:
<informalexample>
<programlisting>
bar
</programlisting>
</informalexample>
</para>
<para>
If a variable that is PASSED BY REFERENCE is
<function>unset</function> inside of a function, only the local
variable is destroyed. The variable in the calling environment
will retain the same value as before <function>unset</function>
was called.
<informalexample>
<programlisting role="php">
function foo(&$bar) {
unset($bar);
$bar = "blah";
}
$bar = 'something';
echo "$bar\n";
foo($bar);
echo "$bar\n";
</programlisting>
</informalexample>
The above example would output:
<informalexample>
<programlisting>
something
something
</programlisting>
</informalexample>
</para>
<para>
If a static variable is <function>unset</function> inside of a
function, <function>unset</function> unsets the reference to the
static variable, rather than the static variable itself.
<informalexample>
<programlisting role="php">
function foo() {
static $a;
$a++;
echo "$a\n";
unset($a);
}
foo();
foo();
foo();
</programlisting>
</informalexample>
The above example would output:
<informalexample>
<programlisting>
1
2
3
</programlisting>
</informalexample>
</para>
<para>
If you would like to <function>unset</function> a global variable inside of a
function, you can use the <parameter>$GLOBALS</parameter> array to do so:
<informalexample>
<programlisting role="php">
function foo() {
unset($GLOBALS['bar']);
}
$bar = "something";
foo();
</programlisting>
</informalexample>
</para>
<para>
See also <function>isset</function> and
<function>empty</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.var-dump">
<refnamediv>
<refname>var_dump</refname>
<refpurpose>Dumps information about a variable</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>var_dump</function></funcdef>
<paramdef>mixed <parameter>expression</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
This function returns structured information about an expression
that includes its type and value. Arrays are explored
recursively with values indented to show structure.
</simpara>
<simpara>
Compare <function>var_dump</function> to
<function>print_r</function>.
</simpara>
<para>
<informalexample>
<programlisting role="php">
<pre>
<?php
$a = array (1, 2, array ("a", "b", "c"));
var_dump ($a);
?>
</pre>
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/vmailmgr.xml
+++ phpdoc/nl/functions/vmailmgr.xml
<reference id="ref.vmailmgr">
<title>Vmailmgr functions</title>
<titleabbrev>Vmailmgr</titleabbrev>
<partintro>
<simpara>
These functions require <ulink url="&url.qmail;">qmail</ulink> and the
<ulink url="&url.vmailmgr;">vmailmgr package</ulink> by Bruce
Guenter.</simpara>
<simpara>
For all functions, the following two variables are defined as:
string vdomain the domain name of your virtual domain
(vdomain.com) string basepwd the password of the 'real' user that
holds the virtual users</simpara>
<simpara>
Only up to 8 characters are recognized in passwords for virtual
users</simpara>
<simpara>
Return status for all functions matches response in response.h</simpara>
<para>
<simplelist>
<member>O ok</member>
<member>1 bad</member>
<member>2 error</member>
<member>3 error connecting</member>
</simplelist></para>
<para>
Known problems: <function>vm_deluser</function> does not delete
the user directory as it should. <function>vm_addalias</function>
currently does not work correctly.</para>
<para>
<informalexample>
<programlisting>
<?php
dl("php3_vmailmgr.so"); //load the shared library
$vdomain="vdomain.com";
$basepwd="password";
?>
</programlisting>
</informalexample></para>
</partintro>
<refentry id="function.vm-adduser">
<refnamediv>
<refname>vm_adduser</refname>
<refpurpose>Add a new virtual user with a password</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>vm_adduser</function></funcdef>
<paramdef>string <parameter>vdomain</parameter></paramdef>
<paramdef>string <parameter>basepwd</parameter></paramdef>
<paramdef>string <parameter>newusername</parameter></paramdef>
<paramdef>string <parameter>newuserpassword</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Add a new virtual user with a
password. <parameter>newusername</parameter> is the email login
name and <parameter>newuserpassword</parameter> the password for
this user.</simpara>
</refsect1>
</refentry>
<refentry id="function.vm-addalias">
<refnamediv>
<refname>vm_addalias</refname>
<refpurpose>Add an alias to a virtual user</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>vm_addalias</function></funcdef>
<paramdef>string <parameter>vdomain</parameter></paramdef>
<paramdef>string <parameter>basepwd</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>alias</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Add an alias to a virtual user. <parameter>username</parameter>
is the email login name and <parameter>alias</parameter>
is an alias for this vuser.</simpara>
</refsect1>
</refentry>
<refentry id="function.vm-passwd">
<refnamediv>
<refname>vm_passwd</refname>
<refpurpose>Changes a virtual users password</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>vm_passwd</function></funcdef>
<paramdef>string <parameter>vdomain</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
<paramdef>string <parameter>password</parameter></paramdef>
<paramdef>string <parameter>newpassword</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Changes a virtual users password. <parameter>username</parameter>
is the email login name, <parameter>password</parameter> the old
password for the vuser, and <parameter>newpassword</parameter>
the new password.</simpara>
</refsect1>
</refentry>
<refentry id="function.vm-delalias">
<refnamediv>
<refname>vm_delalias</refname>
<refpurpose>Removes an alias</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>vm_delalias</function></funcdef>
<paramdef>string <parameter>vdomain</parameter></paramdef>
<paramdef>string <parameter>basepwd</parameter></paramdef>
<paramdef>string <parameter>alias</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Removes an alias.</simpara>
</refsect1>
</refentry>
<refentry id="function.vm-deluser">
<refnamediv>
<refname>vm_deluser</refname>
<refpurpose>Removes a virtual user</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>vm_deluser</function></funcdef>
<paramdef>string <parameter>vdomain</parameter></paramdef>
<paramdef>string <parameter>username</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
Removes a virtual user..</simpara>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/wddx.xml
+++ phpdoc/nl/functions/wddx.xml
<reference id="ref.wddx">
<title>WDDX functions</title>
<titleabbrev>WDDX</titleabbrev>
<partintro>
<para>
These functions are intended for work with <ulink
url="&url.wddx;">WDDX</ulink>.</para>
<para>
Note that 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.
<example>
<title>Serializing a single value</title>
<programlisting role="php">
<?php
print wddx_serialize_value("PHP to WDDX packet example", "PHP packet");
?>
</programlisting>
</example></para>
<para>
This example will produce:
<informalexample>
<programlisting role="php">
<wddxPacket version='1.0'><header comment='PHP
packet'/><data>
<string>PHP to WDDX packet
example</string></data></wddxPacket>
</programlisting>
</informalexample>
<example>
<title>Using incremental packets</title>
<programlisting role="php">
<?php
$pi = 3.1415926;
$packet_id = wddx_packet_start("PHP");
wddx_add_vars($packet_id, "pi");
/* Suppose $cities came from database */
$cities = array("Austin", "Novato", "Seattle");
wddx_add_vars($packet_id, "cities");
$packet = wddx_packet_end($packet_id);
print $packet;
?>
</programlisting>
</example></para>
<para>
This example will produce:
<informalexample>
<programlisting role="php">
<wddxPacket version='1.0'><header
comment='PHP'/><data><struct>
<var
name='pi'><number>3.1415926</number></var><var
name='cities'>
<array
length='3'><string>Austin</string><string>Novato</string>
<string>Seattle</string></array></var></struct></data></wddxPacket>
</programlisting>
</informalexample></para>
</partintro>
<refentry id="function.wddx-serialize-value">
<refnamediv>
<refname>wddx_serialize_value</refname>
<refpurpose>Serialize a single value into a WDDX packet</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>wddx_serialize_value</function></funcdef>
<paramdef>mixed <parameter>var</parameter></paramdef>
<paramdef>string
<parameter><optional>comment</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>wddx_serialize_value</function> is used to create a
WDDX packet from a single given value. It takes the value
contained in <parameter>var</parameter>, and an optional
<parameter>comment</parameter> string that appears in the packet
header, and returns the WDDX packet.</para>
</refsect1>
</refentry>
<refentry id="function.wddx-serialize-vars">
<refnamediv>
<refname>wddx_serialize_vars</refname>
<refpurpose>Serialize variables into a WDDX packet</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>wddx_serialize_vars</function></funcdef>
<paramdef>mixed <parameter>var_name</parameter></paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>wddx_serialize_vars</function> is used to create a WDDX
packet with a structure that contains the serialized
representation of the passed variables.</para>
<para>
<function>wddx_serialize_vars</function> 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.</para>
<para>
<example>
<title>wddx_serialize_vars example</title>
<programlisting>
<?php
$a = 1;
$b = 5.5;
$c = array("blue", "orange", "violet");
$d = "colors";
$clvars = array("c", "d");
print wddx_serialize_vars("a", "b", $clvars);
?>
</programlisting>
</example></para>
<para>
The above example will produce:
<programlisting>
<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>
</programlisting></para>
</refsect1>
</refentry>
<refentry id="function.wddx-packet-start">
<refnamediv>
<refname>wddx_packet_start</refname>
<refpurpose>Starts a new WDDX packet with structure inside it</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>wddx_packet_start</function></funcdef>
<paramdef>string
<parameter><optional>comment</optional></parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Use <function>wddx_packet_start</function> to start a new WDDX
packet for incremental addition of variables. It takes an
optional <parameter>comment</parameter> string and returns a
packet ID for use in later functions. It automatically creates a
structure definition inside the packet to contain the variables.</para>
</refsect1>
</refentry>
<refentry id="function.wddx-packet-end">
<refnamediv>
<refname>wddx_packet_end</refname>
<refpurpose>Ends a WDDX packet with the specified ID</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>wddx_packet_end</function></funcdef>
<paramdef>int <parameter>packet_id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>wddx_packet_end</function> ends the WDDX packet
specified by the <parameter>packet_id</parameter> and returns the
string with the packet.</para>
</refsect1>
</refentry>
<refentry id="function.wddx-add-vars">
<refnamediv>
<refname>wddx_add_vars</refname>
<refpurpose>Ends a WDDX packet with the specified ID</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef><function>wddx_add_vars</function></funcdef>
<paramdef>int <parameter>packet_id</parameter></paramdef>
<paramdef>mixed <parameter>name_var</parameter></paramdef>
<paramdef>mixed
<parameter><optional>...</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>wddx_add_vars</function> is used to serialize passed
variables and add the result to the packet specified by the
<parameter>packet_id</parameter>. The variables to be serialized
are specified in exactly the same way as
<function>wddx_serialize_vars</function>.</para>
</refsect1>
</refentry>
<refentry id="function.wddx-deserialize">
<refnamediv>
<refname>wddx_deserialize</refname>
<refpurpose>Deserializes a WDDX packet</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>wddx_deserialize</function></funcdef>
<paramdef>string <parameter>packet</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>wddx_deserialized</function> takes a
<parameter>packet</parameter> string and deserializes it. It
returns the result which can be string, number, or array. Note
that structures are deserialized into associative arrays.</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/xml.xml
+++ phpdoc/nl/functions/xml.xml
<reference id="ref.xml">
<title>XML parser functions</title>
<titleabbrev>XML</titleabbrev>
<partintro>
<sect1 id="xml.partintro">
<title>Introduction</title>
<sect2 id="xml.intro">
<title>About XML</title>
<para>
XML (eXtensible Markup Language) is a data format for structured
document interchange on the Web. It is a standard defined by
The World Wide Web consortium (W3C). Information about XML and
related technologies can be found at <ulink
url="&url.xml;">&url.xml;</ulink>.
</para>
</sect2>
<sect2 id="xml.install">
<title>Installation</title>
<para>
This extension uses <productname>expat</productname>, which can
be found at <ulink url="&url.expat;">&url.expat;</ulink>. The
Makefile that comes with expat does not build a library by
default, you can use this make rule for that:
<programlisting role="makefile">
libexpat.a: $(OBJS)
ar -rc $@ $(OBJS)
ranlib $@
</programlisting>
A source RPM package of expat can be found at <ulink
url="&url.expat.rpm;">&url.expat.rpm;</ulink>.
</para>
<para>
Note that if you are using Apache-1.3.7 or later, you already
have the required expat library. Simply configure PHP using
<option role="configure">--with-xml</option> (without any
additional path) and it will automatically use the expat library
built into Apache.
</para>
<para>
On UNIX, run <command>configure</command> with the <option
role="configure">--with-xml</option> option. The
<productname>expat</productname> library should be installed
somewhere your compiler can find it. If you compile PHP as a
module for Apache 1.3.9 or later, PHP will automatically use the
bundled <productname>expat</productname> library from Apache.
You may need to set <envar>CPPFLAGS</envar> and
<envar>LDFLAGS</envar> in your environment before running
configure if you have installed expat somewhere exotic.
</para>
<para>
Build PHP. <emphasis>Tada!</emphasis> That should be it.
</para>
</sect2>
<sect2 id="xml.about">
<title>About This Extension</title>
<para>
This PHP extension implements support for James Clark's
<productname>expat</productname> in PHP. This toolkit lets you
parse, but not validate, XML documents. It supports three
source <link linkend="xml.encoding">character encodings</link>
also provided by PHP: <literal>US-ASCII</literal>,
<literal>ISO-8859-1</literal> and <literal>UTF-8</literal>.
<literal>UTF-16</literal> is not supported.
</para>
<para>
This extension lets you <link
linkend="function.xml-parser-create">create XML parsers</link>
and then define <emphasis>handlers</emphasis> for different XML
events. Each XML parser also has a few <link
linkend="function.xml-parser-set-option">parameters</link> you
can adjust.
</para>
<para>
The XML event handlers defined are:
<table>
<title>Supported XML handlers</title>
<tgroup cols="2">
<thead>
<row>
<entry>PHP function to set handler</entry>
<entry>Event description</entry>
</row>
</thead>
<tbody>
<row>
<entry><function>xml_set_element_handler</function></entry>
<entry>
Element events are issued whenever the XML parser
encounters start or end tags. There are separate handlers
for start tags and end tags.
</entry>
</row>
<row>
<entry>
<function>xml_set_character_data_handler</function>
</entry>
<entry>
Character data is roughly all the non-markup contents of
XML documents, including whitespace between tags. Note
that the XML parser does not add or remove any whitespace,
it is up to the application (you) to decide whether
whitespace is significant.
</entry>
</row>
<row>
<entry>
<function>xml_set_processing_instruction_handler</function>
</entry>
<entry>
PHP programmers should be familiar with processing
instructions (PIs) already. <?php ?> is a processing
instruction, where <replaceable>php</replaceable> is called
the "PI target". The handling of these are
application-specific, except that all PI targets starting
with "XML" are reserved.
</entry>
</row>
<row>
<entry><function>xml_set_default_handler</function></entry>
<entry>
What goes not to another handler goes to the default
handler. You will get things like the XML and document
type declarations in the default handler.
</entry>
</row>
<row>
<entry>
<function>xml_set_unparsed_entity_decl_handler</function>
</entry>
<entry>
This handler will be called for declaration of an unparsed
(NDATA) entity.
</entry>
</row>
<row>
<entry>
<function>xml_set_notation_decl_handler</function>
</entry>
<entry>
This handler is called for declaration of a notation.
</entry>
</row>
<row>
<entry>
<function>xml_set_external_entity_ref_handler</function>
</entry>
<entry>
This handler is called when the XML parser finds a
reference to an external parsed general entity. This can
be a reference to a file or URL, for example. See <link
linkend="example.xml-external-entity">the external entity
example</link> for a demonstration.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect2>
<sect2 id="xml.case-folding">
<title>Case Folding</title>
<para>
The element handler functions may get their element names
<glossterm>case-folded</glossterm>. Case-folding is defined by
the XML standard as "a process applied to a sequence of
characters, in which those identified as non-uppercase are
replaced by their uppercase equivalents". In other words, when
it comes to XML, case-folding simply means uppercasing.
</para>
<para>
By default, all the element names that are passed to the handler
functions are case-folded. This behaviour can be queried and
controlled per XML parser with the
<function>xml_parser_get_option</function> and
<function>xml_parser_set_option</function> functions,
respectively.
</para>
</sect2>
<sect2 id="xml.error-codes">
<title>Error Codes</title>
<para>
The following constants are defined for XML error codes (as
returned by <function>xml_parse</function>):
<simplelist>
<member>XML_ERROR_NONE</member>
<member>XML_ERROR_NO_MEMORY</member>
<member>XML_ERROR_SYNTAX</member>
<member>XML_ERROR_NO_ELEMENTS</member>
<member>XML_ERROR_INVALID_TOKEN</member>
<member>XML_ERROR_UNCLOSED_TOKEN</member>
<member>XML_ERROR_PARTIAL_CHAR</member>
<member>XML_ERROR_TAG_MISMATCH</member>
<member>XML_ERROR_DUPLICATE_ATTRIBUTE</member>
<member>XML_ERROR_JUNK_AFTER_DOC_ELEMENT</member>
<member>XML_ERROR_PARAM_ENTITY_REF</member>
<member>XML_ERROR_UNDEFINED_ENTITY</member>
<member>XML_ERROR_RECURSIVE_ENTITY_REF</member>
<member>XML_ERROR_ASYNC_ENTITY</member>
<member>XML_ERROR_BAD_CHAR_REF</member>
<member>XML_ERROR_BINARY_ENTITY_REF</member>
<member>XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF</member>
<member>XML_ERROR_MISPLACED_XML_PI</member>
<member>XML_ERROR_UNKNOWN_ENCODING</member>
<member>XML_ERROR_INCORRECT_ENCODING</member>
<member>XML_ERROR_UNCLOSED_CDATA_SECTION</member>
<member>XML_ERROR_EXTERNAL_ENTITY_HANDLING</member>
</simplelist>
</para>
</sect2>
<sect2 id="xml.encoding">
<title>Character Encoding</title>
<para>
PHP's XML extension supports the <ulink
url="&url.unicode;">Unicode</ulink> character set through
different <glossterm>character encoding</glossterm>s. There are
two types of character encodings, <glossterm>source
encoding</glossterm> and <glossterm>target encoding</glossterm>.
PHP's internal representation of the document is always encoded
with <literal>UTF-8</literal>.
</para>
<para>
Source encoding is done when an XML document is <link
linkend="function.xml-parse">parsed</link>. Upon <link
linkend="function.xml-parser-create">creating an XML
parser</link>, a source encoding can be specified (this encoding
can not be changed later in the XML parser's lifetime). The
supported source encodings are <literal>ISO-8859-1</literal>,
<literal>US-ASCII</literal> and <literal>UTF-8</literal>. The
former two are single-byte encodings, which means that each
character is represented by a single byte.
<literal>UTF-8</literal> can encode characters composed by a
variable number of bits (up to 21) in one to four bytes. The
default source encoding used by PHP is
<literal>ISO-8859-1</literal>.
</para>
<para>
Target encoding is done when PHP passes data to XML handler
functions. When an XML parser is created, the target encoding
is set to the same as the source encoding, but this may be
changed at any point. The target encoding will affect character
data as well as tag names and processing instruction targets.
</para>
<para>
If the XML parser encounters characters outside the range that
its source encoding is capable of representing, it will return
an error.
</para>
<para>
If PHP encounters characters in the parsed XML document that can
not be represented in the chosen target encoding, the problem
characters will be "demoted". Currently, this means that such
characters are replaced by a question mark.
</para>
</sect2>
</sect1>
<sect1 id="xml.examples">
<title>Some Examples</title>
<para>
Here are some example PHP scripts parsing XML documents.
</para>
<sect2 id="example.xml-structure">
<title>XML Element Structure Example</title>
<para>
This first example displays the stucture of the start elements in
a document with indentation.
<example>
<title>Show XML Element Structure</title>
<programlisting role="php">
$file = "data.xml";
$depth = array();
function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $i < $depth[$parser]; $i++) {
print " ";
}
print "$name\n";
$depth[$parser]++;
}
function endElement($parser, $name) {
global $depth;
$depth[$parser]--;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
</programlisting>
</example>
</para>
</sect2>
<sect2 id="example.xml-map-tags">
<title>XML Tag Mapping Example</title>
<para>
<example>
<title>Map XML to HTML</title>
<para>
This example maps tags in an XML document directly to HTML
tags. Elements not found in the "map array" are ignored. Of
course, this example will only work with a specific XML
document type.
<programlisting role="php">
$file = "data.xml";
$map_array = array(
"BOLD" => "B",
"EMPHASIS" => "I",
"LITERAL" => "TT"
);
function startElement($parser, $name, $attrs) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "<$htmltag>";
}
}
function endElement($parser, $name) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "</$htmltag>";
}
}
function characterData($parser, $data) {
print $data;
}
$xml_parser = xml_parser_create();
// use case-folding so we are sure to find the tag in $map_array
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
</programlisting>
</para>
</example>
</para>
</sect2>
<sect2 id="example.xml-external-entity">
<title>XML External Entity Example</title>
<para>
This example highlights XML code. It illustrates how to use an
external entity reference handler to include and parse other
documents, as well as how PIs can be processed, and a way of
determining "trust" for PIs containing code.
</para>
<para>
XML documents that can be used for this example are found below
the example (<filename>xmltest.xml</filename> and
<filename>xmltest2.xml</filename>.)
</para>
<para>
<example>
<title>External Entity Example</title>
<programlisting role="php">
$file = "xmltest.xml";
function trustedFile($file) {
// only trust local files owned by ourselves
if (!eregi("^([a-z]+)://", $file)
&& fileowner($file) == getmyuid()) {
return true;
}
return false;
}
function startElement($parser, $name, $attribs) {
print "&lt;<font
color=\"#0000cc\">$name</font>";
if (sizeof($attribs)) {
while (list($k, $v) = each($attribs)) {
print " <font
color=\"#009900\">$k</font>=\"<font
color=\"#990000\">$v</font>\"";
}
}
print "&gt;";
}
function endElement($parser, $name) {
print "&lt;/<font
color=\"#0000cc\">$name</font>&gt;";
}
function characterData($parser, $data) {
print "<b>$data</b>";
}
function PIHandler($parser, $target, $data) {
switch (strtolower($target)) {
case "php":
global $parser_file;
// If the parsed document is "trusted", we say it is safe
// to execute PHP code inside it. If not, display the code
// instead.
if (trustedFile($parser_file[$parser])) {
eval($data);
} else {
printf("Untrusted PHP code: <i>%s</i>",
htmlspecialchars($data));
}
break;
}
}
function defaultHandler($parser, $data) {
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) ==
";") {
printf('<font color="#aa00aa">%s</font>',
htmlspecialchars($data));
} else {
printf('<font size="-1">%s</font>',
htmlspecialchars($data));
}
}
function externalEntityRefHandler($parser, $openEntityNames, $base, $systemId,
$publicId) {
if ($systemId) {
if (!list($parser, $fp) = new_xml_parser($systemId)) {
printf("Could not open entity %s at %s\n", $openEntityNames,
$systemId);
return false;
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($parser, $data, feof($fp))) {
printf("XML error: %s at line %d while parsing entity %s\n",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser), $openEntityNames);
xml_parser_free($parser);
return false;
}
}
xml_parser_free($parser);
return true;
}
return false;
}
function new_xml_parser($file) {
global $parser_file;
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_processing_instruction_handler($xml_parser, "PIHandler");
xml_set_default_handler($xml_parser, "defaultHandler");
xml_set_external_entity_ref_handler($xml_parser, "externalEntityRefHandler");
if (!($fp = @fopen($file, "r"))) {
return false;
}
if (!is_array($parser_file)) {
settype($parser_file, "array");
}
$parser_file[$xml_parser] = $file;
return array($xml_parser, $fp);
}
if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
die("could not open XML input");
}
print "<pre>";
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
print "</pre>";
print "parse complete\n";
xml_parser_free($xml_parser);
?>
</programlisting>
</example>
</para>
<para id="example.xml-xmltest.xml">
<example>
<title>xmltest.xml</title>
<programlisting role="xml">
<?xml version='1.0'?>
<!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [
<!ENTITY plainEntity "FOO entity">
<!ENTITY systemEntity SYSTEM "xmltest2.xml">
]>
<chapter>
<TITLE>Title &plainEntity;</TITLE>
<para>
<informaltable>
<tgroup cols="3">
<tbody>
<row><entry>a1</entry><entry
morerows="1">b1</entry><entry>c1</entry></row>
<row><entry>a2</entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</informaltable>
</para>
&systemEntity;
<sect1 id="about">
<title>About this Document</title>
<para>
<!-- this is a comment -->
<?php print 'Hi! This is PHP version '.phpversion(); ?>
</para>
</sect1>
</chapter>
</programlisting>
</example>
</para>
<para id="example.xml-xmltest2.xml">
This file is included from <filename>xmltest.xml</filename>:
<example>
<title>xmltest2.xml</title>
<programlisting role="xml">
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY testEnt "test entity">
]>
<foo>
<element attrib="value"/>
&testEnt;
<?php print "This is some more PHP code being executed."; ?>
</foo>
</programlisting>
</example>
</para>
</sect2>
</sect1>
</partintro>
<refentry id="function.xml-parser-create">
<refnamediv>
<refname>xml_parser_create</refname>
<refpurpose>create an XML parser</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>xml_parser_create</function></funcdef>
<paramdef>string
<parameter><optional>encoding</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>encoding</parameter> (optional)</term>
<listitem>
<para>
Which character encoding the parser should use. The
following character encodings are supported:
<simplelist>
<member><literal>ISO-8859-1</literal> (default)</member>
<member><literal>US-ASCII</literal></member>
<member><literal>UTF-8</literal></member>
</simplelist>
</para>
</listitem>
</varlistentry>
</variablelist>
This function creates an XML parser and returns a handle for use
by other XML functions. Returns <literal>false</literal> on
failure.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-set-object">
<refnamediv>
<refname>xml_set_object</refname>
<refpurpose>Use XML Parser within an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>xml_set_object</function></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>object <parameter>&object</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function allows to use <parameter>parser</parameter> inside
<parameter>object</parameter>. All callback functions could be
set with <function>xml_set_element_handler</function> etc and
assumed to be methods of <parameter>object</parameter>.
</para>
<programlisting role="php">
<?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>");
?>
</programlisting>
</refsect1>
</refentry>
<refentry id="function.xml-set-element-handler">
<refnamediv>
<refname>xml_set_element_handler</refname>
<refpurpose>set up start and end element handlers</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_set_element_handler</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string
<parameter>startElementHandler</parameter>
</paramdef>
<paramdef>string
<parameter>endElementHandler</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the element handler functions for the XML parser
<parameter>parser</parameter>.
<parameter>startElementHandler</parameter> and
<parameter>endElementHandler</parameter> are strings containing
the names of functions that must exist when
<function>xml_parse</function> is called for
<parameter>parser</parameter>.
</para>
<para>
The function named by <parameter>startElementHandler</parameter>
must accept three parameters:
<funcsynopsis>
<funcprototype>
<funcdef><replaceable>startElementHandler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>array <parameter>attribs</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the
handler.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>name</parameter></term>
<listitem>
<simpara>
The second parameter, <parameter>name</parameter>, contains
the name of the element for which this handler is called. If
<link linkend="xml.case-folding">case-folding</link> is in
effect for this parser, the element name will be in uppercase
letters.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>attribs</parameter></term>
<listitem>
<simpara>
The third parameter, <parameter>attribs</parameter>, contains
an associative array with the element's attributes (if any).
The keys of this array are the attribute names, the values
are the attribute values. Attribute names are <link
linkend="xml.case-folding">case-folded</link> on the same
criteria as element names. Attribute values are
<emphasis>not</emphasis> case-folded.
</simpara>
<simpara>
The original order of the attributes can be retrieved by
walking through <parameter>attribs</parameter> the normal
way, using <function>each</function>. The first key in the
array was the first attribute, and so on.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The function named by <parameter>endElementHandler</parameter>
must accept two parameters:
<funcsynopsis>
<funcprototype>
<funcdef><replaceable>endElementHandler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the
handler.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>name</parameter></term>
<listitem>
<simpara>
The second parameter, <parameter>name</parameter>, contains
the name of the element for which this handler is called. If
<link linkend="xml.case-folding">case-folding</link> is in
effect for this parser, the element name will be in uppercase
letters.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If a handler function is set to an empty string, or
<literal>false</literal>, the handler in question is disabled.
</para>
<para>
True is returned if the handlers are set up, false if
<parameter>parser</parameter> is not a parser.
</para>
<para>
There is currently no support for object/method handlers. See
<function>xml_set_object</function> for using the XML parser
within an object.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-set-character-data-handler">
<refnamediv>
<refname>xml_set_character_data_handler</refname>
<refpurpose>set up character data handler</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_set_character_data_handler</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the character data handler function for the XML parser
<parameter>parser</parameter>. <parameter>handler</parameter> is
a string containing the name of a function that must exist when
<function>xml_parse</function> is called for
<parameter>parser</parameter>.</para>
<para>
The function named by <parameter>handler</parameter> must accept
two parameters:
<funcsynopsis>
<funcprototype>
<funcdef><replaceable>handler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the handler.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>data</parameter></term>
<listitem>
<simpara>
The second parameter, <parameter>data</parameter>, contains
the character data as a string.
</simpara>
</listitem>
</varlistentry>
</variablelist></para>
<para>
If a handler function is set to an empty string, or
<literal>false</literal>, the handler in question is
disabled.
</para>
<para>
True is returned if the handler is set up, false if
<parameter>parser</parameter> is not a parser.
</para>
<para>
There is currently no support for object/method handlers. See
<function>xml_set_object</function> for using the XML parser
within an object.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-set-processing-instruction-handler">
<refnamediv>
<refname>xml_set_processing_instruction_handler</refname>
<refpurpose>
Set up processing instruction (PI) handler
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_set_processing_instruction_handler</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the processing instruction (PI) handler function for the XML
parser <parameter>parser</parameter>.
<parameter>handler</parameter> is a string containing the name of
a function that must exist when <function>xml_parse</function> is
called for <parameter>parser</parameter>.
</para>
<para>
A processing instruction has the following format:
<informalexample>
<programlisting><?
<replaceable>target</replaceable>
<replaceable>data</replaceable>?>
</programlisting>
</informalexample>
You can put PHP code into such a tag, but be aware of one
limitation: in an XML PI, the PI end tag
(<literal>?></literal>) can not be quoted, so this character
sequence should not appear in the PHP code you embed with PIs in
XML documents. If it does, the rest of the PHP code, as well as
the "real" PI end tag, will be treated as character data.
</para>
<para>
The function named by <parameter>handler</parameter> must accept
three parameters:
<funcsynopsis>
<funcprototype>
<funcdef><replaceable>handler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>target</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem><simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the
handler.</simpara></listitem>
</varlistentry>
<varlistentry>
<term><parameter>target</parameter></term>
<listitem><simpara>
The second parameter, <parameter>target</parameter>, contains
the PI target.</simpara></listitem>
</varlistentry>
<varlistentry>
<term><parameter>data</parameter></term>
<listitem><simpara>
The third parameter, <parameter>data</parameter>, contains
the PI data.</simpara></listitem>
</varlistentry>
</variablelist></para>
<para>
If a handler function is set to an empty string, or
<literal>false</literal>, the handler in question is disabled.
</para>
<para>
True is returned if the handler is set up, false if
<parameter>parser</parameter> is not a parser.
</para>
<para>
There is currently no support for object/method handlers. See
<function>xml_set_object</function> for using the XML parser
within an object.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-set-default-handler">
<refnamediv>
<refname>xml_set_default_handler</refname>
<refpurpose>set up default handler</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_set_default_handler</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the default handler function for the XML parser
<parameter>parser</parameter>. <parameter>handler</parameter> is
a string containing the name of a function that must exist when
<function>xml_parse</function> is called for
<parameter>parser</parameter>.</para>
<para>
The function named by <parameter>handler</parameter> must accept
two parameters:
<funcsynopsis>
<funcprototype>
<funcdef><replaceable>handler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<parameter>parser</parameter>
</term>
<listitem>
<simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the
handler.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>data</parameter>
</term>
<listitem>
<simpara>
The second parameter, <parameter>data</parameter>, contains
the character data. This may be the XML declaration,
document type declaration, entities or other data for which
no other handler exists.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If a handler function is set to an empty string, or
<literal>false</literal>, the handler in question is disabled.
</para>
<para>
True is returned if the handler is set up, false if
<parameter>parser</parameter> is not a parser.
</para>
<para>
There is currently no support for object/method handlers. See
<function>xml_set_object</function> for using the XML parser
within an object.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-set-unparsed-entity-decl-handler">
<refnamediv>
<refname>xml_set_unparsed_entity_decl_handler</refname>
<refpurpose>
Set up unparsed entity declaration handler
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_set_unparsed_entity_decl_handler</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the unparsed entity declaration handler function for the XML
parser <parameter>parser</parameter>.
<parameter>handler</parameter> is a string containing the name of
a function that must exist when <function>xml_parse</function> is
called for <parameter>parser</parameter>.</para>
<para>
This handler will be called if the XML parser encounters an
external entity declaration with an NDATA declaration, like the
following:
<programlisting role="xml">
<!ENTITY <parameter>name</parameter> {<parameter>publicId</parameter>
| <parameter>systemId</parameter>}
NDATA <parameter>notationName</parameter>>
</programlisting>
</para>
<para>
See <ulink url="&url.rec-xml;#sec-external-ent">section 4.2.2 of
the XML 1.0 spec</ulink> for the definition of notation declared
external entities.
</para>
<para> The function named by
<parameter>handler</parameter> must accept six parameters:
<funcsynopsis>
<funcprototype>
<funcdef><replaceable>handler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>entityName</parameter></paramdef>
<paramdef>string <parameter>base</parameter></paramdef>
<paramdef>string <parameter>systemId</parameter></paramdef>
<paramdef>string <parameter>publicId</parameter></paramdef>
<paramdef>string <parameter>notationName</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the
handler.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>entityName</parameter></term>
<listitem>
<simpara>
The name of the entity that is about to be defined.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>base</parameter></term>
<listitem><simpara>
This is the base for resolving the system identifier
(<parameter>systemId</parameter>) of the external
entity. Currently this parameter will always be set to
an empty string.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>systemId</parameter></term>
<listitem>
<simpara>
System identifier for the external entity.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>publicId</parameter></term>
<listitem>
<simpara>
Public identifier for the external entity.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>notationName</parameter></term>
<listitem>
<simpara>
Name of the notation of this entity (see
<function>xml_set_notation_decl_handler</function>).
</simpara>
</listitem>
</varlistentry>
</variablelist></para>
<para>
If a handler function is set to an empty string, or
<literal>false</literal>, the handler in question is disabled.
</para>
<para>
True is returned if the handler is set up, false if
<parameter>parser</parameter> is not a parser.
</para>
<para>
There is currently no support for object/method handlers. See
<function>xml_set_object</function> for using the XML parser
within an object.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-set-notation-decl-handler">
<refnamediv>
<refname>xml_set_notation_decl_handler</refname>
<refpurpose>set up notation declaration handler</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_set_notation_decl_handler</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the notation declaration handler function for the XML parser
<parameter>parser</parameter>. <parameter>handler</parameter> is
a string containing the name of a function that must exist when
<function>xml_parse</function> is called for
<parameter>parser</parameter>.
</para>
<para>
A notation declaration is part of the document's DTD and has the
following format: <programlisting role="xml"><!NOTATION
<parameter>name</parameter> {<parameter>systemId</parameter> |
<parameter>publicId</parameter>}></programlisting> See <ulink
url="&url.rec-xml;#Notations">section 4.7 of the XML 1.0
spec</ulink> for the definition of notation declarations.
</para>
<para>
The function named by <parameter>handler</parameter> must accept
five parameters:
<funcsynopsis>
<funcprototype>
<funcdef><replaceable>handler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>notationName</parameter></paramdef>
<paramdef>string <parameter>base</parameter></paramdef>
<paramdef>string <parameter>systemId</parameter></paramdef>
<paramdef>string <parameter>publicId</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term>
<parameter>parser</parameter>
</term>
<listitem>
<simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the
handler.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>notationName</parameter></term>
<listitem>
<simpara>
This is the notation's <parameter>name</parameter>, as per
the notation format described above.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>base</parameter>
</term>
<listitem>
<simpara>
This is the base for resolving the system identifier
(<parameter>systemId</parameter>) of the notation
declaration. Currently this parameter will always be set to
an empty string.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>systemId</parameter></term>
<listitem>
<simpara>
System identifier of the external notation
declaration.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>publicId</parameter>
</term>
<listitem>
<simpara>
Public identifier of the external notation
declaration.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If a handler function is set to an empty string, or
<literal>false</literal>, the handler in question is
disabled.
</para>
<para>
True is returned if the handler is set up, false if
<parameter>parser</parameter> is not a parser.
</para>
<para>
There is currently no support for object/method handlers. See
<function>xml_set_object</function> for using the XML parser
within an object.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-set-external-entity-ref-handler">
<refnamediv>
<refname>xml_set_external_entity_ref_handler</refname>
<refpurpose>set up external entity reference handler</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_set_external_entity_ref_handler</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the notation declaration handler function for the XML parser
<parameter>parser</parameter>. <parameter>handler</parameter> is
a string containing the name of a function that must exist when
<function>xml_parse</function> is called for
<parameter>parser</parameter>.
</para>
<para>
The function named by <parameter>handler</parameter> must accept
five parameters, and should return an integer value. If the
value returned from the handler is false (which it will be if no
value is returned), the XML parser will stop parsing and
<function>xml_get_error_code</function> will return <systemitem
class="constant">XML_ERROR_EXTERNAL_ENTITY_HANDLING</systemitem>.
<funcsynopsis>
<funcprototype>
<funcdef>int <replaceable>handler</replaceable></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string
<parameter>openEntityNames</parameter>
</paramdef>
<paramdef>string <parameter>base</parameter></paramdef>
<paramdef>string <parameter>systemId</parameter></paramdef>
<paramdef>string <parameter>publicId</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
The first parameter, <replaceable>parser</replaceable>, is a
reference to the XML parser calling the handler.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>openEntityNames</parameter></term>
<listitem>
<simpara>
The second parameter, <parameter>openEntityNames</parameter>,
is a space-separated list of the names of the entities that
are open for the parse of this entity (including the name of
the referenced entity).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>base</parameter></term>
<listitem>
<simpara>
This is the base for resolving the system identifier
(<parameter>systemid</parameter>) of the external entity.
Currently this parameter will always be set to an empty
string.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>systemId</parameter></term>
<listitem>
<simpara>
The fourth parameter, <parameter>systemId</parameter>, is the
system identifier as specified in the entity declaration.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>publicId</parameter></term>
<listitem>
<simpara>
The fifth parameter, <parameter>publicId</parameter>, is the
public identifier as specified in the entity declaration, or
an empty string if none was specified; the whitespace in the
public identifier will have been normalized as required by
the XML spec.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
If a handler function is set to an empty string, or
<literal>false</literal>, the handler in question is
disabled.
</para>
<para>
True is returned if the handler is set up, false if
<parameter>parser</parameter> is not a parser.
</para>
<para>
There is currently no support for object/method handlers. See
<function>xml_set_object</function> for using the XML parser
within an object.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-parse">
<refnamediv>
<refname>xml_parse</refname>
<refpurpose>start parsing an XML document</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>xml_parse</function></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int
<parameter><optional>isFinal</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to use.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>data</parameter></term>
<listitem>
<simpara>
Chunk of data to parse. A document may be parsed piece-wise
by calling <function>xml_parse</function> several times with
new data, as long as the <parameter>isFinal</parameter>
parameter is set and true when the last data is parsed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>isFinal</parameter> (optional)</term>
<listitem>
<simpara>
If set and true, <parameter>data</parameter> is the last
piece of data sent in this parse.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
When the XML document is parsed, the handlers for the configured
events are called as many times as necessary, after which this
function returns true or false.
</para>
<para>
True is returned if the parse was successful, false if it was not
successful, or if <parameter>parser</parameter> does not refer to
a valid parser. For unsuccessful parses, error information can
be retrieved with <function>xml_get_error_code</function>,
<function>xml_error_string</function>,
<function>xml_get_current_line_number</function>,
<function>xml_get_current_column_number</function> and
<function>xml_get_current_byte_index</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-get-error-code">
<refnamediv>
<refname>xml_get_error_code</refname>
<refpurpose>get XML parser error code</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>xml_get_error_code</function></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to get error code from.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
This function returns false if <parameter>parser</parameter> does
not refer to a valid parser, or else it returns one of the error
codes listed in the <link linkend="xml.error-codes">error codes
section</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-error-string">
<refnamediv>
<refname>xml_error_string</refname>
<refpurpose>get XML parser error string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>xml_error_string</function></funcdef>
<paramdef>int <parameter>code</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>code</parameter></term>
<listitem>
<simpara>
An error code from <function>xml_get_error_code</function>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
Returns a string with a textual description of the error code
<parameter>code</parameter>, or false if no description was found.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-get-current-line-number">
<refnamediv>
<refname>xml_get_current_line_number</refname>
<refpurpose>get current line number for an XML parser</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_get_current_line_number</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to get line number from.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
This function returns false if <parameter>parser</parameter> does
not refer to a valid parser, or else it returns which line the
parser is currently at in its data buffer.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-get-current-column-number">
<refnamediv>
<refname>xml_get_current_column_number</refname>
<refpurpose>
Get current column number for an XML parser
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_get_current_column_number</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to get column number from.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
This function returns false if <parameter>parser</parameter> does
not refer to a valid parser, or else it returns which column on
the current line (as given by
<function>xml_get_current_line_number</function>) the parser is
currently at.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-get-current-byte-index">
<refnamediv>
<refname>xml_get_current_byte_index</refname>
<refpurpose>get current byte index for an XML parser</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int
<function>xml_get_current_byte_index</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to get byte index from.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
This function returns false if <parameter>parser</parameter> does
not refer to a valid parser, or else it returns which byte index
the parser is currently at in its data buffer (starting at 0).
</para>
</refsect1>
</refentry>
<refentry id="function.xml-parse-into-struct">
<refnamediv>
<refname>xml_parse_into_struct</refname>
<refpurpose>Parse XML data into an array structure</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>xml_parse_into_struct</function></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>array <parameter>&values</parameter></paramdef>
<paramdef>array <parameter>&index</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function parses an XML file into 2 parallel array
structures, one (<parameter>index</parameter>) containing pointers
to the location of the appropriate values in the
<parameter>values</parameter> array. These last two parameters
must be passed by reference.
</para>
<para>
Below is an example that illustrates the internal structure of
the arrays being generated by the function. We use a simple
<literal>note</literal> tag embeded inside a
<literal>para</literal> tag, and then we parse this an print out
the structures generated:
<informalexample>
<programlisting>
$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);
</programlisting>
</informalexample>
When we run that code, the output will be:
<informalexample>
<programlisting>
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
)
)
</programlisting>
</informalexample>
</para>
<para>
Event-driven parsing (based on the expat library) can get
complicated when you have an XML document that is complex.
This function does not produce a DOM style object, but it
generates structures amenable of being transversed in a tree
fashion. Thus, we can create objects representing the data
in the XML file easily. Let's consider the following XML file
representing a small database of aminoacids information:
<example>
<title>moldb.xml - small database of molecular information</title>
<programlisting>
<?xml version="1.0"?>
<moldb>
<molecule>
<name>Alanine</name>
<symbol>ala</symbol>
<code>A</code>
<type>hydrophobic</type>
</molecule>
<molecule>
<name>Lysine</name>
<symbol>lys</symbol>
<code>K</code>
<type>charged</type>
</molecule>
</moldb>
</programlisting>
</example>
And some code to parse the document and generate the appropriate
objects:
<example>
<title>
parsemoldb.php - parses moldb.xml into and array of
molecular objects
</title>
<programlisting role="php">
<?php
class AminoAcid {
var $name; // aa name
var $symbol; // three letter symbol
var $code; // one letter code
var $type; // hydrophobic, charged or neutral
function AminoAcid ($aa) {
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readDatabase($filename) {
// read the xml database of aminoacids
$data = implode("",file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,&$values,&$tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "molecule") {
$molranges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each molecule definition
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parseMol(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
function parseMol($mvalues) {
for ($i=0; $i < count($mvalues); $i++)
$mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
return new AminoAcid($mol);
}
$db = readDatabase("moldb.xml");
echo "** Database of AminoAcid objects:\n";
print_r($db);
?>
</programlisting>
</example>
After executing <filename>parsemoldb.php</filename>, the variable
<varname>$db</varname> contains an array of
<classname>AminoAcid</classname> objects, and the output of the
script confirms that:
<informalexample>
<programlisting>
** Database of AminoAcid objects:
Array
(
[0] => aminoacid Object
(
[name] => Alanine
[symbol] => ala
[code] => A
[type] => hydrophobic
)
[1] => aminoacid Object
(
[name] => Lysine
[symbol] => lys
[code] => K
[type] => charged
)
)
</programlisting>
</informalexample>
</para>
</refsect1>
</refentry>
<refentry id="function.xml-parser-free">
<refnamediv>
<refname>xml_parser_free</refname>
<refpurpose>Free an XML parser</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>xml_parser_free</function></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to free.
</simpara>
</listitem>
</varlistentry>
</variablelist></para>
<para>
This function returns false if <parameter>parser</parameter> does
not refer to a valid parser, or else it frees the parser and
returns true.
</para>
</refsect1>
</refentry>
<refentry id="function.xml-parser-set-option">
<refnamediv>
<refname>xml_parser_set_option</refname>
<refpurpose>set options in an XML parser</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>xml_parser_set_option</function></funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>int <parameter>option</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to set an option in.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>option</parameter></term>
<listitem>
<simpara>
Which option to set. See below.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<simpara>
The option's new value.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
This function returns false if <parameter>parser</parameter> does
not refer to a valid parser, or if the option could not be set.
Else the option is set and true is returned.
</para>
<para>
The following options are available:
<table>
<title>XML parser options</title>
<tgroup cols="3">
<thead>
<row>
<entry>Option constant</entry>
<entry>Data type</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>XML_OPTION_CASE_FOLDING</entry>
<entry>integer</entry>
<entry>
Controls whether <link
linkend="xml.case-folding">case-folding</link> is enabled
for this XML parser. Enabled by default.
</entry>
</row>
<row>
<entry>XML_OPTION_TARGET_ENCODING</entry>
<entry>string</entry>
<entry>
Sets which <link linkend="xml.encoding">target
encoding</link> to use in this XML parser. By default, it
is set to the same as the source encoding used by
<function>xml_parser_create</function>. Supported target
encodings are <literal>ISO-8859-1</literal>,
<literal>US-ASCII</literal> and <literal>UTF-8</literal>.
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</refsect1>
</refentry>
<refentry id="function.xml-parser-get-option">
<refnamediv>
<refname>xml_parser_get_option</refname>
<refpurpose>get options from an XML parser</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed
<function>xml_parser_get_option</function>
</funcdef>
<paramdef>int <parameter>parser</parameter></paramdef>
<paramdef>int <parameter>option</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<variablelist>
<varlistentry>
<term><parameter>parser</parameter></term>
<listitem>
<simpara>
A reference to the XML parser to get an option
from.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>option</parameter></term>
<listitem>
<simpara>
Which option to fetch. See
<function>xml_parser_set_option</function> for a list of
options.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
This function returns false if <parameter>parser</parameter> does
not refer to a valid parser, or if the option could not be set.
Else the option's value is returned.
</para>
<para>
See <function>xml_parser_set_option</function> for the list of
options.
</para>
</refsect1>
</refentry>
<refentry id="function.utf8-decode">
<refnamediv>
<refname>utf8_decode</refname>
<refpurpose>
Converts a string with ISO-8859-1 characters encoded with UTF-8
to single-byte ISO-8859-1.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>utf8_decode</function></funcdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function decodes <parameter>data</parameter>, assumed to be
<literal>UTF-8</literal> encoded, to <literal>ISO-8859-1</literal>.
</para>
<para>
See <function>utf8_encode</function> for an explaination of UTF-8
encoding.
</para>
</refsect1>
</refentry>
<refentry id="function.utf8-encode">
<refnamediv>
<refname>utf8_encode</refname>
<refpurpose>encodes an ISO-8859-1 string to UTF-8</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>utf8_encode</function></funcdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function encodes the string <parameter>data</parameter> to
<literal>UTF-8</literal>, and returns the encoded version.
<literal>UTF-8</literal> is a standard mechanism used by
<acronym>Unicode</acronym>for encoding <glossterm>wide
character</glossterm> values into a byte stream.
<literal>UTF-8</literal> is transparent to plain
<abbrev>ASCII</abbrev> characters, is self-synchronized (meaning
it is possible for a program to figure out where in the
bytestream characters start) and can be used with normal string
comparison functions for sorting and such. PHP encodes
<literal>UTF-8</literal> characters in up to four bytes, like
this:
<table>
<title>UTF-8 encoding</title>
<tgroup cols="3">
<thead>
<row>
<entry>bytes</entry>
<entry>bits</entry>
<entry>representation</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>7</entry>
<entry>0bbbbbbb</entry>
</row>
<row>
<entry>2</entry>
<entry>11</entry>
<entry>110bbbbb 10bbbbbb</entry>
</row>
<row>
<entry>3</entry>
<entry>16</entry>
<entry>1110bbbb 10bbbbbb 10bbbbbb</entry>
</row>
<row>
<entry>4</entry>
<entry>21</entry>
<entry>11110bbb 10bbbbbb 10bbbbbb 10bbbbbb</entry>
</row>
</tbody>
</tgroup>
</table>
Each <replaceable>b</replaceable> represents a bit that can be
used to store character data.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/yaz.xml
+++ phpdoc/nl/functions/yaz.xml
<reference id="ref.yaz">
<title>YAZ functions</title>
<titleabbrev>YAZ</titleabbrev>
<partintro>
<sect1 id="yaz.intro">
<title>Introduction</title>
<para>
This extension offers a PHP interface to the
<productname>YAZ</productname> toolkit that implements the Z39.50
protocol for information retrieval. With this extension you can easily
implement a Z39.50 origin (client) that searches Z39.50 targets
(servers) in parallel.
</para>
<para>
<productname>YAZ</productname> is available at <ulink
url="&url.yaz;">&url.yaz;</ulink>. You can find news information,
example scripts, etc. for this extension at <ulink
url="&url.yaz-phpyaz;">&url.yaz-phpyaz;</ulink>.
</para>
<para>
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 SQL APIs that are available
for PHP. This means that sessions are stateless but shared amongst
users, thus saving the connect and initialize phase steps in most cases.
</para>
</sect1>
<sect1 id="yaz.install">
<title>Installation</title>
<para>
Compile YAZ and install it. Build PHP with your favourite
modules and add option --with-yaz. Your task is roughly the
following:
</para>
<para>
<informalexample>
<programlisting>
gunzip -c yaz-1.6.tar.gz|tar xf -
gunzip -c php-4.0.X.tar.gz|tar xf -
cd yaz-1.6
/configure --prefix=/usr
make
make install
cd ../php-4.0.X
/configure --with-yaz=/usr/bin
make
make install
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="yaz.example">
<title>Example</title>
<para>
PHP/YAZ keeps track of connections with targets
(Z-Associations). A positive integer represents the ID of a
particular association.
</para>
<para>
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 in array
host.
</para>
<para>
<example>
<title><function>YAZ</function></title>
<programlisting role="php">
$num_hosts = count ($host);
if (empty($term) || count($host) == 0) {
echo '<form method="get">
<input type="checkbox"
name="host[]" value="bagel.indexdata.dk/gils">
GILS test
<input type="checkbox"
name="host[]" value="localhost:9999/Default">
local test
<input type="checkbox" checked="1"
name="host[]" value="z3950.bell-labs.com/books">
BELL Labs Library
<br>
RPN Query:
<input type="text" size="30" name="term">
<input type="submit" name="action" value="Search">
';
} else {
echo 'You searced for ' . htmlspecialchars($term) . '<br>';
for ($i = 0; $i < $num_hosts; $i++) {
$id[] = yaz_connect($host[$i]);
yaz_syntax($id[$i],"sutrs");
yaz_search($id[$i],"rpn",$term);
}
yaz_wait();
for ($i = 0; $i < $num_hosts; $i++) {
echo '<hr>' . $host[$i] . ":";
$error = yaz_error($id[$i]);
if (!empty($error)) {
echo "Error: $error";
} else {
$hits = yaz_hits($id[$i]);
echo "Result Count $hits";
}
echo '<dl>';
for ($p = 1; $p <= 10; $p++) {
$rec = yaz_record($id[$i],$p,"string");
if (empty($rec)) continue;
echo
"<dt><b>$p</b></dt><dd>";
echo ereg_replace("\n", "<br>\n",$rec);
echo "</dd>";
}
echo '</dl>';
}
}
</programlisting>
</example>
</para>
</sect1>
</partintro>
<refentry id="function.yaz-addinfo">
<refnamediv>
<refname>yaz_addinfo</refname>
<refpurpose>Returns additional error information</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_addinfo</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns additional error message for target (last request). An
empty string is returned if last operation was a success or if no
additional information was provided by the target.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-close">
<refnamediv>
<refname>yaz_close</refname>
<refpurpose>Closes a YAZ connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_close</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Closes a connection to a target. The application can no longer
refer to the target with the given ID.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-connect">
<refnamediv>
<refname>yaz_connect</refname>
<refpurpose>
Returns a positive association ID on success; zero on failure
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_connect</function></funcdef>
<paramdef>string <parameter>zurl</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yaz_connect</function> prepares for a connection to a
Z39.50 target. The zurl argument takes the form
host[:port][/database]. If port is omitted 210 is used. If
database is omitted Default is used. This function is
non-blocking and doesn't attempt to establish a socket - it
merely prepares a connect to be performed later when
<function>yaz_wait</function> is called.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-errno">
<refnamediv>
<refname>yaz_errno</refname>
<refpurpose>Returns error number</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_errno</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns error for target (last request). A positive value is
returned if the target returned a diagnostic code; a value of
zero is returned if no errors occurred (success); negative value
is returned for other errors targets didn't indicate the error in
question.
</para>
<para>
<function>Yaz_errno</function> should be called after network
activity for each target - (after <function>yaz_wait</function>
returns) to determine the success or failure of the last
operation (e.g. search).
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-error">
<refnamediv>
<refname>yaz_error</refname>
<refpurpose>Returns error description</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_error</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns error message for target (last request). An empty string
is returned if last operation was a success.
</para>
<para>
<function>Yaz_error</function> returns a english message
corresponding to the last error number as returned by
<function>yaz_errno</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-hits">
<refnamediv>
<refname>yaz_hits</refname>
<refpurpose>Returns number of hits for last search</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_hits</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Yaz_hits</function> returns number of hits for last
search.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-range">
<refnamediv>
<refname>yaz_range</refname>
<refpurpose>
Specifies the maximum number of records to retrieve
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_range</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>int <parameter>start</parameter></paramdef>
<paramdef>int <parameter>number</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function is used in conjunction with
<function>yaz_search</function> to specify the maximum number of
records to retrieve (number) and the first record position
(start). If this function is not invoked (only
<function>yaz_search</function>) start is set to 1 and number is
set to 10.
</para>
<para>
Returns true on success; false on error.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-record">
<refnamediv>
<refname>yaz_record</refname>
<refpurpose>Returns a record</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_record</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>int <parameter>pos</parameter></paramdef>
<paramdef>string <parameter>type</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns record at position or empty string if no record exists at
given position.
</para>
<para>
The <function>yaz_record</function> function inspects a record in
the current result set at the position specified. If no database
record exists at the given position an empty string is
returned. The argument, type, specifies the form of the returned
record. If type is "string" the record is returned in a string
representation suitable for printing (for XML and SUTRS). If type
is "array" the record is returned as an array representation (for
structured records).
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-search">
<refnamediv>
<refname>yaz_search</refname>
<refpurpose>Prepares for a search</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_search</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>string <parameter>type</parameter></paramdef>
<paramdef>string <parameter>query</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>yaz_search</function> prepares for a search on the
target with given id. The type represents the query type - only
"rpn" is supported now in which case the third argument specifies
a Type-1 query (RPN). Like <function>yaz_connect</function> this
function is non-blocking and only prepares for a search to be
executed later when <function>yaz_wait</function> is called.
</para>
</refsect1>
<refsect1>
<title>The RPN query</title>
<para>
The RPN query is a textual represenation 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 is ignored unless surrounded by double
quotes. Tokens beginning with an at-character (<literal>@</literal>)
are considered operators, otherwise they are treated as search terms.
</para>
<table>
<title>RPN Operators</title>
<tgroup cols="2">
<thead>
<row>
<entry>Syntax</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>@and query1 query2</literal></entry>
<entry>intersection of query1 and query2</entry>
</row>
<row>
<entry><literal>@or query1 query2</literal></entry>
<entry>union of query1 and query2</entry>
</row>
<row>
<entry><literal>@not query1 query2</literal></entry>
<entry>query1 and not query2</entry>
</row>
<row>
<entry><literal>@set name</literal></entry>
<entry>result set reference</entry>
</row>
<row>
<entry><literal>@attrset set query</literal></entry>
<entry>specifies attribute-set for query. This construction is only
allowed once - in the beginning of the whole query</entry>
</row>
<row>
<entry><literal>@attr set type=value query</literal></entry>
<entry>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.</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
The following illustrates valid query constructions:
<informalexample>
<screen>computer</screen>
</informalexample>
Matches documents where "computer" occur. No attributes are specified.
</para>
<para>
<informalexample>
<screen>"donald knuth"</screen>
</informalexample>
Matches documents where "donald knuth" occur.
</para>
<para>
<informalexample>
<screen>@attr 1=4 art</screen>
</informalexample>
Attribute type is 1 (Bib-1 use), attribute value is 4
Title), so this should match documents where "art" occur
in the title.
</para>
<para>
<informalexample>
<screen>@attrset gils @and @attr 1=4 art @attr 1=1003 "donald knuth"</screen>
</informalexample>
The query as a whole uses the GILS attributeset. The query matches
documents where "art" occur in the title and in which "donald knuth"
occur in the author.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-syntax">
<refnamediv>
<refname>yaz_syntax</refname>
<refpurpose>
Specifies the object identifier (OID) for the preferred record syntax
for retrieval.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_syntax</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>string <parameter>syntax</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The syntax may be specified in a raw dot-notation (like
<literal>1.2.840.10003.5.10</literal>) or as one of the known
record syntaxes (sutrs, usmarc, grs1, xml, etc.).
This function is used in conjunction with
<function>yaz_search</function> to specify the preferred record
syntax for retrieval.
</para>
</refsect1>
</refentry>
<refentry id="function.yaz-wait">
<refnamediv>
<refname>yaz_wait</refname>
<refpurpose>Executes queries</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>yaz_wait</function></funcdef>
<paramdef>int <parameter>id</parameter></paramdef>
<paramdef>string <parameter>syntax</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function carries out networked (blocked) activity for
outstanding requests which have been prepared by the functions
<function>yaz_connect</function>,
<function>yaz_search</function>. <function>yaz_wait</function>
returns when all targets have either completed all requests or
otherwise completed (in case of errors).
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/functions/zlib.xml
+++ phpdoc/nl/functions/zlib.xml
<reference id="ref.zlib">
<title>Zlib Compression Functions</title>
<titleabbrev>Zlib</titleabbrev>
<partintro>
<para>
This module uses the functions of <ulink
url="&url.zlib;">zlib</ulink> by Jean-loup Gailly and Mark Adler to
transparently read and write gzip (.gz) compressed files. You have
to use a zlib version >= 1.0.9 with this module.
</para>
<para>
This module contains versions of most of the <link
linkend="ref.filesystem">filesystem</link> functions which work
with gzip-compressed files (and uncompressed files, too, but not
with sockets).
</para>
<sect1 id="zlib-example">
<title>Small code example</title>
<para>
Opens a temporary file and writes a test string to it, then it
prints out the content of this file twice.
</para>
<example>
<title>Small Zlib Example</title>
<programlisting role="php">
<?php
$filename = tempnam ('/tmp', 'zlibtest').'.gz';
print
"<html>\n<head></head>\n<body>\n<pre>\n";
$s = "Only a test, test, test, test, test, test, test, test!\n";
// open file for writing with maximum compression
$zp = gzopen($filename, "w9");
// write string to file
gzwrite($zp, $s);
// close file
gzclose($zp);
// open file for reading
$zp = gzopen($filename, "r");
// read 3 char
print gzread($zp, 3);
// output until end of the file and close it.
gzpassthru($zp);
print "\n";
// open file and print content (the 2nd time).
if (readgzfile($filename) != strlen($s)) {
echo "Error with zlib functions!";
}
unlink($filename);
print "</pre>\n</h1></body>\n</html>\n";
?>
</programlisting>
</example>
</sect1>
</partintro>
<refentry id="function.gzclose">
<refnamediv>
<refname>gzclose</refname>
<refpurpose>Close an open gz-file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzclose</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The gz-file pointed to by zp is closed.
</para>
<para>
Returns true on success and false on failure.
</para>
<para>
The gz-file pointer must be valid, and must point to a file
successfully opened by <function>gzopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzeof">
<refnamediv>
<refname>gzeof</refname>
<refpurpose>Test for end-of-file on a gz-file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzeof</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns true if the gz-file pointer is at EOF or an error occurs;
otherwise returns false.
</para>
<para>
The gz-file pointer must be valid, and must point to a file
successfully opened by <function>gzopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzfile">
<refnamediv>
<refname>gzfile</refname>
<refpurpose>Read entire gz-file into an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>array <function>gzfile</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int
<parameter><optional>use_include_path</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>readgzfile</function>, except that
<function>gzfile</function> returns the file in an array.
</para>
<para>
You can use the optional second parameter and set it to "1", if
you want to search for the file in the <link
linkend="ini.include-path">include_path</link>, too.
</para>
<para>
See also <function>readgzfile</function>, and
<function>gzopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzgetc">
<refnamediv>
<refname>gzgetc</refname>
<refpurpose>Get character from gz-file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gzgetc</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns a string containing a single (uncompressed) character
read from the file pointed to by zp. Returns FALSE on EOF (as
does <function>gzeof</function>).
</para>
<para>
The gz-file pointer must be valid, and must point to a file
successfully opened by <function>gzopen</function>.
</para>
<para>
See also <function>gzopen</function>, and
<function>gzgets</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzgets">
<refnamediv>
<refname>gzgets</refname>
<refpurpose>Get line from file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gzgets</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
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).
</para>
<para>
If an error occurs, returns false.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>gzopen</function>.
</para>
<para>
See also <function>gzopen</function>,
<function>gzgetc</function>, and <function>fgets</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzgetss">
<refnamediv>
<refname>gzgetss</refname>
<refpurpose>
Get line from gz-file pointer and strip HTML tags
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gzgetss</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
<paramdef>string
<parameter><optional>allowable_tags</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Identical to <function>gzgets</function>, except that
<function>gzgetss</function> attempts to strip any HTML and PHP
tags from the text it reads.
</para>
<para>
You can use the optional third parameter to specify tags which
should not be stripped.
<note>
<para>
<parameter>Allowable_tags</parameter> was added in PHP 3.0.13,
PHP4B3.
</para>
</note>
</para>
<para>
See also <function>gzgets</function>,
<function>gzopen</function>, and <function>strip_tags</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzopen">
<refnamediv>
<refname>gzopen</refname>
<refpurpose>Open gz-file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzopen</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>string <parameter>mode</parameter></paramdef>
<paramdef>int
<parameter><optional>use_include_path</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Opens a gzip (.gz) file for reading or writing. The mode
parameter is as in <function>fopen</function> ("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.)
</para>
<para>
<function>Gzopen</function> can be used to read a file which is
not in gzip format; in this case <function>gzread</function> will
directly read from the file without decompression.
</para>
<para>
<function>Gzopen</function> 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.
</para>
<para>
If the open fails, the function returns false.
</para>
<para>
You can use the optional third parameter and set it to "1", if
you want to search for the file in the <link
linkend="ini.include-path">include_path</link>, too.
</para>
<para>
<example>
<title><function>Gzopen</function> Example</title>
<programlisting role="php">
$fp = gzopen ("/tmp/file.gz", "r");
</programlisting>
</example>
</para>
<para>
See also <function>gzclose</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzpassthru">
<refnamediv>
<refname>gzpassthru</refname>
<refpurpose>
Output all remaining data on a gz-file pointer
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzpassthru</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Reads to EOF on the given gz-file pointer and writes the
(uncompressed) results to standard output.
</para>
<para>
If an error occurs, returns false.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>gzopen</function>.
</para>
<para>
The gz-file is closed when <function>gzpassthru</function> is
done reading it (leaving <parameter>zp</parameter> useless).
</para>
</refsect1>
</refentry>
<refentry id="function.gzputs">
<refnamediv>
<refname>gzputs</refname>
<refpurpose>Write to a gz-file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzputs</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
<paramdef>string <parameter>str</parameter></paramdef>
<paramdef>int
<parameter><optional>length</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
<function>Gzputs</function> is an alias to
<function>gzwrite</function>, and is identical in every way.
</para>
</refsect1>
</refentry>
<refentry id="function.gzread">
<refnamediv>
<refname>gzread</refname>
<refpurpose>Binary-safe gz-file read</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gzread</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
<paramdef>int <parameter>length</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>gzread</function> reads up to
<parameter>length</parameter> bytes from the gz-file pointer
referenced by <parameter>zp</parameter>. Reading stops when
<parameter>length</parameter> (uncompressed) bytes have been read
or EOF is reached, whichever comes first.
</simpara>
<para>
<informalexample>
<programlisting role="php">
// get contents of a gz-file into a string
$filename = "/usr/local/something.txt.gz";
$zd = gzopen ($filename, "r");
$contents = gzread ($zd, 10000);
gzclose ($zd);
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>gzwrite</function>, <function>gzopen</function>,
<function>gzgets</function>, <function>gzgetss</function>,
<function>gzfile</function>, and <function>gzpassthru</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.gzrewind">
<refnamediv>
<refname>gzrewind</refname>
<refpurpose>Rewind the position of a gz-file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzrewind</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the file position indicator for zp to the beginning of the
file stream.
</para>
<para>
If an error occurs, returns 0.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>gzopen</function>.
</para>
<para>
See also <function>gzseek</function> and
<function>gztell</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzseek">
<refnamediv>
<refname>gzseek</refname>
<refpurpose>Seek on a gz-file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzseek</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
<paramdef>int <parameter>offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Sets the file position indicator for the file referenced by zp to
offset bytes into the file stream. Equivalent to calling (in C)
<literal>gzseek( zp, offset, SEEK_SET )</literal>.
</para>
<para>
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.
</para>
<para>
Upon success, returns 0; otherwise, returns -1. Note that seeking
past EOF is not considered an error.
</para>
<para>
See also <function>gztell</function> and
<function>gzrewind</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gztell">
<refnamediv>
<refname>gztell</refname>
<refpurpose>Tell gz-file pointer read/write position</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gztell</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the position of the file pointer referenced by
<parameter>zp</parameter>; i.e., its offset into the file
stream.
</para>
<para>
If an error occurs, returns false.
</para>
<para>
The file pointer must be valid, and must point to a file
successfully opened by <function>gzopen</function>.
</para>
<para>
See also <function>gzopen</function>, <function>gzseek</function>
and <function>gzrewind</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzwrite">
<refnamediv>
<refname>gzwrite</refname>
<refpurpose>Binary-safe gz-file write</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>gzwrite</function></funcdef>
<paramdef>int <parameter>zp</parameter></paramdef>
<paramdef>string <parameter>string</parameter></paramdef>
<paramdef>int
<parameter><optional>length</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>Gzwrite</function> writes the contents of
<parameter>string</parameter> to the gz-file stream pointed to by
<parameter>zp</parameter>. If the <parameter>length</parameter>
argument is given, writing will stop after
<parameter>length</parameter> (uncompressed) bytes have been
written or the end of <parameter>string</parameter> is reached,
whichever comes first.
</simpara>
<simpara>
Note that if the <parameter>length</parameter> argument is given,
then the <link
linkend="ini.magic-quotes-runtime">magic_quotes_runtime</link>
configuration option will be ignored and no slashes will be
stripped from <parameter>string</parameter>.
</simpara>
<simpara>
See also <function>gzread</function>, <function>gzopen</function>,
and <function>gzputs</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.readgzfile">
<refnamediv>
<refname>readgzfile</refname>
<refpurpose>Output a gz-file</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>int <function>readgzfile</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int
<parameter><optional>use_include_path</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Reads a file, decompresses it and writes it to standard
output.
</para>
<para>
<function>Readgzfile</function> can be used to read a file which
is not in gzip format; in this case
<function>readgzfile</function> will directly read from the file
without decompression.
</para>
<para>
Returns the number of (uncompressed) bytes read from the file. If
an error occurs, false is returned and unless the function was
called as <literal>@readgzfile</literal>, an error message is
printed.
</para>
<para>
The file <parameter>filename</parameter> will be opened from the
filesystem and its contents written to standard output.
</para>
<para>
You can use the optional second parameter and set it to "1", if
you want to search for the file in the <link
linkend="ini.include-path">include_path</link>, too.
</para>
<para>
See also <function>gzpassthru</function>,
<function>gzfile</function>, and <function>gzopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzcompress">
<refnamediv>
<refname>gzcompress</refname>
<refpurpose>Gz-compress a string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gzcompress</function></funcdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int
<parameter><optional>level</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns a gzip-compressed version of the input
<parameter>data</parameter> or false on errors. The optional
parameter <parameter>level</parameter> can be given as 0 for no
compression up to 9 for maximum compression.
</para>
<para>
See also <function>gzuncompress</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gzuncompress">
<refnamediv>
<refname>gzuncompress</refname>
<refpurpose>Uncompress a gz-compressed string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>gzuncompress</function></funcdef>
<paramdef>string <parameter>data</parameter></paramdef>
<paramdef>int
<parameter><optional>length</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function takes <parameter>data</parameter> compressed by
<function>gzcompress</function> and returns the orignial
uncompressed data or false on error. The function will return an
error if the uncompressed data is more than 256 times the lenght
of the compressed input <parameter>data</parameter> or more than
the optional parameter <parameter>length</parameter>.
</para>
<para>
See also <function>gzcompress</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/basic-syntax.xml
+++ phpdoc/nl/language/basic-syntax.xml
<chapter id="language.basic-syntax">
<title>Basic syntax</title>
<sect1 id="language.basic-syntax.phpmode">
<title>Escaping from HTML</title>
<para>
There are four ways of escaping from HTML and entering "PHP code
mode":</para>
<para>
<example>
<title>Ways of escaping from HTML</title>
<programlisting>
1. <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
2. <?php echo("if you want to serve XML documents, do like this\n"); ?>
3. <script language="php">
echo ("some editors (like FrontPage) don't
like processing instructions");
</script>
4. <% echo ("You may optionally use ASP-style tags"); %>
<%= $variable; # This is a shortcut for "<%echo .." %>
</programlisting>
</example></para>
<para>
The first way is only available if short tags have been
enabled. This can be done via the <function>short_tags</function>
function, by enabling the <link
linkend="ini.short-open-tag">short_open_tag</link> configuration
setting in the PHP config file, or by compiling PHP with the
--enable-short-tags option to <command>configure</command>.</para>
<para>
The fourth way is only available if ASP-style tags have been
enabled using the <link linkend="ini.asp-tags">asp_tags</link>
configuration setting.
<note>
<para>Support for ASP-style tags was added in 3.0.4.</para>
</note></para>
<para>
The closing tag for the block will include the immediately
trailing newline if one is present.</para></sect1>
<sect1 id="language.basic-syntax.instruction-separation">
<title>Instruction separation</title>
<simpara>
Instructions are separated the same as in C or perl - terminate
each statement with a semicolon.</simpara>
<para>
The closing tag (?>) also implies the end of the statement, so the
following are equivalent:
<informalexample>
<programlisting>
<?php
echo "This is a test";
?>
<?php echo "This is a test" ?>
</programlisting>
</informalexample></para></sect1>
<sect1 id="language.basic-syntax.comments">
<title>Comments</title>
<para>
PHP supports 'C', 'C++' and Unix shell-style comments. For example:
<informalexample><programlisting>
<?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
?>
</programlisting>
</informalexample></para>
<simpara>
The "one-line" comment styles actually only comment to the
end of the line or the current block of PHP code, whichever
comes first.</simpara>
<informalexample><programlisting>
<h1>This is an <?# echo "simple";?> example.</h1>
<p>The header above will say 'This is an example'.
</programlisting></informalexample>
<simpara>
You should be careful not to nest 'C' style comments, which can
happen when commenting out large blocks.</simpara>
<informalexample><programlisting>
<?php
/*
echo "This is a test"; /* This comment will cause a problem */
*/
?>
</programlisting></informalexample></sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/constants.xml
+++ phpdoc/nl/language/constants.xml
<chapter id="language.constants">
<title>Constants</title>
<simpara>
PHP defines several constants and provides a mechanism for defining
more at run-time. Constants are much like variables, save for the
two facts that constants must be defined using the
<function>define</function> function, and that they cannot later be
redefined to another value.
</simpara>
<para>
The predefined constants (always available) are:
<variablelist>
<varlistentry>
<term>__FILE__</term>
<listitem>
<simpara>
The name of the script file presently being parsed. If used
within a file which has been included or required, then the
name of the included file is given, and not the name of the
parent file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>__LINE__</term>
<listitem>
<simpara>
The number of the line within the current script file which is
being parsed. If used within a file which has been included or
required, then the position within the included file is given.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_VERSION</term>
<listitem>
<simpara>
The string representation of the version of the PHP parser
presently in use; e.g. '3.0.8-dev'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_OS</term>
<listitem>
<simpara>
The name of the operating system on which the PHP parser is
executing; e.g. 'Linux'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>TRUE</term>
<listitem>
<simpara>
A true value.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>FALSE</term>
<listitem>
<simpara>
A false value.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_ERROR</term>
<listitem>
<simpara>
Denotes an error other than a parsing error from which
recovery is not possible.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_WARNING</term>
<listitem>
<simpara>
Denotes a condition where PHP knows something is wrong, but
will continue anyway; these can be caught by the script
itself. An example would be an invalid regexp in
<function>ereg</function>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_PARSE</term>
<listitem>
<simpara>
The parser choked on invalid syntax in the script
file. Recovery is not possible.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_NOTICE</term>
<listitem>
<simpara>
Something happened which may or may not be an error. Execution
continues. Examples include using an unquoted string as a hash
index, or accessing a variable which has not been set.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_ALL</term>
<listitem>
<simpara>
All of the E_* constants rolled into one. If used with
<function>error_reporting</function>, will cause any and all
problems noticed by PHP to be reported.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The E_* constants are typically used with the
<function>error_reporting</function> function for setting the
error reporting level. See all these constants at
<link linkend="features.error-handling">Error handling</link>.
</para>
<para>
You can define additional constants using the
<function>define</function> function.</para>
<para>
Note that these are constants, not C-style macros; only valid
scalar data may be represented by a constant.
<example>
<title>Defining Constants</title>
<programlisting>
<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
?>
</programlisting>
</example>
<example>
<title>Using __FILE__ and __LINE__</title>
<programlisting>
<?php
function report_error($file, $line, $message) {
echo "An error occured in $file on line $line: $message.";
}
report_error(__FILE__,__LINE__, "Something went wrong!");
?>
</programlisting>
</example></para>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/control-structures.xml
+++ phpdoc/nl/language/control-structures.xml
<chapter id="control-structures">
<title>Control Structures</title>
<simpara>
Any PHP script is built out of a series of statements. A statement
can be an assignment, a function call, a loop, a conditional
statement of even a statement that does nothing (an empty
statement). Statements usually end with a semicolon. In addition,
statements can be grouped into a statement-group by encapsulating a
group of statements with curly braces. A statement-group is a
statement by itself as well. The various statement types are
described in this chapter.
</simpara>
<sect1 id="control-structures.if">
<title><literal>if</literal></title>
<para>
The <literal>if</literal> construct is one of the most important
features of many languages, PHP included. It allows for
conditional execution of code fragments. PHP features an
<literal>if</literal> structure that is similar to that of C:
<informalexample>
<programlisting>
if (expr)
statement
</programlisting>
</informalexample>
</para>
<simpara>
As described in the section about expressions, expr is evaluated
to its truth value. If <replaceable>expr</replaceable> evaluates
to <literal>TRUE</literal>, PHP will execute statement, and if it
evaluates to <literal>FALSE</literal> - it'll ignore it.
</simpara>
<para>
The following example would display <computeroutput>a is bigger
than b</computeroutput> if <replaceable>$a</replaceable> is bigger
than <replaceable>$b</replaceable>:
<informalexample>
<programlisting role="php">
if ($a > $b)
print "a is bigger than b";
</programlisting>
</informalexample>
</para>
<para>
Often you'd want to have more than one statement to be executed
conditionally. Of course, there's no need to wrap each statement
with an <literal>if</literal> clause. Instead, you can group
several statements into a statement group. For example, this code
would display <computeroutput>a is bigger than b</computeroutput>
if <replaceable>$a</replaceable> is bigger than
<replaceable>$b</replaceable>, and would then assign the value of
<replaceable>$a</replaceable> into <replaceable>$b</replaceable>:
<informalexample>
<programlisting role="php">
if ($a > $b) {
print "a is bigger than b";
$b = $a;
}
</programlisting>
</informalexample>
</para>
<simpara>
If statements can be nested indefinitely within other
<literal>if</literal> statements, which provides you with complete
flexibility for conditional execution of the various parts of your
program.
</simpara>
</sect1>
<sect1 id="control-structures.else">
<title><literal>else</literal></title>
<para>
Often you'd want to execute a statement if a certain condition is
met, and a different statement if the condition is not met. This
is what <literal>else</literal> is for. <literal>else</literal>
extends an <literal>if</literal> statement to execute a statement
in case the expression in the <literal>if</literal> statement
evaluates to <literal>FALSE</literal>. For example, the following
code would display <computeroutput>a is bigger than
b</computeroutput> if <replaceable>$a</replaceable> is bigger than
<replaceable>$b</replaceable>, and <computeroutput>a is NOT bigger
than b</computeroutput> otherwise:
<informalexample>
<programlisting role="php">
if ($a > $b) {
print "a is bigger than b";
} else {
print "a is NOT bigger than b";
}
</programlisting>
</informalexample>
The <literal>else</literal> statement is only executed if the
<literal>if</literal> expression evaluated to
<literal>FALSE</literal>, and if there were any
<literal>elseif</literal> expressions - only if they evaluated to
<literal>FALSE</literal> as well (see <link
linkend="control-structures.elseif">elseif</link>).
</para>
</sect1>
<sect1 id="control-structures.elseif">
<title><literal>elseif</literal></title>
<para>
<literal>elseif</literal>, as its name suggests, is a combination
of <literal>if</literal> and <literal>else</literal>. Like
<literal>else</literal>, it extends an <literal>if</literal>
statement to execute a different statement in case the original
<literal>if</literal> expression evaluates to
<literal>FALSE</literal>. However, unlike
<literal>else</literal>, it will execute that alternative
expression only if the <literal>elseif</literal> conditional
expression evaluates to <literal>TRUE</literal>. For example, the
following code would display <computeroutput>a is bigger than
b</computeroutput>, <computeroutput>a equal to b</computeroutput>
or <computeroutput>a is smaller than b</computeroutput>:
<informalexample>
<programlisting role="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";
}
</programlisting>
</informalexample>
</para>
<simpara>
There may be several <literal>elseif</literal>s within the same
<literal>if</literal> statement. The first
<literal>elseif</literal> expression (if any) that evaluates to
<literal>true</literal> would be executed. In PHP, you can also
write 'else if' (in two words) and the behavior would be identical
to the one of 'elseif' (in a single word). The syntactic meaning
is slightly different (if you're familiar with C, this is the same
behavior) but the bottom line is that both would result in exactly
the same behavior.
</simpara>
<simpara>
The <literal>elseif</literal> statement is only executed if the
preceding <literal>if</literal> expression and any preceding
<literal>elseif</literal> expressions evaluated to
<literal>FALSE</literal>, and the current
<literal>elseif</literal> expression evaluated to
<literal>TRUE</literal>.
</simpara>
</sect1>
<sect1 id="control-structures.alternative-syntax">
<title>Alternative syntax for control structures</title>
<para>
PHP offers an alternative syntax for some of its control
structures; namely, <literal>if</literal>,
<literal>while</literal>, <literal>for</literal>,
<literal>foreach</literal>, and <literal>switch</literal>.
In each case, the basic form of the alternate syntax is to change
the opening brace to a colon (:) and the closing brace to
<literal>endif;</literal>, <literal>endwhile;</literal>,
<literal>endfor;</literal>, <literal>endforeach;</literal>, or
<literal>endswitch;</literal>, respectively.
<informalexample>
<programlisting role="php">
<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>
</programlisting>
</informalexample>
</para>
<simpara>
In the above example, the HTML block "A = 5" is nested within an
<literal>if</literal> statement written in the alternative syntax.
The HTML block would be displayed only if $a is equal to 5.
</simpara>
<para>
The alternative syntax applies to <literal>else</literal> and
<literal>elseif</literal> as well. The following is an
<literal>if</literal> structure with <literal>elseif</literal> and
<literal>else</literal> in the alternative format:
<informalexample>
<programlisting role="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;
</programlisting>
</informalexample>
</para>
<para>
See also <link linkend="control-structures.while">while</link>,
<link linkend="control-structures.for">for</link>, and <link
linkend="control-structures.if">if</link> for further examples.
</para>
</sect1>
<sect1 id="control-structures.while">
<title><literal>while</literal></title>
<para>
<literal>while</literal> loops are the simplest type of loop in
PHP. They behave just like their C counterparts. The basic form
of a <literal>while</literal> statement is:
<informalexample>
<programlisting>
while (expr) statement
</programlisting>
</informalexample>
</para>
<simpara>
The meaning of a <literal>while</literal> statement is simple. It
tells PHP to execute the nested statement(s) repeatedly, as long
as the <literal>while</literal> expression evaluates to
<literal>TRUE</literal>. The value of the expression is checked
each time at the beginning of the loop, so even if this value
changes during the execution of the nested statement(s), execution
will not stop until the end of the iteration (each time PHP runs
the statements in the loop is one iteration). Sometimes, if the
<literal>while</literal> expression evaluates to
<literal>FALSE</literal> from the very beginning, the nested
statement(s) won't even be run once.
</simpara>
<para>
Like with the <literal>if</literal> statement, you can group
multiple statements within the same <literal>while</literal> loop
by surrounding a group of statements with curly braces, or by
using the alternate syntax:
<informalexample>
<programlisting>
while (expr): statement ... endwhile;
</programlisting>
</informalexample>
</para>
<para>
The following examples are identical, and both print numbers from
1 to 10:
<informalexample>
<programlisting>
/* example 1 */
$i = 1;
while ($i <= 10) {
print $i++; /* the printed value would be
$i before the increment
(post-increment) */
}
/* example 2 */
$i = 1;
while ($i <= 10):
print $i;
$i++;
endwhile;
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.do.while">
<title><literal>do..while</literal></title>
<simpara>
<literal>do..while</literal> loops are very similar to
<literal>while</literal> loops, except the truth expression is
checked at the end of each iteration instead of in the beginning.
The main difference from regular <literal>while</literal> loops is
that the first iteration of a <literal>do..while</literal> loop is
guarenteed to run (the truth expression is only checked at the end
of the iteration), whereas it's may not necessarily run with a
regular <literal>while</literal> loop (the truth expression is
checked at the beginning of each iteration, if it evaluates to
<literal>FALSE</literal> right from the beginning, the loop
execution would end immediately).
</simpara>
<para>
There is just one syntax for <literal>do..while</literal> loops:
<informalexample>
<programlisting role="php">
$i = 0;
do {
print $i;
} while ($i>0);
</programlisting>
</informalexample>
</para>
<simpara>
The above loop would run one time exactly, since after the first
iteration, when truth expression is checked, it evaluates to
<literal>FALSE</literal> ($i is not bigger than 0) and the loop
execution ends.
</simpara>
<para>
Advanced C users may be familiar with a different usage of the
<literal>do..while</literal> loop, to allow stopping execution in
the middle of code blocks, by encapsulating them with
<literal>do..while</literal>(0), and using the <link
linkend="control-structures.break"><literal>break</literal></link>
statement. The following code fragment demonstrates this:
<informalexample>
<programlisting role="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);
</programlisting>
</informalexample>
</para>
<simpara>
Don't worry if you don't understand this right away or at all.
You can code scripts and even powerful scripts without using this
`feature'.
</simpara>
</sect1>
<sect1 id="control-structures.for">
<title><literal>for</literal></title>
<para>
<literal>for</literal> loops are the most complex loops in PHP.
They behave like their C counterparts. The syntax of a
<literal>for</literal> loop is:
<informalexample>
<programlisting>
for (expr1; expr2; expr3) statement
</programlisting>
</informalexample>
</para>
<simpara>
The first expression (<replaceable>expr1</replaceable>) is
evaluated (executed) once unconditionally at the beginning of the
loop.
</simpara>
<simpara>
In the beginning of each iteration,
<replaceable>expr2</replaceable> is evaluated. If it evaluates to
<literal>TRUE</literal>, the loop continues and the nested
statement(s) are executed. If it evaluates to
<literal>FALSE</literal>, the execution of the loop ends.
</simpara>
<simpara>
At the end of each iteration, <replaceable>expr3</replaceable> is
evaluated (executed).
</simpara>
<simpara>
Each of the expressions can be empty.
<replaceable>expr2</replaceable> being empty means the loop should
be run indefinitely (PHP implicitly considers it as
<literal>TRUE</literal>, like C). This may not be as useless as
you might think, since often you'd want to end the loop using a
conditional <link
linkend="control-structures.break"><literal>break</literal></link>
statement instead of using the <literal>for</literal> truth
expression.
</simpara>
<para>
Consider the following examples. All of them display numbers from
1 to 10:
<informalexample>
<programlisting role="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++) ;
</programlisting>
</informalexample>
</para>
<simpara>
Of course, the first example appears to be the nicest one (or
perhaps the fourth), but you may find that being able to use empty
expressions in <literal>for</literal> loops comes in handy in many
occasions.
</simpara>
<para>
PHP also supports the alternate "colon syntax" for
<literal>for</literal> loops.
<informalexample>
<programlisting>
for (expr1; expr2; expr3): statement; ...; endfor;
</programlisting>
</informalexample>
</para>
<para>
Other languages have a <literal>foreach</literal> statement to
traverse an array or hash. PHP 3 has no such construct; PHP 4 does
(see <link
linkend="control-structures.foreach">foreach</link>). In PHP 3, you
can combine <link linkend="control-structures.while">while</link>
with the <function>list</function> and <function>each</function>
functions to achieve the same effect. See the documentation for
these functions for an example.
</para>
</sect1>
<sect1 id="control-structures.foreach">
<title><literal>foreach</literal></title>
<para>
PHP 4 (not PHP 3) includes a <literal>foreach</literal> construct,
much like perl and some other languages. This simply gives an easy
way to iterate over arrays. There are two syntaxes; the second is
a minor but useful extension of the first:
<informalexample>
<programlisting>
foreach(array_expression as $value) statement
foreach(array_expression as $key => $value) statement
</programlisting>
</informalexample>
</para>
<simpara>
The first form loops over the array given by
<literal>array_expression</literal>. On each loop, the value of
the current element is assigned to <literal>$value</literal> and
the internal array pointer is advanced by one (so on the next
loop, you'll be looking at the next element).
</simpara>
<simpara>
The second form does the same thing, except that the current
element's key will be assigned to the variable
<literal>$key</literal> on each loop.
</simpara>
<para>
<note>
<para>
When <literal>foreach</literal> first starts executing, the
internal array pointer is automatically reset to the first element
of the array. This means that you do not need to call
<function>reset</function> before a <literal>foreach</literal>
loop.
</para>
</note>
</para>
<para>
<note>
<para>
Also note that <literal>foreach</literal> operates on a copy of
the specified array, not the array itself, therefore the array
pointer is not modified like with the each construct.
</para>
</note>
</para>
<para>
You may have noticed that the following are functionally
identical:
<informalexample>
<programlisting role="php">
reset ($arr);
while (list(, $value) = each ($arr)) {
echo "Value: $value<br>\n";
}
foreach ($arr as $value) {
echo "Value: $value<br>\n";
}
</programlisting>
</informalexample>
The following are also functionally identical:
<informalexample>
<programlisting role="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";
}
</programlisting>
</informalexample>
</para>
<para>
Some more examples to demonstrate usages:
<informalexample>
<programlisting role="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] => $k.\n";
}
/* 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";
}
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.break">
<title><literal>break</literal></title>
<simpara>
<literal>break</literal> ends execution of the current
<literal>for</literal>, <literal>while</literal>, or
<literal>switch</literal> structure.
</simpara>
<simpara>
<literal>break</literal> accepts an optional numeric argument
which tells it how many nested enclosing structures are to be
broken out of.
</simpara>
<para>
<informalexample>
<programlisting role="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;
}
}
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.continue">
<title><literal>continue</literal></title>
<simpara>
<literal>continue</literal> is used within looping structures to
skip the rest of the current loop iteration and continue execution
at the beginning of the next iteration.
</simpara>
<simpara>
<literal>continue</literal> accepts an optional numeric argument
which tells it how many levels of enclosing loops it should skip
to the end of.
</simpara>
<para>
<informalexample>
<programlisting role="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";
}
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="control-structures.switch">
<title><literal>switch</literal></title>
<simpara>
The <literal>switch</literal> statement is similar to a series of
IF statements on the same expression. In many occasions, you may
want to compare the same variable (or expression) with many
different values, and execute a different piece of code depending
on which value it equals to. This is exactly what the
<literal>switch</literal> statement is for.
</simpara>
<para>
The following two examples are two different ways to write the
same thing, one using a series of <literal>if</literal>
statements, and the other using the <literal>switch</literal>
statement:
<informalexample>
<programlisting role="php">
if ($i == 0) {
print "i equals 0";
}
if ($i == 1) {
print "i equals 1";
}
if ($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;
}
</programlisting>
</informalexample>
</para>
<para>
It is important to understand how the <literal>switch</literal>
statement is executed in order to avoid mistakes. The
<literal>switch</literal> statement executes line by line
(actually, statement by statement). In the beginning, no code is
executed. Only when a <literal>case</literal> statement is found
with a value that matches the value of the
<literal>switch</literal> expression does PHP begin to execute the
statements. PHP continues to execute the statements until the end
of the <literal>switch</literal> block, or the first time it sees
a <literal>break</literal> statement. If you don't write a
<literal>break</literal> statement at the end of a case's
statement list, PHP will go on executing the statements of the
following case. For example:
<informalexample>
<programlisting role="php">
switch ($i) {
case 0:
print "i equals 0";
case 1:
print "i equals 1";
case 2:
print "i equals 2";
}
</programlisting>
</informalexample>
</para>
<simpara>
Here, if $i equals to 0, PHP would execute all of the print
statements! If $i equals to 1, PHP would execute the last two
print statements, and only if $i equals to 2, you'd get the
'expected' behavior and only 'i equals 2' would be displayed. So,
it's important not to forget <literal>break</literal> statements
(even though you may want to avoid supplying them on purpose under
certain circumstances).
</simpara>
<simpara>
In a <literal>switch</literal> statement, the condition is
evaluated only once and the result is compared to each
<literal>case</literal> statement. In an <literal>elseif</literal>
statement, the condition is evaluated again. If your condition is
more complicated than a simple compare and/or is in a tight loop,
a <literal>switch</literal> may be faster.
</simpara>
<para>
The statement list for a case can also be empty, which simply
passes control into the statement list for the next case.
<informalexample>
<programlisting role="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";
}
</programlisting>
</informalexample>
</para>
<para>
A special case is the default case. This case matches anything
that wasn't matched by the other cases. For example:
<informalexample>
<programlisting role="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";
}
</programlisting>
</informalexample>
</para>
<para>
The <literal>case</literal> expression may be any expression that
evaluates to a simple type, that is, integer or floating-point
numbers and strings. Arrays or objects cannot be used here unless
they are dereferenced to a simple type.
</para>
<para>
The alternative syntax for control structures is supported with
switches. For more information, see <link
linkend="control-structures.alternative-syntax">Alternative syntax
for control structures</link> .
<informalexample>
<programlisting role="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";
endswitch;
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="function.require">
<title><function>require</function></title>
<simpara>
The <function>require</function> statement replaces itself with
the specified file, much like the C preprocessor's
<literal>#include</literal> works.
</simpara>
<simpara>
If "URL fopen wrappers" are enabled in PHP (which they are in the
default configuration), you can specify the file to be
<function>require</function>ed using an URL instead of a local
pathname. See <link linkend="features.remote-files">Remote
files</link> and <function>fopen</function> for more information.
</simpara>
<simpara>
An important note about how this works is that when a file is
<function>include</function>ed or <function>require</function>ed,
parsing drops out of PHP mode and into HTML mode at the beginning
of the target file, and resumes PHP mode again at the end. For
this reason, any code inside the target file which should be
executed as PHP code must be enclosed within <link
linkend="language.basic-syntax.phpmode">valid PHP start and end
tags</link>.
</simpara>
<simpara>
<function>require</function> is not actually a function in PHP;
rather, it is a language construct. It is subject to some
different rules than functions are. For instance,
<function>require</function> is not subject to any containing
control structures. For another, it does not return any value;
attempting to read a return value from a
<function>require</function> call results in a parse error.
</simpara>
<simpara>
Unlike <function>include</function>, <function>require</function>
will <emphasis>always</emphasis> read in the target file,
<emphasis>even if the line it's on never executes</emphasis>. If
you want to conditionally include a file, use
<function>include</function>. The conditional statement won't
affect the <function>require</function>. However, if the line on
which the <function>require</function> occurs is not executed,
neither will any of the code in the target file be executed.
</simpara>
<simpara>
Similarly, looping structures do not affect the behaviour of
<function>require</function>. Although the code contained in the
target file is still subject to the loop, the
<function>require</function> itself happens only once.
</simpara>
<para>
This means that you can't put a <function>require</function>
statement inside of a loop structure and expect it to include the
contents of a different file on each iteration. To do that, use an
<function>include</function> statement.
<informalexample>
<programlisting role="php">
require ('header.inc');
</programlisting>
</informalexample>
</para>
<simpara>
When a file is <function>require</function>ed, the code it
contains inherits the variable scope of the line on which the
<function>require</function> occurs. Any variables available at
that line in the calling file will be available within the called
file. If the <function>require</function> occurs inside a
function within the calling file, then all of the code contained
in the called file will behave as though it had been defined
inside that function.
</simpara>
<para>
If the <function>require</function>ed file is called via HTTP
using the fopen wrappers, and if the target server interprets the
target file as PHP code, variables may be passed to the
<function>require</function>ed file using an URL request string as
used with HTTP GET. This is not strictly speaking the same thing
as <function>require</function>ing the file and having it inherit
the parent file's variable scope; the script is actually being run
on the remote server and the result is then being included into
the local script.
<informalexample>
<programlisting role="php">
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the require()ed file. */
/* Won't work; file.txt wasn't handled by someserver. */
require ("http://someserver/file.txt?varone=1&vartwo=2");
/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
require ("file.php?varone=1&vartwo=2");
/* Works. */
require ("http://someserver/file.php?varone=1&vartwo=2");
$varone = 1;
$vartwo = 2;
require ("file.txt"); /* Works. */
require ("file.php"); /* Works. */
</programlisting>
</informalexample>
</para>
<simpara>
In PHP 3, it is possible to execute a <literal>return</literal>
statement inside a <function>require</function>ed file, as long as
that statement occurs in the global scope of the
<function>require</function>ed file. It may not occur within any
block (meaning inside braces ({}). In PHP 4, however, this ability
has been discontinued. If you need this functionality, see
<function>include</function>.
</simpara>
<simpara>
See also <function>include</function>,
<function>require_once</function>,
<function>include_once</function>, <function>readfile</function>,
and <function>virtual</function>.
</simpara>
</sect1>
<sect1 id="function.include">
<title><function>include</function></title>
<simpara>
The <function>include</function> statement includes and evaluates
the specified file.
</simpara>
<simpara>
If "URL fopen wrappers" are enabled in PHP (which they are in the
default configuration), you can specify the file to be
<function>include</function>ed using an URL instead of a local
pathname. See <link linkend="features.remote-files">Remote
files</link> and <function>fopen</function> for more information.
</simpara>
<simpara>
An important note about how this works is that when a file is
<function>include</function>ed or <function>require</function>ed,
parsing drops out of PHP mode and into HTML mode at the beginning
of the target file, and resumes again at the end. For this reason,
any code inside the target file which should be executed as PHP
code must be enclosed within <link
linkend="language.basic-syntax.phpmode">valid PHP start and end
tags</link>.
</simpara>
<para>
This happens each time the <function>include</function> statement
is encountered, so you can use an <function>include</function>
statement within a looping structure to include a number of
different files.
<informalexample>
<programlisting role="php">
$files = array ('first.inc', 'second.inc', 'third.inc');
for ($i = 0; $i < count($files); $i++) {
include $files[$i];
}
</programlisting>
</informalexample>
</para>
<para>
<function>include</function> differs from
<function>require</function> in that the include statement is
re-evaluated each time it is encountered (and only when it is
being executed), whereas the <function>require</function>
statement is replaced by the required file when it is first
encountered, whether the contents of the file will be evaluated or
not (for example, if it is inside an <link
linkend="control-structures.if">if</link> statement whose
condition evaluated to false).
</para>
<para>
Because <function>include</function> is a special language
construct, you must enclose it within a statement block if it is
inside a conditional block.
<informalexample>
<programlisting role="php">
/* This is WRONG and will not work as desired. */
if ($condition)
include($file);
else
include($other);
/* This is CORRECT. */
if ($condition) {
include($file);
} else {
include($other);
}
</programlisting>
</informalexample>
</para>
<simpara>
In both PHP 3 and PHP 4, it is possible to execute a
<literal>return</literal> statement inside an
<function>include</function>ed file, in order to terminate
processing in that file and return to the script which called
it. Some differences in the way this works exist, however. The
first is that in PHP 3, the <literal>return</literal> may not
appear inside a block unless it's a function block, in which case
the <literal>return</literal> applies to that function and not the
whole file. In PHP 4, however, this restriction does not
exist. Also, PHP 4 allows you to return values from
<function>include</function>ed files. You can take the value of
the <function>include</function> call as you would a normal
function. This generates a parse error in PHP 3.
</simpara>
<example>
<title><function>include</function> in PHP 3 and PHP 4</title>
<para>
Assume the existence of the following file (named
<filename>test.inc</filename>) in the same directory as the main
file:
<programlisting role="php">
<?php
echo "Before the return <br>\n";
if (1) {
return 27;
}
echo "After the return <br>\n";
?>
</programlisting>
</para>
<para>
Assume that the main file (<filename>main.html</filename>)
contains the following:
<programlisting role="php">
<?php
$retval = include ('test.inc');
echo "File returned: '$retval'<br>\n";
?>
</programlisting>
</para>
<para>
When <filename>main.html</filename> is called in PHP 3, it will
generate a parse error on line 2; you can't take the value of an
<function>include</function> in PHP 3. In PHP 4, however, the
result will be:
<screen>
Before the return
File returned: '27'
</screen>
</para>
<para>
Now, assume that <filename>main.html</filename> has been altered
to contain the following:
<programlisting role="php">
<?php
include ('test.inc');
echo "Back in main.html<br>\n";
?>
</programlisting>
</para>
<para>
In PHP 4, the output will be:
<screen>
Before the return
Back in main.html
</screen>
However, PHP 3 will give the following output:
<screen>
Before the return
27Back in main.html
Parse error: parse error in /home/torben/public_html/phptest/main.html on line 5
</screen>
</para>
<para>
The above parse error is a result of the fact that the
<literal>return</literal> statement is enclosed in a non-function
block within <filename>test.inc</filename>. When the return is
moved outside of the block, the output is:
<screen>
Before the return
27Back in main.html
</screen>
</para>
<para>
The spurious '27' is due to the fact that PHP 3 does not support
<literal>return</literal>ing values from files like that.
</para>
</example>
<simpara>
When a file is <function>include</function>ed, the code it
contains inherits the variable scope of the line on which the
<function>include</function> occurs. Any variables available at
that line in the calling file will be available within the called
file. If the <function>include</function> occurs inside a
function within the calling file, then all of the code contained
in the called file will behave as though it had been defined
inside that function.
</simpara>
<para>
If the <function>include</function>ed file is called via HTTP
using the fopen wrappers, and if the target server interprets the
target file as PHP code, variables may be passed to the
<function>include</function>ed file using an URL request string as
used with HTTP GET. This is not strictly speaking the same thing
as <function>include</function>ing the file and having it inherit
the parent file's variable scope; the script is actually being run
on the remote server and the result is then being included into
the local script.
<informalexample>
<programlisting role="php">
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the include()ed file. */
/* Won't work; file.txt wasn't handled by someserver. */
include ("http://someserver/file.txt?varone=1&vartwo=2");
/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
include ("file.php?varone=1&vartwo=2");
/* Works. */
include ("http://someserver/file.php?varone=1&vartwo=2");
$varone = 1;
$vartwo = 2;
include ("file.txt"); /* Works. */
include ("file.php"); /* Works. */
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>require</function>,
<function>require_once</function>,
<function>include_once</function>, <function>readfile</function>,
and <function>virtual</function>.
</simpara>
</sect1>
<sect1 id="function.require-once">
<title><function>require_once</function></title>
<para>
The <function>require_once</function> statement replaces
itself with the specified file, much like the C preprocessor's
<literal>#include</literal> works, and in that respect is
similar to the <function>require</function> statement. The main
difference is that in an inclusion chain, the use of
<function>require_once</function> will assure that the code is
added to your script only once, and avoid clashes with variable
values or function names that can happen.
</para>
<para>
For example, if you create the following 2 include files
<literal>utils.inc</literal> and <literal>foolib.inc</literal>
<example>
<title>utils.inc</title>
<programlisting role="php">
<?php
define(PHPVERSION, floor(phpversion()));
echo "GLOBALS ARE NICE\n";
function goodTea() {
return "Oolong tea tastes good!";
}
?>
</programlisting>
</example>
<example>
<title>foolib.inc</title>
<programlisting role="php">
<?php
require ("utils.inc");
function showVar($var) {
if (PHPVERSION == 4) {
print_r($var);
} else {
dump_var($var);
}
}
// bunch of other functions ...
?>
</programlisting>
</example>
And then you write a script <literal>cause_error_require.php</literal>
<example>
<title>cause_error_require.php</title>
<programlisting role="php">
<?php
require("foolib.inc");
/* the following will generate an error */
require("utils.inc");
$foo = array("1",array("complex","quaternion"));
echo "this is requiring utils.inc again which is also\n";
echo "required in foolib.inc\n";
echo "Running goodTea: ".goodTea()."\n";
echo "Printing foo: \n";
showVar($foo);
?>
</programlisting>
</example>
When you try running the latter one, the resulting ouptut will be (using
PHP 4.01pl2):
<informalexample>
<programlisting>
GLOBALS ARE NICE
GLOBALS ARE NICE
Fatal error: Cannot redeclare causeerror() in utils.inc on line 5
</programlisting>
</informalexample>
By modifying <literal>foolib.inc</literal> and
<literal>cause_errror_require.php</literal>
to use <function>require_once</function>
instead of <function>require</function> and renaming the
last one to <literal>avoid_error_require_once.php</literal>, we have:
<example>
<title>foolib.inc (fixed)</title>
<programlisting role="php">
..
require_once("utils.inc");
function showVar($var) {
..
</programlisting>
</example>
<example>
<title>avoid_error_require_once.php</title>
<programlisting role="php">
..
require_once("foolib.inc");
require_once("utils.inc");
$foo = array("1",array("complex","quaternion"));
..
</programlisting>
</example>
And when running the latter, the output will be (using PHP 4.0.1pl2):
<informalexample>
<programlisting>
GLOBALS ARE NICE
this is requiring globals.inc again which is also
required in foolib.inc
Running goodTea: Oolong tea tastes good!
Printing foo:
Array
(
[0] => 1
[1] => Array
(
[0] => complex
[1] => quaternion
)
)
</programlisting>
</informalexample>
</para>
<para>
Also note that, analogous to the behavior of the
<literal>#include</literal> of the C preprocessor, this statement
acts at "compile time", e.g. when the script is parsed and before it
is executed, and should not be used for parts of the script that need
to be inserted dynamically during its execution. You should use
<function>include_once</function> or <function>include</function>
for that purpose.
</para>
<para>
For more examples on using <function>require_once</function> and
<function>include_once</function>, look at the PEAR code included in
the latest PHP source code distributions.
</para>
<para>
See also: <function>require</function>,
<function>include</function>, <function>include_once</function>,
<function>get_required_files</function>,
<function>get_included_files</function>, <function>readfile</function>,
and <function>virtual</function>.
</para>
</sect1>
<sect1 id="function.include-once">
<title><function>include_once</function></title>
<para>
The <function>include_once</function> statement includes and evaluates
the specified file during the execution of the script.
This is a behavior similar to the <function>include</function> statement,
with the important difference that if the code from a file has already
been included, it will not be included again.
</para>
<para>
As mentioned in the <function>require_once</function> description, the
<function>include_once</function> should be used in the cases in which
the same file might be included and evaluated more than once during a
particular execution of a script, and you want to be sure that it is
included exactly once to avoid problems with function redefinitions,
variable value reassignments, etc.
</para>
<para>
For more examples on using <function>require_once</function> and
<function>include_once</function>, look at the PEAR code included in
the latest PHP source code distributions.
</para>
<para>
<function>include_once</function> was added in PHP 4.0.1pl2
</para>
<para>
See also: <function>require</function>,
<function>include</function>, <function>require_once</function>,
<function>get_required_files</function>,
<function>get_included_files</function>, <function>readfile</function>,
and <function>virtual</function>.
</para>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/expressions.xml
+++ phpdoc/nl/language/expressions.xml
<chapter id="language.expressions">
<title>Expressions</title>
<simpara>
Expressions are the most important building stones of PHP. In PHP,
almost anything you write is an expression. The simplest yet
most accurate way to define an expression is "anything that has a
value".</simpara>
<simpara>
The most basic forms of expressions are constants and variables.
When you type "$a = 5", you're assigning '5' into $a. '5',
obviously,
has the value 5, or in other words '5' is an expression with the
value of 5 (in this case, '5' is an integer constant).</simpara>
<simpara>
After this assignment, you'd expect $a's value to be 5 as
well, so if you wrote $b = $a, you'd expect it to behave just as
if you wrote $b = 5. In other words, $a is an expression with the
value of 5 as well. If everything works right, this is exactly
what will happen.</simpara>
<para>
Slightly more complex examples for expressions are functions. For
instance, consider the following function:
<informalexample>
<programlisting>
function foo () {
return 5;
}
</programlisting>
</informalexample></para>
<simpara>
Assuming you're familiar with the concept of functions (if you're
not, take a look at the chapter about functions), you'd assume
that typing <literal>$c = foo()</literal> is essentially just like
writing <literal>$c = 5</literal>, and you're right. Functions
are expressions with the value of their return value. Since foo()
returns 5, the value of the expression 'foo()' is 5. Usually
functions don't just return a static value but compute something.</simpara>
<simpara>
Of course, values in PHP don't have to be integers, and very often
they aren't. PHP supports three scalar value types: integer values,
floating point values and string values (scalar values are values that
you can't 'break' into smaller pieces, unlike arrays, for instance).
PHP also supports two composite (non-scalar) types: arrays and
objects. Each of these value types can be assigned into variables or
returned from functions.</simpara>
<simpara>
So far, users of PHP/FI 2 shouldn't feel any change. However, PHP
takes expressions much further, in the same way many other
languages do. PHP is an expression-oriented language, in the
sense that almost everything is an expression. Consider the
example we've already dealt with, '$a = 5'. It's easy to see that
there are two values involved here, the value of the integer
constant '5', and the value of $a which is being updated to 5 as
well. But the truth is that there's one additional value involved
here, and that's the value of the assignment itself. The
assignment itself evaluates to the assigned value, in this case 5.
In practice, it means that '$a = 5', regardless of what it does,
is an expression with the value 5. Thus, writing something like
'$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon
marks the end of a statement). Since assignments are parsed in a
right to left order, you can also write '$b = $a = 5'.</simpara>
<simpara>
Another good example of expression orientation is pre- and
post-increment and decrement. Users of PHP/FI 2 and many other
languages may be familiar with the notation of variable++ and
variable--. These are increment and decrement operators. In
PHP/FI 2, the statement '$a++' has no value (is not an
expression), and thus you can't assign it or use it in any way.
PHP enhances the increment/decrement capabilities by making
these expressions as well, like in C. In PHP, like in C, there
are two types of increment - pre-increment and post-increment.
Both pre-increment and post-increment essentially increment the
variable, and the effect on the variable is idential. The
difference is with the value of the increment expression.
Pre-increment, which is written '++$variable', evaluates to the
incremented value (PHP increments the variable before reading its
value, thus the name 'pre-increment'). Post-increment, which is
written '$variable++' evaluates to the original value of
$variable, before it was incremented (PHP increments the variable
after reading its value, thus the name 'post-increment').</simpara>
<simpara>
A very common type of expressions are comparison expressions.
These expressions evaluate to either 0 or 1, meaning FALSE or TRUE
(respectively). PHP supports > (bigger than), >= (bigger than
or equal to), == (equal), != (not equal), < (smaller than) and <=
(smaller than or equal to). These expressions are most commonly used
inside conditional execution, such as <literal>if</literal>
statements.</simpara>
<simpara>
The last example of expressions we'll deal with here is combined
operator-assignment expressions. You already know that if you
want to increment $a by 1, you can simply write '$a++' or '++$a'.
But what if you want to add more than one to it, for instance 3?
You could write '$a++' multiple times, but this is obviously not a
very efficient or comfortable way. A much more common practice is
to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a
plus 3, and is assigned back into $a, which results in
incrementing $a by 3. In PHP, as in several other languages
like C, you can write this in a shorter way, which with time would
become clearer and quicker to understand as well. Adding 3 to the
current value of $a can be written '$a += 3'. This means exactly
"take the value of $a, add 3 to it, and assign it back into $a".
In addition to being shorter and clearer, this also results in
faster execution. The value of '$a += 3', like the value of a
regular assignment, is the assigned value. Notice that it is NOT
3, but the combined value of $a plus 3 (this is the value that's
assigned into $a). Any two-place operator can be used in this
operator-assignment mode, for example '$a -= 5' (subtract 5 from
the value of $a), '$b *= 7' (multiply the value of $b by 7), etc.</simpara>
<para>
There is one more expression that may seem odd if you haven't seen
it in other languages, the ternary conditional operator:
<informalexample><programlisting>
$first ? $second : $third
</programlisting></informalexample>
If the value of the first subexpression is true (non-zero), then
it the second subexpression is evaluated, and that is the result
of the conditional expression. Otherwise, the third subexpression
is evaluated, and that is the value.</para>
<para>
The following example should help you understand pre- and
post-increment and expressions in general a bit better:
<informalexample>
<programlisting>
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 <emphasis>before</emphasis>
the increment, 2*6 = 12 to $f */
$g = double(++$e); /* assign twice the value of $e <emphasis>after</emphasis>
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. */
</programlisting></informalexample></para>
<simpara>
In the beginning of the chapter we said that we'll be describing
the various statement types, and as promised, expressions can be
statements. However, not every expression is a statement. In
this case, a statement has the form of 'expr' ';' that is, an
expression followed by a semicolon. In '$b=$a=5;', $a=5 is a
valid expression, but it's not a statement by itself. '$b=$a=5;'
however is a valid statement.</simpara>
<simpara>
One last thing worth mentioning is the truth value of expressions.
In many events, mainly in conditional execution and loops, you're
not interested in the specific value of the expression, but only
care about whether it means TRUE or FALSE (PHP doesn't have a
dedicated boolean type). The truth value of expressions in PHP is
calculated in a similar way to perl. Any numeric non-zero numeric
value is TRUE, zero is FALSE. Be sure to note that negative
values are non-zero and are thus considered TRUE! The empty
string and the string "0" are FALSE; all other strings are TRUE.
With non-scalar values (arrays and objects) - if the value
contains no elements it's considered FALSE, otherwise it's
considered TRUE.</simpara>
<simpara>
PHP provides a full and powerful implementation of expressions, and
documenting it entirely goes beyond the scope of this manual. The
above examples should give you a good idea about what expressions
are and how you can construct useful expressions. Throughout the
rest of this manual we'll write <replaceable>expr</replaceable>
to indicate any valid PHP expression.</simpara>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/functions.xml
+++ phpdoc/nl/language/functions.xml
<chapter id="functions">
<title>Functions</title>
<sect1 id="functions.user-defined">
<title>User-defined functions</title>
<para>
A function may be defined using syntax such as the following:
<informalexample>
<programlisting role="php">
function foo ($arg_1, $arg_2, ..., $arg_n) {
echo "Example function.\n";
return $retval;
}
</programlisting>
</informalexample>
</para>
<simpara>
Any valid PHP code may appear inside a function, even other
functions and <link linkend="keyword.class">class</link>
definitions.
</simpara>
<simpara>
In PHP 3, functions must be defined before they are referenced. No
such requirement exists in PHP 4.
</simpara>
<simpara>
PHP does not support function overloading, nor is it possible to
undefine or redefine previously-declared functions.
</simpara>
<simpara>
PHP 3 does not support variable numbers of arguments to functions,
although default arguments are supported (see <link
linkend="functions.arguments.default">Default argument
values</link> for more information). PHP 4 supports both: see <link
linkend="functions.variable-arg-list">Variable-length argument
lists</link> and the function references for
<function>func_num_args</function>,
<function>func_get_arg</function>, and
<function>func_get_args</function> for more information.
</simpara>
</sect1>
<sect1 id="functions.arguments">
<title>Function arguments</title>
<simpara>
Information may be passed to functions via the argument list,
which is a comma-delimited list of variables and/or constants.
</simpara>
<para>
PHP supports passing arguments by value (the default), <link
linkend="functions.arguments.by-reference">passing by
reference</link>, and <link
linkend="functions.arguments.default">default argument
values</link>. Variable-length argument lists are supported only
in PHP 4 and later; see <link
linkend="functions.variable-arg-list">Variable-length argument
lists</link> and the function references for
<function>func_num_args</function>,
<function>func_get_arg</function>, and
<function>func_get_args</function> for more information. A
similar effect can be achieved in PHP 3 by passing an array of
arguments to a function:
<informalexample>
<programlisting role="php">
function takes_array($input) {
echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
</programlisting>
</informalexample>
</para>
<sect2 id="functions.arguments.by-reference">
<title>Making arguments be passed by reference</title>
<simpara>
By default, function arguments are passed by value (so that if
you change the value of the argument within the function, it does
not get changed outside of the function). If you wish to allow a
function to modify its arguments, you must pass them by
reference.
</simpara>
<para>
If you want an argument to a function to always be passed by
reference, you can prepend an ampersand (&) to the argument
name in the function definition:
<informalexample>
<programlisting role="php">
function add_some_extra(&$string) {
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'
</programlisting>
</informalexample>
</para>
<para>
If you wish to pass a variable by reference to a function which
does not do this by default, you may prepend an ampersand to the
argument name in the function call:
<informalexample>
<programlisting role="php">
function foo ($bar) {
$bar .= ' and something extra.';
}
$str = 'This is a string, ';
foo ($str);
echo $str; // outputs 'This is a string, '
foo (&$str);
echo $str; // outputs 'This is a string, and something extra.'
</programlisting>
</informalexample>
</para>
</sect2>
<sect2 id="functions.arguments.default">
<title>Default argument values</title>
<para>
A function may define C++-style default values for scalar
arguments as follows:
<informalexample>
<programlisting role="php">
function makecoffee ($type = "cappucino") {
return "Making a cup of $type.\n";
}
echo makecoffee ();
echo makecoffee ("espresso");
</programlisting>
</informalexample>
</para>
<para>
The output from the above snippet is:
<screen>
Making a cup of cappucino.
Making a cup of espresso.
</screen>
</para>
<simpara>
The default value must be a constant expression, not (for
example) a variable or class member.
</simpara>
<para>
Note that when using default arguments, any defaults should be on
the right side of any non-default arguments; otherwise, things
will not work as expected. Consider the following code snippet:
<informalexample>
<programlisting role="php">
function makeyogurt ($type = "acidophilus", $flavour) {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // won't work as expected
</programlisting>
</informalexample>
</para>
<para>
The output of the above example is:
<screen>
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 .
</screen>
</para>
<para>
Now, compare the above with this:
<informalexample>
<programlisting role="php">
function makeyogurt ($flavour, $type = "acidophilus") {
return "Making a bowl of $type $flavour.\n";
}
echo makeyogurt ("raspberry"); // works as expected
</programlisting>
</informalexample>
</para>
<para>
The output of this example is:
<screen>
Making a bowl of acidophilus raspberry.
</screen>
</para>
</sect2>
<sect2 id="functions.variable-arg-list">
<title>Variable-length argument lists</title>
<simpara>
PHP 4 has support for variable-length argument lists in
user-defined functions. This is really quite easy, using the
<function>func_num_args</function>,
<function>func_get_arg</function>, and
<function>func_get_args</function> functions.
</simpara>
<simpara>
No special syntax is required, and argument lists may still be
explicitly provided with function definitions and will behave as
normal.
</simpara>
</sect2>
</sect1>
<sect1 id="functions.returning-values">
<title>Returning values</title>
<para>
Values are returned by using the optional return statement. Any
type may be returned, including lists and objects.
<informalexample>
<programlisting role="php">
function square ($num) {
return $num * $num;
}
echo square (4); // outputs '16'.
</programlisting>
</informalexample>
</para>
<para>
You can't return multiple values from a function, but similar
results can be obtained by returning a list.
<informalexample>
<programlisting role="php">
function small_numbers() {
return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
</programlisting>
</informalexample>
</para>
<para>
To return a reference from a function, you have to use
the reference operator & in both the function declaration and
when assigning the return value to a variable:
<informalexample>
<programlisting role="php">
function &returns_reference() {
return &$someref;
}
$newref = &returns_reference();
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="functions.old-syntax">
<title><literal>old_function</literal></title>
<simpara>
The <literal>old_function</literal> statement allows you to
declare a function using a syntax identical to PHP/FI2 (except you
must replace 'function' with 'old_function'.
</simpara>
<simpara>
This is a deprecated feature, and should only be used by the
PHP/FI2->PHP 3 convertor.
</simpara>
<warning>
<para>
Functions declared as <literal>old_function</literal> cannot be
called from PHP's internal code. Among other things, this means
you can't use them in functions such as
<function>usort</function>, <function>array_walk</function>, and
<function>register_shutdown_function</function>. You can get
around this limitation by writing a wrapper function (in normal
PHP 3 form) to call the <literal>old_function</literal>.
</para>
</warning>
</sect1>
<sect1 id="functions.variable-functions">
<title>Variable functions</title>
<para>
PHP supports the concept of variable functions. This means that if
a variable name has parentheses appended to it, PHP will look for
a function with the same name as whatever the variable evaluates
to, and will attempt to execute it. Among other things, this can
be used to implement callbacks, function tables, and so forth.
</para>
<para>
<example>
<title>Variable function example</title>
<programlisting role="php">
<?php
function foo() {
echo "In foo()<br>\n";
}
function bar( $arg = '' ) {
echo "In bar(); argument was '$arg'.<br>\n";
}
$func = 'foo';
$func();
$func = 'bar';
$func( 'test' );
?>
</programlisting>
</example>
</para>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/oop.xml
+++ phpdoc/nl/language/oop.xml
<chapter id="language.oop">
<title>Classes and Objects</title>
<sect1 id="keyword.class">
<title><literal>class</literal></title>
<para>
A class is a collection of variables and functions working with
these variables. A class is defined using the following syntax:
<informalexample>
<programlisting role="php">
<?php
class Cart {
var $items; // Items in our shopping cart
// Add $num articles of $artnr to the cart
function add_item ($artnr, $num) {
$this->items[$artnr] += $num;
}
// Take $num articles of $artnr out of the cart
function remove_item ($artnr, $num) {
if ($this->items[$artnr] > $num) {
$this->items[$artnr] -= $num;
return true;
} else {
return false;
}
}
}
?>
</programlisting>
</informalexample>
</para>
<para>
This defines a class named Cart that consists of an associative
array of articles in the cart and two functions to add and remove
items from this cart.
</para>
<note><simpara>
In PHP 4, only constant initializers for <literal>var</literal>
variables are allowed. Use constructors for non-constant initializers.
</simpara></note>
<para>
Classes are types, that is, they are blueprints for actual
variables. You have to create a variable of the desired type with
the new operator.
</para>
<informalexample>
<programlisting role="php">
$cart = new Cart;
$cart->add_item("10", 1);
</programlisting>
</informalexample>
<para>
This creates an object $cart of the class Cart. The function
add_item() of that object is being called to add 1 item of article
number 10 to the cart. </para><para> Classes can be extensions of
other classes. The extended or derived class has all variables and
functions of the base class and what you add in the extended
definition. This is done using the extends keyword. Multiple
inheritance is not supported.
</para>
<informalexample>
<programlisting role="php">
class Named_Cart extends Cart {
var $owner;
function set_owner ($name) {
$this->owner = $name;
}
}
</programlisting>
</informalexample>
<para>
This defines a class Named_Cart that has all variables and
functions of Cart plus an additional variable $owner and an
additional function set_owner(). You create a named cart the usual
way and can now set and get the carts owner. You can still use
normal cart functions on named carts:
</para>
<informalexample>
<programlisting role="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)
</programlisting>
</informalexample>
<para>
Within functions of a class the variable $this means this
object. You have to use $this->something to access any variable or
function named something within your current object.
</para>
<para>
Constructors are functions in a class that are automatically
called when you create a new instance of a class. A function
becomes a constructor when it has the same name as the class.
</para>
<informalexample>
<programlisting role="php">
class Auto_Cart extends Cart {
function Auto_Cart () {
$this->add_item ("10", 1);
}
}
</programlisting>
</informalexample>
<para>
This defines a class Auto_Cart that is a Cart plus a constructor
which initializes the cart with one item of article number "10"
each time a new Auto_Cart is being made with "new". Constructors
can also take arguments and these arguments can be optional, which
makes them much more useful.
</para>
<informalexample>
<programlisting role="php">
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);
</programlisting>
</informalexample>
<caution>
<simpara>
For derived classes, the constructor of the parent class is not
automatically called when the derived class's constructor is
called.
</simpara>
</caution>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/operators.xml
+++ phpdoc/nl/language/operators.xml
<chapter id="language.operators">
<title>Operators</title>
<simpara>
</simpara>
<sect1 id="language.operators.arithmetic">
<title>Arithmetic Operators</title>
<simpara>
Remember basic arithmetic from school? These work just
like those.
</simpara>
<table>
<title>Arithmetic Operators</title>
<tgroup cols="3">
<thead>
<row>
<entry>Example</entry>
<entry>Name</entry>
<entry>Result</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a + $b</entry>
<entry>Addition</entry>
<entry>Sum of $a and $b.</entry>
</row>
<row>
<entry>$a - $b</entry>
<entry>Subtraction</entry>
<entry>Difference of $a and $b.</entry>
</row>
<row>
<entry>$a * $b</entry>
<entry>Multiplication</entry>
<entry>Product of $a and $b.</entry>
</row>
<row>
<entry>$a / $b</entry>
<entry>Division</entry>
<entry>Quotient of $a and $b.</entry>
</row>
<row>
<entry>$a % $b</entry>
<entry>Modulus</entry>
<entry>Remainder of $a divided by $b.</entry>
</row>
</tbody>
</tgroup>
</table>
<simpara>
The division operator ("/") returns an integer value (the result
of an integer division) if the two operands are integers (or
strings that get converted to integers) and the quotient is an
integer. If either operand is a floating-point value, or the
operation results in a non-integer value, a floating-point value
is returned.
</simpara>
</sect1>
<sect1 id="language.operators.assignment">
<title>Assignment Operators</title>
<simpara>
The basic assignment operator is "=". Your first inclination might
be to think of this as "equal to". Don't. It really means that the
the left operand gets set to the value of the expression on the
rights (that is, "gets set to").
</simpara>
<para>
The value of an assignment expression is the value assigned. That
is, the value of "$a = 3" is 3. This allows you to do some tricky
things:
<informalexample>
<programlisting role="php">
$a = ($b = 4) + 5; // $a is equal to 9 now, and $b has been set to 4.
</programlisting>
</informalexample>
</para>
<para>
In addition to the basic assignment operator, there are "combined
operators" for all of the binary arithmetic and string operators
that allow you to use a value in an expression and then set its
value to the result of that expression. For example:
<informalexample>
<programlisting role="php">
$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!";
</programlisting>
</informalexample>
</para>
<para>
Note that the assignment copies the original variable to the new
one (assignment by value), so changes to one will not affect the
other. This may also have relevance if you need to copy something
like a large array inside a tight loop. PHP 4 supports assignment
by reference, using the <computeroutput>$var =
&$othervar;</computeroutput> syntax, but this is not possible
in PHP 3. 'Assignment by reference' means that both variables end
up pointing at the same data, and nothing is copied anywhere.
To learn more about references, please read <link
linkend="language.references">References explained</link>.
</para>
</sect1>
<sect1 id="language.operators.bitwise">
<title>Bitwise Operators</title>
<simpara>
Bitwise operators allow you to turn specific bits within an
integer on or off.
</simpara>
<table>
<title>Bitwise Operators</title>
<tgroup cols="3">
<thead>
<row>
<entry>Example</entry>
<entry>Name</entry>
<entry>Result</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a & $b</entry>
<entry>And</entry>
<entry>Bits that are set in both $a and $b are set.</entry>
</row>
<row>
<entry>$a | $b</entry>
<entry>Or</entry>
<entry>Bits that are set in either $a or $b are set.</entry>
</row>
<row>
<entry>$a ^ $b</entry>
<entry>Xor</entry>
<entry>
Bits that are set in $a or $b but not both are set.
</entry>
</row>
<row>
<entry>~ $a</entry>
<entry>Not</entry>
<entry>
Bits that are set in $a are not set, and vice versa.
</entry>
</row>
<row>
<entry>$a << $b</entry>
<entry>Shift left</entry>
<entry>
Shift the bits of $a $b steps to the left (each step means
"multiply by two")
</entry>
</row>
<row>
<entry>$a >> $b</entry>
<entry>Shift right</entry>
<entry>
Shift the bits of $a $b steps to the right (each step means
"divide by two")
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1 id="language.operators.comparison">
<title>Comparison Operators</title>
<simpara>
Comparison operators, as their name implies, allow you to compare
two values.
</simpara>
<table>
<title>Comparison Operators</title>
<tgroup cols="3">
<thead>
<row>
<entry>Example</entry>
<entry>Name</entry>
<entry>Result</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a == $b</entry>
<entry>Equal</entry>
<entry>True if $a is equal to $b.</entry>
</row>
<row>
<entry>$a === $b</entry>
<entry>Identical</entry>
<entry>
True if $a is equal to $b, and they are of the same
type. (PHP 4 only)
</entry>
</row>
<row>
<entry>$a != $b</entry>
<entry>Not equal</entry>
<entry>True if $a is not equal to $b.</entry>
</row>
<row>
<entry>$a !== $b</entry>
<entry>Not identical</entry>
<entry>
True if $a is not equal to $b, or they are not of the same
type. (PHP 4 only)
</entry>
</row>
<row>
<entry>$a < $b</entry>
<entry>Less than</entry>
<entry>True if $a is strictly less than $b.</entry>
</row>
<row>
<entry>$a > $b</entry>
<entry>Greater than</entry>
<entry>True if $a is strictly greater than $b.</entry>
</row>
<row>
<entry>$a <= $b</entry>
<entry>Less than or equal to </entry>
<entry>True if $a is less than or equal to $b.</entry>
</row>
<row>
<entry>$a >= $b</entry>
<entry>Greater than or equal to </entry>
<entry>True if $a is greater than or equal to $b.</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Another conditional operator is the "?:" (or ternary) operator,
which operates as in C and many other languages.
<informalexample>
<programlisting>
(expr1) ? (expr2) : (expr3);
</programlisting>
</informalexample>
This expression evaluates to <replaceable>expr2</replaceable> if
<replaceable>expr1</replaceable> evaluates to true, and
<replaceable>expr3</replaceable> if
<replaceable>expr1</replaceable> evaluates to false.
</para>
</sect1>
<sect1 id="language.operators.errorcontrol">
<title>Error Control Operators</title>
<simpara>
PHP supports one error control operator: the at sign (@). When
prepended to an expression in PHP, any error messages that might
be generated by that expression will be ignored.
</simpara>
<simpara>
If the <link linkend="ini.track-errors">track_errors</link>
feature is enabled, any error message generated by the expression
will be saved in the global variable $php_errormsg. This variable
will be overwritten on each error, so check early if you want to
use it.
</simpara>
<para>
<informalexample>
<programlisting role="php">
<?php
/* Intentional SQL error (extra quote): */
$res = @mysql_query ("select name, code from 'namelist") or
die ("Query failed: error was '$php_errormsg'");
?>
</programlisting>
</informalexample>
</para>
<simpara>
See also <function>error_reporting</function>.
</simpara>
<warning>
<para>
Currently the "@" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "@" to
suppress errors from a certain function and either it isn't
available or has been mistyped, the script will die right there
with no indication as to why.
</para>
</warning>
</sect1>
<sect1 id="language.operators.execution">
<title>Execution Operators</title>
<para>
PHP supports one execution operator: backticks (``). Note that
these are not single-quotes! PHP will attempt to execute the
contents of the backticks as a shell command; the output will be
returned (i.e., it won't simply be dumped to output; it can be
assigned to a variable).
<informalexample>
<programlisting role="php">
$output = ls -al;
echo "<pre>$output</pre>";
</programlisting>
</informalexample>
</para>
<para>
See also <function>system</function>,
<function>passthru</function>, <function>exec</function>,
<function>popen</function>, and
<function>escapeshellcmd</function>.
</para>
</sect1>
<sect1 id="language.operators.increment">
<title>Incrementing/Decrementing Operators</title>
<para>
PHP supports C-style pre- and post-increment and decrement
operators.
</para>
<table>
<title>Increment/decrement Operators</title>
<tgroup cols="3">
<thead>
<row>
<entry>Example</entry>
<entry>Name</entry>
<entry>Effect</entry>
</row>
</thead>
<tbody>
<row>
<entry>++$a</entry>
<entry>Pre-increment</entry>
<entry>Increments $a by one, then returns $a.</entry>
</row>
<row>
<entry>$a++</entry>
<entry>Post-increment</entry>
<entry>Returns $a, then increments $a by one.</entry>
</row>
<row>
<entry>--$a</entry>
<entry>Pre-decrement</entry>
<entry>Decrements $a by one, then returns $a.</entry>
</row>
<row>
<entry>$a--</entry>
<entry>Post-decrement</entry>
<entry>Returns $a, then decrements $a by one.</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Here's a simple example script:
<informalexample>
<programlisting role="php">
<?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";
?>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="language.operators.logical">
<title>Logical Operators</title>
<table>
<title>Logical Operators</title>
<tgroup cols="3">
<thead>
<row>
<entry>Example</entry>
<entry>Name</entry>
<entry>Result</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a and $b</entry>
<entry>And</entry>
<entry>True if both $a and $b are true.</entry>
</row>
<row>
<entry>$a or $b</entry>
<entry>Or</entry>
<entry>True if either $a or $b is true.</entry>
</row>
<row>
<entry>$a xor $b</entry>
<entry>Or</entry>
<entry>True if either $a or $b is true, but not both.</entry>
</row>
<row>
<entry>! $a</entry>
<entry>Not</entry>
<entry>True if $a is not true.</entry>
</row>
<row>
<entry>$a && $b</entry>
<entry>And</entry>
<entry>True if both $a and $b are true.</entry>
</row>
<row>
<entry>$a || $b</entry>
<entry>Or</entry>
<entry>True if either $a or $b is true.</entry>
</row>
</tbody>
</tgroup>
</table>
<simpara>
The reason for the two different variations of "and" and "or"
operators is that they operate at different precedences. (See
<link linkend="language.operators.precedence">Operator
Precedence</link>.)
</simpara>
</sect1>
<sect1 id="language.operators.precedence">
<title>Operator Precedence</title>
<para>
The precedence of an operator specifies how "tightly" it binds two
expressions together. For example, in the expression <literal>1 +
5 * 3</literal>, the answer is <literal>16</literal> and not
<literal>18</literal> because the multiplication ("*") operator
has a higher precedence than the addition ("+") operator.
Parentheses may be used to force precedence, if necessary. For
instance: <literal>(1 + 5) * 3</literal> evaluates to
<literal>18</literal>.
</para>
<para>
The following table lists the precedence of operators with the
lowest-precedence operators listed first.
<table>
<title>Operator Precedence</title>
<tgroup cols="2">
<thead>
<row>
<entry>Associativity</entry>
<entry>Operators</entry>
</row>
</thead>
<tbody>
<row>
<entry>left</entry>
<entry>,</entry>
</row>
<row>
<entry>left</entry>
<entry>or</entry>
</row>
<row>
<entry>left</entry>
<entry>xor</entry>
</row>
<row>
<entry>left</entry>
<entry>and</entry>
</row>
<row>
<entry>right</entry>
<entry>print</entry>
</row>
<row>
<entry>left</entry>
<entry>
= += -= *= /= .= %= &= |= ^= ~= <<= >>=
</entry>
</row>
<row>
<entry>left</entry>
<entry>? :</entry>
</row>
<row>
<entry>left</entry>
<entry>||</entry>
</row>
<row>
<entry>left</entry>
<entry>&&</entry>
</row>
<row>
<entry>left</entry>
<entry>|</entry>
</row>
<row>
<entry>left</entry>
<entry>^</entry>
</row>
<row>
<entry>left</entry>
<entry>&</entry>
</row>
<row>
<entry>non-associative</entry>
<entry>== != === !==</entry>
</row>
<row>
<entry>non-associative</entry>
<entry>< <= > >=</entry>
</row>
<row>
<entry>left</entry>
<entry><< >></entry>
</row>
<row>
<entry>left</entry>
<entry>+ - .</entry>
</row>
<row>
<entry>left</entry>
<entry>* / %</entry>
</row>
<row>
<entry>right</entry>
<entry>! ~ ++ -- (int) (double) (string) (array) (object) @</entry>
</row>
<row>
<entry>right</entry>
<entry>[</entry>
</row>
<row>
<entry>non-associative</entry>
<entry>new</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect1>
<sect1 id="language.operators.string">
<title>String Operators</title>
<simpara>
There are two string operators. The first is the concatenation
operator ('.'), which returns the concatenation of its right and
left arguments. The second is the concatenating assignment
operator ('.='), which appends the argument on the right side to
the argument on the left side. Please read <link
linkend="language.operators.assignment">Assignment
Operators</link> for more information.
</simpara>
<para>
<informalexample>
<programlisting role="php">
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"
$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
</programlisting>
</informalexample>
</para>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/references.xml
+++ phpdoc/nl/language/references.xml
<chapter id="language.references">
<title>References Explained</title>
<sect1 id="language.references.whatare">
<title>What References Are</title>
<simpara>
References in PHP are means to call same variable content with
different names. They are not like C pointers, they are symbol
table aliases. Note that in PHP, variable names and variable
content are different, so same content can have different
names. The most close analogy is Unix filenames and files -
variable names are directory entries, while variable contents is
the file itself. References can be thought of as hardlinking in
Unix filesystem.
</simpara>
</sect1>
<sect1 id="language.references.whatdo">
<title>What References Do</title>
<para>
PHP references allow you to make two variables to refer to the
same content. Meaning, when you do:
<informalexample>
<programlisting role="php">
$a =& $b
</programlisting>
</informalexample>
it means that <varname>$a</varname> and <varname>$b</varname>
point to the same variable.
<note>
<para>
<varname>$a</varname> and <varname>$b</varname> are completely
equal here, that's not <varname>$a</varname> is pointing to
<varname>$b</varname> or vice versa, that's
<varname>$a</varname> and <varname>$b</varname> pointing to the
same place.
</para>
</note>
</para>
<para>
The second thing references do is to pass variables
by-reference. This is done by making local function variable and
caller variable to be reference to the same content. Example:
<informalexample>
<programlisting role="php">
function foo (&$var) {
$var++;
}
$a=5;
foo ($a);
</programlisting>
</informalexample>
will make <varname>$a</varname> to be 6. This happens because in
the function <varname>foo</varname> the variable
<varname>$var</varname> refers to the same content as
<varname>$a</varname>.
</para>
<simpara>
The third thing reference can do is <link
linkend="language.references.return">return by-reference</link>.
</simpara>
</sect1>
<sect1 id="language.references.arent">
<title>What References Are Not</title>
<para>
As said above, references aren't pointers. That means, the
following construct won't do what you expect:
<informalexample>
<programlisting role="php">
function foo (&$var) {
$var =& $GLOBALS["baz"];
}
foo($bar);
</programlisting>
</informalexample>
</para>
<simpara>
What will happen that <varname>$var</varname> in foo will be bound
with <varname>$bar</varname> in caller, but then it will be
re-bound with <varname>$GLOBALS["baz"]</varname>. There's no way
to bind <varname>$bar</varname> in the caller to something else
using reference mechanism, since <varname>$bar</varname> is not
available in the function foo (it is represented by
<varname>$var</varname>, but <varname>$var</varname> has only
variable contents and not name-to-value binding in the calling
symbol table).
</simpara>
</sect1>
<sect1 id="language.references.return">
<title>Returning References</title>
<para>
Returning by-reference it is useful when you want to use a function
to find which variable a reference should be bound to. When
returning references, use this syntax:
<informalexample>
<programlisting role="php">
function &find_var ($param) {
...code...
return $found_var;
}
$foo =& find_var ($bar);
$foo->x = 2;
</programlisting>
</informalexample>
In this example, the property of the object returned by the
<varname>find_var</varname> function would be set, not the
copy, as it would be without using reference syntax.
</para>
<note>
<simpara>
Unlike parameter passing, here you have to use
<literal>&</literal> in both places - to indicate that you
return by-reference, not a copy as usual, and to indicate that
reference binding, rather than usual assignment, should be done
for <varname>$foo</varname>.
</simpara>
</note>
</sect1>
<sect1 id="language.references.unset">
<title>Unsetting References</title>
<para>
When you unset the reference, you just break the binding between
variable name and variable content. This does not mean that
variable content will be destroyed. For example:
<informalexample>
<programlisting role="php">
$a = 1;
$b =& $a;
unset ($a);
</programlisting>
</informalexample>
won't unset <varname>$b</varname>, just <varname>$a</varname>.
</para>
<simpara>
Again, it might be useful to think about this as analogous to Unix
<command>unlink</command> call.
</simpara>
</sect1>
<sect1 id="language.references.spot">
<title>Spotting References</title>
<simpara>
Many syntax constructs in PHP are implemented via referencing
mechanisms, so everything told above about reference binding also
apply to these constructs. Some constructs, like passing and
returning by-reference, are mentioned above. Other constructs that
use references are:
</simpara>
<sect2 id="references.global">
<title><literal>global</literal> References</title>
<para>
When you declare variable as <command>global $var</command> you
are in fact creating reference to a global variable. That means,
this is the same as:
<informalexample>
<programlisting role="php">
$var =& $GLOBALS["var"];
</programlisting>
</informalexample>
</para>
<simpara>
That means, for example, that unsetting <varname>$var</varname>
won't unset global variable.
</simpara>
</sect2>
<sect2 id="references.this">
<title><literal>$this</literal></title>
<simpara>
In an object method, <varname>$this</varname> is always reference
to the caller object.
</simpara>
</sect2>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/types.xml
+++ phpdoc/nl/language/types.xml
<chapter id="language.types">
<title>Types</title>
<para>
PHP supports the following types:
<itemizedlist>
<listitem>
<simpara>
<link linkend="language.types.array">array</link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.double">floating-point numbers
</link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.integer">integer</link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.object">object</link>
</simpara>
</listitem>
<listitem>
<simpara>
<link linkend="language.types.string">string</link>
</simpara>
</listitem>
</itemizedlist>
</para>
<simpara>
The type of a variable is usually not set by the programmer;
rather, it is decided at runtime by PHP depending on the context in
which that variable is used.
</simpara>
<simpara>
If you would like to force a variable to be converted to a certain
type, you may either <link
linkend="language.types.typecasting">cast</link> the variable or
use the <function>settype</function> function on it.
</simpara>
<simpara>
Note that a variable may behave in different manners in certain
situations, depending on what type it is at the time. For more
information, see the section on <link
linkend="language.types.type-juggling">Type Juggling</link>.
</simpara>
<sect1 id="language.types.integer">
<title>Integers</title>
<para>
Integers can be specified using any of the following syntaxes:
<informalexample>
<programlisting role="php">
$a = 1234; # decimal number
$a = -123; # a negative number
$a = 0123; # octal number (equivalent to 83 decimal)
$a = 0x12; # hexadecimal number (equivalent to 18 decimal)
</programlisting>
</informalexample>
The size of an integer is platform-dependent, although a
maximum value of about 2 billion is the usual value
(that's 32 bits signed).
</para>
</sect1>
<sect1 id="language.types.double">
<title>Floating point numbers</title>
<para>
Floating point numbers ("doubles") can be specified using any of
the following syntaxes:
<informalexample>
<programlisting role="php">
$a = 1.234; $a = 1.2e3;
</programlisting>
</informalexample>
The size of a floating point number is platform-dependent,
although a maximum of ~1.8e308 with a precision of roughly 14
decimal digits is a common value (that's 64 bit IEEE format).
</para>
<warning id="warn.float-precision">
<para>
It is quite usual that simple decimal fractions like
<literal>0.1</literal> or <literal>0.7</literal> cannot be
converted into their internal binary counterparts without a
little loss of precision. This can lead to confusing results: for
example, <literal>floor((0.1+0.7)*10)</literal> will usually
return <literal>7</literal> instead of the expected
<literal>8</literal> as the result of the internal representation
really being something like <literal>7.9999999999...</literal>.
</para>
<para>
This is related to the fact that it is impossible to exactly
express some fractions in decimal notation with a finite number
of digits. For instance, <literal>1/3</literal> in decimal form
becomes <literal>0.3333333. . .</literal>.
</para>
<para>
So never trust floating number results to the last digit and
never compare floating point numbers for equality. If you really
need higher precision, you should use the <link
linkend="ref.bc">arbitrary precision math functions</link>
instead.
</para>
</warning>
</sect1>
<sect1 id="language.types.string">
<title>Strings</title>
<para>
Strings can be specified using one of two sets of delimiters.
</para>
<para>
If the string is enclosed in double-quotes ("), variables within
the string will be expanded (subject to some parsing
limitations). As in C and Perl, the backslash ("\") character can
be used in specifying special characters:
<table>
<title>Escaped characters</title>
<tgroup cols="2">
<thead>
<row>
<entry>sequence</entry>
<entry>meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>\n</literal></entry>
<entry>linefeed (LF or 0x0A in ASCII)</entry>
</row>
<row>
<entry><literal>\r</literal></entry>
<entry>carriage return (CR or 0x0D in ASCII)</entry>
</row>
<row>
<entry><literal>\t</literal></entry>
<entry>horizontal tab (HT or 0x09 in ASCII)</entry>
</row>
<row>
<entry><literal>\\</literal></entry>
<entry>backslash</entry>
</row>
<row>
<entry><literal>\$</literal></entry>
<entry>dollar sign</entry>
</row>
<row>
<entry><literal>\"</literal></entry>
<entry>double-quote</entry>
</row>
<row>
<entry><literal>\[0-7]{1,3}</literal></entry>
<entry>
the sequence of characters matching the regular
expression is a character in octal notation
</entry>
</row>
<row>
<entry><literal>\x[0-9A-Fa-f]{1,2}</literal></entry>
<entry>
the sequence of characters matching the regular
expression is a character in hexadecimal notation
</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
You can escape any other character, but a warning will be issued
at the highest warning level.
</para>
<para>
The second way to delimit a string uses the single-quote ("'")
character. When a string is enclosed in single quotes, the only
escapes that will be understood are "\\" and "\'". This is for
convenience, so that you can have single-quotes and backslashes in
a single-quoted string. Variables will <emphasis>not</emphasis> be
expanded inside a single-quoted string.
</para>
<simpara>
Another way to delimit strings is by using here doc syntax
("<<<"). One should provide an identifier after
<literal><<<</literal>, then the string, and then the
same identifier to close the quotation. The closing identifier
<emphasis>must</emphasis> begin in the first column of the line.
The label used must follow the same naming rules as any other
label in PHP: it must contain only alphanumeric characters and
underscores, and must start with a non-digit character or
underscore.
</simpara>
<para>
Here doc text behaves just like a double-quoted string, without
the double-quotes. This means that you do not need to escape quotes
in your here docs, but you can still use the escape codes listed
above. Variables are expanded, but the same care must be taken
when expressing complex variables inside a here doc as with
strings.
<example>
<title>Here doc string quoting example</title>
<programlisting>
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
/* More complex example, with variables. */
class foo {
var $foo;
var $bar;
function foo() {
$this->foo = 'Foo';
$this->bar = array('Bar1', 'Bar2', 'Bar3');
}
}
$foo = new foo();
$name = 'MyName';
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>
</programlisting>
</example>
</para>
<note>
<para>
Here doc support was added in PHP 4.
</para>
</note>
<para>
Strings may be concatenated using the '.' (dot) operator. Note
that the '+' (addition) operator will not work for this. Please
see <link linkend="language.operators.string">String
operators</link> for more information.
</para>
<para>
Characters within strings may be accessed by treating the string
as a numerically-indexed array of characters, using C-like
syntax. See below for examples.
</para>
<para>
<example>
<title>Some string examples</title>
<programlisting role="php">
<?php
/* Assigning a string. */
$str = "This is a string";
/* Appending to it. */
$str = $str . " with some more text";
/* Another way to append, includes an escaped newline. */
$str .= " and a newline at the end.\n";
/* This string will end up being '<p>Number: 9</p>' */
$num = 9;
$str = "<p>Number: $num</p>";
/* This one will be '<p>Number: $num</p>' */
$num = 9;
$str = '<p>Number: $num</p>';
/* Get the first character of a string */
$str = 'This is a test.';
$first = $str[0];
/* Get the last character of a string. */
$str = 'This is still a test.';
$last = $str[strlen($str)-1];
?>
</programlisting>
</example>
</para>
<sect2 id="language.types.string.conversion">
<title>String conversion</title>
<simpara>
When a string is evaluated as a numeric value, the resulting
value and type are determined as follows.
</simpara>
<simpara>
The string will evaluate as a double if it contains any of the
characters '.', 'e', or 'E'. Otherwise, it will evaluate as an
integer.
</simpara>
<para>
The value is given by the initial portion of the string. If the
string starts with valid numeric data, this will be the value
used. Otherwise, the value will be 0 (zero). Valid numeric data
is an optional sign, followed by one or more digits (optionally
containing a decimal point), followed by an optional
exponent. The exponent is an 'e' or 'E' followed by one or more
digits.
</para>
<simpara>
When the first expression is a string, the type of the variable
will depend on the second expression.
</simpara>
<informalexample>
<programlisting role="php">
$foo = 1 + "10.5"; // $foo is double (11.5)
$foo = 1 + "-1.3e3"; // $foo is double (-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 = 1 + "10 Little Piggies"; // $foo is integer (11)
$foo = "10.0 pigs " + 1; // $foo is integer (11)
$foo = "10.0 pigs " + 1.0; // $foo is double (11)
</programlisting>
</informalexample>
<simpara>
For more information on this conversion, see the Unix manual page
for strtod(3).
</simpara>
<para>
If you would like to test any of the examples in this section,
you can cut and paste the examples and insert the following line
to see for yourself what's going on:
<informalexample>
<programlisting role="php">
echo "\$foo==$foo; type is " . gettype ($foo) . "<br>\n";
</programlisting>
</informalexample>
</para>
</sect2>
</sect1>
<sect1 id="language.types.array">
<title>Arrays</title>
<para>
Arrays actually act like both hash tables (associative arrays) and
indexed arrays (vectors).
</para>
<sect2 id="language.types.array.single-dim">
<title>Single Dimension Arrays</title>
<para>
PHP supports both scalar and associative arrays. In fact, there
is no difference between the two. You can create an array using
the <function>list</function> or <function>array</function>
functions, or you can explicitly set each array element value.
<informalexample>
<programlisting role="php">
$a[0] = "abc";
$a[1] = "def";
$b["foo"] = 13;
</programlisting>
</informalexample>
</para>
<para>
You can also create an array by simply adding values to the
array. When you assign a value to an array variable using empty
brackets, the value will be added onto the end of the array.
<informalexample>
<programlisting role="php">
$a[] = "hello"; // $a[2] == "hello"
$a[] = "world"; // $a[3] == "world"
</programlisting>
</informalexample>
</para>
<para>
Arrays may be sorted using the <function>asort</function>,
<function>arsort</function>, <function>ksort</function>,
<function>rsort</function>, <function>sort</function>,
<function>uasort</function>, <function>usort</function>, and
<function>uksort</function> functions depending on the type of
sort you want.
</para>
<para>
You can count the number of items in an array using the
<function>count</function> function.
</para>
<para>
You can traverse an array using <function>next</function> and
<function>prev</function> functions. Another common way to
traverse an array is to use the <function>each</function>
function.
</para>
</sect2>
<sect2 id="language.types.array.multi-dim">
<title>Multi-Dimensional Arrays</title>
<para>
Multi-dimensional arrays are actually pretty simple. For each
dimension of the array, you add another [key] value to the end:
<informalexample>
<programlisting role="php">
$a[1] = $f; # one dimensional examples
$a["foo"] = $f;
$a[1][0] = $f; # two dimensional
$a["foo"][2] = $f; # (you can mix numeric and associative indices)
$a[3]["bar"] = $f; # (you can mix numeric and associative indices)
$a["foo"][4]["bar"][0] = $f; # four dimensional!
</programlisting>
</informalexample>
</para>
<para>
In PHP 3 it is not possible to reference multidimensional arrays
directly within strings. For instance, the following will not
have the desired result:
<informalexample>
<programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This won't work: $a[3][bar]";
</programlisting>
</informalexample>
In PHP 3, the above will output <computeroutput>This won't work:
Array[bar]</computeroutput>. The string concatenation operator,
however, can be used to overcome this:
<informalexample>
<programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This will work: " . $a[3][bar];
</programlisting>
</informalexample>
</para>
<para>
In PHP 4, however, the whole problem may be circumvented by
enclosing the array reference (inside the string) in curly
braces:
<informalexample>
<programlisting role="php">
$a[3]['bar'] = 'Bob';
echo "This will work: {$a[3][bar]}";
</programlisting>
</informalexample>
</para>
<para>
You can "fill up" multi-dimensional arrays in many ways, but the
trickiest one to understand is how to use the
<function>array</function> command for associative arrays. These
two snippets of code fill up the one-dimensional array in the
same way:
<informalexample>
<programlisting role="php">
# Example 1:
$a["color"] = "red";
$a["taste"] = "sweet";
$a["shape"] = "round";
$a["name"] = "apple";
$a[3] = 4;
# Example 2:
$a = array(
"color" => "red",
"taste" => "sweet",
"shape" => "round",
"name" => "apple",
3 => 4
);
</programlisting>
</informalexample>
</para>
<para>
The <function>array</function> function can be nested for
multi-dimensional arrays:
<informalexample>
<programlisting role="php">
<?
$a = array(
"apple" => array(
"color" => "red",
"taste" => "sweet",
"shape" => "round"
),
"orange" => array(
"color" => "orange",
"taste" => "tart",
"shape" => "round"
),
"banana" => array(
"color" => "yellow",
"taste" => "paste-y",
"shape" => "banana-shaped"
)
);
echo $a["apple"]["taste"]; # will output "sweet"
?>
</programlisting>
</informalexample>
</para>
</sect2>
</sect1>
<sect1 id="language.types.object">
<title>Objects</title>
<sect2 id="language.types.object.init">
<title>Object Initialization</title>
<para>
To initialize an object, you use the <literal>new</literal>
statement to instantiate the object to a variable.
<informalexample>
<programlisting role="php">
<?php
class foo {
function do_foo() {
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
</programlisting>
</informalexample>
</para>
<simpara>
For a full discussion, please read the section <link
linkend="language.oop">Classes and Objects</link>.
</simpara>
</sect2>
</sect1>
<sect1 id="language.types.type-juggling">
<title>Type Juggling</title>
<simpara>
PHP does not require (or support) explicit type definition in
variable declaration; a variable's type is determined by the
context in which that variable is used. That is to say, if you
assign a string value to variable <parameter>var</parameter>,
<parameter>var</parameter> becomes a string. If you then assign an
integer value to <parameter>var</parameter>, it becomes an
integer.
</simpara>
<para>
An example of PHP's automatic type conversion is the addition
operator '+'. If any of the operands is a double, then all
operands are evaluated as doubles, and the result will be a
double. Otherwise, the operands will be interpreted as integers,
and the result will also be an integer. Note that this does NOT
change the types of the operands themselves; the only change is in
how the operands are evaluated.
<informalexample>
<programlisting role="php">
$foo = "0"; // $foo is string (ASCII 48)
$foo++; // $foo is the string "1" (ASCII 49)
$foo += 1; // $foo is now an integer (2)
$foo = $foo + 1.3; // $foo is now a double (3.3)
$foo = 5 + "10 Little Piggies"; // $foo is integer (15)
$foo = 5 + "10 Small Pigs"; // $foo is integer (15)
</programlisting>
</informalexample>
</para>
<simpara>
If the last two examples above seem odd, see <link
linkend="language.types.string.conversion">String
conversion</link>.
</simpara>
<simpara>
If you wish to force a variable to be evaluated as a certain type,
see the section on <link linkend="language.types.typecasting">Type
casting</link>. If you wish to change the type of a variable, see
<function>settype</function>.
</simpara>
<para>
If you would like to test any of the examples in this section, you
can cut and paste the examples and insert the following line to
see for yourself what's going on:
<informalexample>
<programlisting role="php">
echo "\$foo==$foo; type is " . gettype ($foo) . "<br>\n";
</programlisting>
</informalexample>
</para>
<note>
<para>
The behaviour of an automatic conversion to array is currently
undefined.
<informalexample>
<programlisting role="php">
$a = 1; // $a is an integer
$a[0] = "f"; // $a becomes an array, with $a[0] holding "f"
</programlisting>
</informalexample>
</para>
<para>
While the above example may seem like it should clearly result in
$a becoming an array, the first element of which is 'f', consider
this:
<informalexample>
<programlisting role="php">
$a = "1"; // $a is a string
$a[0] = "f"; // What about string offsets? What happens?
</programlisting>
</informalexample>
</para>
<para>
Since PHP supports indexing into strings via offsets using the
same syntax as array indexing, the example above leads to a
problem: should $a become an array with its first element being
"f", or should "f" become the first character of the string $a?
</para>
<para>
For this reason, as of PHP 3.0.12 and PHP 4.0b3-RC4, the result
of this automatic conversion is considered to be undefined. Fixes
are, however, being discussed.
</para>
</note>
<sect2 id="language.types.typecasting">
<title>Type Casting</title>
<para>
Type casting in PHP works much as it does in C: the name of the
desired type is written in parentheses before the variable which
is to be cast.
<informalexample>
<programlisting role="php">
$foo = 10; // $foo is an integer
$bar = (double) $foo; // $bar is a double
</programlisting>
</informalexample>
</para>
<para>
The casts allowed are:
<itemizedlist>
<listitem>
<simpara>(int), (integer) - cast to integer</simpara>
</listitem>
<listitem>
<simpara>(real), (double), (float) - cast to double</simpara>
</listitem>
<listitem>
<simpara>(string) - cast to string</simpara>
</listitem>
<listitem>
<simpara>(array) - cast to array</simpara>
</listitem>
<listitem>
<simpara>(object) - cast to object</simpara>
</listitem>
</itemizedlist>
</para>
<para>
Note that tabs and spaces are allowed inside the parentheses, so
the following are functionally equivalent:
<informalexample>
<programlisting role="php">
$foo = (int) $bar;
$foo = ( int ) $bar;
</programlisting>
</informalexample>
</para>
<para>
It may not be obvious exactly what will happen when casting
between certain types. For instance, the following should be
noted.
</para>
<para>
When casting from a scalar or a string variable to an array, the
variable will become the first element of the array:
<informalexample>
<programlisting role="php">
$var = 'ciao';
$arr = (array) $var;
echo $arr[0]; // outputs 'ciao'
</programlisting>
</informalexample>
</para>
<para>
When casting from a scalar or a string variable to an object, the
variable will become an attribute of the object; the attribute
name will be 'scalar':
<informalexample>
<programlisting role="php">
$var = 'ciao';
$obj = (object) $var;
echo $obj->scalar; // outputs 'ciao'
</programlisting>
</informalexample>
</para>
</sect2>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
Index: phpdoc/nl/language/variables.xml
+++ phpdoc/nl/language/variables.xml
<chapter id="language.variables">
<title>Variables</title>
<sect1 id="language.variables.basics">
<title>Basics</title>
<simpara>
Variables in PHP are represented by a dollar sign followed by the
name of the variable. The variable name is case-sensitive.
</simpara>
<para>
Variable names follow the same rules as other labels in PHP. A
valid variable name starts with a letter or underscore, followed
by any number of letters, numbers, or underscores. As a regular
expression, it would be expressed thus:
'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
</para>
<note>
<simpara>
For our purposes here, a letter is a-z, A-Z, and the ASCII
characters from 127 through 255 (0x7f-0xff).
</simpara>
</note>
<para>
<informalexample>
<programlisting role="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 ASCII 228.
</programlisting>
</informalexample>
</para>
<para>
In PHP 3, variables are always assigned by value. That is to say,
when you assign an expression to a variable, the entire value of
the original expression is copied into the destination
variable. This means, for instance, that after assigning one
variable's value to another, changing one of those variables will
have no effect on the other. For more information on this kind of
assignment, see <link
linkend="language.expressions">Expressions</link>.
</para>
<para>
PHP 4 offers another way to assign values to variables:
<emphasis>assign by reference</emphasis>. This means that the new
variable simply references (in other words, "becomes an alias for"
or "points to") the original variable. Changes to the new variable
affect the original, and vice versa. This also means that no
copying is performed; thus, the assignment happens more
quickly. However, any speedup will likely be noticed only in tight
loops or when assigning large arrays or objects.
</para>
<para>
To assign by reference, simply prepend an ampersand (&) to the
beginning of the variable which is being assigned (the source
variable). For instance, the following code snippet outputs 'My
name is Bob' twice:
<informalexample>
<programlisting role="php">
<?php
$foo = 'Bob'; // Assign the value 'Bob' to $foo
$bar = &$foo; // Reference $foo via $bar.
$bar = "My name is $bar"; // Alter $bar...
echo $foo; // $foo is altered too.
echo $bar;
?>
</programlisting>
</informalexample>
</para>
<para>
One important thing to note is that only named variables may be
assigned by reference.
<informalexample>
<programlisting role="php">
<?php
$foo = 25;
$bar = &$foo; // This is a valid assignment.
$bar = &(24 * 7); // Invalid; references an unnamed expression.
function test() {
return 25;
}
$bar = &test(); // Invalid.
?>
</programlisting>
</informalexample>
</para>
</sect1>
<sect1 id="language.variables.predefined">
<title>Predefined variables</title>
<simpara>
PHP provides a large number of predefined variables to any script
which it runs. Many of these variables, however, cannot be fully
documented as they are dependent upon which server is running, the
version and setup of the server, and other factors. Some of these
variables will not be available when PHP is run on the
command-line.
</simpara>
<simpara>
Despite these factors, here is a list of predefined variables
available under a stock installation of PHP 3 running as a module
under a stock installation of <ulink
url="&url.apache;">Apache</ulink> 1.3.6.
</simpara>
<simpara>
For a list of all predefined variables (and lots of other useful
information), please see (and use) <function>phpinfo</function>.
</simpara>
<note>
<simpara>
This list is neither exhaustive nor intended to be. It is simply
a guideline as to what sorts of predefined variables you can
expect to have access to in your script.
</simpara>
</note>
<sect2 id="language.variables.predefined.apache">
<title>Apache variables</title>
<simpara>
These variables are created by the <ulink
url="&url.apache;">Apache</ulink> webserver. If you are running
another webserver, there is no guarantee that it will provide the
same variables; it may omit some, or provide others not listed
here. That said, a large number of these variables are accounted
for in the <ulink url="&url.cgispec;">CGI 1.1
specification</ulink>, so you should be able to expect those.
</simpara>
<simpara>
Note that few, if any, of these will be available (or indeed have
any meaning) if running PHP on the command line.
</simpara>
<para>
<variablelist>
<varlistentry>
<term>GATEWAY_INTERFACE</term>
<listitem>
<simpara>
What revision of the CGI specification the server is using;
i.e. 'CGI/1.1'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_NAME</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_SOFTWARE</term>
<listitem>
<simpara>
Server identification string, given in the headers when
responding to requests.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_PROTOCOL</term>
<listitem>
<simpara>
Name and revision of the information protocol via which the
page was requested; i.e. 'HTTP/1.0';
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REQUEST_METHOD</term>
<listitem>
<simpara>
Which request method was used to access the page; i.e. 'GET',
'HEAD', 'POST', 'PUT'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>QUERY_STRING</term>
<listitem>
<simpara>
The query string, if any, via which the page was accessed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>DOCUMENT_ROOT</term>
<listitem>
<simpara>
The document root directory under which the current script is
executing, as defined in the server's configuration file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ACCEPT</term>
<listitem>
<simpara>
Contents of the <literal>Accept:</literal> header from the
current request, if there is one.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ACCEPT_CHARSET</term>
<listitem>
<simpara>
Contents of the <literal>Accept-Charset:</literal> header
from the current request, if there is one. Example:
'iso-8859-1,*,utf-8'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ENCODING</term>
<listitem>
<simpara>
Contents of the <literal>Accept-Encoding:</literal> header
from the current request, if there is one. Example: 'gzip'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ACCEPT_LANGUAGE</term>
<listitem>
<simpara>
Contents of the <literal>Accept-Language:</literal> header
from the current request, if there is one. Example: 'en'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_CONNECTION</term>
<listitem>
<simpara>
Contents of the <literal>Connection:</literal> header from
the current request, if there is one. Example: 'Keep-Alive'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_HOST</term>
<listitem>
<simpara>
Contents of the <literal>Host:</literal> header from the
current request, if there is one.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_REFERER</term>
<listitem>
<simpara>
The address of the page (if any) which referred the browser
to the current page. This is set by the user's browser; not
all browsers will set this.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_USER_AGENT</term>
<listitem>
<simpara>
Contents of the <literal>User_Agent:</literal> header from
the current request, if there is one. This is a string
denoting the browser software being used to view the current
page; i.e. <computeroutput>Mozilla/4.5 [en] (X11; U; Linux
2.2.9 i586)</computeroutput>. Among other things, you can use
this value with <function>get_browser</function> to tailor
your page's functionality to the capabilities of the user's
browser.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REMOTE_ADDR</term>
<listitem>
<simpara>
The IP address from which the user is viewing the current
page.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REMOTE_PORT</term>
<listitem>
<simpara>
The port being used on the user's machine to communicate with
the web server.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SCRIPT_FILENAME</term>
<listitem>
<simpara>
The absolute pathname of the currently executing script.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_ADMIN</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_PORT</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SERVER_SIGNATURE</term>
<listitem>
<simpara>
String containing the server version and virtual host name
which are added to server-generated pages, if enabled.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PATH_TRANSLATED</term>
<listitem>
<simpara>
Filesystem- (not document root-) based path to the current
script, after the server has done any virtual-to-real
mapping.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>SCRIPT_NAME</term>
<listitem>
<simpara>
Contains the current script's path. This is useful for pages
which need to point to themselves.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>REQUEST_URI</term>
<listitem>
<simpara>
The URI which was given in order to access this page; for
instance, '/index.html'.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</sect2>
<sect2 id="language.variables.predefined.environment">
<title>Environment variables</title>
<simpara>
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.
</simpara>
<simpara>
Other environment variables include the CGI variables, placed
there regardless of whether PHP is running as a server module or
CGI processor.
</simpara>
</sect2>
<sect2 id="language.variables.predefined.php">
<title>PHP variables</title>
<simpara>
These variables are created by PHP itself. The
<varname>$HTTP_*_VARS</varname> variables are available only if
the <link linkend="ini.track-vars">track_vars</link>
configuration is turned on.
</simpara>
<note>
<para>
As of PHP 4.0.3, <link
linkend="ini.track-vars">track_vars</link> is always turned on,
regardless of the configuration file setting.
</para>
</note>
<para>
If the <link
linkend="ini.register-globals">register_globals</link> directive
is set, then these variables will also be made available in the
global scope of the script; i.e., separate from the
<varname>$HTTP_*_VARS</varname> arrays. This feature should be
used with care, and turned off if possible; while the
<varname>$HTTP_*_VARS</varname> variables are safe, the bare
global equivalents can be overwritten by user input, with
possibly malicious intent. If you cannot turn off <link
linkend="ini.register-globals">register_globals</link>, you must
take whatever steps are necessary to ensure that the data you are
using is safe.
</para>
<para>
<variablelist>
<varlistentry>
<term>argv</term>
<listitem>
<simpara>
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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>argc</term>
<listitem>
<simpara>
Contains the number of command line parameters passed to the
script (if run on the command line).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_SELF</term>
<listitem>
<simpara>
The filename of the currently executing script, relative to
the document root. If PHP is running as a command-line
processor, this variable is not available.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_COOKIE_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via HTTP cookies.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_GET_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via the HTTP GET method.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_POST_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via the HTTP POST method.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_POST_FILES</term>
<listitem>
<simpara>
An associative array of variables containing information
about files uploaded via the HTTP POST method. See <link
linkend="features.file-upload.post-method">POST method
uploads</link> for information on the contents of
<varname>$HTTP_POST_FILES</varname>.
</simpara>
<para>
<varname>$HTTP_POST_FILES</varname> is available only in PHP
4.0.0 and later.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_ENV_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script via the parent environment.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>HTTP_SERVER_VARS</term>
<listitem>
<simpara>
An associative array of variables passed to the current
script from the HTTP server. These variables are analogous to
the Apache variables described above.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</sect2>
</sect1>
<sect1 id="language.variables.scope">
<title>Variable scope</title>
<simpara>
The scope of a variable is the context within which it is defined.
For the most part all PHP variables only have a single scope.
This single scope spans included and required files as well. For
example:
</simpara>
<informalexample>
<programlisting role="php">
$a = 1;
include "b.inc";
</programlisting>
</informalexample>
<simpara>
Here the <varname>$a</varname> variable will be available within
the included <filename>b.inc</filename> script. However, within
user-defined functions a local function scope is introduced. Any
variable used inside a function is by default limited to the local
function scope. For example:
</simpara>
<informalexample>
<programlisting role="php">
$a = 1; /* global scope */
Function Test () {
echo $a; /* reference to local scope variable */
}
Test ();
</programlisting>
</informalexample>
<simpara>
This script will not produce any output because the echo statement
refers to a local version of the <varname>$a</varname> variable,
and it has not been assigned a value within this scope. You may
notice that this is a little bit different from the C language in
that global variables in C are automatically available to
functions unless specifically overridden by a local definition.
This can cause some problems in that people may inadvertently
change a global variable. In PHP global variables must be
declared global inside a function if they are going to be used in
that function. An example:
</simpara>
<informalexample>
<programlisting role="php">
$a = 1;
$b = 2;
Function Sum () {
global $a, $b;
$b = $a + $b;
}
Sum ();
echo $b;
</programlisting>
</informalexample>
<simpara>
The above script will output "3". By declaring
<varname>$a</varname> and <varname>$b</varname> global within the
function, all references to either variable will refer to the
global version. There is no limit to the number of global
variables that can be manipulated by a function.
</simpara>
<simpara>
A second way to access variables from the global scope is to use
the special PHP-defined <varname>$GLOBALS</varname> array. The
previous example can be rewritten as:
</simpara>
<informalexample>
<programlisting role="php">
$a = 1;
$b = 2;
Function Sum () {
$GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"];
}
Sum ();
echo $b;
</programlisting>
</informalexample>
<simpara>
The <varname>$GLOBALS</varname> array is an associative array with
the name of the global variable being the key and the contents of
that variable being the value of the array element.
</simpara>
<simpara>
Another important feature of variable scoping is the
<emphasis>static</emphasis> variable. A static variable exists
only in a local function scope, but it does not lose its value
when program execution leaves this scope. Consider the following
example:
</simpara>
<informalexample>
<programlisting role="php">
Function Test () {
$a = 0;
echo $a;
$a++;
}
</programlisting>
</informalexample>
<simpara>
This function is quite useless since every time it is called it
sets <varname>$a</varname> to <literal>0</literal> and prints
"0". The <varname>$a</varname>++ which increments the
variable serves no purpose since as soon as the function exits the
<varname>$a</varname> variable disappears. To make a useful
counting function which will not lose track of the current count,
the <varname>$a</varname> variable is declared static:
</simpara>
<informalexample>
<programlisting role="php">
Function Test () {
static $a = 0;
echo $a;
$a++;
}
</programlisting>
</informalexample>
<simpara>
Now, every time the Test() function is called it will print the
value of <varname>$a</varname> and increment it.
</simpara>
<simpara>
Static variables also provide one way to deal with recursive
functions. A recursive function is one which calls itself. Care
must be taken when writing a recursive function because it is
possible to make it recurse indefinitely. You must make sure you
have an adequate way of terminating the recursion. The following
simple function recursively counts to 10, using the static
variable <varname>$count</varname> to know when to stop:
</simpara>
<informalexample>
<programlisting role="php">
Function Test () {
static $count = 0;
$count++;
echo $count;
if ($count < 10) {
Test ();
}
$count--;
}
</programlisting>
</informalexample>
</sect1>
<sect1 id="language.variables.variable">
<title>Variable variables</title>
<simpara>
Sometimes it is convenient to be able to have variable variable
names. That is, a variable name which can be set and used
dynamically. A normal variable is set with a statement such as:
</simpara>
<informalexample>
<programlisting role="php">
$a = "hello";
</programlisting>
</informalexample>
<simpara>
A variable variable takes the value of a variable and treats that
as the name of a variable. In the above example,
<emphasis>hello</emphasis>, can be used as the name of a variable
by using two dollar signs. i.e.
</simpara>
<informalexample>
<programlisting role="php">
$$a = "world";
</programlisting>
</informalexample>
<simpara>
At this point two variables have been defined and stored in the
PHP symbol tree: <varname>$a</varname> with contents "hello" and
<varname>$hello</varname> with contents "world". Therefore, this
statement:
</simpara>
<informalexample>
<programlisting role="php">
echo "$a ${$a}";
</programlisting>
</informalexample>
<simpara>
produces the exact same output as:
</simpara>
<informalexample>
<programlisting>
echo "$a $hello";
</programlisting>
</informalexample>
<simpara>
i.e. they both produce: <computeroutput>hello world</computeroutput>.
</simpara>
<simpara>
In order to use variable variables with arrays, you have to
resolve an ambiguity problem. That is, if you write
<varname>$$a[1]</varname> then the parser needs to know if you
meant to use <varname>$a[1]</varname> as a variable, or if you
wanted <varname>$$a</varname> as the variable and then the [1]
index from that variable. The syntax for resolving this ambiguity
is: <varname>${$a[1]}</varname> for the first case and
<varname>${$a}[1]</varname> for the second.
</simpara>
</sect1>
<sect1 id="language.variables.external">
<title>Variables from outside PHP</title>
<sect2 id="language.variables.external.form">
<title>HTML Forms (GET and POST)</title>
<simpara>
When a form is submitted to a PHP script, any variables from that
form will be automatically made available to the script by
PHP. If the <link linkend="ini.track-vars">track_vars</link>
configuration option is turned on, then these variables will be
located in the associative arrays
<varname>$HTTP_POST_VARS</varname>,
<varname>$HTTP_GET_VARS</varname>, and/or
<varname>$HTTP_POST_FILES</varname>, according to the
source of the variable in question.
</simpara>
<para>
For more information on these variables, please read <link
linkend="language.variables.predefined">Predefined
variables</link>.
</para>
<para>
<example>
<title>Simple form variable</title>
<programlisting role="php">
<form action="foo.php" method="post">
Name: <input type="text" name="username"><br>
<input type="submit">
</form>
</programlisting>
</example>
</para>
<para>
When the above form is submitted, the value from the text input
will be available in
<varname>$HTTP_POST_VARS['username']</varname>. If the <link
linkend="ini.register-globals">register_globals</link>
configuration directive is turned on, then the variable will also
be available as <varname>$username</varname> in the global scope.
</para>
<simpara>
PHP also understands arrays in the context of form variables. You
may, for example, group related variables together, or use this
feature to retrieve values from a multiple select
input:
</simpara>
<para>
<example>
<title>More complex form variables</title>
<programlisting role="php">
<form action="array.php" method="post">
Name: <input type="text" name="personal[name]"><br>
Email: <input type="text" name="personal[email]"><br>
Beer: <br>
<select multiple name="beer[]">
<option value="warthog">Warthog
<option value="guinness">Guinness
<option value="stuttgarter">Stuttgarter Schwabenbräu
</select>
<input type="submit">
</form>
</programlisting>
</example>
</para>
<para>
In PHP 3, the array form variable usage is limited to
single-dimensional arrays. In PHP 4, no such restriction applies.
</para>
<sect3>
<title>IMAGE SUBMIT variable names</title>
<simpara>
When submitting a form, it is possible to use an image instead
of the standard submit button with a tag like:</simpara>
<informalexample>
<programlisting role="php">
<input type=image src="image.gif" name="sub">
</programlisting>
</informalexample>
<simpara>
When the user clicks somewhere on the image, the accompanying
form will be transmitted to the server with two additional
variables, sub_x and sub_y. These contain the coordinates of the
user click within the image. The experienced may note that the
actual variable names sent by the browser contains a period
rather than an underscore, but PHP converts the period to an
underscore automatically.
</simpara>
</sect3>
</sect2>
<sect2 id="language.variables.external.cookies">
<title>HTTP Cookies</title>
<simpara>
PHP transparently supports HTTP cookies as defined by <ulink
url="&spec.cookies;">Netscape's Spec</ulink>. Cookies are a
mechanism for storing data in the remote browser and thus
tracking or identifying return users. You can set cookies using
the <function>SetCookie</function> function. Cookies are part of
the HTTP header, so the SetCookie function must be called before
any output is sent to the browser. This is the same restriction
as for the <function>Header</function> function. Any cookies
sent to you from the client will automatically be turned into a
PHP variable just like GET and POST method data.</simpara>
<simpara>
If you wish to assign multiple values to a single cookie, just
add <emphasis>[]</emphasis> to the cookie name. For
example:
</simpara>
<informalexample>
<programlisting role="php">
SetCookie ("MyCookie[]", "Testing", time()+3600);
</programlisting>
</informalexample>
<simpara>
Note that a cookie will replace a previous cookie by the same
name in your browser unless the path or domain is different. So,
for a shopping cart application you may want to keep a counter
and pass this along. i.e.
</simpara>
<example>
<title>SetCookie Example</title>
<programlisting role="php">
$Count++;
SetCookie ("Count", $Count, time()+3600);
SetCookie ("Cart[$Count]", $item, time()+3600);
</programlisting>
</example>
</sect2>
<sect2 id="language.variables.external.environment">
<title>Environment variables</title>
<para>
PHP automatically makes environment variables available as normal
PHP variables.
<informalexample>
<programlisting role="php">
echo $HOME; /* Shows the HOME environment variable, if set. */
</programlisting>
</informalexample>
</para>
<para>
Since information coming in via GET, POST and Cookie mechanisms
also automatically create PHP variables, it is sometimes best to
explicitly read a variable from the environment in order to make
sure that you are getting the right version. The
<function>getenv</function> function can be used for this. You
can also set an environment variable with the
<function>putenv</function> function.
</para>
</sect2>
<sect2>
<title>Dots in incoming variable names</title>
<para>
Typically, PHP does not alter the names of variables when they
are passed into a script. However, it should be noted that the
dot (period, full stop) is not a valid character in a PHP
variable name. For the reason, look at it:
<programlisting role="php">
$varname.ext; /* invalid variable name */
</programlisting>
Now, what the parser sees is a variable named
<varname>$varname</varname>, followed by the string concatenation
operator, followed by the barestring (i.e. unquoted string which
doesn't match any known key or reserved words) 'ext'. Obviously,
this doesn't have the intended result.
</para>
<para>
For this reason, it is important to note that PHP will
automatically replace any dots in incoming variable names with
underscores.
</para>
</sect2>
<sect2>
<title>Determining variable types</title>
<para>
Because PHP determines the types of variables and converts them
(generally) as needed, it is not always obvious what type a given
variable is at any one time. PHP includes several functions
which find out what type a variable is. They are
<function>gettype</function>, <function>is_long</function>,
<function>is_double</function>, <function>is_string</function>,
<function>is_array</function>, and
<function>is_object</function>.
</para>
</sect2>
</sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->