The substr_compare() function is used to compare two string format with a specific start position.
Syntax
substr_compare(str1,str2,offset,len,case_insensitive)
Parameters
str1 − The first string to compare
str2 − The second string to compare
offset − The start position for the comparison. If negative, the counting begins from the end of the string.
len − The length of the first string to compare
case_insensitive − If case_insensitivity is TRUE, comparison is case insensitive.
Return
The substr_compare() function returns −
0 - if the two strings are equal
<0 - if string1 (from offset) is less than string2
>0 - if string1 (from offset) is greater than string2
If length is equal or greater than length of string1, this function returns FALSE.
Example
The following is an example −
<?php echo substr_compare("pqrstrs", "qr", 1, 2); ?>
Output
The following is the output −
0
Example
Let us see another example −
<?php echo substr_compare("pqrstrs", "qr", 1, 3); ?>
Output
The following is the output −
1
Example
Let us see another example −
<?php echo substr_compare("Laptop", "AP", 1, 2, true)."\n"; ?>
Output
The following is the output −
0