function AbstractString::beforeLast
Parameters
string|string[] $needle:
File
-
vendor/
symfony/ string/ AbstractString.php, line 197
Class
- AbstractString
- Represents a string of abstract characters.
Namespace
Symfony\Component\StringCode
public function beforeLast(string|iterable $needle, bool $includeNeedle = false, int $offset = 0) : static {
$str = clone $this;
$i = null;
if (\is_string($needle)) {
$needle = [
$needle,
];
}
foreach ($needle as $n) {
$n = (string) $n;
$j = $this->indexOfLast($n, $offset);
if (null !== $j && $j >= $i) {
$i = $offset = $j;
$str->string = $n;
}
}
if (null === $i) {
return $str;
}
if ($includeNeedle) {
$i += $str->length();
}
return $this->slice(0, $i);
}