3v4l.org

run code in 300+ PHP versions simultaneously
<?php function entities( $string ) { $stringBuilder = ""; $offset = 0; if ( empty( $string ) ) { return ""; } while ( $offset >= 0 ) { $decValue = ordutf8( $string, $offset ); $char = unichr($decValue); $htmlEntited = htmlentities( $char ); if( $char != $htmlEntited ){ $stringBuilder .= $htmlEntited . " "; } elseif( $decValue >= 128 ){ $stringBuilder .= "&#" . $decValue . "; "; } else { $stringBuilder .= $char . " "; } } return $stringBuilder; } // source - http://php.net/manual/en/function.ord.php#109812 function ordutf8($string, &$offset) { $code = ord(substr($string, $offset,1)); if ($code >= 128) { //otherwise 0xxxxxxx if ($code < 224) $bytesnumber = 2; //110xxxxx else if ($code < 240) $bytesnumber = 3; //1110xxxx else if ($code < 248) $bytesnumber = 4; //11110xxx $codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0); for ($i = 2; $i <= $bytesnumber; $i++) { $offset ++; $code2 = ord(substr($string, $offset, 1)) - 128; //10xxxxxx $codetemp = $codetemp*64 + $code2; } $code = $codetemp; } $offset += 1; if ($offset >= strlen($string)) $offset = -1; return $code; } // source - http://php.net/manual/en/function.chr.php#88611 function unichr($u) { return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES'); } /* ---- */ var_dump( entities( "😂🧜‍♂️" ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DBs9Q
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'entities'
          2        SEND_VAL                                                 '%F0%9F%98%82%F0%9F%A7%9C%E2%80%8D%E2%99%82%EF%B8%8F'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function entities:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 7
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 7
Branch analysis from position: 35
Branch analysis from position: 7
filename:       /in/DBs9Q
function name:  entities
number of ops:  37
compiled vars:  !0 = $string, !1 = $stringBuilder, !2 = $offset, !3 = $decValue, !4 = $char, !5 = $htmlEntited
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, ''
    5     2        ASSIGN                                                   !2, 0
    7     3        ISSET_ISEMPTY_CV                                         !0
          4      > JMPZ                                                     ~8, ->6
    8     5    > > RETURN                                                   ''
   11     6    > > JMP                                                      ->33
   12     7    >   INIT_FCALL_BY_NAME                                       'ordutf8'
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !3, $9
   13    12        INIT_FCALL_BY_NAME                                       'unichr'
         13        SEND_VAR_EX                                              !3
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !4, $11
   15    16        INIT_FCALL                                               'htmlentities'
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                         $13     
         19        ASSIGN                                                   !5, $13
   16    20        IS_NOT_EQUAL                                             !4, !5
         21      > JMPZ                                                     ~15, ->25
   17    22    >   CONCAT                                           ~16     !5, '+'
         23        ASSIGN_OP                                     8          !1, ~16
   16    24      > JMP                                                      ->33
   18    25    >   IS_SMALLER_OR_EQUAL                                      128, !3
         26      > JMPZ                                                     ~18, ->31
   19    27    >   CONCAT                                           ~19     '%26%23', !3
         28        CONCAT                                           ~20     ~19, '%3B+'
         29        ASSIGN_OP                                     8          !1, ~20
   18    30      > JMP                                                      ->33
   21    31    >   CONCAT                                           ~22     !4, '+'
         32        ASSIGN_OP                                     8          !1, ~22
   11    33    >   IS_SMALLER_OR_EQUAL                                      0, !2
         34      > JMPNZ                                                    ~24, ->7
   25    35    > > RETURN                                                   !1
   26    36*     > RETURN                                                   null

End of function entities

