1763 posts How's the surf doing?
  • Power Elite Author
  • Trendsetter
  • Top Monthly Author
  • Community Superstar
+10 more
tommusrhodus
says
https://github.com/tommusrhodus/FontAwesome-4.1.0-Class-Names

Thought this might help a few people. There’s likely duplicates in there so feel free to submit a change :)

337 posts
  • Elite Author
  • Author Level 7
  • Trendsetter
  • Exclusive Author
+3 more
subsolar
says

Oh great, thanks for sharing, this will sure come in handy!

Bookmarked!

DistinctiveThemes
DistinctiveThemes Recent Posts Threads Started
323 posts
  • Copyright Ninja
  • Trendsetter
  • Exclusive Author
  • Author Level 6
+5 more
DistinctiveThemes
says

Awesome! Thanks for sharing Tom

1642 posts
  • Elite Author
  • Featured Author
  • 7 Years of Membership
  • Author Level 11
+8 more
fuelthemes
says

This will come in handy :)

1368 posts
  • Copyright Ninja
  • Trendsetter
  • Weekly Top Seller
  • 5 Years of Membership
+7 more
Smartik
says
Isn’t it better to update the class name with a single click and save them in DB or a static file?
/**
 * Font Awesome
 *
 * @param string $path font awesomwe css file path
 * @return array
 */
function fontAwesome($path){

    $css = file_get_contents($path);
    $pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"(.+)";\s+}/';

    preg_match_all($pattern, $css, $matches, PREG_SET_ORDER);

    $icons = array();
    foreach ($matches as $match) {
        $icons[$match[1]] = $match[2];
    }
    return $icons;

}

// Usage 
// -------------------------------------------------------
$icons = fontAwesome(PATH_TO_CSS . '/font-awesome/css/font-awesome.css');

// this will return an array with the following structure:
// -------------------------------------------------------
array(
...
[fa-glass] => \f000
...
);

// to replace the value with the name class:
// -------------------------------------------------------
$list_i = array();
foreach ($font as $key => $value) {
    $list_i[$key] = $key;
}
//Use it
print_r($list_i);

//To display the name class without prefix and dashes and Uppercase:
// -------------------------------------------------------

//Replace this:
$list_i[$key] = $key;

//with this
$list_i[$key] = ucfirst( str_ireplace(array('fa-', '-'), array('', ' '), $key) );

1763 posts How's the surf doing?
  • Power Elite Author
  • Trendsetter
  • Top Monthly Author
  • Community Superstar
+10 more
tommusrhodus
says

@Smartik, honest question, why would that method be better? Not challenging at all, just looking for your insight mate :)

In my case, I pull the list of icons into my theme options and my page builder, so once an icon is chosen it’s saved into an option, or into meta. So the array is only called in certain admin situations anyway and then the value saved by itself.

1368 posts
  • Copyright Ninja
  • Trendsetter
  • Weekly Top Seller
  • 5 Years of Membership
+7 more
Smartik
says

@Smartik, honest question, why would that method be better? Not challenging at all, just looking for your insight mate :) In my case, I pull the list of icons into my theme options and my page builder, so once an icon is chosen it’s saved into an option, or into meta. So the array is only called in certain admin situations anyway and then the value saved by itself.

Because you don’t have to update that list manually with every update of font awesome. In my example this will run everytime, but you can change it a bit and run it only when you want to update the list or write the array in a static file, or anything else.

It probably is not better, it is more flexible(that’s what I should say), and allow to manipulate the code in many ways. Your code is excelent for what it is intended to do, but I’ve just added another solution that allows to get the code in an easy way. :)

1763 posts How's the surf doing?
  • Power Elite Author
  • Trendsetter
  • Top Monthly Author
  • Community Superstar
+10 more
tommusrhodus
says

Because you don’t have to update that list manually with every update of font awesome.

Exactly what I wanted to hear, makes total sense now :)

Cheers mate, that’s an awesome snippet you’ve got there, thanks so much for sharing!

8 posts
  • Featured Author
  • Author Level 6
  • 1 Year of Membership
  • Trendsetter
+3 more
CodeSymbol
says

Thanks for sharing.

by
by
by
by
by
by