3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sentence = '[html style="font-size: 18px;" dir="ltr"][div style="font-size: 18px;" dir="ltr"][p style="font-weight: bold;"]Hello,[/p][p]You have got a new message from [a href="https://www.example.com/"]Example.com[/a][br][br].You could check your message on [a href="https://www.example.com/en/manager/inbox.html"]Manager[/a][/p][p][img src="https://www.example.com/assets/images/logo-default-120x50.png" width="120px" height="80px"][div style="color: #D4192D; font-weight: bold;"]Example.com Team[/div][/p][/div][/html]'; // proceed to the replacement of all self-closing tags first $result = preg_replace('~\[ (br|hr|img)\b ([^]]*) ]~xi', '<$1$2/>', $sentence); // then replace the innermost tags until there's nothing to replace $count = 0; do { $result = preg_replace('~ \[ ( (\w+) [^]]* ) ] # opening tag ( [^[]*+ ) # content without other bracketed tags \[/ \2 ] # closing tag ~xi', '<$1>$3</$2>', $result, -1, $count); } while ($count); echo $result;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/tqEkH
function name:  (null)
number of ops:  19
compiled vars:  !0 = $sentence, !1 = $result, !2 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5Bhtml+style%3D%22font-size%3A+18px%3B%22+dir%3D%22ltr%22%5D%5Bdiv+style%3D%22font-size%3A+18px%3B%22+dir%3D%22ltr%22%5D%5Bp+style%3D%22font-weight%3A+bold%3B%22%5DHello%2C%5B%2Fp%5D%5Bp%5DYou+have+got+a+new+message+from+%5Ba+href%3D%22https%3A%2F%2Fwww.example.com%2F%22%5DExample.com%5B%2Fa%5D%5Bbr%5D%5Bbr%5D.You+could+check+your+message+on+%5Ba+href%3D%22https%3A%2F%2Fwww.example.com%2Fen%2Fmanager%2Finbox.html%22%5DManager%5B%2Fa%5D%5B%2Fp%5D%5Bp%5D%5Bimg+src%3D%22https%3A%2F%2Fwww.example.com%2Fassets%2Fimages%2Flogo-default-120x50.png%22+width%3D%22120px%22+height%3D%2280px%22%5D%5Bdiv+style%3D%22color%3A+%23D4192D%3B+font-weight%3A+bold%3B%22%5DExample.com+Team%5B%2Fdiv%5D%5B%2Fp%5D%5B%2Fdiv%5D%5B%2Fhtml%5D'
    6     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%7E%5C%5B+%28br%7Chr%7Cimg%29%5Cb+%28%5B%5E%5D%5D%2A%29+%5D%7Exi'
          3        SEND_VAL                                                 '%3C%241%242%2F%3E'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !1, $4
   10     7        ASSIGN                                                   !2, 0
   12     8    >   INIT_FCALL                                               'preg_replace'
          9        SEND_VAL                                                 '%7E%0A++++++++%5C%5B+%28+%28%5Cw%2B%29+%5B%5E%5D%5D%2A+%29+%5D+++++%23+opening+tag%0A++++++++%28+%5B%5E%5B%5D%2A%2B+%29+++++++++++++++%23+content+without+other+bracketed+tags%0A++++++++%5C%5B%2F+%5C2+%5D+++++++++++++++++%23+closing+tag%0A++++%7Exi'
   16    10        SEND_VAL                                                 '%3C%241%3E%243%3C%2F%242%3E'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 -1
         13        SEND_REF                                                 !2
   12    14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !1, $7
   17    16      > JMPNZ                                                    !2, ->8
   19    17    >   ECHO                                                     !1
   20    18      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
260.67 ms | 1011 KiB | 14 Q