2001-11-10 21:49:43 +00:00
|
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
<!-- $Revision: 1.145 $ -->
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<reference id="ref.strings">
|
|
|
|
|
<title>String functions</title>
|
|
|
|
|
<titleabbrev>Strings</titleabbrev>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<partintro>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
These functions all manipulate strings in various ways. Some more
|
1999-09-13 18:07:16 +00:00
|
|
|
|
specialized sections can be found in the regular expression and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
URL handling sections.
|
|
|
|
|
</simpara>
|
2000-09-10 22:48:18 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</partintro>
|
|
|
|
|
|
1999-09-06 00:24:06 +00:00
|
|
|
|
<refentry id="function.addcslashes">
|
|
|
|
|
<refnamediv>
|
2001-08-05 22:49:38 +00:00
|
|
|
|
<refname>addcslashes</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Quote string with slashes in a C style</refpurpose>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>addcslashes</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>charlist</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
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
|
2001-06-27 09:58:49 +00:00
|
|
|
|
126 are converted to octal representation.
|
2001-06-28 23:03:46 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2001-06-27 09:58:49 +00:00
|
|
|
|
Be careful if you choose to escape characters 0, a, b, f, n, r,
|
2001-06-28 23:03:46 +00:00
|
|
|
|
t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t
|
|
|
|
|
and \v.
|
2001-07-07 18:42:46 +00:00
|
|
|
|
In PHP \0 (&null;), \r (carriage return), \n (newline) and \t (tab)
|
2001-06-28 23:03:46 +00:00
|
|
|
|
are predefined escape sequences, while in C all of these are
|
|
|
|
|
predefined escape sequences.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<parameter>charlist</parameter> like "\0..\37", which would
|
|
|
|
|
escape all characters with ASCII code between 0 and 31.
|
1999-09-06 00:24:06 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>addcslashes</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
When you define a sequence of characters in the charlist argument
|
|
|
|
|
make sure that you know what characters come between the
|
|
|
|
|
characters that you set as the start and end of the range.
|
2001-06-27 09:58:49 +00:00
|
|
|
|
<informalexample>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-06-27 09:58:49 +00:00
|
|
|
|
echo addcslashes('foo[]', 'A..z');
|
|
|
|
|
// All upper and lower-case letters will be escaped
|
2001-08-25 23:01:28 +00:00
|
|
|
|
// ... but so will the [\]^_` and space characters.
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-06-27 09:58:49 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</informalexample>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
Also, if the first character in a range has a lower ASCII value
|
|
|
|
|
than the second character in the range, no range will be
|
|
|
|
|
constructed. Only the start, end and period characters will be
|
|
|
|
|
escaped. Use the <function>ord</function> function to find the
|
|
|
|
|
ASCII value for a character.
|
2001-06-27 09:58:49 +00:00
|
|
|
|
<informalexample>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-06-27 09:58:49 +00:00
|
|
|
|
echo addcslashes("zoo['.']", 'z..A');
|
|
|
|
|
/* output:
|
|
|
|
|
\zoo['\.']
|
|
|
|
|
|
|
|
|
|
*/
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-06-27 09:58:49 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</informalexample>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
2001-06-27 09:58:49 +00:00
|
|
|
|
Added in PHP 4</simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</note>
|
|
|
|
|
</para>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
See also <function>stripcslashes</function>,
|
|
|
|
|
<function>stripslashes</function>,
|
|
|
|
|
<function>htmlspecialchars</function>, and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>quotemeta</function>.
|
|
|
|
|
</para>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.addslashes">
|
|
|
|
|
<refnamediv>
|
2001-08-05 22:49:38 +00:00
|
|
|
|
<refname>addslashes</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Quote string with slashes</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>addslashes</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</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>)
|
2001-07-07 18:42:46 +00:00
|
|
|
|
and NUL (the &null; byte).
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2001-09-15 01:46:41 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
<link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> is ON by default.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
See also <function>stripslashes</function>,
|
|
|
|
|
<function>htmlspecialchars</function>, and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>quotemeta</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.bin2hex">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>bin2hex</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
|
|
|
|
Convert binary data into hexadecimal representation
|
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>bin2hex</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
Returns an ASCII string containing the hexadecimal representation
|
|
|
|
|
of <parameter>str</parameter>. The conversion is done byte-wise
|
2000-02-19 14:53:22 +00:00
|
|
|
|
with the high-nibble first.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.chop">
|
|
|
|
|
<refnamediv>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<refname>chop</refname>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<refpurpose>Alias of <function>rtrim</function></refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<para>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
This function is an alias of <function>rtrim</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2000-08-25 16:56:13 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
<function>chop</function> is different than the Perl
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<literal>chop()</literal> function, which removes the last
|
2000-08-25 16:56:13 +00:00
|
|
|
|
character in the string.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.chr">
|
|
|
|
|
<refnamediv>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<refname>chr</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Return a specific character</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>chr</function></funcdef>
|
|
|
|
|
<paramdef>int <parameter>ascii</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns a one-character string containing the character specified
|
|
|
|
|
by <parameter>ascii</parameter>.
|
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>chr</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$str .= chr(27); /* add an escape character at the end of $str */
|
1999-06-06 18:51:02 +00:00
|
|
|
|
|
|
|
|
|
/* Often this is more useful */
|
|
|
|
|
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$str = sprintf("The string ends in escape: %c", 27);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2001-08-12 23:23:07 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
You can find an ASCII-table over here: <ulink url="&url.asciitable;"
|
|
|
|
|
>&url.asciitable;</ulink>.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
This function complements <function>ord</function>. See also
|
|
|
|
|
<function>sprintf</function> with a format string of
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<literal>%c</literal>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
1999-12-14 04:13:10 +00:00
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.chunk-split">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>chunk_split</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Split a string into smaller chunks</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Can be used to split a string into smaller chunks which is useful
|
2000-02-19 14:53:22 +00:00
|
|
|
|
for e.g. converting <link
|
|
|
|
|
linkend="function.base64-encode">base64_encode</link> output to
|
1999-06-16 14:27:15 +00:00
|
|
|
|
match RFC 2045 semantics. It inserts every
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<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>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>chunk_split</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
1999-06-06 18:51:02 +00:00
|
|
|
|
# format $data using RFC 2045 semantics
|
|
|
|
|
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$new_string = chunk_split(base64_encode($data));
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
This function is significantly faster than
|
|
|
|
|
<function>ereg_replace</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
This function was added in 3.0.6.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.convert-cyr-string">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>convert_cyr_string</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Convert from one Cyrillic character set to another
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 03:05:49 +00:00
|
|
|
|
This function returns the given string converted from one
|
|
|
|
|
Cyrillic character set to another. The <parameter>from</parameter>
|
|
|
|
|
and <parameter>to</parameter> arguments are single characters that
|
1999-09-13 18:07:16 +00:00
|
|
|
|
represent the source and target Cyrillic character sets. The
|
|
|
|
|
supported types are:
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<itemizedlist>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
k - koi8-r
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
w - windows-1251
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
i - iso8859-5
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
a - x-cp866
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
d - x-cp866
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
m - x-mac-cyrillic
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-12-14 07:13:30 +00:00
|
|
|
|
<refentry id="function.count-chars">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>count_chars</refname>
|
|
|
|
|
<refpurpose>
|
2001-04-15 17:23:21 +00:00
|
|
|
|
Return information about characters used in a string
|
1999-12-14 07:13:30 +00:00
|
|
|
|
</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>mixed <function>count_chars</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
|
|
|
|
<paramdef>
|
|
|
|
|
<parameter>
|
|
|
|
|
<optional>mode</optional>
|
|
|
|
|
</parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
1999-12-14 07:13:30 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-04-15 17:23:21 +00:00
|
|
|
|
Counts the number of occurrences of every byte-value (0..255) in
|
1999-12-14 07:13:30 +00:00
|
|
|
|
<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:
|
1999-12-14 04:13:10 +00:00
|
|
|
|
<itemizedlist>
|
1999-12-14 07:13:30 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
0 - an array with the byte-value as key and the frequency of
|
|
|
|
|
every byte as value.
|
1999-12-14 07:13:30 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
1 - same as 0 but only byte-values with a frequency greater
|
|
|
|
|
than zero are listed.
|
1999-12-14 07:13:30 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
2 - same as 0 but only byte-values with a frequency equal to
|
|
|
|
|
zero are listed.
|
1999-12-14 07:13:30 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
3 - a string containing all used byte-values is returned.
|
1999-12-14 07:13:30 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
4 - a string containing all not used byte-values is returned.
|
1999-12-14 07:13:30 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
This function was added in PHP 4.0.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
2000-08-09 13:40:21 +00:00
|
|
|
|
|
|
|
|
|
<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>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
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 transmitted.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
See also: <function>md5</function>
|
2000-08-09 13:40:21 +00:00
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
1999-12-14 04:13:10 +00:00
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.crypt">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>crypt</refname>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
<refpurpose>One-way string encryption (hashing)</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>crypt</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>salt</optional></parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
<function>crypt</function> will return an encrypted string using the
|
2001-12-16 20:38:08 +00:00
|
|
|
|
standard Unix <abbrev>DES</abbrev>-based encryption algorithm or
|
|
|
|
|
alternative algorithms that may be available on the system. Arguments
|
|
|
|
|
are a string to be encrypted and an optional salt string to base the
|
|
|
|
|
encryption on. See the Unix man page for your crypt function for more
|
|
|
|
|
information.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<simpara>
|
2000-09-09 02:48:21 +00:00
|
|
|
|
If the salt argument is not provided, one will be randomly
|
2000-02-19 14:53:22 +00:00
|
|
|
|
generated by PHP.
|
|
|
|
|
</simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
Some operating systems support more than one type of encryption. In
|
|
|
|
|
fact, sometimes the standard DES-based 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 two character 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 two
|
|
|
|
|
character salt applies to your system or the longer twelve character salt
|
|
|
|
|
is applicable.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
2000-09-09 02:48:21 +00:00
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
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 security.
|
2001-08-26 22:41:56 +00:00
|
|
|
|
</simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
The standard DES-based encryption <function>crypt</function> returns the
|
|
|
|
|
salt as the first two characters of the output. It also only uses the
|
|
|
|
|
first eight characters of <parameter>str</parameter>, so longer strings
|
|
|
|
|
that start with the same eight characters will generate the same result
|
|
|
|
|
(when the same salt is used).
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<simpara>
|
|
|
|
|
On systems where the crypt() function supports multiple
|
|
|
|
|
encryption types, the following constants are set to 0 or 1
|
2000-02-19 14:53:22 +00:00
|
|
|
|
depending on whether the given type is available:
|
|
|
|
|
</simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
CRYPT_STD_DES - Standard DES-based encryption with a two character salt
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
CRYPT_EXT_DES - Extended DES-based encryption with a nine character salt
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
|
1999-09-13 18:07:16 +00:00
|
|
|
|
$1$
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
|
1999-09-13 18:07:16 +00:00
|
|
|
|
starting with $2$
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
|
|
|
|
There is no decrypt function, since <function>crypt</function>
|
|
|
|
|
uses a one-way algorithm.
|
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
|
|
|
|
<example>
|
|
|
|
|
<title><function>crypt</function> examples</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
|
|
|
|
$password = crypt("My1sTpassword"); # let salt be generated
|
|
|
|
|
|
|
|
|
|
# You should pass the entire results of crypt() as the salt for comparing a
|
|
|
|
|
# password, to avoid problems when different hashing algorithms are used. (As
|
|
|
|
|
# it says above, standard DES-based password hashing uses a 2-character salt,
|
|
|
|
|
# but MD5-based hashing uses 12.)
|
|
|
|
|
if (crypt($user_input,$password) == $password) {
|
|
|
|
|
echo "Password verified!";
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2001-12-16 20:38:08 +00:00
|
|
|
|
See also <function>md5</function> and <link linkend="ref.mcrypt">the
|
|
|
|
|
Mcrypt extension</link>.
|
2000-08-09 13:40:21 +00:00
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.echo">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>echo</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Output one or more strings</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef><function>echo</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>arg1</parameter></paramdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>argn</optional>...</parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Outputs all parameters.
|
|
|
|
|
</simpara>
|
1999-06-21 22:16:42 +00:00
|
|
|
|
<para>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<function>echo</function> is not actually a function (it is a
|
2001-04-15 17:23:21 +00:00
|
|
|
|
language construct) so you are not required to use parentheses
|
2001-03-21 05:59:43 +00:00
|
|
|
|
with it. In fact, if you want to pass more than one parameter
|
|
|
|
|
to echo, you must not enclose the parameters within parentheses.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>echo</function> examples</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
1999-06-06 18:51:02 +00:00
|
|
|
|
echo "Hello World";
|
1999-11-15 02:28:41 +00:00
|
|
|
|
|
|
|
|
|
echo "This spans
|
|
|
|
|
multiple lines. The newlines will be
|
|
|
|
|
output as well";
|
|
|
|
|
|
|
|
|
|
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
|
2001-03-21 05:59:43 +00:00
|
|
|
|
|
|
|
|
|
echo "escaping characters is done \"Like this\"."
|
|
|
|
|
|
|
|
|
|
//You can use variables inside of an echo statement
|
|
|
|
|
$foo = "foobar";
|
|
|
|
|
$bar = "barbaz";
|
|
|
|
|
|
|
|
|
|
echo "foo is $foo"; // foo is foobar
|
|
|
|
|
|
|
|
|
|
// Using single quotes will print the variable name, not the value
|
|
|
|
|
echo 'foo is $foo'; // foo is $foo
|
|
|
|
|
|
|
|
|
|
// If you are not using any other characters, you can just echo variables
|
|
|
|
|
echo $foo; // foobar
|
|
|
|
|
echo $foo,$bar; // foobarbarbaz
|
|
|
|
|
|
2001-12-08 19:46:08 +00:00
|
|
|
|
echo <<<END
|
|
|
|
|
This uses the "here document" syntax to output
|
|
|
|
|
multiple lines with $variable interpolation. Note
|
|
|
|
|
that the here document terminator must appear on a
|
|
|
|
|
line with just a semicolon no extra whitespace!
|
|
|
|
|
END;
|
|
|
|
|
|
2001-03-21 05:59:43 +00:00
|
|
|
|
// because echo is not a function, following code is invalid.
|
2001-07-07 21:27:21 +00:00
|
|
|
|
($some_var) ? echo('true'): echo('false');
|
2001-03-21 05:59:43 +00:00
|
|
|
|
|
|
|
|
|
// However, the following examples will work:
|
2001-07-07 21:27:21 +00:00
|
|
|
|
($some_var) ? print('true'): print('false'); // print is a function
|
2001-08-05 22:49:38 +00:00
|
|
|
|
echo $some_var ? 'true': 'false'; // changing the statement around
|
2001-03-21 05:59:43 +00:00
|
|
|
|
?>
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</example>
|
2001-03-21 05:59:43 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<function>echo</function> also has a shortcut syntax, where you
|
2001-03-21 05:59:43 +00:00
|
|
|
|
can immediately follow the opening tag with an equals sign.
|
|
|
|
|
<informalexample>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
I have <?=$foo?> foo.
|
|
|
|
|
]]>
|
2001-03-21 05:59:43 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</informalexample>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
|
|
|
|
See also:
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<function>print</function>,
|
|
|
|
|
<function>printf</function>, and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>flush</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.explode">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>explode</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Split a string by string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>array <function>explode</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>separator</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<paramdef>int
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<parameter><optional>limit</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2000-05-25 22:53:51 +00:00
|
|
|
|
Returns an array of strings, each of which is a substring of
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<parameter>string</parameter> formed by splitting it on
|
|
|
|
|
boundaries formed by the string <parameter>separator</parameter>.
|
|
|
|
|
If <parameter>limit</parameter> is set, the returned array will
|
|
|
|
|
contain a maximum of <parameter>limit</parameter> elements with
|
2001-12-07 21:27:53 +00:00
|
|
|
|
the last element containing the rest of
|
|
|
|
|
<parameter>string</parameter>.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
If <parameter>separator</parameter> is an empty string (""),
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<function>explode</function> will return &false;. If
|
2001-12-07 21:27:53 +00:00
|
|
|
|
<parameter>separator</parameter> contains a value that is not contained
|
|
|
|
|
in <parameter>string</parameter>, then <function>explode</function> will
|
|
|
|
|
return an array containing <parameter>string</parameter>.
|
2000-05-26 05:44:59 +00:00
|
|
|
|
</para>
|
2000-12-22 00:57:14 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
The <parameter>limit</parameter> parameter was added in PHP
|
|
|
|
|
4.0.1
|
|
|
|
|
</para>
|
2000-12-22 00:57:14 +00:00
|
|
|
|
</note>
|
2000-05-26 05:44:59 +00:00
|
|
|
|
<para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<example>
|
2001-12-07 21:27:53 +00:00
|
|
|
|
<title><function>explode</function> examples</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
1999-06-06 18:51:02 +00:00
|
|
|
|
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$pieces = explode(" ", $pizza);
|
2001-12-07 21:27:53 +00:00
|
|
|
|
|
|
|
|
|
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
|
|
|
|
|
list($user,$pass,$uid,$gid,$gecos,$home,$shell) = explode(":",$data);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
2000-10-07 22:40:49 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-05-29 12:56:14 +00:00
|
|
|
|
See also
|
|
|
|
|
<function>preg_split</function>,
|
|
|
|
|
<function>spliti</function>,
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<function>split</function>, and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>implode</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-11-22 19:24:09 +00:00
|
|
|
|
<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
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<function>htmlentities</function>
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string
|
|
|
|
|
<function>get_html_translation_table</function>
|
|
|
|
|
</funcdef>
|
|
|
|
|
<paramdef>int <parameter>table</parameter></paramdef>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<paramdef>int
|
|
|
|
|
<parameter><optional>quote_style</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
<function>get_html_translation_table</function> will return the
|
|
|
|
|
translation table that is used internally for
|
|
|
|
|
<function>htmlspecialchars</function> and
|
2000-09-12 17:36:56 +00:00
|
|
|
|
<function>htmlentities</function>. There are two new defines
|
1999-11-22 19:24:09 +00:00
|
|
|
|
(<parameter>HTML_ENTITIES</parameter>,
|
|
|
|
|
<parameter>HTML_SPECIALCHARS</parameter>) that allow you to
|
2000-09-12 17:36:56 +00:00
|
|
|
|
specify the table you want. And as in the
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<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>.
|
1999-11-22 19:24:09 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title>Translation Table Example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$trans = get_html_translation_table(HTML_ENTITIES);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
$str = "Hallo & <Frau> & Kr<4B>mer";
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$encoded = strtr($str, $trans);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
The <literal>$encoded</literal> variable will now contain: "Hallo
|
2000-07-08 13:50:19 +00:00
|
|
|
|
&<sgmltag>amp</sgmltag>;
|
|
|
|
|
&<sgmltag>lt</sgmltag>;Frau&<sgmltag>gt</sgmltag>;
|
|
|
|
|
&<sgmltag>amp</sgmltag>; Kr&<sgmltag>auml</sgmltag>;mer".
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
The cool thing is using <function>array_flip</function> to change
|
|
|
|
|
the direction of the translation.
|
|
|
|
|
<informalexample>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$trans = array_flip($trans);
|
|
|
|
|
$original = strtr($str, $trans);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</informalexample>
|
2000-07-08 13:50:19 +00:00
|
|
|
|
The content of <literal>$original</literal> would be: "Hallo &
|
|
|
|
|
<Frau> & Krämer".
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
See also: <function>htmlspecialchars</function>,
|
|
|
|
|
<function>htmlentities</function>, <function>strtr</function>,
|
|
|
|
|
and <function>array_flip</function>.
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.get-meta-tags">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>get_meta_tags</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
|
|
|
|
Extracts all meta tag content attributes from a file and returns
|
2000-07-05 09:45:05 +00:00
|
|
|
|
an array
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Opens <parameter>filename</parameter> and parses it line by line
|
|
|
|
|
for <meta> tags of the form
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title>Meta Tags Example</title>
|
|
|
|
|
<programlisting role="html">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
<meta name="author" content="name">
|
|
|
|
|
<meta name="tags" content="php3 documentation">
|
|
|
|
|
</head> <!-- parsing stops here -->
|
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
(pay attention to line endings - PHP uses a native function to
|
2000-02-19 14:53:22 +00:00
|
|
|
|
parse the input, so a Mac file won't work on Unix).
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
case.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
Setting <parameter>use_include_path</parameter> to 1 will result
|
2000-02-19 14:53:22 +00:00
|
|
|
|
in PHP trying to open the file along the standard include path.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2000-08-09 10:38:15 +00:00
|
|
|
|
<refentry id="function.hebrev">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>hebrev</refname>
|
|
|
|
|
<refpurpose>
|
|
|
|
|
Convert logical Hebrew text to visual text
|
|
|
|
|
</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
2000-08-09 10:50:56 +00:00
|
|
|
|
<funcdef>string <function>hebrev</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>hebrew_text</parameter></paramdef>
|
2000-08-09 10:38:15 +00:00
|
|
|
|
<paramdef>int
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<parameter><optional>max_chars_per_line</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-08-09 10:38:15 +00:00
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
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.
|
2000-08-09 10:38:15 +00:00
|
|
|
|
</para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<para>
|
2000-08-09 10:38:15 +00:00
|
|
|
|
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>
|
2000-08-09 10:50:56 +00:00
|
|
|
|
<paramdef>string <parameter>hebrew_text</parameter></paramdef>
|
2000-08-09 10:38:15 +00:00
|
|
|
|
<paramdef>int
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<parameter><optional>max_chars_per_line</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-08-09 10:38:15 +00:00
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
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.
|
2000-08-09 10:38:15 +00:00
|
|
|
|
</para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<para>
|
2000-08-09 10:38:15 +00:00
|
|
|
|
See also <function>hebrev</function>
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-09-05 23:11:23 +00:00
|
|
|
|
<refentry id="function.htmlentities">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>htmlentities</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Convert all applicable characters to HTML entities
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>htmlentities</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<paramdef>int
|
|
|
|
|
<parameter><optional>quote_style</optional></parameter>
|
|
|
|
|
</paramdef>
|
2001-10-04 13:00:00 +00:00
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>charset</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
This function is identical to
|
2000-09-11 19:33:48 +00:00
|
|
|
|
<function>htmlspecialchars</function> in all ways, except that
|
|
|
|
|
all characters which have HTML character entity equivalents are
|
2000-09-15 03:26:47 +00:00
|
|
|
|
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.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
<para>
|
2001-10-04 13:00:00 +00:00
|
|
|
|
At present, the ISO-8859-1 character set is used as default.
|
2001-12-17 22:29:42 +00:00
|
|
|
|
Support for the optional second argument was added in PHP 3.0.17 and PHP
|
|
|
|
|
4.0.3.
|
2001-10-04 13:00:00 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
Like <function>htmlspecialchars</function>, it takes an optional
|
|
|
|
|
third argument which defines character set used in conversion.
|
2001-12-17 22:29:42 +00:00
|
|
|
|
Support for this argument was added in PHP 4.1.0.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
<para>
|
|
|
|
|
See also <function>htmlspecialchars</function> and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>nl2br</function>.
|
|
|
|
|
</para>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.htmlspecialchars">
|
|
|
|
|
<refnamediv>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refname>htmlspecialchars</refname>
|
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Convert special characters to HTML entities
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>htmlspecialchars</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<paramdef>int
|
|
|
|
|
<parameter><optional>quote_style</optional></parameter>
|
|
|
|
|
</paramdef>
|
2001-10-04 13:00:00 +00:00
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>charset</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Certain characters have special significance in HTML, and should
|
|
|
|
|
be represented by HTML entities if they are to preserve their
|
2000-09-11 19:33:48 +00:00
|
|
|
|
meanings. This function returns a string with some of these
|
2000-09-12 17:36:56 +00:00
|
|
|
|
conversions made; the translations made are those most
|
2000-09-11 19:33:48 +00:00
|
|
|
|
useful for everyday web programming. If you require all HTML
|
|
|
|
|
character entities to be translated, use
|
|
|
|
|
<function>htmlentities</function> instead.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
This function is useful in preventing user-supplied text from
|
|
|
|
|
containing HTML markup, such as in a message board or guest book
|
2001-08-25 23:01:28 +00:00
|
|
|
|
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.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2000-09-11 19:33:48 +00:00
|
|
|
|
The translations performed are:
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
'&' (ampersand) becomes '&amp;'
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
'"' (double quote) becomes '&quot;' when ENT_NOQUOTES
|
|
|
|
|
is not set.
|
2000-09-12 17:36:56 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
''' (single quote) becomes '&#039;' only when
|
|
|
|
|
ENT_QUOTES is set.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
'<' (less than) becomes '&lt;'
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
'>' (greater than) becomes '&gt;'
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2000-09-12 17:36:56 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title><function>htmlspecialchars</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
|
|
|
|
|
]]>
|
2000-09-12 17:36:56 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2000-09-12 18:13:30 +00:00
|
|
|
|
Note that this function does not translate anything beyond what
|
1999-09-13 18:07:16 +00:00
|
|
|
|
is listed above. For full entity translation, see
|
2001-12-17 22:29:42 +00:00
|
|
|
|
<function>htmlentities</function>. Support for the optional
|
2001-08-25 23:01:28 +00:00
|
|
|
|
second argument was added in PHP 3.0.17 and PHP 4.0.3.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2001-10-04 13:00:00 +00:00
|
|
|
|
<para>
|
|
|
|
|
The third argument defines character set used in conversion. The
|
2001-12-17 22:29:42 +00:00
|
|
|
|
default character set is ISO-8859-1. Support for this third argument was
|
|
|
|
|
added in PHP 4.1.0.
|
2001-10-04 13:00:00 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
See also <function>htmlentities</function> and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>nl2br</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.implode">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>implode</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Join array elements with a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>implode</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>glue</parameter></paramdef>
|
|
|
|
|
<paramdef>array <parameter>pieces</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</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>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>implode</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$colon_separated = implode(":", $array);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
2000-10-07 22:40:49 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
|
|
|
|
See also <function>explode</function>, <function>join</function>,
|
1999-11-15 08:11:01 +00:00
|
|
|
|
and <function>split</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.join">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>join</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Join array elements with a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>join</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>glue</parameter></paramdef>
|
|
|
|
|
<paramdef>array <parameter>pieces</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
|
|
|
|
<function>join</function> is an alias to
|
1999-11-15 08:11:01 +00:00
|
|
|
|
<function>implode</function>, and is identical in every way.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-11-15 08:11:01 +00:00
|
|
|
|
<simpara>
|
|
|
|
|
See also <function>explode</function>, <function>implode</function>,
|
|
|
|
|
and <function>split</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2000-05-23 14:32:14 +00:00
|
|
|
|
<refentry id="function.levenshtein">
|
2000-05-23 14:12:34 +00:00
|
|
|
|
<refnamediv>
|
2000-05-27 00:42:50 +00:00
|
|
|
|
<refname>levenshtein</refname>
|
2000-05-23 14:12:34 +00:00
|
|
|
|
<refpurpose>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
Calculate Levenshtein distance between two strings
|
2000-05-23 14:12:34 +00:00
|
|
|
|
</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
<funcdef>int <function>levenshtein</function></funcdef>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<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>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
2000-05-23 14:12:34 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
This function returns the Levenshtein-Distance between the
|
2000-09-27 20:41:17 +00:00
|
|
|
|
two argument strings or -1, if one of the argument strings
|
|
|
|
|
is longer than the limit of 255 characters (255 should be
|
2001-02-25 02:38:53 +00:00
|
|
|
|
more than enough for name or dictionary comparison, and
|
2000-09-27 20:41:17 +00:00
|
|
|
|
nobody serious would be doing genetic analysis with PHP).
|
2000-05-23 14:12:34 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
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>.
|
2000-05-23 14:12:34 +00:00
|
|
|
|
The complexity of the algorithm is <literal>O(m*n)</literal>,
|
|
|
|
|
where <literal>n</literal> and <literal>m</literal> are the
|
2000-07-05 09:45:05 +00:00
|
|
|
|
length of <parameter>str1</parameter> and
|
2000-05-23 14:12:34 +00:00
|
|
|
|
<parameter>str2</parameter> (rather good when compared to
|
2000-09-27 20:41:17 +00:00
|
|
|
|
<function>similar_text</function>, which is O(max(n,m)**3),
|
2001-08-26 22:41:56 +00:00
|
|
|
|
but still expensive).
|
2000-05-23 14:12:34 +00:00
|
|
|
|
</para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<para>
|
|
|
|
|
In its simplest form the function will take only the two
|
2000-09-27 20:41:17 +00:00
|
|
|
|
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>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<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
|
2000-09-27 20:41:17 +00:00
|
|
|
|
arguments:
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
operation to apply: 'I', 'R' or 'D'
|
2000-09-27 20:41:17 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
actual character in string 1
|
2000-09-27 20:41:17 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
actual character in string 2
|
2000-09-27 20:41:17 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
position in string 1
|
2000-09-27 20:41:17 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
position in string 2
|
2000-09-27 20:41:17 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
remaining characters in string 1
|
2000-09-27 20:41:17 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
remaining characters in string 2
|
2000-09-27 20:41:17 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
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
|
2000-09-27 20:41:17 +00:00
|
|
|
|
certain symbols (characters) or even the context those symbols
|
2001-08-25 23:01:28 +00:00
|
|
|
|
appear in to determine the cost of insert, replace and delete
|
2001-07-16 09:19:52 +00:00
|
|
|
|
operations, but at the cost of losing all optimizations done
|
2000-09-27 20:41:17 +00:00
|
|
|
|
regarding cpu register utilization and cache misses that have
|
2001-08-25 23:01:28 +00:00
|
|
|
|
been worked into the other two variants.
|
|
|
|
|
</para>
|
2000-05-23 14:12:34 +00:00
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
See also <function>soundex</function>,
|
|
|
|
|
<function>similar_text</function>, and
|
|
|
|
|
<function>metaphone</function>.
|
2000-05-23 14:12:34 +00:00
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2001-01-16 23:26:07 +00:00
|
|
|
|
<refentry id="function.localeconv">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>localeconv</refname>
|
|
|
|
|
<refpurpose>Get numeric formatting information</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>array <function>localeconv</function></funcdef>
|
|
|
|
|
<void/>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
Returns an associative array containing localized numeric and
|
|
|
|
|
monetary formatting information.
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
<function>localeconv</function> returns data based upon the current locale
|
|
|
|
|
as set by <function>setlocale</function>. The associative array that is
|
|
|
|
|
returned contains the following fields:
|
|
|
|
|
<informaltable >
|
|
|
|
|
<tgroup cols="2">
|
|
|
|
|
<thead>
|
|
|
|
|
<row>
|
|
|
|
|
<entry>Array element</entry>
|
|
|
|
|
<entry>Description</entry>
|
|
|
|
|
</row>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<row>
|
|
|
|
|
<entry>decimal_point</entry>
|
|
|
|
|
<entry>Decimal point character</entry>
|
|
|
|
|
</row>
|
|
|
|
|
<row>
|
|
|
|
|
<entry>thousands_sep</entry>
|
|
|
|
|
<entry>Thousands separator</entry>
|
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>grouping</entry>
|
|
|
|
|
<entry>Array containing numeric groupings</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>int_curr_symbol</entry>
|
|
|
|
|
<entry>International currency symbol (i.e. USD)</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>currency_symbol</entry>
|
|
|
|
|
<entry>Local currency symbol (i.e. $)</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>mon_decimal_point</entry>
|
|
|
|
|
<entry>Monetary decimal point character</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>mon_thousands_sep</entry>
|
|
|
|
|
<entry>Monetary thousands separator</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>mon_grouping</entry>
|
|
|
|
|
<entry>Array containing monetary groupings</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>positive_sign</entry>
|
|
|
|
|
<entry>Sign for positive values</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>negative_sign</entry>
|
|
|
|
|
<entry>Sign for negative values</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>int_frac_digits</entry>
|
|
|
|
|
<entry>International fractional digits</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>frac_digits</entry>
|
|
|
|
|
<entry>Local fractional digits</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>p_cs_precedes</entry>
|
|
|
|
|
<entry>
|
|
|
|
|
&true; if currency_symbol precedes a positive value, &false;
|
|
|
|
|
if it succeeds one
|
|
|
|
|
</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>p_sep_by_space</entry>
|
|
|
|
|
<entry>
|
|
|
|
|
&true; if a space separates currency_symbol from a positive
|
|
|
|
|
value, &false; otherwise
|
|
|
|
|
</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>n_cs_precedes</entry>
|
|
|
|
|
<entry>
|
|
|
|
|
&true; if currency_symbol precedes a negative value, &false;
|
|
|
|
|
if it succeeds one
|
|
|
|
|
</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>n_sep_by_space</entry>
|
|
|
|
|
<entry>
|
|
|
|
|
&true; if a space separates currency_symbol from a negative
|
|
|
|
|
value, &false; otherwise
|
|
|
|
|
</entry>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</row>
|
|
|
|
|
<row valign="top">
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<entry>p_sign_posn</entry>
|
|
|
|
|
<entry>
|
2001-10-07 18:00:48 +00:00
|
|
|
|
<simplelist columns="2" type="horiz">
|
|
|
|
|
<member>0</member>
|
|
|
|
|
<member>
|
|
|
|
|
Parentheses surround the quantity and currency_symbol</member>
|
|
|
|
|
<member>1</member>
|
|
|
|
|
<member>
|
|
|
|
|
The sign string precedes the quantity and currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
<member>2</member>
|
|
|
|
|
<member>
|
|
|
|
|
The sign string succeeds the quantity and currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
<member>3</member>
|
|
|
|
|
<member>
|
|
|
|
|
The sign string immediately precedes the currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
<member>4</member>
|
|
|
|
|
<member>
|
|
|
|
|
The sign string immediately succeeds the currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
</simplelist>
|
|
|
|
|
</entry>
|
|
|
|
|
</row>
|
|
|
|
|
<row valign="top">
|
|
|
|
|
<entry>n_sign_posn</entry>
|
|
|
|
|
<entry>
|
|
|
|
|
<simplelist columns="2" type="horiz">
|
|
|
|
|
<member>0</member>
|
|
|
|
|
<member>
|
|
|
|
|
Parentheses surround the quantity and currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
<member>1</member>
|
|
|
|
|
<member>
|
|
|
|
|
The sign string precedes the quantity and currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
<member>2</member>
|
|
|
|
|
<member>
|
|
|
|
|
The sign string succeeds the quantity and currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
<member>3</member>
|
|
|
|
|
<member>
|
|
|
|
|
The sign string immediately precedes the currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
<member>4</member>
|
|
|
|
|
<member>The sign string immediately succeeds the currency_symbol
|
|
|
|
|
</member>
|
|
|
|
|
</simplelist>
|
|
|
|
|
</entry>
|
|
|
|
|
</row>
|
|
|
|
|
</tbody>
|
|
|
|
|
</tgroup>
|
|
|
|
|
</informaltable>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
The grouping fields contain arrays that define the way numbers
|
|
|
|
|
should be grouped. For example, the grouping field for the en_US
|
|
|
|
|
locale, would contain a 2 item array with the values 3 and 3.
|
|
|
|
|
The higher the index in the array, the farther left the grouping
|
|
|
|
|
is. If an array element is equal to CHAR_MAX, no further
|
|
|
|
|
grouping is done. If an array element is equal to 0, the
|
|
|
|
|
previous element should be used.
|
2001-01-16 23:26:07 +00:00
|
|
|
|
</para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title><function>localeconv</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-01-16 23:26:07 +00:00
|
|
|
|
setlocale(LC_ALL, "en_US");
|
|
|
|
|
|
|
|
|
|
$locale_info = localeconv();
|
|
|
|
|
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo "<PRE>\n";
|
2001-01-16 23:26:07 +00:00
|
|
|
|
echo "--------------------------------------------\n";
|
|
|
|
|
echo " Monetary information for current locale: \n";
|
|
|
|
|
echo "--------------------------------------------\n\n";
|
|
|
|
|
|
|
|
|
|
echo "int_curr_symbol: {$locale_info["int_curr_symbol"]}\n";
|
|
|
|
|
echo "currency_symbol: {$locale_info["currency_symbol"]}\n";
|
|
|
|
|
echo "mon_decimal_point: {$locale_info["mon_decimal_point"]}\n";
|
|
|
|
|
echo "mon_thousands_sep: {$locale_info["mon_thousands_sep"]}\n";
|
|
|
|
|
echo "positive_sign: {$locale_info["positive_sign"]}\n";
|
|
|
|
|
echo "negative_sign: {$locale_info["negative_sign"]}\n";
|
|
|
|
|
echo "int_frac_digits: {$locale_info["int_frac_digits"]}\n";
|
|
|
|
|
echo "frac_digits: {$locale_info["frac_digits"]}\n";
|
|
|
|
|
echo "p_cs_precedes: {$locale_info["p_cs_precedes"]}\n";
|
|
|
|
|
echo "p_sep_by_space: {$locale_info["p_sep_by_space"]}\n";
|
|
|
|
|
echo "n_cs_precedes: {$locale_info["n_cs_precedes"]}\n";
|
|
|
|
|
echo "n_sep_by_space: {$locale_info["n_sep_by_space"]}\n";
|
|
|
|
|
echo "p_sign_posn: {$locale_info["p_sign_posn"]}\n";
|
|
|
|
|
echo "n_sign_posn: {$locale_info["n_sign_posn"]}\n";
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo "</PRE>\n";
|
|
|
|
|
]]>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2001-01-16 23:26:07 +00:00
|
|
|
|
<para>
|
|
|
|
|
The constant CHAR_MAX is also defined for the use mentioned above.
|
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
Added in PHP 4.0.5
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
<para>
|
|
|
|
|
See also: <function>setlocale</function>.
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<!-- this section is nearly-identical to trim, ltrim and rtrim -->
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.ltrim">
|
|
|
|
|
<refnamediv>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refname>ltrim</refname>
|
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Strip whitespace from the beginning of a string
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<funcdef>string
|
|
|
|
|
<function>ltrim</function>
|
|
|
|
|
</funcdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter>str</parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>charlist</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
2001-09-17 21:33:40 +00:00
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
2001-10-17 16:24:01 +00:00
|
|
|
|
The second parameter was added in PHP 4.1.0
|
2001-09-17 21:33:40 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
This function returns a string with whitespace stripped from the
|
2001-08-09 20:52:55 +00:00
|
|
|
|
beginning of <parameter>str</parameter>.
|
|
|
|
|
Without the second parameter,
|
|
|
|
|
<function>ltrim</function> will strip these characters:
|
|
|
|
|
<!-- sorted by importance. Printed 3 times: trim, ltrim, rtrim -->
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
" " (<acronym>ASCII</acronym> <literal>32</literal>
|
|
|
|
|
(<literal>0x20</literal>)), an ordinary space.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
"\t" (<acronym>ASCII</acronym> <literal>9</literal>
|
|
|
|
|
(<literal>0x09</literal>)), a tab.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 00:55:53 +00:00
|
|
|
|
"\n" (<acronym>ASCII</acronym> <literal>10</literal>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
(<literal>0x0A</literal>)), a new line (line feed).
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 00:55:53 +00:00
|
|
|
|
"\r" (<acronym>ASCII</acronym> <literal>13</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0D</literal>)), a carriage return.
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
"\0" (<acronym>ASCII</acronym> <literal>0</literal>
|
|
|
|
|
(<literal>0x00</literal>)), the <literal>NUL</literal>-byte.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara> <!-- not \v, since not supported by PHP -->
|
|
|
|
|
"\x0B" (<acronym>ASCII</acronym> <literal>11</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0B</literal>)), a vertical tab.
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
You can also specify the characters you want to strip, by means
|
|
|
|
|
of the <parameter>charlist</parameter> parameter.
|
|
|
|
|
Simply list all characters that you want to be stripped. With
|
|
|
|
|
<literal>..</literal> you can specify a range of characters.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title>Usuage example of <function>ltrim</function></title>
|
|
|
|
|
<para>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$text = "\t\tThese are a few words :) ... ";
|
|
|
|
|
$trimmed = ltrim($text);
|
|
|
|
|
// $trimmed = "These are a few words :) ... "
|
|
|
|
|
$trimmed = ltrim($text," \t.");
|
|
|
|
|
// $trimmed = "These are a few words :) ... "
|
|
|
|
|
$clean = ltrim($binary,"\0x00..\0x1F");
|
|
|
|
|
// trim the ASCII control characters at the beginning of $binary
|
|
|
|
|
// (from 0 to 31 inclusive)
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</para>
|
|
|
|
|
</example>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<para>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
See also <function>trim</function> and <function>rtrim</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.md5">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>md5</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Calculate the md5 hash of a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>md5</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Calculates the MD5 hash of <parameter>str</parameter> using the
|
2000-05-23 15:58:32 +00:00
|
|
|
|
<ulink url="&url.rfc;rfc1321.html">RSA Data Security, Inc.
|
2001-02-25 02:38:53 +00:00
|
|
|
|
MD5 Message-Digest Algorithm</ulink>, and returns that hash.
|
2001-12-08 20:04:38 +00:00
|
|
|
|
The hash is a 32-character hexadecimal number.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<para>
|
2001-12-12 07:53:11 +00:00
|
|
|
|
See also: <function>crc32</function> and <function>md5_file</function>
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.md5-file">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>md5_file</refname>
|
|
|
|
|
<refpurpose>Calculates the md5 hash of a given filename</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>md5_file</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>filename</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Calculates the MD5 hash of the specified
|
|
|
|
|
<parameter>filename</parameter> using the
|
|
|
|
|
<ulink url="&url.rfc;rfc1321.html">RSA Data Security, Inc.
|
|
|
|
|
MD5 Message-Digest Algorithm</ulink>, and returns that hash.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
This function has the same purpose of the command line utility
|
|
|
|
|
md5sum.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
See also: <function>md5</function> and <function>crc32</function>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-09-13 16:15:17 +00:00
|
|
|
|
<refentry id="function.metaphone">
|
|
|
|
|
<refnamediv>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<refname>metaphone</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Calculate the metaphone key of a string</refpurpose>
|
1999-09-13 16:15:17 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>metaphone</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-09-13 16:15:17 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Calculates the metaphone key of <parameter>str</parameter>.
|
|
|
|
|
</para>
|
1999-09-13 16:15:17 +00:00
|
|
|
|
<para>
|
1999-09-13 16:48:55 +00:00
|
|
|
|
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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
English pronunciation. The metaphone generated keys are of
|
|
|
|
|
variable length.
|
|
|
|
|
</para>
|
1999-09-13 16:15:17 +00:00
|
|
|
|
<para>
|
1999-09-13 16:48:55 +00:00
|
|
|
|
Metaphone was developed by Lawrence Philips
|
|
|
|
|
<lphilips@verity.com>. It is described in ["Practical
|
2000-07-08 13:50:19 +00:00
|
|
|
|
Algorithms for Programmers", Binstock & Rex, Addison Wesley,
|
1999-09-13 16:48:55 +00:00
|
|
|
|
1995].
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-13 16:15:17 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.nl2br">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>nl2br</refname>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<refpurpose>
|
|
|
|
|
Inserts HTML line breaks before all newlines in a string
|
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>nl2br</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-23 15:35:46 +00:00
|
|
|
|
Returns <parameter>string</parameter> with '<br />' inserted
|
2000-02-19 14:53:22 +00:00
|
|
|
|
before all newlines.
|
|
|
|
|
</para>
|
2001-05-22 16:11:30 +00:00
|
|
|
|
<note>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-05-22 16:11:30 +00:00
|
|
|
|
Starting with PHP 4.0.5, <function>nl2br</function> is now XHTML
|
2001-05-22 22:52:58 +00:00
|
|
|
|
compliant. All versions before 4.0.5 will return
|
2001-05-22 16:11:30 +00:00
|
|
|
|
<parameter>string</parameter> with '<br>' inserted before
|
|
|
|
|
newlines instead of '<br />'.
|
2001-04-24 07:27:01 +00:00
|
|
|
|
</para>
|
2001-05-22 16:11:30 +00:00
|
|
|
|
</note>
|
2001-04-24 07:27:01 +00:00
|
|
|
|
<para>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
See also <function>htmlspecialchars</function>,
|
|
|
|
|
<function>htmlentities</function> and
|
|
|
|
|
<function>wordwrap</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.ord">
|
|
|
|
|
<refnamediv>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<refname>ord</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Return ASCII value of character</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>ord</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns the ASCII value of the first character of
|
|
|
|
|
<parameter>string</parameter>. This function complements
|
|
|
|
|
<function>chr</function>.
|
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>ord</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
if (ord($str) == 10) {
|
1999-09-13 18:07:16 +00:00
|
|
|
|
echo "The first character of \$str is a line feed.\n";
|
1999-06-06 18:51:02 +00:00
|
|
|
|
}
|
2001-12-04 19:17:54 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
2001-08-12 23:23:07 +00:00
|
|
|
|
<para>
|
|
|
|
|
You can find an ASCII-table over here: <ulink url="&url.asciitable;"
|
|
|
|
|
>&url.asciitable;</ulink>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
See also <function>chr</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.parse-str">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>parse_str</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Parses the string into variables</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>void <function>parse_str</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<paramdef>array
|
|
|
|
|
<parameter><optional>arr</optional>
|
|
|
|
|
</parameter>
|
|
|
|
|
</paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Parses <parameter>str</parameter> as if it were the query string
|
2000-09-12 12:10:29 +00:00
|
|
|
|
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.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2001-12-08 21:21:50 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
Support for the optional second parameter was added in PHP 4.0.3.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Using <function>parse_str</function></title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
$str = "first=value&second[]=this+works&second[]=another";
|
1999-06-06 18:51:02 +00:00
|
|
|
|
parse_str($str);
|
2000-02-19 14:53:22 +00:00
|
|
|
|
echo $first; /* prints "value" */
|
1999-06-06 18:51:02 +00:00
|
|
|
|
echo $second[0]; /* prints "this works" */
|
|
|
|
|
echo $second[1]; /* prints "another" */
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</programlisting>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</example>
|
|
|
|
|
</para>
|
2001-12-08 21:21:50 +00:00
|
|
|
|
<para>
|
|
|
|
|
See also <function>set_magic_quotes_runtime</function>
|
|
|
|
|
and <function>urldecode</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.print">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>print</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Output a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef><function>print</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>arg</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
2001-12-14 20:27:08 +00:00
|
|
|
|
Outputs <parameter>arg</parameter>. &return.success;
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
2001-12-14 20:27:08 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title><function>print</function> examples</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
|
|
|
|
print("Hello World");
|
|
|
|
|
|
|
|
|
|
print "print() also works without parentheses.";
|
|
|
|
|
|
|
|
|
|
print "This spans
|
|
|
|
|
multiple lines. The newlines will be
|
|
|
|
|
output as well";
|
|
|
|
|
|
|
|
|
|
print "This spans\nmultiple lines. The newlines will be\noutput as well.";
|
|
|
|
|
|
|
|
|
|
print "escaping characters is done \"Like this\"."
|
|
|
|
|
|
|
|
|
|
//You can use variables inside of an print statement
|
|
|
|
|
$foo = "foobar";
|
|
|
|
|
$bar = "barbaz";
|
|
|
|
|
|
|
|
|
|
print "foo is $foo"; // foo is foobar
|
|
|
|
|
|
|
|
|
|
// Using single quotes will print the variable name, not the value
|
|
|
|
|
print 'foo is $foo'; // foo is $foo
|
|
|
|
|
|
|
|
|
|
// If you are not using any other characters, you can just print variables
|
|
|
|
|
print $foo; // foobar
|
|
|
|
|
|
|
|
|
|
print <<<END
|
|
|
|
|
This uses the "here document" syntax to output
|
|
|
|
|
multiple lines with $variable interpolation. Note
|
|
|
|
|
that the here document terminator must appear on a
|
|
|
|
|
line with just a semicolon no extra whitespace!
|
|
|
|
|
END;
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2001-12-14 20:27:08 +00:00
|
|
|
|
See also <function>echo</function>, <function>printf</function>,
|
2000-02-19 14:53:22 +00:00
|
|
|
|
and <function>flush</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.printf">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>printf</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Output a formatted string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
2001-11-19 13:46:48 +00:00
|
|
|
|
<funcdef>void <function>printf</function></funcdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<paramdef>string <parameter>format</parameter></paramdef>
|
|
|
|
|
<paramdef>mixed
|
|
|
|
|
<parameter><optional>args</optional></parameter>...
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
|
|
|
|
Produces output according to <parameter>format</parameter>, which
|
2000-02-19 14:53:22 +00:00
|
|
|
|
is described in the documentation for <function>sprintf</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2000-08-09 10:18:38 +00:00
|
|
|
|
See also: <function>print</function>, <function>sprintf</function>,
|
2001-02-25 02:38:53 +00:00
|
|
|
|
<function>sscanf</function>, <function>fscanf</function>,
|
|
|
|
|
and <function>flush</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.quoted-printable-decode">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>quoted_printable_decode</refname>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Convert a quoted-printable string to an 8 bit string
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string
|
|
|
|
|
<function>quoted_printable_decode</function>
|
|
|
|
|
</funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
require the IMAP module to work.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.quotemeta">
|
|
|
|
|
<refnamediv>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refname>quotemeta</refname>
|
|
|
|
|
<refpurpose>Quote meta characters</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>quotemeta</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns a version of str with a backslash character
|
|
|
|
|
(<literal>\</literal>) before every character that is among
|
2000-02-19 14:53:22 +00:00
|
|
|
|
these: <screen>. \\ + * ? [ ^ ] ( $ )</screen>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
|
|
|
|
See also <function>addslashes</function>,
|
|
|
|
|
<function>htmlentities</function>,
|
|
|
|
|
<function>htmlspecialchars</function>,
|
|
|
|
|
<function>nl2br</function>, and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>stripslashes</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2001-12-15 14:52:20 +00:00
|
|
|
|
<refentry id='function.str-rot13'>
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>str_rot13</refname>
|
|
|
|
|
<refpurpose>Perform the rot13 transform on a string</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>str_rot13</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
This function performs the ROT13 encoding on the
|
|
|
|
|
<parameter>str</parameter> argument and returns the resulting
|
|
|
|
|
string. The ROT13 encoding simply shifts every letter by 13
|
|
|
|
|
places in the alphabet while leaving non-alpha characters
|
|
|
|
|
untouched. Encoding and decoding are done by the same function,
|
|
|
|
|
passing an encoded string as argument will return the original version.
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<!-- this section is nearly-identical to trim, ltrim and rtrim -->
|
2000-07-31 14:09:34 +00:00
|
|
|
|
<refentry id="function.rtrim">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>rtrim</refname>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<refpurpose>
|
|
|
|
|
Strip whitespace from the end of a string
|
|
|
|
|
</refpurpose>
|
2000-07-31 14:09:34 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2001-05-23 12:01:52 +00:00
|
|
|
|
<funcprototype>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<funcdef>string
|
|
|
|
|
<function>rtrim</function>
|
|
|
|
|
</funcdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter>str</parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>charlist</optional></parameter>
|
|
|
|
|
</paramdef>
|
2001-05-23 12:01:52 +00:00
|
|
|
|
</funcprototype>
|
2000-07-31 14:09:34 +00:00
|
|
|
|
</funcsynopsis>
|
2001-09-17 21:33:40 +00:00
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
2001-10-17 16:24:01 +00:00
|
|
|
|
The second parameter was added in PHP 4.1.0
|
2001-09-17 21:33:40 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
2000-07-31 14:09:34 +00:00
|
|
|
|
<para>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
This function returns a string with whitespace stripped from the
|
|
|
|
|
end of <parameter>str</parameter>.
|
|
|
|
|
Without the second parameter,
|
|
|
|
|
<function>rtrim</function> will strip these characters:
|
|
|
|
|
<!-- sorted by importance. Printed 3 times: trim, ltrim, rtrim -->
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
" " (<acronym>ASCII</acronym> <literal>32</literal>
|
|
|
|
|
(<literal>0x20</literal>)), an ordinary space.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
"\t" (<acronym>ASCII</acronym> <literal>9</literal>
|
|
|
|
|
(<literal>0x09</literal>)), a tab.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 00:55:53 +00:00
|
|
|
|
"\n" (<acronym>ASCII</acronym> <literal>10</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0A</literal>)), a new line (line feed).
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 00:55:53 +00:00
|
|
|
|
"\r" (<acronym>ASCII</acronym> <literal>13</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0D</literal>)), a carriage return.
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
"\0" (<acronym>ASCII</acronym> <literal>0</literal>
|
|
|
|
|
(<literal>0x00</literal>)), the <literal>NUL</literal>-byte.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara> <!-- not \v, since not supported by PHP -->
|
|
|
|
|
"\x0B" (<acronym>ASCII</acronym> <literal>11</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0B</literal>)), a vertical tab.
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
You can also specify the characters you want to strip, by means
|
|
|
|
|
of the <parameter>charlist</parameter> parameter.
|
|
|
|
|
Simply list all characters that you want to be stripped. With
|
|
|
|
|
<literal>..</literal> you can specify a range of characters.
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Usuage example of <function>rtrim</function></title>
|
|
|
|
|
<para>
|
2000-07-31 14:09:34 +00:00
|
|
|
|
<programlisting role="php">
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$text = "\t\tThese are a few words :) ... ";
|
|
|
|
|
$trimmed = rtrim($text);
|
|
|
|
|
// $trimmed = "\t\tThese are a few words :) ..."
|
|
|
|
|
$trimmed = rtrim($text," \t.");
|
|
|
|
|
// $trimmed = "\t\tThese are a few words :)"
|
|
|
|
|
$clean = rtrim($binary,"\0x00..\0x1F");
|
|
|
|
|
// trim the ASCII control characters at the end of $binary
|
|
|
|
|
// (from 0 to 31 inclusive)
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
2000-07-31 14:09:34 +00:00
|
|
|
|
</programlisting>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</para>
|
|
|
|
|
</example>
|
2000-07-31 14:09:34 +00:00
|
|
|
|
<para>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
See also <function>trim</function> and <function>ltrim</function>.
|
2000-07-31 14:09:34 +00:00
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2000-08-09 10:18:38 +00:00
|
|
|
|
<refentry id="function.sscanf">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>sscanf</refname>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<refpurpose>
|
|
|
|
|
Parses input from a string according to a format
|
|
|
|
|
</refpurpose>
|
2000-08-09 10:18:38 +00:00
|
|
|
|
</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>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
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">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-08-09 10:18:38 +00:00
|
|
|
|
// 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";
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
</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">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-08-09 10:18:38 +00:00
|
|
|
|
// get author info and generate DocBook entry
|
|
|
|
|
$auth = "24\tLewis Carroll";
|
2001-12-03 21:59:00 +00:00
|
|
|
|
$n = sscanf($auth,"%d\t%s %s", &$id, &$first, &$last);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo "<author id='$id'>
|
|
|
|
|
<firstname>$first</firstname>
|
|
|
|
|
<surname>$last</surname>
|
|
|
|
|
</author>\n";
|
|
|
|
|
]]>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2000-08-09 10:18:38 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
See also: <function>fscanf</function>, <function>printf</function>,
|
|
|
|
|
and <function>sprintf</function>.
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.setlocale">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>setlocale</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Set locale information</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>setlocale</function></funcdef>
|
2001-03-10 18:51:47 +00:00
|
|
|
|
<paramdef>mixed <parameter>category</parameter></paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<paramdef>string <parameter>locale</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<parameter>Category</parameter> is a named constant (or string)
|
|
|
|
|
specifying the category of the functions affected by the locale
|
|
|
|
|
setting:
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<itemizedlist>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-03-10 18:51:47 +00:00
|
|
|
|
LC_ALL for all of the below
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
LC_COLLATE for string comparison, see
|
|
|
|
|
<function>strcoll</function>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-03-10 18:51:47 +00:00
|
|
|
|
LC_CTYPE for character classification and conversion, for
|
|
|
|
|
example <function>strtoupper</function>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-03-10 18:51:47 +00:00
|
|
|
|
LC_MONETARY for <function>localeconv</function>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<simpara> LC_NUMERIC for decimal separator (See also:
|
|
|
|
|
<function>localeconv</function>)
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
LC_TIME for date and time formatting with
|
|
|
|
|
<function>strftime</function>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</itemizedlist>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
categories, or from "LANG".
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
If locale is zero or <literal>"0"</literal>, the locale setting
|
2000-02-19 14:53:22 +00:00
|
|
|
|
is not affected, only the current setting is returned.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-07-07 18:42:46 +00:00
|
|
|
|
Setlocale returns the new current locale, or &false; if the locale
|
2001-04-15 17:23:21 +00:00
|
|
|
|
functionality is not implemented in the platform, the specified
|
1999-06-06 18:51:02 +00:00
|
|
|
|
locale does not exist or the category name is invalid.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
An invalid category name also causes a warning message.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.similar-text">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>similar_text</refname>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Calculate the similarity between two strings
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>similar_text</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>first</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>second</parameter></paramdef>
|
2001-09-21 20:40:32 +00:00
|
|
|
|
<paramdef>float
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<parameter><optional>percent</optional></parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
the longest string.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
both strings.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.soundex">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>soundex</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Calculate the soundex key of a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>soundex</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Calculates the soundex key of <parameter>str</parameter>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
long, starting with a letter.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
This particular soundex function is one described by Donald Knuth
|
|
|
|
|
in "The Art Of Computer Programming, vol. 3: Sorting And
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Searching", Addison-Wesley (1973), pp. 391-392.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Soundex Examples</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
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';
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</programlisting>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</example>
|
|
|
|
|
</para>
|
2001-12-08 23:39:06 +00:00
|
|
|
|
<para>
|
|
|
|
|
See also <function>levenshtein</function>,
|
|
|
|
|
<function>metaphone</function>, and <function>similar_text</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.sprintf">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>sprintf</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Return a formatted string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>sprintf</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>format</parameter></paramdef>
|
|
|
|
|
<paramdef>mixed
|
|
|
|
|
<parameter><optional>args</optional></parameter>...
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
|
|
|
|
Returns a string produced according to the formatting string
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<parameter>format</parameter>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2000-09-11 19:15:11 +00:00
|
|
|
|
The format string is composed of zero or more directives:
|
1999-06-06 18:51:02 +00:00
|
|
|
|
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>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
and <function>printf</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2000-09-11 19:15:11 +00:00
|
|
|
|
Each conversion specification consists of a percent sign
|
|
|
|
|
(<literal>%</literal>), followed by one or more of these
|
|
|
|
|
elements, in order:
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<orderedlist>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2000-09-11 19:15:11 +00:00
|
|
|
|
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.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2000-09-11 19:15:11 +00:00
|
|
|
|
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.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2000-09-11 19:15:11 +00:00
|
|
|
|
An optional number, a <emphasis>width specifier</emphasis>
|
|
|
|
|
that says how many characters (minimum) this conversion should
|
|
|
|
|
result in.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2000-09-11 19:15:11 +00:00
|
|
|
|
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
|
2001-09-21 23:21:07 +00:00
|
|
|
|
<type>float</type>. (Another function useful for formatting numbers is
|
2000-09-11 19:15:11 +00:00
|
|
|
|
<function>number_format</function>.)
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2000-09-11 19:15:11 +00:00
|
|
|
|
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
|
2001-05-20 00:50:14 +00:00
|
|
|
|
integer, and presented as a (signed) decimal number.
|
|
|
|
|
</member>
|
|
|
|
|
<member>
|
|
|
|
|
<literal>u</literal> - the argument is treated as an
|
|
|
|
|
integer, and presented as an unsigned decimal number.
|
2000-09-11 19:15:11 +00:00
|
|
|
|
</member>
|
|
|
|
|
<member>
|
2001-09-21 23:21:07 +00:00
|
|
|
|
<literal>f</literal> - the argument is treated as a
|
|
|
|
|
<type>float</type>, and presented as a floating-point number.
|
2000-09-11 19:15:11 +00:00
|
|
|
|
</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>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</orderedlist>
|
|
|
|
|
</para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<para>
|
|
|
|
|
As of PHP version 4.0.6 the format string supports argument
|
|
|
|
|
numbering/swapping. Here is an example:
|
|
|
|
|
<example>
|
|
|
|
|
<title>Argument swapping</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-04-09 16:00:17 +00:00
|
|
|
|
$format = "There are %d monkeys in the %s";
|
|
|
|
|
printf($format,$num,$location);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
This might output, "There are 5 monkeys in the tree". But
|
|
|
|
|
imagine we are creating a format string in a separate file,
|
|
|
|
|
commonly because we would like to internationalize it and we
|
|
|
|
|
rewrite it as:
|
|
|
|
|
<example>
|
|
|
|
|
<title>Argument swapping</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-04-09 16:00:17 +00:00
|
|
|
|
$format = "The %s contains %d monkeys";
|
|
|
|
|
printf($format,$num,$location);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
We now have a problem. The order of the placeholders in the
|
|
|
|
|
format string does not match the order of the arguments in the
|
|
|
|
|
code. We would like to leave the code as is and simply indicate
|
|
|
|
|
in the format string which arguments the placeholders refer to.
|
|
|
|
|
We would write the format string like this instead:
|
|
|
|
|
<example>
|
|
|
|
|
<title>Argument swapping</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-04-09 16:00:17 +00:00
|
|
|
|
$format = "The %2\$s contains %1\$d monkeys";
|
|
|
|
|
printf($format,$num,$location);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
An added benefit here is that you can repeat the placeholders without
|
|
|
|
|
adding more arguments in the code. For example:
|
|
|
|
|
<example>
|
|
|
|
|
<title>Argument swapping</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-26 22:41:56 +00:00
|
|
|
|
$format = "The %2\$s contains %1\$d monkeys.
|
2001-08-25 23:01:28 +00:00
|
|
|
|
That's a nice %2\$s full of %1\$d monkeys.";
|
|
|
|
|
printf($format, $num, $location);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
See also: <function>printf</function>,
|
|
|
|
|
<function>sscanf</function>, <function>fscanf</function>, and
|
|
|
|
|
<function>number_format</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Examples</title>
|
|
|
|
|
<para>
|
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>sprintf</function>: zero-padded integers</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>sprintf</function>: formatting currency</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
1999-06-06 18:51:02 +00:00
|
|
|
|
$money1 = 68.75;
|
|
|
|
|
$money2 = 54.35;
|
|
|
|
|
$money = $money1 + $money2;
|
|
|
|
|
// echo $money will output "123.1";
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$formatted = sprintf("%01.2f", $money);
|
1999-06-06 18:51:02 +00:00
|
|
|
|
// echo $formatted will output "123.10"
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2000-12-11 20:50:51 +00:00
|
|
|
|
<refentry id="function.strncasecmp">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strncasecmp</refname>
|
|
|
|
|
<refpurpose>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
Binary safe case-insensitive string comparison of the first n
|
|
|
|
|
characters
|
2000-12-11 20:50:51 +00:00
|
|
|
|
</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strncasecmp</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str1</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>str2</parameter></paramdef>
|
|
|
|
|
<paramdef>int <parameter>len</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
This function is similar to <function>strcasecmp</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.
|
2000-12-11 20:50:51 +00:00
|
|
|
|
</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>
|
|
|
|
|
See also <function>ereg</function>, <function>strcasecmp</function>,
|
|
|
|
|
<function>strcmp</function>, <function>substr</function>,
|
|
|
|
|
<function>stristr</function>, and <function>strstr</function>.
|
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-09-02 14:09:16 +00:00
|
|
|
|
<refentry id="function.strcasecmp">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strcasecmp</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Binary safe case-insensitive string comparison
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-09-02 14:09:16 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strcasecmp</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str1</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>str2</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-09-02 14:09:16 +00:00
|
|
|
|
</funcsynopsis>
|
2000-02-19 23:29:47 +00:00
|
|
|
|
<para>
|
2000-07-08 13:50:19 +00:00
|
|
|
|
Returns < 0 if <parameter>str1</parameter> is less than
|
2000-08-20 19:50:05 +00:00
|
|
|
|
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
1999-09-02 14:09:16 +00:00
|
|
|
|
is greater than <parameter>str2</parameter>, and 0 if they are
|
2000-02-19 14:53:22 +00:00
|
|
|
|
equal.
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<example>
|
2000-02-19 23:29:47 +00:00
|
|
|
|
<title><function>strcasecmp</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-02-19 23:29:47 +00:00
|
|
|
|
$var1 = "Hello";
|
|
|
|
|
$var2 = "hello";
|
2001-08-05 22:49:38 +00:00
|
|
|
|
if (!strcasecmp($var1, $var2)) {
|
2000-02-19 23:29:47 +00:00
|
|
|
|
echo '$var1 is equal to $var2 in a case-insensitive string comparison';
|
|
|
|
|
}
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 23:29:47 +00:00
|
|
|
|
</programlisting>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</example>
|
2000-02-19 23:29:47 +00:00
|
|
|
|
</para>
|
1999-09-02 14:09:16 +00:00
|
|
|
|
<simpara>
|
|
|
|
|
See also <function>ereg</function>, <function>strcmp</function>,
|
2000-12-11 20:50:51 +00:00
|
|
|
|
<function>substr</function>, <function>stristr</function>,
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<function>strncasecmp</function>, and
|
|
|
|
|
<function>strstr</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-09-02 14:09:16 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.strchr">
|
|
|
|
|
<refnamediv>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refname>strchr</refname>
|
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Find the first occurrence of a character
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strchr</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>haystack</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>needle</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
This function is an alias for <function>strstr</function>, and is
|
2000-02-19 14:53:22 +00:00
|
|
|
|
identical in every way.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.strcmp">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strcmp</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Binary safe string comparison</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strcmp</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str1</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>str2</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
2000-07-08 13:50:19 +00:00
|
|
|
|
Returns < 0 if <parameter>str1</parameter> is less than
|
2000-08-20 19:50:05 +00:00
|
|
|
|
<parameter>str2</parameter>; > 0 if <parameter>str1</parameter>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
is greater than <parameter>str2</parameter>, and 0 if they are
|
2000-02-19 14:53:22 +00:00
|
|
|
|
equal.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Note that this comparison is case sensitive.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
See also <function>ereg</function>,
|
|
|
|
|
<function>strcasecmp</function>, <function>substr</function>,
|
2000-12-11 20:50:51 +00:00
|
|
|
|
<function>stristr</function>, <function>strncasecmp</function>,
|
|
|
|
|
<function>strncmp</function>, and <function>strstr</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2001-01-20 19:12:53 +00:00
|
|
|
|
<refentry id="function.strcoll">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strcoll</refname>
|
|
|
|
|
<refpurpose>Locale based string comparison</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strcoll</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
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<parameter>str2</parameter>; > 0 if
|
|
|
|
|
<parameter>str1</parameter> is greater than
|
|
|
|
|
<parameter>str2</parameter>, and 0 if they are equal.
|
|
|
|
|
<function>strcoll</function> uses the current locale for doing
|
|
|
|
|
the comparisons. If the current locale is C or POSIX, this
|
2001-01-20 19:12:53 +00:00
|
|
|
|
function is equivalent to <function>strcmp</function>.
|
|
|
|
|
</simpara>
|
|
|
|
|
<simpara>
|
|
|
|
|
Note that this comparison is case sensitive, and unlike
|
|
|
|
|
<function>strcmp</function> this function is not binary safe.
|
|
|
|
|
</simpara>
|
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
|
|
|
|
Added in PHP 4.0.5.
|
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
|
|
|
|
<simpara>
|
|
|
|
|
See also <function>ereg</function>, <function>strcmp</function>,
|
|
|
|
|
<function>strcasecmp</function>, <function>substr</function>,
|
|
|
|
|
<function>stristr</function>, <function>strncasecmp</function>,
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<function>strncmp</function>, <function>strstr</function>, and
|
|
|
|
|
<function>setlocale</function>.
|
2001-01-20 19:12:53 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.strcspn">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strcspn</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Find length of initial segment not matching mask
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strcspn</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str1</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>str2</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
Returns the length of the initial segment of
|
|
|
|
|
<parameter>str1</parameter> which does <emphasis>not</emphasis>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
contain any of the characters in <parameter>str2</parameter>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
See also <function>strspn</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</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>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strip_tags</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>allowable_tags</optional></parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
1999-09-23 08:49:02 +00:00
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
This function tries to return a string with all HTML and PHP tags
|
|
|
|
|
stripped from a given <parameter>str</parameter>. 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.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-23 08:49:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
You can use the optional second parameter to specify tags which
|
|
|
|
|
should not be stripped.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2001-10-29 01:51:33 +00:00
|
|
|
|
<parameter>allowable_tags</parameter> was added in PHP 3.0.13
|
|
|
|
|
and PHP 4.0b3.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
</para>
|
2001-09-13 07:49:58 +00:00
|
|
|
|
<para>
|
|
|
|
|
<example>
|
|
|
|
|
<title><function>strip_tags</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
$string = strip_tags($string, '<a><b><i><u>');
|
|
|
|
|
]]>
|
2001-09-13 07:49:58 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
2001-10-29 01:51:33 +00:00
|
|
|
|
<warning>
|
|
|
|
|
<para>
|
|
|
|
|
This function does not modify any attributes on the tags that you allow
|
|
|
|
|
using <parameter>allowable_tags</parameter>, including the
|
|
|
|
|
<literal>style</literal> and <literal>onmouseover</literal> attributes
|
|
|
|
|
that a mischievous user may abuse when posting text that will be shown
|
|
|
|
|
to other users.
|
|
|
|
|
</para>
|
|
|
|
|
</warning>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-09-06 00:24:06 +00:00
|
|
|
|
<refentry id="function.stripcslashes">
|
|
|
|
|
<refnamediv>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refname>stripcslashes</refname>
|
|
|
|
|
<refpurpose>
|
|
|
|
|
Un-quote string quoted with <function>addcslashes</function>
|
|
|
|
|
</refpurpose>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>stripcslashes</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns a string with backslashes stripped off. Recognizes
|
|
|
|
|
C-like <literal>\n</literal>, <literal>\r</literal> ..., octal
|
|
|
|
|
and hexadecimal representation.
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Added in PHP4b3-dev.
|
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
|
|
|
|
</para>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
See also <function>addcslashes</function>.
|
|
|
|
|
</simpara>
|
1999-09-06 00:24:06 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.stripslashes">
|
|
|
|
|
<refnamediv>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refname>stripslashes</refname>
|
|
|
|
|
<refpurpose>
|
|
|
|
|
Un-quote string quoted with <function>addslashes</function>
|
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>stripslashes</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns a string with backslashes stripped off.
|
|
|
|
|
(<literal>\'</literal> becomes <literal>'</literal> and so on.)
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Double backslashes are made into a single backslash.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
See also <function>addslashes</function>.
|
|
|
|
|
</simpara>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-09-06 03:40:25 +00:00
|
|
|
|
<refentry id="function.stristr">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>stristr</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Case-insensitive <function>strstr</function>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-09-06 03:40:25 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>stristr</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>haystack</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>needle</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-09-06 03:40:25 +00:00
|
|
|
|
</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>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
are examined in a case-insensitive manner.
|
|
|
|
|
</para>
|
1999-09-06 03:40:25 +00:00
|
|
|
|
<para>
|
2001-07-07 18:42:46 +00:00
|
|
|
|
If <parameter>needle</parameter> is not found, returns &false;.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-06 03:40:25 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
If <parameter>needle</parameter> is not a string, it is converted
|
2000-02-19 14:53:22 +00:00
|
|
|
|
to an integer and applied as the ordinal value of a character.
|
|
|
|
|
</para>
|
1999-09-06 03:40:25 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
See also <function>strchr</function>,
|
|
|
|
|
<function>strrchr</function>, <function>substr</function>, and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>ereg</function>.
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
1999-09-06 03:40:25 +00:00
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.strlen">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strlen</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Get string length</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strlen</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Returns the length of <parameter>string</parameter>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2000-08-20 19:50:05 +00:00
|
|
|
|
<refentry id="function.strnatcmp">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strnatcmp</refname>
|
|
|
|
|
<refpurpose>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
String comparisons using a "natural order" algorithm
|
|
|
|
|
</refpurpose>
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</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>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
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>
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$arr1 = $arr2 = array("img12.png","img10.png","img2.png","img1.png");
|
2000-08-20 19:50:05 +00:00
|
|
|
|
echo "Standard string comparison\n";
|
|
|
|
|
usort($arr1,"strcmp");
|
|
|
|
|
print_r($arr1);
|
|
|
|
|
echo "\nNatural order string comparison\n";
|
|
|
|
|
usort($arr2,"strnatcmp");
|
|
|
|
|
print_r($arr2);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</informalexample>
|
|
|
|
|
The code above will generate the following output:
|
|
|
|
|
<informalexample>
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<screen>
|
|
|
|
|
<![CDATA[
|
2000-08-20 19:50:05 +00:00
|
|
|
|
Standard string comparison
|
|
|
|
|
Array
|
|
|
|
|
(
|
2001-11-21 23:05:19 +00:00
|
|
|
|
[0] => img1.png
|
|
|
|
|
[1] => img10.png
|
|
|
|
|
[2] => img12.png
|
|
|
|
|
[3] => img2.png
|
2000-08-20 19:50:05 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Natural order string comparison
|
|
|
|
|
Array
|
|
|
|
|
(
|
2001-11-21 23:05:19 +00:00
|
|
|
|
[0] => img1.png
|
|
|
|
|
[1] => img2.png
|
|
|
|
|
[2] => img10.png
|
|
|
|
|
[3] => img12.png
|
2000-08-20 19:50:05 +00:00
|
|
|
|
)
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
|
|
|
|
</screen>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
</informalexample>
|
|
|
|
|
For more information 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.
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</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>,
|
2000-12-11 20:50:51 +00:00
|
|
|
|
<function>strncmp</function>, <function>strncasecmp</function>,
|
|
|
|
|
<function>strnatcasecmp</function>, <function>strstr</function>,
|
|
|
|
|
<function>natsort</function> and <function>natcasesort</function>.
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.strnatcasecmp">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strnatcasecmp</refname>
|
|
|
|
|
<refpurpose>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
Case insensitive string comparisons using a "natural order"
|
|
|
|
|
algorithm
|
|
|
|
|
</refpurpose>
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</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>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
This function implements a comparison algorithm that orders
|
|
|
|
|
alphanumeric strings in the way a human being would. The
|
|
|
|
|
behaviour 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.
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
<simpara>
|
|
|
|
|
See also <function>ereg</function>,
|
|
|
|
|
<function>strcasecmp</function>, <function>substr</function>,
|
|
|
|
|
<function>stristr</function>, <function>strcmp</function>,
|
2000-12-11 20:50:51 +00:00
|
|
|
|
<function>strncmp</function>, <function>strncasecmp</function>,
|
|
|
|
|
<function>strnatcmp</function>, and <function>strstr</function>.
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.strncmp">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strncmp</refname>
|
|
|
|
|
<refpurpose>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
Binary safe string comparison of the first n characters
|
|
|
|
|
</refpurpose>
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</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>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
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>
|
2000-08-20 19:50:05 +00:00
|
|
|
|
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>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
See also <function>ereg</function>,
|
|
|
|
|
<function>strncasecmp</function>,
|
2000-08-20 19:50:05 +00:00
|
|
|
|
<function>strcasecmp</function>, <function>substr</function>,
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<function>stristr</function>, <function>strcmp</function>, and
|
|
|
|
|
<function>strstr</function>.
|
2000-08-20 19:50:05 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2000-07-08 20:50:51 +00:00
|
|
|
|
<refentry id="function.str-pad">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>str_pad</refname>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<refpurpose>
|
|
|
|
|
Pad a string to a certain length with another string
|
|
|
|
|
</refpurpose>
|
2000-07-08 20:50:51 +00:00
|
|
|
|
</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
|
2001-08-25 23:01:28 +00:00
|
|
|
|
<parameter><optional>pad_string</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-07-08 20:50:51 +00:00
|
|
|
|
<paramdef>int
|
|
|
|
|
<parameter><optional>pad_type</optional></parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
This functions returns the <parameter>input</parameter> string
|
2001-04-15 17:23:21 +00:00
|
|
|
|
padded on the left, the right, or both sides to the specified
|
2001-02-25 02:38:53 +00:00
|
|
|
|
padding length. If the optional argument
|
2000-07-08 20:50:51 +00:00
|
|
|
|
<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>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
If the value of <parameter>pad_length</parameter> is negative or
|
|
|
|
|
less than the length of the input string, no padding takes place.
|
2000-07-08 20:50:51 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
<example>
|
|
|
|
|
<title><function>str_pad</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-07-08 20:50:51 +00:00
|
|
|
|
$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___"
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-07-08 20:50:51 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.strpos">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strpos</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Find position of first occurrence of a string
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
entire string will be used.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-07-07 18:42:46 +00:00
|
|
|
|
If <parameter>needle</parameter> is not found, returns &false;.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<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>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
1999-12-18 09:31:49 +00:00
|
|
|
|
// in PHP 4.0b3 and newer:
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$pos = strpos($mystring, "b");
|
2001-07-07 21:27:21 +00:00
|
|
|
|
if ($pos === false) { // note: three equal signs
|
1999-12-18 09:31:49 +00:00
|
|
|
|
// not found...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// in versions older than 4.0b3:
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$pos = strpos($mystring, "b");
|
2001-12-14 20:09:33 +00:00
|
|
|
|
if (!is_integer($pos)) {
|
1999-12-18 09:31:49 +00:00
|
|
|
|
// not found...
|
|
|
|
|
}
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
</programlisting>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</informalexample>
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
1999-12-18 09:31:49 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
If <parameter>needle</parameter> is not a string, it is converted
|
2000-02-19 14:53:22 +00:00
|
|
|
|
to an integer and applied as the ordinal value of a character.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
the beginning of <parameter>haystack</parameter>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
See also <function>strrpos</function>,
|
|
|
|
|
<function>strrchr</function>, <function>substr</function>,
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>stristr</function>, and <function>strstr</function>.
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
|
|
|
|
|
<refentry id="function.strrchr">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strrchr</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Find the last occurrence of a character in a string
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strrchr</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>haystack</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>needle</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
This function returns the portion of
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<parameter>haystack</parameter> which starts at the last
|
|
|
|
|
occurrence of <parameter>needle</parameter> and goes until the
|
2000-02-19 14:53:22 +00:00
|
|
|
|
end of <parameter>haystack</parameter>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-07-07 18:42:46 +00:00
|
|
|
|
Returns &false; if <parameter>needle</parameter> is not found.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
If <parameter>needle</parameter> contains more than one
|
2000-02-19 14:53:22 +00:00
|
|
|
|
character, the first is used.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
If <parameter>needle</parameter> is not a string, it is converted
|
|
|
|
|
to an integer and applied as the ordinal value of a character.
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>strrchr</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
1999-06-06 18:51:02 +00:00
|
|
|
|
// get last directory in $PATH
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$dir = substr(strrchr($PATH, ":"), 1);
|
1999-06-06 18:51:02 +00:00
|
|
|
|
|
|
|
|
|
// get everything after last newline
|
|
|
|
|
$text = "Line 1\nLine 2\nLine 3";
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$last = substr(strrchr($text, 10), 1 );
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</programlisting>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</example>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-04-15 17:16:47 +00:00
|
|
|
|
See also <function>strchr</function>, <function>substr</function>,
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>stristr</function>, and <function>strstr</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-10-28 17:26:31 +00:00
|
|
|
|
<refentry id="function.str-repeat">
|
1999-10-28 16:58:56 +00:00
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>str_repeat</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Repeat a string</refpurpose>
|
1999-10-28 16:58:56 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>str_repeat</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>input</parameter></paramdef>
|
|
|
|
|
<paramdef>int <parameter>multiplier</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-10-28 16:58:56 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns <parameter>input_str</parameter> repeated
|
|
|
|
|
<parameter>multiplier</parameter> times.
|
|
|
|
|
<parameter>multiplier</parameter> has to be greater than 0.
|
1999-10-28 17:26:31 +00:00
|
|
|
|
</para>
|
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>str_repeat</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
echo str_repeat("-=", 10);
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-10-28 17:26:31 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
This will output "-=-=-=-=-=-=-=-=-=-=".
|
1999-10-28 16:58:56 +00:00
|
|
|
|
</para>
|
1999-11-02 14:58:47 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
This function was added in PHP 4.0.
|
|
|
|
|
</para>
|
1999-11-02 14:58:47 +00:00
|
|
|
|
</note>
|
1999-10-28 16:58:56 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.strrev">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strrev</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Reverse a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strrev</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
Returns <parameter>string</parameter>, reversed.
|
2001-11-01 22:58:31 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title>Reversing a string with <function>strrev</function></title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
<php
|
2001-11-01 22:58:31 +00:00
|
|
|
|
echo strrev("Hello world!"); // outputs "!dlrow olleH"
|
2001-11-21 23:05:19 +00:00
|
|
|
|
?>
|
|
|
|
|
]]>
|
2001-11-01 22:58:31 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
1999-09-05 23:11:23 +00:00
|
|
|
|
<refentry id="function.strrpos">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strrpos</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Find position of last occurrence of a char in a string
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strrpos</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>haystack</parameter></paramdef>
|
|
|
|
|
<paramdef>char <parameter>needle</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
be used.
|
|
|
|
|
</para>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
<para>
|
2001-07-07 18:42:46 +00:00
|
|
|
|
If <parameter>needle</parameter> is not found, returns &false;.
|
2000-11-12 03:57:21 +00:00
|
|
|
|
<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>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-11-12 03:57:21 +00:00
|
|
|
|
// in PHP 4.0b3 and newer:
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$pos = strrpos($mystring, "b");
|
2001-07-07 21:27:21 +00:00
|
|
|
|
if ($pos === false) { // note: three equal signs
|
2000-11-12 03:57:21 +00:00
|
|
|
|
// not found...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// in versions older than 4.0b3:
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$pos = strrpos($mystring, "b");
|
2001-11-21 23:05:19 +00:00
|
|
|
|
if (is_string($pos) && !$pos) {
|
2000-11-12 03:57:21 +00:00
|
|
|
|
// not found...
|
|
|
|
|
}
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
</programlisting>
|
2000-11-12 03:57:21 +00:00
|
|
|
|
</informalexample>
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
If <parameter>needle</parameter> is not a string, it is converted
|
2000-02-19 14:53:22 +00:00
|
|
|
|
to an integer and applied as the ordinal value of a character.
|
|
|
|
|
</para>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
See also <function>strpos</function>,
|
|
|
|
|
<function>strrchr</function>, <function>substr</function>,
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>stristr</function>, and <function>strstr</function>.
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
1999-09-05 23:11:23 +00:00
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.strspn">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strspn</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Find length of initial segment matching mask
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>int <function>strspn</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str1</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>str2</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
Returns the length of the initial segment of
|
|
|
|
|
<parameter>str1</parameter> which consists entirely of characters
|
2000-02-19 14:53:22 +00:00
|
|
|
|
in <parameter>str2</parameter>.
|
|
|
|
|
</simpara>
|
2001-03-26 03:44:44 +00:00
|
|
|
|
<para>
|
|
|
|
|
The line of code:
|
2000-07-01 21:36:42 +00:00
|
|
|
|
<informalexample>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$var = strspn("42 is the answer, what is the question ...", "1234567890");
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-07-01 21:36:42 +00:00
|
|
|
|
</programlisting>
|
2000-06-28 13:09:33 +00:00
|
|
|
|
</informalexample>
|
2001-03-26 03:44:44 +00:00
|
|
|
|
will assign 2 to <varname>$var</varname>, because the string "42" will
|
|
|
|
|
be the longest segment containing characters from "1234567890".
|
2000-06-28 13:09:33 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<simpara>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
See also <function>strcspn</function>.
|
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.strstr">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strstr</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Find first occurrence of a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strstr</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>haystack</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>needle</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns all of <parameter>haystack</parameter> from the first
|
2000-02-19 14:53:22 +00:00
|
|
|
|
occurrence of <parameter>needle</parameter> to the end.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-07-07 18:42:46 +00:00
|
|
|
|
If <parameter>needle</parameter> is not found, returns &false;.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
If <parameter>needle</parameter> is not a string, it is converted
|
2000-02-19 01:49:29 +00:00
|
|
|
|
to an integer and applied as the ordinal value of a character.
|
2000-07-28 20:05:07 +00:00
|
|
|
|
</para>
|
2001-12-20 22:38:53 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
This function is case-sensitive. For case-insensitive searches, use
|
|
|
|
|
<function>stristr</function>.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
2000-07-28 20:05:07 +00:00
|
|
|
|
<para>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>strstr</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-02-19 14:53:22 +00:00
|
|
|
|
$email = 'sterling@designmultimedia.com';
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$domain = strstr($email, '@');
|
2000-07-05 09:45:05 +00:00
|
|
|
|
print $domain; // prints @designmultimedia.com
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 01:49:29 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-12-20 22:38:53 +00:00
|
|
|
|
See also <function>ereg</function>, <function>preg_match</function>,
|
|
|
|
|
<function>strchr</function>, <function>stristr</function>,
|
|
|
|
|
<function>strpos</function>, <function>strrchr</function>, and
|
|
|
|
|
<function>substr</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
|
|
|
|
|
<refentry id="function.strtok">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strtok</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Tokenize string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strtok</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>arg1</parameter></paramdef>
|
|
|
|
|
<paramdef>string <parameter>arg2</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<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.
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>strtok</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-02-19 14:53:22 +00:00
|
|
|
|
$string = "This is an example string";
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$tok = strtok($string," ");
|
2000-02-19 14:53:22 +00:00
|
|
|
|
while ($tok) {
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo "Word=$tok<br>";
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$tok = strtok(" ");
|
2000-02-19 14:53:22 +00:00
|
|
|
|
}
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</programlisting>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</example>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<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
|
2000-02-19 14:53:22 +00:00
|
|
|
|
found.
|
|
|
|
|
</para>
|
2001-12-16 10:34:01 +00:00
|
|
|
|
<para>
|
|
|
|
|
The behavior when an empty part was found changed with PHP 4.1.0. The old
|
|
|
|
|
behavior returned an empty string, while the new, correct, behavior
|
|
|
|
|
simply skips the part of the string:
|
|
|
|
|
<example>
|
|
|
|
|
<title>Old <function>strtok</function> behavior</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
$first_token = strtok('/something', '/');
|
|
|
|
|
$second_token = strtok('/');
|
|
|
|
|
var_dump ($first_token, $second_token);
|
|
|
|
|
|
|
|
|
|
/* Output:
|
|
|
|
|
string(0) ""
|
|
|
|
|
string(9) "something"
|
|
|
|
|
*/
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
<example>
|
|
|
|
|
<title>New <function>strtok</function> behavior</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
$first_token = strtok('/something', '/');
|
|
|
|
|
$second_token = strtok('/');
|
|
|
|
|
var_dump ($first_token, $second_token);
|
|
|
|
|
|
|
|
|
|
/* Output:
|
|
|
|
|
string(9) "something"
|
|
|
|
|
bool(false)
|
|
|
|
|
*/
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
Also be careful that your tokens may be equal to "0". This
|
2001-07-07 18:42:46 +00:00
|
|
|
|
evaluates to &false; in conditional expressions.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
See also <function>split</function> and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>explode</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.strtolower">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strtolower</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Make a string lowercase</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strtolower</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns <parameter>string</parameter> with all alphabetic
|
2000-02-19 14:53:22 +00:00
|
|
|
|
characters converted to lowercase.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
Note that 'alphabetic' is determined by the current locale. This
|
|
|
|
|
means that in i.e. the default "C" locale, characters such as
|
2001-08-05 22:49:38 +00:00
|
|
|
|
umlaut-A (Ä) will not be converted.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2000-02-19 01:49:29 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>strtolower</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-02-19 14:53:22 +00:00
|
|
|
|
$str = "Mary Had A Little Lamb and She LOVED It So";
|
2001-08-26 22:41:56 +00:00
|
|
|
|
$str = strtolower($str);
|
2000-02-19 14:53:22 +00:00
|
|
|
|
print $str; # Prints mary had a little lamb and she loved it so
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-10-31 00:45:52 +00:00
|
|
|
|
See also <function>strtoupper</function>,
|
|
|
|
|
<function>ucfirst</function>,
|
|
|
|
|
and <function>ucwords</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.strtoupper">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strtoupper</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Make a string uppercase</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>strtoupper</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>string</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Returns <parameter>string</parameter> with all alphabetic
|
2000-02-19 14:53:22 +00:00
|
|
|
|
characters converted to uppercase.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
Note that 'alphabetic' is determined by the current locale. For
|
|
|
|
|
instance, in the default "C" locale characters such as umlaut-a
|
2000-02-19 14:53:22 +00:00
|
|
|
|
(<28>) will not be converted.
|
|
|
|
|
</para>
|
2000-02-19 02:06:35 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>strtoupper</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-02-19 14:53:22 +00:00
|
|
|
|
$str = "Mary Had A Little Lamb and She LOVED It So";
|
2001-08-26 22:41:56 +00:00
|
|
|
|
$str = strtoupper($str);
|
2000-02-19 14:53:22 +00:00
|
|
|
|
print $str; # Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<para>
|
2001-10-31 00:45:52 +00:00
|
|
|
|
See also <function>strtolower</function>,
|
|
|
|
|
<function>ucfirst</function>,
|
|
|
|
|
and <function>ucwords</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.str-replace">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>str_replace</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
Replace all occurrences of the search string with the replacement string
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
2001-01-22 21:48:59 +00:00
|
|
|
|
<funcdef>mixed <function>str_replace</function></funcdef>
|
|
|
|
|
<paramdef>mixed <parameter>search</parameter></paramdef>
|
|
|
|
|
<paramdef>mixed <parameter>replace</parameter></paramdef>
|
|
|
|
|
<paramdef>mixed <parameter>subject</parameter></paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
This function returns a string or an array with all occurences of
|
|
|
|
|
<parameter>search</parameter> in <parameter>subject</parameter>
|
|
|
|
|
replaced with the given <parameter>replace</parameter> value. If
|
|
|
|
|
you don't need fancy replacing rules, you should always use this
|
|
|
|
|
function instead of <function>ereg_replace</function> or
|
|
|
|
|
<function>preg_replace</function>.
|
|
|
|
|
</para>
|
2001-01-22 21:48:59 +00:00
|
|
|
|
<para>
|
|
|
|
|
In PHP 4.0.5 and later, every parameter to
|
|
|
|
|
<function>str_replace</function> can be an array.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2001-08-25 23:01:28 +00:00
|
|
|
|
If <parameter>subject</parameter> is an array, then the search
|
|
|
|
|
and replace is performed with every entry of
|
|
|
|
|
<parameter>subject</parameter>, and the return value is an array
|
|
|
|
|
as well.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
If <parameter>search</parameter> and
|
|
|
|
|
<parameter>replace</parameter> are arrays, then
|
|
|
|
|
<function>str_replace</function> takes a value from each array
|
|
|
|
|
and uses them to do search and replace on
|
|
|
|
|
<parameter>subject</parameter>. If
|
|
|
|
|
<parameter>replace</parameter> has fewer values than
|
|
|
|
|
<parameter>search</parameter>, then an empty string is used for
|
|
|
|
|
the rest of replacement values. If <parameter>search</parameter>
|
|
|
|
|
is an array and <parameter>replace</parameter> is a string; then
|
|
|
|
|
this replacement string is used for every value of
|
|
|
|
|
<parameter>search</parameter>. The converse would not make
|
|
|
|
|
sense, though.
|
2001-01-22 21:48:59 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
<example>
|
2001-01-22 21:48:59 +00:00
|
|
|
|
<title><function>str_replace</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
$bodytag = str_replace("%body%", "black", "<body text=%body%>");
|
|
|
|
|
]]>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</programlisting>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</example>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-11-16 00:41:55 +00:00
|
|
|
|
This function is binary safe.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2001-01-22 21:48:59 +00:00
|
|
|
|
<function>str_replace</function> was added in PHP 3.0.6, but was
|
2000-02-19 14:53:22 +00:00
|
|
|
|
buggy up until PHP 3.0.8.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-01-22 21:48:59 +00:00
|
|
|
|
See also <function>ereg_replace</function>,
|
|
|
|
|
<function>preg_replace</function>, and <function>strtr</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.strtr">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>strtr</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Translate certain characters</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
This function returns a copy of <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.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
If <parameter>from</parameter> and <parameter>to</parameter> are
|
|
|
|
|
different lengths, the extra characters in the longer of the two
|
|
|
|
|
are ignored.
|
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>strtr</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
1999-06-06 18:51:02 +00:00
|
|
|
|
$addr = strtr($addr, "<22><><EFBFBD>", "aao");
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</programlisting>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</example>
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
1999-11-22 19:24:09 +00:00
|
|
|
|
<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.
|
1999-11-27 20:34:06 +00:00
|
|
|
|
</para>
|
1999-11-22 19:24:09 +00:00
|
|
|
|
<para>
|
|
|
|
|
Examples:
|
|
|
|
|
<informalexample>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
$trans = array("hello" => "hi", "hi" => "hello");
|
1999-11-22 19:24:09 +00:00
|
|
|
|
echo strtr("hi all, I said hello", $trans) . "\n";
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</informalexample>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
This will show: "hello all, I said hi",
|
1999-11-22 19:24:09 +00:00
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
|
|
|
|
This feature (two arguments) was added in PHP 4.0.
|
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
|
|
|
|
<para>
|
|
|
|
|
See also <function>ereg_replace</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.substr">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>substr</refname>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refpurpose>Return part of a string</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<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>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
Substr returns the portion of <parameter>string</parameter>
|
|
|
|
|
specified by the <parameter>start</parameter> and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<parameter>length</parameter> parameters.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
If <parameter>start</parameter> is positive, the returned string
|
2000-08-27 21:05:36 +00:00
|
|
|
|
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>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title>Basic <function>substr</function> usage</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$rest = substr("abcdef", 1); // returns "bcdef"
|
|
|
|
|
$rest = substr("abcdef", 1, 3); // returns "bcd"
|
2001-12-20 23:05:09 +00:00
|
|
|
|
$rest = substr("abcdef", 0, 4); // returns "abcd"
|
|
|
|
|
$rest = substr("abcdef", 0, 8); // returns "abcdef"
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
If <parameter>start</parameter> is negative, the returned string
|
|
|
|
|
will start at the <parameter>start</parameter>'th character
|
2001-08-26 22:41:56 +00:00
|
|
|
|
from the end of <parameter>string</parameter>.</para>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title>Using a negative <parameter>start</parameter></title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-08-05 22:49:38 +00:00
|
|
|
|
$rest = substr("abcdef", -1); // returns "f"
|
|
|
|
|
$rest = substr("abcdef", -2); // returns "ef"
|
|
|
|
|
$rest = substr("abcdef", -3, 1); // returns "d"
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
If <parameter>length</parameter> is given and is positive, the string
|
|
|
|
|
returned will contain at most <parameter>length</parameter> characters
|
|
|
|
|
beginning from <parameter>start</parameter> (depending on the length of
|
|
|
|
|
<parameter>string</parameter>. If <parameter>string</parameter> is less
|
|
|
|
|
than <parameter>start</parameter> characters long, &false; will be
|
|
|
|
|
returned.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
If <parameter>length</parameter> is given and is negative, then that many
|
|
|
|
|
characters will be omitted from the end of <parameter>string</parameter>
|
|
|
|
|
(after the start position has been calculated when a
|
|
|
|
|
<parameter>start</parameter> is negative). If
|
|
|
|
|
<parameter>start</parameter> denotes a position beyond this truncation,
|
|
|
|
|
an empty string will be returned.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title>Using a negative <parameter>length</parameter></title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-12-20 23:05:09 +00:00
|
|
|
|
$rest = substr("abcdef", 0, -1); // returns "abcde"
|
|
|
|
|
$rest = substr("abcdef", 2, -1); // returns "cde"
|
|
|
|
|
$rest = substr("abcdef", 4, -4); // returns ""
|
|
|
|
|
$rest = substr("abcdef", -3, -1); // returns "de"
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2001-12-20 23:05:09 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
See also <function>strrchr</function> and
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>ereg</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2000-07-11 20:19:01 +00:00
|
|
|
|
<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>
|
2001-11-06 02:22:46 +00:00
|
|
|
|
<paramdef>string <parameter>haystack</parameter></paramdef>
|
2000-07-11 20:19:01 +00:00
|
|
|
|
<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>
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-07-11 20:19:01 +00:00
|
|
|
|
print substr_count("This is a test", "is"); // prints out 2
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-07-11 20:19:01 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
|
1999-12-09 09:05:12 +00:00
|
|
|
|
<refentry id="function.substr-replace">
|
1999-11-22 10:53:29 +00:00
|
|
|
|
<refnamediv>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<refname>substr_replace</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Replace text within a portion of a string</refpurpose>
|
1999-11-22 10:53:29 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<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>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</funcsynopsis>
|
1999-11-22 10:53:29 +00:00
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
<function>substr_replace</function> replaces a copy of
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<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
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<parameter>string</parameter>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
If <parameter>start</parameter> is negative, the replacing will
|
|
|
|
|
begin at the <parameter>start</parameter>'th character from the
|
2001-08-26 22:41:56 +00:00
|
|
|
|
end of <parameter>string</parameter>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-11-22 10:53:29 +00:00
|
|
|
|
<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>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>substr_replace</function> example</title>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
1999-11-22 10:53:29 +00:00
|
|
|
|
$var = 'ABCDEFGH:/MNRPQR/';
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo "Original: $var<hr>\n";
|
1999-11-22 10:53:29 +00:00
|
|
|
|
|
|
|
|
|
/* These two examples replace all of $var with 'bob'. */
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo substr_replace($var, 'bob', 0) . "<br>\n";
|
|
|
|
|
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br>\n";
|
1999-11-22 10:53:29 +00:00
|
|
|
|
|
|
|
|
|
/* Insert 'bob' right at the beginning of $var. */
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo substr_replace($var, 'bob', 0, 0) . "<br>\n";
|
1999-11-22 10:53:29 +00:00
|
|
|
|
|
|
|
|
|
/* These next two replace 'MNRPQR' in $var with 'bob'. */
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo substr_replace($var, 'bob', 10, -1) . "<br>\n";
|
|
|
|
|
echo substr_replace($var, 'bob', -7, -1) . "<br>\n";
|
1999-11-22 10:53:29 +00:00
|
|
|
|
|
|
|
|
|
/* Delete 'MNRPQR' from $var. */
|
2001-11-21 23:05:19 +00:00
|
|
|
|
echo substr_replace($var, '', 10, -1) . "<br>\n";
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
See also <function>str_replace</function> and
|
|
|
|
|
<function>substr</function>.
|
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<function>substr_replace</function> was added in PHP 4.0.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
1999-11-22 10:53:29 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<!-- this section is nearly-identical to trim, ltrim and rtrim -->
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<refentry id="function.trim">
|
|
|
|
|
<refnamediv>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refname>trim</refname>
|
|
|
|
|
<refpurpose>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
Strip whitespace from the beginning and end of a string
|
1999-09-13 18:07:16 +00:00
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
<funcdef>string
|
|
|
|
|
<function>trim</function>
|
|
|
|
|
</funcdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter>str</parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>charlist</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
2001-09-17 21:33:40 +00:00
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
2001-10-17 16:24:01 +00:00
|
|
|
|
The second parameter was added in PHP 4.1.0
|
2001-09-17 21:33:40 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<para>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
This function returns a string with whitespace stripped from the
|
|
|
|
|
beginning and end of <parameter>str</parameter>.
|
|
|
|
|
Without the second parameter,
|
|
|
|
|
<function>trim</function> will strip these characters:
|
|
|
|
|
<!-- sorted by importance. Printed 3 times: trim, ltrim, rtrim -->
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
" " (<acronym>ASCII</acronym> <literal>32</literal>
|
|
|
|
|
(<literal>0x20</literal>)), an ordinary space.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
"\t" (<acronym>ASCII</acronym> <literal>9</literal>
|
|
|
|
|
(<literal>0x09</literal>)), a tab.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 00:55:53 +00:00
|
|
|
|
"\n" (<acronym>ASCII</acronym> <literal>10</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0A</literal>)), a new line (line feed).
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
2001-08-26 00:55:53 +00:00
|
|
|
|
"\r" (<acronym>ASCII</acronym> <literal>13</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0D</literal>)), a carriage return.
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara>
|
|
|
|
|
"\0" (<acronym>ASCII</acronym> <literal>0</literal>
|
|
|
|
|
(<literal>0x00</literal>)), the <literal>NUL</literal>-byte.
|
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<simpara> <!-- not \v, since not supported by PHP -->
|
|
|
|
|
"\x0B" (<acronym>ASCII</acronym> <literal>11</literal>
|
2001-08-25 21:08:41 +00:00
|
|
|
|
(<literal>0x0B</literal>)), a vertical tab.
|
2001-08-09 20:52:55 +00:00
|
|
|
|
</simpara>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<para>
|
2001-08-09 20:52:55 +00:00
|
|
|
|
You can also specify the characters you want to strip, by means
|
|
|
|
|
of the <parameter>charlist</parameter> parameter.
|
|
|
|
|
Simply list all characters that you want to be stripped. With
|
|
|
|
|
<literal>..</literal> you can specify a range of characters.
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Usuage example of <function>trim</function></title>
|
|
|
|
|
<para>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$text = "\t\tThese are a few words :) ... ";
|
|
|
|
|
$trimmed = trim($text);
|
|
|
|
|
// $trimmed = "These are a few words :) ..."
|
|
|
|
|
$trimmed = trim($text," \t.");
|
|
|
|
|
// $trimmed = "These are a few words :)"
|
|
|
|
|
$clean = trim($binary,"\0x00..\0x1F");
|
|
|
|
|
// trim the ASCII control characters at the beginning and end of $binary
|
|
|
|
|
// (from 0 to 31 inclusive)
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</para>
|
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
See also <function>ltrim</function> and <function>rtrim</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.ucfirst">
|
|
|
|
|
<refnamediv>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refname>ucfirst</refname>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<refpurpose>Make a string's first character uppercase</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>ucfirst</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 03:05:49 +00:00
|
|
|
|
Returns a string with the first character of
|
2001-02-25 02:38:53 +00:00
|
|
|
|
<parameter>str</parameter> capitalized, if that character is
|
|
|
|
|
alphabetic.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
Note that 'alphabetic' is determined by the current locale. For
|
|
|
|
|
instance, in the default "C" locale characters such as umlaut-a
|
2001-08-05 22:49:38 +00:00
|
|
|
|
(ä) will not be converted.
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<example>
|
2001-06-23 20:10:52 +00:00
|
|
|
|
<title><function>ucfirst</function> example</title>
|
2001-08-26 22:41:56 +00:00
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-11-21 18:39:05 +00:00
|
|
|
|
$foo = 'hello world!';
|
2001-11-21 19:13:24 +00:00
|
|
|
|
$foo = ucfirst($foo); // Hello world!
|
2001-11-21 18:39:05 +00:00
|
|
|
|
|
|
|
|
|
$bar = 'HELLO WORLD!';
|
|
|
|
|
$bar = ucfirst($bar); // HELLO WORLD!
|
|
|
|
|
$bar = ucfirst(strtolower($bar)); // Hello world!
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
2001-11-21 18:39:05 +00:00
|
|
|
|
See also <function>strtolower</function>, <function>strtoupper</function>,
|
2001-10-31 00:45:52 +00:00
|
|
|
|
and <function>ucwords</function>.
|
2000-02-19 14:53:22 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.ucwords">
|
|
|
|
|
<refnamediv>
|
1999-09-13 18:07:16 +00:00
|
|
|
|
<refname>ucwords</refname>
|
|
|
|
|
<refpurpose>
|
|
|
|
|
Uppercase the first character of each word in a string
|
|
|
|
|
</refpurpose>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
2000-06-24 07:38:45 +00:00
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>ucwords</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</funcsynopsis>
|
2000-02-19 23:29:47 +00:00
|
|
|
|
<para>
|
2001-04-15 17:23:21 +00:00
|
|
|
|
Returns a string with the first character of each word in
|
2001-02-25 02:38:53 +00:00
|
|
|
|
<parameter>str</parameter> capitalized, if that character is
|
|
|
|
|
alphabetic.
|
2000-07-05 09:45:05 +00:00
|
|
|
|
<example>
|
|
|
|
|
<title><function>ucwords</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2001-11-21 18:39:05 +00:00
|
|
|
|
$foo = 'hello world!';
|
|
|
|
|
$foo = ucwords($foo); // Hello World!
|
|
|
|
|
|
|
|
|
|
$bar = 'HELLO WORLD!';
|
|
|
|
|
$bar = ucwords($bar); // HELLO WORLD!
|
|
|
|
|
$bar = ucwords(strtolower($bar)); // Hello World!
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-07-05 09:45:05 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
2000-10-27 14:47:18 +00:00
|
|
|
|
<note>
|
|
|
|
|
<simpara>
|
|
|
|
|
The definition of a word is any string of characters
|
|
|
|
|
that is immediately after a whitespace (These are:
|
|
|
|
|
space, form-feed, newline, carriage return, horizontal tab,
|
|
|
|
|
and vertical tab).
|
|
|
|
|
</simpara>
|
|
|
|
|
</note>
|
2000-02-19 23:29:47 +00:00
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
<para>
|
|
|
|
|
See also <function>strtoupper</function>,
|
2000-02-19 14:53:22 +00:00
|
|
|
|
<function>strtolower</function> and <function>ucfirst</function>.
|
|
|
|
|
</para>
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
2001-11-19 13:46:48 +00:00
|
|
|
|
<refentry id="function.vprintf">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>vprintf</refname>
|
|
|
|
|
<refpurpose>Output a formatted string</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>void <function>vprintf</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>format</parameter></paramdef>
|
|
|
|
|
<paramdef>array
|
|
|
|
|
<parameter>args</parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
|
|
|
|
Display array values as a formatted string according to
|
|
|
|
|
<parameter>format</parameter> (which is described in the documentation
|
|
|
|
|
for <function>sprintf</function>).
|
|
|
|
|
</simpara>
|
|
|
|
|
<simpara>
|
|
|
|
|
Operates as <function>printf</function> but accepts an array of
|
|
|
|
|
arguments, rather than a variable number of arguments.
|
|
|
|
|
</simpara>
|
|
|
|
|
<simpara>
|
|
|
|
|
See also: <function>printf</function>, <function>sprintf</function>,
|
|
|
|
|
<function>vsprintf</function>
|
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
|
|
<refentry id="function.vsprintf">
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>vsprintf</refname>
|
|
|
|
|
<refpurpose>Return a formatted string</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>vsprintf</function></funcdef>
|
|
|
|
|
<paramdef>string <parameter>format</parameter></paramdef>
|
|
|
|
|
<paramdef>array
|
|
|
|
|
<parameter>args</parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<simpara>
|
|
|
|
|
Return array values as a formatted string according to
|
|
|
|
|
<parameter>format</parameter> (which is described in the documentation
|
|
|
|
|
for <function>sprintf</function>).
|
|
|
|
|
</simpara>
|
|
|
|
|
<simpara>
|
|
|
|
|
Operates as <function>sprintf</function> but accepts an array of
|
|
|
|
|
arguments, rather than a variable number of arguments.
|
|
|
|
|
</simpara>
|
|
|
|
|
<simpara>
|
|
|
|
|
See also: <function>sprintf</function>, <function>vsprintf</function>,
|
|
|
|
|
<function>vprintf</function>
|
|
|
|
|
</simpara>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
|
|
|
|
|
<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>
|
2000-08-22 02:51:50 +00:00
|
|
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
<paramdef>int
|
|
|
|
|
<parameter><optional>width</optional></parameter>
|
|
|
|
|
</paramdef>
|
|
|
|
|
<paramdef>string
|
|
|
|
|
<parameter><optional>break</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-09-11 20:23:00 +00:00
|
|
|
|
<paramdef>int
|
|
|
|
|
<parameter><optional>cut</optional></parameter>
|
|
|
|
|
</paramdef>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
2001-02-25 02:38:53 +00:00
|
|
|
|
Returns a string with <parameter>str</parameter> wrapped
|
|
|
|
|
at the column number specified by the (optional)
|
|
|
|
|
<parameter>width</parameter> parameter. The line is broken
|
|
|
|
|
using the (optional) <parameter>break</parameter> parameter.
|
2000-08-21 22:33:33 +00:00
|
|
|
|
</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>
|
2000-09-11 20:23:00 +00:00
|
|
|
|
<para>
|
|
|
|
|
If the <parameter>cut</parameter> is set to 1, the string is
|
2001-08-26 22:41:56 +00:00
|
|
|
|
always wrapped at the specified width. So if you have a word
|
|
|
|
|
that is larger than the given width, it is broken apart.
|
|
|
|
|
(See second example).
|
2000-11-22 01:43:30 +00:00
|
|
|
|
<note>
|
|
|
|
|
<para>
|
|
|
|
|
The <parameter>cut</parameter> parameter was added in PHP 4.0.3.
|
|
|
|
|
</para>
|
|
|
|
|
</note>
|
2000-09-11 20:23:00 +00:00
|
|
|
|
</para>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
<para>
|
|
|
|
|
<example>
|
|
|
|
|
<title><function>wordwrap</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-08-21 22:33:33 +00:00
|
|
|
|
$text = "The quick brown fox jumped over the lazy dog.";
|
|
|
|
|
$newtext = wordwrap( $text, 20 );
|
|
|
|
|
|
|
|
|
|
echo "$newtext\n";
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
This example would display:
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
<informalexample>
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<screen>
|
|
|
|
|
<![CDATA[
|
2000-08-21 22:33:33 +00:00
|
|
|
|
The quick brown fox
|
2000-09-11 20:23:00 +00:00
|
|
|
|
jumped over the lazy dog.
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
|
|
|
|
</screen>
|
2000-09-11 20:23:00 +00:00
|
|
|
|
</informalexample>
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
<example>
|
|
|
|
|
<title><function>wordwrap</function> example</title>
|
|
|
|
|
<programlisting role="php">
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<![CDATA[
|
2000-09-11 20:23:00 +00:00
|
|
|
|
$text = "A very long woooooooooooord.";
|
|
|
|
|
$newtext = wordwrap( $text, 8, "\n", 1);
|
|
|
|
|
|
|
|
|
|
echo "$newtext\n";
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
2000-09-11 20:23:00 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
This example would display:
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
<informalexample>
|
2001-11-21 23:05:19 +00:00
|
|
|
|
<screen>
|
|
|
|
|
<![CDATA[
|
2000-09-11 20:23:00 +00:00
|
|
|
|
A very
|
|
|
|
|
long
|
|
|
|
|
wooooooo
|
|
|
|
|
ooooord.
|
2001-11-21 23:05:19 +00:00
|
|
|
|
]]>
|
|
|
|
|
</screen>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
</informalexample>
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
See also <function>nl2br</function>.
|
|
|
|
|
</para>
|
2000-08-22 02:51:50 +00:00
|
|
|
|
</refsect1>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
</refentry>
|
|
|
|
|
|
2001-12-17 19:49:37 +00:00
|
|
|
|
<refentry id='function.nl-langinfo'>
|
|
|
|
|
<refnamediv>
|
|
|
|
|
<refname>nl_langinfo</refname>
|
|
|
|
|
<refpurpose>
|
|
|
|
|
Query language and locale information
|
|
|
|
|
</refpurpose>
|
|
|
|
|
</refnamediv>
|
|
|
|
|
<refsect1>
|
|
|
|
|
<title>Description</title>
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
<funcprototype>
|
|
|
|
|
<funcdef>string <function>nl_langinfo</function></funcdef>
|
|
|
|
|
<paramdef>int <parameter>item</parameter></paramdef>
|
|
|
|
|
</funcprototype>
|
|
|
|
|
</funcsynopsis>
|
|
|
|
|
<para>
|
|
|
|
|
&warn.undocumented.func;
|
|
|
|
|
</para>
|
|
|
|
|
</refsect1>
|
|
|
|
|
</refentry>
|
2000-08-21 22:33:33 +00:00
|
|
|
|
|
1999-06-06 18:51:02 +00:00
|
|
|
|
</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
|
2001-12-12 20:47:43 +00:00
|
|
|
|
indent-tabs-mode:nil
|
1999-06-06 18:51:02 +00:00
|
|
|
|
sgml-parent-document:nil
|
1999-12-14 07:13:30 +00:00
|
|
|
|
sgml-default-dtd-file:"../../manual.ced"
|
1999-06-06 18:51:02 +00:00
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
|
End:
|
2001-09-21 22:47:49 +00:00
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
|
vi: ts=1 sw=1
|
1999-06-06 18:51:02 +00:00
|
|
|
|
-->
|