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 StrPos(?string $text, ?string $find , int $startIndex = 0, bool $exact = false): int
|
Gets the first index for the search value.
Remarks
The integer -1 is returned if the search value is not found.
This alternative for PHP strpos() always returns an integer. It can be
simply tested for success $index >= 0 or failure $index < 0.
Example
| PHP |
// Gets the first index for the search value.
private static function StrPos()
{
$text = "This here.";
$find = "Here";
$index = LJC::StrPos($text, $find);
$result = strval($index);
// result:
// 5
$index = LJC::StrPos("This here.", "Here", exact: true);
$result = strval($index);
// result:
// -1
}
|
Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.