/ LJCPHPCodeDoc / LJCCommonLib / LJCCommon / StrPos


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 $start = 0, bool $exact = false) : int

Gets the first index for the search value. (E)

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
 $webCommonPath = "c:/inetpub/wwwroot/LJCPHPCommon";
 require_once "$webCommonPath/LJCCommonLib.php";
 
 // $index = 5
 $index = LJCCommon::StrPos("This here.", "Here");
 
 // $index = -1
 $index = LJCCommon::StrPos("This here.", "Here", exact: true);

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