Home » PHP strcasecmp() function

PHP strcasecmp() function

by Online Tutorials Library

PHP string strcasecmp() function

PHP string strcasecmp() is predefine function. It is used to compare two given string. It is binary safe and case-insensitive. It is similar to the strncasecmp() function.

It returns:

  • If the two strings are equal: [ 0 ]
  • If string1 is less than string2: [< 0]
  • If string1 is greater than string2: > 0

Syntax:

Parameter Description Required/Optional
string 1 Specify first string to compare. Required.
String2 Specify the second string to compare. Reuired.

Example 1

Output:

Your first string is:TutorASPIRE  Your second string is:TUTORaspire  0  

Example 2

Output:

By using strcasecmp() function:0  using strcasecmp() function:0  

Example 3

Output:

-75  -7  

Example 4

Output:

$str is equal to $vstr2 in a case-insensitive string comparison  

Reference:

http://php.net/manual/en/function.strcasecmp.php

Next TopicPHP String

You may also like