RGBA format HEX into RGB format HEX? PHP

前端 未结 4 747
攒了一身酷
攒了一身酷 2021-01-16 18:02

I want to convert back and forth between RGBA-formated HEX colors (like0xFF0000FF) and RGB-formated HEX colors (like 0xFF0000) in PHP.

How

4条回答
  •  情书的邮戳
    2021-01-16 18:54

    These two functions will do what you need:

    function rgbaToRgb ($rgba) {
        return substr($rgba, 0, -2);
    }
    
    function rgbToRgba ($rgb) {
        return $rgb . "FF";
    }
    

    The first one simply removes the last two characters, whilst the second one simply appends FF.

提交回复
热议问题