3v4l.org

run code in 300+ PHP versions simultaneously
<?php // stackoverflow.com/questions/20348380 function fixJSON($json) { $regex = <<<'REGEX' ~ "[^"\\]*(?:\\.|[^"\\]*)*" (*SKIP)(*F) | '([^'\\]*(?:\\.|[^'\\]*)*)' ~x REGEX; return preg_replace_callback($regex, function($matches) { return '"' . preg_replace('~\\\\.(*SKIP)(*F)|"~', '\\"', $matches[1]) . '"'; }, $json); } $json = "{'id': '3', 'answer': '1'},{'id': '4', 'answer': 'здесь ответ на вопрос, 12345 abc'},{'id': '4', 'answer': '123'}"; $obj = json_decode(fixJSON("[$json]")); foreach ($obj as $key=>$val) { echo "$val->answer\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/YhZNp
function name:  (null)
number of ops:  21
compiled vars:  !0 = $json, !1 = $obj, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                   !0, '%7B%27id%27%3A+%273%27%2C+%27answer%27%3A+%271%27%7D%2C%7B%27id%27%3A+%274%27%2C+%27answer%27%3A+%27%D0%B7%D0%B4%D0%B5%D1%81%D1%8C+%D0%BE%D1%82%D0%B2%D0%B5%D1%82+%D0%BD%D0%B0+%D0%B2%D0%BE%D0%BF%D1%80%D0%BE%D1%81%2C+12345+abc%27%7D%2C%7B%27id%27%3A+%274%27%2C+%27answer%27%3A+%27123%27%7D'
   19     1        INIT_FCALL                                               'json_decode'
          2        INIT_FCALL                                               'fixjson'
          3        ROPE_INIT                                     3  ~6      '%5B'
          4        ROPE_ADD                                      1  ~6      ~6, !0
          5        ROPE_END                                      2  ~5      ~6, '%5D'
          6        SEND_VAL                                                 ~5
          7        DO_FCALL                                      0  $8      
          8        SEND_VAR                                                 $8
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !1, $9
   20    11      > FE_RESET_R                                       $11     !1, ->19
         12    > > FE_FETCH_R                                       ~12     $11, !2, ->19
         13    >   ASSIGN                                                   !3, ~12
   21    14        FETCH_OBJ_R                                      ~14     !2, 'answer'
         15        NOP                                                      
         16        FAST_CONCAT                                      ~15     ~14, '%0A'
         17        ECHO                                                     ~15
   20    18      > JMP                                                      ->12
         19    >   FE_FREE                                                  $11
   22    20      > RETURN                                                   1

Function fixjson:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YhZNp
function name:  fixJSON
number of ops:  10
compiled vars:  !0 = $json, !1 = $regex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, '%7E%0A++++%22%5B%5E%22%5C%5C%5D%2A%28%3F%3A%5C%5C.%7C%5B%5E%22%5C%5C%5D%2A%29%2A%22%0A++++%28%2ASKIP%29%28%2AF%29%0A++%7C+%27%28%5B%5E%27%5C%5C%5D%2A%28%3F%3A%5C%5C.%7C%5B%5E%27%5C%5C%5D%2A%29%2A%29%27%0A%7Ex'
   13     2        INIT_FCALL                                               'preg_replace_callback'
          3        SEND_VAR                                                 !1
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FYhZNp%3A13%240'
   15     5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
   16     9*     > RETURN                                                   null

End of function fixjson

Function %00%7Bclosure%7D%2Fin%2FYhZNp%3A13%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YhZNp
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%7E%5C%5C.%28%2ASKIP%29%28%2AF%29%7C%22%7E'
          3        SEND_VAL                                                 '%5C%22'
          4        FETCH_DIM_R                                      ~1      !0, 1
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                         $2      
          7        CONCAT                                           ~3      '%22', $2
          8        CONCAT                                           ~4      ~3, '%22'
          9      > RETURN                                                   ~4
   15    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FYhZNp%3A13%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.97 ms | 1402 KiB | 20 Q