Funzione PHP Strncasecmp()

Sintassi:
strncasecmp ($string1, $string2, $length)
Parametri:Questa funzione accetta due parametri come mostrato nella sintassi sopra e descritto di seguito :
  • $string1, $string2:questi parametri definiscono le stringhe da confrontare.
  • $length:specifica il numero di caratteri su ogni riga da utilizzare nel confronto. Questo parametro è obbligatorio
Valore restituito:Questa funzione restituisce un numero intero a seconda delle condizioni descritte di seguito:
  • strncasecmp ( ) restituisce 0 - se le due stringhe sono uguali.
  • strncasecmp() restituisce < 0 - se string1 è minore di string2
  • strncasecmp() restituisce > 0 - se string1 è maggiore di string2
Esempi:
Input: string1 = "Hello", string2 = "hEllo", length = 6 Output: 0 Input: string1 = "Geeks ", string2 =" Gfg ", length = 3 Output: -1 Input: string1 =" Nerd ", string2 =" Geeks ", length = 4 Output: 7
I programmi seguenti illustrano la funzione strncasecmp() in PHP:Programma 1 : Quando due righe sono identiche: $str1 = "Geek per geek" ; $str2 = "Geeks for Geeks" ;
/ / Entrambe le righe sono uguali $test = strncasecmp ( $str1 , $str2 , 16); echo " $test " ;
?> Output:
0
Programma 2 : Quando la prima riga è maggiore della seconda riga:

// Righe di input $str1 = "Geek per Geek " ; $str2 = "Segnali per" ; $test = strncasecmp ( $str1 >, $str2 , 16);
// In questo caso, la seconda riga è più piccola eco "$test" ;
?>
Output:
6
Programma 3 : la prima riga è inferiore alla seconda riga:
// Righe di immissione $str1 = "Geek per" ; $str2 = "Geek per Geek" ; $test = strncasecmp ( $str1 >, $str2 , 16);
// In questo caso, la prima riga è più piccola eco "$test" ;
?>
Output:
-6 
Programma 4 : Questo programma illustra la distinzione tra maiuscole e minuscole della funzione:
// Righe di input $str1 = " GEEKS FOR GEEKS " ; $str2 = "Geek per Geek" ;
// Entrambe le righe sono uguali $test = strncasecmp ( $str1 , $str2 , 16); eco " $test " ;
?>
Output:
0
Programma 5 : due righe della stessa lunghezza, ma contenenti caratteri diversi. In questo caso viene visualizzata la differenza tra i valori ASCII dei due caratteri. La funzione restituisce un valore positivo se il carattere nella riga1 ha un valore ASCII maggiore e negativo se il carattere nella riga2 ha un valore ASCII maggiore.
// Righe di input $str1 = "Buono" ; $str2 = "Goon" ; $test1 = strncasecmp ( $str1 , $str2 , 4);
// La seconda riga ha un carattere
// con un valore ASCII maggiore echo "$test1 " ; echo " " ; $test2 = strncasecmp
( $str2 , $str1 , 4);
// La prima riga ha un carattere
// con un valore ASCII maggiore echo "$test2 " ;
?>
Output:
-10 10
Link :
http://php.net/ manual / en / function.strncasecmp.php

Ci auguriamo che questo articolo ti abbia aiutato a risolvere il problema. Oltre a Funzione PHP Strncasecmp(), controlla altri argomenti relativi a PHP.

Vuoi eccellere in Python? Consulta la nostra recensione dei migliori corsi online Python 2023. Se sei interessato alla scienza dei dati, controlla anche come imparare a programmare in R.

A proposito, questo materiale è disponibile anche in altre lingue:



Davies Jackson

San Francisco | 2023-03-26

Semplice e chiaro. Grazie per la condivisione. Il mio punto debole è sempre stato il Funzione PHP Strncasecmp() e altri problemi con il PHP 😁. Spero solo che non emerga più

Xu Robinson

Tallinn | 2023-03-26

Mi stavo preparando per il mio colloquio di codifica, grazie per aver chiarito questo punto - Funzione PHP Strncasecmp() in Python non è il più semplice. Spero solo che non emerga più

Ken Schteiner

Shanghai | 2023-03-26

Forse ci sono altre risposte? Cosa significa esattamente Funzione PHP Strncasecmp() significa esattamente?. Non sono proprio sicuro che sia il metodo migliore

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically