HH\Lib\Str\splice_l
Return the string with a slice specified by the offset/length replaced by the given replacement string
namespace HH\Lib\Str;
function splice_l(
\HH\Lib\Locale\Locale $locale,
string $string,
string $replacement,
int $offset,
?int $length = NULL,
): string;
If the length is omitted or exceeds the upper bound of the string, the remainder of the string will be replaced. If the length is zero, the replacement will be inserted at the offset.
Offset can be positive or negative. When positive, replacement starts from the beginning of the string; when negative, replacement starts from the end of the string.
Some examples:
Str\splice_l($l, "apple", "orange", 0)without$length,$stringis replaced, resolving to"orange"Str\splice_l($l, "apple", "orange", 3)inserting at$offset3from the start of$stringresolves to"apporange"Str\splice_l($l, "apple", "orange", -2)inserting at$offset-2from the end of$stringresolves to"apporange"Str\splice_l($l, "apple", "orange", 0, 0)with$length0,$replacementis appended at$offset0and resolves to"orangeapple"Str\splice_l($l, "apple", "orange", 5, 0)with$length0,$replacementis appended at$offset5and resolves to"appleorange"
Guide
Parameters
\HH\Lib\Locale\Locale $localestring $stringstring $replacementint $offset?int $length = NULL
Returns
string
Examples
$locale = \HH\Lib\Locale\create("en_US.UTF-8");
$result = Str\splice_l($locale, "apple", "orange", 5, 0);
echo "Splice string with en_US.UTF-8: $result \n";