Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Autocode
- {
- public function code_increment($prefix='',$count=4,$last_kode='')
- {
- $output='';
- $next='';
- if(empty($last_kode))
- {
- $order=1;
- $next=sprintf("%0".$count."s",$order);
- $output=$prefix.$next;
- }else{
- $lenght_prefix=strlen($prefix);
- $next=(int) substr($last_kode,$lenght_prefix,$count);
- $next++;
- $next=sprintf("%0".$count."s",$next);
- $output=$prefix.$next;
- }
- return $output;
- }
- public function code_date($prefix='',$format='Ymd',$timezone='Asia/Jakarta')
- {
- date_default_timezone_set($timezone);
- $date=date($format);
- $generate=$prefix.$date;
- return $generate;
- }
- public function code_random($prefix='',$length=20,$alphabet=FALSE)
- {
- $output='';
- if(empty($alphabet) || $alphabet==FALSE)
- {
- $output= substr(str_shuffle("0123456789"), 0, $length);
- }else{
- $output= substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
- }
- $generate=$prefix.$output;
- return $generate;
- }
- }
- //TEST
- <?php
- require_once('Autocode.php');
- //RANDOM
- echo "----RANDOM----".'<br/>';
- echo "----WITHOUT PREFIX".'<br/>';
- echo $this->autocode->code_random('',10,TRUE).'<br/>';
- echo "----PREFIX".'<br/>';
- echo $this->autocode->code_random("CR-",40,TRUE).'<br/>';
- $random=$this->autocode->code_random("CR-",40,TRUE);
- echo strtoupper($random).'<br/>';
- echo '<p> </p>';
- //DATE
- echo "----DATE----".'<br/>';
- echo "----WITHOUT PREFIX".'<br/>';
- echo $this->autocode->code_date('','Ymd').'<br/>';
- echo "----PREFIX".'<br/>';
- echo $this->autocode->code_date("CD/",'YmdH').'<br/>';
- echo $this->autocode->code_date("CD/",'dmYHis').'<br/>';
- echo '<p> </p>';
- //INCREMENT
- echo "----INCREMENT----".'<br/>';
- $last_code="CI-2345677";
- $count=7; //523049 6 character
- echo "----WITHOUT PREFIX".'<br/>';
- echo $this->autocode->code_increment('',6).'<br/>';
- echo "----PREFIX Last Code ".$last_code.'<br/>';
- echo $this->autocode->code_increment('CI-',$count,$last_code);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement