diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/util.inc.php | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php index 81c7d807..c3e70f89 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -590,11 +590,23 @@ SADFACE; { $regex = '/ ( - (?: [\x20-\xFF] ){1,100} # ignore lower non-printable range + [\x20-\xFF]{1,100} # ignore lower non-printable range ) | . # anything else /x'; return iconv('MS-ANSI', 'UTF-8', preg_replace($regex, '$1', $string)); } + /** + * Clamp given value into [min, max] range. + */ + public static function clamp(int &$value, int $min, int $max) + { + if ($value < $min) { + $value = $min; + } elseif ($value > $max) { + $value = $max; + } + } + } |