strncasecmp

(PHP 4 >= 4.0.2, PHP 5, PHP 7)

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 2 notes

up
-6
sazalach at gmail dot com
8 years ago
<?php
$str1
= "red";
$str2 = "redent";
$test=strncasecmp($str1, $str2 , 3);
if (
$str1==$str2)
{
echo
"$test";
}
else
{
echo
"$test" ;
}
?>

if we run the above script then we will get return 0, because first string $str1 = "red" and second $str2 = "redent" but in comparison i have set the first three character will try to match. as per condition if two string are equal then it will return 0. But in below example it will return greater than 0 because here is str1 is greater than str2.

<?php
$str1
= "redmyshirt";
$str2 = "redent";
$test=strncasecmp($str1, $str2 , 4);
if (
$str1==$str2)
{
echo
"$test";
}
else
{
echo
"$test" ;
}
?>

as same if we run the below script it will return -1 because str1 is less than str2.

<?php
$str1
= "red";
$str2 = "redent";
$test=strncasecmp($str1, $str2 , 4);
if (
$str1==$str2)
{
echo
"$test";
}
else
{
echo
"$test" ;
}
?>

ya..i think its easy to understand
up
-46
saikumar dot msc at gmail dot com
9 years ago
Example:
<?php
$string
= “true”;
if(
strncasecmp($string, “Trudeau”, 4)) { print “True”; } else { print "False" }
?>

If we look at above example, immediately we will say the final output will be 'False', but that's not real.

Method "strncasecmp()" returns 1 because the first four characters of ‘Trud’ come before the first four characters of "true" when sorted not case sensitively.
To Top