当前位置:网站首页>PHP obtains some values in the string according to the specified characters, and reorganizes the remaining strings into a new array
PHP obtains some values in the string according to the specified characters, and reorganizes the remaining strings into a new array
2022-07-02 05:49:00 【Jill__ er】
Original string
SystemStatus_View_1.00
Results show :
/*
array(2) {
["version"]=>
string(4) "1.00"
["code"]=>
string(17) "SystemStatus_+_View"
}
*/
<?php
/**
* function : Split string SystemStatus_View_1.00, according to _ Take out the last part 1.00;
* And the remaining parts are spliced into SystemStatus_+_View
*/
define('SYSTEMSTATUS_VIEW', 'SystemStatus_View_1.00');
function strFun($str)
{
$ret = array();
if($str){
$tmp = explode('_', $str);
var_dump($tmp);
/*
array(3) {
[0]=>
string(12) "SystemStatus"
[1]=>
string(4) "View"
[2]=>
string(4) "1.00"
}
*/
echo count($tmp); //3
if(preg_match('/\d+.\d+/', $tmp[count($tmp)-1]))
{
$ret['version'] = array_pop($tmp); //array_pop() Function to delete the last element in the array
$ret['code'] = implode('_+_', $tmp); //implode() Function returns a string composed of array elements . Group elements into a string
}
}
return $ret;
}
var_dump(strFun(SYSTEMSTATUS_VIEW));
?>
边栏推荐
- [Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
- “簡單”的無限魔方
- vite如何兼容低版本浏览器
- Yyds dry inventory what is test driven development
- Opencv LBP features
- Php/js cookie sharing across domains
- 数理统计与机器学习
- Practice C language advanced address book design
- php数组转化为xml
- [golang syntax] be careful with the copy of slices
猜你喜欢
随机推荐
vite如何兼容低版本浏览器
Fabric. JS upload local image to canvas background
2022-2-14 learning xiangniuke project - Section 7 account setting
Appnuim environment configuration and basic knowledge
[personal test] copy and paste code between VirtualBox virtual machine and local
[Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
php按照指定字符,获取字符串中的部分值,并重组剩余字符串为新的数组
Zzuli: maximum Convention and minimum common multiple
Record sentry's path of stepping on the pit
Zzuli:1062 greatest common divisor
[paper translation] gcnet: non local networks meet squeeze exception networks and beyond
Applet jumps to official account
H5 jump applet
Get the details of the next largest number
centos8安装mysql8.0.22教程
VSCode paste image插件保存图片路径设置
How to change the IP address of computer mobile phone simulator
Zzuli:1066 character classification statistics
Zzuli:1064 encrypted characters
Simply encapsulate JS and apply it








