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 $str3 = 'タグは #1\20001#2 です'; echo "$str3\n"; var_dump( extract_tag_arr($str3) ); // -> `1\\20001#2`が得られてしまう // $str からタグ配列を得る function extract_tag_arr($str){ // タグ抽出のために、特殊な空白文字を半角スペースへ変換 $str = replace_to_space($str); // タグ抽出 $tag_arr = []; //preg_match_all('['.PAT_TAG.']' , $str, $ms); preg_match_all('/'.PAT_TAG.'/u' , $str, $ms); foreach ( $ms[0] as $m ) { //$tag_arr[] = ltrim(trim($m), '#'); $tag_arr[] = preg_replace('/\A[\p{Cc}\p{Cf}\p{Z}]++|[\p{Cc}\p{Cf}\p{Z}]++\z/u', '', $m); } return $tag_arr; } // 特殊な空白文字を半角スペースへ変換 function replace_to_space($str){ $encoded = json_encode($str); $table = [ '\u2000'=>' ', '\u2001'=>' ', '\u2002'=>' ', '\u2003'=>' ', '\u2004'=>' ', '\u2005'=>' ', '\u2006'=>' ', '\u2007'=>' ', '\u2008'=>' ', '\u2009'=>' ' ,'\u200A'=>' ' ,'\u00a0'=>' ' ]; $search = array_keys($table); $replace = array_values($table); return str_replace($search,$replace,$encoded); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BX8CO
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                                                 
   16    24        ASSIGN                                                   !2, '%E3%82%BF%E3%82%B0%E3%81%AF+%231%5C20001%232+%E3%81%A7%E3%81%99'
   17    25        NOP                                                      
         26        FAST_CONCAT                                      ~13     !2, '%0A'
         27        ECHO                                                     ~13
   18    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                                                 
   46    34      > RETURN                                                   1

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

End of function extract_tag_arr

Function replace_to_space:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BX8CO
function name:  replace_to_space
number of ops:  21
compiled vars:  !0 = $str, !1 = $encoded, !2 = $table, !3 = $search, !4 = $replace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        INIT_FCALL                                               'json_encode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
   38     5        ASSIGN                                                   !2, <array>
   43     6        INIT_FCALL                                               'array_keys'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !3, $8
   44    10        INIT_FCALL                                               'array_values'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $10     
         13        ASSIGN                                                   !4, $10
   45    14        INIT_FCALL                                               'str_replace'
         15        SEND_VAR                                                 !3
         16        SEND_VAR                                                 !4
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $12     
         19      > RETURN                                                   $12
   46    20*     > RETURN                                                   null

End of function replace_to_space

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.43 ms | 1409 KiB | 29 Q