PHP strncmp() Function
Complete PHP String Reference
Definition and Usage
The strncmp() function compares two strings.
This function returns:
- 0 - if the two strings are equal
- <0 - if string1 is less than string2
- >0 - if string1 is greater than string2
Syntax
|
strncmp(string1,string2,length)
|
| Parameter |
Description |
| string1 |
Required. Specifies the first string to compare |
| string2 |
Required. Specifies the second string to compare |
| length |
Required. Specify the number of characters from each string
to be used in the comparison |
Tips and Notes
Note: The strncmp() is binary safe and case-sensitive.
Example
<?php
echo strncmp("Hello world!","Hello earth!",6);
?>
|
The output of the code above will be:
Complete PHP String Reference

The Altova MissionKit is an integrated suite of tools ideal for:
- XML development
- Web & Web services development
- Data mapping & integration
- Rendering & publishing XML & database data
- XBRL validation, taxonomy editing, transformation & rendering
The MissionKit for XML Developers includes XMLSpy® - the industry-leading XML editor; MapForce® - a
graphical data mapping, conversion, and integration tool; StyleVision® - a visual XSLT stylesheet designer;
DiffDog® - an XML-aware diff/merge tool; and 2 additional tools.
Try all 6 products free for 30 days!
Download a fully-functional free trial
|
|
|
|