3v4l.org

run code in 300+ 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 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 6
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 51
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 6
Branch analysis from position: 37
Branch analysis from position: 6
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 6
Branch analysis from position: 37
Branch analysis from position: 6
filename:       /in/CnSh8
function name:  (null)
number of ops:  55
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                                                      ->35
   11     6    >   INIT_FCALL                                               'strpos'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 '%22'
          9        SEND_VAR                                                 !3
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !1, $11
   12    12        INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !0
         14        SEND_VAR                                                 !3
         15        ADD                                              ~13     !1, 1
         16        SUB                                              ~14     ~13, !3
         17        SEND_VAL                                                 ~14
         18        DO_ICALL                                         $15     
         19        ASSIGN                                                   !5, $15
   13    20      > JMPZ                                                     !4, ->25
   15    21    >   BOOL_NOT                                         ~17     !4
         22        ASSIGN                                                   !4, ~17
   16    23        ASSIGN_OP                                     8          !2, !5
         24      > JMP                                                      ->33
   19    25    >   INIT_FCALL                                               'str_replace'
         26        SEND_VAL                                                 '%2C'
         27        SEND_VAL                                                 '%3B'
         28        SEND_VAR                                                 !5
         29        DO_ICALL                                         $20     
         30        ASSIGN_OP                                     8          !2, $20
   20    31        BOOL_NOT                                         ~22     !4
         32        ASSIGN                                                   !4, ~22
   22    33    >   ADD                                              ~24     !1, 1
         34        ASSIGN                                                   !3, ~24
   10    35    >   BOOL                                             ~26     !1
         36      > JMPNZ                                                    ~26, ->6
   27    37    >   STRLEN                                           ~27     !0
         38        IS_SMALLER                                               !1, ~27
         39      > JMPZ                                                     ~28, ->51
         40    >   INIT_FCALL                                               'str_replace'
         41        SEND_VAL                                                 '%2C'
         42        SEND_VAL                                                 '%3B'
         43        INIT_FCALL                                               'substr'
         44        SEND_VAR                                                 !0
         45        STRLEN                                           ~29     !2
         46        SEND_VAL                                                 ~29
         47        DO_ICALL                                         $30     
         48        SEND_VAR                                                 $30
         49        DO_ICALL                                         $31     
         50        ASSIGN_OP                                     8          !2, $31
   28    51    >   CONCAT                                           ~33     !0, '%0A'
         52        ECHO                                                     ~33
   29    53        ECHO                                                     !2
         54      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.83 ms | 1400 KiB | 19 Q