|
20#
樓主 |
發表于 2023-10-6 09:36:52
|
只看Ta
roc29a 發表于 2023-10-6 09:34
$typeoption = DB::fetch_all("SELECT optionid,rules FROM %t WHERE optionid > %d", array('forum_typeo ... - <!-- forum_typeoption表中所有1 = xx 2 = yy 3 = zz更改為 [rules]xx yy zz -->
- $typeoption = DB::fetch_all("SELECT optionid,rules FROM %t WHERE optionid > %d", array('forum_typeoption', 6));
- $typeoptionvar = DB::fetch_all("SELECT optionid,value FROM %t WHERE tid = %d", array('forum_typeoptionvar', $tid));
- //取出含數字字符串中最大的數字
- function extractMaxNumber($str) {
- $maxNumber = '';
- $isNumber = false;
- for ($i = 0; $i < strlen($str); $i++) {
- if (is_numeric($str[$i])) {
- if (!$isNumber) {
- $maxNumber = $str[$i];
- $isNumber = true;
- } else {
- $maxNumber .= $str[$i];
- }
- } else {
- $isNumber = false;
- }
- }
- return (int) $maxNumber;
- }
- //$typeoption的[rules],$choices分割成數組
- foreach ($typeoption as $keys => $types) {
- if (strpos($types[rules], 'choices') !== false) {//$typeoption找出選擇和多選的rules
- $choices[$keys][rules]=$types[rules];
- $optionids[$keys]=$types[optionid];
- $optionids=array_values($optionids);
- $choices[$keys][rules]=strstr($choices[$keys][rules],'1 = ');
- $choices[$keys][rules]=strstr($choices[$keys][rules],'"',true);//把數組截取
- for($i=1;$i<=extractMaxNumber($choices[$keys][rules]);$i++){
- $choices[$keys][rules]=str_replace("$i = ", ",$i=", $choices[$keys][rules]);
- }
- $choices[$keys][rules]=substr($choices[$keys][rules],1);//去除第一個字符
- $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數組
- $typeoption[$keys][rules]=$choices[$keys][rules];
- }
- }
- //$typeoptionvar,$optionids數組里的$choice分割成數組并替換
- foreach ($typeoptionvar as $key => $type){
- if (in_array($type[optionid], $optionids)){
- $choice[$key][rules]=$type[value];
- for($i=1;$i<=extractMaxNumber($choice[$key][rules]);$i++){
- $choice[$key][rules]=preg_replace('/\s+/','', $choice[$key][rules]);
- }
- $choice[$key][rules]=str_split($choice[$key][rules]);
- //把$choice最底層數組含數字元素替換成對應的$choices含有數字的元素并去除數字和=
- foreach($choice[$key][rules] as $tion => $rule){
- foreach($choices[$key][rules] as $tions => $rules){
- if (strpos($rules, "$rule") !== false) {
- $choice[$key][rules][$tion]=$choices[$key][rules][$choice[$key][rules][$tion]-1];
- }
- }
- for($i=1;$i<=extractMaxNumber($choice[$key][rules][$tion]);$i++){
- $choice[$key][rules][$tion]=str_replace("$i=", " ", $choice[$key][rules][$tion]);
- }
-
-
- }
- $choice[$key][rules]=implode(" ", $choice[$key][rules]);
- $typeoptionvar[$key][value]=$choice[$key][rules];
- }
- }
復制代碼 |
|