- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
substr_compare() function in PHP
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)."
"; ?>
Output
The following is the output −
0