Source of file AbcStr.php
Size: 1,162 Bytes - Last Modified: 2022-01-13T10:01:10+00:00
/var/www/docs.ssmods.com/process/src/src/abc/code/Classes/AbcStr.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344 | <?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); if (count($words) <= $wordLimit) $overflowIndicator = ''; $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; } public function __toString() { return $this->str; } } |