strcmp and strcasecmp

strcmp and strcasecmp

strcmp and strcasecmp functions are used to compare strings.

Both function
1.returns <0 if argument1 is less than argument2
2.returns >0 if argument1 is greater than argument2
3.returns 0 if argument1 is equal to argument2

strcmp comparision - case sensitive comparision
strcasecmp - case-insensitive comparision.

Example

$var1 = “Test”;
$var2 = “test”;

if (strcasecmp($var1, $var2) == 0) {
echo ‘Equal’;
}else{
echo ‘Not Equal’;
}

if (strcmp($var1, $var2) == 0) {
echo ‘Equal’;
}else{
echo ‘Not Equal’;
}

strcasecmp($var1, $var2) return 0
strcmp($var1, $var2) return

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.