3v4l.org

run code in 500+ PHP versions simultaneously
<?php $text = <<<TEXT == My Subheading == === My sub Subheading === ==== another heading ==== TEXT; class ContentParser { private $patterns = []; private $replacements = []; public function __construct() { $this->patterns = [ // Headings "/^==== (.+?) ====\h*$/m", "/^=== (.+?) ===\h*$/m", "/^== (.+?) ==\h*$/m", ]; $this->replacements = [ // Headings "<h3>$1</h3>", "<h2>$1</h2>", "<h1>$1</h1>", ]; } public function parse($input) { if (!empty($input)) { $output = preg_replace($this->patterns, $this->replacements, $input); } else { $output = false; // I don't recommend returning a boolean when otherwise returning strings } return $output; } } $object = new ContentParser(); var_export($object->parse($text));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iuUa4
function name:  (null)
number of ops:  11
compiled vars:  !0 = $text, !1 = $object
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3D%3D+My+Subheading+%3D%3D+%0A%3D%3D%3D+My+sub+Subheading+%3D%3D%3D%0A%3D%3D%3D%3D+another+heading+%3D%3D%3D%3D'
   39     1        NEW                                                  $3      'ContentParser'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $3
   40     4        INIT_FCALL                                                   'var_export'
          5        INIT_METHOD_CALL                                             !1, 'parse'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0  $6      
          8        SEND_VAR                                                     $6
          9        DO_ICALL                                                     
         10      > RETURN                                                       1

Class ContentParser:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iuUa4
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   ASSIGN_OBJ                                                   'patterns'
   17     1        OP_DATA                                                      <array>
   21     2        ASSIGN_OBJ                                                   'replacements'
   23     3        OP_DATA                                                      <array>
   28     4      > RETURN                                                       null

End of function __construct

Function parse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iuUa4
function name:  parse
number of ops:  13
compiled vars:  !0 = $input, !1 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   RECV                                                 !0      
   30     1        ISSET_ISEMPTY_CV                                     ~2      !0
          2        BOOL_NOT                                             ~3      ~2
          3      > JMPZ                                                         ~3, ->10
   31     4    >   FETCH_OBJ_R                                          ~4      'patterns'
          5        FETCH_OBJ_R                                          ~5      'replacements'
          6        FRAMELESS_ICALL_3                preg_replace        ~6      ~4, ~5
          7        OP_DATA                                                      !0
          8        ASSIGN                                                       !1, ~6
   30     9      > JMP                                                          ->11
   33    10    >   ASSIGN                                                       !1, <false>
   35    11    > > RETURN                                                       !1
   36    12*     > RETURN                                                       null

End of function parse

End of class ContentParser.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.45 ms | 1984 KiB | 14 Q