Gen. partnerAlgotech

PHP function substr_compare()

Binary safe comparison of 2 strings from offset up to character length

|
September 11, 2019

Availability in PHP 5.0

Binary safe comparison of 2 strings from offset up to character length

Parameters

Parameter Data type Default value Note
$main_str string not Main string being compared.
$str string not Main string being compared.
$offset int not Starting position for comparison. If negative, it starts counting from the end of the string.
$length int null, Length of the comparison.
$case_insensitivity bool null If case_insensitivity is true, the comparison is not case sensitive.

Return values

int

  • 0 if main_str of offset position is less than str
  • 0 if it is greater than str
  • 0 if they are equal.

If offset is equal to or greater than the length of main_str or the length is set and is less than 1, substr_compare prints a warning and returns false.

Additional resources

Official substr-compare documentation

Loading comments...

Stay in the loop

Subscribe to our newsletter and get the latest cybersecurity news delivered straight to your inbox.

Your data is safe. You can unsubscribe from the newsletter at any time.