@@ 491-502 (lines=12) @@ | ||
488 | * |
|
489 | * @return Stringy Object with its $str being the first $n chars |
|
490 | */ |
|
491 | public function first($n) |
|
492 | { |
|
493 | $stringy = static::create($this->str, $this->encoding); |
|
494 | ||
495 | if ($n < 0) { |
|
496 | $stringy->str = ''; |
|
497 | } else { |
|
498 | return $stringy->substr(0, $n); |
|
499 | } |
|
500 | ||
501 | return $stringy; |
|
502 | } |
|
503 | ||
504 | /** |
|
505 | * Returns the encoding used by the Stringy object. |
|
@@ 820-831 (lines=12) @@ | ||
817 | * |
|
818 | * @return Stringy Object with its $str being the last $n chars |
|
819 | */ |
|
820 | public function last($n) |
|
821 | { |
|
822 | $stringy = static::create($this->str, $this->encoding); |
|
823 | ||
824 | if ($n <= 0) { |
|
825 | $stringy->str = ''; |
|
826 | } else { |
|
827 | return $stringy->substr(-$n); |
|
828 | } |
|
829 | ||
830 | return $stringy; |
|
831 | } |
|
832 | ||
833 | /** |
|
834 | * Splits on newlines and carriage returns, returning an array of Stringy |