Longhorn PHP 2026 - Call For Papers

str_increment

(PHP 8 >= 8.3.0)

str_incrementBir alfasayısal dizgeyi artırır

Açıklama

str_increment(string $dizge): string

Artırılmış alfasayısal ASCII dizge ile döner.

Bağımsız Değişkenler

dizge

Girdi dizgesi.

Dönen Değerler

Artırılmış alfasayısal ASCII dizge döner.

Hatalar/İstisnalar

dizge boşsa bir ValueError yavrulanır.

dizge bir alfasayısal ASCII dizge değilse bir ValueError yavrulanır.

Örnekler

Örnek 1 Temel str_increment() örneği

<?php
$str
= 'ABC';
var_dump(str_increment($str));
?>

Yukarıdaki örneğin çıktısı:

string(3) "ABD"

Örnek 2 Karakter taşmalı str_increment() örneği

<?php
$str
= 'DZ';
var_dump(str_increment($str));

$str = 'ZZ';
var_dump(str_increment($str));
?>

Yukarıdaki örneğin çıktısı:

string(2) "EA"
string(3) "AAA"

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
6
yarns_purport0n at icloud dot com
1 year ago
The strings are incremented per character and each character position can be one of 3 modes:
1. [A-Z] uppercase
2. [a-z] lowercase
3. [0-9] decimal

you can mix any combination of the modes and (at least in right to left languages like english) it always increments from the right overflowing leftwards
the mode/type of character that overflows remains the mode/type of the first (0 index) position.
so: input 'zZ9' & 'aaA0' is returned
so: input 'Z9z' & 'AA0a' is returned
so: input '9zZ' & '10aA' is returned

Example:
<?php
$str = 'zZ9'; // overflows in lowercase
echo $str = str_increment($str).PHP_EOL; // aaA0
$str = 'Z9z'; // overflows in uppercase
echo $str = str_increment($str).PHP_EOL; // AA0a
$str = '9zZ'; // overflows in decimal
echo ($str = str_increment($str)); // 10aA
?>
To Top