1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-05 04:37:51 +02:00

Text Helper: new method increment() added.

This commit is contained in:
Awilum
2012-11-11 22:29:46 +02:00
parent 1d24f81280
commit a6cd237525

View File

@@ -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;
}
/**