久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

123
返回列表 發帖
樓主: roc29a

[求助] 分類信息字段中的選擇和多選的數據庫表,123替換

2

主題

19

回帖

24

積分

初學乍練

貢獻
0 點
金幣
0 個
21#
 樓主| 發表于 2023-10-6 09:38:32 | 只看Ta
  1. <!-- forum_typeoption表中所有1 = xx 2 = yy 3 = zz更改為 [rules]xx yy zz -->
  2. $typeoption = DB::fetch_all("SELECT optionid,rules FROM %t WHERE optionid > %d", array('forum_typeoption', 6));
  3. $typeoptionvar = DB::fetch_all("SELECT optionid,value FROM %t WHERE tid = %d", array('forum_typeoptionvar', $tid));
  4. //取出含數字字符串中最大的數字
  5. function extractMaxNumber($str) {
  6.   $maxNumber = '';
  7.   $isNumber = false;
  8.   for ($i = 0; $i < strlen($str); $i++) {
  9.     if (is_numeric($str[$i])) {
  10.       if (!$isNumber) {
  11.         $maxNumber = $str[$i];
  12.         $isNumber = true;
  13.       } else {
  14.         $maxNumber .= $str[$i];
  15.       }
  16.     } else {
  17.       $isNumber = false;
  18.     }
  19.   }
  20.   return (int) $maxNumber;
  21. }
  22. //$typeoption的[rules],$choices分割成數組
  23. foreach ($typeoption as $keys => $types) {
  24.   if (strpos($types[rules], 'choices') !== false) {//$typeoption找出選擇和多選的rules
  25.     $choices[$keys][rules]=$types[rules];
  26.     $optionids[$keys]=$types[optionid];
  27.     $optionids=array_values($optionids);
  28.     $choices[$keys][rules]=strstr($choices[$keys][rules],'1 = ');
  29.     $choices[$keys][rules]=strstr($choices[$keys][rules],'"',true);//把數組截取
  30.       for($i=1;$i<=extractMaxNumber($choices[$keys][rules]);$i++){
  31.         $choices[$keys][rules]=str_replace("$i = ", ",$i=", $choices[$keys][rules]);
  32.       }
  33.     $choices[$keys][rules]=substr($choices[$keys][rules],1);//去除第一個字符
  34.     $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數組
  35.     $typeoption[$keys][rules]=$choices[$keys][rules];
  36.   }
  37. }

  38. //$typeoptionvar,$optionids數組里的$choice分割成數組并替換
  39. foreach ($typeoptionvar as $key => $type){
  40.   if (in_array($type[optionid], $optionids)){
  41.     $choice[$key][rules]=$type[value];
  42.       for($i=1;$i<=extractMaxNumber($choice[$key][rules]);$i++){
  43.         $choice[$key][rules]=preg_replace('/\s+/','', $choice[$key][rules]);
  44.       }
  45.     $choice[$key][rules]=str_split($choice[$key][rules]);
  46.     //把$choice最底層數組含數字元素替換成對應的$choices含有數字的元素并去除數字和=
  47.     foreach($choice[$key][rules] as $tion => $rule){
  48.       foreach($choices[$key][rules] as $tions => $rules){
  49.         if (strpos($rules, "$rule") !== false) {
  50.           $choice[$key][rules][$tion]=$choices[$key][rules][$choice[$key][rules][$tion]-1];
  51.         }
  52.       }
  53.       for($i=1;$i<=extractMaxNumber($choice[$key][rules][$tion]);$i++){
  54.         $choice[$key][rules][$tion]=str_replace("$i=", " ", $choice[$key][rules][$tion]);
  55.       }
  56.       
  57.       
  58.     }
  59.     $choice[$key][rules]=implode(" ", $choice[$key][rules]);
  60.     $typeoptionvar[$key][value]=$choice[$key][rules];
  61.   }
  62. }
復制代碼


回復

使用道具 舉報

2

主題

19

回帖

24

積分

初學乍練

貢獻
0 點
金幣
0 個
22#
 樓主| 發表于 2023-10-6 10:33:52 | 只看Ta
