diff options
author | Greg Aker <greg@gregaker.net> | 2011-08-20 20:58:37 +0200 |
---|---|---|
committer | Greg Aker <greg@gregaker.net> | 2011-08-20 20:58:37 +0200 |
commit | 394d8c5bd3e04bd7992793ca7c648f4306a9539d (patch) | |
tree | d061b4339f2c3f30428256efae741ab04fd2bf6e /system/helpers/string_helper.php | |
parent | 43194ea1af658914a89ca49aed4dca4617b9c4ff (diff) | |
parent | d56be70257696d0bbf2dcc880888d8dc17cba21c (diff) |
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into develop
Diffstat (limited to 'system/helpers/string_helper.php')
-rw-r--r-- | system/helpers/string_helper.php | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 7765bba31..9fa69f46c 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -243,6 +243,23 @@ if ( ! function_exists('random_string')) // ------------------------------------------------------------------------ /** + * Add's _1 to a string or increment the ending number to allow _2, _3, etc + * + * @param string $str required + * @param string $separator What should the duplicate number be appended with + * @param string $first Which number should be used for the first dupe increment + * @return string + */ +function increment_string($str, $separator = '_', $first = 1) +{ + preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); + + return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; +} + +// ------------------------------------------------------------------------ + +/** * Alternator * * Allows strings to be alternated. See docs... |