PHP strncmp() Function


The strncasecmp() function is used to compare two given string. It is binary safe and case-insensitive.This is similar to the strncmp() function.

Syntax
strncmp(string1,string2,length)
Parameters
  • String1 - (Required) Specify the First string to compare.
  • String2 - (Required) Specify the second string to compare.
  • length - (Required) Specify the length of string to be used the comparision.
Example
<?php
    echo strcasecmp("Hii Hello!","HII HELLO!");
?>

Output

0
This Function returns 0 ,the two strings are equal.
Example
<?php
    echo strcasecmp("Hii Hello!","HI")."<br>"; 
    echo strcasecmp("Hii Hello!","HII HELLO! HOW ARE YOU ?"); 
?>

Output

8
-14

Prev Next