1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- class Str{
- public static function truncate($str, $len, $symbols = null){
- if($str && $len){
- if(mb_strlen($str) > $len){
- $str = mb_substr($str, 0, $len, "UTF-8");
- if($symbols)
- $str .= $symbols;
- }
- }
-
- return $str;
- }
-
- public static function split($str, $len){
- if(strlen($str) > $len){
- $str = strrev($str);
- $str = str_split($str, $len);
- $arr = array();
- foreach($str as $val){
- array_unshift($arr, strrev($val));
- }
- $str = $arr;
- }
- else
- $str = array($str);
-
- return $str;
- }
-
- public static function rsplit($str, $len){
- if(strlen($str) > $len){
- $str = strrev($str);
- $str = str_split($str, $len);
- $arr = array();
- foreach($str as $val){
- $arr[] = strrev($val);
- }
- $str = $arr;
- }
- else
- $str = array($str);
-
- return $str;
- }
-
- public static function isBlank($str){
- $str = trim($str);
-
- return empty($str) && $str !== 0 && $str !== "0" ? true : false;
- }
- }
|