static function getExcerpt(String $text, int $needlePosition, int $needleLength, int $contextLength) : string
    {
        $left = max($needlePosition - $contextLength, 0);
        $bufferLength = $needleLength + (2 * $contextLength);

        if($needleLength + $contextLength + $needlePosition > strlen($text)) {
            $text = substr($text, $left);
        } else {
            $text = substr($text, $left, $bufferLength);
        }

        return $text;
    }
static function getExcerpt(String $text, int $needlePosition, int $needleLength, int $contextLength) : string
    {
        $left = max($needlePosition - $contextLength, 0);
        $bufferLength = $needleLength + (2 * $contextLength);

        if($needleLength + $contextLength + $needlePosition > strlen($text)) {
            $text = substr($text, $left);
        } else {
            $text = substr($text, $left, $bufferLength);
        }

        return $text;
    }
static function getExcerpt ( String $ text , int $ needlePosition , int $ needleLength , int $ contextLength ) : string { $ left = max ( $ needlePosition - $ contextLength , 0 ) ; $ bufferLength = $ needleLength + ( 2 * $ contextLength ) ; if ( $ needleLength + $ contextLength + $ needlePosition > strlen ( $ text ) ) { $ text = substr ( $ text , $ left ) ; } else { $ text = substr ( $ text , $ left , $ bufferLength ) ; } return $ text ; }
Get a excerpt from a string by a neddle postion and its length

@param string $text
@param int $needlePosition
@param int $needleLength
@param int $contextLength
@return string
Get a excerpt from a string by a neddle postion and its length