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; if($str[0]=='"') $str = " " .$str; $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 trim($str) . "\n"; echo trim($newstr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 11
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 11
Branch analysis from position: 33
Branch analysis from position: 11
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 11
Branch analysis from position: 33
Branch analysis from position: 11
Branch analysis from position: 9
filename:       /in/hNLAF
function name:  (null)
number of ops:  47
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, '%221%22%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        FETCH_DIM_R                                          ~10     !0, 0
          5        IS_EQUAL                                                     ~10, '%22'
          6      > JMPZ                                                         ~11, ->9
          7    >   CONCAT                                               ~12     '+', !0
          8        ASSIGN                                                       !0, ~12
    9     9    >   ASSIGN                                                       !4, <false>
   11    10      > JMP                                                          ->31
   12    11    >   FRAMELESS_ICALL_3                strpos              ~15     !0, '%22'
         12        OP_DATA                                                      !3
         13        ASSIGN                                                       !1, ~15
   13    14        ADD                                                  ~17     !1, 1
         15        SUB                                                  ~18     ~17, !3
         16        FRAMELESS_ICALL_3                substr              ~19     !0, !3
         17        OP_DATA                                                      ~18
         18        ASSIGN                                                       !5, ~19
   14    19      > JMPZ                                                         !4, ->24
   16    20    >   BOOL_NOT                                             ~21     !4
         21        ASSIGN                                                       !4, ~21
   17    22        ASSIGN_OP                                         8          !2, !5
   14    23      > JMP                                                          ->29
   20    24    >   FRAMELESS_ICALL_3                str_replace         ~24     '%2C', '%3B'
         25        OP_DATA                                                      !5
         26        ASSIGN_OP                                         8          !2, ~24
   21    27        BOOL_NOT                                             ~26     !4
         28        ASSIGN                                                       !4, ~26
   23    29    >   ADD                                                  ~28     !1, 1
         30        ASSIGN                                                       !3, ~28
   11    31    >   IS_NOT_EQUAL                                                 !1, <false>
         32      > JMPNZ                                                        ~30, ->11
   28    33    >   STRLEN                                               ~31     !0
         34        IS_SMALLER                                                   !1, ~31
         35      > JMPZ                                                         ~32, ->41
         36    >   STRLEN                                               ~33     !2
         37        FRAMELESS_ICALL_2                substr              ~34     !0, ~33
         38        FRAMELESS_ICALL_3                str_replace         ~35     '%2C', '%3B'
         39        OP_DATA                                                      ~34
         40        ASSIGN_OP                                         8          !2, ~35
   29    41    >   FRAMELESS_ICALL_1                trim                ~37     !0
         42        CONCAT                                               ~38     ~37, '%0A'
         43        ECHO                                                         ~38
   30    44        FRAMELESS_ICALL_1                trim                ~39     !2
         45        ECHO                                                         ~39
         46      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
176.3 ms | 3475 KiB | 13 Q