3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ColorLuminance($hex, $lum) { // validate hex string $hex = preg_replace("/[^0-9a-f]/i", "", $hex); if (strlen($hex) < 6) { $hex = $hex[0] + $hex[0] + $hex[1] + $hex[1] + $hex[2] + $hex[2]; } // convert to decimal and change luminosity $rgb = "#"; for ($i = 0; $i < 3; $i++) { echo substr($hex, $i * 2, 2) . " * "; $c = base_convert(substr($hex, $i * 2, 2), 16, 10); echo $c . " - "; $c = base_convert((round(min(max(0, floatval($c + ($c * $lum))),255))), 10, 16); echo $c . " - "; $rgb .= substr('00' + $c, strlen($c)); echo $rgb . " - "; } return $rgb; } echo ColorLuminance("#69c", 0) . "\n"; // returns "#6699cc" /*echo ColorLuminance("6699CC", 0.2) . "\n";// "#7ab8f5" - 20% lighter echo ColorLuminance("69C", -0.5) . "\n";// "#334d66" - 50% darker echo ColorLuminance("000", 1) . "\n";// "#000000" - true black cannot be made lighter!*/
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sJ9Ab
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'colorluminance'
          1        SEND_VAL                                                 '%2369c'
          2        SEND_VAL                                                 0
          3        DO_FCALL                                      0  $0      
          4        CONCAT                                           ~1      $0, '%0A'
          5        ECHO                                                     ~1
   31     6      > RETURN                                                   1

Function colorluminance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 26
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 26
Branch analysis from position: 82
Branch analysis from position: 26
Branch analysis from position: 23
filename:       /in/sJ9Ab
function name:  ColorLuminance
number of ops:  84
compiled vars:  !0 = $hex, !1 = $lum, !2 = $rgb, !3 = $i, !4 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%2F%5B%5E0-9a-f%5D%2Fi'
          4        SEND_VAL                                                 ''
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !0, $5
    7     8        STRLEN                                           ~7      !0
          9        IS_SMALLER                                               ~7, 6
         10      > JMPZ                                                     ~8, ->23
    8    11    >   FETCH_DIM_R                                      ~9      !0, 0
         12        FETCH_DIM_R                                      ~10     !0, 0
         13        ADD                                              ~11     ~9, ~10
         14        FETCH_DIM_R                                      ~12     !0, 1
         15        ADD                                              ~13     ~11, ~12
         16        FETCH_DIM_R                                      ~14     !0, 1
         17        ADD                                              ~15     ~13, ~14
         18        FETCH_DIM_R                                      ~16     !0, 2
         19        ADD                                              ~17     ~15, ~16
         20        FETCH_DIM_R                                      ~18     !0, 2
         21        ADD                                              ~19     ~17, ~18
         22        ASSIGN                                                   !0, ~19
   12    23    >   ASSIGN                                                   !2, '%23'
   13    24        ASSIGN                                                   !3, 0
         25      > JMP                                                      ->80
   15    26    >   INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !0
         28        MUL                                              ~23     !3, 2
         29        SEND_VAL                                                 ~23
         30        SEND_VAL                                                 2
         31        DO_ICALL                                         $24     
         32        CONCAT                                           ~25     $24, '+%2A+'
         33        ECHO                                                     ~25
   17    34        INIT_FCALL                                               'base_convert'
         35        INIT_FCALL                                               'substr'
         36        SEND_VAR                                                 !0
         37        MUL                                              ~26     !3, 2
         38        SEND_VAL                                                 ~26
         39        SEND_VAL                                                 2
         40        DO_ICALL                                         $27     
         41        SEND_VAR                                                 $27
         42        SEND_VAL                                                 16
         43        SEND_VAL                                                 10
         44        DO_ICALL                                         $28     
         45        ASSIGN                                                   !4, $28
   18    46        CONCAT                                           ~30     !4, '+-+'
         47        ECHO                                                     ~30
   19    48        INIT_FCALL                                               'base_convert'
         49        INIT_FCALL                                               'round'
         50        INIT_FCALL                                               'min'
         51        INIT_FCALL                                               'max'
         52        SEND_VAL                                                 0
         53        MUL                                              ~31     !4, !1
         54        ADD                                              ~32     !4, ~31
         55        CAST                                          5  ~33     ~32
         56        SEND_VAL                                                 ~33
         57        DO_ICALL                                         $34     
         58        SEND_VAR                                                 $34
         59        SEND_VAL                                                 255
         60        DO_ICALL                                         $35     
         61        SEND_VAR                                                 $35
         62        DO_ICALL                                         $36     
         63        SEND_VAR                                                 $36
         64        SEND_VAL                                                 10
         65        SEND_VAL                                                 16
         66        DO_ICALL                                         $37     
         67        ASSIGN                                                   !4, $37
   20    68        CONCAT                                           ~39     !4, '+-+'
         69        ECHO                                                     ~39
   21    70        INIT_FCALL                                               'substr'
         71        ADD                                              ~40     '00', !4
         72        SEND_VAL                                                 ~40
         73        STRLEN                                           ~41     !4
         74        SEND_VAL                                                 ~41
         75        DO_ICALL                                         $42     
         76        ASSIGN_OP                                     8          !2, $42
   22    77        CONCAT                                           ~44     !2, '+-+'
         78        ECHO                                                     ~44
   13    79        PRE_INC                                                  !3
         80    >   IS_SMALLER                                               !3, 3
         81      > JMPNZ                                                    ~46, ->26
   25    82    > > RETURN                                                   !2
   26    83*     > RETURN                                                   null

End of function colorluminance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.09 ms | 1407 KiB | 26 Q