3v4l.org

run code in 300+ PHP versions simultaneously
<?php // タグの条件 define("PAT_TAG", "(^|[\\s])([##]\\S+)"); // $str1 $str1 = 'タグは #1 #2 です'; echo "$str1\n"; var_dump( extract_tag_arr($str1) ); // -> `1`と`2`が得られる // str2 $str2 = 'タグは #1 #2 です'; echo "$str2\n"; var_dump( extract_tag_arr($str2) ); // -> `1 #2`が得られてしまう $str3 = 'タグは #1\20001#2 です'; echo "$str3\n"; var_dump( extract_tag_arr($str3) ); // -> `1\\20001#2`が得られてしまう // $str からタグ配列を得る function extract_tag_arr($str){ // タグ抽出 $tag_arr = []; preg_match_all('/'.PAT_TAG.'/u' , $str, $ms); foreach ( $ms[0] as $m ) { $tag_arr[] = preg_replace('/(\A[\p{Cc}\p{Cf}\p{Z}]++|[\p{Cc}\p{Cf}\p{Z}]++\z)(#|#)/u', '', $m); } return $tag_arr; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LZjlF
function name:  (null)
number of ops:  35
compiled vars:  !0 = $str1, !1 = $str2, !2 = $str3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'PAT_TAG'
          2        SEND_VAL                                                 '%28%5E%7C%5B%5Cs%5D%29%28%5B%23%EF%BC%83%5D%5CS%2B%29'
          3        DO_ICALL                                                 
    6     4        ASSIGN                                                   !0, '%E3%82%BF%E3%82%B0%E3%81%AF+%231+%232+%E3%81%A7%E3%81%99'
    7     5        NOP                                                      
          6        FAST_CONCAT                                      ~5      !0, '%0A'
          7        ECHO                                                     ~5
    8     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL_BY_NAME                                       'extract_tag_arr'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                                 
   11    14        ASSIGN                                                   !1, '%E3%82%BF%E3%82%B0%E3%81%AF+%231%E2%80%80%232+%E3%81%A7%E3%81%99'
   12    15        NOP                                                      
         16        FAST_CONCAT                                      ~9      !1, '%0A'
         17        ECHO                                                     ~9
   13    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL_BY_NAME                                       'extract_tag_arr'
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $10     
         22        SEND_VAR                                                 $10
         23        DO_ICALL                                                 
   15    24        ASSIGN                                                   !2, '%E3%82%BF%E3%82%B0%E3%81%AF+%231%5C20001%232+%E3%81%A7%E3%81%99'
   16    25        NOP                                                      
         26        FAST_CONCAT                                      ~13     !2, '%0A'
         27        ECHO                                                     ~13
   17    28        INIT_FCALL                                               'var_dump'
         29        INIT_FCALL_BY_NAME                                       'extract_tag_arr'
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0  $14     
         32        SEND_VAR                                                 $14
         33        DO_ICALL                                                 
   28    34      > RETURN                                                   1

Function extract_tag_arr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/LZjlF
function name:  extract_tag_arr
number of ops:  24
compiled vars:  !0 = $str, !1 = $tag_arr, !2 = $ms, !3 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, <array>
   23     2        INIT_FCALL                                               'preg_match_all'
          3        FETCH_CONSTANT                                   ~5      'PAT_TAG'
          4        CONCAT                                           ~6      '%2F', ~5
          5        CONCAT                                           ~7      ~6, '%2Fu'
          6        SEND_VAL                                                 ~7
          7        SEND_VAR                                                 !0
          8        SEND_REF                                                 !2
          9        DO_ICALL                                                 
   24    10        FETCH_DIM_R                                      ~9      !2, 0
         11      > FE_RESET_R                                       $10     ~9, ->21
         12    > > FE_FETCH_R                                               $10, !3, ->21
   25    13    >   INIT_FCALL                                               'preg_replace'
         14        SEND_VAL                                                 '%2F%28%5CA%5B%5Cp%7BCc%7D%5Cp%7BCf%7D%5Cp%7BZ%7D%5D%2B%2B%7C%5B%5Cp%7BCc%7D%5Cp%7BCf%7D%5Cp%7BZ%7D%5D%2B%2B%5Cz%29%28%23%7C%EF%BC%83%29%2Fu'
         15        SEND_VAL                                                 ''
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $12     
         18        ASSIGN_DIM                                               !1
         19        OP_DATA                                                  $12
   24    20      > JMP                                                      ->12
         21    >   FE_FREE                                                  $10
   27    22      > RETURN                                                   !1
   28    23*     > RETURN                                                   null

End of function extract_tag_arr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.93 ms | 1405 KiB | 21 Q