Monday 29 September 2014

strncasecmp in PHP

 PHP strncasecmp() function is  identical to strcmp() function ,except that lowercase and uppercase Versions of the same letter compare as equal.

The function returns :

0 –if the two strings are exactly equivalent
<0 – if smaller byte is found in the string1.
>0 – if smaller byte is found in the string2.
Syntax:

strncasecmp(string1,string2,length)
string1 : Required.Specifies the first string.

string2 : Required. Specifies the second string.

length : Required. Specify the number of characters to use in the comparison.

Tip: This function is binary safe and case-insensitive.

Example:

<?php
echo strncasecmp("good morning","Good Night",6);
?>
Output will be:
-1

0 comments:

Post a Comment