3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* function clean_string($string) { $parts = preg_split('/\s+/', $string); $partsCount = count($parts); for ($i = 0; $i < $partsCount; $i++) { if ($parts[$i] === strtoupper($parts[$i])) { $parts[$i] = ucfirst(strtolower($parts[$i])); } } return implode(' ', $parts); } */ //or shorter:) function cleanString($string){ return array_reduce(preg_split('/\s+/', $string), function ($carry, $item){ return $carry . ' '. (($item === strtoupper($item)) ? ucfirst(strtolower($item)) : $item); }); } echo cleanString('INTERVIEW – Jo Stenuit, Belgisch designdirecteur Mazda Motor Europe');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PrYqu
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'cleanstring'
          1        SEND_VAL                                                 'INTERVIEW+%E2%80%93+Jo+Stenuit%2C+Belgisch+designdirecteur+Mazda+Motor+Europe'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function cleanstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PrYqu
function name:  cleanString
number of ops:  12
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'array_reduce'
          2        INIT_FCALL                                               'preg_split'
          3        SEND_VAL                                                 '%2F%5Cs%2B%2F'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FPrYqu%3A21%240'
   23     8        SEND_VAL                                                 ~2
          9        DO_ICALL                                         $3      
         10      > RETURN                                                   $3
   24    11*     > RETURN                                                   null

End of function cleanstring

Function %00%7Bclosure%7D%2Fin%2FPrYqu%3A21%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PrYqu
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        CONCAT                                           ~2      !0, '+'
          3        INIT_FCALL                                               'strtoupper'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6        IS_IDENTICAL                                             !1, $3
          7      > JMPZ                                                     ~4, ->16
          8    >   INIT_FCALL                                               'ucfirst'
          9        INIT_FCALL                                               'strtolower'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                         $6      
         14        QM_ASSIGN                                        ~7      $6
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~7      !1
         17    >   CONCAT                                           ~8      ~2, ~7
         18      > RETURN                                                   ~8
   23    19*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FPrYqu%3A21%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.43 ms | 1403 KiB | 24 Q