This repository was archived by the owner on Sep 1, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStrIncrement.php
More file actions
76 lines (74 loc) · 1.8 KB
/
StrIncrement.php
File metadata and controls
76 lines (74 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* String Increment Class
* @author http://weibo.com/yakeing
* @version 3.0
* StrIncrement::NewStr(string, Hex)
*/
namespace str_increment;
class StrIncrement{
/**
* Increment string
* @param string $string [ Raw string ]
* @param options $Hex [ letters ] alphabetic character / [ lowercase ] lLower case letters / [ uppercase ] uppercase letter / [16] hxe / [10]
*/
public static function NewStr($string, $Hex=62){
if(!ctype_alnum($string) && !is_int($string)) return false;
static $instance = null;
if(is_null($instance)){
$instance = new self();
}
switch($Hex){
case 'letters':
if(!ctype_alpha($string)) return false;
$start = 10;
$length = 52;
break;
case 'lowercase':
if(!ctype_lower($string)) return false;
$start = 10;
$length = 26;
break;
case 'uppercase':
if(!ctype_upper($string)) return false;
$start = 36;
$length = 26;
break;
default:
$start = 0;
$length = ($Hex > 62)?62:$Hex;
break;
}
$Table = $instance->CapacityTable($start, $length);
$first = substr($Table, 0, 1);
$last = substr($Table, -1);
$i = $len = strlen($string)-1;
$ArrStr = str_split($string);
while(true){
$str = (string)$ArrStr[$i];
if($last == $str){
$ArrStr[$i] = $first;
--$i;
if(0 > $i) break;
}else{
$NewStr = $instance->Calculation($str, $Table);
$ArrStr[$i] = $NewStr;
break;
}
}
return implode('', $ArrStr);
}
//Increasing
private function Calculation($str, $Table){
$StrLast = strstr($Table, $str);
if($StrLast == false){
return substr($Table, 0, 1);
}
return substr($StrLast, 1, 1);
}
//Character table
private function CapacityTable($start, $length){
$str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr($str, $start, $length);
}
}