当前位置:网站首页>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));
?>
边栏推荐
- Centos8 installation mysql8.0.22 tutorial
- c语言中的几个关键字
- Fabric. JS basic brush
- Taskbar explicit / implicit toggle function
- File contains vulnerabilities (II)
- [technical notes-08]
- idea開發工具常用的插件合集匯總
- Fabric. JS gradient
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
猜你喜欢
"Original, excellent and vulgar" in operation and maintenance work
[personal test] copy and paste code between VirtualBox virtual machine and local
青训营--数据库实操项目
正则表达式总结
mysql事务和隔离级别
KMP idea and template code
Technologists talk about open source: This is not just using love to generate electricity
A collection of commonly used plug-ins for idea development tools
记录sentry的踩坑之路
Vite打包后的dist不能直接在浏览器打开吗
随机推荐
Youth training camp -- database operation project
mysql的约束总结
小程序跳装到公众号
Opencv LBP features
KMP idea and template code
Zzuli:1060 numbers in reverse order
XSS basic content learning (continuous update)
Php/js cookie sharing across domains
centos8安裝mysql8.0.22教程
RGB infinite cube (advanced version)
php内类名称与类内方法名相同
h5跳小程序
Fabric. JS compact JSON
[personal test] copy and paste code between VirtualBox virtual machine and local
Zzuli:1066 character classification statistics
“簡單”的無限魔方
Ls1046nfs mount file system
brew install * 失败,解决方法
运动健身的一些心得经验
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法