如何按顺序获取收据编号,如AB0810001

时间:2012-10-08 09:26:34

标签: php javascript html css

AB是收据代码应该是下一个( 08 今天的日期)并且10001是收据号?

3 个答案:

答案 0 :(得分:1)

$prefix      = 'AB';
$today       =  date("d");
$receipt_num = '10001';//from db value

echo $prefix.$today.$receipt_num;

答案 1 :(得分:0)

如果您确定收据号码前面总共有4个字符,您当然可以使用substr

$data = 'AB0810001';
$receipt = substr($data, 4);
echo $receipt;  // will output 10001

答案 2 :(得分:0)

如果您的意思是如何从该字符串中获取这些块,则应该这样做:

var str = 'AB0810001';
var result = str.match(/([A-Z]{2})(\d{2})(\d{5})/);
result.shift();
console.log(result); //=> ['AB', '08', '10001']