Example #1
0
 /**
  * Create a new Multiline object from a string.
  *
  * First the input string is split into lines by the detected end-of-line
  * character. Afterwards any extra EOL chars will be trimmed.
  *
  * @see \nochso\Omni\EOL
  *
  * @param string $input      A string to split into a Multiline object
  * @param string $defaultEol Default end-of-line type to split the input by. This is a fallback in case it could
  *                           not be detected from the input string. Optional, defaults to `EOL::EOL_LF` i.e. "\n".
  *                           See the `EOL::EOL_*` class constants.
  *
  * @return \nochso\Omni\Multiline
  */
 public static function create($input, $defaultEol = \nochso\Omni\EOL::EOL_LF)
 {
     $eol = EOL::detectDefault($input, $defaultEol);
     $lines = explode($eol, $input);
     $multiline = new self($lines);
     // Remove left-over line feeds
     $multiline->apply(function ($line) {
         return trim($line, "\r\n");
     });
     $multiline->setEol($eol);
     return $multiline;
 }