randomcompat_substr

函数


randomcompat_substr ( $binary_string, $start, $length = null )
参数
  • (string)
    $binary_string
    Required:
  • (int)
    $start
    Required:
  • (int|null)
    $length
    (optional)
    Required:
    Default: null
返回值
  • (string)
定义位置
  • wp-includes/random_compat/byte_safe_strings.php
    , line 161
引入
弃用

substr()的实现,不受mbstring.func_overload的影响。

这个版本只是使用默认的 substr()

function RandomCompat_substr($binary_string, $start, $length = null)
        {
            if (!is_string($binary_string)) {
                throw new TypeError(
                    'RandomCompat_substr(): First argument should be a string'
                );
            }

            if (!is_int($start)) {
                throw new TypeError(
                    'RandomCompat_substr(): Second argument should be an integer'
                );
            }

            if ($length !== null) {
                if (!is_int($length)) {
                    throw new TypeError(
                        'RandomCompat_substr(): Third argument should be an integer, or omitted'
                    );
                }

                return (string) substr(
                    (string )$binary_string,
                    (int) $start,
                    (int) $length
                );
            }

            return (string) substr(
                (string) $binary_string,
                (int) $start
            );
        }
    }
}