src/Cli.php
protected static function breakString($line, $width, $addSpaces = true) {
        $words = explode(' ', $line);
        $result = [];

        $line = '';
        foreach ($words as $word) {
            $candidate = trim($line.' '.$word);

            // Check for a new line.
            if (strlen($candidate) > $width) {
                if ($line === '') {
                    // The word is longer than a line.
                    if ($addSpaces) {
                        $result[] = substr($candidate, 0, $width);
                    } else {
                        $result[] = $candidate;
                    }
                } else {
                    if ($addSpaces) {
                        $line .= str_repeat(' ', $width - strlen($line));
                    }

                    // Start a new line.
                    $result[] = $line;
                    $line = $word;
                }
            } else {
                $line = $candidate;
            }
        }

        // Add the remaining line.
        if ($line) {
            if ($addSpaces) {
                $line .= str_repeat(' ', $width - strlen($line));
            }

            // Start a new line.
            $result[] = $line;
        }

        return $result;
    }
protected static function breakString($line, $width, $addSpaces = true) {
        $words = explode(' ', $line);
        $result = [];

        $line = '';
        foreach ($words as $word) {
            $candidate = trim($line.' '.$word);

            // Check for a new line.
            if (strlen($candidate) > $width) {
                if ($line === '') {
                    // The word is longer than a line.
                    if ($addSpaces) {
                        $result[] = substr($candidate, 0, $width);
                    } else {
                        $result[] = $candidate;
                    }
                } else {
                    if ($addSpaces) {
                        $line .= str_repeat(' ', $width - strlen($line));
                    }

                    // Start a new line.
                    $result[] = $line;
                    $line = $word;
                }
            } else {
                $line = $candidate;
            }
        }

        // Add the remaining line.
        if ($line) {
            if ($addSpaces) {
                $line .= str_repeat(' ', $width - strlen($line));
            }

            // Start a new line.
            $result[] = $line;
        }

        return $result;
    }
protected static function breakString ( $ line , $ width , $ addSpaces = true ) { $ words = explode ( ' ' , $ line ) ; $ result = [ ] ; $ line = '' ; foreach ( $ words as $ word ) { $ candidate = trim ( $ line . ' ' . $ word ) ; // Check for a new line. if ( strlen ( $ candidate ) > $ width ) { if ( $ line === '' ) { // The word is longer than a line. if ( $ addSpaces ) { $ result [ ] = substr ( $ candidate , 0 , $ width ) ; } else { $ result [ ] = $ candidate ; } } else { if ( $ addSpaces ) { $ line .= str_repeat ( ' ' , $ width - strlen ( $ line ) ) ; } // Start a new line. $ result [ ] = $ line ; $ line = $ word ; } } else { $ line = $ candidate ; } } // Add the remaining line. if ( $ line ) { if ( $ addSpaces ) { $ line .= str_repeat ( ' ' , $ width - strlen ( $ line ) ) ; } // Start a new line. $ result [ ] = $ line ; } return $ result ; }
Breaks a line of text according to a given width.

@param string $line The text of the line.
@param int $width The width of the cell.
@param bool $addSpaces Whether or not to right pad the lines with spaces.
@return array Returns an array of lines, broken on word boundaries.
Breaks a line of text according to a given width .