Skip to content

Instantly share code, notes, and snippets.

@shrimp2t
Created August 14, 2017 02:37
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 shrimp2t/95a94b90abe78bc2fd5e359588e7e021 to your computer and use it in GitHub Desktop.
Save shrimp2t/95a94b90abe78bc2fd5e359588e7e021 to your computer and use it in GitHub Desktop.
Get font-awesome icons from css file
<?php
**
* Remove items from an array
* @param array $array The array to manage
* @param void $element An array or a string of the item to remove
* @return array The cleaned array with resetted keys
*/
function array_delete($array, $element) {
return (is_array($element)) ? array_values(array_diff($array, $element)) : array_values(array_diff($array, array($element)));
}
$icons_file ='assets/font-awesome/css/font-awesome.css';
if ( ! is_readable( $icons_file ) ) {
return array();
}
$parsed_file = file_get_contents($icons_file);
preg_match_all("/fa\-([a-zA-z0-9\-]+[^\:\.\,\s])/", $parsed_file, $matches);
$exclude_icons = array("fa-lg", "fa-2x", "fa-3x", "fa-4x", "fa-5x", "fa-ul", "fa-li", "fa-fw", "fa-border", "fa-pulse", "fa-rotate-90", "fa-rotate-180", "fa-rotate-270", "fa-spin", "fa-flip-horizontal", "fa-flip-vertical", "fa-stack", "fa-stack-1x", "fa-stack-2x", "fa-inverse", 'fa-pull-left', 'fa-pull-right');
$icons = array_delete($matches[0], $exclude_icons);
return $icons;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment