3v4l.org

run code in 300+ PHP versions simultaneously
<?php function do_split($name) { return preg_split('/([A-Z]{2,}|([A-Z][^A-Z]*))/', $name, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); } function convert_case($name) { return implode( '_', array_map( 'strtolower', do_split($name) ) ); } function convert_case2($name) { $output = ''; foreach ($name as $char) { print_r("{$char} " . json_encode(ctype_upper($char))); } return strtolower($output); } convert_case2('FooBARbar'); $samples = array( 'FooBar', 'FooBAR', 'FOObar', 'foo_bar', 'FOO_bar', 'foo_BAR', 'foo_Bar', 'Foo_bar', ); /* print_r(array_map(function ($name) { return array( 'name' => $name, 'split' => do_split($name), 'converted' => convert_case($name), ); }, $samples)); */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P1G20
function name:  (null)
number of ops:  5
compiled vars:  !0 = $samples
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'convert_case2'
          1        SEND_VAL                                                 'FooBARbar'
          2        DO_FCALL                                      0          
   27     3        ASSIGN                                                   !0, <array>
   47     4      > RETURN                                                   1

Function do_split:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P1G20
function name:  do_split
number of ops:  9
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%28%5BA-Z%5D%7B2%2C%7D%7C%28%5BA-Z%5D%5B%5EA-Z%5D%2A%29%29%2F'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 null
          5        SEND_VAL                                                 3
          6        DO_ICALL                                         $1      
          7      > RETURN                                                   $1
    5     8*     > RETURN                                                   null

End of function do_split

Function convert_case:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P1G20
function name:  convert_case
number of ops:  14
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'implode'
    9     2        SEND_VAL                                                 '_'
   10     3        INIT_FCALL                                               'array_map'
   11     4        SEND_VAL                                                 'strtolower'
   12     5        INIT_FCALL                                               'do_split'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $1      
          8        SEND_VAR                                                 $1
          9        DO_ICALL                                         $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                         $3      
         12      > RETURN                                                   $3
   15    13*     > RETURN                                                   null

End of function convert_case

Function convert_case2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/P1G20
function name:  convert_case2
number of ops:  23
compiled vars:  !0 = $name, !1 = $output, !2 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN                                                   !1, ''
   19     2      > FE_RESET_R                                       $4      !0, ->17
          3    > > FE_FETCH_R                                               $4, !2, ->17
   20     4    >   INIT_FCALL                                               'print_r'
          5        NOP                                                      
          6        FAST_CONCAT                                      ~5      !2, '+'
          7        INIT_FCALL                                               'json_encode'
          8        INIT_FCALL                                               'ctype_upper'
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                         $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                         $7      
         13        CONCAT                                           ~8      ~5, $7
         14        SEND_VAL                                                 ~8
         15        DO_ICALL                                                 
   19    16      > JMP                                                      ->3
         17    >   FE_FREE                                                  $4
   22    18        INIT_FCALL                                               'strtolower'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $10     
         21      > RETURN                                                   $10
   23    22*     > RETURN                                                   null

End of function convert_case2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.31 ms | 1403 KiB | 29 Q