public function substring($string, $start, $end = null)
    {
        $string = (string)$string;

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

        if ($end === null) {
            $end = mb_strlen($string, 'UTF-8');
        }
        $start = max(0, $start);
        $end = max(0, $end);
        if ($start > $end) {
            $temp = $start;
            $start = $end;
            $end = $temp;
        }
        $length = $end - $start;
        return mb_substr($string, $start, $length, 'UTF-8');
    }
public function substring ( $ string , $ start , $ end = null ) { $ string = ( string ) $ string ; if ( $ end === null ) { $ end = mb_strlen ( $ string , 'UTF-8' ) ; } $ start = max ( 0 , $ start ) ; $ end = max ( 0 , $ end ) ; if ( $ start > $ end ) { $ temp = $ start ; $ start = $ end ; $ end = $ temp ; } $ length = $ end - $ start ; return mb_substr ( $ string , $ start , $ length , 'UTF-8' ) ; }
Return the characters in a string from a start index to an end index

This implementation follows the JavaScript specification for "substring".

Examples::

String.substring('Hello, World!', 7, 12) == 'World'
String.substring('Hello, World!', 7) == 'World!'

@param string $string
@param integer $start Start index
@param integer $end End index
@return string The substring
Return the characters in a string from a start index to an end index