I’m a huge fan of Font Awesome and I use it in all of my projects. So recently I was building something where I needed an array of Font Awesome icons. I made some searches and found an array, but it was pretty outdated, so I tried to use some regex to generate an array of Font Awesome icons in PHP and it made it really easy.

So in case anyone wants an array of Font Awesome, you can run the following regex:

$pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"\\\\(.+)";\s+}/';
$subject =  file_get_contents('font-awesome/css/font-awesome.css');
preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);

And if you put the following code after it, you can print that array in a more organized way:

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


echo '<pre>';
echo '</pre>';

It will generate an array list which will look like this:

    [fa-500px] => f26e
    [fa-adjust] => f042
    [fa-adn] => f170
    [fa-align-center] => f037
    [fa-align-justify] => f039
    [fa-align-left] => f036
    [fa-align-right] => f038

Hope it will help you all! 🙂