3v4l.org

run code in 300+ PHP versions simultaneously
<?php function utf8ToLocalEncoding($s) { if (substr(PHP_OS, 0, 3) === 'WIN' || true) { list(, $code) = explode(".", setlocale(LC_CTYPE, 0)); $s = @iconv("UTF-8", "cp" . $code . "//TRANSLIT", $s); } return $s; } function localEncodingToUtf8($s) { if (substr(PHP_OS, 0, 3) === 'WIN' || true) { list(, $code) = explode(".", setlocale(LC_CTYPE, 0)); $s = @iconv("cp" . $code . "//TRANSLIT", "UTF-8", $s); } return $s; } $original = "šířéč"; $a = utf8toLocalEncoding($original); $b = localEncodingToUtf8($a); var_dump($original, $a, $b, $original === $b); var_dump(setlocale(LC_CTYPE, 0));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4rv3S
function name:  (null)
number of ops:  24
compiled vars:  !0 = $original, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, '%C5%A1%C3%AD%C5%99%C3%A9%C4%8D'
   20     1        INIT_FCALL                                               'utf8tolocalencoding'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   21     5        INIT_FCALL                                               'localencodingtoutf8'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
   23     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !2
         13        IS_IDENTICAL                                     ~8      !0, !2
         14        SEND_VAL                                                 ~8
         15        DO_ICALL                                                 
   24    16        INIT_FCALL                                               'var_dump'
         17        INIT_FCALL                                               'setlocale'
         18        SEND_VAL                                                 0
         19        SEND_VAL                                                 0
         20        DO_ICALL                                         $10     
         21        SEND_VAR                                                 $10
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Function utf8tolocalencoding:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 31
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 9
filename:       /in/4rv3S
function name:  utf8ToLocalEncoding
number of ops:  33
compiled vars:  !0 = $s, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'substr'
          2        SEND_VAL                                                 'Linux'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 3
          5        DO_ICALL                                         $2      
          6        IS_IDENTICAL                                     ~3      $2, 'WIN'
          7      > JMPNZ_EX                                         ~3      ~3, ->9
          8    >   BOOL                                             ~3      <true>
          9    > > JMPZ                                                     ~3, ->31
    5    10    >   INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '.'
         12        INIT_FCALL                                               'setlocale'
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 0
         15        DO_ICALL                                         $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                         $5      
         18        FETCH_LIST_R                                     $6      $5, 1
         19        ASSIGN                                                   !1, $6
         20        FREE                                                     $5
    6    21        BEGIN_SILENCE                                    ~8      
         22        INIT_FCALL_BY_NAME                                       'iconv'
         23        SEND_VAL_EX                                              'UTF-8'
         24        CONCAT                                           ~9      'cp', !1
         25        CONCAT                                           ~10     ~9, '%2F%2FTRANSLIT'
         26        SEND_VAL_EX                                              ~10
         27        SEND_VAR_EX                                              !0
         28        DO_FCALL                                      0  $11     
         29        END_SILENCE                                              ~8
         30        ASSIGN                                                   !0, $11
    8    31    > > RETURN                                                   !0
    9    32*     > RETURN                                                   null

End of function utf8tolocalencoding

Function localencodingtoutf8:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 31
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 9
filename:       /in/4rv3S
function name:  localEncodingToUtf8
number of ops:  33
compiled vars:  !0 = $s, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'substr'
          2        SEND_VAL                                                 'Linux'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 3
          5        DO_ICALL                                         $2      
          6        IS_IDENTICAL                                     ~3      $2, 'WIN'
          7      > JMPNZ_EX                                         ~3      ~3, ->9
          8    >   BOOL                                             ~3      <true>
          9    > > JMPZ                                                     ~3, ->31
   13    10    >   INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '.'
         12        INIT_FCALL                                               'setlocale'
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 0
         15        DO_ICALL                                         $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                         $5      
         18        FETCH_LIST_R                                     $6      $5, 1
         19        ASSIGN                                                   !1, $6
         20        FREE                                                     $5
   14    21        BEGIN_SILENCE                                    ~8      
         22        INIT_FCALL_BY_NAME                                       'iconv'
         23        CONCAT                                           ~9      'cp', !1
         24        CONCAT                                           ~10     ~9, '%2F%2FTRANSLIT'
         25        SEND_VAL_EX                                              ~10
         26        SEND_VAL_EX                                              'UTF-8'
         27        SEND_VAR_EX                                              !0
         28        DO_FCALL                                      0  $11     
         29        END_SILENCE                                              ~8
         30        ASSIGN                                                   !0, $11
   16    31    > > RETURN                                                   !0
   17    32*     > RETURN                                                   null

End of function localencodingtoutf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.29 ms | 1411 KiB | 26 Q