You can use these two functions:
from shkspr.mobi
function mb_substr_replace($original, $replacement, $position, $length) { $startString = mb_substr($original, 0, $position, "UTF-8"); $endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8"); $out = $startString . $replacement . $endString; return $out; }
From github
function mb_substr_replace($str, $repl, $start, $length = null) { preg_match_all('/./us', $str, $ar); preg_match_all('/./us', $repl, $rar); $length = is_int($length) ? $length : utf8_strlen($str); array_splice($ar[0], $start, $length, $rar[0]); return implode($ar[0]); }
I tried both and both work well
source share