src/BitWeb/Stdlib/StringUtil.php
public static function stringLinesLimiter($string, $linesLimit, $removeEmptyLines = false, $stringLengthLimit = 189, $lineStringLengthLimit = 63)
    {
        $lines = explode(PHP_EOL, $string);
        if ($removeEmptyLines) {
            for ($i = 0; $i < count($lines); $i++) {
                $element = trim(self::replaceNewlines($lines[$i], ''));
                if ($element == '') {
                    unset($lines[$i]);
                }
            }
        }

        $stringLinesArray = array();
        $count = $linesLimit;
        $charactersLeft = $stringLengthLimit;

        foreach ($lines as &$line) {
            $line = self::replaceNewlines($line, '');
            if (strlen($line) >= ($count * $lineStringLengthLimit)) {
                $stringLinesArray[] = self::subString($line, $count * $lineStringLengthLimit);
                break;
            }
            $count = $count - 1;
            if (count($lines) > $linesLimit && $count < 1) {
                $stringLinesArray[] = $line . '...';
            } else {
                $stringLinesArray[] = $line;
            }
            if ($count < 1) {
                break;
            }
        }

        $string = implode(PHP_EOL, $stringLinesArray);

        return $string;
    }
public static function stringLinesLimiter($string, $linesLimit, $removeEmptyLines = false, $stringLengthLimit = 189, $lineStringLengthLimit = 63)
    {
        $lines = explode(PHP_EOL, $string);
        if ($removeEmptyLines) {
            for ($i = 0; $i < count($lines); $i++) {
                $element = trim(self::replaceNewlines($lines[$i], ''));
                if ($element == '') {
                    unset($lines[$i]);
                }
            }
        }

        $stringLinesArray = array();
        $count = $linesLimit;
        $charactersLeft = $stringLengthLimit;

        foreach ($lines as &$line) {
            $line = self::replaceNewlines($line, '');
            if (strlen($line) >= ($count * $lineStringLengthLimit)) {
                $stringLinesArray[] = self::subString($line, $count * $lineStringLengthLimit);
                break;
            }
            $count = $count - 1;
            if (count($lines) > $linesLimit && $count < 1) {
                $stringLinesArray[] = $line . '...';
            } else {
                $stringLinesArray[] = $line;
            }
            if ($count < 1) {
                break;
            }
        }

        $string = implode(PHP_EOL, $stringLinesArray);

        return $string;
    }
public static function stringLinesLimiter ( $ string , $ linesLimit , $ removeEmptyLines = false , $ stringLengthLimit = 189 , $ lineStringLengthLimit = 63 ) { $ lines = explode ( PHP_EOL , $ string ) ; if ( $ removeEmptyLines ) { for ( $ i = 0 ; $ i < count ( $ lines ) ; $ i ++ ) { $ element = trim ( self :: replaceNewlines ( $ lines [ $ i ] , '' ) ) ; if ( $ element == '' ) { unset ( $ lines [ $ i ] ) ; } } } $ stringLinesArray = array ( ) ; $ count = $ linesLimit ; $ charactersLeft = $ stringLengthLimit ; foreach ( $ lines as & $ line ) { $ line = self :: replaceNewlines ( $ line , '' ) ; if ( strlen ( $ line ) >= ( $ count * $ lineStringLengthLimit ) ) { $ stringLinesArray [ ] = self :: subString ( $ line , $ count * $ lineStringLengthLimit ) ; break ; } $ count = $ count - 1 ; if ( count ( $ lines ) > $ linesLimit && $ count < 1 ) { $ stringLinesArray [ ] = $ line . '...' ; } else { $ stringLinesArray [ ] = $ line ; } if ( $ count < 1 ) { break ; } } $ string = implode ( PHP_EOL , $ stringLinesArray ) ; return $ string ; }
Limits string to number of lines, adds "..." to the end

@param string $string
@param int $limit
Limits string to number of lines adds ... to the end