Core Function SubStrCount
From Sputnik Wiki
SubStrCount( <expression>, <expression2>, <offset>, <length>, <flag> )
Contents |
Description
Count the number of substring occurrences
Parameters
expression
The string to search in.
expression2
The substring to search for.
offset
Optional; The offset where to start counting.
count
Optional; The number of characters to extract. By default the entire remainder of the string.
length
Optional; The maximum length after the specified offset to search for the substring.
flag
Optional; The flag to set the case.
0 = Case insensitive (Default) 1 = Case sensitive
Return Value
Success: Returns number of occurrences.
Failure: Returns 0.
Remarks
None.
Example
$text = 'This is a test'; println( strlen($text) ); // 14 // the string is reduced to 't', so it prints 1 println( "1: " . SubstrCount($text, 't', 13, 1) ); // the string is reduced to 'This is a test', so it prints 2 println( "2: " . SubstrCount($text, 'is') ); // the string is reduced to 's is a test', so it prints 1 println( "1: " . SubstrCount($text, 'is', 3) ); // the text is reduced to 's i', so it prints 0 println( "O: " . SubstrCount($text, 'is', 3, 3) ); // the text is reduced to '', because 5+10 > 14, so it prints 0 println( "O: " . SubstrCount($text, 'is', 5, 10) ); // prints only 1, because it doesn't count overlapped substrings $text2 = 'gcdgcdgcd'; println( "1: " . SubstrCount($text2, 'gcdgcd') );