Latest web development tutorials

PHP strncasecmp () function

PHP String Reference PHP String Reference

Examples

Compares two strings (case insensitive):

<?php
echo strncasecmp("Hello world!","hello earth!",6);
?>

Running instance »

Definition and Usage

strncasecmp () function compares two strings (case insensitive).

Note: strncasecmp () is binary safe and is not case sensitive.

Tip: This function strcasecmp () function is similar, except that, strcasecmp () no length parameter.


grammar

strncasecmp( string1,string2,length )

参数 描述
string1 必需。规定要比较的第一个字符串。
string2 必需。规定要比较的第二个字符串。
length 必需。规定每个字符串用于比较的字符数。

technical details

return value: This function returns:
  • 0 - if the two strings are equal
  • <0 - if string1 is less than string2
  • > 0 - if string1 is greater than string2
PHP version: 4.0.2+


More examples

Example 1

Compares two strings (case-insensitive, Hello and hELLo output the same):

<?php
echo strncasecmp("Hello","Hello",6);
echo "<br>";
echo strncasecmp("Hello","hELLo",6);
?>

Running instance »


PHP String Reference PHP String Reference