php-doc-en/functions/misc.xml
2001-07-07 21:27:21 +00:00

1083 lines
33 KiB
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>
<void/>
</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>
<void/>
</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>bool <function>connection_timeout</function></funcdef>
<void/>
</funcprototype>
</funcsynopsis>
<simpara>
Returns &true; if script timed out.
</simpara>
<warning>
<title>Deprecated</title>
<simpara>
This function is deprecated, and doesn't even exist anymore
as of 4.0.5.
</simpara>
<!-- so it's quite late to declare it 'deprecated' by now :)
TODO: correct connection handling. Any volunteers?
-->
</warning>
<simpara>
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.constant">
<refnamediv>
<refname>constant</refname>
<refpurpose>Returns the value of a constant</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>mixed <function>constant</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
<function>constant</function> will return the value of the
constant indicated by <parameter>name</parameter>.
</simpara>
<simpara>
<function>constant</function> is useful if you need to retrieve
the value of a constant, but do not know it's name. i.e. It is
stored in a variable or returned by a function.
</simpara>
<para>
<example>
<title><function>constant</function> example</title>
<programlisting role="php">
&lt;php
define ("MAXSIZE", 100);
echo MAXSIZE;
echo constant("MAXSIZE"); // same thing as the previous line
?&gt;
</programlisting>
</example>
</para>
<para>
See also <function>define</function>,
<function>defined</function> and the section on <link
linkend="language.constants">Constants</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.define">
<refnamediv>
<refname>define</refname>
<refpurpose>Defines a named constant.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>bool <function>define</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
<paramdef>bool
<parameter><optional>case_insensitive</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Defines a named constant. See the
<link linkend="language.constants">section on constants</link>
for more details.
</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 &true; is given, then the constant will be
defined case-insensitive. The default behaviour is
case-sensitive; i.e. CONSTANT and Constant represent different
values.
</para>
<para>
<example>
<title>Defining Constants</title>
<programlisting role="php">
&lt;?php
define ("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.
define ("GREETING", "Hello you.",TRUE);
echo GREETING; // outputs "Hello you."
echo Greeting; // outputs "Hello you."
?&gt;
</programlisting>
</example>
</para>
<para>
<function>define</function> returns &true;
on success and &false; if
an error occurs.
</para>
<para>
See also <function>defined</function>,
<function>constant</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>bool <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.
<example>
<title>Checking Constants</title>
<programlisting role="php">
&lt;?php
if (defined("CONSTANT")){ // Note that it should be quoted
echo CONSTANT; //
}
?&gt;
</programlisting>
</example>
</para>
<para>
See also <function>define</function>,
<function>constant</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>
<function>die</function> outputs <parameter>message</parameter>
and terminates parsing of the script. It does not return
anything.
</simpara>
<simpara>
Alternatively, <function>die</function> will also accept a
function as a parameter. That function will be executed
before <function>die</function> terminates parsing of the script.
</simpara>
<para>
<example>
<title><function>die</function> example</title>
<programlisting role="php">
&lt;?php
$filename = '/path/to/data-file';
$file = fopen ($filename, 'r')
or die("unable to open file ($filename)");
?&gt;
</programlisting>
</example>
</para>
<para>
<example>
<title><function>die</function> example using a function</title>
<programlisting role="php">
&lt;?php
function handle_error($msg) {
if ($fp = @fopen("/tmp/error.log", "a")) {
fwrite($fp, $msg, strlen($msg));
fclose($fp);
}
}
if ($bad) {
die(handle_error("Something bad happened.\n"));
}
?&gt;
</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">
&lt;?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.&lt;br&gt;';
echo $str;
eval ("\$str = \"$str\";");
echo $str;
?&gt;
</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>
<paramdef>mixed <parameter>status</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<simpara>
The <function>exit</function> function terminates execution of
the script. It has no return value, but will use
<parameter>status</parameter> as its exit status.
</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">
&lt;?php
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "&lt;b&gt;$key:&lt;/b&gt; $value&lt;br&gt;\n";
}
return $str;
}
echo "$HTTP_USER_AGENT&lt;hr&gt;\n";
$browser = get_browser();
echo list_array ((array) $browser);
?&gt;
</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)&lt;hr&gt;
&lt;b&gt;browser_name_pattern:&lt;/b&gt; Mozilla/4\.5.*&lt;br&gt;
&lt;b&gt;parent:&lt;/b&gt; Netscape 4.0&lt;br&gt;
&lt;b&gt;platform:&lt;/b&gt; Unknown&lt;br&gt;
&lt;b&gt;majorver:&lt;/b&gt; 4&lt;br&gt;
&lt;b&gt;minorver:&lt;/b&gt; 5&lt;br&gt;
&lt;b&gt;browser:&lt;/b&gt; Netscape&lt;br&gt;
&lt;b&gt;version:&lt;/b&gt; 4&lt;br&gt;
&lt;b&gt;frames:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;tables:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;cookies:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;backgroundsounds:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;vbscript:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;javascript:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;javaapplets:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;activexcontrols:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;beta:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;crawler:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;authenticodeupdate:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;msn:&lt;/b&gt; &lt;br&gt;
</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>bool <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.
&return.success;
</simpara>
<note>
<simpara>
Care should be taken when using the
<function>show_source</function> and
<function>highlight_file</function> functions to make sure that
you do not inadvertently reveal sensitive information such as
passwords or any other type of information that might create a
potential security risk.
</simpara>
</note>
<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 &quot;ForceType&quot; 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>
&lt;Location /source&gt;
ForceType application/x-httpd-php
&lt;/Location&gt;
</programlisting></informalexample>
</para>
<simpara>
And then make a file named &quot;source&quot; and put it in your
web root directory.
</simpara>
<para>
<programlisting role="php">
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Source Display&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY BGCOLOR=&quot;white&quot;&gt;
&lt;?php
$script = getenv (&quot;PATH_TRANSLATED&quot;);
if(!$script) {
echo &quot;&lt;BR&gt;&lt;B&gt;ERROR: Script Name needed&lt;/B&gt;&lt;BR&gt;&quot;;
} else {
if (ereg(&quot;(\.php|\.inc)$&quot;,$script)) {
echo &quot;&lt;H1&gt;Source of: $PATH_INFO&lt;/H1&gt;\n&lt;HR&gt;\n&quot;;
highlight_file($script);
} else {
echo &quot;&lt;H1&gt;ERROR: Only PHP or include script names are allowed&lt;/H1&gt;&quot;;
}
}
echo &quot;&lt;HR&gt;Processed: &quot;.date(&quot;Y/M/d H:i:s&quot;,time());
?&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</programlisting>
</para>
<simpara>
Then you can use an URL like the one below to display a colorized
version of a script located in &quot;/path/to/script.php&quot;
in your web site.
</simpara>
<para>
<informalexample>
<programlisting>
http://your.server.com/source/path/to/script.php
</programlisting>
</informalexample>
</para>
</example>
</para>
&tip.ob-capture;
<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>bool <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.
&return.success;
</simpara>
&tip.ob-capture;
<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>bool <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.
It returns &true; on success, &false; otherwise (PHP 4).
</simpara>
<simpara>
This function is an alias for the function
<function>highlight_file</function>
</simpara>
<note>
<simpara>
Care should be taken when using the
<function>show_source</function> and
<function>highlight_file</function> functions to make sure that
you do not inadvertently reveal sensitive information such as
passwords or any other type of information that might create a
potential security risk.
</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>bool
<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:
-->