Skip to content

Commit 67bb299

Browse files
Allow defaulting end parameter to start value in findBetween
1 parent aa9adc8 commit 67bb299

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

framework/helpers/BaseStringHelper.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -529,17 +529,22 @@ public static function mask($string, $start, $length, $mask = '*') {
529529
}
530530

531531
/**
532-
* Returns the portion of the string that lies between the first occurrence of the start string
533-
* and the last occurrence of the end string after that.
532+
* Returns the portion of the string that lies between the first occurrence of the `$start` string
533+
* and the last occurrence of the `$end` string after that.
534534
*
535535
* @param string $string The input string.
536536
* @param string $start The string marking the start of the portion to extract.
537-
* @param string $end The string marking the end of the portion to extract.
537+
* @param string|null $end The string marking the end of the portion to extract.
538+
* If the `$end` string is not provided, it defaults to the value of the `$start` string.
538539
* @return string|null The portion of the string between the first occurrence of
539-
* start and the last occurrence of end, or null if either start or end cannot be found.
540+
* `$start` and the last occurrence of `$end`, or null if either `$start` or `$end` cannot be found.
540541
*/
541542
public static function findBetween($string, $start, $end)
542543
{
544+
if ($end === null) {
545+
$end = $start;
546+
}
547+
543548
$startPos = mb_strpos($string, $start);
544549

545550
if ($startPos === false) {

0 commit comments

Comments
 (0)