| @@ 622-633 (lines=12) @@ | ||
| 619 | * |
|
| 620 | * @return static Object with its $str being the first $n chars |
|
| 621 | */ |
|
| 622 | public function first($n) |
|
| 623 | { |
|
| 624 | $stringy = static::create($this->str, $this->encoding); |
|
| 625 | ||
| 626 | if ($n < 0) { |
|
| 627 | $stringy->str = ''; |
|
| 628 | } else { |
|
| 629 | return $stringy->substr(0, $n); |
|
| 630 | } |
|
| 631 | ||
| 632 | return $stringy; |
|
| 633 | } |
|
| 634 | ||
| 635 | /** |
|
| 636 | * Returns the encoding used by the Stringy object. |
|
| @@ 1026-1037 (lines=12) @@ | ||
| 1023 | * |
|
| 1024 | * @return static Object with its $str being the last $n chars |
|
| 1025 | */ |
|
| 1026 | public function last($n) |
|
| 1027 | { |
|
| 1028 | $stringy = static::create($this->str, $this->encoding); |
|
| 1029 | ||
| 1030 | if ($n <= 0) { |
|
| 1031 | $stringy->str = ''; |
|
| 1032 | } else { |
|
| 1033 | return $stringy->substr(-$n); |
|
| 1034 | } |
|
| 1035 | ||
| 1036 | return $stringy; |
|
| 1037 | } |
|
| 1038 | ||
| 1039 | /** |
|
| 1040 | * Splits on newlines and carriage returns, returning an array of Stringy |
|