PHP substr_compare() Function
Complete PHP String Reference
Definition and Usage
The substr_compare() function compares two strings from a specified start
position.
This function returns:
- 0 - if the two strings are equal
- <0 - if string1 (from startpos) is less than string2
- >0 - if string1 (from startpos) is greater than string2
If length is equal or greater than length of string1, this function returns
FALSE.
Syntax
substr_compare(string1,string2,startpos,length,case)
|
Parameter |
Description |
string1 |
Required. Specifies the first string to compare |
string2 |
Required. Specifies the second string to compare |
startpos |
Required. Specifies where to start comparing in
string1 |
length |
Optional. Specifies how much of string1 to compare |
case |
Optional. Specifies whether or not to perform a case-sensitive
compare.
Default is FALSE (case-sensitive) |
Tips and Notes
Tip: This function is binary safe and optionally case-sensitive.
Example 1
<?php
echo substr_compare("Hello world","Hello world",0);
?>
|
The output of the code above will be:
Example 2
<?php
echo substr_compare("Hello world","world",6);
?>
|
The output of the code above will be:
Example 3
<?php
echo substr_compare("Hello world","WORLD",6,TRUE);
?>
|
The output of the code above will be:
Complete PHP String Reference
Learn XML with <oXygen/> XML Editor - Free Trial!
|
|
oXygen helps you learn to define,
edit, validate and transform XML documents. Supported technologies include XML Schema,
DTD, Relax NG, XSLT, XPath, XQuery, CSS.
Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!
Do you have any XML related questions? Get free answers from the oXygen
XML forum
and from the video
demonstrations.
Download a FREE 30-day trial today!
|
|