From a6cd2375251792e01473ab0178b41bd27c772622 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 11 Nov 2012 22:29:46 +0200 Subject: [PATCH] Text Helper: new method increment() added. --- monstra/helpers/text.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/monstra/helpers/text.php b/monstra/helpers/text.php index 67cfdb4..ebe8b39 100644 --- a/monstra/helpers/text.php +++ b/monstra/helpers/text.php @@ -227,6 +227,22 @@ break; } } + + + /** + * Add's _1 to a string or increment the ending number to allow _2, _3, etc + * + * @param string $str String to increment + * @param integer $first Start with + * @param string $separator Separator + * @return string + */ + public static function increment($str, $first = 1, $separator = '_') { + + preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); + + return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; + } /**