3v4l.org

run code in 500+ PHP versions simultaneously
<?php $indicator = '<span class="required">*</span>'; echo "** Before **\n"; var_dump( $indicator ); function replace_glyth( $haystack, $replacement ) { return str_replace( '*', $replacement, $haystack ); } // Replacing the asterisk. echo "\n\n** Direct replacement **\n"; var_dump( replace_glyth( $indicator, 'required' ) ); function replace_translatable_glyth( $haystack, $replacement ) { $pattern = '/(<span class="required">)(.*)(<\/span>)/i'; $replacement = sprintf( '${1}%s${3}', $replacement ); $new = preg_replace( $pattern, $replacement, $haystack ); return $new; $pattern = '/<span class="required">(?<glyth>.*)<\/span>/i'; preg_match( $pattern, $haystack, $matches ); var_dump( $matches ); // No glyth found. if ( empty( $matches['glyth' ] ) ) { return $haystack; } return str_replace( $matches['glyth'], $replacement, $haystack ); } // Since the asterisk is translatable ... echo "\n\n** Pattern to adjust for translatable glyth **\n"; var_dump( replace_translatable_glyth( $indicator, '**required**' ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mA2Hm
function name:  (null)
number of ops:  22
compiled vars:  !0 = $indicator
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cspan+class%3D%22required%22%3E%2A%3C%2Fspan%3E'
    4     1        ECHO                                                         '%2A%2A+Before+%2A%2A%0A'
    5     2        INIT_FCALL                                                   'var_dump'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                                     
   12     5        ECHO                                                         '%0A%0A%2A%2A+Direct+replacement+%2A%2A%0A'
   13     6        INIT_FCALL                                                   'var_dump'
          7        INIT_FCALL                                                   'replace_glyth'
          8        SEND_VAR                                                     !0
          9        SEND_VAL                                                     'required'
         10        DO_FCALL                                          0  $3      
         11        SEND_VAR                                                     $3
         12        DO_ICALL                                                     
   36    13        ECHO                                                         '%0A%0A%2A%2A+Pattern+to+adjust+for+translatable+glyth+%2A%2A%0A'
   37    14        INIT_FCALL                                                   'var_dump'
         15        INIT_FCALL                                                   'replace_translatable_glyth'
         16        SEND_VAR                                                     !0
         17        SEND_VAL                                                     '%2A%2Arequired%2A%2A'
         18        DO_FCALL                                          0  $5      
         19        SEND_VAR                                                     $5
         20        DO_ICALL                                                     
         21      > RETURN                                                       1

Function replace_glyth:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mA2Hm
function name:  replace_glyth
number of ops:  6
compiled vars:  !0 = $haystack, !1 = $replacement
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    8     2        FRAMELESS_ICALL_3                str_replace         ~2      '%2A', !1
          3        OP_DATA                                                      !0
          4      > RETURN                                                       ~2
    9     5*     > RETURN                                                       null

End of function replace_glyth

Function replace_translatable_glyth:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mA2Hm
function name:  replace_translatable_glyth
number of ops:  28
compiled vars:  !0 = $haystack, !1 = $replacement, !2 = $pattern, !3 = $new, !4 = $matches
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   16     2        ASSIGN                                                       !2, '%2F%28%3Cspan+class%3D%22required%22%3E%29%28.%2A%29%28%3C%5C%2Fspan%3E%29%2Fi'
   17     3        ROPE_INIT                                         3  ~7      '%24%7B1%7D'
          4        ROPE_ADD                                          1  ~7      ~7, !1
          5        ROPE_END                                          2  ~6      ~7, '%24%7B3%7D'
          6        ASSIGN                                                       !1, ~6
   18     7        FRAMELESS_ICALL_3                preg_replace        ~10     !2, !1
          8        OP_DATA                                                      !0
          9        ASSIGN                                                       !3, ~10
   20    10      > RETURN                                                       !3
   22    11*       ASSIGN                                                       !2, '%2F%3Cspan+class%3D%22required%22%3E%28%3F%3Cglyth%3E.%2A%29%3C%5C%2Fspan%3E%2Fi'
   23    12*       INIT_FCALL                                                   'preg_match'
         13*       SEND_VAR                                                     !2
         14*       SEND_VAR                                                     !0
         15*       SEND_REF                                                     !4
         16*       DO_ICALL                                                     
   25    17*       INIT_FCALL                                                   'var_dump'
         18*       SEND_VAR                                                     !4
         19*       DO_ICALL                                                     
   28    20*       ISSET_ISEMPTY_DIM_OBJ                             1          !4, 'glyth'
         21*       JMPZ                                                         ~15, ->23
   29    22*       RETURN                                                       !0
   32    23*       FETCH_DIM_R                                          ~16     !4, 'glyth'
         24*       FRAMELESS_ICALL_3                str_replace         ~17     ~16, !1
         25*       OP_DATA                                                      !0
         26*       RETURN                                                       ~17
   33    27*     > RETURN                                                       null

End of function replace_translatable_glyth

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
170.73 ms | 1911 KiB | 17 Q