当前位置:网站首页>php中判断版本号是否连续
php中判断版本号是否连续
2022-07-02 06:23:00 【夜空の雪風】
前言
在做excel数据导入到数据库表的过程中需要验证excel中的版本号一栏中的版本号是否连续。
版本号格式:1,1.1,1.2,1.2.1,2,2.1,2.2,2.2.1(正确)
版本号格式:1,1.1,1.1,1.2.1,2,2.1,2.2,2.2.1(错误)
版本号格式:1,1.2,1.1,1.2.1,2,2.2,2.1,2.1.1(错误)
这里需要用到php中的字符串函数,strpos,strrpos,substr。
/** * 判断编号是否连续,编号格式:1,1.1,1.2,1.2.1,2,2.1,2.2,2.2.1 * @param $data * @param string $mark * @return void */
function judge_code_continuity($data, $errData = [], $mark = '.')
{
foreach ($data as $key => $val) {
if (!empty($val)) {
//判断是否存在重复编号
if (in_array($val, array_slice($data, 0, $key))) {
$errData[] = "编号" . $key . "存在重复,请检查以后重新上传";
break;
}
if ($key == 0) {
} else if (!strpos($val, $mark)) {
if (!in_array($val - 1, array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
break;
}
} else {
$position = strrpos($val, $mark, 0);
$temp = substr($val, $position + 1, strlen($val) - $position) - 1;
$profit = substr($val, 0, $position);
$pointPosition = strrpos($profit, $mark, 0);
$pointBefore = substr($profit, 0, $pointPosition);
$pointAfter = substr($profit, -1, $pointPosition);
if ($temp == 0) {
if (!in_array(substr($val, 0, $position), array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
break;
}
} else {
if (!in_array(substr($val, 0, $position) . "." . ($temp), array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
break;
}
}
if ($pointBefore && in_array($pointBefore . "." . ($pointAfter + 1), array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
}
}
} else {
continue;
}
}
return $errData;
}
这里会把一串版本号中不正确的返回错误信息。
边栏推荐
- sqli-labs通关汇总-page1
- Latex compilation error I found no \bibstyle &\bibdata &\citation command
- Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
- sprintf_ How to use s
- Browser scrolling for more implementations
- Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
- The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem
- Overload global and member new/delete
- Code execution sequence with and without resolve in promise
- 查询GPU时无进程运行,但是显存却被占用了
猜你喜欢

PgSQL learning notes

Recursion (maze problem, Queen 8 problem)

解决微信小程序swiper组件bindchange事件抖动问题

The use of regular expressions in JS

Pytest (2) mark function

A preliminary study on ant group G6

js中map和forEach的用法

Sqli-labs customs clearance (less6-less14)

The table component specifies the concatenation parallel method

Fe - wechat applet - Bluetooth ble development research and use
随机推荐
ts和js区别
JS divides an array into groups of three
PHP Session原理简析
CVE-2015-1635(MS15-034 )远程代码执行漏洞复现
SQLI-LABS通关(less2-less5)
uniapp引入本地字体
sqli-labs通關匯總-page2
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
2021-07-19C#CAD二次开发创建多线段
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
Utilisation de la carte et de foreach dans JS
Pytest (1) case collection rules
[Zhang San learns C language] - deeply understand data storage
Latex compiles Chinese in vscode and solves the problem of using Chinese path
Selenium memo: selenium\webdriver\remote\remote_ connection. Py:374: resourcewarning: unclosed < XXXX > solution
Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
Implement strstr() II
2021-07-17C#/CAD二次开发创建圆(5)
Record RDS troubleshooting once -- RDS capacity increases dramatically