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

search for in the

strncmp> <strnatcmp
Last updated: Fri, 24 Jul 2009

view this page in

strncasecmp

(PHP 4 >= 4.0.2, PHP 5)

strncasecmp대소문자 구분 없는 처음 n 문자의 바이너리 안전 문자열 비교

설명

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

비교에 사용하는 각 문자열에 (최대 제한) 비교할 문자 수를 지정할 수 있는 차이를 제외하면, strcasecmp()와 동일합니다.

인수

str1

첫번째 문자열.

str2

두번째 문자열.

len

비교에 사용할 문자열의 길이.

반환값

str1str2 보다 작으면 < 0을; str1str2 보다 크면 > 0을, 같으면 0을 반환합니다.

참고

  • preg_match() - 정규표현식 매치를 수행
  • strcmp() - 바이너리 안전 문자열 비교
  • strcasecmp() - 대소문자 구분 없는 바이너리 안전 문자열 비교
  • substr() - Return part of a string
  • stristr() - 대소문자를 구분하지 않는 strstr
  • strstr() - 문자열이 처음으로 나오는 부분을 찾습니다



add a note add a note User Contributed Notes
strncasecmp
khootz
28-Nov-2006 04: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 10: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, 24 Jul 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites