嘟嘟社区

[经验] 向技术大佬们求个PHP正则,和补上缺失php代码


本帖最后由 Front 于 2022-5-11 20:49 编辑
  1. {"message":"获取成功","state":"1","messages":"获取成功;","data":{"pageRule":{"maxModule":40,"supportLayouts":{"sm":[{"cssName":"grid-s5m0","layoutCompId":1},{"cssName":"grid-m0s5","layoutCompId":228}],"sme":[{"cssName":"grid-s5m0e5","layoutCompId":20},{"cssName":"grid-m0s5e5","layoutCompId":229},{"cssName":"grid-s5e5m0","layoutCompId":230}],"m":[{"cssName":"grid-m0","layoutCompId":231}]},"maxLayout":5},"pageStruct":{"hd":[{"layoutCompId":23,"layoutWidgetId":24384400531,"cssName":"grid-m","main":[{"moduleId":5001,"moduleWidgetId":24384400532,"title":"店铺招牌","toolBar":{"isdel":"1","isadd":"1","ismove":"1","isedit":"1","microscope_data":"’5001-24384400532’","spm":"’110.0.5001-24384400532’","width":"909","uri":"/module/moduleForm.htm?widgetId=24384400532&sid=407382596&pageId=1411561970","context":"h950"}},{"moduleId":5002,"moduleWidgetId":24384400533,"title":"导航","toolBar":{"isdel":"0","isadd":"1","ismove":"1","isedit":"1","microscope_data":"’5002-24384400533’","spm":"’110.0.5002-24384400533’","width":"650","uri":"/module/moduleForm.htm?widgetId=24384400533&sid=407382596&pageId=1411561970","context":"h950"}}],"layoutBar":{"max":2}}],"bd":[{"layoutCompId":231,"layoutWidgetId":24384400536,"cssName":"grid-m0","main":[{"moduleId":4024,"moduleWidgetId":24384400537,"title":"图片轮播","toolBar":{"isdel":"1","isadd":"1","ismove":"1","isedit":"1","microscope_data":"’4024-24384400537’","spm":"’110.0.4024-24384400537’","width":"773","uri":"/module/moduleForm.htm?widgetId=24384400537&sid=407382596&pageId=1411561970","context":"b550-b190-b750-b950"}},{"moduleId":137712,"moduleWidgetId":24384400538,"title":"特价专区","toolBar":{"isdel":"1","isadd":"1","ismove":"1","isedit":"1","needwidth":"1","microscope_data":"’137712-24384400538’","spm":"’110.0.137712-24384400538’","width":"670","uri":"/module/moduleForm.htm?widgetId=24384400538&sid=407382596&pageId=1411561970","context":"b950-h950-f950"}}],"layoutBar":{}},{"layoutCompId":1,"layoutWidgetId":24384400542,"cssName":"grid-s5m0","sub":[{"moduleId":4031,"moduleWidgetId":24384400543,"title":"搜索店内宝贝","toolBar":{"isdel":"1","isadd":"1","ismove":"1","isedit":"1","microscope_data":"’4031-24384400543’","spm":"’110.0.4031-24384400543’","uri":"/module/moduleForm.htm?widgetId=24384400543&sid=407382596&pageId=1411561970","context":"b550-b190-b750-b950"}}],"main":[{"moduleId":4004,"moduleWidgetId":24384400546,"title":"宝贝推荐","toolBar":{"isdel":"1","isadd":"1","ismove":"1","isedit":"1","needwidth":"1","renderwmove":"1","renderurl":"//siteadmin.taobao.com/module/modulePreview.htm?widgetId=24384400546&sid=407382596&pageId=1411561970","microscope_data":"’4004-24384400546’","spm":"’110.0.4004-24384400546’","width":"800","uri":"//siteadmin.taobao.com/module/edit/itemRecommend.htm?widgetId=24384400546&sid=407382596&pageId=1411561970","context":"b550-b190-b750-b950"}}],"layoutBar":{}},{"layoutCompId":231,"layoutWidgetId":24384400547,"cssName":"grid-m0","main":[{"moduleId":4004,"moduleWidgetId":24384400548,"title":"宝贝推荐","toolBar":{"isdel":"1","isadd":"1","ismove":"1","isedit":"1","needwidth":"1","renderwmove":"1","renderurl":"//siteadmin.taobao.com/module/modulePreview.htm?widgetId=24384400548&sid=407382596&pageId=1411561970","microscope_data":"’4004-24384400548’","spm":"’110.0.4004-24384400548’","width":"800","uri":"//siteadmin.taobao.com/module/edit/itemRecommend.htm?widgetId=24384400548&sid=407382596&pageId=1411561970","context":"b550-b190-b750-b950"}}],"layoutBar":{}}],"ft":[{"layoutCompId":33,"layoutWidgetId":24384400534,"cssName":"grid-m","main":[{"moduleId":5003,"moduleWidgetId":24384584044,"title":"自定义内容区","toolBar":{"isdel":"1","isadd":"1","ismove":"1","isedit":"1","microscope_data":"’5003-24384584044’","spm":"’110.0.5003-24384584044’","width":"880","uri":"/module/moduleForm.htm?widgetId=24384584044&sid=407382596&pageId=1411561970","context":"f950-b550-b190-b750-b950"}}],"layoutBar":{"max":1}}]}},"operatorCode":"0"}

