return join('', $result); } else { $matchIndex = strpos($str, $search); if ($matchIndex === false) { return $str; } $before = substr($str, 0, $matchIndex); $after = substr($str, $matchIndex + strlen($search)); //mb_strlen used to calculate multi-byte character index $args = array($search, mb_strlen($before), $str); return $before . to_string($replace->apply(null, $args)) . $after; } } $replace = to_string($replace); if ($isRegEx) { $replace = RegExp::toReplacementString($replace); return preg_replace($search, $replace, $str, $limit); } else { $parts = explode($search, $str); $first = array_shift($parts); return $first . $replace . implode($search, $parts); } }, 'toLowerCase' => function () { $self = Func::getContext(); return mb_strtolower($self->value); }, 'toLocaleLowerCase' => function () { $self = Func::getContext(); return mb_strtolower($self->value); }, 'toUpperCase' => function () { $self = Func::getContext(); return mb_strtoupper($self->value);