RandomCompat_substr

Advertisement

Summery Summery

substr() implementation that isn’t brittle to mbstring.func_overload

Syntax Syntax

RandomCompat_substr( string $binary_string, int $start, int $length = null )

Description Description

This version just uses the default substr()

Parameters Parameters

$binary_string

(string) (Required)

$start

(int) (Required)

$length

(int) (Optional) (optional)

Default value: null

Return Return

(string)

Source Source

File: wp-includes/random_compat/byte_safe_strings.php

        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($binary_string, $start, $length);
            }

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

Advertisement

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.