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

search for in the

strncmp> <strnatcmp
[edit] Last updated: Fri, 17 May 2013

view this page in

strncasecmp

(PHP 4 >= 4.0.2, PHP 5)

strncasecmp Confronto sicuro con i testi binari, insensibile alle lettere maiuscole/minuscole sui primi n caratteri

Descrizione

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

Questa funzione è simile a strcasecmp(), con la differenza che si può indicare il numero dei caratteri (len) per ciascuna stringa che possono essere utilizzati per il confronto.

Restituisce < 0 if str1 se è minore di str2; > 0 se str1 è maggiore di str2, e 0 se sono uguali.

Vedere anche ereg(), strcasecmp(), strcmp(), substr(), stristr() e strstr().



add a note add a note User Contributed Notes strncasecmp - [2 notes]
up
0
khootz
6 years ago
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
up
0
djdykes
7 years ago
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

 
show source | credits | stats | sitemap | contact | advertising | mirror sites