3v4l.org

run code in 500+ PHP versions simultaneously
<?php ini_set('display_errors', '1'); // display runtime errors error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED); // error reporting date_default_timezone_set('UTC'); function detect_encoding($ystr, $csetlist='UTF-8, ISO-8859-1, ISO-8859-15, ISO-8859-2, ISO-8859-9, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-16, UTF-7, ASCII, SJIS, EUC-JP, JIS, ISO-2022-JP, EUC-CN, GB18030, ISO-2022-KR, KOI8-R, KOI8-U') { // Fix: starting from PHP 7.1 it warns about illegal argument if using: ISO-8859-11 return mb_detect_encoding((string)$ystr, (string)$csetlist, true); // mixed: (bool) FALSE or (string) 'CHARSET' } $str = 'A + B'; echo detect_encoding($str); echo "\n"; echo mb_convert_encoding($str, 'UTF-8', detect_encoding($str)); echo "\n"; echo "\n"; $str = 'A - B'; echo detect_encoding('A - B'); echo "\n"; echo mb_convert_encoding($str, 'UTF-8', detect_encoding($str));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ib2Fd
function name:  (null)
number of ops:  47
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'ini_set'
          1        SEND_VAL                                                     'display_errors'
          2        SEND_VAL                                                     '1'
          3        DO_ICALL                                                     
    4     4        INIT_FCALL                                                   'error_reporting'
          5        FETCH_CONSTANT                                       ~2      'E_STRICT'
          6        BW_NOT                                               ~3      ~2
          7        BW_AND                                               ~4      ~3, 30711
          8        BW_AND                                               ~5      ~4, -8193
          9        SEND_VAL                                                     ~5
         10        DO_ICALL                                                     
    5    11        INIT_FCALL                                                   'date_default_timezone_set'
         12        SEND_VAL                                                     'UTC'
         13        DO_ICALL                                                     
   11    14        ASSIGN                                                       !0, 'A+%2B+B'
   12    15        INIT_FCALL                                                   'detect_encoding'
         16        SEND_VAR                                                     !0
         17        DO_FCALL                                          0  $9      
         18        ECHO                                                         $9
   13    19        ECHO                                                         '%0A'
   14    20        INIT_FCALL                                                   'mb_convert_encoding'
         21        SEND_VAR                                                     !0
         22        SEND_VAL                                                     'UTF-8'
         23        INIT_FCALL                                                   'detect_encoding'
         24        SEND_VAR                                                     !0
         25        DO_FCALL                                          0  $10     
         26        SEND_VAR                                                     $10
         27        DO_ICALL                                             $11     
         28        ECHO                                                         $11
   15    29        ECHO                                                         '%0A'
   16    30        ECHO                                                         '%0A'
   17    31        ASSIGN                                                       !0, 'A+-+B'
   18    32        INIT_FCALL                                                   'detect_encoding'
         33        SEND_VAL                                                     'A+-+B'
         34        DO_FCALL                                          0  $13     
         35        ECHO                                                         $13
   19    36        ECHO                                                         '%0A'
   20    37        INIT_FCALL                                                   'mb_convert_encoding'
         38        SEND_VAR                                                     !0
         39        SEND_VAL                                                     'UTF-8'
         40        INIT_FCALL                                                   'detect_encoding'
         41        SEND_VAR                                                     !0
         42        DO_FCALL                                          0  $14     
         43        SEND_VAR                                                     $14
         44        DO_ICALL                                             $15     
         45        ECHO                                                         $15
         46      > RETURN                                                       1

Function detect_encoding:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ib2Fd
function name:  detect_encoding
number of ops:  11
compiled vars:  !0 = $ystr, !1 = $csetlist
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      'UTF-8%2C+ISO-8859-1%2C+ISO-8859-15%2C+ISO-8859-2%2C+ISO-8859-9%2C+ISO-8859-3%2C+ISO-8859-4%2C+ISO-8859-5%2C+ISO-8859-6%2C+ISO-8859-7%2C+ISO-8859-8%2C+ISO-8859-10%2C+ISO-8859-13%2C+ISO-8859-14%2C+ISO-8859-16%2C+UTF-7%2C+ASCII%2C+SJIS%2C+EUC-JP%2C+JIS%2C+ISO-2022-JP%2C+EUC-CN%2C+GB18030%2C+ISO-2022-KR%2C+KOI8-R%2C+KOI8-U'
    8     2        INIT_FCALL                                                   'mb_detect_encoding'
          3        CAST                                              6  ~2      !0
          4        SEND_VAL                                                     ~2
          5        CAST                                              6  ~3      !1
          6        SEND_VAL                                                     ~3
          7        SEND_VAL                                                     <true>
          8        DO_ICALL                                             $4      
          9      > RETURN                                                       $4
    9    10*     > RETURN                                                       null

End of function detect_encoding

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.85 ms | 1175 KiB | 17 Q