public function substr($string, $start, $length = null)
    {
        $string = (string)$string;

        if ($length === null) {
            $length = mb_strlen($string, 'UTF-8');
        }
        $length = max(0, $length);
        return mb_substr($string, $start, $length, 'UTF-8');
    }
public function substr($string, $start, $length = null)
    {
        $string = (string)$string;

        if ($length === null) {
            $length = mb_strlen($string, 'UTF-8');
        }
        $length = max(0, $length);
        return mb_substr($string, $start, $length, 'UTF-8');
    }
public function substr ( $ string , $ start , $ length = null ) { $ string = ( string ) $ string ; if ( $ length === null ) { $ length = mb_strlen ( $ string , 'UTF-8' ) ; } $ length = max ( 0 , $ length ) ; return mb_substr ( $ string , $ start , $ length , 'UTF-8' ) ; }
Return the characters in a string from start up to the given length

This implementation follows the JavaScript specification for "substr".

Examples::

String.substr('Hello, World!', 7, 5) == 'World'
String.substr('Hello, World!', 7) == 'World!'
String.substr('Hello, World!', -6) == 'World!'

@param string $string A string
@param integer $start Start offset
@param integer $length Maximum length of the substring that is returned
@return string The substring
Return the characters in a string from start up to the given length