Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

strncasecmp

(PHP 4 >= 4.0.2, PHP 5)

strncasecmp --  Сравнение первых n символов строк без учета регистра, безопасное для данных в двоичной форме

Описание

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

Эта функция подобна strcasecmp(), за исключением того, что можно указать максимальное количество символов в обоих строках, которые будут участвовать в сравнении.

Возвращает отрицательное число, если str1 меньше, чем str2; положительное число, если str1 больше, чем str2, и 0 если строки равны.

См. также описание функций ereg(), strcasecmp(), strcmp(), substr(), stristr() и strstr().



add a note add a note User Contributed Notes
strncasecmp
khootz
27-Nov-2006 08: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 03: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, 26 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571