(PHP 8 >= 8.3.0)
str_increment — Increment an alphanumeric string
str_increment(string $string): string
Returns the incremented alphanumeric ASCII string.
stringThe input string.
Returns the incremented alphanumeric ASCII string.
A ValueError is thrown if string is empty.
A ValueError is thrown if string is not an alphanumeric ASCII string.
Example #1 Basic str_increment() example
<?php $str = 'ABC'; var_dump(str_increment($str)); ?>
The above example will output:
string(3) "ABD"
Example #2 str_increment() example with a carry
<?php $str = 'DZ'; var_dump(str_increment($str)); $str = 'ZZ'; var_dump(str_increment($str)); ?>
The above example will output:
string(2) "EA" string(3) "AAA"
© 1997–2025 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.str-increment.php