svn: /phpdoc/en/trunk/reference/strings/functions/ strspn.xml

From: Date: Tue, 22 Sep 2009 07:16:41 +0000
Subject: svn: /phpdoc/en/trunk/reference/strings/functions/ strspn.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4964@lists.php.net to get a copy of this message
torben Tue, 22 Sep 2009 07:16:41 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=288549 Log: Flush out the documentation for strspn() a bit. This an example of a very poorly documented function. Addresses bug #46912 This still needs work. Bug: http://bugs.php.net/46912 (Open) poorly choosen/ambigous example Changed paths: U phpdoc/en/trunk/reference/strings/functions/strspn.xml Modified: phpdoc/en/trunk/reference/strings/functions/strspn.xml =================================================================== --- phpdoc/en/trunk/reference/strings/functions/strspn.xml 2009-09-22 07:11:50 UTC (rev 288548) +++ phpdoc/en/trunk/reference/strings/functions/strspn.xml 2009-09-22 07:16:41 UTC (rev 288549) @@ -3,34 +3,49 @@ <refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.strspn"> <refnamediv> <refname>strspn</refname> - <refpurpose>Find length of initial segment matching mask</refpurpose> + <refpurpose> + Finds the length of the first segment of a string consisting + entirely of characters contained within a given mask. + </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> <type>int</type><methodname>strspn</methodname> - <methodparam><type>string</type><parameter>str1</parameter></methodparam> - <methodparam><type>string</type><parameter>str2</parameter></methodparam> + <methodparam><type>string</type><parameter>subject</parameter></methodparam> + <methodparam><type>string</type><parameter>mask</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>start</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam> </methodsynopsis> <para> - Finds the length of the initial segment matching mask. + Returns the length of the first group of consecutive characters + from <parameter>mask</parameter> found + in <parameter>subject</parameter>. </para> <para> + If <parameter>start</parameter> and <parameter>length</parameter> + are omitted, then all of <parameter>subject</parameter> will be + examined. If they are included, then the effect will be the same as + calling <literal>strspn(substr($subject, $start, $length), + $mask)</literal> (see <xref linkend="function.substr" /> + for more information). + </para> + <para> The line of code: <informalexample> <programlisting role="php"> <![CDATA[ <?php -$var = strspn("42 is the answer, what is the question ...", "1234567890"); +$var = strspn("42 is the answer to the 128th question.", "1234567890"); ?> ]]> </programlisting> </informalexample> - will assign 2 to <varname>$var</varname>, because the string "42" will - be the longest segment containing characters from "1234567890". + will assign <literal>2</literal> to <varname>$var</varname>, + because the string "42" is the first segment + from <parameter>subject</parameter> to consist only of characters + contained within "1234567890". </para> </refsect1> @@ -39,18 +54,18 @@ <para> <variablelist> <varlistentry> - <term><parameter>str1</parameter></term> + <term><parameter>subject</parameter></term> <listitem> <para> - The first string. + The string to examine. </para> </listitem> </varlistentry> <varlistentry> - <term><parameter>str2</parameter></term> + <term><parameter>mask</parameter></term> <listitem> <para> - The second string. + The list of allowable characters to include in counted segments. </para> </listitem> </varlistentry> @@ -58,18 +73,47 @@ <term><parameter>start</parameter></term> <listitem> <para> - The start position of the string to examine. - Negative value counts position from the end of a string. + The position in <parameter>subject</parameter> to + start searching. </para> + <para> + If <parameter>start</parameter> is given and is non-negative, + then <function>strspn</function> will begin + examining <parameter>subject</parameter> at + the <parameter>start</parameter>'th position. For instance, in + the string '<literal>abcdef</literal>', the character at + position <literal>0</literal> is '<literal>a</literal>', the + character at position <literal>2</literal> is + '<literal>c</literal>', and so forth. + </para> + <para> + If <parameter>start</parameter> is given and is negative, + then <function>strspn</function> will begin + examining <parameter>subject</parameter> at + the <parameter>start</parameter>'th position from the end + of <parameter>subject</parameter>. + </para> </listitem> </varlistentry> <varlistentry> <term><parameter>length</parameter></term> <listitem> <para> - The length of the string to examine. - Negative value sets length from the end of a string. + The length of the segment from <parameter>subject</parameter> + to examine. </para> + <para> + If <parameter>length</parameter> is given and is non-negative, + then <parameter>subject</parameter> will be examined + for <parameter>length</parameter> characters after the starting + position. + </para> + <para> + If <parameter>length</parameter>is given and is negative, + then <parameter>subject</parameter> will be examined from the + starting position up to <parameter>length</parameter> + characters from the end of <parameter>subject</parameter>. + </para> </listitem> </varlistentry> </variablelist> @@ -117,7 +161,7 @@ <programlisting role="php"> <![CDATA[ <?php -echo strspn("foo", "o", 1, 2); // 2 +echo strspn("foo", "o", 1, 2); // prints: 2 ?> ]]> </programlisting>

« previous php.doc.cvs (#4964) next »