3v4l.org

run code in 300+ 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:  9
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        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '%2A'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
    9     8*     > 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:  35
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        INIT_FCALL                                               'sprintf'
          4        SEND_VAL                                                 '%24%7B1%7D%25s%24%7B3%7D'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !1, $6
   18     8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $8      
         13        ASSIGN                                                   !3, $8
   20    14      > RETURN                                                   !3
   22    15*       ASSIGN                                                   !2, '%2F%3Cspan+class%3D%22required%22%3E%28%3F%3Cglyth%3E.%2A%29%3C%5C%2Fspan%3E%2Fi'
   23    16*       INIT_FCALL                                               'preg_match'
         17*       SEND_VAR                                                 !2
         18*       SEND_VAR                                                 !0
         19*       SEND_REF                                                 !4
         20*       DO_ICALL                                                 
   25    21*       INIT_FCALL                                               'var_dump'
         22*       SEND_VAR                                                 !4
         23*       DO_ICALL                                                 
   28    24*       ISSET_ISEMPTY_DIM_OBJ                         1          !4, 'glyth'
         25*       JMPZ                                                     ~13, ->27
   29    26*       RETURN                                                   !0
   32    27*       INIT_FCALL                                               'str_replace'
         28*       FETCH_DIM_R                                      ~14     !4, 'glyth'
         29*       SEND_VAL                                                 ~14
         30*       SEND_VAR                                                 !1
         31*       SEND_VAR                                                 !0
         32*       DO_ICALL                                         $15     
         33*       RETURN                                                   $15
   33    34*     > RETURN                                                   null

End of function replace_translatable_glyth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.27 ms | 1403 KiB | 25 Q