doulvli9462 2014-11-13 05:40
浏览 28
已采纳

Yii - 解析自定义网址

I have a need to parse custom url's into data. The urls might look like this:

http://host.com/categoryXXX/brandYYY/markZZZ/page/1/otherparameters/othervalues

Where the first three parameters are basically prefix+value pairs (category - prefix, XXX - value). They might not all be present except for the first one (category).

All of the other parameters are optional and may or may not be present, and they also come in pairs 'key/value', AKA the usual path format of Yii.

I honestly have no idea how to parse such complex urls. Basically, I need a proper urlManager rule and a working mechanism to parse them.

Will appreciate any suggestions.

  • 写回答

1条回答 默认 最新

  • duankuang1046 2014-11-13 06:02
    关注
    /\/category(?P<category_id>[^\/]*)(?:\/brand(?P<brand_id>[^\/]*))?(?:\/mark(?P<mark_id>[^\/]*))?/i
    

    This will create named captures for all of the fields you are looking for. brand_id and mark_id are optional

    Working version: http://regex101.com/r/fQ7mU0/3

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

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?