- 積分
- 24
- 金幣
- 0 個(gè)
- 社區(qū)幣
- 0 元
初學(xué)乍練
- 貢獻(xiàn)
- 0 點(diǎn)
- 金幣
- 0 個(gè)
|
改進(jìn)了一下,并把圖片的雜亂碼去掉
- //取出含數(shù)字字符串中最大的數(shù)字
- 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分割成數(shù)組
- 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);//把數(shù)組截取
- 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);//去除第一個(gè)字符
- $choices[$keys][rules]=explode(",",$choices[$keys][rules]);//字符串分割成數(shù)組
- $typeoption[$keys][rules]=$choices[$keys][rules];
- }
- }
- //$typeoptionvar,$optionids數(shù)組里的$choice分割成數(shù)組并替換
- foreach ($typeoptionvar as $key => $type){
- if (in_array($type[optionid], $optionids)){
- $choice[$key][value]=$type[value];
- for($i=1;$i<=extractMaxNumber($choice[$key][value]);$i++){
- $choice[$key][value]=preg_replace('/\s+/','', $choice[$key][value]);
- }
- $choice[$key][value]=str_split($choice[$key][value]);
- //把$choice最底層數(shù)組含數(shù)字元素替換成對應(yīng)的$choices含有數(shù)字的元素并去除數(shù)字和=
- foreach($choice[$key][value] as $tion => $rule){
- foreach($choices[$key][rules] as $tions => $rules){
- if (strpos($rules, "$rule") !== false) {
- $choice[$key][value][$tion]=$choices[$key][rules][$choice[$key][value][$tion]-1];
- }
- }
- for($i=1;$i<=extractMaxNumber($choice[$key][value][$tion]);$i++){
- $choice[$key][value][$tion]=str_replace("$i=", " ", $choice[$key][value][$tion]);
- }
- }
- $choice[$key][value]=implode(" ", $choice[$key][value]);
- $typeoptionvar[$key][value]=$choice[$key][value];
- }
- }
- foreach ($typeoptionvar as $key => $type) {
- if (strpos($type[value], 'data') !== false) {
- $image[$key][value]=strstr($typeoptionvar[$key][value],'data');
- $image[$key][value]=str_replace('";}','',$image[$key][value]);
- $typeoptionvar[$key][value]=$image[$key][value];
- }
- }
復(fù)制代碼 |
|