选择语言 :

 Core_UTF8::substr_replace

Replaces text within a portion of a UTF-8 string. This is a UTF8-aware version of substr_replace.

$str = UTF8::substr_replace($str, $replacement, $offset);

string Core_UTF8::substr_replace( string $str , string $replacement , integer $offset [, $length = null ] )
author
Harry Fuecks hfuecks@gmail.com

参数列表

参数 类型 描述 默认值
$str string Input string
$replacement string Replacement string
$offset integer Offset
$length unknown null
返回值
  • string
File: ./core/classes/utf8.class.php
public static function substr_replace($str, $replacement, $offset, $length = null)
{
    if ( UTF8::is_ascii($str) ) return ($length === null) ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length);

    $length = ($length === null) ? UTF8::strlen($str) : (int)$length;
    preg_match_all('/./us', $str, $str_array);
    preg_match_all('/./us', $replacement, $replacement_array);

    array_splice($str_array[0], $offset, $length, $replacement_array[0]);
    return implode('', $str_array[0]);
}