改進了一下,并把圖片的雜亂碼去掉
  1. //取出含數字字符串中最大的數字
  2. function extractMaxNumber($str) {
  3.   $maxNumber = '';
  4.   $isNumber = false;
  5.   for ($i = 0; $i < strlen($str); $i++) {
  6.     if (is_numeric($str[$i])) {
  7.       if (!$isNumber) {
  8.         $maxNumber = $str[$i];
  9.         $isNumber = true;
  10.       } else {
  11.         $maxNumber .= $str[$i];
  12.       }
  13.     } else {
  14.       $isNumber = false;
  15.     }
  16.   }
  17.   return (int) $maxNumber;
  18. }
  19. //$typeoption的[rules],$choices分割成數組
  20. foreach ($typeoption as $keys => $types) {
  21.   if (strpos($types[rules], 'choices') !== false) {//$typeoption找出選擇和多選的rules
  22.     $choices[$keys][rules]=$types[rules];
  23.     $optionids[$keys]=$types[optionid];
  24.     $optionids=array_values($optionids);
  25.     $choices[$keys][rules]=strstr($choices[$keys][rules],'1 = ');
  26.     $choices[$keys][rules]=strstr($choices[$keys][rules],'"',true);//把數組截取
  27.       for($i=1;$i<=extractMaxNumber($choices[$keys][rules]);$i++){
  28.         $choices[$keys][rules]=str_replace("$i = ", ",$i=", $choices[$keys][rules]);
  29.       }
  30.     $choices[$keys][rules]=substr($choices[$keys][rules],1);//去除第一個字符
  31.     $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數組
  32.     $typeoption[$keys][rules]=$choices[$keys][rules];
  33.   }
  34. }

  35. //$typeoptionvar,$optionids數組里的$choice分割成數組并替換
  36. foreach ($typeoptionvar as $key => $type){
  37.   if (in_array($type[optionid], $optionids)){
  38.     $choice[$key][value]=$type[value];
  39.       for($i=1;$i<=extractMaxNumber($choice[$key][value]);$i++){
  40.         $choice[$key][value]=preg_replace('/\s+/','', $choice[$key][value]);
  41.       }
  42.     $choice[$key][value]=str_split($choice[$key][value]);
  43.     //把$choice最底層數組含數字元素替換成對應的$choices含有數字的元素并去除數字和=
  44.     foreach($choice[$key][value] as $tion => $rule){
  45.       foreach($choices[$key][rules] as $tions => $rules){
  46.         if (strpos($rules, "$rule") !== false) {
  47.           $choice[$key][value][$tion]=$choices[$key][rules][$choice[$key][value][$tion]-1];
  48.         }
  49.       }
  50.       for($i=1;$i<=extractMaxNumber($choice[$key][value][$tion]);$i++){
  51.         $choice[$key][value][$tion]=str_replace("$i=", " ", $choice[$key][value][$tion]);
  52.       }   
  53.     }
  54.     $choice[$key][value]=implode(" ", $choice[$key][value]);
  55.     $typeoptionvar[$key][value]=$choice[$key][value];
  56.   }
  57. }

  58. foreach ($typeoptionvar as $key => $type) {
  59.     if (strpos($type[value], 'data') !== false) {
  60.         $image[$key][value]=strstr($typeoptionvar[$key][value],'data');
  61.         $image[$key][value]=str_replace('";}','',$image[$key][value]);
  62.         $typeoptionvar[$key][value]=$image[$key][value];
  63.     }
  64. }
復制代碼
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

  • 關注公眾號
  • 有償服務微信
  • 有償服務QQ

手機版|小黑屋|Discuz! 官方交流社區 ( 皖ICP備16010102號 |皖公網安備34010302002376號 )|網站地圖|star

GMT+8, 2025-9-19 02:08 , Processed in 0.071014 second(s), 23 queries .

Powered by Discuz! W1.0 Licensed

Copyright © 2001-2025 Discuz! Team.

關燈 在本版發帖
有償服務QQ
有償服務微信
返回頂部
快速回復 返回頂部 返回列表