3v4l.org

run code in 500+ PHP versions simultaneously
<?php $input = <<<INPUT <p>Foo?</p> [[{ &quot;fid&quot;:&quot;123456&quot;,&quot;view_mode&quot;:&quot;default&quot;,&quot;type&quot;:&quot;media&quot;,&quot;attributes&quot;:{ &quot;class&quot;:&quot;css-class1 css-class2 css-class3&quot; ,&quot;alt&quot;:&quot;Overridden alt attribute for embed&quot; ,&quot;title&quot;:&quot;Overridden title attribute for embed&quot; }, &quot;fields&quot;:{ &quot;format&quot;:&quot;default&quot; ,&quot;alt&quot;:&quot;Overridden alt attribute for embed&quot;,&quot;field_file_image_alt_text[und][0][value]&quot;:&quot;Media alt attribute&quot; ,&quot;title&quot;:&quot;Overridden title attribute for embed&quot;,&quot;field_file_image_title_text[und][0][value]&quot;:&quot;Media title attribute&quot;} }]] <p>Bar baz!</p> INPUT; $pattern = '/\[\[\s*(?<tag_info>\{.+\})\s*\]\]/sU'; $matches = []; var_dump(preg_match($pattern, $input, $matches)); var_dump($matches); $tag_info = $matches['tag_info']; var_dump('BEFORE'); var_dump(json_decode($tag_info)); function fix(string $parsed_potentially_broken_json): string { $r = str_replace("\n", " ", $parsed_potentially_broken_json); // This is what \Drupal\Component\Utility\Html::decodeEntities() does. return html_entity_decode($r, ENT_QUOTES, 'UTF-8'); } var_dump('AFTER'); var_dump(json_decode(fix($tag_info)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cD86J
function name:  (null)
number of ops:  38
compiled vars:  !0 = $input, !1 = $pattern, !2 = $matches, !3 = $tag_info
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cp%3EFoo%3F%3C%2Fp%3E%0A%5B%5B%7B+%26quot%3Bfid%26quot%3B%3A%26quot%3B123456%26quot%3B%2C%26quot%3Bview_mode%26quot%3B%3A%26quot%3Bdefault%26quot%3B%2C%26quot%3Btype%26quot%3B%3A%26quot%3Bmedia%26quot%3B%2C%26quot%3Battributes%26quot%3B%3A%7B+%26quot%3Bclass%26quot%3B%3A%26quot%3Bcss-class1%0Acss-class2+css-class3%26quot%3B+%2C%26quot%3Balt%26quot%3B%3A%26quot%3BOverridden+alt+attribute+for+embed%26quot%3B+%2C%26quot%3Btitle%26quot%3B%3A%26quot%3BOverridden+title+attribute+for+embed%26quot%3B+%7D%2C%0A%26quot%3Bfields%26quot%3B%3A%7B+%26quot%3Bformat%26quot%3B%3A%26quot%3Bdefault%26quot%3B+%2C%26quot%3Balt%26quot%3B%3A%26quot%3BOverridden+alt+attribute+for+embed%26quot%3B%2C%26quot%3Bfield_file_image_alt_text%5Bund%5D%5B0%5D%5Bvalue%5D%26quot%3B%3A%26quot%3BMedia+alt+attribute%26quot%3B+%2C%26quot%3Btitle%26quot%3B%3A%26quot%3BOverridden+title+attribute+for+embed%26quot%3B%2C%26quot%3Bfield_file_image_title_text%5Bund%5D%5B0%5D%5Bvalue%5D%26quot%3B%3A%26quot%3BMedia+title+attribute%26quot%3B%7D+%7D%5D%5D%0A%3Cp%3EBar+baz%21%3C%2Fp%3E'
   11     1        ASSIGN                                                       !1, '%2F%5C%5B%5C%5B%5Cs%2A%28%3F%3Ctag_info%3E%5C%7B.%2B%5C%7D%29%5Cs%2A%5C%5D%5C%5D%2FsU'
   12     2        ASSIGN                                                       !2, <array>
   13     3        INIT_FCALL                                                   'var_dump'
          4        INIT_FCALL                                                   'preg_match'
          5        SEND_VAR                                                     !1
          6        SEND_VAR                                                     !0
          7        SEND_REF                                                     !2
          8        DO_ICALL                                             $7      
          9        SEND_VAR                                                     $7
         10        DO_ICALL                                                     
   14    11        INIT_FCALL                                                   'var_dump'
         12        SEND_VAR                                                     !2
         13        DO_ICALL                                                     
   16    14        FETCH_DIM_R                                          ~10     !2, 'tag_info'
         15        ASSIGN                                                       !3, ~10
   18    16        INIT_FCALL                                                   'var_dump'
         17        SEND_VAL                                                     'BEFORE'
         18        DO_ICALL                                                     
   19    19        INIT_FCALL                                                   'var_dump'
         20        INIT_FCALL                                                   'json_decode'
         21        SEND_VAR                                                     !3
         22        DO_ICALL                                             $13     
         23        SEND_VAR                                                     $13
         24        DO_ICALL                                                     
   28    25        INIT_FCALL                                                   'var_dump'
         26        SEND_VAL                                                     'AFTER'
         27        DO_ICALL                                                     
   29    28        INIT_FCALL                                                   'var_dump'
         29        INIT_FCALL                                                   'json_decode'
         30        INIT_FCALL                                                   'fix'
         31        SEND_VAR                                                     !3
         32        DO_FCALL                                          0  $16     
         33        SEND_VAR                                                     $16
         34        DO_ICALL                                             $17     
         35        SEND_VAR                                                     $17
         36        DO_ICALL                                                     
         37      > RETURN                                                       1

Function fix:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cD86J
function name:  fix
number of ops:  13
compiled vars:  !0 = $parsed_potentially_broken_json, !1 = $r
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
   23     1        FRAMELESS_ICALL_3                str_replace         ~2      '%0A', '+'
          2        OP_DATA                                                      !0
          3        ASSIGN                                                       !1, ~2
   25     4        INIT_FCALL                                                   'html_entity_decode'
          5        SEND_VAR                                                     !1
          6        SEND_VAL                                                     3
          7        SEND_VAL                                                     'UTF-8'
          8        DO_ICALL                                             $4      
          9        VERIFY_RETURN_TYPE                                           $4
         10      > RETURN                                                       $4
   26    11*       VERIFY_RETURN_TYPE                                           
         12*     > RETURN                                                       null

End of function fix

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.22 ms | 489 KiB | 12 Q