3v4l.org

run code in 500+ PHP versions simultaneously
<?php $rgba = 'rgba(80,80,80,0.5)'; function blendChannels(float $alpha, int $channel1, int $channel2): int { // blend 2 channels return intval(($channel1 * $alpha) + ($channel2 * (1.0 - $alpha))); } function convertRGBAtoHEX6(string $rgba): string { // sanitize $rgba = strtolower(trim($rgba)); // check if (substr($rgba, 0, 5) != 'rgba(') { return $rgba; } // extract channels $channels = explode(',', substr($rgba, 5, strpos($rgba, ')') - 5)); // compute rgb with white background $alpha = $channels[3]; $r = blendChannels($alpha, $channels[0], 0xFF); $g = blendChannels($alpha, $channels[1], 0xFF); $b = blendChannels($alpha, $channels[2], 0xFF); return sprintf('#%02x%02x%02x', $r, $g, $b); } echo convertRGBAtoHEX6($rgba);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ick2o
function name:  (null)
number of ops:  6
compiled vars:  !0 = $rgba
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'rgba%2880%2C80%2C80%2C0.5%29'
   29     1        INIT_FCALL                                                   'convertrgbatohex6'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $2      
          4        ECHO                                                         $2
          5      > RETURN                                                       1

Function blendchannels:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ick2o
function name:  blendChannels
number of ops:  12
compiled vars:  !0 = $alpha, !1 = $channel1, !2 = $channel2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    8     3        MUL                                                  ~3      !1, !0
          4        SUB                                                  ~4      1, !0
          5        MUL                                                  ~5      !2, ~4
          6        ADD                                                  ~6      ~3, ~5
          7        CAST                                              4  ~7      ~6
          8        VERIFY_RETURN_TYPE                                           ~7
          9      > RETURN                                                       ~7
    9    10*       VERIFY_RETURN_TYPE                                           
         11*     > RETURN                                                       null

End of function blendchannels

Function convertrgbatohex6:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ick2o
function name:  convertRGBAtoHEX6
number of ops:  54
compiled vars:  !0 = $rgba, !1 = $channels, !2 = $alpha, !3 = $r, !4 = $g, !5 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
   14     1        INIT_FCALL                                                   'strtolower'
          2        FRAMELESS_ICALL_1                trim                ~6      !0
          3        SEND_VAL                                                     ~6
          4        DO_ICALL                                             $7      
          5        ASSIGN                                                       !0, $7
   16     6        FRAMELESS_ICALL_3                substr              ~9      !0, 0
          7        OP_DATA                                                      5
          8        IS_NOT_EQUAL                                                 ~9, 'rgba%28'
          9      > JMPZ                                                         ~10, ->12
   17    10    >   VERIFY_RETURN_TYPE                                           !0
         11      > RETURN                                                       !0
   20    12    >   INIT_FCALL                                                   'explode'
         13        SEND_VAL                                                     '%2C'
         14        FRAMELESS_ICALL_2                strpos              ~11     !0, '%29'
         15        SUB                                                  ~12     ~11, 5
         16        FRAMELESS_ICALL_3                substr              ~13     !0, 5
         17        OP_DATA                                                      ~12
         18        SEND_VAL                                                     ~13
         19        DO_ICALL                                             $14     
         20        ASSIGN                                                       !1, $14
   22    21        FETCH_DIM_R                                          ~16     !1, 3
         22        ASSIGN                                                       !2, ~16
   23    23        INIT_FCALL                                                   'blendchannels'
         24        SEND_VAR                                                     !2
         25        FETCH_DIM_R                                          ~18     !1, 0
         26        SEND_VAL                                                     ~18
         27        SEND_VAL                                                     255
         28        DO_FCALL                                          0  $19     
         29        ASSIGN                                                       !3, $19
   24    30        INIT_FCALL                                                   'blendchannels'
         31        SEND_VAR                                                     !2
         32        FETCH_DIM_R                                          ~21     !1, 1
         33        SEND_VAL                                                     ~21
         34        SEND_VAL                                                     255
         35        DO_FCALL                                          0  $22     
         36        ASSIGN                                                       !4, $22
   25    37        INIT_FCALL                                                   'blendchannels'
         38        SEND_VAR                                                     !2
         39        FETCH_DIM_R                                          ~24     !1, 2
         40        SEND_VAL                                                     ~24
         41        SEND_VAL                                                     255
         42        DO_FCALL                                          0  $25     
         43        ASSIGN                                                       !5, $25
   26    44        INIT_FCALL                                                   'sprintf'
         45        SEND_VAL                                                     '%23%2502x%2502x%2502x'
         46        SEND_VAR                                                     !3
         47        SEND_VAR                                                     !4
         48        SEND_VAR                                                     !5
         49        DO_ICALL                                             $27     
         50        VERIFY_RETURN_TYPE                                           $27
         51      > RETURN                                                       $27
   27    52*       VERIFY_RETURN_TYPE                                           
         53*     > RETURN                                                       null

End of function convertrgbatohex6

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.97 ms | 1718 KiB | 20 Q