当前位置:网站首页>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));
?>
边栏推荐
- 正则表达式总结
- brew install * 失败,解决方法
- Appnuim environment configuration and basic knowledge
- Alibaba: open source and self-developed liquid cooling data center technology
- Operator details
- Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
- Ls1046nfs mount file system
- Ubuntu 20.04 installing mysql8
- [technical notes-08]
- Applet jumps to official account
猜你喜欢
随机推荐
all3dp.com网站中全部Arduino项目(2022.7.1)
VSCode paste image插件保存图片路径设置
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
Get the details of the next largest number
Zzuli:1065 count the number of numeric characters
Alibaba: open source and self-developed liquid cooling data center technology
文件包含漏洞(一)
Visual Studio導入
1036 Boys vs Girls
H5 jump applet
js判断移动端还是pc端
“簡單”的無限魔方
Centos8 installation mysql8.0.22 tutorial
ThreadLocal memory leak
5g market trend in 2020
【技术随记-08】
Zzuli:1068 binary number
【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
Foreign trade marketing website system development function case making
Software testing learning - day 4









