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

From: Date: Sat, 19 Dec 2009 11:01:06 +0000
Subject: svn: /phpdoc/en/trunk/reference/strings/functions/ strrpos.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-5686@lists.php.net to get a copy of this message
degeberg Sat, 19 Dec 2009 11:01:06 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=292326 Log: Fixed #50317. Bug: http://bugs.php.net/50317 (Open) strrpos offset behavior is opposite of what docs describe Changed paths: U phpdoc/en/trunk/reference/strings/functions/strrpos.xml Modified: phpdoc/en/trunk/reference/strings/functions/strrpos.xml =================================================================== --- phpdoc/en/trunk/reference/strings/functions/strrpos.xml 2009-12-19 10:59:29 UTC (rev 292325) +++ phpdoc/en/trunk/reference/strings/functions/strrpos.xml 2009-12-19 11:01:06 UTC (rev 292326) @@ -22,52 +22,6 @@ as the needle, then only the first character of that string will be used. </para> - <para> - If <parameter>needle</parameter> is not found, returns &false;. - </para> - <para> - It is easy to mistake the return values for "character found at - position 0" and "character not found". Here's how to detect - the difference: - <informalexample> - <programlisting role="php"> -<![CDATA[ -<?php - -// in PHP 4.0.0 and newer: -$pos = strrpos($mystring, "b"); -if ($pos === false) { // note: three equal signs - // not found... -} - -// in versions older than 4.0.0: -$pos = strrpos($mystring, "b"); -if (is_bool($pos) && !$pos) { - // not found... -} -?> -]]> - </programlisting> - </informalexample> - </para> - <para> - If <parameter>needle</parameter> is not a string, it is converted - to an integer and applied as the ordinal value of a character. - </para> - <note> - <simpara> - As of PHP 5.0.0 <parameter>offset</parameter> may - be specified to begin searching an arbitrary number of characters into - the string. Negative values will stop searching at an arbitrary point - prior to the end of the string. - </simpara> - </note> - <note> - <simpara> - The <parameter>needle</parameter> may be a string of more than one - character as of PHP 5.0.0. - </simpara> - </note> </refsect1> <refsect1 role="parameters"> @@ -78,6 +32,7 @@ <term><parameter>haystack</parameter></term> <listitem> <para> + The string to search in. </para> </listitem> </varlistentry> @@ -85,6 +40,8 @@ <term><parameter>needle</parameter></term> <listitem> <para> + If <parameter>needle</parameter> is not a string, it is converted + to an integer and applied as the ordinal value of a character. </para> </listitem> </varlistentry> @@ -92,6 +49,9 @@ <term><parameter>offset</parameter></term> <listitem> <para> + May be specified to begin searching an arbitrary number of characters into + the string. Negative values will stop searching at an arbitrary point + prior to the end of the string. </para> </listitem> </varlistentry> @@ -102,10 +62,94 @@ <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> - + Returns the position where the needle exists. Returns &false; if the needle + was not found. </para> </refsect1> + + <refsect1 role="changelog"> + &reftitle.changelog; + <para> + <informaltable> + <tgroup cols="2"> + <thead> + <row> + <entry>&Version;</entry> + <entry>&Description;</entry> + </row> + </thead> + <tbody> + <row> + <entry>5.0.0</entry> + <entry> + The <parameter>needle</parameter> may now be a string of more than one + character. + </entry> + </row> + <row> + <entry>5.0.0</entry> + <entry> + The <parameter>offset</parameter> parameter was introduced. + </entry> + </row> + </tbody> + </tgroup> + </informaltable> + </para> + </refsect1> + + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Checking if a needle is in the haystack</title> + <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: + </para> + <programlisting role="php"> +<![CDATA[ +<?php +// in PHP 4.0.0 and newer: +$pos = strrpos($mystring, "b"); +if ($pos === false) { // note: three equal signs + // not found... +} + +// in versions older than 4.0.0: +$pos = strrpos($mystring, "b"); +if (is_bool($pos) && !$pos) { + // not found... +} +?> +]]> + </programlisting> + </example> + </para> + <para> + <example> + <title>Searching with offsets</title> + <programlisting role="php"> +<![CDATA[ +<?php +$foo = "0123456789a123456789b123456789c"; + +var_dump(strrpos($foo, '7', -5)); // Starts looking backwards five positions + // from the end. Result: int(17) + +var_dump(strrpos($foo, '7', 20)); // Starts searching 20 positions into the + // string. Result: int(27) + +var_dump(strrpos($foo, '7', 28)); // Result: bool(false) +?> +]]> + </programlisting> + </example> + </para> + </refsect1> + <refsect1 role="seealso"> &reftitle.seealso; <para>

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