A WordPress-centric search engine for devs and theme authors



randomcompat_substr ›

Sincen/a
Deprecatedn/a
randomcompat_substr ( $binary_string, $start, $length = null )
Parameters: (3)
  • (string) $binary_string
    Required: Yes
  • (int) $start
    Required: Yes
  • (int) $length (optional)
    Required: No
    Default: null
Returns:
  • (string)
Defined at:
Codex:

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

This version just uses the default substr()



Source

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);
        }
    }
}