3v4l.org

run code in 300+ PHP versions simultaneously
<?php function validate_utf8() { return (bool)preg_match('//u', serialize(func_get_args())); } function test($input) { $output = htmlspecialchars($input, ENT_QUOTES, 'UTF-8'); $code = str_replace('%', '\\x', rawurlencode($input)); if (validate_utf8($input)) { echo "【{$output}】({$code}) は有効なUTF-8シーケンスです。\n"; } else { echo "({$code}) は無効なUTF-8シーケンスです。\n"; } } test("☝( ◠‿◠ )☝"); test("ゔ〲〰"); test("\x0a\x92\xff"); // てきとー test("\xef\xbb\xbf"); // BOMだっけ test(""); // 空文字 echo "\n"; test("\x2f"); // スラッシュ(1バイト) test("\xc0\xaf"); // スラッシュ(冗長2バイト) test("\xe0\x80\xaf"); // スラッシュ(冗長3バイト) test("\xf0\x80\x80\xaf"); // スラッシュ(冗長4バイト)
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pVCpj
function name:  (null)
number of ops:  29
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  17     0  E >   INIT_FCALL                                               'test'
         1        SEND_VAL                                                 '%E2%98%9D%28+%E2%97%A0%E2%80%BF%E2%97%A0+%29%E2%98%9D'
         2        DO_FCALL                                      0          
  18     3        INIT_FCALL                                               'test'
         4        SEND_VAL                                                 '%E3%82%94%E3%80%B2%E3%80%B0'
         5        DO_FCALL                                      0          
  19     6        INIT_FCALL                                               'test'
         7        SEND_VAL                                                 '%0A%92%FF'
         8        DO_FCALL                                      0          
  20     9        INIT_FCALL                                               'test'
        10        SEND_VAL                                                 '%EF%BB%BF'
        11        DO_FCALL                                      0          
  21    12        INIT_FCALL                                               'test'
        13        SEND_VAL                                                 ''
        14        DO_FCALL                                      0          
  23    15        ASSIGN_OBJ                                               '%0A'
  25    16        INIT_FCALL                                               'test'
        17        SEND_VAL                                                 '%2F'
        18        DO_FCALL                                      0          
  26    19        INIT_FCALL                                               'test'
        20        SEND_VAL                                                 '%C0%AF'
        21        DO_FCALL                                      0          
  27    22        INIT_FCALL                                               'test'
        23        SEND_VAL                                                 '%E0%80%AF'
        24        DO_FCALL                                      0          
  28    25        INIT_FCALL                                               'test'
        26        SEND_VAL                                                 '%F0%80%80%AF'
        27        DO_FCALL                                      0          
        28      > RETURN                                                   1

Function validate_utf8:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pVCpj
function name:  validate_utf8
number of ops:  11
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   INIT_FCALL                                               'preg_match'
         1        SEND_VAL                                                 '%2F%2Fu'
         2        INIT_FCALL                                               'serialize'
         3        DECLARE_ANON_INHERITED_CLASS                     :0      
         4        SEND_VAL                                                 ~0
         5        DO_ICALL                                         $1      
         6        SEND_VAR                                                 $1
         7        DO_ICALL                                         $2      
         8        MAKE_REF                                         ~3      $2
         9      > RETURN                                                   ~3
   4    10*     > RETURN                                                   null

End of function validate_utf8

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pVCpj
function name:  test
number of ops:  32
compiled vars:  !0 = $input, !1 = $output, !2 = $code
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   5     0  E >   RECV                                             !0      
   7     1        INIT_FCALL                                               'htmlspecialchars'
         2        SEND_VAR                                                 !0
         3        SEND_VAL                                                 3
         4        SEND_VAL                                                 'UTF-8'
         5        DO_ICALL                                         $3      
         6        QM_ASSIGN                                                !1
   8     7        INIT_FCALL                                               'str_replace'
         8        SEND_VAL                                                 '%25'
         9        SEND_VAL                                                 '%5Cx'
        10        INIT_FCALL                                               'rawurlencode'
        11        SEND_VAR                                                 !0
        12        DO_ICALL                                         $5      
        13        SEND_VAR                                                 $5
        14        DO_ICALL                                         $6      
        15        QM_ASSIGN                                                !2
  10    16        INIT_FCALL                                               'validate_utf8'
        17        SEND_VAR                                                 !0
        18        DO_FCALL                                      0  $8      
        19      > JMPZ                                                     $8, ->27
  11    20    >   ROPE_INIT                                     5  ~10     '%E3%80%90'
        21        ROPE_ADD                                      1  ~10     ~10, !1
        22        ROPE_ADD                                      2  ~10     ~10, '%E3%80%91%28'
        23        ROPE_ADD                                      3  ~10     ~10, !2
        24        ROPE_END                                      4  ~9      ~10, '%29+%E3%81%AF%E6%9C%89%E5%8A%B9%E3%81%AAUTF-8%E3%82%B7%E3%83%BC%E3%82%B1%E3%83%B3%E3%82%B9%E3%81%A7%E3%81%99%E3%80%82%0A'
        25        ASSIGN_OBJ                                               ~9
        26      > JMP                                                      ->31
  13    27    >   ROPE_INIT                                     3  ~14     '%28'
        28        ROPE_ADD                                      1  ~14     ~14, !2
        29        ROPE_END                                      2  ~13     ~14, '%29+%E3%81%AF%E7%84%A1%E5%8A%B9%E3%81%AAUTF-8%E3%82%B7%E3%83%BC%E3%82%B1%E3%83%B3%E3%82%B9%E3%81%A7%E3%81%99%E3%80%82%0A'
        30        ASSIGN_OBJ                                               ~13
  16    31    > > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
12.12 ms | 416 KiB | 7 Q