Blog Details

how to compare string in php



                                

* PHP strncmp() Function :-

  • The strncmp() function compares two strings.
  • Note: The strncmp() is binary-safe and case-sensitive.
 

Syntax :

strncmp(string1,string2,length)  

string1

     Required. Specifies the first string to compare

string2

     Required. Specifies the second string to compare

length

     Required. Specify the number of characters from each string to be used in the comparison

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

Example :

<html> <body> <?php echo strncmp("Hello","Hello",6); echo "<br>"; echo strncmp("Hello","hELLo",6); ?> </body> </html>

Output :

0 -1


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote