English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strncmp() Function Usage and Example

PHP String Character String Function Manual

The strncmp() function is used for binary-safe comparison of the first few characters of strings (case sensitive).

Syntax

int strncmp ( string $str1 , string $str2 , int $len )

Definition and Usage

Used to compare the first len characters.

Return Value

 If str1 Less than str2 Returns < 0; if str1 Greater than str2 Returns > 0; if they are equal, return 0.

Parameter

Serial NumberParameters and Description
1

string1

First String

2

string2

Second String

3

len

Maximum Comparison Length

Online Example

Try the following example to compare two strings (case sensitive):

<?php
   //strncmp function compares two strings (case sensitive)
   echo strncmp("input","input",6);
   echo "<br>";
   
   echo strncmp("input","iMPut",6);
?>
Test and see‹/›

Output Result

0
8448

PHP String Character String Function Manual