3v4l.org

run code in 300+ PHP versions simultaneously
<?php function wordSafeSplit(string $text, int $pieces = 2) { $wordsPerPiece = ceil(str_word_count($text) / $pieces); return preg_split( "~([^\w'-]*[\w'-]+[^\w' -]*){{$wordsPerPiece}}\K\s?~", $text, $pieces ); } $text = "The Quick : Brown Fox Jumped Over The Lazy / Dog"; var_export(wordSafeSplit($text));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Btd1T
function name:  (null)
number of ops:  8
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, 'The+Quick+%3A+Brown+Fox+Jumped+Over+The+Lazy+%2F+Dog'
   14     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'wordsafesplit'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function wordsafesplit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Btd1T
function name:  wordSafeSplit
number of ops:  20
compiled vars:  !0 = $text, !1 = $pieces, !2 = $wordsPerPiece
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
    5     2        INIT_FCALL                                               'ceil'
          3        INIT_FCALL                                               'str_word_count'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        DIV                                              ~4      $3, !1
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !2, $5
    6    10        INIT_FCALL                                               'preg_split'
    7    11        ROPE_INIT                                     3  ~8      '%7E%28%5B%5E%5Cw%27-%5D%2A%5B%5Cw%27-%5D%2B%5B%5E%5Cw%27+-%5D%2A%29%7B'
         12        ROPE_ADD                                      1  ~8      ~8, !2
         13        ROPE_END                                      2  ~7      ~8, '%7D%5CK%5Cs%3F%7E'
         14        SEND_VAL                                                 ~7
    8    15        SEND_VAR                                                 !0
    9    16        SEND_VAR                                                 !1
    6    17        DO_ICALL                                         $10     
    9    18      > RETURN                                                   $10
   11    19*     > RETURN                                                   null

End of function wordsafesplit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.22 ms | 1017 KiB | 18 Q