3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "[ABC] This & Text"; Echo make_post_type($string); function make_post_type($string) { $needle = array('-', ' '); $arr = explode(" ", $string); foreach($arr as &$a){ if($a[0] != "[" && $a[-1] != "]"){ $a = preg_replace("/[^a-zA-Z0-9_\s]/", "", strtolower($a)); // Remove special characters }else{ $a = substr($a, 1,-1); } } $string = preg_replace('!\s+!', ' ', implode(" ", $arr)); // Now remove extra spaces return str_replace($needle, '_', $string); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rZlaP
function name:  (null)
number of ops:  6
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5BABC%5D+This+%26+Text'
    4     1        INIT_FCALL_BY_NAME                                       'make_post_type'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
   20     5      > RETURN                                                   1

Function make_post_type:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 8, Position 2 = 33
Branch analysis from position: 8
2 jumps found. (Code = 126) Position 1 = 9, Position 2 = 33
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 15
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/rZlaP
function name:  make_post_type
number of ops:  51
compiled vars:  !0 = $string, !1 = $needle, !2 = $arr, !3 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        ASSIGN                                                   !1, <array>
    9     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !2, $5
   10     7      > FE_RESET_RW                                      $7      !2, ->33
          8    > > FE_FETCH_RW                                              $7, !3, ->33
   11     9    >   FETCH_DIM_R                                      ~8      !3, 0
         10        IS_NOT_EQUAL                                     ~9      ~8, '%5B'
         11      > JMPZ_EX                                          ~9      ~9, ->15
         12    >   FETCH_DIM_R                                      ~10     !3, -1
         13        IS_NOT_EQUAL                                     ~11     ~10, '%5D'
         14        BOOL                                             ~9      ~11
         15    > > JMPZ                                                     ~9, ->26
   12    16    >   INIT_FCALL                                               'preg_replace'
         17        SEND_VAL                                                 '%2F%5B%5Ea-zA-Z0-9_%5Cs%5D%2F'
         18        SEND_VAL                                                 ''
         19        INIT_FCALL                                               'strtolower'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $12     
         22        SEND_VAR                                                 $12
         23        DO_ICALL                                         $13     
         24        ASSIGN                                                   !3, $13
   11    25      > JMP                                                      ->32
   14    26    >   INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !3
         28        SEND_VAL                                                 1
         29        SEND_VAL                                                 -1
         30        DO_ICALL                                         $15     
         31        ASSIGN                                                   !3, $15
   10    32    > > JMP                                                      ->8
         33    >   FE_FREE                                                  $7
   17    34        INIT_FCALL                                               'preg_replace'
         35        SEND_VAL                                                 '%21%5Cs%2B%21'
         36        SEND_VAL                                                 '+'
         37        INIT_FCALL                                               'implode'
         38        SEND_VAL                                                 '+'
         39        SEND_VAR                                                 !2
         40        DO_ICALL                                         $17     
         41        SEND_VAR                                                 $17
         42        DO_ICALL                                         $18     
         43        ASSIGN                                                   !0, $18
   19    44        INIT_FCALL                                               'str_replace'
         45        SEND_VAR                                                 !1
         46        SEND_VAL                                                 '_'
         47        SEND_VAR                                                 !0
         48        DO_ICALL                                         $20     
         49      > RETURN                                                   $20
   20    50*     > RETURN                                                   null

End of function make_post_type

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.88 ms | 1021 KiB | 19 Q