3v4l.org

run code in 300+ PHP versions simultaneously
<?php // phpcs:ignoreFile $separator = '-'; $subjects = [ 'SomeCamelCase' => 'Some-Camel-Case', 'Some12With5Numbers' => 'Some-12-With-5-Numbers', 'SomePDFInText' => 'Some-PDF-In-Text', '123LeadingNumbers' => '123-Leading-Numbers', 'ItIs2016' => 'It-Is-2016', 'What-If' => 'What-If', 'ASingleLetterB' => 'A-Single-Letter-B', 'some_snake_case' => 'some_snake_case', 'Title_Snake_Case' => 'Title-_-Snake-_-Case', 'lower-with-dash' => 'lowerwithdash', 'FFS!' => 'FFS-!', 'WithA😃' => 'With-A-😃', 'PDF123' => 'PDF-123', 'EmojiInThe🤞Middle' => 'Emoji-In-The-🤞-Middle', '12345' => '12345', '123A' => '123-A', 'A123' => 'A-123', 'War&Peace' => 'War-&-Peace', 'lowerThenTitleCase' => 'lower-Then-Title-Case', '123lower' => '123-lower', 'lower123' => 'lower-123', 'ItIsÜber' => 'It-Is-Über', 'SømeThing' => 'Søme-Thing', ]; foreach ($subjects as $subject => $expect) { $pattern = <<<REGEXP / ( (?:\p{Lu}\p{Ll}+) # Upper followed by lower | (?:\p{Lu}+(?!\p{Ll})) # Upper not followed by lower | (?:\p{N}+) # Runs of numbers ) /ux REGEXP; $result = implode( $separator, preg_split( $pattern, str_replace($separator, '', $subject), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY, ), ); echo $result === $expect ? '✅' : '❌', ' ', $result, PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 32
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 32
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/ISIYe
function name:  (null)
number of ops:  34
compiled vars:  !0 = $separator, !1 = $subjects, !2 = $expect, !3 = $subject, !4 = $pattern, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, '-'
    7     1        ASSIGN                                                   !1, <array>
   33     2      > FE_RESET_R                                       $8      !1, ->32
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->32
          4    >   ASSIGN                                                   !3, ~9
   34     5        ASSIGN                                                   !4, '%2F%0A%28%0A++++%28%3F%3A%5Cp%7BLu%7D%5Cp%7BLl%7D%2B%29+%23+Upper+followed+by+lower%0A++++%7C%0A++++%28%3F%3A%5Cp%7BLu%7D%2B%28%3F%21%5Cp%7BLl%7D%29%29+%23+Upper+not+followed+by+lower%0A++++%7C%0A++++%28%3F%3A%5Cp%7BN%7D%2B%29+%23+Runs+of+numbers%0A%29%0A%2Fux'
   46     6        INIT_FCALL                                               'implode'
   47     7        SEND_VAR                                                 !0
   48     8        INIT_FCALL                                               'preg_split'
   49     9        SEND_VAR                                                 !4
   50    10        INIT_FCALL                                               'str_replace'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 ''
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $12     
         15        SEND_VAR                                                 $12
   51    16        SEND_VAL                                                 -1
   52    17        SEND_VAL                                                 3
   48    18        DO_ICALL                                         $13     
   52    19        SEND_VAR                                                 $13
   46    20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !5, $14
   56    22        IS_IDENTICAL                                             !5, !2
         23      > JMPZ                                                     ~16, ->26
         24    >   QM_ASSIGN                                        ~17     '%E2%9C%85'
         25      > JMP                                                      ->27
         26    >   QM_ASSIGN                                        ~17     '%E2%9D%8C'
         27    >   ECHO                                                     ~17
   57    28        ECHO                                                     '+'
   58    29        ECHO                                                     !5
   59    30        ECHO                                                     '%0A'
   33    31      > JMP                                                      ->3
         32    >   FE_FREE                                                  $8
   60    33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.63 ms | 1452 KiB | 16 Q