Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.