3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mb_detect_encoding2 ($string, $enc=null, $ret=null) { static $enclist = array( 'UTF-8', 'ASCII', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', 'Windows-1251', 'Windows-1252', 'Windows-1254', ); $result = false; foreach ($enclist as $item) { $sample = iconv($item, $item, $string); if (md5($sample) == md5($string)) { if ($ret === NULL) { $result = $item; } else { $result = true; } break; } } return $result; } $strings = array( 'ASCII' => 'ASCII', 'UTF-8' => "Tr\xc3\xb6t", 'Windows-1252 with ASCII' => "Tr\xf6t", 'Windows-1252 only' => "\xf6\xfd\x80", 'Windows-1252 only with an undefined character' => "\xf6\xfd\x81", ); $detect = array('ASCII', 'Windows-1252', 'UTF-8'); foreach ($strings as $name => $string) { $detected_loose = mb_detect_encoding2($string, $detect, true); $detected_strict = mb_detect_encoding2($string, $detect, false); if ($detected_loose === $detected_strict) { if ($detected_loose === false) { echo "'$name' could not be detected!\n"; } else { echo "'$name' was detected as $detected_loose\n"; } } else { echo "'$name' was " . ($detected_loose === false ? 'not detected' : "detected as $detected_loose") . ' in loose mode, but ' . ($detected_strict === false ? 'not detected' : "detected as $detected_strict") . " in strict mode\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 56
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 56
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 33
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
Branch analysis from position: 49
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
filename:       /in/nceZs
function name:  (null)
number of ops:  58
compiled vars:  !0 = $strings, !1 = $detect, !2 = $string, !3 = $name, !4 = $detected_loose, !5 = $detected_strict
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, <array>
   33     1        ASSIGN                                                   !1, <array>
   35     2      > FE_RESET_R                                       $8      !0, ->56
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->56
          4    >   ASSIGN                                                   !3, ~9
   36     5        INIT_FCALL                                               'mb_detect_encoding2'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 <true>
          9        DO_FCALL                                      0  $11     
         10        ASSIGN                                                   !4, $11
   37    11        INIT_FCALL                                               'mb_detect_encoding2'
         12        SEND_VAR                                                 !2
         13        SEND_VAR                                                 !1
         14        SEND_VAL                                                 <false>
         15        DO_FCALL                                      0  $13     
         16        ASSIGN                                                   !5, $13
   38    17        IS_IDENTICAL                                             !4, !5
         18      > JMPZ                                                     ~15, ->33
   39    19    >   TYPE_CHECK                                    4          !4
         20      > JMPZ                                                     ~16, ->26
   40    21    >   ROPE_INIT                                     3  ~18     '%27'
         22        ROPE_ADD                                      1  ~18     ~18, !3
         23        ROPE_END                                      2  ~17     ~18, '%27+could+not+be+detected%21%0A'
         24        ECHO                                                     ~17
         25      > JMP                                                      ->32
   42    26    >   ROPE_INIT                                     5  ~21     '%27'
         27        ROPE_ADD                                      1  ~21     ~21, !3
         28        ROPE_ADD                                      2  ~21     ~21, '%27+was+detected+as+'
         29        ROPE_ADD                                      3  ~21     ~21, !4
         30        ROPE_END                                      4  ~20     ~21, '%0A'
         31        ECHO                                                     ~20
         32    > > JMP                                                      ->55
   45    33    >   ROPE_INIT                                     3  ~25     '%27'
         34        ROPE_ADD                                      1  ~25     ~25, !3
         35        ROPE_END                                      2  ~24     ~25, '%27+was+'
   46    36        TYPE_CHECK                                    4          !4
         37      > JMPZ                                                     ~27, ->40
         38    >   QM_ASSIGN                                        ~28     'not+detected'
         39      > JMP                                                      ->43
         40    >   NOP                                                      
         41        FAST_CONCAT                                      ~29     'detected+as+', !4
         42        QM_ASSIGN                                        ~28     ~29
         43    >   CONCAT                                           ~30     ~24, ~28
   47    44        CONCAT                                           ~31     ~30, '+in+loose+mode%2C+but+'
   48    45        TYPE_CHECK                                    4          !5
         46      > JMPZ                                                     ~32, ->49
         47    >   QM_ASSIGN                                        ~33     'not+detected'
         48      > JMP                                                      ->52
         49    >   NOP                                                      
         50        FAST_CONCAT                                      ~34     'detected+as+', !5
         51        QM_ASSIGN                                        ~33     ~34
         52    >   CONCAT                                           ~35     ~31, ~33
   49    53        CONCAT                                           ~36     ~35, '+in+strict+mode%0A'
         54        ECHO                                                     ~36
   35    55    > > JMP                                                      ->3
         56    >   FE_FREE                                                  $8
   51    57      > RETURN                                                   1

Function mb_detect_encoding2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 28
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 28
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 28
Branch analysis from position: 28
filename:       /in/nceZs
function name:  mb_detect_encoding2
number of ops:  31
compiled vars:  !0 = $string, !1 = $enc, !2 = $ret, !3 = $enclist, !4 = $result, !5 = $item, !6 = $sample
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
    5     3        BIND_STATIC                                              !3
   13     4        ASSIGN                                                   !4, <false>
   15     5      > FE_RESET_R                                       $8      !3, ->28
          6    > > FE_FETCH_R                                               $8, !5, ->28
   16     7    >   INIT_FCALL_BY_NAME                                       'iconv'
          8        SEND_VAR_EX                                              !5
          9        SEND_VAR_EX                                              !5
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $9      
         12        ASSIGN                                                   !6, $9
   17    13        INIT_FCALL                                               'md5'
         14        SEND_VAR                                                 !6
         15        DO_ICALL                                         $11     
         16        INIT_FCALL                                               'md5'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $12     
         19        IS_EQUAL                                                 $11, $12
         20      > JMPZ                                                     ~13, ->27
   18    21    >   TYPE_CHECK                                    2          !2
         22      > JMPZ                                                     ~14, ->25
         23    >   ASSIGN                                                   !4, !5
         24      > JMP                                                      ->26
         25    >   ASSIGN                                                   !4, <true>
   19    26    > > JMP                                                      ->28
   15    27    > > JMP                                                      ->6
         28    >   FE_FREE                                                  $8
   23    29      > RETURN                                                   !4
   24    30*     > RETURN                                                   null

End of function mb_detect_encoding2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.66 ms | 1407 KiB | 17 Q