复制代码

把上面的数据匹配分别hd,bd,ft组成下面的数据。

  1. {hd:[{id:24384400531,pid:23,main:[{id:24384400532,pid:5001},{id:24384400533,pid:5002}]}],
  2. bd:[{id:24384400536,pid:231,main:[{id:24384400537,pid:4024},{id:24384400538,pid:137712}]},{id:24384400542,pid:1,main:[{id:24384400546,pid:4004}],sub:[{id:24384400543,pid:4031}]},{id:24384400547,pid:231,main:[{id:24384400548,pid:4004}]}],
  3. ft:[{id:24384400534,pid:33,main:[{id:24384584044,pid:5003}]}]}

复制代码

ps:在网上找到不完整的php代码,求大佬帮忙补上缺失代码。

  1.   $u_bd=$bd_bj[‘data’][‘pageStruct’][‘bd’];
  2.   $ujc_bds=’bd:[‘;       
  3.   for($i=0;$i<count($u_bd);$i++){
  4.           if($i<(count($u_bd)-1)){$ds=’,’;}else{$ds=”;};
  5.   $ujc_bd='{‘;
  6.         if(isset($u_bd[$i][‘main’]))        {
  7.                 $main=’id:’.$u_bd[$i][‘layoutWidgetId’].’,pid:’.$u_bd[$i][‘layoutCompId’].’,main:[‘;
  8.                 $bodys=”;
  9.                 for($k=0;$k<count($u_bd[$i][‘main’]);$k++){
  10.                   if($k<(count($u_bd[$i][‘main’])-1)){$d=’,’;}else{$d=”;}
  11.                   if($k==(count($u_bd[$i][‘main’])-1)){$body='{id:’.$u_bd[$i][‘main’][$k][‘moduleWidgetId’].’,pid:’.$u_bd[$i][‘main’][$k][‘moduleId’].’},{id:’.$widgetid.’,pid:5003}’;}
  12.                   else{$body='{id:’.$u_bd[$i][‘main’][$k][‘moduleWidgetId’].’,pid:’.$u_bd[$i][‘main’][$k][‘moduleId’].’}’.$d.”;}
  13.                   $bodys=$bodys.$body;
  14.                 }
  15.                 $main=$main.$bodys.’]’;
  16.         }else{$main=”;}
  17.        
  18.         if(isset($u_bd[$i][‘sub’]))        {
  19.                 $sub=’,sub:[‘;
  20.                 $bodys=”;
  21.                 for($k=0;$k<count($u_bd[$i][‘sub’]);$k++){
  22.                   if($k<(count($u_bd[$i][‘sub’])-1)){$d=’,’;}else{$d=”;}
  23.                   $body='{id:’.$u_bd[$i][‘sub’][$k][‘moduleWidgetId’].’,pid:’.$u_bd[$i][‘sub’][$k][‘moduleId’].’}’.$d.”;
  24.                   $bodys=$bodys.$body;
  25.                 }
  26.                 $sub=$sub.$bodys.’]’;
  27.         }else{$sub=”;}
  28.        
  29.   $ujc_bd=$ujc_bd.$main.$sub.’}’.$ds.”;
  30.   $ujc_bds=$ujc_bds.$ujc_bd;
  31.   }
  32.   $ujc_bds=$ujc_bds.’]’;
  33.   
  34.   
  35.   $buju='{‘.$ujc_hds.’,’.$ujc_bds.’,’.$ujc_fts.’}’;
  36.   echo $buju;

复制代码

不用补全 直接手打上去了

小旭 发表于 2022-5-11 20:52
不用补全 直接手打上去了