Skip to content

Instantly share code, notes, and snippets.

@navitronic
Created March 21, 2014 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navitronic/9679452 to your computer and use it in GitHub Desktop.
Save navitronic/9679452 to your computer and use it in GitHub Desktop.
Display all hexadecimal colours within a less or css file.
<?php
$less = file_get_contents(__DIR__ . '/app.less');
preg_match_all('/#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b/', $less, $matches);
$colors = array_values($matches[0]);
$colors = array_map(function($color){ return strtolower($color); }, $colors);
$colors = array_unique($colors);
sort($colors);
foreach ($colors as $color) {
echo '<div style="float:left; width:80px;height:80px;background-color:' . $color . '">' . $color . '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment