关于PHP拆分字符串的步骤
程序员文章站
2022-04-12 12:03:39
...
关于PHP拆分字符串的方法
我有个字符串
$data = "Model:Galaxy Nexus SystemVersion:4.3 AppVersionCode:78 AppVersionName:3.140801.4";
我拆分为:
$a = “Model:Galaxy Nexus”,
$b = “SystemVersion:4.3”,
$c = “AppVersionCode:78”,
$d = “AppVersionName:3.140801.4”,
请问有什么好方法吗?
------解决思路----------------------
我有个字符串
$data = "Model:Galaxy Nexus SystemVersion:4.3 AppVersionCode:78 AppVersionName:3.140801.4";
我拆分为:
$a = “Model:Galaxy Nexus”,
$b = “SystemVersion:4.3”,
$c = “AppVersionCode:78”,
$d = “AppVersionName:3.140801.4”,
请问有什么好方法吗?
------解决思路----------------------
$data = "Model:Galaxy Nexus SystemVersion:4.3 AppVersionCode:78 AppVersionName:3.140801.4";
$ar = preg_split('/(\w+:)/', $data, -1, PREG_SPLIT_NO_EMPTY
------解决思路----------------------
PREG_SPLIT_DELIM_CAPTURE);
$ar = array_map('join', array_chunk($ar, 2));
print_r($ar);
Array
(
[0] => Model:Galaxy Nexus
[1] => SystemVersion:4.3
[2] => AppVersionCode:78
[3] => AppVersionName:3.140801.4
)
相关文章
相关视频
下一篇: 浅析Vue的异步组件函数