3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = '1,"4052","B00K6ED81S",,"Bottle, white - 6,5 l, WENKO","Good design!","Bottle, white 6,5 l, WENKO",,,"item","23",23,"23",23,31.22,31.22,,1,,,,0,8,"4",,0,,0,0,,0,,0,0,0,,'; $pos=1; // set $pos to make sure while loop does not end directly. $newstr = ""; $prevPos = 0; $skip = false; // flag to know if replace should be done or not while($pos != false){ $pos = strpos($str, '"', $prevPos); // find " in string after prevPos $part = substr($str, $prevPos, $pos+1-$prevPos); // substring the part (first time it runs it will be '1,"' then '4052"') if($skip){ // if it's between two " (a string) skip the replace //echo "skip " . $part . "\n"; $skip =!$skip; // change the flag $newstr .= $part; }else{ // if it's not in a string do the replace on the $part //echo "!skip " . $part . "\n"; $newstr .= str_replace(",", ";", $part); $skip =!$skip; // change the flag. } $prevPos = $pos+1; // set new $prevPos } // if the loop ends and there is no more " in the string we need to replace , to ; on the rest of the string. // we know the loop ended at strlen($newstr), so that is the $part. if($pos<strlen($str)) $newstr .= str_replace(",", ";", substr($str, strlen($newstr))); echo $str . "\n"; echo $newstr;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 6
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 6
Branch analysis from position: 28
Branch analysis from position: 6
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 6
Branch analysis from position: 28
Branch analysis from position: 6
filename:       /in/CnSh8
function name:  (null)
number of ops:  40
compiled vars:  !0 = $str, !1 = $pos, !2 = $newstr, !3 = $prevPos, !4 = $skip, !5 = $part
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '1%2C%224052%22%2C%22B00K6ED81S%22%2C%2C%22Bottle%2C+white+-+6%2C5+l%2C+WENKO%22%2C%22Good+design%21%22%2C%22Bottle%2C+white+6%2C5+l%2C+WENKO%22%2C%2C%2C%22item%22%2C%2223%22%2C23%2C%2223%22%2C23%2C31.22%2C31.22%2C%2C1%2C%2C%2C%2C0%2C8%2C%224%22%2C%2C0%2C%2C0%2C0%2C%2C0%2C%2C0%2C0%2C0%2C%2C'
    5     1        ASSIGN                                                       !1, 1
    6     2        ASSIGN                                                       !2, ''
    7     3        ASSIGN                                                       !3, 0
    8     4        ASSIGN                                                       !4, <false>
   10     5      > JMP                                                          ->26
   11     6    >   FRAMELESS_ICALL_3                strpos              ~11     !0, '%22'
          7        OP_DATA                                                      !3
          8        ASSIGN                                                       !1, ~11
   12     9        ADD                                                  ~13     !1, 1
         10        SUB                                                  ~14     ~13, !3
         11        FRAMELESS_ICALL_3                substr              ~15     !0, !3
         12        OP_DATA                                                      ~14
         13        ASSIGN                                                       !5, ~15
   13    14      > JMPZ                                                         !4, ->19
   15    15    >   BOOL_NOT                                             ~17     !4
         16        ASSIGN                                                       !4, ~17
   16    17        ASSIGN_OP                                         8          !2, !5
   13    18      > JMP                                                          ->24
   19    19    >   FRAMELESS_ICALL_3                str_replace         ~20     '%2C', '%3B'
         20        OP_DATA                                                      !5
         21        ASSIGN_OP                                         8          !2, ~20
   20    22        BOOL_NOT                                             ~22     !4
         23        ASSIGN                                                       !4, ~22
   22    24    >   ADD                                                  ~24     !1, 1
         25        ASSIGN                                                       !3, ~24
   10    26    >   IS_NOT_EQUAL                                                 !1, <false>
         27      > JMPNZ                                                        ~26, ->6
   27    28    >   STRLEN                                               ~27     !0
         29        IS_SMALLER                                                   !1, ~27
         30      > JMPZ                                                         ~28, ->36
         31    >   STRLEN                                               ~29     !2
         32        FRAMELESS_ICALL_2                substr              ~30     !0, ~29
         33        FRAMELESS_ICALL_3                str_replace         ~31     '%2C', '%3B'
         34        OP_DATA                                                      ~30
         35        ASSIGN_OP                                         8          !2, ~31
   28    36    >   CONCAT                                               ~33     !0, '%0A'
         37        ECHO                                                         ~33
   29    38        ECHO                                                         !2
         39      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.93 ms | 2140 KiB | 13 Q