Showing posts with label PHP strncmp. Show all posts
Showing posts with label PHP strncmp. Show all posts

Monday, 29 September 2014

strncmp in PHP

PHP strncmp() function is utilized to compares two strings.
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:

strncmp(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-sensitive.

Example:

<?php
echo strncmp("Good Morning","Good night",5);
?>
Output will be:
0