dsh7623 2013-04-15 08:20
浏览 37
已采纳

在字符串php中解析字符串

I have a problem with regular expressions in PHP.

I have a string: "NAPLAK ROSSO+S.ARG.+LACC.ARG.+NK", all of this words contain options like ROSSO,S.ARG, Are colors ROSSO = Red, s.arg = silver and so on.

Out of this string i need to generate a description like:

Material: Naplak, Color: Red, Silver.... ....

I thought, that there is going to be an array with laguage codes something like this:

$options = array(
    "ROSSO" => "COLOR_RED",
    "S.ARG" => "COLOR_SILVER"
);

Could you please help me to write a regular expression for this purpose?

Best regargs, RussianRoot.

  • 写回答

2条回答 默认 最新

  • dongluzhi5208 2013-04-15 08:45
    关注

    I don't think you need regex for this. Probably easier and faster to do something like:

    $item = explode(' ', "NAPLAK ROSSO+S.ARG.+LACC.ARG.+NK");
    $args = explode('+', $item[1]);
    $item = $item[0];
    
    echo $item;
    

    Gives us "NAPLAK"

    print_r($args);
    

    Gives us:

    array(4) [ 'ROSSO', 'S.ARG', 'LACC.ARG.', 'NK' ];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求Houdini使用行家,付费。价格面议。
  • ¥15 AttributeError: 'EasyDict' object has no attribute 'BACKUP_DB_INFO'
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 CF1927D 求Hack