@@ 391-402 (lines=12) @@ | ||
388 | * @param int $n Number of characters to retrieve from the start |
|
389 | * @return Stringy Object with its $str being the first $n chars |
|
390 | */ |
|
391 | public function first($n) |
|
392 | { |
|
393 | $stringy = static::create($this->str, $this->encoding); |
|
394 | ||
395 | if ($n < 0) { |
|
396 | $stringy->str = ''; |
|
397 | } else { |
|
398 | return $stringy->substr(0, $n); |
|
399 | } |
|
400 | ||
401 | return $stringy; |
|
402 | } |
|
403 | ||
404 | /** |
|
405 | * Returns the encoding used by the Stringy object. |
|
@@ 641-652 (lines=12) @@ | ||
638 | * @param int $n Number of characters to retrieve from the end |
|
639 | * @return Stringy Object with its $str being the last $n chars |
|
640 | */ |
|
641 | public function last($n) |
|
642 | { |
|
643 | $stringy = static::create($this->str, $this->encoding); |
|
644 | ||
645 | if ($n <= 0) { |
|
646 | $stringy->str = ''; |
|
647 | } else { |
|
648 | return $stringy->substr(-$n); |
|
649 | } |
|
650 | ||
651 | return $stringy; |
|
652 | } |
|
653 | ||
654 | /** |
|
655 | * Returns the length of the string. An alias for PHP's mb_strlen() function. |