Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP substr_compare() Function

PHP substr_compare() Function

PHP String Reference Manual PHP String Reference Manual

Example

Compare two strings:

Run Example »


Definition and Usage

The substr_compare() function compares two strings from a specified starting position.

**Tip:** This function is binary-safe and selectively case-sensitive.


Syntax

substr_compare(

string1,string2,startpos,length,case

)

Parameters Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to compare.
startpos Required. Specifies where in string1 to start the comparison. If negative, counting starts from the end of the string.
length Optional. Specifies the number of characters of string1 to compare.
case Optional. A boolean specifying whether to perform a case-sensitive comparison:
  • FALSE - Default. Case-sensitive
  • TRUE - Case-insensitive
  • |

    Technical Details

    | Return value: | This function returns:

    If length is greater than or equal to the length of string1, the function returns FALSE. | | --- | --- | | PHP version: | 5+ | | Changelog: | Since PHP 5.1, negative *startpos* is allowed. |

    More examples

    Example 1

    Compare two strings, with the start position used for comparison in string1 set to 6:

    Run Example »

    Example 2

    Using all parameters:

    Run Example »

    Example 3

    Different return values:

    Run Example »


    PHP String Reference Manual PHP String Reference Manual