3v4l.org

run code in 300+ PHP versions simultaneously
<?php $body = <<<HTML <body class="old_attr"> <div>(content)</div> </body> HTML; $new_class = "new_class_attr"; $body = preg_replace('~<body[^>]*class *= *["\']\K~', "$new_class ", $body, 1, $count); if (!$count) { $body = preg_replace('~<body\K~', " class=\"$new_class\"", $body, 1); } echo $body;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/MVHoY
function name:  (null)
number of ops:  26
compiled vars:  !0 = $body, !1 = $new_class, !2 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Cbody+class%3D%22old_attr%22%3E%0A++++%3Cdiv%3E%28content%29%3C%2Fdiv%3E%0A%3C%2Fbody%3E'
    8     1        ASSIGN                                                   !1, 'new_class_attr'
   10     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%7E%3Cbody%5B%5E%3E%5D%2Aclass+%2A%3D+%2A%5B%22%27%5D%5CK%7E'
          4        NOP                                                      
          5        FAST_CONCAT                                      ~5      !1, '+'
          6        SEND_VAL                                                 ~5
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 1
          9        SEND_REF                                                 !2
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !0, $6
   11    12        BOOL_NOT                                         ~8      !2
         13      > JMPZ                                                     ~8, ->24
   12    14    >   INIT_FCALL                                               'preg_replace'
         15        SEND_VAL                                                 '%7E%3Cbody%5CK%7E'
         16        ROPE_INIT                                     3  ~10     '+class%3D%22'
         17        ROPE_ADD                                      1  ~10     ~10, !1
         18        ROPE_END                                      2  ~9      ~10, '%22'
         19        SEND_VAL                                                 ~9
         20        SEND_VAR                                                 !0
         21        SEND_VAL                                                 1
         22        DO_ICALL                                         $12     
         23        ASSIGN                                                   !0, $12
   14    24    >   ECHO                                                     !0
   15    25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.23 ms | 1399 KiB | 15 Q