/ LJCPHPCodeDoc / LJCCommonLib / LJC / StrRPos


Parameters
$text - The text to be searched.
$find - The search value.
$start - The search start index.
$exact - Indicates if a case sensitive search is performed.

Returns

The integer index value.

Syntax

PHP
public static function StrRPos(?string $text, ?string $find, int $startIndex = 0
, bool $exact = false): int

Gets the last index for the search value.

Remarks

The integer -1 is returned if the search value is not found. It can be simply tested for success $index >= 0 or failure $index < 0.

This alternative for PHP strrpos() always returns an integer.

Example

PHP
 // Gets the last index for the search value.
 private static function StrRPos()
 {
   $text = "This here is here.";
   $find = "Here";
   $index = LJC::StrRPos($text, $find);
   $result = strval($index);
 
   // result:
   // 13
 
   $index = LJC::StrPos("This here.", "Here", exact: true);
   $result = strval($index);
 
   // result:
   // -1
 }

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.