所以,我有多列这样格式化{a|b|c}{e|f|g}{h|i|j}[d]
。
a,e,h,d是数字(例如:2,3,4.5等)
b,f,i是日期(例如,2014年1月1日-是,带点)
c,g,j是随机格式化的ID,其中包含数字和字母
该列如下所示:
{5|1.1.2014|a23yiuahd3}{5.25|2.1.2014|a23yiuahd3}{9.25|2.1.2014|a23yiuahd3}[7]
我把头分开了两天,以弄清楚如何在php中输出它们,如下所示:
5 5.25 9.25
将鼠标悬停在每个数字上会显示日期和用户(ID)。
我尝试使用preg_match,但只会在同一个数组中输出第一个{...}或所有它们。所以没有好事。
我尝试将多个子字符串拆分为多个子字符串,如下所示:
$i={5|1.1.2014|a23yiuahd3
$i_rest={5.25|2.1.2014|a23yiuahd3}{9.25|2.1.2014|a23yiuahd3}[7]
$i2={5.25|2.1.2014|a23yiuahd3
$i2_rest={9.25|2.1.2014|a23yiuahd3}[7] ,
但是我有很多专栏,而且数据库超载。
根据一个请求,我等待大约7秒钟。
任何想法都欢迎。
首先,分割您的字符串。
$s = "{5|1.1.2014|a23yiuahd3}{5.25|2.1.2014|a23yiuahd3}{9.25|2.1.2014|a23yiuahd3}[7]";
preg_match_all('/{([\d.]+)\|([\d.]+)\|([\da-z]+)}/', $s, $match);
print_r($match);
Array
(
[0] => Array
(
[0] => {5|1.1.2014|a23yiuahd3}
[1] => {5.25|2.1.2014|a23yiuahd3}
[2] => {9.25|2.1.2014|a23yiuahd3}
)
[1] => Array
(
[0] => 5
[1] => 5.25
[2] => 9.25
)
[2] => Array
(
[0] => 1.1.2014
[1] => 2.1.2014
[2] => 2.1.2014
)
[3] => Array
(
[0] => a23yiuahd3
[1] => a23yiuahd3
[2] => a23yiuahd3
)
)
现在,您可以从数组中提取数据$match
并进行自己的输出。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句