当前位置:网站首页>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));
?>
边栏推荐
猜你喜欢
随机推荐
文件包含漏洞(一)
【LeetCode】Day92-盛最多水的容器
软件测试 - 概念篇
1037 Magic Coupon
MySQL foundation --- query (learn MySQL foundation in 1 day)
mysql的约束总结
Zzuli:1062 greatest common divisor
运动健身的一些心得经验
【技术随记-08】
Centos8 installation mysql8.0.22 tutorial
Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders
Cube magique infini "simple"
Appnuim environment configuration and basic knowledge
2022-2-14 learning xiangniuke project - Section 7 account setting
GRBL 软件:简单解释的基础知识
Generate QR code
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
线程池概述
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
软件测试基础篇