Home > Backend Development > PHP Tutorial > 关于PHP拆分字符串的步骤

关于PHP拆分字符串的步骤

WBOY
Release: 2016-06-13 12:07:15
Original
1186 people have browsed it

关于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";<br />$ar = preg_split('/(\w+:)/', $data, -1, PREG_SPLIT_NO_EMPTY <br><font color='#FF8000'>------解决思路----------------------</font><br> PREG_SPLIT_DELIM_CAPTURE);<br />$ar = array_map('join', array_chunk($ar, 2));<br />print_r($ar);
Copy after login
Array<br />(<br />    [0] => Model:Galaxy Nexus <br />    [1] => SystemVersion:4.3 <br />    [2] => AppVersionCode:78 <br />    [3] => AppVersionName:3.140801.4<br />)<br /><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template