mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix modifier length
This commit is contained in:
parent
cae6824bd3
commit
454fff1a08
@ -53,7 +53,7 @@ class Modifier {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function escape($text, $type = 'html') {
|
public static function escape($text, $type = 'html') {
|
||||||
switch($type) {
|
switch(strtolower($type)) {
|
||||||
case "url":
|
case "url":
|
||||||
return urlencode($text);
|
return urlencode($text);
|
||||||
case "html";
|
case "html";
|
||||||
@ -115,7 +115,7 @@ class Modifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strip spaces symbols on edge of string end multiple spaces into string
|
* Strip spaces symbols on edge of string end multiple spaces in string
|
||||||
* @static
|
* @static
|
||||||
* @param string $str
|
* @param string $str
|
||||||
* @param bool $to_line strip line ends
|
* @param bool $to_line strip line ends
|
||||||
@ -131,16 +131,19 @@ class Modifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return length of UTF8 string, array, countable object
|
||||||
* @param mixed $item
|
* @param mixed $item
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function length($item) {
|
public static function length($item) {
|
||||||
if(is_scalar($item)) {
|
if(is_scalar($item)) {
|
||||||
return strlen($item);
|
return strlen(preg_replace('#[\x00-\x7F]|[\x80-\xDF][\x00-\xBF]|[\xE0-\xEF][\x00-\xBF]{2}#s', ' ', $item));
|
||||||
} elseif (is_array($item)) {
|
} elseif (is_array($item)) {
|
||||||
return count($item);
|
return count($item);
|
||||||
|
} elseif(is_object($item) && ($item instanceof \Countable)) {
|
||||||
|
return count($item);
|
||||||
} else {
|
} else {
|
||||||
return count((array)$item);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user