Function ordutf8:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 58
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 40
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 63
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 40
Branch analysis from position: 57
Branch analysis from position: 40
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
Branch analysis from position: 35
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
Branch analysis from position: 29
Branch analysis from position: 24
Branch analysis from position: 58
filename:       /in/DBs9Q
function name:  ordutf8
number of ops:  65
compiled vars:  !0 = $string, !1 = $offset, !2 = $code, !3 = $bytesnumber, !4 = $codetemp, !5 = $i, !6 = $code2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2        INIT_FCALL                                               'ord'
          3        INIT_FCALL                                               'substr'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $7      
          8        SEND_VAR                                                 $7
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !2, $8
   31    11        IS_SMALLER_OR_EQUAL                                      128, !2
         12      > JMPZ                                                     ~10, ->58
   32    13    >   IS_SMALLER                                               !2, 224
         14      > JMPZ                                                     ~11, ->17
         15    >   ASSIGN                                                   !3, 2
         16      > JMP                                                      ->24
   33    17    >   IS_SMALLER                                               !2, 240
         18      > JMPZ                                                     ~13, ->21
         19    >   ASSIGN                                                   !3, 3
         20      > JMP                                                      ->24
   34    21    >   IS_SMALLER                                               !2, 248
         22      > JMPZ                                                     ~15, ->24
         23    >   ASSIGN                                                   !3, 4
   35    24    >   SUB                                              ~17     !2, 192
         25        IS_SMALLER                                               2, !3
         26      > JMPZ                                                     ~18, ->29
         27    >   QM_ASSIGN                                        ~19     32
         28      > JMP                                                      ->30
         29    >   QM_ASSIGN                                        ~19     0
         30    >   SUB                                              ~20     ~17, ~19
         31        IS_SMALLER                                               3, !3
         32      > JMPZ                                                     ~21, ->35
         33    >   QM_ASSIGN                                        ~22     16
         34      > JMP                                                      ->36
         35    >   QM_ASSIGN                                        ~22     0
         36    >   SUB                                              ~23     ~20, ~22
         37        ASSIGN                                                   !4, ~23
   36    38        ASSIGN                                                   !5, 2
         39      > JMP                                                      ->55
   37    40    >   PRE_INC                                                  !1
   38    41        INIT_FCALL                                               'ord'
         42        INIT_FCALL                                               'substr'
         43        SEND_VAR                                                 !0
         44        SEND_VAR                                                 !1
         45        SEND_VAL                                                 1
         46        DO_ICALL                                         $27     
         47        SEND_VAR                                                 $27
         48        DO_ICALL                                         $28     
         49        SUB                                              ~29     $28, 128
         50        ASSIGN                                                   !6, ~29
   39    51        MUL                                              ~31     !4, 64
         52        ADD                                              ~32     ~31, !6
         53        ASSIGN                                                   !4, ~32
   36    54        PRE_INC                                                  !5
         55    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         56      > JMPNZ                                                    ~35, ->40
   41    57    >   ASSIGN                                                   !2, !4
   43    58    >   ASSIGN_OP                                     1          !1, 1
   44    59        STRLEN                                           ~38     !0
         60        IS_SMALLER_OR_EQUAL                                      ~38, !1
         61      > JMPZ                                                     ~39, ->63
         62    >   ASSIGN                                                   !1, -1
   45    63    > > RETURN                                                   !2
   46    64*     > RETURN                                                   null

End of function ordutf8

Function unichr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DBs9Q
function name:  unichr
number of ops:  11
compiled vars:  !0 = $u
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   50     1        INIT_FCALL                                               'mb_convert_encoding'
          2        CAST                                          4  ~1      !0
          3        CONCAT                                           ~2      '%26%23', ~1
          4        CONCAT                                           ~3      ~2, '%3B'
          5        SEND_VAL                                                 ~3
          6        SEND_VAL                                                 'UTF-8'
          7        SEND_VAL                                                 'HTML-ENTITIES'
          8        DO_ICALL                                         $4      
          9      > RETURN                                                   $4
   51    10*     > RETURN                                                   null

End of function unichr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.68 ms | 1017 KiB | 19 Q