添加一个值字母数字
add the one values alphanumberic
我实现了获取字母数字值和加一值的功能。
$string = "VDLE009567";
$person = $numbers = array();
if(preg_match_all('/([a-z ]+[0-9]+)/i', $string, $mt)) {
$nrmt = count($mt[0]);
for($i=0; $i<$nrmt; $i++) {
if(preg_match('/([a-z ]+)([0-9]+)/i', $mt[0][$i], $mt2)) {
echo $person[$i] = trim($mt2[1]);
echo $numbers[$i] = $mt2[2];
}
}
}
echo $numbers=$numbers[0]+1;
我需要获得 "VDLE009568" 的值,但我得到了 "VDLE9568" 的值。有什么办法可以得到这个 "VDLE009568"
将此代码用于结果
<?php
$string = "VDLE999999";
$person = $numbers = array();
if (preg_match_all('/([a-z ]+[0-9]+)/i', $string, $mt)) {
$nrmt = count($mt[0]);
for ($i = 0; $i < $nrmt; $i++) {
if (preg_match('/([a-z ]+)([0-9]+)/i', $mt[0][$i], $mt2)) {
$personout = $person[$i] = trim($mt2[1]);
$numbers[$i] = $mt2[2];
if ($numbers[0] == 999999) {
$last = substr($personout, -1, 1);
$personout = substr($personout, 0, -1) . (++$last);
$numbers[0] = 0;
}
echo $personout;
}
}
}
echo $numbers = str_pad($numbers[0] + 1, 6, '0', STR_PAD_LEFT);
结果:VDLF000001 Online Test Click Here
根据您的要求,我对代码进行了一些更改
<?php
$string = "VDLE999999";
$person = $numbers = array();
if(preg_match_all('/([a-z ]+[0-9]+)/i', $string, $mt)) {
$nrmt = count($mt[0]);
for($i=0; $i<$nrmt; $i++) {
if(preg_match('/([a-z ]+)([0-9]+)/i', $mt[0][$i], $mt2)) {
$person[$i] = trim($mt2[1]);
$numbers[$i] = $mt2[2];
}
}
}
$num = (string)$numbers[0];
$word_length = strlen($num);
$max = 9;
$max_str = '';
for($i=0;$i<$word_length;$i++){
$max_str .=$max;
}
$max_str = (int)$max_str;
if($num < $max_str){
echo $numbers=str_pad($num+1, $word_length, '0', STR_PAD_LEFT);
}else{
$numbers=str_pad($num+1,$word_length+1, '0', STR_PAD_LEFT);
$new_str = strrev((string)$numbers);
$new_num = (int)$new_str;
echo $numbers = str_pad($new_num,$word_length+1, '0', STR_PAD_LEFT);
}
我实现了获取字母数字值和加一值的功能。
$string = "VDLE009567";
$person = $numbers = array();
if(preg_match_all('/([a-z ]+[0-9]+)/i', $string, $mt)) {
$nrmt = count($mt[0]);
for($i=0; $i<$nrmt; $i++) {
if(preg_match('/([a-z ]+)([0-9]+)/i', $mt[0][$i], $mt2)) {
echo $person[$i] = trim($mt2[1]);
echo $numbers[$i] = $mt2[2];
}
}
}
echo $numbers=$numbers[0]+1;
我需要获得 "VDLE009568" 的值,但我得到了 "VDLE9568" 的值。有什么办法可以得到这个 "VDLE009568"
将此代码用于结果
<?php
$string = "VDLE999999";
$person = $numbers = array();
if (preg_match_all('/([a-z ]+[0-9]+)/i', $string, $mt)) {
$nrmt = count($mt[0]);
for ($i = 0; $i < $nrmt; $i++) {
if (preg_match('/([a-z ]+)([0-9]+)/i', $mt[0][$i], $mt2)) {
$personout = $person[$i] = trim($mt2[1]);
$numbers[$i] = $mt2[2];
if ($numbers[0] == 999999) {
$last = substr($personout, -1, 1);
$personout = substr($personout, 0, -1) . (++$last);
$numbers[0] = 0;
}
echo $personout;
}
}
}
echo $numbers = str_pad($numbers[0] + 1, 6, '0', STR_PAD_LEFT);
结果:VDLF000001 Online Test Click Here
根据您的要求,我对代码进行了一些更改
<?php
$string = "VDLE999999";
$person = $numbers = array();
if(preg_match_all('/([a-z ]+[0-9]+)/i', $string, $mt)) {
$nrmt = count($mt[0]);
for($i=0; $i<$nrmt; $i++) {
if(preg_match('/([a-z ]+)([0-9]+)/i', $mt[0][$i], $mt2)) {
$person[$i] = trim($mt2[1]);
$numbers[$i] = $mt2[2];
}
}
}
$num = (string)$numbers[0];
$word_length = strlen($num);
$max = 9;
$max_str = '';
for($i=0;$i<$word_length;$i++){
$max_str .=$max;
}
$max_str = (int)$max_str;
if($num < $max_str){
echo $numbers=str_pad($num+1, $word_length, '0', STR_PAD_LEFT);
}else{
$numbers=str_pad($num+1,$word_length+1, '0', STR_PAD_LEFT);
$new_str = strrev((string)$numbers);
$new_num = (int)$new_str;
echo $numbers = str_pad($new_num,$word_length+1, '0', STR_PAD_LEFT);
}