Sha256: 9580ea12857d686a06701b638fdc1d8ce5182fb6101546b7dd9fc9eb5b644a45
Contents?: true
Size: 1.07 KB
Versions: 11
Compression:
Stored size: 1.07 KB
Contents
<?php class AbcStr{ public $str = ''; public $originalStr = ''; public static $wordLimit = 50; public static $charLimit = 300; public function __construct($str) { $this->str = $str; $this->originalStr = $str; } public static function get($str){ return new self($str); } public function limitWords($wordLimit = null, $overflowIndicator = '...') { if (!$wordLimit) $wordLimit = self::$wordLimit; $words = explode(" ",$this->str); $this->str = implode(" ",array_splice($words,0,$wordLimit)).$overflowIndicator; return $this; } public function limitChars($charLimit = null, $overflowIndicator = '...') { if (!$charLimit) $charLimit = self::$charLimit; if (strlen($this->str) <= $charLimit) return $this; $effectiveLimit = $charLimit - strlen($overflowIndicator); $this->str = substr($this->str, 0, $effectiveLimit).$overflowIndicator; return $this; } public function limitCharsNoDotDot($charLimit = null) { $this->limitChars($charLimit = null, $overflowIndicator = ''); return $this; } }
Version data entries
11 entries across 11 versions & 1 rubygems