当前位置:网站首页>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));
?>
边栏推荐
- 软件测试基础篇
- 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
- [personal test] copy and paste code between VirtualBox virtual machine and local
- Fabric. JS iText sets the color and background color of the specified text
- Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
- A collection of commonly used plug-ins for idea development tools
- brew install * 失败,解决方法
- 6. Network - Foundation
- 文件包含漏洞(二)
- Php/js cookie sharing across domains
猜你喜欢
软件测试 - 概念篇
Cube magique infini "simple"
Disable access to external entities in XML parsing
Importation de studio visuel
“簡單”的無限魔方
Record sentry's path of stepping on the pit
Detailed explanation of Pointer use
Youth training camp -- database operation project
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
随机推荐
[leetcode] day92 container with the most water
A collection of commonly used plug-ins for idea development tools
The Hong Kong Stock Exchange learned from US stocks and pushed spac: the follow-up of many PE companies could not hide the embarrassment of the world's worst stock market
Foreign trade marketing website system development function case making
简单封装 js并应用
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
[Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
all3dp.com网站中全部Arduino项目(2022.7.1)
Usage record of vector
Detailed explanation of Pointer use
RNN recurrent neural network
Fabric. JS centered element
【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
“簡單”的無限魔方
RGB 无限立方体(高级版)
How to write good code - Defensive Programming Guide
Financial portal related information
js判断移动端还是pc端
Uva548 tree
测试 - 用例篇