Disneyland 1972 Love the old s
/ /

XtScript Function: strstr and stristr

Return a part of haystack after the first occurence of a needle found.

strstr is an XtScript function to return a part of string started from the certain first occurrence of the case-sensitive substring passed in the needle argument found.

If you want the function to treat the substring passed in the needle argument as case-insensitive, you can use XtScript stristr function instead.

XtScript strstr and stristr function basic syntax:

<!--parser:xtscript-->
	# Return a part of the haystack from the case-sensitive needle
	call strstr $haystack=...; $needle=...; $before_needle=...

	# Return a part of the haystack from the case-insensitive needle
	call stristr $haystack=...; $needle=...; $before_needle=...
<!--/parser:xtscript-->

Available arguments in XtScript strstr and stristr function:

List of arguments in XtScript strstr and stristr function
ArgumentsValueMandatoryExplanation
$haystackstringRequiredSpecify the main string.
$needlestringRequiredSpecify the substring where a part of the main string will be returned started from.
$before_needle0 (false) or 1 (true)OptionalSpecify which part of the main string will be returned after the substring ($needle) found, after or before the needle. If this argument is not passed, then the default value will be 0.

Learn XtScript strstr and stristr function from examples

Return a part of the string from after the first occurrence case-sensitive needle found, needle included.

- Code:
<!--parser:xtscript-->
	var $string = XtScript and xtgem is an XTreme combination!
	var $ne = xt

	var $partial = call strstr $haystack=$string; $needle=$ne; $before_needle=0

	print String: $string <br/>
	print Partial: $partial
<!--/parser:xtscript-->
- Result:
String: XtScript and xtgem is an XTreme combination!
Partial: xtgem is an XTreme combination!

Return a part of the string from before the first occurrence case-insensitive needle found, needle excluded.

- Code:
<!--parser:xtscript-->
	# Assigning space into variable using chr function so we can use space as the last character in print
	var $spa = call chr $val=32

	var $string = Whether it is Xtscipt code or PHP CODE, all Code are fun to learn!

	print String: $string <br/>
	print Partial:$spa
	call stristr $haystack=$string; $needle=CoDe; $before_needle=1
<!--/parser:xtscript-->
- Result:
String: Whether it is Xtscipt code or PHP CODE, all Code are fun to learn!
Partial: Whether it is Xtscipt