parseLines() public static method

Parse text by lines
public static parseLines ( string $text, boolean $toAssoc = true ) : array
$text string
$toAssoc boolean
return array
Beispiel #1
0
 public function testParseLines()
 {
     isSame(array('asd'), Str::parseLines('asd', false));
     isSame(array('asd' => 'asd'), Str::parseLines('asd', true));
     isSame(array('asd' => 'asd'), Str::parseLines('asd'));
     $lines = array('', false, 123, 456, ' 123   ', '      ', 'ASD', '0');
     isSame(array('123' => '123', '456' => '456', 'ASD' => 'ASD', '0' => '0'), Str::parseLines(implode("\r", $lines), true));
     isSame(array('123' => '123', '456' => '456', 'ASD' => 'ASD', '0' => '0'), Str::parseLines(implode("\n", $lines), true));
     isSame(array('123', '456', '123', 'ASD', '0'), Str::parseLines(implode("\r\n", $lines), false));
 }
Beispiel #2
0
 /**
  * Parse lines to assoc list
  *
  * @param $input
  * @return string
  */
 public static function parseLines($input)
 {
     if (is_array($input)) {
         $input = implode(PHP_EOL, $input);
     }
     return Str::parseLines($input, true);
 }