PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

strncmp> <strnatcmp
Last updated: Fri, 05 Sep 2008

view this page in

strncasecmp

(PHP 4 >= 4.0.2, PHP 5)

strncasecmpCompare en binaire des chaînes de caractères

Description

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

strncasecmp() est similaire à strcasecmp(), à la différence près qu'elle permet de limiter le nombre de caractères utilisés pour comparer str1 et str2 , avec le paramètre len .

Liste de paramètres

str1

La première chaîne.

str2

La seconde chaîne.

len

La longueur des chaînes à utiliser dans la comparaison.

Valeurs de retour

Retourne < 0 si str1 est plus petite que str2 ; > 0 si str1 est plus grande que str2 , et 0 si elles sont égales.



add a note add a note User Contributed Notes
strncasecmp
khootz
28-Nov-2006 05:23
i assume you can also use the ! (not) operator

<?php

if (!strncasecmp($string, 'Trudeau', 4)){
       print
"true";
}

?>

since booleans in PHP translate 0 to FALSE and any other integer to TRUE.

!0  = !false = true
!1  = !true = false
!-1 = !true = false
djdykes
31-Aug-2005 12:43
Hi all,

be aware when comparing strings using the strcmp family. if you write code like this...

if (strncasecmp($string, 'Trudeau', 4))
 print "true";

The above code returns 1 which evaluates to boolean 'true'

that statement will always be true... because these functions return 0 only when equal. so a better test would be

if ( (strncasecmp($string, 'Trudeau', 4)) == 0)
 print "true";

always test these functions equality with 0

regards

strncmp> <strnatcmp
Last updated: Fri, 05 Sep 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites