classes/phing/util/StringHelper.php
public static function substring($string, $startpos, $endpos = -1)
    {
        $len = strlen($string);
        $endpos = (int) (($endpos === -1) ? $len - 1 : $endpos);
        if ($startpos > $len - 1 || $startpos < 0) {
            trigger_error("substring(), Startindex out of bounds must be 0<n<$len", E_USER_ERROR);
        }
        if ($endpos > $len - 1 || $endpos < $startpos) {
            trigger_error("substring(), Endindex out of bounds must be $startpos<n<" . ($len - 1), E_USER_ERROR);
        }
        if ($startpos === $endpos) {
            return (string) $string{$startpos};
        } else {
            $len = $endpos - $startpos;
        }

        return substr($string, $startpos, $len + 1);
    }
public static function substring($string, $startpos, $endpos = -1)
    {
        $len = strlen($string);
        $endpos = (int) (($endpos === -1) ? $len - 1 : $endpos);
        if ($startpos > $len - 1 || $startpos < 0) {
            trigger_error("substring(), Startindex out of bounds must be 0<n<$len", E_USER_ERROR);
        }
        if ($endpos > $len - 1 || $endpos < $startpos) {
            trigger_error("substring(), Endindex out of bounds must be $startpos<n<" . ($len - 1), E_USER_ERROR);
        }
        if ($startpos === $endpos) {
            return (string) $string{$startpos};
        } else {
            $len = $endpos - $startpos;
        }

        return substr($string, $startpos, $len + 1);
    }
public static function substring ( $ string , $ startpos , $ endpos = - 1 ) { $ len = strlen ( $ string ) ; $ endpos = ( int ) ( ( $ endpos === - 1 ) ? $ len - 1 : $ endpos ) ; if ( $ startpos > $ len - 1 || $ startpos < 0 ) { trigger_error ( "substring(), Startindex out of bounds must be 0<n<$len" , E_USER_ERROR ) ; } if ( $ endpos > $ len - 1 || $ endpos < $ startpos ) { trigger_error ( "substring(), Endindex out of bounds must be $startpos<n<" . ( $ len - 1 ) , E_USER_ERROR ) ; } if ( $ startpos === $ endpos ) { return ( string ) $ string { $ startpos } ; } else { $ len = $ endpos - $ startpos ; } return substr ( $ string , $ startpos , $ len + 1 ) ; }
a natural way of getting a subtring, php's circular string buffer and strange
return values suck if you want to program strict as of C or friends

@param string $string
@param int $startpos
@param int $endpos

@return string
a natural way of getting a subtring php s circular string buffer and strange return values suck if you want to program strict as of C or friends