note 115520 deleted from function.preg-replace by cmb

From: Date: Sun, 22 Sep 2019 07:59:41 +0000
Subject: note 115520 deleted from function.preg-replace by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212302@lists.php.net to get a copy of this message
Note Submitter: eurosat7 at yahoo dot de ---- If you want to limit multiple occurences of any char in a sequence you might want to use this function. <?php function limit_char_repeat($string,$maxrepeat){ return preg_replace("/(.)\\1{".$maxrepeat.",}/ms",str_repeat('\1',$maxrepeat),$string); } ?> Example: <?php $string=" --------------------- Heeeeeeeeeeeeeeeeeeeello Woooooooooooooooorld!!!!!!!!!!!!!!!!!!!!!!!! =============================================================================================================== ~~~~~~~~~~~~~~~~ ~ ~ ~ "; echo limit_char_repeat($string,5); ?> Output: ----- Heeeeello Wooooorld!!!!! ===== ~~~~~ ~ ~ ~

« previous php.notes (#212302) next »