3v4l.org

run code in 500+ PHP versions simultaneously
<?php $bbcode = <<<BBCODE [b]Check out this demo[/b] ¯\_(ツ)_/¯ [table] [**]header1[||]header2[||]header3[||]...[/**] [*]child1.1[|]child1.2[|]child1.3[|]... [*]child2.1[|]child2.2[|]child2.3[|]... [*]child3.1[|]child3.2[|]child3.3[|]... [*]...[|]...[|]...[|]... [/table] simple text [table] [**]a 1[||]and a 2[/**] [*]A[|]B [*]C[|]D [/table] [s]3, you're out[/s] blah BBCODE; function BBTableToHTML($m) { return "<table class=\"ui compact stripet yellow table\">\n" . preg_replace_callback_array( [ '~\[\*\*]([^[]*(?:\[(?!/?\*\*])[^[]*)*)\[/\*\*]~' => 'BBTHeadToHTML', '~(?:\[\*].*\R*)+~' => 'BBTBodyToHTML', '~\[\*](.*)~' => 'BBTBodyRowToHTML' ], $m[1] ) . "</table>"; } function BBTHeadToHTML($m) { return "\t<thead>\n" . "\t\t<tr>\n\t\t\t<th>" . str_replace('[||]', "</th>\n\t\t\t<th>", $m[1]) . "</th>\n\t\t</tr>\n" . "\t</thead>"; } function BBTBodyToHTML($m) { return "\t<tbody>\n{$m[0]}\t</tbody>\n"; } function BBTBodyRowToHTML($m) { return "\t\t<tr>\n\t\t\t<td>" . str_replace('[|]', "</td>\n\t\t\t<td>", $m[1]) . "</td>\n\t\t</tr>"; } echo preg_replace_callback( '~\[table]\R*([^[]*(?:\[(?!/?table])[^[]*)*)\R*\[/table]~', 'BBTableToHTML', $bbcode );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/77snX
function name:  (null)
number of ops:  8
compiled vars:  !0 = $bbcode
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%5Bb%5DCheck+out+this+demo%5B%2Fb%5D%0A%C2%AF%5C_%28%E3%83%84%29_%2F%C2%AF%0A%5Btable%5D%0A%5B%2A%2A%5Dheader1%5B%7C%7C%5Dheader2%5B%7C%7C%5Dheader3%5B%7C%7C%5D...%5B%2F%2A%2A%5D%0A%5B%2A%5Dchild1.1%5B%7C%5Dchild1.2%5B%7C%5Dchild1.3%5B%7C%5D...%0A%5B%2A%5Dchild2.1%5B%7C%5Dchild2.2%5B%7C%5Dchild2.3%5B%7C%5D...%0A%5B%2A%5Dchild3.1%5B%7C%5Dchild3.2%5B%7C%5Dchild3.3%5B%7C%5D...%0A%5B%2A%5D...%5B%7C%5D...%5B%7C%5D...%5B%7C%5D...%0A%5B%2Ftable%5D%0Asimple+text%0A%5Btable%5D%0A%5B%2A%2A%5Da+1%5B%7C%7C%5Dand+a+2%5B%2F%2A%2A%5D%0A%5B%2A%5DA%5B%7C%5DB%0A%5B%2A%5DC%5B%7C%5DD%0A%5B%2Ftable%5D%0A%0A%5Bs%5D3%2C+you%27re+out%5B%2Fs%5D%0Ablah'
   51     1        INIT_FCALL                                                   'preg_replace_callback'
   52     2        SEND_VAL                                                     '%7E%5C%5Btable%5D%5CR%2A%28%5B%5E%5B%5D%2A%28%3F%3A%5C%5B%28%3F%21%2F%3Ftable%5D%29%5B%5E%5B%5D%2A%29%2A%29%5CR%2A%5C%5B%2Ftable%5D%7E'
   53     3        SEND_VAL                                                     'BBTableToHTML'
   54     4        SEND_VAR                                                     !0
   51     5        DO_ICALL                                             $2      
   54     6        ECHO                                                         $2
   55     7      > RETURN                                                       1

Function bbtabletohtml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/77snX
function name:  BBTableToHTML
number of ops:  10
compiled vars:  !0 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
   26     1        INIT_FCALL                                                   'preg_replace_callback_array'
   28     2        SEND_VAL                                                     <array>
   32     3        FETCH_DIM_R                                          ~1      !0, 1
          4        SEND_VAL                                                     ~1
   26     5        DO_ICALL                                             $2      
   32     6        CONCAT                                               ~3      '%3Ctable+class%3D%22ui+compact+stripet+yellow+table%22%3E%0A', $2
   34     7        CONCAT                                               ~4      ~3, '%3C%2Ftable%3E'
          8      > RETURN                                                       ~4
   35     9*     > RETURN                                                       null

End of function bbtabletohtml

Function bbtheadtohtml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/77snX
function name:  BBTHeadToHTML
number of ops:  9
compiled vars:  !0 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   RECV                                                 !0      
   39     1        FETCH_DIM_R                                          ~1      !0, 1
          2        FRAMELESS_ICALL_3                str_replace         ~2      '%5B%7C%7C%5D', '%3C%2Fth%3E%0A%09%09%09%3Cth%3E'
          3        OP_DATA                                                      ~1
          4        CONCAT                                               ~3      '%09%3Cthead%3E%0A%09%09%3Ctr%3E%0A%09%09%09%3Cth%3E', ~2
          5        CONCAT                                               ~4      ~3, '%3C%2Fth%3E%0A%09%09%3C%2Ftr%3E%0A'
   40     6        CONCAT                                               ~5      ~4, '%09%3C%2Fthead%3E'
          7      > RETURN                                                       ~5
   41     8*     > RETURN                                                       null

End of function bbtheadtohtml

Function bbtbodytohtml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/77snX
function name:  BBTBodyToHTML
number of ops:  7
compiled vars:  !0 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   RECV                                                 !0      
   44     1        ROPE_INIT                                         3  ~3      '%09%3Ctbody%3E%0A'
          2        FETCH_DIM_R                                          ~1      !0, 0
          3        ROPE_ADD                                          1  ~3      ~3, ~1
          4        ROPE_END                                          2  ~2      ~3, '%09%3C%2Ftbody%3E%0A'
          5      > RETURN                                                       ~2
   45     6*     > RETURN                                                       null

End of function bbtbodytohtml

Function bbtbodyrowtohtml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/77snX
function name:  BBTBodyRowToHTML
number of ops:  8
compiled vars:  !0 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   47     0  E >   RECV                                                 !0      
   48     1        FETCH_DIM_R                                          ~1      !0, 1
          2        FRAMELESS_ICALL_3                str_replace         ~2      '%5B%7C%5D', '%3C%2Ftd%3E%0A%09%09%09%3Ctd%3E'
          3        OP_DATA                                                      ~1
          4        CONCAT                                               ~3      '%09%09%3Ctr%3E%0A%09%09%09%3Ctd%3E', ~2
          5        CONCAT                                               ~4      ~3, '%3C%2Ftd%3E%0A%09%09%3C%2Ftr%3E'
          6      > RETURN                                                       ~4
   49     7*     > RETURN                                                       null

End of function bbtbodyrowtohtml

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
170.69 ms | 2335 KiB | 15 Q