0

私はこのようなコードを持っています

            error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); 
            function multiexplode ($delimiters,$string) {
                $ready = str_replace($delimiters, $delimiters[0], $string);
                $launch = explode($delimiters[0], $ready);
                return  $launch;
            }
            function my_replace($srch, $replace, $subject, $skip=1){
                $subject = explode($srch, $subject.' ', $skip+1);
                $subject[$skip] = str_replace($srch, $replace, $subject[$skip]);
                while (($tmp = array_pop($subject)) == '');
                $subject[]=$tmp;
                return implode($srch, $subject);
            }
            function replace_element($str,$search,$replace,$num) {
                $num = $num - 1;
                $pieces = explode(',',$str);
                if($pieces[$num] == $search) {
                    $pieces[$num] = $replace;
                }
                return implode(',',$pieces);
            } 
            function returnFormat($template, $subject){
                preg_match_all("/\|/", $template, $matches, PREG_OFFSET_CAPTURE);
                foreach($matches[0] as $v) $subject = substr_replace($subject, "|", $v[1], 1);
                return $subject;
                }   

                $replace = "|";
                $pattern = "\|";

            $string = "101131110|101113110|"; 
            $data = "1020,0000,2022,1023,1024,1025,1024,1025,0000|1020,0000,2022,1023,1027,1025,1024,1025,0000|";
                $char = '3';
                $string = str_replace('|', '', $string);    $positions = array();
                $pos = -1; $b=0; 
                while (($pos = strpos($string, $char, $pos+1)) !== false) {{
                    $positions[] = $pos+1; }

                $result2 = implode(',', $positions);
                $res = explode(',',$result2); 
                $exp = multiexplode(array(",","|"),$data);
                $eyz= my_replace('|', ',', $data, 0);       
                $z=1; $y=1;
                foreach ($res as $val) {
                    $res2[$z]=$val; 
                    $valz = $res2[$z];
                    $z++; 
                    }
                        foreach ($exp as $value) {
                        $exp2[$y]=$value; 
                        $vals = $exp2[$valz];
                        $y++; 
                        } 

                        $items = explode(',',$eyz); 
                        $occurences = array_count_values($items);   
                        $st=$occurences[$vals];
                        $fix=replace_element($eyz,$vals,'JJJJ',$valz);

                preg_match_all("/$pattern/", $data, $matches, PREG_OFFSET_CAPTURE);
                    foreach($matches[0] as $v) $fix = substr_replace($fix, $replace, $v[1], 1);
                    echo "<br/>RESULT : <br/><font color='green'>".$fix."</font>";      
                        $b++;
                }

私はこのような結果を持っています

結果 1 : 1020,0000,2022,1023,JJJJ,1025,1024,1025,0000|1020,0000,2022,1023,1027,1025,1024,1025,0000| 結果 2 : 1020,0000,2022,1023,1024,1025,1024,1025,0000|1020,0000,2022,1023,1027,JJJJ,1024,1025,0000|

ループの結果を組み合わせる方法なので、次のような出力があります。

1020,0000,2022,1023,JJJJ,1025,1024,1025,0000|1020,0000,2022,1023,1027,JJJJ,1024,1025,0000|

前もって感謝します

よろしく、

4

1 に答える 1