3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ConvertToAPICase($str) { return preg_replace_callback('/(^[a-z])|-([\w])/', function($matches) { return str_replace('-', '', strtoupper($matches[0])); }, $str); } function ConvertToJSCase($str) { $str = preg_replace_callback('/([A-Z]+|[0-9])/', function($matches) { return '-' . strtolower($matches[0]); }, $str); // remove first dash return preg_replace('/^-/', '', $str); } echo ConvertToJSCase('NicamAllAges'); echo ' - '; echo ConvertToAPICase('nicam-age-6'); echo ' - '; echo ConvertToJSCase('NicamAge6'); echo ' - '; echo ConvertToJSCase('nicamAge12'); echo ' - '; echo ConvertToJSCase('NicamAA');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bImIP
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'converttojscase'
          1        SEND_VAL                                                 'NicamAllAges'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   19     4        ECHO                                                     '+-+'
   20     5        INIT_FCALL                                               'converttoapicase'
          6        SEND_VAL                                                 'nicam-age-6'
          7        DO_FCALL                                      0  $1      
          8        ECHO                                                     $1
   21     9        ECHO                                                     '+-+'
   22    10        INIT_FCALL                                               'converttojscase'
         11        SEND_VAL                                                 'NicamAge6'
         12        DO_FCALL                                      0  $2      
         13        ECHO                                                     $2
   23    14        ECHO                                                     '+-+'
   24    15        INIT_FCALL                                               'converttojscase'
         16        SEND_VAL                                                 'nicamAge12'
         17        DO_FCALL                                      0  $3      
         18        ECHO                                                     $3
   25    19        ECHO                                                     '+-+'
   26    20        INIT_FCALL                                               'converttojscase'
         21        SEND_VAL                                                 'NicamAA'
         22        DO_FCALL                                      0  $4      
         23        ECHO                                                     $4
         24      > RETURN                                                   1

Function converttoapicase:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bImIP
function name:  ConvertToAPICase
number of ops:  9
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_replace_callback'
          2        SEND_VAL                                                 '%2F%28%5E%5Ba-z%5D%29%7C-%28%5B%5Cw%5D%29%2F'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FbImIP%3A4%240'
    6     4        SEND_VAL                                                 ~1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
    7     8*     > RETURN                                                   null

End of function converttoapicase

Function %00%7Bclosure%7D%2Fin%2FbImIP%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bImIP
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'str_replace'
          2        SEND_VAL                                                 '-'
          3        SEND_VAL                                                 ''
          4        INIT_FCALL                                               'strtoupper'
          5        FETCH_DIM_R                                      ~1      !0, 0
          6        SEND_VAL                                                 ~1
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                         $3      
         10      > RETURN                                                   $3
    6    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FbImIP%3A4%240

Function converttojscase:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bImIP
function name:  ConvertToJSCase
number of ops:  15
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'preg_replace_callback'
          2        SEND_VAL                                                 '%2F%28%5BA-Z%5D%2B%7C%5B0-9%5D%29%2F'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FbImIP%3A10%241'
   12     4        SEND_VAL                                                 ~1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
   10     7        ASSIGN                                                   !0, $2
   15     8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAL                                                 '%2F%5E-%2F'
         10        SEND_VAL                                                 ''
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $4      
         13      > RETURN                                                   $4
   16    14*     > RETURN                                                   null

End of function converttojscase

Function %00%7Bclosure%7D%2Fin%2FbImIP%3A10%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bImIP
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'strtolower'
          2        FETCH_DIM_R                                      ~1      !0, 0
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5        CONCAT                                           ~3      '-', $2
          6      > RETURN                                                   ~3
   12     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FbImIP%3A10%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.79 ms | 1402 KiB | 28 Q