2018-01-24 21:50:57 2330次浏览 3条回答 0 悬赏 30 金钱

w_100,h_100
转成
(w=>100 h=>100)的数组。。。

最佳答案

  • gahdwaf 发布于 2018-01-25 01:31 举报

    示例:

    $imageStyle = 'w_100,h_100';
    $styles = explode(',', $imageStyle);
    $parsedStyle = [];
    foreach ($styles as $style) {
        $size = explode('_', $style);
        $parsedStyle[$size[0]] = $size[1];
    }
    print_r($parsedStyle);
    
    2 条回复
    回复于 2018-01-26 10:20 回复

    。。。我其实是想问有没有简单的解决办法的,我现在就是用的这种

    回复于 2018-01-26 22:59 回复

    也可以用正则啊,例:

    $imageStyle = 'w_100,h_200';
    preg_replace_callback('/([a-z]+)_([\d]+)/', function ($matchs) use (&$parsedStyle){
        $parsedStyle[$matchs[1]] = $matchs[2];
    }, $imageStyle);
    print_r($parsedStyle);
    
    觉得很赞
您需要登录后才可以回答。登录 | 立即注册
livingxue
见习主管

livingxue

注册时间:2017-10-31
最后登录:2019-02-22
在线时长:12小时53分
  • 粉丝0
  • 金钱50
  • 威望10
  • 积分270

热门问题