Change language

PHP Strncasecmp () Function

|
Syntax:
strncasecmp ($string1, $string2, $length)
Parameters:This function takes two parameter as shown in the above syntax and described below:
  • $string1, $string2:these parameters define the strings to compare.
  • $length:specifies the number of characters on each line to be used in the comparison. This parameter is required
Return value:This function returns an integer depending on the conditions described below:
  • strncasecmp ( ) returns 0 - if the two strings are equal.
  • strncasecmp() returns < 0 - if string1 is less than string2
  • strncasecmp() returns > 0 - if string1 is greater than string2
Examples:
Input: string1 = "Hello", string2 = "hEllo", length = 6 Output: 0 Input: string1 = "Geeks ", string2 =" Gfg ", length = 3 Output: -1 Input: string1 =" Nerd ", string2 =" Geeks ", length = 4 Output: 7
The programs below illustrate the strncasecmp() function in PHP:Program 1 : When two lines are identical: $str1 = "Geeks for Geeks" ; $str2 = "Geeks for Geeks " ;  
// Both lines are equal $test = strncasecmp ( $str1 , $str2 , 16); echo " $test " ;  
?>
Output:
0
Program 2 : When the first line is greater than the second line:
 
// Input lines $str1 = "Geeks for Geeks" ; $str2 = "Geeks for" ; $test = strncasecmp ( $str1 , $str2 , 16);  
// In this case, the second line is smaller echo "$test" ;  
?>
Output:
6
Program 3 : The first line is less than the second line:  
// Input lines $str1 = "Geeks for" ; $str2 = "Geeks for Geeks " ; $test = strncasecmp ( $str1 , $str2 , 16);  
// In this case, the first line is smaller echo "$test" ;  
?>
Output:
-6 
Program 4 : This program illustrates the case insensitivity of the function:  
// Input lines $str1 = " GEEKS FOR GEEKS " ; $str2 = "Geeks for Geeks " ;  
// Both lines are equal $test = strncasecmp ( $str1 , $str2 , 16); echo " $test " ;  
?>
Output:
0
Program 5 : two lines of the same length, but containing different characters. In this case, the difference between the ASCII values ​​of the two characters is displayed. The function returns a positive value if the character in line1 has a higher ASCII value, and negative if the character in line2 has a higher ASCII value.  
// Input lines $str1 = "Good" ; $str2 = "Goon" ; $test1 = strncasecmp ( $str1 , $str2 , 4);  
// The second line has a character
// with a higher ASCII value echo "$test1 " ; echo " " ; $test2 = strncasecmp ( $str2 , $str1 , 4);  
// The first line has a character
// with a higher ASCII value echo "$test2 " ;  
?>
Output:
-10 10
Link :
http://php.net/ manual / en / function.strncasecmp.php

PHP Strncasecmp () Function cmp: Questions

PHP Strncasecmp () Function PHP: Questions

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method