CSSmin::str_slice PHP Method

str_slice() private method

PHP port of Javascript's "slice" function for strings only Author: Tubal Martin http://blog.margenn.com Tests: http://margenn.com/tubal/str_slice/
private str_slice ( string $str, integer $start, integer | boolean $end = FALSE ) : string
$str string
$start integer index
$end integer | boolean index (optional)
return string
    private function str_slice($str, $start = 0, $end = FALSE)
    {
        if ($end !== FALSE && ($start < 0 || $end <= 0)) {
            $max = strlen($str);
            if ($start < 0) {
                if (($start = $max + $start) < 0) {
                    return '';
                }
            }
            if ($end < 0) {
                if (($end = $max + $end) < 0) {
                    return '';
                }
            }
            if ($end <= $start) {
                return '';
            }
        }
        $slice = $end === FALSE ? substr($str, $start) : substr($str, $start, $end - $start);
        return $slice === FALSE ? '' : $slice;
    }