[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-cvs
Subject:    [DOC-CVS] =?utf-8?q?svn:_/phpdoc/en/trunk/reference/strings/functions/_strripos.xml_strrpos.xml?=
From:       George_Peter_Banyard <girgias () php ! net>
Date:       2019-04-23 0:51:32
Message-ID: svn-girgias-1555980692-347318-1426465873 () svn ! php ! net
[Download RAW message or body]

girgias                                  Tue, 23 Apr 2019 00:51:32 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=347318

Log:
Fix Doc Bug #73913

A better description of how the offset parameter works (especially with negative offsets)
Added some examples to illustrate how offset affects the function.

Maybe an example that compares this to strpos should be there too?

------
Inspired by anonymous 96388 (php.florianberberich@outlook.com)

Bug: https://bugs.php.net/73913 (Assigned) broken strrpos with negative offset
      
Changed paths:
    U   phpdoc/en/trunk/reference/strings/functions/strripos.xml
    U   phpdoc/en/trunk/reference/strings/functions/strrpos.xml

Modified: phpdoc/en/trunk/reference/strings/functions/strripos.xml
===================================================================
--- phpdoc/en/trunk/reference/strings/functions/strripos.xml	2019-04-22 22:23:12 UTC (rev 347317)
+++ phpdoc/en/trunk/reference/strings/functions/strripos.xml	2019-04-23 00:51:32 UTC (rev 347318)
@@ -45,10 +45,23 @@
     <varlistentry>
      <term><parameter>offset</parameter></term>
      <listitem>
+      <para>
+       If zero or positive, the search is performed left to right skipping the
+       first <parameter>offset</parameter> bytes of the
+       <parameter>haystack</parameter>.
+      </para>
       <para>
-       If specified, search will start this number of characters counted from the
-       beginning of the string. If the value is negative, search will instead start
-       from that many characters from the end of the string, searching backwards.
+       If negative, the search is performed right to left skipping the
+       last <parameter>offset</parameter> bytes of the
+       <parameter>haystack</parameter> and searching for the first occurrence
+       of <parameter>needle</parameter>.
+       <note>
+        <para>
+         This is effectively looking for the last occurrence of
+         <parameter>needle</parameter> before the last
+         <parameter>offset</parameter> bytes.
+        </para>
+       </note>
       </para>
      </listitem>
     </varlistentry>
@@ -62,7 +75,11 @@
    Returns the position where the needle exists relative to the beginnning of
    the <parameter>haystack</parameter> string (independent of search direction
    or offset).
-   Also note that string positions start at 0, and not 1.
+   <note>
+    <simpara>
+     String positions start at 0, and not 1.
+    </simpara>
+   </note>
   </para>
   <para>
    Returns &false; if the needle was not found.

Modified: phpdoc/en/trunk/reference/strings/functions/strrpos.xml
===================================================================
--- phpdoc/en/trunk/reference/strings/functions/strrpos.xml	2019-04-22 22:23:12 UTC (rev 347317)
+++ phpdoc/en/trunk/reference/strings/functions/strrpos.xml	2019-04-23 00:51:32 UTC (rev 347318)
@@ -41,10 +41,23 @@
     <varlistentry>
      <term><parameter>offset</parameter></term>
      <listitem>
+      <para>
+       If zero or positive, the search is performed left to right skipping the
+       first <parameter>offset</parameter> bytes of the
+       <parameter>haystack</parameter>.
+      </para>
       <para>
-       If specified, search will start this number of characters counted from the
-       beginning of the string. If the value is negative, search will instead start
-       from that many characters from the end of the string, searching backwards.
+       If negative, the search is performed right to left skipping the
+       last <parameter>offset</parameter> bytes of the
+       <parameter>haystack</parameter> and searching for the first occurrence
+       of <parameter>needle</parameter>.
+       <note>
+        <para>
+         This is effectively looking for the last occurrence of
+         <parameter>needle</parameter> before the last
+         <parameter>offset</parameter> bytes.
+        </para>
+       </note>
       </para>
      </listitem>
     </varlistentry>
@@ -58,7 +71,11 @@
    Returns the position where the needle exists relative to the beginning of
    the <parameter>haystack</parameter> string (independent of search direction
    or offset).
-   Also note that string positions start at 0, and not 1.
+   <note>
+    <simpara>
+     String positions start at 0, and not 1.
+    </simpara>
+   </note>
   </para>
   <para>
    Returns &false; if the needle was not found.
@@ -123,16 +140,41 @@
 <?php
 $foo = "0123456789a123456789b123456789c";

-var_dump(strrpos($foo, '7', -5));  // Starts looking backwards five positions
-                                   // from the end. Result: int(17)
+// Looking for '0' from the 0th byte (from the beginning)
+var_dump(strrpos($foo, '0', 0));

-var_dump(strrpos($foo, '7', 20));  // Starts searching 20 positions into the
-                                   // string. Result: int(27)
+// Looking for '0' from the 1st byte (after byte "0")
+var_dump(strrpos($foo, '0', 1));

-var_dump(strrpos($foo, '7', 28));  // Result: bool(false)
+// Looking for '7' from the 21th byte (after byte 20)
+var_dump(strrpos($foo, '7', 20));
+
+// Looking for '7' from the 29th byte (after byte 28)
+var_dump(strrpos($foo, '7', 28));
+
+// Looking for '7' right to left from the 5th byte from the end
+var_dump(strrpos($foo, '7', -5));
+
+// Looking for 'c' right to left from the 2nd byte from the end
+var_dump(strrpos($foo, 'c', -2));
+
+// Looking for '9c' right to left from the 2nd byte from the end
+var_dump(strrpos($foo, '9c', -2));
 ?>
 ]]>
     </programlisting>
+   &example.outputs;
+   <screen>
+<![CDATA[
+int(0)
+bool(false)
+int(27)
+bool(false)
+int(17)
+bool(false)
+int(29)
+]]>
+   </screen>
    </example>
   </para>
  </refsect1>



-- 
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic