diff options
author | Greg Aker <greg@gregaker.net> | 2011-08-20 18:58:58 +0200 |
---|---|---|
committer | Greg Aker <greg@gregaker.net> | 2011-08-20 18:58:58 +0200 |
commit | abbad9ea53e81c6e3211029711ac5b2ab4f1978d (patch) | |
tree | 9a4d5a8587da1dd3a365251afa37be2f835a53c2 /system/helpers/string_helper.php | |
parent | 71644d683d0a15a6f7e04fabd0f51a4200d620b4 (diff) | |
parent | d56be70257696d0bbf2dcc880888d8dc17cba21c (diff) |
Merge branch 'develop' into feature/unit-tests
Conflicts:
.hgignore
Diffstat (limited to 'system/helpers/string_helper.php')
-rw-r--r-- | system/helpers/string_helper.php | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 9f730bd10..9fa69f46c 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -150,7 +150,7 @@ if ( ! function_exists('reduce_double_slashes')) /** * Reduce Multiples * - * Reduces multiple instances of a particular character. Example: + * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * @@ -187,7 +187,7 @@ if ( ! function_exists('reduce_multiples')) * Useful for generating passwords or hashes. * * @access public - * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 + * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 * @param integer number of characters * @return string */ @@ -243,9 +243,26 @@ 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... + * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) |