php The strncmp function is used to compare two strings. Its syntax is strncmp(string1,string2,length). The parameter string1 is required and refers to the first string to be compared; string2 is required and refers to the second string to be compared. string.
php How to use strncmp function?
Definition and usage
strncmp() function compares two strings.
Note: strncmp() is binary safe and case-sensitive.
Tips: This function is similar to the strcmp() function, except that strcmp() does not have a length parameter.
Syntax
strncmp(string1,string2,length)
Parameters
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to be compared.
length Required. Specifies the number of characters of each string used in the comparison.
Return value:
This function returns:
0 - if the two strings are equal
>0 - if string1 is greater than string2
PHP version: 4
Example 1
Compare two String (case sensitive, China and CHINA output are different):
<?php echo strncmp("China","China",6); echo "<br>"; echo strncmp("China","CHINA",6); ?>
Output:
0 1
Example 2
Compare two strings (case sensitive):
<?php echo strncmp("I love China!","I love Shanghai!",6); ?>
Output:
0
The above is the detailed content of How to use php strncmp function?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
