XtScript Function: strrpos and strripos
XtScript strrpos and strripos is XtScript function that will search and return the position of the last occurrence of a matched substring.
The difference between strrpos and strripos is that strrpos will search the substring as CASE-SENSITIVE, while strripos as CASE-INSENSITIVE.
If you want the function to search and return the position of the first occurrence of a substring, you can use XtScript strpos and stripos function instead.
XtScript strrpos and strripos function basic syntax:
<!--parser:xtscript--> # Find the last occurrence of a case-sensitive substring and return the position call strrpos $haystack=...; $needle=...; $offset=... # Find the last occurrence of a case-insensitive substring and return the position call strripos $haystack=...; $needle=...; $offset=... <!--/parser:xtscript-->
Available arguments in XtScript strrpos and strripos function:
Argument | Value | Mandatory | Explanation |
---|---|---|---|
$haystack | string | Required | Specify the main string where the substring will be searched in. |
$needle | string | Required | Specify the substring that searched for. |
$offset | number | Optional | Specify the index of a character the search will be started from. Negative value will make the function work started from the number from the end of string, making it has backward behaviour. |
Learn XtScript strrpos and strripos function from examples
Search and return the position of the last occurrence of a case-sensitive substring using XtScript strrpos function.
- Code:<!--parser:xtscript--> var $string = Adam Jordan | Michael Jordan | Angela Jordan | michael Heissenberg var $fname = Jordan var $name = Michael print Names: $string <br/><br/> print "$fname" family name found on position: <b> call strrpos $haystack=$string; $needle=$fname print </b> <br/><br/> print "$name" found on position: <b> call strrpos $haystack=$string; $needle=$name print </b> <!--/parser:xtscript-->- Result:
"Jordan" family name found on position: 38
"Michael" found on position: 14
Search and return the position of the last occurrence of a case-insensitive substring using XtScript strripos function
- Code:<!--parser:xtscript--> var $string = Go Goes Going GOal var $srch = go print String: $string <br/><br/> print "$srch" found at position: <b> call strripos $haystack=$string; $needle=$srch; print </b> <br/><br/> print With \$offset=-5, "$srch" found at position: <b> call strripos $haystack=$string; $needle=$srch; $offset=-5 print </b> <!--/parser:xtscript-->- Result:
"go" found at position: 14
With $offset=-5, "go" found at position: 8