diff options
author | Phil Sturgeon <email@philsturgeon.co.uk> | 2011-08-14 20:23:55 +0200 |
---|---|---|
committer | Phil Sturgeon <email@philsturgeon.co.uk> | 2011-08-14 20:23:55 +0200 |
commit | dbac73b4011a85c4ac3b3a7a6a8e30533b881155 (patch) | |
tree | fc7a72c29a933d77ea1358427cac3797e2ba029c | |
parent | d8ef630f2d4d32eee998969e548d36dc629340d4 (diff) |
Added increment_string() docs and changelog.
-rw-r--r-- | system/helpers/string_helper.php | 4 | ||||
-rw-r--r-- | user_guide/changelog.html | 1 | ||||
-rw-r--r-- | user_guide/helpers/string_helper.html | 11 |
3 files changed, 15 insertions, 1 deletions
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 2f928a7d1..9fa69f46c 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -246,9 +246,11 @@ 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, $first = 1, $separator = '_') +function increment_string($str, $separator = '_', $first = 1) { preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); diff --git a/user_guide/changelog.html b/user_guide/changelog.html index 8f0fad783..20b1c4e49 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -70,6 +70,7 @@ Change Log </li> <li>Helpers <ul> + <li class="reactor">Added <samp>increment_string()</samp> to <a href="helpers/string_helper.html">String Helper</a> to turn "foo" into "foo-1" or "foo-1" into "foo-2".</li> </ul> </li> <li>Database diff --git a/user_guide/helpers/string_helper.html b/user_guide/helpers/string_helper.html index 169ee4ebb..7c1d30c59 100644 --- a/user_guide/helpers/string_helper.html +++ b/user_guide/helpers/string_helper.html @@ -90,6 +90,17 @@ String Helper <code>echo random_string('alnum', 16);</code> +<h2>increment_string()</h2> + +<p>Increments a string by appending a number to it or increasing the number. Useful for creating "copies" or a file or duplicating database content which has unique titles or slugs.</p> + +<p>Usage example:</p> + +<code>echo increment_string('file', '_'); // "file_1"<br/> +echo increment_string('file', '-', 2); // "file-2"<br/> +echo increment_string('file-4'); // "file-5"<br/></code> + + <h2>alternator()</h2> <p>Allows two or more items to be alternated between, when cycling through a loop. Example:</p> |