3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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
Jump found. Position 1 = -2
filename:       /in/bImIP
function name:  (null)
number of ops:  27
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
   9     1        NOP                                                      
  18     2        INIT_FCALL                                               'converttojscase'
         3        SEND_VAL                                                 'NicamAllAges'
         4        DO_FCALL                                      0  $0      
         5        ECHO                                                     $0
  19     6        ECHO                                                     '+-+'
  20     7        INIT_FCALL                                               'converttoapicase'
         8        SEND_VAL                                                 'nicam-age-6'
         9        DO_FCALL                                      0  $1      
        10        ECHO                                                     $1
  21    11        ECHO                                                     '+-+'
  22    12        INIT_FCALL                                               'converttojscase'
        13        SEND_VAL                                                 'NicamAge6'
        14        DO_FCALL                                      0  $2      
        15        ECHO                                                     $2
  23    16        ECHO                                                     '+-+'
  24    17        INIT_FCALL                                               'converttojscase'
        18        SEND_VAL                                                 'nicamAge12'
        19        DO_FCALL                                      0  $3      
        20        ECHO                                                     $3
  25    21        ECHO                                                     '+-+'
  26    22        INIT_FCALL                                               'converttojscase'
        23        SEND_VAL                                                 'NicamAA'
        24        DO_FCALL                                      0  $4      
        25        ECHO                                                     $4
        26      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FbImIP0x7f20a2be50c3:
Finding entry points
Branch analysis from position: 0
Jump found. 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_VAR                                                 $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%2FbImIP0x7f20a2be50c3

Function converttoapicase:
Finding entry points
Branch analysis from position: 0
Jump found. 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%2FbImIP0x7f20a2be50c3'
   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%2FbImIP0x7f20a2be5179:
Finding entry points
Branch analysis from position: 0
Jump found. 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_VAR                                                 $1
         4        DO_ICALL                                         $2      
         5        CONCAT                                           ~3      '-', $2
         6      > RETURN                                                   ~3
  12     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FbImIP0x7f20a2be5179

Function converttojscase:
Finding entry points
Branch analysis from position: 0
Jump found. 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%2FbImIP0x7f20a2be5179'
  12     4        SEND_VAL                                                 ~1
         5        SEND_VAR                                                 !0
         6        DO_ICALL                                         $2      
         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

Generated using Vulcan Logic Dumper, using php 7.3.0