3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CI_Parser { /** * Left delimeter character for psuedo vars * * @var string */ public $l_delim = '{'; /** * Right delimeter character for psuedo vars * * @var string */ public $r_delim = '}'; /** * Reference to CodeIgniter instance * * @var object */ protected $CI; // -------------------------------------------------------------------- /** * Class constructor * * @return void */ public function __construct() { $this->CI =& get_instance(); } // -------------------------------------------------------------------- /** * Parse a template * * Parses pseudo-variables contained in the specified template view, * replacing them with the data in the second param * * @param string * @param array * @param bool * @return string */ public function parse($template, $data, $return = FALSE) { $template = $this->CI->load->view($template, $data, TRUE); return $this->_parse($template, $data, $return); } // -------------------------------------------------------------------- /** * Parse a String * * Parses pseudo-variables contained in the specified string, * replacing them with the data in the second param * * @param string * @param array * @param bool * @return string */ public function parse_string($template, $data, $return = FALSE) { return $this->_parse($template, $data, $return); } // -------------------------------------------------------------------- /** * Parse a template * * Parses pseudo-variables contained in the specified template, * replacing them with the data in the second param * * @param string * @param array * @param bool * @return string */ protected function _parse($template, $data, $return = FALSE) { if ($template === '') { return FALSE; } foreach ($data as $key => $val) { $template = is_array($val) ? $this->_parse_pair($key, $val, $template) : $template = $this->_parse_single($key, (string) $val, $template); } if ($return === FALSE) { $this->CI->output->append_output($template); } return $template; } // -------------------------------------------------------------------- /** * Set the left/right variable delimiters * * @param string * @param string * @return void */ public function set_delimiters($l = '{', $r = '}') { $this->l_delim = $l; $this->r_delim = $r; } // -------------------------------------------------------------------- /** * Parse a single key/value * * @param string * @param string * @param string * @return string */ protected function _parse_single($key, $val, $string) { return str_replace($this->l_delim.$key.$this->r_delim, (string) $val, $string); } // -------------------------------------------------------------------- /** * Parse a tag pair * * Parses tag pairs: {some_tag} string... {/some_tag} * * @param string * @param array * @param string * @return string */ protected function _parse_pair($variable, $data, $string) { if (FALSE === ($match = $this->_match_pair($string, $variable))) { return $string; } $str = ''; foreach ($data as $row) { $temp = $match[1]; foreach ($row as $key => $val) { $temp = is_array($val) ? $this->_parse_pair($key, $val, $temp) : $this->_parse_single($key, $val, $temp); } $str .= $temp; } return str_replace($match[0], $str, $string); } // -------------------------------------------------------------------- /** * Matches a variable pair * * @param string * @param string * @return mixed */ protected function _match_pair($string, $variable) { return preg_match('|'.preg_quote($this->l_delim).$variable.preg_quote($this->r_delim).'(.+?)'.preg_quote($this->l_delim).'/'.$variable.preg_quote($this->r_delim).'|s', $string, $match) ? $match : FALSE; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RI6v7
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  192     0  E > > RETURN                                                   1

Class CI_Parser:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RI6v7
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL_BY_NAME                                       'get_instance'
          1        DO_FCALL                                      0  $1      
          2        MAKE_REF                                         $2      $1
          3        ASSIGN_OBJ_REF                                           'CI'
          4        OP_DATA                                                  $2
   35     5      > RETURN                                                   null

End of function __construct

Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RI6v7
function name:  parse
number of ops:  18
compiled vars:  !0 = $template, !1 = $data, !2 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   52     3        FETCH_OBJ_R                                      ~3      'CI'
          4        FETCH_OBJ_R                                      ~4      ~3, 'load'
          5        INIT_METHOD_CALL                                         ~4, 'view'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        SEND_VAL_EX                                              <true>
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !0, $5
   54    11        INIT_METHOD_CALL                                         '_parse'
         12        SEND_VAR_EX                                              !0
         13        SEND_VAR_EX                                              !1
         14        SEND_VAR_EX                                              !2
         15        DO_FCALL                                      0  $7      
         16      > RETURN                                                   $7
   55    17*     > RETURN                                                   null

End of function parse

Function parse_string:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RI6v7
function name:  parse_string
number of ops:  10
compiled vars:  !0 = $template, !1 = $data, !2 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   72     3        INIT_METHOD_CALL                                         '_parse'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        DO_FCALL                                      0  $3      
          8      > RETURN                                                   $3
   73     9*     > RETURN                                                   null

End of function parse_string

Function _parse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 28
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 28
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 28
filename:       /in/RI6v7
function name:  _parse
number of ops:  38
compiled vars:  !0 = $template, !1 = $data, !2 = $return, !3 = $val, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   90     3        IS_IDENTICAL                                             !0, ''
          4      > JMPZ                                                     ~5, ->6
   92     5    > > RETURN                                                   <false>
   95     6    > > FE_RESET_R                                       $6      !1, ->28
          7    > > FE_FETCH_R                                       ~7      $6, !3, ->28
          8    >   ASSIGN                                                   !4, ~7
   97     9        TYPE_CHECK                                  128          !3
         10      > JMPZ                                                     ~9, ->18
   98    11    >   INIT_METHOD_CALL                                         '_parse_pair'
         12        SEND_VAR_EX                                              !4
         13        SEND_VAR_EX                                              !3
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0  $10     
         16        QM_ASSIGN                                        ~11     $10
         17      > JMP                                                      ->26
   99    18    >   INIT_METHOD_CALL                                         '_parse_single'
         19        SEND_VAR_EX                                              !4
         20        CAST                                          6  ~12     !3
         21        SEND_VAL_EX                                              ~12
         22        SEND_VAR_EX                                              !0
         23        DO_FCALL                                      0  $13     
         24        ASSIGN                                           ~14     !0, $13
         25        QM_ASSIGN                                        ~11     ~14
   97    26    >   ASSIGN                                                   !0, ~11
   95    27      > JMP                                                      ->7
         28    >   FE_FREE                                                  $6
  102    29        TYPE_CHECK                                    4          !2
         30      > JMPZ                                                     ~16, ->36
  104    31    >   FETCH_OBJ_R                                      ~17     'CI'
         32        FETCH_OBJ_R                                      ~18     ~17, 'output'
         33        INIT_METHOD_CALL                                         ~18, 'append_output'
         34        SEND_VAR_EX                                              !0
         35        DO_FCALL                                      0          
  107    36    > > RETURN                                                   !0
  108    37*     > RETURN                                                   null

End of function _parse

Function set_delimiters:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RI6v7
function name:  set_delimiters
number of ops:  7
compiled vars:  !0 = $l, !1 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  119     0  E >   RECV_INIT                                        !0      '%7B'
          1        RECV_INIT                                        !1      '%7D'
  121     2        ASSIGN_OBJ                                               'l_delim'
          3        OP_DATA                                                  !0
  122     4        ASSIGN_OBJ                                               'r_delim'
          5        OP_DATA                                                  !1
  123     6      > RETURN                                                   null

End of function set_delimiters

Function _parse_single:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RI6v7
function name:  _parse_single
number of ops:  15
compiled vars:  !0 = $key, !1 = $val, !2 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  135     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
  137     3        INIT_FCALL                                               'str_replace'
          4        FETCH_OBJ_R                                      ~3      'l_delim'
          5        CONCAT                                           ~4      ~3, !0
          6        FETCH_OBJ_R                                      ~5      'r_delim'
          7        CONCAT                                           ~6      ~4, ~5
          8        SEND_VAL                                                 ~6
          9        CAST                                          6  ~7      !1
         10        SEND_VAL                                                 ~7
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $8      
         13      > RETURN                                                   $8
  138    14*     > RETURN                                                   null

End of function _parse_single

Function _parse_pair:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 39
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 39
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 36
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 36
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 36
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/RI6v7
function name:  _parse_pair
number of ops:  48
compiled vars:  !0 = $variable, !1 = $data, !2 = $string, !3 = $match, !4 = $str, !5 = $row, !6 = $temp, !7 = $val, !8 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  152     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
  154     3        INIT_METHOD_CALL                                         '_match_pair'
          4        SEND_VAR_EX                                              !2
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $9      
          7        ASSIGN                                           ~10     !3, $9
          8        TYPE_CHECK                                    4          ~10
          9      > JMPZ                                                     ~11, ->11
  156    10    > > RETURN                                                   !2
  159    11    >   ASSIGN                                                   !4, ''
  160    12      > FE_RESET_R                                       $13     !1, ->39
         13    > > FE_FETCH_R                                               $13, !5, ->39
  162    14    >   FETCH_DIM_R                                      ~14     !3, 1
         15        ASSIGN                                                   !6, ~14
  163    16      > FE_RESET_R                                       $16     !5, ->36
         17    > > FE_FETCH_R                                       ~17     $16, !7, ->36
         18    >   ASSIGN                                                   !8, ~17
  165    19        TYPE_CHECK                                  128          !7
         20      > JMPZ                                                     ~19, ->28
  166    21    >   INIT_METHOD_CALL                                         '_parse_pair'
         22        SEND_VAR_EX                                              !8
         23        SEND_VAR_EX                                              !7
         24        SEND_VAR_EX                                              !6
         25        DO_FCALL                                      0  $20     
         26        QM_ASSIGN                                        ~21     $20
         27      > JMP                                                      ->34
  167    28    >   INIT_METHOD_CALL                                         '_parse_single'
         29        SEND_VAR_EX                                              !8
         30        SEND_VAR_EX                                              !7
         31        SEND_VAR_EX                                              !6
         32        DO_FCALL                                      0  $22     
         33        QM_ASSIGN                                        ~21     $22
  165    34    >   ASSIGN                                                   !6, ~21
  163    35      > JMP                                                      ->17
         36    >   FE_FREE                                                  $16
  170    37        ASSIGN_OP                                     8          !4, !6
  160    38      > JMP                                                      ->13
         39    >   FE_FREE                                                  $13
  173    40        INIT_FCALL                                               'str_replace'
         41        FETCH_DIM_R                                      ~25     !3, 0
         42        SEND_VAL                                                 ~25
         43        SEND_VAR                                                 !4
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $26     
         46      > RETURN                                                   $26
  174    47*     > RETURN                                                   null

End of function _parse_pair

Function _match_pair:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RI6v7
function name:  _match_pair
number of ops:  38
compiled vars:  !0 = $string, !1 = $variable, !2 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  185     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  187     2        INIT_FCALL                                               'preg_match'
          3        INIT_FCALL                                               'preg_quote'
          4        FETCH_OBJ_R                                      ~3      'l_delim'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        CONCAT                                           ~5      '%7C', $4
          8        CONCAT                                           ~6      ~5, !1
          9        INIT_FCALL                                               'preg_quote'
         10        FETCH_OBJ_R                                      ~7      'r_delim'
         11        SEND_VAL                                                 ~7
         12        DO_ICALL                                         $8      
         13        CONCAT                                           ~9      ~6, $8
         14        CONCAT                                           ~10     ~9, '%28.%2B%3F%29'
         15        INIT_FCALL                                               'preg_quote'
         16        FETCH_OBJ_R                                      ~11     'l_delim'
         17        SEND_VAL                                                 ~11
         18        DO_ICALL                                         $12     
         19        CONCAT                                           ~13     ~10, $12
         20        CONCAT                                           ~14     ~13, '%2F'
         21        CONCAT                                           ~15     ~14, !1
         22        INIT_FCALL                                               'preg_quote'
         23        FETCH_OBJ_R                                      ~16     'r_delim'
         24        SEND_VAL                                                 ~16
         25        DO_ICALL                                         $17     
         26        CONCAT                                           ~18     ~15, $17
         27        CONCAT                                           ~19     ~18, '%7Cs'
         28        SEND_VAL                                                 ~19
  188    29        SEND_VAR                                                 !0
         30        SEND_REF                                                 !2
         31        DO_ICALL                                         $20     
         32      > JMPZ                                                     $20, ->35
  189    33    >   QM_ASSIGN                                        ~21     !2
         34      > JMP                                                      ->36
         35    >   QM_ASSIGN                                        ~21     <false>
         36    > > RETURN                                                   ~21
  190    37*     > RETURN                                                   null

End of function _match_pair

End of class CI_Parser.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.51 ms | 1416 KiB | 19 Q