Documented new second parameter of trim, ltrim and rtrim (and chop of course)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@53987 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jeroen van Wolffelaar 2001-08-09 20:52:55 +00:00
parent 734ee2adcd
commit e377521e73

View file

@ -1,5 +1,5 @@
<?xml encoding="iso-8859-1"?>
<!-- $Revision: 1.102 $ -->
<!-- $Revision: 1.103 $ -->
<reference id="ref.strings">
<title>String functions</title>
<titleabbrev>Strings</titleabbrev>
@ -153,37 +153,20 @@ echo addcslashes("zoo['.']", 'z..A');
<refentry id="function.chop">
<refnamediv>
<refname>chop</refname>
<refpurpose>Remove trailing whitespace</refpurpose>
<refpurpose>Alias of <function>rtrim</function></refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>chop</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the argument string without trailing whitespace,
including newlines.
<example>
<title><function>chop</function> example</title>
<programlisting role="php">
$trimmed = chop($line);
</programlisting>
</example>
This function is an alias of <function>rtrim</function>.
</para>
<note>
<para>
<function>chop</function> is different than the Perl
<parameter>chop()</parameter> function, which removes the last
<literal>chop()</literal> function, which removes the last
character in the string.
</para>
</note>
<para>
See also <function>trim</function>, <function>ltrim</function>,
<function>rtrim</function>, and <function>chop</function>.
</para>
</refsect1>
</refentry>
@ -1323,6 +1306,7 @@ echo "&lt;/PRE&gt;\n";
</refsect1>
</refentry>
<!-- this section is nearly-identical to trim, ltrim and rtrim -->
<refentry id="function.ltrim">
<refnamediv>
<refname>ltrim</refname>
@ -1334,19 +1318,96 @@ echo "&lt;/PRE&gt;\n";
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>ltrim</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<funcdef>string
<function>ltrim</function>
</funcdef>
<paramdef>string
<parameter>str</parameter>
</paramdef>
<paramdef>string
<parameter><optional>charlist</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns a string with whitespace stripped from the
beginning of <parameter>str</parameter>. The whitespace
characters it currently strips are: "\n", "\r", "\t", "\v", "\0",
and a plain space.
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>
"\n" (<acronym>ASCII</acronym> <literal>13</literal>
(<literal>0x0D</literal>)), a newline.
</simpara>
</listitem>
<listitem>
<simpara>
"\r" (<acronym>ASCII</acronym> <literal>10</literal>
(<literal>0x0A</literal>)), a return.
</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>
(<literal>0x0B</literal>)), a <!-- TODO: -->.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
See also <function>chop</function>, <function>rtrim</function>, and
<function>trim</function>.
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>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>
<note>
<simpara>
The second parameter was added in PHP 4.0.7
</simpara>
</note>
<para>
See also <function>trim</function> and <function>rtrim</function>.
</para>
</refsect1>
</refentry>
@ -1617,32 +1678,108 @@ echo $second[1]; /* prints "another" */
</refsect1>
</refentry>
<!-- this section is nearly-identical to trim, ltrim and rtrim -->
<refentry id="function.rtrim">
<refnamediv>
<refname>rtrim</refname>
<refpurpose>Remove trailing whitespace.</refpurpose>
<refpurpose>
Strip whitespace from the end of a string
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>rtrim</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<funcdef>string
<function>rtrim</function>
</funcdef>
<paramdef>string
<parameter>str</parameter>
</paramdef>
<paramdef>string
<parameter><optional>charlist</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
Returns the argument string without trailing whitespace,
including newlines. This is an alias for <function>chop</function>.
<example>
<title><function>rtrim</function> example</title>
<programlisting role="php">
$trimmed = rtrim($line);
</programlisting>
</example>
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>
"\n" (<acronym>ASCII</acronym> <literal>13</literal>
(<literal>0x0D</literal>)), a newline.
</simpara>
</listitem>
<listitem>
<simpara>
"\r" (<acronym>ASCII</acronym> <literal>10</literal>
(<literal>0x0A</literal>)), a return.
</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>
(<literal>0x0B</literal>)), a <!-- TODO: -->.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
See also <function>trim</function>, <function>ltrim</function>, and
<function>rtrim</function>.
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>
<programlisting role="php">
<![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)
?>
]]>
</programlisting>
</para>
</example>
<note>
<simpara>
The second parameter was added in PHP 4.0.7
</simpara>
</note>
<para>
See also <function>trim</function> and <function>ltrim</function>.
</para>
</refsect1>
</refentry>
@ -3398,6 +3535,7 @@ echo substr_replace($var, '', 10, -1) . "&lt;br&gt;\n";
</refsect1>
</refentry>
<!-- this section is nearly-identical to trim, ltrim and rtrim -->
<refentry id="function.trim">
<refnamediv>
<refname>trim</refname>
@ -3409,19 +3547,96 @@ echo substr_replace($var, '', 10, -1) . "&lt;br&gt;\n";
<title>Description</title>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>trim</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
<funcdef>string
<function>trim</function>
</funcdef>
<paramdef>string
<parameter>str</parameter>
</paramdef>
<paramdef>string
<parameter><optional>charlist</optional></parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
This function returns a string with whitespace stripped from
the beginning and end of <parameter>str</parameter>. The
whitespace characters it currently strips are: "\n", "\r", "\t",
"\v", "\0", and a plain space.
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>
"\n" (<acronym>ASCII</acronym> <literal>13</literal>
(<literal>0x0D</literal>)), a newline.
</simpara>
</listitem>
<listitem>
<simpara>
"\r" (<acronym>ASCII</acronym> <literal>10</literal>
(<literal>0x0A</literal>)), a return.
</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>
(<literal>0x0B</literal>)), a <!-- TODO: -->.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
See also <function>chop</function>, <function>rtrim</function> and
<function>ltrim</function>.
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>
<note>
<simpara>
The second parameter was added in PHP 4.0.7
</simpara>
</note>
<para>
See also <function>ltrim</function> and <function>rtrim</function>.
</para>
</refsect1>
</refentry>