3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo mb_detect_encoding('garcía'); print "\n"; echo mb_detect_encoding('García'); print "\n"; echo is_utf8('garcía'); print "\n"; echo is_utf8('García'); print "\n"; echo is_utf82('garcía'); print "\n"; echo is_utf82('García'); print "\n"; echo is_utf83('garcía'); print "\n"; echo is_utf83('García'); function is_utf8($str) { return (bool) preg_match('//u', $str); } function is_utf82($str) { return (bool) preg_match('!!u', $str); } function is_utf83($str) { return ! (false === mb_detect_encoding($string, 'UTF-8', true)); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ePkCf
function name:  (null)
number of ops:  40
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'mb_detect_encoding'
          1        SEND_VAL                                                 'garc%C3%ADa'
          2        DO_ICALL                                         $0      
          3        ECHO                                                     $0
    4     4        ECHO                                                     '%0A'
    5     5        INIT_FCALL                                               'mb_detect_encoding'
          6        SEND_VAL                                                 'Garc%C3%83%C2%ADa'
          7        DO_ICALL                                         $1      
          8        ECHO                                                     $1
    6     9        ECHO                                                     '%0A'
    7    10        INIT_FCALL_BY_NAME                                       'is_utf8'
         11        SEND_VAL_EX                                              'garc%C3%ADa'
         12        DO_FCALL                                      0  $2      
         13        ECHO                                                     $2
    8    14        ECHO                                                     '%0A'
    9    15        INIT_FCALL_BY_NAME                                       'is_utf8'
         16        SEND_VAL_EX                                              'Garc%C3%83%C2%ADa'
         17        DO_FCALL                                      0  $3      
         18        ECHO                                                     $3
   10    19        ECHO                                                     '%0A'
   11    20        INIT_FCALL_BY_NAME                                       'is_utf82'
         21        SEND_VAL_EX                                              'garc%C3%ADa'
         22        DO_FCALL                                      0  $4      
         23        ECHO                                                     $4
   12    24        ECHO                                                     '%0A'
   13    25        INIT_FCALL_BY_NAME                                       'is_utf82'
         26        SEND_VAL_EX                                              'Garc%C3%83%C2%ADa'
         27        DO_FCALL                                      0  $5      
         28        ECHO                                                     $5
   14    29        ECHO                                                     '%0A'
   15    30        INIT_FCALL_BY_NAME                                       'is_utf83'
         31        SEND_VAL_EX                                              'garc%C3%ADa'
         32        DO_FCALL                                      0  $6      
         33        ECHO                                                     $6
   16    34        ECHO                                                     '%0A'
   17    35        INIT_FCALL_BY_NAME                                       'is_utf83'
         36        SEND_VAL_EX                                              'Garc%C3%83%C2%ADa'
         37        DO_FCALL                                      0  $7      
         38        ECHO                                                     $7
   31    39      > RETURN                                                   1

Function is_utf8:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ePkCf
function name:  is_utf8
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%2Fu'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        BOOL                                             ~2      $1
          6      > RETURN                                                   ~2
   23     7*     > RETURN                                                   null

End of function is_utf8

Function is_utf82:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ePkCf
function name:  is_utf82
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%21%21u'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        BOOL                                             ~2      $1
          6      > RETURN                                                   ~2
   27     7*     > RETURN                                                   null

End of function is_utf82

Function is_utf83:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ePkCf
function name:  is_utf83
number of ops:  10
compiled vars:  !0 = $str, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'mb_detect_encoding'
          2        SEND_VAR                                                 !1
          3        SEND_VAL                                                 'UTF-8'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $2      
          6        TYPE_CHECK                                    4  ~3      $2
          7        BOOL_NOT                                         ~4      ~3
          8      > RETURN                                                   ~4
   31     9*     > RETURN                                                   null

End of function is_utf83

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.64 ms | 1400 KiB | 17 Q