3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ ['this is a test', 'This Is a Test', false], ['why sunless tanning is A hot trend', 'Why Sunless Tanning Is a Hot Trend', false], ['Satin Sheets are a Luxury you Can Afford', 'Satin Sheets Are a Luxury You Can Afford', false], ['the Dangers Of Hiking Without Proper Shoes', 'The Dangers of Hiking Without Proper Shoes', false], ['an hour or so', 'An Hour or So', false], ['Of the meaning Of Of', 'Of the Meaning of Of', false], ['Thing With Extra Spaces', 'Thing With Extra Spaces', false], ['Thing with extra spaces', 'Thing With Extra Spaces', true], ['Observations of isolated pulsars and disk-fed X-ray binaries.', 'Observations of Isolated Pulsars and Disk-Fed X-Ray Binaries.', false] ]; function APATitle($title, $keepMultipleSpaces = false, $blackList = []) { if (!is_string($title)) { return false; } $blackList = $blackList ? array_map('strtolower', (array)$blackList) : ['a', 'an', 'and', 'at', 'but', 'by', 'for', 'in', 'nor', 'of', 'on', 'or', 'so', 'the', 'to', 'up', 'yet']; if (!$keepMultipleSpaces) { $title = preg_replace('~\s+~', ' ', $title); } return preg_replace_callback( '~(?!^)\b(?:' . implode('|', $blackList) . ')\b(?!$)(*SKIP)(*FAIL)|\b[a-z]+\b~', function ($m) { return ucfirst($m[0]); }, strtolower($title) ); } foreach ($tests as [$input, $expectedOutput, $keepMultipleSpaces]) { $output = APATitle($input, $keepMultipleSpaces); echo ($output === $expectedOutput ? 'SUCCESS' : 'FAILURE') . "\"{$input}\" became \"{$output}\"\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 28
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/j3qaW
function name:  (null)
number of ops:  30
compiled vars:  !0 = $tests, !1 = $input, !2 = $expectedOutput, !3 = $keepMultipleSpaces, !4 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   38     1      > FE_RESET_R                                       $6      !0, ->28
          2    > > FE_FETCH_R                                               $6, $7, ->28
          3    >   FETCH_LIST_R                                     $8      $7, 0
          4        ASSIGN                                                   !1, $8
          5        FETCH_LIST_R                                     $10     $7, 1
          6        ASSIGN                                                   !2, $10
          7        FETCH_LIST_R                                     $12     $7, 2
          8        ASSIGN                                                   !3, $12
          9        FREE                                                     $7
   39    10        INIT_FCALL                                               'apatitle'
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !3
         13        DO_FCALL                                      0  $14     
         14        ASSIGN                                                   !4, $14
   40    15        IS_IDENTICAL                                             !4, !2
         16      > JMPZ                                                     ~16, ->19
         17    >   QM_ASSIGN                                        ~17     'SUCCESS'
         18      > JMP                                                      ->20
         19    >   QM_ASSIGN                                        ~17     'FAILURE'
         20    >   ROPE_INIT                                     5  ~19     '%22'
         21        ROPE_ADD                                      1  ~19     ~19, !1
         22        ROPE_ADD                                      2  ~19     ~19, '%22+became+%22'
         23        ROPE_ADD                                      3  ~19     ~19, !4
         24        ROPE_END                                      4  ~18     ~19, '%22%0A'
         25        CONCAT                                           ~22     ~17, ~18
         26        ECHO                                                     ~22
   38    27      > JMP                                                      ->2
         28    >   FE_FREE                                                  $6
   41    29      > RETURN                                                   1

Function apatitle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
Branch analysis from position: 25
filename:       /in/j3qaW
function name:  APATitle
number of ops:  42
compiled vars:  !0 = $title, !1 = $keepMultipleSpaces, !2 = $blackList
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
          2        RECV_INIT                                        !2      <array>
   17     3        TYPE_CHECK                                   64  ~3      !0
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->7
   18     6    > > RETURN                                                   <false>
   21     7    > > JMPZ                                                     !2, ->15
   22     8    >   INIT_FCALL                                               'array_map'
          9        SEND_VAL                                                 'strtolower'
         10        CAST                                          7  ~5      !2
         11        SEND_VAL                                                 ~5
         12        DO_ICALL                                         $6      
         13        QM_ASSIGN                                        ~7      $6
         14      > JMP                                                      ->16
   23    15    >   QM_ASSIGN                                        ~7      <array>
   21    16    >   ASSIGN                                                   !2, ~7
   25    17        BOOL_NOT                                         ~9      !1
         18      > JMPZ                                                     ~9, ->25
   26    19    >   INIT_FCALL                                               'preg_replace'
         20        SEND_VAL                                                 '%7E%5Cs%2B%7E'
         21        SEND_VAL                                                 '+'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $10     
         24        ASSIGN                                                   !0, $10
   29    25    >   INIT_FCALL                                               'preg_replace_callback'
   30    26        INIT_FCALL                                               'implode'
         27        SEND_VAL                                                 '%7C'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                         $12     
         30        CONCAT                                           ~13     '%7E%28%3F%21%5E%29%5Cb%28%3F%3A', $12
         31        CONCAT                                           ~14     ~13, '%29%5Cb%28%3F%21%24%29%28%2ASKIP%29%28%2AFAIL%29%7C%5Cb%5Ba-z%5D%2B%5Cb%7E'
         32        SEND_VAL                                                 ~14
   31    33        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fj3qaW%3A31%240'
   33    34        SEND_VAL                                                 ~15
   34    35        INIT_FCALL                                               'strtolower'
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $16     
         38        SEND_VAR                                                 $16
         39        DO_ICALL                                         $17     
         40      > RETURN                                                   $17
   36    41*     > RETURN                                                   null

End of function apatitle

Function %00%7Bclosure%7D%2Fin%2Fj3qaW%3A31%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j3qaW
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        INIT_FCALL                                               'ucfirst'
          2        FETCH_DIM_R                                      ~1      !0, 0
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5      > RETURN                                                   $2
   33     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fj3qaW%3A31%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
204.44 ms | 1407 KiB | 26 Q