当前位置:网站首页>php按照指定字符,获取字符串中的部分值,并重组剩余字符串为新的数组
php按照指定字符,获取字符串中的部分值,并重组剩余字符串为新的数组
2022-07-02 05:47:00 【杰儿__er】
原始字符串
SystemStatus_View_1.00
结果显示:
/*
array(2) {
["version"]=>
string(4) "1.00"
["code"]=>
string(17) "SystemStatus_+_View"
}
*/
<?php
/**
* 功能:拆分字符串SystemStatus_View_1.00,按照_取出最后一部分1.00;
* 并把其余部分按照新的规则进行拼接为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()函数删除数组中的最后一个元素
$ret['code'] = implode('_+_', $tmp); //implode()函数返回一个由数组元素组合成的字符串。即将元素组个为一个字符串
}
}
return $ret;
}
var_dump(strFun(SYSTEMSTATUS_VIEW));
?>
边栏推荐
- Ls1046nfs mount file system
- Fabric. JS round brush
- Determine whether there is an element in the string type
- 【LeetCode】Day92-盛最多水的容器
- 5g market trend in 2020
- MySQL foundation --- query (learn MySQL foundation in 1 day)
- Gee series: unit 8 time series analysis in Google Earth engine [time series]
- JVM class loading mechanism
- 【技术随记-08】
- Cube magique infini "simple"
猜你喜欢
随机推荐
Fabric. JS centered element
RNN recurrent neural network
centos8安装mysql8.0.22教程
460. LFU cache bidirectional linked list
线程池概述
1035 Password
[paper translation] gcnet: non local networks meet squeeze exception networks and beyond
Lantern Festival gift - plant vs zombie game (realized by Matlab)
A collection of commonly used plug-ins for idea development tools
Zzuli:1067 faulty odometer
mysql事务和隔离级别
KMP idea and template code
5g market trend in 2020
Thread pool overview
brew install * 失败,解决方法
Opencv LBP features
Alibaba: open source and self-developed liquid cooling data center technology
OLED12864 液晶屏
GRBL 软件:简单解释的基础知识
Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan









