PHP Classes

sequential roll number: How do I generate sequential numbers with characters in PHP like

Recommend this page to a friend!
  All requests RSS feed  >  sequential roll number  >  Request new recommendation  >  A request is featured when there is no good recommended package on the site when it is posted. Featured requests  >  No recommendations No recommendations  

sequential roll number

Edit

Picture of muhammed salim k by muhammed salim k - 6 years ago (2018-02-16)

How do I generate sequential numbers with characters in PHP like

This request is clear and relevant.
This request is not clear or is not relevant.

0

How do I generate sequential numbers with characters in PHP like “16it” default number and increment number is 01,02 like that(16it01)?

  • 1 Clarification request
  • 1. Picture of zinsou A.A.E.Moïse by zinsou A.A.E.Moïse - 6 years ago (2018-02-20) Reply

    hi the goal you try to achieve is really simple.if i take your example, 16it as base and then increment like 01,02 etc... we need here to know the max length for your sequential number to do it and the real range eg: 16it01-16it09

    you can try this yourself and alter it to fit your requirement

    function sequential_id($max=6,$data='sequential_id.txt',$prepend='16it'){

    
    $i=0;
    $maxnumber='';
    while($i<($max-strlen($prepend))){
    	$maxnumber .='9';
    	$i++;
    }
    
    

    if(file_exists($data)){
    	$id=trim(file_get_contents($data));
    	if(strlen($id)==strlen($maxnumber)){
    		/*you must use only one file per counter otherwise the file will be formatted 
    		to restart counter according to $max arg */
    		if($id==$maxnumber) return false;/*if the max number with the length $max 
    		is reached the response will always be false; so be sure to test the value before use it*/
    	
    		$id++;
    		file_put_contents($data,($id=str_pad($id,strlen($maxnumber),'0',STR_PAD_LEFT)));
    		return $prepend.$id;
    	}else{
    		$id=0;
    		file_put_contents($data,($id=str_pad($id,strlen($maxnumber),'0',STR_PAD_LEFT)));
    		return $prepend.$id;
    	}
    }else{
    	$id=0;
    	file_put_contents($data,($id=str_pad($id,strlen($maxnumber),'0',STR_PAD_LEFT)));
    	return $prepend.$id;
    }
    

    }

    Ask clarification

    Recommend package
    : 
    :