Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,10 +1748,12 @@ public static function substrCount($haystack, $needle, $offset = 0, $length = nu
public static function substrReplace($string, $replace, $offset = 0, $length = null)
{
if ($length === null) {
$length = strlen($string);
$length = static::length($string);
}

return substr_replace($string, $replace, $offset, $length);
return mb_substr($string, 0, $offset)
.$replace
.mb_substr($string, $offset + $length);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,12 @@ public function testSubstrReplace()
$this->assertSame('Laravel – The PHP Framework for Web Artisans', Str::substrReplace('Laravel Framework', '– The PHP Framework for Web Artisans', 8));
}

public function testSubstrReplaceWithMultibyte()
{
$this->assertSame('kengä', Str::substrReplace('kenkä', 'ng', -3, 2));
$this->assertSame('kenga', Str::substrReplace('kenka', 'ng', -3, 2));
}

public function testTake()
{
$this->assertSame('ab', Str::take('abcdef', 2));
Expand Down
Loading