douzhongjian0752 2014-01-26 12:05
浏览 67
已采纳

如何在字符之间从数据库中获取多个字符串

So, i have multiple columns formatted like this {a|b|c}{e|f|g}{h|i|j}[d].

a,e,h,d are numbers (ex: 2,3,4.5 etc)

b,f,i are dates (ex 1.1.2014 - yes, with dots)

c,g,j is an ID formatted randomly which contain numbers and letters

The column looks like this :

{5|1.1.2014|a23yiuahd3}{5.25|2.1.2014|a23yiuahd3}{9.25|2.1.2014|a23yiuahd3}[7]

I ripped my head apart 2 days to figure how to output them in php like this:

5 5.25 9.25 Hovering on each number will show you the date and the user(ID).

I tried with preg_match but it will only output me the first {...} or all of them in the same array. So no good thing.

I tried splitting in multiple substrings with a lot of other substrings like this :

$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] ,

but i got a lot of colums and i overload the database.

On one request i wait about 7 seconds.

Any ideas are welcome.

  • 写回答

1条回答 默认 最新

  • donglu9872 2014-01-26 12:28
    关注

    First, split your string.

    $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);
    

    Output

    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
            )
    
    )
    

    Now you can pull out data from an array $match and make your own output.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度