PHP code example of 10quality / php-css-color-parser

1. Go to this page and download the library: Download 10quality/php-css-color-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

10quality / php-css-color-parser example snippets


use TenQuality\Utility\Color\CssParser;

// This will echo "#44FCCD"
echo CssParser::hex('#44fCCd');

// This will echo "#44FFFF"
echo CssParser::hex('#4ff');

// This will echo "#FFFFFF"
echo CssParser::hex('white');

// This will echo "#89CC7F"
echo CssParser::hex('89cc7F');

// This will echo "#44FCCD44"
echo CssParser::hexTransparent('#44fCCd44');

// This will echo "#44FFFFFF"
echo CssParser::hexTransparent('#4ff');

// This will echo "#FFFFFFFF"
echo CssParser::hexTransparent('white');

// This will echo "0x4444FCCD"
echo CssParser::argb('#44fCCd44');

// This will echo "0xFF44FFFF"
echo CssParser::argb('#4ff');

// This will echo "0xFFFFFFFF"
echo CssParser::argb('white');

// This will echo "rgba(57,115,157,0.53)"
echo CssParser::rgba('#39739d88');

// This will echo "rgba(255,255,255,1)"
echo CssParser::rgba('white');

// This will dump the following array "[57,115,157,255]"
var_dump(CssParser::array('#39739d'));

// This will echo "{"red":57,"green":115,"blue":157,"alpha":255}"
echo CssParser::string('#39739d');

CssParser::setAlpha('0');
// Or
CssParser::setAlpha(CssParser::ALPHA_TRANSPARENT);

// This will echo "#44FFFF00"
echo CssParser::hexTransparent('#4ff');

// This will echo "rgba(255,255,255,0)"
echo CssParser::rgba('white');

// This will echo "0x0044FFFF"
echo CssParser::argb('#4ff');

CssParser::setAlpha('F');
// Or
CssParser::setAlpha(CssParser::ALPHA_OPAQUE);

// This will exho "#00008B"
echo CssParser::hex('darkblue', ['/darkblue/','/darkgreen/'], ['00008B','006400']);