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